14#ifndef ZEPHYR_INCLUDE_AUDIO_CODEC_H_
15#define ZEPHYR_INCLUDE_AUDIO_CODEC_H_
172struct audio_codec_api {
173 int (*configure)(
const struct device *dev,
175 void (*start_output)(
const struct device *dev);
176 void (*stop_output)(
const struct device *dev);
177 int (*set_property)(
const struct device *dev,
181 int (*apply_properties)(
const struct device *dev);
182 int (*clear_errors)(
const struct device *dev);
183 int (*register_error_callback)(
const struct device *dev,
206 const struct audio_codec_api *api =
207 (
const struct audio_codec_api *)dev->
api;
209 return api->configure(dev, cfg);
221 const struct audio_codec_api *api =
222 (
const struct audio_codec_api *)dev->
api;
224 api->start_output(dev);
236 const struct audio_codec_api *api =
237 (
const struct audio_codec_api *)dev->
api;
239 api->stop_output(dev);
259 const struct audio_codec_api *api =
260 (
const struct audio_codec_api *)dev->
api;
262 return api->set_property(dev, property, channel, val);
278 const struct audio_codec_api *api =
279 (
const struct audio_codec_api *)dev->
api;
281 return api->apply_properties(dev);
296 const struct audio_codec_api *api =
297 (
const struct audio_codec_api *)dev->
api;
299 if (api->clear_errors ==
NULL) {
303 return api->clear_errors(dev);
323 const struct audio_codec_api *api =
324 (
const struct audio_codec_api *)dev->
api;
326 if (api->register_error_callback ==
NULL) {
330 return api->register_error_callback(dev, cb);
349 const struct audio_codec_api *api = (
const struct audio_codec_api *)dev->
api;
351 if (api->route_input ==
NULL) {
355 return api->route_input(dev, channel, input);
374 const struct audio_codec_api *api = (
const struct audio_codec_api *)dev->
api;
376 if (api->route_output ==
NULL) {
380 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:203
void(* audio_codec_error_callback_t)(const struct device *dev, uint32_t errors)
Callback for error interrupt.
Definition codec.h:165
audio_dai_type_t
Digital Audio Interface (DAI) type.
Definition codec.h:63
static void audio_codec_start_output(const struct device *dev)
Set codec to start output audio playback.
Definition codec.h:219
audio_pcm_width_t
PCM audio sample bit widths.
Definition codec.h:53
audio_codec_error_type
Codec error type.
Definition codec.h:141
audio_route_t
Definition codec.h:113
audio_property_t
Codec properties that can be set by audio_codec_set_property().
Definition codec.h:75
static int audio_codec_clear_errors(const struct device *dev)
Clear any codec errors.
Definition codec.h:294
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:254
static void audio_codec_stop_output(const struct device *dev)
Set codec to stop output audio playback.
Definition codec.h:234
audio_pcm_rate_t
PCM audio sample rates.
Definition codec.h:37
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:320
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:346
audio_channel_t
Audio channel identifiers to use in audio_codec_set_property().
Definition codec.h:85
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:371
static int audio_codec_apply_properties(const struct device *dev)
Atomically apply any cached properties.
Definition codec.h:276
@ AUDIO_DAI_TYPE_PCMA
PCM Interface, variant A.
Definition codec.h:67
@ AUDIO_DAI_TYPE_I2S
I2S Interface.
Definition codec.h:64
@ AUDIO_DAI_TYPE_LEFT_JUSTIFIED
I2S Interface, left justified.
Definition codec.h:65
@ AUDIO_DAI_TYPE_INVALID
Other interfaces can be added here.
Definition codec.h:69
@ AUDIO_DAI_TYPE_RIGHT_JUSTIFIED
I2S Interface, right justified.
Definition codec.h:66
@ AUDIO_DAI_TYPE_PCMB
PCM Interface, variant B.
Definition codec.h:68
@ AUDIO_PCM_WIDTH_16_BITS
16-bit sample width
Definition codec.h:54
@ AUDIO_PCM_WIDTH_32_BITS
32-bit sample width
Definition codec.h:57
@ AUDIO_PCM_WIDTH_20_BITS
20-bit sample width
Definition codec.h:55
@ AUDIO_PCM_WIDTH_24_BITS
24-bit sample width
Definition codec.h:56
@ AUDIO_CODEC_ERROR_UNDERVOLTAGE
Power low voltage.
Definition codec.h:149
@ AUDIO_CODEC_ERROR_OVERVOLTAGE
Power high voltage.
Definition codec.h:152
@ AUDIO_CODEC_ERROR_OVERTEMPERATURE
Codec over-temperature.
Definition codec.h:146
@ AUDIO_CODEC_ERROR_DC
Output direct-current.
Definition codec.h:155
@ AUDIO_CODEC_ERROR_OVERCURRENT
Output over-current.
Definition codec.h:143
@ AUDIO_ROUTE_CAPTURE
Definition codec.h:117
@ AUDIO_ROUTE_BYPASS
Definition codec.h:114
@ AUDIO_ROUTE_PLAYBACK
Definition codec.h:115
@ AUDIO_ROUTE_PLAYBACK_CAPTURE
Definition codec.h:116
@ AUDIO_PROPERTY_INPUT_VOLUME
Input volume.
Definition codec.h:78
@ AUDIO_PROPERTY_OUTPUT_VOLUME
Output volume.
Definition codec.h:76
@ AUDIO_PROPERTY_INPUT_MUTE
Input mute/unmute.
Definition codec.h:79
@ AUDIO_PROPERTY_OUTPUT_MUTE
Output mute/unmute.
Definition codec.h:77
@ AUDIO_PCM_RATE_32K
32 kHz sample rate
Definition codec.h:43
@ AUDIO_PCM_RATE_192K
192 kHz sample rate
Definition codec.h:47
@ AUDIO_PCM_RATE_11P025K
11.025 kHz sample rate
Definition codec.h:39
@ AUDIO_PCM_RATE_22P05K
22.05 kHz sample rate
Definition codec.h:41
@ AUDIO_PCM_RATE_8K
8 kHz sample rate
Definition codec.h:38
@ AUDIO_PCM_RATE_48K
48 kHz sample rate
Definition codec.h:45
@ AUDIO_PCM_RATE_44P1K
44.1 kHz sample rate
Definition codec.h:44
@ AUDIO_PCM_RATE_96K
96 kHz sample rate
Definition codec.h:46
@ AUDIO_PCM_RATE_16K
16 kHz sample rate
Definition codec.h:40
@ AUDIO_PCM_RATE_24K
24 kHz sample rate
Definition codec.h:42
@ AUDIO_CHANNEL_FRONT_LEFT
Front left channel.
Definition codec.h:86
@ AUDIO_CHANNEL_FRONT_RIGHT
Front right channel.
Definition codec.h:87
@ AUDIO_CHANNEL_ALL
All channels.
Definition codec.h:97
@ AUDIO_CHANNEL_REAR_RIGHT
Rear right channel.
Definition codec.h:91
@ AUDIO_CHANNEL_REAR_LEFT
Rear left channel.
Definition codec.h:90
@ AUDIO_CHANNEL_LFE
Low frequency effect channel.
Definition codec.h:88
@ AUDIO_CHANNEL_HEADPHONE_RIGHT
Headphone right.
Definition codec.h:96
@ AUDIO_CHANNEL_SIDE_RIGHT
Side right channel.
Definition codec.h:94
@ AUDIO_CHANNEL_FRONT_CENTER
Front center channel.
Definition codec.h:89
@ AUDIO_CHANNEL_SIDE_LEFT
Side left channel.
Definition codec.h:93
@ AUDIO_CHANNEL_REAR_CENTER
Rear center channel.
Definition codec.h:92
@ AUDIO_CHANNEL_HEADPHONE_LEFT
Headphone left.
Definition codec.h:95
#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
Main header file for I2S (Inter-IC Sound) driver API.
#define NULL
Definition iar_missing_defs.h:20
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Codec configuration parameters.
Definition codec.h:123
audio_dai_type_t dai_type
Digital interface type.
Definition codec.h:125
uint32_t mclk_freq
MCLK input frequency in Hz.
Definition codec.h:124
audio_dai_cfg_t dai_cfg
DAI configuration info.
Definition codec.h:126
audio_route_t dai_route
Codec route type.
Definition codec.h:127
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
Interface configuration options.
Definition i2s.h:296
Digital Audio Interface Configuration.
Definition codec.h:105
struct i2s_config i2s
I2S configuration.
Definition codec.h:106
Codec property values.
Definition codec.h:133
bool mute
Mute if true, unmute if false.
Definition codec.h:135
int vol
Volume level (codec-specific)
Definition codec.h:134