aboutsummaryrefslogtreecommitdiff
path: root/lib/efm32
diff options
context:
space:
mode:
authorchrysn2012-03-01 02:09:02 +0100
committerchrysn2012-03-01 02:18:22 +0100
commit541fded753a27b8670c5b485ecec1794c02de187 (patch)
tree80bd29674e52d060d6e6aee0553ead0db0678355 /lib/efm32
parenta747e887bd819ad20bca83e8f43c9e81798a59f6 (diff)
convenience functions for efm32 gpio
also, the whole gpio header file is now a big doxygen group, structuring the convenience functions and the register/value definitions
Diffstat (limited to 'lib/efm32')
-rw-r--r--lib/efm32/tinygecko/Makefile2
-rw-r--r--lib/efm32/tinygecko/gpio.c23
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/efm32/tinygecko/Makefile b/lib/efm32/tinygecko/Makefile
index afe1e93..a2bffc1 100644
--- a/lib/efm32/tinygecko/Makefile
+++ b/lib/efm32/tinygecko/Makefile
@@ -30,7 +30,7 @@ CFLAGS = -Os -g -Wall -Wextra -I../../../include -fno-common \
-ffunction-sections -fdata-sections -MD -D$(FAMILY)
# ARFLAGS = rcsv
ARFLAGS = rcs
-OBJS = vector.o devicerevision.o
+OBJS = vector.o devicerevision.o gpio.o
VPATH += ../
diff --git a/lib/efm32/tinygecko/gpio.c b/lib/efm32/tinygecko/gpio.c
new file mode 100644
index 0000000..6e49f17
--- /dev/null
+++ b/lib/efm32/tinygecko/gpio.c
@@ -0,0 +1,23 @@
+#include <libopencm3/efm32/tinygecko/gpio.h>
+
+void gpio_set_mode(u32 gpioport, u8 mode, u16 gpios)
+{
+ u8 i;
+ u32 modemaskl = 0, modesetl = 0, modemaskh = 0, modeseth = 0;
+
+ for (i = 0; i < 8; ++i)
+ {
+ if (gpios & (1<<i)) {
+ modemaskl |= GPIO_MODE_MASK << (i*4);
+ modesetl |= mode << (i*4);
+ }
+ if (gpios & (0x100<<i)) {
+ modemaskh |= GPIO_MODE_MASK << (i*4);
+ modeseth |= mode << (i*4);
+ }
+ }
+ GPIO_Px_MODEL(gpioport) &= ~modemaskl;
+ GPIO_Px_MODEL(gpioport) |= modesetl;
+ GPIO_Px_MODEH(gpioport) &= ~modemaskh;
+ GPIO_Px_MODEH(gpioport) |= modeseth;
+}