4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-03-02 09:35:28 +08:00

[Infineon]Fix spi cs problem

This commit is contained in:
Rbb666 2023-03-29 18:48:01 +08:00 committed by guo
parent 9f38248f11
commit b8988227d7
2 changed files with 13 additions and 15 deletions

View File

@ -38,7 +38,7 @@ struct ifx_sw_spi_cs
#endif #endif
static struct ifx_spi spi_bus_obj[] = static struct ifx_spi spi_bus_obj[] =
{ {
#ifdef BSP_USING_SPI0 #if defined(BSP_USING_SPI0)
{ {
.bus_name = "spi0", .bus_name = "spi0",
.spi_bus = &spi_bus0, .spi_bus = &spi_bus0,
@ -47,7 +47,7 @@ static struct ifx_spi spi_bus_obj[] =
.mosi_pin = GET_PIN(0, 2), .mosi_pin = GET_PIN(0, 2),
}, },
#endif #endif
#ifdef BSP_USING_SPI3 #if defined(BSP_USING_SPI3)
{ {
.bus_name = "spi3", .bus_name = "spi3",
.spi_bus = &spi_bus3, .spi_bus = &spi_bus3,
@ -56,7 +56,7 @@ static struct ifx_spi spi_bus_obj[] =
.mosi_pin = GET_PIN(6, 0), .mosi_pin = GET_PIN(6, 0),
}, },
#endif #endif
#ifdef BSP_USING_SPI6 #if defined(BSP_USING_SPI6)
{ {
.bus_name = "spi6", .bus_name = "spi6",
.spi_bus = &spi_bus6, .spi_bus = &spi_bus6,
@ -69,7 +69,7 @@ static struct ifx_spi spi_bus_obj[] =
/* private rt-thread spi ops function */ /* private rt-thread spi ops function */
static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *configuration); static rt_err_t spi_configure(struct rt_spi_device *device, struct rt_spi_configuration *configuration);
static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message); static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message);
static struct rt_spi_ops ifx_spi_ops = static struct rt_spi_ops ifx_spi_ops =
{ {
@ -146,7 +146,7 @@ static rt_err_t spi_configure(struct rt_spi_device *device,
return RT_EOK; return RT_EOK;
} }
static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message) static rt_ssize_t spixfer(struct rt_spi_device *device, struct rt_spi_message *message)
{ {
RT_ASSERT(device != NULL); RT_ASSERT(device != NULL);
RT_ASSERT(message != NULL); RT_ASSERT(message != NULL);
@ -158,9 +158,9 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
struct ifx_sw_spi_cs *cs = device->parent.user_data; struct ifx_sw_spi_cs *cs = device->parent.user_data;
/* take CS */ /* take CS */
if (message->cs_take) if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE))
{ {
cyhal_gpio_write(cs->pin, PIN_LOW); cyhal_gpio_write(device->cs_pin, PIN_LOW);
LOG_D("spi take cs\n"); LOG_D("spi take cs\n");
} }
@ -185,12 +185,12 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
} }
} }
if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS)) if (message->cs_release && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE))
{ {
if (device->config.mode & RT_SPI_CS_HIGH) if (device->config.mode & RT_SPI_CS_HIGH)
cyhal_gpio_write(cs->pin, PIN_LOW); cyhal_gpio_write(device->cs_pin, PIN_LOW);
else else
cyhal_gpio_write(cs->pin, PIN_HIGH); cyhal_gpio_write(device->cs_pin, PIN_HIGH);
} }
return message->length; return message->length;

View File

@ -112,11 +112,6 @@ menu "On-chip Peripheral Drivers"
menuconfig BSP_USING_SPI0 menuconfig BSP_USING_SPI0
bool "Enable SPI0 BUS" bool "Enable SPI0 BUS"
default n default n
if BSP_USING_SPI0
config BSP_USING_SPI0_SAMPLE
bool "Enable SPI0 BUS Sample"
default n
endif
menuconfig BSP_USING_SPI3 menuconfig BSP_USING_SPI3
bool "Enable SPI3 BUS" bool "Enable SPI3 BUS"
default n default n
@ -125,6 +120,9 @@ menu "On-chip Peripheral Drivers"
bool "Enable SPI3 BUS Sample" bool "Enable SPI3 BUS Sample"
default n default n
endif endif
menuconfig BSP_USING_SPI6
bool "Enable SPI6 BUS"
default n
endif endif
menuconfig BSP_USING_ADC menuconfig BSP_USING_ADC