Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
Typedefs | Functions
sbl::adc Namespace Reference

Typedefs

using SampleTime = sbl::hal::adc::SampleTime
 
using Resolution = sbl::hal::adc::Resolution
 

Functions

template<typename Driver >
uint16_t read (const AdcHandle &handle, SampleTime sample_time=SampleTime::Medium)
 Blocking single-channel ADC read.
 
template<typename Driver >
uint32_t to_millivolts (uint16_t raw_value, uint32_t vref_mv=3300)
 Convert raw ADC value to voltage (millivolts)
 
template<typename Driver >
void start_scan (const AdcHandle *channels, uint8_t num_channels, uint16_t *buffer, SampleTime sample_time=SampleTime::Slow)
 Start continuous DMA scan of multiple ADC channels.
 
template<typename Driver >
void stop_scan ()
 Stop DMA scan mode.
 

Typedef Documentation

◆ Resolution

Definition at line 56 of file driver.hpp.

◆ SampleTime

Definition at line 55 of file driver.hpp.

Function Documentation

◆ read()

template<typename Driver >
uint16_t sbl::adc::read ( const AdcHandle handle,
SampleTime  sample_time = SampleTime::Medium 
)
inline

Blocking single-channel ADC read.

Convenience function that composes low-level driver primitives. Configures the channel, starts conversion, waits for completion, and returns the raw value.

Template Parameters
DriverADC driver type (e.g., sbl::driver::Adc)
Parameters
handleADC channel handle from hardware config
sample_timeSampling duration (default: Medium)
Returns
Raw ADC value (resolution depends on driver)
Note
Not ISR-safe — polls for conversion complete (busy-wait loop)

Example: auto value = sbl::adc::read<sbl::driver::Adc>(sbl::hw::adc::knob1);

Definition at line 76 of file driver.hpp.

◆ start_scan()

template<typename Driver >
void sbl::adc::start_scan ( const AdcHandle channels,
uint8_t  num_channels,
uint16_t *  buffer,
SampleTime  sample_time = SampleTime::Slow 
)
inline

Start continuous DMA scan of multiple ADC channels.

The ADC scans all channels in sequence with circular DMA, depositing results into buffer[0..num_channels-1]. The CPU reads the buffer at any time for the latest value — no synchronization needed (16-bit aligned reads are atomic on Cortex-M).

Template Parameters
DriverADC driver type (e.g., sbl::driver::Adc)
Parameters
channelsArray of AdcHandle defining the scan sequence
num_channelsNumber of channels to scan (1–16)
bufferDMA-accessible buffer with num_channels elements
sample_timeSampling duration for all channels (default: Slow)
Note
Not ISR-safe — init-time only (configures ADC + DMA hardware)

Definition at line 47 of file scan.hpp.

◆ stop_scan()

template<typename Driver >
void sbl::adc::stop_scan ( )
inline

Stop DMA scan mode.

Stops continuous conversion and disables DMA. After this call, polling functions (read<Driver>()) can be used again.

Template Parameters
DriverADC driver type
Note
Not ISR-safe — tears down DMA and ADC hardware

Definition at line 64 of file scan.hpp.

◆ to_millivolts()

template<typename Driver >
uint32_t sbl::adc::to_millivolts ( uint16_t  raw_value,
uint32_t  vref_mv = 3300 
)
inline

Convert raw ADC value to voltage (millivolts)

Template Parameters
DriverADC driver type for resolution info
Parameters
raw_valueRaw ADC reading
vref_mvReference voltage in millivolts (default: 3300mV)
Returns
Voltage in millivolts
Note
ISR-safe — pure arithmetic, no hardware access

Definition at line 97 of file driver.hpp.