Kleidos API Search

In development. It changes without notice.

Topic

Audio Drivers

The ES8311 codec, the ES7210 microphone converter, the AW88298 amplifier, and amplifiers switched by a power chip or a pin.

Part Boards
Es8311 M5StickS3. On the M5Cardputer ADV it is only powered down.
ES7210 CoreS3 SE, LILYGO T-Deck. It is only powered down: the firmware uses no microphone.
Aw88298 CoreS3 SE
Axp192Amp Core2 v1.3, whose amplifier hangs off the AXP192
GpioAmp An amplifier switched by a pin, or that is always on

These drivers set up a chip; the samples go through the I2S facade (GPIO & Buses). An amplifier is off when nothing plays.

See also
Sound: Catalog, Renderers & Speaker

Files

file src/drivers/audio/audio_amp_factory.cpp
Compile-time selection of the speaker amplifier driver.
file src/drivers/audio/audio_codec_factory.cpp
Compile-time selection of the I2S codec driver.
file src/drivers/audio/aw88298.h
Driver for the Awinic AW88298 I2S smart amplifier.
file src/drivers/audio/aw88298_regs.h
Register map and bring-up values of the AW88298 amplifier.
file src/drivers/audio/axp192_amp.h
Driver for an amplifier gated by the AXP192 PMIC GPIO2 line.
file src/drivers/audio/es7210.h
Power-down helper for the unused Everest ES7210 microphone-array ADC.
file src/drivers/audio/es7210_regs.h
Register map and power-down values for the unused ES7210 mic ADC.
file src/drivers/audio/es8311.h
Driver for the Everest ES8311 mono audio codec.
file src/drivers/audio/es8311_regs.h
Register map and bring-up values of the ES8311 codec.
file src/drivers/audio/gpio_amp.h
Driver for a GPIO-gated analog Class-D amplifier.
file src/drivers/audio/i_audio_amp.h
Abstract contract for the speaker power amplifier after the codec DAC.
file src/drivers/audio/i_audio_codec.h
Abstract contract for an external I2S audio codec (DAC/ADC chip).

Classes

class kleidos::drivers::audio::Aw88298
Awinic AW88298 mono Class-D amplifier with an embedded DAC sitting on the I2S data-out line. On the CoreS3 SE the chip's reset input RSTN is a pin of the AW9523B I/O expander, so the driver owns both the amplifier (I2C 0x36) and the expander bit that holds it in reset (I2C 0x58, P0.2). The I2S clocks must already run before setEnabled(true), as the amplifier locks its sample-rate divider from the bit clock. More about kleidos::drivers::audio::Aw88298
class kleidos::drivers::audio::Axp192Amp
Amplifier whose enable line is wired to GPIO2 of the AXP192 power chip: the NS4168 I2S amplifier of the Core2 v1.3. The amplifier embeds its own DAC and sits on the I2S data-out line; only its shutdown pin is on the power chip. The driver keeps its own small I2C view of the power chip and writes the function field of GPIO2_CTL (0x93) directly, apart from the power manager's instance. More about kleidos::drivers::audio::Axp192Amp
class kleidos::drivers::audio::Es8311
Everest ES8311 low-power mono codec driver (DAC playback + ADC capture). More about kleidos::drivers::audio::Es8311
struct kleidos::drivers::audio::es8311::RegWrite
One register write of a sequence. More about kleidos::drivers::audio::es8311::RegWrite
class kleidos::drivers::audio::GpioAmp
Generic enable-line amplifier for "dumb" analog Class-D parts (e.g. NS4150B, NS4168) whose shutdown pin is wired to a plain MCU GPIO. When the enable pin is negative the amplifier has no software gate (always on); the driver then behaves as a no-op so the rest of the audio path stays uniform. More about kleidos::drivers::audio::GpioAmp
class kleidos::drivers::audio::IAudioAmp
Speaker power-amplifier driver interface. More about kleidos::drivers::audio::IAudioAmp
struct kleidos::drivers::audio::CodecFormat
Sample format requested from a codec at begin(). More about kleidos::drivers::audio::CodecFormat
class kleidos::drivers::audio::IAudioCodec
External I2S audio-codec driver interface. More about kleidos::drivers::audio::IAudioCodec

Functions

boolkleidos::drivers::audio::powerDownEs7210 (int address)
Force an ES7210 microphone-array ADC into its lowest-power state.
boolkleidos::drivers::audio::powerDownEs8311 (uint8_t address)
Power down an ES8311 that no Es8311 instance drives.
boolkleidos::drivers::audio::registerEs8311Introspection (uint8_t address)
List the ES8311 with the introspection engine when it is on the board.
IAudioAmp *kleidos::drivers::audio::createAmp ()
Returns the board's amplifier instance, or nullptr when the board has no software-gated amplifier (always-on part or codec-internal drive). The concrete type is selected at compile time from the board's configuration. The returned pointer has static storage duration; callers must not delete it.
IAudioCodec *kleidos::drivers::audio::createCodec (uint8_t address)
Returns the codec driver selected for this build (fixed per board at build time) at the given I2C address, or nullptr if the board declares no I2S codec. The returned pointer is owned by the driver layer (static storage); callers must not delete it.

