Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
input.hpp
Go to the documentation of this file.
1/**
2 * @file input.hpp
3 * @brief CV input convenience functions
4 * @ingroup hal
5 *
6 * Composes ADC driver reads with CvInput update in a single call.
7 * Mirrors the sbl::adc::read<Driver>() pattern.
8 *
9 * Usage:
10 * #include <sbl/hal/cv/input.hpp>
11 *
12 * sbl::cv::read<sbl::driver::Adc>(knob, handle, SampleTime::Slow);
13 */
14
15#ifndef SBL_HAL_CV_INPUT_HPP_
16#define SBL_HAL_CV_INPUT_HPP_
17
20
21namespace sbl {
22namespace cv {
23
27
28/**
29 * @brief Read ADC channel and feed into CvInput filter
30 *
31 * Blocking read followed by CvInput::update(). Returns the smoothed value.
32 *
33 * @tparam Driver ADC driver type (e.g., sbl::driver::Adc)
34 * @param input CvInput instance to update
35 * @param handle ADC channel handle
36 * @param sample_time Sampling duration (default: Slow for pot sources)
37 * @return Smoothed value (0–65535)
38 *
39 * @note Not ISR-safe — wraps blocking ADC polling read
40 */
41template<typename Driver>
42inline uint16_t read(CvInput& input, const AdcHandle& handle,
43 adc::SampleTime sample_time = adc::SampleTime::Slow) {
44 uint16_t raw = adc::read<Driver>(handle, sample_time);
45 input.update(raw);
46 return input.value();
47}
48
49/**
50 * @brief Read from DMA scan buffer and feed into CvInput filter
51 *
52 * For use with sbl::adc::start_scan(). The DMA buffer is the abstraction
53 * boundary — no driver template needed. Casts to volatile to ensure the
54 * compiler generates a real memory read (buffer is updated by DMA hardware).
55 *
56 * @param input CvInput instance to update
57 * @param buffer DMA scan buffer (from start_scan)
58 * @param channel_index Index of this channel in the scan sequence
59 * @return Smoothed value (0–65535)
60 *
61 * @note ISR-safe — volatile DMA buffer read, no blocking
62 */
63inline uint16_t read_dma(CvInput& input, const uint16_t* buffer,
64 uint8_t channel_index) {
65 // Volatile cast forces a real memory read — DMA updates this asynchronously
66 auto raw = static_cast<const volatile uint16_t*>(buffer)[channel_index];
67 input.update(raw);
68 return input.value();
69}
70
71} // namespace cv
72} // namespace sbl
73
74#endif // SBL_HAL_CV_INPUT_HPP_
Smoothed CV input with EWMA filtering and range scaling.
Definition input.hpp:51
uint16_t value() const
Current smoothed value (0–65535)
Definition input.hpp:69
void update(uint16_t raw)
Feed a new raw ADC sample.
Definition input.hpp:60
CV Input component — smoothed ADC reading with range scaling.
ADC driver interface - canonical types for MCU driver implementations.
Smoothing
Smoothing presets for CvInput EWMA filter.
Definition input.hpp:35
uint16_t read_dma(CvInput &input, const uint16_t *buffer, uint8_t channel_index)
Read from DMA scan buffer and feed into CvInput filter.
Definition input.hpp:63
uint16_t read(CvInput &input, const AdcHandle &handle, adc::SampleTime sample_time=adc::SampleTime::Slow)
Read ADC channel and feed into CvInput filter.
Definition input.hpp:42
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