Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
scan.hpp
Go to the documentation of this file.
1/**
2 * @file scan.hpp
3 * @brief ADC DMA scan interface — continuous multi-channel acquisition
4 * @ingroup hal
5 *
6 * Platform-agnostic interface for DMA-based ADC scanning. The driver
7 * handles all DMA configuration internally; the HAL just forwards calls.
8 *
9 * Usage:
10 * #include <sbl/hal/adc/scan.hpp>
11 *
12 * SBL_DMA_BUFFER static volatile uint16_t adc_buf[2];
13 * const sbl::AdcHandle channels[] = { sbl::hw::adc::knob1, sbl::hw::adc::knob2 };
14 * sbl::adc::start_scan<sbl::driver::Adc>(channels, 2, adc_buf);
15 *
16 * // Main loop: just read adc_buf[0], adc_buf[1] — always fresh
17 */
18
19#ifndef SBL_HAL_ADC_SCAN_HPP_
20#define SBL_HAL_ADC_SCAN_HPP_
21
22#include "handle.hpp"
23#include "types.hpp"
24
25namespace sbl {
26namespace adc {
27
29
30/**
31 * @brief Start continuous DMA scan of multiple ADC channels
32 *
33 * The ADC scans all channels in sequence with circular DMA, depositing
34 * results into buffer[0..num_channels-1]. The CPU reads the buffer at
35 * any time for the latest value — no synchronization needed (16-bit
36 * aligned reads are atomic on Cortex-M).
37 *
38 * @tparam Driver ADC driver type (e.g., sbl::driver::Adc)
39 * @param channels Array of AdcHandle defining the scan sequence
40 * @param num_channels Number of channels to scan (1–16)
41 * @param buffer DMA-accessible buffer with num_channels elements
42 * @param sample_time Sampling duration for all channels (default: Slow)
43 *
44 * @note Not ISR-safe — init-time only (configures ADC + DMA hardware)
45 */
46template<typename Driver>
47inline void start_scan(const AdcHandle* channels, uint8_t num_channels,
48 uint16_t* buffer,
49 SampleTime sample_time = SampleTime::Slow) {
50 Driver::start_dma_scan(channels, num_channels, buffer, sample_time);
51}
52
53/**
54 * @brief Stop DMA scan mode
55 *
56 * Stops continuous conversion and disables DMA. After this call,
57 * polling functions (read<Driver>()) can be used again.
58 *
59 * @tparam Driver ADC driver type
60 *
61 * @note Not ISR-safe — tears down DMA and ADC hardware
62 */
63template<typename Driver>
64inline void stop_scan() {
65 Driver::stop_dma_scan();
66}
67
68} // namespace adc
69} // namespace sbl
70
71#endif // SBL_HAL_ADC_SCAN_HPP_
void stop_scan()
Stop DMA scan mode.
Definition scan.hpp:64
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.
Definition scan.hpp:47
sbl::hal::adc::SampleTime SampleTime
Definition driver.hpp:55
SampleTime
ADC sample time configuration.
Definition types.hpp:30
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
ADC channel handle.
Definition handle.hpp:29
Common types for SBL hardware abstraction.
UART handle type for hardware abstraction.