#ifndef UART_H #define UART_H class UART { public: /** setup */ void init(UartBautRate rate) { uart_init(rate, rate); } /** how many chars are available for reading? */ uint8_t available() { return (READ_PERI_REG(UART_STATUS(UART0)) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT; } /** number of bytes within the TX-FIFO */ uint8_t txFifoUsed() const { return (( READ_PERI_REG(UART_STATUS(UART0))>>UART_TXFIFO_CNT_S)& UART_TXFIFO_CNT); } /** size of the TX FIFO */ uint8_t txFifoLen() const { return 126; } /** is it possible to add something to the TX fifo? */ uint8_t txFifoFree() const { return txFifoLen() - txFifoUsed(); } /** fetch one char from the uart */ char readChar() const { return READ_PERI_REG(UART_FIFO(UART0)) & 0xFF; } void writeChar(const char c) { while(!txFifoFree()) {;} WRITE_PERI_REG(UART_FIFO(UART0), c); } // void write(const char c) { // uart_tx_one_char(UART0, c); // } /** write the given data to the uart */ void write(const void* data, const uint16_t len) { for (uint16_t i = 0; i < len; ++i) { writeChar( ((uint8_t*)data)[i] ); //uart_tx_one_char(UART0, ((uint8_t*)data)[i]); } } }; extern UART uart; #endif // UART_H