Sound Byte Libs 1ee2ca6
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
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 * ## Validation Usage
21 *
22 * Add validation at the bottom of driver adc.hpp:
23 * ```cpp
24 * #include <sbl/validation/adc_requirements.hpp>
25 * static_assert(sbl::validation::adc_driver_valid<sbl::driver::Adc>,
26 * "ADC driver missing required methods");
27 * ```
28 *
29 * @see method_detection.hpp
30 */
31
32#ifndef SBL_VALIDATION_ADC_REQUIREMENTS_HPP_
33#define SBL_VALIDATION_ADC_REQUIREMENTS_HPP_
34
35#include "method_detection.hpp"
36
37namespace sbl {
38namespace validation {
39
40/**
41 * @brief ADC driver requirements validator
42 *
43 * Validates that ADC drivers provide all required methods.
44 */
45template<typename AdcDriver>
47public:
48 /**
49 * @brief Validate all required ADC methods
50 */
51 static constexpr bool validate() {
53 "SBL ERROR: ADC driver missing init() method.\n"
54 "Required: static void init()");
55
57 "SBL ERROR: ADC driver missing configure_channel() method.\n"
58 "Required: static void configure_channel(const AdcHandle&, SampleTime)");
59
61 "SBL ERROR: ADC driver missing start_conversion() method.\n"
62 "Required: static void start_conversion(const AdcHandle&)");
63
65 "SBL ERROR: ADC driver missing is_conversion_complete() method.\n"
66 "Required: static bool is_conversion_complete()");
67
69 "SBL ERROR: ADC driver missing read_raw() method.\n"
70 "Required: static uint16_t read_raw()");
71
73 "SBL ERROR: ADC driver missing resolution_bits() method.\n"
74 "Required: static constexpr uint8_t resolution_bits()");
75
76 return true;
77 }
78};
79
80/**
81 * @brief Helper to validate an ADC driver implementation
82 *
83 * Usage:
84 * ```cpp
85 * static_assert(sbl::validation::adc_driver_valid<MyAdcDriver>,
86 * "ADC driver incomplete");
87 * ```
88 */
89template<typename AdcDriver>
91
92} // namespace validation
93} // namespace sbl
94
95#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.