Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
gpio_requirements.hpp
Go to the documentation of this file.
1/**
2 * @file gpio_requirements.hpp
3 * @brief GPIO driver requirements validator
4 * @ingroup validation
5 *
6 * Validates that GPIO drivers provide required functionality using the
7 * method detection system. This is the core GPIO contract enforcement
8 * for Sound Byte Libs drivers.
9 *
10 * ## GPIO Driver Contract
11 *
12 * Every Sound Byte Libs GPIO driver MUST implement these methods:
13 * - `set_mode(const GpioHandle&, PinMode)` - Configure pin mode
14 * - `write(const GpioHandle&, bool)` - Write logical value (handles active_low)
15 * - `read(const GpioHandle&) -> bool` - Read logical value (handles active_low)
16 * - `toggle(const GpioHandle&)` - Toggle pin output
17 *
18 * ## Validation Usage
19 *
20 * Add validation at the bottom of driver gpio.hpp:
21 * ```cpp
22 * #include <sbl/validation/gpio_requirements.hpp>
23 * static_assert(sbl::validation::gpio_driver_valid<sbl::driver::Gpio>,
24 * "GPIO driver missing required methods");
25 * ```
26 *
27 * @see method_detection.hpp
28 */
29
30#ifndef SBL_VALIDATION_GPIO_REQUIREMENTS_HPP_
31#define SBL_VALIDATION_GPIO_REQUIREMENTS_HPP_
32
33#include "method_detection.hpp"
34
35namespace sbl {
36namespace validation {
37
38/**
39 * @brief GPIO driver requirements validator
40 *
41 * Validates that GPIO drivers provide all required handle-first methods.
42 */
43template<typename GpioDriver>
45public:
46 /**
47 * @brief Validate all required GPIO methods
48 */
49 static constexpr bool validate() {
51 "SBL ERROR: GPIO driver missing set_mode() method.\n"
52 "Required: static void set_mode(const GpioHandle&, PinMode)");
53
55 "SBL ERROR: GPIO driver missing write() method.\n"
56 "Required: static void write(const GpioHandle&, bool)");
57
59 "SBL ERROR: GPIO driver missing read() method.\n"
60 "Required: static bool read(const GpioHandle&)");
61
63 "SBL ERROR: GPIO driver missing toggle() method.\n"
64 "Required: static void toggle(const GpioHandle&)");
65
66 return true;
67 }
68};
69
70/**
71 * @brief Helper to validate a GPIO driver implementation
72 *
73 * Usage:
74 * ```cpp
75 * static_assert(sbl::validation::gpio_driver_valid<MyGpioDriver>,
76 * "GPIO driver incomplete");
77 * ```
78 */
79template<typename GpioDriver>
81
82} // namespace validation
83} // namespace sbl
84
85#endif // SBL_VALIDATION_GPIO_REQUIREMENTS_HPP_
GPIO driver requirements validator.
static constexpr bool validate()
Validate all required GPIO methods.
Method and interface detection for driver validation.
constexpr bool gpio_driver_valid
Helper to validate a GPIO driver implementation.
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
GPIO Driver Method Detection (Handle-First API)