Skip to content

Commit

Permalink
fix zero dma buffer bug: must be 4-bytes aligned
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhang Zhao Xiang committed Apr 23, 2018
1 parent aeb4d8e commit 7535dbc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 9 additions & 3 deletions components/driver/i2s.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,12 @@ esp_err_t i2s_zero_dma_buffer(i2s_port_t i2s_num)
}
}
if (p_i2s_obj[i2s_num]->tx && p_i2s_obj[i2s_num]->tx->buf != NULL && p_i2s_obj[i2s_num]->tx->buf_size != 0) {
int bytes_left = 0;
bytes_left = (p_i2s_obj[i2s_num]->tx->buf_size - p_i2s_obj[i2s_num]->tx->rw_pos) % 4;
if (bytes_left) {
size_t zero_bytes = 0, bytes_written;
i2s_write(i2s_num, (void *)&zero_bytes, bytes_left, &bytes_written, portMAX_DELAY);
}
for (int i = 0; i < p_i2s_obj[i2s_num]->dma_buf_count; i++) {
memset(p_i2s_obj[i2s_num]->tx->buf[i], 0, p_i2s_obj[i2s_num]->tx->buf_size);
}
Expand Down Expand Up @@ -1228,7 +1234,7 @@ esp_err_t i2s_write_expand(i2s_port_t i2s_num, const void *src, size_t size, siz
return ESP_OK;
}

int i2s_read_bytes(i2s_port_t i2s_num, const void *dest, size_t size, TickType_t ticks_to_wait)
int i2s_read_bytes(i2s_port_t i2s_num, void *dest, size_t size, TickType_t ticks_to_wait)
{
size_t bytes_read = 0;
int res = 0;
Expand All @@ -1240,7 +1246,7 @@ int i2s_read_bytes(i2s_port_t i2s_num, const void *dest, size_t size, TickType_t
}
}

esp_err_t i2s_read(i2s_port_t i2s_num, const void *dest, size_t size, size_t *bytes_read, TickType_t ticks_to_wait)
esp_err_t i2s_read(i2s_port_t i2s_num, void *dest, size_t size, size_t *bytes_read, TickType_t ticks_to_wait)
{
char *data_ptr, *dest_byte;
int bytes_can_read;
Expand Down Expand Up @@ -1286,7 +1292,7 @@ int i2s_push_sample(i2s_port_t i2s_num, const void *sample, TickType_t ticks_to_
}
}

int i2s_pop_sample(i2s_port_t i2s_num, const void *sample, TickType_t ticks_to_wait)
int i2s_pop_sample(i2s_port_t i2s_num, void *sample, TickType_t ticks_to_wait)
{
size_t bytes_pop = 0;
int res = 0;
Expand Down
6 changes: 3 additions & 3 deletions components/driver/include/driver/i2s.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ esp_err_t i2s_write_expand(i2s_port_t i2s_num, const void *src, size_t size, siz
* - The amount of bytes read, if timeout, bytes read will be less than the size passed in
* - ESP_FAIL Parameter error
*/
int i2s_read_bytes(i2s_port_t i2s_num, const void *dest, size_t size, TickType_t ticks_to_wait) __attribute__ ((deprecated));
int i2s_read_bytes(i2s_port_t i2s_num, void *dest, size_t size, TickType_t ticks_to_wait) __attribute__ ((deprecated));

/**
* @brief Read data from I2S DMA receive buffer
Expand All @@ -358,7 +358,7 @@ int i2s_read_bytes(i2s_port_t i2s_num, const void *dest, size_t size, TickType_t
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
*/
esp_err_t i2s_read(i2s_port_t i2s_num, const void *dest, size_t size, size_t *bytes_read, TickType_t ticks_to_wait);
esp_err_t i2s_read(i2s_port_t i2s_num, void *dest, size_t size, size_t *bytes_read, TickType_t ticks_to_wait);

/**
* @brief Write a single sample to the I2S DMA TX buffer.
Expand Down Expand Up @@ -394,7 +394,7 @@ int i2s_push_sample(i2s_port_t i2s_num, const void *sample, TickType_t ticks_to_
* - Number of bytes successfully read from DMA buffer, will be either zero or the size of configured sample buffer (in bytes).
* - ESP_FAIL Parameter error
*/
int i2s_pop_sample(i2s_port_t i2s_num, const void *sample, TickType_t ticks_to_wait) __attribute__ ((deprecated));
int i2s_pop_sample(i2s_port_t i2s_num, void *sample, TickType_t ticks_to_wait) __attribute__ ((deprecated));

/**
* @brief Set sample rate used for I2S RX and TX.
Expand Down

0 comments on commit 7535dbc

Please sign in to comment.