pub struct PwmInput<TIM>
where TIM: Instance + WithPwm + CPin<0>,
{ /* private fields */ }
Expand description

Represents a TIMer configured as a PWM input. This peripheral will emit an interrupt on CC2 events, which occurs at two times in this mode:

  1. When a new cycle is started: the duty cycle will be 1.00
  2. When the period is captured. the duty cycle will be an observable value. An example interrupt handler is provided:
use stm32f4xx_hal::{pac::TIM8, pwm_input::PwmInput};

type Monitor = PwmInput<TIM8>;

fn tim8_cc2(monitor: &Monitor) {
    let duty_clocks = monitor.get_duty_cycle_clocks();
    let period_clocks = monitor.get_period_clocks();
    // check if this interrupt was caused by a capture at the wrong CC2,
    // peripheral limitation.
    if !monitor.is_valid_capture() {
        return;
    }
    let duty = monitor.get_duty_cycle();
}

Implementations§

source§

impl<TIM> PwmInput<TIM>
where TIM: Instance + WithPwm + CPin<0>,

source

pub fn release(self) -> Timer<TIM>

source§

impl PwmInput<TIM1>

source

pub fn get_period_clocks(&self) -> <TIM1 as General>::Width

Period of PWM signal in terms of clock cycles

source

pub fn get_duty_cycle_clocks(&self) -> <TIM1 as General>::Width

Duty cycle in terms of clock cycles

source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

source§

impl PwmInput<TIM2>

source

pub fn get_period_clocks(&self) -> <TIM2 as General>::Width

Period of PWM signal in terms of clock cycles

source

pub fn get_duty_cycle_clocks(&self) -> <TIM2 as General>::Width

Duty cycle in terms of clock cycles

source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

source§

impl PwmInput<TIM3>

source

pub fn get_period_clocks(&self) -> <TIM3 as General>::Width

Period of PWM signal in terms of clock cycles

source

pub fn get_duty_cycle_clocks(&self) -> <TIM3 as General>::Width

Duty cycle in terms of clock cycles

source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

source§

impl PwmInput<TIM4>

source

pub fn get_period_clocks(&self) -> <TIM4 as General>::Width

Period of PWM signal in terms of clock cycles

source

pub fn get_duty_cycle_clocks(&self) -> <TIM4 as General>::Width

Duty cycle in terms of clock cycles

source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

source§

impl PwmInput<TIM5>

source

pub fn get_period_clocks(&self) -> <TIM5 as General>::Width

Period of PWM signal in terms of clock cycles

source

pub fn get_duty_cycle_clocks(&self) -> <TIM5 as General>::Width

Duty cycle in terms of clock cycles

source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

source§

impl PwmInput<TIM8>

source

pub fn get_period_clocks(&self) -> <TIM8 as General>::Width

Period of PWM signal in terms of clock cycles

source

pub fn get_duty_cycle_clocks(&self) -> <TIM8 as General>::Width

Duty cycle in terms of clock cycles

source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

source§

impl PwmInput<TIM9>

source

pub fn get_period_clocks(&self) -> <TIM9 as General>::Width

Period of PWM signal in terms of clock cycles

source

pub fn get_duty_cycle_clocks(&self) -> <TIM9 as General>::Width

Duty cycle in terms of clock cycles

source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

source§

impl PwmInput<TIM12>

source

pub fn get_period_clocks(&self) -> <TIM12 as General>::Width

Period of PWM signal in terms of clock cycles

source

pub fn get_duty_cycle_clocks(&self) -> <TIM12 as General>::Width

Duty cycle in terms of clock cycles

source

pub fn get_duty_cycle(&self) -> f32

Observed duty cycle as a float in range [0.00, 1.00]

source

pub fn is_valid_capture(&self) -> bool

Returns whether the timer’s duty cycle is a valid observation (Limitation of how the captures work is extra CC2 interrupts are generated when the PWM cycle enters a new period).

Methods from Deref<Target = Timer<TIM>>§

source

pub fn configure(&mut self, clocks: &Clocks)

source

pub fn configure_external(&mut self, clocks: &Clocks)

source

pub fn listen(&mut self, event: SysEvent)

Starts listening for an event

source

pub fn unlisten(&mut self, event: SysEvent)

Stops listening for an event

source

pub fn configure(&mut self, clocks: &Clocks)

source

pub fn set_master_mode(&mut self, mode: TIM::Mms)

Trait Implementations§

source§

impl<TIM> Deref for PwmInput<TIM>
where TIM: Instance + WithPwm + CPin<0>,

§

type Target = Timer<TIM>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<TIM> DerefMut for PwmInput<TIM>
where TIM: Instance + WithPwm + CPin<0>,

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl<TIM> RefUnwindSafe for PwmInput<TIM>
where TIM: RefUnwindSafe, <TIM as TimCPin<0>>::Ch<PushPull>: RefUnwindSafe,

§

impl<TIM> Send for PwmInput<TIM>
where TIM: Send, <TIM as TimCPin<0>>::Ch<PushPull>: Send,

§

impl<TIM> Sync for PwmInput<TIM>
where TIM: Sync, <TIM as TimCPin<0>>::Ch<PushPull>: Sync,

§

impl<TIM> Unpin for PwmInput<TIM>
where TIM: Unpin, <TIM as TimCPin<0>>::Ch<PushPull>: Unpin,

§

impl<TIM> UnwindSafe for PwmInput<TIM>
where TIM: UnwindSafe, <TIM as TimCPin<0>>::Ch<PushPull>: 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>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.