Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
uart_requirements.hpp
Go to the documentation of this file.
1/**
2 * @file uart_requirements.hpp
3 * @brief UART driver requirements validator
4 * @ingroup validation
5 *
6 * Validates that UART drivers provide required functionality using the
7 * method detection system. This is the core UART contract enforcement
8 * for Sound Byte Libs drivers.
9 *
10 * ## UART Driver Contract
11 *
12 * Every Sound Byte Libs UART driver MUST implement these methods:
13 * - `init(const UartHandle&)` - Initialize UART with manifest-resolved handle
14 * - `write_byte(uint8_t byte)` - Write single byte (blocking)
15 * - `write(const uint8_t* data, size_t len)` - Write buffer (blocking)
16 *
17 * ## Validation Usage
18 *
19 * Add validation at the bottom of driver uart.hpp:
20 * ```cpp
21 * #include <sbl/validation/uart_requirements.hpp>
22 * static_assert(sbl::validation::uart_driver_valid<sbl::driver::Uart>,
23 * "UART driver missing required methods");
24 * ```
25 *
26 * @see method_detection.hpp
27 */
28
29#ifndef SBL_VALIDATION_UART_REQUIREMENTS_HPP_
30#define SBL_VALIDATION_UART_REQUIREMENTS_HPP_
31
32#include "method_detection.hpp"
33
34namespace sbl {
35namespace validation {
36
37/**
38 * @brief UART driver requirements validator
39 *
40 * Validates that UART drivers provide all required methods.
41 */
42template<typename UartDriver>
44public:
45 /**
46 * @brief Validate all required UART methods
47 */
48 static constexpr bool validate() {
50 "SBL ERROR: UART driver missing init() method.\n"
51 "Required: static void init(const sbl::UartHandle& handle)");
52
54 "SBL ERROR: UART driver missing write_byte() method.\n"
55 "Required: static void write_byte(uint8_t byte)");
56
58 "SBL ERROR: UART driver missing write() method.\n"
59 "Required: static void write(const uint8_t* data, size_t len)");
60
61 return true;
62 }
63};
64
65/**
66 * @brief Helper to validate a UART driver implementation
67 *
68 * Usage:
69 * ```cpp
70 * static_assert(sbl::validation::uart_driver_valid<MyUartDriver>,
71 * "UART driver incomplete");
72 * ```
73 */
74template<typename UartDriver>
76
77} // namespace validation
78} // namespace sbl
79
80#endif // SBL_VALIDATION_UART_REQUIREMENTS_HPP_
UART driver requirements validator.
static constexpr bool validate()
Validate all required UART methods.
Method and interface detection for driver validation.
constexpr bool uart_driver_valid
Helper to validate a UART driver implementation.
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
UART Driver Method Detection.