parent
65f1804005
commit
7ff64c1cfd
|
@ -85,9 +85,6 @@ static rt_err_t stm32_spi_init(struct stm32_spi *spi_drv, struct rt_spi_configur
|
|||
RT_ASSERT(spi_drv != RT_NULL);
|
||||
RT_ASSERT(cfg != RT_NULL);
|
||||
|
||||
rt_pin_mode(cfg->cs_pin, PIN_MODE_OUTPUT);
|
||||
rt_pin_write(cfg->cs_pin, PIN_HIGH);
|
||||
|
||||
SPI_HandleTypeDef *spi_handle = &spi_drv->handle;
|
||||
|
||||
if (cfg->mode & RT_SPI_SLAVE)
|
||||
|
@ -299,12 +296,12 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
|
|||
struct stm32_spi *spi_drv = rt_container_of(device->bus, struct stm32_spi, spi_bus);
|
||||
SPI_HandleTypeDef *spi_handle = &spi_drv->handle;
|
||||
|
||||
if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS))
|
||||
if (message->cs_take && !(device->config.mode & RT_SPI_NO_CS) && (device->cs_pin != PIN_NONE))
|
||||
{
|
||||
if (device->config.mode & RT_SPI_CS_HIGH)
|
||||
rt_pin_write(device->config.cs_pin, PIN_HIGH);
|
||||
rt_pin_write(device->cs_pin, PIN_HIGH);
|
||||
else
|
||||
rt_pin_write(device->config.cs_pin, PIN_LOW);
|
||||
rt_pin_write(device->cs_pin, PIN_LOW);
|
||||
}
|
||||
|
||||
LOG_D("%s transfer prepare and start", spi_drv->config->bus_name);
|
||||
|
@ -433,12 +430,12 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
|
|||
#endif /* SOC_SERIES_STM32H7 || SOC_SERIES_STM32F7 */
|
||||
}
|
||||
|
||||
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)
|
||||
rt_pin_write(device->config.cs_pin, PIN_LOW);
|
||||
rt_pin_write(device->cs_pin, PIN_LOW);
|
||||
else
|
||||
rt_pin_write(device->config.cs_pin, PIN_HIGH);
|
||||
rt_pin_write(device->cs_pin, PIN_HIGH);
|
||||
}
|
||||
|
||||
return message->length;
|
||||
|
@ -571,7 +568,7 @@ static int rt_hw_spi_bus_init(void)
|
|||
/**
|
||||
* 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, struct rt_spi_configuration *cfg)
|
||||
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);
|
||||
|
@ -583,9 +580,14 @@ rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name,
|
|||
spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
|
||||
RT_ASSERT(spi_device != RT_NULL);
|
||||
|
||||
result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, RT_NULL);
|
||||
spi_device->cs_pin = cs_pin;
|
||||
if(cs_pin != PIN_NONE)
|
||||
{
|
||||
rt_pin_mode(cs_pin, PIN_MODE_OUTPUT);
|
||||
rt_pin_write(cs_pin, PIN_HIGH);
|
||||
}
|
||||
|
||||
result = rt_spi_configure(spi_device, cfg);
|
||||
result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, RT_NULL);
|
||||
|
||||
if (result != RT_EOK)
|
||||
{
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, struct rt_spi_configuration *cfg);
|
||||
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GPIOA, GPIO_PIN_4);
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GET_PIN(A, 4));
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q64", "spi10"))
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GPIOB, GPIO_PIN_12);
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GET_PIN(B, 12));
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q16", "spi20"))
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "drv_spi.h"
|
||||
static int rt_hw_nrf24l01_init(void)
|
||||
{
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GPIOG, GPIO_PIN_7);
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GET_PIN(G, 7));
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_COMPONENT_EXPORT(rt_hw_nrf24l01_init);
|
||||
|
|
|
@ -70,7 +70,7 @@ INIT_APP_EXPORT(stm32_sdcard_mount);
|
|||
static int rt_hw_spi2_tfcard(void)
|
||||
{
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GPIOD, GPIO_PIN_2);
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GET_PIN(D, 2));
|
||||
return msd_init("sd0", "spi20");
|
||||
}
|
||||
INIT_DEVICE_EXPORT(rt_hw_spi2_tfcard);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GPIOB, GPIO_PIN_12);
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GET_PIN(B, 12));
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q64", "spi20"))
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GPIOA, GPIO_PIN_4);
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GET_PIN(A, 4));
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q64", "spi10"))
|
||||
{
|
||||
|
|
|
@ -13,6 +13,6 @@
|
|||
int w5500_spi_device_init()
|
||||
{
|
||||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
return rt_hw_spi_device_attach("spi2","spi20",GPIOG,GPIO_PIN_9);
|
||||
return rt_hw_spi_device_attach("spi2","spi20",GET_PIN(G, 9));
|
||||
}
|
||||
INIT_DEVICE_EXPORT(w5500_spi_device_init);
|
||||
|
|
|
@ -14,6 +14,6 @@
|
|||
int w5500_spi_device_init()
|
||||
{
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
return rt_hw_spi_device_attach("spi2","spi20",GPIOB,GPIO_PIN_12);
|
||||
return rt_hw_spi_device_attach("spi2", "spi20", GET_PIN(B, 12));
|
||||
}
|
||||
INIT_DEVICE_EXPORT(w5500_spi_device_init);
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi3", "spi30", GPIOF, GPIO_PIN_8);
|
||||
rt_hw_spi_device_attach("spi3", "spi30", GET_PIN(F, 8));
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q64", "spi30"))
|
||||
{
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GPIOB, GPIO_PIN_14);
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GET_PIN(B, 14));
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "spi10"))
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GPIOB, GPIO_PIN_12);
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GET_PIN(B, 12));
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q16", "spi20"))
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi3", "spi30", GPIOD, GPIO_PIN_13);
|
||||
rt_hw_spi_device_attach("spi3", "spi30", GET_PIN(D, 13));
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q64", "spi30"))
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi5", "spi50", GPIOF, GPIO_PIN_6);
|
||||
rt_hw_spi_device_attach("spi5", "spi50", GET_PIN(F, 6));
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q256", "spi50"))
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
static int rt_hw_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi5", "spi50", GPIOF, GPIO_PIN_6);
|
||||
rt_hw_spi_device_attach("spi5", "spi50", GET_PIN(F, 6));
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "spi50"))
|
||||
{
|
||||
|
|
|
@ -149,7 +149,7 @@ static void lcd_gpio_init(void)
|
|||
int rt_hw_spi_lcd_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOI_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GPIOI, GPIO_PIN_0);
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GET_PIN(I, 0));
|
||||
lcd_gpio_init();
|
||||
|
||||
rt_pin_write(LCD_RES_PIN, PIN_HIGH);
|
||||
|
|
|
@ -18,7 +18,7 @@ static int rt_flash_init(void)
|
|||
extern rt_spi_flash_device_t rt_sfud_flash_probe(const char *spi_flash_dev_name, const char *spi_dev_name);
|
||||
extern int fal_init(void);
|
||||
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GPIOA, GPIO_PIN_4);
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GET_PIN(A, 4));
|
||||
|
||||
/* initialize SPI Flash device */
|
||||
rt_sfud_flash_probe("norflash0", "spi10");
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
static int rt_hw_spi_flash_with_sfud_init(void)
|
||||
{
|
||||
rt_err_t err = RT_EOK;
|
||||
rt_hw_spi_device_attach("spi1", "spi10", SPI_CS_GPIO, SPI_CS_PIN);
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GET_PIN(D, 6));
|
||||
|
||||
/* init W25Q16 , And register as a block device */
|
||||
if (RT_NULL == rt_sfud_flash_probe(FAL_USING_NOR_FLASH_DEV_NAME, "spi10"))
|
||||
|
|
|
@ -37,7 +37,7 @@ static int rt_hw_lcd_config(void)
|
|||
struct rt_spi_configuration cfg;
|
||||
cfg.data_width = 8;
|
||||
cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_3 | RT_SPI_MSB;
|
||||
cfg.max_hz = 42 * 1000 * 1000; /* 42M,SPI max 42MHz,lcd 4-wire spi */
|
||||
cfg.max_hz = 42 * 1000 * 1000; /* 42M, SPI max 42MHz, lcd 4-wire spi */
|
||||
|
||||
rt_spi_configure(spi_dev_lcd, &cfg);
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ static void lcd_gpio_init(void)
|
|||
|
||||
static int rt_hw_lcd_init(void)
|
||||
{
|
||||
rt_hw_spi_device_attach("spi2", "lcd", GPIOC, GPIO_PIN_3);
|
||||
rt_hw_spi_device_attach("spi2", "lcd", GET_PIN(C, 3));
|
||||
lcd_gpio_init();
|
||||
/* Memory Data Access Control */
|
||||
lcd_write_cmd(0x36);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include "drv_spi.h"
|
||||
static int rt_hw_nrf24l01_init(void)
|
||||
{
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GPIOD, GPIO_PIN_5);
|
||||
rt_hw_spi_device_attach("spi2", "spi20", GET_PIN(D, 5));
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_COMPONENT_EXPORT(rt_hw_nrf24l01_init);
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
static int rt_hw_spi1_tfcard(void)
|
||||
{
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GPIOC, GPIO_PIN_3);
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GET_PIN(C, 3));
|
||||
return msd_init("sd0", "spi10");
|
||||
}
|
||||
INIT_DEVICE_EXPORT(rt_hw_spi1_tfcard);
|
||||
|
|
|
@ -130,7 +130,7 @@ static int rt_hw_lcd_init(void)
|
|||
{
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
rt_hw_spi_device_attach("spi3", "spi30", GPIOD, GPIO_PIN_7);
|
||||
rt_hw_spi_device_attach("spi3", "spi30", GET_PIN(D, 7));
|
||||
lcd_gpio_init();
|
||||
|
||||
/* Memory Data Access Control */
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
static int rt_hw_spi_lcd_init(void)
|
||||
{
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GPIOA, GPIO_PIN_4);
|
||||
rt_hw_spi_device_attach("spi1", "spi10", GET_PIN(A, 4));
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ static int rt_spi_device_init(void)
|
|||
{
|
||||
struct rt_spi_configuration cfg;
|
||||
|
||||
rt_hw_spi_device_attach("spi5", "spi50", NULL, NULL);
|
||||
rt_hw_spi_device_attach("spi5", "spi50", PIN_NONE);
|
||||
|
||||
cfg.data_width = 8;
|
||||
cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB | RT_SPI_NO_CS;
|
||||
|
|
|
@ -22,7 +22,7 @@ static int rt_spi_device_init(void)
|
|||
{
|
||||
struct rt_spi_configuration cfg;
|
||||
|
||||
rt_hw_spi_device_attach(SPI_NAME, SPI_DEVICE_NAME, NULL, NULL);
|
||||
rt_hw_spi_device_attach(SPI_NAME, SPI_DEVICE_NAME, PIN_NONE);
|
||||
|
||||
cfg.data_width = 8;
|
||||
cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB | RT_SPI_NO_CS;
|
||||
|
|
|
@ -25,6 +25,8 @@ struct rt_device_pin
|
|||
const struct rt_pin_ops *ops;
|
||||
};
|
||||
|
||||
#define PIN_NONE (-1)
|
||||
|
||||
#define PIN_LOW 0x00
|
||||
#define PIN_HIGH 0x01
|
||||
|
||||
|
@ -43,7 +45,7 @@ struct rt_device_pin
|
|||
#define PIN_IRQ_DISABLE 0x00
|
||||
#define PIN_IRQ_ENABLE 0x01
|
||||
|
||||
#define PIN_IRQ_PIN_NONE -1
|
||||
#define PIN_IRQ_PIN_NONE PIN_NONE
|
||||
|
||||
struct rt_device_pin_mode
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <drivers/pin.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
|
@ -79,7 +79,6 @@ struct rt_spi_configuration
|
|||
rt_uint8_t mode;
|
||||
rt_uint8_t data_width;
|
||||
rt_uint16_t reserved;
|
||||
rt_base_t cs_pin;
|
||||
|
||||
rt_uint32_t max_hz;
|
||||
};
|
||||
|
@ -113,6 +112,7 @@ struct rt_spi_device
|
|||
struct rt_spi_bus *bus;
|
||||
|
||||
struct rt_spi_configuration config;
|
||||
rt_base_t cs_pin;
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
|
|
|
@ -80,7 +80,6 @@ rt_err_t rt_spi_configure(struct rt_spi_device *device,
|
|||
device->config.data_width = cfg->data_width;
|
||||
device->config.mode = cfg->mode & RT_SPI_MODE_MASK ;
|
||||
device->config.max_hz = cfg->max_hz ;
|
||||
device->config.cs_pin = cfg->cs_pin ;
|
||||
|
||||
if (device->bus != RT_NULL)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue