Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Audio Codec Interface

Abstraction for audio codecs. More...

Data Structures

union  audio_dai_cfg_t
 Digital Audio Interface Configuration. More...
 
struct  audio_codec_cfg
 Codec configuration parameters. More...
 
union  audio_property_value_t
 Codec property values. More...
 

Typedefs

typedef void(* audio_codec_error_callback_t) (const struct device *dev, uint32_t errors)
 Callback for error interrupt.
 

Enumerations

enum  audio_pcm_rate_t {
  AUDIO_PCM_RATE_8K = 8000 , AUDIO_PCM_RATE_16K = 16000 , AUDIO_PCM_RATE_24K = 24000 , AUDIO_PCM_RATE_32K = 32000 ,
  AUDIO_PCM_RATE_44P1K = 44100 , AUDIO_PCM_RATE_48K = 48000 , AUDIO_PCM_RATE_96K = 96000 , AUDIO_PCM_RATE_192K = 192000
}
 PCM audio sample rates. More...
 
enum  audio_pcm_width_t { AUDIO_PCM_WIDTH_16_BITS = 16 , AUDIO_PCM_WIDTH_20_BITS = 20 , AUDIO_PCM_WIDTH_24_BITS = 24 , AUDIO_PCM_WIDTH_32_BITS = 32 }
 PCM audio sample bit widths. More...
 
enum  audio_dai_type_t { AUDIO_DAI_TYPE_I2S , AUDIO_DAI_TYPE_INVALID }
 Digital Audio Interface (DAI) type. More...
 
enum  audio_property_t { AUDIO_PROPERTY_OUTPUT_VOLUME , AUDIO_PROPERTY_OUTPUT_MUTE }
 Codec properties that can be set by audio_codec_set_property(). More...
 
enum  audio_channel_t {
  AUDIO_CHANNEL_FRONT_LEFT , AUDIO_CHANNEL_FRONT_RIGHT , AUDIO_CHANNEL_LFE , AUDIO_CHANNEL_FRONT_CENTER ,
  AUDIO_CHANNEL_REAR_LEFT , AUDIO_CHANNEL_REAR_RIGHT , AUDIO_CHANNEL_REAR_CENTER , AUDIO_CHANNEL_SIDE_LEFT ,
  AUDIO_CHANNEL_SIDE_RIGHT , AUDIO_CHANNEL_ALL
}
 Audio channel identifiers to use in audio_codec_set_property(). More...
 
enum  audio_codec_error_type {
  AUDIO_CODEC_ERROR_OVERCURRENT = BIT(0) , AUDIO_CODEC_ERROR_OVERTEMPERATURE = BIT(1) , AUDIO_CODEC_ERROR_UNDERVOLTAGE = BIT(2) , AUDIO_CODEC_ERROR_OVERVOLTAGE = BIT(3) ,
  AUDIO_CODEC_ERROR_DC = BIT(4)
}
 Codec error type. More...
 

Functions

static int audio_codec_configure (const struct device *dev, struct audio_codec_cfg *cfg)
 Configure the audio codec.
 
static void audio_codec_start_output (const struct device *dev)
 Set codec to start output audio playback.
 
static void audio_codec_stop_output (const struct device *dev)
 Set codec to stop output audio playback.
 
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.
 
static int audio_codec_apply_properties (const struct device *dev)
 Atomically apply any cached properties.
 
static int audio_codec_clear_errors (const struct device *dev)
 Clear any codec errors.
 
static int audio_codec_register_error_callback (const struct device *dev, audio_codec_error_callback_t cb)
 Register a callback function for codec error.
 

Detailed Description

Abstraction for audio codecs.

Since
1.13
Version
0.1.0

Typedef Documentation

◆ audio_codec_error_callback_t

audio_codec_error_callback_t

#include <include/zephyr/audio/codec.h>

Callback for error interrupt.

Parameters
devPointer to the codec device
errorsDevice errors (bitmask of audio_codec_error_type values)

Enumeration Type Documentation

◆ audio_channel_t

#include <include/zephyr/audio/codec.h>

Audio channel identifiers to use in audio_codec_set_property().

Enumerator
AUDIO_CHANNEL_FRONT_LEFT 

Front left channel.

AUDIO_CHANNEL_FRONT_RIGHT 

Front right channel.

AUDIO_CHANNEL_LFE 

Low frequency effect channel.

AUDIO_CHANNEL_FRONT_CENTER 

Front center channel.

AUDIO_CHANNEL_REAR_LEFT 

Rear left channel.

AUDIO_CHANNEL_REAR_RIGHT 

Rear right channel.

AUDIO_CHANNEL_REAR_CENTER 

Rear center channel.

AUDIO_CHANNEL_SIDE_LEFT 

Side left channel.

AUDIO_CHANNEL_SIDE_RIGHT 

Side right channel.

AUDIO_CHANNEL_ALL 

All channels.

◆ audio_codec_error_type

#include <include/zephyr/audio/codec.h>

Codec error type.

Enumerator
AUDIO_CODEC_ERROR_OVERCURRENT 

Output over-current.

