Added support for hardware toggle

This commit is contained in:
BlackMark 2019-07-26 19:44:20 +02:00
parent 468368692e
commit c1820f62f1

12
io.hpp
View File

@ -14,6 +14,10 @@
defined(__AVR_ATmega8__) || defined(__AVR_ATmega8A__) || defined(__AVR_ATmega168A__) || defined(__AVR_ATmega328P__) defined(__AVR_ATmega8__) || defined(__AVR_ATmega8A__) || defined(__AVR_ATmega168A__) || defined(__AVR_ATmega328P__)
#define GPIO_6 defined(__AVR_ATtiny13A__) || defined(__AVR_ATtiny85__) #define GPIO_6 defined(__AVR_ATtiny13A__) || defined(__AVR_ATtiny85__)
#define HARDWARE_TOGGLE \
defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega168A__) || \
defined(__AVR_ATmega328P__) || defined(__AVR_ATtiny13A__) || defined(__AVR_ATtiny85__)
#define PORT_A_AVAILABLE GPIO_32 #define PORT_A_AVAILABLE GPIO_32
#define PORT_B_AVAILABLE GPIO_32 || GPIO_23 || GPIO_6 #define PORT_B_AVAILABLE GPIO_32 || GPIO_23 || GPIO_6
#define PORT_C_AVAILABLE GPIO_32 || GPIO_23 #define PORT_C_AVAILABLE GPIO_32 || GPIO_23
@ -255,11 +259,19 @@ class Pin {
static inline void toggle() FORCE_INLINE static inline void toggle() FORCE_INLINE
{ {
#if HARDWARE_TOGGLE
constexpr auto bus = detail::getBus(pin);
constexpr auto pinReg = detail::getPIN(bus);
constexpr auto pinBit = detail::getPin(pin);
*pinReg |= (1 << pinBit);
#else
constexpr auto bus = detail::getBus(pin); constexpr auto bus = detail::getBus(pin);
constexpr auto portReg = detail::getPORT(bus); constexpr auto portReg = detail::getPORT(bus);
constexpr auto pinBit = detail::getPin(pin); constexpr auto pinBit = detail::getPin(pin);
*portReg ^= (1 << pinBit); *portReg ^= (1 << pinBit);
#endif
} }
static inline bool read() FORCE_INLINE static inline bool read() FORCE_INLINE