Skip to content

Commit 3f3ba84

Browse files
committed
i2s: update driver
1 parent 6a404fd commit 3f3ba84

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

main/inc/device/i2s.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
#define DEVICE_I2S_C_
1010

1111
extern void i2s0_init(void);
12+
extern void i2s0_set_sample_rate(int rate);
1213

1314
#endif /* DEVICE_I2S_C_ */

main/src/device/i2s.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,38 @@
88
#include "freertos/FreeRTOS.h"
99
#include "driver/i2s.h"
1010

11+
static int i2s0_sample_rate = 44100;
12+
static int i2s0_bits_per_sample = 16;
13+
1114
void i2s0_init(void)
1215
{
13-
int use_apll = 0;
1416
esp_chip_info_t chip_info;
1517
esp_chip_info(&chip_info);
16-
// Don't use apll on rev0 chips
17-
if (chip_info.revision != 0) {
18-
use_apll = 1;
19-
}
2018
i2s_config_t i2s_config = {
2119
.mode = I2S_MODE_MASTER | I2S_MODE_TX, // Only TX
22-
.sample_rate = 44100,
23-
.bits_per_sample = 16,
24-
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, // 2-channels
2520
.communication_format = I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB,
21+
.use_apll = chip_info.revision, // Don't use apll on rev0 chips
22+
.sample_rate = i2s0_sample_rate,
23+
.bits_per_sample = i2s0_bits_per_sample,
24+
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT, // 2-channels
2625
.dma_buf_count = 8,
2726
.dma_buf_len = 64,
28-
.use_apll = use_apll,
2927
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1 // Interrupt level 1
3028
};
29+
i2s_driver_install(0, &i2s_config, 0, NULL);
3130
i2s_pin_config_t pin_config = {
3231
.bck_io_num = 22,
3332
.ws_io_num = 21,
3433
.data_out_num = 19,
3534
.data_in_num = -1 // Not used
3635
};
37-
i2s_driver_install(0, &i2s_config, 0, NULL);
3836
i2s_set_pin(0, &pin_config);
3937
}
38+
39+
void i2s0_set_sample_rate(int rate)
40+
{
41+
if (rate != i2s0_sample_rate) {
42+
i2s_set_sample_rates(0, rate);
43+
i2s0_sample_rate = rate;
44+
}
45+
}

0 commit comments

Comments
 (0)