diff options
Diffstat (limited to 'include/arch/arduino-nano')
-rw-r--r-- | include/arch/arduino-nano/driver/gpio.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/include/arch/arduino-nano/driver/gpio.h b/include/arch/arduino-nano/driver/gpio.h index 6acf977..1a2fbe0 100644 --- a/include/arch/arduino-nano/driver/gpio.h +++ b/include/arch/arduino-nano/driver/gpio.h @@ -58,6 +58,19 @@ class GPIO { DDRD &= ~_BV(pin - 24); } } + inline void input(unsigned char const pin, unsigned char const pull) { + if (pin < 8) { + } else if (pin < 16) { + DDRB &= ~_BV(pin - 8); + PORTB |= _BV(pin - 8); + } else if (pin < 24) { + DDRC &= ~_BV(pin - 16); + PORTC |= _BV(pin - 16); + } else if (pin < 32) { + DDRD &= ~_BV(pin - 24); + PORTD |= _BV(pin - 24); + } + } inline void output(unsigned char const pin) { if (pin < 8) { } else if (pin < 16) { @@ -68,6 +81,19 @@ class GPIO { DDRD |= _BV(pin - 24); } } + inline void output(unsigned char const pin, unsigned char const value) { + if (pin < 8) { + } else if (pin < 16) { + PORTB = value ? (PORTB | _BV(pin - 8)) : (PORTB & ~_BV(pin - 8)); + DDRB |= _BV(pin - 8); + } else if (pin < 24) { + PORTC = value ? (PORTC | _BV(pin - 16)) : (PORTC & ~_BV(pin - 16)); + DDRC |= _BV(pin - 16); + } else if (pin < 32) { + PORTD = value ? (PORTD | _BV(pin - 24)) : (PORTD & ~_BV(pin - 24)); + DDRD |= _BV(pin - 24); + } + } inline unsigned char read(unsigned char const pin) { if (pin < 8) { } @@ -104,6 +130,26 @@ class GPIO { } } } + inline void enable_int(unsigned char const pin) { + if (pin < 8) { + } else if (pin < 16) { + PCMSK0 |= _BV(pin - 8); + } else if (pin < 24) { + PCMSK1 |= _BV(pin - 16); + } else if (pin < 32) { + PCMSK2 |= _BV(pin - 24); + } + } + inline void disable_int(unsigned char const pin) { + if (pin < 8) { + } else if (pin < 16) { + PCMSK0 &= ~_BV(pin - 8); + } else if (pin < 24) { + PCMSK1 &= ~_BV(pin - 16); + } else if (pin < 32) { + PCMSK2 &= ~_BV(pin - 24); + } + } }; extern GPIO gpio; |