Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ADC self-calibration #233

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ impl Adc<Ready> {
self.precision = precision;
}

/// Trigger internal ADC calibration
///
/// This process is documented in Reference Manual RM377, section 13.3.3
/// Calibration (ADCAL)
pub fn calibrate(&mut self) -> Result<(), Error> {
if self._state != Ready
|| self.rb.cr.read().aden().bit_is_set()
|| self.rb.cfgr1.read().dmaen().bit_is_set()
{
return Err(Error::InvalidAdcState);
}

self.rb.cr.modify(|_, w| w.adcal().set_bit());
while self.rb.cr.read().adcal().bit_is_set() {}
Ok(())
}

/// Starts a continuous conversion process
///
/// The `channel` argument specifies which channel should be converted.
Expand Down Expand Up @@ -321,6 +338,7 @@ where
}

/// Indicates that the ADC peripheral is ready
#[derive(PartialEq)]
pub struct Ready;

/// Indicates that the ADC peripheral is performing conversions
Expand Down Expand Up @@ -615,6 +633,9 @@ pub enum Error {
/// just keeps writing more values. It does mean that some values in the
/// buffer were overwritten though.
BufferOverrun,

/// Invalid ADC state for requested operation
InvalidAdcState,
}

macro_rules! int_adc {
Expand Down
Loading