PebbleOS v4.47.0-1362-gd278268fe
Loading...
Searching...
No Matches
Audio drivers

Interface for audio drivers. More...

Data Structures

struct  pbl_audio_dai_ops
 DAI driver operations. More...
 
struct  pbl_audio_codec_cfg
 Codec configuration for a stream. More...
 
struct  pbl_audio_codec_ops
 Codec driver operations, called with the lock of the card held. More...
 
struct  pbl_audio_codec
 A codec: a separate chip converting between the link and the analog side. More...
 
struct  pbl_audio_amp_ops
 Amplifier driver operations, called with the lock of the card held. More...
 
struct  pbl_audio_amp
 An amplifier between the output and the speaker, on while playing. More...
 
struct  pbl_audio_dai
 A digital audio interface of the SoC, streaming one direction or both. More...
 
struct  pbl_audio
 An audio device: a card, a DAI and what it is wired to, streaming both directions. More...
 

Macros

#define PBL_AUDIO_CODEC_INIT(sym, _name, _init, _parent, _ops)
 Initializer of a struct pbl_audio_codec.
 
#define PBL_AUDIO_AMP_INIT(sym, _name, _init, _parent, _ops)
 Initializer of a struct pbl_audio_amp.
 
#define PBL_AUDIO_DAI_STATE_DEFINE(sym)
 Define the class state of a DAI.
 
#define PBL_AUDIO_DAI_INIT(sym, _name, _parent, _ops)
 Initializer for a struct pbl_audio_dai.
 
#define PBL_AUDIO_CARD_DEFINE(sym, _name, _dai, _codec, _amp, _fmt, _clocks)
 Define a card.
 

Functions

static const struct pbl_audio * pbl_audio_dai_card (const struct pbl_audio_dai *dai)
 Get the card of a DAI, for drivers.
 
void pbl_audio_period_elapsed (const struct pbl_audio *audio, enum pbl_audio_dir dir)
 Report the end of the period the hardware was working on.
 
void pbl_audio_report_xrun (const struct pbl_audio *audio, enum pbl_audio_dir dir)
 Report a hardware overrun or underrun, flagged in the next callback.
 
void * pbl_audio_period (const struct pbl_audio *audio, enum pbl_audio_dir dir, uint8_t idx)
 Get a period of a running stream, for drivers.
 
static const struct pbl_audio_stream * pbl_audio_stream (const struct pbl_audio *audio, enum pbl_audio_dir dir)
 Get a running stream, for drivers.
 
static int32_t pbl_audio_gain_to_step (int32_t gain_mdb, int32_t min_mdb, int32_t step_mdb)
 Convert a gain in mdB to the register steps of a hardware gain stage.
 

Link formats

Flags of struct pbl_audio_link::fmt.

#define PBL_AUDIO_FMT_I2S   PBL_BIT(0)
 I2S framing.
 
#define PBL_AUDIO_FMT_CODEC_MASTER   PBL_BIT(1)
 The codec drives the bit and frame clocks.
 
#define PBL_AUDIO_FMT_PDM   PBL_BIT(2)
 PDM: the 1-bit stream of digital microphones.
 

Detailed Description

Interface for audio drivers.

A DAI driver embeds a struct pbl_audio_dai in its instance, sets it up with PBL_AUDIO_DAI_STATE_DEFINE() and PBL_AUDIO_DAI_INIT(), implements the struct pbl_audio_dai_ops the class calls and reports each period with pbl_audio_period_elapsed(). Codec and amplifier drivers embed a struct pbl_audio_codec or struct pbl_audio_amp, set up with PBL_AUDIO_CODEC_INIT() or PBL_AUDIO_AMP_INIT(). PBL_AUDIO_CARD_DEFINE() links them into a card.


Data Structure Documentation

◆ pbl_audio_codec_cfg

struct pbl_audio_codec_cfg

Codec configuration for a stream.

