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
adc_requirements.hpp
Go to the documentation of this file.
1/**
2 * @file adc_requirements.hpp
3 * @brief ADC driver requirements validator
4 * @ingroup validation
5 *
6 * Validates that ADC drivers provide required functionality using the
7 * method detection system. This is the core ADC contract enforcement
8 * for Sound Byte Libs drivers.
9 *
10 * ## ADC Driver Contract
11 *
12 * Every Sound Byte Libs ADC driver MUST implement these methods:
13 * - `init()` - Initialize ADC peripheral (returns void or bool)
14 * - `configure_channel(const AdcHandle&, SampleTime)` - Configure channel
15 * - `start_conversion(const AdcHandle&)` - Start single conversion
16 * - `is_conversion_complete() -> bool` - Check if conversion done
17 * - `read_raw() -> uint16_t` - Read conversion result
18 * - `resolution_bits() -> uint8_t` - Get ADC resolution (constexpr)
19 *
20 * Optional methods (validated if present):
21 * - `start_dma_scan(const AdcHandle*, uint8_t, uint16_t*, SampleTime)` - DMA scan
22 * - `stop_dma_scan()` - Stop DMA scan
23 *
24 * ## Validation Usage
25 *
26 * Add validation at the bottom of driver adc.hpp:
27 * ```cpp
28 * #include <sbl/hw/validation/adc_requirements.hpp>
29 * static_assert(sbl::validation::adc_driver_valid<sbl::driver::Adc>,
30 * "ADC driver missing required methods");
31 * ```
32 *
33 * @see method_detection.hpp
34 */
35
36#ifndef SBL_HW_VALIDATION_ADC_REQUIREMENTS_HPP_
37#define SBL_HW_VALIDATION_ADC_REQUIREMENTS_HPP_
38
39#include "method_detection.hpp"
40
41namespace sbl {
42namespace validation {
43
44/**
45 * @brief ADC driver requirements validator
46 *
47 * Validates that ADC drivers provide all required methods.
48 */
49template<typename AdcDriver>
51public:
52 /**
53 * @brief Validate all required ADC methods
54 */
55 static constexpr bool validate() {
56 // Required methods
57
58 static_assert(has_adc_init<AdcDriver>::value, "SBL ERROR: ADC driver missing init() method.\n"
59 "Required: static bool init()");
60
62 "SBL ERROR: ADC driver missing configure_channel() method.\n"
63 "Required: static void configure_channel(const AdcHandle&, SampleTime)");
64
66 "SBL ERROR: ADC driver missing start_conversion() method.\n"
67 "Required: static void start_conversion(const AdcHandle&)");
68
70 "SBL ERROR: ADC driver missing is_conversion_complete() method.\n"
71 "Required: static bool is_conversion_complete()");
72
73 static_assert(has_adc_read_raw<AdcDriver>::value, "SBL ERROR: ADC driver missing read_raw() method.\n"
74 "Required: static uint16_t read_raw()");
75
77 "SBL ERROR: ADC driver missing resolution_bits() method.\n"
78 "Required: static constexpr uint8_t resolution_bits()");
79
80 // Optional methods (validated if present)
81 // If start_dma_scan is present, stop_dma_scan must be too.
82
84 "SBL ERROR: ADC provides start_dma_scan() but not stop_dma_scan().\n"
85 "Both must be present for DMA scan support.");
86
87 return true;
88 }
89};
90
91/**
92 * @brief Helper to validate an ADC driver implementation
93 *
94 * Usage:
95 * ```cpp
96 * static_assert(sbl::validation::adc_driver_valid<MyAdcDriver>,
97 * "ADC driver incomplete");
98 * ```
99 */
100template<typename AdcDriver>
102
103} // namespace validation
104} // namespace sbl
105
106#endif // SBL_HW_VALIDATION_ADC_REQUIREMENTS_HPP_
ADC driver requirements validator.
static constexpr bool validate()
Validate all required ADC methods.
Method and interface detection for driver validation.
constexpr bool adc_driver_valid
Helper to validate an ADC driver implementation.
Root namespace for all Sound Byte Libs code.
True if T::configure_channel(const AdcHandle&, SampleTime) is a valid static call.
True if T::init() is a valid static call.
True if T::is_conversion_complete() is a valid static call.
True if T::read_raw() is a valid static call.
True if T::resolution_bits() is a valid static call.
True if T::start_conversion(const AdcHandle&) is a valid static call.
True if T::start_dma_scan(const AdcHandle*, uint8_t, uint16_t*, SampleTime) is a valid static call (o...
True if T::stop_dma_scan() is a valid static call (optional)