pub unsafe extern "C" fn spi_bus_add_device(
host_id: spi_host_device_t,
dev_config: *const spi_device_interface_config_t,
handle: *mut spi_device_handle_t,
) -> esp_err_t
Expand description
@brief Allocate a device on a SPI bus
This initializes the internal structures for a device, plus allocates a CS pin on the indicated SPI master peripheral and routes it to the indicated GPIO. All SPI master devices have three CS pins and can thus control up to three devices.
@note On ESP32, due to the delay of GPIO matrix, the maximum frequency SPI Master can correctly samples the slave’s
output is lower than the case using IOMUX. Typical maximum frequency communicating with an ideal slave
without data output delay: 80MHz (IOMUX pins) and 26MHz (GPIO matrix pins). With the help of extra dummy
cycles in half-duplex mode, the delay can be compensated by setting input_delay_ns
in dev_config
structure
correctly.
There's no notable delay on chips other than ESP32.
@param host_id SPI peripheral to allocate device on
@param dev_config SPI interface protocol config for the device
@param handle Pointer to variable to hold the device handle
@return
- ESP_ERR_INVALID_ARG if parameter is invalid or configuration combination is not supported (e.g.
dev_config->post_cb
isn’t set while flag SPI_DEVICE_NO_RETURN_RESULT
is enabled)
- ESP_ERR_INVALID_STATE if selected clock source is unavailable or spi bus not initialized
- ESP_ERR_NOT_FOUND if host doesn’t have any free CS slots
- ESP_ERR_NO_MEM if out of memory
- ESP_OK on success