|
@@ -37,6 +37,7 @@ const static char TAG[] = "AC101";
|
|
|
|
|
|
#define SPKOUT_EN ((1 << 11) | (1 << 7))
|
|
|
#define EAROUT_EN ((1 << 11) | (1 << 12) | (1 << 13))
|
|
|
+#define BIN(a,b,c,d) 0b##a##b##c##d
|
|
|
|
|
|
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
|
|
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
|
@@ -90,51 +91,52 @@ static bool init(int i2c_port_num, int i2s_num, i2s_config_t *i2s_config) {
|
|
|
ESP_LOGI(TAG, "DAC using I2C sda:%u, scl:%u", i2c_config.sda_io_num, i2c_config.scl_io_num);
|
|
|
|
|
|
res = i2c_write_reg(CHIP_AUDIO_RS, 0x123);
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ vTaskDelay(100 / portTICK_PERIOD_MS);
|
|
|
|
|
|
if (ESP_OK != res) {
|
|
|
ESP_LOGE(TAG, "AC101 reset failed! %d", res);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- i2c_write_reg(PLL_CTRL1, 0x014f);
|
|
|
-
|
|
|
- i2c_write_reg(PLL_CTRL2, 0x8600);
|
|
|
+
|
|
|
+ i2c_write_reg(PLL_CTRL1, BIN(0000,0001,0100,1111));
|
|
|
+ i2c_write_reg(PLL_CTRL2, BIN(1000,0110,0000,0000));
|
|
|
+
|
|
|
|
|
|
-
|
|
|
- i2c_write_reg(SYSCLK_CTRL, 0x8b08);
|
|
|
- i2c_write_reg(MOD_CLK_ENA, 0x800c);
|
|
|
- i2c_write_reg(MOD_RST_CTRL, 0x800c);
|
|
|
- i2c_write_reg(I2S_SR_CTRL, 0x7000);
|
|
|
+
|
|
|
+ i2c_write_reg(SYSCLK_CTRL, BIN(1010,1010,0000,1000));
|
|
|
+ i2c_write_reg(MOD_CLK_ENA, BIN(1000,0000,0000,1100));
|
|
|
+ i2c_write_reg(MOD_RST_CTRL, BIN(1000,0000,0000,1100));
|
|
|
+ i2c_write_reg(I2S_SR_CTRL, BIN(0111,0000,0000,0000));
|
|
|
|
|
|
-
|
|
|
- i2c_write_reg(I2S1LCK_CTRL, 0x8850);
|
|
|
- i2c_write_reg(I2S1_SDOUT_CTRL, 0xc000);
|
|
|
- i2c_write_reg(I2S1_SDIN_CTRL, 0xc000);
|
|
|
- i2c_write_reg(I2S1_MXR_SRC, 0x2200);
|
|
|
-
|
|
|
- i2c_write_reg(ADC_SRCBST_CTRL, 0xccc4);
|
|
|
- i2c_write_reg(ADC_SRC, 0x2020);
|
|
|
- i2c_write_reg(ADC_DIG_CTRL, 0x8000);
|
|
|
- i2c_write_reg(ADC_APC_CTRL, 0xbbc3);
|
|
|
+
|
|
|
+ i2c_write_reg(I2S1LCK_CTRL, BIN(1000,1000,0101,0000));
|
|
|
+ i2c_write_reg(I2S1_SDOUT_CTRL, BIN(1100,0000,0000,0000));
|
|
|
+ i2c_write_reg(I2S1_SDIN_CTRL, BIN(1100,0000,0000,0000));
|
|
|
+ i2c_write_reg(I2S1_MXR_SRC, BIN(0010,0010,0000,0000));
|
|
|
+ i2c_write_reg(ADC_SRCBST_CTRL, BIN(0100,0100,0100,0000));
|
|
|
+#if ENABLE_ADC
|
|
|
+ i2c_write_reg(ADC_SRC, BIN(0000,0100,0000,1000));
|
|
|
+ i2c_write_reg(ADC_DIG_CTRL, BIN(1000,0000,0000,0000));
|
|
|
+ i2c_write_reg(ADC_ANA_CTRL, BIN(1011, 1011,0000,0000));
|
|
|
+#else
|
|
|
+ i2c_write_reg(ADC_SRC, BIN(0000,0000,0000,0000));
|
|
|
+ i2c_write_reg(ADC_DIG_CTRL, BIN(0000,0000,0000,0000));
|
|
|
+ i2c_write_reg(ADC_ANA_CTRL, BIN(0011, 0011,0000,0000));
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
- i2c_write_reg(DAC_MXR_SRC, 0xcc00);
|
|
|
- i2c_write_reg(DAC_DIG_CTRL, 0x8000);
|
|
|
- i2c_write_reg(OMIXER_SR, 0x0081);
|
|
|
- i2c_write_reg(OMIXER_DACA_CTRL, 0xf080);
|
|
|
+ i2c_write_reg(DAC_MXR_SRC, BIN(1000,1000,0000,0000));
|
|
|
+ i2c_write_reg(DAC_DIG_CTRL, BIN(1000,0000,0000,0000));
|
|
|
+ i2c_write_reg(OMIXER_DACA_CTRL, BIN(1111,0000,0000,000));
|
|
|
+ i2c_write_reg(OMIXER_DACA_CTRL, BIN(1100,0000,0000,000));
|
|
|
+#if ENABLE_ADC
|
|
|
+ i2c_write_reg(OMIXER_SR, BIN(0000,0001,0000,0010));
|
|
|
+#else
|
|
|
+ i2c_write_reg(OMIXER_SR, BIN(0000,0101,0000,1010));
|
|
|
+#endif
|
|
|
|
|
|
-
|
|
|
- uint16_t regval = i2c_read_reg(I2S1LCK_CTRL);
|
|
|
- regval &= 0xffc3;
|
|
|
- regval |= (AC_MODE_SLAVE << 15);
|
|
|
- regval |= (BIT_LENGTH_16_BITS << 4);
|
|
|
- regval |= (AC_MODE_SLAVE << 2);
|
|
|
- res |= i2c_write_reg(I2S1LCK_CTRL, regval);
|
|
|
- res |= i2c_write_reg(I2S_SR_CTRL, SAMPLE_RATE_44100);
|
|
|
-
|
|
|
|
|
|
i2s_pin_config_t i2s_pin_config = (i2s_pin_config_t) { .bck_io_num = 27, .ws_io_num = 26,
|
|
|
.data_out_num = 25, .data_in_num = 35
|