Skip to content

Commit 0947a44

Browse files
yangpengyaRbb666
authored andcommitted
[bsp][hc32][spi]update rt_hw_spi_device_attach
1 parent 60d7198 commit 0947a44

File tree

7 files changed

+17
-42
lines changed

7 files changed

+17
-42
lines changed

bsp/hc32/ev_hc32f448_lqfp80/board/ports/drv_spi_flash.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
#define SPI_BUS_NAME "spi1"
2828
#define SPI_FLASH_DEVICE_NAME "spi10"
2929
#define SPI_FLASH_CHIP "w25q64"
30-
#define SPI_FLASH_SS_PORT GPIO_PORT_C
31-
#define SPI_FLASH_SS_PIN GPIO_PIN_07
30+
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
3231
/* Partition Name */
3332
#define FS_PARTITION_NAME "filesystem"
3433

@@ -55,7 +54,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name)
5554

5655
static int rt_hw_spi_flash_with_sfud_init(void)
5756
{
58-
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN);
57+
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN);
5958

6059
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
6160
{

bsp/hc32/ev_hc32f460_lqfp100_v2/board/ports/drv_spi_flash.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
#define SPI_BUS_NAME "spi3"
2727
#define SPI_FLASH_DEVICE_NAME "spi30"
2828
#define SPI_FLASH_CHIP "w25q64"
29-
#define SPI_FLASH_SS_PORT GPIO_PORT_C
30-
#define SPI_FLASH_SS_PIN GPIO_PIN_07
29+
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
3130
/* Partition Name */
3231
#define FS_PARTITION_NAME "filesystem"
3332

@@ -54,7 +53,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name)
5453

5554
static int rt_hw_spi_flash_with_sfud_init(void)
5655
{
57-
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN);
56+
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN);
5857

5958
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
6059
{

bsp/hc32/ev_hc32f4a0_lqfp176/board/ports/drv_spi_flash.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
#define SPI_BUS_NAME "spi1"
2727
#define SPI_FLASH_DEVICE_NAME "spi10"
2828
#define SPI_FLASH_CHIP "w25q64"
29-
#define SPI_FLASH_SS_PORT GPIO_PORT_C
30-
#define SPI_FLASH_SS_PIN GPIO_PIN_07
29+
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
3130
/* Partition Name */
3231
#define FS_PARTITION_NAME "filesystem"
3332

@@ -54,7 +53,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name)
5453

5554
static int rt_hw_spi_flash_with_sfud_init(void)
5655
{
57-
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN);
56+
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN);
5857

5958
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
6059
{

bsp/hc32/lckfb-hc32f4a0-lqfp100/board/ports/drv_spi_flash.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
#define SPI_BUS_NAME "spi1"
2727
#define SPI_FLASH_DEVICE_NAME "spi10"
2828
#define SPI_FLASH_CHIP "w25q64"
29-
#define SPI_FLASH_SS_PORT GPIO_PORT_A
30-
#define SPI_FLASH_SS_PIN GPIO_PIN_04
29+
#define SPI_FLASH_SS_PIN GET_PIN(A, 4)
3130
/* Partition Name */
3231
#define FS_PARTITION_NAME "filesystem"
3332

@@ -54,7 +53,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name)
5453

5554
static int rt_hw_spi_flash_with_sfud_init(void)
5655
{
57-
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN);
56+
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN);
5857

