#ifndef _TB_UART_HPP #define _TB_UART_HPP #include extern "C" { #include "tb_uart_io.h" } class TbUart { public: explicit constexpr TbUart(unsigned index) : index_(index) {} void write(char c) const { tb_uart_write(index_, static_cast(c)); } void write(const char *str) const { while (*str) write(*str++); } bool connected() const { return tb_uart_connected(index_); } bool canRead() const { return tb_uart_can_read(index_); } // Returns [0..255] on success, or -1 if RX FIFO is empty. int tryRead() const { return tb_uart_try_read(index_); } void clearOverrun() const { tb_uart_clear_overrun(index_); } private: unsigned index_; }; #endif