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构造模式
41 lines
871 B
C++
41 lines
871 B
C++
#ifndef __UART_DRIVER_H__
|
|
#define __UART_DRIVER_H__
|
|
|
|
#include <cstdint>
|
|
#include "bus_core.h"
|
|
|
|
enum class UartPort : uint8_t {
|
|
_0 = 0,
|
|
_1, _2, _3, _4, _5, _6,
|
|
MAX
|
|
};
|
|
|
|
class USART {
|
|
public:
|
|
USART(UartPort port, uint32_t baudrate = 115200);
|
|
~USART();
|
|
|
|
USART(const USART &) = delete;
|
|
USART &operator=(const USART &) = delete;
|
|
|
|
RetCode send_byte(uint8_t data);
|
|
RetCode send_data(const uint8_t *data, uint32_t len);
|
|
RetCode receive_byte(uint8_t *data, uint32_t timeout_ms);
|
|
void reinit(uint32_t baudrate);
|
|
|
|
UartPort port() const { return port_; }
|
|
bool is_initialized() const { return initialized_; }
|
|
|
|
static void setDefault(USART *uart);
|
|
static USART *defaultInstance() { return default_; }
|
|
|
|
private:
|
|
UartPort port_;
|
|
uint32_t baudrate_;
|
|
bool initialized_ = false;
|
|
|
|
static USART *default_;
|
|
};
|
|
|
|
#endif
|