summaryrefslogtreecommitdiffstats
path: root/stm32/app/pins.h
diff options
context:
space:
mode:
authorfishsoupisgood <github@madingley.org>2020-05-26 14:33:34 +0100
committerfishsoupisgood <github@madingley.org>2020-05-26 14:33:34 +0100
commitf0d941bef6a9b6e3af78cfc68e1f82d6b47ccb2f (patch)
tree22a88d00cb28e075b5397ff5db586d548023f2f2 /stm32/app/pins.h
downloadheating-f0d941bef6a9b6e3af78cfc68e1f82d6b47ccb2f.tar.gz
heating-f0d941bef6a9b6e3af78cfc68e1f82d6b47ccb2f.tar.bz2
heating-f0d941bef6a9b6e3af78cfc68e1f82d6b47ccb2f.zip
happy
Diffstat (limited to 'stm32/app/pins.h')
-rw-r--r--stm32/app/pins.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/stm32/app/pins.h b/stm32/app/pins.h
new file mode 100644
index 0000000..9ea01cf
--- /dev/null
+++ b/stm32/app/pins.h
@@ -0,0 +1,53 @@
+#ifndef _PINS_H_
+#define _PINS_H_
+
+/* st seem to change these with every chip revision */
+
+#define MAP_AF(a) do { \
+ gpio_set_mode( a ## _PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, a ); \
+ } while (0)
+
+/* STM32F1 doesn't have AF pull up, but also doesn't disconnect af inputs so just use regular pull up */
+#define MAP_AF_PU(a) do { \
+ gpio_set_mode( a ## _PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, a); \
+ gpio_set( a ## _PORT, a); \
+ } while (0)
+
+#define MAP_AF_OD(a) do { \
+ gpio_set_mode( a ## _PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN, a ); \
+ } while (0)
+
+
+#define MAP_OUTPUT_PP(a) do { \
+ gpio_set_mode( a ## _PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, a ); \
+ } while (0)
+
+
+#define MAP_OUTPUT_OD(a) do { \
+ gpio_set_mode( a ## _PORT, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, a ); \
+ } while (0)
+
+
+/* STM32F1 madly uses the output register to drive the other end of the resistor, so pull up */
+/* requires us to write a 1 there */
+
+#define MAP_INPUT_PU(a) do { \
+ gpio_set_mode( a ## _PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_PULL_UPDOWN, a); \
+ gpio_set( a ## _PORT, a); \
+ } while (0)
+
+
+#define MAP_INPUT(a) do { \
+ gpio_set_mode( a ## _PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, a); \
+ } while (0)
+
+#define MAP_ANALOG(a) do { \
+ gpio_set_mode( a ## _PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, a); \
+ } while (0)
+
+
+#define CLEAR(a) gpio_clear( a ## _PORT, a)
+#define SET(a) gpio_set( a ## _PORT, a)
+#define GET(a) gpio_get( a ## _PORT, a)
+
+#endif