Skip to content

Commit ab73628

Browse files
committed
SetDutyCycle
1 parent d1f02bd commit ab73628

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/timer/hal_1.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
//! TIM2 and TIM5 are a general purpose 32-bit auto-reload up/downcounter with
44
//! a 16-bit prescaler.
55
6+
use core::convert::Infallible;
7+
68
use embedded_hal_one::delay::DelayUs;
79

8-
use super::{Delay, Instance, SysDelay};
10+
use super::{Delay, Instance, SysDelay, WithPwm, PwmChannel};
911
use fugit::ExtU32;
1012

1113
impl DelayUs for SysDelay {
@@ -27,3 +29,17 @@ impl<TIM: Instance, const FREQ: u32> DelayUs for Delay<TIM, FREQ> {
2729
self.delay(ms.millis());
2830
}
2931
}
32+
33+
impl<TIM: Instance + WithPwm, const C: u8> embedded_hal_one::pwm::ErrorType for PwmChannel<TIM, C> {
34+
type Error = Infallible;
35+
}
36+
37+
impl<TIM: Instance + WithPwm, const C: u8> embedded_hal_one::pwm::SetDutyCycle for PwmChannel<TIM, C> {
38+
fn get_max_duty_cycle(&self) -> u16 {
39+
self.get_max_duty()
40+
}
41+
fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error> {
42+
self.set_duty(duty);
43+
Ok(())
44+
}
45+
}

0 commit comments

Comments
 (0)