河北水利局项目
This commit is contained in:
248
APP/Led.c
Normal file
248
APP/Led.c
Normal file
@@ -0,0 +1,248 @@
|
||||
/*——————————————————————————
|
||||
* 文 件 名:Led.c
|
||||
* 文件说明:Led源文件
|
||||
*
|
||||
* 当前版本:V8.0
|
||||
* 作 者:ZL
|
||||
* 开始日期:2013-12-30
|
||||
*———————————————————————————*/
|
||||
#include "Led.h"
|
||||
#include "include.h"
|
||||
|
||||
|
||||
bool OLDNEW_VERSION_DETECT = false;//false 旧版本,true 新版本
|
||||
/*
|
||||
st_gpio_config up_send_led = LED_INIT(UP_SEND);
|
||||
st_gpio_config up_receive_led = LED_INIT(UP_RECEIVE);
|
||||
st_gpio_config down_send_led = LED_INIT(DOWN_SEND);
|
||||
st_gpio_config down_receive_led = LED_INIT(DOWN_RECEIVE);
|
||||
st_gpio_config alarm_led = LED_INIT(ALARM);
|
||||
st_gpio_config running_led = LED_INIT(RUNNING);
|
||||
*/
|
||||
|
||||
/*
|
||||
st_gpio_config running_led = {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_1, GPIO_Mode_IPU}; //PA1 运行
|
||||
st_gpio_config alarm_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_3, GPIO_Mode_IPU}; //PC3 告警
|
||||
|
||||
st_gpio_config plcRx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_0, GPIO_Mode_IPU}; //PC0 PLC RX
|
||||
st_gpio_config plcTx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_2, GPIO_Mode_IPU}; //PC2 PLC TX
|
||||
|
||||
st_gpio_config up_RS485Rx_led = {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_12, GPIO_Mode_IPU}; //PA12 4851RX 485上行
|
||||
st_gpio_config up_RS485Tx_led = {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_11, GPIO_Mode_IPU}; //PA11 4851TX
|
||||
|
||||
st_gpio_config MBUS1Rx_led = {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_8, GPIO_Mode_IPU}; //PA8 MBUS1RX
|
||||
st_gpio_config MBUS1Tx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_9, GPIO_Mode_IPU}; //PC9 MBUS1TX
|
||||
|
||||
st_gpio_config dn_RS485Rx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_8, GPIO_Mode_IPU}; //PC8 4852RX 485下行
|
||||
st_gpio_config dn_RS485Rx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_7, GPIO_Mode_IPU}; //PC7 4852TX
|
||||
|
||||
st_gpio_config MBUS2Rx_led = {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_6, GPIO_Mode_IPU}; //PC6 MBUS2RX
|
||||
st_gpio_config MBUS2Tx_led = {GPIOB, RCC_APB2Periph_GPIOB, GPIO_Pin_15, GPIO_Mode_IPU}; //PB15 MBUS2TX
|
||||
*/
|
||||
|
||||
st_gpio_config led_boardharddetect[1] =
|
||||
{
|
||||
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_1, GPIO_Mode_IPU}, //PA1 运行
|
||||
};
|
||||
|
||||
|
||||
|
||||
st_gpio_config led_list[] =
|
||||
{
|
||||
#if HARDBOARD_VERSION == 0
|
||||
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_1, GPIO_Mode_IPU}, //PA1 运行
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_3, GPIO_Mode_IPU}, //PC3 告警
|
||||
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_0, GPIO_Mode_IPU}, //PC0 PLC RX RED
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_2, GPIO_Mode_IPU}, //PC2 PLC TX
|
||||
|
||||
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_12, GPIO_Mode_IPU}, //PA12 4851RX RED
|
||||
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_11, GPIO_Mode_IPU}, //PA11 4851TX GREEN
|
||||
|
||||
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_8, GPIO_Mode_IPU}, //PA8 MBUS1RX
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_9, GPIO_Mode_IPU}, //PC9 MBUS1TX
|
||||
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_8, GPIO_Mode_IPU}, //PC8 4852RX
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_7, GPIO_Mode_IPU}, //PC7 4852TX
|
||||
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_6, GPIO_Mode_IPU}, //PC6 MBUS2RX
|
||||
{GPIOB, RCC_APB2Periph_GPIOB, GPIO_Pin_15, GPIO_Mode_IPU}, //PB15 MBUS2TX
|
||||
|
||||
|
||||
// {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_1, GPIO_Mode_IPD}, //PA1 运行
|
||||
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_3, GPIO_Mode_IPD}, //PC3 告警
|
||||
//
|
||||
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_0, GPIO_Mode_IPD}, //PC0 PLC RX RED
|
||||
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_2, GPIO_Mode_IPD}, //PC2 PLC TX
|
||||
//
|
||||
// {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_12, GPIO_Mode_IPD}, //PA12 4851RX RED
|
||||
// {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_11, GPIO_Mode_IPD}, //PA11 4851TX GREEN
|
||||
//
|
||||
// {GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_8, GPIO_Mode_IPD}, //PA8 MBUS1RX
|
||||
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_9, GPIO_Mode_IPD}, //PC9 MBUS1TX
|
||||
//
|
||||
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_8, GPIO_Mode_IPD}, //PC8 4852RX
|
||||
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_7, GPIO_Mode_IPD}, //PC7 4852TX
|
||||
//
|
||||
// {GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_6, GPIO_Mode_IPD}, //PC6 MBUS2RX
|
||||
// {GPIOB, RCC_APB2Periph_GPIOB, GPIO_Pin_15, GPIO_Mode_IPD}, //PB15 MBUS2TX
|
||||
|
||||
#else
|
||||
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_1, GPIO_Mode_Out_OD}, //PA1 运行
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_3, GPIO_Mode_Out_OD}, //PC3 告警
|
||||
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_0, GPIO_Mode_Out_OD}, //PC0 PLC RX RED
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_2, GPIO_Mode_Out_OD}, //PC2 PLC TX
|
||||
|
||||
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_12, GPIO_Mode_Out_OD}, //PA12 4851RX RED
|
||||
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_11, GPIO_Mode_Out_OD}, //PA11 4851TX GREEN
|
||||
|
||||
{GPIOA, RCC_APB2Periph_GPIOA, GPIO_Pin_8, GPIO_Mode_Out_OD}, //PA8 MBUS1RX
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_9, GPIO_Mode_Out_OD}, //PC9 MBUS1TX
|
||||
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_8, GPIO_Mode_Out_OD}, //PC8 4852RX
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_7, GPIO_Mode_Out_OD}, //PC7 4852TX
|
||||
|
||||
{GPIOC, RCC_APB2Periph_GPIOC, GPIO_Pin_6, GPIO_Mode_Out_OD}, //PC6 MBUS2RX
|
||||
{GPIOB, RCC_APB2Periph_GPIOB, GPIO_Pin_15, GPIO_Mode_Out_OD}, //PB15 MBUS2TX
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
st_gpio_config * CurrentOperationLED = &led_list[0];
|
||||
/*——————————————————————————
|
||||
* 函 数 名:LED_Init
|
||||
* 输入参数:led 灯
|
||||
* 输出参数:None
|
||||
* 返 回 值:None
|
||||
* 功能说明:初始化LED灯
|
||||
*——————————————————————————*/
|
||||
void LED_Init(st_gpio_config led)
|
||||
{
|
||||
gpio_init(led);
|
||||
LED_Off(led);
|
||||
}
|
||||
|
||||
|
||||
void init_all_led(void)
|
||||
{
|
||||
|
||||
LED_Init(led_boardharddetect[0]);
|
||||
if(GPIO_ReadInputDataBit(led_boardharddetect[0].GPIO_port,led_boardharddetect[0].GPIO_Pin) == 0x01)
|
||||
{
|
||||
OLDNEW_VERSION_DETECT = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
OLDNEW_VERSION_DETECT = false;
|
||||
}
|
||||
|
||||
for (u8 i = 0; i < sizeof(led_list) / sizeof(st_gpio_config); i++)
|
||||
{
|
||||
if(OLDNEW_VERSION_DETECT == false)
|
||||
{
|
||||
led_list[i].GPIO_mode = GPIO_Mode_IPU;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_list[i].GPIO_mode = GPIO_Mode_Out_OD;
|
||||
}
|
||||
|
||||
LED_Init(led_list[i]);
|
||||
LED_Off(led_list[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void test_led(void)
|
||||
{
|
||||
for (u8 i = 0; i < sizeof(led_list) / sizeof(st_gpio_config); i++)
|
||||
{
|
||||
COM_led_on(i);
|
||||
//vTaskDelay( 1000 / portTICK_RATE_MS );
|
||||
//COM_led_off(i);
|
||||
//vTaskDelay( 1000 / portTICK_RATE_MS );
|
||||
}
|
||||
|
||||
printf("OK\r\n");
|
||||
}
|
||||
|
||||
|
||||
void COM_led_init(u8 led)
|
||||
{
|
||||
LED_Init(led_list[led]);
|
||||
}
|
||||
|
||||
void COM_led_on(u8 led)
|
||||
{
|
||||
LED_On(led_list[led]);
|
||||
}
|
||||
|
||||
void COM_led_off(u8 led)
|
||||
{
|
||||
LED_Off(led_list[led]);
|
||||
}
|
||||
|
||||
/*——————————————————————————
|
||||
* 函 数 名:LED_On
|
||||
* 输入参数:led 灯
|
||||
* 输出参数:None
|
||||
* 返 回 值:None
|
||||
* 功能说明:点亮Led灯
|
||||
*——————————————————————————*/
|
||||
void LED_On(st_gpio_config led)
|
||||
{
|
||||
//#if HARDBOARD_VERSION == 0
|
||||
if(OLDNEW_VERSION_DETECT == false)
|
||||
led.GPIO_port->BSRR = led.GPIO_Pin;//GPIO_PIN[led]; //设置位为 1
|
||||
//#else
|
||||
else
|
||||
led.GPIO_port->BRR = led.GPIO_Pin;
|
||||
//#endif
|
||||
}
|
||||
|
||||
/*——————————————————————————
|
||||
* 函 数 名:LED_Off
|
||||
* 输入参数:led 灯
|
||||
* 输出参数:None
|
||||
* 返 回 值:None
|
||||
* 功能说明:关闭Led灯
|
||||
*——————————————————————————*/
|
||||
void LED_Off(st_gpio_config led)
|
||||
{
|
||||
//#if HARDBOARD_VERSION == 0
|
||||
if(OLDNEW_VERSION_DETECT == false)
|
||||
led.GPIO_port->BRR = led.GPIO_Pin;//GPIO_PIN[led]; //清除位为 0
|
||||
//#else
|
||||
else
|
||||
led.GPIO_port->BSRR = led.GPIO_Pin;
|
||||
//#endif
|
||||
}
|
||||
|
||||
/*——————————————————————————
|
||||
* 函 数 名:LED_Toggle
|
||||
* 输入参数:led 灯
|
||||
* 输出参数:None
|
||||
* 返 回 值:None
|
||||
* 功能说明:电平反转
|
||||
*——————————————————————————*/
|
||||
void LED_Toggle(st_gpio_config led)
|
||||
{
|
||||
//#if HARDBOARD_VERSION == 0
|
||||
if(OLDNEW_VERSION_DETECT == false)
|
||||
led.GPIO_port->ODR ^= led.GPIO_Pin;//GPIO_PIN[led];
|
||||
//#else
|
||||
else
|
||||
led.GPIO_port->ODR ^= led.GPIO_Pin;
|
||||
//#endif
|
||||
}
|
||||
|
||||
|
||||
void off_all_led(void)
|
||||
{
|
||||
for (u8 i = 0; i < sizeof(led_list) / sizeof(st_gpio_config); i++)
|
||||
{
|
||||
//LED_Init(led_list[i]);
|
||||
LED_Off(led_list[i]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user