re-export SetDutyCycle for user convenience

This commit is contained in:
rafael 2024-10-21 11:54:17 +02:00
parent 8baf88f8f4
commit 693bd8c6de

View File

@ -1,7 +1,7 @@
//! Pulse Width Modulation (PWM) //! Pulse Width Modulation (PWM)
use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef};
use embedded_hal_1::pwm::{Error, ErrorKind, ErrorType, SetDutyCycle}; use embedded_hal_1::pwm::{Error, ErrorKind, ErrorType};
use fixed::traits::ToFixed; use fixed::traits::ToFixed;
use fixed::FixedU16; use fixed::FixedU16;
use pac::pwm::regs::{ChDiv, Intr}; use pac::pwm::regs::{ChDiv, Intr};
@ -10,6 +10,8 @@ use pac::pwm::vals::Divmode;
use crate::gpio::{AnyPin, Pin as GpioPin, Pull, SealedPin as _}; use crate::gpio::{AnyPin, Pin as GpioPin, Pull, SealedPin as _};
use crate::{pac, peripherals, RegExt}; use crate::{pac, peripherals, RegExt};
pub use embedded_hal_1::pwm::SetDutyCycle;
/// The configuration of a PWM slice. /// The configuration of a PWM slice.
/// Note the period in clock cycles of a slice can be computed as: /// Note the period in clock cycles of a slice can be computed as:
/// `(top + 1) * (phase_correct ? 1 : 2) * divider` /// `(top + 1) * (phase_correct ? 1 : 2) * divider`
@ -113,9 +115,7 @@ impl<'d> SetDutyCycle for Pwm<'d> {
} }
fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error> { fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error> {
info!("duty {}",&duty);
let max_duty = self.max_duty_cycle(); let max_duty = self.max_duty_cycle();
info!("max duty {}", &max_duty);
if duty > max_duty { if duty > max_duty {
return Err(PwmError::InvalidDutyCycle); return Err(PwmError::InvalidDutyCycle);
} }