Files
DTU-LCD/Drivers/BSP/LED/led.h
2026-01-24 20:03:14 +08:00

45 lines
1.5 KiB
C
Raw Permalink 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.
#ifndef __LED_H__
#define __LED_H__
#include "./SYSTEM/sys/sys.h"
/* LED状态枚举 - 使用枚举类型提高类型安全性 */
typedef enum {
LED_OFF = 0, /* LED熄灭 */
LED_ON = 1 /* LED点亮 */
} LED_State_t;
/* LED极性定义 */
#define LED_POLARITY_LOW_ACTIVE 0 /* 低电平有效(低电平亮) */
#define LED_POLARITY_HIGH_ACTIVE 1 /* 高电平有效(高电平亮) */
/* LED配置结构体 - 所有硬件相关参数集中在此 */
typedef struct {
GPIO_TypeDef *port; /* GPIO端口 (如: GPIOA, GPIOB, ...) */
uint16_t pin; /* GPIO引脚 (如: GPIO_PIN_0, GPIO_PIN_1, ...) */
uint8_t polarity; /* 极性LED_POLARITY_LOW_ACTIVE 或 LED_POLARITY_HIGH_ACTIVE */
GPIO_PinState default_state; /* 默认状态GPIO_PIN_SET 或 GPIO_PIN_RESET */
uint32_t speed; /* GPIO速度GPIO_SPEED_FREQ_LOW/MEDIUM/HIGH */
uint32_t pull; /* 上拉下拉GPIO_PULLUP/GPIO_PULLDOWN/GPIO_NOPULL */
} LED_Config_t;
/* LED数量定义 - 修改此值以适配不同数量的LED */
#define LED_COUNT 20
/* 函数声明 */
void LED_Init(void);
void LED_On(uint8_t led_id);
void LED_Off(uint8_t led_id);
void LED_Toggle(uint8_t led_id);
void LED_Set(uint8_t led_id, LED_State_t state);
LED_State_t LED_GetState(uint8_t led_id);
void LED_Printf(uint8_t* ledbuf);
/* 向后兼容的宏定义基于新的API实现 */
#define LED_POW(x) LED_Set(0, x) /* 电源指示灯 */
#define LED_RUN 1 /* 运行指示灯 */
#endif