Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(i2s): Use separate variables when reading and writing #10509

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions libraries/ESP_I2S/src/ESP_I2S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,17 +806,19 @@ bool I2SClass::configureRX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slo

size_t I2SClass::readBytes(char *buffer, size_t size) {
size_t bytes_read = 0;
size_t bytes_to_read = 0;
size_t total_size = 0;
last_error = ESP_FAIL;
if (rx_chan == NULL) {
return total_size;
}
while (total_size < size) {
bytes_read = size - total_size;
if (rx_transform_buf != NULL && bytes_read > I2S_READ_CHUNK_SIZE) {
bytes_read = I2S_READ_CHUNK_SIZE;
bytes_read = 0;
bytes_to_read = size - total_size;
if (rx_transform_buf != NULL && bytes_to_read > I2S_READ_CHUNK_SIZE) {
bytes_to_read = I2S_READ_CHUNK_SIZE;
}
I2S_ERROR_CHECK_RETURN(rx_fn(rx_chan, rx_transform_buf, (char *)(buffer + total_size), bytes_read, &bytes_read, _timeout), 0);
I2S_ERROR_CHECK_RETURN(rx_fn(rx_chan, rx_transform_buf, (char *)(buffer + total_size), bytes_to_read, &bytes_read, _timeout), 0);
total_size += bytes_read;
}
return total_size;
Expand All @@ -825,13 +827,15 @@ size_t I2SClass::readBytes(char *buffer, size_t size) {
size_t I2SClass::write(const uint8_t *buffer, size_t size) {
size_t written = 0;
size_t bytes_sent = 0;
size_t bytes_to_send = 0;
last_error = ESP_FAIL;
if (tx_chan == NULL) {
return written;
}
while (written < size) {
bytes_sent = size - written;
esp_err_t err = i2s_channel_write(tx_chan, (char *)(buffer + written), bytes_sent, &bytes_sent, _timeout);
bytes_sent = 0;
bytes_to_send = size - written;
esp_err_t err = i2s_channel_write(tx_chan, (char *)(buffer + written), bytes_to_send, &bytes_sent, _timeout);
setWriteError(err);
I2S_ERROR_CHECK_RETURN(err, written);
written += bytes_sent;
Expand Down
Loading