From ddf105a1754b7054d31b49ac7ab48f73b9113676 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Thu, 15 Aug 2019 18:07:11 +0200 Subject: [PATCH] Made library header only again and provided way to disable interrupt vectors --- hardware.hpp | 2 +- hardware0.cpp | 35 ----------------------------------- hardware0.hpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- hardware1.cpp | 28 ---------------------------- hardware1.hpp | 40 +++++++++++++++++++++++++++++++++++++++- 5 files changed, 86 insertions(+), 66 deletions(-) delete mode 100644 hardware0.cpp delete mode 100644 hardware1.cpp diff --git a/hardware.hpp b/hardware.hpp index c359fb8..0cf5b8a 100644 --- a/hardware.hpp +++ b/hardware.hpp @@ -338,7 +338,7 @@ class InterruptHardware { } protected: - static void rxIntHandler() + static void rxIntHandler() FORCE_INLINE { auto data = HardwareImpl::rxByteInterrupt(); diff --git a/hardware0.cpp b/hardware0.cpp deleted file mode 100644 index d65e3a5..0000000 --- a/hardware0.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "hardware0.hpp" - -#include - -namespace uart { -namespace detail { - -#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; - -ISR(USART0_RX_vect) -{ - if (fnRx0IntHandler) - fnRx0IntHandler(); -} - -ISR(USART0_UDRE_vect) -{ - if (fnDataReg0EmptyIntHandler) - fnDataReg0EmptyIntHandler(); -} - -#else -#error "This chip is not supported" -#endif - -} // namespace detail -} // namespace uart diff --git a/hardware0.hpp b/hardware0.hpp index 4c13d84..7e7dcea 100644 --- a/hardware0.hpp +++ b/hardware0.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef UART_HARDWARE_0_HPP +#define UART_HARDWARE_0_HPP #include @@ -114,3 +115,47 @@ class Hardware0 } // namespace uart #undef FORCE_INLINE + +#endif + +////////////////////////////////////////////////////////////////////////// + +#ifdef UART0_INT_VECTORS + +#include + +namespace uart { +namespace detail { + +#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; + +ISR(USART0_RX_vect) +{ + if (fnRx0IntHandler) + fnRx0IntHandler(); +} + +ISR(USART0_UDRE_vect) +{ + if (fnDataReg0EmptyIntHandler) + fnDataReg0EmptyIntHandler(); +} + +#else +#error "This chip is not supported" +#endif + +} // namespace detail +} // namespace uart + +#undef UART0_INT_VECTORS + +#endif diff --git a/hardware1.cpp b/hardware1.cpp deleted file mode 100644 index 91d9f0c..0000000 --- a/hardware1.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "hardware1.hpp" - -#include - -namespace uart { -namespace detail { - -#if defined(__AVR_ATmega1284P__) - -void (*fnRx1IntHandler)() = nullptr; -void (*fnDataReg1EmptyIntHandler)() = nullptr; - -ISR(USART1_RX_vect) -{ - if (fnRx1IntHandler) - fnRx1IntHandler(); -} - -ISR(USART1_UDRE_vect) -{ - if (fnDataReg1EmptyIntHandler) - fnDataReg1EmptyIntHandler(); -} - -#endif - -} // namespace detail -} // namespace uart diff --git a/hardware1.hpp b/hardware1.hpp index 901012a..6023a61 100644 --- a/hardware1.hpp +++ b/hardware1.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef UART_HARDWARE_1_HPP +#define UART_HARDWARE_1_HPP #include @@ -118,3 +119,40 @@ class Hardware1 } // namespace uart #undef FORCE_INLINE + +#endif + +////////////////////////////////////////////////////////////////////////// + +#ifdef UART1_INT_VECTORS + +#include + +namespace uart { +namespace detail { + +#if defined(__AVR_ATmega1284P__) + +void (*fnRx1IntHandler)() = nullptr; +void (*fnDataReg1EmptyIntHandler)() = nullptr; + +ISR(USART1_RX_vect) +{ + if (fnRx1IntHandler) + fnRx1IntHandler(); +} + +ISR(USART1_UDRE_vect) +{ + if (fnDataReg1EmptyIntHandler) + fnDataReg1EmptyIntHandler(); +} + +#endif + +} // namespace detail +} // namespace uart + +#undef UART1_INT_VECTORS + +#endif