Skip to content
Snippets Groups Projects
Commit 34d55c30 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

AVR GPIO: Add pullup support

parent 444e0329
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
#include "driver/gpio.h"
#include <avr/io.h>
#include <avr/interrupt.h>
GPIO gpio;
ISR(PCINT0_vect)
{
}
ISR(PCINT1_vect)
{
}
ISR(PCINT2_vect)
{
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment