From 35a62370fb5d9d44d6e7ce24a76472ebc6573a15 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 2 Sep 2019 20:01:35 +0200 Subject: Arduino Nano GPIO: Add pinToPort and pinToBitmask helpers --- include/arch/arduino-nano/driver/gpio.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include') diff --git a/include/arch/arduino-nano/driver/gpio.h b/include/arch/arduino-nano/driver/gpio.h index 72099bc..0b4ca26 100644 --- a/include/arch/arduino-nano/driver/gpio.h +++ b/include/arch/arduino-nano/driver/gpio.h @@ -39,6 +39,18 @@ class GPIO { inline void setup() { DDRB = _BV(PB5); } + inline volatile uint8_t * pinToPort(uint8_t pin) { + if (pin <= pb7) { + return &PORTB; + } + if (pin <= pc6) { + return &PORTC; + } + return &PORTD; + } + inline unsigned char pinToBitmask(uint8_t pin) { + return _BV(pin % 8); + } #pragma GCC diagnostic ignored "-Wunused-parameter" inline void led_on(unsigned char id) { PORTB |= _BV(PB5); -- cgit v1.2.3