Sound Byte Libs 29c5ff3
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() -> bool` - Initialize ADC peripheral
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/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_VALIDATION_ADC_REQUIREMENTS_HPP_
37#define SBL_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
59 "SBL ERROR: ADC driver missing init() method.\n"
60 "Required: static bool init()");
61
63 "SBL ERROR: ADC driver missing configure_channel() method.\n"
64 "Required: static void configure_channel(const AdcHandle&, SampleTime)");
65
67 "SBL ERROR: ADC driver missing start_conversion() method.\n"
68 "Required: static void start_conversion(const AdcHandle&)");
69
71 "SBL ERROR: ADC driver missing is_conversion_complete() method.\n"
72 "Required: static bool is_conversion_complete()");
73
75 "SBL ERROR: ADC driver missing read_raw() method.\n"
76 "Required: static uint16_t read_raw()");
77
79 "SBL ERROR: ADC driver missing resolution_bits() method.\n"
80 "Required: static constexpr uint8_t resolution_bits()");
81
82 // --- Optional methods (validated if present) ---
83 // DMA scan is platform-specific (STM32H7 only currently).
84 // If start_dma_scan is present, stop_dma_scan should be too.
85
86 static_assert(
89 "SBL ERROR: ADC provides start_dma_scan() but not stop_dma_scan().\n"
90 "Both must be present for DMA scan support.");
91
92 return true;
93 }
94};
95
96/**
97 * @brief Helper to validate an ADC driver implementation
98 *
99 * Usage:
100 * ```cpp
101 * static_assert(sbl::validation::adc_driver_valid<MyAdcDriver>,
102 * "ADC driver incomplete");
103 * ```
104 */
105template<typename AdcDriver>
107
108} // namespace validation
109} // namespace sbl
110
111#endif // SBL_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 functionality.
Definition aliases.hpp:24
ADC Driver Method Detection.