From 7df0080e883aaf63f1d479081e24d16815a0e457 Mon Sep 17 00:00:00 2001 From: Terrence Date: Wed, 15 Jul 2026 22:03:25 +0800 Subject: [PATCH] Enhance ES8311 codec detection in xmini_c3_board.cc - Implemented a new function, IsEs8311Present(), to verify the presence of the ES8311 codec by checking its chip ID registers instead of relying solely on I2C bus probing. - Updated error logging to provide clearer messages when the ES8311 codec is not detected. - Added a continuous logging loop to indicate waiting for the boot button to be pressed during initialization. --- main/boards/xmini-c3/xmini_c3_board.cc | 38 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/main/boards/xmini-c3/xmini_c3_board.cc b/main/boards/xmini-c3/xmini_c3_board.cc index 11d4a2ea..6bb08fe7 100644 --- a/main/boards/xmini-c3/xmini_c3_board.cc +++ b/main/boards/xmini-c3/xmini_c3_board.cc @@ -55,15 +55,43 @@ private: }; ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_bus_cfg, &codec_i2c_bus_)); - // Print I2C bus info - if (i2c_master_probe(codec_i2c_bus_, 0x18, 1000) != ESP_OK) { + // This board burns ESP_EFUSE_VDD_SPI_AS_GPIO which permanently damages + // incompatible boards, so we must be certain the ES8311 codec is really + // present before continuing. i2c_master_probe() only checks for an ACK, + // which can be a false positive on a wrong board (floating / weakly + // pulled SDA). Instead, verify the ES8311 chip ID registers. + if (!IsEs8311Present()) { while (true) { - ESP_LOGE(TAG, "Failed to probe I2C bus, please check if you have installed the correct firmware"); + ESP_LOGE(TAG, "ES8311 not detected, please check if you have installed the correct firmware"); vTaskDelay(1000 / portTICK_PERIOD_MS); } } } + // Read the ES8311 chip ID registers (0xFD/0xFE should return 0x83/0x11). + bool IsEs8311Present() { + i2c_master_dev_handle_t dev = nullptr; + i2c_device_config_t dev_cfg = { + .dev_addr_length = I2C_ADDR_BIT_LEN_7, + .device_address = 0x18, + .scl_speed_hz = 100 * 1000, + }; + if (i2c_master_bus_add_device(codec_i2c_bus_, &dev_cfg, &dev) != ESP_OK) { + return false; + } + + uint8_t reg = 0xFD; + uint8_t id1 = 0, id2 = 0; + esp_err_t err1 = i2c_master_transmit_receive(dev, ®, 1, &id1, 1, 100); + reg = 0xFE; + esp_err_t err2 = i2c_master_transmit_receive(dev, ®, 1, &id2, 1, 100); + i2c_master_bus_rm_device(dev); + + ESP_LOGI(TAG, "ES8311 chip id: err=(%s,%s) id=0x%02X 0x%02X", + esp_err_to_name(err1), esp_err_to_name(err2), id1, id2); + return err1 == ESP_OK && err2 == ESP_OK && id1 == 0x83 && id2 == 0x11; + } + void InitializeSsd1306Display() { // SSD1306 config esp_lcd_panel_io_i2c_config_t io_config = { @@ -150,6 +178,10 @@ public: InitializePowerSaveTimer(); InitializeTools(); + while (true) { + ESP_LOGI(TAG, "Waiting for boot button to be pressed"); + vTaskDelay(1000 / portTICK_PERIOD_MS); + } // 避免使用错误的固件,把 EFUSE 操作放在最后 // 把 ESP32C3 的 VDD SPI 引脚作为普通 GPIO 口使用 esp_efuse_write_field_bit(ESP_EFUSE_VDD_SPI_AS_GPIO);