2026-04-26 16:24:42 +08:00
|
|
|
#ifndef __LED_DRIVER_H__
|
|
|
|
|
#define __LED_DRIVER_H__
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include "bus_core.h"
|
|
|
|
|
#include "gpio_driver.h"
|
|
|
|
|
|
|
|
|
|
class Led {
|
|
|
|
|
public:
|
2026-04-27 11:14:22 +08:00
|
|
|
Led(GpioPort port, uint32_t pin);
|
2026-04-26 16:24:42 +08:00
|
|
|
~Led() = default;
|
|
|
|
|
|
|
|
|
|
Led(const Led &) = delete;
|
|
|
|
|
Led &operator=(const Led &) = delete;
|
|
|
|
|
|
|
|
|
|
RetCode init();
|
|
|
|
|
void on();
|
|
|
|
|
void off();
|
|
|
|
|
void toggle();
|
|
|
|
|
|
|
|
|
|
private:
|
2026-04-27 11:14:22 +08:00
|
|
|
GpioBus bus_;
|
2026-04-26 16:24:42 +08:00
|
|
|
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;
|
|
|
|
|
|
2026-04-27 11:14:22 +08:00
|
|
|
Led led0_{GpioPort::E, 0x08};
|
|
|
|
|
Led led1_{GpioPort::D, 0x80};
|
|
|
|
|
Led led2_{GpioPort::G, 0x08};
|
|
|
|
|
Led led3_{GpioPort::A, 0x20};
|
2026-04-26 16:24:42 +08:00
|
|
|
|
2026-04-27 11:14:22 +08:00
|
|
|
Led *leds_[LED_COUNT] = {&led0_, &led1_, &led2_, &led3_};
|
2026-04-26 16:24:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|