mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-08-18 11:53:05 +08:00
[bsp][drivers][soft_spi] unify the software SPI driver
This commit is contained in:
@@ -43,9 +43,6 @@ if GetDepend('BSP_USING_I2S'):
|
||||
if GetDepend('BSP_USING_WM8904'):
|
||||
src += ['drv_sound_wm8904.c']
|
||||
|
||||
if GetDepend('BSP_USING_SOFT_SPI'):
|
||||
src += ['drv_soft_spi.c']
|
||||
|
||||
if GetDepend('BSP_USING_LCD'):
|
||||
src += ['drv_st7796.c']
|
||||
src += ['sample/lcd_sample.c']
|
||||
|
||||
@@ -1,230 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-04-14 Wangyuqiang the first version
|
||||
*/
|
||||
#include "board.h"
|
||||
#include "drv_soft_spi.h"
|
||||
|
||||
#if defined BSP_USING_SOFT_SPI
|
||||
|
||||
#define LOG_TAG "drv.soft_spi"
|
||||
#include <drv_log.h>
|
||||
|
||||
static struct lpc_soft_spi_config soft_spi_config[] =
|
||||
{
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
SOFT_SPI1_BUS_CONFIG,
|
||||
#endif
|
||||
#ifdef BSP_USING_SOFT_SPI2
|
||||
SOFT_SPI2_BUS_CONFIG,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct lpc_soft_spi spi_obj[sizeof(soft_spi_config) / sizeof(soft_spi_config[0])];
|
||||
|
||||
/**
|
||||
* Attach the spi device to soft SPI bus, this function must be used after initialization.
|
||||
*/
|
||||
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;
|
||||
|
||||
/* 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);
|
||||
|
||||
result = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void lpc_spi_gpio_init(struct lpc_soft_spi *spi)
|
||||
{
|
||||
struct lpc_soft_spi_config *cfg = (struct lpc_soft_spi_config *)spi->cfg;
|
||||
rt_pin_mode(cfg->sck, PIN_MODE_OUTPUT);
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_INPUT);
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_OUTPUT);
|
||||
|
||||
rt_pin_write(cfg->miso, PIN_HIGH);
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
|
||||
static void lpc_tog_sclk(void *data)
|
||||
{
|
||||
struct lpc_soft_spi_config* cfg = (struct lpc_soft_spi_config*)data;
|
||||
if(rt_pin_read(cfg->sck) == PIN_HIGH)
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
static void lpc_set_sclk(void *data, rt_int32_t state)
|
||||
{
|
||||
struct lpc_soft_spi_config* cfg = (struct lpc_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
static void lpc_set_mosi(void *data, rt_int32_t state)
|
||||
{
|
||||
struct lpc_soft_spi_config* cfg = (struct lpc_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->mosi, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
static void lpc_set_miso(void *data, rt_int32_t state)
|
||||
{
|
||||
struct lpc_soft_spi_config* cfg = (struct lpc_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->miso, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->miso, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
static rt_int32_t lpc_get_sclk(void *data)
|
||||
{
|
||||
struct lpc_soft_spi_config* cfg = (struct lpc_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->sck);
|
||||
}
|
||||
|
||||
static rt_int32_t lpc_get_mosi(void *data)
|
||||
{
|
||||
struct lpc_soft_spi_config* cfg = (struct lpc_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->mosi);
|
||||
}
|
||||
|
||||
static rt_int32_t lpc_get_miso(void *data)
|
||||
{
|
||||
struct lpc_soft_spi_config* cfg = (struct lpc_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->miso);
|
||||
}
|
||||
|
||||
static void lpc_dir_mosi(void *data, rt_int32_t state)
|
||||
{
|
||||
struct lpc_soft_spi_config* cfg = (struct lpc_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
static void lpc_dir_miso(void *data, rt_int32_t state)
|
||||
{
|
||||
struct lpc_soft_spi_config* cfg = (struct lpc_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
static void lpc_udelay(rt_uint32_t us)
|
||||
{
|
||||
rt_uint32_t ticks;
|
||||
rt_uint32_t told, tnow, tcnt = 0;
|
||||
rt_uint32_t reload = SysTick->LOAD;
|
||||
|
||||
ticks = us * reload / (1000000UL / RT_TICK_PER_SECOND);
|
||||
told = SysTick->VAL;
|
||||
while (1)
|
||||
{
|
||||
tnow = SysTick->VAL;
|
||||
if (tnow != told)
|
||||
{
|
||||
if (tnow < told)
|
||||
{
|
||||
tcnt += told - tnow;
|
||||
}
|
||||
else
|
||||
{
|
||||
tcnt += reload - tnow + told;
|
||||
}
|
||||
told = tnow;
|
||||
if (tcnt >= ticks)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void lpc_pin_init(void)
|
||||
{
|
||||
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct lpc_soft_spi);
|
||||
|
||||
for(rt_size_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
lpc_spi_gpio_init(&spi_obj[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static struct rt_spi_bit_ops lpc_soft_spi_ops =
|
||||
{
|
||||
.data = RT_NULL,
|
||||
.pin_init = lpc_pin_init,
|
||||
.tog_sclk = lpc_tog_sclk,
|
||||
.set_sclk = lpc_set_sclk,
|
||||
.set_mosi = lpc_set_mosi,
|
||||
.set_miso = lpc_set_miso,
|
||||
.get_sclk = lpc_get_sclk,
|
||||
.get_mosi = lpc_get_mosi,
|
||||
.get_miso = lpc_get_miso,
|
||||
.dir_mosi = lpc_dir_mosi,
|
||||
.dir_miso = lpc_dir_miso,
|
||||
.udelay = lpc_udelay,
|
||||
.delay_us = 1,
|
||||
};
|
||||
|
||||
/* Soft SPI initialization function */
|
||||
int rt_hw_softspi_init(void)
|
||||
{
|
||||
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct lpc_soft_spi);
|
||||
rt_err_t result;
|
||||
|
||||
for (rt_size_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
lpc_soft_spi_ops.data = (void *)&soft_spi_config[i];
|
||||
spi_obj[i].spi.ops = &lpc_soft_spi_ops;
|
||||
spi_obj[i].cfg = (void *)&soft_spi_config[i];
|
||||
result = rt_spi_bit_add_bus(&spi_obj[i].spi, soft_spi_config[i].bus_name, &lpc_soft_spi_ops);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_hw_softspi_init);
|
||||
|
||||
#endif /* BSP_USING_SOFT_SPI */
|
||||
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-04-14 Wangyuqiang the first version
|
||||
*/
|
||||
|
||||
#ifndef DRV_SOFT_SPI_H_
|
||||
#define DRV_SOFT_SPI_H_
|
||||
|
||||
#include <rtdevice.h>
|
||||
#include <dev_spi_bit_ops.h>
|
||||
|
||||
/* lpc soft spi config */
|
||||
struct lpc_soft_spi_config
|
||||
{
|
||||
rt_uint8_t sck;
|
||||
rt_uint8_t mosi;
|
||||
rt_uint8_t miso;
|
||||
const char *bus_name;
|
||||
};
|
||||
|
||||
/* lpc soft spi dirver */
|
||||
struct lpc_soft_spi
|
||||
{
|
||||
struct rt_spi_bit_obj spi;
|
||||
struct lpc_soft_spi_config *cfg;
|
||||
};
|
||||
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
#define SOFT_SPI1_BUS_CONFIG \
|
||||
{ \
|
||||
.sck = BSP_S_SPI1_SCK_PIN, \
|
||||
.mosi = BSP_S_SPI1_MOSI_PIN, \
|
||||
.miso = BSP_S_SPI1_MISO_PIN, \
|
||||
.bus_name = "sspi1", \
|
||||
}
|
||||
#endif /* BSP_USING_SOFT_SPI1 */
|
||||
#ifdef BSP_USING_SOFT_SPI2
|
||||
#define SOFT_SPI2_BUS_CONFIG \
|
||||
{ \
|
||||
.sck = BSP_S_SPI2_SCK_PIN, \
|
||||
.mosi = BSP_S_SPI2_MOSI_PIN, \
|
||||
.miso = BSP_S_SPI2_MISO_PIN, \
|
||||
.bus_name = "sspi2", \
|
||||
}
|
||||
#endif /* BSP_USING_SOFT_SPI2 */
|
||||
|
||||
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__ */
|
||||
@@ -166,46 +166,90 @@ menu "On-chip Peripheral Drivers"
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable soft SPI BUS"
|
||||
bool "Enable software SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_PIN
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_SPI
|
||||
select RT_USING_SOFT_SPI
|
||||
if BSP_USING_SOFT_SPI
|
||||
config BSP_USING_SOFT_SPI1
|
||||
bool "Enable soft SPI1 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI1
|
||||
comment "Notice: num = 32 * PORTx + PINx + 1"
|
||||
comment "1_11 --> 44; 0_15 --> 16; 1_8 --> 41"
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
int "sspi1 SCL pin number"
|
||||
default 44
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
int "sspi1 MISO pin number"
|
||||
default 16
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
int "sspi1 MOSI pin number"
|
||||
default 41
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 44
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 41
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 16
|
||||
endif
|
||||
|
||||
config BSP_USING_SOFT_SPI2
|
||||
bool "Enable soft SPI2 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI2
|
||||
comment "Notice: num = 32 * PORTx + PINx + 1"
|
||||
comment "1_9 --> 42; 0_18 --> 19; 1_10 --> 43"
|
||||
config BSP_S_SPI2_SCK_PIN
|
||||
int "sspi2 SCL pin number"
|
||||
default 42
|
||||
config BSP_S_SPI2_MOSI_PIN
|
||||
int "sspi2 MISO pin number"
|
||||
default 19
|
||||
config BSP_S_SPI2_MISO_PIN
|
||||
int "sspi2 MOSI pin number"
|
||||
default 43
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable software SPI2 Bus (swspi2)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI2
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config RT_SOFT_SPI2_SCK_PIN
|
||||
int "swspi2 SCK pin number"
|
||||
default 42
|
||||
config RT_SOFT_SPI2_MISO_PIN
|
||||
int "swspi2 MISO pin number"
|
||||
default 43
|
||||
config RT_SOFT_SPI2_MOSI_PIN
|
||||
int "swspi2 MOSI pin number"
|
||||
default 19
|
||||
endif
|
||||
endif
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 44 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 41 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 16 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 42 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 43 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 19 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi2" if RT_USING_SOFT_SPI2
|
||||
|
||||
menuconfig BSP_USING_ADC
|
||||
config BSP_USING_ADC
|
||||
|
||||
@@ -9,26 +9,29 @@
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "dev_spi_flash.h"
|
||||
#include "dev_spi_flash_sfud.h"
|
||||
#include "drv_soft_spi.h"
|
||||
#include "drv_pin.h"
|
||||
|
||||
#define cs_pin GET_PINS(1,5)
|
||||
#define cs_pin GET_PINS(1, 5)
|
||||
|
||||
static struct rt_spi_device soft_spi_flash_device;
|
||||
|
||||
static int rt_soft_spi_flash_init(void)
|
||||
{
|
||||
int result = -1;
|
||||
|
||||
result = rt_hw_softspi_device_attach("sspi1", "sspi10", cs_pin);
|
||||
rt_kprintf("value is %d\n",result);
|
||||
result = rt_spi_bus_attach_device_cspin(&soft_spi_flash_device, "swspi10", "swspi1",
|
||||
cs_pin, RT_NULL);
|
||||
rt_kprintf("value is %d\n", result);
|
||||
|
||||
if(result == RT_EOK)
|
||||
if (result == RT_EOK)
|
||||
{
|
||||
rt_kprintf("rt_hw_softspi_device_attach successful!\n");
|
||||
rt_kprintf("attach soft SPI device successful!\n");
|
||||
}
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "sspi10"))
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "swspi10"))
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
@@ -148,47 +148,90 @@ menu "On-chip Peripheral Drivers"
|
||||
endif
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable soft SPI BUS"
|
||||
bool "Enable software SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_PIN
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_SPI
|
||||
select RT_USING_SOFT_SPI
|
||||
if BSP_USING_SOFT_SPI
|
||||
config BSP_USING_SOFT_SPI0
|
||||
bool "Enable SPI0 Bus (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI0
|
||||
config BSP_S_SPI0_SCK_PIN
|
||||
int "spi0 SCK pin number (GP)"
|
||||
range 0 28
|
||||
default 6
|
||||
config BSP_S_SPI0_MOSI_PIN
|
||||
int "spi0 MOSI pin number (GP)"
|
||||
range 0 28
|
||||
default 7
|
||||
config BSP_S_SPI0_MISO_PIN
|
||||
int "spi0 MISO pin number (GP)"
|
||||
range 0 28
|
||||
default 4
|
||||
endif
|
||||
config BSP_USING_SOFT_SPI1
|
||||
bool "Enable SPI1 Bus (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
int "spi1 SCK pin number (GP)"
|
||||
range 0 28
|
||||
default 10
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
int "spi1 MOSI pin number (GP)"
|
||||
range 0 28
|
||||
default 11
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
int "spi1 MISO pin number (GP)"
|
||||
range 0 28
|
||||
default 12
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI0
|
||||
bool "Enable software SPI0 Bus (swspi0)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI0
|
||||
if BSP_USING_SOFT_SPI0
|
||||
config RT_SOFT_SPI0_SCK_PIN
|
||||
int "swspi0 SCK pin number"
|
||||
default 6
|
||||
config RT_SOFT_SPI0_MISO_PIN
|
||||
int "swspi0 MISO pin number"
|
||||
default 4
|
||||
config RT_SOFT_SPI0_MOSI_PIN
|
||||
int "swspi0 MOSI pin number"
|
||||
default 7
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 10
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 12
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 11
|
||||
endif
|
||||
endif
|
||||
config RT_SOFT_SPI0_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI0_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 6 if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI0_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 4 if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI0_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 7 if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI0_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI0_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi0" if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 10 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 12 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 11 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
menuconfig BSP_USING_ADC
|
||||
bool "Enable ADC"
|
||||
|
||||
@@ -148,47 +148,90 @@ menu "On-chip Peripheral Drivers"
|
||||
endif
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable soft SPI BUS"
|
||||
bool "Enable software SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_PIN
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_SPI
|
||||
select RT_USING_SOFT_SPI
|
||||
if BSP_USING_SOFT_SPI
|
||||
config BSP_USING_SOFT_SPI0
|
||||
bool "Enable SPI0 Bus (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI0
|
||||
config BSP_S_SPI0_SCK_PIN
|
||||
int "spi0 SCK pin number (GP)"
|
||||
range 0 28
|
||||
default 6
|
||||
config BSP_S_SPI0_MOSI_PIN
|
||||
int "spi0 MOSI pin number (GP)"
|
||||
range 0 28
|
||||
default 7
|
||||
config BSP_S_SPI0_MISO_PIN
|
||||
int "spi0 MISO pin number (GP)"
|
||||
range 0 28
|
||||
default 4
|
||||
endif
|
||||
config BSP_USING_SOFT_SPI1
|
||||
bool "Enable SPI1 Bus (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
int "spi1 SCK pin number (GP)"
|
||||
range 0 28
|
||||
default 10
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
int "spi1 MOSI pin number (GP)"
|
||||
range 0 28
|
||||
default 11
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
int "spi1 MISO pin number (GP)"
|
||||
range 0 28
|
||||
default 12
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI0
|
||||
bool "Enable software SPI0 Bus (swspi0)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI0
|
||||
if BSP_USING_SOFT_SPI0
|
||||
config RT_SOFT_SPI0_SCK_PIN
|
||||
int "swspi0 SCK pin number"
|
||||
default 6
|
||||
config RT_SOFT_SPI0_MISO_PIN
|
||||
int "swspi0 MISO pin number"
|
||||
default 4
|
||||
config RT_SOFT_SPI0_MOSI_PIN
|
||||
int "swspi0 MOSI pin number"
|
||||
default 7
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 10
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 12
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 11
|
||||
endif
|
||||
endif
|
||||
config RT_SOFT_SPI0_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI0_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 6 if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI0_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 4 if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI0_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 7 if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI0_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI0_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi0" if RT_USING_SOFT_SPI0
|
||||
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 10 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 12 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 11 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
menuconfig BSP_USING_ADC
|
||||
bool "Enable ADC"
|
||||
|
||||
@@ -10,9 +10,6 @@ if GetDepend('BSP_USING_PIN'):
|
||||
if GetDepend('BSP_USING_UART'):
|
||||
src += ['drv_uart.c']
|
||||
|
||||
if GetDepend('BSP_USING_SOFT_SPI'):
|
||||
src += ['drv_soft_spi.c']
|
||||
|
||||
if GetDepend('BSP_USING_ADC'):
|
||||
src += ['drv_adc.c']
|
||||
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-06-02 Chushicheng the first version
|
||||
*/
|
||||
#include "drv_soft_spi.h"
|
||||
#include "board.h"
|
||||
|
||||
#if defined BSP_USING_SOFT_SPI
|
||||
#define LOG_TAG "drv.soft_spi"
|
||||
#include <rtdbg.h>
|
||||
|
||||
static struct pico_soft_spi_config soft_spi_config[] =
|
||||
{
|
||||
#ifdef BSP_USING_SOFT_SPI0
|
||||
SOFT_SPI0_BUS_CONFIG,
|
||||
#endif
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
SOFT_SPI1_BUS_CONFIG,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct pico_soft_spi spi_obj[sizeof(soft_spi_config) / sizeof(soft_spi_config[0])];
|
||||
|
||||
/**
|
||||
* Attach the spi device to soft SPI bus, this function must be used after initialization.
|
||||
*/
|
||||
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;
|
||||
|
||||
/* 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);
|
||||
|
||||
result = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void pico_spi_gpio_init(struct pico_soft_spi *spi)
|
||||
{
|
||||
struct pico_soft_spi_config *cfg = (struct pico_soft_spi_config *)spi->cfg;
|
||||
rt_pin_mode(cfg->sck, PIN_MODE_OUTPUT);
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_INPUT);
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_OUTPUT);
|
||||
|
||||
rt_pin_write(cfg->miso, PIN_HIGH);
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
|
||||
static void pico_tog_sclk(void *data)
|
||||
{
|
||||
struct pico_soft_spi_config* cfg = (struct pico_soft_spi_config*)data;
|
||||
if(rt_pin_read(cfg->sck) == PIN_HIGH)
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
static void pico_set_sclk(void *data, rt_int32_t state)
|
||||
{
|
||||
struct pico_soft_spi_config* cfg = (struct pico_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
static void pico_set_mosi(void *data, rt_int32_t state)
|
||||
{
|
||||
struct pico_soft_spi_config* cfg = (struct pico_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->mosi, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
static void pico_set_miso(void *data, rt_int32_t state)
|
||||
{
|
||||
struct pico_soft_spi_config* cfg = (struct pico_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->miso, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->miso, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
static rt_int32_t pico_get_sclk(void *data)
|
||||
{
|
||||
struct pico_soft_spi_config* cfg = (struct pico_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->sck);
|
||||
}
|
||||
|
||||
static rt_int32_t pico_get_mosi(void *data)
|
||||
{
|
||||
struct pico_soft_spi_config* cfg = (struct pico_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->mosi);
|
||||
}
|
||||
|
||||
static rt_int32_t pico_get_miso(void *data)
|
||||
{
|
||||
struct pico_soft_spi_config* cfg = (struct pico_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->miso);
|
||||
}
|
||||
|
||||
static void pico_dir_mosi(void *data, rt_int32_t state)
|
||||
{
|
||||
struct pico_soft_spi_config* cfg = (struct pico_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
static void pico_dir_miso(void *data, rt_int32_t state)
|
||||
{
|
||||
struct pico_soft_spi_config* cfg = (struct pico_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
static void pico_udelay(rt_uint32_t us)
|
||||
{
|
||||
busy_wait_us_32(us);
|
||||
}
|
||||
|
||||
static void pico_pin_init(void)
|
||||
{
|
||||
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct pico_soft_spi);
|
||||
|
||||
for(rt_size_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
pico_spi_gpio_init(&spi_obj[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static struct rt_spi_bit_ops pico_soft_spi_ops =
|
||||
{
|
||||
.data = RT_NULL,
|
||||
.pin_init = pico_pin_init,
|
||||
.tog_sclk = pico_tog_sclk,
|
||||
.set_sclk = pico_set_sclk,
|
||||
.set_mosi = pico_set_mosi,
|
||||
.set_miso = pico_set_miso,
|
||||
.get_sclk = pico_get_sclk,
|
||||
.get_mosi = pico_get_mosi,
|
||||
.get_miso = pico_get_miso,
|
||||
.dir_mosi = pico_dir_mosi,
|
||||
.dir_miso = pico_dir_miso,
|
||||
.udelay = pico_udelay,
|
||||
.delay_us = 1,
|
||||
};
|
||||
|
||||
/* Soft SPI initialization function */
|
||||
int rt_hw_softspi_init(void)
|
||||
{
|
||||
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct pico_soft_spi);
|
||||
rt_err_t result;
|
||||
|
||||
for (rt_size_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
pico_soft_spi_ops.data = (void *)&soft_spi_config[i];
|
||||
spi_obj[i].spi.ops = &pico_soft_spi_ops;
|
||||
spi_obj[i].cfg = (void *)&soft_spi_config[i];
|
||||
|
||||
result = rt_spi_bit_add_bus(&spi_obj[i].spi, soft_spi_config[i].bus_name, &pico_soft_spi_ops);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_DEVICE_EXPORT(rt_hw_softspi_init);
|
||||
|
||||
#endif /* BSP_USING_SOFT_SPI */
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-06-02 Chushicheng the first version
|
||||
*/
|
||||
#ifndef DRV_SOFT_SPI_H_
|
||||
#define DRV_SOFT_SPI_H_
|
||||
|
||||
#ifdef BSP_USING_SOFT_SPI
|
||||
#include <rtdevice.h>
|
||||
#include <dev_spi_bit_ops.h>
|
||||
|
||||
/* pico soft spi config */
|
||||
struct pico_soft_spi_config
|
||||
{
|
||||
rt_uint8_t sck;
|
||||
rt_uint8_t mosi;
|
||||
rt_uint8_t miso;
|
||||
const char *bus_name;
|
||||
};
|
||||
|
||||
/* pico soft spi dirver */
|
||||
struct pico_soft_spi
|
||||
{
|
||||
struct rt_spi_bit_obj spi;
|
||||
struct pico_soft_spi_config *cfg;
|
||||
};
|
||||
|
||||
#ifdef BSP_USING_SOFT_SPI0
|
||||
#define SOFT_SPI0_BUS_CONFIG \
|
||||
{ \
|
||||
.sck = BSP_S_SPI0_SCK_PIN, \
|
||||
.mosi = BSP_S_SPI0_MOSI_PIN, \
|
||||
.miso = BSP_S_SPI0_MISO_PIN, \
|
||||
.bus_name = "sspi0", \
|
||||
}
|
||||
#endif /* BSP_USING_SOFT_SPI0 */
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
#define SOFT_SPI1_BUS_CONFIG \
|
||||
{ \
|
||||
.sck = BSP_S_SPI1_SCK_PIN, \
|
||||
.mosi = BSP_S_SPI_MOSI_PIN, \
|
||||
.miso = BSP_S_SPI1_MISO_PIN, \
|
||||
.bus_name = "sspi1", \
|
||||
}
|
||||
#endif /* BSP_USING_SOFT_SPI1 */
|
||||
|
||||
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 /* BSP_USING_SOFT_SPI */
|
||||
#endif /* __DRV_SOFT_SPI__ */
|
||||
@@ -29,9 +29,6 @@ if GetDepend(['BSP_USING_HW_I2C']):
|
||||
if GetDepend(['BSP_USING_SPI']):
|
||||
src += ['drv_spi.c']
|
||||
|
||||
if GetDepend(['BSP_USING_SOFT_SPI']):
|
||||
src += ['drv_soft_spi.c']
|
||||
|
||||
if GetDepend(['BSP_USING_SCI']):
|
||||
src += ['drv_sci.c']
|
||||
|
||||
|
||||
@@ -1,235 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2025, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-03-12 Wangyuqiang the first version
|
||||
*/
|
||||
#include <board.h>
|
||||
#include <string.h>
|
||||
#include "drv_soft_spi.h"
|
||||
#include "drv_config.h"
|
||||
|
||||
#if defined BSP_USING_SOFT_SPI
|
||||
|
||||
//#define DRV_DEBUG
|
||||
#define LOG_TAG "drv.soft_spi"
|
||||
#include <drv_log.h>
|
||||
|
||||
static struct ra_soft_spi_config soft_spi_config[] =
|
||||
{
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
SOFT_SPI1_BUS_CONFIG,
|
||||
#endif
|
||||
#ifdef BSP_USING_SOFT_SPI2
|
||||
SOFT_SPI2_BUS_CONFIG,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct ra_soft_spi spi_obj[sizeof(soft_spi_config) / sizeof(soft_spi_config[0])];
|
||||
|
||||
/**
|
||||
* Attach the spi device to soft SPI bus, this function must be used after initialization.
|
||||
*/
|
||||
rt_err_t rt_soft_spi_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;
|
||||
|
||||
/* 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);
|
||||
|
||||
result = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void ra_spi_gpio_init(struct ra_soft_spi *spi)
|
||||
{
|
||||
struct ra_soft_spi_config *cfg = (struct ra_soft_spi_config *)spi->cfg;
|
||||
rt_pin_mode(cfg->sck, PIN_MODE_OUTPUT);
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_INPUT);
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_OUTPUT);
|
||||
|
||||
rt_pin_write(cfg->miso, PIN_HIGH);
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
|
||||
static void ra_tog_sclk(void *data)
|
||||
{
|
||||
struct ra_soft_spi_config* cfg = (struct ra_soft_spi_config*)data;
|
||||
if(rt_pin_read(cfg->sck) == PIN_HIGH)
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
static void ra_set_sclk(void *data, rt_int32_t state)
|
||||
{
|
||||
struct ra_soft_spi_config* cfg = (struct ra_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
static void ra_set_mosi(void *data, rt_int32_t state)
|
||||
{
|
||||
struct ra_soft_spi_config* cfg = (struct ra_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->mosi, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
static void ra_set_miso(void *data, rt_int32_t state)
|
||||
{
|
||||
struct ra_soft_spi_config* cfg = (struct ra_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->miso, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->miso, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
static rt_int32_t ra_get_sclk(void *data)
|
||||
{
|
||||
struct ra_soft_spi_config* cfg = (struct ra_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->sck);
|
||||
}
|
||||
|
||||
static rt_int32_t ra_get_mosi(void *data)
|
||||
{
|
||||
struct ra_soft_spi_config* cfg = (struct ra_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->mosi);
|
||||
}
|
||||
|
||||
static rt_int32_t ra_get_miso(void *data)
|
||||
{
|
||||
struct ra_soft_spi_config* cfg = (struct ra_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->miso);
|
||||
}
|
||||
|
||||
static void ra_dir_mosi(void *data, rt_int32_t state)
|
||||
{
|
||||
struct ra_soft_spi_config* cfg = (struct ra_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
static void ra_dir_miso(void *data, rt_int32_t state)
|
||||
{
|
||||
struct ra_soft_spi_config* cfg = (struct ra_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
static void ra_udelay(rt_uint32_t us)
|
||||
{
|
||||
rt_uint32_t ticks;
|
||||
rt_uint32_t told, tnow, tcnt = 0;
|
||||
rt_uint32_t reload = SysTick->LOAD;
|
||||
|
||||
ticks = us * reload / (1000000UL / RT_TICK_PER_SECOND);
|
||||
told = SysTick->VAL;
|
||||
while (1)
|
||||
{
|
||||
tnow = SysTick->VAL;
|
||||
if (tnow != told)
|
||||
{
|
||||
if (tnow < told)
|
||||
{
|
||||
tcnt += told - tnow;
|
||||
}
|
||||
else
|
||||
{
|
||||
tcnt += reload - tnow + told;
|
||||
}
|
||||
told = tnow;
|
||||
if (tcnt >= ticks)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ra_pin_init(void)
|
||||
{
|
||||
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct ra_soft_spi);
|
||||
|
||||
for(rt_size_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
ra_spi_gpio_init(&spi_obj[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static struct rt_spi_bit_ops ra_soft_spi_ops =
|
||||
{
|
||||
.data = RT_NULL,
|
||||
.pin_init = ra_pin_init,
|
||||
.tog_sclk = ra_tog_sclk,
|
||||
.set_sclk = ra_set_sclk,
|
||||
.set_mosi = ra_set_mosi,
|
||||
.set_miso = ra_set_miso,
|
||||
.get_sclk = ra_get_sclk,
|
||||
.get_mosi = ra_get_mosi,
|
||||
.get_miso = ra_get_miso,
|
||||
.dir_mosi = ra_dir_mosi,
|
||||
.dir_miso = ra_dir_miso,
|
||||
.udelay = ra_udelay,
|
||||
.delay_us = 1,
|
||||
};
|
||||
|
||||
/* Soft SPI initialization function */
|
||||
int rt_hw_softspi_init(void)
|
||||
{
|
||||
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct ra_soft_spi);
|
||||
rt_err_t result;
|
||||
|
||||
for (rt_size_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
memcpy(&spi_obj[i].ops, &ra_soft_spi_ops, sizeof(struct rt_spi_bit_ops));
|
||||
spi_obj[i].ops.data = (void *)&soft_spi_config[i];
|
||||
spi_obj[i].spi.ops = &ra_soft_spi_ops;
|
||||
spi_obj[i].cfg = (void *)&soft_spi_config[i];
|
||||
result = rt_spi_bit_add_bus(&spi_obj[i].spi, soft_spi_config[i].bus_name, &spi_obj[i].ops);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_hw_softspi_init);
|
||||
|
||||
#endif /* BSP_USING_SOFT_SPI */
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2025, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-04-14 Wangyuqiang the first version
|
||||
*/
|
||||
|
||||
#ifndef __DRV_SOFT_SPI__
|
||||
#define __DRV_SOFT_SPI__
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
#include <dev_spi_bit_ops.h>
|
||||
|
||||
/* ra soft spi config */
|
||||
struct ra_soft_spi_config
|
||||
{
|
||||
rt_base_t sck;
|
||||
rt_base_t mosi;
|
||||
rt_base_t miso;
|
||||
const char *bus_name;
|
||||
};
|
||||
|
||||
/* ra soft spi dirver */
|
||||
struct ra_soft_spi
|
||||
{
|
||||
struct rt_spi_bit_obj spi;
|
||||
struct rt_spi_bit_ops ops;
|
||||
struct ra_soft_spi_config *cfg;
|
||||
};
|
||||
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
#define SOFT_SPI1_BUS_CONFIG \
|
||||
{ \
|
||||
.sck = BSP_S_SPI1_SCK_PIN, \
|
||||
.mosi = BSP_S_SPI1_MOSI_PIN, \
|
||||
.miso = BSP_S_SPI1_MISO_PIN, \
|
||||
.bus_name = "sspi1", \
|
||||
}
|
||||
#endif /* BSP_USING_SOFT_SPI1 */
|
||||
#ifdef BSP_USING_SOFT_SPI2
|
||||
#define SOFT_SPI2_BUS_CONFIG \
|
||||
{ \
|
||||
.sck = BSP_S_SPI2_SCK_PIN, \
|
||||
.mosi = BSP_S_SPI2_MOSI_PIN, \
|
||||
.miso = BSP_S_SPI2_MISO_PIN, \
|
||||
.bus_name = "sspi2", \
|
||||
}
|
||||
#endif /* BSP_USING_SOFT_SPI2 */
|
||||
|
||||
rt_err_t rt_soft_spi_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__ */
|
||||
@@ -217,31 +217,50 @@ endmenu
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable soft SPI BUS"
|
||||
bool "Enable software SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_PIN
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_SPI
|
||||
select RT_USING_SOFT_SPI
|
||||
if BSP_USING_SOFT_SPI
|
||||
config BSP_USING_SOFT_SPI1
|
||||
bool "Enable soft SPI1 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI1
|
||||
comment "Please refer to the 'bsp_io.h' file to configure the pins"
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
hex "spi1 sck pin number (hex)"
|
||||
range 0x0000 0xFFFF
|
||||
default 0x0204
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
hex "spi1 mosi pin number (hex)"
|
||||
range 0x0000 0xFFFF
|
||||
default 0x050C
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
hex "spi1 miso pin number (hex)"
|
||||
range 0x0000 0xFFFF
|
||||
default 0x050B
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 516
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 1291
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 1292
|
||||
endif
|
||||
endif
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 516 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 1291 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 1292 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
menuconfig BSP_USING_ADC
|
||||
bool "Enable ADC"
|
||||
|
||||
@@ -12,28 +12,28 @@
|
||||
#define Pins_Arduino_h
|
||||
|
||||
/* pins alias. Must keep in sequence */
|
||||
#define D0 (0)
|
||||
#define D1 (1)
|
||||
#define D2 (2)
|
||||
#define D3 (3)
|
||||
#define D4 (4)
|
||||
#define D5 (5)
|
||||
#define D6 (6)
|
||||
#define D7 (7)
|
||||
#define D8 (8)
|
||||
#define D9 (9)
|
||||
#define D10 (10)
|
||||
#define D11 (11)
|
||||
#define D12 (12)
|
||||
#define D13 (13)
|
||||
#define D14 (14)
|
||||
#define D15 (15)
|
||||
#define A0 (16)
|
||||
#define A1 (17)
|
||||
#define A2 (18)
|
||||
#define A3 (19)
|
||||
#define A4 (20)
|
||||
#define A5 (21)
|
||||
#define D0 (0)
|
||||
#define D1 (1)
|
||||
#define D2 (2)
|
||||
#define D3 (3)
|
||||
#define D4 (4)
|
||||
#define D5 (5)
|
||||
#define D6 (6)
|
||||
#define D7 (7)
|
||||
#define D8 (8)
|
||||
#define D9 (9)
|
||||
#define D10 (10)
|
||||
#define D11 (11)
|
||||
#define D12 (12)
|
||||
#define D13 (13)
|
||||
#define D14 (14)
|
||||
#define D15 (15)
|
||||
#define A0 (16)
|
||||
#define A1 (17)
|
||||
#define A2 (18)
|
||||
#define A3 (19)
|
||||
#define A4 (20)
|
||||
#define A5 (21)
|
||||
|
||||
#define RTDUINO_PIN_MAX_LIMIT A5 /* pin number max limit check */
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#define RTDUINO_SERIAL2_DEVICE_NAME "uart4"
|
||||
|
||||
/* soft spi1: P204-SS P511-MISO P512-MOSI */
|
||||
#define SS D13
|
||||
#define RTDUINO_DEFAULT_SPI_BUS_NAME "sspi1"
|
||||
#define SS D13
|
||||
#define RTDUINO_DEFAULT_SPI_BUS_NAME "swspi1"
|
||||
|
||||
#endif /* Pins_Arduino_h */
|
||||
|
||||
@@ -32,9 +32,6 @@ if GetDepend(['RT_USING_SPI']):
|
||||
if GetDepend(['RT_USING_QSPI']):
|
||||
src += ['drv_qspi.c']
|
||||
|
||||
if GetDepend('RT_USING_SOFT_SPI'):
|
||||
src += ['drv_soft_spi.c']
|
||||
|
||||
if GetDepend(['RT_USING_I2C']):
|
||||
if GetDepend('BSP_USING_HARD_I2C1') or GetDepend('BSP_USING_HARD_I2C2') or GetDepend('BSP_USING_HARD_I2C3') or GetDepend('BSP_USING_HARD_I2C4'):
|
||||
src += ['drv_hard_i2c.c']
|
||||
|
||||
@@ -1,206 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2024, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-6-14 solar first version
|
||||
*/
|
||||
#include <board.h>
|
||||
#include <string.h>
|
||||
#include "drv_soft_spi.h"
|
||||
#include "drv_config.h"
|
||||
|
||||
#if defined(RT_USING_SPI) && defined(RT_USING_SOFT_SPI) && defined(RT_USING_PIN)
|
||||
|
||||
//#define DRV_DEBUG
|
||||
#define LOG_TAG "drv.soft_spi"
|
||||
#include <drv_log.h>
|
||||
|
||||
static struct stm32_soft_spi_config soft_spi_config[] =
|
||||
{
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
SOFT_SPI1_BUS_CONFIG,
|
||||
#endif
|
||||
#ifdef BSP_USING_SOFT_SPI2
|
||||
SOFT_SPI2_BUS_CONFIG,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct stm32_soft_spi spi_obj[sizeof(soft_spi_config) / sizeof(soft_spi_config[0])];
|
||||
|
||||
/**
|
||||
* Attach the spi device to soft SPI bus, this function must be used after initialization.
|
||||
*/
|
||||
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;
|
||||
|
||||
/* 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);
|
||||
|
||||
result = rt_spi_bus_attach_device_cspin(spi_device, device_name, bus_name, cs_pin, RT_NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void stm32_spi_gpio_init(struct stm32_soft_spi *spi)
|
||||
{
|
||||
struct stm32_soft_spi_config *cfg = (struct stm32_soft_spi_config *)spi->cfg;
|
||||
rt_pin_mode(cfg->sck, PIN_MODE_OUTPUT);
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_INPUT);
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_OUTPUT);
|
||||
|
||||
rt_pin_write(cfg->miso, PIN_HIGH);
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
|
||||
void stm32_tog_sclk(void *data)
|
||||
{
|
||||
struct stm32_soft_spi_config* cfg = (struct stm32_soft_spi_config*)data;
|
||||
if(rt_pin_read(cfg->sck) == PIN_HIGH)
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_set_sclk(void *data, rt_int32_t state)
|
||||
{
|
||||
|
||||
struct stm32_soft_spi_config* cfg = (struct stm32_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_set_mosi(void *data, rt_int32_t state)
|
||||
{
|
||||
struct stm32_soft_spi_config* cfg = (struct stm32_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->mosi, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_set_miso(void *data, rt_int32_t state)
|
||||
{
|
||||
struct stm32_soft_spi_config* cfg = (struct stm32_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->miso, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->miso, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
rt_int32_t stm32_get_sclk(void *data)
|
||||
{
|
||||
struct stm32_soft_spi_config* cfg = (struct stm32_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->sck);
|
||||
}
|
||||
|
||||
rt_int32_t stm32_get_mosi(void *data)
|
||||
{
|
||||
struct stm32_soft_spi_config* cfg = (struct stm32_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->mosi);
|
||||
}
|
||||
|
||||
rt_int32_t stm32_get_miso(void *data)
|
||||
{
|
||||
struct stm32_soft_spi_config* cfg = (struct stm32_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->miso);
|
||||
}
|
||||
|
||||
void stm32_dir_mosi(void *data, rt_int32_t state)
|
||||
{
|
||||
struct stm32_soft_spi_config* cfg = (struct stm32_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_dir_miso(void *data, rt_int32_t state)
|
||||
{
|
||||
struct stm32_soft_spi_config* cfg = (struct stm32_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
static void stm32_pin_init(void)
|
||||
{
|
||||
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct stm32_soft_spi);
|
||||
|
||||
for(rt_size_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
stm32_spi_gpio_init(&spi_obj[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static struct rt_spi_bit_ops stm32_soft_spi_ops =
|
||||
{
|
||||
.data = RT_NULL,
|
||||
.pin_init = stm32_pin_init,
|
||||
.tog_sclk = stm32_tog_sclk,
|
||||
.set_sclk = stm32_set_sclk,
|
||||
.set_mosi = stm32_set_mosi,
|
||||
.set_miso = stm32_set_miso,
|
||||
.get_sclk = stm32_get_sclk,
|
||||
.get_mosi = stm32_get_mosi,
|
||||
.get_miso = stm32_get_miso,
|
||||
.dir_mosi = stm32_dir_mosi,
|
||||
.dir_miso = stm32_dir_miso,
|
||||
.udelay = rt_hw_us_delay,
|
||||
.delay_us = 1,
|
||||
};
|
||||
|
||||
/* Soft SPI initialization function */
|
||||
int rt_hw_softspi_init(void)
|
||||
{
|
||||
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct stm32_soft_spi);
|
||||
rt_err_t result;
|
||||
|
||||
for (rt_size_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
memcpy(&spi_obj[i].ops, &stm32_soft_spi_ops, sizeof(struct rt_spi_bit_ops));
|
||||
spi_obj[i].ops.data = (void *)&soft_spi_config[i];
|
||||
spi_obj[i].spi.ops = &stm32_soft_spi_ops;
|
||||
spi_obj[i].cfg = (void *)&soft_spi_config[i];
|
||||
result = rt_spi_bit_add_bus(&spi_obj[i].spi, soft_spi_config[i].bus_name, &spi_obj[i].ops);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_hw_softspi_init);
|
||||
|
||||
#endif /* defined(RT_USING_SPI) && defined(RT_USING_SOFT_SPI) && defined(RT_USING_PIN) */
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-6-14 solar first version
|
||||
*/
|
||||
|
||||
#ifndef __DRV_SOFT_SPI__
|
||||
#define __DRV_SOFT_SPI__
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
#include <dev_spi_bit_ops.h>
|
||||
|
||||
/* stm32 soft spi config */
|
||||
struct stm32_soft_spi_config
|
||||
{
|
||||
rt_uint8_t sck;
|
||||
rt_uint8_t mosi;
|
||||
rt_uint8_t miso;
|
||||
const char *bus_name;
|
||||
};
|
||||
|
||||
/* stm32 soft spi dirver */
|
||||
struct stm32_soft_spi
|
||||
{
|
||||
struct rt_spi_bit_obj spi;
|
||||
struct rt_spi_bit_ops ops;
|
||||
struct stm32_soft_spi_config *cfg;
|
||||
};
|
||||
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
#define SOFT_SPI1_BUS_CONFIG \
|
||||
{ \
|
||||
.sck = BSP_S_SPI1_SCK_PIN, \
|
||||
.mosi = BSP_S_SPI1_MOSI_PIN, \
|
||||
.miso = BSP_S_SPI1_MISO_PIN, \
|
||||
.bus_name = "sspi1", \
|
||||
}
|
||||
#endif /* BSP_USING_SOFT_SPI1 */
|
||||
#ifdef BSP_USING_SOFT_SPI2
|
||||
#define SOFT_SPI2_BUS_CONFIG \
|
||||
{ \
|
||||
.sck = BSP_S_SPI2_SCK_PIN, \
|
||||
.mosi = BSP_S_SPI2_MOSI_PIN, \
|
||||
.miso = BSP_S_SPI2_MISO_PIN, \
|
||||
.bus_name = "sspi2", \
|
||||
}
|
||||
#endif /* BSP_USING_SOFT_SPI2 */
|
||||
|
||||
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__ */
|
||||
@@ -54,7 +54,7 @@ menu "Onboard Peripheral Drivers"
|
||||
endif
|
||||
|
||||
config BSP_USING_TOUCH_RES
|
||||
bool "Use LCD TOUCH Resistance (sspi1)"
|
||||
bool "Use LCD TOUCH Resistance (swspi1)"
|
||||
select RT_USING_TOUCH
|
||||
select RT_TOUCH_PIN_IRQ
|
||||
select BSP_USING_SOFT_SPI
|
||||
@@ -94,7 +94,7 @@ menu "Onboard Peripheral Drivers"
|
||||
default n
|
||||
|
||||
config BSP_USING_SOFT_SPI_FLASH
|
||||
bool "Enable soft SPI FLASH (W25Q128 sspi2)"
|
||||
bool "Enable soft SPI FLASH (W25Q128 swspi2)"
|
||||
select BSP_USING_SOFT_SPI
|
||||
select BSP_USING_SOFT_SPI2
|
||||
select RT_USING_SFUD
|
||||
@@ -449,48 +449,90 @@ menu "On-chip Peripheral Drivers"
|
||||
default n
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable soft SPI BUS"
|
||||
bool "Enable software SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_SPI
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_PIN
|
||||
if BSP_USING_SOFT_SPI
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable soft SPI1 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
int "soft spi1 sck pin number"
|
||||
range 1 176
|
||||
default 16
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
int "soft spi1 miso pin number"
|
||||
range 1 176
|
||||
default 18
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
int "soft spi1 mosi pin number"
|
||||
range 1 176
|
||||
default 91
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 16
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 18
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 91
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable soft SPI2 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config BSP_S_SPI2_SCK_PIN
|
||||
int "soft spi2 sck pin number"
|
||||
range 1 176
|
||||
default 19
|
||||
config BSP_S_SPI2_MISO_PIN
|
||||
int "soft spi2 miso pin number"
|
||||
range 1 176
|
||||
default 20
|
||||
config BSP_S_SPI2_MOSI_PIN
|
||||
int "soft spi2 mosi pin number"
|
||||
range 1 176
|
||||
default 21
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable software SPI2 Bus (swspi2)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI2
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config RT_SOFT_SPI2_SCK_PIN
|
||||
int "swspi2 SCK pin number"
|
||||
default 19
|
||||
config RT_SOFT_SPI2_MISO_PIN
|
||||
int "swspi2 MISO pin number"
|
||||
default 20
|
||||
config RT_SOFT_SPI2_MOSI_PIN
|
||||
int "swspi2 MOSI pin number"
|
||||
default 21
|
||||
endif
|
||||
endif
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 16 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 18 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 91 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 19 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 20 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 21 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi2" if RT_USING_SOFT_SPI2
|
||||
|
||||
menuconfig BSP_USING_SPI
|
||||
bool "Enable SPI BUS"
|
||||
|
||||
@@ -9,18 +9,21 @@
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "dev_spi_flash.h"
|
||||
#include "dev_spi_flash_sfud.h"
|
||||
#include "drv_spi.h"
|
||||
#include "drv_soft_spi.h"
|
||||
|
||||
#ifdef BSP_USING_SOFT_SPI_FLASH
|
||||
|
||||
static struct rt_spi_device soft_spi_flash_device;
|
||||
|
||||
static int rt_soft_spi_flash_init(void)
|
||||
{
|
||||
rt_hw_softspi_device_attach("sspi2", "sspi20", GET_PIN(B, 14));
|
||||
rt_spi_bus_attach_device_cspin(&soft_spi_flash_device, "swspi20", "swspi2",
|
||||
GET_PIN(B, 14), RT_NULL);
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "sspi20"))
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "swspi20"))
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
*/
|
||||
|
||||
#include <drv_touch_xpt.h>
|
||||
#include <drv_soft_spi.h>
|
||||
#include <drv_spi.h>
|
||||
#include <drv_gpio.h>
|
||||
|
||||
@@ -19,10 +18,10 @@
|
||||
|
||||
#ifdef BSP_USING_TOUCH_RES
|
||||
|
||||
static const rt_uint8_t xpt2046_tx_data[21] = {0xD0, 0, 0xD0, 0, 0xD0, 0, 0xD0, 0, 0xD0, 0, 0x90, 0, 0x90, 0, 0x90, 0, 0x90, 0, 0x90, 0, 0};
|
||||
static const rt_uint8_t xpt2046_tx_data[21] = { 0xD0, 0, 0xD0, 0, 0xD0, 0, 0xD0, 0, 0xD0, 0, 0x90, 0, 0x90, 0, 0x90, 0, 0x90, 0, 0x90, 0, 0 };
|
||||
|
||||
/* Please calibrate the resistive touch screen before use, it is best to store the calibrated data */
|
||||
rt_err_t xpt2046_calibration(const char *lcd_name,const char *touch_name)
|
||||
rt_err_t xpt2046_calibration(const char *lcd_name, const char *touch_name)
|
||||
{
|
||||
/* Find the TFT LCD device */
|
||||
rt_device_t lcd = rt_device_find(lcd_name);
|
||||
@@ -215,8 +214,7 @@ static rt_err_t xpt2046_touch_control(struct rt_touch_device *touch, int cmd, vo
|
||||
return result;
|
||||
}
|
||||
|
||||
static struct rt_touch_ops xpt2046_ops =
|
||||
{
|
||||
static struct rt_touch_ops xpt2046_ops = {
|
||||
.touch_readpoint = xpt2046_touch_readpoint,
|
||||
.touch_control = xpt2046_touch_control,
|
||||
};
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
#include <rtdevice.h>
|
||||
#include "drv_touch_xpt.h"
|
||||
#include "drv_soft_spi.h"
|
||||
|
||||
#ifdef PKG_USING_GUIENGINE
|
||||
#include <rtgui/event.h>
|
||||
@@ -31,10 +30,12 @@ static rt_bool_t touch_down = RT_FALSE;
|
||||
* the drv_touch_xpt.h file,and set BSP_TOUCH_CALIBRATE to RT_FALSE */
|
||||
#define BSP_TOUCH_CALIBRATE RT_TRUE
|
||||
|
||||
#define BSP_XPT2046_SPI_BUS "sspi1"
|
||||
#define BSP_XPT2046_SPI_BUS "swspi1"
|
||||
#define TOUCH_DEVICE_NAME "xpt0"
|
||||
#define TFTLCD_DEVICE_NAME "lcd"
|
||||
|
||||
static struct rt_spi_device xpt2046_spi_device;
|
||||
|
||||
void xpt2046_init_hw(void)
|
||||
{
|
||||
/* Find the touch device */
|
||||
@@ -64,7 +65,8 @@ void xpt2046_init_hw(void)
|
||||
|
||||
/* Mount the spi device to the spi bus, here is the soft spi,
|
||||
* if you use other spi, please modify the following */
|
||||
rt_hw_softspi_device_attach(BSP_XPT2046_SPI_BUS, dev_name, rt_pin_get(BSP_XPT2046_CS_PIN));
|
||||
rt_spi_bus_attach_device_cspin(&xpt2046_spi_device, dev_name, BSP_XPT2046_SPI_BUS,
|
||||
rt_pin_get(BSP_XPT2046_CS_PIN), RT_NULL);
|
||||
|
||||
/* configure spi device */
|
||||
rt_xpt2046_t tc = (rt_xpt2046_t)touch;
|
||||
@@ -78,7 +80,7 @@ void xpt2046_init_hw(void)
|
||||
|
||||
#if (BSP_TOUCH_CALIBRATE == RT_TRUE)
|
||||
/* Calibrate touch */
|
||||
xpt2046_calibration(TFTLCD_DEVICE_NAME,TOUCH_DEVICE_NAME);
|
||||
xpt2046_calibration(TFTLCD_DEVICE_NAME, TOUCH_DEVICE_NAME);
|
||||
#endif /* BSP_TOUCH_CALIBRATE == RT_TRUE */
|
||||
|
||||
/* init the TFT LCD */
|
||||
@@ -97,14 +99,14 @@ void xpt2046_entry(void *parameter)
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef PKG_USING_LVGL
|
||||
#ifndef PKG_USING_LVGL
|
||||
rt_device_t lcd = rt_device_find(TFTLCD_DEVICE_NAME);
|
||||
if (lcd == RT_NULL)
|
||||
{
|
||||
rt_kprintf("can't find display device:%s\n", TFTLCD_DEVICE_NAME);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static rt_bool_t is_touching = RT_FALSE;
|
||||
static int no_touch_count = 0;
|
||||
@@ -113,9 +115,9 @@ void xpt2046_entry(void *parameter)
|
||||
static int stable_x = 0, stable_y = 0;
|
||||
|
||||
/* 5-point moving average filter for coordinate smoothing */
|
||||
#define HISTORY_SIZE 5
|
||||
static int history_x[HISTORY_SIZE] = {0};
|
||||
static int history_y[HISTORY_SIZE] = {0};
|
||||
#define HISTORY_SIZE 5
|
||||
static int history_x[HISTORY_SIZE] = { 0 };
|
||||
static int history_y[HISTORY_SIZE] = { 0 };
|
||||
static int history_index = 0;
|
||||
static int history_count = 0;
|
||||
|
||||
@@ -140,7 +142,8 @@ void xpt2046_entry(void *parameter)
|
||||
history_x[history_index] = current_x;
|
||||
history_y[history_index] = current_y;
|
||||
history_index = (history_index + 1) % HISTORY_SIZE;
|
||||
if (history_count < HISTORY_SIZE) history_count++;
|
||||
if (history_count < HISTORY_SIZE)
|
||||
history_count++;
|
||||
|
||||
int avg_x = 0, avg_y = 0;
|
||||
if (history_count > 0)
|
||||
@@ -161,7 +164,7 @@ void xpt2046_entry(void *parameter)
|
||||
|
||||
no_touch_count = 0;
|
||||
|
||||
#ifdef PKG_USING_LVGL
|
||||
#ifdef PKG_USING_LVGL
|
||||
if (!is_touching)
|
||||
{
|
||||
touch_hold_count++;
|
||||
@@ -206,10 +209,10 @@ void xpt2046_entry(void *parameter)
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
#else
|
||||
const rt_uint32_t black = 0x0;
|
||||
rt_graphix_ops(lcd)->set_pixel((const char *)(&black), avg_x, avg_y);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -220,9 +223,9 @@ void xpt2046_entry(void *parameter)
|
||||
{
|
||||
if (no_touch_count >= RELEASE_DEBOUNCE_COUNT)
|
||||
{
|
||||
#ifdef PKG_USING_LVGL
|
||||
#ifdef PKG_USING_LVGL
|
||||
lv_port_indev_input(stable_x, stable_y, LV_INDEV_STATE_REL);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
is_touching = RT_FALSE;
|
||||
no_touch_count = 0;
|
||||
@@ -234,9 +237,9 @@ void xpt2046_entry(void *parameter)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef PKG_USING_LVGL
|
||||
#ifdef PKG_USING_LVGL
|
||||
lv_port_indev_input(stable_x, stable_y, LV_INDEV_STATE_PR);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,48 +277,90 @@ menu "On-chip Peripheral Drivers"
|
||||
default n
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable soft SPI BUS"
|
||||
bool "Enable software SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_SPI
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_PIN
|
||||
if BSP_USING_SOFT_SPI
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable soft SPI1 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
int "soft spi1 sck pin number"
|
||||
range 1 176
|
||||
default 16
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
int "soft spi1 miso pin number"
|
||||
range 1 176
|
||||
default 18
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
int "soft spi1 mosi pin number"
|
||||
range 1 176
|
||||
default 91
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 16
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 18
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 91
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable soft SPI2 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config BSP_S_SPI2_SCK_PIN
|
||||
int "soft spi2 sck pin number"
|
||||
range 1 176
|
||||
default 19
|
||||
config BSP_S_SPI2_MISO_PIN
|
||||
int "soft spi2 miso pin number"
|
||||
range 1 176
|
||||
default 20
|
||||
config BSP_S_SPI2_MOSI_PIN
|
||||
int "soft spi2 mosi pin number"
|
||||
range 1 176
|
||||
default 21
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable software SPI2 Bus (swspi2)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI2
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config RT_SOFT_SPI2_SCK_PIN
|
||||
int "swspi2 SCK pin number"
|
||||
default 19
|
||||
config RT_SOFT_SPI2_MISO_PIN
|
||||
int "swspi2 MISO pin number"
|
||||
default 20
|
||||
config RT_SOFT_SPI2_MOSI_PIN
|
||||
int "swspi2 MOSI pin number"
|
||||
default 21
|
||||
endif
|
||||
endif
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 16 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 18 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 91 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 19 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 20 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 21 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi2" if RT_USING_SOFT_SPI2
|
||||
|
||||
menuconfig BSP_USING_SPI
|
||||
bool "Enable SPI BUS"
|
||||
|
||||
@@ -44,9 +44,9 @@ Hardware Drivers Config --->
|
||||
| 19 (D19) | GET_PIN(B, 2) | 是 | |
|
||||
| 20 (D20) | GET_PIN(G, 0) | 是 | |
|
||||
| 21 (D21) | GET_PIN(A, 0) | 是 | |
|
||||
| 22 (D22) | GET_PIN(G, 5) | 是 | SSPI1-SCK,默认被RT-Thread的SPI设备框架sspi1接管|
|
||||
| 23 (D23) | GET_PIN(G, 3) | 是 | SSPI1-MISO,默认被RT-Thread的SPI设备框架sspi1接管 |
|
||||
| 24 (D24) | GET_PIN(G, 1) | 是 | SSPI1-MOSI,默认被RT-Thread的SPI设备框架sspi1接管 |
|
||||
| 22 (D22) | GET_PIN(G, 5) | 是 | SWSPI1-SCK,默认被RT-Thread的SPI设备框架swspi1接管|
|
||||
| 23 (D23) | GET_PIN(G, 3) | 是 | SWSPI1-MISO,默认被RT-Thread的SPI设备框架swspi1接管 |
|
||||
| 24 (D24) | GET_PIN(G, 1) | 是 | SWSPI1-MOSI,默认被RT-Thread的SPI设备框架swspi1接管 |
|
||||
| 25 (D25) | GET_PIN(G, 7) | 是 | I2C1-SCL,默认被RT-Thread的I2C设备框架i2c1接管 |
|
||||
| 26 (D26) | GET_PIN(D, 7) | 是 | I2C1-SDA,默认被RT-Thread的I2C设备框架i2c1接管 |
|
||||
| 27 (D27) | GET_PIN(B, 6) | 是 | I2C2-SCL,默认被RT-Thread的I2C设备框架i2c2接管 |
|
||||
|
||||
@@ -19,51 +19,50 @@
|
||||
* Analog pins MUST give the device name and channel(ADC, PWM or DAC).
|
||||
* Arduino Pin must keep in sequence.
|
||||
*/
|
||||
const pin_map_t pin_map_table[]=
|
||||
{
|
||||
{D0, GET_PIN(A, 10), "uart1"}, /* Serial-RX */
|
||||
{D1, GET_PIN(A, 9), "uart1"}, /* Serial-TX */
|
||||
{D2, GET_PIN(A, 8)},
|
||||
{D3, GET_PIN(B, 10), "pwm2", 3}, /* PWM */
|
||||
{D4, GET_PIN(A, 1)},
|
||||
{D5, GET_PIN(B, 14)},
|
||||
{D6, GET_PIN(B, 11), "pwm2", 4}, /* PWM */
|
||||
{D7, GET_PIN(B, 15)},
|
||||
{D8, GET_PIN(F, 15)},
|
||||
{D9, GET_PIN(E, 11), "pwm1", 2}, /* PWM */
|
||||
{D10, GET_PIN(E, 13), "pwm1", 3}, /* PWM */
|
||||
{D11, GET_PIN(D, 12), "pwm4", 1}, /* PWM */
|
||||
{D12, GET_PIN(D, 10)},
|
||||
{D13, GET_PIN(D, 8)},
|
||||
{D14, GET_PIN(E, 14)},
|
||||
{D15, GET_PIN(E, 12)},
|
||||
{D16, GET_PIN(E, 15)},
|
||||
{D17, GET_PIN(D, 9)},
|
||||
{D18, GET_PIN(G, 2)},
|
||||
{D19, GET_PIN(B, 2)},
|
||||
{D20, GET_PIN(G, 0)},
|
||||
{D21, GET_PIN(A, 0)},
|
||||
{D22, GET_PIN(G, 5), "sspi1"}, /* SOFT-SPI-SCK */
|
||||
{D23, GET_PIN(G, 3), "sspi1"}, /* SOFT-SPI-SCK */
|
||||
{D24, GET_PIN(G, 1), "sspi1"}, /* SOFT-SPI-SCK */
|
||||
{D25, GET_PIN(G, 7), "i2c4"}, /* I2C-SCL (Wire) */
|
||||
{D26, GET_PIN(D, 7), "i2c4"}, /* I2C-SDA (Wire) */
|
||||
{D27, GET_PIN(B, 6), "i2c5"}, /* I2C-SCL (Wire) */
|
||||
{D28, GET_PIN(B, 7), "i2c5"}, /* I2C-SDA (Wire) */
|
||||
{D29, GET_PIN(G, 6)}, /* SPI-SS */
|
||||
{D30, GET_PIN(G, 4)},
|
||||
{D31, GET_PIN(A, 2), "uart2"}, /* Serial2-TX */
|
||||
{D32, GET_PIN(A, 3), "uart2"}, /* Serial2-RX */
|
||||
{D33, GET_PIN(F, 12)}, /* On-Board R_LED */
|
||||
{D34, GET_PIN(F, 11)}, /* On-Board B_LED */
|
||||
{D35, GET_PIN(B, 0)}, /* On_Board Buzzer */
|
||||
{D36, GET_PIN(C, 5)}, /* On-Board KEY_UP */
|
||||
{D37, GET_PIN(C, 1)}, /* On-Board KEY_DOWM */
|
||||
{D38, GET_PIN(C, 0)}, /* On-Board KEY_LEFT */
|
||||
{D39, GET_PIN(C, 4)}, /* On-Board KEY_RIGHT */
|
||||
{A0, GET_PIN(F, 6), "adc3", 4}, /* ADC */
|
||||
{A1, GET_PIN(F, 7), "adc3", 5}, /* ADC */
|
||||
{A2, GET_PIN(F, 4), "adc3", 14}, /* ADC */
|
||||
{A3, GET_PIN(F, 5), "adc3", 15}, /* ADC */
|
||||
{DAC0, GET_PIN(A, 4), "dac1", 1}, /* DAC */
|
||||
const pin_map_t pin_map_table[] = {
|
||||
{ D0, GET_PIN(A, 10), "uart1" }, /* Serial-RX */
|
||||
{ D1, GET_PIN(A, 9), "uart1" }, /* Serial-TX */
|
||||
{ D2, GET_PIN(A, 8) },
|
||||
{ D3, GET_PIN(B, 10), "pwm2", 3 }, /* PWM */
|
||||
{ D4, GET_PIN(A, 1) },
|
||||
{ D5, GET_PIN(B, 14) },
|
||||
{ D6, GET_PIN(B, 11), "pwm2", 4 }, /* PWM */
|
||||
{ D7, GET_PIN(B, 15) },
|
||||
{ D8, GET_PIN(F, 15) },
|
||||
{ D9, GET_PIN(E, 11), "pwm1", 2 }, /* PWM */
|
||||
{ D10, GET_PIN(E, 13), "pwm1", 3 }, /* PWM */
|
||||
{ D11, GET_PIN(D, 12), "pwm4", 1 }, /* PWM */
|
||||
{ D12, GET_PIN(D, 10) },
|
||||
{ D13, GET_PIN(D, 8) },
|
||||
{ D14, GET_PIN(E, 14) },
|
||||
{ D15, GET_PIN(E, 12) },
|
||||
{ D16, GET_PIN(E, 15) },
|
||||
{ D17, GET_PIN(D, 9) },
|
||||
{ D18, GET_PIN(G, 2) },
|
||||
{ D19, GET_PIN(B, 2) },
|
||||
{ D20, GET_PIN(G, 0) },
|
||||
{ D21, GET_PIN(A, 0) },
|
||||
{ D22, GET_PIN(G, 5), "swspi1" }, /* SOFT-SPI-SCK */
|
||||
{ D23, GET_PIN(G, 3), "swspi1" }, /* SOFT-SPI-SCK */
|
||||
{ D24, GET_PIN(G, 1), "swspi1" }, /* SOFT-SPI-SCK */
|
||||
{ D25, GET_PIN(G, 7), "i2c4" }, /* I2C-SCL (Wire) */
|
||||
{ D26, GET_PIN(D, 7), "i2c4" }, /* I2C-SDA (Wire) */
|
||||
{ D27, GET_PIN(B, 6), "i2c5" }, /* I2C-SCL (Wire) */
|
||||
{ D28, GET_PIN(B, 7), "i2c5" }, /* I2C-SDA (Wire) */
|
||||
{ D29, GET_PIN(G, 6) }, /* SPI-SS */
|
||||
{ D30, GET_PIN(G, 4) },
|
||||
{ D31, GET_PIN(A, 2), "uart2" }, /* Serial2-TX */
|
||||
{ D32, GET_PIN(A, 3), "uart2" }, /* Serial2-RX */
|
||||
{ D33, GET_PIN(F, 12) }, /* On-Board R_LED */
|
||||
{ D34, GET_PIN(F, 11) }, /* On-Board B_LED */
|
||||
{ D35, GET_PIN(B, 0) }, /* On_Board Buzzer */
|
||||
{ D36, GET_PIN(C, 5) }, /* On-Board KEY_UP */
|
||||
{ D37, GET_PIN(C, 1) }, /* On-Board KEY_DOWM */
|
||||
{ D38, GET_PIN(C, 0) }, /* On-Board KEY_LEFT */
|
||||
{ D39, GET_PIN(C, 4) }, /* On-Board KEY_RIGHT */
|
||||
{ A0, GET_PIN(F, 6), "adc3", 4 }, /* ADC */
|
||||
{ A1, GET_PIN(F, 7), "adc3", 5 }, /* ADC */
|
||||
{ A2, GET_PIN(F, 4), "adc3", 14 }, /* ADC */
|
||||
{ A3, GET_PIN(F, 5), "adc3", 15 }, /* ADC */
|
||||
{ DAC0, GET_PIN(A, 4), "dac1", 1 }, /* DAC */
|
||||
};
|
||||
|
||||
@@ -12,51 +12,51 @@
|
||||
#define Pins_Arduino_h
|
||||
|
||||
/* pins alias. Must keep in sequence */
|
||||
#define D0 (0)
|
||||
#define D1 (1)
|
||||
#define D2 (2)
|
||||
#define D3 (3)
|
||||
#define D4 (4)
|
||||
#define D5 (5)
|
||||
#define D6 (6)
|
||||
#define D7 (7)
|
||||
#define D8 (8)
|
||||
#define D9 (9)
|
||||
#define D10 (10)
|
||||
#define D11 (11)
|
||||
#define D12 (12)
|
||||
#define D13 (13)
|
||||
#define D14 (14)
|
||||
#define D15 (15)
|
||||
#define D16 (16)
|
||||
#define D17 (17)
|
||||
#define D18 (18)
|
||||
#define D19 (19)
|
||||
#define D20 (20)
|
||||
#define D21 (21)
|
||||
#define D22 (22)
|
||||
#define D23 (23)
|
||||
#define D24 (24)
|
||||
#define D25 (25)
|
||||
#define D26 (26)
|
||||
#define D27 (27)
|
||||
#define D28 (28)
|
||||
#define D29 (29)
|
||||
#define D30 (30)
|
||||
#define D31 (31)
|
||||
#define D32 (32)
|
||||
#define D33 (33)
|
||||
#define D34 (34)
|
||||
#define D35 (35)
|
||||
#define D36 (36)
|
||||
#define D37 (37)
|
||||
#define D38 (38)
|
||||
#define D39 (39)
|
||||
#define A0 (40)
|
||||
#define A1 (41)
|
||||
#define A2 (42)
|
||||
#define A3 (43)
|
||||
#define DAC0 (44)
|
||||
#define D0 (0)
|
||||
#define D1 (1)
|
||||
#define D2 (2)
|
||||
#define D3 (3)
|
||||
#define D4 (4)
|
||||
#define D5 (5)
|
||||
#define D6 (6)
|
||||
#define D7 (7)
|
||||
#define D8 (8)
|
||||
#define D9 (9)
|
||||
#define D10 (10)
|
||||
#define D11 (11)
|
||||
#define D12 (12)
|
||||
#define D13 (13)
|
||||
#define D14 (14)
|
||||
#define D15 (15)
|
||||
#define D16 (16)
|
||||
#define D17 (17)
|
||||
#define D18 (18)
|
||||
#define D19 (19)
|
||||
#define D20 (20)
|
||||
#define D21 (21)
|
||||
#define D22 (22)
|
||||
#define D23 (23)
|
||||
#define D24 (24)
|
||||
#define D25 (25)
|
||||
#define D26 (26)
|
||||
#define D27 (27)
|
||||
#define D28 (28)
|
||||
#define D29 (29)
|
||||
#define D30 (30)
|
||||
#define D31 (31)
|
||||
#define D32 (32)
|
||||
#define D33 (33)
|
||||
#define D34 (34)
|
||||
#define D35 (35)
|
||||
#define D36 (36)
|
||||
#define D37 (37)
|
||||
#define D38 (38)
|
||||
#define D39 (39)
|
||||
#define A0 (40)
|
||||
#define A1 (41)
|
||||
#define A2 (42)
|
||||
#define A3 (43)
|
||||
#define DAC0 (44)
|
||||
|
||||
#define RTDUINO_PIN_MAX_LIMIT DAC0 /* pin number max limit check */
|
||||
|
||||
@@ -68,8 +68,8 @@
|
||||
#define RTDUINO_DEFAULT_IIC_BUS_NAME "i2c4"
|
||||
|
||||
#define SS D32 /* Chip select pin of default spi */
|
||||
/* sspi1 : PG.5-SCK PG.3-MISO PG.1-MOSI */
|
||||
#define RTDUINO_DEFAULT_SPI_BUS_NAME "sspi1"
|
||||
/* swspi1 : PG.5-SCK PG.3-MISO PG.1-MOSI */
|
||||
#define RTDUINO_DEFAULT_SPI_BUS_NAME "swspi1"
|
||||
|
||||
/* Serial2(uart2) : PA.2-TX PA.3-RX */
|
||||
#define RTDUINO_SERIAL2_DEVICE_NAME "uart2"
|
||||
|
||||
@@ -347,48 +347,90 @@ menu "On-chip Peripheral Drivers"
|
||||
default n
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable soft SPI BUS"
|
||||
bool "Enable software SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_SPI
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_PIN
|
||||
if BSP_USING_SOFT_SPI
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable soft SPI1 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
int "soft spi1 sck pin number(G,5)"
|
||||
range 0 143
|
||||
default 101
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
int "soft spi1 miso pin numbe(G,3)"
|
||||
range 0 143
|
||||
default 99
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
int "soft spi1 mosi pin number(G,1)"
|
||||
range 0 143
|
||||
default 97
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 101
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 99
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 97
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable soft SPI2 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config BSP_S_SPI2_SCK_PIN
|
||||
int "soft spi2 sck pin number"
|
||||
range 0 143
|
||||
default 19
|
||||
config BSP_S_SPI2_MISO_PIN
|
||||
int "soft spi2 miso pin number"
|
||||
range 0 143
|
||||
default 20
|
||||
config BSP_S_SPI2_MOSI_PIN
|
||||
int "soft spi2 mosi pin number"
|
||||
range 0 143
|
||||
default 21
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable software SPI2 Bus (swspi2)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI2
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config RT_SOFT_SPI2_SCK_PIN
|
||||
int "swspi2 SCK pin number"
|
||||
default 19
|
||||
config RT_SOFT_SPI2_MISO_PIN
|
||||
int "swspi2 MISO pin number"
|
||||
default 20
|
||||
config RT_SOFT_SPI2_MOSI_PIN
|
||||
int "swspi2 MOSI pin number"
|
||||
default 21
|
||||
endif
|
||||
endif
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 101 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 99 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 97 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 19 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 20 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 21 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi2" if RT_USING_SOFT_SPI2
|
||||
|
||||
menuconfig BSP_USING_SPI
|
||||
bool "Enable SPI BUS"
|
||||
|
||||
@@ -9,19 +9,22 @@
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "dev_spi_flash.h"
|
||||
#include "dev_spi_flash_sfud.h"
|
||||
#include <drv_spi.h>
|
||||
#include <drv_soft_spi.h>
|
||||
|
||||
#ifdef BSP_USING_SOFT_SPI_FLASH
|
||||
|
||||
static struct rt_spi_device soft_spi_flash_device;
|
||||
|
||||
static int rt_soft_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
rt_hw_soft_spi_device_attach("sspi2", "sspi20", "PB.14");
|
||||
rt_spi_bus_attach_device_cspin(&soft_spi_flash_device, "swspi20", "swspi2",
|
||||
rt_pin_get("PB.14"), RT_NULL);
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "sspi20"))
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "swspi20"))
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
@@ -44,9 +44,9 @@ Hardware Drivers Config --->
|
||||
| 19 (D19) | GET_PIN(B, 2) | 是 | |
|
||||
| 20 (D20) | GET_PIN(G, 0) | 是 | |
|
||||
| 21 (D21) | GET_PIN(A, 0) | 是 | |
|
||||
| 22 (D22) | GET_PIN(G, 5) | 是 | SSPI1-SCK,默认被RT-Thread的SPI设备框架sspi1接管|
|
||||
| 23 (D23) | GET_PIN(G, 3) | 是 | SSPI1-MISO,默认被RT-Thread的SPI设备框架sspi1接管 |
|
||||
| 24 (D24) | GET_PIN(G, 1) | 是 | SSPI1-MOSI,默认被RT-Thread的SPI设备框架sspi1接管 |
|
||||
| 22 (D22) | GET_PIN(G, 5) | 是 | SWSPI1-SCK,默认被RT-Thread的SPI设备框架swspi1接管|
|
||||
| 23 (D23) | GET_PIN(G, 3) | 是 | SWSPI1-MISO,默认被RT-Thread的SPI设备框架swspi1接管 |
|
||||
| 24 (D24) | GET_PIN(G, 1) | 是 | SWSPI1-MOSI,默认被RT-Thread的SPI设备框架swspi1接管 |
|
||||
| 25 (D25) | GET_PIN(G, 7) | 是 | I2C1-SCL,默认被RT-Thread的I2C设备框架i2c1接管 |
|
||||
| 26 (D26) | GET_PIN(D, 7) | 是 | I2C1-SDA,默认被RT-Thread的I2C设备框架i2c1接管 |
|
||||
| 27 (D27) | GET_PIN(B, 6) | 是 | I2C2-SCL,默认被RT-Thread的I2C设备框架i2c2接管 |
|
||||
|
||||
@@ -42,9 +42,9 @@ const pin_map_t pin_map_table[] = {
|
||||
{ D19, GET_PIN(B, 2) },
|
||||
{ D20, GET_PIN(G, 0) },
|
||||
{ D21, GET_PIN(A, 0) },
|
||||
{ D22, GET_PIN(G, 5), "sspi1" }, /* SOFT-SPI-SCK */
|
||||
{ D23, GET_PIN(G, 3), "sspi1" }, /* SOFT-SPI-MISO */
|
||||
{ D24, GET_PIN(G, 1), "sspi1" }, /* SOFT-SPI-MOSI */
|
||||
{ D22, GET_PIN(G, 5), "swspi1" }, /* SOFT-SPI-SCK */
|
||||
{ D23, GET_PIN(G, 3), "swspi1" }, /* SOFT-SPI-MISO */
|
||||
{ D24, GET_PIN(G, 1), "swspi1" }, /* SOFT-SPI-MOSI */
|
||||
{ D25, GET_PIN(G, 7), "swi2c4" }, /* I2C-SCL (Wire) */
|
||||
{ D26, GET_PIN(D, 7), "swi2c4" }, /* I2C-SDA (Wire) */
|
||||
{ D27, GET_PIN(B, 6), "swi2c5" }, /* I2C-SCL (Wire) */
|
||||
|
||||
@@ -68,8 +68,8 @@
|
||||
#define RTDUINO_DEFAULT_IIC_BUS_NAME "swi2c4"
|
||||
|
||||
#define SS D32 /* Chip select pin of default spi */
|
||||
/* sspi1 : PG.5-SCK PG.3-MISO PG.1-MOSI */
|
||||
#define RTDUINO_DEFAULT_SPI_BUS_NAME "sspi1"
|
||||
/* swspi1 : PG.5-SCK PG.3-MISO PG.1-MOSI */
|
||||
#define RTDUINO_DEFAULT_SPI_BUS_NAME "swspi1"
|
||||
|
||||
/* Serial2(uart2) : PA.2-TX PA.3-RX */
|
||||
#define RTDUINO_SERIAL2_DEVICE_NAME "uart2"
|
||||
|
||||
@@ -636,48 +636,90 @@ menu "On-chip Peripheral Drivers"
|
||||
default n
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable soft SPI BUS"
|
||||
bool "Enable software SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_SPI
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_PIN
|
||||
if BSP_USING_SOFT_SPI
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable soft SPI1 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
int "soft spi1 sck pin number(G,5)"
|
||||
range 0 143
|
||||
default 101
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
int "soft spi1 miso pin numbe(G,3)"
|
||||
range 0 143
|
||||
default 99
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
int "soft spi1 mosi pin number(G,1)"
|
||||
range 0 143
|
||||
default 97
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 101
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 99
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 97
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable soft SPI2 BUS (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config BSP_S_SPI2_SCK_PIN
|
||||
int "soft spi2 sck pin number"
|
||||
range 0 143
|
||||
default 19
|
||||
config BSP_S_SPI2_MISO_PIN
|
||||
int "soft spi2 miso pin number"
|
||||
range 0 143
|
||||
default 20
|
||||
config BSP_S_SPI2_MOSI_PIN
|
||||
int "soft spi2 mosi pin number"
|
||||
range 0 143
|
||||
default 21
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable software SPI2 Bus (swspi2)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI2
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config RT_SOFT_SPI2_SCK_PIN
|
||||
int "swspi2 SCK pin number"
|
||||
default 19
|
||||
config RT_SOFT_SPI2_MISO_PIN
|
||||
int "swspi2 MISO pin number"
|
||||
default 20
|
||||
config RT_SOFT_SPI2_MOSI_PIN
|
||||
int "swspi2 MOSI pin number"
|
||||
default 21
|
||||
endif
|
||||
endif
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 101 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 99 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 97 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 19 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 20 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 21 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi2" if RT_USING_SOFT_SPI2
|
||||
|
||||
menuconfig BSP_USING_SPI
|
||||
bool "Enable SPI BUS"
|
||||
|
||||
@@ -9,19 +9,22 @@
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "dev_spi_flash.h"
|
||||
#include "dev_spi_flash_sfud.h"
|
||||
#include <drv_spi.h>
|
||||
#include <drv_soft_spi.h>
|
||||
|
||||
#ifdef BSP_USING_SOFT_SPI_FLASH
|
||||
|
||||
static struct rt_spi_device soft_spi_flash_device;
|
||||
|
||||
static int rt_soft_spi_flash_init(void)
|
||||
{
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
rt_hw_soft_spi_device_attach("sspi2", "sspi20", "PB.14");
|
||||
rt_spi_bus_attach_device_cspin(&soft_spi_flash_device, "swspi20", "swspi2",
|
||||
rt_pin_get("PB.14"), RT_NULL);
|
||||
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "sspi20"))
|
||||
if (RT_NULL == rt_sfud_flash_probe("W25Q128", "swspi20"))
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ if GetDepend('SOC_RISCV_FAMILY_CH32'):
|
||||
src += ['drv_i2c.c']
|
||||
|
||||
if GetDepend('BSP_USING_SPI'):
|
||||
src += ['drv_soft_spi.c','drv_spi.c']
|
||||
src += ['drv_spi.c']
|
||||
|
||||
if GetDepend('BSP_USING_RTC'):
|
||||
src += ['drv_rtc.c']
|
||||
|
||||
@@ -1,238 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-10-01 zhs the first version which add from wch
|
||||
*/
|
||||
|
||||
#include <board.h>
|
||||
#include "drv_soft_spi.h"
|
||||
|
||||
#ifdef BSP_USING_SOFT_SPI
|
||||
|
||||
#define LOG_TAG "drv.soft_spi"
|
||||
#include <drv_log.h>
|
||||
|
||||
static struct ch32_soft_spi_config soft_spi_config[] =
|
||||
{
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
SOFT_SPI1_BUS_CONFIG,
|
||||
#endif
|
||||
#ifdef BSP_USING_SOFT_SPI2
|
||||
SOFT_SPI2_BUS_CONFIG,
|
||||
#endif
|
||||
};
|
||||
|
||||
static struct ch32_soft_spi spi_obj[sizeof(soft_spi_config) / sizeof(soft_spi_config[0])];
|
||||
|
||||
/**
|
||||
* 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 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void ch32_spi_gpio_init(struct ch32_soft_spi *spi)
|
||||
{
|
||||
struct ch32_soft_spi_config *cfg = (struct ch32_soft_spi_config *)spi->cfg;
|
||||
rt_pin_mode(cfg->sck, PIN_MODE_OUTPUT);
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_INPUT);
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_OUTPUT);
|
||||
|
||||
rt_pin_write(cfg->miso, PIN_HIGH);
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
|
||||
void ch32_tog_sclk(void *data)
|
||||
{
|
||||
struct ch32_soft_spi_config* cfg = (struct ch32_soft_spi_config*)data;
|
||||
if(rt_pin_read(cfg->sck) == PIN_HIGH)
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
void ch32_set_sclk(void *data, rt_int32_t state)
|
||||
{
|
||||
|
||||
struct ch32_soft_spi_config* cfg = (struct ch32_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->sck, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void ch32_set_mosi(void *data, rt_int32_t state)
|
||||
{
|
||||
struct ch32_soft_spi_config* cfg = (struct ch32_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->mosi, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void ch32_set_miso(void *data, rt_int32_t state)
|
||||
{
|
||||
struct ch32_soft_spi_config* cfg = (struct ch3_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_write(cfg->miso, PIN_HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_write(cfg->miso, PIN_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
rt_int32_t ch32_get_sclk(void *data)
|
||||
{
|
||||
struct ch32_soft_spi_config* cfg = (struct ch32_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->sck);
|
||||
}
|
||||
|
||||
rt_int32_t ch32_get_mosi(void *data)
|
||||
{
|
||||
struct ch32_soft_spi_config* cfg = (struct ch32_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->mosi);
|
||||
}
|
||||
|
||||
rt_int32_t ch32_get_miso(void *data)
|
||||
{
|
||||
struct ch32_soft_spi_config* cfg = (struct ch32_soft_spi_config*)data;
|
||||
return rt_pin_read(cfg->miso);
|
||||
}
|
||||
|
||||
void ch32_dir_mosi(void *data, rt_int32_t state)
|
||||
{
|
||||
struct ch32_soft_spi_config* cfg = (struct ch32_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_mode(cfg->mosi, PIN_MODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
void ch32_dir_miso(void *data, rt_int32_t state)
|
||||
{
|
||||
struct ch32_soft_spi_config* cfg = (struct ch32_soft_spi_config*)data;
|
||||
if (state)
|
||||
{
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_INPUT);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_pin_mode(cfg->miso, PIN_MODE_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
static void ch32_udelay(rt_uint32_t us)
|
||||
{
|
||||
rt_uint32_t ticks;
|
||||
rt_uint32_t told, tnow, tcnt = 0;
|
||||
rt_uint32_t reload = SysTick->CMP;
|
||||
|
||||
ticks = us * reload / (1000000 / RT_TICK_PER_SECOND);
|
||||
told = SysTick->CNT;
|
||||
while (1)
|
||||
{
|
||||
tnow = SysTick->CNT;
|
||||
if (tnow != told)
|
||||
{
|
||||
if (tnow > told)
|
||||
{
|
||||
tcnt += tnow - told;
|
||||
}
|
||||
else
|
||||
{
|
||||
tcnt += reload - told + tnow;
|
||||
}
|
||||
told = tnow;
|
||||
if (tcnt >= ticks)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void ch32_pin_init(void)
|
||||
{
|
||||
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct ch32_soft_spi);
|
||||
|
||||
for(rt_size_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
ch32_spi_gpio_init(&spi_obj[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static struct rt_spi_bit_ops ch32_soft_spi_ops =
|
||||
{
|
||||
.data = RT_NULL,
|
||||
.pin_init = ch32_pin_init,
|
||||
.tog_sclk = ch32_tog_sclk,
|
||||
.set_sclk = ch32_set_sclk,
|
||||
.set_mosi = ch32_set_mosi,
|
||||
.set_miso = ch32_set_miso,
|
||||
.get_sclk = ch32_get_sclk,
|
||||
.get_mosi = ch32_get_mosi,
|
||||
.get_miso = ch32_get_miso,
|
||||
.dir_mosi = ch32_dir_mosi,
|
||||
.dir_miso = ch32_dir_miso,
|
||||
.udelay = ch32_udelay,
|
||||
.delay_us = 1,
|
||||
};
|
||||
|
||||
/* Soft SPI initialization function */
|
||||
int rt_soft_spi_init(void)
|
||||
{
|
||||
rt_size_t obj_num = sizeof(spi_obj) / sizeof(struct ch32_soft_spi);
|
||||
rt_err_t result;
|
||||
|
||||
for (rt_size_t i = 0; i < obj_num; i++)
|
||||
{
|
||||
ch32_soft_spi_ops.data = (void *)&soft_spi_config[i];
|
||||
spi_obj[i].spi.ops = &ch32_soft_spi_ops;
|
||||
spi_obj[i].cfg = (void *)&soft_spi_config[i];
|
||||
result = rt_spi_bit_add_bus(&spi_obj[i].spi, soft_spi_config[i].bus_name, &ch32_soft_spi_ops);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_soft_spi_init);
|
||||
|
||||
#endif /* BSP_USING_SOFT_SPI */
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2022-10-01 zhs the first version which add from wch
|
||||
*/
|
||||
#ifndef LIBRARIES_HAL_DRIVERS_DRV_SOFT_SPI_H_
|
||||
#define LIBRARIES_HAL_DRIVERS_DRV_SOFT_SPI_H_
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
#include <dev_spi_bit_ops.h>
|
||||
|
||||
/* ch32 soft spi config */
|
||||
struct ch32_soft_spi_config
|
||||
{
|
||||
rt_uint8_t sck;
|
||||
rt_uint8_t mosi;
|
||||
rt_uint8_t miso;
|
||||
const char *bus_name;
|
||||
};
|
||||
|
||||
/* ch32 soft spi dirver */
|
||||
struct ch32_soft_spi
|
||||
{
|
||||
struct rt_spi_bit_obj spi;
|
||||
struct ch32_soft_spi_config *cfg;
|
||||
};
|
||||
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
#define SOFT_SPI1_BUS_CONFIG \
|
||||
{ \
|
||||
.sck = BSP_S_SPI1_SCK_PIN, \
|
||||
.mosi = BSP_S_SPI1_MOSI_PIN, \
|
||||
.miso = BSP_S_SPI1_MISO_PIN, \
|
||||
.bus_name = "sspi1", \
|
||||
}
|
||||
#endif /* BSP_USING_SOFT_SPI1 */
|
||||
#ifdef BSP_USING_SOFT_SPI2
|
||||
#define SOFT_SPI2_BUS_CONFIG \
|
||||
{ \
|
||||
.sck = BSP_S_SPI2_SCK_PIN, \
|
||||
.mosi = BSP_S_SPI2_MOSI_PIN, \
|
||||
.miso = BSP_S_SPI2_MISO_PIN, \
|
||||
.bus_name = "sspi2", \
|
||||
}
|
||||
#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);
|
||||
int rt_soft_spi_init(void);
|
||||
|
||||
#endif /* __DRV_SOFT_SPI__ */
|
||||
|
||||
@@ -153,7 +153,6 @@ menu "On-chip Peripheral Drivers"
|
||||
endif
|
||||
menuconfig BSP_USING_SPI
|
||||
bool "Enable SPI"
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_SPI
|
||||
|
||||
if BSP_USING_SPI
|
||||
@@ -175,45 +174,90 @@ menu "On-chip Peripheral Drivers"
|
||||
default n
|
||||
endif
|
||||
|
||||
config BSP_USING_SOFT_SPI1
|
||||
bool "Enable SSPI1 Bus (User SPI)"
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
comment "Notice: PB9 --> 25; PB8 --> 24; PB7 --> 23"
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
int "sspi1 SCL pin number"
|
||||
range 1 79
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 25
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
int "sspi1 MISO pin number"
|
||||
range 1 79
|
||||
default 24
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
int "sspi1 MOSI pin number"
|
||||
range 1 79
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 23
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 24
|
||||
endif
|
||||
|
||||
config BSP_USING_SOFT_SPI2
|
||||
bool "Enable SSPI2 Bus (soft SPI)"
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable software SPI2 Bus (swspi2)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI
|
||||
select RT_USING_SOFT_SPI2
|
||||
if BSP_USING_SOFT_SPI2
|
||||
comment "Notice: PE0 --> 64; PE1 --> 65; PE2 --> 66"
|
||||
config BSP_S_SPI2_SCK_PIN
|
||||
int "sspi2 SCL pin number"
|
||||
range 1 79
|
||||
config RT_SOFT_SPI2_SCK_PIN
|
||||
int "swspi2 SCK pin number"
|
||||
default 64
|
||||
config BSP_S_SPI2_MOSI_PIN
|
||||
int "sspi2 MISO pin number"
|
||||
range 1 79
|
||||
default 65
|
||||
config BSP_S_SPI2_MISO_PIN
|
||||
int "sspi2 MOSI pin number"
|
||||
range 1 79
|
||||
config RT_SOFT_SPI2_MISO_PIN
|
||||
int "swspi2 MISO pin number"
|
||||
default 66
|
||||
config RT_SOFT_SPI2_MOSI_PIN
|
||||
int "swspi2 MOSI pin number"
|
||||
default 65
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 25 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 23 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 24 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 64 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 66 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 65 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi2" if RT_USING_SOFT_SPI2
|
||||
|
||||
config BSP_USING_RTC
|
||||
bool "Enable RTC"
|
||||
select RT_USING_RTC
|
||||
|
||||
@@ -439,48 +439,90 @@ menu "On-chip Peripheral Drivers"
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable SOFT SPI"
|
||||
bool "Enable software SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_SPI
|
||||
select RT_USING_SOFT_SPI
|
||||
|
||||
if BSP_USING_SOFT_SPI
|
||||
config BSP_USING_SOFT_SPI1
|
||||
bool "Enable SSPI1 Bus (User SPI)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI1
|
||||
comment "Notice: PB9 --> 25; PB8 --> 24; PB7 --> 23"
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
int "sspi1 SCL pin number"
|
||||
range 1 79
|
||||
default 25
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
int "sspi1 MISO pin number"
|
||||
range 1 79
|
||||
default 24
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
int "sspi1 MOSI pin number"
|
||||
range 1 79
|
||||
default 23
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 25
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 23
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 24
|
||||
endif
|
||||
|
||||
config BSP_USING_SOFT_SPI2
|
||||
bool "Enable SSPI2 Bus (soft SPI)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI2
|
||||
comment "Notice: PE0 --> 64; PE1 --> 65; PE2 --> 66"
|
||||
config BSP_S_SPI2_SCK_PIN
|
||||
int "sspi2 SCL pin number"
|
||||
range 1 79
|
||||
default 64
|
||||
config BSP_S_SPI2_MOSI_PIN
|
||||
int "sspi2 MISO pin number"
|
||||
range 1 79
|
||||
default 65
|
||||
config BSP_S_SPI2_MISO_PIN
|
||||
int "sspi2 MOSI pin number"
|
||||
range 1 79
|
||||
default 66
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable software SPI2 Bus (swspi2)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI2
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config RT_SOFT_SPI2_SCK_PIN
|
||||
int "swspi2 SCK pin number"
|
||||
default 64
|
||||
config RT_SOFT_SPI2_MISO_PIN
|
||||
int "swspi2 MISO pin number"
|
||||
default 66
|
||||
config RT_SOFT_SPI2_MOSI_PIN
|
||||
int "swspi2 MOSI pin number"
|
||||
default 65
|
||||
endif
|
||||
endif
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 25 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 23 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 24 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 64 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 66 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 65 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi2" if RT_USING_SOFT_SPI2
|
||||
|
||||
config BSP_USING_RTC
|
||||
bool "Enable RTC"
|
||||
|
||||
@@ -150,48 +150,90 @@ menu "On-chip Peripheral Drivers"
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SOFT_SPI
|
||||
bool "Enable SOFT SPI"
|
||||
bool "Enable software SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_SPI
|
||||
select RT_USING_SOFT_SPI
|
||||
|
||||
if BSP_USING_SOFT_SPI
|
||||
config BSP_USING_SOFT_SPI1
|
||||
bool "Enable SSPI1 Bus (User SPI)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI1
|
||||
comment "Notice: PB9 --> 25; PB8 --> 24; PB7 --> 23"
|
||||
config BSP_S_SPI1_SCK_PIN
|
||||
int "sspi1 SCL pin number"
|
||||
range 1 79
|
||||
default 25
|
||||
config BSP_S_SPI1_MOSI_PIN
|
||||
int "sspi1 MISO pin number"
|
||||
range 1 79
|
||||
default 24
|
||||
config BSP_S_SPI1_MISO_PIN
|
||||
int "sspi1 MOSI pin number"
|
||||
range 1 79
|
||||
default 23
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI1
|
||||
if BSP_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "swspi1 SCK pin number"
|
||||
default 25
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "swspi1 MISO pin number"
|
||||
default 23
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "swspi1 MOSI pin number"
|
||||
default 24
|
||||
endif
|
||||
|
||||
config BSP_USING_SOFT_SPI2
|
||||
bool "Enable SSPI2 Bus (soft SPI)"
|
||||
default n
|
||||
if BSP_USING_SOFT_SPI2
|
||||
comment "Notice: PE0 --> 64; PE1 --> 65; PE2 --> 66"
|
||||
config BSP_S_SPI2_SCK_PIN
|
||||
int "sspi2 SCL pin number"
|
||||
range 1 79
|
||||
default 64
|
||||
config BSP_S_SPI2_MOSI_PIN
|
||||
int "sspi2 MISO pin number"
|
||||
range 1 79
|
||||
default 65
|
||||
config BSP_S_SPI2_MISO_PIN
|
||||
int "sspi2 MOSI pin number"
|
||||
range 1 79
|
||||
default 66
|
||||
endif
|
||||
menuconfig BSP_USING_SOFT_SPI2
|
||||
bool "Enable software SPI2 Bus (swspi2)"
|
||||
default n
|
||||
select RT_USING_SOFT_SPI2
|
||||
if BSP_USING_SOFT_SPI2
|
||||
config RT_SOFT_SPI2_SCK_PIN
|
||||
int "swspi2 SCK pin number"
|
||||
default 64
|
||||
config RT_SOFT_SPI2_MISO_PIN
|
||||
int "swspi2 MISO pin number"
|
||||
default 66
|
||||
config RT_SOFT_SPI2_MOSI_PIN
|
||||
int "swspi2 MOSI pin number"
|
||||
default 65
|
||||
endif
|
||||
endif
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 25 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 23 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 24 if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi1" if RT_USING_SOFT_SPI1
|
||||
|
||||
config RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_SCK_PIN_DEFAULT
|
||||
int
|
||||
default 64 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MISO_PIN_DEFAULT
|
||||
int
|
||||
default 66 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_MOSI_PIN_DEFAULT
|
||||
int
|
||||
default 65 if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
default y if RT_USING_SOFT_SPI2
|
||||
|
||||
config RT_SOFT_SPI2_BUS_NAME_DEFAULT
|
||||
string
|
||||
default "swspi2" if RT_USING_SOFT_SPI2
|
||||
|
||||
menuconfig BSP_USING_RTC
|
||||
bool "Enable RTC"
|
||||
|
||||
+171
-17
@@ -13,174 +13,328 @@ menuconfig RT_USING_SPI
|
||||
default n
|
||||
|
||||
menuconfig RT_USING_SOFT_SPI
|
||||
bool "Use GPIO to simulate SPI"
|
||||
bool "Use GPIO to simulate SPI (swspi)"
|
||||
default n
|
||||
select RT_USING_PIN
|
||||
select RT_USING_SPI_BITOPS
|
||||
if RT_USING_SOFT_SPI
|
||||
config RT_SOFT_SPI0_HAS_PIN_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI0_SCK_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI0_MISO_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI0_MOSI_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI0_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI0_BUS_NAME_DEFAULT
|
||||
string
|
||||
|
||||
menuconfig RT_USING_SOFT_SPI0
|
||||
bool "Enable SPI0 Bus (software simulation)"
|
||||
default y
|
||||
bool "Enable software SPI0 Bus (swspi0)"
|
||||
default n
|
||||
if RT_USING_SOFT_SPI0
|
||||
config RT_SOFT_SPI0_SCK_PIN
|
||||
int "SCK pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI0_SCK_PIN_DEFAULT if RT_SOFT_SPI0_HAS_PIN_DEFAULT
|
||||
default 1
|
||||
config RT_SOFT_SPI0_MISO_PIN
|
||||
int "MISO pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI0_MISO_PIN_DEFAULT if RT_SOFT_SPI0_HAS_PIN_DEFAULT
|
||||
default 2
|
||||
config RT_SOFT_SPI0_MOSI_PIN
|
||||
int "MOSI pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI0_MOSI_PIN_DEFAULT if RT_SOFT_SPI0_HAS_PIN_DEFAULT
|
||||
default 3
|
||||
config RT_SOFT_SPI0_BUS_NAME
|
||||
string "Bus name"
|
||||
default "spi0"
|
||||
default RT_SOFT_SPI0_BUS_NAME_DEFAULT if RT_SOFT_SPI0_HAS_BUS_NAME_DEFAULT
|
||||
default "swspi0"
|
||||
config RT_SOFT_SPI0_TIMING_DELAY
|
||||
int "Timing delay (us)"
|
||||
range 0 32767
|
||||
default 1
|
||||
endif
|
||||
config RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI1_SCK_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI1_MISO_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI1_MOSI_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI1_BUS_NAME_DEFAULT
|
||||
string
|
||||
|
||||
menuconfig RT_USING_SOFT_SPI1
|
||||
bool "Enable SPI1 Bus (software simulation)"
|
||||
default y
|
||||
bool "Enable software SPI1 Bus (swspi1)"
|
||||
default n
|
||||
if RT_USING_SOFT_SPI1
|
||||
config RT_SOFT_SPI1_SCK_PIN
|
||||
int "SCK pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI1_SCK_PIN_DEFAULT if RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
default 4
|
||||
config RT_SOFT_SPI1_MISO_PIN
|
||||
int "MISO pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI1_MISO_PIN_DEFAULT if RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
default 5
|
||||
config RT_SOFT_SPI1_MOSI_PIN
|
||||
int "MOSI pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI1_MOSI_PIN_DEFAULT if RT_SOFT_SPI1_HAS_PIN_DEFAULT
|
||||
default 6
|
||||
config RT_SOFT_SPI1_BUS_NAME
|
||||
string "Bus name"
|
||||
default "spi1"
|
||||
default RT_SOFT_SPI1_BUS_NAME_DEFAULT if RT_SOFT_SPI1_HAS_BUS_NAME_DEFAULT
|
||||
default "swspi1"
|
||||
config RT_SOFT_SPI1_TIMING_DELAY
|
||||
int "Timing delay (us)"
|
||||
range 0 32767
|
||||
default 1
|
||||
endif
|
||||
config RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI2_SCK_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI2_MISO_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI2_MOSI_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI2_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI2_BUS_NAME_DEFAULT
|
||||
string
|
||||
|
||||
menuconfig RT_USING_SOFT_SPI2
|
||||
bool "Enable SPI2 Bus (software simulation)"
|
||||
bool "Enable software SPI2 Bus (swspi2)"
|
||||
default n
|
||||
if RT_USING_SOFT_SPI2
|
||||
config RT_SOFT_SPI2_SCK_PIN
|
||||
int "SCK pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI2_SCK_PIN_DEFAULT if RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
default 7
|
||||
config RT_SOFT_SPI2_MISO_PIN
|
||||
int "MISO pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI2_MISO_PIN_DEFAULT if RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
default 8
|
||||
config RT_SOFT_SPI2_MOSI_PIN
|
||||
int "MOSI pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI2_MOSI_PIN_DEFAULT if RT_SOFT_SPI2_HAS_PIN_DEFAULT
|
||||
default 9
|
||||
config RT_SOFT_SPI2_BUS_NAME
|
||||
string "Bus name"
|
||||
default "spi2"
|
||||
default RT_SOFT_SPI2_BUS_NAME_DEFAULT if RT_SOFT_SPI2_HAS_BUS_NAME_DEFAULT
|
||||
default "swspi2"
|
||||
config RT_SOFT_SPI2_TIMING_DELAY
|
||||
int "Timing delay (us)"
|
||||
range 0 32767
|
||||
default 1
|
||||
endif
|
||||
config RT_SOFT_SPI3_HAS_PIN_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI3_SCK_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI3_MISO_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI3_MOSI_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI3_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI3_BUS_NAME_DEFAULT
|
||||
string
|
||||
|
||||
menuconfig RT_USING_SOFT_SPI3
|
||||
bool "Enable SPI3 Bus (software simulation)"
|
||||
bool "Enable software SPI3 Bus (swspi3)"
|
||||
default n
|
||||
if RT_USING_SOFT_SPI3
|
||||
config RT_SOFT_SPI3_SCK_PIN
|
||||
int "SCK pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI3_SCK_PIN_DEFAULT if RT_SOFT_SPI3_HAS_PIN_DEFAULT
|
||||
default 10
|
||||
config RT_SOFT_SPI3_MISO_PIN
|
||||
int "MISO pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI3_MISO_PIN_DEFAULT if RT_SOFT_SPI3_HAS_PIN_DEFAULT
|
||||
default 11
|
||||
config RT_SOFT_SPI3_MOSI_PIN
|
||||
int "MOSI pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI3_MOSI_PIN_DEFAULT if RT_SOFT_SPI3_HAS_PIN_DEFAULT
|
||||
default 12
|
||||
config RT_SOFT_SPI3_BUS_NAME
|
||||
string "Bus name"
|
||||
default "spi3"
|
||||
default RT_SOFT_SPI3_BUS_NAME_DEFAULT if RT_SOFT_SPI3_HAS_BUS_NAME_DEFAULT
|
||||
default "swspi3"
|
||||
config RT_SOFT_SPI3_TIMING_DELAY
|
||||
int "Timing delay (us)"
|
||||
range 0 32767
|
||||
default 1
|
||||
endif
|
||||
config RT_SOFT_SPI4_HAS_PIN_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI4_SCK_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI4_MISO_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI4_MOSI_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI4_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI4_BUS_NAME_DEFAULT
|
||||
string
|
||||
|
||||
menuconfig RT_USING_SOFT_SPI4
|
||||
bool "Enable SPI4 Bus (software simulation)"
|
||||
bool "Enable software SPI4 Bus (swspi4)"
|
||||
default n
|
||||
if RT_USING_SOFT_SPI4
|
||||
config RT_SOFT_SPI4_SCK_PIN
|
||||
int "SCK pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI4_SCK_PIN_DEFAULT if RT_SOFT_SPI4_HAS_PIN_DEFAULT
|
||||
default 13
|
||||
config RT_SOFT_SPI4_MISO_PIN
|
||||
int "MISO pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI4_MISO_PIN_DEFAULT if RT_SOFT_SPI4_HAS_PIN_DEFAULT
|
||||
default 14
|
||||
config RT_SOFT_SPI4_MOSI_PIN
|
||||
int "MOSI pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI4_MOSI_PIN_DEFAULT if RT_SOFT_SPI4_HAS_PIN_DEFAULT
|
||||
default 15
|
||||
config RT_SOFT_SPI4_BUS_NAME
|
||||
string "Bus name"
|
||||
default "spi4"
|
||||
default RT_SOFT_SPI4_BUS_NAME_DEFAULT if RT_SOFT_SPI4_HAS_BUS_NAME_DEFAULT
|
||||
default "swspi4"
|
||||
config RT_SOFT_SPI4_TIMING_DELAY
|
||||
int "Timing delay (us)"
|
||||
range 0 32767
|
||||
default 1
|
||||
endif
|
||||
config RT_SOFT_SPI5_HAS_PIN_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI5_SCK_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI5_MISO_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI5_MOSI_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI5_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI5_BUS_NAME_DEFAULT
|
||||
string
|
||||
|
||||
menuconfig RT_USING_SOFT_SPI5
|
||||
bool "Enable SPI5 Bus (software simulation)"
|
||||
bool "Enable software SPI5 Bus (swspi5)"
|
||||
default n
|
||||
if RT_USING_SOFT_SPI5
|
||||
config RT_SOFT_SPI5_SCK_PIN
|
||||
int "SCK pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI5_SCK_PIN_DEFAULT if RT_SOFT_SPI5_HAS_PIN_DEFAULT
|
||||
default 16
|
||||
config RT_SOFT_SPI5_MISO_PIN
|
||||
int "MISO pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI5_MISO_PIN_DEFAULT if RT_SOFT_SPI5_HAS_PIN_DEFAULT
|
||||
default 17
|
||||
config RT_SOFT_SPI5_MOSI_PIN
|
||||
int "MOSI pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI5_MOSI_PIN_DEFAULT if RT_SOFT_SPI5_HAS_PIN_DEFAULT
|
||||
default 18
|
||||
config RT_SOFT_SPI5_BUS_NAME
|
||||
string "Bus name"
|
||||
default "spi5"
|
||||
default RT_SOFT_SPI5_BUS_NAME_DEFAULT if RT_SOFT_SPI5_HAS_BUS_NAME_DEFAULT
|
||||
default "swspi5"
|
||||
config RT_SOFT_SPI5_TIMING_DELAY
|
||||
int "Timing delay (us)"
|
||||
range 0 32767
|
||||
default 1
|
||||
endif
|
||||
config RT_SOFT_SPI6_HAS_PIN_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI6_SCK_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI6_MISO_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI6_MOSI_PIN_DEFAULT
|
||||
int
|
||||
|
||||
config RT_SOFT_SPI6_HAS_BUS_NAME_DEFAULT
|
||||
bool
|
||||
|
||||
config RT_SOFT_SPI6_BUS_NAME_DEFAULT
|
||||
string
|
||||
|
||||
menuconfig RT_USING_SOFT_SPI6
|
||||
bool "Enable SPI6 Bus (software simulation)"
|
||||
bool "Enable software SPI6 Bus (swspi6)"
|
||||
default n
|
||||
if RT_USING_SOFT_SPI6
|
||||
config RT_SOFT_SPI6_SCK_PIN
|
||||
int "SCK pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI6_SCK_PIN_DEFAULT if RT_SOFT_SPI6_HAS_PIN_DEFAULT
|
||||
default 19
|
||||
config RT_SOFT_SPI6_MISO_PIN
|
||||
int "MISO pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI6_MISO_PIN_DEFAULT if RT_SOFT_SPI6_HAS_PIN_DEFAULT
|
||||
default 20
|
||||
config RT_SOFT_SPI6_MOSI_PIN
|
||||
int "MOSI pin number"
|
||||
range 0 32767
|
||||
default RT_SOFT_SPI6_MOSI_PIN_DEFAULT if RT_SOFT_SPI6_HAS_PIN_DEFAULT
|
||||
default 21
|
||||
config RT_SOFT_SPI6_BUS_NAME
|
||||
string "Bus name"
|
||||
default "spi6"
|
||||
default RT_SOFT_SPI6_BUS_NAME_DEFAULT if RT_SOFT_SPI6_HAS_BUS_NAME_DEFAULT
|
||||
default "swspi6"
|
||||
config RT_SOFT_SPI6_TIMING_DELAY
|
||||
int "Timing delay (us)"
|
||||
range 0 32767
|
||||
|
||||
@@ -253,10 +253,10 @@ int rt_soft_spi_init(void)
|
||||
{
|
||||
rt_memcpy(&spi_obj[i].ops, &soft_spi_ops, sizeof(struct rt_spi_bit_ops));
|
||||
spi_obj[i].ops.data = (void *)&soft_spi_config[i];
|
||||
spi_obj[i].spi.ops = &soft_spi_ops;
|
||||
spi_obj[i].ops.delay_us = soft_spi_config[i].timing_delay;
|
||||
spi_obj[i].spi.ops = &spi_obj[i].ops;
|
||||
spi_obj[i].cfg = (void *)&soft_spi_config[i];
|
||||
spi_soft_pin_init(&spi_obj[i]);
|
||||
spi_obj[i].spi.ops->delay_us = soft_spi_config[i].timing_delay;
|
||||
result = rt_spi_bit_add_bus(&spi_obj[i].spi, soft_spi_config[i].bus_name, &spi_obj[i].ops);
|
||||
RT_ASSERT(result == RT_EOK);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user