17static constexpr uint8_t REG_MODE_CONFIG = 0x00;
18static constexpr uint8_t REG_SDP_FORMAT = 0x01;
19static constexpr uint8_t REG_MUTE_CONTROL = 0x05;
20static constexpr uint8_t REG_STATE_CONTROL = 0x06;
21static constexpr uint8_t REG_GAIN = 0x08;
22static constexpr uint8_t MCLK_PULSES = 20;
29static constexpr GainEntry GAIN_TABLE[] = {
30 {1.0f, 0x11}, {3.5f, 0x13}, {18.0f, 0x21}, {20.5f, 0x23},
31 {22.5f, 0x06}, {24.5f, 0x41}, {25.0f, 0x07}, {27.0f, 0x43},
33static constexpr uint8_t GAIN_COUNT =
sizeof(GAIN_TABLE) /
sizeof(GAIN_TABLE[0]);
36static uint8_t nearest_gain_index(
float gain_db) {
38 for (uint8_t i = 1; i < GAIN_COUNT; i++) {
39 if (std::fabs(gain_db - GAIN_TABLE[i].db) < std::fabs(gain_db - GAIN_TABLE[best].db))
49 gpio_set_direction(mclk, GPIO_MODE_OUTPUT);
50 for (uint8_t i = 0; i < MCLK_PULSES; i++) {
51 gpio_set_level(mclk, 0);
53 gpio_set_level(mclk, 1);
58 const bool ok = this->
write_byte(REG_MODE_CONFIG, 0x01) && this->
write_byte(REG_STATE_CONTROL, 0x00) &&