feat(es3c28p): fix audio speed-up, boost mic gain, and correct I2S pinout
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -34,8 +34,8 @@
|
||||
port = <I2S_NUM_0>;
|
||||
pin-bclk = <&gpio0 5 GPIO_FLAG_NONE>;
|
||||
pin-ws = <&gpio0 7 GPIO_FLAG_NONE>;
|
||||
pin-data-out = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
pin-data-in = <&gpio0 8 GPIO_FLAG_NONE>;
|
||||
pin-data-out = <&gpio0 8 GPIO_FLAG_NONE>;
|
||||
pin-data-in = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
pin-mclk = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
|
||||
@@ -113,13 +113,19 @@ static i2s_data_bit_width_t to_esp32_bits_per_sample(uint8_t bits) {
|
||||
}
|
||||
|
||||
static void get_esp32_std_config(Esp32I2sInternal* internal, const I2sConfig* config, i2s_std_config_t* std_cfg) {
|
||||
i2s_slot_mode_t slot_mode = I2S_SLOT_MODE_STEREO;
|
||||
if ((config->channel_left != I2S_CHANNEL_NONE && config->channel_right == I2S_CHANNEL_NONE) ||
|
||||
(config->channel_left == I2S_CHANNEL_NONE && config->channel_right != I2S_CHANNEL_NONE)) {
|
||||
slot_mode = I2S_SLOT_MODE_MONO;
|
||||
}
|
||||
|
||||
std_cfg->clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(config->sample_rate);
|
||||
std_cfg->slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), I2S_SLOT_MODE_STEREO);
|
||||
std_cfg->slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), slot_mode);
|
||||
|
||||
if (config->communication_format & I2S_FORMAT_STAND_MSB) {
|
||||
std_cfg->slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), I2S_SLOT_MODE_STEREO);
|
||||
std_cfg->slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), slot_mode);
|
||||
} else if (config->communication_format & (I2S_FORMAT_STAND_PCM_SHORT | I2S_FORMAT_STAND_PCM_LONG)) {
|
||||
std_cfg->slot_cfg = I2S_STD_PCM_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), I2S_SLOT_MODE_STEREO);
|
||||
std_cfg->slot_cfg = I2S_STD_PCM_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), slot_mode);
|
||||
}
|
||||
|
||||
if (config->channel_left != I2S_CHANNEL_NONE && config->channel_right == I2S_CHANNEL_NONE) {
|
||||
|
||||
@@ -62,6 +62,8 @@
|
||||
#include <driver/i2s_common.h>
|
||||
#include <driver/i2s_std.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/drivers/i2s_controller.h>
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32P4
|
||||
#include <driver/ppa.h>
|
||||
@@ -429,6 +431,20 @@ const esp_elfsym main_symbols[] {
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
|
||||
ESP_ELFSYM_EXPORT(i2s_channel_tune_rate),
|
||||
#endif
|
||||
// tactility/device.h (kernel device discovery)
|
||||
ESP_ELFSYM_EXPORT(device_find_by_name),
|
||||
ESP_ELFSYM_EXPORT(device_find_first_active_by_type),
|
||||
ESP_ELFSYM_EXPORT(device_is_ready),
|
||||
ESP_ELFSYM_EXPORT(device_lock),
|
||||
ESP_ELFSYM_EXPORT(device_try_lock),
|
||||
ESP_ELFSYM_EXPORT(device_unlock),
|
||||
// tactility/drivers/i2s_controller.h
|
||||
ESP_ELFSYM_EXPORT(i2s_controller_read),
|
||||
ESP_ELFSYM_EXPORT(i2s_controller_write),
|
||||
ESP_ELFSYM_EXPORT(i2s_controller_set_config),
|
||||
ESP_ELFSYM_EXPORT(i2s_controller_get_config),
|
||||
ESP_ELFSYM_EXPORT(i2s_controller_reset),
|
||||
ESP_ELFSYM_EXPORT(I2S_CONTROLLER_TYPE),
|
||||
// driver/i2s_std.h
|
||||
ESP_ELFSYM_EXPORT(i2s_channel_init_std_mode),
|
||||
ESP_ELFSYM_EXPORT(i2s_channel_reconfig_std_clock),
|
||||
|
||||
Reference in New Issue
Block a user