Variables

constexpr uint8_tkleidos::drivers::audio::aw88298::kRegSysCtrl
I2SEN / AMPPD / PWDN.
constexpr uint8_tkleidos::drivers::audio::aw88298::kRegSysCtrl2
RMSE / HAGCE / HDCCE / HMUTE.
constexpr uint8_tkleidos::drivers::audio::aw88298::kRegI2sCtrl
I2S format + sample-rate code.
constexpr uint8_tkleidos::drivers::audio::aw88298::kRegHagcCfg4
Volume.
constexpr uint8_tkleidos::drivers::audio::aw88298::kRegBstCtrl2
Boost mode.
constexpr uint16_tkleidos::drivers::audio::aw88298::kBoostDisabled
reg 0x61: boost mode disabled.
constexpr uint16_tkleidos::drivers::audio::aw88298::kSysCtrlEnable
reg 0x04: I2SEN=1 AMPPD=0 PWDN=0.
constexpr uint16_tkleidos::drivers::audio::aw88298::kSysCtrlDisable
reg 0x04: I2SEN=0 (mute output).
constexpr uint16_tkleidos::drivers::audio::aw88298::kSysCtrl2Clear
reg 0x05: no AGC/DCC/mute.
constexpr uint16_tkleidos::drivers::audio::aw88298::kVolumeFull
reg 0x0C: full volume.
constexpr uint16_tkleidos::drivers::audio::aw88298::kI2sFormatBase
reg 0x06 base: I2SBCK=0 (16*2 BCLK per frame).
constexpr uint8_tkleidos::drivers::audio::aw88298::kAw9523OutputPort0
Output port 0 register.
constexpr uint8_tkleidos::drivers::audio::aw88298::kAw9523ConfigPort0
Direction port 0 (0 = output).
constexpr uint8_tkleidos::drivers::audio::aw88298::kAw9523AmpMask
P0.2 drives the amp's RSTN (0 = reset).
constexpr uint8_tkleidos::drivers::audio::aw88298::kRateTable []
Rate-code buckets.
constexpr size_tkleidos::drivers::audio::aw88298::kRateTableSize
Table length.
constexpr uint8_tkleidos::drivers::audio::es7210::kRegReset
Reset / CSM control (used only as a presence probe).
constexpr uint8_tkleidos::drivers::audio::es7210::kRegClockOff
Master-clock and ADC-clock gating.
constexpr uint8_tkleidos::drivers::audio::es7210::kRegPowerDown
Global power-down bits.
constexpr uint8_tkleidos::drivers::audio::es7210::kRegAnalog
Analog power (VMID / LDO).
constexpr uint8_tkleidos::drivers::audio::es7210::kRegMic1Power
Mic 1 power.
constexpr uint8_tkleidos::drivers::audio::es7210::kRegMic2Power
Mic 2 power.
constexpr uint8_tkleidos::drivers::audio::es7210::kRegMic3Power
Mic 3 power.
constexpr uint8_tkleidos::drivers::audio::es7210::kRegMic4Power
Mic 4 power.
constexpr uint8_tkleidos::drivers::audio::es7210::kRegMic12Power
Mic 1/2 bias + ADC + PGA power.
constexpr uint8_tkleidos::drivers::audio::es7210::kRegMic34Power
Mic 3/4 bias + ADC + PGA power.
constexpr uint8_tkleidos::drivers::audio::es7210::kClockOffAll
reg 0x01: gate all ADC clocks.
constexpr uint8_tkleidos::drivers::audio::es7210::kPowerDownAll
reg 0x06: assert power-down bits.
constexpr uint8_tkleidos::drivers::audio::es7210::kAnalogPowerDown
reg 0x40: power down analog (VMID/LDO).
constexpr uint8_tkleidos::drivers::audio::es7210::kMicPowerDown
regs 0x47..0x4C: mic bias + ADC + PGA off.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegReset
CSM power on/off.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegClkManager01
Clock manager (MCLK source).
constexpr uint8_tkleidos::drivers::audio::es8311::kRegClkManager02
Clock manager (MULT_PRE).
constexpr uint8_tkleidos::drivers::audio::es8311::kRegSdpIn
Serial port, playback side (SDP_IN).
constexpr uint8_tkleidos::drivers::audio::es8311::kRegSystem0D
Analog circuitry power.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegSystem0E
PGA / ADC modulator.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegSystem12
DAC power.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegSystem13
HP/output drive enable.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegAdc14
Mic select / PGA gain.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegAdc17
ADC volume.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegAdc1C
ADC EQ bypass / DC offset.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegDacVolume
DAC volume (0xBF == 0 dB).
constexpr uint8_tkleidos::drivers::audio::es8311::kRegDac37
DAC EQ bypass.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegChipId1
Read-only ID high.
constexpr uint8_tkleidos::drivers::audio::es8311::kRegChipId2
Read-only ID low.
constexpr uint8_tkleidos::drivers::audio::es8311::kChipId1
Expected ID high byte.
constexpr uint8_tkleidos::drivers::audio::es8311::kChipId2
Expected ID low byte.
constexpr uint8_tkleidos::drivers::audio::es8311::kResetPowerOn
reg 0x00: CSM power on.
constexpr uint8_tkleidos::drivers::audio::es8311::kResetPowerDown
reg 0x00: CSM off, every block in reset (power-on value).
constexpr uint8_tkleidos::drivers::audio::es8311::kClk01SpeakerMode
MCLK=BCLK (DAC path).
constexpr uint8_tkleidos::drivers::audio::es8311::kClk01MicMode
MCLK=BCLK (ADC path).
constexpr uint8_tkleidos::drivers::audio::es8311::kClk01AllOff
reg 0x01: every clock gate off.
constexpr uint8_tkleidos::drivers::audio::es8311::kClk02MultPre3
reg 0x02: MULT_PRE=3 (MCLK from BCLK).
constexpr uint8_tkleidos::drivers::audio::es8311::kSdpI2s16Bit
reg 0x09/0x0A: I2S, 16-bit words, left slot, unmuted.
constexpr uint8_tkleidos::drivers::audio::es8311::kSystem0DPowerUp
reg 0x0D: analog circuitry on.
constexpr uint8_tkleidos::drivers::audio::es8311::kSystem0DPowerDown
reg 0x0D: analog circuitry off.
constexpr uint8_tkleidos::drivers::audio::es8311::kSystem0EAdcEnable
reg 0x0E: PGA + ADC modulator on.
constexpr uint8_tkleidos::drivers::audio::es8311::kSystem0EAdcDisable
reg 0x0E: PGA + ADC modulator off.
constexpr uint8_tkleidos::drivers::audio::es8311::kSystem12DacUp
reg 0x12: DAC power on.
constexpr uint8_tkleidos::drivers::audio::es8311::kSystem12DacDown
reg 0x12: DAC power down (power-on value).
constexpr uint8_tkleidos::drivers::audio::es8311::kSystem13OutputDrive
reg 0x13: HP/output drive enable.
constexpr uint8_tkleidos::drivers::audio::es8311::kSystem13OutputOff
reg 0x13: output drive off.
constexpr uint8_tkleidos::drivers::audio::es8311::kAdc14MicPgaMin
reg 0x14: minimum mic PGA gain.
constexpr uint8_tkleidos::drivers::audio::es8311::kAdc17VolumeMax
reg 0x17: ADC volume at full scale.
constexpr uint8_tkleidos::drivers::audio::es8311::kAdc1CEqBypass
reg 0x1C: ADC EQ bypass / DC offset default.
constexpr uint8_tkleidos::drivers::audio::es8311::kDacVolume0dB
reg 0x32: DAC volume at 0 dB.
constexpr uint8_tkleidos::drivers::audio::es8311::kDacVolumeMute
reg 0x32: DAC volume at -95.5 dB (mute).
constexpr uint8_tkleidos::drivers::audio::es8311::kDac37EqBypass
reg 0x37: DAC EQ bypass.
constexpr uint8_tkleidos::drivers::audio::es8311::kBitsPerSample
constexpr uint32_tkleidos::drivers::audio::es8311::kMinSampleRateHz
Lowest sample rate the codec's clock tree takes (datasheet: 8 to 96 kHz).
constexpr uint32_tkleidos::drivers::audio::es8311::kMaxSampleRateHz
Highest sample rate the codec's clock tree takes.
constexpr std::arraykleidos::drivers::audio::es8311::kSpeakerBringUp
constexpr size_tkleidos::drivers::audio::es8311::kBringUpVolumeIndex
Index of the DAC volume write in kSpeakerBringUp.
constexpr std::arraykleidos::drivers::audio::es8311::kPowerDown
constexpr size_tkleidos::drivers::audio::es8311::kPowerDownResetIndex
Index of the state machine's write in kPowerDown.
constexpr size_tkleidos::drivers::audio::es8311::kPowerDownAnalogIndex

