Library guide · API index and notation
This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.
import "std/embedded/chip/esp_adc"
Names used in signatures
Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.
| Alias | Package | Source file |
|---|---|---|
esp_gdma |
std/embedded/chip/esp_gdma |
esp_adc.dodo |
hal |
std/embedded/hal |
esp_adc.dodo |
APB_SARADC_BASE
Constant · Source
pub const APB_SARADC_BASE: usize = 0x6000_E000
CLOCK_DIVIDER
Constant · Source
The PCR divider of the 40 MHz crystal that clocks the controller, and the timer’s rate.
pub const CLOCK_DIVIDER: u32 = 16
TIMER_HZ
Constant · Source
pub const TIMER_HZ: u32 = 1_250_000
MIN_RATE_HZ
Constant · Source
pub const MIN_RATE_HZ: u32 = 306
MAX_RATE_HZ
Constant · Source
pub const MAX_RATE_HZ: u32 = 83_333
MAX_CHANNELS
Constant · Source
Pattern table entries, and GPIO 0 to 6 as ADC1 channels 0 to 6.
pub const MAX_CHANNELS: usize = 8
ADC_CHANNELS
Constant · Source
pub const ADC_CHANNELS: u32 = 7
Attenuation
Enum · Source
The analog front end’s attenuation of an input: the larger, the higher the voltage it reads, from about 0.95 V at 0 dB to about 3.3 V at 12 dB.
pub enum Attenuation {
Db0,
Db2p5,
Db6,
Db12
}
attenuation_code
Function · Source
The attenuation’s code, 0 to 3, as the converter and eFuse number them.
pub fn attenuation_code(attenuation: &Attenuation) -> u32
Channel
Struct · Source
One entry of a stream’s pattern: an input, GPIO 0 to 6, and its attenuation.
pub struct Channel {
pub pin: u32
pub attenuation: Attenuation
}
Calibration
Struct · Source
The converter’s calibration, from the chip’s eFuse, per attenuation code: the initial code that cancels its offset, and a reference point (a reading and the millivolts that gave it); and per channel the offset from the others at 0 dB, which shrinks with attenuation.
schemeis 0 for a chip without calibration data, where millivolts are only roughly right.
pub struct Calibration {
pub scheme: u32
pub init_code: [4]u32
pub reference_mv: [4]u32
pub reference_code: [4]u32
pub channel_offset: [7]i32
}
Calibration.none
Function · Source
No calibration data.
pub fn none() -> Calibration
Calibration.millivolts
Function · Source
The millivolts a reading
rawofchannelat attenuation codeattenuationstands for: the reading less the channel’s offset, scaled by the reference point, as Espressif’s drivers compute it.
pub fn millivolts(&self, channel: u32, attenuation: u32, raw: u32) -> u16
sample_millivolts
Function · Source
The parts of a sample word.
pub fn sample_millivolts(sample: u32) -> u16
sample_channel
Function · Source
pub fn sample_channel(sample: u32) -> u32
sample_raw
Function · Source
pub fn sample_raw(sample: u32) -> u16
result_raw
Function · Source
The conversion a result word in memory holds: the reading, the channel, and whether it is an ADC1 conversion of one of its channels.
pub fn result_raw(word: u32) -> u32
result_channel
Function · Source
pub fn result_channel(word: u32) -> u32
result_valid
Function · Source
pub fn result_valid(word: u32) -> bool
timer_target
Function · Source
The timer target for
rate_hzconversions a second; InvalidInput out of range.
pub fn timer_target(rate_hz: u32) -> u32!hal.Error
Stream
Struct · Source
A running continuous conversion; see above.
pub struct Stream<R: hal.Registers> {
// Private implementation fields omitted.
}
Stream.start
Function · Source
Convert
channelsin turn,rate_hzconversions a second in all, intobufferthrough GDMA channeldmawith descriptorsdescriptors(3 words per part), calibrating withcalibration. The caller owns the converter, has powered it, set its clock (the crystal divided by CLOCK_DIVIDER), and loaded the initial code, owns the channel, and has checked that the buffer is in SRAM. InvalidInput for no channels or more than MAX_CHANNELS, a pin other than GPIO 0 to 6 or the same pin twice, a rate out of range, or a buffer too short for a sample in each part.
pub fn start(bus: R, channels: &[Channel], rate_hz: u32, dma: u32, descriptors: &mut[u32], buffer: &mut[u8], calibration: Calibration) -> Stream<R>!hal.Error from(descriptors, buffer)
Stream.rate_hz
Function · Source
The conversions a second the timer gives, in all channels.
pub fn rate_hz(&self) -> u32
Stream.channels
Function · Source
The entries in the pattern.
pub fn channels(&self) -> u32
Stream.capacity
Function · Source
The samples the ring holds when full.
pub fn capacity(&self) -> usize
Stream.part_samples
Function · Source
Samples per part: they become readable this many at a time.
pub fn part_samples(&self) -> usize
Stream.available
Function · Source
The samples converted and readable now.
pub fn available(&mut self) -> usize
Stream.poll_read
Function · Source
The samples converted since the last call, oldest first, as many as fit
samples, without waiting; returns how many. Overrun once after the ring filled up: the conversions after the last sample read were lost, and the stream starts again.
pub fn poll_read(&mut self, samples: &mut[u32]) -> usize!hal.Error
Stream.read
Function · Source
Wait until
samplesis full. Overrun as for poll_read, with the samples read before it dropped.
pub fn read(&mut self, samples: &mut[u32]) -> void!hal.Error
Stream.stop
Function · Source
Stop converting and streaming, and put the controller’s settings back, the converter’s power no longer forced. Dropping the stream does this too.
pub fn stop(&mut self)