Sound Byte Libs 0.5.1-340-gab5b79a
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 * @code
11 * #include <sbl/hw/hal/adc/scan.hpp>
12 *
13 * SBL_DMA_BUFFER static uint16_t adc_buf[2];
14 * const sbl::AdcHandle channels[] = { sbl::hw::adc::knob1, sbl::hw::adc::knob2 };
15 * sbl::adc::start_scan<sbl::driver::Adc>(channels, 2, adc_buf);
16 *
17 * // Main loop: read each slot through a volatile access, as
18 * // Pot::update_dma() does
19 * knob1.update_dma(adc_buf, 0);
20 * knob2.update_dma(adc_buf, 1);
21 * @endcode
22 *
23 * start_scan() takes a plain uint16_t*. The DMA writes the buffer behind
24 * the compiler's back, so the reader is responsible for volatile access.
25 */
26
27#ifndef SBL_HW_HAL_ADC_SCAN_HPP_
28#define SBL_HW_HAL_ADC_SCAN_HPP_
29
30#include "handle.hpp"
31#include "types.hpp"
32
33namespace sbl {
34namespace adc {
35
37
38/**
39 * @brief Start continuous DMA scan of multiple ADC channels
40 *
41 * The ADC scans all channels in sequence with circular DMA, depositing
42 * results into buffer[0..num_channels-1]. The CPU reads the buffer at
43 * any time for the latest value - no synchronization needed (16-bit
44 * aligned reads are atomic on Cortex-M).
45 *
46 * @tparam Driver ADC driver type (e.g., sbl::driver::Adc)
47 * @param channels Array of AdcHandle defining the scan sequence
48 * @param num_channels Number of channels to scan (1-16)
49 * @param buffer DMA-accessible buffer with num_channels elements
50 * @param sample_time Sampling duration for all channels (default: Slow)
51 *
52 * @context Not ISR-safe: init-time only (configures ADC + DMA hardware)
53 */
54template<typename Driver>
55inline void start_scan(const AdcHandle* channels, uint8_t num_channels, uint16_t* buffer,
56 SampleTime sample_time = SampleTime::Slow) {
57 Driver::start_dma_scan(channels, num_channels, buffer, sample_time);
58}
59
60/**
61 * @brief Start continuous DMA scan with per-channel sample times
62 *
63 * Allows different sample times per channel - use SampleTime::Slow for
64 * high-impedance pot sources and SampleTime::Medium or Fast for buffered
65 * CV jack inputs.
66 *
67 * @tparam Driver ADC driver type (e.g., sbl::driver::Adc)
68 * @param channels Array of AdcHandle defining the scan sequence
69 * @param num_channels Number of channels to scan (1-16)
70 * @param buffer DMA-accessible buffer with num_channels elements
71 * @param sample_times Per-channel sampling durations (array of num_channels)
72 *
73 * @context Not ISR-safe: init-time only (configures ADC + DMA hardware)
74 */
75template<typename Driver>
76inline void start_scan(const AdcHandle* channels, uint8_t num_channels, uint16_t* buffer,
77 const SampleTime* sample_times) {
78 Driver::start_dma_scan(channels, num_channels, buffer, sample_times);
79}
80
81/**
82 * @brief Stop DMA scan mode
83 *
84 * Stops continuous conversion and disables DMA. After this call,
85 * polling functions (read<Driver>()) can be used again.
86 *
87 * @tparam Driver ADC driver type
88 *
89 * @context Not ISR-safe: tears down DMA and ADC hardware
90 */
91template<typename Driver>
92inline void stop_scan() {
93 Driver::stop_dma_scan();
94}
95
96} // namespace adc
97} // namespace sbl
98
99#endif // SBL_HW_HAL_ADC_SCAN_HPP_
void stop_scan()
Stop DMA scan mode.
Definition scan.hpp:92
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:55
SampleTime
ADC sample time configuration.
Definition types.hpp:32
Root namespace for all Sound Byte Libs code.
MIDI message types.
ADC channel handle.
Definition handle.hpp:26
UART handle type for hardware abstraction.