From 0947a446582e17694255aff31542aaa1145af2c4 Mon Sep 17 00:00:00 2001 From: yangpeng Date: Wed, 4 Dec 2024 10:16:05 +0800 Subject: [PATCH] [bsp][hc32][spi]update rt_hw_spi_device_attach --- .../board/ports/drv_spi_flash.c | 5 ++--- .../board/ports/drv_spi_flash.c | 5 ++--- .../board/ports/drv_spi_flash.c | 5 ++--- .../board/ports/drv_spi_flash.c | 5 ++--- bsp/hc32/libraries/hc32_drivers/drv_spi.c | 19 ++++--------------- bsp/hc32/libraries/hc32_drivers/drv_spi.h | 9 +-------- bsp/hc32/platform/sfud/drv_spi_flash.c | 11 ++++------- 7 files changed, 17 insertions(+), 42 deletions(-) diff --git a/bsp/hc32/ev_hc32f448_lqfp80/board/ports/drv_spi_flash.c b/bsp/hc32/ev_hc32f448_lqfp80/board/ports/drv_spi_flash.c index 15d4e15ab84..f8e6d15ccc5 100644 --- a/bsp/hc32/ev_hc32f448_lqfp80/board/ports/drv_spi_flash.c +++ b/bsp/hc32/ev_hc32f448_lqfp80/board/ports/drv_spi_flash.c @@ -27,8 +27,7 @@ #define SPI_BUS_NAME "spi1" #define SPI_FLASH_DEVICE_NAME "spi10" #define SPI_FLASH_CHIP "w25q64" -#define SPI_FLASH_SS_PORT GPIO_PORT_C -#define SPI_FLASH_SS_PIN GPIO_PIN_07 +#define SPI_FLASH_SS_PIN GET_PIN(C, 7) /* Partition Name */ #define FS_PARTITION_NAME "filesystem" @@ -55,7 +54,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name) static int rt_hw_spi_flash_with_sfud_init(void) { - rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN); + rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN); if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME)) { diff --git a/bsp/hc32/ev_hc32f460_lqfp100_v2/board/ports/drv_spi_flash.c b/bsp/hc32/ev_hc32f460_lqfp100_v2/board/ports/drv_spi_flash.c index f4b73c4db82..741162100fe 100644 --- a/bsp/hc32/ev_hc32f460_lqfp100_v2/board/ports/drv_spi_flash.c +++ b/bsp/hc32/ev_hc32f460_lqfp100_v2/board/ports/drv_spi_flash.c @@ -26,8 +26,7 @@ #define SPI_BUS_NAME "spi3" #define SPI_FLASH_DEVICE_NAME "spi30" #define SPI_FLASH_CHIP "w25q64" -#define SPI_FLASH_SS_PORT GPIO_PORT_C -#define SPI_FLASH_SS_PIN GPIO_PIN_07 +#define SPI_FLASH_SS_PIN GET_PIN(C, 7) /* Partition Name */ #define FS_PARTITION_NAME "filesystem" @@ -54,7 +53,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name) static int rt_hw_spi_flash_with_sfud_init(void) { - rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN); + rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN); if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME)) { diff --git a/bsp/hc32/ev_hc32f4a0_lqfp176/board/ports/drv_spi_flash.c b/bsp/hc32/ev_hc32f4a0_lqfp176/board/ports/drv_spi_flash.c index 7f394c8f20e..e076d8c1ef5 100644 --- a/bsp/hc32/ev_hc32f4a0_lqfp176/board/ports/drv_spi_flash.c +++ b/bsp/hc32/ev_hc32f4a0_lqfp176/board/ports/drv_spi_flash.c @@ -26,8 +26,7 @@ #define SPI_BUS_NAME "spi1" #define SPI_FLASH_DEVICE_NAME "spi10" #define SPI_FLASH_CHIP "w25q64" -#define SPI_FLASH_SS_PORT GPIO_PORT_C -#define SPI_FLASH_SS_PIN GPIO_PIN_07 +#define SPI_FLASH_SS_PIN GET_PIN(C, 7) /* Partition Name */ #define FS_PARTITION_NAME "filesystem" @@ -54,7 +53,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name) static int rt_hw_spi_flash_with_sfud_init(void) { - rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN); + rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN); if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME)) { diff --git a/bsp/hc32/lckfb-hc32f4a0-lqfp100/board/ports/drv_spi_flash.c b/bsp/hc32/lckfb-hc32f4a0-lqfp100/board/ports/drv_spi_flash.c index afc14643cb9..3cedadeb5c4 100644 --- a/bsp/hc32/lckfb-hc32f4a0-lqfp100/board/ports/drv_spi_flash.c +++ b/bsp/hc32/lckfb-hc32f4a0-lqfp100/board/ports/drv_spi_flash.c @@ -26,8 +26,7 @@ #define SPI_BUS_NAME "spi1" #define SPI_FLASH_DEVICE_NAME "spi10" #define SPI_FLASH_CHIP "w25q64" -#define SPI_FLASH_SS_PORT GPIO_PORT_A -#define SPI_FLASH_SS_PIN GPIO_PIN_04 +#define SPI_FLASH_SS_PIN GET_PIN(A, 4) /* Partition Name */ #define FS_PARTITION_NAME "filesystem" @@ -54,7 +53,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name) static int rt_hw_spi_flash_with_sfud_init(void) { - rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN); + rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN); if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME)) { diff --git a/bsp/hc32/libraries/hc32_drivers/drv_spi.c b/bsp/hc32/libraries/hc32_drivers/drv_spi.c index 1a0acdc74aa..eccc05e544f 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_spi.c +++ b/bsp/hc32/libraries/hc32_drivers/drv_spi.c @@ -508,7 +508,7 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess else rt_pin_write(device->cs_pin, PIN_LOW); } - + LOG_D("%s transfer prepare and start", spi_drv->config->bus_name); LOG_D("%s sendbuf: %X, recvbuf: %X, length: %d", spi_drv->config->bus_name, (uint32_t)message->send_buf, (uint32_t)message->recv_buf, message->length); @@ -637,30 +637,19 @@ static const struct rt_spi_ops hc32_spi_ops = /** * Attach the spi device to SPI bus, this function must be used after initialization. */ -rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, uint8_t cs_gpio_port, uint16_t cs_gpio_pin) +rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin) { RT_ASSERT(bus_name != RT_NULL); RT_ASSERT(device_name != RT_NULL); rt_err_t result; struct rt_spi_device *spi_device; - struct hc32_hw_spi_cs *cs_pin; - stc_gpio_init_t stcGpioInit; - - GPIO_StructInit(&stcGpioInit); - stcGpioInit.u16PinState = PIN_STAT_SET; - stcGpioInit.u16PinDir = PIN_DIR_OUT; - stcGpioInit.u16PullUp = PIN_PU_ON; - GPIO_Init(cs_gpio_port, cs_gpio_pin, &stcGpioInit); /* attach the device to spi bus*/ spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device)); RT_ASSERT(spi_device != RT_NULL); - cs_pin = (struct hc32_hw_spi_cs *)rt_malloc(sizeof(struct hc32_hw_spi_cs)); - RT_ASSERT(cs_pin != RT_NULL); - cs_pin->port = cs_gpio_port; - cs_pin->pin = cs_gpio_pin; - result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin); + + result = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL); if (result != RT_EOK) { diff --git a/bsp/hc32/libraries/hc32_drivers/drv_spi.h b/bsp/hc32/libraries/hc32_drivers/drv_spi.h index 654a030bb60..5ac5ade8cdf 100644 --- a/bsp/hc32/libraries/hc32_drivers/drv_spi.h +++ b/bsp/hc32/libraries/hc32_drivers/drv_spi.h @@ -24,13 +24,6 @@ extern "C" { #endif - -struct hc32_hw_spi_cs -{ - rt_uint8_t port; - rt_uint16_t pin; -}; - struct hc32_spi_irq_config { struct hc32_irq_config irq_config; @@ -58,7 +51,7 @@ struct hc32_spi rt_uint16_t spi_dma_flag; }; -rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, uint8_t cs_gpio_port, uint16_t cs_gpio_pin); +rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin); #ifdef __cplusplus diff --git a/bsp/hc32/platform/sfud/drv_spi_flash.c b/bsp/hc32/platform/sfud/drv_spi_flash.c index 931de2a91d5..0af1c7cb189 100644 --- a/bsp/hc32/platform/sfud/drv_spi_flash.c +++ b/bsp/hc32/platform/sfud/drv_spi_flash.c @@ -27,20 +27,17 @@ #define SPI_BUS_NAME "spi1" #define SPI_FLASH_DEVICE_NAME "spi10" #define SPI_FLASH_CHIP "w25q64" - #define SPI_FLASH_SS_PORT GPIO_PORT_C - #define SPI_FLASH_SS_PIN GPIO_PIN_07 + #define SPI_FLASH_SS_PIN GET_PIN(C, 7) #elif defined(HC32F460) #define SPI_BUS_NAME "spi3" #define SPI_FLASH_DEVICE_NAME "spi30" #define SPI_FLASH_CHIP "w25q64" - #define SPI_FLASH_SS_PORT GPIO_PORT_C - #define SPI_FLASH_SS_PIN GPIO_PIN_07 + #define SPI_FLASH_SS_PIN GET_PIN(C, 7) #elif defined(HC32F472) #define SPI_BUS_NAME "spi1" #define SPI_FLASH_DEVICE_NAME "spi10" #define SPI_FLASH_CHIP "w25q64" - #define SPI_FLASH_SS_PORT GPIO_PORT_B - #define SPI_FLASH_SS_PIN GPIO_PIN_12 + #define SPI_FLASH_SS_PIN GET_PIN(B,12) #endif #define SPI_FLASH_CMD_ENABLE_RESET 0x66 #define SPI_FLASH_CMD_RESET_DEVICE 0x99 @@ -72,7 +69,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name) static int rt_hw_spi_flash_with_sfud_init(void) { - rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN); + rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN); if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME)) {