|
@@ -24,19 +24,49 @@
|
24
|
24
|
|
25
|
25
|
/**
|
26
|
26
|
* Fast I/O interfaces for STM32
|
27
|
|
- * These use GPIO functions instead of Direct Port Manipulation, as on AVR.
|
|
27
|
+ * These use GPIO register access for fast port manipulation.
|
28
|
28
|
*/
|
29
|
29
|
|
|
30
|
+// --------------------------------------------------------------------------
|
|
31
|
+// Public Variables
|
|
32
|
+// --------------------------------------------------------------------------
|
|
33
|
+
|
|
34
|
+extern GPIO_TypeDef * FastIOPortMap[];
|
|
35
|
+
|
|
36
|
+// --------------------------------------------------------------------------
|
|
37
|
+// Public functions
|
|
38
|
+// --------------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+void FastIO_init(); // Must be called before using fast io macros
|
|
41
|
+
|
|
42
|
+// --------------------------------------------------------------------------
|
|
43
|
+// Defines
|
|
44
|
+// --------------------------------------------------------------------------
|
|
45
|
+
|
30
|
46
|
#define _BV(b) (1 << (b))
|
|
47
|
+#define _BV32(b) (1UL << (b))
|
|
48
|
+
|
|
49
|
+#if defined(STM32F0xx) || defined(STM32F1xx) || defined(STM32F3xx) || defined(STM32L0xx) || defined(STM32L4xx)
|
|
50
|
+ #define _WRITE(IO, V) do { \
|
|
51
|
+ if (V) FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO])) ; \
|
|
52
|
+ else FastIOPortMap[STM_PORT(digitalPin[IO])]->BRR = _BV32(STM_PIN(digitalPin[IO])) ; \
|
|
53
|
+ } while(0)
|
|
54
|
+#else
|
|
55
|
+ #define _WRITE(IO, V) (FastIOPortMap[STM_PORT(digitalPin[IO])]->BSRR = _BV32(STM_PIN(digitalPin[IO] + (V ? 0 : 16))))
|
|
56
|
+#endif
|
31
|
57
|
|
32
|
|
-#define READ(IO) digitalRead(IO)
|
33
|
|
-#define WRITE(IO,V) digitalWrite(IO,V)
|
34
|
|
-#define WRITE_VAR(IO,V) WRITE(IO,V)
|
|
58
|
+#define _READ(IO) bool(READ_BIT(FastIOPortMap[STM_PORT(digitalPin[IO])]->IDR, _BV32(STM_PIN(digitalPin[IO]))))
|
|
59
|
+#define _TOGGLE(IO) (FastIOPortMap[STM_PORT(digitalPin[IO])]->ODR ^= _BV32(STM_PIN(digitalPin[IO])))
|
35
|
60
|
|
36
|
61
|
#define _GET_MODE(IO)
|
37
|
62
|
#define _SET_MODE(IO,M) pinMode(IO, M)
|
38
|
63
|
#define _SET_OUTPUT(IO) pinMode(IO, OUTPUT) /*!< Output Push Pull Mode & GPIO_NOPULL */
|
39
|
64
|
|
|
65
|
+#define WRITE_VAR(IO,V) _WRITE(IO,V)
|
|
66
|
+#define WRITE(IO,V) _WRITE(IO,V)
|
|
67
|
+#define READ(IO) _READ(IO)
|
|
68
|
+#define TOGGLE(IO) _TOGGLE(IO)
|
|
69
|
+
|
40
|
70
|
#define OUT_WRITE(IO,V) do{ _SET_OUTPUT(IO); WRITE(IO,V); }while(0)
|
41
|
71
|
|
42
|
72
|
#define SET_INPUT(IO) _SET_MODE(IO, INPUT) /*!< Input Floating Mode */
|
|
@@ -44,8 +74,6 @@
|
44
|
74
|
#define SET_INPUT_PULLDOWN(IO) _SET_MODE(IO, INPUT_PULLDOWN) /*!< Input with Pull-down activation */
|
45
|
75
|
#define SET_OUTPUT(IO) OUT_WRITE(IO, LOW)
|
46
|
76
|
|
47
|
|
-#define TOGGLE(IO) OUT_WRITE(IO, !READ(IO))
|
48
|
|
-
|
49
|
77
|
#define GET_INPUT(IO)
|
50
|
78
|
#define GET_OUTPUT(IO)
|
51
|
79
|
#define GET_TIMER(IO)
|