Files
lishanpi/bsp/device/led/led_driver.h
T
hm 2b9622f565 refactor: UartBus全面重构为USART,支持直接构造即可用
- UartBus -> USART (类名更符合外设命名规范)
- 构造函数 USART(UartPort port, uint32_t baudrate) 自动完成GPIO+外设初始化
- 移除default_instance()单例模式,移除init()/deinit()/irq_handler()
- 新增reinit(baudrate)支持时钟切换后波特率重新校准
- 新增static setDefault()用于printf路由选择
- 移除UartConfig配置结构体
- 更新iap.h/iap.cpp中UartBus引用为USART
- 更新main.cpp使用新USART构造模式
2026-04-27 11:14:22 +08:00

49 lines
894 B
C++

#ifndef __LED_DRIVER_H__
#define __LED_DRIVER_H__
#include <cstdint>
#include "bus_core.h"
#include "gpio_driver.h"
class Led {
public:
Led(GpioPort port, uint32_t pin);
~Led() = default;
Led(const Led &) = delete;
Led &operator=(const Led &) = delete;
RetCode init();
void on();
void off();
void toggle();
private:
GpioBus bus_;
GpioPin pin_;
};
class LedManager {
public:
static LedManager &instance();
RetCode init_all();
Led &led(uint8_t index);
LedManager(const LedManager &) = delete;
LedManager &operator=(const LedManager &) = delete;
private:
LedManager();
static constexpr uint8_t LED_COUNT = 4;
Led led0_{GpioPort::E, 0x08};
Led led1_{GpioPort::D, 0x80};
Led led2_{GpioPort::G, 0x08};
Led led3_{GpioPort::A, 0x20};
Led *leds_[LED_COUNT] = {&led0_, &led1_, &led2_, &led3_};
};
#endif