PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches
audio.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <pbl/device.h>
#include <pbl/kernel/mutex.h>
#include <pbl/util/bits.h>

Data Structures

struct  pbl_audio_pos
 Stream position at a period boundary. More...
 
struct  pbl_audio_stream
 A stream. More...
 
struct  pbl_audio_caps
 What a device can do. More...
 
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 linked device held. More...
 
struct  pbl_audio_amp
 An amplifier between the output and the speaker. More...
 
struct  pbl_audio_dai
 A digital audio interface of the SoC, streaming one direction. More...
 
struct  pbl_audio
 An audio device: a card, a DAI and what it is wired to. More...
 

Macros

#define PBL_AUDIO_BUF_ALIGN   32U
 Alignment, in bytes, of rings and their size: the largest data cache line.
 
#define PBL_AUDIO_MAX_PERIODS   32U
 Most periods in a ring.
 
#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, _dir)
 Initializer for a struct pbl_audio_dai.
 
#define PBL_AUDIO_CARD_DEFINE(sym, _name, _dai, _codec, _amp, _fmt, _clocks)
 Define a card.
 
Sample rates

Bits of struct pbl_audio_caps::rates.

#define PBL_AUDIO_RATE_8000   PBL_BIT(0)
 8 kHz.
 
#define PBL_AUDIO_RATE_11025   PBL_BIT(1)
 11.025 kHz.
 
#define PBL_AUDIO_RATE_12000   PBL_BIT(2)
 12 kHz.
 
#define PBL_AUDIO_RATE_16000   PBL_BIT(3)
 16 kHz.
 
#define PBL_AUDIO_RATE_22050   PBL_BIT(4)
 22.05 kHz.
 
#define PBL_AUDIO_RATE_24000   PBL_BIT(5)
 24 kHz.
 
#define PBL_AUDIO_RATE_32000   PBL_BIT(6)
 32 kHz.
 
#define PBL_AUDIO_RATE_44100   PBL_BIT(7)
 44.1 kHz.
 
#define PBL_AUDIO_RATE_48000   PBL_BIT(8)
 48 kHz.
 
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.
 

Typedefs

typedef void(* pbl_audio_period_cb) (const struct pbl_audio *audio, void *period, const struct pbl_audio_pos *pos, void *arg)
 Period callback, called from the driver's interrupt.
 

Enumerations

enum  pbl_audio_dir { PBL_AUDIO_PLAYBACK , PBL_AUDIO_CAPTURE }
 Stream direction. More...
 

Functions

static uint8_t pbl_audio_dir (const struct pbl_audio *audio)
 Get the direction of a card.
 
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)
 Report the end of the period the hardware was working on.
 
void pbl_audio_report_xrun (const struct pbl_audio *audio)
 Report a hardware overrun or underrun, flagged in the next callback.
 
void * pbl_audio_period (const struct pbl_audio *audio, uint8_t idx)
 Get a period of the running stream, for drivers.
 
int pbl_audio_get_caps (const struct pbl_audio *audio, struct pbl_audio_caps *caps)
 Get what a device can do, including its codec.
 
int pbl_audio_start (const struct pbl_audio *audio, const struct pbl_audio_stream *stream)
 Start streaming.
 
int pbl_audio_period_ready (const struct pbl_audio *audio, void *period)
 Give a period back to the hardware: refilled for playback, read for capture.
 
int pbl_audio_stop (const struct pbl_audio *audio)
 Stop streaming.
 
int pbl_audio_set_gain (const struct pbl_audio *audio, int32_t gain_mdb)
 Set the gain.
 
int pbl_audio_set_mute (const struct pbl_audio *audio, bool mute)
 Mute or unmute.
 
int pbl_audio_get_position (const struct pbl_audio *audio, struct pbl_audio_pos *pos)
 Get the current stream position.
 
bool pbl_audio_is_running (const struct pbl_audio *audio)
 Check whether a device is streaming.
 
size_t pbl_audio_ring_bytes (const struct pbl_audio_stream *stream)
 Get the bytes of a ring.
 
void * pbl_audio_buf_alloc (size_t size)
 Allocate a ring: aligned and padded to PBL_AUDIO_BUF_ALIGN, reachable by DMA.
 
void pbl_audio_buf_free (void *buf)
 Free a ring from pbl_audio_buf_alloc().
 
uint32_t pbl_audio_rate_bit (uint32_t rate)
 Get the bit of a sample rate.
 
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.
 

Variables

const struct pbl_audio *const SPEAKER
 The board's speaker, a playback device.
 
const struct pbl_audio *const MIC
 The board's microphone, a capture device.