Data Fields
uint8_t channels Channels per frame on the link.
enum pbl_audio_dir dir Direction of the stream, one of pbl_audio_dir.
uint32_t fmt Link format, PBL_AUDIO_FMT_* flags.
int32_t gain_mdb Gain, in mdB.
bool mute Mute.
uint32_t rate Sample rate, in Hz.
uint8_t streaming Directions already streaming, with their path enabled, as PBL_BIT() of each.

◆ pbl_audio_codec

struct pbl_audio_codec

A codec: a separate chip converting between the link and the analog side.

Data Fields
struct pbl_device dev Device.
const struct pbl_audio_codec_ops * ops Driver operations.

◆ pbl_audio_amp

struct pbl_audio_amp

An amplifier between the output and the speaker, on while playing.

Data Fields
struct pbl_device dev Device.
const struct pbl_audio_amp_ops * ops Driver operations.

◆ pbl_audio_link

struct pbl_audio_link

What a device is wired to.

Data Fields
const struct pbl_audio_amp * amp Amplifier, or NULL.
const struct pbl_audio_codec * codec Codec on the link, or NULL.
uint32_t fmt Link format, PBL_AUDIO_FMT_* flags.

◆ pbl_audio_dai

struct pbl_audio_dai

A digital audio interface of the SoC, streaming one direction or both.

Data Fields
struct pbl_device dev Device.
const struct pbl_audio_dai_ops * ops Driver operations.
struct pbl_audio_dai_state * state Runtime state.

◆ pbl_audio

struct pbl_audio

An audio device: a card, a DAI and what it is wired to, streaming both directions.

Data Fields
const struct pbl_audio_dai * dai DAI.
struct pbl_device dev Device.
const struct pbl_audio_link * link What the DAI is wired to.
struct pbl_audio_state * state Runtime state.

Macro Definition Documentation

◆ PBL_AUDIO_AMP_INIT

#define PBL_AUDIO_AMP_INIT (   sym,
  _name,
  _init,
  _parent,
  _ops 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, &pbl_audio_amp_class), \
.ops = (_ops), \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153

Initializer of a struct pbl_audio_amp.

Parameters
symSymbol of the amplifier.
_nameName.
_initInit function, or NULL.
_parentParent device, or NULL.
_opsDriver operations.

◆ PBL_AUDIO_CARD_DEFINE

#define PBL_AUDIO_CARD_DEFINE (   sym,
  _name,
  _dai,
  _codec,
  _amp,
  _fmt,
  _clocks 
)
Value:
static struct pbl_audio_state sym##_audio_state; \
static const struct pbl_audio_link sym##_link = { \
.codec = (_codec), \
.amp = (_amp), \
.fmt = (_fmt) | (_clocks), \
}; \
const struct pbl_audio sym = { \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, pbl_audio_dev_init, &(_dai)->dev, &pbl_audio_class), \
.dai = (_dai), \
.state = &sym##_audio_state, \
.link = &sym##_link, \
}; \
PBL_DEVICE_REGISTER(sym, &sym.dev)
struct pbl_audio_state * state
Runtime state.
Definition driver.h:250
const struct pbl_audio_codec * codec
Codec on the link, or NULL.
Definition driver.h:199
const struct pbl_audio_link * link
What the DAI is wired to.
Definition driver.h:252
const struct pbl_audio_amp * amp
Amplifier, or NULL.
Definition driver.h:201
struct pbl_device dev
Device.
Definition driver.h:246
An audio device: a card, a DAI and what it is wired to, streaming both directions.
Definition driver.h:244
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:132

Define a card.

Parameters
symSymbol of the card, a struct pbl_audio.
_nameDevice name.
_daiDAI.
_codecCodec on the link, or NULL.
_ampAmplifier, or NULL.
_fmtLink framing, PBL_AUDIO_FMT_I2S, PBL_AUDIO_FMT_PDM or 0.
_clocksWho drives the clocks, PBL_AUDIO_FMT_CODEC_MASTER or 0.

◆ PBL_AUDIO_CODEC_INIT

