summaryrefslogtreecommitdiff
path: root/include/arch/arduino-nano/driver
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-08-07 17:30:37 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-08-07 17:30:37 +0200
commit34d55c304253fde0fc113f384f619171e3cf3167 (patch)
tree9c8a4a5c49124d4a1ab9d5580d758f0c6f5aebc6 /include/arch/arduino-nano/driver
parent444e03292cf59f8d91e73084f1ed648e02662e58 (diff)
AVR GPIO: Add pullup support
Diffstat (limited to 'include/arch/arduino-nano/driver')
-rw-r--r--include/arch/arduino-nano/driver/gpio.h46
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;