Skip to content

Commit f6c80b0

Browse files
committed
resolve mcpwm FIXME
1 parent b1440cb commit f6c80b0

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

esp-hal-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ esp32 = { version = "0.15.0", features = ["critical-section"], optional = true
5454
esp32c2 = { version = "0.5.1", features = ["critical-section"], optional = true }
5555
esp32c3 = { version = "0.8.1", features = ["critical-section"], optional = true }
5656
esp32s2 = { version = "0.6.0", features = ["critical-section"], optional = true }
57-
esp32s3 = { version = "0.8.0", features = ["critical-section"], optional = true }
57+
esp32s3 = { version = "0.10.0", features = ["critical-section"], optional = true }
5858

5959
[features]
6060
esp32 = ["esp32/rt" , "procmacros/xtensa", "xtensa-lx-rt/esp32", "xtensa-lx/esp32", "critical-section/restore-state-u32", "lock_api"]

esp-hal-common/src/mcpwm/timer.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,39 @@ impl<const TIM: u8, PWM: PwmPeripheral> Timer<TIM, PWM> {
6767
// We only write to our TIMERx_SYNC register
6868
let block = unsafe { &*PWM::block() };
6969

70-
// FIXME replace with safe API after https://github.com/esp-rs/esp-pacs/issues/57
7170
match TIM {
7271
0 => {
7372
let sw = block.timer0_sync.read().sw().bit_is_set();
74-
let bits = ((direction as u32) << 20) + ((phase as u32) << 4) + ((!sw as u32) << 1);
75-
unsafe { block.timer0_sync.write(|w| w.bits(bits)) }
73+
block.timer0_sync.write(|w| {
74+
w.timer0_phase_direction()
75+
.variant(direction as u8 != 0)
76+
.timer0_phase()
77+
.variant(phase)
78+
.sw()
79+
.variant(!sw)
80+
});
7681
}
7782
1 => {
7883
let sw = block.timer1_sync.read().sw().bit_is_set();
79-
let bits = ((direction as u32) << 20) + ((phase as u32) << 4) + ((!sw as u32) << 1);
80-
unsafe { block.timer1_sync.write(|w| w.bits(bits)) }
84+
block.timer1_sync.write(|w| {
85+
w.timer1_phase_direction()
86+
.variant(direction as u8 != 0)
87+
.timer1_phase()
88+
.variant(phase)
89+
.sw()
90+
.variant(!sw)
91+
});
8192
}
8293
2 => {
8394
let sw = block.timer2_sync.read().sw().bit_is_set();
84-
let bits = ((direction as u32) << 20) + ((phase as u32) << 4) + ((!sw as u32) << 1);
85-
unsafe { block.timer2_sync.write(|w| w.bits(bits)) }
95+
block.timer2_sync.write(|w| {
96+
w.timer2_phase_direction()
97+
.variant(direction as u8 != 0)
98+
.timer2_phase()
99+
.variant(phase)
100+
.sw()
101+
.variant(!sw)
102+
});
86103
}
87104
_ => {
88105
unreachable!()

0 commit comments

Comments
 (0)