AUDIO_CODEC_ERROR_OVERTEMPERATURE 

Codec over-temperature.

AUDIO_CODEC_ERROR_UNDERVOLTAGE 

Power low voltage.

AUDIO_CODEC_ERROR_OVERVOLTAGE 

Power high voltage.

AUDIO_CODEC_ERROR_DC 

Output direct-current.

◆ audio_dai_type_t

#include <include/zephyr/audio/codec.h>

Digital Audio Interface (DAI) type.

Enumerator
AUDIO_DAI_TYPE_I2S 

I2S Interface.

AUDIO_DAI_TYPE_INVALID 

Other interfaces can be added here.

◆ audio_pcm_rate_t

#include <include/zephyr/audio/codec.h>

PCM audio sample rates.

Enumerator
AUDIO_PCM_RATE_8K 

8 kHz sample rate

AUDIO_PCM_RATE_16K 

16 kHz sample rate

AUDIO_PCM_RATE_24K 

24 kHz sample rate

AUDIO_PCM_RATE_32K 

32 kHz sample rate

AUDIO_PCM_RATE_44P1K 

44.1 kHz sample rate

AUDIO_PCM_RATE_48K 

48 kHz sample rate

AUDIO_PCM_RATE_96K 

96 kHz sample rate

AUDIO_PCM_RATE_192K 

192 kHz sample rate

◆ audio_pcm_width_t

#include <include/zephyr/audio/codec.h>

PCM audio sample bit widths.

Enumerator
AUDIO_PCM_WIDTH_16_BITS 

16-bit sample width

AUDIO_PCM_WIDTH_20_BITS 

20-bit sample width

AUDIO_PCM_WIDTH_24_BITS 

24-bit sample width

AUDIO_PCM_WIDTH_32_BITS 

32-bit sample width

◆ audio_property_t

#include <include/zephyr/audio/codec.h>

Codec properties that can be set by audio_codec_set_property().

Enumerator
AUDIO_PROPERTY_OUTPUT_VOLUME 

Output volume.

AUDIO_PROPERTY_OUTPUT_MUTE 

Output mute/unmute.

Function Documentation

◆ audio_codec_apply_properties()

static int audio_codec_apply_properties ( const struct device dev)
inlinestatic

#include <include/zephyr/audio/codec.h>

Atomically apply any cached properties.

Following one or more invocations of audio_codec_set_property, that may have been cached by the driver, audio_codec_apply_properties can be invoked to apply all the properties as atomic as possible

Parameters
devPointer to the device structure for codec driver instance.
Returns
0 on success, negative error code on failure

◆ audio_codec_clear_errors()

static int audio_codec_clear_errors ( const struct device dev)
inlinestatic

#include <include/zephyr/audio/codec.h>

Clear any codec errors.

Clear all codec errors. If an error interrupt exists, it will be de-asserted.

Parameters
devPointer to the device structure for codec driver instance.
Returns
0 on success, negative error code on failure

◆ audio_codec_configure()

static int audio_codec_configure ( const struct device dev,
struct audio_codec_cfg cfg 
)
inlinestatic

#include <include/zephyr/audio/codec.h>

Configure the audio codec.

Configure the audio codec device according to the configuration parameters provided as input

Parameters
devPointer to the device structure for codec driver instance.
cfgPointer to the structure containing the codec configuration.
Returns
0 on success, negative error code on failure

◆ audio_codec_register_error_callback()

static int audio_codec_register_error_callback ( const struct device dev,
audio_codec_error_callback_t  cb 
)
inlinestatic

#include <include/zephyr/audio/codec.h>

Register a callback function for codec error.

The callback will be called from a thread, so I2C or SPI operations are safe. However, the thread's stack is limited and defined by the driver. It is currently up to the caller to ensure that the callback does not overflow the stack.

Parameters
devPointer to the audio codec device
cbThe function that should be called when an error is detected fires
Returns
0 if successful, negative errno code if failure.

◆ audio_codec_set_property()

static int audio_codec_set_property ( const struct device dev,
audio_property_t  property,
audio_channel_t  channel,
audio_property_value_t  val 
)
inlinestatic

#include <include/zephyr/audio/codec.h>

Set a codec property defined by audio_property_t.

Set a property such as volume level, clock configuration etc.

Parameters
devPointer to the device structure for codec driver instance.
propertyThe codec property to set
channelThe audio channel for which the property has to be set
valpointer to a property value of type audio_codec_property_value_t
Returns
0 on success, negative error code on failure

◆ audio_codec_start_output()

static void audio_codec_start_output ( const struct device dev)
inlinestatic

#include <include/zephyr/audio/codec.h>

Set codec to start output audio playback.

Setup the audio codec device to start the audio playback

Parameters
devPointer to the device structure for codec driver instance.

◆ audio_codec_stop_output()

static void audio_codec_stop_output ( const struct device dev)
inlinestatic

#include <include/zephyr/audio/codec.h>

Set codec to stop output audio playback.

Setup the audio codec device to stop the audio playback

Parameters
devPointer to the device structure for codec driver instance.