Skip to content

Commit 94ec3c8

Browse files
committed
Merge branch 'bugfix/i2s_param_comments' into 'release/v3.0'
modify i2s param and comments See merge request idf/esp-idf!2266
2 parents ba13d28 + 7535dbc commit 94ec3c8

File tree

5 files changed

+56
-125
lines changed

5 files changed

+56
-125
lines changed

components/driver/i2s.c

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,12 @@ esp_err_t i2s_zero_dma_buffer(i2s_port_t i2s_num)
10101010
}
10111011
}
10121012
if (p_i2s_obj[i2s_num]->tx && p_i2s_obj[i2s_num]->tx->buf != NULL && p_i2s_obj[i2s_num]->tx->buf_size != 0) {
1013+
int bytes_left = 0;
1014+
bytes_left = (p_i2s_obj[i2s_num]->tx->buf_size - p_i2s_obj[i2s_num]->tx->rw_pos) % 4;
1015+
if (bytes_left) {
1016+
size_t zero_bytes = 0, bytes_written;
1017+
i2s_write(i2s_num, (void *)&zero_bytes, bytes_left, &bytes_written, portMAX_DELAY);
1018+
}
10131019
for (int i = 0; i < p_i2s_obj[i2s_num]->dma_buf_count; i++) {
10141020
memset(p_i2s_obj[i2s_num]->tx->buf[i], 0, p_i2s_obj[i2s_num]->tx->buf_size);
10151021
}
@@ -1119,9 +1125,9 @@ esp_err_t i2s_driver_uninstall(i2s_port_t i2s_num)
11191125
return ESP_OK;
11201126
}
11211127

