14#ifndef ZEPHYR_INCLUDE_AUDIO_CODEC_H_
15#define ZEPHYR_INCLUDE_AUDIO_CODEC_H_
171struct audio_codec_api {
172 int (*configure)(
const struct device *dev,
174 void (*start_output)(
const struct device *dev);
175 void (*stop_output)(
const struct device *dev);
176 int (*set_property)(
const struct device *dev,
180 int (*apply_properties)(
const struct device *dev);
181 int (*clear_errors)(
const struct device *dev);
182 int (*register_error_callback)(
const struct device *dev,
205 const struct audio_codec_api *api =
206 (
const struct audio_codec_api *)dev->
api;
208 return api->configure(dev, cfg);
220 const struct audio_codec_api *api =
221 (
const struct audio_codec_api *)dev->
api;
223 api->start_output(dev);
235 const struct audio_codec_api *api =
236 (
const struct audio_codec_api *)dev->
api;
238 api->stop_output(dev);
258 const struct audio_codec_api *api =
259 (
const struct audio_codec_api *)dev->
api;
261 return api->set_property(dev, property, channel, val);
277 const struct audio_codec_api *api =
278 (
const struct audio_codec_api *)dev->
api;
280 return api->apply_properties(dev);
295 const struct audio_codec_api *api =
296 (
const struct audio_codec_api *)dev->
api;
298 if (api->clear_errors == NULL) {
302 return api->clear_errors(dev);
322 const struct audio_codec_api *api =
323 (
const struct audio_codec_api *)dev->
api;
325 if (api->register_error_callback == NULL) {
329 return api->register_error_callback(dev, cb);
348 const struct audio_codec_api *api = (
const struct audio_codec_api *)dev->
api;
350 if (api->route_input == NULL) {
354 return api->route_input(dev, channel, input);
373 const struct audio_codec_api *api = (
const struct audio_codec_api *)dev->
api;
375 if (api->route_output == NULL) {
379 return api->route_output(dev, channel, output);
static int audio_codec_configure(const struct device *dev, struct audio_codec_cfg *cfg)
Configure the audio codec.
Definition codec.h:202
void(* audio_codec_error_callback_t)(const struct device *dev, uint32_t errors)
Callback for error interrupt.
Definition codec.h:164
audio_dai_type_t
Digital Audio Interface (DAI) type.
Definition codec.h:62
static void audio_codec_start_output(const struct device *dev)
Set codec to start output audio playback.
Definition codec.h:218
audio_pcm_width_t
PCM audio sample bit widths.
Definition codec.h:52
audio_codec_error_type
Codec error type.
Definition codec.h:140
audio_route_t
Definition codec.h:112
audio_property_t
Codec properties that can be set by audio_codec_set_property().
Definition codec.h:74
static int audio_codec_clear_errors(const struct device *dev)
Clear any codec errors.
Definition codec.h:293
static int audio_codec_set_property(const struct device *dev, audio_property_t property, audio_channel_t channel, audio_property_value_t val)
Set a codec property defined by audio_property_t.
Definition codec.h:253
static void audio_codec_stop_output(const struct device *dev)
Set codec to stop output audio playback.
Definition codec.h:233
audio_pcm_rate_t
PCM audio sample rates.
Definition codec.h:36
static int audio_codec_register_error_callback(const struct device *dev, audio_codec_error_callback_t cb)
Register a callback function for codec error.
Definition codec.h:319
static int audio_codec_route_input(const struct device *dev, audio_channel_t channel, uint32_t input)
Sets up signal routing for a given input channel.
Definition codec.h:345
audio_channel_t
Audio channel identifiers to use in audio_codec_set_property().
Definition codec.h:84
static int audio_codec_route_output(const struct device *dev, audio_channel_t channel, uint32_t output)
Sets up signal routing for a given output channel.
Definition codec.h:370
static int audio_codec_apply_properties(const struct device *dev)
Atomically apply any cached properties.
Definition codec.h:275
@ AUDIO_DAI_TYPE_PCMA
PCM Interface, variant A.
Definition codec.h:66
@ AUDIO_DAI_TYPE_I2S
I2S Interface.
Definition codec.h:63
@ AUDIO_DAI_TYPE_LEFT_JUSTIFIED
I2S Interface, left justified.
Definition codec.h:64
@ AUDIO_DAI_TYPE_INVALID
Other interfaces can be added here.
Definition codec.h:68
@ AUDIO_DAI_TYPE_RIGHT_JUSTIFIED
I2S Interface, right justified.
Definition codec.h:65
@ AUDIO_DAI_TYPE_PCMB
PCM Interface, variant B.
Definition codec.h:67
@ AUDIO_PCM_WIDTH_16_BITS
16-bit sample width
Definition codec.h:53
@ AUDIO_PCM_WIDTH_32_BITS
32-bit sample width
Definition codec.h:56
@ AUDIO_PCM_WIDTH_20_BITS
20-bit sample width
Definition codec.h:54
@ AUDIO_PCM_WIDTH_24_BITS
24-bit sample width
Definition codec.h:55
@ AUDIO_CODEC_ERROR_UNDERVOLTAGE
Power low voltage.
Definition codec.h:148
@ AUDIO_CODEC_ERROR_OVERVOLTAGE
Power high voltage.
Definition codec.h:151
@ AUDIO_CODEC_ERROR_OVERTEMPERATURE
Codec over-temperature.
Definition codec.h:145
@ AUDIO_CODEC_ERROR_DC
Output direct-current.
Definition codec.h:154
@ AUDIO_CODEC_ERROR_OVERCURRENT
Output over-current.
Definition codec.h:142
@ AUDIO_ROUTE_CAPTURE
Definition codec.h:116
@ AUDIO_ROUTE_BYPASS
Definition codec.h:113
@ AUDIO_ROUTE_PLAYBACK
Definition codec.h:114
@ AUDIO_ROUTE_PLAYBACK_CAPTURE
Definition codec.h:115
@ AUDIO_PROPERTY_INPUT_VOLUME
Input volume.
Definition codec.h:77
@ AUDIO_PROPERTY_OUTPUT_VOLUME
Output volume.
Definition codec.h:75
@ AUDIO_PROPERTY_INPUT_MUTE
Input mute/unmute.
Definition codec.h:78
@ AUDIO_PROPERTY_OUTPUT_MUTE
Output mute/unmute.
Definition codec.h:76
@ AUDIO_PCM_RATE_32K
32 kHz sample rate
Definition codec.h:42
@ AUDIO_PCM_RATE_192K
192 kHz sample rate
Definition codec.h:46
@ AUDIO_PCM_RATE_11P025K
11.025 kHz sample rate
Definition codec.h:38
@ AUDIO_PCM_RATE_22P05K
22.05 kHz sample rate
Definition codec.h:40
@ AUDIO_PCM_RATE_8K
8 kHz sample rate
Definition codec.h:37
@ AUDIO_PCM_RATE_48K
48 kHz sample rate
Definition codec.h:44
@ AUDIO_PCM_RATE_44P1K
44.1 kHz sample rate
Definition codec.h:43
@ AUDIO_PCM_RATE_96K
96 kHz sample rate
Definition codec.h:45
@ AUDIO_PCM_RATE_16K
16 kHz sample rate
Definition codec.h:39
@ AUDIO_PCM_RATE_24K
24 kHz sample rate
Definition codec.h:41
@ AUDIO_CHANNEL_FRONT_LEFT
Front left channel.
Definition codec.h:85
@ AUDIO_CHANNEL_FRONT_RIGHT
Front right channel.
Definition codec.h:86
@ AUDIO_CHANNEL_ALL
All channels.
Definition codec.h:96
@ AUDIO_CHANNEL_REAR_RIGHT
Rear right channel.
Definition codec.h:90
@ AUDIO_CHANNEL_REAR_LEFT
Rear left channel.
Definition codec.h:89
@ AUDIO_CHANNEL_LFE
Low frequency effect channel.
Definition codec.h:87
@ AUDIO_CHANNEL_HEADPHONE_RIGHT
Headphone right.
Definition codec.h:95
@ AUDIO_CHANNEL_SIDE_RIGHT
Side right channel.
Definition codec.h:93
@ AUDIO_CHANNEL_FRONT_CENTER
Front center channel.
Definition codec.h:88
@ AUDIO_CHANNEL_SIDE_LEFT
Side left channel.
Definition codec.h:92
@ AUDIO_CHANNEL_REAR_CENTER
Rear center channel.
Definition codec.h:91
@ AUDIO_CHANNEL_HEADPHONE_LEFT
Headphone left.
Definition codec.h:94
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOSYS
Function not implemented.
Definition errno.h:82
Public APIs for the I2S (Inter-IC Sound) bus drivers.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Codec configuration parameters.
Definition codec.h:122
audio_dai_type_t dai_type
Digital interface type.
Definition codec.h:124
uint32_t mclk_freq
MCLK input frequency in Hz.
Definition codec.h:123
audio_dai_cfg_t dai_cfg
DAI configuration info.
Definition codec.h:125
audio_route_t dai_route
Codec route type.
Definition codec.h:126
Runtime device structure (in ROM) per driver instance.
Definition device.h:411
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:417
Interface configuration options.
Definition i2s.h:295
Digital Audio Interface Configuration.
Definition codec.h:104
Codec property values.
Definition codec.h:132
bool mute
Mute if true, unmute if false.
Definition codec.h:134
int vol
Volume level (codec-specific)
Definition codec.h:133