14#ifndef ZEPHYR_INCLUDE_AUDIO_CODEC_H_
15#define ZEPHYR_INCLUDE_AUDIO_CODEC_H_
150struct audio_codec_api {
151 int (*configure)(
const struct device *dev,
153 void (*start_output)(
const struct device *dev);
154 void (*stop_output)(
const struct device *dev);
155 int (*set_property)(
const struct device *dev,
159 int (*apply_properties)(
const struct device *dev);
160 int (*clear_errors)(
const struct device *dev);
161 int (*register_error_callback)(
const struct device *dev,
182 const struct audio_codec_api *api =
183 (
const struct audio_codec_api *)dev->
api;
185 return api->configure(dev, cfg);
197 const struct audio_codec_api *api =
198 (
const struct audio_codec_api *)dev->
api;
200 api->start_output(dev);
212 const struct audio_codec_api *api =
213 (
const struct audio_codec_api *)dev->
api;
215 api->stop_output(dev);
235 const struct audio_codec_api *api =
236 (
const struct audio_codec_api *)dev->
api;
238 return api->set_property(dev, property, channel, val);
254 const struct audio_codec_api *api =
255 (
const struct audio_codec_api *)dev->
api;
257 return api->apply_properties(dev);
272 const struct audio_codec_api *api =
273 (
const struct audio_codec_api *)dev->
api;
275 if (api->clear_errors == NULL) {
279 return api->clear_errors(dev);
299 const struct audio_codec_api *api =
300 (
const struct audio_codec_api *)dev->
api;
302 if (api->register_error_callback == NULL) {
306 return api->register_error_callback(dev, cb);
static int audio_codec_configure(const struct device *dev, struct audio_codec_cfg *cfg)
Configure the audio codec.
Definition: codec.h:179
audio_dai_type_t
Digital Audio Interface (DAI) type.
Definition: codec.h:60
static void audio_codec_start_output(const struct device *dev)
Set codec to start output audio playback.
Definition: codec.h:195
audio_pcm_width_t
PCM audio sample bit widths.
Definition: codec.h:50
audio_codec_error_type
Codec error type.
Definition: codec.h:119
audio_property_t
Codec properties that can be set by audio_codec_set_property().
Definition: codec.h:68
static int audio_codec_clear_errors(const struct device *dev)
Clear any codec errors.
Definition: codec.h:270
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:230
static void audio_codec_stop_output(const struct device *dev)
Set codec to stop output audio playback.
Definition: codec.h:210
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:296
audio_channel_t
Audio channel identifiers to use in audio_codec_set_property().
Definition: codec.h:76
void(* audio_codec_error_callback_t)(const struct device *dev, uint32_t errors)
Callback for error interrupt.
Definition: codec.h:143
static int audio_codec_apply_properties(const struct device *dev)
Atomically apply any cached properties.
Definition: codec.h:252
@ AUDIO_DAI_TYPE_I2S
I2S Interface.
Definition: codec.h:61
@ AUDIO_DAI_TYPE_INVALID
Other interfaces can be added here.
Definition: codec.h:62
@ AUDIO_PCM_WIDTH_16_BITS
16-bit sample width
Definition: codec.h:51
@ AUDIO_PCM_WIDTH_32_BITS
32-bit sample width
Definition: codec.h:54
@ AUDIO_PCM_WIDTH_20_BITS
20-bit sample width
Definition: codec.h:52
@ AUDIO_PCM_WIDTH_24_BITS
24-bit sample width
Definition: codec.h:53
@ AUDIO_CODEC_ERROR_UNDERVOLTAGE
Power low voltage.
Definition: codec.h:127
@ AUDIO_CODEC_ERROR_OVERVOLTAGE
Power high voltage.
Definition: codec.h:130
@ AUDIO_CODEC_ERROR_OVERTEMPERATURE
Codec over-temperature.
Definition: codec.h:124
@ AUDIO_CODEC_ERROR_DC
Output direct-current.
Definition: codec.h:133
@ AUDIO_CODEC_ERROR_OVERCURRENT
Output over-current.
Definition: codec.h:121
@ AUDIO_PROPERTY_OUTPUT_VOLUME
Output volume.
Definition: codec.h:69
@ AUDIO_PROPERTY_OUTPUT_MUTE
Output mute/unmute.
Definition: codec.h:70
@ AUDIO_PCM_RATE_32K
32 kHz sample rate
Definition: codec.h:40
@ AUDIO_PCM_RATE_192K
192 kHz sample rate
Definition: codec.h:44
@ AUDIO_PCM_RATE_8K
8 kHz sample rate
Definition: codec.h:37
@ AUDIO_PCM_RATE_48K
48 kHz sample rate
Definition: codec.h:42
@ AUDIO_PCM_RATE_44P1K
44.1 kHz sample rate
Definition: codec.h:41
@ AUDIO_PCM_RATE_96K
96 kHz sample rate
Definition: codec.h:43
@ AUDIO_PCM_RATE_16K
16 kHz sample rate
Definition: codec.h:38
@ AUDIO_PCM_RATE_24K
24 kHz sample rate
Definition: codec.h:39
@ AUDIO_CHANNEL_FRONT_LEFT
Front left channel.
Definition: codec.h:77
@ AUDIO_CHANNEL_FRONT_RIGHT
Front right channel.
Definition: codec.h:78
@ AUDIO_CHANNEL_ALL
All channels.
Definition: codec.h:86
@ AUDIO_CHANNEL_REAR_RIGHT
Rear right channel.
Definition: codec.h:82
@ AUDIO_CHANNEL_REAR_LEFT
Rear left channel.
Definition: codec.h:81
@ AUDIO_CHANNEL_LFE
Low frequency effect channel.
Definition: codec.h:79
@ AUDIO_CHANNEL_SIDE_RIGHT
Side right channel.
Definition: codec.h:85
@ AUDIO_CHANNEL_FRONT_CENTER
Front center channel.
Definition: codec.h:80
@ AUDIO_CHANNEL_SIDE_LEFT
Side left channel.
Definition: codec.h:84
@ AUDIO_CHANNEL_REAR_CENTER
Rear center channel.
Definition: codec.h:83
#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:102
audio_dai_type_t dai_type
Digital interface type.
Definition: codec.h:104
uint32_t mclk_freq
MCLK input frequency in Hz.
Definition: codec.h:103
audio_dai_cfg_t dai_cfg
DAI configuration info.
Definition: codec.h:105
Runtime device structure (in ROM) per driver instance.
Definition: device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:409
Interface configuration options.
Definition: i2s.h:295
Digital Audio Interface Configuration.
Definition: codec.h:94
Codec property values.
Definition: codec.h:111
bool mute
Mute if true, unmute if false.
Definition: codec.h:113
int vol
Volume level in 0.5dB resolution.
Definition: codec.h:112