1122-
int i2s_write_bytes(i2s_port_t i2s_num, const char *src, size_t size, TickType_t ticks_to_wait)
1128+
int i2s_write_bytes(i2s_port_t i2s_num, const void *src, size_t size, TickType_t ticks_to_wait)
11231129
{
1124-
int bytes_written = 0;
1130+
size_t bytes_written = 0;
11251131
int res = 0;
11261132
res = i2s_write(i2s_num, src, size, &bytes_written, ticks_to_wait);
11271133
if (res != ESP_OK) {
@@ -1131,15 +1137,16 @@ int i2s_write_bytes(i2s_port_t i2s_num, const char *src, size_t size, TickType_t
11311137
}
11321138
}
11331139

1134-
esp_err_t i2s_write(i2s_port_t i2s_num, const char *src, size_t size, int *bytes_written, TickType_t ticks_to_wait)
1140+
esp_err_t i2s_write(i2s_port_t i2s_num, const void *src, size_t size, size_t *bytes_written, TickType_t ticks_to_wait)
11351141
{
1136-
char *data_ptr;
1142+
char *data_ptr, *src_byte;
11371143
int bytes_can_write;
11381144
*bytes_written = 0;
11391145
I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_ERR_INVALID_ARG);
11401146
I2S_CHECK((size < I2S_MAX_BUFFER_SIZE), "size is too large", ESP_ERR_INVALID_ARG);
11411147
I2S_CHECK((p_i2s_obj[i2s_num]->tx), "tx NULL", ESP_ERR_INVALID_ARG);
11421148
xSemaphoreTake(p_i2s_obj[i2s_num]->tx->mux, (portTickType)portMAX_DELAY);
1149+
src_byte = (char *)src;
11431150
while (size > 0) {
11441151
if (p_i2s_obj[i2s_num]->tx->rw_pos == p_i2s_obj[i2s_num]->tx->buf_size || p_i2s_obj[i2s_num]->tx->curr_ptr == NULL) {
11451152
if (xQueueReceive(p_i2s_obj[i2s_num]->tx->queue, &p_i2s_obj[i2s_num]->tx->curr_ptr, ticks_to_wait) == pdFALSE) {
@@ -1154,17 +1161,17 @@ esp_err_t i2s_write(i2s_port_t i2s_num, const char *src, size_t size, int *bytes
11541161
if (bytes_can_write > size) {
11551162
bytes_can_write = size;
11561163
}
1157-
memcpy(data_ptr, src, bytes_can_write);
1164+
memcpy(data_ptr, src_byte, bytes_can_write);
11581165
size -= bytes_can_write;
1159-
src += bytes_can_write;
1166+
src_byte += bytes_can_write;
11601167
p_i2s_obj[i2s_num]->tx->rw_pos += bytes_can_write;
11611168
(*bytes_written) += bytes_can_write;
11621169
}
11631170
xSemaphoreGive(p_i2s_obj[i2s_num]->tx->mux);
11641171
return ESP_OK;
11651172
}
11661173

1167-
esp_err_t i2s_write_expand(i2s_port_t i2s_num, const char *src, int size, int src_bits, int aim_bits, int *bytes_written, TickType_t ticks_to_wait)
1174+
esp_err_t i2s_write_expand(i2s_port_t i2s_num, const void *src, size_t size, size_t src_bits, size_t aim_bits, size_t *bytes_written, TickType_t ticks_to_wait)
11681175
{
11691176
char *data_ptr;
11701177
int bytes_can_write, tail;
@@ -1227,9 +1234,9 @@ esp_err_t i2s_write_expand(i2s_port_t i2s_num, const char *src, int size, int sr
12271234
return ESP_OK;
12281235
}
12291236

1230-
int i2s_read_bytes(i2s_port_t i2s_num, char* dest, size_t size, TickType_t ticks_to_wait)
1237+
int i2s_read_bytes(i2s_port_t i2s_num, void *dest, size_t size, TickType_t ticks_to_wait)
12311238
{
1232-
int bytes_read = 0;
1239+
size_t bytes_read = 0;
12331240
int res = 0;
12341241
res = i2s_read(i2s_num, dest, size, &bytes_read, ticks_to_wait);
12351242
if (res != ESP_OK) {
@@ -1239,11 +1246,12 @@ int i2s_read_bytes(i2s_port_t i2s_num, char* dest, size_t size, TickType_t ticks
12391246
}
12401247
}
12411248

1242-
esp_err_t i2s_read(i2s_port_t i2s_num, char* dest, size_t size, int *bytes_read, TickType_t ticks_to_wait)
1249+
esp_err_t i2s_read(i2s_port_t i2s_num, void *dest, size_t size, size_t *bytes_read, TickType_t ticks_to_wait)
12431250
{
1244-
char *data_ptr;
1251+
char *data_ptr, *dest_byte;
12451252
int bytes_can_read;
12461253
*bytes_read = 0;
1254+
dest_byte = (char *)dest;
12471255
I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_ERR_INVALID_ARG);
12481256
I2S_CHECK((size < I2S_MAX_BUFFER_SIZE), "size is too large", ESP_ERR_INVALID_ARG);
12491257
I2S_CHECK((p_i2s_obj[i2s_num]->rx), "rx NULL", ESP_ERR_INVALID_ARG);
@@ -1261,90 +1269,40 @@ esp_err_t i2s_read(i2s_port_t i2s_num, char* dest, size_t size, int *bytes_read,
12611269
if (bytes_can_read > size) {
12621270
bytes_can_read = size;
12631271
}
1264-
memcpy(dest, data_ptr, bytes_can_read);
1272+
memcpy(dest_byte, data_ptr, bytes_can_read);
12651273
size -= bytes_can_read;
1266-
dest += bytes_can_read;
1274+
dest_byte += bytes_can_read;
12671275
p_i2s_obj[i2s_num]->rx->rw_pos += bytes_can_read;
12681276
(*bytes_read) += bytes_can_read;
12691277
}
12701278
xSemaphoreGive(p_i2s_obj[i2s_num]->rx->mux);
12711279
return ESP_OK;
12721280
}
12731281

1274-
int i2s_push_sample(i2s_port_t i2s_num, const char *sample, TickType_t ticks_to_wait)
1282+
int i2s_push_sample(i2s_port_t i2s_num, const void *sample, TickType_t ticks_to_wait)
12751283
{
1276-
int bytes_push = 0;
1284+
size_t bytes_push = 0;
12771285
int res = 0;
1278-
res = i2s_write_sample(i2s_num, sample, &bytes_push, ticks_to_wait);
1286+
I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_FAIL);
1287+
res = i2s_write(i2s_num, sample, p_i2s_obj[i2s_num]->bytes_per_sample, &bytes_push, ticks_to_wait);
12791288
if (res != ESP_OK) {
12801289
return ESP_FAIL;
12811290
} else {
12821291
return bytes_push;
12831292
}
12841293
}
12851294

1286-
esp_err_t i2s_write_sample(i2s_port_t i2s_num, const char *sample, int *sample_write, TickType_t ticks_to_wait)
1287-
{
1288-
int i;
1289-
char *data_ptr;
1290-
*sample_write = 0;
1291-
I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_ERR_INVALID_ARG);
1292-
if (p_i2s_obj[i2s_num]->tx->rw_pos == p_i2s_obj[i2s_num]->tx->buf_size || p_i2s_obj[i2s_num]->tx->curr_ptr == NULL) {
1293-
if (xQueueReceive(p_i2s_obj[i2s_num]->tx->queue, &p_i2s_obj[i2s_num]->tx->curr_ptr, ticks_to_wait) == pdFALSE) {
1294-
return *sample_write;
1295-
}
1296-
ESP_LOGD(I2S_TAG, "rw_pos: %d, buf_size: %d, curr_ptr: %d", p_i2s_obj[i2s_num]->tx->rw_pos, p_i2s_obj[i2s_num]->tx->buf_size, (int)p_i2s_obj[i2s_num]->tx->curr_ptr);
1297-
p_i2s_obj[i2s_num]->tx->rw_pos = 0;
1298-
}
1299-
data_ptr = (char*)p_i2s_obj[i2s_num]->tx->curr_ptr;
1300-
data_ptr += p_i2s_obj[i2s_num]->tx->rw_pos;
1301-
for (i = 0; i < p_i2s_obj[i2s_num]->bytes_per_sample * p_i2s_obj[i2s_num]->channel_num; i++) {
1302-
*data_ptr++ = *sample++;
1303-
(*sample_write) += 1;
1304-
}
1305-
p_i2s_obj[i2s_num]->tx->rw_pos += (*sample_write);
1306-
return ESP_OK;
1307-
1308-
}
1309-
1310-
int i2s_pop_sample(i2s_port_t i2s_num, char *sample, TickType_t ticks_to_wait)
1295+
int i2s_pop_sample(i2s_port_t i2s_num, void *sample, TickType_t ticks_to_wait)
13111296
{
1312-
int bytes_pop = 0;
1297+
size_t bytes_pop = 0;
13131298
int res = 0;
1314-
res = i2s_read_sample(i2s_num, sample, &bytes_pop, ticks_to_wait);
1299+
I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_FAIL);
1300+
res = i2s_read(i2s_num, sample, p_i2s_obj[i2s_num]->bytes_per_sample, &bytes_pop, ticks_to_wait);
13151301
if (res != ESP_OK) {
13161302
return ESP_FAIL;
13171303
} else {
13181304
return bytes_pop;
13191305
}
13201306
}
13211307

1322-
esp_err_t i2s_read_sample(i2s_port_t i2s_num, char *sample, int *sample_read, TickType_t ticks_to_wait)
1323-
{
1324-
int i;
1325-
*sample_read = 0;
1326-
char *data_ptr;
1327-
I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_ERR_INVALID_ARG);
1328-
if (p_i2s_obj[i2s_num]->rx->rw_pos == p_i2s_obj[i2s_num]->rx->buf_size || p_i2s_obj[i2s_num]->rx->curr_ptr == NULL) {
1329-
if (xQueueReceive(p_i2s_obj[i2s_num]->rx->queue, &p_i2s_obj[i2s_num]->rx->curr_ptr, ticks_to_wait) == pdFALSE) {
1330-
return *sample_read;
1331-
}
1332-
p_i2s_obj[i2s_num]->rx->rw_pos = 0;
1333-
}
1334-
data_ptr = (char*)p_i2s_obj[i2s_num]->rx->curr_ptr;
1335-
data_ptr += p_i2s_obj[i2s_num]->rx->rw_pos;
1336-
for (i = 0; i < p_i2s_obj[i2s_num]->bytes_per_sample; i++) {
1337-
*sample++ = *data_ptr++;
1338-
(*sample_read) += 1;
1339-
}
1340-
if (p_i2s_obj[i2s_num]->channel_num == 2) {
1341-
for (i = 0; i < p_i2s_obj[i2s_num]->bytes_per_sample; i++) {
1342-
*sample++ = *data_ptr++;
1343-
(*sample_read) += 1;
1344-
}
1345-
}
1346-
1347-
p_i2s_obj[i2s_num]->rx->rw_pos += p_i2s_obj[i2s_num]->bytes_per_sample * p_i2s_obj[i2s_num]->channel_num;
1348-
return ESP_OK;
1349-
}
13501308