Back to the top

Function Documentation

createAmp() #

IAudioAmp * kleidos::drivers::audio::createAmp()

Returns the board's amplifier instance, or nullptr when the board has no software-gated amplifier (always-on part or codec-internal drive). The concrete type is selected at compile time from the board's configuration. The returned pointer has static storage duration; callers must not delete it.

Returns
Pointer to the static amp instance, or nullptr if no gated amp exists.
See also
IAudioCodec, createCodec

createCodec() #

IAudioCodec * kleidos::drivers::audio::createCodec(uint8_t address)

Returns the codec driver selected for this build (fixed per board at build time) at the given I2C address, or nullptr if the board declares no I2S codec. The returned pointer is owned by the driver layer (static storage); callers must not delete it.

Parameters
NameDirectionMeaning
addressinI2C address of the codec chip.
Returns
Pointer to the static codec instance, or nullptr.
See also
IAudioAmp, createAmp

powerDownEs7210() #

bool kleidos::drivers::audio::powerDownEs7210(int address)

Force an ES7210 microphone-array ADC into its lowest-power state.

Kleidos never captures audio, but on the boards that carry an ES7210 (T-Deck, CoreS3 SE) the chip powers up with its clocks running and its analog supply on. This probes the device and, if present, writes the power-down sequence (microphone inputs off, analog off, clocks gated, global power-down) and registers the chip's register table for introspection. It only ever touches the ES7210's own address, so it does not disturb the other chips sharing the bus.

