pub struct PwmChannel<TIMERX, PIN, const C: u8> { /* private fields */ }Expand description
One PWM output of a timer, configured and ready to take a duty value.
Channels of one timer share the period (PSC/CAR belong to their common
counter); duty is the channel’s own.
Duties reach separate registers, but all the enables live in one: enabling a channel while another is enabled elsewhere — from an interrupt, say — can lose one of the writes.
Implementations§
Source§impl<TIMERX: PwmOps<C>, PIN: ChannelPin<TIMERX, C>, const C: u8> PwmChannel<TIMERX, PIN, C>
impl<TIMERX: PwmOps<C>, PIN: ChannelPin<TIMERX, C>, const C: u8> PwmChannel<TIMERX, PIN, C>
Sourcepub fn set_duty(&mut self, cv: u16)
pub fn set_duty(&mut self, cv: u16)
Sets the duty, in timer ticks of the period.
Active for cv ticks out of max_duty: zero is a
permanently inactive pin, max_duty and above a permanently active one.
The value reaches the output at the next rollover, not mid-period.
Sourcepub fn max_duty(&self) -> u16
pub fn max_duty(&self) -> u16
Returns the duty that corresponds to a fully active output.
The period the counter runs on, car() + 1 ticks, which is also the
resolution. A period spanning the whole counter reports one tick short,
being the only value that does not fit u16.
Sourcepub fn listen(&mut self)
pub fn listen(&mut self)
Lets the compare match raise an interrupt.
Fires at the point in the period where the output flips, not at the
rollover — that one is CountDownTimer::listen.
The whole timer shares one NVIC line, so a handler serving several
channels tells them apart by is_listening and
is_pending together. The flag alone will not do:
after reset an untouched channel compares against zero and raises its
flag once per rollover. Unmasking the line is the caller’s.
Sourcepub fn unlisten(&mut self)
pub fn unlisten(&mut self)
Stops the compare match from raising an interrupt. Leaves the NVIC alone.
Sourcepub fn is_listening(&self) -> bool
pub fn is_listening(&self) -> bool
Whether this channel’s compare match reaches the NVIC.
Sourcepub fn is_pending(&self) -> bool
pub fn is_pending(&self) -> bool
Whether this channel’s flag is raised.
Sourcepub fn clear_interrupt(&mut self)
pub fn clear_interrupt(&mut self)
Clears this channel’s flag.
A handler must call this: a compare match yields no value to consume, so unlike a capture there is nothing else that acknowledges it, and hardware never clears the flag on its own.
Trait Implementations§
Source§impl<TIMERX: PwmOps<C>, PIN: ChannelPin<TIMERX, C>, const C: u8> ErrorType for PwmChannel<TIMERX, PIN, C>
Writing a duty cannot fail: the value goes straight into a compare register
the hardware always accepts.
impl<TIMERX: PwmOps<C>, PIN: ChannelPin<TIMERX, C>, const C: u8> ErrorType for PwmChannel<TIMERX, PIN, C>
Writing a duty cannot fail: the value goes straight into a compare register the hardware always accepts.
Source§impl<TIMERX: PwmOps<C>, PIN: ChannelPin<TIMERX, C>, const C: u8> SetDutyCycle for PwmChannel<TIMERX, PIN, C>
Duty control for portable drivers, delegating to PwmChannel::set_duty.
impl<TIMERX: PwmOps<C>, PIN: ChannelPin<TIMERX, C>, const C: u8> SetDutyCycle for PwmChannel<TIMERX, PIN, C>
Duty control for portable drivers, delegating to PwmChannel::set_duty.
set_duty_cycle_percent and friends are the trait’s own defaults over these
two, scaled against the period the timer currently runs on.
Source§fn max_duty_cycle(&self) -> u16
fn max_duty_cycle(&self) -> u16
Source§fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error>
fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error>
duty / max_duty. Read more