2b9622f565
- 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构造模式
56 lines
739 B
C++
56 lines
739 B
C++
#include "led_driver.h"
|
|
|
|
Led::Led(GpioPort port, uint32_t pin)
|
|
: bus_(port), pin_(bus_, pin)
|
|
{
|
|
}
|
|
|
|
RetCode Led::init()
|
|
{
|
|
RetCode ret = bus_.init();
|
|
if (ret != RET_OK) return ret;
|
|
ret = pin_.init();
|
|
if (ret != RET_OK) return ret;
|
|
off();
|
|
return RET_OK;
|
|
}
|
|
|
|
void Led::on()
|
|
{
|
|
pin_.set();
|
|
}
|
|
|
|
void Led::off()
|
|
{
|
|
pin_.reset();
|
|
}
|
|
|
|
void Led::toggle()
|
|
{
|
|
pin_.toggle();
|
|
}
|
|
|
|
LedManager &LedManager::instance()
|
|
{
|
|
static LedManager mgr;
|
|
return mgr;
|
|
}
|
|
|
|
LedManager::LedManager()
|
|
{
|
|
}
|
|
|
|
RetCode LedManager::init_all()
|
|
{
|
|
for (auto *l : leds_) {
|
|
RetCode ret = l->init();
|
|
if (ret != RET_OK) return ret;
|
|
}
|
|
return RET_OK;
|
|
}
|
|
|
|
Led &LedManager::led(uint8_t index)
|
|
{
|
|
return *leds_[index];
|
|
}
|