Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6e88445

Browse files
fix(i2s): Use separate variables when reading and writing (#10509)
1 parent dc1a49e commit 6e88445

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

‎libraries/ESP_I2S/src/ESP_I2S.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -806,17 +806,19 @@ bool I2SClass::configureRX(uint32_t rate, i2s_data_bit_width_t bits_cfg, i2s_slo
806806

807807
size_t I2SClass::readBytes(char *buffer, size_t size) {
808808
size_t bytes_read = 0;
809+
size_t bytes_to_read = 0;
809810
size_t total_size = 0;
810811
last_error = ESP_FAIL;
811812
if (rx_chan == NULL) {
812813
return total_size;
813814
}
814815
while (total_size < size) {
815-
bytes_read = size - total_size;
816-
if (rx_transform_buf != NULL && bytes_read > I2S_READ_CHUNK_SIZE) {
817-
bytes_read = I2S_READ_CHUNK_SIZE;
816+
bytes_read = 0;
817+
bytes_to_read = size - total_size;
818+
if (rx_transform_buf != NULL && bytes_to_read > I2S_READ_CHUNK_SIZE) {
819+
bytes_to_read = I2S_READ_CHUNK_SIZE;
818820
}
819-
I2S_ERROR_CHECK_RETURN(rx_fn(rx_chan, rx_transform_buf, (char *)(buffer + total_size), bytes_read, &bytes_read, _timeout), 0);
821+
I2S_ERROR_CHECK_RETURN(rx_fn(rx_chan, rx_transform_buf, (char *)(buffer + total_size), bytes_to_read, &bytes_read, _timeout), 0);
820822
total_size += bytes_read;
821823
}
822824
return total_size;
@@ -825,13 +827,15 @@ size_t I2SClass::readBytes(char *buffer, size_t size) {
825827
size_t I2SClass::write(const uint8_t *buffer, size_t size) {
826828
size_t written = 0;
827829
size_t bytes_sent = 0;
830+
size_t bytes_to_send = 0;
828831
last_error = ESP_FAIL;
829832
if (tx_chan == NULL) {
830833
return written;
831834
}
832835
while (written < size) {
833-
bytes_sent = size - written;
834-
esp_err_t err = i2s_channel_write(tx_chan, (char *)(buffer + written), bytes_sent, &bytes_sent, _timeout);
836+
bytes_sent = 0;
837+
bytes_to_send = size - written;
838+
esp_err_t err = i2s_channel_write(tx_chan, (char *)(buffer + written), bytes_to_send, &bytes_sent, _timeout);
835839
setWriteError(err);
836840
I2S_ERROR_CHECK_RETURN(err, written);
837841
written += bytes_sent;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /