sta-core/src/hal/uart.cpp
2022-05-07 16:16:19 +02:00

44 lines
844 B
C++

#include <sta/hal/uart.hpp>
#ifdef STA_HAL_UART_ENABLE
#include <sta/assert.hpp>
namespace sta
{
HalUART::HalUART(UART_HandleTypeDef * handle)
: handle_{handle}
{
STA_ASSERT(handle != nullptr);
}
void HalUART::write(const uint8_t * buffer, size_t size)
{
STA_ASSERT(buffer != nullptr);
HAL_UART_Transmit(handle_, const_cast<uint8_t *>(buffer), size, HAL_MAX_DELAY);
}
} // namespace sta
#ifdef STA_HAL_UART_DEBUG_SERIAL
// Get extern declaration for DebugSerial because const namespace level variables have internal linkage by default
#include <sta/debug_serial.hpp>
#include <usart.h>
namespace sta
{
HalUART gHalDebugSerial(&STA_HAL_UART_DEBUG_SERIAL);
// Used by <sta/debug.hpp>
PrintableUART DebugSerial(&gHalDebugSerial);
} // namespace sta
#endif // STA_HAL_UART_DEBUG_SERIAL
#endif // STA_HAL_UART_ENABLE