From 34d55c304253fde0fc113f384f619171e3cf3167 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 7 Aug 2018 17:30:37 +0200 Subject: AVR GPIO: Add pullup support --- include/arch/arduino-nano/driver/gpio.h | 46 +++++++++++++++++++++++++++++++++ src/arch/arduino-nano/driver/gpio.cc | 13 ++++++++++ 2 files changed, 59 insertions(+) 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; diff --git a/src/arch/arduino-nano/driver/gpio.cc b/src/arch/arduino-nano/driver/gpio.cc index b1f9c63..707f2bd 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 +#include GPIO gpio; + +ISR(PCINT0_vect) +{ +} + +ISR(PCINT1_vect) +{ +} + +ISR(PCINT2_vect) +{ +} -- cgit v1.2.3