[bsp][lpc55sxx]update: drv_soft_i2c drv_soft_spi
1.config pin in menuconfig; 2.update format; 3.chang soft_i2c name
This commit is contained in:
parent
b3ea130ddd
commit
5d299ffdcd
@ -8,7 +8,7 @@
|
||||
* 2023-04-11 linshire the first version
|
||||
*/
|
||||
|
||||
#include <board.h>
|
||||
#include "board.h"
|
||||
#include "drv_soft_i2c.h"
|
||||
|
||||
#ifdef BSP_USING_SOFT_I2C
|
||||
@ -186,7 +186,7 @@ static rt_err_t lpc55s69_i2c_bus_unlock(const struct lpc55s69_soft_i2c_config *c
|
||||
}
|
||||
|
||||
/* I2C initialization function */
|
||||
int rt_hw_i2c_init(void)
|
||||
int rt_soft_i2c_init(void)
|
||||
{
|
||||
rt_err_t result;
|
||||
|
||||
@ -208,6 +208,6 @@ int rt_hw_i2c_init(void)
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_hw_i2c_init);
|
||||
INIT_BOARD_EXPORT(rt_soft_i2c_init);
|
||||
|
||||
#endif /* BSP_USING_SOFT_I2C */
|
||||
|
@ -11,10 +11,7 @@
|
||||
#ifndef __DRV_I2C__
|
||||
#define __DRV_I2C__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
#include <drv_pin.h>
|
||||
|
||||
/* lpc55s69 config class */
|
||||
struct lpc55s69_soft_i2c_config
|
||||
@ -31,33 +28,23 @@ struct lpc55s69_i2c
|
||||
};
|
||||
|
||||
#ifdef BSP_USING_SOFT_I2C1
|
||||
/* Notice: PIO0_15(scl) --> 22; PIO1_8(sda) --> 24 */
|
||||
|
||||
#define BSP_SOFT_I2C1_SCL_PIN GET_PINS(0,15)
|
||||
#define BSP_SOFT_I2C1_SDA_PIN GET_PINS(1,8)
|
||||
|
||||
#define SOFT_I2C1_BUS_CONFIG \
|
||||
{ \
|
||||
.scl = BSP_SOFT_I2C1_SCL_PIN, \
|
||||
.sda = BSP_SOFT_I2C1_SDA_PIN, \
|
||||
.bus_name = "i2c1", \
|
||||
.bus_name = "si2c1", \
|
||||
}
|
||||
#endif /*BSP_USING_SOFT_I2C1*/
|
||||
|
||||
#ifdef BSP_USING_SOFT_I2C2
|
||||
/* Notice: PIO0_18(scl) --> 56; PIO1_10(sda) --> 40 */
|
||||
|
||||
#define BSP_SOFT_I2C2_SCL_PIN GET_PINS(0,18)
|
||||
#define BSP_SOFT_I2C2_SDA_PIN GET_PINS(1,10)
|
||||
|
||||
#define SOFT_I2C2_BUS_CONFIG \
|
||||
{ \
|
||||
.scl = BSP_SOFT_I2C2_SCL_PIN, \
|
||||
.sda = BSP_SOFT_I2C2_SDA_PIN, \
|
||||
.bus_name = "i2c2", \
|
||||
.bus_name = "si2c2", \
|
||||
}
|
||||
#endif /*BSP_USING_SOFT_I2C2*/
|
||||
|
||||
int rt_hw_i2c_init(void);
|
||||
int rt_soft_i2c_init(void);
|
||||
|
||||
#endif
|
||||
|
@ -7,11 +7,10 @@
|
||||
* Date Author Notes
|
||||
* 2023-04-14 Wangyuqiang the first version
|
||||
*/
|
||||
#include <board.h>
|
||||
#include "board.h"
|
||||
#include "drv_soft_spi.h"
|
||||
|
||||
#if defined(RT_USING_PIN) && defined(RT_USING_SPI_BITOPS) && defined(RT_USING_SPI)
|
||||
|
||||
#if defined BSP_USING_SOFT_SPI
|
||||
|
||||
#define LOG_TAG "drv.soft_spi"
|
||||
#include <drv_log.h>
|
||||
@ -19,10 +18,10 @@
|
||||
static struct lpc_soft_spi_config soft_spi_config[] =
|
||||
{
|
||||
#ifdef BSP_USING_SOFT_SPI1
|
||||
SOFT_SPI1_BUS_CONFIG,
|
||||
SOFT_SPI1_BUS_CONFIG,
|
||||
#endif
|
||||
#ifdef BSP_USING_SOFT_SPI2
|
||||
SOFT_SPI2_BUS_CONFIG,
|
||||
SOFT_SPI2_BUS_CONFIG,
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -31,7 +30,6 @@ static struct lpc_soft_spi_config soft_spi_config[] =
|
||||
*/
|
||||
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;
|
||||
|
||||
@ -55,7 +53,7 @@ static void lpc_spi_gpio_init(struct lpc_soft_spi *spi)
|
||||
rt_pin_write(cfg->mosi, PIN_HIGH);
|
||||
}
|
||||
|
||||
void lpc_tog_sclk(void *data)
|
||||
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)
|
||||
@ -68,9 +66,8 @@ void lpc_tog_sclk(void *data)
|
||||
}
|
||||
}
|
||||
|
||||
void lpc_set_sclk(void *data, rt_int32_t state)
|
||||
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)
|
||||
{
|
||||
@ -82,7 +79,7 @@ void lpc_set_sclk(void *data, rt_int32_t state)
|
||||
}
|
||||
}
|
||||
|
||||
void lpc_set_mosi(void *data, rt_int32_t state)
|
||||
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)
|
||||
@ -95,7 +92,7 @@ void lpc_set_mosi(void *data, rt_int32_t state)
|
||||
}
|
||||
}
|
||||
|
||||
void lpc_set_miso(void *data, rt_int32_t state)
|
||||
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)
|
||||
@ -108,25 +105,25 @@ void lpc_set_miso(void *data, rt_int32_t state)
|
||||
}
|
||||
}
|
||||
|
||||
rt_int32_t lpc_get_sclk(void *data)
|
||||
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);
|
||||
}
|
||||
|
||||
rt_int32_t lpc_get_mosi(void *data)
|
||||
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);
|
||||
}
|
||||
|
||||
rt_int32_t lpc_get_miso(void *data)
|
||||
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);
|
||||
}
|
||||
|
||||
void lpc_dir_mosi(void *data, rt_int32_t state)
|
||||
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)
|
||||
@ -139,7 +136,7 @@ void lpc_dir_mosi(void *data, rt_int32_t state)
|
||||
}
|
||||
}
|
||||
|
||||
void lpc_dir_miso(void *data, rt_int32_t state)
|
||||
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)
|
||||
@ -183,19 +180,19 @@ static void lpc_udelay(rt_uint32_t us)
|
||||
}
|
||||
|
||||
static struct rt_spi_bit_ops lpc_soft_spi_ops =
|
||||
{
|
||||
.data = RT_NULL,
|
||||
.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,
|
||||
{
|
||||
.data = RT_NULL,
|
||||
.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,
|
||||
};
|
||||
|
||||
static struct lpc_soft_spi spi_obj[sizeof(soft_spi_config) / sizeof(soft_spi_config[0])];
|
||||
@ -220,4 +217,4 @@ int rt_hw_softspi_init(void)
|
||||
}
|
||||
INIT_BOARD_EXPORT(rt_hw_softspi_init);
|
||||
|
||||
#endif /* defined(RT_USING_SPI) && defined(RT_USING_SPI_BITOPS) && defined(RT_USING_PIN) */
|
||||
#endif /* BSP_USING_SOFT_SPI */
|
||||
|
@ -11,22 +11,8 @@
|
||||
#ifndef DRV_SOFT_SPI_H_
|
||||
#define DRV_SOFT_SPI_H_
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtdevice.h>
|
||||
#include <spi-bit-ops.h>
|
||||
#include <drv_pin.h>
|
||||
|
||||
/* Notice: PIO1_11(sck) --> 93; PIO0_15(miso) --> 22; PIO1_8(mosi) --> 24 */
|
||||
|
||||
#define BSP_S_SPI1_SCK_PIN GET_PINS(1,11)
|
||||
#define BSP_S_SPI1_MISO_PIN GET_PINS(0,15)
|
||||
#define BSP_S_SPI1_MOSI_PIN GET_PINS(1,8)
|
||||
|
||||
/* Notice: PIO1_9(sck) --> 10; PIO0_18(miso) --> 56; PIO1_10(mosi) --> 40 */
|
||||
|
||||
#define BSP_S_SPI2_SCK_PIN GET_PINS(1,9)
|
||||
#define BSP_S_SPI2_MISO_PIN GET_PINS(0,18)
|
||||
#define BSP_S_SPI2_MOSI_PIN GET_PINS(1,10)
|
||||
|
||||
/* lpc soft spi config */
|
||||
struct lpc_soft_spi_config
|
||||
|
@ -128,10 +128,30 @@ menu "On-chip Peripheral Drivers"
|
||||
config BSP_USING_SOFT_I2C1
|
||||
bool "Enable I2C1 Bus (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_I2C1
|
||||
comment "Notice: num = 32 * PORTx + PINx + 1"
|
||||
comment "0_15 --> 16; 1_8 --> 41"
|
||||
config BSP_SOFT_I2C1_SCL_PIN
|
||||
int "si2c1 SCL pin number"
|
||||
default 16
|
||||
config BSP_SOFT_I2C1_SDA_PIN
|
||||
int "si2c1 SDA pin number"
|
||||
default 41
|
||||
endif
|
||||
|
||||
config BSP_USING_SOFT_I2C2
|
||||
bool "Enable I2C2 Bus (software simulation)"
|
||||
default n
|
||||
if BSP_USING_SOFT_I2C2
|
||||
comment "Notice: num = 32 * PORTx + PINx + 1"
|
||||
comment "0_18 --> 19; 1_10 --> 43"
|
||||
config BSP_SOFT_I2C2_SCL_PIN
|
||||
int "si2c2 SCL pin number"
|
||||
default 19
|
||||
config BSP_SOFT_I2C2_SDA_PIN
|
||||
int "si2c2 SDA pin number"
|
||||
default 43
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_SPI
|
||||
@ -157,13 +177,39 @@ menu "On-chip Peripheral Drivers"
|
||||
select RT_USING_SPI_BITOPS
|
||||
select RT_USING_SPI
|
||||
if BSP_USING_SOFT_SPI
|
||||
menuconfig BSP_USING_SOFT_SPI1
|
||||
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_SPI2
|
||||
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
|
||||
endif
|
||||
|
||||
menuconfig BSP_USING_ADC
|
||||
|
Loading…
x
Reference in New Issue
Block a user