Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
audio_requirements.hpp
Go to the documentation of this file.
1/**
2 * @file audio_requirements.hpp
3 * @brief Audio driver requirements validator
4 * @ingroup validation
5 *
6 * Validates that audio drivers provide required functionality using the
7 * method detection system. This is the core audio contract enforcement
8 * for Sound Byte Libs drivers.
9 *
10 * ## Audio Driver Contract
11 *
12 * Every Sound Byte Libs audio driver MUST implement these methods:
13 * - `init()` - Initialize with default settings
14 * - `init(const AudioConfig&)` - Initialize with custom settings
15 * - `set_callback(AudioCallback)` - Register processing callback
16 * - `start()` - Begin audio streaming
17 * - `stop()` - Stop audio streaming
18 *
19 * ## Validation Usage
20 *
21 * Add validation at the bottom of driver sai.hpp (or i2s.hpp, etc.):
22 * ```cpp
23 * #include <sbl/validation/audio_requirements.hpp>
24 * static_assert(sbl::validation::audio_driver_valid<sbl::driver::Sai>,
25 * "SAI driver missing required audio methods");
26 * ```
27 *
28 * @see method_detection.hpp
29 */
30
31#ifndef SBL_VALIDATION_AUDIO_REQUIREMENTS_HPP_
32#define SBL_VALIDATION_AUDIO_REQUIREMENTS_HPP_
33
34#include "method_detection.hpp"
35
36namespace sbl {
37namespace validation {
38
39/**
40 * @brief Audio driver requirements validator
41 *
42 * Validates that audio drivers provide all required methods.
43 */
44template<typename AudioDriver>
46public:
47 static constexpr bool validate() {
49 "SBL ERROR: Audio driver missing init() method.\n"
50 "Required: static init() (void or bool)");
51
53 "SBL ERROR: Audio driver missing init(const AudioConfig&) method.\n"
54 "Required: static init(const sbl::hal::audio::AudioConfig&) (void or bool)");
55
57 "SBL ERROR: Audio driver missing set_callback() method.\n"
58 "Required: static void set_callback(sbl::hal::audio::AudioCallback)");
59
61 "SBL ERROR: Audio driver missing start() method.\n"
62 "Required: static void start()");
63
65 "SBL ERROR: Audio driver missing stop() method.\n"
66 "Required: static void stop()");
67
68 return true;
69 }
70};
71
72/**
73 * @brief Helper to validate an audio driver implementation
74 *
75 * Usage:
76 * ```cpp
77 * static_assert(sbl::validation::audio_driver_valid<MyAudioDriver>,
78 * "Audio driver incomplete");
79 * ```
80 */
81template<typename AudioDriver>
83
84} // namespace validation
85} // namespace sbl
86
87#endif // SBL_VALIDATION_AUDIO_REQUIREMENTS_HPP_
Audio driver requirements validator.
Method and interface detection for driver validation.
constexpr bool audio_driver_valid
Helper to validate an audio driver implementation.
Root namespace for all Sound Byte Libs functionality.
Definition aliases.hpp:24
Audio Driver Method Detection.