Skip to content

Commit b5aa071

Browse files
committed
fix PwmExt
1 parent 2ad748e commit b5aa071

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

examples/pwm-sinus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn main() -> ! {
2020
let gpioa = dp.GPIOA.split();
2121
let channels = (gpioa.pa8.into_alternate(), gpioa.pa9.into_alternate());
2222

23-
let mut pwm = dp.TIM1.pwm_us(&clocks, channels, 100.micros());
23+
let mut pwm = dp.TIM1.pwm_us(channels, 100.micros(), &clocks);
2424
let mut counter = dp.TIM2.counter_us(&clocks);
2525
let max_duty = pwm.get_max_duty();
2626

examples/pwm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() -> ! {
1818
let gpioa = dp.GPIOA.split();
1919
let channels = (gpioa.pa8.into_alternate(), gpioa.pa9.into_alternate());
2020

21-
let pwm = dp.TIM1.pwm_hz(&clocks, channels, 20.kHz()).split();
21+
let pwm = dp.TIM1.pwm_hz(channels, 20.kHz(), &clocks).split();
2222
let (mut ch1, _ch2) = pwm;
2323
let max_duty = ch1.get_max_duty();
2424
ch1.set_duty(max_duty / 2);

src/timer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,6 @@ impl<TIM: Instance + MasterTimer, const FREQ: u32> FTimer<TIM, FREQ> {
726726
pub(crate) const fn compute_arr_presc(freq: u32, clock: u32) -> (u16, u32) {
727727
let ticks = clock / freq;
728728
let psc = (ticks - 1) / (1 << 16);
729-
assert!(psc <= u16::MAX as u32);
730729
let arr = ticks / (psc + 1) - 1;
731730
(psc as u16, arr)
732731
}

src/timer/pwm.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,45 +90,56 @@ where
9090
{
9191
}
9292

93-
pub trait PwmExt<P, PINS>
93+
pub trait PwmExt
9494
where
9595
Self: Sized + Instance + WithPwm,
96-
PINS: Pins<Self, P>,
9796
{
98-
fn pwm<const FREQ: u32>(
97+
fn pwm<P, PINS, const FREQ: u32>(
9998
self,
100-
clocks: &Clocks,
10199
pins: PINS,
102100
time: TimerDurationU32<FREQ>,
103-
) -> Pwm<Self, P, PINS, FREQ>;
101+
clocks: &Clocks,
102+
) -> Pwm<Self, P, PINS, FREQ>
103+
where
104+
PINS: Pins<Self, P>;
104105

105-
fn pwm_hz(self, clocks: &Clocks, pins: PINS, freq: Hertz) -> PwmHz<Self, P, PINS>;
106+
fn pwm_hz<P, PINS>(self, pins: PINS, freq: Hertz, clocks: &Clocks) -> PwmHz<Self, P, PINS>
107+
where
108+
PINS: Pins<Self, P>;
106109

107-
fn pwm_us(
110+
fn pwm_us<P, PINS>(
108111
self,
109-
clocks: &Clocks,
110112
pins: PINS,
111113
time: TimerDurationU32<1_000_000>,
112-
) -> Pwm<Self, P, PINS, 1_000_000> {
113-
self.pwm::<1_000_000>(clocks, pins, time)
114+
clocks: &Clocks,
115+
) -> Pwm<Self, P, PINS, 1_000_000>
116+
where
117+
PINS: Pins<Self, P>,
118+
{
119+
self.pwm::<_, _, 1_000_000>(pins, time, clocks)
114120
}
115121
}
116122

117-
impl<TIM, P, PINS> PwmExt<P, PINS> for TIM
123+
impl<TIM> PwmExt for TIM
118124
where
119125
Self: Sized + Instance + WithPwm,
120-
PINS: Pins<Self, P>,
121126
{
122-
fn pwm<const FREQ: u32>(
127+
fn pwm<P, PINS, const FREQ: u32>(
123128
self,
124-
clocks: &Clocks,
125129
pins: PINS,
126130
time: TimerDurationU32<FREQ>,
127-
) -> Pwm<TIM, P, PINS, FREQ> {
131+
clocks: &Clocks,
132+
) -> Pwm<TIM, P, PINS, FREQ>
133+
where
134+
PINS: Pins<Self, P>,
135+
{
128136
FTimer::<Self, FREQ>::new(self, clocks).pwm(pins, time)
129137
}
130138

131-
fn pwm_hz(self, clocks: &Clocks, pins: PINS, time: Hertz) -> PwmHz<TIM, P, PINS> {
139+
fn pwm_hz<P, PINS>(self, pins: PINS, time: Hertz, clocks: &Clocks) -> PwmHz<TIM, P, PINS>
140+
where
141+
PINS: Pins<Self, P>,
142+
{
132143
Timer::new(self, clocks).pwm_hz(pins, time)
133144
}
134145
}

0 commit comments

Comments
 (0)