components/driver/include/driver/i2s.h

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ esp_err_t i2s_driver_uninstall(i2s_port_t i2s_num);
269269
* - The amount of bytes written, if timeout, the result will be less than the size passed in.
270270
* - ESP_FAIL Parameter error
271271
*/
272-
int i2s_write_bytes(i2s_port_t i2s_num, const char *src, size_t size, TickType_t ticks_to_wait) __attribute__ ((deprecated));
272+
int i2s_write_bytes(i2s_port_t i2s_num, const void *src, size_t size, TickType_t ticks_to_wait) __attribute__ ((deprecated));
273273

274274
/**
275275
* @brief Write data to I2S DMA transmit buffer.
@@ -293,7 +293,7 @@ int i2s_write_bytes(i2s_port_t i2s_num, const char *src, size_t size, TickType_t
293293
* - ESP_OK Success
294294
* - ESP_ERR_INVALID_ARG Parameter error
295295
*/
296-
esp_err_t i2s_write(i2s_port_t i2s_num, const char *src, size_t size, int *bytes_written, TickType_t ticks_to_wait);
296+
esp_err_t i2s_write(i2s_port_t i2s_num, const void *src, size_t size, size_t *bytes_written, TickType_t ticks_to_wait);
297297

298298
/**
299299
* @brief Write data to I2S DMA transmit buffer while expanding the number of bits per sample. For example, expanding 16-bit PCM to 32-bit PCM.
@@ -324,7 +324,7 @@ esp_err_t i2s_write(i2s_port_t i2s_num, const char *src, size_t size, int *bytes
324324
* - ESP_OK Success
325325
* - ESP_ERR_INVALID_ARG Parameter error
326326
*/
327-
esp_err_t i2s_write_expand(i2s_port_t i2s_num, const char *src, int size, int src_bits, int aim_bits, int *bytes_written, TickType_t ticks_to_wait);
327+
esp_err_t i2s_write_expand(i2s_port_t i2s_num, const void *src, size_t size, size_t src_bits, size_t aim_bits, size_t *bytes_written, TickType_t ticks_to_wait);
328328

