mirror of
https://github.com/espressif/esp-idf.git
synced 2025-11-02 05:36:31 +00:00
spi: add enum for spi dma channels
This commit is contained in:
@@ -29,8 +29,6 @@ extern "C"
|
||||
|
||||
//Maximum amount of bytes that can be put in one DMA descriptor
|
||||
#define SPI_MAX_DMA_LEN (4096-4)
|
||||
//Set the ``dma_chan`` to this, then driver will auto-alloc a DMA channel
|
||||
#define DMA_AUTO_CHAN (-2)
|
||||
|
||||
/**
|
||||
* Transform unsigned integer of length <= 32 bits to the format which can be
|
||||
@@ -74,6 +72,24 @@ extern "C"
|
||||
|
||||
#define SPICOMMON_BUSFLAG_NATIVE_PINS SPICOMMON_BUSFLAG_IOMUX_PINS
|
||||
|
||||
/**
|
||||
* @brief SPI DMA channels
|
||||
*/
|
||||
typedef enum {
|
||||
SPI_DMA_DISABLED = 0, ///< Do not enable DMA for SPI
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
SPI_DMA_CH1 = 1, ///< Enable DMA, select DMA Channel 1
|
||||
SPI_DMA_CH2 = 2, ///< Enable DMA, select DMA Channel 2
|
||||
#endif
|
||||
SPI_DMA_CH_AUTO = 3, ///< Enable DMA, channel is automatically selected by driver
|
||||
} spi_common_dma_t;
|
||||
|
||||
#if __cplusplus
|
||||
/* Needed for C++ backwards compatibility with earlier ESP-IDF where this argument is a bare 'int'. Can be removed in ESP-IDF 5 */
|
||||
typedef int spi_dma_chan_t;
|
||||
#else
|
||||
typedef spi_common_dma_t spi_dma_chan_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief This is a configuration structure for a SPI bus.
|
||||
@@ -107,13 +123,10 @@ 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 - DMA_AUTO_CHAN: allocate a free channel automatically;
|
||||
* - 1 or 2: assign a specific DMA channel;
|
||||
* - 0: non-dma mode;
|
||||
* 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 to DMA_AUTO_CHAN to let the driver to allocate the DMA channel.
|
||||
* @param dma_chan - Selecting a DMA channel for an SPI bus allows transactions on the bus with size only limited by the amount of internal memory.
|
||||
* - Selecting SPI_DMA_DISABLED limits the size of transactions.
|
||||
* - Set to SPI_DMA_DISABLED if only the SPI flash uses this bus.
|
||||
* - Set to SPI_DMA_CH_AUTO 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.
|
||||
@@ -129,7 +142,7 @@ typedef struct {
|
||||
* - ESP_ERR_NO_MEM if out of memory
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t spi_bus_initialize(spi_host_device_t host_id, const spi_bus_config_t *bus_config, int dma_chan);
|
||||
esp_err_t spi_bus_initialize(spi_host_device_t host_id, const spi_bus_config_t *bus_config, spi_dma_chan_t dma_chan);
|
||||
|
||||
/**
|
||||
* @brief Free a SPI bus
|
||||
|
||||
@@ -121,7 +121,7 @@ bool spicommon_periph_free(spi_host_device_t host);
|
||||
* @brief Alloc DMA for SPI Slave
|
||||
*
|
||||
* @param host_id SPI host ID
|
||||
* @param dma_chan DMA_AUTO_CHAN: auto dma allocate mode; 0: non-dma mode; 1 or 2: assign a specific DMA channel;
|
||||
* @param dma_chan DMA channel to be used
|
||||
* @param[out] out_actual_tx_dma_chan Actual TX DMA channel (if you choose to assign a specific DMA channel, this will be the channel you assigned before)
|
||||
* @param[out] out_actual_rx_dma_chan Actual RX DMA channel (if you choose to assign a specific DMA channel, this will be the channel you assigned before)
|
||||
*
|
||||
@@ -130,7 +130,7 @@ bool spicommon_periph_free(spi_host_device_t host);
|
||||
* - ESP_ERR_NO_MEM: No enough memory
|
||||
* - ESP_ERR_NOT_FOUND: There is no available DMA channel
|
||||
*/
|
||||
esp_err_t spicommon_slave_dma_chan_alloc(spi_host_device_t host_id, int dma_chan, uint32_t *out_actual_tx_dma_chan, uint32_t *out_actual_rx_dma_chan);
|
||||
esp_err_t spicommon_slave_dma_chan_alloc(spi_host_device_t host_id, spi_dma_chan_t dma_chan, uint32_t *out_actual_tx_dma_chan, uint32_t *out_actual_rx_dma_chan);
|
||||
|
||||
/**
|
||||
* @brief Free DMA for SPI Slave
|
||||
|
||||
@@ -93,13 +93,10 @@ 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 - DMA_AUTO_CHAN: allocate a free channel automatically;
|
||||
* - 1 or 2: assign a specific DMA channel;
|
||||
* - 0: non-dma mode;
|
||||
* 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 to DMA_AUTO_CHAN to let the driver to allocate the DMA channel.
|
||||
* @param dma_chan - Selecting a DMA channel for an SPI bus allows transactions on the bus with size only limited by the amount of internal memory.
|
||||
* - Selecting SPI_DMA_DISABLED limits the size of transactions.
|
||||
* - Set to SPI_DMA_DISABLED if only the SPI flash uses this bus.
|
||||
* - Set to SPI_DMA_CH_AUTO 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.
|
||||
@@ -115,7 +112,7 @@ struct spi_slave_transaction_t {
|
||||
* - ESP_ERR_NO_MEM if out of memory
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
esp_err_t spi_slave_initialize(spi_host_device_t host, const spi_bus_config_t *bus_config, const spi_slave_interface_config_t *slave_config, int dma_chan);
|
||||
esp_err_t spi_slave_initialize(spi_host_device_t host, const spi_bus_config_t *bus_config, const spi_slave_interface_config_t *slave_config, spi_dma_chan_t dma_chan);
|
||||
|
||||
/**
|
||||
* @brief Free a SPI bus claimed as a SPI slave interface
|
||||
|
||||
@@ -86,11 +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
|
||||
int dma_chan; /**< DMA channel to used.
|
||||
* - DMA_AUTO_CHAN: allocate a free channel automatically;
|
||||
* - 1 or 2: assign a specific DMA channel;
|
||||
* - 0: non-dma mode;
|
||||
*/
|
||||
spi_dma_chan_t dma_chan; ///< DMA channel to used.
|
||||
spi_slave_hd_callback_config_t cb_config; ///< Callback configuration
|
||||
} spi_slave_hd_slot_config_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user