文章目录
- 一、简介
- 1.工具的目的
- 2. 更新点
- 下个更新
- 三、配置文件
一、简介
1.工具的目的
① 可视化选择IO口功能。
② 自由配置IO支持的功能。
③ 适用各类MCU,方便移植和开发。
④ 功能配置和裁剪(选项-syscfg-待完成–需要适配keil语法有些麻烦)
ls_syscfg.h 目的更快的配置外设参数和功能,跟专注业务代码开发。
2. 更新点
① 新增宏名称
② 注释
③ 回调函数(中断回调、按键回调)
④ 变更排序方式,按GPIOA、B、C排序
⑤ 回调函数会在ls_gpio.h生成弱函数,可由外部重新定义。
__WEAK void key0 (key_event_t event) {switch (event) {case KEY_EVENT_SINGLE_CLICK:break;}
}
下个更新
- syscfg功能
- 相应例程更新
- 基本完成功能
更多基于工具的项目开源。
三、配置文件
/********************************************************************************
* @file ls_gpio.h
* @author jianqiang.xue
* @version V1.3.0
* @date 2023-06-04
* @brief 业务类--GPIO定义
********************************************************************************/
#ifndef __LS_GPIO_H
#define __LS_GPIO_H
#define LS_IO_VERSION "CX32L003_通用模板"#include "cx32l003_hal.h"
#include "cx32l003_hal_def.h"
#include "bsp_gpio.h"
#include "bsp_exti.h"/* GPIO_EXTI_INT_EDGE; // 中断类型 边沿触发GPIO_EXTI_INT_LOWFALL; // 下降沿触发中断GPIO_EXTI_INT_HIGHRISE; // 上升沿触发中断GPIO_EXTI_INT_FALLRISE; // 下降沿上升沿都触发中断
GPIO_EXTI_INT_LEVEL; // 中断类型 电平触发GPIO_EXTI_INT_LOWFALL; // 低电平触发中断GPIO_EXTI_INT_HIGHRISE; // 高电平触发中断 */#define GPIO_CLK(GPIO) (RCC_HCLKEN_##GPIO##CKEN)
#define GPIO_APBx (0)
/************************************GPIO***********************************/
#define LS_IO_NUM (16)
/* Public Struct -------------------------------------------------------------*/union io_support_t {uint64_t val; // 对外值struct {uint64_t swo : 1;uint64_t adc0_ch0 : 1;uint64_t adc0_ch1 : 1;uint64_t adc0_ch2 : 1;uint64_t adc0_ch3 : 1;uint64_t adc0_ch4 : 1;uint64_t adc0_ch5 : 1;uint64_t adc0_ch6 : 1;uint64_t tim1_ch1 : 1; // PWM0uint64_t tim1_ch2 : 1; // PWM1uint64_t tim1_ch3 : 1; // PWM2uint64_t tim1_ch4 : 1; // PWM3uint64_t tim2_ch1 : 1; // PWM4uint64_t tim2_ch2 : 1; // PWM5uint64_t tim2_ch3 : 1; // PWM6uint64_t tim2_ch4 : 1; // PWM7uint64_t uart0_tx : 1;uint64_t uart0_rx : 1;uint64_t uart1_tx : 1;uint64_t uart1_rx : 1;uint64_t uart2_tx : 1;uint64_t uart2_rx : 1;uint64_t i2c0_scl : 1; // 硬件IICuint64_t i2c0_sda : 1;uint64_t i2c_scl_soft : 1; // 软件IICuint64_t i2c_sda_soft : 1;uint64_t spi0_clk : 1;uint64_t spi0_mosi : 1;uint64_t spi0_miso : 1;uint64_t spi0_nss : 1;#if !LS_IO_EXTEND_SUPPORTuint64_t reserve : 34;
#endif} bit;
};typedef enum {IO_TYPE_IN_NULL = 0, // 无上下拉IO_TYPE_IN_PULLUP, // 输入,上拉IO_TYPE_IN_PULLDOWN, // 输入,下拉IO_TYPE_OUT_PP, // 默认输出 推免输出IO_TYPE_OUT_OD, // 开漏输出// 中断输入IO_TYPE_INIRQ_LEVEL_LOW, // 电平触发-低电平IO_TYPE_INIRQ_LEVEL_HIGH, // 电平触发-高电平IO_TYPE_INIRQ_EDGE_LOWFALL, // 边沿触发-下降沿IO_TYPE_INIRQ_EDGE_HIGHRISE, // 边沿触发-上降沿IO_TYPE_INIRQ_EDGE_FALLRISE, // 边沿触发-任意电平变化IO_TYPE_SWO, // 默认烧录脚IO_TYPE_KEY, // 按键IO_TYPE_MATRIX_KEY_X, // 矩阵键盘X轴IO_TYPE_MATRIX_KEY_Y, // 矩阵键盘Y轴IO_TYPE_W2812X,IO_TYPE_ADC0_CH0, // ADC0_0IO_TYPE_ADC0_CH1, // ADC0_1IO_TYPE_ADC0_CH2, // ADC0_2IO_TYPE_ADC0_CH3, // ADC0_3IO_TYPE_ADC0_CH4, // ADC0_4IO_TYPE_ADC0_CH5, // ADC0_5IO_TYPE_ADC0_CH6, // ADC0_6IO_TYPE_TIM1_CH1, // PWM0IO_TYPE_TIM1_CH2, // PWM1IO_TYPE_TIM1_CH3, // PWM2IO_TYPE_TIM1_CH4, // PWM3IO_TYPE_TIM2_CH1, // PWM4IO_TYPE_TIM2_CH2, // PWM5IO_TYPE_TIM2_CH3, // PWM6IO_TYPE_TIM2_CH4, // PWM7IO_TYPE_UART0_TX, // 串口0,TXIO_TYPE_UART0_RX, // 串口0,RXIO_TYPE_UART1_TX, // 串口1,TXIO_TYPE_UART1_RX, // 串口1,RXIO_TYPE_UART2_TX, // 串口2,TXIO_TYPE_UART2_RX, // 串口2,RXIO_TYPE_I2C0_SCL, // 硬件IIC0IO_TYPE_I2C0_SDA, // 硬件IIC0IO_TYPE_I2C_SCL_SOFT, // 软件IICIO_TYPE_I2C_SDA_SOFT, // 软件IICIO_TYPE_SPI0_CLK, // SPI0_时钟IO_TYPE_SPI0_MOSI, // SPI0_主机输出IO_TYPE_SPI0_MISO, // SPI0_主机输入IO_TYPE_SPI0_NSS, // SPI0_片选IO_TYPE_MAX,
} io_type_t;extern const union io_support_t g_io_support[LS_IO_NUM]; // 引脚支持类型
extern const io_type_t g_io_default_type[LS_IO_NUM]; // 引脚默认类型
extern const bsp_gpio_t g_io_cfg[LS_IO_NUM]; // 引脚配置(时钟中断号)
extern const uint8_t g_io_pin_num[LS_IO_NUM]; // 数组下标对应的引脚号
#ifdef LS_IO
const uint8_t g_io_pin_num[LS_IO_NUM] = {5, 6, 10, 12, 11, 13, 14, 15, 16, 17, 18, 19, 20, 1, 2, 3,
};const bsp_gpio_t g_io_cfg[LS_IO_NUM] = {{(GPIOA), (GPIO_PIN_1), GPIO_CLK(GPIOA), (0), (GPIOA_IRQn)},{(GPIOA), (GPIO_PIN_2), GPIO_CLK(GPIOA), (0), (GPIOA_IRQn)},{(GPIOA), (GPIO_PIN_3), GPIO_CLK(GPIOA), (0), (GPIOA_IRQn)},{(GPIOB), (GPIO_PIN_4), GPIO_CLK(GPIOB), (0), (GPIOB_IRQn)},{(GPIOB), (GPIO_PIN_5), GPIO_CLK(GPIOB), (0), (GPIOB_IRQn)},{(GPIOC), (GPIO_PIN_3), GPIO_CLK(GPIOC), (0), (GPIOC_IRQn)},{(GPIOC), (GPIO_PIN_4), GPIO_CLK(GPIOC), (0), (GPIOC_IRQn)},{(GPIOC), (GPIO_PIN_5), GPIO_CLK(GPIOC), (0), (GPIOC_IRQn)},{(GPIOC), (GPIO_PIN_6), GPIO_CLK(GPIOC), (0), (GPIOC_IRQn)},{(GPIOC), (GPIO_PIN_7), GPIO_CLK(GPIOC), (0), (GPIOC_IRQn)},{(GPIOD), (GPIO_PIN_1), GPIO_CLK(GPIOD), (0), (GPIOD_IRQn)},{(GPIOD), (GPIO_PIN_2), GPIO_CLK(GPIOD), (0), (GPIOD_IRQn)},{(GPIOD), (GPIO_PIN_3), GPIO_CLK(GPIOD), (0), (GPIOD_IRQn)},{(GPIOD), (GPIO_PIN_4), GPIO_CLK(GPIOD), (0), (GPIOD_IRQn)},{(GPIOD), (GPIO_PIN_5), GPIO_CLK(GPIOD), (0), (GPIOD_IRQn)},{(GPIOD), (GPIO_PIN_6), GPIO_CLK(GPIOD), (0), (GPIOD_IRQn)},
};const union io_support_t g_io_support[LS_IO_NUM] = {{0x74A0000}, {0x23452400}, {0x20204000}, {0x23410000}, {0x4821000},{0x844404}, {0x488808}, {0x4100000}, {0x8208102}, {0x10080201},{0x40001}, {0x10100210}, {0x8012020}, {0x3020100}, {0x10458040},{0x88A2280},
};const io_type_t g_io_default_type[LS_IO_NUM] = {IO_TYPE_UART0_RX, IO_TYPE_UART0_TX, IO_TYPE_TIM2_CH3, IO_TYPE_OUT_PP, IO_TYPE_TIM2_CH1,IO_TYPE_TIM1_CH3, IO_TYPE_TIM1_CH4, IO_TYPE_OUT_PP, IO_TYPE_ADC0_CH0, IO_TYPE_SWO,IO_TYPE_SWO, IO_TYPE_TIM1_CH2, IO_TYPE_TIM2_CH2, IO_TYPE_TIM1_CH1, IO_TYPE_TIM2_CH4,IO_TYPE_ADC0_CH6,
};__weak void app_io_exti_cb(void *gpiox, uint16_t gpio_pin) {
// [中断回调START]
// [中断回调END]
}#include "ls_key.h"
// __WEAK void xxx (key_event_t event) {
// switch (event) {
// case KEY_EVENT_SINGLE_CLICK:
// break;
// }
// }__WEAK const ls_key_cb_t ls_key_cb_list[] = {
// [按键扫描START]
// [按键扫描END]{0xFF, NULL} // 必须有
};
#endif // __LS_IO_END// [引脚宏名称START]
// [引脚宏名称END]
#endif // __LS_GPIO_H
gitee
1.0版本
- ADC
AT+ADC0_CFG?
AT+ADC0_TIMER_MS=300
AT+ADC0_START
AT+ADC0_STOP
AT+GET_ADC0_VAL?
AT+ADC0_CFG=?
AT+ADC0_CFG=1,10
#include "bsp_adc.h"
extern bsp_adc_cfg_t g_adc0_cfg;
extern os_timer_id OS_TIMER_ID(adc0_collection);
extern uint32_t g_adc0_timer_ms;static int atcmd_adc0_cfg_help(atcmd_pack_t *pack) {char buff[60] = {0};snprintf(buff, 60, "AT+ADC0_CFG=<clk_sel(0-7)>,<sample_num(0-255)>\r\n");strcat(buff, AT_OK);pack->reply((uint8_t*)buff, strlen(buff));return 0;
}static int atcmd_get_adc0_cfg(atcmd_pack_t *pack) {char buff[30] = {0};snprintf(buff, 30, "%d,%d\r\n", g_adc0_cfg.clk_sel, g_adc0_cfg.sample_num);strcat(buff, AT_OK);pack->reply((uint8_t*)buff, strlen(buff));return 0;
}static int atcmd_set_adc0_cfg(atcmd_pack_t *pack) {uint32_t argc[2] = {0};char buff[20] = {0};pack->argc = sscanf((char*)(pack->data), "%d,%d", &argc[0], &argc[1]);if (pack->argc != 2) {strcat(buff, AT_ARGCERR);pack->reply((uint8_t*)buff, strlen(buff));return -2;}bsp_adc0_deinit();g_adc0_cfg.clk_sel = (uint8_t)argc[0];g_adc0_cfg.sample_num = argc[1];if (bsp_adc0_init(&g_adc0_cfg)) {strcat(buff, AT_ERROR);} else {strcat(buff, AT_OK);}pack->reply((uint8_t*)buff, strlen(buff));return 0;
}static int atcmd_set_adc0_timer_ms(atcmd_pack_t *pack) {uint32_t argc[1] = {0};uint8_t buff[40] = {0};pack->argc = sscanf((char*)(pack->data), "%d", &argc[0]);if (pack->argc != 1) return -1;// 先停止周期任务,并将任务全部取消。OS_TIMER_STOP(adc0_collection);if (argc[0]) {if (os_timer_restart(OS_TIMER_ID(adc0_collection), argc[0]) != OS_OK)strcat((char*)buff, "adc0 timer restart fail");g_adc0_timer_ms = argc[0];} else {if (os_timer_stop(OS_TIMER_ID(adc0_collection)) != OS_OK)strcat((char*)buff, "adc0 timer stop fail");}strcat((char*)buff, AT_OK);pack->reply(buff, strlen((char*)buff));return 0;
}static int atcmd_adc0_start(atcmd_pack_t *pack) {uint8_t buff[40] = {0};if (os_timer_restart(OS_TIMER_ID(adc0_collection), g_adc0_timer_ms) != OS_OK)strcat((char*)buff, "adc0 timer restart fail");strcat((char*)buff, AT_OK);pack->reply(buff, strlen((char*)buff));return 0;
}static int atcmd_adc0_stop(atcmd_pack_t *pack) {uint8_t buff[40] = {0};if (os_timer_stop(OS_TIMER_ID(adc0_collection)) != OS_OK)strcat((char*)buff, "adc0 timer stop fail");strcat((char*)buff, AT_OK);pack->reply(buff, strlen((char*)buff));return 0;
}static int atcmd_get_adc0_val(atcmd_pack_t *pack) {uint8_t buff[60] = {0};snprintf((char *)buff, 60, "%d,%d,%d,%d,%d,%d,%d,%d\r\n",bsp_adc0_get_ch_val(0), bsp_adc0_get_ch_val(1), bsp_adc0_get_ch_val(2), bsp_adc0_get_ch_val(3),bsp_adc0_get_ch_val(4), bsp_adc0_get_ch_val(5), bsp_adc0_get_ch_val(6), bsp_adc0_get_ch_val(7));strcat((char*)buff, AT_OK);pack->reply(buff, strlen((char*)buff));return 0;
}static int atcmd_get_adc0_designated_val(atcmd_pack_t *pack) {uint32_t argc[1];uint8_t buff[30] = {0};pack->argc = sscanf((char*)(pack->data), "%d", &argc[0]);if (pack->argc != 1) return -1;snprintf((char *)buff, 30, "%d", bsp_adc0_get_ch_val(argc[0]));strcat((char*)buff, AT_OK);pack->reply(buff, strlen((char*)buff));return 0;
}ATCMD_INIT("AT+ADC0_TIMER_MS=", atcmd_set_adc0_timer_ms);
ATCMD_INIT("AT+ADC0_START", atcmd_adc0_start);
ATCMD_INIT("AT+ADC0_STOP", atcmd_adc0_stop);
ATCMD_INIT("AT+GET_ADC0_VAL=", atcmd_get_adc0_designated_val);
ATCMD_INIT("AT+GET_ADC0_VAL?", atcmd_get_adc0_val);ATCMD_INIT("AT+ADC0_CFG=?", atcmd_adc0_cfg_help);
ATCMD_INIT("AT+ADC0_CFG=", atcmd_set_adc0_cfg);
ATCMD_INIT("AT+ADC0_CFG?", atcmd_get_adc0_cfg);
- PWM
AT+PWM=0,10
AT+TIM1_CFG=7,99,0
AT+TIM1_CFG=?
AT+PWM_TASK=
#include "bsp_pwm.h"
#include "bsp_tim.h"
#if LS_TIM1_EN
extern bsp_tim_cfg_t g_tim1_cfg;
static int atcmd_set_tim1_cfg_help(atcmd_pack_t *pack) {char buff[85] = {0};snprintf(buff, 60, "AT+TIM1_CFG=<prescaler(0-65534)>,<period(0-65534)>,<level_logic(0-1)>\r\n");strcat(buff, AT_OK);pack->reply((uint8_t*)buff, strlen(buff));return 0;
}
static int atcmd_set_tim1_cfg(atcmd_pack_t *pack) {uint32_t argc[3] = {0};char buff[10] = {0};pack->argc = sscanf((char*)(pack->data), "%d,%d,%d", &argc[0], &argc[1], &argc[2]);if (pack->argc != 3) {strcat(buff, AT_ARGCERR);pack->reply((uint8_t*)buff, strlen(buff));return -2;}bsp_tim1_pwm_deinit();g_tim1_cfg.prescaler = (uint16_t)argc[0];g_tim1_cfg.period = (uint16_t)argc[1];g_tim1_cfg.level_logic = (uint8_t)argc[2];if (bsp_tim1_pwm_init(&g_tim1_cfg)) {strcat(buff, AT_ERROR);} else {strcat(buff, AT_OK);}pack->reply((uint8_t*)buff, strlen(buff));return 0;
}
ATCMD_INIT("AT+TIM1_CFG=?", atcmd_set_tim1_cfg_help);
ATCMD_INIT("AT+TIM1_CFG=", atcmd_set_tim1_cfg);
#endif
#if LS_TIM2_EN
extern bsp_tim_cfg_t g_tim2_cfg;
static int atcmd_set_tim2_cfg_help(atcmd_pack_t *pack) {char buff[85] = {0};snprintf(buff, 60, "AT+TIM2_CFG=<prescaler(0-65534)>,<period(0-65534)>,<level_logic(0-1)>\r\n");strcat(buff, AT_OK);pack->reply((uint8_t*)buff, strlen(buff));return 0;
}
static int atcmd_set_tim2_cfg(atcmd_pack_t *pack) {uint32_t argc[3] = {0};char buff[10] = {0};pack->argc = sscanf((char*)(pack->data), "%d,%d,%d", &argc[0], &argc[1], &argc[2]);if (pack->argc != 3) {strcat(buff, AT_ARGCERR);pack->reply((uint8_t*)buff, strlen(buff));return -2;}bsp_tim2_pwm_deinit();g_tim2_cfg.prescaler = (uint16_t)argc[0];g_tim2_cfg.period = (uint16_t)argc[1];g_tim2_cfg.level_logic = (uint8_t)argc[2];if (bsp_tim2_pwm_init(&g_tim2_cfg)) {strcat(buff, AT_ERROR);} else {strcat(buff, AT_OK);}pack->reply((uint8_t*)buff, strlen(buff));return 0;
}
ATCMD_INIT("AT+TIM2_CFG=?", atcmd_set_tim2_cfg_help);
ATCMD_INIT("AT+TIM2_CFG=", atcmd_set_tim2_cfg);
#endifstatic int atcmd_set_pwm_val_help(atcmd_pack_t *pack) {char buff[60] = {0};snprintf(buff, 60, "AT+PWM=<ch(0-7)>,<val(0-65535)>\r\n");strcat(buff, AT_OK);pack->reply((uint8_t*)buff, strlen(buff));return 0;
}static int atcmd_set_pwm_val(atcmd_pack_t *pack) {uint32_t argc[2] = {0};uint8_t buff[10] = {0};pack->argc = sscanf((char*)(pack->data), "%d,%d", &argc[0], &argc[1]);if (pack->argc != 2) {strcat((char*)buff, AT_ARGCERR);pack->reply(buff, strlen((char*)buff));return -2;}if (bsp_pwm_set_pulse(argc[0], argc[1])) {strcat((char*)buff, AT_ERROR);} else {strcat((char*)buff, AT_OK);}pack->reply(buff, strlen((char*)buff));return 0;
}ATCMD_INIT("AT+PWM=?", atcmd_set_pwm_val_help);
ATCMD_INIT("AT+PWM=", atcmd_set_pwm_val);