From 25bd873f943c336ce3e8f53d5be006a90b5ef944 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sat, 10 Aug 2019 12:54:23 +0200 Subject: [PATCH] Fixed non-portable preprocessor defines --- io.hpp | 83 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 33 deletions(-) diff --git a/io.hpp b/io.hpp index 7b91716..cf5f519 100644 --- a/io.hpp +++ b/io.hpp @@ -7,25 +7,42 @@ ////////////////////////////////////////////////////////////////////////// // Preprocessor defines -#define GPIO_32 \ - defined(__AVR_ATmega32__) || defined(__AVR_ATmega32A__) || defined(__AVR_ATmega644P__) || \ - defined(__AVR_ATmega1284P__) -#define GPIO_23 \ - defined(__AVR_ATmega8__) || defined(__AVR_ATmega8A__) || defined(__AVR_ATmega168A__) || defined(__AVR_ATmega328P__) -#define GPIO_6 defined(__AVR_ATtiny13A__) || defined(__AVR_ATtiny85__) +#if defined(__AVR_ATmega32__) || defined(__AVR_ATmega32A__) || defined(__AVR_ATmega644P__) || \ + defined(__AVR_ATmega1284P__) +#define GPIO_32 +#endif -#define HARDWARE_TOGGLE \ - defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega168A__) || \ - defined(__AVR_ATmega328P__) || defined(__AVR_ATtiny13A__) || defined(__AVR_ATtiny85__) +#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega8A__) || defined(__AVR_ATmega168A__) || defined(__AVR_ATmega328P__) +#define GPIO_23 +#endif -#define PORT_A_AVAILABLE GPIO_32 -#define PORT_B_AVAILABLE GPIO_32 || GPIO_23 || GPIO_6 -#define PORT_C_AVAILABLE GPIO_32 || GPIO_23 -#define PORT_D_AVAILABLE GPIO_32 || GPIO_23 +#if defined(__AVR_ATtiny13A__) || defined(__AVR_ATtiny85__) +#define GPIO_6 +#endif -#define PIN_B6_AVAILABLE GPIO_32 || GPIO_23 -#define PIN_B7_AVAILABLE GPIO_32 || GPIO_23 -#define PIN_C7_AVAILABLE GPIO_32 +#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega168A__) || \ + defined(__AVR_ATmega328P__) || defined(__AVR_ATtiny13A__) || defined(__AVR_ATtiny85__) +#define HARDWARE_TOGGLE +#endif + +#ifdef GPIO_32 +#define PORT_A_AVAILABLE +#endif + +#if defined(GPIO_32) || defined(GPIO_23) || defined(GPIO_6) +#define PORT_B_AVAILABLE +#endif + +#if defined(GPIO_32) || defined(GPIO_23) +#define PORT_C_AVAILABLE +#define PORT_D_AVAILABLE +#define PIN_B6_AVAILABLE +#define PIN_B7_AVAILABLE +#endif + +#if defined(GPIO_32) +#define PIN_C7_AVAILABLE +#endif #define FORCE_INLINE __attribute__((always_inline)) @@ -37,7 +54,7 @@ namespace io { enum class Dir { IN, OUT }; enum class P { -#if PORT_A_AVAILABLE +#ifdef PORT_A_AVAILABLE A0 = 0x00, A1 = 0x01, A2 = 0x02, @@ -48,22 +65,22 @@ enum class P { A7 = 0x07, #endif -#if PORT_B_AVAILABLE +#ifdef PORT_B_AVAILABLE B0 = 0x10, B1 = 0x11, B2 = 0x12, B3 = 0x13, B4 = 0x14, B5 = 0x15, -#if PIN_B6_AVAILABLE +#ifdef PIN_B6_AVAILABLE B6 = 0x16, #endif -#if PIN_B7_AVAILABLE +#ifdef PIN_B7_AVAILABLE B7 = 0x17, #endif #endif -#if PORT_C_AVAILABLE +#ifdef PORT_C_AVAILABLE C0 = 0x20, C1 = 0x21, C2 = 0x22, @@ -71,12 +88,12 @@ enum class P { C4 = 0x24, C5 = 0x25, C6 = 0x26, -#if PIN_C7_AVAILABLE +#ifdef PIN_C7_AVAILABLE C7 = 0x27, #endif #endif -#if PORT_D_AVAILABLE +#ifdef PORT_D_AVAILABLE D0 = 0x30, D1 = 0x31, D2 = 0x32, @@ -89,16 +106,16 @@ enum class P { }; enum class Bus { -#if PORT_A_AVAILABLE +#ifdef PORT_A_AVAILABLE A = 0x00, #endif -#if PORT_B_AVAILABLE +#ifdef PORT_B_AVAILABLE B = 0x01, #endif -#if PORT_C_AVAILABLE +#ifdef PORT_C_AVAILABLE C = 0x02, #endif -#if PORT_D_AVAILABLE +#ifdef PORT_D_AVAILABLE D = 0x03, #endif }; @@ -108,7 +125,7 @@ enum class Bus { namespace detail { -#if PORT_A_AVAILABLE +#ifdef PORT_A_AVAILABLE static constexpr volatile uint8_t *PORT_A_DIR_REG = &DDRA; static constexpr volatile uint8_t *PORT_A_OUTPUT_REG = &PORTA; static constexpr volatile uint8_t *PORT_A_INPUT_REG = &PINA; @@ -118,7 +135,7 @@ static constexpr volatile uint8_t *PORT_A_OUTPUT_REG = nullptr; static constexpr volatile uint8_t *PORT_A_INPUT_REG = nullptr; #endif -#if PORT_B_AVAILABLE +#ifdef PORT_B_AVAILABLE static constexpr volatile uint8_t *PORT_B_DIR_REG = &DDRB; static constexpr volatile uint8_t *PORT_B_OUTPUT_REG = &PORTB; static constexpr volatile uint8_t *PORT_B_INPUT_REG = &PINB; @@ -128,7 +145,7 @@ static constexpr volatile uint8_t *PORT_B_OUTPUT_REG = nullptr; static constexpr volatile uint8_t *PORT_B_INPUT_REG = nullptr; #endif -#if PORT_C_AVAILABLE +#ifdef PORT_C_AVAILABLE static constexpr volatile uint8_t *PORT_C_DIR_REG = &DDRC; static constexpr volatile uint8_t *PORT_C_OUTPUT_REG = &PORTC; static constexpr volatile uint8_t *PORT_C_INPUT_REG = &PINC; @@ -138,7 +155,7 @@ static constexpr volatile uint8_t *PORT_C_OUTPUT_REG = nullptr; static constexpr volatile uint8_t *PORT_C_INPUT_REG = nullptr; #endif -#if PORT_D_AVAILABLE +#ifdef PORT_D_AVAILABLE static constexpr volatile uint8_t *PORT_D_DIR_REG = &DDRD; static constexpr volatile uint8_t *PORT_D_OUTPUT_REG = &PORTD; static constexpr volatile uint8_t *PORT_D_INPUT_REG = &PIND; @@ -259,7 +276,7 @@ class Pin { static inline void toggle() FORCE_INLINE { -#if HARDWARE_TOGGLE +#ifdef HARDWARE_TOGGLE constexpr auto bus = detail::getBus(pin); constexpr auto pinReg = detail::getPIN(bus); constexpr auto pinBit = detail::getPin(pin); @@ -342,7 +359,7 @@ class Port { static inline void invert() FORCE_INLINE { -#if HARDWARE_TOGGLE +#ifdef HARDWARE_TOGGLE constexpr auto pinReg = detail::getPIN(port); *pinReg = 0xFF;