329329
/**
330330
* @brief Read data from I2S DMA receive buffer
@@ -336,7 +336,7 @@ esp_err_t i2s_write_expand(i2s_port_t i2s_num, const char *src, int size, int sr
336336
* - The amount of bytes read, if timeout, bytes read will be less than the size passed in
337337
* - ESP_FAIL Parameter error
338338
*/
339-
int i2s_read_bytes(i2s_port_t i2s_num, char* dest, size_t size, TickType_t ticks_to_wait) __attribute__ ((deprecated));
339+
int i2s_read_bytes(i2s_port_t i2s_num, void *dest, size_t size, TickType_t ticks_to_wait) __attribute__ ((deprecated));
340340

341341
/**
342342
* @brief Read data from I2S DMA receive buffer
@@ -358,69 +358,43 @@ int i2s_read_bytes(i2s_port_t i2s_num, char* dest, size_t size, TickType_t ticks
358358
* - ESP_OK Success
359359
* - ESP_ERR_INVALID_ARG Parameter error
360360
*/
361-
esp_err_t i2s_read(i2s_port_t i2s_num, char* dest, size_t size, int *bytes_read, TickType_t ticks_to_wait);
361+
esp_err_t i2s_read(i2s_port_t i2s_num, void *dest, size_t size, size_t *bytes_read, TickType_t ticks_to_wait);
362362

