Function esp_idf_svc::hal::sys::spi_bus_add_device
source · pub unsafe extern "C" fn spi_bus_add_device(
host_id: u32,
dev_config: *const spi_device_interface_config_t,
handle: *mut *mut spi_device_t,
) -> i32
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 While in general, speeds up to 80MHz on the dedicated SPI pins and 40MHz on GPIO-matrix-routed pins are supported, full-duplex transfers routed over the GPIO matrix only support speeds up to 26MHz.
@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