5958
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
6059
{

bsp/hc32/libraries/hc32_drivers/drv_spi.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ static rt_ssize_t hc32_spi_xfer(struct rt_spi_device *device, struct rt_spi_mess
508508
else
509509
rt_pin_write(device->cs_pin, PIN_LOW);
510510
}
511-
511+
512512
LOG_D("%s transfer prepare and start", spi_drv->config->bus_name);
513513
LOG_D("%s sendbuf: %X, recvbuf: %X, length: %d", spi_drv->config->bus_name,
514514
(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 =
637637
/**
638638
* Attach the spi device to SPI bus, this function must be used after initialization.
639639
*/
640-
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)
640+
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin)
641641
{
642642
RT_ASSERT(bus_name != RT_NULL);
643643
RT_ASSERT(device_name != RT_NULL);
644644

645645
rt_err_t result;
646646
struct rt_spi_device *spi_device;
647-
struct hc32_hw_spi_cs *cs_pin;
648-
stc_gpio_init_t stcGpioInit;
649-
650-
GPIO_StructInit(&stcGpioInit);
651-
stcGpioInit.u16PinState = PIN_STAT_SET;
652-
stcGpioInit.u16PinDir = PIN_DIR_OUT;
653-
stcGpioInit.u16PullUp = PIN_PU_ON;
654-
GPIO_Init(cs_gpio_port, cs_gpio_pin, &stcGpioInit);
655647

656648
/* attach the device to spi bus*/
657649
spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
658650
RT_ASSERT(spi_device != RT_NULL);
659-
cs_pin = (struct hc32_hw_spi_cs *)rt_malloc(sizeof(struct hc32_hw_spi_cs));
660-
RT_ASSERT(cs_pin != RT_NULL);
661-
cs_pin->port = cs_gpio_port;
662-
cs_pin->pin = cs_gpio_pin;
663-
result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
651+
652+
result = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL);
664653

665654
if (result != RT_EOK)
666655
{

bsp/hc32/libraries/hc32_drivers/drv_spi.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@
2424
extern "C" {
2525
#endif
2626

27-
28-
struct hc32_hw_spi_cs
29-
{
30-
rt_uint8_t port;
31-
rt_uint16_t pin;
32-
};
33-
3427
struct hc32_spi_irq_config
3528
{
3629
struct hc32_irq_config irq_config;
@@ -58,7 +51,7 @@ struct hc32_spi
5851
rt_uint16_t spi_dma_flag;
5952
};
6053

61-
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);
54+
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);
6255

6356

6457
#ifdef __cplusplus

bsp/hc32/platform/sfud/drv_spi_flash.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,17 @@
2727
#define SPI_BUS_NAME "spi1"
2828
#define SPI_FLASH_DEVICE_NAME "spi10"
2929
#define SPI_FLASH_CHIP "w25q64"
30-
#define SPI_FLASH_SS_PORT GPIO_PORT_C
31-
#define SPI_FLASH_SS_PIN GPIO_PIN_07
30+
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
3231
#elif defined(HC32F460)
3332
#define SPI_BUS_NAME "spi3"
3433
#define SPI_FLASH_DEVICE_NAME "spi30"
3534
#define SPI_FLASH_CHIP "w25q64"
36-
#define SPI_FLASH_SS_PORT GPIO_PORT_C
37-
#define SPI_FLASH_SS_PIN GPIO_PIN_07
35+
#define SPI_FLASH_SS_PIN GET_PIN(C, 7)
3836
#elif defined(HC32F472)
3937
#define SPI_BUS_NAME "spi1"
4038
#define SPI_FLASH_DEVICE_NAME "spi10"
4139
#define SPI_FLASH_CHIP "w25q64"
42-
#define SPI_FLASH_SS_PORT GPIO_PORT_B
43-
#define SPI_FLASH_SS_PIN GPIO_PIN_12
40+
#define SPI_FLASH_SS_PIN GET_PIN(B,12)
4441
#endif
4542
#define SPI_FLASH_CMD_ENABLE_RESET 0x66
4643
#define SPI_FLASH_CMD_RESET_DEVICE 0x99
@@ -72,7 +69,7 @@ static void rt_hw_spi_flash_reset(char *spi_dev_name)
7269

7370
static int rt_hw_spi_flash_with_sfud_init(void)
7471
{
75-
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PORT, SPI_FLASH_SS_PIN);
72+
rt_hw_spi_device_attach(SPI_BUS_NAME, SPI_FLASH_DEVICE_NAME, SPI_FLASH_SS_PIN);
7673

7774
if (RT_NULL == rt_sfud_flash_probe(SPI_FLASH_CHIP, SPI_FLASH_DEVICE_NAME))
7875
{

0 commit comments

Comments
 (0)