Skip to content

Commit

Permalink
[stm32][softspi]soft spi attach函数问题解决方案 (#6868)
Browse files Browse the repository at this point in the history
* [softspi]soft spi attach函数问题解决方案

* 更改函数名

> RT-Thread/rt-thread#6868
  • Loading branch information
wdfk-prog committed Jan 29, 2023
1 parent b401ad6 commit f5c548b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
20 changes: 11 additions & 9 deletions libraries/HAL_Drivers/drv_soft_spi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -30,23 +30,25 @@ static struct stm32_soft_spi_config soft_spi_config[] =
/**
* Attach the spi device to soft SPI bus, this function must be used after initialization.
*/
rt_err_t rt_hw_soft_spi_device_attach(const char *bus_name, const char *device_name, const char *pin_name)
rt_err_t rt_hw_softspi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin)
{

rt_err_t result;
struct rt_spi_device *spi_device;

/* initialize the cs pin && select the slave*/
rt_base_t cs_pin = rt_pin_get(pin_name);

rt_pin_mode(cs_pin,PIN_MODE_OUTPUT);
rt_pin_write(cs_pin,PIN_HIGH);
if(cs_pin != PIN_NONE)
{
rt_pin_mode(cs_pin,PIN_MODE_OUTPUT);
rt_pin_write(cs_pin,PIN_HIGH);
}

/* attach the device to soft spi bus*/
spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
RT_ASSERT(spi_device != RT_NULL);
spi_device->cs_pin = cs_pin;

result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, RT_NULL);
return result;
}

Expand Down Expand Up @@ -208,7 +210,7 @@ static struct rt_spi_bit_ops stm32_soft_spi_ops =
static struct stm32_soft_spi spi_obj[sizeof(soft_spi_config) / sizeof(soft_spi_config[0])];

/* Soft SPI initialization function */
int rt_soft_spi_init(void)
int rt_hw_softspi_init(void)
{
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct stm32_soft_spi);
rt_err_t result;
Expand All @@ -225,6 +227,6 @@ int rt_soft_spi_init(void)

return RT_EOK;
}
INIT_BOARD_EXPORT(rt_soft_spi_init);
INIT_BOARD_EXPORT(rt_hw_softspi_init);

#endif /* defined(RT_USING_SPI) && defined(RT_USING_SPI_BITOPS) && defined(RT_USING_PIN) */
4 changes: 2 additions & 2 deletions libraries/HAL_Drivers/drv_soft_spi.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2022, RT-Thread Development Team
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -50,7 +50,7 @@ struct stm32_soft_spi
}
#endif /* BSP_USING_SOFT_SPI2 */

rt_err_t rt_hw_soft_spi_device_attach(const char *bus_name, const char *device_name, const char *pin_name);
rt_err_t rt_hw_softspi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);
int rt_soft_spi_init(void);

#endif /* __DRV_SOFT_SPI__ */

0 comments on commit f5c548b

Please sign in to comment.