Implemented peeking with and without data for interrupt and blocking mode

This commit is contained in:
2019-08-02 18:20:06 +02:00
parent 95963295e2
commit a3d76a138d
4 changed files with 67 additions and 7 deletions

View File

@@ -105,7 +105,17 @@ class Hardware1 {
return HardwareImpl::rxByteBlocking(byte);
}
static data_t peek() FORCE_INLINE {}
static bool peek(data_t &byte) FORCE_INLINE
{
static_cast<void>(byte);
static_assert(driven != Driven::BLOCKING, "Peek with data is not supported in blocking mode");
return false;
}
static bool peek() FORCE_INLINE
{
return HardwareImpl::peekBlocking();
}
private:
using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1,
@@ -144,14 +154,27 @@ class Hardware1<mode, cfg, Driven::INTERRUPT> {
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 {}
static bool peek(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];
return true;
}
static bool peek() FORCE_INLINE
{
return (sm_rxBuf.head != sm_rxBuf.tail);
}
private:
using HardwareImpl = detail::Hardware<detail::Registers1, detail::ControlFlagsA1, detail::ControlFlagsB1,