#ifndef LED_H #define LED_H /** * led.h — OOPC 不透明指针接口 * * 外部调用者只能看到: * 1. typedef struct Led_S Led_S; ← 前向声明,无结构体内容 * 2. 所有 API 函数声明 * 结构体字段完全隐藏在 led.c 中 */ #include "stm32f10x.h" /* ── 返回码枚举 ── */ typedef enum { LED_OK = 0, LED_ERR_NULL = -1, LED_ERR_PIN = -2 } Led_Err; /* ── 前向声明:不透明指针类型 ── */ typedef struct Led_S Led_S; /* ── 公开 API ── */ /** * Led_Create — 在指定 GPIO 端口/引脚上创建一个 LED 对象 * @param port GPIO 基地址,如 GPIOA、GPIOB * @param pin GPIO_Pin_x,如 GPIO_Pin_0、GPIO_Pin_13 * @return 不透明指针,失败返回 NULL */ Led_S* Led_Create(GPIO_TypeDef* port, uint16_t pin); /** * Led_On — 点亮 LED */ void Led_On(Led_S* me); /** * Led_Off — 熄灭 LED */ void Led_Off(Led_S* me); /** * Led_Toggle — 翻转 LED 状态 */ void Led_Toggle(Led_S* me); /** * Led_GetState — 读取当前 LED 状态 * @return 0=灭, 1=亮 */ uint8_t Led_GetState(const Led_S* me); /** * Led_SetBrightness — 通过 PWM 设置亮度(0-100) * 注释:本 Demo 不做 PWM,仅保留接口展示扩展能力 */ void Led_SetBrightness(Led_S* me, uint8_t pct); /** * Led_Destroy — 销毁 LED 对象,归还内存池槽位 */ void Led_Destroy(Led_S* me); #endif /* LED_H */