| 199 | } |
| 200 | |
| 201 | static error_t initMicrophone(::Device* i2c_controller) { |
| 202 | // ES7210 quad-channel microphone ADC at 0x40. |
| 203 | // Register sequence from M5Unified (M5Unified.cpp, _microphone_enabled_cb_tab5). |
| 204 | // Configures 4-slot TDM output at 48kHz/16-bit with MIC1+MIC2 active and MICBIAS enabled. |
| 205 | static constexpr uint8_t ES7210_I2C_ADDR = 0x40; |
| 206 | static constexpr uint8_t INIT_DATA[] = { |
| 207 | 0x00, 0xFF, // RESET_CTL: full reset |
| 208 | 0x00, 0x41, // RESET_CTL: release reset, keep CSM active |
| 209 | 0x01, 0x1F, // CLK_ON_OFF: enable all clocks |
| 210 | 0x06, 0x00, // DIGITAL_PDN: power up all digital blocks |
| 211 | 0x07, 0x20, // ADC_OSR: OSR=256 |
| 212 | 0x08, 0x10, // MODE_CFG: I2S slave, TDM mode |
| 213 | 0x09, 0x30, // TCT0_CHPINI: chopper init period |
| 214 | 0x0A, 0x30, // TCT1_CHPINI |
| 215 | 0x20, 0x0A, // ADC34_HPF2 |
| 216 | 0x21, 0x2A, // ADC34_HPF1 |
| 217 | 0x22, 0x0A, // ADC12_HPF2 |
| 218 | 0x23, 0x2A, // ADC12_HPF1 |
| 219 | 0x02, 0xC1, // CLK_CTRL: MCLK from I2S, PLL off |
| 220 | 0x04, 0x01, // SDPOUT_CTL1: TDM output enable |
| 221 | 0x05, 0x00, // SDPOUT_CTL0 |
| 222 | 0x11, 0x60, // DBIAS: adjust reference voltage for P4 |
| 223 | 0x40, 0x42, // ANALOG_SYS: enable analog supply |
| 224 | 0x41, 0x70, // MICBIAS12: enable MICBIAS for MIC1+MIC2 |
| 225 | 0x42, 0x70, // MICBIAS34: enable MICBIAS for MIC3+MIC4 |
| 226 | 0x43, 0x1B, // MIC1_GAIN: +30 dB |
| 227 | 0x44, 0x1B, // MIC2_GAIN: +30 dB |
| 228 | 0x45, 0x00, // MIC3_GAIN: AEC ref, no gain |
| 229 | 0x46, 0x00, // MIC4_GAIN: AEC ref, no gain |
| 230 | 0x47, 0x00, // MIC1_LP |
| 231 | 0x48, 0x00, // MIC2_LP |
| 232 | 0x49, 0x00, // MIC3_LP |
| 233 | 0x4A, 0x00, // MIC4_LP |
| 234 | 0x4B, 0x00, // MIC12_PDN: power up MIC1+MIC2 |
| 235 | 0x4C, 0xFF, // MIC34_PDN: keep MIC3+MIC4 in power-down (AEC ref not needed) |
| 236 | 0x01, 0x14, // CLK_ON_OFF: final clock config |
| 237 | }; |
| 238 | |
| 239 | error_t error = i2c_controller_write_register_array( |
| 240 | i2c_controller, |
| 241 | ES7210_I2C_ADDR, |
| 242 | INIT_DATA, |
| 243 | sizeof(INIT_DATA), |
| 244 | pdMS_TO_TICKS(1000) |
| 245 | ); |
| 246 | if (error != ERROR_NONE) { |
| 247 | LOG_E(TAG, "Failed to init ES7210: %s", error_to_string(error)); |
| 248 | } |
| 249 | return error; |
| 250 | } |
| 251 | |
| 252 | static bool initBoot() { |
| 253 | auto* i2c0 = device_find_by_name("i2c0"); |
no test coverage detected