diff options
| author | wdfk-prog <[email protected]> | 2025-09-25 10:31:19 +0800 |
|---|---|---|
| committer | R b b666 <[email protected]> | 2025-09-25 11:41:58 +0800 |
| commit | 7e5cd483600a5ad66d3d9d3dc761281469bec69e (patch) | |
| tree | 0564e8c09981589bc0153485158d3b44b80cdfca /components/drivers/spi | |
| parent | da99c507c49cac27ba5a5a8315b0b0c8ac00ca2a (diff) | |
feat[SPI]: Add SPI device detach function
Diffstat (limited to 'components/drivers/spi')
| -rw-r--r-- | components/drivers/spi/dev_spi_core.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/components/drivers/spi/dev_spi_core.c b/components/drivers/spi/dev_spi_core.c index 53bb7284fa..42f829447a 100644 --- a/components/drivers/spi/dev_spi_core.c +++ b/components/drivers/spi/dev_spi_core.c @@ -123,6 +123,34 @@ rt_err_t rt_spi_bus_attach_device_cspin(struct rt_spi_device *device, return -RT_ERROR; } +rt_err_t rt_spi_bus_detach_device_cspin(struct rt_spi_device *device) +{ + rt_err_t result; + + RT_ASSERT(device != RT_NULL); + + result = rt_device_unregister(&device->parent); + if (result != RT_EOK) + { + LOG_E("Failed to unregister spi device, result: %d", result); + return result; + } + + if (device->bus != RT_NULL && device->bus->owner == device) + { + device->bus->owner = RT_NULL; + } + + if (device->cs_pin != PIN_NONE) + { + rt_pin_mode(device->cs_pin, PIN_MODE_INPUT); + } + + device->bus = RT_NULL; + + return RT_EOK; +} + rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device, const char *name, const char *bus_name, @@ -131,6 +159,11 @@ rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device, return rt_spi_bus_attach_device_cspin(device, name, bus_name, PIN_NONE, user_data); } +rt_err_t rt_spi_bus_detach_device(struct rt_spi_device *device) +{ + return rt_spi_bus_detach_device_cspin(device); +} + rt_err_t rt_spi_bus_configure(struct rt_spi_device *device) { rt_err_t result = -RT_ERROR; |
