aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2015-01-29 00:01:46 +0100
committerKarel Kočí <cynerd@email.cz>2015-01-29 00:01:46 +0100
commit0be64cb86f8856dc8342a24c5d99290d7e1cc8d2 (patch)
treebd8d0411975823d99ae7ae359265bfbf2fae9645
downloadavr-ioe-0be64cb86f8856dc8342a24c5d99290d7e1cc8d2.tar.gz
avr-ioe-0be64cb86f8856dc8342a24c5d99290d7e1cc8d2.tar.bz2
avr-ioe-0be64cb86f8856dc8342a24c5d99290d7e1cc8d2.zip
Initial commit
Only GPIO output implemented. Implementing: Macros gpio_get_mode(SET, PIN) gpio_set_out(SET, PIN) gpio_set_in(SET, PIN) gpio_set_high(SET, PIN) gpio_set_low(SET, PIN) gpio_set_value(SET, PIN, VALUE)
-rw-r--r--GPIO.h35
-rw-r--r--README.md6
2 files changed, 41 insertions, 0 deletions
diff --git a/GPIO.h b/GPIO.h
new file mode 100644
index 0000000..0c7ba72
--- /dev/null
+++ b/GPIO.h
@@ -0,0 +1,35 @@
+#include <avr/io.h>
+#include <stdint.h>
+
+#ifndef _IOE_GPIO_H_
+#define _IOE_GPIO_H_
+
+#define __GPIO_JOIN2(TXT1, TXT2) TXT1##TXT2
+#define __GPIO_JOIN3(TXT1, TXT2, TXT3) TXT1##TXT2##TXT3
+
+#define gpio_get_mode(SET, PIN) \
+ __GPIO_JOIN2(DDR, SET) & _BV(__GPIO_JOIN3(DD, SET, PIN))
+
+// GPIO output section
+#define gpio_set_out(SET, PIN) \
+ __GPIO_JOIN2(DDR, SET) |= _BV(__GPIO_JOIN3(DD, SET, PIN))
+
+#define gpio_set_high(SET, PIN) \
+ __GPIO_JOIN2(PORT, SET) |= _BV(__GPIO_JOIN3(PORT, SET, PIN))
+
+#define gpio_set_low(SET, PIN) \
+ __GPIO_JOIN2(PORT, SET) &= ~_BV(__GPIO_JOIN3(PORT, SET, PIN))
+
+#define gpio_set(SET, PIN, VALUE) \
+ if (value) \
+ gpio_set_high(SET, PIN); \
+ else \
+ gpio_set_low(SET, PIN);
+
+// GPIO input section
+#define gpio_set_in(SET, PIN) \
+ __GPIO_JOIN2(DDR, SET) &= ~_BV(__GPIO_JOIN3(DD, SET, PIN))
+
+// TODO whole output and switching betwen input and output
+
+#endif /* _IOE_GPIO_H_ */
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..015c9d4
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+#AVR-IOE
+##AVR input/output expansion
+
+
+
+This is package of code for various inputs and outputs from AVR micro-controllers. Code is targeted for three different chips, ATmega328p, ATmega32u4 and ATtiny85. But should support all AVR5 and AVR25 micro-controllers.