|
@@ -39,6 +39,8 @@
|
39
|
39
|
#ifndef _FASTIO_DUE_H
|
40
|
40
|
#define _FASTIO_DUE_H
|
41
|
41
|
|
|
42
|
+#include <pins_arduino.h>
|
|
43
|
+
|
42
|
44
|
/**
|
43
|
45
|
* Utility functions
|
44
|
46
|
*/
|
|
@@ -64,7 +66,7 @@
|
64
|
66
|
|
65
|
67
|
// Write to a pin
|
66
|
68
|
#define _WRITE_VAR(IO,V) do { \
|
67
|
|
- volatile Pio* port = g_APinDescription[IO].pPort; \
|
|
69
|
+ volatile Pio* port = digitalPinToPort(IO); \
|
68
|
70
|
uint32_t mask = g_APinDescription[IO].ulPin; \
|
69
|
71
|
if (V) port->PIO_SODR = mask; \
|
70
|
72
|
else port->PIO_CODR = mask; \
|
|
@@ -84,26 +86,19 @@
|
84
|
86
|
// Set pin as input
|
85
|
87
|
#define _SET_INPUT(IO) do{ \
|
86
|
88
|
pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
|
87
|
|
- PIO_Configure(g_APinDescription[IO].pPort, PIO_INPUT, g_APinDescription[IO].ulPin, 0); \
|
|
89
|
+ PIO_Configure(g_APinDescription[IO].pPort, PIO_INPUT, digitalPinToBitMask(IO), 0); \
|
88
|
90
|
}while(0)
|
89
|
91
|
|
90
|
92
|
// Set pin as output
|
91
|
93
|
#define _SET_OUTPUT(IO) do{ \
|
92
|
94
|
pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
|
93
|
|
- PIO_Configure(g_APinDescription[IO].pPort, _READ(IO) ? PIO_OUTPUT_1 : PIO_OUTPUT_0, g_APinDescription[IO].ulPin, g_APinDescription[IO].ulPinConfiguration); \
|
|
95
|
+ PIO_Configure(g_APinDescription[IO].pPort, _READ(IO) ? PIO_OUTPUT_1 : PIO_OUTPUT_0, digitalPinToBitMask(IO), g_APinDescription[IO].ulPinConfiguration); \
|
94
|
96
|
g_pinStatus[IO] = (g_pinStatus[IO] & 0xF0) | PIN_STATUS_DIGITAL_OUTPUT;\
|
95
|
97
|
}while(0)
|
96
|
98
|
|
97
|
99
|
// Set pin as input with pullup mode
|
98
|
100
|
#define _PULLUP(IO,V) pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
|
99
|
101
|
|
100
|
|
-// Check if pin is an input
|
101
|
|
-#define _GET_INPUT(IO)
|
102
|
|
-// Check if pin is an output
|
103
|
|
-#define _GET_OUTPUT(IO)
|
104
|
|
-// Check if pin is a timer
|
105
|
|
-#define _GET_TIMER(IO)
|
106
|
|
-
|
107
|
102
|
// Read a pin (wrapper)
|
108
|
103
|
#define READ(IO) _READ(IO)
|
109
|
104
|
|
|
@@ -120,13 +115,16 @@
|
120
|
115
|
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
|
121
|
116
|
// Set pin as output (wrapper) - reads the pin and sets the output to that value
|
122
|
117
|
#define SET_OUTPUT(IO) _SET_OUTPUT(IO)
|
123
|
|
-// Check if pin is an input (wrapper)
|
124
|
|
-#define GET_INPUT(IO) _GET_INPUT(IO)
|
125
|
|
-// Check if pin is an output (wrapper)
|
126
|
|
-#define GET_OUTPUT(IO) _GET_OUTPUT(IO)
|
127
|
118
|
|
128
|
|
-// Check if pin is a timer (wrapper)
|
129
|
|
-#define GET_TIMER(IO) _GET_TIMER(IO)
|
|
119
|
+// Check if pin is an input
|
|
120
|
+#define GET_INPUT(IO) !(digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO))
|
|
121
|
+// Check if pin is an output
|
|
122
|
+#define GET_OUTPUT(IO) !!(digitalPinToPort(IO)->PIO_OSR & digitalPinToBitMask(IO))
|
|
123
|
+// Check if pin is a timer
|
|
124
|
+#define GET_TIMER(IO) ( \
|
|
125
|
+ (g_APinDescription[IO].ulPinAttribute & PIN_ATTR_TIMER) == PIN_ATTR_TIMER \
|
|
126
|
+ || (g_APinDescription[IO].ulPinAttribute & PIN_ATTR_PWM) == PIN_ATTR_PWM \
|
|
127
|
+)
|
130
|
128
|
|
131
|
129
|
// Shorthand
|
132
|
130
|
#define OUT_WRITE(IO,V) { SET_OUTPUT(IO); WRITE(IO,V); }
|