diff --git a/hardware.hpp b/hardware.hpp index abbc535..d78d6d0 100644 --- a/hardware.hpp +++ b/hardware.hpp @@ -220,7 +220,7 @@ class Hardware { uint8_t interruptVal = 0; if (driven == Driven::INTERRUPT) - interruptVal |= (1 << CtrlFlagsB::DATA_REG_EMPTY_INT_ENABLE) | (1 << CtrlFlagsB::RX_INT_ENABLE); + interruptVal = (1 << CtrlFlagsB::RX_INT_ENABLE); return interruptVal; } diff --git a/hardware0.cpp b/hardware0.cpp index 220f9b4..d65e3a5 100644 --- a/hardware0.cpp +++ b/hardware0.cpp @@ -5,7 +5,12 @@ namespace uart { namespace detail { -#if defined(__AVR_ATmega1284P__) +#if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega328P__) + +#if defined(__AVR_ATmega328P__) +#define USART0_RX_vect USART_RX_vect +#define USART0_UDRE_vect USART_UDRE_vect +#endif void (*fnRx0IntHandler)() = nullptr; void (*fnDataReg0EmptyIntHandler)() = nullptr; diff --git a/hardware0.hpp b/hardware0.hpp index 93c5f4d..3acbbd0 100644 --- a/hardware0.hpp +++ b/hardware0.hpp @@ -15,7 +15,7 @@ namespace uart { namespace detail { -#if defined(__AVR_ATmega1284P__) +#if defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega328P__) /* The following works in avr-gcc 5.4.0, but is not legal C++, because ptr's are not legal constexpr's @@ -213,11 +213,15 @@ class Hardware0 { static void rxIntHandler() { + auto data = HardwareImpl::rxByteInterrupt(); + 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(); + sm_rxBuf.buf[tmpHead] = data; + } else { + // TODO: Handle overflow } } diff --git a/hardware1.cpp b/hardware1.cpp index f7b70cc..91d9f0c 100644 --- a/hardware1.cpp +++ b/hardware1.cpp @@ -22,8 +22,6 @@ ISR(USART1_UDRE_vect) fnDataReg1EmptyIntHandler(); } -#else -#error "This chip is not supported" #endif } // namespace detail diff --git a/hardware1.hpp b/hardware1.hpp index b666379..3dbe177 100644 --- a/hardware1.hpp +++ b/hardware1.hpp @@ -84,8 +84,6 @@ extern void (*fnDataReg1EmptyIntHandler)(); #define HAS_UART1 -#else -#error "This chip is not supported" #endif } // namespace detail @@ -217,11 +215,15 @@ class Hardware1 { static void rxIntHandler() { + auto data = HardwareImpl::rxByteInterrupt(); + 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(); + sm_rxBuf.buf[tmpHead] = data; + } else { + // TODO: Handle overflow } }