Struct nrf52810_hal::pwm::Pwm

source ·
pub struct Pwm<T>
where T: Instance,
{ /* private fields */ }
Expand description

A safe wrapper around the raw peripheral.

Implementations§

source§

impl<T> Pwm<T>
where T: Instance,

source

pub fn new(pwm: T) -> Pwm<T>

Takes ownership of the peripheral and applies sane defaults.

source

pub fn set_prescaler(&self, div: Prescaler) -> &Pwm<T>

Sets the PWM clock prescaler.

source

pub fn prescaler(&self) -> Prescaler

Sets the PWM clock prescaler.

source

pub fn set_max_duty(&self, duty: u16) -> &Pwm<T>

Sets the maximum duty cycle value.

source

pub fn max_duty(&self) -> u16

Returns the maximum duty cycle value.

source

pub fn set_period(&self, freq: Hertz) -> &Pwm<T>

Sets the PWM output frequency.

source

pub fn period(&self) -> Hertz

Returns the PWM output frequency.

source

pub fn set_output_pin( &self, channel: Channel, pin: Pin<Output<PushPull>> ) -> &Pwm<T>

Sets the associated output pin for the PWM channel.

Modifying the pin configuration while the PWM instance is enabled is not recommended.

source

pub fn swap_output_pin( &mut self, channel: Channel, pin: Pin<Output<PushPull>> ) -> Option<Pin<Output<PushPull>>>

Sets the output pin of channel, and returns the old pin (if any).

Modifying the pin configuration while the PWM instance is enabled is not recommended.

source

pub fn clear_output_pin( &mut self, channel: Channel ) -> Option<Pin<Output<PushPull>>>

Disables the output pin of channel.

The output pin is returned, if one was previously configured.

Modifying the pin configuration while the PWM instance is enabled is not recommended.

source

pub fn enable(&self)

Enables the PWM generator.

source

pub fn disable(&self)

Disables the PWM generator.

source

pub fn enable_channel(&self, channel: Channel) -> &Pwm<T>

Enables a PWM channel.

source

pub fn disable_channel(&self, channel: Channel) -> &Pwm<T>

Disables a PWM channel.

source

pub fn enable_group(&self, group: Group) -> &Pwm<T>

Enables a PWM group.

source

pub fn disable_group(&self, group: Group) -> &Pwm<T>

Disables a PWM group.

source

pub fn set_load_mode(&self, mode: LoadMode) -> &Pwm<T>

Cofigures how a sequence is read from RAM and is spread to the compare register.

source

pub fn load_mode(&self) -> LoadMode

Returns how a sequence is read from RAM and is spread to the compare register.

source

pub fn set_counter_mode(&self, mode: CounterMode) -> &Pwm<T>

Selects operating mode of the wave counter.

source

pub fn counter_mode(&self) -> CounterMode

Returns selected operating mode of the wave counter.

source

pub fn set_step_mode(&self, mode: StepMode) -> &Pwm<T>

Selects source for advancing the active sequence.

source

pub fn step_mode(&self) -> StepMode

Returns selected source for advancing the active sequence.

source

pub fn set_duty_on_common(&self, duty: u16)

Sets duty cycle (15 bit) for all PWM channels. Will replace any ongoing sequence playback.

source

pub fn set_duty_off_common(&self, duty: u16)

Sets inverted duty cycle (15 bit) for all PWM channels. Will replace any ongoing sequence playback.

source

pub fn duty_on_common(&self) -> u16

Returns the common duty cycle value for all PWM channels in Common load mode.

source

pub fn duty_off_common(&self) -> u16

Returns the inverted common duty cycle value for all PWM channels in Common load mode.

source

pub fn set_duty_on_group(&self, group: Group, duty: u16)

Sets duty cycle (15 bit) for a PWM group. Will replace any ongoing sequence playback.

source

pub fn set_duty_off_group(&self, group: Group, duty: u16)

Sets inverted duty cycle (15 bit) for a PWM group. Will replace any ongoing sequence playback.

source

pub fn duty_on_group(&self, group: Group) -> u16

Returns duty cycle value for a PWM group.

source

pub fn duty_off_group(&self, group: Group) -> u16

Returns inverted duty cycle value for a PWM group.

source

pub fn set_duty_on(&self, channel: Channel, duty: u16)

Sets duty cycle (15 bit) for a PWM channel. Will replace any ongoing sequence playback and the other channels will return to their previously set value.

source

pub fn set_duty_off(&self, channel: Channel, duty: u16)

Sets inverted duty cycle (15 bit) for a PWM channel. Will replace any ongoing sequence playback and the other channels will return to their previously set value.

source

pub fn duty_on(&self, channel: Channel) -> u16

Returns the duty cycle value for a PWM channel.

source

pub fn duty_off(&self, channel: Channel) -> u16

Returns the inverted duty cycle value for a PWM group.

source

pub fn set_loop(&self, mode: Loop)

Sets number of playbacks of sequences.

source

pub fn one_shot(&self) -> &Pwm<T>

Looping disabled (stop at the end of the sequence).

source

pub fn loop_inf(&self) -> &Pwm<T>

Loops playback of sequences indefinitely.

source

pub fn repeat(&self, times: u16) -> &Pwm<T>

Sets number of playbacks of sequences.

source

pub fn set_seq_refresh(&self, seq: Seq, periods: u32) -> &Pwm<T>

Sets number of additional PWM periods between samples loaded into compare register.

source

pub fn set_seq_end_delay(&self, seq: Seq, periods: u32) -> &Pwm<T>

