Browse Source

[bsp][lpc55sxx]update: drv_spi

褚仕成 2 years ago
parent
commit
5f8b33f85d

+ 8 - 24
bsp/lpc55sxx/Libraries/drivers/drv_spi.c

@@ -75,13 +75,6 @@ static struct lpc_spi lpc_obj[] =
 #endif
 #endif
 };
 };
 
 
-
-struct lpc_sw_spi_cs
-{
-    rt_uint32_t pin;
-};
-
-
 static uint32_t lpc_get_spi_freq(SPI_Type *base)
 static uint32_t lpc_get_spi_freq(SPI_Type *base)
 {
 {
     uint32_t freq = 0;
     uint32_t freq = 0;
@@ -153,18 +146,13 @@ static rt_err_t lpc_spi_init(SPI_Type *base, struct rt_spi_configuration *cfg)
     return RT_EOK;
     return RT_EOK;
 }
 }
 
 
-rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_uint32_t pin)
+rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin)
 {
 {
     rt_err_t ret = RT_EOK;
     rt_err_t ret = RT_EOK;
 
 
     struct rt_spi_device *spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
     struct rt_spi_device *spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
-    struct lpc_sw_spi_cs *cs_pin = (struct lpc_sw_spi_cs *)rt_malloc(sizeof(struct lpc_sw_spi_cs));
-
-    cs_pin->pin = pin;
-    rt_pin_mode(pin, PIN_MODE_OUTPUT);
-    rt_pin_write(pin, PIN_HIGH);
 
 
-    ret = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
+    ret = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL);
 
 
     return ret;
     return ret;
 }
 }
@@ -174,8 +162,7 @@ rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name,
 static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg)
 static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *cfg)
 {
 {
     rt_err_t ret = RT_EOK;
     rt_err_t ret = RT_EOK;
-    struct lpc_spi *spi = RT_NULL;
-    spi = (struct lpc_spi *)(device->bus->parent.user_data);
+    struct lpc_spi *spi = rt_container_of(device->bus, struct lpc_spi, parent);
     ret = lpc_spi_init(spi->SPIx, cfg);
     ret = lpc_spi_init(spi->SPIx, cfg);
 
 
     return ret;
     return ret;
@@ -195,15 +182,12 @@ static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *m
 
 
     RT_ASSERT(device != RT_NULL);
     RT_ASSERT(device != RT_NULL);
     RT_ASSERT(device->bus != RT_NULL);
     RT_ASSERT(device->bus != RT_NULL);
-    RT_ASSERT(device->bus->parent.user_data != RT_NULL);
-
 
 
-    struct lpc_spi *spi = (struct lpc_spi *)(device->bus->parent.user_data);
-    struct lpc_sw_spi_cs *cs = device->parent.user_data;
+    struct lpc_spi *spi = rt_container_of(device->bus, struct lpc_spi, parent);
 
 
-    if(message->cs_take)
+    if(message->cs_take && (device->cs_pin != PIN_NONE))
     {
     {
-        rt_pin_write(cs->pin, PIN_LOW);
+        rt_pin_write(device->cs_pin, PIN_LOW);
     }
     }
 
 
     transfer.dataSize = message->length;
     transfer.dataSize = message->length;
@@ -245,9 +229,9 @@ static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *m
 
 
 
 
 
 
-    if(message->cs_release)
+    if(message->cs_release && (device->cs_pin != PIN_NONE))
     {
     {
-        rt_pin_write(cs->pin, PIN_HIGH);
+        rt_pin_write(device->cs_pin, PIN_HIGH);
     }
     }
 
 
     return message->length;
     return message->length;

+ 1 - 1
bsp/lpc55sxx/lpc55s69_nxp_evk/board/Kconfig

@@ -147,7 +147,7 @@ menu "On-chip Peripheral Drivers"
 
 
                 config BSP_USING_SPI8
                 config BSP_USING_SPI8
                     bool "Enable Flexcomm8 as High Speed SPI"
                     bool "Enable Flexcomm8 as High Speed SPI"
-                    default y
+                    default n
             endif
             endif
 
 
     menuconfig BSP_USING_SOFT_SPI
     menuconfig BSP_USING_SOFT_SPI

+ 4 - 4
bsp/stm32/libraries/HAL_Drivers/drv_qspi.c

@@ -210,9 +210,9 @@ static rt_ssize_t qspixfer(struct rt_spi_device *device, struct rt_spi_message *
     rt_int32_t length = message->length;
     rt_int32_t length = message->length;
 
 
 #ifdef BSP_QSPI_USING_SOFTCS
 #ifdef BSP_QSPI_USING_SOFTCS
-    if (message->cs_take && (device->parent.cs_pin != PIN_NONE))
+    if (message->cs_take && (device->cs_pin != PIN_NONE))
     {
     {
-        rt_pin_write(device->parent.cs_pin, PIN_LOW);
+        rt_pin_write(device->cs_pin, PIN_LOW);
     }
     }
 #endif
 #endif
 
 
@@ -264,9 +264,9 @@ static rt_ssize_t qspixfer(struct rt_spi_device *device, struct rt_spi_message *
 
 
 __exit:
 __exit:
 #ifdef BSP_QSPI_USING_SOFTCS
 #ifdef BSP_QSPI_USING_SOFTCS
-    if (message->cs_release && (device->parent.cs_pin != PIN_NONE))
+    if (message->cs_release && (device->cs_pin != PIN_NONE))
     {
     {
-        rt_pin_write(device->parent.cs_pin, PIN_HIGH);
+        rt_pin_write(device->cs_pin, PIN_HIGH);
     }
     }
 #endif
 #endif
     return result;
     return result;