From c7d822026839b9b453430f1a3c88597cba1d13da Mon Sep 17 00:00:00 2001 From: Rbb666 Date: Sat, 8 Feb 2025 11:19:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?[drivers/spi]=E4=BF=AE=E5=A4=8Dspi=20config?= =?UTF-8?q?ure=E4=BC=9A=E6=89=A7=E8=A1=8C=E4=B8=A4=E6=AC=A1=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/spi/dev_spi_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/drivers/spi/dev_spi_core.c b/components/drivers/spi/dev_spi_core.c index 3a3008d6e7c..881d6a8b247 100644 --- a/components/drivers/spi/dev_spi_core.c +++ b/components/drivers/spi/dev_spi_core.c @@ -140,7 +140,7 @@ rt_err_t rt_spi_bus_configure(struct rt_spi_device *device) result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER); if (result == RT_EOK) { - if (device->bus->owner == RT_NULL || device->bus->owner == device) + if (device->bus->owner == device) { /* current device is using, re-configure SPI bus */ result = device->bus->ops->configure(device, &device->config); From d17fafb2bf5ab594a4c7ca5b1c321d629bc669ee Mon Sep 17 00:00:00 2001 From: Rbb666 Date: Mon, 10 Feb 2025 12:35:52 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9rt=5Fspi=5Fbus=5Fconfigur?= =?UTF-8?q?e=E5=88=A4=E5=BF=99=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/spi/dev_spi_core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/drivers/spi/dev_spi_core.c b/components/drivers/spi/dev_spi_core.c index 881d6a8b247..4bf1db3150a 100644 --- a/components/drivers/spi/dev_spi_core.c +++ b/components/drivers/spi/dev_spi_core.c @@ -150,17 +150,17 @@ 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 - */ - result = -RT_EBUSY; - } /* release lock */ rt_mutex_release(&(device->bus->lock)); } + else + { + /* RT_EBUSY is not an error condition and + * the configuration will take effect once the device has the bus + */ + result = -RT_EBUSY; + } } else { From b5eeb6cb73741d5ea8d7898a8c6a9252d1b64d2a Mon Sep 17 00:00:00 2001 From: Rbb666 Date: Tue, 11 Feb 2025 11:53:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?SPI=E6=8C=82=E8=BD=BD=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E6=80=BB=E7=BA=BF=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E4=B8=BA=E7=A9=BA=E5=88=99=E8=B5=8B=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/spi/dev_spi_core.c | 28 ++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/components/drivers/spi/dev_spi_core.c b/components/drivers/spi/dev_spi_core.c index 4bf1db3150a..978d5a4161c 100644 --- a/components/drivers/spi/dev_spi_core.c +++ b/components/drivers/spi/dev_spi_core.c @@ -64,7 +64,7 @@ rt_err_t rt_spi_bus_register(struct rt_spi_bus *bus, for (int i = 0; i < pin_count; ++i) { bus->pins[i] = rt_pin_get_named_pin(&bus->parent, "cs", i, - RT_NULL, RT_NULL); + RT_NULL, RT_NULL); } } else if (pin_count == 0) @@ -103,12 +103,15 @@ rt_err_t rt_spi_bus_attach_device_cspin(struct rt_spi_device *device, { device->bus = (struct rt_spi_bus *)bus; + if (device->bus->owner == RT_NULL) + device->bus->owner = device; + /* initialize spidev device */ result = rt_spidev_device_init(device, name); if (result != RT_EOK) return result; - if(cs_pin != PIN_NONE) + if (cs_pin != PIN_NONE) { rt_pin_mode(cs_pin, PIN_MODE_OUTPUT); } @@ -150,17 +153,16 @@ 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 + */ + result = -RT_EBUSY; + } /* release lock */ rt_mutex_release(&(device->bus->lock)); } - else - { - /* RT_EBUSY is not an error condition and - * the configuration will take effect once the device has the bus - */ - result = -RT_EBUSY; - } } else { @@ -451,7 +453,7 @@ rt_err_t rt_spi_sendrecv16(struct rt_spi_device *device, } len = rt_spi_transfer(device, &senddata, recvdata, 2); - if(len < 0) + if (len < 0) { return (rt_err_t)len; } @@ -578,7 +580,7 @@ rt_err_t rt_spi_take(struct rt_spi_device *device) message.cs_take = 1; result = device->bus->ops->xfer(device, &message); - if(result < 0) + if (result < 0) { return (rt_err_t)result; } @@ -598,7 +600,7 @@ rt_err_t rt_spi_release(struct rt_spi_device *device) message.cs_release = 1; result = device->bus->ops->xfer(device, &message); - if(result < 0) + if (result < 0) { return (rt_err_t)result; }