Sets number of additional PWM periods after the sequence ends.

source

pub fn start_seq(&self, seq: Seq)

Loads the first PWM value on all enabled channels from a sequence and starts playing that sequence. Causes PWM generation to start if not running.

source

pub fn next_step(&self)

Steps by one value in the current sequence on all enabled channels, if the NextStep step mode is selected. Does not cause PWM generation to start if not running.

source

pub fn stop(&self)

Stops PWM pulse generation on all channels at the end of current PWM period, and stops sequence playback.

source

pub fn load<B0, B1>( self, seq0_buffer: Option<B0>, seq1_buffer: Option<B1>, start: bool ) -> Result<PwmSeq<T, B0, B1>, (Error, Pwm<T>, Option<B0>, Option<B1>)>
where B0: ReadBuffer<Word = u16> + 'static, B1: ReadBuffer<Word = u16> + 'static,

Loads the given sequence buffers and optionally (re-)starts sequence playback. Returns a PemSeq, containing Pwm<T> and the buffers.

source

pub fn enable_interrupt(&self, event: PwmEvent) -> &Pwm<T>

Enables interrupt triggering on the specified event.

source

pub fn disable_interrupt(&self, event: PwmEvent) -> &Pwm<T>

Disables interrupt triggering on the specified event.

source

pub fn is_event_triggered(&self, event: PwmEvent) -> bool

Checks if an event has been triggered.

source

pub fn reset_event(&self, event: PwmEvent)

Marks event as handled.

source

pub fn event_stopped(&self) -> &Reg<EVENTS_STOPPED_SPEC>

Returns reference to Stopped event endpoint for PPI.

source

pub fn event_loops_done(&self) -> &Reg<EVENTS_LOOPSDONE_SPEC>

Returns reference to LoopsDone event endpoint for PPI.

source

pub fn event_pwm_period_end(&self) -> &Reg<EVENTS_PWMPERIODEND_SPEC>

Returns reference to PwmPeriodEnd event endpoint for PPI.

source

pub fn event_seq0_end(&self) -> &Reg<EVENTS_SEQEND_SPEC>

Returns reference to Seq0 End event endpoint for PPI.

source

pub fn event_seq1_end(&self) -> &Reg<EVENTS_SEQEND_SPEC>

Returns reference to Seq1 End event endpoint for PPI.

source

pub fn event_seq0_started(&self) -> &Reg<EVENTS_SEQSTARTED_SPEC>

Returns reference to Seq0 Started event endpoint for PPI.

source

pub fn event_seq1_started(&self) -> &Reg<EVENTS_SEQSTARTED_SPEC>

Returns reference to Seq1 Started event endpoint for PPI.

source

pub fn task_start_seq0(&self) -> &Reg<TASKS_SEQSTART_SPEC>

Returns reference to Seq0 Start task endpoint for PPI.

source

pub fn task_start_seq1(&self) -> &Reg<TASKS_SEQSTART_SPEC>

Returns reference to Seq1 Started task endpoint for PPI.

source

pub fn task_next_step(&self) -> &Reg<TASKS_NEXTSTEP_SPEC>

Returns reference to NextStep task endpoint for PPI.

source

pub fn task_stop(&self) -> &Reg<TASKS_STOP_SPEC>

Returns reference to Stop task endpoint for PPI.

source

pub fn split_channels( &self ) -> (PwmChannel<'_, T>, PwmChannel<'_, T>, PwmChannel<'_, T>, PwmChannel<'_, T>)

Returns individual handles to the four PWM channels.

source

pub fn split_groups(&self) -> (PwmGroup<'_, T>, PwmGroup<'_, T>)

Returns individual handles to the two PWM groups.

source

pub fn free(self) -> (T, Pins)

Consumes self and returns back the raw peripheral.

Trait Implementations§

source§

impl<T> Debug for Pwm<T>
where T: Debug + Instance,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<T> Pwm for Pwm<T>
where T: Instance,

§

type Channel = Channel

Enumeration of channels that can be used with this Pwm interface Read more
§

type Duty = u16

Type for the duty methods Read more
§

type Time = Hertz

A time unit that can be converted into a human time unit (e.g. seconds)
source§

fn enable(&mut self, channel: <Pwm<T> as Pwm>::Channel)

Enables a PWM channel
source§

fn disable(&mut self, channel: <Pwm<T> as Pwm>::Channel)

Disables a PWM channel
source§

fn get_duty(&self, channel: <Pwm<T> as Pwm>::Channel) -> <Pwm<T> as Pwm>::Duty

Returns the current duty cycle
source§

fn set_duty( &mut self, channel: <Pwm<T> as Pwm>::Channel, duty: <Pwm<T> as Pwm>::Duty )

Sets a new duty cycle
source§

fn get_max_duty(&self) -> <Pwm<T> as Pwm>::Duty

Returns the maximum duty cycle value
source§

fn get_period(&self) -> <Pwm<T> as Pwm>::Time

Returns the current PWM period
source§

fn set_period<P>(&mut self, period: P)
where P: Into<<Pwm<T> as Pwm>::Time>,

Sets a new PWM period

Auto Trait Implementations§

§

impl<T> Freeze for Pwm<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Pwm<T>
where T: RefUnwindSafe,

§

impl<T> Send for Pwm<T>
where T: Send,

§

impl<T> Sync for Pwm<T>
where T: Sync,

§

impl<T> Unpin for Pwm<T>
where T: Unpin,

§

impl<T> UnwindSafe for Pwm<T>
where T: 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> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.