This commit is contained in:
刘正航
2026-04-16 16:55:01 +08:00
commit 609eb878d1
624 changed files with 214375 additions and 0 deletions

445
User/bsp/src/bsp_led.c Normal file
View File

@@ -0,0 +1,445 @@
/*
*********************************************************************************************************
*
* 模块名称 : LED指示灯驱动模块
* 文件名称 : bsp_led.c
* 版 本 : V1.0
* 说 明 : 驱动LED指示灯
*
* 修改记录 :
* 版本号 日期 作者 说明
* V1.0 2013-02-01 armfly 正式发布
*
* Copyright (C), 2013-2014, 安富莱电子 www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
/*
该程序适用于安富莱STM32-V4 开发板
如果用于其它硬件请修改GPIO定义
如果用户的LED指示灯个数小于4个可以将多余的LED全部定义为和第1个LED一样并不影响程序功能
*/
/* 按键口对应的RCC时钟 */
#define RCC_ALL_LED (RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_GPIOF)
#define GPIO_PORT_LED1 GPIOA
#define GPIO_PIN_LED1 GPIO_Pin_15
#define GPIO_PORT_LED2 GPIOC
#define GPIO_PIN_LED2 GPIO_Pin_10
#define GPIO_PORT_LED3 GPIOC
#define GPIO_PIN_LED3 GPIO_Pin_11
#define GPIO_PORT_LED4 GPIOC
#define GPIO_PIN_LED4 GPIO_Pin_12
#define GPIO_PORT_LED5 GPIOD
#define GPIO_PIN_LED5 GPIO_Pin_0
#define GPIO_PORT_LED6 GPIOD
#define GPIO_PIN_LED6 GPIO_Pin_1
#define GPIO_PORT_LED7 GPIOF
#define GPIO_PIN_LED7 GPIO_Pin_5
#define GPIO_PORT_LED8 GPIOF
#define GPIO_PIN_LED8 GPIO_Pin_4
#define GPIO_PORT_LED9 GPIOF
#define GPIO_PIN_LED9 GPIO_Pin_3
#define GPIO_PORT_LED10 GPIOF
#define GPIO_PIN_LED10 GPIO_Pin_2
#define GPIO_PORT_LED11 GPIOF
#define GPIO_PIN_LED11 GPIO_Pin_1
#define GPIO_PORT_LED12 GPIOF
#define GPIO_PIN_LED12 GPIO_Pin_0
#define GPIO_PORT_LED13 GPIOE
#define GPIO_PIN_LED13 GPIO_Pin_5
#define GPIO_PORT_LED14 GPIOE
#define GPIO_PIN_LED14 GPIO_Pin_4
/*
*********************************************************************************************************
* 函 数 名: bsp_InitLed
* 功能说明: 配置LED指示灯相关的GPIO, 该函数被 bsp_Init() 调用。
* 形 参: 无
* 返 回 值: 无
*********************************************************************************************************
*/
void bsp_InitLed(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 打开GPIO时钟 */
RCC_APB2PeriphClockCmd(RCC_ALL_LED, ENABLE);
/*
配置所有的LED指示灯GPIO为推挽输出模式
由于将GPIO设置为输出时GPIO输出寄存器的值缺省是0因此会驱动LED点亮.
这是我不希望的因此在改变GPIO为输出前先关闭LED指示灯
*/
bsp_LedOff(1);
bsp_LedOff(2);
bsp_LedOff(3);
bsp_LedOff(4);
bsp_LedOff(5);
bsp_LedOff(6);
bsp_LedOn(7);
bsp_LedOff(8);
bsp_LedOff(9);
bsp_LedOff(10);
bsp_LedOff(11);
bsp_LedOff(12);
bsp_LedOff(13);
bsp_LedOff(14);
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /* 推挽输出模式 */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED1;
GPIO_Init(GPIO_PORT_LED1, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED2;
GPIO_Init(GPIO_PORT_LED2, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED3;
GPIO_Init(GPIO_PORT_LED3, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED4;
GPIO_Init(GPIO_PORT_LED4, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED5;
GPIO_Init(GPIO_PORT_LED5, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED6;
GPIO_Init(GPIO_PORT_LED6, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED7;
GPIO_Init(GPIO_PORT_LED7, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED8;
GPIO_Init(GPIO_PORT_LED8, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED9;
GPIO_Init(GPIO_PORT_LED9, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED10;
GPIO_Init(GPIO_PORT_LED10, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED11;
GPIO_Init(GPIO_PORT_LED11, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED12;
GPIO_Init(GPIO_PORT_LED12, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED13;
GPIO_Init(GPIO_PORT_LED13, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_PIN_LED14;
GPIO_Init(GPIO_PORT_LED14, &GPIO_InitStructure);
}
/*
*********************************************************************************************************
* 函 数 名: bsp_LedOn
* 功能说明: 点亮指定的LED指示灯。
* 形 参: _no : 指示灯序号,范围 1 - 4
* 返 回 值: 无
*********************************************************************************************************
*/
void bsp_LedOff(uint8_t _no)
{
_no--;
if (_no == 0)
{
GPIO_PORT_LED1->BRR = GPIO_PIN_LED1;
}
else if (_no == 1)
{
GPIO_PORT_LED2->BRR = GPIO_PIN_LED2;
}
else if (_no == 2)
{
GPIO_PORT_LED3->BRR = GPIO_PIN_LED3;
}
else if (_no == 3)
{
GPIO_PORT_LED4->BRR = GPIO_PIN_LED4;
}
else if (_no == 4)
{
GPIO_PORT_LED5->BRR = GPIO_PIN_LED5;
}
else if (_no == 5)
{
GPIO_PORT_LED6->BRR = GPIO_PIN_LED6;
}
else if (_no == 6)
{
GPIO_PORT_LED7->BRR = GPIO_PIN_LED7;
}
else if (_no == 7)
{
GPIO_PORT_LED8->BRR = GPIO_PIN_LED8;
}
else if (_no == 8)
{
GPIO_PORT_LED9->BRR = GPIO_PIN_LED9;
}
else if (_no == 9)
{
GPIO_PORT_LED10->BRR = GPIO_PIN_LED10;
}
else if (_no == 10)
{
GPIO_PORT_LED11->BRR = GPIO_PIN_LED11;
}
else if (_no == 11)
{
GPIO_PORT_LED12->BRR = GPIO_PIN_LED12;
}
else if (_no == 12)
{
GPIO_PORT_LED13->BRR = GPIO_PIN_LED13;
}
else if (_no == 13)
{
GPIO_PORT_LED14->BRR = GPIO_PIN_LED14;
}
}
/*
*********************************************************************************************************
* 函 数 名: bsp_LedOff
* 功能说明: 熄灭指定的LED指示灯。
* 形 参: _no : 指示灯序号,范围 1 - 4
* 返 回 值: 无
*********************************************************************************************************
*/
void bsp_LedOn(uint8_t _no)
{
_no--;
if (_no == 0)
{
GPIO_PORT_LED1->BSRR = GPIO_PIN_LED1;
}
else if (_no == 1)
{
GPIO_PORT_LED2->BSRR = GPIO_PIN_LED2;
}
else if (_no == 2)
{
GPIO_PORT_LED3->BSRR = GPIO_PIN_LED3;
}
else if (_no == 3)
{
GPIO_PORT_LED4->BSRR = GPIO_PIN_LED4;
}
else if (_no == 4)
{
GPIO_PORT_LED5->BSRR = GPIO_PIN_LED5;
}
else if (_no == 5)
{
GPIO_PORT_LED6->BSRR = GPIO_PIN_LED6;
}
else if (_no == 6)
{
GPIO_PORT_LED7->BSRR = GPIO_PIN_LED7;
}
else if (_no == 7)
{
GPIO_PORT_LED8->BSRR = GPIO_PIN_LED8;
}
else if (_no == 8)
{
GPIO_PORT_LED9->BSRR = GPIO_PIN_LED9;
}
else if (_no == 9)
{
GPIO_PORT_LED10->BSRR = GPIO_PIN_LED10;
}
else if (_no == 10)
{
GPIO_PORT_LED11->BSRR = GPIO_PIN_LED11;
}
else if (_no == 11)
{
GPIO_PORT_LED12->BSRR = GPIO_PIN_LED12;
}
else if (_no == 12)
{
GPIO_PORT_LED13->BSRR = GPIO_PIN_LED13;
}
else if (_no == 13)
{
GPIO_PORT_LED14->BSRR = GPIO_PIN_LED14;
}
}
/*
*********************************************************************************************************
* 函 数 名: bsp_LedToggle
* 功能说明: 翻转指定的LED指示灯。
* 形 参: _no : 指示灯序号,范围 1 - 4
* 返 回 值: 按键代码
*********************************************************************************************************
*/
void bsp_LedToggle(uint8_t _no)
{
if (_no == 1)
{
GPIO_PORT_LED1->ODR ^= GPIO_PIN_LED1;
}
else if (_no == 2)
{
GPIO_PORT_LED2->ODR ^= GPIO_PIN_LED2;
}
else if (_no == 3)
{
GPIO_PORT_LED3->ODR ^= GPIO_PIN_LED3;
}
else if (_no == 4)
{
GPIO_PORT_LED4->ODR ^= GPIO_PIN_LED4;
}
}
/*
*********************************************************************************************************
* 函 数 名: bsp_IsLedOn
* 功能说明: 判断LED指示灯是否已经点亮。
* 形 参: _no : 指示灯序号,范围 1 - 4
* 返 回 值: 1表示已经点亮0表示未点亮
*********************************************************************************************************
*/
uint8_t bsp_IsLedOn(uint8_t _no)
{
if (_no == 1)
{
if ((GPIO_PORT_LED1->ODR & GPIO_PIN_LED1) == 0)
{
return 1;
}
return 0;
}
else if (_no == 2)
{
if ((GPIO_PORT_LED2->ODR & GPIO_PIN_LED2) == 0)
{
return 1;
}
return 0;
}
else if (_no == 3)
{
if ((GPIO_PORT_LED3->ODR & GPIO_PIN_LED3) == 0)
{
return 1;
}
return 0;
}
else if (_no == 4)
{
if ((GPIO_PORT_LED4->ODR & GPIO_PIN_LED4) == 0)
{
return 1;
}
return 0;
}
return 0;
}
void bsp_LedAllOff(void)
{
bsp_LedOff(1);
bsp_LedOff(2);
bsp_LedOff(3);
bsp_LedOff(4);
bsp_LedOff(5);
bsp_LedOff(6);
bsp_LedOff(7);
bsp_LedOff(8);
bsp_LedOff(9);
bsp_LedOff(10);
bsp_LedOff(11);
bsp_LedOff(12);
bsp_LedOff(13);
bsp_LedOff(14);
}
static void ChannelLedAllOff(void)
{
bsp_LedOff(1);
bsp_LedOff(2);
bsp_LedOff(3);
bsp_LedOff(4);
bsp_LedOff(5);
bsp_LedOff(6);
}
static void ResLedAllOff(void)
{
bsp_LedOff(7);
bsp_LedOff(8);
bsp_LedOff(9);
bsp_LedOff(10);
bsp_LedOff(11);
bsp_LedOff(12);
bsp_LedOff(13);
bsp_LedOff(14);
}
//----------------------------------------
// ch = 1,2,3,4,5,6
//---------------------------------------
void bsp_ChannelSelect(uint8_t _ch)
{
static uint8_t s_ucOldCh=255;
if(_ch==s_ucOldCh)
{
ChannelLedAllOff();
bsp_RealyAllOff();
s_ucOldCh=255;
}
else
{
s_ucOldCh = _ch;
ChannelLedAllOff();
bsp_LedOn(_ch);
bsp_RelayOn(_ch);
}
}
void bsp_ResSelect(uint8_t _res)
{
ResLedAllOff();
//printf("_res:%d\r\n",_res);
bsp_LedOn(_res);
bsp_SelectRes(_res);
}
/***************************** 安富莱电子 www.armfly.com (END OF FILE) *********************************/