update es32f0654 , es32f369x drivers.

This commit is contained in:
liuhy 2021-09-10 18:13:18 +08:00
parent ca77bbfb0a
commit 0f6a753992
25 changed files with 186 additions and 72 deletions

View File

@ -127,6 +127,8 @@ void SysTick_Configuration(void)
{ {
/* ticks = sysclk / RT_TICK_PER_SECOND */ /* ticks = sysclk / RT_TICK_PER_SECOND */
SysTick_Config(ald_cmu_get_sys_clock() / RT_TICK_PER_SECOND); SysTick_Config(ald_cmu_get_sys_clock() / RT_TICK_PER_SECOND);
__systick_interval = 1;
} }
/** /**

View File

@ -64,8 +64,6 @@ static void i2c_io_sample(int argc, char *argv[])
temp_msg.flags = RT_I2C_RD; /* I2C读 */ temp_msg.flags = RT_I2C_RD; /* I2C读 */
s_stat = rt_i2c_transfer(i2c_bus,&temp_msg,num_msg); /* 传输消息 */ s_stat = rt_i2c_transfer(i2c_bus,&temp_msg,num_msg); /* 传输消息 */
rt_thread_mdelay(400);
if( s_stat == num_msg ) if( s_stat == num_msg )
{ {
rt_kprintf("receive successful. \n receive messege : %s \n:",buffer); rt_kprintf("receive successful. \n receive messege : %s \n:",buffer);
@ -87,8 +85,6 @@ static void i2c_io_sample(int argc, char *argv[])
temp_msg.flags = RT_I2C_WR; /* I2C写 */ temp_msg.flags = RT_I2C_WR; /* I2C写 */
s_stat = rt_i2c_transfer(i2c_bus,&temp_msg,num_msg); /* 传输一条 */ s_stat = rt_i2c_transfer(i2c_bus,&temp_msg,num_msg); /* 传输一条 */
rt_thread_mdelay(400);
if( s_stat == num_msg ) if( s_stat == num_msg )
{ {
rt_kprintf(" send successful \n messege : %s \n:",buffer); rt_kprintf(" send successful \n messege : %s \n:",buffer);

View File

@ -19,9 +19,10 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include <stdlib.h> #include <stdlib.h>
#include "drv_gpio.h"
/* PIN脚编号查看驱动文件drv_gpio.c确定 */ /* PIN脚编号查看驱动文件drv_gpio.c确定 */
#define LED_PIN_NUM 40 /*PB9*/ #define LED_PIN_NUM GET_PIN(B,9) /*PB9*/
static int pin_num; static int pin_num;
static void led_entry(void *parameter) static void led_entry(void *parameter)

View File

@ -16,16 +16,17 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include "drv_gpio.h"
/* 引脚编号通过查看驱动文件drv_gpio.c确定 */ /* 引脚编号通过查看驱动文件drv_gpio.c确定 */
#ifndef BEEP_PIN_NUM #ifndef BEEP_PIN_NUM
#define BEEP_PIN_NUM 40 /* PB9 */ #define BEEP_PIN_NUM GET_PIN(B,9) /* PB9 */
#endif #endif
#ifndef KEY0_PIN_NUM #ifndef KEY0_PIN_NUM
#define KEY0_PIN_NUM 18 /* PF0 */ #define KEY0_PIN_NUM GET_PIN(F,0) /* PF0 */
#endif #endif
#ifndef KEY1_PIN_NUM #ifndef KEY1_PIN_NUM
#define KEY1_PIN_NUM 19 /* PF1 */ #define KEY1_PIN_NUM GET_PIN(F,1) /* PF1 */
#endif #endif
void beep_on(void *args) void beep_on(void *args)

View File

@ -30,11 +30,12 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include "drv_gpio.h"
#ifdef RT_USING_PM #ifdef RT_USING_PM
#define PM_NAME "pm" /* 设备名称 */ #define PM_NAME "pm" /* 设备名称 */
#define WAKE_UP_PIN 19 /* 唤醒源 */ #define WAKE_UP_PIN GET_PIN(F,0) /* 唤醒源 */
#define SLEEP_TIMES 12 /* 进入睡眠次数,轮流进入不同的睡眠模式,包括无睡眠模式 */ #define SLEEP_TIMES 12 /* 进入睡眠次数,轮流进入不同的睡眠模式,包括无睡眠模式 */

View File

@ -16,13 +16,13 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include "drv_gpio.h"
#ifdef RT_USING_PWM #ifdef RT_USING_PWM
#define LED_PIN_NUM 16 /* LED PIN脚编号查看驱动文件drv_gpio.c确定 */ #define LED_PIN_NUM GET_PIN(A,2) /* LED PIN脚编号查看驱动文件drv_gpio.c确定 */
#define PWM_DEV_NAME "pwm1" /* PWM设备名称 */ #define PWM_DEV_NAME "pwm1" /* PWM设备名称 */
#define PWM_DEV_CHANNEL 1 /* PA8 PWM通道 */ #define PWM_DEV_CHANNEL 1 /* PWM通道 */
struct rt_device_pwm *pwm_dev; /* PWM设备句柄 */ struct rt_device_pwm *pwm_dev; /* PWM设备句柄 */

View File

@ -12,16 +12,28 @@
* uart_sample * uart_sample
* uart_sample uart2 * uart_sample uart2
* 使使 * 使使
* "hello RT-Thread!" * "hello RT-Thread!"
*/ */
#include <rtthread.h> #include <rtthread.h>
#define SAMPLE_UART_NAME "uart2" /* 串口设备名称 */ /* 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 struct rt_semaphore rx_sem;
static rt_device_t serial; static rt_device_t serial;
/* 接收数据回调函数 */ /* 接收数据回调函数 */
static rt_err_t uart_input(rt_device_t dev, rt_size_t size) static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
@ -33,7 +45,8 @@ static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
} }
static void serial_thread_entry(void *parameter) static void serial_thread_entry(void *parameter)
{ {
#if (UART_SAMPLE_TYPE == 1)
char ch; char ch;
while (1) while (1)
@ -48,6 +61,42 @@ static void serial_thread_entry(void *parameter)
ch = ch + 1; ch = ch + 1;
rt_device_write(serial, 0, &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[]) static int uart_sample(int argc, char *argv[])

View File

@ -418,14 +418,14 @@ static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t
} }
/* clear TIR */ /* clear TIR */
h_can->perh->TxMailBox[box_num].TXID &= CAN_TXID0_TXMREQ_MSK; 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) if (RT_CAN_STDID == pmsg->ide)
{ {
h_can->perh->TxMailBox[box_num].TXID |= (txheader.std << CAN_TXID0_STDID_POSS) | txheader.rtr; h_can->perh->TxMailBox[box_num].TXID |= (txheader.std << CAN_TXID0_STDID_POSS) | (txheader.rtr << CAN_TXID0_RTR_POS);
} }
else else
{ {
h_can->perh->TxMailBox[box_num].TXID |= (txheader.ext << CAN_TXID0_EXID_POSS) | txheader.type | txheader.rtr; h_can->perh->TxMailBox[box_num].TXID |= (txheader.ext << CAN_TXID0_EXID_POSS) | (txheader.type << CAN_TXID0_IDE_POS) | (txheader.rtr << CAN_TXID0_RTR_POS);
} }
/* Set up the DLC */ /* Set up the DLC */
h_can->perh->TxMailBox[box_num].TXFCON = pmsg->len & 0x0FU; h_can->perh->TxMailBox[box_num].TXFCON = pmsg->len & 0x0FU;

View File

@ -314,12 +314,18 @@ 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) rt_inline const struct pin_irq_map *get_pin_irq_map(rt_uint16_t gpio_pin)
{ {
rt_int32_t mapindex = gpio_pin & 0x00FF; uint8_t map_index = 0U;
if (mapindex < 0 || mapindex >= ITEM_NUM(pin_irq_map))
while(gpio_pin >> (++map_index))
{
}
map_index--;
if (map_index >= ITEM_NUM(pin_irq_map))
{ {
return RT_NULL; return RT_NULL;
} }
return &pin_irq_map[mapindex]; return &pin_irq_map[map_index];
}; };
rt_err_t es32f0_pin_attach_irq(struct rt_device *device, rt_int32_t pin, rt_err_t es32f0_pin_attach_irq(struct rt_device *device, rt_int32_t pin,

View File

@ -26,6 +26,8 @@
#include "es_conf_info_gpio.h" #include "es_conf_info_gpio.h"
#define GET_PIN(port,pin) (ES_PIN_GPIO_##port##_##pin)
int rt_hw_pin_init(void); int rt_hw_pin_init(void);
#endif #endif

View File

@ -81,9 +81,9 @@ static void _i2c_init(void)
#ifdef BSP_USING_I2C1 #ifdef BSP_USING_I2C1
#if defined(ES_I2C1_SDA_GPIO_FUNC)&&defined(ES_I2C1_SDA_GPIO_PORT)&&defined(ES_I2C1_SDA_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_SDA_GPIO_FUNC; gpio_instruct.func = ES_I2C1_SCL_GPIO_FUNC;
ald_gpio_init(ES_I2C1_SDA_GPIO_PORT, ES_I2C1_SDA_GPIO_PIN, &gpio_instruct); ald_gpio_init(ES_I2C1_SCL_GPIO_PORT, ES_I2C1_SCL_GPIO_PIN, &gpio_instruct);
#endif #endif
#if defined(ES_I2C1_SDA_GPIO_FUNC)&&defined(ES_I2C1_SDA_GPIO_PORT)&&defined(ES_I2C1_SDA_GPIO_PIN) #if defined(ES_I2C1_SDA_GPIO_FUNC)&&defined(ES_I2C1_SDA_GPIO_PORT)&&defined(ES_I2C1_SDA_GPIO_PIN)

View File

@ -129,6 +129,8 @@ void SysTick_Configuration(void)
{ {
/* ticks = sysclk / RT_TICK_PER_SECOND */ /* ticks = sysclk / RT_TICK_PER_SECOND */
SysTick_Config(ald_cmu_get_sys_clock() / RT_TICK_PER_SECOND); SysTick_Config(ald_cmu_get_sys_clock() / RT_TICK_PER_SECOND);
__systick_interval = 1;
} }
/** /**

View File

@ -64,8 +64,6 @@ static void i2c_io_sample(int argc, char *argv[])
temp_msg.flags = RT_I2C_RD; /* I2C读 */ temp_msg.flags = RT_I2C_RD; /* I2C读 */
s_stat = rt_i2c_transfer(i2c_bus,&temp_msg,num_msg); /* 传输消息 */ s_stat = rt_i2c_transfer(i2c_bus,&temp_msg,num_msg); /* 传输消息 */
rt_thread_mdelay(400);
if( s_stat == num_msg ) if( s_stat == num_msg )
{ {
rt_kprintf("receive successful. \n receive messege : %s \n:",buffer); rt_kprintf("receive successful. \n receive messege : %s \n:",buffer);
@ -87,8 +85,6 @@ static void i2c_io_sample(int argc, char *argv[])
temp_msg.flags = RT_I2C_WR; /* I2C写 */ temp_msg.flags = RT_I2C_WR; /* I2C写 */
s_stat = rt_i2c_transfer(i2c_bus,&temp_msg,num_msg); /* 传输一条 */ s_stat = rt_i2c_transfer(i2c_bus,&temp_msg,num_msg); /* 传输一条 */
rt_thread_mdelay(400);
if( s_stat == num_msg ) if( s_stat == num_msg )
{ {
rt_kprintf(" send successful \n messege : %s \n:",buffer); rt_kprintf(" send successful \n messege : %s \n:",buffer);

View File

@ -18,10 +18,11 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include <stdlib.h> #include <stdlib.h>
#include "drv_gpio.h"
/* PIN脚编号查看驱动文件drv_gpio.c确定 */ /* PIN脚编号查看驱动文件drv_gpio.c确定 */
#define LED_PIN_NUM 19 /*PF1*/ #define LED_PIN_NUM GET_PIN( F , 1 )
static int pin_num; static int pin_num;
static void led_entry(void *parameter) static void led_entry(void *parameter)

View File

@ -15,17 +15,18 @@
*/ */
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include "drv_gpio.h"
/* 引脚编号通过查看驱动文件drv_gpio.c确定 */ /* 引脚编号通过查看驱动文件drv_gpio.c确定 */
#ifndef BEEP_PIN_NUM #ifndef BEEP_PIN_NUM
#define BEEP_PIN_NUM 19 /* PF1 */ #define BEEP_PIN_NUM GET_PIN( F , 1 )
#endif #endif
#ifndef KEY0_PIN_NUM #ifndef KEY0_PIN_NUM
#define KEY0_PIN_NUM 52 /* PC11 */ #define KEY0_PIN_NUM GET_PIN( C , 11 )
#endif #endif
#ifndef KEY1_PIN_NUM #ifndef KEY1_PIN_NUM
#define KEY1_PIN_NUM 53 /* PC12 */ #define KEY1_PIN_NUM GET_PIN( C , 12 )
#endif #endif
void beep_on(void *args) void beep_on(void *args)

View File

@ -30,15 +30,14 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include "drv_pm.h" #include "drv_pm.h"
#include "ald_gpio.h" #include "drv_gpio.h"
#ifdef RT_USING_PM #ifdef RT_USING_PM
#define PM_NAME "pm" /* 设备名称 */ #define PM_NAME "pm" /* 设备名称 */
#define WAKE_UP_PIN 51 /* 唤醒源 */ #define WAKE_UP_PIN GET_PIN( C , 10 ) /* 唤醒源 */
#define SLEEP_TIMES 12 /* 进入睡眠次数,轮流进入不同的睡眠模式,包括无睡眠模式 */ #define SLEEP_TIMES 12 /* 进入睡眠次数,轮流进入不同的睡眠模式,包括无睡眠模式 */
/*部分芯片进入深度睡眠后,部分外设的部分寄存器可能会丢失*/ /*部分芯片进入深度睡眠后,部分外设的部分寄存器可能会丢失*/
#define SAVE_REG UART0 #define SAVE_REG UART0

View File

@ -16,13 +16,13 @@
#include <rtthread.h> #include <rtthread.h>
#include <rtdevice.h> #include <rtdevice.h>
#include "drv_gpio.h"
#ifdef RT_USING_PWM #ifdef RT_USING_PWM
#define LED_PIN_NUM 37 /* PF1 LED PIN脚编号查看驱动文件drv_gpio.c确定 */ #define LED_PIN_NUM GET_PIN( C , 6 ) /* LED PIN脚编号查看驱动文件drv_gpio.c确定 */
#define PWM_DEV_NAME "pwm1" /* PWM设备名称 */ #define PWM_DEV_NAME "pwm1" /* PWM设备名称 */
#define PWM_DEV_CHANNEL 1 /* PWM通道 */ #define PWM_DEV_CHANNEL 1 /* PWM通道 */
struct rt_device_pwm *pwm_dev; /* PWM设备句柄 */ struct rt_device_pwm *pwm_dev; /* PWM设备句柄 */

View File

@ -12,16 +12,28 @@
* uart_sample * uart_sample
* uart_sample uart2 * uart_sample uart2
* 使使 * 使使
* "hello RT-Thread!" * "hello RT-Thread!"
*/ */
#include <rtthread.h> #include <rtthread.h>
#define SAMPLE_UART_NAME "uart0" /* 串口设备名称 */ /* 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 "uart1" /* 串口设备名称 */
/* 用于接收消息的信号量 */ /* 用于接收消息的信号量 */
static struct rt_semaphore rx_sem; static struct rt_semaphore rx_sem;
static rt_device_t serial; static rt_device_t serial;
/* 接收数据回调函数 */ /* 接收数据回调函数 */
static rt_err_t uart_input(rt_device_t dev, rt_size_t size) static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
@ -33,7 +45,8 @@ static rt_err_t uart_input(rt_device_t dev, rt_size_t size)
} }
static void serial_thread_entry(void *parameter) static void serial_thread_entry(void *parameter)
{ {
#if (UART_SAMPLE_TYPE == 1)
char ch; char ch;
while (1) while (1)
@ -48,6 +61,42 @@ static void serial_thread_entry(void *parameter)
ch = ch + 1; ch = ch + 1;
rt_device_write(serial, 0, &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[]) static int uart_sample(int argc, char *argv[])

View File

@ -68,8 +68,8 @@ static adc_channel_t es32f3_adc_get_channel(rt_uint32_t channel)
gpio_initstruct.mode = GPIO_MODE_INPUT; gpio_initstruct.mode = GPIO_MODE_INPUT;
gpio_initstruct.pupd = GPIO_FLOATING; gpio_initstruct.pupd = GPIO_FLOATING;
gpio_initstruct.odos = GPIO_OPEN_DRAIN; gpio_initstruct.odos = GPIO_OPEN_DRAIN;
gpio_initstruct.podrv = GPIO_OUT_DRIVE_1; gpio_initstruct.podrv = GPIO_OUT_DRIVE_6;
gpio_initstruct.nodrv = GPIO_OUT_DRIVE_1; gpio_initstruct.nodrv = GPIO_OUT_DRIVE_6;
gpio_initstruct.flt = GPIO_FILTER_DISABLE; gpio_initstruct.flt = GPIO_FILTER_DISABLE;
gpio_initstruct.type = GPIO_TYPE_CMOS; gpio_initstruct.type = GPIO_TYPE_CMOS;
gpio_initstruct.func = GPIO_FUNC_0; gpio_initstruct.func = GPIO_FUNC_0;

View File

@ -413,14 +413,14 @@ static int _can_sendmsg(struct rt_can_device *can, const void *buf, rt_uint32_t
/* clear TIR */ /* clear TIR */
h_can->perh->TxMailBox[box_num].TXID &= CAN_TXID0_TXMREQ_MSK; 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) if (RT_CAN_STDID == pmsg->ide)
{ {
h_can->perh->TxMailBox[box_num].TXID |= (txheader.std << CAN_TXID0_STDID_POSS) | txheader.rtr; h_can->perh->TxMailBox[box_num].TXID |= (txheader.std << CAN_TXID0_STDID_POSS) | (txheader.rtr << CAN_TXID0_RTR_POS);
} }
else else
{ {
h_can->perh->TxMailBox[box_num].TXID |= (txheader.ext << CAN_TXID0_EXID_POSS) | txheader.type | txheader.rtr; h_can->perh->TxMailBox[box_num].TXID |= (txheader.ext << CAN_TXID0_EXID_POSS) | (txheader.type << CAN_TXID0_IDE_POS) | (txheader.rtr << CAN_TXID0_RTR_POS);
} }
/* Set up the DLC */ /* Set up the DLC */
h_can->perh->TxMailBox[box_num].TXFCON = pmsg->len & 0x0FU; h_can->perh->TxMailBox[box_num].TXFCON = pmsg->len & 0x0FU;

View File

@ -274,8 +274,8 @@ void es32f3_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode)
/* Configure GPIO_InitStructure */ /* Configure GPIO_InitStructure */
gpio_initstruct.mode = GPIO_MODE_OUTPUT; gpio_initstruct.mode = GPIO_MODE_OUTPUT;
gpio_initstruct.func = GPIO_FUNC_1; gpio_initstruct.func = GPIO_FUNC_1;
gpio_initstruct.podrv = GPIO_OUT_DRIVE_1; gpio_initstruct.podrv = GPIO_OUT_DRIVE_6;
gpio_initstruct.nodrv = GPIO_OUT_DRIVE_0_1; gpio_initstruct.nodrv = GPIO_OUT_DRIVE_6;
gpio_initstruct.type = GPIO_TYPE_CMOS; gpio_initstruct.type = GPIO_TYPE_CMOS;
gpio_initstruct.odos = GPIO_PUSH_PULL; gpio_initstruct.odos = GPIO_PUSH_PULL;
gpio_initstruct.flt = GPIO_FILTER_DISABLE; gpio_initstruct.flt = GPIO_FILTER_DISABLE;
@ -316,12 +316,18 @@ void es32f3_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) rt_inline const struct pin_irq_map *get_pin_irq_map(rt_uint16_t gpio_pin)
{ {
rt_int32_t mapindex = gpio_pin & 0x00FF; uint8_t map_index = 0U;
if (mapindex < 0 || mapindex >= ITEM_NUM(pin_irq_map))
while(gpio_pin >> (++map_index))
{
}
map_index--;
if (map_index >= ITEM_NUM(pin_irq_map))
{ {
return RT_NULL; return RT_NULL;
} }
return &pin_irq_map[mapindex]; return &pin_irq_map[map_index];
}; };
rt_err_t es32f3_pin_attach_irq(struct rt_device *device, rt_int32_t pin, rt_err_t es32f3_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
@ -442,8 +448,8 @@ rt_err_t es32f3_pin_irq_enable(struct rt_device *device, rt_base_t pin,
/* Configure GPIO_InitStructure */ /* Configure GPIO_InitStructure */
gpio_initstruct.mode = GPIO_MODE_INPUT; gpio_initstruct.mode = GPIO_MODE_INPUT;
gpio_initstruct.odos = GPIO_PUSH_PULL; gpio_initstruct.odos = GPIO_PUSH_PULL;
gpio_initstruct.podrv = GPIO_OUT_DRIVE_1; gpio_initstruct.podrv = GPIO_OUT_DRIVE_6;
gpio_initstruct.nodrv = GPIO_OUT_DRIVE_1; gpio_initstruct.nodrv = GPIO_OUT_DRIVE_6;
gpio_initstruct.func = GPIO_FUNC_1; gpio_initstruct.func = GPIO_FUNC_1;
gpio_initstruct.flt = GPIO_FILTER_DISABLE; gpio_initstruct.flt = GPIO_FILTER_DISABLE;
switch (pin_irq_hdr_tab[irqindex].mode) switch (pin_irq_hdr_tab[irqindex].mode)

View File

@ -25,6 +25,8 @@
#define DRV_GPIO_H__ #define DRV_GPIO_H__
#include "es_conf_info_gpio.h" #include "es_conf_info_gpio.h"
#define GET_PIN(port,pin) (ES_PIN_GPIO_##port##_##pin)
int rt_hw_pin_init(void); int rt_hw_pin_init(void);

View File

@ -49,8 +49,8 @@ static void _i2c_init(void)
gpio_instruct.mode = GPIO_MODE_OUTPUT; gpio_instruct.mode = GPIO_MODE_OUTPUT;
gpio_instruct.odos = GPIO_OPEN_DRAIN; gpio_instruct.odos = GPIO_OPEN_DRAIN;
gpio_instruct.pupd = GPIO_PUSH_UP; gpio_instruct.pupd = GPIO_PUSH_UP;
gpio_instruct.podrv = GPIO_OUT_DRIVE_1; gpio_instruct.podrv = GPIO_OUT_DRIVE_6;
gpio_instruct.nodrv = GPIO_OUT_DRIVE_0_1; gpio_instruct.nodrv = GPIO_OUT_DRIVE_6;
gpio_instruct.flt = GPIO_FILTER_DISABLE; gpio_instruct.flt = GPIO_FILTER_DISABLE;
gpio_instruct.type = GPIO_TYPE_CMOS; gpio_instruct.type = GPIO_TYPE_CMOS;
@ -83,9 +83,9 @@ static void _i2c_init(void)
#ifdef BSP_USING_I2C1 #ifdef BSP_USING_I2C1
#if defined(ES_I2C1_SDA_GPIO_FUNC)&&defined(ES_I2C1_SDA_GPIO_PORT)&&defined(ES_I2C1_SDA_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_SDA_GPIO_FUNC; gpio_instruct.func = ES_I2C1_SCL_GPIO_FUNC;
ald_gpio_init(ES_I2C1_SDA_GPIO_PORT, ES_I2C1_SDA_GPIO_PIN, &gpio_instruct); ald_gpio_init(ES_I2C1_SCL_GPIO_PORT, ES_I2C1_SCL_GPIO_PIN, &gpio_instruct);
#endif #endif
#if defined(ES_I2C1_SDA_GPIO_FUNC)&&defined(ES_I2C1_SDA_GPIO_PORT)&&defined(ES_I2C1_SDA_GPIO_PIN) #if defined(ES_I2C1_SDA_GPIO_FUNC)&&defined(ES_I2C1_SDA_GPIO_PORT)&&defined(ES_I2C1_SDA_GPIO_PIN)

View File

@ -283,8 +283,8 @@ int rt_hw_spi_init(void)
gpio_instruct.pupd = GPIO_PUSH_UP_DOWN; gpio_instruct.pupd = GPIO_PUSH_UP_DOWN;
gpio_instruct.odos = GPIO_PUSH_PULL; gpio_instruct.odos = GPIO_PUSH_PULL;
gpio_instruct.podrv = GPIO_OUT_DRIVE_1; gpio_instruct.podrv = GPIO_OUT_DRIVE_6;
gpio_instruct.nodrv = GPIO_OUT_DRIVE_1; gpio_instruct.nodrv = GPIO_OUT_DRIVE_6;
gpio_instruct.type = GPIO_TYPE_TTL; gpio_instruct.type = GPIO_TYPE_TTL;
gpio_instruct.flt = GPIO_FILTER_DISABLE; gpio_instruct.flt = GPIO_FILTER_DISABLE;

View File

@ -198,8 +198,8 @@ static rt_err_t es32f3x_configure(struct rt_serial_device *serial, struct serial
gpio_initstructure.mode = GPIO_MODE_OUTPUT; gpio_initstructure.mode = GPIO_MODE_OUTPUT;
gpio_initstructure.odos = GPIO_PUSH_PULL; gpio_initstructure.odos = GPIO_PUSH_PULL;
gpio_initstructure.pupd = GPIO_PUSH_UP; gpio_initstructure.pupd = GPIO_PUSH_UP;
gpio_initstructure.podrv = GPIO_OUT_DRIVE_1; gpio_initstructure.podrv = GPIO_OUT_DRIVE_6;
gpio_initstructure.nodrv = GPIO_OUT_DRIVE_1; gpio_initstructure.nodrv = GPIO_OUT_DRIVE_6;
gpio_initstructure.flt = GPIO_FILTER_DISABLE; gpio_initstructure.flt = GPIO_FILTER_DISABLE;
gpio_initstructure.type = GPIO_TYPE_TTL; gpio_initstructure.type = GPIO_TYPE_TTL;