shuichan_old/V1.4-Chinese/STM32F103_App1/HardWare/LED/led.c

54 lines
1.2 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "led.h"
static uint32_t last_tick = 0;
static uint32_t net_led_tick = 0;
/* 联网状态标志0=未联网1=联网成功 */
volatile uint8_t g_net_led_connected = 0;
void ledInit(void)
{
GPIO_InitTypeDef g = {0};
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
g.Mode = GPIO_MODE_OUTPUT_PP;
g.Pull = GPIO_NOPULL;
g.Speed = GPIO_SPEED_FREQ_LOW;
/* LED2 - PC13 */
g.Pin = LED2_Pin;
HAL_GPIO_Init(LED2_Port, &g);
/* 联网指示灯 - PA1, 默认熄灭 */
g.Pin = NET_LED_Pin;
HAL_GPIO_Init(NET_LED_Port, &g);
LED2_OFF;
NET_LED_OFF;
g_net_led_connected = 0;
last_tick = HAL_GetTick();
net_led_tick = HAL_GetTick();
}
/* 主动事件: 每500ms LED2闪烁一次 */
void activeEvents(void)
{
if (HAL_GetTick() - last_tick >= 200) {
last_tick = HAL_GetTick();
LED2_TOGGLE;
}
/* 联网指示灯控制:未联网时每 500ms 闪烁,联网成功后常亮 */
if (!g_net_led_connected) {
if (HAL_GetTick() - net_led_tick >= 500) {
net_led_tick = HAL_GetTick();
NET_LED_TOGGLE;
}
} else {
NET_LED_ON;
}
}