pub struct Adc<'a, M: ModeAdc> { /* private fields */ }Expand description
ADC driver instance.
Implementations§
Source§impl<'a> Adc<'a, Blocking>
impl<'a> Adc<'a, Blocking>
Sourcepub fn new_blocking<I: Instance>(
_inst: Peri<'a, I>,
pin: Peri<'a, impl AdcPin<I>>,
config: LpadcConfig,
) -> Result<Self>
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 instancepin- GPIO pin to use for ADCconfig- ADC configuration
Sourcepub fn enable_interrupt(&mut self, mask: u32)
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
Sourcepub fn disable_interrupt(&mut self, mask: u32)
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
pub fn set_fifo_watermark(&mut self, watermark: u8) -> Result<()>
Sourcepub fn do_software_trigger(&self, trigger_id_mask: u8) -> Result<()>
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 validErr(Error::InvalidConfig)if the mask was greater than0b1111
Sourcepub fn set_conv_command_config(
&self,
index: usize,
config: &ConvCommandConfig,
) -> Result<()>
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 successfullyErr(Error::InvalidConfig)if the index is out of range
Sourcepub fn set_conv_trigger_config(
&self,
trigger_id: usize,
config: &ConvTriggerConfig,
) -> Result<()>
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
Sourcepub fn do_reset_fifo(&self)
pub fn do_reset_fifo(&self)
Reset the FIFO buffer.
Clears all pending conversion results from the FIFO.
Sourcepub fn get_conv_result(&self) -> Result<ConvResult>
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 availableErr(Error::FifoEmpty)if the FIFO is empty
Source§impl<'a> Adc<'a, Async>
impl<'a> Adc<'a, Async>
Sourcepub 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>
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 instancepin- GPIO pin to use for ADC_irq- Interrupt binding for this ADC instanceconfig- ADC configuration
Sourcepub fn set_averages(&mut self, avgs: Avgs)
pub fn set_averages(&mut self, avgs: Avgs)
Set the number of averages
Sourcepub fn set_sample_time(&mut self, st: Sts)
pub fn set_sample_time(&mut self, st: Sts)
Set the sample time
pub fn set_resolution(&mut self, mode: Mode)
Sourcepub async fn read(&mut self) -> Result<u16>
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:
- Enables the FIFO watermark interrupt
- Triggers a software conversion on trigger 0
- Waits for the conversion to complete
- Returns the conversion result
§Returns
16-bit ADC conversion value
Source§impl<'a, M: ModeAdc> Adc<'a, M>
impl<'a, M: ModeAdc> Adc<'a, M>
Sourcepub fn do_offset_calibration(&self)
pub fn do_offset_calibration(&self)
Perform offset calibration. Waits for calibration to complete before returning.
Sourcepub fn get_gain_conv_result(&self, gain_adjustment: f32) -> u32
pub fn get_gain_conv_result(&self, gain_adjustment: f32) -> u32
Sourcepub fn do_auto_calibration(&self)
pub fn do_auto_calibration(&self)
Perform automatic gain calibration.