aboutsummaryrefslogtreecommitdiff
path: root/lib/efm32/tinygecko
diff options
context:
space:
mode:
Diffstat (limited to 'lib/efm32/tinygecko')
-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;
+}