format es32f06543

This commit is contained in:
Meco Man 2021-10-09 15:33:43 -04:00
parent ee27b0cf3e
commit 421867f49e
47 changed files with 2757 additions and 4166 deletions

View File

@ -0,0 +1,4 @@
# files format check exclude path, please follow the instructions below to modify;
dir_path:
- libraries

View File

@ -23,30 +23,30 @@
#ifndef __ES_CONF_INFO_ADC_H__
#define __ES_CONF_INFO_ADC_H__
#include "es_conf_info_map.h"
#include <ald_adc.h>
#define ES_C_ADC_CLK_DIV_1 ADC_CKDIV_1
#define ES_C_ADC_CLK_DIV_1 ADC_CKDIV_1
#define ES_C_ADC_CLK_DIV_2 ADC_CKDIV_2
#define ES_C_ADC_CLK_DIV_4 ADC_CKDIV_4
#define ES_C_ADC_CLK_DIV_8 ADC_CKDIV_8
#define ES_C_ADC_CLK_DIV_16 ADC_CKDIV_16
#define ES_C_ADC_CLK_DIV_32 ADC_CKDIV_32
#define ES_C_ADC_CLK_DIV_32 ADC_CKDIV_32
#define ES_C_ADC_CLK_DIV_64 ADC_CKDIV_64
#define ES_C_ADC_CLK_DIV_128 ADC_CKDIV_128
#define ES_C_ADC_ALIGN_RIGHT ADC_DATAALIGN_RIGHT
#define ES_C_ADC_ALIGN_RIGHT ADC_DATAALIGN_RIGHT
#define ES_C_ADC_ALIGN_LEFT ADC_DATAALIGN_LEFT
#define ES_C_ADC_CONV_BIT_6 ADC_CONV_BIT_6
#define ES_C_ADC_CONV_BIT_6 ADC_CONV_BIT_6
#define ES_C_ADC_CONV_BIT_8 ADC_CONV_BIT_8
#define ES_C_ADC_CONV_BIT_10 ADC_CONV_BIT_10
#define ES_C_ADC_CONV_BIT_12 ADC_CONV_BIT_12
#define ES_C_ADC_SAMPLE_TIME_1 ADC_SAMPLETIME_1
#define ES_C_ADC_SAMPLE_TIME_1 ADC_SAMPLETIME_1
#define ES_C_ADC_SAMPLE_TIME_2 ADC_SAMPLETIME_2
#define ES_C_ADC_SAMPLE_TIME_4 ADC_SAMPLETIME_4
#define ES_C_ADC_SAMPLE_TIME_15 ADC_SAMPLETIME_15
@ -56,41 +56,41 @@
/* codes_main */
#define ES_ADC0_ALIGN ES_C_ADC_ALIGN_RIGHT
#define ES_ADC1_ALIGN ES_C_ADC_ALIGN_RIGHT
#define ES_ADC1_DATA_BIT ES_C_ADC_CONV_BIT_12
#define ES_ADC0_ALIGN ES_C_ADC_ALIGN_RIGHT
#define ES_ADC1_ALIGN ES_C_ADC_ALIGN_RIGHT
#define ES_ADC1_DATA_BIT ES_C_ADC_CONV_BIT_12
#define ES_ADC0_DATA_BIT ES_C_ADC_CONV_BIT_12
#ifndef ES_DEVICE_NAME_ADC0
#define ES_DEVICE_NAME_ADC0 "adc0"
#endif
#endif
#ifndef ES_DEVICE_NAME_ADC1
#define ES_DEVICE_NAME_ADC1 "adc1"
#endif
#ifndef ES_ADC0_CLK_DIV
#define ES_ADC0_CLK_DIV ES_C_ADC_CLK_DIV_128
#endif
#ifndef ES_ADC0_ALIGN
#ifndef ES_ADC0_CLK_DIV
#define ES_ADC0_CLK_DIV ES_C_ADC_CLK_DIV_128
#endif
#ifndef ES_ADC0_ALIGN
#define ES_ADC0_ALIGN ES_C_ADC_ALIGN_RIGHT
#endif
#ifndef ES_ADC0_DATA_BIT
#ifndef ES_ADC0_DATA_BIT
#define ES_ADC0_DATA_BIT ES_C_ADC_CONV_BIT_12
#endif
#ifndef ES_ADC0_NCH_SAMPLETIME
#ifndef ES_ADC0_NCH_SAMPLETIME
#define ES_ADC0_NCH_SAMPLETIME ES_C_ADC_SAMPLE_TIME_4
#endif
#ifndef ES_ADC1_CLK_DIV
#define ES_ADC1_CLK_DIV ES_C_ADC_CLK_DIV_128
#endif
#ifndef ES_ADC1_ALIGN
#ifndef ES_ADC1_CLK_DIV
#define ES_ADC1_CLK_DIV ES_C_ADC_CLK_DIV_128
#endif
#ifndef ES_ADC1_ALIGN
#define ES_ADC1_ALIGN ES_C_ADC_ALIGN_RIGHT
#endif
#ifndef ES_ADC1_DATA_BIT
#ifndef ES_ADC1_DATA_BIT
#define ES_ADC1_DATA_BIT ES_C_ADC_CONV_BIT_12
#endif
#ifndef ES_ADC1_NCH_SAMPLETIME
#ifndef ES_ADC1_NCH_SAMPLETIME
#define ES_ADC1_NCH_SAMPLETIME ES_C_ADC_SAMPLE_TIME_4
#endif

View File

@ -32,11 +32,11 @@
/*默认的CAN硬件过滤器的编号 0 */
#define ES_C_CAN_DEFAULT_FILTER_NUMBER 0
/*硬件过滤器,过滤帧类型*/
/*硬件过滤器,过滤帧类型*/
#define ES_C_CAN_FILTER_FRAME_TYPE 0
#define ES_C_CAN_SJW_NUM_1 CAN_SJW_1
#define ES_C_CAN_SJW_NUM_1 CAN_SJW_1
#define ES_C_CAN_SJW_NUM_2 CAN_SJW_2
#define ES_C_CAN_SJW_NUM_3 CAN_SJW_3
#define ES_C_CAN_SJW_NUM_4 CAN_SJW_4
@ -44,7 +44,7 @@
/* CAN 配置 */
/* codes_main */
@ -55,7 +55,7 @@
#ifndef ES_CAN0_AUTO_BAN_RE_T
#define ES_CAN0_AUTO_BAN_RE_T ES_C_ENABLE
#endif
#endif
#ifndef ES_CAN0_SPEED
#define ES_CAN0_SPEED 1000000
#endif

View File

@ -25,7 +25,7 @@
#define __ES_CONF_INFO_CMU_H__
#include <ald_cmu.h>
#include <ald_cmu.h>
/* 时钟树 配置 */
@ -33,19 +33,19 @@
#define ES_C_MUL_9 CMU_PLL1_OUTPUT_36M
#define ES_C_MUL_12 CMU_PLL1_OUTPUT_48M
#define ES_C_DIV_1 CMU_DIV_1
#define ES_C_DIV_2 CMU_DIV_2
#define ES_C_DIV_4 CMU_DIV_4
#define ES_C_DIV_8 CMU_DIV_8
#define ES_C_DIV_16 CMU_DIV_16
#define ES_C_DIV_32 CMU_DIV_32
#define ES_C_DIV_64 CMU_DIV_64
#define ES_C_DIV_128 CMU_DIV_128
#define ES_C_DIV_256 CMU_DIV_256
#define ES_C_DIV_512 CMU_DIV_512
#define ES_C_DIV_1024 CMU_DIV_1024
#define ES_C_DIV_2048 CMU_DIV_2048
#define ES_C_DIV_4096 CMU_DIV_4096
#define ES_C_DIV_1 CMU_DIV_1
#define ES_C_DIV_2 CMU_DIV_2
#define ES_C_DIV_4 CMU_DIV_4
#define ES_C_DIV_8 CMU_DIV_8
#define ES_C_DIV_16 CMU_DIV_16
#define ES_C_DIV_32 CMU_DIV_32
#define ES_C_DIV_64 CMU_DIV_64
#define ES_C_DIV_128 CMU_DIV_128
#define ES_C_DIV_256 CMU_DIV_256
#define ES_C_DIV_512 CMU_DIV_512
#define ES_C_DIV_1024 CMU_DIV_1024
#define ES_C_DIV_2048 CMU_DIV_2048
#define ES_C_DIV_4096 CMU_DIV_4096
#define ES_C_HOSC_DIV_1 CMU_PLL1_INPUT_HOSC
#define ES_C_HOSC_DIV_2 CMU_PLL1_INPUT_HOSC_2

View File

