Skip to main content

PwmChannel

Struct PwmChannel 

Source
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>

Source

pub fn enable(&mut self)

Drives the pin from the comparison, keeping the duty already set.

Source

pub fn disable(&mut self)

Stops driving the pin, leaving the channel configured.

Source

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.

Source

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.

Source

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.

Source

pub fn unlisten(&mut self)

Stops the compare match from raising an interrupt. Leaves the NVIC alone.

Source

pub fn is_listening(&self) -> bool

Whether this channel’s compare match reaches the NVIC.

Source

pub fn is_pending(&self) -> bool

Whether this channel’s flag is raised.

Source

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.

Source§

type Error = !

Error type
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.

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

Get the maximum duty cycle value. Read more
Source§

fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error>

Set the duty cycle to duty / max_duty. Read more
Source§

fn set_duty_cycle_fully_off(&mut self) -> Result<(), Self::Error>

Set the duty cycle to 0%, or always inactive.
Source§

fn set_duty_cycle_fully_on(&mut self) -> Result<(), Self::Error>

Set the duty cycle to 100%, or always active.
Source§

fn set_duty_cycle_fraction( &mut self, num: u16, denom: u16, ) -> Result<(), Self::Error>

Set the duty cycle to num / denom. Read more
Source§

fn set_duty_cycle_percent(&mut self, percent: u8) -> Result<(), Self::Error>

Set the duty cycle to percent / 100 Read more

Auto Trait Implementations§

§

impl<TIMERX, PIN, const C: u8> Freeze for PwmChannel<TIMERX, PIN, C>
where TIMERX: Freeze, PIN: Freeze,

§

impl<TIMERX, PIN, const C: u8> RefUnwindSafe for PwmChannel<TIMERX, PIN, C>
where TIMERX: RefUnwindSafe, PIN: RefUnwindSafe,

§

impl<TIMERX, PIN, const C: u8> Send for PwmChannel<TIMERX, PIN, C>
where TIMERX: Send, PIN: Send,

§

impl<TIMERX, PIN, const C: u8> Sync for PwmChannel<TIMERX, PIN, C>
where TIMERX: Sync, PIN: Sync,

§

impl<TIMERX, PIN, const C: u8> Unpin for PwmChannel<TIMERX, PIN, C>
where TIMERX: Unpin, PIN: Unpin,

§

impl<TIMERX, PIN, const C: u8> UnsafeUnpin for PwmChannel<TIMERX, PIN, C>
where TIMERX: UnsafeUnpin, PIN: UnsafeUnpin,

§

impl<TIMERX, PIN, const C: u8> UnwindSafe for PwmChannel<TIMERX, PIN, C>
where TIMERX: UnwindSafe, PIN: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.