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
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/hw/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_HW_VALIDATION_GPIO_REQUIREMENTS_HPP_
31#define SBL_HW_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
54 static_assert(has_gpio_write<GpioDriver>::value, "SBL ERROR: GPIO driver missing write() method.\n"
55 "Required: static void write(const GpioHandle&, bool)");
56
57 static_assert(has_gpio_read<GpioDriver>::value, "SBL ERROR: GPIO driver missing read() method.\n"
58 "Required: static bool read(const GpioHandle&)");
59
60 static_assert(has_gpio_toggle<GpioDriver>::value, "SBL ERROR: GPIO driver missing toggle() method.\n"
61 "Required: static void toggle(const GpioHandle&)");
62
63 return true;
64 }
65};
66
67/**
68 * @brief Helper to validate a GPIO driver implementation
69 *
70 * Usage:
71 * ```cpp
72 * static_assert(sbl::validation::gpio_driver_valid<MyGpioDriver>,
73 * "GPIO driver incomplete");
74 * ```
75 */
76template<typename GpioDriver>
78
79} // namespace validation
80} // namespace sbl
81
82#endif // SBL_HW_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 code.
True if T::read(const GpioHandle&) is a valid static call.
True if T::set_mode(const GpioHandle&, PinMode) is a valid static call.
True if T::toggle(const GpioHandle&) is a valid static call.
True if T::write(const GpioHandle&, bool) is a valid static call.