@ -33,29 +33,29 @@
/* GPIO 配置 */
typedef struct {
uint8_t pin;
uint8_t pin_mode;
uint8_t pin_level;
uint8_t irq_en;
uint8_t irq_mode;
void (*callback)(void *arg);
uint8_t pin;
uint8_t pin_mode;
uint8_t pin_level;
uint8_t irq_en;
uint8_t irq_mode;
void (*callback)(void *arg);
} gpio_conf_t;
/*参数的定义*/
#define ES_C_GPIO_LEVEL_HIGH PIN_HIGH
#define ES_C_GPIO_LEVEL_HIGH PIN_HIGH
#define ES_C_GPIO_LEVEL_LOW PIN_LOW
#define ES_C_GPIO_MODE_OUTPUT PIN_MODE_OUTPUT
#define ES_C_GPIO_MODE_INPUT PIN_MODE_INPUT
#define ES_C_GPIO_MODE_INPUT_PULLUP PIN_MODE_INPUT_PULLUP
#define ES_C_GPIO_MODE_INPUT_PULLDOWN PIN_MODE_INPUT_PULLDOWN
#define ES_C_GPIO_MODE_OUTPUT_OD PIN_MODE_OUTPUT_OD
#define ES_C_GPIO_MODE_OUTPUT PIN_MODE_OUTPUT
#define ES_C_GPIO_MODE_INPUT PIN_MODE_INPUT
#define ES_C_GPIO_MODE_INPUT_PULLUP PIN_MODE_INPUT_PULLUP
#define ES_C_GPIO_MODE_INPUT_PULLDOWN PIN_MODE_INPUT_PULLDOWN
#define ES_C_GPIO_MODE_OUTPUT_OD PIN_MODE_OUTPUT_OD
#define ES_C_GPIO_IRQ_ENABLE PIN_IRQ_ENABLE
#define ES_C_GPIO_IRQ_ENABLE PIN_IRQ_ENABLE
#define ES_C_GPIO_IRQ_DISABLE PIN_IRQ_DISABLE
#define ES_C_GPIO_IRQ_MODE_FALL PIN_IRQ_MODE_FALLING
#define ES_C_GPIO_IRQ_MODE_FALL PIN_IRQ_MODE_FALLING
#define ES_C_GPIO_IRQ_MODE_RISE PIN_IRQ_MODE_RISING
#define ES_C_GPIO_IRQ_MODE_R_F PIN_IRQ_MODE_RISING_FALLING
@ -75,7 +75,7 @@ typedef struct {
/*GPIO外部中断回调函数控制需要补充是否中断*/
#if 11111
#ifndef ES_INIT_GPIO_A_0_IRQ_EN
#define ES_INIT_GPIO_A_0_IRQ_EN ES_C_GPIO_IRQ_DISABLE
#endif
@ -682,67 +682,67 @@ typedef struct {
#if 11111
#ifdef ES_CONF_EXTI_IRQ_0
void irq_pin0_callback(void* arg);
void irq_pin0_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_1
void irq_pin1_callback(void* arg);
#endif
void irq_pin1_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_2
void irq_pin2_callback(void* arg);
void irq_pin2_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_3
void irq_pin3_callback(void* arg);
void irq_pin3_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_4
void irq_pin4_callback(void* arg);
void irq_pin4_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_5
void irq_pin5_callback(void* arg);
#endif
void irq_pin5_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_6
void irq_pin6_callback(void* arg);
void irq_pin6_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_7
void irq_pin7_callback(void* arg);
void irq_pin7_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_8
void irq_pin8_callback(void* arg);
void irq_pin8_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_9
void irq_pin9_callback(void* arg);
#endif
void irq_pin9_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_10
void irq_pin10_callback(void* arg);
void irq_pin10_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_11
void irq_pin11_callback(void* arg);
void irq_pin11_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_12
void irq_pin12_callback(void* arg);
void irq_pin12_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_13
void irq_pin13_callback(void* arg);
#endif
void irq_pin13_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_14
void irq_pin14_callback(void* arg);
void irq_pin14_callback(void* arg);
#endif
#ifdef ES_CONF_EXTI_IRQ_15
void irq_pin15_callback(void* arg);
void irq_pin15_callback(void* arg);
#endif
@ -783,7 +783,7 @@ void irq_pin15_callback(void* arg);
defined(ES_INIT_PIN_GPIO_H_0) || defined(ES_INIT_PIN_GPIO_H_1) || defined(ES_INIT_PIN_GPIO_H_2) || defined(ES_INIT_PIN_GPIO_H_3) || \
defined(ES_INIT_PIN_GPIO_H_4) || defined(ES_INIT_PIN_GPIO_H_5) || defined(ES_INIT_PIN_GPIO_H_6) || defined(ES_INIT_PIN_GPIO_H_7) || \
defined(ES_INIT_PIN_GPIO_H_8) || defined(ES_INIT_PIN_GPIO_H_9) || defined(ES_INIT_PIN_GPIO_H_10) || defined(ES_INIT_PIN_GPIO_H_11) || \
defined(ES_INIT_PIN_GPIO_H_12) || defined(ES_INIT_PIN_GPIO_H_13) || defined(ES_INIT_PIN_GPIO_H_14) || defined(ES_INIT_PIN_GPIO_H_15)
defined(ES_INIT_PIN_GPIO_H_12) || defined(ES_INIT_PIN_GPIO_H_13) || defined(ES_INIT_PIN_GPIO_H_14) || defined(ES_INIT_PIN_GPIO_H_15)
#define ES_INIT_GPIOS
@ -792,9 +792,9 @@ void irq_pin15_callback(void* arg);
#ifdef ES_INIT_GPIOS
static gpio_conf_t gpio_conf_all[] =
static gpio_conf_t gpio_conf_all[] =
{
#ifdef ES_INIT_PIN_GPIO_A_0
{
@ -5147,12 +5147,12 @@ static gpio_conf_t gpio_conf_all[] =
#endif
};
#endif
};
#endif
#endif

View File

@ -27,7 +27,7 @@
#include <ald_cmu.h>
#include <ald_timer.h>
#define ES_C_HWTIMER_MODE_UP HWTIMER_CNTMODE_UP
#define ES_C_HWTIMER_MODE_UP HWTIMER_CNTMODE_UP
#define ES_C_HWTIMER_MODE_DOWN HWTIMER_CNTMODE_DW
/* HWTIMER 配置 */
@ -37,35 +37,35 @@
#ifndef ES_AD16C4T0_HWTIMER_MODE
#define ES_AD16C4T0_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#endif
#define ES_AD16C4T0_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#endif
#ifndef ES_GP16C4T0_HWTIMER_MODE
#define ES_GP16C4T0_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#define ES_GP16C4T0_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#endif
#ifndef ES_GP16C2T0_HWTIMER_MODE
#define ES_GP16C2T0_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#define ES_GP16C2T0_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#endif
#ifndef ES_GP1624T1_HWTIMER_MODE
#define ES_GP16C2T1_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#define ES_GP16C2T1_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#endif
#ifndef ES_BS16T0_HWTIMER_MODE
#define ES_BS16T0_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#define ES_BS16T0_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#endif
#ifndef ES_BS16T1_HWTIMER_MODE
#define ES_BS16T1_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#define ES_BS16T1_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#endif
#ifndef ES_BS16T2_HWTIMER_MODE
#define ES_BS16T2_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#define ES_BS16T2_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#endif
#ifndef ES_BS16T3_HWTIMER_MODE
#define ES_BS16T3_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#define ES_BS16T3_HWTIMER_MODE ES_C_HWTIMER_MODE_UP
#endif
#define ES_AD16C4T0_HWTIMER_PRES 1
#define ES_AD16C4T0_HWTIMER_PRES 1
#define ES_GP16C4T0_HWTIMER_PRES 1
#define ES_GP16C2T0_HWTIMER_PRES 1
#define ES_GP16C2T1_HWTIMER_PRES 1
@ -76,28 +76,28 @@
#ifndef ES_DEVICE_NAME_AD16C4T0_HWTIMER
#define ES_DEVICE_NAME_AD16C4T0_HWTIMER "timer0"
#endif
#endif
#ifndef ES_DEVICE_NAME_GP16C4T0_HWTIMER
#define ES_DEVICE_NAME_GP16C4T0_HWTIMER "timer1"
#endif
#endif
#ifndef ES_DEVICE_NAME_GP16C2T0_HWTIMER
#define ES_DEVICE_NAME_GP16C2T0_HWTIMER "timer2"
#endif
#endif
#ifndef ES_DEVICE_NAME_GP16C2T1_HWTIMER
#define ES_DEVICE_NAME_GP16C2T1_HWTIMER "timer3"
#endif
#endif
#ifndef ES_DEVICE_NAME_BS16T0_HWTIMER
#define ES_DEVICE_NAME_BS16T0_HWTIMER "timer4"
#endif
#endif
#ifndef ES_DEVICE_NAME_BS16T1_HWTIMER
#define ES_DEVICE_NAME_BS16T1_HWTIMER "timer5"
#endif
#endif
#ifndef ES_DEVICE_NAME_BS16T2_HWTIMER
#define ES_DEVICE_NAME_BS16T2_HWTIMER "timer6"
#endif
#endif
#ifndef ES_DEVICE_NAME_BS16T3_HWTIMER
#define ES_DEVICE_NAME_BS16T3_HWTIMER "timer7"
#endif
#endif
#endif

View File

@ -29,35 +29,35 @@
#include <ald_gpio.h>
#include <rtdbg.h>
#define ES_C_I2C_STRETCH I2C_NOSTRETCH_DISABLE
#define ES_C_I2C_STRETCH I2C_NOSTRETCH_DISABLE
#define ES_C_I2C_NO_STRETCH I2C_NOSTRETCH_ENABLE
#define ES_C_I2C_GENERALCALL I2C_GENERALCALL_ENABLE
#define ES_C_I2C_NO_GENERALCALL I2C_GENERALCALL_DISABLE
#define ES_C_I2C_ADDR_7_MODE I2C_ADDR_7BIT
#define ES_C_I2C_ADDR_7_MODE I2C_ADDR_7BIT
#define ES_C_I2C_ADDR_10_MODE I2C_ADDR_10BIT
/* I2C 配置 */
/* codes_main */
#ifndef ES_DEVICE_NAME_I2C0
#define ES_DEVICE_NAME_I2C0 "i2c0"
#endif
#endif
#ifndef ES_DEVICE_NAME_I2C1
#define ES_DEVICE_NAME_I2C1 "i2c1"
#endif
#endif
#ifndef ES_I2C0_CLK_SPEED
#define ES_I2C0_CLK_SPEED 100000
#endif
@ -70,8 +70,8 @@
#ifndef ES_I2C0_STRETCH
#define ES_I2C0_STRETCH ES_C_I2C_STRETCH
#endif
#ifndef ES_I2C0_ADDR_MODE
#define ES_I2C0_ADDR_MODE ES_C_I2C_ADDR_7_MODE
#ifndef ES_I2C0_ADDR_MODE
#define ES_I2C0_ADDR_MODE ES_C_I2C_ADDR_7_MODE
#endif
#ifndef ES_I2C1_CLK_SPEED
@ -85,11 +85,11 @@
#endif
#ifndef ES_I2C1_STRETCH
#define ES_I2C1_STRETCH ES_C_I2C_STRETCH
#endif
#ifndef ES_I2C1_ADDR_MODE
#define ES_I2C1_ADDR_MODE ES_C_I2C_ADDR_7_MODE
#endif
#ifndef ES_I2C1_ADDR_MODE
#define ES_I2C1_ADDR_MODE ES_C_I2C_ADDR_7_MODE
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -23,10 +23,10 @@
#include <ald_cmu.h>
#include <ald_pmu.h>
#define ES_PMU_SAVE_LOAD_UART
#define ES_PMU_SAVE_LOAD_UART
/* PM 配置 */
#endif

View File

@ -37,7 +37,7 @@
#define ES_C_PWM_OC_MODE_PWM2 TIMER_OC_MODE_PWM2
/* PWM 配置 */
@ -50,23 +50,23 @@
#ifndef ES_PWM_OC_POLARITY
#define ES_PWM_OC_POLARITY ES_C_PWM_OC_POL_HIGH
#endif
#ifndef ES_PWM_OC_MODE
#endif
#ifndef ES_PWM_OC_MODE
#define ES_PWM_OC_MODE ES_C_PWM_OC_MODE_PWM2
#endif
#ifndef ES_DEVICE_NAME_AD16C4T0_PWM
#define ES_DEVICE_NAME_AD16C4T0_PWM "pwm0"
#endif
#endif
#ifndef ES_DEVICE_NAME_GP16C4T0_PWM
#define ES_DEVICE_NAME_GP16C4T0_PWM "pwm1"
#endif
#endif
#ifndef ES_DEVICE_NAME_GP16C2T0_PWM
#define ES_DEVICE_NAME_GP16C2T0_PWM "pwm2"
#endif
#endif
#ifndef ES_DEVICE_NAME_GP16C2T1_PWM
#define ES_DEVICE_NAME_GP16C2T1_PWM "pwm3"
#endif
#endif
#endif

View File

@ -38,6 +38,6 @@
#ifndef ES_DEVICE_NAME_RTC
#define ES_DEVICE_NAME_RTC "rtc"
#endif
#endif
#endif

View File

@ -27,7 +27,7 @@
#define ES_C_ENABLE 1
#define ES_C_DISABLE 0
/* codes_main */
//#define ES_USE_ASSERT ES_C_ENABLE
@ -37,7 +37,7 @@
#endif
#if ES_USE_ASSERT
#if ES_USE_ASSERT
#define USE_ASSERT
#endif

View File

@ -42,7 +42,7 @@
_CONF_.max_hz = ES_SPI##_I_##_MAX_HZ; \
}while(0)
// spi_config.mode &= ~RT_SPI_SLAVE; /* 主机模式 */
// spi_config.mode &= ~RT_SPI_3WIRE; /* 4线双向传输 */
// spi_config.mode |= RT_SPI_CPHA; /* 第二边沿采样 */
@ -52,14 +52,14 @@
// spi_config.data_width = 8; /* 数据长度8 */
// spi_config.max_hz = 2000000; /* 最快时钟频率 */
#define ES_C_SPI_CLK_POL_HIGH RT_SPI_CPOL
#define ES_C_SPI_CLK_POL_LOW !RT_SPI_CPOL
#define ES_C_SPI_CLK_PHA_FIRST !RT_SPI_CPHA
#define ES_C_SPI_CLK_POL_HIGH RT_SPI_CPOL
#define ES_C_SPI_CLK_POL_LOW !RT_SPI_CPOL
#define ES_C_SPI_CLK_PHA_FIRST !RT_SPI_CPHA
#define ES_C_SPI_CLK_PHA_SECOND RT_SPI_CPHA
#define ES_C_SPI_MSB RT_SPI_MSB
#define ES_C_SPI_LSB RT_SPI_LSB
#define ES_C_SPI_MSB RT_SPI_MSB
#define ES_C_SPI_LSB RT_SPI_LSB
#define ES_C_SPI_CS_LOW_LEVEL 0
#define ES_C_SPI_CS_HIGH_LEVEL 1
@ -69,64 +69,64 @@
#ifndef ES_DEVICE_NAME_SPI0_BUS
#define ES_DEVICE_NAME_SPI0_BUS "spi0"
#endif
#endif
#ifndef ES_DEVICE_NAME_SPI0_DEV0
#define ES_DEVICE_NAME_SPI0_DEV0 "spi00"
#endif
#endif
#ifndef ES_DEVICE_NAME_SPI1_BUS
#define ES_DEVICE_NAME_SPI1_BUS "spi1"
#endif
#endif
#ifndef ES_DEVICE_NAME_SPI1_DEV0
#define ES_DEVICE_NAME_SPI1_DEV0 "spi10"
#endif
#endif
#define ES_SPI_CS_LEVEL ES_C_SPI_CS_LOW_LEVEL
#ifndef ES_SPI0_CPHA_1_2
#ifndef ES_SPI0_CPHA_1_2
#define ES_SPI0_CPHA_1_2 ES_C_SPI_CLK_PHA_SECOND
#endif
#ifndef ES_SPI0_CPOL_H_L
#define ES_SPI0_CPOL_H_L ES_C_SPI_CLK_POL_HIGH
#endif
#ifndef ES_SPI0_M_L_SB
#define ES_SPI0_M_L_SB RT_SPI_MSB
#endif
#ifndef ES_SPI0_MAX_HZ
#ifndef ES_SPI0_CPOL_H_L
#define ES_SPI0_CPOL_H_L ES_C_SPI_CLK_POL_HIGH
#endif
#ifndef ES_SPI0_M_L_SB
#define ES_SPI0_M_L_SB RT_SPI_MSB
#endif
#ifndef ES_SPI0_MAX_HZ
#define ES_SPI0_MAX_HZ 2000000
#endif
#endif
#ifndef ES_SPI0_NSS_PIN
#define ES_SPI0_NSS_PIN 0xFFFFFFFF
#endif
#ifndef ES_SPI1_CPHA_1_2
#define ES_SPI1_CPHA_1_2 ES_C_SPI_CLK_PHA_SECOND
#endif
#ifndef ES_SPI1_CPOL_H_L
#define ES_SPI1_CPOL_H_L ES_C_SPI_CLK_POL_HIGH
#endif
#ifndef ES_SPI1_M_L_SB
#define ES_SPI1_M_L_SB RT_SPI_MSB
#endif
#ifndef ES_SPI1_MAX_HZ
#ifndef ES_SPI1_CPHA_1_2
#define ES_SPI1_CPHA_1_2 ES_C_SPI_CLK_PHA_SECOND
#endif
#ifndef ES_SPI1_CPOL_H_L
#define ES_SPI1_CPOL_H_L ES_C_SPI_CLK_POL_HIGH
#endif
#ifndef ES_SPI1_M_L_SB
#define ES_SPI1_M_L_SB RT_SPI_MSB
#endif
#ifndef ES_SPI1_MAX_HZ
#define ES_SPI1_MAX_HZ 2000000
#endif
#endif
#ifndef ES_SPI1_NSS_PIN
#define ES_SPI1_NSS_PIN 0xFFFFFFFF
#endif
#endif
#define ES_SPI0_MASTER_SLAVE !RT_SPI_SLAVE
#define ES_SPI0_WIRE_3_4 !RT_SPI_3WIRE
#define ES_SPI0_CS RT_SPI_NO_CS
#define ES_SPI0_DATA_W 8
#define ES_SPI1_MASTER_SLAVE !RT_SPI_SLAVE
#define ES_SPI1_WIRE_3_4 !RT_SPI_3WIRE
#define ES_SPI1_CS RT_SPI_NO_CS
#define ES_SPI1_DATA_W 8
#endif

View File

@ -26,17 +26,17 @@
#include "es_conf_info_map.h"
#include <ald_gpio.h>
#include <ald_uart.h>
#include <ald_uart.h>
#include <ald_usart.h>
#include <ald_cmu.h>
#define ES_C_UART_PARITY_NONE PARITY_NONE
#define ES_C_UART_PARITY_NONE PARITY_NONE
#define ES_C_UART_PARITY_ODD PARITY_ODD
#define ES_C_UART_PARITY_EVEN PARITY_EVEN
#define ES_C_UART_STOP_1 STOP_BITS_1
#define ES_C_UART_STOP_1 STOP_BITS_1
#define ES_C_UART_STOP_2 STOP_BITS_2
@ -48,7 +48,7 @@
#ifndef ES_DEVICE_NAME_UART0
#define ES_DEVICE_NAME_UART0 "uart0"
#endif
#endif
#ifndef ES_DEVICE_NAME_UART1
#define ES_DEVICE_NAME_UART1 "uart1"
#endif
@ -60,72 +60,72 @@
#endif
#ifndef ES_DEVICE_NAME_USART0
#define ES_DEVICE_NAME_USART0 "usart0"
#endif
#endif
#ifndef ES_DEVICE_NAME_USART1
#define ES_DEVICE_NAME_USART1 "usart1"
#endif
#ifndef ES_CONF_UART0_BAUD_RATE
#define ES_CONF_UART0_BAUD_RATE 115200
#define ES_CONF_UART0_BAUD_RATE 115200
#endif
#ifndef ES_CONF_UART0_PARITY
#define ES_CONF_UART0_PARITY ES_C_UART_PARITY_NONE
#endif
#ifndef ES_CONF_UART0_STOP_BITS
#define ES_CONF_UART0_STOP_BITS ES_C_UART_STOP_1
#endif
#endif
#ifndef ES_CONF_UART1_BAUD_RATE
#define ES_CONF_UART1_BAUD_RATE 115200
#define ES_CONF_UART1_BAUD_RATE 115200
#endif
#ifndef ES_CONF_UART1_PARITY
#define ES_CONF_UART1_PARITY ES_C_UART_PARITY_NONE
#endif
#ifndef ES_CONF_UART1_STOP_BITS
#define ES_CONF_UART1_STOP_BITS ES_C_UART_STOP_1
#endif
#endif
#ifndef ES_CONF_UART2_BAUD_RATE
#define ES_CONF_UART2_BAUD_RATE 115200
#define ES_CONF_UART2_BAUD_RATE 115200
#endif
#ifndef ES_CONF_UART2_PARITY
#define ES_CONF_UART2_PARITY ES_C_UART_PARITY_NONE
#endif
#ifndef ES_CONF_UART2_STOP_BITS
#define ES_CONF_UART2_STOP_BITS ES_C_UART_STOP_1
#endif
#endif
#ifndef ES_CONF_UART3_BAUD_RATE
#define ES_CONF_UART3_BAUD_RATE 115200
#define ES_CONF_UART3_BAUD_RATE 115200
#endif
#ifndef ES_CONF_UART3_PARITY
#define ES_CONF_UART3_PARITY ES_C_UART_PARITY_NONE
#endif
#ifndef ES_CONF_UART3_STOP_BITS
#define ES_CONF_UART3_STOP_BITS ES_C_UART_STOP_1
#endif
#endif
#ifndef ES_CONF_USART0_BAUD_RATE
#define ES_CONF_USART0_BAUD_RATE 115200
#define ES_CONF_USART0_BAUD_RATE 115200
#endif
#ifndef ES_CONF_USART0_PARITY
#define ES_CONF_USART0_PARITY ES_C_UART_PARITY_NONE
#endif
#ifndef ES_CONF_USART0_STOP_BITS
#define ES_CONF_USART0_STOP_BITS ES_C_UART_STOP_1
#endif
#endif
#ifndef ES_CONF_USART1_BAUD_RATE
#define ES_CONF_USART1_BAUD_RATE 115200
#define ES_CONF_USART1_BAUD_RATE 115200
#endif
#ifndef ES_CONF_USART1_PARITY
#define ES_CONF_USART1_PARITY ES_C_UART_PARITY_NONE
#endif
#ifndef ES_CONF_USART1_STOP_BITS
#define ES_CONF_USART1_STOP_BITS ES_C_UART_STOP_1
#endif
#endif
#define ES_UART0_CONFIG \
{ \
ES_CONF_UART0_BAUD_RATE, \
@ -137,7 +137,7 @@
RT_SERIAL_RB_BUFSZ, \
0 \
}
#define ES_UART1_CONFIG \
{ \
@ -150,8 +150,8 @@
RT_SERIAL_RB_BUFSZ, \
0 \
}
#define ES_UART2_CONFIG \
{ \
ES_CONF_UART2_BAUD_RATE, \
@ -163,8 +163,8 @@
RT_SERIAL_RB_BUFSZ, \
0 \
}
#define ES_UART3_CONFIG \
{ \
ES_CONF_UART3_BAUD_RATE, \
@ -189,8 +189,8 @@
RT_SERIAL_RB_BUFSZ, \
0 \
}
#define ES_USART1_CONFIG \
{ \
ES_CONF_USART1_BAUD_RATE, \

View File

@ -1,7 +1,7 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -18,7 +18,7 @@
* Change Logs:
* Date Author Notes
* 2019-01-23 wangyq the first version
* 2019-11-01 wangyq update libraries
* 2019-11-01 wangyq update libraries
* 2021-04-20 liuhy the second version
*/
@ -55,57 +55,57 @@ void NVIC_Configuration(void)
*******************************************************************************/
void SystemClock_Config(void)
{
SYSCFG_UNLOCK();
#if ES_CMU_LRC_EN
SYSCFG_UNLOCK();
#if ES_CMU_LRC_EN
SET_BIT(CMU->CLKENR, CMU_CLKENR_LRCEN_MSK);
#else
CLEAR_BIT(CMU->CLKENR, CMU_CLKENR_LRCEN_MSK);
#endif /*ES_CMU_LRC_EN*/
#if ES_CMU_LOSC_EN
#endif /*ES_CMU_LRC_EN*/
#if ES_CMU_LOSC_EN
SET_BIT(CMU->CLKENR, CMU_CLKENR_LOSCEN_MSK);
#else
CLEAR_BIT(CMU->CLKENR, CMU_CLKENR_LOSCEN_MSK);
#endif /*ES_CMU_LOSC_EN*/
#if ES_CMU_HRC_EN
#endif /*ES_CMU_LOSC_EN*/
#if ES_CMU_HRC_EN
SET_BIT(CMU->CLKENR, CMU_CLKENR_HRCEN_MSK);
#else
CLEAR_BIT(CMU->CLKENR, CMU_CLKENR_HRCEN_MSK);
#endif /*ES_CMU_HRC_EN*/
#if ES_CMU_HOSC_EN
#endif /*ES_CMU_HRC_EN*/
#if ES_CMU_HOSC_EN
SET_BIT(CMU->CLKENR, CMU_CLKENR_HOSCEN_MSK);
#else
CLEAR_BIT(CMU->CLKENR, CMU_CLKENR_HOSCEN_MSK);
#endif /*ES_CMU_HOSC_EN*/
#endif /*ES_CMU_HOSC_EN*/
SYSCFG_LOCK();
SYSCFG_LOCK();
#if ES_CMU_PLL1_EN
#if ES_CMU_PLL1_EN
/*PLL的源必须是4M*/
ald_cmu_pll1_config(ES_PLL1_REFER_CLK, ES_PLL1_OUT_CLK);
#if ES_CMU_PLL1_SAFE_EN
ald_cmu_pll_safe_config(ENABLE);
#else
ald_cmu_pll_safe_config(DISABLE);
#endif
#else
CLEAR_BIT(CMU->CLKENR, CMU_CLKENR_PLL1EN_MSK);
#endif /*ES_CMU_PLL1_EN*/
#endif /*ES_CMU_PLL1_EN*/
ald_cmu_clock_config(ES_SYS_CLK_SOURSE, ES_SYS_CLK);
ald_cmu_div_config(CMU_SYS,ES_CMU_SYS_DIV);
ald_cmu_div_config(CMU_HCLK_1,ES_CMU_HCLK_1_DIV);
ald_cmu_div_config(CMU_PCLK_1,ES_CMU_PCLK_1_DIV);
ald_cmu_div_config(CMU_PCLK_2,ES_CMU_PCLK_2_DIV);
ald_cmu_perh_clock_config(CMU_PERH_ALL, ENABLE);
/*低功耗时钟使能*/
/*低功耗时钟使能*/
#ifdef RT_USING_PM
SYSCFG_UNLOCK();
SET_BIT(CMU->LPENR, CMU_LPENR_LRCEN_MSK);
@ -127,7 +127,7 @@ void SysTick_Configuration(void)
{
/* ticks = sysclk / RT_TICK_PER_SECOND */
SysTick_Config(ald_cmu_get_sys_clock() / RT_TICK_PER_SECOND);
__systick_interval = 1;
}

View File

@ -1,7 +1,7 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -17,7 +17,7 @@
*
* Change Logs:
* Date Author Notes
* 2019-01-23 wangyq the first version
* 2019-01-23 wangyq the first version
* 2021-04-20 liuhy the second version
*/

View File

@ -1,52 +0,0 @@
# 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

View File

@ -1,47 +0,0 @@
# 外设驱动测试用例
## 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

View File

@ -1,62 +0,0 @@
/*
* 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>
#ifdef RT_USING_ADC
#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);
#endif

View File

@ -1,148 +0,0 @@
/*
* 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"
#ifdef RT_USING_CAN
#define CAN_DEV_NAME "can0" /* 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~0x1ffhdr为-1设置默认过滤表 */
RT_CAN_FILTER_ITEM_INIT(0x300, 0, 0, 0, 0x700, RT_NULL, RT_NULL), /* std,match ID:0x300~0x3ffhdr为-1 */
RT_CAN_FILTER_ITEM_INIT(0x211, 0, 0, 0, 0x7ff, RT_NULL, RT_NULL), /* std,match ID:0x211hdr为-1 */
RT_CAN_FILTER_STD_INIT(0x486, RT_NULL, RT_NULL), /* std,match ID:0x486hdr为-1 */
{0x555, 0, 0, 0, 0x7ff, 7,} /* std,match ID:0x555hdr为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);
#endif

View File

@ -1,89 +0,0 @@
/*
* 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值2tick值之差换算为时间等同于定时时间值
*/
#include <rtthread.h>
#include <rtdevice.h>
#ifdef RT_USING_HWTIMER
#define HWTIMER_DEV_NAME "timer1" /* 定时器名称 */
/* 定时器超时回调函数 */
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);
#endif

View File

@ -1,109 +0,0 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Change Logs:
* Date Author Notes
* 2020-12-15 liuhy first implementation.
*/
/*
* I2C 使
* i2c_e2_sample
* i2c_e2_sample
* 使I2C总线设备i2c0
* I2C e2promST24C04WP
*/
/*ST24C04WP 有2个Block Block0 的从机地址为0x50,Block1 的从机地址为0x51
Block有 25616,(,),*/
#include <rtthread.h>
#include <rtdevice.h>
#ifdef RT_USING_I2C
#define I2C_BUS_NAME "i2c0" /*I2C总线设备名称 */
#define SLAVE_ADDR 0x50 /*从机地址*/
#define MEM_ADDR 0x00 /*从机的起始储存地址,范围0x00到0xEF(例程写读范围2页)*/
#define ADDR_LEN 1 /*定义从机储存地址的长度默认8位,1字节*/
#define STR_LEN 16 /*接收发送的页数据长度 ,最大16*/
static rt_uint8_t mem_addr,rx_buffer[33] = { 0U }; /*读两页,需要32字节字符串结束'\0'*/
/*第一个字节' '用来放 E2PROM 的内存地址,最后一个字节'\0'作为子串的结束不存入e2prom*/
static rt_uint8_t tx_buffer1[STR_LEN + ADDR_LEN + 1] = " e2prom example !\0";
static rt_uint8_t tx_buffer2[STR_LEN + ADDR_LEN + 1] = " ABCDEFGH12345678\0";
static void i2c_e2_sample(int argc, char *argv[])
{
struct rt_i2c_bus_device *i2c_bus = RT_NULL; /* I2C总线设备句柄 */
struct rt_i2c_msg i2c_msg[2]; /* I2C消息 */
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;
}
/*写T24C04WP
(MEM_ADDR & 0x0F) + STR_LEN <= 16, (MEM_ADDR , MEM_ADDR + STR_LEN )
(0x10 + MEM_ADDR , 0x10 + MEM_ADDR + STR_LEN )
(MEM_ADDR & 0x0F) + STR_LEN > 16, */
tx_buffer1[0] = MEM_ADDR;
/*初始化消息*/
i2c_msg[0].addr = SLAVE_ADDR; /* 从机地址 */
i2c_msg[0].len = ADDR_LEN + STR_LEN ; /* 写入的长度,地址+数据 */
i2c_msg[0].buf = tx_buffer1; /* 待写入第一段数据 */
i2c_msg[0].flags = RT_I2C_WR; /* I2C写 */
s_stat = rt_i2c_transfer(i2c_bus,i2c_msg,1); /* 写入第一段数据 */
if( s_stat == 1 )rt_kprintf("write successful. \nmessage: %s\n",&tx_buffer1[1]);
else rt_kprintf("device %s write fail \n",I2C_BUS_NAME);
tx_buffer2[0] = MEM_ADDR + 0x10; /*加一页*/
i2c_msg[0].buf = tx_buffer2; /* 待写入第二段数据 */
s_stat = rt_i2c_transfer(i2c_bus,i2c_msg,1); /* 写入第二段数据 */
if( s_stat == 1 )rt_kprintf("write successful. \nmessage: %s\n",&tx_buffer2[1]);
else rt_kprintf("device %s write fail \n",I2C_BUS_NAME);
/*读T24C04WP 读2页的数据。读数据需要2条消息第一条消息发送读取的地址。
*/
mem_addr = MEM_ADDR & 0xF0; /*从页的开始读*/
i2c_msg[0].len = ADDR_LEN;
i2c_msg[0].buf = &mem_addr;
i2c_msg[1].addr = SLAVE_ADDR; /* 从机地址 */
i2c_msg[1].len = 32; /* 读取的数据长度2*16 */
i2c_msg[1].buf = rx_buffer; /* 数据存放地址 */
i2c_msg[1].flags = RT_I2C_RD; /* I2C读 */
s_stat = rt_i2c_transfer(i2c_bus,i2c_msg,2); /* 读已写的2页 */
if( s_stat == 2 )rt_kprintf(" read successful \n messege : %s \n",rx_buffer);
else
rt_kprintf("read fail \n");
return;
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(i2c_e2_sample, i2c e2prom sample);
#endif

View File

@ -1,109 +0,0 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Change Logs:
* Date Author Notes
* 2020-12-15 liuhy first implementation.
*/
/*
* I2C 使
* i2c_io_sample
* i2c_io_sample
* 使I2C总线设备i2c0
* I2C 1
*/
#include <rtthread.h>
#include <rtdevice.h>
#ifdef RT_USING_I2C
#define I2C_BUS_NAME "i2c0" /* 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); /* 传输消息 */
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); /* 传输一条 */
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);
#endif

