diff --git a/include/arch/arduino-nano/driver/gpio.h b/include/arch/arduino-nano/driver/gpio.h index 6acf977e720847e5495eea8c1a971ad4d66d563d..1a2fbe079daf97272ad35f539cb74224b35e5899 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; diff --git a/src/arch/arduino-nano/driver/gpio.cc b/src/arch/arduino-nano/driver/gpio.cc index b1f9c63401cd7f2d21848f6c0d64869a93c28703..707f2bddae8ebd6ef6349849314389c72eeb29c5 100644 --- a/src/arch/arduino-nano/driver/gpio.cc +++ b/src/arch/arduino-nano/driver/gpio.cc @@ -1,4 +1,17 @@ #include "driver/gpio.h" #include <avr/io.h> +#include <avr/interrupt.h> GPIO gpio; + +ISR(PCINT0_vect) +{ +} + +ISR(PCINT1_vect) +{ +} + +ISR(PCINT2_vect) +{ +}