embassy-mcxa

Crates

git

Versions

mcx-a256

Flavors

Adc

Struct Adc 

Source
pub struct Adc<'a, M: ModeAdc> { /* private fields */ }
Expand description

ADC driver instance.

Implementations§

Source§

impl<'a> Adc<'a, Blocking>

Source

pub fn new_blocking<I: Instance>( _inst: Peri<'a, I>, pin: Peri<'a, impl AdcPin<I>>, config: LpadcConfig, ) -> Result<Self>

Create a new blocking instance of the ADC driver.

§Arguments
  • _inst - ADC peripheral instance
  • pin - GPIO pin to use for ADC
  • config - ADC configuration
Source

pub fn enable_interrupt(&mut self, mask: u32)

Enable ADC interrupts.

Enables the interrupt sources specified in the bitmask.

§Arguments
  • mask - Bitmask of interrupt sources to enable
Source

pub fn disable_interrupt(&mut self, mask: u32)

Disable ADC interrupts.

Disables the interrupt sources specified in the bitmask.

§Arguments
  • mask - Bitmask of interrupt sources to disable
Source

pub fn set_fifo_watermark(&mut self, watermark: u8) -> Result<()>

Source

pub fn do_software_trigger(&self, trigger_id_mask: u8) -> Result<()>

Trigger ADC conversion(s) via software.

Initiates conversion(s) for the trigger(s) specified in the bitmask. Each bit in the mask corresponds to a trigger ID (bit 0 = trigger 0, etc.).

§Arguments
  • trigger_id_mask - Bitmask of trigger IDs to activate (bit N = trigger N)
§Returns
  • Ok(()) if the triger mask was valid
  • Err(Error::InvalidConfig) if the mask was greater than 0b1111
Source

pub fn set_conv_command_config( &self, index: usize, config: &ConvCommandConfig, ) -> Result<()>

Set conversion command configuration.

Configures a conversion command slot with the specified parameters. Commands define how conversions are performed (channel, resolution, etc.).

§Arguments
  • index - Command index (Must be in range 1..=7)
  • config - Command configuration
§Returns
  • Ok(()) if the command was configured successfully
  • Err(Error::InvalidConfig) if the index is out of range
Source

pub fn set_conv_trigger_config( &self, trigger_id: usize, config: &ConvTriggerConfig, ) -> Result<()>

Set conversion trigger configuration.

Configures a trigger to initiate conversions. Triggers can be activated by software or hardware signals.

§Arguments
  • trigger_id - Trigger index (0..=3)
  • config - Trigger configuration
Source

pub fn do_reset_fifo(&self)

Reset the FIFO buffer.

Clears all pending conversion results from the FIFO.

Source

pub fn get_conv_result(&self) -> Result<ConvResult>

Get conversion result from FIFO.

Reads and returns the next conversion result from the FIFO. Returns None if the FIFO is empty.

§Returns
  • Some(ConvResult) if a result is available
  • Err(Error::FifoEmpty) if the FIFO is empty
Source§

impl<'a> Adc<'a, Async>

Source

pub fn new_async<I: Instance>( _inst: Peri<'a, I>, pin: Peri<'a, impl AdcPin<I>>, _irq: impl Binding<I::Interrupt, InterruptHandler<I>> + 'a, config: LpadcConfig, ) -> Result<Self>

Initialize ADC with interrupt support.

§Arguments
  • _inst - ADC peripheral instance
  • pin - GPIO pin to use for ADC
  • _irq - Interrupt binding for this ADC instance
  • config - ADC configuration
Source

pub fn set_averages(&mut self, avgs: Avgs)

Set the number of averages

Source

pub fn set_sample_time(&mut self, st: Sts)

Set the sample time

Source

pub fn set_resolution(&mut self, mode: Mode)

Source

pub async fn read(&mut self) -> Result<u16>

Read ADC value asynchronously.

Performs a single ADC conversion and returns the result when the ADC interrupt is triggered.

The function:

  1. Enables the FIFO watermark interrupt
  2. Triggers a software conversion on trigger 0
  3. Waits for the conversion to complete
  4. Returns the conversion result
§Returns

16-bit ADC conversion value

Source§

impl<'a, M: ModeAdc> Adc<'a, M>

Source

pub fn do_offset_calibration(&self)

Perform offset calibration. Waits for calibration to complete before returning.

Source

pub fn get_gain_conv_result(&self, gain_adjustment: f32) -> u32

Calculate gain conversion result from gain adjustment factor.

§Arguments
  • gain_adjustment - Gain adjustment factor
§Returns

Gain calibration register value

Source

pub fn do_auto_calibration(&self)

Perform automatic gain calibration.

Auto Trait Implementations§

§

impl<'a, M> Freeze for Adc<'a, M>
where M: Freeze,

§

impl<'a, M> !RefUnwindSafe for Adc<'a, M>

§

impl<'a, M> !Send for Adc<'a, M>

§

impl<'a, M> !Sync for Adc<'a, M>

§

impl<'a, M> Unpin for Adc<'a, M>
where M: Unpin,

§

impl<'a, M> !UnwindSafe for Adc<'a, M>

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 = 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>,

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.