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 Pot input convenience functions
4 * @ingroup hal
5 *
6 * Composes ADC driver reads with Pot update in a single call.
7 * Same pattern as sbl::cv::read<Driver>() / sbl::cv::read_dma().
8 *
9 * Usage:
10 * #include <sbl/hal/pot/input.hpp>
11 *
12 * sbl::pot::read<sbl::driver::Adc>(knob, handle, SampleTime::Slow);
13 * sbl::pot::read_dma(knob, adc_buf, 0);
14 */
15
16#ifndef SBL_HAL_POT_INPUT_HPP_
17#define SBL_HAL_POT_INPUT_HPP_
18
21
22namespace sbl {
23namespace pot {
24
27
28/**
29 * @brief Read ADC channel and feed into Pot (EWMA + deadband)
30 *
31 * Blocking read followed by Pot::update(). Returns the stable value.
32 *
33 * @tparam Driver ADC driver type (e.g., sbl::driver::Adc)
34 * @param pot Pot instance to update
35 * @param handle ADC channel handle
36 * @param sample_time Sampling duration (default: Slow for pot sources)
37 * @return Stable (deadbanded) value (0-65535)
38 *
39 * @note Not ISR-safe — wraps blocking ADC polling read
40 */
41template<typename Driver>
42inline uint16_t read(Pot& pot, const AdcHandle& handle,
43 adc::SampleTime sample_time = adc::SampleTime::Slow) {
44 uint16_t raw = adc::read<Driver>(handle, sample_time);
45 pot.update(raw);
46 return pot.value();
47}
48
49/**
50 * @brief Read from DMA scan buffer and feed into Pot
51 *
52 * For use with sbl::adc::start_scan(). Casts to volatile to ensure the
53 * compiler generates a real memory read (buffer updated by DMA hardware).
54 *
55 * @param pot Pot instance to update
56 * @param buffer DMA scan buffer (from start_scan)
57 * @param channel_index Index of this channel in the scan sequence
58 * @return Stable (deadbanded) value (0-65535)
59 *
60 * @note ISR-safe — volatile DMA buffer read, no blocking
61 */
62inline uint16_t read_dma(Pot& pot, const uint16_t* buffer,
63 uint8_t channel_index) {
64 auto raw = static_cast<const volatile uint16_t*>(buffer)[channel_index];
65 pot.update(raw);
66 return pot.value();
67}
68
69} // namespace pot
70} // namespace sbl
71
72#endif // SBL_HAL_POT_INPUT_HPP_
Potentiometer with EWMA smoothing, deadband, and change detection.
Definition pot.hpp:50
uint16_t value() const
Current stable (deadbanded) value (0-65535)
Definition pot.hpp:97
void update(uint16_t raw)
Feed a new raw ADC sample through EWMA → deadband check.
Definition pot.hpp:66
ADC driver interface - canonical types for MCU driver implementations.
SampleTime
ADC sample time configuration.
Definition types.hpp:30
uint16_t read_dma(Pot &pot, const uint16_t *buffer, uint8_t channel_index)
Read from DMA scan buffer and feed into Pot.
Definition input.hpp:62
uint16_t read(Pot &pot, const AdcHandle &handle, adc::SampleTime sample_time=adc::SampleTime::Slow)
Read ADC channel and feed into Pot (EWMA + deadband)
Definition input.hpp:42
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
Potentiometer component — smoothed ADC with deadband + change detection.
ADC channel handle.
Definition handle.hpp:29