Parameters
NameDirectionMeaning
addressin7-bit ES7210 I2C address. A negative value is a no-op (board has no ES7210), returning true.
Return values
ValueMeaning
trueThe chip was absent (nothing to do) or powered down successfully.
falseThe chip acknowledged but a power-down register write failed.

powerDownEs8311() #

bool kleidos::drivers::audio::powerDownEs8311(uint8_t address)

Power down an ES8311 that no Es8311 instance drives.

For a codec whose supply outlives the firmware's hold on it: on the M5Cardputer ADV the chip keeps its supply while the board sleeps, and keeps whatever state the last firmware (another image, or this one before a crash) left it in. The sleep path calls this whether or not the speaker HAL ever started the codec. It probes the chip-id pair 0xFD / 0xFE and, when it matches, writes es8311::kPowerDown, every step of it, which leaves the chip as it reads at power-on. It touches only the codec's own address, so the keyboard and IMU sharing the bus are left alone.

Parameters
NameDirectionMeaning
addressin7-bit ES8311 I2C address.
Return values
ValueMeaning
trueThe chip did not answer (nothing to do) or was powered down.
falseAnother chip answered at address, or a power-down write failed.

registerEs8311Introspection() #

bool kleidos::drivers::audio::registerEs8311Introspection(uint8_t address)

List the ES8311 with the introspection engine when it is on the board.

Reads the chip-id pair 0xFD / 0xFE at address and, when it matches, registers the codec's register table. It writes nothing to the chip. Call it once during single-threaded board bring-up, as the registry asks: the codec driver itself starts only with the first tone, and not at all while the sound setting is off.

Parameters
NameDirectionMeaning
addressin7-bit ES8311 I2C address.
Return values
ValueMeaning
trueThe chip answered with its id and its table is registered.
falseNo ES8311 at address, the address is not the one the table reads through, or the registry refused the table.

Back to the top

Variable Documentation

kBitsPerSample #

uint8_t kleidos::drivers::audio::es8311::kBitsPerSample
constexpr

The only sample width the clock scheme serves: two 16-bit slots per frame are the 32 bit clocks MULT_PRE=3 multiplies to 256 times the sample rate.

kPowerDown #

std::array kleidos::drivers::audio::es8311::kPowerDown
constexpr

The power-down, written in this order: the DAC volume to mute first, so nothing that still reaches the output is heard, then the output driver, the DAC and the microphone PGA and ADC modulator off, then the state machine off with every block held in reset, and only then the analog circuitry and every clock gate off. The analog write comes after the state machine's: while the state machine runs it owns SYSTEM3's bias and reference bits, and a 0xFC written then read back 0x84 on a Cardputer ADV, its bias generators left on; written after, it holds. The sequence leaves the codec as it reads at power-on (RESET 0x1F, SYSTEM3 0xFC, SYSTEM8 0x02), whatever state it was in before, so the same sequence serves a codec the driver started and one it never did.

kPowerDownAnalogIndex #

size_t kleidos::drivers::audio::es8311::kPowerDownAnalogIndex
constexpr

Index of the analog power-down in kPowerDown, which must follow the state machine's write.

kSpeakerBringUp #

std::array kleidos::drivers::audio::es8311::kSpeakerBringUp
constexpr

The speaker's bring-up, written in this order once the bit clock runs: state machine on, master clock from the bit clock times 8, the playback port at I2S 16-bit, analog circuitry, DAC and output driver on, the DAC volume at 0 dB and its equalizer bypassed. The driver writes its own level over the volume entry, the one at kBringUpVolumeIndex.

Back to the top