提交 c1fa39a8 编写于 作者: B bernard 提交者: Gitee

!86 fix some bugs and update libraries

Merge pull request !86 from 刘泓研/gitee_master
...@@ -64,7 +64,7 @@ CONFIG_RT_USING_DEVICE=y ...@@ -64,7 +64,7 @@ CONFIG_RT_USING_DEVICE=y
CONFIG_RT_USING_CONSOLE=y CONFIG_RT_USING_CONSOLE=y
CONFIG_RT_CONSOLEBUF_SIZE=128 CONFIG_RT_CONSOLEBUF_SIZE=128
CONFIG_RT_CONSOLE_DEVICE_NAME="uart1" CONFIG_RT_CONSOLE_DEVICE_NAME="uart1"
CONFIG_RT_VER_NUM=0x40002 CONFIG_RT_VER_NUM=0x40003
# CONFIG_RT_USING_CPU_FFS is not set # CONFIG_RT_USING_CPU_FFS is not set
# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set # CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set
...@@ -115,18 +115,29 @@ CONFIG_RT_USING_SERIAL=y ...@@ -115,18 +115,29 @@ CONFIG_RT_USING_SERIAL=y
# CONFIG_RT_SERIAL_USING_DMA is not set # CONFIG_RT_SERIAL_USING_DMA is not set
CONFIG_RT_SERIAL_RB_BUFSZ=64 CONFIG_RT_SERIAL_RB_BUFSZ=64
# CONFIG_RT_USING_CAN is not set # CONFIG_RT_USING_CAN is not set
# CONFIG_RT_USING_HWTIMER is not set CONFIG_RT_USING_HWTIMER=y
# CONFIG_RT_USING_CPUTIME is not set # CONFIG_RT_USING_CPUTIME is not set
# CONFIG_RT_USING_I2C is not set CONFIG_RT_USING_I2C=y
# CONFIG_RT_I2C_DEBUG is not set
CONFIG_RT_USING_I2C_BITOPS=y
# CONFIG_RT_I2C_BITOPS_DEBUG is not set
CONFIG_RT_USING_PIN=y CONFIG_RT_USING_PIN=y
# CONFIG_RT_USING_ADC is not set CONFIG_RT_USING_ADC=y
# CONFIG_RT_USING_PWM is not set # CONFIG_RT_USING_DAC is not set
CONFIG_RT_USING_PWM=y
# CONFIG_RT_USING_MTD_NOR is not set # CONFIG_RT_USING_MTD_NOR is not set
# CONFIG_RT_USING_MTD_NAND is not set # CONFIG_RT_USING_MTD_NAND is not set
# CONFIG_RT_USING_PM is not set CONFIG_RT_USING_PM=y
# CONFIG_RT_USING_RTC is not set CONFIG_RT_USING_RTC=y
# CONFIG_RT_USING_ALARM is not set
# CONFIG_RT_USING_SOFT_RTC is not set
# CONFIG_RT_USING_SDIO is not set # CONFIG_RT_USING_SDIO is not set
# CONFIG_RT_USING_SPI is not set CONFIG_RT_USING_SPI=y
# CONFIG_RT_USING_QSPI is not set
# CONFIG_RT_USING_SPI_MSD is not set
# CONFIG_RT_USING_SFUD is not set
# CONFIG_RT_USING_ENC28J60 is not set
# CONFIG_RT_USING_SPI_WIFI is not set
# CONFIG_RT_USING_WDT is not set # CONFIG_RT_USING_WDT is not set
# CONFIG_RT_USING_AUDIO is not set # CONFIG_RT_USING_AUDIO is not set
# CONFIG_RT_USING_SENSOR is not set # CONFIG_RT_USING_SENSOR is not set
...@@ -192,11 +203,15 @@ CONFIG_RT_USING_PIN=y ...@@ -192,11 +203,15 @@ CONFIG_RT_USING_PIN=y
# #
# IoT - internet of things # IoT - internet of things
# #
# CONFIG_PKG_USING_LORAWAN_DRIVER is not set
# CONFIG_PKG_USING_PAHOMQTT is not set # CONFIG_PKG_USING_PAHOMQTT is not set
# CONFIG_PKG_USING_UMQTT is not set
# CONFIG_PKG_USING_WEBCLIENT is not set # CONFIG_PKG_USING_WEBCLIENT is not set
# CONFIG_PKG_USING_WEBNET is not set # CONFIG_PKG_USING_WEBNET is not set
# CONFIG_PKG_USING_MONGOOSE is not set # CONFIG_PKG_USING_MONGOOSE is not set
# CONFIG_PKG_USING_MYMQTT is not set # CONFIG_PKG_USING_MYMQTT is not set
# CONFIG_PKG_USING_KAWAII_MQTT is not set
# CONFIG_PKG_USING_BC28_MQTT is not set
# CONFIG_PKG_USING_WEBTERMINAL is not set # CONFIG_PKG_USING_WEBTERMINAL is not set
# CONFIG_PKG_USING_CJSON is not set # CONFIG_PKG_USING_CJSON is not set
# CONFIG_PKG_USING_JSMN is not set # CONFIG_PKG_USING_JSMN is not set
...@@ -223,6 +238,7 @@ CONFIG_RT_USING_PIN=y ...@@ -223,6 +238,7 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_COAP is not set # CONFIG_PKG_USING_COAP is not set
# CONFIG_PKG_USING_NOPOLL is not set # CONFIG_PKG_USING_NOPOLL is not set
# CONFIG_PKG_USING_NETUTILS is not set # CONFIG_PKG_USING_NETUTILS is not set
# CONFIG_PKG_USING_CMUX is not set
# CONFIG_PKG_USING_PPP_DEVICE is not set # CONFIG_PKG_USING_PPP_DEVICE is not set
# CONFIG_PKG_USING_AT_DEVICE is not set # CONFIG_PKG_USING_AT_DEVICE is not set
# CONFIG_PKG_USING_ATSRV_SOCKET is not set # CONFIG_PKG_USING_ATSRV_SOCKET is not set
...@@ -235,8 +251,10 @@ CONFIG_RT_USING_PIN=y ...@@ -235,8 +251,10 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_GAGENT_CLOUD is not set # CONFIG_PKG_USING_GAGENT_CLOUD is not set
# CONFIG_PKG_USING_ALI_IOTKIT is not set # CONFIG_PKG_USING_ALI_IOTKIT is not set
# CONFIG_PKG_USING_AZURE is not set # CONFIG_PKG_USING_AZURE is not set
# CONFIG_PKG_USING_TENCENT_IOTHUB is not set # CONFIG_PKG_USING_TENCENT_IOT_EXPLORER is not set
# CONFIG_PKG_USING_JIOT-C-SDK is not set # CONFIG_PKG_USING_JIOT-C-SDK is not set
# CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set
# CONFIG_PKG_USING_JOYLINK is not set
# CONFIG_PKG_USING_NIMBLE is not set # CONFIG_PKG_USING_NIMBLE is not set
# CONFIG_PKG_USING_OTA_DOWNLOADER is not set # CONFIG_PKG_USING_OTA_DOWNLOADER is not set
# CONFIG_PKG_USING_IPMSG is not set # CONFIG_PKG_USING_IPMSG is not set
...@@ -251,6 +269,15 @@ CONFIG_RT_USING_PIN=y ...@@ -251,6 +269,15 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_QXWZ is not set # CONFIG_PKG_USING_QXWZ is not set
# CONFIG_PKG_USING_SMTP_CLIENT is not set # CONFIG_PKG_USING_SMTP_CLIENT is not set
# CONFIG_PKG_USING_ABUP_FOTA is not set # CONFIG_PKG_USING_ABUP_FOTA is not set
# CONFIG_PKG_USING_LIBCURL2RTT is not set
# CONFIG_PKG_USING_CAPNP is not set
# CONFIG_PKG_USING_RT_CJSON_TOOLS is not set
# CONFIG_PKG_USING_AGILE_TELNET is not set
# CONFIG_PKG_USING_NMEALIB is not set
# CONFIG_PKG_USING_AGILE_JSMN is not set
# CONFIG_PKG_USING_PDULIB is not set
# CONFIG_PKG_USING_BTSTACK is not set
# CONFIG_PKG_USING_LORAWAN_ED_STACK is not set
# #
# security packages # security packages
...@@ -258,6 +285,8 @@ CONFIG_RT_USING_PIN=y ...@@ -258,6 +285,8 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_MBEDTLS is not set # CONFIG_PKG_USING_MBEDTLS is not set
# CONFIG_PKG_USING_libsodium is not set # CONFIG_PKG_USING_libsodium is not set
# CONFIG_PKG_USING_TINYCRYPT is not set # CONFIG_PKG_USING_TINYCRYPT is not set
# CONFIG_PKG_USING_TFM is not set
# CONFIG_PKG_USING_YD_CRYPTO is not set
# #
# language packages # language packages
...@@ -274,6 +303,7 @@ CONFIG_RT_USING_PIN=y ...@@ -274,6 +303,7 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_STEMWIN is not set # CONFIG_PKG_USING_STEMWIN is not set
# CONFIG_PKG_USING_WAVPLAYER is not set # CONFIG_PKG_USING_WAVPLAYER is not set
# CONFIG_PKG_USING_TJPGD is not set # CONFIG_PKG_USING_TJPGD is not set
# CONFIG_PKG_USING_HELIX is not set
# #
# tools packages # tools packages
...@@ -289,6 +319,12 @@ CONFIG_RT_USING_PIN=y ...@@ -289,6 +319,12 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_COREMARK is not set # CONFIG_PKG_USING_COREMARK is not set
# CONFIG_PKG_USING_DHRYSTONE is not set # CONFIG_PKG_USING_DHRYSTONE is not set
# CONFIG_PKG_USING_NR_MICRO_SHELL is not set # CONFIG_PKG_USING_NR_MICRO_SHELL is not set
# CONFIG_PKG_USING_CHINESE_FONT_LIBRARY is not set
# CONFIG_PKG_USING_LUNAR_CALENDAR is not set
# CONFIG_PKG_USING_BS8116A is not set
# CONFIG_PKG_USING_GPS_RMC is not set
# CONFIG_PKG_USING_URLENCODE is not set
# CONFIG_PKG_USING_UMCN is not set
# #
# system packages # system packages
...@@ -299,6 +335,7 @@ CONFIG_RT_USING_PIN=y ...@@ -299,6 +335,7 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_LWEXT4 is not set # CONFIG_PKG_USING_LWEXT4 is not set
# CONFIG_PKG_USING_PARTITION is not set # CONFIG_PKG_USING_PARTITION is not set
# CONFIG_PKG_USING_FAL is not set # CONFIG_PKG_USING_FAL is not set
# CONFIG_PKG_USING_FLASHDB is not set
# CONFIG_PKG_USING_SQLITE is not set # CONFIG_PKG_USING_SQLITE is not set
# CONFIG_PKG_USING_RTI is not set # CONFIG_PKG_USING_RTI is not set
# CONFIG_PKG_USING_LITTLEVGL2RTT is not set # CONFIG_PKG_USING_LITTLEVGL2RTT is not set
...@@ -307,6 +344,15 @@ CONFIG_RT_USING_PIN=y ...@@ -307,6 +344,15 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_LITTLEFS is not set # CONFIG_PKG_USING_LITTLEFS is not set
# CONFIG_PKG_USING_THREAD_POOL is not set # CONFIG_PKG_USING_THREAD_POOL is not set
# CONFIG_PKG_USING_ROBOTS is not set # CONFIG_PKG_USING_ROBOTS is not set
# CONFIG_PKG_USING_EV is not set
# CONFIG_PKG_USING_SYSWATCH is not set
# CONFIG_PKG_USING_SYS_LOAD_MONITOR is not set
# CONFIG_PKG_USING_PLCCORE is not set
# CONFIG_PKG_USING_RAMDISK is not set
# CONFIG_PKG_USING_MININI is not set
# CONFIG_PKG_USING_QBOOT is not set
# CONFIG_PKG_USING_UCOSIII_WRAPPER is not set
# CONFIG_PKG_USING_PPOOL is not set
# #
# peripheral libraries and drivers # peripheral libraries and drivers
...@@ -323,6 +369,10 @@ CONFIG_RT_USING_PIN=y ...@@ -323,6 +369,10 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_SX12XX is not set # CONFIG_PKG_USING_SX12XX is not set
# CONFIG_PKG_USING_SIGNAL_LED is not set # CONFIG_PKG_USING_SIGNAL_LED is not set
# CONFIG_PKG_USING_LEDBLINK is not set # CONFIG_PKG_USING_LEDBLINK is not set
# CONFIG_PKG_USING_LITTLED is not set
# CONFIG_PKG_USING_LKDGUI is not set
# CONFIG_PKG_USING_NRF5X_SDK is not set
# CONFIG_PKG_USING_NRFX is not set
# CONFIG_PKG_USING_WM_LIBRARIES is not set # CONFIG_PKG_USING_WM_LIBRARIES is not set
# CONFIG_PKG_USING_KENDRYTE_SDK is not set # CONFIG_PKG_USING_KENDRYTE_SDK is not set
# CONFIG_PKG_USING_INFRARED is not set # CONFIG_PKG_USING_INFRARED is not set
...@@ -336,9 +386,27 @@ CONFIG_RT_USING_PIN=y ...@@ -336,9 +386,27 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_I2C_TOOLS is not set # CONFIG_PKG_USING_I2C_TOOLS is not set
# CONFIG_PKG_USING_NRF24L01 is not set # CONFIG_PKG_USING_NRF24L01 is not set
# CONFIG_PKG_USING_TOUCH_DRIVERS is not set # CONFIG_PKG_USING_TOUCH_DRIVERS is not set
# CONFIG_PKG_USING_LCD_DRIVERS is not set
# CONFIG_PKG_USING_MAX17048 is not set # CONFIG_PKG_USING_MAX17048 is not set
# CONFIG_PKG_USING_RPLIDAR is not set # CONFIG_PKG_USING_RPLIDAR is not set
# CONFIG_PKG_USING_AS608 is not set
# CONFIG_PKG_USING_RC522 is not set
# CONFIG_PKG_USING_WS2812B is not set
# CONFIG_PKG_USING_EMBARC_BSP is not set
# CONFIG_PKG_USING_EXTERN_RTC_DRIVERS is not set
# CONFIG_PKG_USING_MULTI_RTIMER is not set
# CONFIG_PKG_USING_MAX7219 is not set
# CONFIG_PKG_USING_BEEP is not set
# CONFIG_PKG_USING_EASYBLINK is not set
# CONFIG_PKG_USING_PMS_SERIES is not set
# CONFIG_PKG_USING_CAN_YMODEM is not set
# CONFIG_PKG_USING_LORA_RADIO_DRIVER is not set
# CONFIG_PKG_USING_QLED is not set
# CONFIG_PKG_USING_PAJ7620 is not set
# CONFIG_PKG_USING_AGILE_CONSOLE is not set
# CONFIG_PKG_USING_LD3320 is not set
# CONFIG_PKG_USING_WK2124 is not set
# CONFIG_PKG_USING_LY68L6400 is not set
# CONFIG_PKG_USING_DM9051 is not set
# #
# miscellaneous packages # miscellaneous packages
...@@ -373,8 +441,14 @@ CONFIG_RT_USING_PIN=y ...@@ -373,8 +441,14 @@ CONFIG_RT_USING_PIN=y
# CONFIG_PKG_USING_ELAPACK is not set # CONFIG_PKG_USING_ELAPACK is not set
# CONFIG_PKG_USING_ARMv7M_DWT is not set # CONFIG_PKG_USING_ARMv7M_DWT is not set
# CONFIG_PKG_USING_VT100 is not set # CONFIG_PKG_USING_VT100 is not set
# CONFIG_PKG_USING_TETRIS is not set
# CONFIG_PKG_USING_ULAPACK is not set # CONFIG_PKG_USING_ULAPACK is not set
# CONFIG_PKG_USING_UKAL is not set # CONFIG_PKG_USING_UKAL is not set
# CONFIG_PKG_USING_CRCLIB is not set
# CONFIG_PKG_USING_THREES is not set
# CONFIG_PKG_USING_2048 is not set
# CONFIG_PKG_USING_LWGPS is not set
# CONFIG_PKG_USING_TENSORFLOWLITEMICRO is not set
# #
# Hardware Drivers Config # Hardware Drivers Config
...@@ -442,4 +516,18 @@ CONFIG_BSP_USING_UART1=y ...@@ -442,4 +516,18 @@ CONFIG_BSP_USING_UART1=y
# #
# Offboard Peripheral Drivers # Offboard Peripheral Drivers
# #
#
# Peripheral Drivers test example
#
# CONFIG_BSP_USING_EXAMPLE_ADC_VOL is not set
# CONFIG_BSP_USING_EXAMPLE_HWTIMER is not set
# CONFIG_BSP_USING_EXAMPLE_I2C is not set
# CONFIG_BSP_USING_EXAMPLE_LED_BLINK is not set
# CONFIG_BSP_USING_EXAMPLE_PIN_BEEP is not set
# CONFIG_BSP_USING_EXAMPLE_PWM_LED is not set
# CONFIG_BSP_USING_EXAMPLE_RTC is not set
# CONFIG_BSP_USING_EXAMPLE_SPI is not set
# CONFIG_BSP_USING_EXAMPLE_UART is not set
# CONFIG_BSP_USING_EXAMPLE_PM is not set
CONFIG_SOC_ES32F0334LT=y CONFIG_SOC_ES32F0334LT=y
...@@ -86,6 +86,22 @@ msh > ...@@ -86,6 +86,22 @@ msh >
2. 输入`menuconfig`命令配置工程,配置好之后保存退出。 2. 输入`menuconfig`命令配置工程,配置好之后保存退出。
a)如果需要使用内核用例,先配置rt-thread内核,如图:
![kernel_config](figures/k_conf.jpg)
然后配置内核用例,如图:
![kernel_samples](figures/k_ex.jpg)
b)如果需要使用驱动用例:先使能驱动,如图:
![driver_config](figures/drv_conf.jpg)
然后配置驱动用例,如图:
![driver_sample](figures/drv_ex.jpg)
3. 输入`pkgs --update`命令更新软件包。 3. 输入`pkgs --update`命令更新软件包。
4. 输入`scons --target=mdk5/iar` 命令重新生成工程。 4. 输入`scons --target=mdk5/iar` 命令重新生成工程。
...@@ -94,7 +110,7 @@ msh > ...@@ -94,7 +110,7 @@ msh >
## 4. 联系人信息 ## 4. 联系人信息
- [wangyongquan](https://github.com/wangyq2018) - [liuhongyan](https://gitee.com/liuhongyan98)
## 5. 参考 ## 5. 参考
......
...@@ -127,4 +127,50 @@ menu "Hardware Drivers Config" ...@@ -127,4 +127,50 @@ menu "Hardware Drivers Config"
endmenu endmenu
menu "Peripheral Drivers test example"
config BSP_USING_EXAMPLE_ADC_VOL
bool "BSP_USING_EXAMPLE_ADC_VOL"
default n
config BSP_USING_EXAMPLE_HWTIMER
bool "BSP_USING_EXAMPLE_HWTIMER"
default n
config BSP_USING_EXAMPLE_I2C
bool "BSP_USING_EXAMPLE_I2C"
default n
config BSP_USING_EXAMPLE_LED_BLINK
bool "BSP_USING_EXAMPLE_LED_BLINK"
default y
config BSP_USING_EXAMPLE_PIN_BEEP
bool "BSP_USING_EXAMPLE_PIN_BEEP"
default y
config BSP_USING_EXAMPLE_PWM_LED
bool "BSP_USING_EXAMPLE_PWM_LED"
default n
config BSP_USING_EXAMPLE_RTC
bool "BSP_USING_EXAMPLE_RTC"
default n
config BSP_USING_EXAMPLE_SPI
bool "BSP_USING_EXAMPLE_SPI"
default n
config BSP_USING_EXAMPLE_UART
bool "BSP_USING_EXAMPLE_UART"
default y
config BSP_USING_EXAMPLE_PM
bool "BSP_USING_EXAMPLE_PM"
default n
endmenu
endmenu endmenu
...@@ -2,6 +2,8 @@ from building import * ...@@ -2,6 +2,8 @@ from building import *
cwd = GetCurrentDir() cwd = GetCurrentDir()
objs = []
# add the general drivers. # add the general drivers.
src = Split(''' src = Split('''
board.c board.c
...@@ -50,5 +52,43 @@ if GetDepend(['BSP_USING_ADC']): ...@@ -50,5 +52,43 @@ if GetDepend(['BSP_USING_ADC']):
CPPPATH = [cwd] CPPPATH = [cwd]
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
objs = objs + group
src = []
cwd = GetCurrentDir()
include_path = [cwd]
if GetDepend('BSP_USING_EXAMPLE_ADC_VOL'):
src += ['bsp_driver_example/adc_vol_sample.c']
if GetDepend('BSP_USING_EXAMPLE_HWTIMER'):
src += ['bsp_driver_example/hwtimer_sample.c']
if GetDepend('BSP_USING_EXAMPLE_I2C'):
src += ['bsp_driver_example/i2c_sample.c']
if GetDepend('BSP_USING_EXAMPLE_LED_BLINK'):
src += ['bsp_driver_example/led_blink_sample.c']
if GetDepend('BSP_USING_EXAMPLE_PIN_BEEP'):
src += ['bsp_driver_example/pin_beep_sample.c']
if GetDepend('BSP_USING_EXAMPLE_PWM_LED'):
src += ['bsp_driver_example/pwm_led_sample.c']
if GetDepend('BSP_USING_EXAMPLE_RTC'):
src += ['bsp_driver_example/rtc_sample.c']
if GetDepend('BSP_USING_EXAMPLE_UART'):
src += ['bsp_driver_example/uart_sample.c']
if GetDepend('BSP_USING_EXAMPLE_SPI'):
src += ['bsp_driver_example/spi_sample.c']
if GetDepend('BSP_USING_EXAMPLE_PM'):
src += ['bsp_driver_example/pm_sample.c']
group = DefineGroup('bsp-drivers-test-samples', src, depend = [''], CPPPATH = include_path)
Return('group') objs = objs + group
Return('objs')
\ No newline at end of file
# Prerequisites
*.d
# Object files
*.o
*.ko
*.obj
*.elf
# Linker output
*.ilk
*.map
*.exp
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
*.idb
*.pdb
# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
# 外设驱动测试用例
## 1、介绍
这个软件包包含一些外设设备操作的例程。
### 1.1 例程说明
| 文件 | 说明 |
| ---------------- | ------------------------------- |
| adc_vol_sample.c | 使用 ADC 设备转换电压数据 |
| can_sample.c | 通过 CAN 设备发送一帧,并创建一个线程接收数据然后打印输出。 |
| hwtimer_sample.c | 使用 硬件定时器定时 |
| i2c_sample.c | 使用 i2c 设备进行读写 |
| pm.c | 反复进入不同程度的睡眠。 |
| led_blink_sample.c | 使用 pin 设备控制 LED 闪烁 |
| pin_beep_sample.c | 使用 pin 设备控制蜂鸣器 |
| pwm_led_sample.c | 使用 pwm 设备控制 LED 的亮度 |
| rtc_sample.c | 使用 rtc 设备设置年月日时分秒信息 |
| spi_sample.c | 使用 spi 设备进行读写 |
| uart_sample.c | 使用 serial 设备中断接收及轮询发送模式收发数据 |
### 1.2 依赖
依赖设备管理模块提供的设备驱动。
## 2、如何打开 外设驱动测试用例
使用 外设驱动测试用例 需要在 RT-Thread 的menuconfig中选择它,具体路径如下:
```
Hardware Driver Config --->
Peripheral Driver test example--->
```
## 3、使用 外设驱动测试用例
在打开 Peripheral Driver test example 后,当进行 BSP 编译时,选择的软件包相关源代码会被加入到 BSP 工程中进行编译。
## 4、注意事项
暂无。
## 5、联系方式 & 感谢
* 维护:[misonyo](https://github.com/misonyo)
* 主页:https://github.com/RT-Thread-packages/peripheral-sample
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-29 misonyo first implementation.
*/
/*
* 程序清单: ADC 设备使用例程
* 例程导出了 adc_sample 命令到控制终端
* 命令调用格式:adc_sample
* 程序功能:通过 ADC 设备采样电压值并转换为数值。
* 示例代码参考电压为3.3V,转换位数为12位。
*/
#include <rtthread.h>
#include <rtdevice.h>
#define ADC_DEV_NAME "adc0" /* ADC 设备名称 */
#define ADC_DEV_CHANNEL 5 /* PA1 ADC 通道 */
#define REFER_VOLTAGE 330 /* 参考电压 3.3V,数据精度乘以100保留2位小数*/
#define CONVERT_BITS (1 << 12) /* 转换位数为12位 */
static int adc_vol_sample(int argc, char *argv[])
{
rt_adc_device_t adc_dev;
rt_uint32_t value, vol;
rt_err_t ret = RT_EOK;
/* 查找设备 */
adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
if (adc_dev == RT_NULL)
{
rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
return RT_ERROR;
}
/* 使能设备 */
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL);
/* 读取采样值 */
value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL);
rt_kprintf("the value is :%d \n", value);
/* 转换为对应电压值 */
vol = value * REFER_VOLTAGE / CONVERT_BITS;
rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100);
/* 关闭通道 */
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL);
return ret;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(adc_vol_sample, adc voltage convert sample);
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2019-06-25 misonyo first implementation.
*/
/*
* 程序清单:这是一个 CAN 设备使用例程
* 例程导出了 can_sample 命令到控制终端
* 命令调用格式:can_sample can2
* 命令解释:命令第二个参数是要使用的 CAN 设备名称,为空则使用默认的 CAN 设备
* 程序功能:通过 CAN 设备发送一帧,并创建一个线程接收数据然后打印输出。
*/
#include <rtthread.h>
#include "rtdevice.h"
#define CAN_DEV_NAME "can2" /* CAN 设备名称 */
static struct rt_semaphore rx_sem; /* 用于接收消息的信号量 */
static rt_device_t can_dev; /* CAN 设备句柄 */
/* 接收数据回调函数 */
static rt_err_t can_rx_call(rt_device_t dev, rt_size_t size)
{
/* CAN 接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
rt_sem_release(&rx_sem);
return RT_EOK;
}
static void can_rx_thread(void *parameter)
{
int i;
struct rt_can_msg rxmsg = {0};
/* 设置接收回调函数 */
rt_device_set_rx_indicate(can_dev, can_rx_call);
#ifdef RT_CAN_USING_HDR
rt_err_t res;
struct rt_can_filter_item items[5] =
{
RT_CAN_FILTER_ITEM_INIT(0x100, 0, 0, 0, 0x700, RT_NULL, RT_NULL), /* std,match ID:0x100~0x1ff,hdr为-1,设置默认过滤表 */
RT_CAN_FILTER_ITEM_INIT(0x300, 0, 0, 0, 0x700, RT_NULL, RT_NULL), /* std,match ID:0x300~0x3ff,hdr为-1 */
RT_CAN_FILTER_ITEM_INIT(0x211, 0, 0, 0, 0x7ff, RT_NULL, RT_NULL), /* std,match ID:0x211,hdr为-1 */
RT_CAN_FILTER_STD_INIT(0x486, RT_NULL, RT_NULL), /* std,match ID:0x486,hdr为-1 */
{0x555, 0, 0, 0, 0x7ff, 7,} /* std,match ID:0x555,hdr为7,指定设置7号过滤表 */
};
struct rt_can_filter_config cfg = {5, 1, items}; /* 一共有5个过滤表 */
/* 设置硬件过滤表 */
res = rt_device_control(can_dev, RT_CAN_CMD_SET_FILTER, &cfg);
RT_ASSERT(res == RT_EOK);
#endif
while (1)
{
/* hdr值为-1,表示直接从uselist链表读取数据 */
rxmsg.hdr = -1;
/* 阻塞等待接收信号量 */
rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
/* 从CAN读取一帧数据 */
rt_device_read(can_dev, 0, &rxmsg, sizeof(rxmsg));
/* 打印数据ID及内容 */
rt_kprintf("ID:%x ", rxmsg.id);
for (i = 0; i < 8; i++)
{
rt_kprintf("%2x ", rxmsg.data[i]);
}
rt_kprintf("\n");
}
}
int can_sample(int argc, char *argv[])
{
struct rt_can_msg msg = {0};
rt_err_t res;
rt_size_t size;
rt_thread_t thread;
char can_name[RT_NAME_MAX];
if (argc == 2)
{
rt_strncpy(can_name, argv[1], RT_NAME_MAX);
}
else
{
rt_strncpy(can_name, CAN_DEV_NAME, RT_NAME_MAX);
}
can_dev = rt_device_find(can_name);
if (!can_dev)
{
rt_kprintf("find %s failed!\n", can_name);
return RT_ERROR;
}
/* 初始化CAN接收信号量 */
rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
/* 以中断接收及发送方式打开CAN设备 */
res = rt_device_open(can_dev, RT_DEVICE_FLAG_INT_TX | RT_DEVICE_FLAG_INT_RX);
RT_ASSERT(res == RT_EOK);
thread = rt_thread_create("can_rx", can_rx_thread, RT_NULL, 1024, 25, 10);
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
rt_kprintf("create can_rx thread failed!\n");
}
msg.id = 0x78; /* ID为0x78 */
msg.ide = RT_CAN_STDID; /* 标准格式 */
msg.rtr = RT_CAN_DTR; /* 数据帧 */
msg.len = 8; /* 数据长度为8 */
/* 待发送的8字节数据 */
msg.data[0] = 0x00;
msg.data[1] = 0x11;
msg.data[2] = 0x22;
msg.data[3] = 0x33;
msg.data[4] = 0x44;
msg.data[5] = 0x55;
msg.data[6] = 0x66;
msg.data[7] = 0x77;
/* 发送一帧CAN数据 */
size = rt_device_write(can_dev, 0, &msg, sizeof(msg));
if (size == 0)
{
rt_kprintf("can dev write data failed!\n");
}
return res;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(can_sample, can device sample);
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-30 misonyo first implementation.
*/
/*
* 程序清单:这是一个 hwtimer 设备使用例程
* 例程导出了 hwtimer_sample 命令到控制终端
* 命令调用格式:hwtimer_sample
* 程序功能:硬件定时器超时回调函数周期性的打印当前tick值,2次tick值之差换算为时间等同于定时时间值。
*/
#include <rtthread.h>
#include <rtdevice.h>
#define HWTIMER_DEV_NAME "timer0" /* 定时器名称 */
/* 定时器超时回调函数 */
static rt_err_t timeout_cb(rt_device_t dev, rt_size_t size)
{
rt_kprintf("tick is :%d !\n", rt_tick_get());
return 0;
}
static int hwtimer_sample(int argc, char *argv[])
{
rt_err_t ret = RT_EOK;
rt_hwtimerval_t timeout_s; /* 定时器超时值 */
rt_device_t hw_dev = RT_NULL; /* 定时器设备句柄 */
rt_hwtimer_mode_t mode; /* 定时器模式 */
/* 查找定时器设备 */
hw_dev = rt_device_find(HWTIMER_DEV_NAME);
if (hw_dev == RT_NULL)
{
rt_kprintf("hwtimer sample run failed! can't find %s device!\n", HWTIMER_DEV_NAME);
return RT_ERROR;
}
/* 以读写方式打开设备 */
ret = rt_device_open(hw_dev, RT_DEVICE_OFLAG_RDWR);
if (ret != RT_EOK)
{
rt_kprintf("open %s device failed!\n", HWTIMER_DEV_NAME);
return ret;
}
/* 设置超时回调函数 */
rt_device_set_rx_indicate(hw_dev, timeout_cb);
/* 设置模式为周期性定时器 */
mode = HWTIMER_MODE_PERIOD;
ret = rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, &mode);
if (ret != RT_EOK)
{
rt_kprintf("set mode failed! ret is :%d\n", ret);
return ret;
}
/* 设置定时器超时值为5s并启动定时器 */
timeout_s.sec = 5; /* 秒 */
timeout_s.usec = 0; /* 微秒 */
if (rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s)) != sizeof(timeout_s))
{
rt_kprintf("set timeout value failed\n");
return RT_ERROR;
}
/* 延时3500ms */
rt_thread_mdelay(3500);
/* 读取定时器当前值 */
rt_device_read(hw_dev, 0, &timeout_s, sizeof(timeout_s));
rt_kprintf("Read: Sec = %d, Usec = %d\n", timeout_s.sec, timeout_s.usec);
return ret;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(hwtimer_sample, hwtimer sample);
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-12-15 liuhy first implementation.
*/
/*
* 程序清单:这是一个 I2C 设备使用例程
* 例程导出了 i2c_io_sample 命令到控制终端
* 命令调用格式:i2c_io_sample
* 命令解释:使用默认的I2C总线设备
* 程序功能:通过 I2C 设备接收数据并打印,然后将接收的字符加1输出。
*/
#include <rtthread.h>
#include <rtdevice.h>
#define I2C_BUS_NAME "i2c1" /* I2C总线设备名称 */
#define SLAVE_ADDR 0x2D /* 从机地址 */
#define STR_LEN 16 /* 接收发送的数据长度 */
static void i2c_io_sample(int argc, char *argv[])
{
struct rt_i2c_bus_device *i2c_bus = RT_NULL; /* I2C总线设备句柄 */
struct rt_i2c_msg temp_msg; /* I2C消息 */
rt_uint8_t buffer[STR_LEN] = { 0U };
rt_uint32_t i,num_msg;
rt_size_t s_stat;
i2c_bus = (struct rt_i2c_bus_device *)rt_device_find(I2C_BUS_NAME); /* 通过名字获取I2C总线设备的句柄 */
if( i2c_bus == RT_NULL)
{
rt_kprintf("can't find i2c device :%s !\n",I2C_BUS_NAME);
return;
}
/*初始化消息*/
temp_msg.addr = SLAVE_ADDR; /* 从机地址 */
temp_msg.len = STR_LEN; /* 传输的数据长度 */
temp_msg.buf = buffer; /* 读写缓存器 */
num_msg = 1; /* 传输一条消息 */
temp_msg.flags = RT_I2C_RD; /* I2C读 */
s_stat = rt_i2c_transfer(i2c_bus,&temp_msg,num_msg); /* 传输消息 */
rt_thread_mdelay(400);
if( s_stat == num_msg )
{
rt_kprintf("receive successful. \n receive messege : %s \n:",buffer);
for( i = 0 ; i < STR_LEN ; i++)
rt_kprintf(" %x",(unsigned int)buffer[i]);
rt_kprintf("\n");
}
else
{
rt_kprintf("device s% recieve fail \n buffer : s%\n",I2C_BUS_NAME,buffer);
return;
}
for( i = 0 ; i < STR_LEN ; i++)
buffer[i]++;
temp_msg.flags = RT_I2C_WR; /* I2C写 */
s_stat = rt_i2c_transfer(i2c_bus,&temp_msg,num_msg); /* 传输一条 */
rt_thread_mdelay(400);
if( s_stat == num_msg )
{
rt_kprintf(" send successful \n messege : %s \n:",buffer);
for( i = 0 ; i < STR_LEN ; i++)
rt_kprintf(" %x",(unsigned int)buffer[i]);
rt_kprintf("\n");
}
else
{
rt_kprintf("device s% send fail \n",I2C_BUS_NAME);
return;
}
return;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(i2c_io_sample, i2c io sample);
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-09-25 misonyo first edition.
*/
/*
* 程序清单:这是一个通过PIN脚控制LED亮灭的使用例程
* 例程导出了 led_sample 命令到控制终端
* 命令调用格式:led_sample
* 命令解释:命令第二个参数是要使用的PIN脚编号,为空则使用例程默认的引脚编号。
* 程序功能:程序创建一个led线程,线程每隔1000ms改变PIN脚状态,达到控制led灯
* 亮灭的效果。
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <stdlib.h>
/* PIN脚编号,查看驱动文件drv_gpio.c确定 */
#define LED_PIN_NUM 45 /*PA12*/
static int pin_num;
static void led_entry(void *parameter)
{
int count = 0;
/* 设置PIN脚模式为输出 */
rt_pin_mode(pin_num, PIN_MODE_OUTPUT);
while (1)
{
count++;
rt_kprintf("thread run count : %d\r\n", count);
/* 拉低PIN脚 */
rt_pin_write(pin_num, PIN_LOW);
rt_kprintf("led on!\r\n");
/* 延时1000ms */
rt_thread_mdelay(1000);
/* 拉高PIN脚 */
rt_pin_write(pin_num, PIN_HIGH);
rt_kprintf("led off!\r\n");
rt_thread_mdelay(1000);
}
}
static int led_sample(int argc, char *argv[])
{
rt_thread_t tid;
rt_err_t ret = RT_EOK;
/* 判断命令行参数是否给定了PIN脚编号 */
if (argc == 2)
{
pin_num = atoi(argv[1]);
}
else
{
pin_num = LED_PIN_NUM;
}
tid = rt_thread_create("led",
led_entry,
RT_NULL,
512,
RT_THREAD_PRIORITY_MAX / 3,
20);
if (tid != RT_NULL)
{
rt_thread_startup(tid);
}
else
{
ret = RT_ERROR;
}
return ret;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(led_sample, led sample);
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-08-15 misonyo first implementation.
*/
/*
* 程序清单:这是一个 PIN 设备使用例程
* 例程导出了 pin_beep_sample 命令到控制终端
* 命令调用格式:pin_beep_sample
* 程序功能:通过按键控制蜂鸣器对应引脚的电平状态控制蜂鸣器
*/
#include <rtthread.h>
#include <rtdevice.h>
/* 引脚编号,通过查看驱动文件drv_gpio.c确定 */
#ifndef BEEP_PIN_NUM
#define BEEP_PIN_NUM 45 /* PA12 */
#endif
#ifndef KEY0_PIN_NUM
#define KEY0_PIN_NUM 18 /* PF0 */
#endif
#ifndef KEY1_PIN_NUM
#define KEY1_PIN_NUM 19 /* PF1 */
#endif
void beep_on(void *args)
{
rt_kprintf("turn on beep!\n");
rt_pin_write(BEEP_PIN_NUM, PIN_HIGH);
}
void beep_off(void *args)
{
rt_kprintf("turn off beep!\n");
rt_pin_write(BEEP_PIN_NUM, PIN_LOW);
}
static void pin_beep_sample(void)
{
/* 蜂鸣器引脚为输出模式 */
rt_pin_mode(BEEP_PIN_NUM, PIN_MODE_OUTPUT);
/* 默认低电平 */
rt_pin_write(BEEP_PIN_NUM, PIN_LOW);
/* 按键0引脚为输入模式 */
rt_pin_mode(KEY0_PIN_NUM, PIN_MODE_INPUT_PULLUP);
/* 绑定中断,下降沿模式,回调函数名为beep_on */
rt_pin_attach_irq(KEY0_PIN_NUM, PIN_IRQ_MODE_FALLING, beep_on, RT_NULL);
/* 使能中断 */
rt_pin_irq_enable(KEY0_PIN_NUM, PIN_IRQ_ENABLE);
/* 按键1引脚为输入模式 */
rt_pin_mode(KEY1_PIN_NUM, PIN_MODE_INPUT_PULLUP);
/* 绑定中断,下降沿模式,回调函数名为beep_off */
rt_pin_attach_irq(KEY1_PIN_NUM, PIN_IRQ_MODE_FALLING, beep_off, RT_NULL);
/* 使能中断 */
rt_pin_irq_enable(KEY1_PIN_NUM, PIN_IRQ_ENABLE);
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(pin_beep_sample, pin beep sample);
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-12-15 liuhy first implementation.
*/
/*
* 程序清单:这是一个 pm睡眠唤醒的使用例程
* 例程导出了 pm_sample 命令到控制终端
* 命令调用格式:pm_sample
* 命令解释:进入不同的睡眠模式,然后用按键唤醒
* 程序功能:通过串口输出字符串,告知进入睡眠和唤醒睡眠的情况。
*/
#include <rtthread.h>
#include <rtdevice.h>
#define PM_NAME "pm" /* 设备名称 */
#define WAKE_UP_PIN 18 /* 唤醒源 */
#define SLEEP_TIMES 12 /* 进入睡眠次数,轮流进入不同的睡眠模式,包括无睡眠模式 */
struct pm_callback_t
{
volatile int in_fun_times; /*进入函数的次数*/
volatile char flag; /*标志*/
volatile int mode; /*需要打印的模式*/
};
volatile struct pm_callback_t g_pm_data;
/*进入睡眠前,睡眠唤醒后,都会进入。*/
/*函数打印睡眠相关的信息*/
void sleep_in_out_callback(rt_uint8_t event, rt_uint8_t mode, void *data)
{
/*没有标志,不处理*/
if(!(g_pm_data.flag))
{
return;
}
/*标志不正常,清空标志*/
if((g_pm_data.flag) > 2)
{
(g_pm_data.flag) = 0;
return;
}
/*模式不匹配*/
if(g_pm_data.mode != mode )
{
return;
}
/*进入的事件*/
switch(event)
{
/*进入睡眠前*/
case RT_PM_ENTER_SLEEP: g_pm_data.flag = 1;
rt_kprintf("\n\r##%d : ENTER ",g_pm_data.in_fun_times);
g_pm_data.in_fun_times++; /*进入睡眠次数+1*/
break;
/*睡眠唤醒后*/
case RT_PM_EXIT_SLEEP: g_pm_data.flag = 0; /*睡眠唤醒后*/
rt_kprintf("\n\rEXIT\n\r");
rt_pm_release(mode); /*释放休眠模式*/
return;
default: break;
};
/*当前的睡眠模式*/
switch(mode)
{
case PM_SLEEP_MODE_NONE: rt_kprintf("PM_SLEEP_MODE_NONE\n\r");
break;
case PM_SLEEP_MODE_IDLE: rt_kprintf("PM_SLEEP_MODE_IDLE\n\r");
break;
case PM_SLEEP_MODE_LIGHT: rt_kprintf("PM_SLEEP_MODE_LIGHT\n\r");
break;
case PM_SLEEP_MODE_DEEP: rt_kprintf("PM_SLEEP_MODE_DEEP\n\r");
break;
case PM_SLEEP_MODE_STANDBY: rt_kprintf("PM_SLEEP_MODE_STANDBY\n\r");
break;
case PM_SLEEP_MODE_SHUTDOWN: rt_kprintf("PM_SLEEP_MODE_SHUTDOWN\n\r");
break;
case PM_SLEEP_MODE_MAX: rt_kprintf("PM_SLEEP_MODE_MAX\n\r");
break;
default: break;
}
}
/* pm测试函数 */
static void pm_test(void *parameter)
{
int in_mode[7],i = 0;
g_pm_data.in_fun_times = 0;
g_pm_data.flag = 0;
in_mode[0] = PM_SLEEP_MODE_NONE;
in_mode[1] = PM_SLEEP_MODE_IDLE;
in_mode[2] = PM_SLEEP_MODE_LIGHT;
in_mode[3] = PM_SLEEP_MODE_DEEP;
in_mode[4] = PM_SLEEP_MODE_STANDBY;
in_mode[5] = PM_SLEEP_MODE_SHUTDOWN;
in_mode[6] = PM_SLEEP_MODE_MAX;
/*设置回调函数和私有数据*/
rt_pm_notify_set(sleep_in_out_callback,RT_NULL);
while(i < SLEEP_TIMES)
{
g_pm_data.mode = in_mode[i%6];
/*无休眠模式,不赋予标志*/
if(g_pm_data.mode != PM_SLEEP_MODE_NONE)
{
g_pm_data.flag = 2;
}
/*请求选择的休眠模式*/
rt_pm_request(in_mode[i%6]);
rt_thread_mdelay(500);
/*无休眠模式,不需要额外的等待*/
while(( g_pm_data.flag != 0 )&&(g_pm_data.mode != PM_SLEEP_MODE_NONE))
{
rt_thread_mdelay(500);
}
/*释放选择的休眠模式*/
rt_pm_release(in_mode[i%6]);
i++;
}
/*清除回调函数和私有数据*/
rt_pm_notify_set(RT_NULL,RT_NULL);
rt_kprintf("thread pm_test close\n\r");
}
/*按键唤醒的回调函数*/
void wake_by_pin(void *args)
{
}
static int pm_sample(int argc, char *argv[])
{
rt_thread_t thread;
/* 按键引脚为输入模式 */
rt_pin_mode(WAKE_UP_PIN, PIN_MODE_INPUT_PULLUP);
/* 绑定中断,下降沿模式,回调函数名为wake_by_pin */
rt_pin_attach_irq(WAKE_UP_PIN, PIN_IRQ_MODE_RISING, wake_by_pin, RT_NULL);
/* 使能中断 */
rt_pin_irq_enable(WAKE_UP_PIN, PIN_IRQ_ENABLE);
thread = rt_thread_create("pm_test", pm_test, RT_NULL, 1024, 25, 10);
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
rt_kprintf("create pm_test thread failed!\n\r");
}
return RT_EOK;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(pm_sample, pm sample);
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-25 misonyo first implementation.
*/
/*
* 程序清单:这是一个 PWM 设备使用例程
* 例程导出了 pwm_led_sample 命令到控制终端
* 命令调用格式:pwm_led_sample
* 程序功能:通过 PWM 设备控制 LED 灯的亮度,可以看到LED不停的由暗变到亮,然后又从亮变到暗。
*/
#include <rtthread.h>
#include <rtdevice.h>
#define LED_PIN_NUM 45 /* PA12 LED PIN脚编号,查看驱动文件drv_gpio.c确定 */
#define PWM_DEV_NAME "pwm0" /* PWM设备名称 */
#define PWM_DEV_CHANNEL 2 /* PA9 PWM通道 */
struct rt_device_pwm *pwm_dev; /* PWM设备句柄 */
static int pwm_led_sample(int argc, char *argv[])
{
rt_uint32_t period, pulse, dir;
period = 500000; /* 周期为0.5ms,单位为纳秒ns */
dir = 1; /* PWM脉冲宽度值的增减方向 */
pulse = 0; /* PWM脉冲宽度值,单位为纳秒ns */
/* 查找设备 */
pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME);
if (pwm_dev == RT_NULL)
{
rt_kprintf("pwm sample run failed! can't find %s device!\n", PWM_DEV_NAME);
return RT_ERROR;
}
/* 设置PWM周期和脉冲宽度默认值 */
rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, period, pulse);
/* 使能设备 */
rt_pwm_enable(pwm_dev, PWM_DEV_CHANNEL);
while (1)
{
rt_thread_mdelay(50);
if (dir)
{
pulse += 5000; /* 从0值开始每次增加5000ns */
}
else
{
pulse -= 5000; /* 从最大值开始每次减少5000ns */
}
if (pulse >= period)
{
dir = 0;
}
if (0 == pulse)
{
dir = 1;
}
/* 设置PWM周期和脉冲宽度 */
rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, period, pulse);
}
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(pwm_led_sample, pwm sample);
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-30 misonyo first implementation.
*/
/*
* 程序清单:这是一个 RTC 设备使用例程
* 例程导出了 rtc_sample 命令到控制终端
* 命令调用格式:rtc_sample
* 程序功能:设置RTC设备的日期和时间,延时一段时间后获取当前时间并打印显示。
*/
#include <rtthread.h>
#include <rtdevice.h>
static int rtc_sample(int argc, char *argv[])
{
rt_err_t ret = RT_EOK;
time_t now;
/* 设置日期 */
ret = set_date(2018, 12, 3);
if (ret != RT_EOK)
{
rt_kprintf("set RTC date failed\n");
return ret;
}
/* 设置时间 */
ret = set_time(11, 15, 50);
if (ret != RT_EOK)
{
rt_kprintf("set RTC time failed\n");
return ret;
}
/* 延时3秒 */
rt_thread_mdelay(3000);
/* 获取时间 */
now = time(RT_NULL);
rt_kprintf("%s\n", ctime(&now));
return ret;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(rtc_sample, rtc sample);
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2020-12-15 liuhy first implementation.
*/
/*
* 程序清单:这是一个 SPI 设备使用例程
* 例程导出了 spi_io_sample 命令到控制终端
* 命令调用格式:spi_io_sample
* 程序功能:通过SPI设备先读取数据,然后每个字符加1后输出。
*/
#include <rtthread.h>
#include <rtdevice.h>
#define SPI_DEVICE_NAME "spi00"
#define BUF_LEN 16
static void spi_io_sample(int argc, char *argv[])
{
struct rt_spi_device * spi_dev; /* spi设备的句柄 */
struct rt_spi_configuration spi_config;
rt_uint8_t i,buffer[BUF_LEN] = { 0U };
rt_err_t s_stat;
rt_err_t result;
/* 查找 spi设备 获取spi设备句柄 */
spi_dev = (struct rt_spi_device *)rt_device_find(SPI_DEVICE_NAME);
if (spi_dev == RT_NULL)
{
rt_kprintf("spi sample run failed! can't find %s device!\n", SPI_DEVICE_NAME);
return;
}
/* 清空配置结构体 */
rt_memset(&spi_config,0,sizeof(struct rt_spi_configuration));
spi_config.mode &= ~RT_SPI_SLAVE; /* 主机模式 */
spi_config.mode &= ~RT_SPI_3WIRE; /* 4线,双向传输 */
spi_config.mode |= RT_SPI_CPHA; /* 第二边沿采样 */
spi_config.mode |= RT_SPI_CPOL; /* 空闲高电平 */
spi_config.mode |= RT_SPI_NO_CS; /* 禁用软件从机选择管理 */
spi_config.mode |= RT_SPI_MSB; /* 高位在前 */
spi_config.data_width = 8; /* 数据长度:8 */
spi_config.max_hz = 2000000; /* 最快时钟频率 */
/* 配置SPI设备 */
s_stat = rt_spi_configure(spi_dev,&spi_config);
if(s_stat != RT_EOK)
{
rt_kprintf(" spi config fail !\n ");
return;
}
/* 获取总线 ,防止总线被多个线程同时使用 */
result = rt_spi_take_bus(spi_dev);
if (result != RT_EOK)
{
rt_kprintf(" %s take spi bus failed! \n", SPI_DEVICE_NAME);
return;
}
/* 选中片选 */
result = rt_spi_take(spi_dev);
if (result != RT_EOK)
{
rt_kprintf(" %s take spi cs failed! \n", SPI_DEVICE_NAME);
return;
}
/*接收一次数据*/
result = rt_spi_recv(spi_dev,buffer,BUF_LEN);
if(result != BUF_LEN)
{
rt_kprintf("receive fail. \n buffer is : %s \n:",buffer);
for( i = 0 ; i < BUF_LEN ; i++)
rt_kprintf(" %x",(unsigned int)buffer[i]);
rt_kprintf("\n");
return;
}
rt_kprintf("receive successful. \n buffer is : %s \n:",buffer);
for( i = 0 ; i < BUF_LEN ; i++)
rt_kprintf(" %x",(unsigned int)buffer[i]);
rt_kprintf("\n");
/* 将接收到的数据加1 */
for( i = 0 ; i < BUF_LEN ; i++)
buffer[i]++;
/*发送数据*/
result = rt_spi_send(spi_dev,buffer,BUF_LEN);
if(result != BUF_LEN)
{
rt_kprintf("send fail. \n buffer is : %s \n:",buffer);
for( i = 0 ; i < BUF_LEN ; i++)
rt_kprintf(" %x",(unsigned int)buffer[i]);
rt_kprintf("\n");
return;
}
rt_kprintf("send successful. \n buffer is : %s \n:",buffer);
for( i = 0 ; i < BUF_LEN ; i++)
rt_kprintf(" %x",(unsigned int)buffer[i]);
rt_kprintf("\n");
/* 释放片选 */
result = rt_spi_release(spi_dev);
if (result != RT_EOK)
{
rt_kprintf(" %s release spi cs failed! \n", SPI_DEVICE_NAME);
return;
}
/* 释放总线 */
result = rt_spi_release_bus(spi_dev);
if (result != RT_EOK)
{
rt_kprintf(" %s release spi bus failed! \n", SPI_DEVICE_NAME);
return;
}
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(spi_io_sample, spi sample);
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-08-15 misonyo first implementation.
*/
/*
* 程序清单:这是一个 串口 设备使用例程
* 例程导出了 uart_sample 命令到控制终端
* 命令调用格式:uart_sample uart2
* 命令解释:命令第二个参数是要使用的串口设备名称,为空则使用默认的串口设备
* 程序功能:通过串口输出字符串"hello RT-Thread!",然后错位输出输入的字符
*/
#include <rtthread.h>
#define SAMPLE_UART_NAME "uart1" /* 串口设备名称 */
/* 用于接收消息的信号量 */
static struct rt_semaphore rx_sem;
static rt_device_t serial;
/* 接收数据回调函数 */
static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
{
/* 串口接收到数据后产生中断,调用此回调函数,然后发送接收信号量 */
rt_sem_release(&rx_sem);
return RT_EOK;
}
static void serial_thread_entry(void *parameter)
{
char ch;
while (1)
{
/* 从串口读取一个字节的数据,没有读取到则等待接收信号量 */
while (rt_device_read(serial, -1, &ch, 1) != 1)
{
/* 阻塞等待接收信号量,等到信号量后再次读取数据 */
rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
}
/* 读取到的数据通过串口错位输出 */
ch = ch + 1;
rt_device_write(serial, 0, &ch, 1);
}
}
static int uart_sample(int argc, char *argv[])
{
rt_err_t ret = RT_EOK;
char uart_name[RT_NAME_MAX];
char str[] = "hello RT-Thread!\r\n";
if (argc == 2)
{
rt_strncpy(uart_name, argv[1], RT_NAME_MAX);
}
else
{
rt_strncpy(uart_name, SAMPLE_UART_NAME, RT_NAME_MAX);
}
/* 查找串口设备 */
serial = rt_device_find(uart_name);
if (!serial)
{
rt_kprintf("find %s failed!\n", uart_name);
return RT_ERROR;
}
/* 初始化信号量 */
rt_sem_init(&rx_sem, "rx_sem", 0, RT_IPC_FLAG_FIFO);
/* 以中断接收及轮询发送方式打开串口设备 */
rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
/* 设置接收回调函数 */
rt_device_set_rx_indicate(serial, uart_input);
/* 发送字符串 */
rt_device_write(serial, 0, str, (sizeof(str) - 1));
/* 创建 serial 线程 */
rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024, 25, 10);
/* 创建成功则启动线程 */
if (thread != RT_NULL)
{
rt_thread_startup(thread);
}
else
{
ret = RT_ERROR;
}
return ret;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(uart_sample, uart device sample);
...@@ -146,9 +146,9 @@ static rt_err_t es32f0_get_adc_value(struct rt_adc_device *device, rt_uint32_t c ...@@ -146,9 +146,9 @@ static rt_err_t es32f0_get_adc_value(struct rt_adc_device *device, rt_uint32_t c
RT_ASSERT(value != RT_NULL); RT_ASSERT(value != RT_NULL);
/* config adc channel */ /* config adc channel */
nm_config.channel = es32f0_adc_get_channel(channel); nm_config.ch = es32f0_adc_get_channel(channel);
nm_config.rank = ADC_NCH_RANK_1; nm_config.idx = ADC_NCH_IDX_1;
nm_config.samp_time = ADC_SAMPLETIME_4; nm_config.samp = ADC_SAMPLETIME_4;
ald_adc_normal_channel_config(_hadc, &nm_config); ald_adc_normal_channel_config(_hadc, &nm_config);
ald_adc_normal_start(_hadc); ald_adc_normal_start(_hadc);
...@@ -172,16 +172,16 @@ int rt_hw_adc_init(void) ...@@ -172,16 +172,16 @@ int rt_hw_adc_init(void)
/* adc function initialization */ /* adc function initialization */
_h_adc0.perh = ADC0; _h_adc0.perh = ADC0;
_h_adc0.init.data_align = ADC_DATAALIGN_RIGHT; _h_adc0.init.align = ADC_DATAALIGN_RIGHT;
_h_adc0.init.scan_mode = DISABLE; _h_adc0.init.scan = DISABLE;
_h_adc0.init.cont_mode = DISABLE; _h_adc0.init.cont = DISABLE;
_h_adc0.init.disc_mode = ADC_ALL_DISABLE; _h_adc0.init.disc = ADC_ALL_DISABLE;
_h_adc0.init.disc_nbr = ADC_DISC_NBR_1; _h_adc0.init.disc_nr = ADC_DISC_NR_1;
_h_adc0.init.conv_res = ADC_CONV_RES_10; _h_adc0.init.data_bit = ADC_CONV_BIT_12;
_h_adc0.init.clk_div = ADC_CKDIV_128; _h_adc0.init.div = ADC_CKDIV_128;
_h_adc0.init.nche_sel = ADC_NCHESEL_MODE_ALL; _h_adc0.init.nche_sel = ADC_NCHESEL_MODE_ALL;
_h_adc0.init.neg_ref = ADC_NEG_REF_VSS; _h_adc0.init.n_ref = ADC_NEG_REF_VSS;
_h_adc0.init.pos_ref = ADC_POS_REF_VDD; _h_adc0.init.p_ref = ADC_POS_REF_VDD;
ald_adc_init(&_h_adc0); ald_adc_init(&_h_adc0);
rt_hw_adc_register(&_device_adc0, "adc0", &es32f0_adc_ops, &_h_adc0); rt_hw_adc_register(&_device_adc0, "adc0", &es32f0_adc_ops, &_h_adc0);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
* Date Author Notes * Date Author Notes
* 2019-03-19 wangyq the first version * 2019-03-19 wangyq the first version
* 2019-11-01 wangyq update libraries * 2019-11-01 wangyq update libraries
* 2020-12-15 liuhy update libraries
*/ */
#include <rtthread.h> #include <rtthread.h>
...@@ -29,7 +30,7 @@ static void _i2c_init(void) ...@@ -29,7 +30,7 @@ static void _i2c_init(void)
/* Initialize I2C Pin */ /* Initialize I2C Pin */
gpio_instruct.mode = GPIO_MODE_OUTPUT; gpio_instruct.mode = GPIO_MODE_OUTPUT;
gpio_instruct.odos = GPIO_PUSH_PULL; gpio_instruct.odos = GPIO_OPEN_DRAIN;
gpio_instruct.pupd = GPIO_PUSH_UP; gpio_instruct.pupd = GPIO_PUSH_UP;
gpio_instruct.odrv = GPIO_OUT_DRIVE_NORMAL; gpio_instruct.odrv = GPIO_OUT_DRIVE_NORMAL;
gpio_instruct.flt = GPIO_FILTER_DISABLE; gpio_instruct.flt = GPIO_FILTER_DISABLE;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* 2019-04-08 wangyq the first version * 2019-04-08 wangyq the first version
* 2019-11-01 wangyq adapt to the new power management interface * 2019-11-01 wangyq adapt to the new power management interface
*/ */
#include <rthw.h>
#include <board.h> #include <board.h>
#include <rtdevice.h> #include <rtdevice.h>
#include <drv_lptim.h> #include <drv_lptim.h>
...@@ -24,6 +24,21 @@ static void uart_console_reconfig(void) ...@@ -24,6 +24,21 @@ static void uart_console_reconfig(void)
rt_device_control(rt_console_get_device(), RT_DEVICE_CTRL_CONFIG, &config); rt_device_control(rt_console_get_device(), RT_DEVICE_CTRL_CONFIG, &config);
} }
static void delay(void)
{
long i;
rt_base_t level;
level = rt_hw_interrupt_disable();
i = 0;
do{
i++;
}
while (i < 10000);
rt_hw_interrupt_enable(level);
}
/** /**
* This function will put ES32F033x into sleep mode. * This function will put ES32F033x into sleep mode.
* *
...@@ -50,22 +65,26 @@ static void sleep(struct rt_pm *pm, uint8_t mode) ...@@ -50,22 +65,26 @@ static void sleep(struct rt_pm *pm, uint8_t mode)
{ {
/* Enter SLEEP Mode, Main regulator is ON */ /* Enter SLEEP Mode, Main regulator is ON */
ald_pmu_stop1_enter(); ald_pmu_stop1_enter();
delay();
} }
break; break;
case PM_SLEEP_MODE_DEEP: case PM_SLEEP_MODE_DEEP:
/* Enter STOP 2 mode */ /* Enter STOP 2 mode */
ald_pmu_stop2_enter(); ald_pmu_stop2_enter();
delay();
break; break;
case PM_SLEEP_MODE_STANDBY: case PM_SLEEP_MODE_STANDBY:
/* Enter STANDBY mode */ /* Enter STANDBY mode */
ald_pmu_stop2_enter(); ald_pmu_stop2_enter();
delay();
break; break;
case PM_SLEEP_MODE_SHUTDOWN: case PM_SLEEP_MODE_SHUTDOWN:
/* Enter SHUTDOWNN mode */ /* Enter SHUTDOWNN mode */
ald_pmu_stop2_enter(); ald_pmu_stop2_enter();
delay();
break; break;
default: default:
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
* *
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2019-03-19 wangyq the first version * 2019-01-24 wangyq the first version
* 2019-11-01 wangyq update libraries * 2019-11-01 wangyq update libraries
* 2020-12-15 liuhy update libraries
*/ */
#include <rtthread.h> #include <rtthread.h>
...@@ -146,19 +147,21 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message * ...@@ -146,19 +147,21 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
RT_ASSERT(device != RT_NULL); RT_ASSERT(device != RT_NULL);
RT_ASSERT(device->bus != RT_NULL); RT_ASSERT(device->bus != RT_NULL);
RT_ASSERT(device->bus->parent.user_data != RT_NULL); RT_ASSERT(device->bus->parent.user_data != RT_NULL);
RT_ASSERT(message->send_buf != RT_NULL || message->recv_buf != RT_NULL);
hspi = (spi_handle_t *)device->bus->parent.user_data; hspi = (spi_handle_t *)device->bus->parent.user_data;
cs = device->parent.user_data; cs = device->parent.user_data;
/* only send data */ if(message->send_buf != RT_NULL || message->recv_buf != RT_NULL)
if (message->recv_buf == RT_NULL) {
/* send & receive */
if ((message->send_buf != RT_NULL) && (message->recv_buf != RT_NULL))
{ {
if (message->cs_take) if (message->cs_take)
{ {
rt_pin_write(cs->pin, 0); rt_pin_write(cs->pin, 0);
} }
res = ald_spi_send(hspi, (rt_uint8_t *)message->send_buf, (rt_int32_t)message->length, SPITIMEOUT); res = ald_spi_send_recv(hspi, (rt_uint8_t *)message->send_buf, (rt_uint8_t *)message->recv_buf,
(rt_int32_t)message->length, SPITIMEOUT);
if (message->cs_release) if (message->cs_release)
{ {
rt_pin_write(cs->pin, 1); rt_pin_write(cs->pin, 1);
...@@ -166,41 +169,56 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message * ...@@ -166,41 +169,56 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
if (res != RT_EOK) if (res != RT_EOK)
return RT_ERROR; return RT_ERROR;
} }
else
/* only receive data */
if (message->send_buf == RT_NULL)
{ {
if (message->cs_take) /* only send data */
if (message->recv_buf == RT_NULL)
{ {
rt_pin_write(cs->pin, 0); if (message->cs_take)
{
rt_pin_write(cs->pin, 0);
}
res = ald_spi_send(hspi, (rt_uint8_t *)message->send_buf, (rt_int32_t)message->length, SPITIMEOUT);
if (message->cs_release)
{
rt_pin_write(cs->pin, 1);
}
if (res != RT_EOK)
return RT_ERROR;
} }
res = ald_spi_recv(hspi, (rt_uint8_t *)message->recv_buf, (rt_int32_t)message->length, SPITIMEOUT); /* only receive data */
if (message->cs_release) if (message->send_buf == RT_NULL)
{ {
rt_pin_write(cs->pin, 1); if (message->cs_take)
{
rt_pin_write(cs->pin, 0);
}
res = ald_spi_recv(hspi, (rt_uint8_t *)message->recv_buf, (rt_int32_t)message->length, SPITIMEOUT);
if (message->cs_release)
{
rt_pin_write(cs->pin, 1);
}
if (res != RT_EOK)
return RT_ERROR;
} }
if (res != RT_EOK)
return RT_ERROR;
} }
/* send & receive */ }
else else
{ {
if (message->cs_take) if (message->cs_take)
{ {
rt_pin_write(cs->pin, 0); rt_pin_write(cs->pin, 0);
} }
res = ald_spi_send_recv(hspi, (rt_uint8_t *)message->send_buf, (rt_uint8_t *)message->recv_buf,
(rt_int32_t)message->length, SPITIMEOUT);
if (message->cs_release) if (message->cs_release)
{ {
rt_pin_write(cs->pin, 1); rt_pin_write(cs->pin, 1);
} }
if (res != RT_EOK) return RT_EOK;
return RT_ERROR;
} }
return message->length; return message->length;
} }
const struct rt_spi_ops es32f0_spi_ops = const struct rt_spi_ops es32f0_spi_ops =
...@@ -209,21 +227,45 @@ const struct rt_spi_ops es32f0_spi_ops = ...@@ -209,21 +227,45 @@ const struct rt_spi_ops es32f0_spi_ops =
spixfer, spixfer,
}; };
static struct rt_spi_bus _spi_bus0, _spi_bus1;
static spi_handle_t _spi0, _spi1; rt_err_t es32f0_spi_device_attach(rt_uint32_t pin, const char *bus_name, const char *device_name)
int es32f0_spi_register_bus(SPI_TypeDef *SPIx, const char *name) {
/* define spi Instance */
struct rt_spi_device *spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
RT_ASSERT(spi_device != RT_NULL);
struct es32f0_hw_spi_cs *cs_pin = (struct es32f0_hw_spi_cs *)rt_malloc(sizeof(struct es32f0_hw_spi_cs));
RT_ASSERT(cs_pin != RT_NULL);
cs_pin->pin = pin;
rt_pin_mode(pin, PIN_MODE_OUTPUT);
rt_pin_write(pin, 1);
return rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
}
#ifdef BSP_USING_SPI0
static struct rt_spi_bus _spi_bus0;
static spi_handle_t _spi0;
#endif
#ifdef BSP_USING_SPI1
static struct rt_spi_bus _spi_bus1;
static spi_handle_t _spi1;
#endif
int rt_hw_spi_init(void)
{ {
int result = RT_EOK;
struct rt_spi_bus *spi_bus; struct rt_spi_bus *spi_bus;
spi_handle_t *spi; spi_handle_t *spi;
gpio_init_t gpio_instruct; gpio_init_t gpio_instruct;
if (SPIx == SPI0) #ifdef BSP_USING_SPI0
{ _spi0.perh = SPI0;
_spi0.perh = SPI0; spi_bus = &_spi_bus0;
spi_bus = &_spi_bus0; spi = &_spi0;
spi = &_spi0; rt_device_t spi_bus_dev0;
/* SPI0 gpio init */ /* SPI0 gpio init */
gpio_instruct.mode = GPIO_MODE_OUTPUT; gpio_instruct.mode = GPIO_MODE_OUTPUT;
gpio_instruct.odos = GPIO_PUSH_PULL; gpio_instruct.odos = GPIO_PUSH_PULL;
gpio_instruct.func = GPIO_FUNC_4; gpio_instruct.func = GPIO_FUNC_4;
...@@ -236,14 +278,33 @@ int es32f0_spi_register_bus(SPI_TypeDef *SPIx, const char *name) ...@@ -236,14 +278,33 @@ int es32f0_spi_register_bus(SPI_TypeDef *SPIx, const char *name)
/* PB4->SPI0_MISO */ /* PB4->SPI0_MISO */
gpio_instruct.mode = GPIO_MODE_INPUT; gpio_instruct.mode = GPIO_MODE_INPUT;
ald_gpio_init(GPIOB, GPIO_PIN_4, &gpio_instruct); ald_gpio_init(GPIOB, GPIO_PIN_4, &gpio_instruct);
spi_bus->parent.user_data = spi;
result = rt_spi_bus_register(spi_bus, "spi0", &es32f0_spi_ops);
if (result != RT_EOK)
{
return result;
} }
else if (SPIx == SPI1)
rt_device_register(spi_bus_dev0, "spi00", RT_DEVICE_FLAG_RDWR);
/* SPI0_NSS = PA15 = PIN 50 */
result = es32f0_spi_device_attach(50, "spi0", "spi00");
if (result != RT_EOK)
{ {
_spi1.perh = SPI1; return result;
spi_bus = &_spi_bus1; }
spi = &_spi1;
#endif
/* SPI1 gpio init */ #ifdef BSP_USING_SPI1
_spi1.perh = SPI1;
spi_bus = &_spi_bus1;
spi = &_spi1;
rt_device_t spi_bus_dev0;
/* SPI1 gpio init */
gpio_instruct.mode = GPIO_MODE_OUTPUT; gpio_instruct.mode = GPIO_MODE_OUTPUT;
gpio_instruct.odos = GPIO_PUSH_PULL; gpio_instruct.odos = GPIO_PUSH_PULL;
gpio_instruct.func = GPIO_FUNC_4; gpio_instruct.func = GPIO_FUNC_4;
...@@ -256,39 +317,24 @@ int es32f0_spi_register_bus(SPI_TypeDef *SPIx, const char *name) ...@@ -256,39 +317,24 @@ int es32f0_spi_register_bus(SPI_TypeDef *SPIx, const char *name)
/* PB14->SPI1_MISO */ /* PB14->SPI1_MISO */
gpio_instruct.mode = GPIO_MODE_INPUT; gpio_instruct.mode = GPIO_MODE_INPUT;
ald_gpio_init(GPIOB, GPIO_PIN_14, &gpio_instruct); ald_gpio_init(GPIOB, GPIO_PIN_14, &gpio_instruct);
spi_bus->parent.user_data = spi;
result = rt_spi_bus_register(spi_bus, "spi1", &es32f0_spi_ops);
if (result != RT_EOK)
{
return result;
} }
else
rt_device_register(spi_bus_dev0, "spi10", RT_DEVICE_FLAG_RDWR);
/* SPI1_NSS = PC00 = PIN 8 */
result = es32f0_spi_device_attach(8, "spi1", "spi10");
if (result != RT_EOK)
{ {
return -1; return result;
} }
spi_bus->parent.user_data = spi;
return rt_spi_bus_register(spi_bus, name, &es32f0_spi_ops);
}
rt_err_t es32f0_spi_device_attach(rt_uint32_t pin, const char *bus_name, const char *device_name)
{
/* define spi Instance */
struct rt_spi_device *spi_device = (struct rt_spi_device *)rt_malloc(sizeof(struct rt_spi_device));
RT_ASSERT(spi_device != RT_NULL);
struct es32f0_hw_spi_cs *cs_pin = (struct es32f0_hw_spi_cs *)rt_malloc(sizeof(struct es32f0_hw_spi_cs));
RT_ASSERT(cs_pin != RT_NULL);
cs_pin->pin = pin;
rt_pin_mode(pin, PIN_MODE_OUTPUT);
rt_pin_write(pin, 1);
return rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
}
int rt_hw_spi_init(void)
{
int result = 0;
#ifdef BSP_USING_SPI0
result = es32f0_spi_register_bus(SPI0, "spi0");
#endif
#ifdef BSP_USING_SPI1
result = es32f0_spi_register_bus(SPI1, "spi1");
#endif #endif
return result; return result;
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#define __ALD_ACMP_H__ #define __ALD_ACMP_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "utils.h" #include "utils.h"
...@@ -38,187 +38,171 @@ extern "C" { ...@@ -38,187 +38,171 @@ extern "C" {
/** /**
* @brief Acmp interrupt * @brief Acmp interrupt
*/ */
typedef enum typedef enum {
{ ACMP_IT_EDGE = (1U << 0), /**< Edge interrupt bit */
ACMP_IT_EDGE = (1U << 0), /**< Edge interrupt bit */ ACMP_IT_WARMUP = (1U << 1), /**< Warm up interrupt bit */
ACMP_IT_WARMUP = (1U << 1), /**< Warm up interrupt bit */
} acmp_it_t; } acmp_it_t;
/** /**
* @brief Acmp interrupt * @brief Acmp interrupt
*/ */
typedef enum typedef enum {
{ ACMP_FLAG_EDGE = (1U << 0), /**< Edge interrupt flag */
ACMP_FLAG_EDGE = (1U << 0), /**< Edge interrupt flag */ ACMP_FLAG_WARMUP = (1U << 1), /**< Warm up interrupt flag */
ACMP_FLAG_WARMUP = (1U << 1), /**< Warm up interrupt flag */
} acmp_flag_t; } acmp_flag_t;
/** /**
* @brief Acmp interrupt flag * @brief Acmp interrupt flag
*/ */
typedef enum typedef enum {
{ ACMP_STATUS_EDGE = (1U << 0), /**< Edge interrupt flag */
ACMP_STATUS_EDGE = (1U << 0), /**< Edge interrupt flag */ ACMP_STATUS_WARMUP = (1U << 1), /**< Warm up interrupt flag */
ACMP_STATUS_WARMUP = (1U << 1), /**< Warm up interrupt flag */
} acmp_status_t; } acmp_status_t;
/** /**
* @brief Acmp positive input * @brief Acmp positive input
*/ */
typedef enum typedef enum {
{ ACMP_POS_CH0 = 0U, /**< Channel 0 as positive input */
ACMP_POS_CH0 = 0, /**< Channel 0 as positive input */ ACMP_POS_CH1 = 1U, /**< Channel 1 as positive input */
ACMP_POS_CH1 = 1, /**< Channel 1 as positive input */ ACMP_POS_CH2 = 2U, /**< Channel 2 as positive input */
ACMP_POS_CH2 = 2, /**< Channel 2 as positive input */ ACMP_POS_CH3 = 3U, /**< Channel 3 as positive input */
ACMP_POS_CH3 = 3, /**< Channel 3 as positive input */ ACMP_POS_CH4 = 4U, /**< Channel 4 as positive input */
ACMP_POS_CH4 = 4, /**< Channel 4 as positive input */ ACMP_POS_CH5 = 5U, /**< Channel 5 as positive input */
ACMP_POS_CH5 = 5, /**< Channel 5 as positive input */ ACMP_POS_CH6 = 6U, /**< Channel 6 as positive input */
ACMP_POS_CH6 = 6, /**< Channel 6 as positive input */ ACMP_POS_CH7 = 7U, /**< Channel 7 as positive input */
ACMP_POS_CH7 = 7, /**< Channel 7 as positive input */
} acmp_pos_input_t; } acmp_pos_input_t;
/** /**
* @brief Acmp negative input * @brief Acmp negative input
*/ */
typedef enum typedef enum {
{ ACMP_NEG_CH0 = 0U, /**< Channel 0 as negative input */
ACMP_NEG_CH0 = 0, /**< Channel 0 as negative input */ ACMP_NEG_CH1 = 1U, /**< Channel 1 as negative input */
ACMP_NEG_CH1 = 1, /**< Channel 1 as negative input */ ACMP_NEG_CH2 = 2U, /**< Channel 2 as negative input */
ACMP_NEG_CH2 = 2, /**< Channel 2 as negative input */ ACMP_NEG_CH3 = 3U, /**< Channel 3 as negative input */
ACMP_NEG_CH3 = 3, /**< Channel 3 as negative input */ ACMP_NEG_CH4 = 4U, /**< Channel 4 as negative input */
ACMP_NEG_CH4 = 4, /**< Channel 4 as negative input */ ACMP_NEG_CH5 = 5U, /**< Channel 5 as negative input */
ACMP_NEG_CH5 = 5, /**< Channel 5 as negative input */ ACMP_NEG_CH6 = 6U, /**< Channel 6 as negative input */
ACMP_NEG_CH6 = 6, /**< Channel 6 as negative input */ ACMP_NEG_CH7 = 7U, /**< Channel 7 as negative input */
ACMP_NEG_CH7 = 7, /**< Channel 7 as negative input */ ACMP_NEG_1V25 = 8U, /**< 1.25v as negative input */
ACMP_NEG_1V25 = 8, /**< 1.25v as negative input */ ACMP_NEG_2V5 = 9U, /**< 2.5v as negative input */
ACMP_NEG_2V5 = 9, /**< 2.5v as negative input */ ACMP_NEG_VDD = 10U, /**< VDD as negative input */
ACMP_NEG_VDD = 10, /**< VDD as negative input */
} acmp_neg_input_t; } acmp_neg_input_t;
/** /**
* @brief Acmp mode * @brief Acmp mode
*/ */
typedef enum typedef enum {
{ ACMP_ULTRA_LOW_POWER = 0U, /**< Ultra low power mode */
ACMP_ULTRA_LOW_POWER = 0, /**< Ultra low power mode */ ACMP_LOW_POWER = 1U, /**< Low power mode */
ACMP_LOW_POWER = 1, /**< Low power mode */ ACMP_MIDDLE_POWER = 2U, /**< Middle power mode */
ACMP_MIDDLE_POWER = 2, /**< Middle power mode */ ACMP_HIGH_POWER = 3U, /**< High power mode */
ACMP_HIGH_POWER = 3, /**< High power mode */
} acmp_mode_t; } acmp_mode_t;
/** /**
* @brief Acmp warm-up time * @brief Acmp warm-up time
*/ */
typedef enum typedef enum {
{ ACMP_4_PCLK = 0U, /**< 4 hfperclk cycles */
ACMP_4_PCLK = 0, /**< 4 hfperclk cycles */ ACMP_8_PCLK = 1U, /**< 4 hfperclk cycles */
ACMP_8_PCLK = 1, /**< 4 hfperclk cycles */ ACMP_16_PCLK = 2U, /**< 4 hfperclk cycles */
ACMP_16_PCLK = 2, /**< 4 hfperclk cycles */ ACMP_32_PCLK = 3U, /**< 4 hfperclk cycles */
ACMP_32_PCLK = 3, /**< 4 hfperclk cycles */ ACMP_64_PCLK = 4U, /**< 4 hfperclk cycles */
ACMP_64_PCLK = 4, /**< 4 hfperclk cycles */ ACMP_128_PCLK = 5U, /**< 4 hfperclk cycles */
ACMP_128_PCLK = 5, /**< 4 hfperclk cycles */ ACMP_256_PCLK = 6U, /**< 4 hfperclk cycles */
ACMP_256_PCLK = 6, /**< 4 hfperclk cycles */ ACMP_512_PCLK = 7U, /**< 4 hfperclk cycles */
ACMP_512_PCLK = 7, /**< 4 hfperclk cycles */
} acmp_warm_time_t; } acmp_warm_time_t;
/** /**
* @brief Acmp hysteresis level * @brief Acmp hysteresis level
*/ */
typedef enum typedef enum {
{ ACMP_HYST_0 = 0U, /**< No hysteresis */
ACMP_HYST_0 = 0, /**< No hysteresis */ ACMP_HYST_15 = 1U, /**< 15mV hysteresis */
ACMP_HYST_15 = 1, /**< 15mV hysteresis */ ACMP_HYST_22 = 2U, /**< 22mV hysteresis */
ACMP_HYST_22 = 2, /**< 22mV hysteresis */ ACMP_HYST_29 = 3U, /**< 29mV hysteresis */
ACMP_HYST_29 = 3, /**< 29mV hysteresis */ ACMP_HYST_36 = 4U, /**< 36mV hysteresis */
ACMP_HYST_36 = 4, /**< 36mV hysteresis */ ACMP_HYST_43 = 5U, /**< 43mV hysteresis */
ACMP_HYST_43 = 5, /**< 43mV hysteresis */ ACMP_HYST_50 = 6U, /**< 50mV hysteresis */
ACMP_HYST_50 = 6, /**< 50mV hysteresis */ ACMP_HYST_57 = 7U, /**< 57mV hysteresis */
ACMP_HYST_57 = 7, /**< 57mV hysteresis */
} acmp_hystsel_t; } acmp_hystsel_t;
/** /**
* @brief Acmp inactive state * @brief Acmp inactive state
*/ */
typedef enum typedef enum {
{ ACMP_INACTVAL_LOW = 0U, /**< The inactive value is 0 */
ACMP_INACTVAL_LOW = 0, /**< The inactive value is 0 */ ACMP_INACTVAL_HIGH = 1U, /**< The inactive value is 1 */
ACMP_INACTVAL_HIGH = 1, /**< The inactive value is 1 */
} acmp_inactval_t; } acmp_inactval_t;
/** /**
* @brief which edges set up interrupt * @brief which edges set up interrupt
*/ */
typedef enum typedef enum {
{ ACMP_EDGE_NONE = 0U, /**< Disable EDGE interrupt */
ACMP_EDGE_NONE = 0, /**< Disable EDGE interrupt */ ACMP_EDGE_FALL = 1U, /**< Falling edges set EDGE interrupt */
ACMP_EDGE_FALL = 1, /**< Falling edges set EDGE interrupt */ ACMP_EDGE_RISE = 2U, /**< rise edges set EDGE interrupt */
ACMP_EDGE_RISE = 2, /**< rise edges set EDGE interrupt */ ACMP_EDGE_ALL = 3U, /**< Falling edges and rise edges set EDGE interrupt */
ACMP_EDGE_ALL = 3, /**< Falling edges and rise edges set EDGE interrupt */
} acmp_edge_t; } acmp_edge_t;
/** /**
* @brief Acmp output function * @brief Acmp output function
*/ */
typedef enum typedef enum {
{ ACMP_OUT_DISABLE = 0U, /**< Disable acmp output */
ACMP_OUT_DISABLE = 0, /**< Disable acmp output */ ACMP_OUT_ENABLE = 1U, /**< Enable acmp output */
ACMP_OUT_ENABLE = 1, /**< Enable acmp output */
} acmp_out_func_t; } acmp_out_func_t;
/** /**
* @brief Acmp warm-up interrupt function * @brief Acmp warm-up interrupt function
*/ */
typedef enum typedef enum {
{ ACMP_WARM_DISABLE = 0U, /**< Disable acmp warm-up interrupt */
ACMP_WARM_DISABLE = 0, /**< Disable acmp warm-up interrupt */ ACMP_WARM_ENABLE = 1U, /**< Enable acmp warm-up interrupt */
ACMP_WARM_ENABLE = 1, /**< Enable acmp warm-up interrupt */
} acmp_warm_it_func; } acmp_warm_it_func;
/** /**
* @brief Acmp gpio output invert * @brief Acmp gpio output invert
*/ */
typedef enum typedef enum {
{ ACMP_GPIO_NO_INV = 0U, /**< Acmp output to gpio is not inverted */
ACMP_GPIO_NO_INV = 0, /**< Acmp output to gpio is not inverted */ ACMP_GPIO_INV = 1U, /**< Acmp output to gpio is inverted */
ACMP_GPIO_INV = 1, /**< Acmp output to gpio is inverted */
} acmp_invert_t; } acmp_invert_t;
/** /**
* @brief Acmp output config structure definition * @brief Acmp output config structure definition
*/ */
typedef struct typedef struct {
{ acmp_out_func_t out_func; /**< Acmp output function */
acmp_out_func_t out_func; /**< Acmp output function */ acmp_invert_t gpio_inv; /**< If invert gpio output */
acmp_invert_t gpio_inv; /**< If invert gpio output */
} acmp_output_config_t; } acmp_output_config_t;
/** /**
* @brief Acmp init structure definition * @brief Acmp init structure definition
*/ */
typedef struct typedef struct {
{ acmp_mode_t mode; /**< Acmp operation mode */
acmp_mode_t mode; /**< Acmp operation mode */ acmp_warm_time_t warm_time; /**< Acmp warm up time */
acmp_warm_time_t warm_time; /**< Acmp warm up time */ acmp_hystsel_t hystsel; /**< Acmp hysteresis level */
acmp_hystsel_t hystsel; /**< Acmp hysteresis level */ acmp_warm_it_func warm_func; /**< Acmp warm-up interrupt enable/disable */
acmp_warm_it_func warm_func; /**< Acmp warm-up interrupt enable/disable */ acmp_pos_input_t pos_port; /**< Acmp positive port select */
acmp_pos_input_t pos_port; /**< Acmp positive port select */ acmp_neg_input_t neg_port; /**< Acmp negative port select */
acmp_neg_input_t neg_port; /**< Acmp negative port select */ acmp_inactval_t inactval; /**< Acmp inavtive output value */
acmp_inactval_t inactval; /**< Acmp inavtive output value */ acmp_edge_t edge; /** Select edges to set interrupt flag */
acmp_edge_t edge; /** Select edges to set interrupt flag */ uint8_t vdd_level; /** Select scaling factor for CDD reference level, MAX is 63 */
uint8_t vdd_level; /** Select scaling factor for CDD reference level, MAX is 63 */
} acmp_init_t; } acmp_init_t;
/** /**
* @brief ACMP Handle Structure definition * @brief ACMP Handle Structure definition
*/ */
typedef struct acmp_handle_s typedef struct acmp_handle_s {
{ ACMP_TypeDef *perh; /**< Register base address */
ACMP_TypeDef *perh; /**< Register base address */ acmp_init_t init; /**< ACMP required parameters */
acmp_init_t init; /**< ACMP required parameters */ lock_state_t lock; /**< Locking object */
lock_state_t lock; /**< Locking object */
void (*acmp_warmup_cplt_cbk)(struct acmp_handle_s *arg); /**< Acmp warm-up complete callback */ void (*acmp_warmup_cplt_cbk)(struct acmp_handle_s *arg); /**< Acmp warm-up complete callback */
void (*acmp_edge_cplt_cbk)(struct acmp_handle_s *arg); /**< Acmp edge trigger callback */ void (*acmp_edge_cplt_cbk)(struct acmp_handle_s *arg); /**< Acmp edge trigger callback */
} acmp_handle_t; } acmp_handle_t;
/** /**
* @} * @}
...@@ -237,64 +221,64 @@ typedef struct acmp_handle_s ...@@ -237,64 +221,64 @@ typedef struct acmp_handle_s
* @{ * @{
*/ */
#define IS_ACMP_TYPE(x) (((x) == ACMP0) || \ #define IS_ACMP_TYPE(x) (((x) == ACMP0) || \
((x) == ACMP1)) ((x) == ACMP1))
#define IS_ACMP_MODE_TYPE(x) (((x) == ACMP_ULTRA_LOW_POWER) || \ #define IS_ACMP_MODE_TYPE(x) (((x) == ACMP_ULTRA_LOW_POWER) || \
((x) == ACMP_LOW_POWER) || \ ((x) == ACMP_LOW_POWER) || \
((x) == ACMP_MIDDLE_POWER) || \ ((x) == ACMP_MIDDLE_POWER) || \
((x) == ACMP_HIGH_POWER)) ((x) == ACMP_HIGH_POWER))
#define IS_ACMP_IT_TYPE(x) (((x) == ACMP_IT_EDGE) || \ #define IS_ACMP_IT_TYPE(x) (((x) == ACMP_IT_EDGE) || \
((x) == ACMP_IT_WARMUP)) ((x) == ACMP_IT_WARMUP))
#define IS_ACMP_FLAG_TYPE(x) (((x) == ACMP_FLAG_EDGE) || \ #define IS_ACMP_FLAG_TYPE(x) (((x) == ACMP_FLAG_EDGE) || \
((x) == ACMP_FLAG_WARMUP)) ((x) == ACMP_FLAG_WARMUP))
#define IS_ACMP_STATUS_TYPE(x) (((x) == ACMP_STATUS_EDGE) || \ #define IS_ACMP_STATUS_TYPE(x) (((x) == ACMP_STATUS_EDGE) || \
((x) == ACMP_STATUS_WARMUP)) ((x) == ACMP_STATUS_WARMUP))
#define IS_ACMP_POS_INPUT_TYPE(x) (((x) == ACMP_POS_CH0) || \ #define IS_ACMP_POS_INPUT_TYPE(x) (((x) == ACMP_POS_CH0) || \
((x) == ACMP_POS_CH1) || \ ((x) == ACMP_POS_CH1) || \
((x) == ACMP_POS_CH2) || \ ((x) == ACMP_POS_CH2) || \
((x) == ACMP_POS_CH3) || \ ((x) == ACMP_POS_CH3) || \
((x) == ACMP_POS_CH4) || \ ((x) == ACMP_POS_CH4) || \
((x) == ACMP_POS_CH5) || \ ((x) == ACMP_POS_CH5) || \
((x) == ACMP_POS_CH6) || \ ((x) == ACMP_POS_CH6) || \
((x) == ACMP_POS_CH7)) ((x) == ACMP_POS_CH7))
#define IS_ACMP_NEG_INPUT_TYPE(x) (((x) == ACMP_NEG_CH0) || \ #define IS_ACMP_NEG_INPUT_TYPE(x) (((x) == ACMP_NEG_CH0) || \
((x) == ACMP_NEG_CH1) || \ ((x) == ACMP_NEG_CH1) || \
((x) == ACMP_NEG_CH2) || \ ((x) == ACMP_NEG_CH2) || \
((x) == ACMP_NEG_CH3) || \ ((x) == ACMP_NEG_CH3) || \
((x) == ACMP_NEG_CH4) || \ ((x) == ACMP_NEG_CH4) || \
((x) == ACMP_NEG_CH5) || \ ((x) == ACMP_NEG_CH5) || \
((x) == ACMP_NEG_CH6) || \ ((x) == ACMP_NEG_CH6) || \
((x) == ACMP_NEG_CH7) || \ ((x) == ACMP_NEG_CH7) || \
((x) == ACMP_NEG_1V25) || \ ((x) == ACMP_NEG_1V25) || \
((x) == ACMP_NEG_2V5) || \ ((x) == ACMP_NEG_2V5) || \
((x) == ACMP_NEG_VDD)) ((x) == ACMP_NEG_VDD))
#define IS_ACMP_WARM_UP_TIME_TYPE(x) (((x) == ACMP_4_PCLK) || \ #define IS_ACMP_WARM_UP_TIME_TYPE(x) (((x) == ACMP_4_PCLK) || \
((x) == ACMP_8_PCLK) || \ ((x) == ACMP_8_PCLK) || \
((x) == ACMP_16_PCLK) || \ ((x) == ACMP_16_PCLK) || \
((x) == ACMP_32_PCLK) || \ ((x) == ACMP_32_PCLK) || \
((x) == ACMP_64_PCLK) || \ ((x) == ACMP_64_PCLK) || \
((x) == ACMP_128_PCLK) || \ ((x) == ACMP_128_PCLK) || \
((x) == ACMP_256_PCLK) || \ ((x) == ACMP_256_PCLK) || \
((x) == ACMP_512_PCLK)) ((x) == ACMP_512_PCLK))
#define IS_ACMP_HYSTSEL_TYPE(x) (((x) == ACMP_HYST_0) || \ #define IS_ACMP_HYSTSEL_TYPE(x) (((x) == ACMP_HYST_0) || \
((x) == ACMP_HYST_15) || \ ((x) == ACMP_HYST_15) || \
((x) == ACMP_HYST_22) || \ ((x) == ACMP_HYST_22) || \
((x) == ACMP_HYST_29) || \ ((x) == ACMP_HYST_29) || \
((x) == ACMP_HYST_36) || \ ((x) == ACMP_HYST_36) || \
((x) == ACMP_HYST_43) || \ ((x) == ACMP_HYST_43) || \
((x) == ACMP_HYST_50) || \ ((x) == ACMP_HYST_50) || \
((x) == ACMP_HYST_57)) ((x) == ACMP_HYST_57))
#define IS_ACMP_INACTVAL_TYPE(x) (((x) == ACMP_INACTVAL_LOW) || \ #define IS_ACMP_INACTVAL_TYPE(x) (((x) == ACMP_INACTVAL_LOW) || \
((x) == ACMP_INACTVAL_HIGH)) ((x) == ACMP_INACTVAL_HIGH))
#define IS_ACMP_EDGE_TYPE(x) (((x) == ACMP_EDGE_NONE) || \ #define IS_ACMP_EDGE_TYPE(x) (((x) == ACMP_EDGE_NONE) || \
((x) == ACMP_EDGE_FALL) || \ ((x) == ACMP_EDGE_FALL) || \
((x) == ACMP_EDGE_RISE) || \ ((x) == ACMP_EDGE_RISE) || \
((x) == ACMP_EDGE_ALL)) ((x) == ACMP_EDGE_ALL))
#define IS_ACMP_OUT_FUNC_TYPE(x) (((x) == ACMP_OUT_DISABLE) || \ #define IS_ACMP_OUT_FUNC_TYPE(x) (((x) == ACMP_OUT_DISABLE) || \
((x) == ACMP_OUT_ENABLE)) ((x) == ACMP_OUT_ENABLE))
#define IS_ACMP_INVERT_TYPE(x) (((x) == ACMP_GPIO_NO_INV) || \ #define IS_ACMP_INVERT_TYPE(x) (((x) == ACMP_GPIO_NO_INV) || \
((x) == ACMP_GPIO_INV)) ((x) == ACMP_GPIO_INV))
#define IS_ACMP_WARM_FUNC_TYPE(x) (((x) == ACMP_WARM_DISABLE) || \ #define IS_ACMP_WARM_FUNC_TYPE(x) (((x) == ACMP_WARM_DISABLE) || \
((x) == ACMP_WARM_ENABLE)) ((x) == ACMP_WARM_ENABLE))
/** /**
* @} * @}
*/ */
...@@ -348,8 +332,7 @@ uint8_t ald_acmp_out_result(acmp_handle_t *hperh); ...@@ -348,8 +332,7 @@ uint8_t ald_acmp_out_result(acmp_handle_t *hperh);
* @} * @}
*/ */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" }
}
#endif #endif
#endif #endif
...@@ -35,44 +35,44 @@ extern "C" { ...@@ -35,44 +35,44 @@ extern "C" {
/** @defgroup BKPC_Public_Macros BKPC Public Macros /** @defgroup BKPC_Public_Macros BKPC Public Macros
* @{ * @{
*/ */
#define BKPC_LOCK() (WRITE_REG(BKPC->PROT, 0)) #define BKPC_LOCK() (WRITE_REG(BKPC->PROT, 0U))
#define BKPC_UNLOCK() (WRITE_REG(BKPC->PROT, 0x9669AA55)) #define BKPC_UNLOCK() (WRITE_REG(BKPC->PROT, 0x9669AA55U))
#define BKPC_LRC_ENABLE() \ #define BKPC_LRC_ENABLE() \
do { \ do { \
BKPC_UNLOCK(); \ BKPC_UNLOCK(); \
SET_BIT(BKPC->CR, BKPC_CR_LRCEN_MSK); \ SET_BIT(BKPC->CR, BKPC_CR_LRCEN_MSK); \
BKPC_LOCK(); \ BKPC_LOCK(); \
} while (0) } while (0)
#define BKPC_LRC_DISABLE() \ #define BKPC_LRC_DISABLE() \
do { \ do { \
BKPC_UNLOCK(); \ BKPC_UNLOCK(); \
CLEAR_BIT(BKPC->CR, BKPC_CR_LRCEN_MSK); \ CLEAR_BIT(BKPC->CR, BKPC_CR_LRCEN_MSK); \
BKPC_LOCK(); \ BKPC_LOCK(); \
} while (0) } while (0)
#define BKPC_LOSM_ENABLE() \ #define BKPC_LOSM_ENABLE() \
do { \ do { \
BKPC_UNLOCK(); \ BKPC_UNLOCK(); \
SET_BIT(BKPC->CR, BKPC_CR_LOSMEN_MSK); \ SET_BIT(BKPC->CR, BKPC_CR_LOSMEN_MSK); \
BKPC_LOCK(); \ BKPC_LOCK(); \
} while (0) } while (0)
#define BKPC_LOSM_DISABLE() \ #define BKPC_LOSM_DISABLE() \
do { \ do { \
BKPC_UNLOCK(); \ BKPC_UNLOCK(); \
CLEAR_BIT(BKPC->CR, BKPC_CR_LOSMEN_MSK);\ CLEAR_BIT(BKPC->CR, BKPC_CR_LOSMEN_MSK);\
BKPC_LOCK(); \ BKPC_LOCK(); \
} while (0) } while (0)
#define BKPC_LOSC_ENABLE() \ #define BKPC_LOSC_ENABLE() \
do { \ do { \
BKPC_UNLOCK(); \ BKPC_UNLOCK(); \
SET_BIT(BKPC->CR, BKPC_CR_LOSCEN_MSK); \ SET_BIT(BKPC->CR, BKPC_CR_LOSCEN_MSK); \
BKPC_LOCK(); \ BKPC_LOCK(); \
} while (0) } while (0)
#define BKPC_LOSC_DISABLE() \ #define BKPC_LOSC_DISABLE() \
do { \ do { \
BKPC_UNLOCK(); \ BKPC_UNLOCK(); \
CLEAR_BIT(BKPC->CR, BKPC_CR_LOSCEN_MSK);\ CLEAR_BIT(BKPC->CR, BKPC_CR_LOSCEN_MSK);\
BKPC_LOCK(); \ BKPC_LOCK(); \
} while (0) } while (0)
/** /**
* @} * @}
*/ */
...@@ -83,37 +83,31 @@ extern "C" { ...@@ -83,37 +83,31 @@ extern "C" {
/** /**
* @brief BKPC ldo output select * @brief BKPC ldo output select
*/ */
typedef enum typedef enum {
{ BKPC_LDO_OUTPUT_1_6 = 0x0U, /**< 1.6V */
BKPC_LDO_OUTPUT_1_6 = 0x0, /**< 1.6V */ BKPC_LDO_OUTPUT_1_3 = 0x1U, /**< 1.3V */
BKPC_LDO_OUTPUT_1_3 = 0x1, /**< 1.3V */ BKPC_LDO_OUTPUT_1_4 = 0x2U, /**< 1.4V */
BKPC_LDO_OUTPUT_1_4 = 0x2, /**< 1.4V */ BKPC_LDO_OUTPUT_1_5 = 0x4U, /**< 1.5V */
BKPC_LDO_OUTPUT_1_5 = 0x4, /**< 1.5V */
} bkpc_ldo_output_t; } bkpc_ldo_output_t;
/** /**
* @brief BKPC BOR voltage select * @brief Standby wakeup port select
*/ */
typedef enum typedef enum {
{ PMU_STANDBY_PORT_SEL_PA0 = 0x0U, /**< Wakeup by PA0 */
BKPC_BOR_VOL_1_7 = 0x0, /**< 1.7V */ PMU_STANDBY_PORT_SEL_PA1 = 0x1U, /**< Wakeup by PA1 */
BKPC_BOR_VOL_2_0 = 0x1, /**< 2.0V */ PMU_STANDBY_PORT_SEL_PA2 = 0x2U, /**< Wakeup by PA2 */
BKPC_BOR_VOL_2_1 = 0x2, /**< 2.1V */ PMU_STANDBY_PORT_SEL_PA3 = 0x3U, /**< Wakeup by PA3 */
BKPC_BOR_VOL_2_2 = 0x3, /**< 2.2V */ PMU_STANDBY_PORT_SEL_NONE = 0xFU, /**< Wakeup by other source */
BKPC_BOR_VOL_2_3 = 0x4, /**< 2.3V */ } bkpc_wakeup_port_t;
BKPC_BOR_VOL_2_4 = 0x5, /**< 2.4V */
BKPC_BOR_VOL_2_5 = 0x6, /**< 2.5V */
BKPC_BOR_VOL_2_6 = 0x7, /**< 2.6V */
BKPC_BOR_VOL_2_8 = 0x8, /**< 2.8V */
BKPC_BOR_VOL_3_0 = 0x9, /**< 3.0V */
BKPC_BOR_VOL_3_1 = 0xA, /**< 3.1V */
BKPC_BOR_VOL_3_3 = 0xB, /**< 3.3V */
BKPC_BOR_VOL_3_6 = 0xC, /**< 3.6V */
BKPC_BOR_VOL_3_7 = 0xD, /**< 3.7V */
BKPC_BOR_VOL_4_0 = 0xE, /**< 4.0V */
BKPC_BOR_VOL_4_3 = 0xF, /**< 4.3V */
} bkpc_bor_vol_t;
/**
* @brief Standby wakeup level
*/
typedef enum {
PMU_STANDBY_LEVEL_HIGH = 0x0U, /**< High level */
PMU_STANDBY_LEVEL_LOW = 0x1U, /**< Low level */
} bkpc_wakeup_level_t;
/** /**
* @} * @}
*/ */
...@@ -126,22 +120,13 @@ typedef enum ...@@ -126,22 +120,13 @@ typedef enum
((x) == BKPC_LDO_OUTPUT_1_3) || \ ((x) == BKPC_LDO_OUTPUT_1_3) || \
((x) == BKPC_LDO_OUTPUT_1_4) || \ ((x) == BKPC_LDO_OUTPUT_1_4) || \
((x) == BKPC_LDO_OUTPUT_1_5)) ((x) == BKPC_LDO_OUTPUT_1_5))
#define IS_BKPC_BOR_VOL(x) (((x) == BKPC_BOR_VOL_1_7) || \ #define IS_BKPC_WAKEUP_PORT(x) (((x) == PMU_STANDBY_PORT_SEL_PA0) || \
((x) == BKPC_BOR_VOL_2_0) || \ ((x) == PMU_STANDBY_PORT_SEL_PA1) || \
((x) == BKPC_BOR_VOL_2_1) || \ ((x) == PMU_STANDBY_PORT_SEL_PA2) || \
((x) == BKPC_BOR_VOL_2_2) || \ ((x) == PMU_STANDBY_PORT_SEL_PA3) || \
((x) == BKPC_BOR_VOL_2_3) || \ ((x) == PMU_STANDBY_PORT_SEL_NONE))
((x) == BKPC_BOR_VOL_2_4) || \ #define IS_BKPC_WAKEUP_LEVEL(x) (((x) == PMU_STANDBY_LEVEL_HIGH) || \
((x) == BKPC_BOR_VOL_2_5) || \ ((x) == PMU_STANDBY_LEVEL_LOW))
((x) == BKPC_BOR_VOL_2_6) || \
((x) == BKPC_BOR_VOL_2_8) || \
((x) == BKPC_BOR_VOL_3_0) || \
((x) == BKPC_BOR_VOL_3_1) || \
((x) == BKPC_BOR_VOL_3_3) || \
((x) == BKPC_BOR_VOL_3_6) || \
((x) == BKPC_BOR_VOL_3_7) || \
((x) == BKPC_BOR_VOL_4_0) || \
((x) == BKPC_BOR_VOL_4_3))
#define IS_BKPC_RAM_IDX(x) ((x) < 32) #define IS_BKPC_RAM_IDX(x) ((x) < 32)
/** /**
* @} * @}
...@@ -154,8 +139,8 @@ typedef enum ...@@ -154,8 +139,8 @@ typedef enum
* @{ * @{
*/ */
/* control functions */ /* control functions */
extern void ald_bkpc_standby_wakeup_config(bkpc_wakeup_port_t port, bkpc_wakeup_level_t level);
extern void ald_bkpc_ldo_config(bkpc_ldo_output_t output, type_func_t state); extern void ald_bkpc_ldo_config(bkpc_ldo_output_t output, type_func_t state);
extern void ald_bkpc_bor_config(bkpc_bor_vol_t vol, type_func_t state);
/** /**
* @} * @}
*/ */
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#define __ALD_CRC_H__ #define __ALD_CRC_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "utils.h" #include "utils.h"
...@@ -39,75 +39,69 @@ extern "C" { ...@@ -39,75 +39,69 @@ extern "C" {
/** /**
* @brief CRC mode * @brief CRC mode
*/ */
typedef enum typedef enum {
{ CRC_MODE_CCITT = 0U, /**< Ccitt */
CRC_MODE_CCITT = 0, /**< Ccitt */ CRC_MODE_8 = 1U, /**< Crc8 */
CRC_MODE_8 = 1, /**< Crc8 */ CRC_MODE_16 = 2U, /**< Crc16 */
CRC_MODE_16 = 2, /**< Crc16 */ CRC_MODE_32 = 3U, /**< Crc32 */
CRC_MODE_32 = 3, /**< Crc32 */
} crc_mode_t; } crc_mode_t;
/** /**
* @brief CRC input length * @brief CRC input length
*/ */
typedef enum typedef enum {
{ CRC_LEN_AUTO = 0U, /**< Auto */
CRC_LEN_AUTO = 0, /**< Auto */ CRC_DATASIZE_8 = 1U, /**< Byte */
CRC_DATASIZE_8 = 1, /**< Byte */ CRC_DATASIZE_16 = 2U, /**< Half word */
CRC_DATASIZE_16 = 2, /**< Half word */ CRC_DATASIZE_32 = 3U, /**< Word */
CRC_DATASIZE_32 = 3, /**< Word */
} crc_datasize_t; } crc_datasize_t;
/** /**
* @brief CRC whether write error or no * @brief CRC whether write error or no
*/ */
typedef enum typedef enum {
{ CRC_WERR_NO = 0U, /**< No error */
CRC_WERR_NO = 0, /**< No error */ CRC_WERR_ERR = 1U, /**< Error */
CRC_WERR_ERR = 1, /**< Error */
} crc_werr_t; } crc_werr_t;
/** /**
* @brief CRC state structures definition * @brief CRC state structures definition
*/ */
typedef enum typedef enum {
{ CRC_STATE_RESET = 0x0U, /**< Peripheral is not initialized */
CRC_STATE_RESET = 0x0, /**< Peripheral is not initialized */ CRC_STATE_READY = 0x1U, /**< Peripheral Initialized and ready for use */
CRC_STATE_READY = 0x1, /**< Peripheral Initialized and ready for use */ CRC_STATE_BUSY = 0x2U, /**< An internal process is ongoing */
CRC_STATE_BUSY = 0x2, /**< An internal process is ongoing */ CRC_STATE_ERROR = 0x4U, /**< Error */
CRC_STATE_ERROR = 0x4, /**< Error */
} crc_state_t; } crc_state_t;
/** /**
* @brief CRC init structure definition * @brief CRC init structure definition
*/ */
typedef struct typedef struct {
{ crc_mode_t mode; /**< CRC mode */
crc_mode_t mode; /**< CRC mode */ type_func_t data_rev; /**< CRC data reverse or no */
type_func_t data_rev; /**< CRC data reverse or no */ type_func_t data_inv; /**< CRC data inverse or no */
type_func_t data_inv; /**< CRC data inverse or no */ type_func_t chs_rev; /**< CRC check sum reverse or no */
type_func_t chs_rev; /**< CRC check sum reverse or no */ type_func_t chs_inv; /**< CRC check sum inverse or no */
type_func_t chs_inv; /**< CRC check sum inverse or no */ uint32_t seed; /**< CRC seed */
uint32_t seed; /**< CRC seed */
} crc_init_t; } crc_init_t;
/** /**
* @brief CRC Handle Structure definition * @brief CRC Handle Structure definition
*/ */
typedef struct crc_handle_s typedef struct crc_handle_s {
{ CRC_TypeDef *perh; /**< Register base address */
CRC_TypeDef *perh; /**< Register base address */ crc_init_t init; /**< CRC required parameters */
crc_init_t init; /**< CRC required parameters */ uint8_t *cal_buf; /**< The pointer of preparing buffer */
uint8_t *cal_buf; /**< The pointer of preparing buffer */ uint32_t *cal_res; /**< The pointer of result */
uint32_t *cal_res; /**< The pointer of result */
#ifdef ALD_DMA #ifdef ALD_DMA
dma_handle_t hdma; /**< CRC DMA handle parameters */ dma_handle_t hdma; /**< CRC DMA handle parameters */
#endif #endif
lock_state_t lock; /**< Locking object */ lock_state_t lock; /**< Locking object */
crc_state_t state; /**< CRC operation state */ crc_state_t state; /**< CRC operation state */
void (*cal_cplt_cbk)(struct crc_handle_s *arg); /**< Calculate completed callback */ void (*cal_cplt_cbk)(struct crc_handle_s *arg); /**< Calculate completed callback */
void (*err_cplt_cbk)(struct crc_handle_s *arg); /**< Calculate error callback */ void (*err_cplt_cbk)(struct crc_handle_s *arg); /**< Calculate error callback */
} crc_handle_t; } crc_handle_t;
/** /**
* @} * @}
...@@ -131,9 +125,9 @@ typedef struct crc_handle_s ...@@ -131,9 +125,9 @@ typedef struct crc_handle_s
*/ */
#define IS_CRC(x) ((x) == CRC) #define IS_CRC(x) ((x) == CRC)
#define IS_CRC_MODE(x) (((x) == CRC_MODE_CCITT) || \ #define IS_CRC_MODE(x) (((x) == CRC_MODE_CCITT) || \
((x) == CRC_MODE_8) || \ ((x) == CRC_MODE_8) || \
((x) == CRC_MODE_16) || \ ((x) == CRC_MODE_16) || \
((x) == CRC_MODE_32)) ((x) == CRC_MODE_32))
/** /**
* @} * @}
*/ */
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#define __ALD_CRYPT_H__ #define __ALD_CRYPT_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "utils.h" #include "utils.h"
...@@ -39,105 +39,96 @@ extern "C" { ...@@ -39,105 +39,96 @@ extern "C" {
/** /**
* @brief CRYPT encrypt or decrypt select * @brief CRYPT encrypt or decrypt select
*/ */
typedef enum typedef enum {
{ CRYPT_DECRYPT = 0U, /**< Decrypt */
CRYPT_DECRYPT = 0, /**< Decrypt */ CRYPT_ENCRYPT = 1U, /**< Encrypt */
CRYPT_ENCRYPT = 1, /**< Encrypt */
} crypt_encs_t; } crypt_encs_t;
/** /**
* @brief CRYPT mode select * @brief CRYPT mode select
*/ */
typedef enum typedef enum {
{ CRYPT_MODE_ECB = 0U, /**< ECB */
CRYPT_MODE_ECB = 0, /**< ECB */ CRYPT_MODE_CBC = 1U, /**< CBC */
CRYPT_MODE_CBC = 1, /**< CBC */ CRYPT_MODE_CTR = 2U, /**< CTR */
CRYPT_MODE_CTR = 2, /**< CTR */
} crypt_mode_t; } crypt_mode_t;
/** /**
* @brief CRYPT data type * @brief CRYPT data type
*/ */
typedef enum typedef enum {
{ CRYPT_DATA_CHANGE_NO = 0U, /**< No exchange */
CRYPT_DATA_CHANGE_NO = 0, /**< No exchange */ CRYPT_DATA_CHANGE_16 = 1U, /**< 16bit exchange */
CRYPT_DATA_CHANGE_16 = 1, /**< 16bit exchange */ CRYPT_DATA_CHANGE_8 = 2U, /**< 8bit exchange */
CRYPT_DATA_CHANGE_8 = 2, /**< 8bit exchange */ CRYPT_DATA_CHANGE_1 = 3U, /**< 1bit exchange */
CRYPT_DATA_CHANGE_1 = 3, /**< 1bit exchange */
} crypt_datatype_t; } crypt_datatype_t;
/** /**
* @brief CRYPT interrupt * @brief CRYPT interrupt
*/ */
typedef enum typedef enum {
{ CRYPT_IT_IT = 0x80U, /**< Interrupt */
CRYPT_IT_IT = 0x80, /**< Interrupt */
} crypt_it_t; } crypt_it_t;
/** /**
* @brief CRYPT interrupt flag * @brief CRYPT interrupt flag
*/ */
typedef enum typedef enum {
{ CRYPT_FLAG_AESIF = 0x1U, /**< Aes flag */
CRYPT_FLAG_AESIF = 0x1, /**< Aes flag */ CRYPT_FLAG_DONE = 0x100U, /**< Complete flag */
CRYPT_FLAG_DONE = 0x100, /**< Complete flag */
} crypt_flag_t; } crypt_flag_t;
/** /**
* @brief CRYPT state structures definition * @brief CRYPT state structures definition
*/ */
typedef enum typedef enum {
{ CRYPT_STATE_RESET = 0x0U, /**< Peripheral is not initialized */
CRYPT_STATE_RESET = 0x0, /**< Peripheral is not initialized */ CRYPT_STATE_READY = 0x1U, /**< Peripheral Initialized and ready for use */
CRYPT_STATE_READY = 0x1, /**< Peripheral Initialized and ready for use */ CRYPT_STATE_BUSY = 0x2U, /**< An internal process is ongoing */
CRYPT_STATE_BUSY = 0x2, /**< An internal process is ongoing */ CRYPT_STATE_ERROR = 0x4U, /**< Error */
CRYPT_STATE_ERROR = 0x4, /**< Error */
} crypt_state_t; } crypt_state_t;
/** /**
* @brief CRYPT data type * @brief CRYPT data type
*/ */
typedef enum typedef enum {
{ DATA_32_BIT = 0U, /**< 32 bit data,don't swap */
DATA_32_BIT = 0, /**< 32 bit data,don't swap */ DATA_16_BIT = 1U, /**< 16 bit data,swap */
DATA_16_BIT = 1, /**< 16 bit data,swap */ DATA_8_BIT = 2U, /**< 8 bit data,swap */
DATA_8_BIT = 2, /**< 8 bit data,swap */ DATA_1_BIT = 3U, /**< 1 bit data, swap */
DATA_1_BIT = 3, /**< 1 bit data, swap */
} crypt_data_t; } crypt_data_t;
/** /**
* @brief CRYPT init structure definition * @brief CRYPT init structure definition
*/ */
typedef struct typedef struct {
{ crypt_mode_t mode; /**< Crypt mode */
crypt_mode_t mode; /**< Crypt mode */ crypt_data_t type; /**< Data type select */
crypt_data_t type; /**< Data type select */
} crypt_init_t; } crypt_init_t;
/** /**
* @brief CRYPT Handle Structure definition * @brief CRYPT Handle Structure definition
*/ */
typedef struct crypt_handle_s typedef struct crypt_handle_s {
{ CRYPT_TypeDef *perh; /**< Register base address */
CRYPT_TypeDef *perh; /**< Register base address */ crypt_init_t init; /**< CRYPT required parameters */
crypt_init_t init; /**< CRYPT required parameters */
#ifdef ALD_DMA #ifdef ALD_DMA
dma_handle_t hdma_m2p; /**< CRYPT DMA handle parameters memory to crypt module */ dma_handle_t hdma_m2p; /**< CRYPT DMA handle parameters memory to crypt module */
dma_handle_t hdma_p2m; /**< CRYPT DMA handle parameters crypt module to memory */ dma_handle_t hdma_p2m; /**< CRYPT DMA handle parameters crypt module to memory */
#endif #endif
uint8_t *plain_text; /**< Pointer to plain text */ uint8_t *plain_text; /**< Pointer to plain text */
uint8_t *cipher_text; /**< Pointer to cipher text */ uint8_t *cipher_text; /**< Pointer to cipher text */
uint32_t size; /**< The size of crypt data buf */ uint32_t size; /**< The size of crypt data buf */
uint32_t count; /**< The count of crypt data buf */ uint32_t count; /**< The count of crypt data buf */
uint32_t step; /**< The step of once crypt 4(aes) */ uint32_t step; /**< The step of once crypt 4(aes) */
uint32_t dir; /**< ENCRYPT or DECRYPT */ uint32_t dir; /**< ENCRYPT or DECRYPT */
uint32_t iv[4]; /**< The iv of crypt */ uint32_t iv[4]; /**< The iv of crypt */
uint32_t key[4]; /**< The key of crypt */ uint32_t key[4]; /**< The key of crypt */
lock_state_t lock; /**< Locking object */ lock_state_t lock; /**< Locking object */
crypt_state_t state; /**< CRYPT operation state */ crypt_state_t state; /**< CRYPT operation state */
void (*crypt_cplt_cbk)(struct crypt_handle_s *arg); /**< Crypt completed callback */ void (*crypt_cplt_cbk)(struct crypt_handle_s *arg); /**< Crypt completed callback */
void (*err_cplt_cbk)(struct crypt_handle_s *arg); /**< Crypt error callback */ void (*err_cplt_cbk)(struct crypt_handle_s *arg); /**< Crypt error callback */
} crypt_handle_t; } crypt_handle_t;
/** /**
* @} * @}
...@@ -148,7 +139,7 @@ typedef struct crypt_handle_s ...@@ -148,7 +139,7 @@ typedef struct crypt_handle_s
*/ */
#define CRYPT_GO(handle) (SET_BIT((handle)->perh->CON, CRYPT_CON_GO_MSK)) #define CRYPT_GO(handle) (SET_BIT((handle)->perh->CON, CRYPT_CON_GO_MSK))
#define CRYPT_FIFOEN_ENABLE(handle) (SET_BIT((handle)->perh->CON, CRYPT_CON_FIFOEN_MSK)) #define CRYPT_FIFOEN_ENABLE(handle) (SET_BIT((handle)->perh->CON, CRYPT_CON_FIFOEN_MSK))
#define CRYPT_FIFOEN_DISABLE(handle) (CLEAR_BIT(handle)->perh->CON, CRYPT_CON_FIFOEN_MSK)) #define CRYPT_FIFOEN_DISABLE(handle) (CLEAR_BIT((handle)->perh->CON, CRYPT_CON_FIFOEN_MSK))
#define CRYPT_IVEN_ENABLE(handle) (SET_BIT((handle)->perh->CON, CRYPT_CON_IVEN_MSK)) #define CRYPT_IVEN_ENABLE(handle) (SET_BIT((handle)->perh->CON, CRYPT_CON_IVEN_MSK))
#define CRYPT_IVEN_DISABLE(handle) (CLEAR_BIT((handle)->perh->CON, CRYPT_CON_IVEN_MSK)) #define CRYPT_IVEN_DISABLE(handle) (CLEAR_BIT((handle)->perh->CON, CRYPT_CON_IVEN_MSK))
#define CRYPT_IE_ENABLE(handle) (SET_BIT((handle)->perh->CON, CRYPT_CON_IE_MSK)) #define CRYPT_IE_ENABLE(handle) (SET_BIT((handle)->perh->CON, CRYPT_CON_IE_MSK))
...@@ -156,7 +147,7 @@ typedef struct crypt_handle_s ...@@ -156,7 +147,7 @@ typedef struct crypt_handle_s
#define CRYPT_DMA_ENABLE(handle) (SET_BIT((handle)->perh->CON, CRYPT_CON_DMAEN_MSK)) #define CRYPT_DMA_ENABLE(handle) (SET_BIT((handle)->perh->CON, CRYPT_CON_DMAEN_MSK))
#define CRYPT_DMA_DISABLE(handle) (CLEAR_BIT((handle)->perh->CON, CRYPT_CON_DMAEN_MSK)) #define CRYPT_DMA_DISABLE(handle) (CLEAR_BIT((handle)->perh->CON, CRYPT_CON_DMAEN_MSK))
#define CRYPT_SETDIR(handle, dir) do {(handle)->perh->CON &= ~(0x1 << CRYPT_CON_ENCS_POS); \ #define CRYPT_SETDIR(handle, dir) do {(handle)->perh->CON &= ~(0x1 << CRYPT_CON_ENCS_POS); \
(handle)->perh->CON |= (dir << CRYPT_CON_ENCS_POS);} while (0) (handle)->perh->CON |= (dir << CRYPT_CON_ENCS_POS);} while (0)
#define CRYPT_WRITE_FIFO(handle, data) ((handle)->perh->FIFO = (data)) #define CRYPT_WRITE_FIFO(handle, data) ((handle)->perh->FIFO = (data))
#define CRYPT_READ_FIFO(handle) ((handle)->perh->FIFO) #define CRYPT_READ_FIFO(handle) ((handle)->perh->FIFO)
/** /**
...@@ -168,13 +159,13 @@ typedef struct crypt_handle_s ...@@ -168,13 +159,13 @@ typedef struct crypt_handle_s
*/ */
#define IS_CRYPT(x) ((x) == CRYPT) #define IS_CRYPT(x) ((x) == CRYPT)
#define IS_CRYPT_MODE(x) (((x) == CRYPT_MODE_ECB) || \ #define IS_CRYPT_MODE(x) (((x) == CRYPT_MODE_ECB) || \
((x) == CRYPT_MODE_CBC) || \ ((x) == CRYPT_MODE_CBC) || \
((x) == CRYPT_MODE_CTR)) ((x) == CRYPT_MODE_CTR))
#define IS_CRYPT_IT(x) ((x) == CRYPT_IT_IT) #define IS_CRYPT_IT(x) ((x) == CRYPT_IT_IT)
#define IS_CRYPT_FLAG(x) (((x) == CRYPT_FLAG_AESIF) || \ #define IS_CRYPT_FLAG(x) (((x) == CRYPT_FLAG_AESIF) || \
((x) == CRYPT_FLAG_DONE)) ((x) == CRYPT_FLAG_DONE))
#define IS_CRYPT_IV_LEN(x) (((x) == IV_2_LEN) || \ #define IS_CRYPT_IV_LEN(x) (((x) == IV_2_LEN) || \
((x) == IV_4_LEN)) ((x) == IV_4_LEN))
/** /**
* @} * @}
*/ */
...@@ -205,9 +196,9 @@ ald_status_t ald_crypt_encrypt_by_it(crypt_handle_t *hperh, uint8_t *plain_text, ...@@ -205,9 +196,9 @@ ald_status_t ald_crypt_encrypt_by_it(crypt_handle_t *hperh, uint8_t *plain_text,
ald_status_t ald_crypt_decrypt_by_it(crypt_handle_t *hperh, uint8_t *cipher_text, uint8_t *plain_text, uint32_t size); ald_status_t ald_crypt_decrypt_by_it(crypt_handle_t *hperh, uint8_t *cipher_text, uint8_t *plain_text, uint32_t size);
#ifdef ALD_DMA #ifdef ALD_DMA
ald_status_t ald_crypt_encrypt_by_dma(crypt_handle_t *hperh, uint8_t *plain_text, ald_status_t ald_crypt_encrypt_by_dma(crypt_handle_t *hperh, uint8_t *plain_text,
uint8_t *cipher_text, uint32_t size, uint8_t channel_m2p, uint8_t channel_p2m); uint8_t *cipher_text, uint32_t size, uint8_t channel_m2p, uint8_t channel_p2m);
ald_status_t ald_crypt_decrypt_by_dma(crypt_handle_t *hperh, uint8_t *cipher_text, ald_status_t ald_crypt_decrypt_by_dma(crypt_handle_t *hperh, uint8_t *cipher_text,
uint8_t *plain_text, uint32_t size, uint8_t channel_m2p, uint8_t channel_p2m); uint8_t *plain_text, uint32_t size, uint8_t channel_m2p, uint8_t channel_p2m);
#endif #endif
/** /**
* @} * @}
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#define __ALD_DBGC_H__ #define __ALD_DBGC_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "utils.h" #include "utils.h"
...@@ -41,34 +41,32 @@ extern "C" { ...@@ -41,34 +41,32 @@ extern "C" {
/** /**
* @brief Debug mode select * @brief Debug mode select
*/ */
typedef enum typedef enum {
{ DEBC_MODE_SLEEP = (1U << 0), /**< Sleep mode */
DEBC_MODE_SLEEP = (1u << 0), /**< Sleep mode */ DEBC_MODE_STOP1 = (1U << 1), /**< STOP1 mode */
DEBC_MODE_STOP1 = (1u << 1), /**< STOP1 mode */ DEBC_MODE_STOP2 = (1U << 2), /**< STOP2 mode */
DEBC_MODE_STOP2 = (1u << 2), /**< STOP2 mode */ DEBC_MODE_STANDBY = (1U << 3), /**< Standby mode */
DEBC_MODE_STANDBY = (1u << 3), /**< Standby mode */
} dbgc_mode_t; } dbgc_mode_t;
/** /**
* @brief Debug peripheral select * @brief Debug peripheral select
*/ */
typedef enum typedef enum {
{ DEBC_PERH_TIMER0 = (1U << 0), /**< AD16C4T0 */
DEBC_PERH_TIMER0 = (1u << 0), /**< AD16C4T0 */ DEBC_PERH_TIMER1 = (1U << 1), /**< BS16T0 */
DEBC_PERH_TIMER1 = (1u << 1), /**< BS16T0 */ DEBC_PERH_TIMER2 = (1U << 2), /**< GP16C2T0 */
DEBC_PERH_TIMER2 = (1u << 2), /**< GP16C2T0 */ DEBC_PERH_TIMER3 = (1U << 3), /**< GP16C2T1 */
DEBC_PERH_TIMER3 = (1u << 3), /**< GP16C2T1 */ DEBC_PERH_TIMER4 = (1U << 4), /**< BS16T1 */
DEBC_PERH_TIMER4 = (1u << 4), /**< BS16T1 */ DEBC_PERH_TIMER5 = (1U << 5), /**< BS16T2 */
DEBC_PERH_TIMER5 = (1u << 5), /**< BS16T2 */ DEBC_PERH_TIMER6 = (1U << 6), /**< GP16C4T0 */
DEBC_PERH_TIMER6 = (1u << 6), /**< GP16C4T0 */ DEBC_PERH_TIMER7 = (1U << 7), /**< BS16T3 */
DEBC_PERH_TIMER7 = (1u << 7), /**< BS16T3 */ DEBC_PERH_I2C0 = (1U << 8), /**< I2C0 SMBUS */
DEBC_PERH_I2C0 = (1u << 8), /**< I2C0 SMBUS */ DEBC_PERH_I2C1 = (1U << 9), /**< I2C1 SMBUS */
DEBC_PERH_I2C1 = (1u << 9), /**< I2C1 SMBUS */ DEBC_PERH_CAN = (1U << 12), /**< CAN */
DEBC_PERH_CAN = (1u << 12), /**< CAN */ DEBC_PERH_LPTIM0 = (1U << 0) | (1U << 16), /**< LPTIM0 */
DEBC_PERH_LPTIM0 = (1u << 0) | (1u << 16), /**< LPTIM0 */ DEBC_PERH_IWDT = (1U << 8) | (1U << 16), /**< IWDT */
DEBC_PERH_IWDT = (1u << 8) | (1u << 16), /**< IWDT */ DEBC_PERH_WWDT = (1U << 9) | (1U << 16), /**< WWDT */
DEBC_PERH_WWDT = (1u << 9) | (1u << 16), /**< WWDT */ DEBC_PERH_RTC = (1U << 10) | (1U << 16), /**< RTC */
DEBC_PERH_RTC = (1u << 10) | (1u << 16), /**< RTC */
} dbgc_perh_t; } dbgc_perh_t;
/** /**
* @} * @}
...@@ -83,7 +81,7 @@ typedef enum ...@@ -83,7 +81,7 @@ typedef enum
*/ */
__INLINE uint32_t ald_dbgc_get_rev_id(void) __INLINE uint32_t ald_dbgc_get_rev_id(void)
{ {
return (DBGC->IDCODE >> 16); return (DBGC->IDCODE >> 16);
} }
/** /**
...@@ -92,7 +90,7 @@ __INLINE uint32_t ald_dbgc_get_rev_id(void) ...@@ -92,7 +90,7 @@ __INLINE uint32_t ald_dbgc_get_rev_id(void)
*/ */
__INLINE uint32_t ald_dbgc_get_core_id(void) __INLINE uint32_t ald_dbgc_get_core_id(void)
{ {
return (DBGC->IDCODE >> 12) & 0xF; return (DBGC->IDCODE >> 12) & 0xF;
} }
/** /**
...@@ -101,7 +99,7 @@ __INLINE uint32_t ald_dbgc_get_core_id(void) ...@@ -101,7 +99,7 @@ __INLINE uint32_t ald_dbgc_get_core_id(void)
*/ */
__INLINE uint32_t ald_dbgc_get_device_id(void) __INLINE uint32_t ald_dbgc_get_device_id(void)
{ {
return DBGC->IDCODE & 0xFFF; return DBGC->IDCODE & 0xFFF;
} }
/** /**
...@@ -112,10 +110,10 @@ __INLINE uint32_t ald_dbgc_get_device_id(void) ...@@ -112,10 +110,10 @@ __INLINE uint32_t ald_dbgc_get_device_id(void)
*/ */
__INLINE void ald_dbgc_mode_config(dbgc_mode_t mode, type_func_t state) __INLINE void ald_dbgc_mode_config(dbgc_mode_t mode, type_func_t state)
{ {
if (state) if (state)
SET_BIT(DBGC->CR, mode); SET_BIT(DBGC->CR, mode);
else else
CLEAR_BIT(DBGC->CR, mode); CLEAR_BIT(DBGC->CR, mode);
} }
/** /**
...@@ -126,20 +124,18 @@ __INLINE void ald_dbgc_mode_config(dbgc_mode_t mode, type_func_t state) ...@@ -126,20 +124,18 @@ __INLINE void ald_dbgc_mode_config(dbgc_mode_t mode, type_func_t state)
*/ */
__INLINE void ald_dbgc_perh_config(dbgc_perh_t perh, type_func_t state) __INLINE void ald_dbgc_perh_config(dbgc_perh_t perh, type_func_t state)
{ {
if ((perh >> 16) & 0x1) if ((perh >> 16) & 0x1) {
{ if (state)
if (state) SET_BIT(DBGC->APB2FZ, perh);
SET_BIT(DBGC->APB2FZ, perh); else
else CLEAR_BIT(DBGC->APB2FZ, perh);
CLEAR_BIT(DBGC->APB2FZ, perh); }
} else {
else if (state)
{ SET_BIT(DBGC->APB1FZ, perh);
if (state) else
SET_BIT(DBGC->APB1FZ, perh); CLEAR_BIT(DBGC->APB1FZ, perh);
else }
CLEAR_BIT(DBGC->APB1FZ, perh);
}
} }
/** /**
* @} * @}
......
...@@ -36,21 +36,21 @@ extern "C" { ...@@ -36,21 +36,21 @@ extern "C" {
* @{ * @{
*/ */
#define FLASH_REG_UNLOCK() \ #define FLASH_REG_UNLOCK() \
do { \ do { \
if (op_cmd == OP_FLASH) { \ if (op_cmd == OP_FLASH) { \
WRITE_REG(MSC->FLASHKEY, 0x8ACE0246); \ WRITE_REG(MSC->FLASHKEY, 0x8ACE0246U); \
WRITE_REG(MSC->FLASHKEY, 0x9BDF1357); \ WRITE_REG(MSC->FLASHKEY, 0x9BDF1357U); \
} \ } \
else { \ else { \
WRITE_REG(MSC->INFOKEY, 0x7153BFD9); \ WRITE_REG(MSC->INFOKEY, 0x7153BFD9U); \
WRITE_REG(MSC->INFOKEY, 0x0642CEA8); \ WRITE_REG(MSC->INFOKEY, 0x0642CEA8U); \
} \ } \
} while (0) } while (0)
#define FLASH_REQ() (SET_BIT(MSC->FLASHCR, MSC_FLASHCR_FLASHREQ_MSK)) #define FLASH_REQ() (SET_BIT(MSC->FLASHCR, MSC_FLASHCR_FLASHREQ_MSK))
#define FLASH_REQ_FIN() (CLEAR_BIT(MSC->FLASHCR, MSC_FLASHCR_FLASHREQ_MSK)) #define FLASH_REQ_FIN() (CLEAR_BIT(MSC->FLASHCR, MSC_FLASHCR_FLASHREQ_MSK))
#define FLASH_IAP_ENABLE() (SET_BIT(MSC->FLASHCR, MSC_FLASHCR_IAPEN_MSK)) #define FLASH_IAP_ENABLE() (SET_BIT(MSC->FLASHCR, MSC_FLASHCR_IAPEN_MSK))
#define FLASH_IAP_DISABLE() (CLEAR_BIT(MSC->FLASHCR, MSC_FLASHCR_IAPEN_MSK)) #define FLASH_IAP_DISABLE() (CLEAR_BIT(MSC->FLASHCR, MSC_FLASHCR_IAPEN_MSK))
#define FLASH_BASE_ADDR 0x00000000 #define FLASH_BASE_ADDR 0x00000000U
#define FLASH_PAGE_SIZE 1024UL #define FLASH_PAGE_SIZE 1024UL
#define FLASH_WORD_SIZE 8UL #define FLASH_WORD_SIZE 8UL
#define FLASH_TOTAL_SIZE 256UL #define FLASH_TOTAL_SIZE 256UL
...@@ -67,9 +67,9 @@ extern "C" { ...@@ -67,9 +67,9 @@ extern "C" {
#define INFO_PAGE_ADDR(ADDR) ((ADDR) & (~INFO_PAGE_MASK)) #define INFO_PAGE_ADDR(ADDR) ((ADDR) & (~INFO_PAGE_MASK))
#ifdef USE_FLASH_FIFO #ifdef USE_FLASH_FIFO
#define FLASH_FIFO 1 #define FLASH_FIFO 1
#else #else
#define FLASH_FIFO 0 #define FLASH_FIFO 0
#endif #endif
/** /**
* @} * @}
...@@ -78,24 +78,22 @@ extern "C" { ...@@ -78,24 +78,22 @@ extern "C" {
/** @defgroup FLASH_Private_Types FLASH Private Types /** @defgroup FLASH_Private_Types FLASH Private Types
* @{ * @{
*/ */
typedef enum typedef enum {
{ FLASH_CMD_AE = 0x000051AEU, /**< Program area erase all */
FLASH_CMD_AE = 0x000051AE, /**< Program area erase all */ FLASH_CMD_PE = 0x00005EA1U, /**< Page erase */
FLASH_CMD_PE = 0x00005EA1, /**< Page erase */ FLASH_CMD_WP = 0x00005DA2U, /**< Word program */
FLASH_CMD_WP = 0x00005DA2, /**< Word program */ FLASH_CMD_DATAPE = 0x00005BA4U, /**< Data flash page page erase */
FLASH_CMD_DATAPE = 0x00005BA4, /**< Data flash page page erase */ FLASH_CMD_DATAWP = 0x00005AA5U, /**< Data flash word program */
FLASH_CMD_DATAWP = 0x00005AA5, /**< Data flash word program */
} flash_cmd_type; } flash_cmd_type;
typedef enum typedef enum {
{ OP_FLASH = 0U, /**< Operate Pragram area */
OP_FLASH = 0, /**< Operate Pragram area */ OP_INFO = 1U, /**< Operate info area */
OP_INFO = 1, /**< Operate info area */
} op_cmd_type; } op_cmd_type;
/** /**
* @} * @}
*/ */
/** @addtogroup Flash_Private_Functions /** @addtogroup Flash_Private_Functions
* @{ * @{
*/ */
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#define __ALD_GPIO_H__ #define __ALD_GPIO_H__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "utils.h" #include "utils.h"
...@@ -52,7 +52,7 @@ extern "C" { ...@@ -52,7 +52,7 @@ extern "C" {
#define GPIO_PIN_13 (1U << 13) #define GPIO_PIN_13 (1U << 13)
#define GPIO_PIN_14 (1U << 14) #define GPIO_PIN_14 (1U << 14)
#define GPIO_PIN_15 (1U << 15) #define GPIO_PIN_15 (1U << 15)
#define GPIO_PIN_ALL (0xFFFF) #define GPIO_PIN_ALL (0xFFFFU)
/** /**
* @} * @}
*/ */
...@@ -65,125 +65,114 @@ extern "C" { ...@@ -65,125 +65,114 @@ extern "C" {
/** /**
* @brief GPIO mode * @brief GPIO mode
*/ */
typedef enum typedef enum {
{ GPIO_MODE_CLOSE = 0x0U, /**< Digital close Analog open */
GPIO_MODE_CLOSE = 0x0, /**< Digital close Analog open */ GPIO_MODE_INPUT = 0x1U, /**< Input */
GPIO_MODE_INPUT = 0x1, /**< Input */ GPIO_MODE_OUTPUT = 0x2U, /**< Output */
GPIO_MODE_OUTPUT = 0x2, /**< Output */
} gpio_mode_t; } gpio_mode_t;
/** /**
* @brief GPIO open-drain or push-pull * @brief GPIO open-drain or push-pull
*/ */
typedef enum typedef enum {
{ GPIO_PUSH_PULL = 0x0U, /**< Push-Pull */
GPIO_PUSH_PULL = 0x0, /**< Push-Pull */ GPIO_OPEN_DRAIN = 0x2U, /**< Open-Drain. Can't output high level */
GPIO_OPEN_DRAIN = 0x2, /**< Open-Drain */ GPIO_OPEN_SOURCE = 0x3U, /**< Open-Source. Can't output low level */
GPIO_OPEN_SOURCE = 0x3, /**< Open-Source */
} gpio_odos_t; } gpio_odos_t;
/** /**
* @brief GPIO push-up or push-down * @brief GPIO push-up or push-down
*/ */
typedef enum typedef enum {
{ GPIO_FLOATING = 0x0U, /**< Floating */
GPIO_FLOATING = 0x0,/**< Floating */ GPIO_PUSH_UP = 0x1U, /**< Push-Up */
GPIO_PUSH_UP = 0x1,/**< Push-Up */ GPIO_PUSH_DOWN = 0x2U, /**< Push-Down */
GPIO_PUSH_DOWN = 0x2,/**< Push-Down */ GPIO_PUSH_UP_DOWN = 0x3U, /**< Push-Up and Push-Down */
GPIO_PUSH_UP_DOWN = 0x3,/**< Push-Up and Push-Down */
} gpio_push_t; } gpio_push_t;
/** /**
* @brief GPIO output drive * @brief GPIO output drive
*/ */
typedef enum typedef enum {
{ GPIO_OUT_DRIVE_NORMAL = 0x0U, /**< Normal current flow */
GPIO_OUT_DRIVE_NORMAL = 0x0, /**< Normal current flow */ GPIO_OUT_DRIVE_STRONG = 0x1U, /**< Strong current flow */
GPIO_OUT_DRIVE_STRONG = 0x1, /**< Strong current flow */
} gpio_out_drive_t; } gpio_out_drive_t;
/** /**
* @brief GPIO filter * @brief GPIO filter
*/ */
typedef enum typedef enum {
{ GPIO_FILTER_DISABLE = 0x0U, /**< Disable filter */
GPIO_FILTER_DISABLE = 0x0, /**< Disable filter */ GPIO_FILTER_ENABLE = 0x1U, /**< Enable filter */
GPIO_FILTER_ENABLE = 0x1, /**< Enable filter */
} gpio_filter_t; } gpio_filter_t;
/** /**
* @brief GPIO type * @brief GPIO type
*/ */
typedef enum typedef enum {
{ GPIO_TYPE_CMOS = 0x0U, /**< CMOS Type */
GPIO_TYPE_CMOS = 0x0, /**< CMOS Type */ GPIO_TYPE_TTL = 0x1U, /**< TTL Type */
GPIO_TYPE_TTL = 0x1, /**< TTL Type */
} gpio_type_t; } gpio_type_t;
/** /**
* @brief GPIO functions * @brief GPIO functions
*/ */
typedef enum typedef enum {
{ GPIO_FUNC_0 = 0U, /**< function #0 */
GPIO_FUNC_0 = 0, /**< function #0 */ GPIO_FUNC_1 = 1U, /**< function #1 */
GPIO_FUNC_1 = 1, /**< function #1 */ GPIO_FUNC_2 = 2U, /**< function #2 */
GPIO_FUNC_2 = 2, /**< function #2 */ GPIO_FUNC_3 = 3U, /**< function #3 */
GPIO_FUNC_3 = 3, /**< function #3 */ GPIO_FUNC_4 = 4U, /**< function #4 */
GPIO_FUNC_4 = 4, /**< function #4 */ GPIO_FUNC_5 = 5U, /**< function #5 */
GPIO_FUNC_5 = 5, /**< function #5 */ GPIO_FUNC_6 = 6U, /**< function #6 */
GPIO_FUNC_6 = 6, /**< function #6 */ GPIO_FUNC_7 = 7U, /**< function #7 */
GPIO_FUNC_7 = 7, /**< function #7 */
} gpio_func_t; } gpio_func_t;
/** /**
* @brief GPIO Init Structure definition * @brief GPIO Init Structure definition
*/ */
typedef struct typedef struct {
{ gpio_mode_t mode; /**< Specifies the operating mode for the selected pins.
gpio_mode_t mode; /**< Specifies the operating mode for the selected pins.
This parameter can be any value of @ref gpio_mode_t */ This parameter can be any value of @ref gpio_mode_t */
gpio_odos_t odos; /**< Specifies the Open-Drain or Push-Pull for the selected pins. gpio_odos_t odos; /**< Specifies the Open-Drain or Push-Pull for the selected pins.
This parameter can be a value of @ref gpio_odos_t */ This parameter can be a value of @ref gpio_odos_t */
gpio_push_t pupd; /**< Specifies the Pull-up or Pull-Down for the selected pins. gpio_push_t pupd; /**< Specifies the Pull-up or Pull-Down for the selected pins.
This parameter can be a value of @ref gpio_push_t */ This parameter can be a value of @ref gpio_push_t */
gpio_out_drive_t odrv; /**< Specifies the output driver for the selected pins. gpio_out_drive_t odrv; /**< Specifies the output driver for the selected pins.
This parameter can be a value of @ref gpio_out_drive_t */ This parameter can be a value of @ref gpio_out_drive_t */
gpio_filter_t flt; /**< Specifies the input filter for the selected pins. gpio_filter_t flt; /**< Specifies the input filter for the selected pins.
This parameter can be a value of @ref gpio_filter_t */ This parameter can be a value of @ref gpio_filter_t */
gpio_type_t type; /**< Specifies the type for the selected pins. gpio_type_t type; /**< Specifies the type for the selected pins.
This parameter can be a value of @ref gpio_type_t */ This parameter can be a value of @ref gpio_type_t */
gpio_func_t func; /**< Specifies the function for the selected pins. gpio_func_t func; /**< Specifies the function for the selected pins.
This parameter can be a value of @ref gpio_func_t */ This parameter can be a value of @ref gpio_func_t */
} gpio_init_t; } gpio_init_t;
/** /**
* @brief EXTI trigger style * @brief EXTI trigger style
*/ */
typedef enum typedef enum {
{ EXTI_TRIGGER_RISING_EDGE = 0U, /**< Rising edge trigger */
EXTI_TRIGGER_RISING_EDGE = 0, /**< Rising edge trigger */ EXTI_TRIGGER_TRAILING_EDGE = 1U, /**< Trailing edge trigger */
EXTI_TRIGGER_TRAILING_EDGE = 1, /**< Trailing edge trigger */ EXTI_TRIGGER_BOTH_EDGE = 2U, /**< Rising and trailing edge trigger */
EXTI_TRIGGER_BOTH_EDGE = 2, /**< Rising and trailing edge trigger */
} exti_trigger_style_t; } exti_trigger_style_t;
/** /**
* @brief EXTI filter clock select * @brief EXTI filter clock select
*/ */
typedef enum typedef enum {
{ EXTI_FILTER_CLOCK_10K = 0U, /**< cks = 10KHz */
EXTI_FILTER_CLOCK_10K = 0, /**< cks = 10KHz */ EXTI_FILTER_CLOCK_32K = 1U, /**< cks = 32KHz */
EXTI_FILTER_CLOCK_32K = 1, /**< cks = 32KHz */
} exti_filter_clock_t; } exti_filter_clock_t;
/** /**
* @brief EXTI Init Structure definition * @brief EXTI Init Structure definition
*/ */
typedef struct typedef struct {
{ type_func_t filter; /**< Enable filter. */
type_func_t filter; /**< Enable filter. */ exti_filter_clock_t cks; /**< Filter clock select. */
exti_filter_clock_t cks; /**< Filter clock select. */ uint8_t filter_time; /**< Filter duration */
uint8_t filter_time; /**< Filter duration */
} exti_init_t; } exti_init_t;
/** /**
* @} * @}
...@@ -193,37 +182,37 @@ typedef struct ...@@ -193,37 +182,37 @@ typedef struct
* @defgroup GPIO_Private_Macros GPIO Private Macros * @defgroup GPIO_Private_Macros GPIO Private Macros
* @{ * @{
*/ */
#define PIN_MASK 0xFFFF #define PIN_MASK 0xFFFFU
#define UNLOCK_KEY 0x55AA #define UNLOCK_KEY 0x55AAU
#define IS_GPIO_PIN(x) ((((x) & (uint16_t)0x00) == 0) && ((x) != (uint16_t)0x0)) #define IS_GPIO_PIN(x) ((((x) & (uint16_t)0x00) == 0) && ((x) != (uint16_t)0x0))
#define IS_GPIO_PORT(GPIOx) ((GPIOx == GPIOA) || \ #define IS_GPIO_PORT(GPIOx) ((GPIOx == GPIOA) || \
(GPIOx == GPIOB) || \ (GPIOx == GPIOB) || \
(GPIOx == GPIOC) || \ (GPIOx == GPIOC) || \
(GPIOx == GPIOD) || \ (GPIOx == GPIOD) || \
(GPIOx == GPIOE) || \ (GPIOx == GPIOE) || \
(GPIOx == GPIOF) || \ (GPIOx == GPIOF) || \
(GPIOx == GPIOG) || \ (GPIOx == GPIOG) || \
(GPIOx == GPIOH)) (GPIOx == GPIOH))
#define IS_GPIO_MODE(x) (((x) == GPIO_MODE_CLOSE) || \ #define IS_GPIO_MODE(x) (((x) == GPIO_MODE_CLOSE) || \
((x) == GPIO_MODE_INPUT) || \ ((x) == GPIO_MODE_INPUT) || \
((x) == GPIO_MODE_OUTPUT)) ((x) == GPIO_MODE_OUTPUT))
#define IS_GPIO_ODOS(x) (((x) == GPIO_PUSH_PULL) || \ #define IS_GPIO_ODOS(x) (((x) == GPIO_PUSH_PULL) || \
((x) == GPIO_OPEN_DRAIN) || \ ((x) == GPIO_OPEN_DRAIN) || \
((x) == GPIO_OPEN_SOURCE)) ((x) == GPIO_OPEN_SOURCE))
#define IS_GPIO_PUPD(x) (((x) == GPIO_FLOATING) || \ #define IS_GPIO_PUPD(x) (((x) == GPIO_FLOATING) || \
((x) == GPIO_PUSH_UP) || \ ((x) == GPIO_PUSH_UP) || \
((x) == GPIO_PUSH_DOWN) || \ ((x) == GPIO_PUSH_DOWN) || \
((x) == GPIO_PUSH_UP_DOWN)) ((x) == GPIO_PUSH_UP_DOWN))
#define IS_GPIO_ODRV(x) (((x) == GPIO_OUT_DRIVE_NORMAL) || \ #define IS_GPIO_ODRV(x) (((x) == GPIO_OUT_DRIVE_NORMAL) || \
((x) == GPIO_OUT_DRIVE_STRONG)) ((x) == GPIO_OUT_DRIVE_STRONG))
#define IS_GPIO_FLT(x) (((x) == GPIO_FILTER_DISABLE) || \ #define IS_GPIO_FLT(x) (((x) == GPIO_FILTER_DISABLE) || \
((x) == GPIO_FILTER_ENABLE)) ((x) == GPIO_FILTER_ENABLE))
#define IS_GPIO_TYPE(x) (((x) == GPIO_TYPE_TTL) || \ #define IS_GPIO_TYPE(x) (((x) == GPIO_TYPE_TTL) || \
((x) == GPIO_TYPE_CMOS)) ((x) == GPIO_TYPE_CMOS))
#define IS_TRIGGER_STYLE(x) (((x) == EXTI_TRIGGER_RISING_EDGE) || \ #define IS_TRIGGER_STYLE(x) (((x) == EXTI_TRIGGER_RISING_EDGE) || \
((x) == EXTI_TRIGGER_TRAILING_EDGE) || \ ((x) == EXTI_TRIGGER_TRAILING_EDGE) || \
((x) == EXTI_TRIGGER_BOTH_EDGE)) ((x) == EXTI_TRIGGER_BOTH_EDGE))
#define IS_EXTI_FLTCKS_TYPE(x) (((x) == EXTI_FILTER_CLOCK_10K) || \ #define IS_EXTI_FLTCKS_TYPE(x) (((x) == EXTI_FILTER_CLOCK_10K) || \
((x) == EXTI_FILTER_CLOCK_32K)) ((x) == EXTI_FILTER_CLOCK_32K))
#define IS_GPIO_FUNC(x) ((x) <= 7) #define IS_GPIO_FUNC(x) ((x) <= 7)
......
...@@ -36,10 +36,10 @@ extern "C" { ...@@ -36,10 +36,10 @@ extern "C" {
* @defgroup IAP_Private_Macros IAP Private Macros * @defgroup IAP_Private_Macros IAP Private Macros
* @{ * @{
*/ */
#define IAP_WSP_ADDR 0x10000000 #define IAP_WSP_ADDR 0x10000000U
#define IAP_PE_ADDR 0x10000004 #define IAP_PE_ADDR 0x10000004U
#define IAP_WP_ADDR 0x10000008 #define IAP_WP_ADDR 0x10000008U
#define IAP_DWP_ADDR 0x1000000c #define IAP_DWP_ADDR 0x1000000cU
/** /**
* @} * @}
*/ */
......
...@@ -38,12 +38,11 @@ extern "C" { ...@@ -38,12 +38,11 @@ extern "C" {
/** /**
* @brief Wwdt no dog window * @brief Wwdt no dog window
*/ */
typedef enum typedef enum {
{ WWDT_WIN_25 = 0x0U, /**< No dog window size: 25% */
WWDT_WIN_25 = 0x0, /**< No dog window size: 25% */ WWDT_WIN_50 = 0x1U, /**< No dog window size: 50% */
WWDT_WIN_50 = 0x1, /**< No dog window size: 50% */ WWDT_WIN_75 = 0x2U, /**< No dog window size: 75% */
WWDT_WIN_75 = 0x2, /**< No dog window size: 75% */ WWDT_WIN_00 = 0x3U, /**< No dog window size: 0% */
WWDT_WIN_00 = 0x3, /**< No dog window size: 0% */
} wwdt_win_t; } wwdt_win_t;
/** /**
...@@ -54,10 +53,10 @@ typedef enum ...@@ -54,10 +53,10 @@ typedef enum
* @defgroup WDT_Private_Macros WDT Private Macros * @defgroup WDT_Private_Macros WDT Private Macros
* @{ * @{
*/ */
#define WWDT_UNLOCK() {WRITE_REG(WWDT->LOCK, 0x1ACCE551);} #define WWDT_UNLOCK() {WRITE_REG(WWDT->LOCK, 0x1ACCE551U);}
#define WWDT_LOCK() {WRITE_REG(WWDT->LOCK, 0xFFFFFFFF);} #define WWDT_LOCK() {WRITE_REG(WWDT->LOCK, 0xFFFFFFFFU);}
#define IWDT_UNLOCK() {WRITE_REG(IWDT->LOCK, 0x1ACCE551);} #define IWDT_UNLOCK() {WRITE_REG(IWDT->LOCK, 0x1ACCE551U);}
#define IWDT_LOCK() {WRITE_REG(IWDT->LOCK, 0xFFFFFFFF);} #define IWDT_LOCK() {WRITE_REG(IWDT->LOCK, 0xFFFFFFFFU);}
/** /**
* @} * @}
...@@ -72,7 +71,7 @@ typedef enum ...@@ -72,7 +71,7 @@ typedef enum
(x == WWDT_WIN_75) || \ (x == WWDT_WIN_75) || \
(x == WWDT_WIN_00)) (x == WWDT_WIN_00))
#define IS_FUNC_STATE(x) (((x) == DISABLE) || \ #define IS_FUNC_STATE(x) (((x) == DISABLE) || \
((x) == ENABLE)) ((x) == ENABLE))
/** /**
* @} * @}
*/ */
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册