|
@@ -48,7 +48,7 @@
|
48
|
48
|
#define USEABLE_HARDWARE_PWM(p) ((2 <= p) && (p <= 13))
|
49
|
49
|
|
50
|
50
|
#ifndef MASK
|
51
|
|
- #define MASK(PIN) (1 << PIN)
|
|
51
|
+ #define MASK(PIN) (1 << PIN)
|
52
|
52
|
#endif
|
53
|
53
|
|
54
|
54
|
/**
|
|
@@ -59,76 +59,78 @@
|
59
|
59
|
* Why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
|
60
|
60
|
*/
|
61
|
61
|
|
62
|
|
-/// Read a pin
|
63
|
|
-#define _READ(IO) ((bool)(DIO ## IO ## _WPORT -> PIO_PDSR & (MASK(DIO ## IO ## _PIN))))
|
|
62
|
+// Read a pin
|
|
63
|
+#define _READ(IO) bool(DIO ## IO ## _WPORT -> PIO_PDSR & MASK(DIO ## IO ## _PIN))
|
64
|
64
|
|
65
|
|
-/// Write to a pin
|
66
|
|
-#define _WRITE_VAR(IO, v) do { \
|
|
65
|
+// Write to a pin
|
|
66
|
+#define _WRITE_VAR(IO,V) do { \
|
67
|
67
|
volatile Pio* port = g_APinDescription[IO].pPort; \
|
68
|
68
|
uint32_t mask = g_APinDescription[IO].ulPin; \
|
69
|
|
- if (v) port->PIO_SODR = mask; \
|
|
69
|
+ if (V) port->PIO_SODR = mask; \
|
70
|
70
|
else port->PIO_CODR = mask; \
|
71
|
71
|
} while(0)
|
72
|
72
|
|
73
|
|
-/// Write to a pin
|
74
|
|
-#define _WRITE(IO, v) do { \
|
|
73
|
+// Write to a pin
|
|
74
|
+#define _WRITE(IO,V) do { \
|
75
|
75
|
volatile Pio* port = (DIO ## IO ## _WPORT); \
|
76
|
76
|
uint32_t mask = MASK(DIO ## IO ## _PIN); \
|
77
|
|
- if (v) port->PIO_SODR = mask; \
|
|
77
|
+ if (V) port->PIO_SODR = mask; \
|
78
|
78
|
else port->PIO_CODR = mask; \
|
79
|
79
|
} while(0)
|
80
|
80
|
|
81
|
|
-/// toggle a pin
|
82
|
|
-#define _TOGGLE(IO) _WRITE(IO, !READ(IO))
|
|
81
|
+// toggle a pin
|
|
82
|
+#define _TOGGLE(IO) _WRITE(IO, !READ(IO))
|
83
|
83
|
|
84
|
|
-/// set pin as input
|
85
|
|
-#define _SET_INPUT(IO) do{ pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
|
86
|
|
- PIO_Configure(g_APinDescription[IO].pPort, PIO_INPUT, g_APinDescription[IO].ulPin, 0); \
|
87
|
|
- }while(0)
|
88
|
|
-/// set pin as output
|
89
|
|
-#define _SET_OUTPUT(IO) do{ pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
|
90
|
|
- PIO_Configure(g_APinDescription[IO].pPort, _READ(IO) ? PIO_OUTPUT_1 : PIO_OUTPUT_0, \
|
91
|
|
- g_APinDescription[IO].ulPin, g_APinDescription[IO].ulPinConfiguration); \
|
92
|
|
- g_pinStatus[IO] = (g_pinStatus[IO] & 0xF0) | PIN_STATUS_DIGITAL_OUTPUT;\
|
93
|
|
- }while(0)
|
|
84
|
+// set pin as input
|
|
85
|
+#define _SET_INPUT(IO) do{ \
|
|
86
|
+ pmc_enable_periph_clk(g_APinDescription[IO].ulPeripheralId); \
|
|
87
|
+ PIO_Configure(g_APinDescription[IO].pPort, PIO_INPUT, g_APinDescription[IO].ulPin, 0); \
|
|
88
|
+}while(0)
|
94
|
89
|
|
95
|
|
-/// set pin as input with pullup mode
|
96
|
|
-#define _PULLUP(IO, v) { pinMode(IO, v != LOW ? INPUT_PULLUP : INPUT); }
|
|
90
|
+// set pin as output
|
|
91
|
+#define _SET_OUTPUT(IO) do{ \
|
|
92
|
+ 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); \
|
|
94
|
+ g_pinStatus[IO] = (g_pinStatus[IO] & 0xF0) | PIN_STATUS_DIGITAL_OUTPUT;\
|
|
95
|
+}while(0)
|
97
|
96
|
|
98
|
|
-/// check if pin is an input
|
|
97
|
+// set pin as input with pullup mode
|
|
98
|
+#define _PULLUP(IO,V) pinMode(IO, (V) ? INPUT_PULLUP : INPUT)
|
|
99
|
+
|
|
100
|
+// check if pin is an input
|
99
|
101
|
#define _GET_INPUT(IO)
|
100
|
|
-/// check if pin is an output
|
|
102
|
+// check if pin is an output
|
101
|
103
|
#define _GET_OUTPUT(IO)
|
102
|
104
|
|
103
|
|
-/// check if pin is a timer
|
|
105
|
+// check if pin is a timer
|
104
|
106
|
#define _GET_TIMER(IO)
|
105
|
107
|
|
106
|
|
-/// Read a pin wrapper
|
107
|
|
-#define READ(IO) _READ(IO)
|
|
108
|
+// Read a pin wrapper
|
|
109
|
+#define READ(IO) _READ(IO)
|
108
|
110
|
|
109
|
|
-/// Write to a pin wrapper
|
110
|
|
-#define WRITE_VAR(IO, v) _WRITE_VAR(IO, v)
|
111
|
|
-#define WRITE(IO, v) _WRITE(IO, v)
|
|
111
|
+// Write to a pin wrapper
|
|
112
|
+#define WRITE_VAR(IO,V) _WRITE_VAR(IO,V)
|
|
113
|
+#define WRITE(IO,V) _WRITE(IO,V)
|
112
|
114
|
|
113
|
|
-/// toggle a pin wrapper
|
114
|
|
-#define TOGGLE(IO) _TOGGLE(IO)
|
|
115
|
+// toggle a pin wrapper
|
|
116
|
+#define TOGGLE(IO) _TOGGLE(IO)
|
115
|
117
|
|
116
|
|
-/// set pin as input wrapper
|
117
|
|
-#define SET_INPUT(IO) _SET_INPUT(IO)
|
118
|
|
-/// set pin as input with pullup wrapper
|
|
118
|
+// set pin as input wrapper
|
|
119
|
+#define SET_INPUT(IO) _SET_INPUT(IO)
|
|
120
|
+// set pin as input with pullup wrapper
|
119
|
121
|
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
|
120
|
|
-/// set pin as output wrapper - reads the pin and sets the output to that value
|
121
|
|
-#define SET_OUTPUT(IO) _SET_OUTPUT(IO)
|
122
|
|
-/// check if pin is an input wrapper
|
123
|
|
-#define GET_INPUT(IO) _GET_INPUT(IO)
|
124
|
|
-/// check if pin is an output wrapper
|
125
|
|
-#define GET_OUTPUT(IO) _GET_OUTPUT(IO)
|
|
122
|
+// set pin as output wrapper - reads the pin and sets the output to that value
|
|
123
|
+#define SET_OUTPUT(IO) _SET_OUTPUT(IO)
|
|
124
|
+// check if pin is an input wrapper
|
|
125
|
+#define GET_INPUT(IO) _GET_INPUT(IO)
|
|
126
|
+// check if pin is an output wrapper
|
|
127
|
+#define GET_OUTPUT(IO) _GET_OUTPUT(IO)
|
126
|
128
|
|
127
|
|
-/// check if pin is a timer (wrapper)
|
128
|
|
-#define GET_TIMER(IO) _GET_TIMER(IO)
|
|
129
|
+// check if pin is a timer (wrapper)
|
|
130
|
+#define GET_TIMER(IO) _GET_TIMER(IO)
|
129
|
131
|
|
130
|
132
|
// Shorthand
|
131
|
|
-#define OUT_WRITE(IO, v) { SET_OUTPUT(IO); WRITE(IO, v); }
|
|
133
|
+#define OUT_WRITE(IO,V) { SET_OUTPUT(IO); WRITE(IO,V); }
|
132
|
134
|
|
133
|
135
|
/**
|
134
|
136
|
* Ports and functions
|