Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion bsp/es32f0654/.config
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ CONFIG_FINSH_CMD_SIZE=80
# CONFIG_FINSH_USING_AUTH is not set
CONFIG_FINSH_USING_MSH=y
CONFIG_FINSH_USING_MSH_DEFAULT=y
# CONFIG_FINSH_USING_MSH_ONLY is not set
CONFIG_FINSH_USING_MSH_ONLY=y
CONFIG_FINSH_ARG_MAX=10

#
Expand Down Expand Up @@ -126,6 +126,7 @@ CONFIG_RT_USING_PIN=y
# CONFIG_RT_USING_SPI is not set
# CONFIG_RT_USING_WDT is not set
# CONFIG_RT_USING_AUDIO is not set
# CONFIG_RT_USING_SENSOR is not set

#
# Using WiFi
Expand Down Expand Up @@ -324,9 +325,22 @@ CONFIG_BSP_USING_GPIO=y
CONFIG_BSP_USING_UART2=y
# CONFIG_BSP_USING_UART3 is not set

#
# SPI Drivers
#
# CONFIG_BSP_USING_SPI0 is not set
# CONFIG_BSP_USING_SPI1 is not set

#
# I2C Drivers
#
# CONFIG_BSP_USING_I2C0 is not set
# CONFIG_BSP_USING_I2C1 is not set

#
# Onboard Peripheral Drivers
#
# CONFIG_BSP_USING_SPI_FLASH is not set

#
# Offboard Peripheral Drivers
Expand Down
10 changes: 7 additions & 3 deletions bsp/es32f0654/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ ES-PDS-ES32F0654-V1.0
本 BSP 目前对外设的支持情况如下:

| **板载外设** | **支持情况** | **备注** |
| :---------------- | :----------: | :------------------------------------ |
| GPIO | 支持 | 54 GPIOs |
| UART | 支持 | UART0/1/2/3 |
| :---------------- | :----------: | :------------------------------------|
| SPI FLASH | 支持 | |

| **片上外设** | **支持情况** | **备注** |
| :---------------- | :----------: | :------------------------------------|
| GPIO | 支持 | 54 GPIOs |
| UART | 支持 | UART0/1/2/3 |
| SPI | 支持 | SPI0/1 |
| I2C | 支持 | I2C0/1 |

| **扩展模块** | **支持情况** | **备注** |

Expand Down
3 changes: 1 addition & 2 deletions bsp/es32f0654/applications/main.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*
* File : main.c
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-01-28 wangyq first implementation
* 2019-01-28 wangyq the first version
*/

#include <rtthread.h>
Expand Down
33 changes: 33 additions & 0 deletions bsp/es32f0654/drivers/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,43 @@ menu "Hardware Drivers Config"
default n
endmenu

menu "SPI Drivers"
config BSP_USING_SPI0
bool "Enable SPI0 BUS PB03/PB04/PB05(CLK/MISO/MOSI)"
select RT_USING_SPI
select RT_USING_PIN
default n

config BSP_USING_SPI1
bool "Enable SPI1 BUS PB13/PB14/PB15(CLK/MISO/MOSI)"
select RT_USING_SPI
select RT_USING_PIN
default n
endmenu

menu "I2C Drivers"
config BSP_USING_I2C0
bool "Enable I2C0 BUS PB08/PB09(SCL/SDA)"
select RT_USING_I2C
default n
config BSP_USING_I2C1
bool "Enable I2C1 BUS PB10/PB11(SCL/SDA)"
select RT_USING_I2C
default n
endmenu

endmenu

menu "Onboard Peripheral Drivers"

config BSP_USING_SPI_FLASH
bool "Enable SPI FLASH (W25Q64 spi0)"
select BSP_USING_SPI
select BSP_USING_SPI0
select RT_USING_SFUD
select RT_SFUD_USING_SFDP
default n

endmenu

menu "Offboard Peripheral Drivers"
Expand Down
20 changes: 17 additions & 3 deletions bsp/es32f0654/drivers/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ src = Split('''
board.c
''')

# add gpio drivers.
# add gpio code
if GetDepend('RT_USING_PIN'):
src += ['drv_gpio.c']
if GetDepend(['RT_USING_SERIAL']):
src += ['drv_usart.c']

# add serial driver code
if GetDepend('BSP_USING_UART0') or GetDepend('BSP_USING_UART1') or GetDepend('BSP_USING_UART2') or GetDepend('BSP_USING_UART3'):
src += ['drv_uart.c']

# add spi driver code
if GetDepend('BSP_USING_SPI0') or GetDepend('BSP_USING_SPI1'):
src += ['drv_spi.c']

# add i2c driver code
if GetDepend('BSP_USING_I2C0') or GetDepend('BSP_USING_I2C1'):
src += ['drv_i2c.c']

# add spi flash driver code
if GetDepend('BSP_USING_SPI_FLASH'):
src += ['drv_spiflash.c']

CPPPATH = [cwd]
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
Expand Down
3 changes: 1 addition & 2 deletions bsp/es32f0654/drivers/board.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* File : board.c
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
Expand All @@ -12,7 +11,7 @@
#include <rthw.h>
#include <rtthread.h>
#include "board.h"
#include "drv_usart.h"
#include "drv_uart.h"
#include "drv_gpio.h"
#include <ald_cmu.h>
#include <ald_gpio.h>
Expand Down
1 change: 0 additions & 1 deletion bsp/es32f0654/drivers/board.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* File : board.h
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
Expand Down
1 change: 0 additions & 1 deletion bsp/es32f0654/drivers/drv_gpio.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* File : drv_gpio.c
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
Expand Down
1 change: 0 additions & 1 deletion bsp/es32f0654/drivers/drv_gpio.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*
* File : drv_gpio.h
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
Expand Down
140 changes: 140 additions & 0 deletions bsp/es32f0654/drivers/drv_i2c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-01-24 wangyq the first version
*/