View File

@ -1,84 +0,0 @@
/*
* 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 41
* 使PIN脚编号使
* led线程线1000ms改变PIN脚状态led灯
*
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <stdlib.h>
#include "drv_gpio.h"
/* PIN脚编号查看驱动文件drv_gpio.c确定 */
#define LED_PIN_NUM GET_PIN(B,9) /*PB9*/
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);

View File

@ -1,68 +0,0 @@
/*
* 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>
#include "drv_gpio.h"
/* 引脚编号通过查看驱动文件drv_gpio.c确定 */
#ifndef BEEP_PIN_NUM
#define BEEP_PIN_NUM GET_PIN(B,9) /* PB9 */
#endif
#ifndef KEY0_PIN_NUM
#define KEY0_PIN_NUM GET_PIN(F,0) /* PF0 */
#endif
#ifndef KEY1_PIN_NUM
#define KEY1_PIN_NUM GET_PIN(F,1) /* 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);

View File

@ -1,211 +0,0 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Change Logs:
* Date Author Notes
* 2020-12-15 liuhy first implementation.
*/
/*
* pm睡眠唤醒的使用例程
* pm_sample
* pm_sample
*
*
* SYSTICKUARTEXTI等
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_gpio.h"
#ifdef RT_USING_PM
#define PM_NAME "pm" /* 设备名称 */
#define WAKE_UP_PIN GET_PIN(F,0) /* 唤醒源 */
#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; /*睡眠唤醒后*/
/*从深睡眠唤醒后等待UART时钟未恢复稳定输出可能丢失*/
rt_kprintf("\n\rEXIT\n\r");
rt_pm_request(PM_SLEEP_MODE_NONE); /*进无休眠模式*/
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_release_all(PM_SLEEP_MODE_NONE);
/*请求选择的休眠模式*/
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_all(in_mode[i%6]);
i++;
}
/*切换为无睡眠模式*/
rt_pm_request(PM_SLEEP_MODE_NONE);
/*清除回调函数和私有数据*/
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);
#endif

View File

@ -1,78 +0,0 @@
/*
* 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>
#include "drv_gpio.h"
#ifdef RT_USING_PWM
#define LED_PIN_NUM GET_PIN(A,2) /* LED PIN脚编号查看驱动文件drv_gpio.c确定 */
#define PWM_DEV_NAME "pwm1" /* PWM设备名称 */
#define PWM_DEV_CHANNEL 1 /* 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);
#endif

View File

