diff options
| author | wdfk-prog <[email protected]> | 2024-10-04 17:31:30 +0800 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2024-10-06 00:02:53 -0400 |
| commit | 99503d3ff601e5d5052812776333edea0aaf06c9 (patch) | |
| tree | 20263fed75b266178eb43d6b895d7353b8039651 /components | |
| parent | 9bcb904a0b32b68999be75f171151ae1ecc9f10f (diff) | |
feat:[drivers][spi] rt_spi_bus_configure 添加 -RT_EBUSY 返回值,并增加说明注释
Diffstat (limited to 'components')
| -rw-r--r-- | components/drivers/include/drivers/dev_spi.h | 23 | ||||
| -rw-r--r-- | components/drivers/spi/dev_spi_core.c | 7 |
2 files changed, 28 insertions, 2 deletions
diff --git a/components/drivers/include/drivers/dev_spi.h b/components/drivers/include/drivers/dev_spi.h index d7eda39599..50ebb52416 100644 --- a/components/drivers/include/drivers/dev_spi.h +++ b/components/drivers/include/drivers/dev_spi.h @@ -184,7 +184,19 @@ rt_err_t rt_spi_bus_attach_device_cspin(struct rt_spi_device *device, rt_base_t cs_pin, void *user_data); -/* re-configure SPI bus */ +/** + * @brief Reconfigure the SPI bus for the specified device. + * @param device: Pointer to the SPI device attached to the SPI bus. + * @retval RT_EOK if the SPI device was successfully released and the bus was configured. + * RT_EBUSY if the SPI bus is currently in use; the new configuration will take effect once the device releases the bus. + * Other return values indicate failure to configure the SPI bus due to various reasons. + * @note If the configuration of the SPI device has been updated and requires bus re-initialization, + * call this function directly. This function will reconfigure the SPI bus for the specified device. + * If this is the first time to initialize the SPI device, please call rt_spi_configure or rt_qspi_configure. + * This function is used to reconfigure the SPI bus when the SPI device is already in use. + * For further details, refer to: + * https://github.com/RT-Thread/rt-thread/pull/8528 + */ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device); /** @@ -223,7 +235,14 @@ rt_err_t rt_spi_take(struct rt_spi_device *device); */ rt_err_t rt_spi_release(struct rt_spi_device *device); -/* set configuration on SPI device */ +/** + * @brief This function can set configuration on SPI device. + * @param device: the SPI device attached to SPI bus + * @param cfg: the configuration pointer. + * @retval RT_EOK on release SPI device successfully. + * RT_EBUSY is not an error condition and the configuration will take effect once the device has the bus + * others on taken SPI bus failed. + */ rt_err_t rt_spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg); diff --git a/components/drivers/spi/dev_spi_core.c b/components/drivers/spi/dev_spi_core.c index 9733a01a5e..e8525505a5 100644 --- a/components/drivers/spi/dev_spi_core.c +++ b/components/drivers/spi/dev_spi_core.c @@ -106,6 +106,13 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device) LOG_E("SPI device %s configuration failed", device->parent.parent.name); } } + else + { + /* RT_EBUSY is not an error condition and + * the configuration will take effect once the device has the bus + */ + return -RT_EBUSY; + } /* release lock */ rt_mutex_release(&(device->bus->lock)); |
