spi: add dma channel auto-alloc feature on esp32

This commit is contained in:
Armando
2021-01-26 20:18:52 +08:00
committed by bot
parent 06f92003a3
commit 2e670bf6af
7 changed files with 120 additions and 84 deletions

View File

@@ -105,11 +105,11 @@ typedef struct {
*
* @param host_id SPI peripheral that controls this bus
* @param bus_config Pointer to a spi_bus_config_t struct specifying how the host should be initialized
* @param dma_chan Either channel 1 or 2, or 0 in the case when no DMA is required. Selecting a DMA channel
* for a SPI bus allows transfers on the bus to have sizes only limited by the amount of
* internal memory. Selecting no DMA channel (by passing the value 0) limits the amount of
* bytes transfered to a maximum of 64. Set to 0 if only the SPI flash uses
* this bus.
* @param dma_chan -1: auto dma allocate mode; 0: non-dma mode; 1 or 2: assign a specific DMA channel;
* Selecting a DMA channel for an SPI bus allows transfers on the bus to have sizes only
* limited by the amount of internal memory. Selecting no DMA channel (by passing the
* value 0) limits the amount of bytes transfered to a maximum of 64. Set to 0 if only
* the SPI flash uses this bus. Set -1 to let the driver to allocate the DMA channel.
*
* @warning If a DMA channel is selected, any transmit and receive buffer used should be allocated in
* DMA-capable memory.
@@ -120,7 +120,7 @@ typedef struct {
*
* @return
* - ESP_ERR_INVALID_ARG if configuration is invalid
* - ESP_ERR_INVALID_STATE if host already is in use
* - ESP_ERR_INVALID_STATE if host already is in use or DMA channel is not available
* - ESP_ERR_NO_MEM if out of memory
* - ESP_OK on success
*/

View File

@@ -115,19 +115,6 @@ bool spicommon_periph_in_use(spi_host_device_t host);
*/
bool spicommon_periph_free(spi_host_device_t host);
/**
* @brief Try to claim a SPI DMA channel
*
* Call this if your driver wants to use SPI with a DMA channnel.
*
* @param dma_chan channel to claim
*
* @note This public API is deprecated.
*
* @return True if success; false otherwise.
*/
bool spicommon_dma_chan_claim(int dma_chan);
/**
* @brief Check whether the spi DMA channel is in use.
*
@@ -151,12 +138,13 @@ bool spicommon_dma_chan_in_use(int dma_chan);
bool spicommon_dma_chan_free(int dma_chan);
/**
* @brief Connect SPI and DMA peripherals
* @brief Try to claim a SPI DMA channel and connect it with SPI peripherals
*
* @param host SPI peripheral
* @param dma_chan DMA channel
* @param host_id SPI host ID
* @param dma_chan -1: auto dma allocate mode; 0: non-dma mode; 1 or 2: assign a specific DMA channel;
* @param[out] out_actual_dma_chan Actual DMA channel (if you choose to assign a specific DMA channel, this will be the channel you assigned before)
*/
void spicommon_connect_spi_and_dma(spi_host_device_t host, int dma_chan);
esp_err_t spicommon_alloc_dma(spi_host_device_t host_id, int dma_chan, uint32_t *out_actual_dma_chan);
/**
* @brief Connect a SPI peripheral to GPIO pins

View File

@@ -93,9 +93,11 @@ struct spi_slave_transaction_t {
* @param host SPI peripheral to use as a SPI slave interface
* @param bus_config Pointer to a spi_bus_config_t struct specifying how the host should be initialized
* @param slave_config Pointer to a spi_slave_interface_config_t struct specifying the details for the slave interface
* @param dma_chan Either 1 or 2. A SPI bus used by this driver must have a DMA channel associated with
* it. The SPI hardware has two DMA channels to share. This parameter indicates which
* one to use.
* @param dma_chan -1: auto dma allocate mode; 0: non-dma mode; 1 or 2: assign a specific DMA channel;
* Selecting a DMA channel for an SPI bus allows transfers on the bus to have sizes only
* limited by the amount of internal memory. Selecting no DMA channel (by passing the
* value 0) limits the amount of bytes transfered to a maximum of 64. Set to 0 if only
* the SPI flash uses this bus. Set -1 to let the driver to allocate the DMA channel.
*
* @warning If a DMA channel is selected, any transmit and receive buffer used should be allocated in
* DMA-capable memory.
@@ -106,7 +108,7 @@ struct spi_slave_transaction_t {
*
* @return
* - ESP_ERR_INVALID_ARG if configuration is invalid
* - ESP_ERR_INVALID_STATE if host already is in use
* - ESP_ERR_INVALID_STATE if host already is in use or DMA channel is not available
* - ESP_ERR_NO_MEM if out of memory
* - ESP_OK on success
*/

View File

@@ -86,7 +86,7 @@ typedef struct {
uint32_t address_bits; ///< address field bits, multiples of 8 and at least 8.
uint32_t dummy_bits; ///< dummy field bits, multiples of 8 and at least 8.
uint32_t queue_size; ///< Transaction queue size. This sets how many transactions can be 'in the air' (queued using spi_slave_hd_queue_trans but not yet finished using spi_slave_hd_get_trans_result) at the same time
uint32_t dma_chan; ///< DMA channel used
uint32_t dma_chan; ///< DMA channel used. -1: auto dma allocate mode; 0: non-dma mode; 1 or 2: assign a specific DMA channel;
spi_slave_hd_callback_config_t cb_config; ///< Callback configuration
} spi_slave_hd_slot_config_t;