@ -1,55 +0,0 @@
/*
* 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>
#ifdef RT_USING_RTC
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);
#endif

View File

@ -1,152 +0,0 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* 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>
#ifdef RT_USING_SPI
#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设备的句柄 */
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;
}
/* 配置SPI设备 */
s_stat = rt_spi_configure(spi_dev,&(spi_dev->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);
#endif

View File

@ -1,149 +0,0 @@
/*
* 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>
/* UART_SAMPLE_TYPE = 1,错位输出
= 2
*/
#define UART_SAMPLE_TYPE 1
#if (UART_SAMPLE_TYPE == 2)
#define SAMPLE_UART_RXBUF_SIZE 256 /* 接收缓存大小 */
#define SAMPLE_UART_END_SRTING "\r\n" /* 结尾固定格式 */
#endif
#define SAMPLE_UART_NAME "uart0" /* 串口设备名称 */
/* 用于接收消息的信号量 */
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)
{
#if (UART_SAMPLE_TYPE == 1)
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);
}
#endif
#if (UART_SAMPLE_TYPE == 2)
char rx_buf[SAMPLE_UART_RXBUF_SIZE],*end = SAMPLE_UART_END_SRTING; /*rx_buf[]:接收缓存,可修改大小 end[]:固定的结束格式(可修改,不可包含'\0'*/
uint32_t rx_index = 0; /*接收数据的索引 */
uint32_t end_len = rt_strlen(end); /*固定的结束格式的长度*/
while(1)
{
/* 从串口读取一个字节的数据,没有读取到则等待接收信号量 */
while (rt_device_read(serial, -1, (rx_buf + rx_index), 1) != 1)
{
/* 阻塞等待接收信号量,等到信号量后再次读取数据 */
rt_sem_take(&rx_sem, RT_WAITING_FOREVER);
}
rx_index++;
if(rx_index >= SAMPLE_UART_RXBUF_SIZE)
{
rt_kprintf("rx_buf over!\r\n"); /*范围越界*/
}
/*判断是否固定的结尾格式*/
if((rx_index >= end_len)&&\
((rt_strncmp(end,(rx_buf + rx_index - end_len),end_len)) == 0))
{
rt_device_write(serial, 0, rx_buf, rx_index);
rx_index = 0;
}
}
#endif
}
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);

View File

