From 36f8f266e9d774b7c80c9408d297022956373399 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sat, 5 Oct 2024 02:19:19 -0400 Subject: [PATCH] =?UTF-8?q?feat:[drivers][spi]=20rt=5Fspi=5Fconfigure=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=92=E6=96=A5=E4=BF=9D=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/drivers/spi/dev_qspi_core.c | 19 ++++++++++++++++--- components/drivers/spi/dev_spi_core.c | 19 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/components/drivers/spi/dev_qspi_core.c b/components/drivers/spi/dev_qspi_core.c index e56fd947d01..9dd2c5feb51 100644 --- a/components/drivers/spi/dev_qspi_core.c +++ b/components/drivers/spi/dev_qspi_core.c @@ -18,10 +18,23 @@ rt_err_t rt_qspi_configure(struct rt_qspi_device *device, struct rt_qspi_configu /* reset the CS pin */ if (device->parent.cs_pin != PIN_NONE) { - if (cfg->parent.mode & RT_SPI_CS_HIGH) - rt_pin_write(device->parent.cs_pin, PIN_LOW); + rt_err_t result = rt_mutex_take(&(device->parent.bus->lock), RT_WAITING_FOREVER); + if (result == RT_EOK) + { + if (cfg->parent.mode & RT_SPI_CS_HIGH) + { + rt_pin_write(device->parent.cs_pin, PIN_LOW); + } + else + { + rt_pin_write(device->parent.cs_pin, PIN_HIGH); + } + rt_mutex_release(&(device->parent.bus->lock)); + } else - rt_pin_write(device->parent.cs_pin, PIN_HIGH); + { + return result; + } } /* If the configurations are the same, we don't need to set again. */ diff --git a/components/drivers/spi/dev_spi_core.c b/components/drivers/spi/dev_spi_core.c index e8525505a5d..cef4d0a8115 100644 --- a/components/drivers/spi/dev_spi_core.c +++ b/components/drivers/spi/dev_spi_core.c @@ -135,10 +135,23 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device, /* reset the CS pin */ if (device->cs_pin != PIN_NONE) { - if (cfg->mode & RT_SPI_CS_HIGH) - rt_pin_write(device->cs_pin, PIN_LOW); + rt_err_t result = rt_mutex_take(&(device->bus->lock), RT_WAITING_FOREVER); + if (result == RT_EOK) + { + if (cfg->mode & RT_SPI_CS_HIGH) + { + rt_pin_write(device->cs_pin, PIN_LOW); + } + else + { + rt_pin_write(device->cs_pin, PIN_HIGH); + } + rt_mutex_release(&(device->bus->lock)); + } else - rt_pin_write(device->cs_pin, PIN_HIGH); + { + return result; + } } /* If the configurations are the same, we don't need to set again. */