aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Otto2010-05-12 18:10:38 +0200
committerThomas Otto2010-05-12 18:12:31 +0200
commit388f940475b6c66c0622f3ab1a9a48e5fed96775 (patch)
tree04f795d32a4686ddb8acfe76279daa88560c8b5d
parent898c118e1e4b3b9237e85db305bb66b45c935d54 (diff)
Initial EXTI support.
Thanks to Mark Butler <mbutler@physics.otago.ac.nz>.
-rw-r--r--include/libopenstm32.h1
-rw-r--r--include/libopenstm32/exti.h71
-rw-r--r--lib/Makefile2
-rw-r--r--lib/exti.c131
4 files changed, 204 insertions, 1 deletions
diff --git a/include/libopenstm32.h b/include/libopenstm32.h
index c675ddf..4dbde73 100644
--- a/include/libopenstm32.h
+++ b/include/libopenstm32.h
@@ -43,5 +43,6 @@
#include <libopenstm32/pwr.h>
#include <libopenstm32/crc.h>
#include <libopenstm32/bkp.h>
+#include <libopenstm32/exti.h>
#endif
diff --git a/include/libopenstm32/exti.h b/include/libopenstm32/exti.h
new file mode 100644
index 0000000..c2e4867
--- /dev/null
+++ b/include/libopenstm32/exti.h
@@ -0,0 +1,71 @@
+/*
+ * This file is part of the libopenstm32 project.
+ *
+ * Copyright (C) 2010 Mark Butler <mbutler@physics.otago.ac.nz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LIBOPENSTM32_EXTI_H
+#define LIBOPENSTM32_EXTI_H
+
+#include <libopenstm32/memorymap.h>
+#include <libopenstm32/common.h>
+
+/*Define EXTI Registers */
+#define EXTI_IMR MMIO32(EXTI_BASE + 0x00)
+#define EXTI_EMR MMIO32(EXTI_BASE + 0x04)
+#define EXTI_RTSR MMIO32(EXTI_BASE + 0x08)
+#define EXTI_FTSR MMIO32(EXTI_BASE + 0x0C)
+#define EXTI_SWIER MMIO32(EXTI_BASE + 0x10)
+#define EXTI_PR MMIO32(EXTI_BASE + 0x14)
+
+/* EXTI number definitions */
+#define EXTI0 (1 << 0)
+#define EXTI1 (1 << 1)
+#define EXTI2 (1 << 2)
+#define EXTI3 (1 << 3)
+#define EXTI4 (1 << 4)
+#define EXTI5 (1 << 5)
+#define EXTI6 (1 << 6)
+#define EXTI7 (1 << 7)
+#define EXTI8 (1 << 8)
+#define EXTI9 (1 << 9)
+#define EXTI10 (1 << 10)
+#define EXTI11 (1 << 11)
+#define EXTI12 (1 << 12)
+#define EXTI13 (1 << 13)
+#define EXTI14 (1 << 14)
+#define EXTI15 (1 << 15)
+#define EXTI16 (1 << 16)
+#define EXTI17 (1 << 17)
+#define EXTI18 (1 << 18)
+#define EXTI19 (1 << 19)
+
+/*Define trigger types*/
+typedef enum trigger_e{
+EXTI_TRIGGER_RISING,
+EXTI_TRIGGER_FALLING,
+EXTI_TRIGGER_BOTH,
+}exti_trigger_type;
+
+/*Function Prototypes */
+void exti_set_trigger(u32 extis,exti_trigger_type trig);
+void exti_enable_request(u32 extis);
+void exti_disable_request(u32 extis);
+void exti_reset_request(u32 extis);
+void exti_select_source(u32 exti, u32 gpioport);
+
+
+#endif
diff --git a/lib/Makefile b/lib/Makefile
index d85afee..f694b12 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,7 +28,7 @@ CFLAGS = -Os -g -Wall -Wextra -I../include -fno-common \
# ARFLAGS = rcsv
ARFLAGS = rcs
OBJS = vector.o rcc.o gpio.o usart.o adc.o spi.o flash.o nvic.o \
- rtc.o i2c.o dma.o systick.o
+ rtc.o i2c.o dma.o systick.o exti.o
# Be silent per default, but 'make V=1' will show all compiler calls.
ifneq ($(V),1)
diff --git a/lib/exti.c b/lib/exti.c
new file mode 100644
index 0000000..ccef676
--- /dev/null
+++ b/lib/exti.c
@@ -0,0 +1,131 @@
+/*
+ * This file is part of the libopenstm32 project.
+ *
+ * Copyright (C) 2010 Mark Butler <mbutler@physics.otago.ac.nz>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <libopenstm32/exti.h>
+#include <libopenstm32/gpio.h>
+
+void exti_set_trigger(u32 extis, exti_trigger_type trig)
+{
+ switch(trig)
+ {
+ case EXTI_TRIGGER_RISING:
+ EXTI_RTSR |= extis;
+ EXTI_FTSR &= ~extis;
+ break;
+ case EXTI_TRIGGER_FALLING:
+ EXTI_RTSR &= ~extis;
+ EXTI_FTSR |= extis;
+ break;
+ case EXTI_TRIGGER_BOTH:
+ EXTI_RTSR |= extis;
+ EXTI_FTSR |= extis;
+ break;
+ }
+}
+
+void exti_enable_request(u32 extis)
+{
+ //enable interrupts
+ EXTI_IMR |= extis;
+ //enable events
+ EXTI_EMR |= extis;
+}
+
+void exti_disable_request(u32 extis)
+{
+ //disable interrupts
+ EXTI_IMR &= ~extis;
+ //disable events
+ EXTI_EMR &= ~extis;
+}
+
+/*
+Reset the interrupt request by writing a 1 to the corresponding
+pending bit register
+*/
+void exti_reset_request(u32 extis)
+{
+ EXTI_PR |= extis;
+}
+
+
+/*Remap an external interrupt line to the corresponding
+pin on the specified GPIO port TODO: this could be rewritten in less lines of code */
+void exti_select_source(u32 exti, u32 gpioport)
+{
+ u8 shift =0;
+ u8 bits = 0;
+ switch (exti)
+ {
+ case EXTI0:
+ case EXTI4:
+ case EXTI8:
+ case EXTI12:
+ shift = 0;
+ break;
+ case EXTI1:
+ case EXTI5:
+ case EXTI9:
+ case EXTI13:
+ shift = 4;
+ break;
+ case EXTI2:
+ case EXTI6:
+ case EXTI10:
+ case EXTI14:
+ shift = 8;
+ break;
+ case EXTI3:
+ case EXTI7:
+ case EXTI11:
+ case EXTI15:
+ shift = 12;
+ break;
+ }
+
+ switch (gpioport)
+ {
+ case GPIOA:
+ bits = 0xF;
+ break;
+ case GPIOB:
+ bits = 0xE;
+ break;
+ case GPIOC:
+ bits = 0xD;
+ break;
+ case GPIOD:
+ bits = 0xC;
+ break;
+ case GPIOE:
+ bits = 0xB;
+ break;
+ case GPIOF:
+ bits = 0xA;
+ break;
+ case GPIOG:
+ bits = 0x9;
+ break;
+ }
+
+ if(exti < EXTI4) AFIO_EXTICR1 &=~ ( bits << shift );
+ else if (exti < EXTI8) AFIO_EXTICR2 &=~ ( bits << shift );
+ else if (exti < EXTI12) AFIO_EXTICR3 &=~ ( bits << shift );
+ else if (exti < EXTI16) AFIO_EXTICR4 &=~ ( bits << shift ); //ensure that only valid EXTI lines are used
+} \ No newline at end of file