/
bortsov
/
ch32v203-BatteryDisplay
Обзор
Документация
Войти
/
bortsov
/
ch32v203-BatteryDisplay
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
source/HeartbeatLed.cpp
37 строк
915 B
Vitaliy Bortsov
gpio: optimizing access by new API
12 апр 2026, 20:22
12 апр 2026, 20:22
050e9e2
Код
Авторство
О чём код?
#include "HeatbeatLed.h" class HeartbeatLedImplementation: public LedInterface { public: HeartbeatLedImplementation(const enum Gpio id, const int nPin) : LedInterface{}, gpio_{id}, nPin_{nPin} { gpio::init(gpio_, nPin_, GpioMode::OUT_PUSHPULL, GpioSpeed::SPEED_2Mhz); } virtual void on() override{} virtual void off() override{} virtual void toggle() override { if (state_) { state_ = false; gpio::reset(gpio_, nPin_); } else { state_ = true; gpio::set(gpio_, nPin_); } } virtual void setPeriod(const int ms) override{} virtual void process(const int time_ms) override{} ~HeartbeatLedImplementation() = default; private: const enum Gpio gpio_; const int nPin_; bool state_{}; }; std::unique_ptr<LedInterface> createHeartbeatLed(const enum Gpio id, const int nPin) { return std::make_unique<HeartbeatLedImplementation>(id, nPin); }