Sound Byte Libs 0.5.1-121-g3358a44
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/hw/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_HW_HAL_ADC_SCAN_HPP_
20#define SBL_HW_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 Start continuous DMA scan with per-channel sample times
55 *
56 * Allows different sample times per channel — use SampleTime::Slow for
57 * high-impedance pot sources and SampleTime::Medium or Fast for buffered
58 * CV jack inputs.
59 *
60 * @tparam Driver ADC driver type (e.g., sbl::driver::Adc)
61 * @param channels Array of AdcHandle defining the scan sequence
62 * @param num_channels Number of channels to scan (1–16)
63 * @param buffer DMA-accessible buffer with num_channels elements
64 * @param sample_times Per-channel sampling durations (array of num_channels)
65 *
66 * @note Not ISR-safe — init-time only (configures ADC + DMA hardware)
67 */
68template<typename Driver>
69inline void start_scan(const AdcHandle* channels, uint8_t num_channels,
70 uint16_t* buffer,
71 const SampleTime* sample_times) {
72 Driver::start_dma_scan(channels, num_channels, buffer, sample_times);
73}
74
75/**
76 * @brief Stop DMA scan mode
77 *
78 * Stops continuous conversion and disables DMA. After this call,
79 * polling functions (read<Driver>()) can be used again.
80 *
81 * @tparam Driver ADC driver type
82 *
83 * @note Not ISR-safe — tears down DMA and ADC hardware
84 */
85template<typename Driver>
86inline void stop_scan() {
87 Driver::stop_dma_scan();
88}
89
90} // namespace adc
91} // namespace sbl
92
93#endif // SBL_HW_HAL_ADC_SCAN_HPP_
void stop_scan()
Stop DMA scan mode.
Definition scan.hpp:86
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 code.
Definition assert.hpp:51
ADC channel handle.
Definition handle.hpp:29
Common types for SBL hardware abstraction.
UART handle type for hardware abstraction.