@ -1,7 +1,7 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -134,7 +134,7 @@ static adc_channel_t es32f0_adc_get_channel(rt_uint32_t channel)
es32f0_channel = ADC_CHANNEL_15;
ald_gpio_init(ES_GPIO_ADC_CH15_GPIO, ES_GPIO_ADC_CH15_PIN, &gpio_initstruct);
break;
default:
break;
}
@ -153,7 +153,7 @@ static rt_err_t es32f0_get_adc_value(struct rt_adc_device *device, rt_uint32_t c
/* config adc channel */
nm_config.ch = es32f0_adc_get_channel(channel);
nm_config.idx = ADC_NCH_IDX_1;
/*aaabbbccc*/
nm_config.samp = ES_ADC0_NCH_SAMPLETIME;
nm_config.samp = ADC_SAMPLETIME_4;
@ -176,7 +176,7 @@ static const struct rt_adc_ops es32f0_adc_ops =
int rt_hw_adc_init(void)
{
int result = RT_EOK;
adc_handle_t _h_adc;
_h_adc.init.scan = DISABLE;
@ -185,25 +185,25 @@ int rt_hw_adc_init(void)
_h_adc.init.disc_nr = ADC_DISC_NR_1;
_h_adc.init.nche_sel = ADC_NCHESEL_MODE_ALL;
_h_adc.init.n_ref = ADC_NEG_REF_VSS;
_h_adc.init.p_ref = ADC_POS_REF_VDD;
_h_adc.init.nch_nr = ADC_NCH_NR_16;
_h_adc.init.p_ref = ADC_POS_REF_VDD;
_h_adc.init.nch_nr = ADC_NCH_NR_16;
#ifdef BSP_USING_ADC0
static adc_handle_t _h_adc0;
_h_adc0.init = _h_adc.init;
_h_adc0.perh = ADC0;
_h_adc0.init.align = ES_ADC0_ALIGN;
_h_adc0.init.data_bit = ES_ADC0_DATA_BIT;
_h_adc0.init.div = ES_ADC0_CLK_DIV;
_h_adc0.init.div = ES_ADC0_CLK_DIV;
ald_adc_init(&_h_adc0);
result = rt_hw_adc_register(&_device_adc0, ES_DEVICE_NAME_ADC0, &es32f0_adc_ops, &_h_adc0);
#endif /*BSP_USING_ADC0*/
return result;
}
INIT_BOARD_EXPORT(rt_hw_adc_init);

View File

@ -1,7 +1,7 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -17,7 +17,7 @@
*
* Change Logs:
* Date Author Notes
* 2019-11-09 wangyq the first version
* 2019-11-09 wangyq the first version
* 2021-04-20 liuhy the second version
*/
@ -30,26 +30,26 @@ static struct es32f0_can can;
static rt_uint32_t get_can_baud_index(rt_uint32_t baud,can_init_t * init)
{
{
/* attention !!! baud calculation example: Pclk / ((1 + seg1 + seg2) * psc) Pclk=48 / ((1 + seg1=3 + seg2=2) * 8) = 1MHz */
double target,temp,min;
uint32_t i,j,j_max,near = 0;
target = (double)(ald_cmu_get_pclk1_clock());
target/= baud; /*计算误差1*/
target/= baud; /*计算误差1*/
min = 0xFFFFFFFF;
for(i = 1 + 16 + 8 ;i > 2;i--) /*SYNC_SEG + SEG1 + SEG2*/
{
j_max = target/i/(0.98) + 1; /*缩小范围*/
j_max = target/i/(0.98) + 1; /*缩小范围*/
j_max = (j_max > 1024) ? (1024) : (j_max);
for(j = target/i/1.02 ;j < j_max;j++)
{
temp = target/i/j; /*计算误差2*/
{
temp = target/i/j; /*计算误差2*/
temp = (temp > 1) ? (temp - 1) : (1 - temp);
temp+= ((1.0 * i * j) / 0xFFFFFFFF) ;
temp+= ((1.0 * i * j) / 0xFFFFFFFF) ;
if(temp < min)
{
if(temp > 0.000001)
@ -57,12 +57,12 @@ static rt_uint32_t get_can_baud_index(rt_uint32_t baud,can_init_t * init)
near = (i<<16) + j;
min = temp;
}
else
else
{
init->seg1 = (can_seg1_t)((i - 1)*2/3-1);
init->seg2 = (can_seg2_t)(i - init->seg1 - 1 - 1 - 1);
init->psc = j;
return 0;
}
}
@ -76,15 +76,15 @@ static rt_uint32_t get_can_baud_index(rt_uint32_t baud,can_init_t * init)
init->seg1 = (can_seg1_t)((i - 1)*2/3-1);
init->seg2 = (can_seg2_t)(i - init->seg1 - 1 - 1 - 1);
init->psc = j;
return 0;
}
else
{
return 1;
return 1;
}
}
static rt_err_t _can_config(struct rt_can_device *can_device, struct can_configure *cfg)
{
@ -118,13 +118,13 @@ static rt_err_t _can_config(struct rt_can_device *can_device, struct can_configu
drv_can->CanHandle.init.mode = CAN_MODE_SILENT_LOOPBACK;
break;
}
/*配置参数*/
/*配置参数*/
if(get_can_baud_index(cfg->baud_rate,&(drv_can->CanHandle.init)))
{
return -RT_ERROR;
return -RT_ERROR;
}
drv_can->CanHandle.init.sjw = (can_sjw_t)(cfg->reserved);
/* init can */
// baud_index = get_can_baud_index(cfg->baud_rate);
@ -188,14 +188,14 @@ static rt_err_t _can_control(struct rt_can_device *can_device, int cmd, void *ar
{
NVIC_SetPriority(CAN0_IRQn, 1);
NVIC_EnableIRQ(CAN0_IRQn);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_FP0, ENABLE);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_FF0, ENABLE);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_FOV0, ENABLE);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_FP1, ENABLE);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_FF1, ENABLE);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_FOV1, ENABLE);
}
else if (argval == RT_DEVICE_FLAG_INT_TX)
{
@ -208,13 +208,13 @@ static rt_err_t _can_control(struct rt_can_device *can_device, int cmd, void *ar
{
NVIC_SetPriority(CAN0_IRQn, 1);
NVIC_EnableIRQ(CAN0_IRQn);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_WARN, ENABLE);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_PERR, ENABLE);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_BOF, ENABLE);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_PRERR, ENABLE);
ald_can_interrupt_config(&drv_can->CanHandle, CAN_IT_ERR, ENABLE);
}
break;
#ifdef RT_CAN_USING_HDR
@ -229,53 +229,53 @@ static rt_err_t _can_control(struct rt_can_device *can_device, int cmd, void *ar
filter_cfg = (struct rt_can_filter_config *)arg;
/* get default filter */
for (int i = 0; i < filter_cfg->count; i++)
{
/*默认过滤表判断*/
if(filter_cfg->items[i].hdr < drv_can->device.config.maxhdr)
{
/*默认过滤表判断*/
if(filter_cfg->items[i].hdr < drv_can->device.config.maxhdr)
drv_can->FilterConfig.number = filter_cfg->items[i].hdr;
else
else
drv_can->FilterConfig.number = ES_C_CAN_DEFAULT_FILTER_NUMBER;
if(filter_cfg->items[i].mode)
{
/*标识符列表模式: 类型匹配 id匹配为接收的id = 配置的id
= mask */
/*扩展帧*/
if(filter_cfg->items[i].ide)
{
// filter_cfg->items[i].id = filter_cfg->items[i].id ; /*id 29 位*/
/*标识符列表模式: 类型匹配 id匹配为接收的id = 配置的id
= mask */
/*扩展帧*/
if(filter_cfg->items[i].ide)
{
// filter_cfg->items[i].id = filter_cfg->items[i].id ; /*id 29 位*/
filter_cfg->items[i].mask = ((filter_cfg->items[i].mask << 3) |
(filter_cfg->items[i].ide << 2) |
(filter_cfg->items[i].rtr << 1));
(filter_cfg->items[i].rtr << 1));
}
else /*标准帧*/
else /*标准帧*/
{
filter_cfg->items[i].id = (filter_cfg->items[i].id << 18);
filter_cfg->items[i].id = (filter_cfg->items[i].id << 18);
filter_cfg->items[i].mask = ((filter_cfg->items[i].mask << 21) |
(filter_cfg->items[i].ide << 2) |
(filter_cfg->items[i].rtr << 1));
}
(filter_cfg->items[i].rtr << 1));
}
}
else
{
/*标识符掩码模式*/
/*扩展帧*/
if(filter_cfg->items[i].ide)
{
filter_cfg->items[i].mask = (filter_cfg->items[i].mask)<<3;
}
else /*标准帧*/
/*标识符掩码模式*/
/*扩展帧*/
if(filter_cfg->items[i].ide)
{
filter_cfg->items[i].id = (filter_cfg->items[i].id)<<18;
filter_cfg->items[i].mask = (filter_cfg->items[i].mask)<<3;
}
else /*标准帧*/
{
filter_cfg->items[i].id = (filter_cfg->items[i].id)<<18;
filter_cfg->items[i].mask = (filter_cfg->items[i].mask)<<21;
}
}
#if ES_C_CAN_FILTER_FRAME_TYPE
/*匹配类型*/
/*匹配类型*/
filter_cfg->items[i].mask |= 0x6;
#endif
#endif
}
drv_can->FilterConfig.id_high = (filter_cfg->items[i].id >> 13) & 0xFFFF;
@ -309,7 +309,7 @@ static rt_err_t _can_control(struct rt_can_device *can_device, int cmd, void *ar
break;
case RT_CAN_CMD_SET_BAUD:
argval = (rt_uint32_t) arg;
if (argval != drv_can->device.config.baud_rate)
{
drv_can->device.config.baud_rate = argval;
@ -418,9 +418,9 @@ static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t
}
/* clear TIR */
h_can->perh->TxMailBox[box_num].TXID &= CAN_TXID0_TXMREQ_MSK;
/* Set up the Id */
/* Set up the Id */
if (RT_CAN_STDID == pmsg->ide)
{
{
h_can->perh->TxMailBox[box_num].TXID |= (txheader.std << CAN_TXID0_STDID_POSS) | (txheader.rtr << CAN_TXID0_RTR_POS);
}
else
@ -533,8 +533,8 @@ static void _can_rx_isr(struct rt_can_device *can, rt_uint32_t fifo)
/* RX interrupt */
else
{
if(CAN_RX_MSG_PENDING(h_can, CAN_RX_FIFO0) != 0)
{
if(CAN_RX_MSG_PENDING(h_can, CAN_RX_FIFO0) != 0)
{
/* save to user list */
rt_hw_can_isr(can, RT_CAN_EVENT_RX_IND | fifo << 8);
}
@ -554,8 +554,8 @@ static void _can_rx_isr(struct rt_can_device *can, rt_uint32_t fifo)
/* RX interrupt */
else
{
if(CAN_RX_MSG_PENDING(h_can, CAN_RX_FIFO1) != 0)
{
if(CAN_RX_MSG_PENDING(h_can, CAN_RX_FIFO1) != 0)
{
/* save to user list */
rt_hw_can_isr(can, RT_CAN_EVENT_RX_IND | fifo << 8);
}
@ -679,21 +679,21 @@ int rt_hw_can_init(void)
h_gpio.flt = GPIO_FILTER_DISABLE;
h_gpio.type = GPIO_TYPE_TTL;
#if defined(ES_CAN0_RX_GPIO_FUNC)&&defined(ES_CAN0_RX_GPIO_PORT)&&defined(ES_CAN0_RX_GPIO_PIN)
#if defined(ES_CAN0_RX_GPIO_FUNC)&&defined(ES_CAN0_RX_GPIO_PORT)&&defined(ES_CAN0_RX_GPIO_PIN)
/* Initialize can rx pin */
h_gpio.mode = GPIO_MODE_INPUT;
h_gpio.mode = GPIO_MODE_INPUT;
h_gpio.func = ES_CAN0_RX_GPIO_FUNC;
ald_gpio_init(ES_CAN0_RX_GPIO_PORT, ES_CAN0_RX_GPIO_PIN, &h_gpio);
#endif
#if defined(ES_CAN0_TX_GPIO_FUNC)&&defined(ES_CAN0_TX_GPIO_PORT)&&defined(ES_CAN0_TX_GPIO_PIN)
#endif
#if defined(ES_CAN0_TX_GPIO_FUNC)&&defined(ES_CAN0_TX_GPIO_PORT)&&defined(ES_CAN0_TX_GPIO_PIN)
/* Initialize can tx pin */
h_gpio.mode = GPIO_MODE_OUTPUT;
h_gpio.mode = GPIO_MODE_OUTPUT;
h_gpio.func = ES_CAN0_TX_GPIO_FUNC;
ald_gpio_init(ES_CAN0_TX_GPIO_PORT, ES_CAN0_TX_GPIO_PIN, &h_gpio);
#endif
#endif
/* config default filter */
can_filter_t filter = {0};
@ -708,7 +708,7 @@ int rt_hw_can_init(void)
filter.active = ENABLE;
can.FilterConfig = filter;
can.device.config = (struct can_configure)ES_CAN0_CONFIG;
can.device.config = (struct can_configure)ES_CAN0_CONFIG;
#ifdef RT_CAN_USING_HDR
can.device.config.maxhdr = 14;
#endif

View File

@ -17,7 +17,7 @@
*
* Change Logs:
* Date Author Notes
* 2019-11-09 wangyq the first version
* 2019-11-09 wangyq the first version
* 2021-04-20 liuhy the second version
*/

View File

@ -1,7 +1,7 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -18,7 +18,7 @@
* Change Logs:
* Date Author Notes
* 2019-01-23 wangyq the first version
* 2019-11-01 wangyq update libraries
* 2019-11-01 wangyq update libraries
* 2021-04-20 liuhy the second version
*/
@ -79,143 +79,143 @@ struct rt_pin_irq_hdr pin_irq_hdr_tab[] =
RT_WEAK void irq_pin0_callback(void* arg)
{
rt_kprintf("\r\nEXTI 0\r\n");
}
}
#endif
#ifdef ES_CONF_EXTI_IRQ_1
#ifdef ES_CONF_EXTI_IRQ_1
RT_WEAK void irq_pin1_callback(void* arg)
{
rt_kprintf("\r\nEXTI 1\r\n");
}
}
#endif
#ifdef ES_CONF_EXTI_IRQ_2
RT_WEAK void irq_pin2_callback(void* arg)
{
rt_kprintf("\r\nEXTI 2\r\n");
}
rt_kprintf("\r\nEXTI 2\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_3
RT_WEAK void irq_pin3_callback(void* arg)
{
rt_kprintf("\r\nEXTI 3\r\n");
}
#endif
rt_kprintf("\r\nEXTI 3\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_4
RT_WEAK void irq_pin4_callback(void* arg)
{
rt_kprintf("\r\nEXTI 4\r\n");
}
#endif
rt_kprintf("\r\nEXTI 4\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_5
RT_WEAK void irq_pin5_callback(void* arg)
{
rt_kprintf("\r\nEXTI 5\r\n");
}
#endif
rt_kprintf("\r\nEXTI 5\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_6
RT_WEAK void irq_pin6_callback(void* arg)
{
rt_kprintf("\r\nEXTI 6\r\n");
}
#endif
rt_kprintf("\r\nEXTI 6\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_7
RT_WEAK void irq_pin7_callback(void* arg)
{
rt_kprintf("\r\nEXTI 7\r\n");
}
#endif
rt_kprintf("\r\nEXTI 7\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_8
RT_WEAK void irq_pin8_callback(void* arg)
{
rt_kprintf("\r\nEXTI 8\r\n");
}
#endif
rt_kprintf("\r\nEXTI 8\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_9
RT_WEAK void irq_pin9_callback(void* arg)
{
rt_kprintf("\r\nEXTI 9\r\n");
}
#endif
rt_kprintf("\r\nEXTI 9\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_10
RT_WEAK void irq_pin10_callback(void* arg)
{
rt_kprintf("\r\nEXTI 10\r\n");
}
#endif
rt_kprintf("\r\nEXTI 10\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_11
RT_WEAK void irq_pin11_callback(void* arg)
{
rt_kprintf("\r\nEXTI 11\r\n");
}
#endif
rt_kprintf("\r\nEXTI 11\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_12
RT_WEAK void irq_pin12_callback(void* arg)
{
rt_kprintf("\r\nEXTI 12\r\n");
}
#endif
rt_kprintf("\r\nEXTI 12\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_13
RT_WEAK void irq_pin13_callback(void* arg)
{
rt_kprintf("\r\nEXTI 13\r\n");
}
#endif
rt_kprintf("\r\nEXTI 13\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_14
RT_WEAK void irq_pin14_callback(void* arg)
{
rt_kprintf("\r\nEXTI 14\r\n");
}
#endif
rt_kprintf("\r\nEXTI 14\r\n");
}
#endif
#ifdef ES_CONF_EXTI_IRQ_15
RT_WEAK void irq_pin15_callback(void* arg)
{
rt_kprintf("\r\nEXTI 15\r\n");
}
#endif
rt_kprintf("\r\nEXTI 15\r\n");
}
#endif
#define ITEM_NUM(items) sizeof(items) / sizeof(items[0])
@ -315,12 +315,12 @@ void es32f0_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
rt_inline const struct pin_irq_map *get_pin_irq_map(rt_uint16_t gpio_pin)
{
uint8_t map_index = 0U;
while(gpio_pin >> (++map_index))
{
}
map_index--;
if (map_index >= ITEM_NUM(pin_irq_map))
{
return RT_NULL;
@ -563,16 +563,16 @@ void EXTI12_15_Handler(void)
int rt_hw_pin_init(void)
{
int result;
#ifdef ES_INIT_GPIOS
rt_size_t i,gpio_conf_num = sizeof(gpio_conf_all) / sizeof(gpio_conf_t);
#endif
#endif
ald_cmu_perh_clock_config(CMU_PERH_GPIO, ENABLE);
result = rt_device_pin_register(ES_DEVICE_NAME_PIN, &_es32f0_pin_ops, RT_NULL);
if(result != RT_EOK)return result;
@ -582,20 +582,20 @@ int rt_hw_pin_init(void)
for(i = 0;i < gpio_conf_num;i++)
{
rt_pin_mode( gpio_conf_all[i].pin,gpio_conf_all[i].pin_mode);
if((gpio_conf_all[i].pin_mode == ES_C_GPIO_MODE_OUTPUT)||(gpio_conf_all[i].pin_mode == ES_C_GPIO_MODE_OUTPUT_OD))
rt_pin_write(gpio_conf_all[i].pin,gpio_conf_all[i].pin_level);
if(!gpio_conf_all[i].irq_en)continue;
rt_pin_attach_irq(gpio_conf_all[i].pin, gpio_conf_all[i].irq_mode, gpio_conf_all[i].callback, RT_NULL);
rt_pin_irq_enable(gpio_conf_all[i].pin, gpio_conf_all[i].irq_en);
}
#endif
#endif
return result;
}
INIT_BOARD_EXPORT(rt_hw_pin_init);

View File

@ -18,7 +18,7 @@
* Change Logs:
* Date Author Notes
* 2019-01-23 wangyq the first version
* 2021-04-20 liuhy the second version
* 2021-04-20 liuhy the second version
*/
#ifndef DRV_GPIO_H__

View File

@ -1,7 +1,7 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -26,7 +26,7 @@
#include <rtthread.h>
#include <rtdevice.h>
#include <drv_hwtimer.h>
#include <board.h>
#include <board.h>
#ifdef RT_USING_HWTIMER
@ -203,7 +203,7 @@ static void es32f0_hwtimer_init(rt_hwtimer_t *timer, rt_uint32_t state)
struct rt_hwtimer_info *hwtimer_info = (struct rt_hwtimer_info *)timer->info;
RT_ASSERT(hwtimer != RT_NULL);
if (1 == state)
@ -212,7 +212,7 @@ static void es32f0_hwtimer_init(rt_hwtimer_t *timer, rt_uint32_t state)
ald_timer_interrupt_config(hwtimer->hwtimer_periph, TIMER_IT_UPDATE, ENABLE);
NVIC_EnableIRQ(hwtimer->IRQn);
}
hwtimer->parent.freq = ald_cmu_get_pclk1_clock()/((hwtimer->hwtimer_periph->perh->PRES & 0xFFFF)+1);
hwtimer_info->maxfreq = hwtimer->parent.freq;
hwtimer_info->minfreq = (hwtimer->parent.freq)/0xFFFF;
@ -267,19 +267,19 @@ static rt_err_t es32f0_hwtimer_control(rt_hwtimer_t *timer,
{
case HWTIMER_CTRL_FREQ_SET:
freq = *(rt_uint32_t *)args;
ret = -RT_ERROR;
if(freq)
{
{
double temp,target;
temp = (double)ald_cmu_get_pclk1_clock();
target = temp/freq;
if(target < 0x10001) /*×î´ó·ÖƵ = max(PRES)+1*/
if(target < 0x10001) /*最大分频 = max(PRES)+1*/
{
temp = target - (int)(target);
if((temp > 0.998)&&(target < 0x10000))
{
hwtimer->hwtimer_periph->perh->PRES = (uint32_t)target;
@ -290,14 +290,14 @@ static rt_err_t es32f0_hwtimer_control(rt_hwtimer_t *timer,
hwtimer->hwtimer_periph->perh->PRES = (uint32_t)target - 1;
ret = RT_EOK;
}
}
if(ret == RT_EOK) /*¸üÐÂÐÅÏ¢*/
if(ret == RT_EOK) /*更新信息*/
hwtimer->parent.freq = ald_cmu_get_pclk1_clock()/((hwtimer->hwtimer_periph->perh->PRES & 0xFFFF)+1);
}
break;
case HWTIMER_CTRL_STOP:
@ -327,14 +327,14 @@ int rt_hw_hwtimer_init(void)
#ifdef BSP_USING_AD16C4T0_HWTIMER
static timer_handle_t ad16c4t0_hwtimer_periph;
ad16c4t0_hwtimer_periph.perh = AD16C4T0;
ad16c4t0_hwtimer.IRQn = AD16C4T0_BRK_UP_TRIG_COM_IRQn;
ad16c4t0_hwtimer_periph.init.prescaler = ES_AD16C4T0_HWTIMER_PRES - 1;
ad16c4t0_hwtimer_periph.init.prescaler = ES_AD16C4T0_HWTIMER_PRES - 1;
ad16c4t0_hwtimer_periph.init.mode = ( ES_AD16C4T0_HWTIMER_MODE == HWTIMER_CNTMODE_UP )? TIMER_CNT_MODE_UP : TIMER_CNT_MODE_DOWN;
ad16c4t0_hwtimer.hwtimer_periph = &ad16c4t0_hwtimer_periph;
ad16c4t0_hwtimer.parent.info = &ad16c4t0_info;
ad16c4t0_hwtimer.parent.ops = &es32f0_hwtimer_ops;
ret = rt_device_hwtimer_register(&ad16c4t0_hwtimer.parent, ES_DEVICE_NAME_AD16C4T0_HWTIMER, &ad16c4t0_hwtimer);
@ -342,14 +342,14 @@ int rt_hw_hwtimer_init(void)
#ifdef BSP_USING_GP16C4T0_HWTIMER
static timer_handle_t gp16c4t0_hwtimer_periph;
gp16c4t0_hwtimer_periph.perh = GP16C4T0;
gp16c4t0_hwtimer.IRQn = GP16C4T0_LCD_IRQn;
gp16c4t0_hwtimer_periph.init.prescaler = ES_GP16C4T0_HWTIMER_PRES - 1;
gp16c4t0_hwtimer_periph.init.prescaler = ES_GP16C4T0_HWTIMER_PRES - 1;
gp16c4t0_hwtimer_periph.init.mode = ( ES_GP16C4T0_HWTIMER_MODE == HWTIMER_CNTMODE_UP )? TIMER_CNT_MODE_UP : TIMER_CNT_MODE_DOWN;
gp16c4t0_hwtimer.hwtimer_periph = &gp16c4t0_hwtimer_periph;
gp16c4t0_hwtimer.parent.info = &gp16c4t0_info;
gp16c4t0_hwtimer.parent.ops = &es32f0_hwtimer_ops;
ret = rt_device_hwtimer_register(&gp16c4t0_hwtimer.parent, ES_DEVICE_NAME_GP16C4T0_HWTIMER, &gp16c4t0_hwtimer);
@ -357,14 +357,14 @@ int rt_hw_hwtimer_init(void)
#ifdef BSP_USING_GP16C2T0_HWTIMER
static timer_handle_t gp16c2t0_hwtimer_periph;
gp16c2t0_hwtimer_periph.perh = GP16C2T0;
gp16c2t0_hwtimer.IRQn = GP16C2T0_IRQn;
gp16c2t0_hwtimer_periph.init.prescaler = ES_GP16C2T0_HWTIMER_PRES - 1;
gp16c2t0_hwtimer_periph.init.prescaler = ES_GP16C2T0_HWTIMER_PRES - 1;
gp16c2t0_hwtimer_periph.init.mode = ( ES_GP16C2T0_HWTIMER_MODE == HWTIMER_CNTMODE_UP )? TIMER_CNT_MODE_UP : TIMER_CNT_MODE_DOWN;
gp16c2t0_hwtimer.hwtimer_periph = &gp16c2t0_hwtimer_periph;
gp16c2t0_hwtimer.parent.info = &gp16c2t0_info;
gp16c2t0_hwtimer.parent.ops = &es32f0_hwtimer_ops;
ret = rt_device_hwtimer_register(&gp16c2t0_hwtimer.parent, ES_DEVICE_NAME_GP16C2T0_HWTIMER, &gp16c2t0_hwtimer);
@ -372,14 +372,14 @@ int rt_hw_hwtimer_init(void)
#ifdef BSP_USING_GP16C2T1_HWTIMER
static timer_handle_t gp16c2t1_hwtimer_periph;
gp16c2t1_hwtimer_periph.perh = GP16C2T1;
gp16c2t1_hwtimer.IRQn = GP16C2T1_IRQn;
gp16c2t1_hwtimer_periph.init.prescaler = ES_GP16C2T1_HWTIMER_PRES - 1;
gp16c2t1_hwtimer_periph.init.prescaler = ES_GP16C2T1_HWTIMER_PRES - 1;
gp16c2t1_hwtimer_periph.init.mode = ( ES_GP16C2T1_HWTIMER_MODE == HWTIMER_CNTMODE_UP )? TIMER_CNT_MODE_UP : TIMER_CNT_MODE_DOWN;
gp16c2t1_hwtimer.hwtimer_periph = &gp16c2t1_hwtimer_periph;
gp16c2t1_hwtimer.parent.info = &gp16c2t1_info;
gp16c2t1_hwtimer.parent.ops = &es32f0_hwtimer_ops;
ret = rt_device_hwtimer_register(&gp16c2t1_hwtimer.parent, ES_DEVICE_NAME_GP16C2T1_HWTIMER, &gp16c2t1_hwtimer);
@ -387,14 +387,14 @@ int rt_hw_hwtimer_init(void)
#ifdef BSP_USING_BS16T0_HWTIMER
static timer_handle_t bs16t0_hwtimer_periph;
bs16t0_hwtimer_periph.perh = BS16T0;
bs16t0_hwtimer.IRQn = BS16T0_IRQn;
bs16t0_hwtimer_periph.init.prescaler = ES_BS16T0_HWTIMER_PRES - 1;
bs16t0_hwtimer_periph.init.prescaler = ES_BS16T0_HWTIMER_PRES - 1;
bs16t0_hwtimer_periph.init.mode = ( ES_BS16T0_HWTIMER_MODE == HWTIMER_CNTMODE_UP )? TIMER_CNT_MODE_UP : TIMER_CNT_MODE_DOWN;
bs16t0_hwtimer.hwtimer_periph = &bs16t0_hwtimer_periph;
bs16t0_hwtimer.parent.info = &bs16t0_info;
bs16t0_hwtimer.parent.ops = &es32f0_hwtimer_ops;
ret = rt_device_hwtimer_register(&bs16t0_hwtimer.parent, ES_DEVICE_NAME_BS16T0_HWTIMER, &bs16t0_hwtimer);
@ -402,14 +402,14 @@ int rt_hw_hwtimer_init(void)
#ifdef BSP_USING_BS16T1_HWTIMER
static timer_handle_t bs16t1_hwtimer_periph;
bs16t1_hwtimer_periph.perh = BS16T1;
bs16t1_hwtimer.IRQn = BS16T1_UART2_IRQn;
bs16t1_hwtimer_periph.init.prescaler = ES_BS16T1_HWTIMER_PRES - 1;
bs16t1_hwtimer_periph.init.prescaler = ES_BS16T1_HWTIMER_PRES - 1;
bs16t1_hwtimer_periph.init.mode = ( ES_BS16T1_HWTIMER_MODE == HWTIMER_CNTMODE_UP )? TIMER_CNT_MODE_UP : TIMER_CNT_MODE_DOWN;
bs16t1_hwtimer.hwtimer_periph = &bs16t1_hwtimer_periph;
bs16t1_hwtimer.parent.info = &bs16t1_info;
bs16t1_hwtimer.parent.ops = &es32f0_hwtimer_ops;
ret = rt_device_hwtimer_register(&bs16t1_hwtimer.parent, ES_DEVICE_NAME_BS16T1_HWTIMER, &bs16t1_hwtimer);
@ -417,14 +417,14 @@ int rt_hw_hwtimer_init(void)
#ifdef BSP_USING_BS16T2_HWTIMER
static timer_handle_t bs16t2_hwtimer_periph;
bs16t2_hwtimer_periph.perh = BS16T2;
bs16t2_hwtimer.IRQn = BS16T2_UART3_IRQn;
bs16t2_hwtimer_periph.init.prescaler = ES_BS16T2_HWTIMER_PRES - 1;
bs16t2_hwtimer_periph.init.prescaler = ES_BS16T2_HWTIMER_PRES - 1;
bs16t2_hwtimer_periph.init.mode = ( ES_BS16T2_HWTIMER_MODE == HWTIMER_CNTMODE_UP )? TIMER_CNT_MODE_UP : TIMER_CNT_MODE_DOWN;
bs16t2_hwtimer.hwtimer_periph = &bs16t2_hwtimer_periph;
bs16t2_hwtimer.parent.info = &bs16t2_info;
bs16t2_hwtimer.parent.ops = &es32f0_hwtimer_ops;
ret = rt_device_hwtimer_register(&bs16t2_hwtimer.parent, ES_DEVICE_NAME_BS16T2_HWTIMER, &bs16t2_hwtimer);
@ -432,14 +432,14 @@ int rt_hw_hwtimer_init(void)
#ifdef BSP_USING_BS16T3_HWTIMER
static timer_handle_t bs16t3_hwtimer_periph;
bs16t3_hwtimer_periph.perh = BS16T3;
bs16t3_hwtimer.IRQn = BS16T3_DAC0_IRQn;
bs16t3_hwtimer_periph.init.prescaler = ES_BS16T3_HWTIMER_PRES - 1;
bs16t3_hwtimer_periph.init.prescaler = ES_BS16T3_HWTIMER_PRES - 1;
bs16t3_hwtimer_periph.init.mode = ( ES_BS16T3_HWTIMER_MODE == HWTIMER_CNTMODE_UP )? TIMER_CNT_MODE_UP : TIMER_CNT_MODE_DOWN;
bs16t3_hwtimer.hwtimer_periph = &bs16t3_hwtimer_periph;
bs16t3_hwtimer.parent.info = &bs16t3_info;
bs16t3_hwtimer.parent.ops = &es32f0_hwtimer_ops;
ret = rt_device_hwtimer_register(&bs16t3_hwtimer.parent, ES_DEVICE_NAME_BS16T3_HWTIMER, &bs16t3_hwtimer);

View File

@ -17,7 +17,7 @@
*
* Change Logs:
* Date Author Notes
* 2019-3-19 wangyq the first version
* 2019-3-19 wangyq the first version
* 2021-04-20 liuhy the second version
*/

View File

@ -54,16 +54,16 @@ static void _i2c_init(void)
gpio_instruct.func = GPIO_FUNC_5;
#ifdef BSP_USING_I2C0
#if defined(ES_I2C0_SCL_GPIO_FUNC)&&defined(ES_I2C0_SCL_GPIO_PORT)&&defined(ES_I2C0_SCL_GPIO_PIN)
#if defined(ES_I2C0_SCL_GPIO_FUNC)&&defined(ES_I2C0_SCL_GPIO_PORT)&&defined(ES_I2C0_SCL_GPIO_PIN)
gpio_instruct.func = ES_I2C0_SCL_GPIO_FUNC;
ald_gpio_init(ES_I2C0_SCL_GPIO_PORT, ES_I2C0_SCL_GPIO_PIN, &gpio_instruct);
#endif
#endif
#if defined(ES_I2C0_SDA_GPIO_FUNC)&&defined(ES_I2C0_SDA_GPIO_PORT)&&defined(ES_I2C0_SDA_GPIO_PIN)
gpio_instruct.func = ES_I2C0_SDA_GPIO_FUNC;
ald_gpio_init(ES_I2C0_SDA_GPIO_PORT, ES_I2C0_SDA_GPIO_PIN, &gpio_instruct);
#endif
ald_gpio_init(ES_I2C0_SDA_GPIO_PORT, ES_I2C0_SDA_GPIO_PIN, &gpio_instruct);
#endif
/* Initialize I2C Function */
_h_i2c0.perh = I2C0;
@ -76,33 +76,33 @@ static void _i2c_init(void)
ald_i2c_reset(&_h_i2c0);
ald_i2c_init(&_h_i2c0);
#endif
#ifdef BSP_USING_I2C1
#if defined(ES_I2C1_SCL_GPIO_FUNC)&&defined(ES_I2C1_SCL_GPIO_PORT)&&defined(ES_I2C1_SCL_GPIO_PIN)
#if defined(ES_I2C1_SCL_GPIO_FUNC)&&defined(ES_I2C1_SCL_GPIO_PORT)&&defined(ES_I2C1_SCL_GPIO_PIN)
gpio_instruct.func = ES_I2C1_SCL_GPIO_FUNC;
ald_gpio_init(ES_I2C1_SCL_GPIO_PORT, ES_I2C1_SCL_GPIO_PIN, &gpio_instruct);
#endif
#if defined(ES_I2C1_SDA_GPIO_FUNC)&&defined(ES_I2C1_SDA_GPIO_PORT)&&defined(ES_I2C1_SDA_GPIO_PIN)
#endif
#if defined(ES_I2C1_SDA_GPIO_FUNC)&&defined(ES_I2C1_SDA_GPIO_PORT)&&defined(ES_I2C1_SDA_GPIO_PIN)
gpio_instruct.func = ES_I2C1_SDA_GPIO_FUNC;
ald_gpio_init(ES_I2C1_SDA_GPIO_PORT, ES_I2C1_SDA_GPIO_PIN, &gpio_instruct);
#endif
#endif
/* Initialize i2c function */
_h_i2c1.perh = I2C1;
_h_i2c1.init.duty = I2C_DUTYCYCLE_2;
_h_i2c1.init.duty = I2C_DUTYCYCLE_2;
_h_i2c1.init.clk_speed = ES_I2C1_CLK_SPEED;
_h_i2c1.init.own_addr1 = ES_I2C1_OWN_ADDR1;
_h_i2c1.init.addr_mode = ES_I2C1_ADDR_MODE;
_h_i2c1.init.general_call = ES_I2C1_GENERAL_CALL;
_h_i2c1.init.no_stretch = ES_I2C1_STRETCH;
ald_i2c_reset(&_h_i2c1);
ald_i2c_init(&_h_i2c1);
#endif
}

View File

@ -1,7 +1,7 @@
/*
* Copyright (C) 2018 Shanghai Eastsoft Microelectronics Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
@ -17,7 +17,7 @@
*
* Change Logs:
* Date Author Notes
* 2019-01-24 wangyq the first version
* 2019-01-24 wangyq the first version
* 2021-04-20 liuhy the second version
*/

View File

@ -22,7 +22,7 @@
* 2020-12-15 liuhy the first version
*/
#include "drv_pm.h"
#include "drv_pm.h"
#ifdef RT_USING_PM
@ -57,18 +57,18 @@ static void sleep(struct rt_pm *pm, uint8_t mode)
ald_pmu_stop1_enter();
break;
case PM_SLEEP_MODE_DEEP:
/* Enter STOP 2 mode */
case PM_SLEEP_MODE_DEEP:
/* Enter STOP 2 mode */
ald_pmu_stop2_enter();
break;
case PM_SLEEP_MODE_STANDBY:
/* Enter STANDBY mode */
/* Enter STANDBY mode */
ald_pmu_stop2_enter();
break;
case PM_SLEEP_MODE_SHUTDOWN:
/* Enter SHUTDOWNN mode */
/* Enter SHUTDOWNN mode */
ald_pmu_stop2_enter();
break;

View File

@ -64,24 +64,24 @@ static rt_err_t es32f0_pwm_control(struct rt_device_pwm *device, int cmd, void *
pwm_channel = TIMER_CHANNEL_1;
_ccep_ch_en = timer_initstruct->perh->CCEP & TIMER_CCEP_CC1EN_MSK;
}
else if (2 == cfg->channel)
else if (2 == cfg->channel)
{
pwm_channel = TIMER_CHANNEL_2;
_ccep_ch_en = timer_initstruct->perh->CCEP & TIMER_CCEP_CC2EN_MSK;
}
else if (3 == cfg->channel)
else if (3 == cfg->channel)
{
pwm_channel = TIMER_CHANNEL_3;
_ccep_ch_en = timer_initstruct->perh->CCEP & TIMER_CCEP_CC3EN_MSK;
}
else if (4 == cfg->channel)
else if (4 == cfg->channel)
{
pwm_channel = TIMER_CHANNEL_4;
_ccep_ch_en = timer_initstruct->perh->CCEP & TIMER_CCEP_CC4EN_MSK;
}
else
return RT_EINVAL;
switch (cmd)
{
case PWM_CMD_ENABLE:
@ -93,11 +93,11 @@ static rt_err_t es32f0_pwm_control(struct rt_device_pwm *device, int cmd, void *
break;
case PWM_CMD_SET:
/*当通道没开的时候:关通道,设置输出模式和极性,初始化通道*/
if(!_ccep_ch_en)
{
tim_ocinit.oc_mode = ES_PWM_OC_MODE;
if(!_ccep_ch_en)
{
tim_ocinit.oc_mode = ES_PWM_OC_MODE;
tim_ocinit.oc_polarity = ES_PWM_OC_POLARITY;
tim_ocinit.oc_fast_en = DISABLE;
tim_ocinit.ocn_polarity = TIMER_OCN_POLARITY_HIGH;
@ -105,32 +105,32 @@ static rt_err_t es32f0_pwm_control(struct rt_device_pwm *device, int cmd, void *
tim_ocinit.oc_idle = TIMER_OC_IDLE_RESET;
ald_timer_oc_config_channel(timer_initstruct, &tim_ocinit, pwm_channel);
}
bus_speed = (uint64_t)ald_cmu_get_pclk1_clock();
/*外设的计数器最大值*/
_maxcnt = 0xFFFF;
/*当最大分频 <= _maxcnt时估计大概的分频加快速度 */
tmp = bus_speed * (cfg->period)/1000000000/_maxcnt;
timer_initstruct->init.prescaler = (tmp > 2U) ? (tmp - 2U) : 0U ; /*bus_speed < 500000000*/
/* count registers max , auto adjust prescaler */
do
{
_arr = bus_speed * (cfg->period) / 1000000000 /(++timer_initstruct->init.prescaler);
}
while (_arr > _maxcnt);
while (_arr > _maxcnt);
WRITE_REG(timer_initstruct->perh->AR, (uint32_t)_arr);
timer_initstruct->init.period = (uint32_t)_arr;
/* update prescaler */
WRITE_REG(timer_initstruct->perh->PRES, --timer_initstruct->init.prescaler);
pwm_set_duty(timer_initstruct, pwm_channel, cfg->pulse);
break;
case PWM_CMD_GET:
@ -170,25 +170,25 @@ int rt_hw_pwm_init(void)
/* gpio initialization */
#if defined(ES_AD16C4T0_CH1_GPIO_FUNC)&&defined(ES_AD16C4T0_CH1_GPIO_PORT)&&defined(ES_AD16C4T0_CH1_GPIO_PIN)
#if defined(ES_AD16C4T0_CH1_GPIO_FUNC)&&defined(ES_AD16C4T0_CH1_GPIO_PORT)&&defined(ES_AD16C4T0_CH1_GPIO_PIN)
gpio_initstructure.func = ES_AD16C4T0_CH1_GPIO_FUNC;
ald_gpio_init(ES_AD16C4T0_CH1_GPIO_PORT, ES_AD16C4T0_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_AD16C4T0_CH2_GPIO_FUNC)&&defined(ES_AD16C4T0_CH2_GPIO_PORT)&&defined(ES_AD16C4T0_CH2_GPIO_PIN)
#endif
#if defined(ES_AD16C4T0_CH2_GPIO_FUNC)&&defined(ES_AD16C4T0_CH2_GPIO_PORT)&&defined(ES_AD16C4T0_CH2_GPIO_PIN)
gpio_initstructure.func = ES_AD16C4T0_CH2_GPIO_FUNC;
ald_gpio_init(ES_AD16C4T0_CH2_GPIO_PORT, ES_AD16C4T0_CH2_GPIO_PIN, &gpio_initstructure);
#endif
#endif
#if defined(ES_AD16C4T0_CH3_GPIO_FUNC)&&defined(ES_AD16C4T0_CH3_GPIO_PORT)&&defined(ES_AD16C4T0_CH3_GPIO_FUNC)
#if defined(ES_AD16C4T0_CH3_GPIO_FUNC)&&defined(ES_AD16C4T0_CH3_GPIO_PORT)&&defined(ES_AD16C4T0_CH3_GPIO_FUNC)
gpio_initstructure.func = ES_AD16C4T0_CH3_GPIO_FUNC;
ald_gpio_init(ES_AD16C4T0_CH3_GPIO_PORT, ES_AD16C4T0_CH3_GPIO_PIN, &gpio_initstructure);
#endif
#endif
#if defined(ES_AD16C4T0_CH4_GPIO_FUNC)&&defined(ES_AD16C4T0_CH4_GPIO_PORT)&&defined(ES_AD16C4T0_CH4_GPIO_PIN)
#if defined(ES_AD16C4T0_CH4_GPIO_FUNC)&&defined(ES_AD16C4T0_CH4_GPIO_PORT)&&defined(ES_AD16C4T0_CH4_GPIO_PIN)
gpio_initstructure.func = ES_AD16C4T0_CH4_GPIO_FUNC;
ald_gpio_init(ES_AD16C4T0_CH4_GPIO_PORT, ES_AD16C4T0_CH4_GPIO_PIN, &gpio_initstructure);
#endif
ald_gpio_init(ES_AD16C4T0_CH4_GPIO_PORT, ES_AD16C4T0_CH4_GPIO_PIN, &gpio_initstructure);
#endif
ret = rt_device_pwm_register(&ad16c4t0_pwm_dev, ES_DEVICE_NAME_AD16C4T0_PWM, &es32f0_pwm_ops,
&ad16c4t0_timer_initstruct);
@ -202,26 +202,26 @@ int rt_hw_pwm_init(void)
ald_timer_pwm_init(&gp16c4t0_timer_initstruct);
/* gpio initialization */
#if defined(ES_GP16C4T0_CH1_GPIO_FUNC)&&defined(ES_GP16C4T0_CH1_GPIO_PORT)&&defined(ES_GP16C4T0_CH1_GPIO_PIN)
gpio_initstructure.func = ES_GP16C4T0_CH1_GPIO_FUNC;
ald_gpio_init(ES_GP16C4T0_CH1_GPIO_PORT, ES_GP16C4T0_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C4T0_CH2_GPIO_FUNC)&&defined(ES_GP16C4T0_CH2_GPIO_PORT)&&defined(ES_GP16C4T0_CH2_GPIO_PIN)
gpio_initstructure.func = ES_GP16C4T0_CH2_GPIO_FUNC;
ald_gpio_init(ES_GP16C4T0_CH2_GPIO_PORT, ES_GP16C4T0_CH2_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C4T0_CH3_GPIO_FUNC)&&defined(ES_GP16C4T0_CH3_GPIO_PORT)&&defined(ES_GP16C4T0_CH3_GPIO_PIN)
#if defined(ES_GP16C4T0_CH1_GPIO_FUNC)&&defined(ES_GP16C4T0_CH1_GPIO_PORT)&&defined(ES_GP16C4T0_CH1_GPIO_PIN)
gpio_initstructure.func = ES_GP16C4T0_CH1_GPIO_FUNC;
ald_gpio_init(ES_GP16C4T0_CH1_GPIO_PORT, ES_GP16C4T0_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C4T0_CH2_GPIO_FUNC)&&defined(ES_GP16C4T0_CH2_GPIO_PORT)&&defined(ES_GP16C4T0_CH2_GPIO_PIN)
gpio_initstructure.func = ES_GP16C4T0_CH2_GPIO_FUNC;
ald_gpio_init(ES_GP16C4T0_CH2_GPIO_PORT, ES_GP16C4T0_CH2_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C4T0_CH3_GPIO_FUNC)&&defined(ES_GP16C4T0_CH3_GPIO_PORT)&&defined(ES_GP16C4T0_CH3_GPIO_PIN)
gpio_initstructure.func = ES_GP16C4T0_CH3_GPIO_FUNC;
ald_gpio_init(ES_GP16C4T0_CH3_GPIO_PORT, ES_GP16C4T0_CH3_GPIO_PIN, &gpio_initstructure);
#endif
#endif
#if defined(ES_GP16C4T0_CH4_GPIO_FUNC)&&defined(ES_GP16C4T0_CH4_GPIO_PORT)&&defined(ES_GP16C4T0_CH4_GPIO_PIN)
gpio_initstructure.func = ES_GP16C4T0_CH4_GPIO_FUNC;
ald_gpio_init(ES_GP16C4T0_CH4_GPIO_PORT, ES_GP16C4T0_CH4_GPIO_PIN, &gpio_initstructure);
#endif
ald_gpio_init(ES_GP16C4T0_CH4_GPIO_PORT, ES_GP16C4T0_CH4_GPIO_PIN, &gpio_initstructure);
#endif
ret = rt_device_pwm_register(&gp16c4t0_pwm_dev, ES_DEVICE_NAME_GP16C4T0_PWM, &es32f0_pwm_ops,
&gp16c4t0_timer_initstruct);
@ -236,16 +236,16 @@ int rt_hw_pwm_init(void)
ald_timer_pwm_init(&gp16c2t0_timer_initstruct);
/* gpio initialization */
#if defined(ES_GP16C2T0_CH1_GPIO_FUNC)&&defined(ES_GP16C2T0_CH1_GPIO_PORT)&&defined(ES_GP16C2T0_CH1_GPIO_PIN)
#if defined(ES_GP16C2T0_CH1_GPIO_FUNC)&&defined(ES_GP16C2T0_CH1_GPIO_PORT)&&defined(ES_GP16C2T0_CH1_GPIO_PIN)
gpio_initstructure.func = ES_GP16C2T0_CH1_GPIO_FUNC;
ald_gpio_init(ES_GP16C2T0_CH1_GPIO_PORT, ES_GP16C2T0_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C2T0_CH2_GPIO_FUNC)&&defined(ES_GP16C2T0_CH2_GPIO_PORT)&&defined(ES_GP16C2T0_CH2_GPIO_PIN)
ald_gpio_init(ES_GP16C2T0_CH1_GPIO_PORT, ES_GP16C2T0_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C2T0_CH2_GPIO_FUNC)&&defined(ES_GP16C2T0_CH2_GPIO_PORT)&&defined(ES_GP16C2T0_CH2_GPIO_PIN)
gpio_initstructure.func = ES_GP16C2T0_CH2_GPIO_FUNC;
ald_gpio_init(ES_GP16C2T0_CH2_GPIO_PORT, ES_GP16C2T0_CH2_GPIO_PIN, &gpio_initstructure);
#endif
ald_gpio_init(ES_GP16C2T0_CH2_GPIO_PORT, ES_GP16C2T0_CH2_GPIO_PIN, &gpio_initstructure);
#endif
ret = rt_device_pwm_register(&gp16c2t0_pwm_dev, ES_DEVICE_NAME_GP16C2T0_PWM, &es32f0_pwm_ops,
&gp16c2t0_timer_initstruct);
@ -260,16 +260,16 @@ int rt_hw_pwm_init(void)
ald_timer_pwm_init(&gp16c2t1_timer_initstruct);
/* gpio initialization */
#if defined(ES_GP16C2T1_CH1_GPIO_FUNC)&&defined(ES_GP16C2T1_CH1_GPIO_PORT)&&defined(ES_GP16C2T1_CH1_GPIO_PIN)
#if defined(ES_GP16C2T1_CH1_GPIO_FUNC)&&defined(ES_GP16C2T1_CH1_GPIO_PORT)&&defined(ES_GP16C2T1_CH1_GPIO_PIN)
gpio_initstructure.func = ES_GP16C2T1_CH1_GPIO_FUNC;
ald_gpio_init(ES_GP16C2T1_CH1_GPIO_PORT, ES_GP16C2T1_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C2T1_CH2_GPIO_FUNC)&&defined(ES_GP16C2T1_CH2_GPIO_PORT)&&defined(ES_GP16C2T1_CH2_GPIO_PIN)
ald_gpio_init(ES_GP16C2T1_CH1_GPIO_PORT, ES_GP16C2T1_CH1_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_GP16C2T1_CH2_GPIO_FUNC)&&defined(ES_GP16C2T1_CH2_GPIO_PORT)&&defined(ES_GP16C2T1_CH2_GPIO_PIN)
gpio_initstructure.func = ES_GP16C2T1_CH2_GPIO_FUNC;
ald_gpio_init(ES_GP16C2T1_CH2_GPIO_PORT, ES_GP16C2T1_CH2_GPIO_PIN, &gpio_initstructure);
#endif
ald_gpio_init(ES_GP16C2T1_CH2_GPIO_PORT, ES_GP16C2T1_CH2_GPIO_PIN, &gpio_initstructure);
#endif
ret = rt_device_pwm_register(&gp16c2t1_pwm_dev, ES_DEVICE_NAME_GP16C2T1_PWM, &es32f0_pwm_ops,
&gp16c2t1_timer_initstruct);

View File

@ -24,11 +24,11 @@
#include <rthw.h>
#include <rtthread.h>
#include <rtdevice.h>
#include <rtdevice.h>
#include <sys/time.h>
#include <string.h>
#include "board.h"
#include "drv_rtc.h"
#include "drv_rtc.h"
#ifdef RT_USING_RTC
@ -129,7 +129,7 @@ int rt_hw_rtc_init(void)
rt_err_t ret = RT_EOK;
static struct rt_device rtc_dev;
rtc_init_t rtc_initstruct;
/* enable clk */
ald_rtc_source_select(ES_RTC_CLK_SOURCE);
@ -138,7 +138,7 @@ int rt_hw_rtc_init(void)
CMU_LOSC_ENABLE();
ald_cmu_losc_safe_config(ENABLE);
}
/* set default time */
RTC_UNLOCK();
WRITE_REG(RTC->TIME, 0x134251);
@ -150,7 +150,7 @@ int rt_hw_rtc_init(void)
rtc_initstruct.synch_pre_div = 32767;
rtc_initstruct.output = RTC_OUTPUT_DISABLE;
rtc_initstruct.output_polarity = RTC_OUTPUT_POLARITY_HIGH;
__rtc_init(&rtc_initstruct);
rtc_dev.type = RT_Device_Class_RTC;

View File

@ -17,7 +17,7 @@
*
* Change Logs:
* Date Author Notes
* 2019-03-22 wangyq the first version
* 2019-03-22 wangyq the first version
* 2021-04-20 liuhy the second version
*/

View File

@ -77,7 +77,7 @@ rt_err_t spi_configure(struct rt_spi_device *device,
{
hspi->init.phase = SPI_CPHA_FIRST;
}
if (cfg->mode & RT_SPI_MSB)
{
hspi->init.first_bit = SPI_FIRSTBIT_MSB;
@ -86,7 +86,7 @@ rt_err_t spi_configure(struct rt_spi_device *device,
{
hspi->init.first_bit = SPI_FIRSTBIT_LSB;
}
if (cfg->mode & RT_SPI_CPOL)
{
hspi->init.polarity = SPI_CPOL_HIGH;
@ -95,7 +95,7 @@ rt_err_t spi_configure(struct rt_spi_device *device,
{
hspi->init.polarity = SPI_CPOL_LOW;
}
if (cfg->mode & RT_SPI_NO_CS)
{
hspi->init.ss_en = DISABLE;
@ -179,7 +179,7 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
{
rt_pin_write(cs->pin, ES_SPI_CS_LEVEL);
}
if(message->send_buf != RT_NULL || message->recv_buf != RT_NULL)
{
/* send & receive */
@ -201,28 +201,28 @@ static rt_uint32_t spixfer(struct rt_spi_device *device, struct rt_spi_message *
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, !ES_SPI_CS_LEVEL);
}
if (res != RT_EOK)
if (res != RT_EOK)
return RT_ERROR;
else
else
return message->length;
}
else
{
if (message->cs_release)
{
rt_pin_write(cs->pin, !ES_SPI_CS_LEVEL);
}
return RT_EOK;
}
}
const struct rt_spi_ops es32f0_spi_ops =
@ -243,16 +243,16 @@ rt_err_t es32f0_spi_device_attach(rt_uint32_t pin, const char *bus_name, const c
cs_pin->pin = pin;
rt_pin_mode(pin, PIN_MODE_OUTPUT);
rt_pin_write(pin, 1);
result = rt_spi_bus_attach_device(spi_device, device_name, bus_name, (void *)cs_pin);
#ifdef BSP_USING_SPI0
if(!(strcmp(bus_name,ES_DEVICE_NAME_SPI0_BUS)))SPI_BUS_CONFIG(spi_device->config,0);
#endif
#ifdef BSP_USING_SPI1
if(!(strcmp(bus_name,ES_DEVICE_NAME_SPI1_BUS)))SPI_BUS_CONFIG(spi_device->config,1);
#endif
#ifdef BSP_USING_SPI0
if(!(strcmp(bus_name,ES_DEVICE_NAME_SPI0_BUS)))SPI_BUS_CONFIG(spi_device->config,0);
#endif
#ifdef BSP_USING_SPI1
if(!(strcmp(bus_name,ES_DEVICE_NAME_SPI1_BUS)))SPI_BUS_CONFIG(spi_device->config,1);
#endif
return result;
}
@ -274,8 +274,8 @@ int rt_hw_spi_init(void)
spi_handle_t *spi;
gpio_init_t gpio_instruct;
gpio_instruct.odos = GPIO_PUSH_PULL;
gpio_instruct.type = GPIO_TYPE_CMOS;
gpio_instruct.odos = GPIO_PUSH_PULL;
gpio_instruct.type = GPIO_TYPE_CMOS;
gpio_instruct.flt = GPIO_FILTER_DISABLE;
gpio_instruct.odrv = GPIO_OUT_DRIVE_NORMAL;
#ifdef BSP_USING_SPI0
@ -289,19 +289,19 @@ int rt_hw_spi_init(void)
#if defined(ES_SPI0_SCK_GPIO_FUNC)&&defined(ES_SPI0_SCK_GPIO_PORT)&&defined(ES_SPI0_SCK_GPIO_PIN)
gpio_instruct.func = ES_SPI0_SCK_GPIO_FUNC;
ald_gpio_init(ES_SPI0_SCK_GPIO_PORT, ES_SPI0_SCK_GPIO_PIN, &gpio_instruct);
#endif
#endif
#if defined(ES_SPI0_MOSI_GPIO_FUNC)&&defined(ES_SPI0_MOSI_GPIO_PORT)&&defined(ES_SPI0_MOSI_GPIO_PIN)
#if defined(ES_SPI0_MOSI_GPIO_FUNC)&&defined(ES_SPI0_MOSI_GPIO_PORT)&&defined(ES_SPI0_MOSI_GPIO_PIN)
gpio_instruct.func = ES_SPI0_MOSI_GPIO_FUNC;
ald_gpio_init(ES_SPI0_MOSI_GPIO_PORT, ES_SPI0_MOSI_GPIO_PIN, &gpio_instruct);
#endif
#endif
gpio_instruct.mode = GPIO_MODE_INPUT;
#if defined(ES_SPI0_MISO_GPIO_FUNC)&&defined(ES_SPI0_MISO_GPIO_PORT)&&defined(ES_SPI0_MISO_GPIO_PIN)
#if defined(ES_SPI0_MISO_GPIO_FUNC)&&defined(ES_SPI0_MISO_GPIO_PORT)&&defined(ES_SPI0_MISO_GPIO_PIN)
gpio_instruct.func = ES_SPI0_MISO_GPIO_FUNC;
ald_gpio_init(ES_SPI0_MISO_GPIO_PORT, ES_SPI0_MISO_GPIO_PIN, &gpio_instruct);
#endif
#endif
spi_bus->parent.user_data = spi;
result = rt_spi_bus_register(spi_bus, ES_DEVICE_NAME_SPI0_BUS, &es32f0_spi_ops);
@ -309,9 +309,9 @@ int rt_hw_spi_init(void)
{
return result;
}
result = es32f0_spi_device_attach(ES_SPI0_NSS_PIN, ES_DEVICE_NAME_SPI0_BUS, ES_DEVICE_NAME_SPI0_DEV0);
if (result != RT_EOK)
{
return result;
@ -326,23 +326,23 @@ int rt_hw_spi_init(void)
/* SPI1 gpio init */
gpio_instruct.mode = GPIO_MODE_OUTPUT;
#if defined(ES_SPI1_SCK_GPIO_FUNC)&&defined(ES_SPI1_SCK_GPIO_PORT)&&defined(ES_SPI1_SCK_GPIO_PIN)
gpio_instruct.func = ES_SPI1_SCK_GPIO_FUNC;
ald_gpio_init(ES_SPI1_SCK_GPIO_PORT, ES_SPI1_SCK_GPIO_PIN, &gpio_instruct);
#endif
#if defined(ES_SPI1_MOSI_GPIO_FUNC)&&defined(ES_SPI1_MOSI_GPIO_PORT)&&defined(ES_SPI1_MOSI_GPIO_PIN)
ald_gpio_init(ES_SPI1_SCK_GPIO_PORT, ES_SPI1_SCK_GPIO_PIN, &gpio_instruct);
#endif
#if defined(ES_SPI1_MOSI_GPIO_FUNC)&&defined(ES_SPI1_MOSI_GPIO_PORT)&&defined(ES_SPI1_MOSI_GPIO_PIN)
gpio_instruct.func = ES_SPI1_MOSI_GPIO_FUNC;
ald_gpio_init(ES_SPI1_MOSI_GPIO_PORT, ES_SPI1_MOSI_GPIO_PIN, &gpio_instruct);
#endif
ald_gpio_init(ES_SPI1_MOSI_GPIO_PORT, ES_SPI1_MOSI_GPIO_PIN, &gpio_instruct);
#endif
gpio_instruct.mode = GPIO_MODE_INPUT;
#if defined(ES_SPI1_MISO_GPIO_FUNC)&&defined(ES_SPI1_MISO_GPIO_PORT)&&defined(ES_SPI1_MISO_GPIO_PIN)
#if defined(ES_SPI1_MISO_GPIO_FUNC)&&defined(ES_SPI1_MISO_GPIO_PORT)&&defined(ES_SPI1_MISO_GPIO_PIN)
gpio_instruct.func = ES_SPI1_MISO_GPIO_FUNC;
ald_gpio_init(ES_SPI1_MISO_GPIO_PORT, ES_SPI1_MISO_GPIO_PIN, &gpio_instruct);
#endif
ald_gpio_init(ES_SPI1_MISO_GPIO_PORT, ES_SPI1_MISO_GPIO_PIN, &gpio_instruct);
#endif
spi_bus->parent.user_data = spi;
result = rt_spi_bus_register(spi_bus, ES_DEVICE_NAME_SPI1_BUS, &es32f0_spi_ops);
@ -350,13 +350,13 @@ int rt_hw_spi_init(void)
{
return result;
}
result = es32f0_spi_device_attach((ES_SPI1_NSS_PIN, ES_DEVICE_NAME_SPI1_BUS, ES_DEVICE_NAME_SPI1_DEV0);
if (result != RT_EOK)
{
return result;
}
#endif
return result;

View File

@ -17,7 +17,7 @@
*
* Change Logs:
* Date Author Notes
* 2019-01-24 wangyq the first version
* 2019-01-24 wangyq the first version
* 2021-04-20 liuhy the second version
*/
@ -27,7 +27,7 @@
#include <rtthread.h>
#include <rthw.h>
#include <rtdevice.h>
#include "es_conf_info_spi.h"
struct es32f0_hw_spi_cs

View File

@ -21,7 +21,7 @@
int rt_hw_spi_flash_init(void)
{
if (RT_NULL == rt_sfud_flash_probe(ES_DEVICE_NAME_SPI_FALSH_DEV, ES_DEVICE_NAME_SPI_DEV))
{
return -RT_ERROR;

View File

@ -18,7 +18,7 @@
* Change Logs:
* Date Author Notes
* 2019-01-23 wangyq the first version
* 2019-11-01 wangyq update libraries
* 2019-11-01 wangyq update libraries
* 2021-04-20 liuhy the second version
*/
@ -35,7 +35,7 @@ struct es32_uart
{
uart_handle_t huart;
IRQn_Type irq;
};
};
/* es32 usart driver */
struct es32_usart
@ -139,7 +139,7 @@ void BS16T2_UART3_Handler(void)
rt_interrupt_leave();
}
#endif /* BSP_USING_UART3 */
#ifdef BSP_USING_USART0
/* USART0 device driver structure */
struct es32_usart usart0 =
@ -208,7 +208,7 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
{
/*USART*/
struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
#ifdef BSP_USING_USART0
if(usart == (&usart0))
{
@ -217,7 +217,7 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
ald_gpio_init(ES_USART0_TX_GPIO_PORT, ES_USART0_TX_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_USART0_RX_GPIO_FUNC)&&defined(ES_USART0_RX_GPIO_PORT)&&defined(ES_USART0_RX_GPIO_PIN)
#if defined(ES_USART0_RX_GPIO_FUNC)&&defined(ES_USART0_RX_GPIO_PORT)&&defined(ES_USART0_RX_GPIO_PIN)
/* Initialize rx pin ,the same as txpin except mode */
gpio_initstructure.mode = GPIO_MODE_INPUT;
gpio_initstructure.func = ES_USART0_RX_GPIO_FUNC;
@ -225,18 +225,18 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
#endif
ald_cmu_perh_clock_config(CMU_PERH_USART0, ENABLE);
}
#endif /* usart0 gpio init */
#ifdef BSP_USING_USART1
if(usart == (&usart1))
{
#if defined(ES_USART1_TX_GPIO_FUNC)&&defined(ES_USART1_TX_GPIO_PORT)&&defined(ES_USART1_TX_GPIO_PIN)
#if defined(ES_USART1_TX_GPIO_FUNC)&&defined(ES_USART1_TX_GPIO_PORT)&&defined(ES_USART1_TX_GPIO_PIN)
gpio_initstructure.func = ES_USART1_TX_GPIO_FUNC;
ald_gpio_init(ES_USART1_TX_GPIO_PORT, ES_USART1_TX_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_USART1_RX_GPIO_FUNC)&&defined(ES_USART1_RX_GPIO_PORT)&&defined(ES_USART1_RX_GPIO_PIN)
#if defined(ES_USART1_RX_GPIO_FUNC)&&defined(ES_USART1_RX_GPIO_PORT)&&defined(ES_USART1_RX_GPIO_PIN)
/* Initialize rx pin ,the same as txpin except mode */
gpio_initstructure.mode = GPIO_MODE_INPUT;
gpio_initstructure.func = ES_USART1_RX_GPIO_FUNC;
@ -246,29 +246,29 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
ald_cmu_perh_clock_config(CMU_PERH_USART1, ENABLE);
}
#endif /* usart1 gpio init */
usart->huart.init.mode = USART_MODE_TX_RX;
usart->huart.init.baud = cfg->baud_rate;
usart->huart.init.word_length = (usart_word_length_t)(cfg->data_bits - 8);
usart->huart.init.baud = cfg->baud_rate;
usart->huart.init.word_length = (usart_word_length_t)(cfg->data_bits - 8);
usart->huart.init.stop_bits = ((cfg->stop_bits == STOP_BITS_1) ? USART_STOP_BITS_1 : USART_STOP_BITS_2);
usart->huart.init.parity = (usart_parity_t)(cfg->parity == PARITY_NONE ? cfg->parity : (4 - cfg->parity) );
usart->huart.init.fctl = USART_HW_FLOW_CTL_NONE;
usart->huart.init.fctl = USART_HW_FLOW_CTL_NONE;
ald_usart_init(&usart->huart);
/*
BIT_ORDER_LSB BIT_ORDER_MSB
NRZ_NORMAL NRZ_INVERTED
*/
/*
BIT_ORDER_LSB BIT_ORDER_MSB
NRZ_NORMAL NRZ_INVERTED
*/
/* enable rx int */
ald_usart_interrupt_config(&usart->huart, USART_IT_RXNE, ENABLE);
ald_usart_interrupt_config(&usart->huart, USART_IT_RXNE, ENABLE);
}
else
{
/*UART*/
#ifdef BSP_USING_UART0
if(uart == (&uart0))
{
@ -277,7 +277,7 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
ald_gpio_init(ES_UART0_TX_GPIO_PORT, ES_UART0_TX_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_UART0_RX_GPIO_FUNC)&&defined(ES_UART0_RX_GPIO_PORT)&&defined(ES_UART0_RX_GPIO_PIN)
#if defined(ES_UART0_RX_GPIO_FUNC)&&defined(ES_UART0_RX_GPIO_PORT)&&defined(ES_UART0_RX_GPIO_PIN)
/* Initialize rx pin ,the same as txpin except mode */
gpio_initstructure.mode = GPIO_MODE_INPUT;
gpio_initstructure.func = ES_UART0_RX_GPIO_FUNC;
@ -285,18 +285,18 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
#endif
ald_cmu_perh_clock_config(CMU_PERH_UART0, ENABLE);
}
#endif /* uart0 gpio init */
#ifdef BSP_USING_UART1
if(uart == (&uart1))
{
#if defined(ES_UART1_TX_GPIO_FUNC)&&defined(ES_UART1_TX_GPIO_PORT)&&defined(ES_UART1_TX_GPIO_PIN)
#if defined(ES_UART1_TX_GPIO_FUNC)&&defined(ES_UART1_TX_GPIO_PORT)&&defined(ES_UART1_TX_GPIO_PIN)
gpio_initstructure.func = ES_UART1_TX_GPIO_FUNC;
ald_gpio_init(ES_UART1_TX_GPIO_PORT, ES_UART1_TX_GPIO_PIN, &gpio_initstructure);
#endif
#if defined(ES_UART1_RX_GPIO_FUNC)&&defined(ES_UART1_RX_GPIO_PORT)&&defined(ES_UART1_RX_GPIO_PIN)
#if defined(ES_UART1_RX_GPIO_FUNC)&&defined(ES_UART1_RX_GPIO_PORT)&&defined(ES_UART1_RX_GPIO_PIN)
/* Initialize rx pin ,the same as txpin except mode */
gpio_initstructure.mode = GPIO_MODE_INPUT;
gpio_initstructure.func = ES_UART1_RX_GPIO_FUNC;
@ -306,7 +306,7 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
ald_cmu_perh_clock_config(CMU_PERH_UART1, ENABLE);
}
#endif /* uart1 gpio init */
#ifdef BSP_USING_UART2
if(uart == (&uart2))
{
@ -325,11 +325,11 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
ald_cmu_perh_clock_config(CMU_PERH_UART2, ENABLE);
}
#endif /* uart2 gpio init */
#ifdef BSP_USING_UART3
if(uart == (&uart3))
{
#if defined(ES_UART3_TX_GPIO_FUNC)&&defined(ES_UART3_TX_GPIO_PORT)&&defined(ES_UART3_TX_GPIO_PIN)
#if defined(ES_UART3_TX_GPIO_FUNC)&&defined(ES_UART3_TX_GPIO_PORT)&&defined(ES_UART3_TX_GPIO_PIN)
gpio_initstructure.func = ES_UART3_TX_GPIO_FUNC;
ald_gpio_init(ES_UART3_TX_GPIO_PORT, ES_UART3_TX_GPIO_PIN, &gpio_initstructure);
#endif
@ -341,16 +341,16 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
ald_gpio_init(ES_UART3_RX_GPIO_PORT, ES_UART3_RX_GPIO_PIN, &gpio_initstructure);
#endif
ald_cmu_perh_clock_config(CMU_PERH_UART3, ENABLE);
ald_cmu_perh_clock_config(CMU_PERH_UART3, ENABLE);
}
#endif /* uart3 gpio init */
uart->huart.init.mode = UART_MODE_UART;
uart->huart.init.baud = cfg->baud_rate;
uart->huart.init.word_length = (uart_word_length_t)(cfg->data_bits - 5);
uart->huart.init.baud = cfg->baud_rate;
uart->huart.init.word_length = (uart_word_length_t)(cfg->data_bits - 5);
uart->huart.init.stop_bits = (uart_stop_bits_t)cfg->stop_bits;
uart->huart.init.parity = (uart_parity_t)(cfg->parity == PARITY_EVEN ? UART_PARITY_EVEN : cfg->parity);
uart->huart.init.fctl = UART_HW_FLOW_CTL_DISABLE;
uart->huart.init.fctl = UART_HW_FLOW_CTL_DISABLE;
ald_uart_init(&uart->huart);
@ -374,9 +374,9 @@ static rt_err_t es32f0x_configure(struct rt_serial_device *serial, struct serial
/* enable rx int */
ald_uart_interrupt_config(&uart->huart, UART_IT_RXRD, ENABLE);
}
return RT_EOK;
}
@ -387,12 +387,12 @@ static rt_err_t es32f0x_control(struct rt_serial_device *serial, int cmd, void *
RT_ASSERT(serial != RT_NULL);
uart = (struct es32_uart *)serial->parent.user_data;
if((uint32_t)(uart->huart.perh) > (uint32_t)UART3) /*根据外设物理地址区分UART和USART*/
{
{
/*USART*/
struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
switch (cmd)
{
case RT_DEVICE_CTRL_CLR_INT:
@ -409,12 +409,12 @@ static rt_err_t es32f0x_control(struct rt_serial_device *serial, int cmd, void *
ald_usart_interrupt_config(&usart->huart, USART_IT_RXNE, ENABLE);
break;
}
}
else
{
else
{
/*UART*/
switch (cmd)
{
case RT_DEVICE_CTRL_CLR_INT:
@ -432,7 +432,7 @@ static rt_err_t es32f0x_control(struct rt_serial_device *serial, int cmd, void *
break;
}
}
return RT_EOK;
}
@ -442,17 +442,17 @@ static int es32f0x_putc(struct rt_serial_device *serial, char c)
struct es32_uart *uart;
RT_ASSERT(serial != RT_NULL);
uart = (struct es32_uart *)serial->parent.user_data;
if((uint32_t)(uart->huart.perh) > (uint32_t)UART3) /*根据外设物理地址区分UART和USART*/
{
{
/*USART*/
struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
while (!(usart->huart.perh->STAT & USART_STAT_TXEMPIF_MSK)) ;
WRITE_REG(usart->huart.perh->DATA, c);
}
else
{
/*UART*/
else
{
/*UART*/
while (!(uart->huart.perh->SR & 0x40)) ;
WRITE_REG(uart->huart.perh->TBR, c);
}
@ -467,19 +467,19 @@ static int es32f0x_getc(struct rt_serial_device *serial)
RT_ASSERT(serial != RT_NULL);
uart = (struct es32_uart *)serial->parent.user_data;
if((uint32_t)(uart->huart.perh) > (uint32_t)UART3) /*根据外设物理地址区分UART和USART*/
{
{
/*USART*/
struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
struct es32_usart *usart= (struct es32_usart *)serial->parent.user_data;
if (usart->huart.perh->STAT & USART_STAT_RXNEIF_MSK)
{
ch = (uint8_t)(usart->huart.perh->DATA & 0xFF);
}
}
else
{
/*UART*/
else
{
/*UART*/
if (uart->huart.perh->SR & 0x01)
{
ch = (uint8_t)(uart->huart.perh->RBR & 0xFF);
@ -501,7 +501,7 @@ int rt_hw_uart_init(void)
{
#if (defined(BSP_USING_UART0)||defined(BSP_USING_UART1)||defined(BSP_USING_UART2)||defined(BSP_USING_UART3))
struct es32_uart *uart;
#endif
#endif
#if (defined(BSP_USING_USART0)||defined(BSP_USING_USART1))
struct es32_usart *usart;
#endif
@ -549,7 +549,7 @@ int rt_hw_uart_init(void)
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
uart);
#endif /* BSP_USING_UART3 */
#ifdef BSP_USING_USART0
usart = &usart0;
serial4.ops = &es32f0x_uart_ops;