feat(es3c28p): fix audio speed-up, boost mic gain, and correct I2S pinout

This commit is contained in:
Adolfo Reyna
2026-06-23 18:32:33 -04:00
parent 94b5cdbfc4
commit 71cc05e276
4 changed files with 45 additions and 36 deletions
+18 -31
View File
@@ -15,37 +15,28 @@ using namespace tt::hal;
static constexpr auto* TAG = "ES3C28P";
static constexpr uint8_t ES8311_I2C_ADDR = 0x18;
static error_t initSound(::Device* i2c_controller) {
static error_t initCodec(::Device* i2c_controller) {
static constexpr uint8_t ENABLED_BULK_DATA[] = {
0x00, 0x80, // RESET/CSM POWER ON
0x01, 0x3F, // CLOCK_MANAGER/ use MCLK pin (external), all clocks on
0x02, 0x00, // CLOCK_MANAGER/ pre_div=1 pre_multi=1 (256x MCLK is correct ratio)
0x0D, 0x01, // SYSTEM/ Power up analog circuitry
0x12, 0x00, // SYSTEM/ power-up DAC
0x13, 0x10, // SYSTEM/ Enable output to HP drive
0x32, 0xBF, // DAC/ DAC volume (0xBF == ±0 dB)
0x37, 0x08, // DAC/ Bypass DAC equalizer
};
return i2c_controller_write_register_array(
i2c_controller,
ES8311_I2C_ADDR,
ENABLED_BULK_DATA,
sizeof(ENABLED_BULK_DATA),
pdMS_TO_TICKS(1000)
);
}
static error_t initMicrophone(::Device* i2c_controller) {
static constexpr uint8_t ENABLED_BULK_DATA[] = {
0x00, 0x80, // RESET/CSM POWER ON
0x01, 0x3F, // CLOCK_MANAGER/ use MCLK pin (external), all clocks on
0x02, 0x00, // CLOCK_MANAGER/ pre_div=1 pre_multi=1
0x03, 0x10, // CLOCK_MANAGER/ fs_mode=0, adc_osr=16
0x04, 0x10, // CLOCK_MANAGER/ dac_osr=16
0x05, 0x00, // CLOCK_MANAGER/ adc_div=1, dac_div=1
0x06, 0x03, // CLOCK_MANAGER/ bclk_div=4
0x07, 0x00, // CLOCK_MANAGER/ lrck_h=0
0x08, 0xFF, // CLOCK_MANAGER/ lrck_l=255 (div=256)
0x09, 0x0C, // SDPIN_REG09/ DAC SDP format = standard I2S, word length = 16-bit
0x0A, 0x0C, // SDPOUT_REG0A/ ADC SDP format = standard I2S, word length = 16-bit
0x0D, 0x01, // SYSTEM/ Power up analog circuitry
0x0E, 0x02, // SYSTEM/ Enable analog PGA, enable ADC modulator
0x14, 0x10, // ADC_REG14: select Mic1p-Mic1n / PGA GAIN (minimum)
0x17, 0xFF, // ADC_REG17: ADC_VOLUME (MAXGAIN)
0x1C, 0x6A, // ADC_REG1C: ADC Equalizer bypass, cancel DC offset
0x12, 0x00, // SYSTEM/ power-up DAC
0x13, 0x10, // SYSTEM/ Enable output to HP drive (headphone/speaker)
0x14, 0x1A, // SYSTEM/ Select Mic1p-Mic1n / max PGA gain (+30dB)
0x17, 0xFF, // ADC_REG17/ ADC Volume (MAXGAIN)
0x1C, 0x6A, // ADC_REG1C/ ADC Equalizer bypass, cancel DC offset in digital
0x32, 0xBF, // DAC_REG32/ DAC Volume (0xBF = 191)
0x37, 0x08, // DAC_REG37/ Bypass DAC equalizer
};
return i2c_controller_write_register_array(
@@ -78,13 +69,9 @@ static bool initBoot() {
// 3. Configure the ES8311 Codec over the I2C bus
auto* i2c_bus = device_find_by_name("i2c0");
if (i2c_bus != nullptr) {
error_t error = initSound(i2c_bus);
error_t error = initCodec(i2c_bus);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8311 speaker: %s", error_to_string(error));
}
error = initMicrophone(i2c_bus);
if (error != ERROR_NONE) {
LOG_E(TAG, "Failed to enable ES8311 microphone: %s", error_to_string(error));
LOG_E(TAG, "Failed to initialize ES8311 codec: %s", error_to_string(error));
}
} else {
LOG_E(TAG, "i2c0 bus not found, skipping ES8311 initialization");