363363
/**
364364
* @brief Write a single sample to the I2S DMA TX buffer.
365365
*
366-
* This function is deprecated. Use 'i2s_write_sample' instead.
366+
* This function is deprecated. Use 'i2s_write' instead.
367367
* This definition will be removed in a future release.
368368
*
369-
* @return
370-
* - Number of bytes successfully pushed to DMA buffer, will be either zero or the size of configured sample buffer
371-
* - ESP_FAIL Parameter error
372-
*/
373-
int i2s_push_sample(i2s_port_t i2s_num, const char *sample, TickType_t ticks_to_wait) __attribute__ ((deprecated));
374-
375-
/**
376-
* @brief Write a single sample to the I2S DMA TX buffer.
377-
*
378-
* Size of the sample is determined by the channel_format (mono or stereo)) & bits_per_sample configuration (see i2s_config_t).
379-
*
380-
* @param i2s_num I2S_NUM_0, I2S_NUM_1
381-
*
382-
* @param sample Pointer to buffer containing sample to write. Size of buffer (in bytes) = (number of channels) * bits_per_sample / 8.
369+
* @param i2s_num I2S_NUM_0, I2S_NUM_1
383370
*
384-
* @param[out] sample_write Number of bytes successfully pushed to DMA buffer, will be either zero or the size of configured sample buffer.
371+
* @param sample Buffer to read data. Size of buffer (in bytes) = bits_per_sample / 8.
385372
*
386-
* @param ticks_to_wait Timeout in RTOS ticks. If space is not available in the DMA TX buffer within this period, no data is written and function returns 0.
373+
* @param ticks_to_wait Timeout in RTOS ticks. If a sample is not available in the DMA buffer within this period, no data is read and function returns zero.
387374
*
388375
* @return
389-
* - ESP_OK Success
390-
* - ESP_ERR_INVALID_ARG Parameter error
391-
*/
392-
esp_err_t i2s_write_sample(i2s_port_t i2s_num, const char *sample, int *sample_write, TickType_t ticks_to_wait);
393-
394-
/**
395-
* @brief Read a single sample from the I2S DMA RX buffer.
396-
*
397-
* This function is deprecated. Use 'i2s_read_sample' instead.
398-
* This definition will be removed in a future release.
399-
*
400-
* @return
401-
* - Number of bytes successfully read from DMA buffer, will be either zero or the size of configured sample buffer
376+
* - Number of bytes successfully pushed to DMA buffer, will be either zero or the size of configured sample buffer (in bytes).
402377
* - ESP_FAIL Parameter error
403378
*/
404-
int i2s_pop_sample(i2s_port_t i2s_num, char *sample, TickType_t ticks_to_wait) __attribute__ ((deprecated));
379+
int i2s_push_sample(i2s_port_t i2s_num, const void *sample, TickType_t ticks_to_wait) __attribute__ ((deprecated));
405380

406381
/**
407382
* @brief Read a single sample from the I2S DMA RX buffer.
408383
*
409-
* Size of the sample is determined by the channel_format (mono or stereo)) & bits_per_sample configuration (see i2s_config_t).
410-
*
411-
* @param i2s_num I2S_NUM_0, I2S_NUM_1
384+
* This function is deprecated. Use 'i2s_read' instead.
385+
* This definition will be removed in a future release.
412386
*
413-
* @param sample Buffer sample data will be read into. Size of buffer (in bytes) = (number of channels) * bits_per_sample / 8.
387+
* @param i2s_num I2S_NUM_0, I2S_NUM_1
414388
*
415-
* @param[out] sample_read Number of bytes successfully read from DMA buffer, will be either zero or the size of configured sample buffer.
389+
* @param sample Buffer to write data. Size of buffer (in bytes) = bits_per_sample / 8.
416390
*
417-
* @param ticks_to_wait Timeout in RTOS ticks. If a sample is not available in the DMA buffer within this period, no data is read and function returns zero.
391+
* @param ticks_to_wait Timeout in RTOS ticks. If a sample is not available in the DMA buffer within this period, no data is read and function returns zero.
418392
*
419393
* @return
420-
* - ESP_OK Success
421-
* - ESP_ERR_INVALID_ARG Parameter error
394+
* - Number of bytes successfully read from DMA buffer, will be either zero or the size of configured sample buffer (in bytes).
395+
* - ESP_FAIL Parameter error
422396
*/
423-
esp_err_t i2s_read_sample(i2s_port_t i2s_num, char *sample, int *sample_read, TickType_t ticks_to_wait);
397+
int i2s_pop_sample(i2s_port_t i2s_num, void *sample, TickType_t ticks_to_wait) __attribute__ ((deprecated));
424398

