diff options
author | Daniel Friesel <derf@finalrewind.org> | 2019-09-02 20:01:35 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2019-09-02 20:01:35 +0200 |
commit | 35a62370fb5d9d44d6e7ce24a76472ebc6573a15 (patch) | |
tree | d9e37030924c97a04dc023381e9c97a325b24366 /include/arch | |
parent | b8366cf9a5cf87336352b9862cd536660d243a12 (diff) |
Arduino Nano GPIO: Add pinToPort and pinToBitmask helpers
Diffstat (limited to 'include/arch')
-rw-r--r-- | include/arch/arduino-nano/driver/gpio.h | 12 |
1 files changed, 12 insertions, 0 deletions
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); |