gpio写完,延时不准

This commit is contained in:
2026-05-24 22:33:07 +08:00
parent b58f7aca9f
commit 589b67a3f9
113 changed files with 473 additions and 14048 deletions
+162
View File
@@ -0,0 +1,162 @@
//
// Created by anonymous on 2026/5/24.
//
#include "Bsp.h"
#include "Voilet.h"
// LED灯数组
#if (LED_NUM != 0)
const GPIO_CONFIG LED_PERIPH[] = {
{.GpioX = GPIO21, .Mode = GPIO_Mode_Out_PP, .Speed = GPIO_Speed_10MHz},
{.GpioX = GPIO69, .Mode = GPIO_Mode_Out_PP, .Speed = GPIO_Speed_10MHz},
};
#endif
//数字输入数组
#if (DI_NUM != 0)
const GPIO_CONFIG DI_PERIPH[] = {
{},
};
#endif
//数字输出数组
#if (DO_NUM != 0)
const GPIO_CONFIG DO_PERIPH[] = {
{},
};
#endif
//串口配置表
const COM_CONFIG COM_PERIPH[] = {
{COM1,.TxPort = GPIO2, .TxMode = GPIO_Mode_AF_PP,.RxPort = GPIO3, .RxMode = GPIO_Mode_IPU,.Speed = GPIO_Speed_50MHz},
};
void BspExtraInit(void);
/**
* @brief Voilet BSP的初始化函数
* @note void
* @param void
* @retval void
*/
void VoiletBspInit(void) {
unsigned char i = 0;
INTERRUPT_DISABLE
//初始化延时库
DelayConfig();
//关闭所有外设时钟
AllPeriphClockDisable();
//LED灯配置
#if (LED_NUM != 0)
for (i = 0;i < LED_NUM;i++) {
//打开外设时钟
GpioClockEnable(&LED_PERIPH[i].GpioX);
//配置GPIO口
GpioConfig(&LED_PERIPH[i].GpioX, LED_PERIPH[i].Mode, LED_PERIPH[i].Speed);
}
#endif
//DI采集配置
#if (DI_NUM != 0)
// for (i = 0;i < DI_NUM;i++) {
// //打开外设时钟
// GpioClockEnable(&LED_PERIPH[i].GpioX);
// //配置GPIO口
// GpioConfig(&LED_PERIPH[i].GpioX, LED_PERIPH[i].Mode, LED_PERIPH[i].Speed);
// }
#endif
//DO输出配置
#if (DO_NUM != 0)
// for (i = 0;i < DO_NUM;i++) {
// //打开外设时钟
// GpioClockEnable(&LED_PERIPH[i].GpioX);
// //配置GPIO口
// GpioConfig(&LED_PERIPH[i].GpioX, LED_PERIPH[i].Mode, LED_PERIPH[i].Speed);
// }
#endif
//串口配置
for (i = 0;i < ARRAY_LEN(COM_PERIPH);i++) {
UartClockEnable(&COM_PERIPH[i].ComX);
GpioConfig(&COM_PERIPH[i].TxPort, COM_PERIPH[i].TxMode, COM_PERIPH[i].Speed);
GpioConfig(&COM_PERIPH[i].TxPort, COM_PERIPH[i].RxMode, COM_PERIPH[i].Speed);
}
INTERRUPT_ENABLE
BspExtraInit();
}
/**
* @brief 扩展库初始化
* @note 理论上扩展库要在BSP的最后加载
* @param void
* @retval void
*/
void BspExtraInit(void)
{
//LetterShell初始化
#ifdef USE_SHELL
// LetterShellInit(TTY_COM,TTY_BAUD);
#endif
}
/**
* @brief 打开LED灯
* @note void
* @param Chnl 通道
* @retval void
*/
void LedOn(uint8_t Chnl)
{
if (Chnl >= LED_NUM)
return;
GpioSet(&LED_PERIPH[Chnl].GpioX, RESET);
}
/**
* @brief 关闭LED灯
* @note void
* @param Chnl 通道
* @retval void
*/
void LedOff(uint8_t Chnl)
{
if (Chnl >= LED_NUM)
return;
GpioSet(&LED_PERIPH[Chnl].GpioX, SET);
}
void LedSet(uint8_t Chnl,uint8_t Value)
{
if (Chnl >= LED_NUM)
return;
if (Value == LED_ON) {
GpioSet(&LED_PERIPH[Chnl].GpioX, RESET);
}
else {
GpioSet(&LED_PERIPH[Chnl].GpioX, SET);
}
}
/**
* @brief 切换LED灯状态
* @note void
* @param Chnl 通道 Status 状态
* @retval void
*/
void LedToggle(uint8_t Chnl)
{
if (Chnl >= LED_NUM)
return;
if (GpioGet(&LED_PERIPH[Chnl].GpioX) == LED_ON)
{
GpioSet(&LED_PERIPH[Chnl].GpioX,LED_OFF);
}
else
{
GpioSet(&LED_PERIPH[Chnl].GpioX,LED_ON);
}
}
+40
View File
@@ -0,0 +1,40 @@
//
// Created by anonymous on 2026/5/24.
//
#ifndef VOILET_H
#define VOILET_H
#define LED_NUM 2 //LED灯数量
#if (LED_NUM != 0)
#define LED0 0
#define LED1 1
#endif
#define DI_NUM 0
#if (DI_NUM != 0)
#endif
#define DO_NUM 0
#if (DO_NUM != 0)
#endif
#define USE_SHELL //系统使用Shell
#define TTY_COM COM1
typedef struct {
GPIO_MAP_T GpioX;
GPIOMode_TypeDef Mode;
GPIOSpeed_TypeDef Speed;
}GPIO_CONFIG;
typedef struct {
COM_MAP_T ComX;
GPIO_MAP_T TxPort;
GPIOMode_TypeDef TxMode;
GPIO_MAP_T RxPort;
GPIOMode_TypeDef RxMode;
GPIOSpeed_TypeDef Speed;
}COM_CONFIG;
#endif //VOILET_H
+11 -4
View File
@@ -1,16 +1,23 @@
//
// Created by anonymous on 2026/5/24.
//
#include "main.h"
/* C标准库头文件 */
#include <stdio.h>
#include <stdint.h>
/* BSP文件 */
#include "main.h"
#include "Bsp.h"
int main(void) {
uint32_t i;
VoiletBspInit();
UartStdConfig((COM_MAP_T)COM1,9600);
while (1) {
i++;
LedToggle(LED0);
DelayMs(100);
}
return 0;
}
+3 -3
View File
@@ -2,7 +2,7 @@
// Created by anonymous on 2026/5/24.
//
#ifndef HELLOCLIONSTM32F10X_MAIN_H
#define HELLOCLIONSTM32F10X_MAIN_H
#ifndef MAIN_H
#define MAIN_H
#endif //HELLOCLIONSTM32F10X_MAIN_H
#endif //MAIN_H