#define PBL_AUDIO_CODEC_INIT (   sym,
  _name,
  _init,
  _parent,
  _ops 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, &pbl_audio_codec_class), \
.ops = (_ops), \
}

Initializer of a struct pbl_audio_codec.

Parameters
symSymbol of the codec.
_nameName.
_initInit function, or NULL.
_parentParent device, or NULL.
_opsDriver operations.

◆ PBL_AUDIO_DAI_INIT

#define PBL_AUDIO_DAI_INIT (   sym,
  _name,
  _parent,
  _ops 
)
Value:
{ \
.dev = \
PBL_DEVICE_INIT_CLASS(sym, _name, pbl_audio_dai_dev_init, _parent, &pbl_audio_dai_class), \
.ops = (_ops), \
.state = &sym##_dai_state, \
}

Initializer for a struct pbl_audio_dai.

Parameters
symSymbol of the instance, as passed to PBL_AUDIO_DAI_STATE_DEFINE().
_nameDevice name.
_parentParent device, or NULL.
_opsDriver operations.

◆ PBL_AUDIO_DAI_STATE_DEFINE

#define PBL_AUDIO_DAI_STATE_DEFINE (   sym)
Value:
static struct pbl_audio_dai_state sym##_dai_state

Define the class state of a DAI.

Parameters
symSymbol of the instance.

◆ PBL_AUDIO_FMT_CODEC_MASTER

#define PBL_AUDIO_FMT_CODEC_MASTER   PBL_BIT(1)

The codec drives the bit and frame clocks.

◆ PBL_AUDIO_FMT_I2S

#define PBL_AUDIO_FMT_I2S   PBL_BIT(0)

I2S framing.

◆ PBL_AUDIO_FMT_PDM

#define PBL_AUDIO_FMT_PDM   PBL_BIT(2)

PDM: the 1-bit stream of digital microphones.

Function Documentation

◆ pbl_audio_dai_card()

static const struct pbl_audio * pbl_audio_dai_card ( const struct pbl_audio_dai *  dai)
inlinestatic

Get the card of a DAI, for drivers.

Parameters
daiDAI.
Returns
Card, set once it is initialized.

References pbl_audio::dai, and pbl_audio_dai::state.

◆ pbl_audio_gain_to_step()

static int32_t pbl_audio_gain_to_step ( int32_t  gain_mdb,
int32_t  min_mdb,
int32_t  step_mdb 
)
inlinestatic

Convert a gain in mdB to the register steps of a hardware gain stage.

Parameters
gain_mdbGain in mdB.
min_mdbGain of step 0, in mdB.
step_mdbGain per step, in mdB.
Returns
Step, rounded down.

◆ pbl_audio_period()

void * pbl_audio_period ( const struct pbl_audio *  audio,
enum pbl_audio_dir  dir,
uint8_t  idx 
)

Get a period of a running stream, for drivers.

Parameters
audioDevice.
dirDirection, one of pbl_audio_dir.
idxPeriod index, below the number of periods.
Returns
Period.

◆ pbl_audio_period_elapsed()

void pbl_audio_period_elapsed ( const struct pbl_audio *  audio,
enum pbl_audio_dir  dir 
)

Report the end of the period the hardware was working on.

Called by drivers from their interrupt handler, once per period, in ring order.

Parameters
audioDevice.
dirDirection, one of pbl_audio_dir.

◆ pbl_audio_report_xrun()

void pbl_audio_report_xrun ( const struct pbl_audio *  audio,
enum pbl_audio_dir  dir 
)

Report a hardware overrun or underrun, flagged in the next callback.

Called by drivers, from any context.

Parameters
audioDevice.
dirDirection, one of pbl_audio_dir.

◆ pbl_audio_stream()

static const struct pbl_audio_stream * pbl_audio_stream ( const struct pbl_audio *  audio,
enum pbl_audio_dir  dir 
)
inlinestatic

Get a running stream, for drivers.

Parameters
audioDevice.
dirDirection, one of pbl_audio_dir.
Returns
Stream, valid while it runs.

References pbl_audio::state.