Skip to content

Commit 6fa9e55

Browse files
burrbullrursprung
authored andcommitted
implement embedded-hal=1.0.0-alpha.10 SetDutyCycle
1 parent b9d055b commit 6fa9e55

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/timer/hal_1.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
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;
67
use embedded_hal_one::delay::DelayUs;
78

8-
use super::{Delay, Instance, SysDelay};
9+
use super::{Delay, Instance, PwmChannel, SysDelay, WithPwm};
910
use fugit::ExtU32;
1011

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

0 commit comments

Comments
 (0)