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
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/hw/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_HW_VALIDATION_AUDIO_REQUIREMENTS_HPP_
32#define SBL_HW_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() {
48 static_assert(has_audio_init<AudioDriver>::value, "SBL ERROR: Audio driver missing init() method.\n"
49 "Required: static init() (void or bool)");
50
52 "SBL ERROR: Audio driver missing init(const AudioConfig&) method.\n"
53 "Required: static init(const sbl::hal::audio::AudioConfig&) (void or bool)");
54
56 "SBL ERROR: Audio driver missing set_callback() method.\n"
57 "Required: static void set_callback(sbl::hal::audio::AudioCallback)");
58
59 static_assert(has_audio_start<AudioDriver>::value, "SBL ERROR: Audio driver missing start() method.\n"
60 "Required: static void start()");
61
62 static_assert(has_audio_stop<AudioDriver>::value, "SBL ERROR: Audio driver missing stop() method.\n"
63 "Required: static void stop()");
64
65 return true;
66 }
67};
68
69/**
70 * @brief Helper to validate an audio driver implementation
71 *
72 * Usage:
73 * ```cpp
74 * static_assert(sbl::validation::audio_driver_valid<MyAudioDriver>,
75 * "Audio driver incomplete");
76 * ```
77 */
78template<typename AudioDriver>
80
81} // namespace validation
82} // namespace sbl
83
84#endif // SBL_HW_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 code.
True if T::init(const AudioConfig&) is a valid static call.
True if T::init() is a valid static call.
True if T::set_callback(AudioCallback) is a valid static call.
True if T::start() is a valid static call.
True if T::stop() is a valid static call.