Skip to content

rp2040_adc

RP2040’s single 12-bit SAR ADC.

GPIO 26 through 29 are channels 0 through 3. Channel 4 is the internal temperature sensor. One [Rp2040Adc] owns the shared converter and claims external GPIOs as they are first used.

struct Rp2040Adc { /* private fields */ }

Exclusive owner of the shared RP2040 ADC.

Implements: Drop

enum AdcError {
Timeout,
Conversion,
PinInUse,
}

A conversion failure distinguishable from ownership errors.

Implements: Clone, Copy, Debug, Eq, From, PartialEq, StructuralPartialEq

enum Channel {
Gpio26,
Gpio27,
Gpio28,
Gpio29,
Temperature,
}

One of the RP2040 ADC inputs.

Implements: Clone, Copy, Debug, Eq, PartialEq, StructuralPartialEq

const fn raw_to_microvolts(raw: u16) -> u32

Convert a raw count to microvolts using the nominal 3.3 V reference.

This is appropriate for the temperature formula and diagnostics. It is not calibrated voltage metrology: the reference and ADC both vary by device.

const fn temperature_milli_celsius(raw: u16) -> i32

Convert the internal sensor’s raw count to nominal milli-degrees Celsius.

Formula and typical constants are from the RP2040 datasheet. The sensor is not factory calibrated, so callers must treat this as an approximate chip temperature rather than an ambient-temperature measurement.