Clean up usart class a bit
This commit is contained in:
@@ -9,6 +9,10 @@
|
|||||||
#include "stm32f4xx_hal_uart.h"
|
#include "stm32f4xx_hal_uart.h"
|
||||||
|
|
||||||
namespace driver::usart {
|
namespace driver::usart {
|
||||||
|
|
||||||
|
constexpr const uint8_t TX_BUFSIZE{20};
|
||||||
|
constexpr const uint8_t TX_TIMEOUT_MS{200};
|
||||||
|
|
||||||
class Usart {
|
class Usart {
|
||||||
public:
|
public:
|
||||||
explicit Usart(USART_TypeDef* usart, uint32_t baudRate, uint32_t wordLength, uint32_t stopBits,
|
explicit Usart(USART_TypeDef* usart, uint32_t baudRate, uint32_t wordLength, uint32_t stopBits,
|
||||||
@@ -23,6 +27,5 @@ class Usart {
|
|||||||
UART_HandleTypeDef mHandle{};
|
UART_HandleTypeDef mHandle{};
|
||||||
|
|
||||||
void tx(std::string_view range);
|
void tx(std::string_view range);
|
||||||
void flush();
|
|
||||||
};
|
};
|
||||||
} // namespace driver::usart
|
} // namespace driver::usart
|
@@ -1,18 +1,13 @@
|
|||||||
#include "usart.hpp"
|
#include "usart.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <ranges>
|
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
#include "stm32f4xx_hal_uart.h"
|
#include "stm32f4xx_hal_uart.h"
|
||||||
#include "usart.h"
|
|
||||||
|
|
||||||
namespace driver::usart {
|
namespace driver::usart {
|
||||||
|
|
||||||
constexpr const uint8_t TX_BUFSIZE{20};
|
|
||||||
|
|
||||||
Usart::Usart(USART_TypeDef* usart, uint32_t baudRate, uint32_t wordLength, uint32_t stopBits,
|
Usart::Usart(USART_TypeDef* usart, uint32_t baudRate, uint32_t wordLength, uint32_t stopBits,
|
||||||
uint32_t parity, uint32_t mode, uint32_t hwFlowCtl, uint32_t overSampling)
|
uint32_t parity, uint32_t mode, uint32_t hwFlowCtl, uint32_t overSampling)
|
||||||
: mHandle{.Instance = usart,
|
: mHandle{.Instance = usart,
|
||||||
@@ -37,14 +32,10 @@ void Usart::println(const std::string_view str) {
|
|||||||
tx("\r\n");
|
tx("\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Usart::flush() {
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
void Usart::tx(const std::string_view range) {
|
void Usart::tx(const std::string_view range) {
|
||||||
for (uint32_t pt{0}; pt <= range.size(); pt += TX_BUFSIZE) {
|
for (uint32_t pt{0}; pt <= range.size(); pt += TX_BUFSIZE) {
|
||||||
HAL_UART_Transmit(&mHandle, reinterpret_cast<const uint8_t*>(range.begin() + pt),
|
HAL_UART_Transmit(&mHandle, reinterpret_cast<const uint8_t*>(range.begin() + pt),
|
||||||
TX_BUFSIZE, 200);
|
TX_BUFSIZE, TX_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user