Prusa MINI Firmware overview
pins_arduino.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2011 Arduino. All right reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  See the GNU Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 #ifndef _PINS_ARDUINO_H_
19 #define _PINS_ARDUINO_H_
20 // Include board variant
21 #include "variant.h"
22 
23 // Avoid PortName issue
24 _Static_assert(LastPort <= 0x0F, "PortName must be less than 16");
25 
26 // Arduino digital pins alias
27 // GPIO port (A to K) * 16 pins: 176
28 enum {
29  D0,
30  D1,
31  D2,
32  D3,
33  D4,
34  D5,
35  D6,
36  D7,
37  D8,
38  D9,
39  D10,
40  D11,
41  D12,
42  D13,
43  D14,
44  D15,
45  D16,
46  D17,
47  D18,
48  D19,
49  D20,
50  D21,
51  D22,
52  D23,
53  D24,
54  D25,
55  D26,
56  D27,
57  D28,
58  D29,
59  D30,
60  D31,
61  D32,
62  D33,
63  D34,
64  D35,
65  D36,
66  D37,
67  D38,
68  D39,
69  D40,
70  D41,
71  D42,
72  D43,
73  D44,
74  D45,
75  D46,
76  D47,
77  D48,
78  D49,
79  D50,
80  D51,
81  D52,
82  D53,
83  D54,
84  D55,
85  D56,
86  D57,
87  D58,
88  D59,
89  D60,
90  D61,
91  D62,
92  D63,
93  D64,
94  D65,
95  D66,
96  D67,
97  D68,
98  D69,
99  D70,
206 };
207 
208 // Arduino analog pins
209 // Analog pins must be contiguous to be able to loop on each value
210 #define MAX_ANALOG_INPUTS 24
212  "Core NUM_ANALOG_INPUTS limited to MAX_ANALOG_INPUTS");
214  "First analog pin value (A0) must be greater than or equal to NUM_ANALOG_INPUTS");
215 
216 // Defined for backward compatibility with Firmata which unfortunately use it
217 #define AEND (NUM_ANALOG_FIRST + NUM_ANALOG_INPUTS)
218 
219 #if NUM_ANALOG_INPUTS > 0
220  #define PIN_A0 NUM_ANALOG_FIRST
221 static const uint8_t A0 = PIN_A0;
222 #endif
223 #if NUM_ANALOG_INPUTS > 1
224  #define PIN_A1 (PIN_A0 + 1)
225 static const uint8_t A1 = PIN_A1;
226 #endif
227 #if NUM_ANALOG_INPUTS > 2
228  #define PIN_A2 (PIN_A1 + 1)
229 static const uint8_t A2 = PIN_A2;
230 #endif
231 #if NUM_ANALOG_INPUTS > 3
232  #define PIN_A3 (PIN_A2 + 1)
233 static const uint8_t A3 = PIN_A3;
234 #endif
235 #if NUM_ANALOG_INPUTS > 4
236  #define PIN_A4 (PIN_A3 + 1)
237 static const uint8_t A4 = PIN_A4;
238 #endif
239 #if NUM_ANALOG_INPUTS > 5
240  #define PIN_A5 (PIN_A4 + 1)
241 static const uint8_t A5 = PIN_A5;
242 #endif
243 #if NUM_ANALOG_INPUTS > 6
244  #define PIN_A6 (PIN_A5 + 1)
245 static const uint8_t A6 = PIN_A6;
246 #endif
247 #if NUM_ANALOG_INPUTS > 7
248  #define PIN_A7 (PIN_A6 + 1)
249 static const uint8_t A7 = PIN_A7;
250 #endif
251 #if NUM_ANALOG_INPUTS > 8
252  #define PIN_A8 (PIN_A7 + 1)
253 static const uint8_t A8 = PIN_A8;
254 #endif
255 #if NUM_ANALOG_INPUTS > 9
256  #define PIN_A9 (PIN_A8 + 1)
257 static const uint8_t A9 = PIN_A9;
258 #endif
259 #if NUM_ANALOG_INPUTS > 10
260  #define PIN_A10 (PIN_A9 + 1)
261 static const uint8_t A10 = PIN_A10;
262 #endif
263 #if NUM_ANALOG_INPUTS > 11
264  #define PIN_A11 (PIN_A10 + 1)
265 static const uint8_t A11 = PIN_A11;
266 #endif
267 #if NUM_ANALOG_INPUTS > 12
268  #define PIN_A12 (PIN_A11 + 1)
269 static const uint8_t A12 = PIN_A12;
270 #endif
271 #if NUM_ANALOG_INPUTS > 13
272  #define PIN_A13 (PIN_A12 + 1)
273 static const uint8_t A13 = PIN_A13;
274 #endif
275 #if NUM_ANALOG_INPUTS > 14
276  #define PIN_A14 (PIN_A13 + 1)
277 static const uint8_t A14 = PIN_A14;
278 #endif
279 #if NUM_ANALOG_INPUTS > 15
280  #define PIN_A15 (PIN_A14 + 1)
281 static const uint8_t A15 = PIN_A15;
282 #endif
283 #if NUM_ANALOG_INPUTS > 16
284  #define PIN_A16 (PIN_A15 + 1)
285 static const uint8_t A16 = PIN_A16;
286 #endif
287 #if NUM_ANALOG_INPUTS > 17
288  #define PIN_A17 (PIN_A16 + 1)
289 static const uint8_t A17 = PIN_A17;
290 #endif
291 #if NUM_ANALOG_INPUTS > 18
292  #define PIN_A18 (PIN_A17 + 1)
293 static const uint8_t A18 = PIN_A18;
294 #endif
295 #if NUM_ANALOG_INPUTS > 19
296  #define PIN_A19 (PIN_A18 + 1)
297 static const uint8_t A19 = PIN_A19;
298 #endif
299 #if NUM_ANALOG_INPUTS > 20
300  #define PIN_A20 (PIN_A19 + 1)
301 static const uint8_t A20 = PIN_A20;
302 #endif
303 #if NUM_ANALOG_INPUTS > 21
304  #define PIN_A21 (PIN_A20 + 1)
305 static const uint8_t A21 = PIN_A21;
306 #endif
307 #if NUM_ANALOG_INPUTS > 22
308  #define PIN_A22 (PIN_A21 + 1)
309 static const uint8_t A22 = PIN_A22;
310 #endif
311 #if NUM_ANALOG_INPUTS > 23
312  #define PIN_A23 (PIN_A22 + 1)
313 static const uint8_t A23 = PIN_A23;
314 #endif
315 
316 // Default for Arduino connector compatibility
317 // SPI Definitions
318 #ifndef PIN_SPI_SS
319  #define PIN_SPI_SS 10
320 #endif
321 #ifndef PIN_SPI_SS1
322  #define PIN_SPI_SS1 4
323 #endif
324 #ifndef PIN_SPI_SS2
325  #define PIN_SPI_SS2 7
326 #endif
327 #ifndef PIN_SPI_SS3
328  #define PIN_SPI_SS3 8
329 #endif
330 #ifndef PIN_SPI_MOSI
331  #define PIN_SPI_MOSI 11
332 #endif
333 #ifndef PIN_SPI_MISO
334  #define PIN_SPI_MISO 12
335 #endif
336 #ifndef PIN_SPI_SCK
337  #define PIN_SPI_SCK 13
338 #endif
339 
340 static const uint8_t SS = PIN_SPI_SS;
341 static const uint8_t SS1 = PIN_SPI_SS1;
342 static const uint8_t SS2 = PIN_SPI_SS2;
343 static const uint8_t SS3 = PIN_SPI_SS3;
344 static const uint8_t MOSI = PIN_SPI_MOSI;
345 static const uint8_t MISO = PIN_SPI_MISO;
346 static const uint8_t SCK = PIN_SPI_SCK;
347 
348 // I2C Definitions
349 #ifndef PIN_WIRE_SDA
350  #define PIN_WIRE_SDA 14
351 #endif
352 #ifndef PIN_WIRE_SCL
353  #define PIN_WIRE_SCL 15
354 #endif
355 
356 static const uint8_t SDA = PIN_WIRE_SDA;
357 static const uint8_t SCL = PIN_WIRE_SCL;
358 
359 #ifdef __cplusplus
360 extern "C" {
361 #endif
362 
363 #define NOT_AN_INTERRUPT NC // -1
364 
365 // Convert a digital pin number Dxx to a PinName PX_n
366 // Note: Analog pin is also a digital pin.
367 #define digitalPinToPinName(p) (((uint32_t)p < NUM_DIGITAL_PINS) ? digitalPin[p] : NC)
368 // Convert a PinName PX_n to a digital pin number
369 uint32_t pinNametoDigitalPin(PinName p);
370 
371 // Convert an analog pin number to a digital pin number
372 // Used by analogRead api to have A0 == 0
373 #define analogInputToDigitalPin(p) (((uint32_t)p < NUM_ANALOG_INPUTS) ? (p + A0) : p)
374 // Convert an analog pin number Axx to a PinName PX_n
375 #define analogInputToPinName(p) (digitalPinToPinName(analogInputToDigitalPin(p)))
376 // All pins could manage EXTI
377 #define digitalPinToInterrupt(p) (digitalPinIsValid(p) ? p : NOT_AN_INTERRUPT)
378 
379 #define digitalPinHasI2C(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_I2C_SDA) || pin_in_pinmap(digitalPinToPinName(p), PinMap_I2C_SCL))
380 #define digitalPinHasPWM(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_PWM))
381 #define digitalPinHasSerial(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_UART_RX) || pin_in_pinmap(digitalPinToPinName(p), PinMap_UART_TX))
382 #define digitalPinHasSPI(p) (pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_MOSI) || pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_MISO) || pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_SCLK) || pin_in_pinmap(digitalPinToPinName(p), PinMap_SPI_SSEL))
383 
384 #define digitalPinToPort(p) (get_GPIO_Port(STM_PORT(digitalPinToPinName(p))))
385 #define digitalPinToBitMask(p) (STM_GPIO_PIN(digitalPinToPinName(p)))
386 
387 #define analogInPinToBit(p) (STM_GPIO_PIN(digitalPinToPinName(p)))
388 #define portOutputRegister(P) (&(P->ODR))
389 #define portInputRegister(P) (&(P->IDR))
390 
391 #define portSetRegister(P) (&(P->BSRR))
392 #if defined(STM32F2xx) || defined(STM32F4xx) || defined(STM32F7xx)
393  // For those series reset are in the high part so << 16U needed
394  #define portClearRegister(P) (&(P->BSRR))
395 #else
396  #define portClearRegister(P) (&(P->BRR))
397 #endif
398 
399 #if defined(STM32F1xx)
400  // Config registers split in 2 registers:
401  // CRL: pin 0..7
402  // CRH: pin 8..15
403  // Return only CRL
404  #define portModeRegister(P) (&(P->CRL))
405 #else
406  #define portModeRegister(P) (&(P->MODER))
407 #endif
408 #define portConfigRegister(P) (portModeRegister(P))
409 
410 #define digitalPinIsValid(p) (digitalPinToPinName(p) != NC)
411 
412 // As some pin could be duplicated in digitalPin[]
413 // return first occurence of linked PinName (PYx)
414 #define digitalPinFirstOccurence(p) (pinNametoDigitalPin(digitalPinToPinName(p)))
415 
416 // Specific for Firmata. As some pins could be duplicated,
417 // ensure 'p' is not one of the serial pins
418 #if defined(PIN_SERIAL_RX) && defined(PIN_SERIAL_TX)
419  #define pinIsSerial(p) ((digitalPinFirstOccurence(p) == PIN_SERIAL_RX) || (digitalPinFirstOccurence(p) == PIN_SERIAL_TX))
420 #endif
421 
422 #ifdef __cplusplus
423 }
424 #endif
425 
426 // Default Definitions, could be redefined in variant.h
427 #ifndef ADC_RESOLUTION
428  #define ADC_RESOLUTION 12
429 #endif
430 #ifndef DACC_RESOLUTION
431  #define DACC_RESOLUTION 12
432 #endif
433 #ifndef PWM_RESOLUTION
434  #define PWM_RESOLUTION 8
435 #endif
436 #ifndef PWM_FREQUENCY
437  #define PWM_FREQUENCY 1000
438 #endif
439 #ifndef PWM_MAX_DUTY_CYCLE
440  #define PWM_MAX_DUTY_CYCLE 255
441 #endif
442 
443 #endif /*_PINS_ARDUINO_H_*/
D145
Definition: pins_arduino.h:174
DMAX
Definition: pins_arduino.h:205
D44
Definition: pins_arduino.h:73
D143
Definition: pins_arduino.h:172
D35
Definition: pins_arduino.h:64
D153
Definition: pins_arduino.h:182
D71
Definition: pins_arduino.h:100
D51
Definition: pins_arduino.h:80
D82
Definition: pins_arduino.h:111
D76
Definition: pins_arduino.h:105
D38
Definition: pins_arduino.h:67
D30
Definition: pins_arduino.h:59
D6
Definition: pins_arduino.h:35
D132
Definition: pins_arduino.h:161
D140
Definition: pins_arduino.h:169
D115
Definition: pins_arduino.h:144
D58
Definition: pins_arduino.h:87
D2
Definition: pins_arduino.h:31
D26
Definition: pins_arduino.h:55
D107
Definition: pins_arduino.h:136
D108
Definition: pins_arduino.h:137
D74
Definition: pins_arduino.h:103
D0
Definition: pins_arduino.h:29
D158
Definition: pins_arduino.h:187
D29
Definition: pins_arduino.h:58
D144
Definition: pins_arduino.h:173
PIN_SPI_SS1
#define PIN_SPI_SS1
Definition: pins_arduino.h:322
D62
Definition: pins_arduino.h:91
PinName
PinName
Definition: PinNames.h:11
D90
Definition: pins_arduino.h:119
D73
Definition: pins_arduino.h:102
D13
Definition: pins_arduino.h:42
D14
Definition: pins_arduino.h:43
D93
Definition: pins_arduino.h:122
D122
Definition: pins_arduino.h:151
D159
Definition: pins_arduino.h:188
D61
Definition: pins_arduino.h:90
D97
Definition: pins_arduino.h:126
D18
Definition: pins_arduino.h:47
D110
Definition: pins_arduino.h:139
D114
Definition: pins_arduino.h:143
D133
Definition: pins_arduino.h:162
D32
Definition: pins_arduino.h:61
MOSI
static const uint8_t MOSI
Definition: pins_arduino.h:344
D80
Definition: pins_arduino.h:109
D173
Definition: pins_arduino.h:202
D102
Definition: pins_arduino.h:131
SDA
static const uint8_t SDA
Definition: pins_arduino.h:356
NUM_ANALOG_FIRST
#define NUM_ANALOG_FIRST
Definition: variant.h:216
D148
Definition: pins_arduino.h:177
PIN_SPI_SS2
#define PIN_SPI_SS2
Definition: pins_arduino.h:325
D3
Definition: pins_arduino.h:32
D152
Definition: pins_arduino.h:181
D10
Definition: pins_arduino.h:39
D79
Definition: pins_arduino.h:108
D24
Definition: pins_arduino.h:53
D119
Definition: pins_arduino.h:148
D41
Definition: pins_arduino.h:70
D165
Definition: pins_arduino.h:194
D96
Definition: pins_arduino.h:125
D20
Definition: pins_arduino.h:49
D150
Definition: pins_arduino.h:179
D45
Definition: pins_arduino.h:74
D12
Definition: pins_arduino.h:41
D111
Definition: pins_arduino.h:140
D17
Definition: pins_arduino.h:46
D21
Definition: pins_arduino.h:50
D136
Definition: pins_arduino.h:165
PIN_SPI_SS
#define PIN_SPI_SS
Definition: pins_arduino.h:319
D92
Definition: pins_arduino.h:121
D87
Definition: pins_arduino.h:116
D85
Definition: pins_arduino.h:114
D66
Definition: pins_arduino.h:95
D155
Definition: pins_arduino.h:184
D117
Definition: pins_arduino.h:146
D95
Definition: pins_arduino.h:124
D141
Definition: pins_arduino.h:170
D127
Definition: pins_arduino.h:156
_Static_assert
_Static_assert(LastPort<=0x0F, "PortName must be less than 16")
D63
Definition: pins_arduino.h:92
D166
Definition: pins_arduino.h:195
D65
Definition: pins_arduino.h:94
D101
Definition: pins_arduino.h:130
D83
Definition: pins_arduino.h:112
D8
Definition: pins_arduino.h:37
D36
Definition: pins_arduino.h:65
PIN_SPI_SS3
#define PIN_SPI_SS3
Definition: pins_arduino.h:328
D134
Definition: pins_arduino.h:163
D161
Definition: pins_arduino.h:190
D129
Definition: pins_arduino.h:158
D103
Definition: pins_arduino.h:132
D142
Definition: pins_arduino.h:171
D22
Definition: pins_arduino.h:51
D121
Definition: pins_arduino.h:150
D86
Definition: pins_arduino.h:115
pinNametoDigitalPin
uint32_t pinNametoDigitalPin(PinName p)
D126
Definition: pins_arduino.h:155
D100
Definition: pins_arduino.h:129
D78
Definition: pins_arduino.h:107
D7
Definition: pins_arduino.h:36
SS3
static const uint8_t SS3
Definition: pins_arduino.h:343
PIN_SPI_MISO
#define PIN_SPI_MISO
Definition: pins_arduino.h:334
D91
Definition: pins_arduino.h:120
PIN_WIRE_SCL
#define PIN_WIRE_SCL
Definition: pins_arduino.h:353
D174
Definition: pins_arduino.h:203
D124
Definition: pins_arduino.h:153
D31
Definition: pins_arduino.h:60
D25
Definition: pins_arduino.h:54
D120
Definition: pins_arduino.h:149
D138
Definition: pins_arduino.h:167
D160
Definition: pins_arduino.h:189
SCK
static const uint8_t SCK
Definition: pins_arduino.h:346
D147
Definition: pins_arduino.h:176
D109
Definition: pins_arduino.h:138
D123
Definition: pins_arduino.h:152
D50
Definition: pins_arduino.h:79
D137
Definition: pins_arduino.h:166
D89
Definition: pins_arduino.h:118
PIN_WIRE_SDA
#define PIN_WIRE_SDA
Definition: pins_arduino.h:350
D167
Definition: pins_arduino.h:196
D84
Definition: pins_arduino.h:113
D19
Definition: pins_arduino.h:48
D149
Definition: pins_arduino.h:178
D94
Definition: pins_arduino.h:123
D64
Definition: pins_arduino.h:93
D52
Definition: pins_arduino.h:81
uint8_t
const uint8_t[]
Definition: 404_html.c:3
D57
Definition: pins_arduino.h:86
D172
Definition: pins_arduino.h:201
SS2
static const uint8_t SS2
Definition: pins_arduino.h:342
D154
Definition: pins_arduino.h:183
D163
Definition: pins_arduino.h:192
D39
Definition: pins_arduino.h:68
PIN_SPI_MOSI
#define PIN_SPI_MOSI
Definition: pins_arduino.h:331
D59
Definition: pins_arduino.h:88
D53
Definition: pins_arduino.h:82
D40
Definition: pins_arduino.h:69
D34
Definition: pins_arduino.h:63
D106
Definition: pins_arduino.h:135
D70
Definition: pins_arduino.h:99
D171
Definition: pins_arduino.h:200
D162
Definition: pins_arduino.h:191
D112
Definition: pins_arduino.h:141
D170
Definition: pins_arduino.h:199
NUM_ANALOG_INPUTS
constexpr uint8_t NUM_ANALOG_INPUTS
Definition: pinmapping.h:33
D47
Definition: pins_arduino.h:76
D1
Definition: pins_arduino.h:30
D77
Definition: pins_arduino.h:106
D27
Definition: pins_arduino.h:56
D118
Definition: pins_arduino.h:147
D88
Definition: pins_arduino.h:117
D5
Definition: pins_arduino.h:34
D33
Definition: pins_arduino.h:62
D104
Definition: pins_arduino.h:133
SS
static const uint8_t SS
Definition: pins_arduino.h:340
D175
Definition: pins_arduino.h:204
PIN_SPI_SCK
#define PIN_SPI_SCK
Definition: pins_arduino.h:337
D125
Definition: pins_arduino.h:154
D131
Definition: pins_arduino.h:160
D156
Definition: pins_arduino.h:185
D130
Definition: pins_arduino.h:159
SS1
static const uint8_t SS1
Definition: pins_arduino.h:341
D113
Definition: pins_arduino.h:142
D146
Definition: pins_arduino.h:175
D128
Definition: pins_arduino.h:157
MAX_ANALOG_INPUTS
#define MAX_ANALOG_INPUTS
Definition: pins_arduino.h:210
D23
Definition: pins_arduino.h:52
D49
Definition: pins_arduino.h:78
D68
Definition: pins_arduino.h:97
D4
Definition: pins_arduino.h:33
D9
Definition: pins_arduino.h:38
D98
Definition: pins_arduino.h:127
D55
Definition: pins_arduino.h:84
D116
Definition: pins_arduino.h:145
MISO
static const uint8_t MISO
Definition: pins_arduino.h:345
D60
Definition: pins_arduino.h:89
D164
Definition: pins_arduino.h:193
D42
Definition: pins_arduino.h:71
D15
Definition: pins_arduino.h:44
D135
Definition: pins_arduino.h:164
D48
Definition: pins_arduino.h:77
D54
Definition: pins_arduino.h:83
D43
Definition: pins_arduino.h:72
D99
Definition: pins_arduino.h:128
D139
Definition: pins_arduino.h:168
D169
Definition: pins_arduino.h:198
D16
Definition: pins_arduino.h:45
D56
Definition: pins_arduino.h:85
D151
Definition: pins_arduino.h:180
D28
Definition: pins_arduino.h:57
D157
Definition: pins_arduino.h:186
D72
Definition: pins_arduino.h:101
SCL
static const uint8_t SCL
Definition: pins_arduino.h:357
D46
Definition: pins_arduino.h:75
D105
Definition: pins_arduino.h:134
D69
Definition: pins_arduino.h:98
LastPort
Definition: PortNames.h:73
D168
Definition: pins_arduino.h:197
D81
Definition: pins_arduino.h:110
D11
Definition: pins_arduino.h:40
D75
Definition: pins_arduino.h:104
D37
Definition: pins_arduino.h:66
D67
Definition: pins_arduino.h:96