#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "drv_i2c.h"
#include <ald_i2c.h>
#include <ald_gpio.h>

#ifdef RT_USING_I2C

#define TIMEOUT 0x0FFF

/*define i2c Instance*/
struct rt_i2c_bus_device _i2c_device0;
struct rt_i2c_bus_device _i2c_device1;
i2c_handle_t _h_i2c0, _h_i2c1;

static void _i2c_init(void)
{
gpio_init_t gpio_instruct; //i2c function init

/* Initialize I2C Pin*/
gpio_instruct.mode = GPIO_MODE_OUTPUT;
gpio_instruct.odos = GPIO_PUSH_PULL;
gpio_instruct.pupd = GPIO_PUSH_UP;
gpio_instruct.odrv = GPIO_OUT_DRIVE_NORMAL;
gpio_instruct.flt = GPIO_FILTER_DISABLE;
gpio_instruct.type = GPIO_TYPE_CMOS;
gpio_instruct.func = GPIO_FUNC_5;

#ifdef BSP_USING_I2C0
/* Initialize I2C Function */
_h_i2c0.perh = I2C0;
_h_i2c0.init.clk_speed = 100000;
_h_i2c0.init.duty = I2C_DUTYCYCLE_2;
_h_i2c0.init.own_addr1 = 0x0A;
_h_i2c0.init.addr_mode = I2C_ADDR_7BIT;
_h_i2c0.init.general_call = I2C_GENERALCALL_DISABLE;
_h_i2c0.init.no_stretch = I2C_NOSTRETCH_ENABLE;

i2c_reset(&_h_i2c0);
i2c_init(&_h_i2c0);
/* I2C0_SCL->PB8, I2C0_SDA->PB9 */
gpio_init(GPIOB, GPIO_PIN_8 | GPIO_PIN_9, &gpio_instruct);
#endif/*BSP_USING_I2C0*/

#ifdef BSP_USING_I2C1
/* Initialize i2c function */
_h_i2c1.perh = I2C1;
_h_i2c1.init.clk_speed = 100000;
_h_i2c1.init.duty = I2C_DUTYCYCLE_2;
_h_i2c1.init.own_addr1 = 0xA0;
_h_i2c1.init.addr_mode = I2C_ADDR_7BIT;
_h_i2c1.init.general_call = I2C_GENERALCALL_DISABLE;
_h_i2c1.init.no_stretch = I2C_NOSTRETCH_ENABLE;

i2c_reset(&_h_i2c1);
i2c_init(&_h_i2c1);
/* I2C1_SCL->PB10, I2C1_SDA->PB11 */
gpio_init(GPIOB, GPIO_PIN_10 | GPIO_PIN_11, &gpio_instruct);
#endif/*BSP_USING_I2C1*/
}

static rt_size_t es32f0_master_xfer(struct rt_i2c_bus_device *bus,
struct rt_i2c_msg msgs[],
rt_uint32_t num)
{
struct rt_i2c_msg *msg;
rt_uint32_t i;
rt_err_t ret = RT_ERROR;

for (i = 0; i < num; i++)
{
msg = &msgs[i];
if (msg->flags & RT_I2C_RD)
{
if (i2c_master_recv(bus->priv, msg->addr << 1, msg->buf, msg->len, TIMEOUT) != 0)
{
i2c_dbg("i2c bus write failed,i2c bus stop!\n");
goto out;
}
}
else
{
if (i2c_master_send(bus->priv, msg->addr << 1, msg->buf, msg->len, TIMEOUT) != 0)
{
i2c_dbg("i2c bus write failed,i2c bus stop!\n");
goto out;
}
}
}

ret = i;

out:
i2c_dbg("send stop condition\n");

return ret;
}

const struct rt_i2c_bus_device_ops es32f0_i2c_ops =
{
es32f0_master_xfer,
RT_NULL,
RT_NULL,
};

int rt_hw_i2c_init(void)
{
_i2c_init();

#ifdef BSP_USING_I2C0
rt_memset((void *)&_i2c_device0, 0, sizeof(struct rt_i2c_bus_device));
_i2c_device0.ops = &es32f0_i2c_ops;
_i2c_device0.priv = &_h_i2c0;
rt_i2c_bus_device_register(&_i2c_device0, "i2c0");
#endif

#ifdef BSP_USING_I2C1
rt_memset((void *)&_i2c_device1, 0, sizeof(struct rt_i2c_bus_device));
_i2c_device1.ops = &es32f0_i2c_ops;
_i2c_device1.priv = &_h_i2c1;
rt_i2c_bus_device_register(&_i2c_device1, "i2c1");
#endif

return RT_EOK;
}
INIT_DEVICE_EXPORT(rt_hw_i2c_init);
/* end of i2c driver */
#endif
16 changes: 16 additions & 0 deletions bsp/es32f0654/drivers/drv_i2c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-01-24 wangyq the first version
*/

#ifndef DRV_I2C_H__
#define DRV_I2C_H__

int rt_hw_i2c_init(void);

#endif
Loading