19
19
#define _PINS_ARDUINO_H_
20
20
#include <stdbool.h>
21
21
#include <stdlib.h> /* Required for static_assert */
22
- // Include board variant
23
22
#include "variant.h"
24
23
#include "PinNames.h"
25
24
25
+ #include "pins_arduino_analog.h"
26
+ #include "pins_arduino_digital.h"
26
27
27
- // Avoid PortName issue
28
+ /* Avoid PortName issue */
28
29
_Static_assert (LastPort <= 0x0F , "PortName must be less than 16" );
29
30
30
- // Arduino digital pins alias
31
- // GPIO port (A to K) * 16 pins: 176
32
- enum {
33
- D0 , D1 , D2 , D3 , D4 , D5 , D6 , D7 , D8 , D9 ,
34
- D10 , D11 , D12 , D13 , D14 , D15 , D16 , D17 , D18 , D19 ,
35
- D20 , D21 , D22 , D23 , D24 , D25 , D26 , D27 , D28 , D29 ,
36
- D30 , D31 , D32 , D33 , D34 , D35 , D36 , D37 , D38 , D39 ,
37
- D40 , D41 , D42 , D43 , D44 , D45 , D46 , D47 , D48 , D49 ,
38
- D50 , D51 , D52 , D53 , D54 , D55 , D56 , D57 , D58 , D59 ,
39
- D60 , D61 , D62 , D63 , D64 , D65 , D66 , D67 , D68 , D69 ,
40
- D70 , D71 , D72 , D73 , D74 , D75 , D76 , D77 , D78 , D79 ,
41
- D80 , D81 , D82 , D83 , D84 , D85 , D86 , D87 , D88 , D89 ,
42
- D90 , D91 , D92 , D93 , D94 , D95 , D96 , D97 , D98 , D99 ,
43
- D100 , D101 , D102 , D103 , D104 , D105 , D106 , D107 , D108 , D109 ,
44
- D110 , D111 , D112 , D113 , D114 , D115 , D116 , D117 , D118 , D119 ,
45
- D120 , D121 , D122 , D123 , D124 , D125 , D126 , D127 , D128 , D129 ,
46
- D130 , D131 , D132 , D133 , D134 , D135 , D136 , D137 , D138 , D139 ,
47
- D140 , D141 , D142 , D143 , D144 , D145 , D146 , D147 , D148 , D149 ,
48
- D150 , D151 , D152 , D153 , D154 , D155 , D156 , D157 , D158 , D159 ,
49
- D160 , D161 , D162 , D163 , D164 , D165 , D166 , D167 , D168 , D169 ,
50
- D170 , D171 , D172 , D173 , D174 , D175 ,
51
- DMAX
52
- };
53
-
54
- // Arduino analog pins
55
-
56
- #ifndef NUM_ANALOG_INPUTS
57
- #define NUM_ANALOG_INPUTS 0
58
- #endif
59
-
60
- // If NUM_ANALOG_FIRST is not defined:
61
- // - Ax are not contiguous in the digitalPin array
62
- // - analogInputPin array is available
63
- #ifndef NUM_ANALOG_FIRST
64
- #define NUM_ANALOG_FIRST (NUM_DIGITAL_PINS + 1)
65
- #define NUM_ANALOG_LAST (NUM_DIGITAL_PINS + NUM_ANALOG_INPUTS)
66
- #define NUM_ANALOG_INTERNAL_FIRST (NUM_ANALOG_LAST + 1)
67
- #else
68
- #define NUM_ANALOG_INTERNAL_FIRST (NUM_DIGITAL_PINS + 1)
69
- #endif
70
-
71
- // If NUM_ANALOG_INPUTS is not defined there is no analog pins defined.
72
- // Anyway ADC internal channels are always avaialable.
73
- #if NUM_ANALOG_INPUTS > 0
74
- // Analog pins must be contiguous to be able to loop on each value
75
- #define MAX_ANALOG_INPUTS 24
76
31
_Static_assert (NUM_ANALOG_INPUTS <= MAX_ANALOG_INPUTS ,
77
32
"Core NUM_ANALOG_INPUTS limited to MAX_ANALOG_INPUTS" );
78
-
33
+ /* Analog pins must be contiguous to be able to loop on each value */
79
34
_Static_assert (NUM_ANALOG_FIRST >= NUM_ANALOG_INPUTS ,
80
35
"First analog pin value (A0) must be greater than or equal to NUM_ANALOG_INPUTS" );
81
36
82
- #if NUM_ANALOG_INPUTS > 0
83
- #define PIN_A0 NUM_ANALOG_FIRST
84
- static const uint8_t A0 = PIN_A0 ;
85
- #endif
86
- #if NUM_ANALOG_INPUTS > 1
87
- #define PIN_A1 (PIN_A0 + 1)
88
- static const uint8_t A1 = PIN_A1 ;
89
- #endif
90
- #if NUM_ANALOG_INPUTS > 2
91
- #define PIN_A2 (PIN_A1 + 1)
92
- static const uint8_t A2 = PIN_A2 ;
93
- #endif
94
- #if NUM_ANALOG_INPUTS > 3
95
- #define PIN_A3 (PIN_A2 + 1)
96
- static const uint8_t A3 = PIN_A3 ;
97
- #endif
98
- #if NUM_ANALOG_INPUTS > 4
99
- #define PIN_A4 (PIN_A3 + 1)
100
- static const uint8_t A4 = PIN_A4 ;
101
- #endif
102
- #if NUM_ANALOG_INPUTS > 5
103
- #define PIN_A5 (PIN_A4 + 1)
104
- static const uint8_t A5 = PIN_A5 ;
105
- #endif
106
- #if NUM_ANALOG_INPUTS > 6
107
- #define PIN_A6 (PIN_A5 + 1)
108
- static const uint8_t A6 = PIN_A6 ;
109
- #endif
110
- #if NUM_ANALOG_INPUTS > 7
111
- #define PIN_A7 (PIN_A6 + 1)
112
- static const uint8_t A7 = PIN_A7 ;
113
- #endif
114
- #if NUM_ANALOG_INPUTS > 8
115
- #define PIN_A8 (PIN_A7 + 1)
116
- static const uint8_t A8 = PIN_A8 ;
117
- #endif
118
- #if NUM_ANALOG_INPUTS > 9
119
- #define PIN_A9 (PIN_A8 + 1)
120
- static const uint8_t A9 = PIN_A9 ;
121
- #endif
122
- #if NUM_ANALOG_INPUTS > 10
123
- #define PIN_A10 (PIN_A9 + 1)
124
- static const uint8_t A10 = PIN_A10 ;
125
- #endif
126
- #if NUM_ANALOG_INPUTS > 11
127
- #define PIN_A11 (PIN_A10 + 1)
128
- static const uint8_t A11 = PIN_A11 ;
129
- #endif
130
- #if NUM_ANALOG_INPUTS > 12
131
- #define PIN_A12 (PIN_A11 + 1)
132
- static const uint8_t A12 = PIN_A12 ;
133
- #endif
134
- #if NUM_ANALOG_INPUTS > 13
135
- #define PIN_A13 (PIN_A12 + 1)
136
- static const uint8_t A13 = PIN_A13 ;
137
- #endif
138
- #if NUM_ANALOG_INPUTS > 14
139
- #define PIN_A14 (PIN_A13 + 1)
140
- static const uint8_t A14 = PIN_A14 ;
141
- #endif
142
- #if NUM_ANALOG_INPUTS > 15
143
- #define PIN_A15 (PIN_A14 + 1)
144
- static const uint8_t A15 = PIN_A15 ;
145
- #endif
146
- #if NUM_ANALOG_INPUTS > 16
147
- #define PIN_A16 (PIN_A15 + 1)
148
- static const uint8_t A16 = PIN_A16 ;
149
- #endif
150
- #if NUM_ANALOG_INPUTS > 17
151
- #define PIN_A17 (PIN_A16 + 1)
152
- static const uint8_t A17 = PIN_A17 ;
153
- #endif
154
- #if NUM_ANALOG_INPUTS > 18
155
- #define PIN_A18 (PIN_A17 + 1)
156
- static const uint8_t A18 = PIN_A18 ;
157
- #endif
158
- #if NUM_ANALOG_INPUTS > 19
159
- #define PIN_A19 (PIN_A18 + 1)
160
- static const uint8_t A19 = PIN_A19 ;
161
- #endif
162
- #if NUM_ANALOG_INPUTS > 20
163
- #define PIN_A20 (PIN_A19 + 1)
164
- static const uint8_t A20 = PIN_A20 ;
165
- #endif
166
- #if NUM_ANALOG_INPUTS > 21
167
- #define PIN_A21 (PIN_A20 + 1)
168
- static const uint8_t A21 = PIN_A21 ;
169
- #endif
170
- #if NUM_ANALOG_INPUTS > 22
171
- #define PIN_A22 (PIN_A21 + 1)
172
- static const uint8_t A22 = PIN_A22 ;
173
- #endif
174
- #if NUM_ANALOG_INPUTS > 23
175
- #define PIN_A23 (PIN_A22 + 1)
176
- static const uint8_t A23 = PIN_A23 ;
177
- #endif
178
- #endif /* NUM_ANALOG_INPUTS > 0 */
179
-
180
- // Default for Arduino connector compatibility
181
- // SPI Definitions
37
+ /* Default for Arduino connector compatibility */
38
+ /* SPI Definitions */
182
39
#ifndef PIN_SPI_SS
183
- #define PIN_SPI_SS 10
40
+ #define PIN_SPI_SS 10
184
41
#endif
185
42
#ifndef PIN_SPI_SS1
186
- #define PIN_SPI_SS1 4
43
+ #define PIN_SPI_SS1 4
187
44
#endif
188
45
#ifndef PIN_SPI_SS2
189
- #define PIN_SPI_SS2 7
46
+ #define PIN_SPI_SS2 7
190
47
#endif
191
48
#ifndef PIN_SPI_SS3
192
- #define PIN_SPI_SS3 8
49
+ #define PIN_SPI_SS3 8
193
50
#endif
194
51
#ifndef PIN_SPI_MOSI
195
- #define PIN_SPI_MOSI 11
52
+ #define PIN_SPI_MOSI 11
196
53
#endif
197
54
#ifndef PIN_SPI_MISO
198
- #define PIN_SPI_MISO 12
55
+ #define PIN_SPI_MISO 12
199
56
#endif
200
57
#ifndef PIN_SPI_SCK
201
- #define PIN_SPI_SCK 13
58
+ #define PIN_SPI_SCK 13
202
59
#endif
203
60
204
61
static const uint8_t SS = PIN_SPI_SS ;
@@ -209,74 +66,59 @@ static const uint8_t MOSI = PIN_SPI_MOSI;
209
66
static const uint8_t MISO = PIN_SPI_MISO ;
210
67
static const uint8_t SCK = PIN_SPI_SCK ;
211
68
212
- // I2C Definitions
69
+ /* I2C Definitions */
213
70
#ifndef PIN_WIRE_SDA
214
- #define PIN_WIRE_SDA 14
71
+ #define PIN_WIRE_SDA 14
215
72
#endif
216
73
#ifndef PIN_WIRE_SCL
217
- #define PIN_WIRE_SCL 15
74
+ #define PIN_WIRE_SCL 15
218
75
#endif
219
76
220
77
static const uint8_t SDA = PIN_WIRE_SDA ;
221
78
static const uint8_t SCL = PIN_WIRE_SCL ;
222
79
223
- // ADC internal channels (not a pins)
224
- // Only used for analogRead()
225
- #if defined(ADC_CHANNEL_TEMPSENSOR ) || defined(ADC_CHANNEL_TEMPSENSOR_ADC1 )
226
- #define ATEMP (NUM_ANALOG_INTERNAL_FIRST)
227
- #endif
228
- #ifdef ADC_CHANNEL_VREFINT
229
- #define AVREF (NUM_ANALOG_INTERNAL_FIRST + 2)
230
- #endif
231
- #ifdef ADC_CHANNEL_VBAT
232
- #define AVBAT (NUM_ANALOG_INTERNAL_FIRST + 3)
233
- #endif
234
- #if defined(ADC5 ) && defined(ADC_CHANNEL_TEMPSENSOR_ADC5 )
235
- #define ATEMP_ADC5 (NUM_ANALOG_INTERNAL_FIRST + 4)
236
- #endif
237
-
238
80
#ifdef __cplusplus
239
81
extern "C" {
240
82
#endif
241
83
extern const PinName digitalPin [];
242
84
extern const uint32_t analogInputPin [];
243
85
244
- #define NOT_AN_INTERRUPT NC // -1
86
+ #define NOT_AN_INTERRUPT (uint32_t)NC
245
87
246
- // Convert a digital pin number Dxx to a PinName PX_n
247
- // Note: Analog pin is also a digital pin.
88
+ /* Convert a digital pin number Dxx to a PinName PX_n */
89
+ /* Note: Analog pin is also a digital pin */
248
90
#ifndef NUM_ANALOG_LAST
249
91
#define digitalPinToPinName (p ) (((uint32_t)p < NUM_DIGITAL_PINS) ? digitalPin[p] : NC)
250
92
#else
251
93
#define digitalPinToPinName (p ) (((uint32_t)p < NUM_DIGITAL_PINS) ? digitalPin[p] : \
252
94
((uint32_t)p >= NUM_ANALOG_FIRST) && ((uint32_t)p <= NUM_ANALOG_LAST) ? \
253
95
digitalPin[analogInputPin[p-NUM_ANALOG_FIRST]] : NC)
254
96
#endif
255
- // Convert a PinName PX_n to a digital pin number
97
+ /* Convert a PinName PX_n to a digital pin number */
256
98
uint32_t pinNametoDigitalPin (PinName p );
257
99
258
- // Convert an analog pin number to a digital pin number
100
+ /* Convert an analog pin number to a digital pin number */
259
101
#if NUM_ANALOG_INPUTS > 0
260
- // Used by analogRead api to have A0 == 0
261
- // For contiguous analog pins definition in digitalPin array
102
+ /* Used by analogRead api to have A0 == 0 */
103
+ /* For contiguous analog pins definition in digitalPin array */
262
104
#ifndef NUM_ANALOG_LAST
263
105
#define analogInputToDigitalPin (p ) (((uint32_t)p < NUM_ANALOG_INPUTS) ? (p+A0) : p)
264
106
#else
265
- // For non contiguous analog pins definition in digitalPin array
107
+ /* For non contiguous analog pins definition in digitalPin array */
266
108
#define analogInputToDigitalPin (p ) ( \
267
109
((uint32_t)p < NUM_ANALOG_INPUTS) ? analogInputPin[p] : \
268
110
((uint32_t)p >= NUM_ANALOG_FIRST) && ((uint32_t)p <= NUM_ANALOG_LAST) ? \
269
111
analogInputPin[p-NUM_ANALOG_FIRST] : p)
270
112
#endif // !NUM_ANALOG_LAST
271
113
#else
272
- // No analog pin defined
114
+ /* No analog pin defined */
273
115
#define analogInputToDigitalPin (p ) (NUM_DIGITAL_PINS)
274
116
#endif // NUM_ANALOG_INPUTS > 0
275
117
276
- // Convert an analog pin number Axx to a PinName PX_n
118
+ /* Convert an analog pin number Axx to a PinName PX_n */
277
119
PinName analogInputToPinName (uint32_t pin );
278
120
279
- // All pins could manage EXTI
121
+ /* All pins could manage EXTI */
280
122
#define digitalPinToInterrupt (p ) (digitalPinIsValid(p) ? p : NOT_AN_INTERRUPT)
281
123
282
124
#define digitalPinHasI2C (p ) (pin_in_pinmap(digitalPinToPinName(p), PinMap_I2C_SDA) ||\
@@ -299,18 +141,20 @@ PinName analogInputToPinName(uint32_t pin);
299
141
300
142
#define portSetRegister (P ) (&(P->BSRR))
301
143
#if defined(STM32F2xx ) || defined(STM32F4xx ) || defined(STM32F7xx )
302
- // For those series reset are in the high part so << 16U needed
144
+ /* For those series reset are in the high part so << 16U needed */
303
145
#define portClearRegister (P ) (&(P->BSRR))
304
146
#else
305
147
#define portClearRegister (P ) (&(P->BRR))
306
148
#endif
307
149
308
150
309
151
#if defined(STM32F1xx )
310
- // Config registers split in 2 registers:
311
- // CRL: pin 0..7
312
- // CRH: pin 8..15
313
- // Return only CRL
152
+ /*
153
+ * Config registers split in 2 registers:
154
+ * CRL: pin 0..7
155
+ * CRH: pin 8..15
156
+ * Return only CRL
157
+ */
314
158
#define portModeRegister (P ) (&(P->CRL))
315
159
#else
316
160
#define portModeRegister (P ) (&(P->MODER))
@@ -320,33 +164,33 @@ PinName analogInputToPinName(uint32_t pin);
320
164
321
165
#define digitalPinIsValid (p ) (digitalPinToPinName(p) != NC)
322
166
323
- // As some pin could be duplicated in digitalPin[]
324
- // return first occurence of linked PinName (PYx)
167
+ /* As some pin could be duplicated in digitalPin[] */
168
+ /* return first occurence of linked PinName (PYx) */
325
169
#define digitalPinFirstOccurence (p ) (pinNametoDigitalPin(digitalPinToPinName(p)))
326
170
327
- // Specific for Firmata.
328
- // Some pins could be duplicated, ensure 'p' is not one of the serial pins
171
+ /* Specific for Firmata */
172
+ /* Some pins could be duplicated, ensure 'p' is not one of the serial pins */
329
173
#if defined(PIN_SERIAL_RX ) && defined(PIN_SERIAL_TX )
330
174
#define pinIsSerial (p ) ((digitalPinFirstOccurence(p) == PIN_SERIAL_RX) ||\
331
175
(digitalPinFirstOccurence(p) == PIN_SERIAL_TX))
332
176
#endif
333
- // Convenient macro to handle Analog
177
+ /* Convenient macro to handle Analog */
334
178
bool pinIsAnalogInput (uint32_t pin );
335
179
uint32_t digitalPinToAnalogInput (uint32_t pin );
336
180
337
181
#ifdef __cplusplus
338
182
}
339
183
#endif
340
184
341
- // Default Definitions, could be redefined in variant.h
185
+ /* Default Definitions, could be redefined in variant.h */
342
186
#ifndef ADC_RESOLUTION
343
- #define ADC_RESOLUTION 10
187
+ #define ADC_RESOLUTION 10
344
188
#endif
345
189
346
190
#define DACC_RESOLUTION 12
347
191
348
192
#ifndef PWM_RESOLUTION
349
- #define PWM_RESOLUTION 8
193
+ #define PWM_RESOLUTION 8
350
194
#endif
351
195
352
196
_Static_assert ((ADC_RESOLUTION > 0 ) && (ADC_RESOLUTION <= 32 ),
@@ -355,10 +199,10 @@ _Static_assert((PWM_RESOLUTION > 0) &&(PWM_RESOLUTION <= 32),
355
199
"PWM_RESOLUTION must be 0 < x <= 32!" );
356
200
357
201
#ifndef PWM_FREQUENCY
358
- #define PWM_FREQUENCY 1000
202
+ #define PWM_FREQUENCY 1000
359
203
#endif
360
204
#ifndef PWM_MAX_DUTY_CYCLE
361
- #define PWM_MAX_DUTY_CYCLE 4095
205
+ #define PWM_MAX_DUTY_CYCLE 4095
362
206
#endif
363
207
364
208
#endif /*_PINS_ARDUINO_H_*/
0 commit comments