mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
42 lines
968 B
C++
42 lines
968 B
C++
#include <sta/debug/printing/printable_uart.hpp>
|
|
|
|
#include <sta/debug/assert.hpp>
|
|
#include <sta/printf.hpp>
|
|
|
|
#include <cinttypes>
|
|
#include <cstring>
|
|
|
|
|
|
namespace sta
|
|
{
|
|
|
|
PrintableUART::PrintableUART(UART * intf)
|
|
: intf_{intf}
|
|
{
|
|
STA_ASSERT(intf != nullptr);
|
|
STA_ASSERT(intf->settings().mode == UARTMode::RX || intf->settings().mode == UARTMode::RX_TX);
|
|
}
|
|
|
|
void PrintableUART::print(const char * str, size_t length, bool newline /* = false */)
|
|
{
|
|
intf_->acquire();
|
|
intf_->transfer(reinterpret_cast<const uint8_t *>(str), length);
|
|
|
|
if (newline)
|
|
{
|
|
const char * linebreak = "\r\n";
|
|
intf_->transfer(reinterpret_cast<const uint8_t *>(linebreak), 2);
|
|
}
|
|
|
|
intf_->release();
|
|
}
|
|
|
|
void PrintableUART::read(uint8_t * buffer, size_t length)
|
|
{
|
|
intf_->acquire();
|
|
intf_->receive(buffer, length);
|
|
intf_->release();
|
|
}
|
|
|
|
} // namespace sta
|