diff --git a/hardware0.hpp b/hardware0.hpp index 931399d..2cfc727 100644 --- a/hardware0.hpp +++ b/hardware0.hpp @@ -103,7 +103,10 @@ class Hardware0 { HardwareImpl::txByteBlocking(byte); } - static data_t rxByte() FORCE_INLINE {} + static bool rxByte(data_t &byte) FORCE_INLINE + { + return false; + } static data_t peek() FORCE_INLINE {} @@ -139,7 +142,18 @@ class Hardware0 { HardwareImpl::enableDataRegEmptyInt(); } - static data_t rxByte() FORCE_INLINE {} + static bool rxByte(data_t &byte) FORCE_INLINE + { + if (sm_rxBuf.head == sm_rxBuf.tail) + return false; + + uint8_t tmpTail = (sm_rxBuf.tail + 1) % RX_BUFFER_SIZE; + + byte = sm_rxBuf.buf[tmpTail]; + sm_rxBuf.tail = tmpTail; + + return true; + } static data_t peek() FORCE_INLINE {} @@ -148,12 +162,19 @@ class Hardware0 { detail::ControlFlagsC0, cfg, mode, Driven::INTERRUPT>; static constexpr auto TX_BUFFER_SIZE = 16; + static constexpr auto RX_BUFFER_SIZE = 16; static volatile detail::RingBuffer sm_txBuf; + static volatile detail::RingBuffer sm_rxBuf; static void rxIntHandler() { - // TODO + uint8_t tmpHead = (sm_rxBuf.head + 1) % RX_BUFFER_SIZE; + + if (tmpHead != sm_rxBuf.tail) { + sm_rxBuf.head = tmpHead; + sm_rxBuf.buf[tmpHead] = HardwareImpl::rxByteInterrupt(); + } } static void dataRegEmptyIntHandler() FORCE_INLINE @@ -177,6 +198,11 @@ volatile detail::RingBuffer::da Hardware0::TX_BUFFER_SIZE> Hardware0::sm_txBuf = {0, 0, {0}}; +template +volatile detail::RingBuffer::data_t, + Hardware0::RX_BUFFER_SIZE> + Hardware0::sm_rxBuf = {0, 0, {0}}; + } // namespace uart #undef FORCE_INLINE