425399
/**
426400
* @brief Set sample rate used for I2S RX and TX.

examples/bluetooth/a2dp_sink/main/bt_app_av.c

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ void bt_app_a2d_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
5656

5757
void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len)
5858
{
59-
int i2s_write_len;
60-
i2s_write(0, (const char *)data, len, &i2s_write_len, portMAX_DELAY);
59+
size_t bytes_written;
60+
i2s_write(0, data, len, &bytes_written, portMAX_DELAY);
6161
if (++m_pkt_cnt % 100 == 0) {
6262
ESP_LOGE(BT_AV_TAG, "audio data pkt cnt %u", m_pkt_cnt);
6363
}

examples/peripherals/i2s/main/i2s_example_main.c

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static void setup_triangle_sine_waves(int bits)
2929
int *samples_data = malloc(((bits+8)/16)*SAMPLE_PER_CYCLE*4);
3030
unsigned int i, sample_val;
3131
double sin_float, triangle_float, triangle_step = (double) pow(2, bits) / SAMPLE_PER_CYCLE;
32-
int i2s_bytes_write = 0;
32+
size_t i2s_bytes_write = 0;
3333

3434
printf("\r\nTest bits=%d free mem=%d, written data=%d\n", bits, esp_get_free_heap_size(), ((bits+8)/16)*SAMPLE_PER_CYCLE*4);
3535

@@ -69,7 +69,7 @@ static void setup_triangle_sine_waves(int bits)
6969
// i2s_push_sample(0, &samples_data[i*2], 100);
7070
// }
7171
// or write
72-
i2s_write(I2S_NUM, (const char *)samples_data, ((bits+8)/16)*SAMPLE_PER_CYCLE*4, &i2s_bytes_write, 100);
72+
i2s_write(I2S_NUM, samples_data, ((bits+8)/16)*SAMPLE_PER_CYCLE*4, &i2s_bytes_write, 100);
7373

7474
free(samples_data);
7575
}

examples/peripherals/i2s_adc_dac/main/app_main.c

100644100755
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,15 +199,15 @@ void example_i2s_adc_dac(void*arg)
199199
example_i2s_init();
200200
int i2s_read_len = EXAMPLE_I2S_READ_LEN;
201201
int flash_wr_size = 0;
202-
int i2s_bytes_read = 0;
202+
size_t bytes_read, bytes_written;
203203

204204
//2. Record audio from ADC and save in flash
205205
#if RECORD_IN_FLASH_EN
206206
char* i2s_read_buff = (char*) calloc(i2s_read_len, sizeof(char));
207207
uint8_t* flash_write_buff = (uint8_t*) calloc(i2s_read_len, sizeof(char));
208208
while (flash_wr_size < FLASH_RECORD_SIZE) {
209209
//read data from I2S bus, in this case, from ADC.
210-
i2s_read(EXAMPLE_I2S_NUM, (char*) i2s_read_buff, i2s_read_len, &i2s_bytes_read, portMAX_DELAY);
210+
i2s_read(EXAMPLE_I2S_NUM, i2s_read_buff, i2s_read_len, &bytes_read, portMAX_DELAY);
211211
example_disp_buf((uint8_t*) i2s_read_buff, 64);
212212
//save original data from I2S(ADC) into flash.
213213
esp_partition_write(data_partition, flash_wr_size, i2s_read_buff, i2s_read_len);
@@ -222,7 +222,6 @@ void example_i2s_adc_dac(void*arg)
222222

223223
uint8_t* flash_read_buff = (uint8_t*) calloc(i2s_read_len, sizeof(char));
224224
uint8_t* i2s_write_buff = (uint8_t*) calloc(i2s_read_len, sizeof(char));
225-
int i2s_write_len = 0;
226225
while (1) {
227226

228227
//3. Read flash and replay the sound via DAC
@@ -233,7 +232,7 @@ void example_i2s_adc_dac(void*arg)
233232
//process data and scale to 8bit for I2S DAC.
234233
example_i2s_adc_data_scale(i2s_write_buff, flash_read_buff, FLASH_SECTOR_SIZE);
235234
//send data
236-
i2s_write(EXAMPLE_I2S_NUM, (char*) i2s_write_buff, FLASH_SECTOR_SIZE, &i2s_write_len, portMAX_DELAY);
235+
i2s_write(EXAMPLE_I2S_NUM, i2s_write_buff, FLASH_SECTOR_SIZE, &bytes_written, portMAX_DELAY);
237236
printf("playing: %d %%\n", rd_offset * 100 / flash_wr_size);
238237
}
239238
#endif
@@ -246,7 +245,7 @@ void example_i2s_adc_dac(void*arg)
246245
while (offset < tot_size) {
247246
int play_len = ((tot_size - offset) > (4 * 1024)) ? (4 * 1024) : (tot_size - offset);
248247
int i2s_wr_len = example_i2s_dac_data_scale(i2s_write_buff, (uint8_t*)(audio_table + offset), play_len);
249-
i2s_write(EXAMPLE_I2S_NUM, (const char*) i2s_write_buff, i2s_wr_len, &i2s_write_len, portMAX_DELAY);
248+
i2s_write(EXAMPLE_I2S_NUM, i2s_write_buff, i2s_wr_len, &bytes_written, portMAX_DELAY);
250249
offset += play_len;
251250
example_disp_buf((uint8_t*) i2s_write_buff, 32);
252251
}

0 commit comments

Comments
 (0)