fix i2s mix result and error code

This commit is contained in:
Zhang Zhao Xiang
2018-04-11 19:37:31 +08:00
parent f147a8d73d
commit 9deb58859c
5 changed files with 199 additions and 157 deletions
+78 -55
View File
@@ -263,42 +263,55 @@ esp_err_t i2s_driver_uninstall(i2s_port_t i2s_num);
/**
* @brief Write data to I2S DMA transmit buffer.
*
* @param i2s_num I2S_NUM_0, I2S_NUM_1
* This function is deprecated. Use 'i2s_write' instead.
* This definition will be removed in a future release.
*
* @param src Source address to write from
* @return
* - The amount of bytes written, if timeout, the result will be less than the size passed in.
* - ESP_FAIL Parameter error
*/
int i2s_write_bytes(i2s_port_t i2s_num, const void *src, size_t size, TickType_t ticks_to_wait) __attribute__ ((deprecated));
/**
* @brief Write data to I2S DMA transmit buffer.
*
* @param size Size of data in bytes
* @param i2s_num I2S_NUM_0, I2S_NUM_1
*
* @param ticks_to_wait TX buffer wait timeout in RTOS ticks. If this
* @param src Source address to write from
*
* @param size Size of data in bytes
*
* @param[out] bytes_written Number of bytes written, if timeout, the result will be less than the size passed in.
*
* @param ticks_to_wait TX buffer wait timeout in RTOS ticks. If this
* many ticks pass without space becoming available in the DMA
* transmit buffer, then the function will return (note that if the
* data is written to the DMA buffer in pieces, the overall operation
* may still take longer than this timeout.) Pass portMAX_DELAY for no
* timeout.
*
* Format of the data in source buffer is determined by the I2S
* configuration (see i2s_config_t).
*
* @return
* - Number of bytes written, if timeout occurred, bytes written will be less than the size passed.
* - ESP_FAIL Parameter error.
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
*/
int i2s_write_bytes(i2s_port_t i2s_num, const char *src, size_t size, TickType_t ticks_to_wait);
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);
/**
* @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.
*
* @param i2s_num I2S_NUM_0, I2S_NUM_1
* @param i2s_num I2S_NUM_0, I2S_NUM_1
*
* @param src Source address to write from
* @param src Source address to write from
*
* @param size Size of data in bytes
* @param size Size of data in bytes
*
* @param src_bits Source audio bit
* @param src_bits Source audio bit
*
* @param aim_bits Bit wanted, no more than 32, and must be greater than src_bits
* @param aim_bits Bit wanted, no more than 32, and must be greater than src_bits
*
* @param ticks_to_wait TX buffer wait timeout in RTOS ticks. If this
* @param[out] bytes_written Number of bytes written, if timeout, the result will be less than the size passed in.
*
* @param ticks_to_wait TX buffer wait timeout in RTOS ticks. If this
* many ticks pass without space becoming available in the DMA
* transmit buffer, then the function will return (note that if the
* data is written to the DMA buffer in pieces, the overall operation
@@ -309,67 +322,80 @@ int i2s_write_bytes(i2s_port_t i2s_num, const char *src, size_t size, TickType_t
* configuration (see i2s_config_t).
*
* @return
* - Number of bytes written, if timeout occurred, bytes written will be less than the size passed.
* - ESP_FAIL Parameter error.
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
*/
int i2s_write_expand(i2s_port_t i2s_num, const char *src, int size, int src_bits, int aim_bits, TickType_t ticks_to_wait);
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);
/**
* @brief Read data from I2S DMA receive buffer
*
* @param i2s_num I2S_NUM_0, I2S_NUM_1
* This function is deprecated. Use 'i2s_read' instead.
* This definition will be removed in a future release.
*
* @param dest Destination address to read into
* @return
* - 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, void *dest, size_t size, TickType_t ticks_to_wait) __attribute__ ((deprecated));
/**
* @brief Read data from I2S DMA receive buffer
*
* @param size Size of data in bytes
* @param i2s_num I2S_NUM_0, I2S_NUM_1
*
* @param ticks_to_wait RX buffer wait timeout in RTOS ticks. If this many ticks pass without bytes becoming available in the DMA receive buffer, then the function will return (note that if data is read from the DMA buffer in pieces, the overall operation may still take longer than this timeout.) Pass portMAX_DELAY for no timeout.
* @param dest Destination address to read into
*
* @param size Size of data in bytes
*
* @param[out] bytes_read Number of bytes read, if timeout, bytes read will be less than the size passed in.
*
* @param ticks_to_wait RX buffer wait timeout in RTOS ticks. If this many ticks pass without bytes becoming available in the DMA receive buffer, then the function will return (note that if data is read from the DMA buffer in pieces, the overall operation may still take longer than this timeout.) Pass portMAX_DELAY for no timeout.
*
* Format of the data in source buffer is determined by the I2S
* configuration (see i2s_config_t).
* @note If the built-in ADC mode is enabled, we should call i2s_adc_start and i2s_adc_stop around the whole reading process,
* to prevent the data getting corrupted.
*
* @return
* - Number of bytes read, if timeout occurred, bytes written will be less than the size passed.
* - ESP_FAIL Parameter error.
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
*/
int i2s_read_bytes(i2s_port_t i2s_num, char* dest, size_t size, 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 Push (write) a single sample to the I2S DMA TX buffer.
* @brief Write a single sample to the I2S DMA TX buffer.
*
* Size of the sample is determined by the channel_format (mono or stereo)) & bits_per_sample configuration (see i2s_config_t).
* This function is deprecated. Use 'i2s_write' instead.
* This definition will be removed in a future release.
*
* @param i2s_num I2S_NUM_0, I2S_NUM_1
* @param i2s_num I2S_NUM_0, I2S_NUM_1
*
* @param sample Pointer to buffer containing sample to write. Size of buffer (in bytes) = (number of channels) * bits_per_sample / 8.
* @param sample Buffer to read data. Size of buffer (in bytes) = bits_per_sample / 8.
*
* @param ticks_to_wait Push 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.
* @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.
*
* @return
* - Number of bytes successfully pushed to DMA buffer, will be either zero or the size of configured sample buffer.
* - ESP_FAIL Parameter error.
* - Number of bytes successfully pushed to DMA buffer, will be either zero or the size of configured sample buffer (in bytes).
* - ESP_FAIL Parameter error
*/
int i2s_push_sample(i2s_port_t i2s_num, const char *sample, TickType_t ticks_to_wait);
int i2s_push_sample(i2s_port_t i2s_num, const void *sample, TickType_t ticks_to_wait) __attribute__ ((deprecated));
/**
* @brief Pop (read) a single sample from the I2S DMA RX buffer.
* @brief Read a single sample from the I2S DMA RX buffer.
*
* Size of the sample is determined by the channel_format (mono or stereo)) & bits_per_sample configuration (see i2s_config_t).
* This function is deprecated. Use 'i2s_read' instead.
* This definition will be removed in a future release.
*
* @param i2s_num I2S_NUM_0, I2S_NUM_1
* @param i2s_num I2S_NUM_0, I2S_NUM_1
*
* @param sample Buffer sample data will be read into. Size of buffer (in bytes) = (number of channels) * bits_per_sample / 8.
* @param sample Buffer to write data. Size of buffer (in bytes) = bits_per_sample / 8.
*
* @param ticks_to_wait Pop 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.
* @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.
*
* @return
* - Number of bytes successfully read from DMA buffer, will be either zero or the size of configured sample buffer.
* - ESP_FAIL Parameter error.
* - 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, char *sample, TickType_t ticks_to_wait);
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.
@@ -385,7 +411,6 @@ int i2s_pop_sample(i2s_port_t i2s_num, char *sample, TickType_t ticks_to_wait);
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_FAIL I2s is not initialized
* - ESP_ERR_NO_MEM Out of memory
*/
esp_err_t i2s_set_sample_rates(i2s_port_t i2s_num, uint32_t rate);
@@ -445,7 +470,6 @@ esp_err_t i2s_zero_dma_buffer(i2s_port_t i2s_num);
*
* @return
* - ESP_OK Success
* - ESP_FAIL Not initialized
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_ERR_NO_MEM Out of memory
*/
@@ -454,7 +478,7 @@ esp_err_t i2s_set_clk(i2s_port_t i2s_num, uint32_t rate, i2s_bits_per_sample_t b
/**
* @brief Set built-in ADC mode for I2S DMA, this function will initialize ADC pad,
* and set ADC parameters.
* @param adc_unit SAR ADC unit index
* @param adc_unit SAR ADC unit index
* @param adc_channel ADC channel index
* @return
* - ESP_OK Success
@@ -469,10 +493,9 @@ esp_err_t i2s_set_adc_mode(adc_unit_t adc_unit, adc1_channel_t adc_channel);
*
* @param i2s_num i2s port index
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_ERR_INVALID_STATE driver state error
* - ESP_FAIL Internal driver error
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_ERR_INVALID_STATE Driver state error
*/
esp_err_t i2s_adc_enable(i2s_port_t i2s_num);
@@ -481,9 +504,9 @@ esp_err_t i2s_adc_enable(i2s_port_t i2s_num);
* @param i2s_num i2s port index
* @note This function would release the lock of ADC so that other tasks can use ADC.
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_ERR_INVALID_STATE driver state error
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_ERR_INVALID_STATE Driver state error
*/
esp_err_t i2s_adc_disable(i2s_port_t i2s_num);