16 #ifndef Firmata_Boards_h
17 #define Firmata_Boards_h
21 #if defined(ARDUINO) && ARDUINO >= 100
140 #ifndef digitalPinHasPWM
141 #define digitalPinHasPWM(p) IS_PIN_DIGITAL(p)
145 #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
146 #if defined(NUM_ANALOG_INPUTS) && NUM_ANALOG_INPUTS == 6
147 #define TOTAL_ANALOG_PINS 6
148 #define TOTAL_PINS 20 // 14 digital + 6 analog
150 #define TOTAL_ANALOG_PINS 8
151 #define TOTAL_PINS 22 // 14 digital + 8 analog
153 #define VERSION_BLINK_PIN 13
154 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) <= 19)
155 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) < 14 + TOTAL_ANALOG_PINS)
156 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
157 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
158 #define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
159 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
160 #define PIN_TO_DIGITAL(p) (p)
161 #define PIN_TO_ANALOG(p) ((p) - 14)
162 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
163 #define PIN_TO_SERVO(p) ((p) - 2)
164 #define ARDUINO_PINOUT_OPTIMIZE 1
168 #elif defined(WIRING)
169 #define VERSION_BLINK_PIN WLED
170 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
171 #define IS_PIN_ANALOG(p) ((p) >= FIRST_ANALOG_PIN && (p) < (FIRST_ANALOG_PIN+TOTAL_ANALOG_PINS))
172 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
173 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
174 #define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
175 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
176 #define PIN_TO_DIGITAL(p) (p)
177 #define PIN_TO_ANALOG(p) ((p) - FIRST_ANALOG_PIN)
178 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
179 #define PIN_TO_SERVO(p) (p)
183 #elif defined(__AVR_ATmega8__)
184 #define TOTAL_ANALOG_PINS 6
185 #define TOTAL_PINS 20 // 14 digital + 6 analog
186 #define VERSION_BLINK_PIN 13
187 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) <= 19)
188 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) <= 19)
189 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
190 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
191 #define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
192 #define PIN_TO_DIGITAL(p) (p)
193 #define PIN_TO_ANALOG(p) ((p) - 14)
194 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
195 #define PIN_TO_SERVO(p) ((p) - 2)
196 #define ARDUINO_PINOUT_OPTIMIZE 1
200 #elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
201 #define TOTAL_ANALOG_PINS 16
202 #define TOTAL_PINS 70 // 54 digital + 16 analog
203 #define VERSION_BLINK_PIN 13
204 #define PIN_SERIAL1_RX 19
205 #define PIN_SERIAL1_TX 18
206 #define PIN_SERIAL2_RX 17
207 #define PIN_SERIAL2_TX 16
208 #define PIN_SERIAL3_RX 15
209 #define PIN_SERIAL3_TX 14
210 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < TOTAL_PINS)
211 #define IS_PIN_ANALOG(p) ((p) >= 54 && (p) < TOTAL_PINS)
212 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
213 #define IS_PIN_SERVO(p) ((p) >= 2 && (p) - 2 < MAX_SERVOS)
214 #define IS_PIN_I2C(p) ((p) == 20 || (p) == 21)
215 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
216 #define IS_PIN_SERIAL(p) ((p) > 13 && (p) < 20)
217 #define PIN_TO_DIGITAL(p) (p)
218 #define PIN_TO_ANALOG(p) ((p) - 54)
219 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
220 #define PIN_TO_SERVO(p) ((p) - 2)
223 #elif defined(__AVR_ATmega4809__)
224 #define TOTAL_ANALOG_PINS 6
225 #define TOTAL_PINS 20 // 14 digital + 6 analog +
226 #define VERSION_BLINK_PIN 25
227 #define PIN_SERIAL1_RX 0
228 #define PIN_SERIAL1_TX 1
229 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
230 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) < TOTAL_PINS)
231 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
232 #define IS_PIN_SERVO(p) (p)
233 #define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
234 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
235 #define IS_PIN_SERIAL(p) ((p) == 0 || (p) == 1)
236 #define PIN_TO_DIGITAL(p) (p)
237 #define PIN_TO_ANALOG(p) (p) - 14
238 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
239 #define PIN_TO_SERVO(p) (p)
242 #elif defined(__SAM3X8E__)
243 #define TOTAL_ANALOG_PINS 12
244 #define TOTAL_PINS 66 // 54 digital + 12 analog
245 #define VERSION_BLINK_PIN 13
246 #define PIN_SERIAL1_RX 19
247 #define PIN_SERIAL1_TX 18
248 #define PIN_SERIAL2_RX 17
249 #define PIN_SERIAL2_TX 16
250 #define PIN_SERIAL3_RX 15
251 #define PIN_SERIAL3_TX 14
252 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < TOTAL_PINS)
253 #define IS_PIN_ANALOG(p) ((p) >= 54 && (p) < TOTAL_PINS)
254 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
255 #define IS_PIN_SERVO(p) ((p) >= 2 && (p) - 2 < MAX_SERVOS)
256 #define IS_PIN_I2C(p) ((p) == 20 || (p) == 21) // 70 71
257 #define IS_PIN_SERIAL(p) ((p) > 13 && (p) < 20)
258 #define PIN_TO_DIGITAL(p) (p)
259 #define PIN_TO_ANALOG(p) ((p) - 54)
260 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
261 #define PIN_TO_SERVO(p) ((p) - 2)
265 #elif defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010)
266 #define TOTAL_ANALOG_PINS 7
267 #define TOTAL_PINS 22 // 8 digital + 3 spi + 2 i2c + 2 uart + 7 analog
268 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) <= 21)
269 #define IS_PIN_ANALOG(p) ((p) >= 15 && (p) < 15 + TOTAL_ANALOG_PINS)
270 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
271 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS) // deprecated since v2.4
272 #define IS_PIN_I2C(p) ((p) == 11 || (p) == 12) // SDA = 11, SCL = 12
273 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
274 #define IS_PIN_SERIAL(p) ((p) == PIN_SERIAL1_RX || (p) == PIN_SERIAL1_TX) //defined in variant.h RX = 13, TX = 14
275 #define PIN_TO_DIGITAL(p) (p)
276 #define PIN_TO_ANALOG(p) ((p) - 15)
277 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
278 #define PIN_TO_SERVO(p) (p) // deprecated since v2.4
282 #elif defined(ARDUINO_SAMD_MKRZERO)
283 #define TOTAL_ANALOG_PINS 7
284 #define TOTAL_PINS 34 // 8 digital + 3 spi + 2 i2c + 2 uart + 7 analog + 3 usb + 1 aref + 5 sd + 1 bottom pad + 1 led + 1 battery adc
285 #define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 21) || (p) == 32)
286 #define IS_PIN_ANALOG(p) (((p) >= 15 && (p) < 15 + TOTAL_ANALOG_PINS) || (p) == 33)
287 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
288 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS) // deprecated since v2.4
289 #define IS_PIN_I2C(p) ((p) == 11 || (p) == 12) // SDA = 11, SCL = 12
290 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
291 #define IS_PIN_SERIAL(p) ((p) == PIN_SERIAL1_RX || (p) == PIN_SERIAL1_TX) //defined in variant.h RX = 13, TX = 14
292 #define PIN_TO_DIGITAL(p) (p)
293 #define PIN_TO_ANALOG(p) ((p) - 15)
294 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
295 #define PIN_TO_SERVO(p) (p) // deprecated since v2.4
298 #elif defined(ARDUINO_SAMD_MKRFox1200)
299 #define TOTAL_ANALOG_PINS 7
300 #define TOTAL_PINS 33 // 8 digital + 3 spi + 2 i2c + 2 uart + 7 analog + 3 usb + 1 aref + 5 sd + 1 bottom pad + 1 battery adc
301 #define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 21))
302 #define IS_PIN_ANALOG(p) (((p) >= 15 && (p) < 15 + TOTAL_ANALOG_PINS) || (p) == 32)
303 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
304 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS) // deprecated since v2.4
305 #define IS_PIN_I2C(p) ((p) == 11 || (p) == 12) // SDA = 11, SCL = 12
306 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
307 #define IS_PIN_SERIAL(p) ((p) == PIN_SERIAL1_RX || (p) == PIN_SERIAL1_TX) //defined in variant.h RX = 13, TX = 14
308 #define PIN_TO_DIGITAL(p) (p)
309 #define PIN_TO_ANALOG(p) ((p) - 15)
310 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
311 #define PIN_TO_SERVO(p) (p) // deprecated since v2.4
314 #elif defined(ARDUINO_SAMD_MKRWAN1300)
315 #define TOTAL_ANALOG_PINS 7
316 #define TOTAL_PINS 33
317 #define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 21))
318 #define IS_PIN_ANALOG(p) (((p) >= 15 && (p) < 15 + TOTAL_ANALOG_PINS) || (p) == 32)
319 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
320 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS) // deprecated since v2.4
321 #define IS_PIN_I2C(p) ((p) == 11 || (p) == 12) // SDA = 11, SCL = 12
322 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
323 #define IS_PIN_SERIAL(p) ((p) == PIN_SERIAL1_RX || (p) == PIN_SERIAL1_TX) //defined in variant.h RX = 13, TX = 14
324 #define PIN_TO_DIGITAL(p) (p)
325 #define PIN_TO_ANALOG(p) ((p) - 15)
326 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
327 #define PIN_TO_SERVO(p) (p) // deprecated since v2.4
330 #elif defined(ARDUINO_SAMD_MKRGSM1400)
331 #define TOTAL_ANALOG_PINS 7
332 #define TOTAL_PINS 33
333 #define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 21))
334 #define IS_PIN_ANALOG(p) (((p) >= 15 && (p) < 15 + TOTAL_ANALOG_PINS) || (p) == 32)
335 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
336 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS) // deprecated since v2.4
337 #define IS_PIN_I2C(p) ((p) == 11 || (p) == 12) // SDA = 11, SCL = 12
338 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
339 #define IS_PIN_SERIAL(p) ((p) == PIN_SERIAL1_RX || (p) == PIN_SERIAL1_TX) //defined in variant.h RX = 13, TX = 14
340 #define PIN_TO_DIGITAL(p) (p)
341 #define PIN_TO_ANALOG(p) ((p) - 15)
342 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
343 #define PIN_TO_SERVO(p) (p) // deprecated since v2.4
348 #elif defined(_VARIANT_ARDUINO_ZERO_)
349 #define TOTAL_ANALOG_PINS 6
350 #define TOTAL_PINS 25 // 14 digital + 6 analog + 2 i2c + 3 spi
351 #define TOTAL_PORTS 3 // set when TOTAL_PINS > num digitial I/O pins
352 #define VERSION_BLINK_PIN LED_BUILTIN
355 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) <= 19)
356 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) < 14 + TOTAL_ANALOG_PINS)
357 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
358 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS) // deprecated since v2.4
359 #define IS_PIN_I2C(p) ((p) == 20 || (p) == 21) // SDA = 20, SCL = 21
360 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK) // SS = A2
361 #define IS_PIN_SERIAL(p) ((p) == 0 || (p) == 1)
362 #define PIN_TO_DIGITAL(p) (p)
363 #define PIN_TO_ANALOG(p) ((p) - 14)
364 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
365 #define PIN_TO_SERVO(p) (p) // deprecated since v2.4
368 #elif defined(ARDUINO_PRIMO)
369 #define TOTAL_ANALOG_PINS 6
370 #define TOTAL_PINS 22 //14 digital + 6 analog + 2 i2c
371 #define VERSION_BLINK_PIN LED_BUILTIN
372 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < 20)
373 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) < 20)
374 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
375 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS+2)
376 #define IS_PIN_I2C(p) ((p) == PIN_WIRE_SDA || (p) == PIN_WIRE_SCL) // SDA = 20, SCL = 21
377 #define IS_PIN_SPI(p) ((p) == SS || (p)== MOSI || (p) == MISO || (p == SCK)) // 10, 11, 12, 13
378 #define PIN_TO_DIGITAL(p) (p)
379 #define PIN_TO_ANALOG(p) ((p) - 14)
380 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
381 #define PIN_TO_SERVO(p) (p)
384 #elif defined(_VARIANT_ARDUINO_101_X_)
385 #define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS
386 #define TOTAL_PINS NUM_DIGITAL_PINS // 15 digital (including ATN pin) + 6 analog
387 #define VERSION_BLINK_PIN LED_BUILTIN
388 #define PIN_SERIAL1_RX 0
389 #define PIN_SERIAL1_TX 1
390 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) <= 20)
391 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) < 14 + TOTAL_ANALOG_PINS)
392 #define IS_PIN_PWM(p) digitalPinHasPWM(p) // 3, 5, 6, 9
393 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS) // deprecated since v2.4
394 #define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL) // SDA = 18, SCL = 19
395 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
396 #define IS_PIN_SERIAL(p) ((p) == 0 || (p) == 1)
397 #define PIN_TO_DIGITAL(p) (p)
398 #define PIN_TO_ANALOG(p) ((p) - 14)
399 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
400 #define PIN_TO_SERVO(p) (p) // deprecated since v2.4
404 #elif defined(__AVR_AT90USB162__)
405 #define TOTAL_ANALOG_PINS 0
406 #define TOTAL_PINS 21 // 21 digital + no analog
407 #define VERSION_BLINK_PIN 6
408 #define PIN_SERIAL1_RX 2
409 #define PIN_SERIAL1_TX 3
410 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
411 #define IS_PIN_ANALOG(p) (0)
412 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
413 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
414 #define IS_PIN_I2C(p) (0)
415 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
416 #define IS_PIN_SERIAL(p) ((p) == 2 || (p) == 3)
417 #define PIN_TO_DIGITAL(p) (p)
418 #define PIN_TO_ANALOG(p) (0)
419 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
420 #define PIN_TO_SERVO(p) (p)
424 #elif defined(__AVR_ATmega32U4__) && defined(CORE_TEENSY)
425 #define TOTAL_ANALOG_PINS 12
426 #define TOTAL_PINS 25 // 11 digital + 12 analog
427 #define VERSION_BLINK_PIN 11
428 #define PIN_SERIAL1_RX 7
429 #define PIN_SERIAL1_TX 8
430 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
431 #define IS_PIN_ANALOG(p) ((p) >= 11 && (p) <= 22)
432 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
433 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
434 #define IS_PIN_I2C(p) ((p) == 5 || (p) == 6)
435 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
436 #define IS_PIN_SERIAL(p) ((p) == 7 || (p) == 8)
437 #define PIN_TO_DIGITAL(p) (p)
438 #define PIN_TO_ANALOG(p) (((p) < 22) ? 21 - (p) : 11)
439 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
440 #define PIN_TO_SERVO(p) (p)
445 #elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
446 #define TOTAL_ANALOG_PINS 27 // 3.5 has 27 and 3.6 has 25
447 #define TOTAL_PINS 70 // 43 digital + 21 analog-digital + 6 analog (64-69)
448 #define VERSION_BLINK_PIN 13
449 #define PIN_SERIAL1_RX 0
450 #define PIN_SERIAL1_TX 1
451 #define PIN_SERIAL2_RX 9
452 #define PIN_SERIAL2_TX 10
453 #define PIN_SERIAL3_RX 7
454 #define PIN_SERIAL3_TX 8
455 #define PIN_SERIAL4_RX 31
456 #define PIN_SERIAL4_TX 32
457 #define PIN_SERIAL5_RX 34
458 #define PIN_SERIAL5_TX 33
459 #define PIN_SERIAL6_RX 47
460 #define PIN_SERIAL6_TX 48
461 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) <= 63)
462 #define IS_PIN_ANALOG(p) (((p) >= 14 && (p) <= 23) || ((p) >= 31 && (p) <= 39) || ((p) >= 49 && (p) <= 50) || ((p) >= 64 && (p) <= 69))
463 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
464 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
465 #define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
466 #define IS_PIN_SERIAL(p) (((p) > 6 && (p) < 11) || ((p) == 0 || (p) == 1) || ((p) > 30 && (p) < 35) || ((p) == 47 || (p) == 48))
467 #define PIN_TO_DIGITAL(p) (p)
469 #define PIN_TO_ANALOG(p) (((p) <= 23) ? (p) - 14 : (((p) <= 39) ? (p) - 19 : (((p) <= 50) ? (p) - 26 : (((p) <= 65) ? (p) - 55 : (((p) <= 67) ? (p) - 45 : (p) - 43)))))
470 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
471 #define PIN_TO_SERVO(p) (p)
475 #elif defined(__MK20DX128__) || defined(__MK20DX256__)
476 #define TOTAL_ANALOG_PINS 14
477 #define TOTAL_PINS 38 // 24 digital + 10 analog-digital + 4 analog
478 #define VERSION_BLINK_PIN 13
479 #define PIN_SERIAL1_RX 0
480 #define PIN_SERIAL1_TX 1
481 #define PIN_SERIAL2_RX 9
482 #define PIN_SERIAL2_TX 10
483 #define PIN_SERIAL3_RX 7
484 #define PIN_SERIAL3_TX 8
485 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) <= 33)
486 #define IS_PIN_ANALOG(p) (((p) >= 14 && (p) <= 23) || ((p) >= 34 && (p) <= 38))
487 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
488 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
489 #define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
490 #define IS_PIN_SERIAL(p) (((p) > 6 && (p) < 11) || ((p) == 0 || (p) == 1))
491 #define PIN_TO_DIGITAL(p) (p)
492 #define PIN_TO_ANALOG(p) (((p) <= 23) ? (p) - 14 : (p) - 24)
493 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
494 #define PIN_TO_SERVO(p) (p)
498 #elif defined(__MKL26Z64__)
499 #define TOTAL_ANALOG_PINS 13
500 #define TOTAL_PINS 27 // 27 digital + 13 analog-digital
501 #define VERSION_BLINK_PIN 13
502 #define PIN_SERIAL1_RX 0
503 #define PIN_SERIAL1_TX 1
504 #define PIN_SERIAL2_RX 9
505 #define PIN_SERIAL2_TX 10
506 #define PIN_SERIAL3_RX 7
507 #define PIN_SERIAL3_TX 8
508 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) <= 26)
509 #define IS_PIN_ANALOG(p) ((p) >= 14)
510 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
511 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
512 #define IS_PIN_I2C(p) ((p) == 18 || (p) == 19)
513 #define IS_PIN_SERIAL(p) (((p) > 6 && (p) < 11) || ((p) == 0 || (p) == 1))
514 #define PIN_TO_DIGITAL(p) (p)
515 #define PIN_TO_ANALOG(p) ((p) - 14)
516 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
517 #define PIN_TO_SERVO(p) (p)
521 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
522 #define TOTAL_ANALOG_PINS 8
523 #define TOTAL_PINS 46 // 38 digital + 8 analog
524 #define VERSION_BLINK_PIN 6
525 #define PIN_SERIAL1_RX 2
526 #define PIN_SERIAL1_TX 3
527 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
528 #define IS_PIN_ANALOG(p) ((p) >= 38 && (p) < TOTAL_PINS)
529 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
530 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
531 #define IS_PIN_I2C(p) ((p) == 0 || (p) == 1)
532 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
533 #define IS_PIN_SERIAL(p) ((p) == 2 || (p) == 3)
534 #define PIN_TO_DIGITAL(p) (p)
535 #define PIN_TO_ANALOG(p) ((p) - 38)
536 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
537 #define PIN_TO_SERVO(p) (p)
541 #elif defined(__AVR_ATmega32U4__)
542 #define TOTAL_ANALOG_PINS 12
543 #define TOTAL_PINS 30 // 14 digital + 12 analog + 4 SPI (D14-D17 on ISP header)
544 #define VERSION_BLINK_PIN 13
545 #define PIN_SERIAL1_RX 0
546 #define PIN_SERIAL1_TX 1
547 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
548 #define IS_PIN_ANALOG(p) ((p) >= 18 && (p) < TOTAL_PINS)
549 #define IS_PIN_PWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11 || (p) == 13)
550 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
551 #define IS_PIN_I2C(p) ((p) == 2 || (p) == 3)
552 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
553 #define IS_PIN_SERIAL(p) ((p) == 0 || (p) == 1)
554 #define PIN_TO_DIGITAL(p) (p)
555 #define PIN_TO_ANALOG(p) (p) - 18
556 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
557 #define PIN_TO_SERVO(p) (p)
561 #elif defined(ARDUINO_LINUX)
562 #define TOTAL_ANALOG_PINS 6
563 #define TOTAL_PINS 20 // 14 digital + 6 analog
564 #define VERSION_BLINK_PIN 13
565 #define PIN_SERIAL1_RX 0
566 #define PIN_SERIAL1_TX 1
567 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) <= 19)
568 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) <= 19)
569 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
570 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) - 2 < MAX_SERVOS)
571 #define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
572 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
573 #define IS_PIN_SERIAL(p) ((p) == 0 || (p) == 1)
574 #define PIN_TO_DIGITAL(p) (p)
575 #define PIN_TO_ANALOG(p) ((p) - 14)
576 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
577 #define PIN_TO_SERVO(p) ((p) - 2)
581 #elif defined(BLE_NANO)
582 #define TOTAL_ANALOG_PINS 6
583 #define TOTAL_PINS 15 // 9 digital + 3 analog
584 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) <= 14)
585 #define IS_PIN_ANALOG(p) ((p) == 8 || (p) == 9 || (p) == 10 || (p) == 11 || (p) == 12 || (p) == 14) //A0~A5
586 #define IS_PIN_PWM(p) ((p) == 3 || (p) == 5 || (p) == 6)
587 #define IS_PIN_SERVO(p) ((p) >= 2 && (p) <= 7)
588 #define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
589 #define IS_PIN_SPI(p) ((p) == CS || (p) == MOSI || (p) == MISO || (p) == SCK)
590 #define PIN_TO_DIGITAL(p) (p)
591 #define PIN_TO_ANALOG(p) ((p) - 8)
592 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
593 #define PIN_TO_SERVO(p) (p)
597 #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
598 #define TOTAL_ANALOG_PINS 8
599 #define TOTAL_PINS 32 // 24 digital + 8 analog
600 #define VERSION_BLINK_PIN 0
601 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < TOTAL_PINS)
602 #define IS_PIN_ANALOG(p) ((p) >= 24 && (p) < TOTAL_PINS)
603 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
604 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
605 #define IS_PIN_I2C(p) ((p) == 16 || (p) == 17)
606 #define PIN_TO_DIGITAL(p) (p)
607 #define PIN_TO_ANALOG(p) ((p) - 24)
608 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
609 #define PIN_TO_SERVO(p) ((p) - 2)
612 #elif defined(__AVR_ATmega1284P__)
613 #define TOTAL_ANALOG_PINS 8
614 #define TOTAL_PINS 32
615 #define VERSION_BLINK_PIN 13
616 #define PIN_SERIAL1_RX 8 //PD0
617 #define PIN_SERIAL1_TX 9 //PD1
618 #define IS_PIN_DIGITAL(p) ((p) >= 0 && (p) < TOTAL_PINS)
619 #define IS_PIN_ANALOG(p) ((p) >= 24 && (p) < TOTAL_PINS)
620 #define IS_PIN_PWM(p) ((p) == 3 || (p) == 4 || (p) == 6 || (p) == 7 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15)
621 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
622 #define IS_PIN_I2C(p) ((p) == 16 || (p) == 17)
623 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
624 #define IS_PIN_SERIAL(p) ((p) == 8 || (p) == 9)
625 #define PIN_TO_DIGITAL(p) (p)
626 #define PIN_TO_ANALOG(p) (p) - 24
627 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
628 #define PIN_TO_SERVO(p) (p)
632 #elif defined(__AVR_ATmega645__)
633 #define TOTAL_ANALOG_PINS 6
634 #define TOTAL_PINS 42 // 36 digital + 6 analog
635 #define VERSION_BLINK_PIN 13
636 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < TOTAL_PINS)
637 #define IS_PIN_ANALOG(p) ((p) >= 36 && (p) < TOTAL_PINS)
638 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
639 #define IS_PIN_SERVO(p) ((p) >= 0 && (p) < MAX_SERVOS)
640 #define IS_PIN_I2C(p) ((p) == 4 || (p) == 5)
641 #define PIN_TO_DIGITAL(p) (p)
642 #define PIN_TO_ANALOG(p) ((p) - 36)
643 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
644 #define PIN_TO_SERVO(p) ((p) - 2)
648 #elif defined(_BOARD_FUBARINO_SD_)
649 #define TOTAL_ANALOG_PINS NUM_ANALOG_PINS // 15
650 #define TOTAL_PINS NUM_DIGITAL_PINS // 45, All pins can be digital
651 #define MAX_SERVOS NUM_DIGITAL_PINS
652 #define VERSION_BLINK_PIN PIN_LED1
653 #define IS_PIN_DIGITAL(p) 1
654 #define IS_PIN_ANALOG(p) ((p) >= 30 && (p) <= 44)
655 #define IS_PIN_PWM(p) IS_PIN_DIGITAL(p)
656 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
657 #define IS_PIN_I2C(p) ((p) == 1 || (p) == 2)
658 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
659 #define PIN_TO_DIGITAL(p) (p)
660 #define PIN_TO_ANALOG(p) (14 - (p - 30))
661 #define PIN_TO_PWM(p) (p)
662 #define PIN_TO_SERVO(p) (p)
667 #elif defined(_BOARD_FUBARINO_MINI_)
668 #define TOTAL_ANALOG_PINS 14 // We have to fake this because of the poor analog pin mapping planning in FubarinoMini
669 #define TOTAL_PINS NUM_DIGITAL_PINS // 33
670 #define MAX_SERVOS NUM_DIGITAL_PINS
671 #define VERSION_BLINK_PIN PIN_LED1
672 #define IS_PIN_DIGITAL(p) ((p) != 14 && (p) != 15 && (p) != 31 && (p) != 32)
673 #define IS_PIN_ANALOG(p) ((p) == 0 || ((p) >= 3 && (p) <= 13))
674 #define IS_PIN_PWM(p) IS_PIN_DIGITAL(p)
675 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
676 #define IS_PIN_I2C(p) ((p) == 25 || (p) == 26)
677 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
678 #define PIN_TO_DIGITAL(p) (p)
679 #define PIN_TO_ANALOG(p) (p)
680 #define PIN_TO_PWM(p) (p)
681 #define PIN_TO_SERVO(p) (p)
685 #elif defined(_BOARD_UNO_) && defined(__PIC32) // NOTE: no _BOARD_UNO32_ to use
686 #define TOTAL_ANALOG_PINS NUM_ANALOG_PINS // 12
687 #define TOTAL_PINS NUM_DIGITAL_PINS // 47 All pins can be digital
688 #define MAX_SERVOS NUM_DIGITAL_PINS // All pins can be servo with SoftPWMservo
689 #define VERSION_BLINK_PIN PIN_LED1
690 #define IS_PIN_DIGITAL(p) ((p) >= 2)
691 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) <= 25)
692 #define IS_PIN_PWM(p) IS_PIN_DIGITAL(p)
693 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
694 #define IS_PIN_I2C(p) ((p) == 45 || (p) == 46)
695 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
696 #define PIN_TO_DIGITAL(p) (p)
697 #define PIN_TO_ANALOG(p) ((p) - 14)
698 #define PIN_TO_PWM(p) (p)
699 #define PIN_TO_SERVO(p) (p)
703 #elif defined(_BOARD_DP32_)
704 #define TOTAL_ANALOG_PINS 15 // Really only has 9, but have to override because of mistake in variant file
705 #define TOTAL_PINS NUM_DIGITAL_PINS // 19
706 #define MAX_SERVOS NUM_DIGITAL_PINS // All pins can be servo with SoftPWMservo
707 #define VERSION_BLINK_PIN PIN_LED1
708 #define IS_PIN_DIGITAL(p) (((p) != 1) && ((p) != 4) && ((p) != 5) && ((p) != 15) && ((p) != 16))
709 #define IS_PIN_ANALOG(p) ((p) >= 6 && (p) <= 14)
710 #define IS_PIN_PWM(p) IS_PIN_DIGITAL(p)
711 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
712 #define IS_PIN_I2C(p) ((p) == 2 || (p) == 3)
713 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
714 #define PIN_TO_DIGITAL(p) (p)
715 #define PIN_TO_ANALOG(p) (p)
716 #define PIN_TO_PWM(p) (p)
717 #define PIN_TO_SERVO(p) (p)
721 #elif defined(_BOARD_UC32_)
722 #define TOTAL_ANALOG_PINS NUM_ANALOG_PINS // 12
723 #define TOTAL_PINS NUM_DIGITAL_PINS // 47 All pins can be digital
724 #define MAX_SERVOS NUM_DIGITAL_PINS // All pins can be servo with SoftPWMservo
725 #define VERSION_BLINK_PIN PIN_LED1
726 #define IS_PIN_DIGITAL(p) ((p) >= 2)
727 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) <= 25)
728 #define IS_PIN_PWM(p) IS_PIN_DIGITAL(p)
729 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
730 #define IS_PIN_I2C(p) ((p) == 45 || (p) == 46)
731 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
732 #define PIN_TO_DIGITAL(p) (p)
733 #define PIN_TO_ANALOG(p) ((p) - 14)
734 #define PIN_TO_PWM(p) (p)
735 #define PIN_TO_SERVO(p) (p)
739 #elif defined(_BOARD_WF32_)
740 #define TOTAL_ANALOG_PINS NUM_ANALOG_PINS
741 #define TOTAL_PINS NUM_DIGITAL_PINS
742 #define MAX_SERVOS NUM_DIGITAL_PINS
743 #define VERSION_BLINK_PIN PIN_LED1
744 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) <= 49) // Accounts for SD and WiFi dedicated pins
745 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) <= 25)
746 #define IS_PIN_PWM(p) IS_PIN_DIGITAL(p)
747 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
748 #define IS_PIN_I2C(p) ((p) == 34 || (p) == 35)
749 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
750 #define PIN_TO_DIGITAL(p) (p)
751 #define PIN_TO_ANALOG(p) ((p) - 14)
752 #define PIN_TO_PWM(p) (p)
753 #define PIN_TO_SERVO(p) (p)
757 #elif defined(_BOARD_WIFIRE_)
758 #define TOTAL_ANALOG_PINS NUM_ANALOG_PINS // 14
759 #define TOTAL_PINS NUM_DIGITAL_PINS // 71
760 #define MAX_SERVOS NUM_DIGITAL_PINS
761 #define VERSION_BLINK_PIN PIN_LED1
762 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) <= 47) // Accounts for SD and WiFi dedicated pins
763 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) <= 25)
764 #define IS_PIN_PWM(p) IS_PIN_DIGITAL(p)
765 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
766 #define IS_PIN_I2C(p) ((p) == 34 || (p) == 35)
767 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
768 #define PIN_TO_DIGITAL(p) (p)
769 #define PIN_TO_ANALOG(p) ((p) <= 25 ? ((p) - 14) : (p) - 36)
770 #define PIN_TO_PWM(p) (p)
771 #define PIN_TO_SERVO(p) (p)
775 #elif defined(_BOARD_MEGA_) && defined(__PIC32) // NOTE: no _BOARD_MAX32_ to use
776 #define TOTAL_ANALOG_PINS NUM_ANALOG_PINS // 16
777 #define TOTAL_PINS NUM_DIGITAL_PINS // 87
778 #define MAX_SERVOS NUM_DIGITAL_PINS
779 #define VERSION_BLINK_PIN PIN_LED1
780 #define IS_PIN_DIGITAL(p) ((p) >= 2)
781 #define IS_PIN_ANALOG(p) ((p) >= 54 && (p) <= 69)
782 #define IS_PIN_PWM(p) IS_PIN_DIGITAL(p)
783 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
784 #define IS_PIN_I2C(p) ((p) == 34 || (p) == 35)
785 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
786 #define PIN_TO_DIGITAL(p) (p)
787 #define PIN_TO_ANALOG(p) ((p) - 54)
788 #define PIN_TO_PWM(p) (p)
789 #define PIN_TO_SERVO(p) (p)
793 #elif defined(_BOARD_CHIPKIT_PI_)
794 #define TOTAL_ANALOG_PINS 16
795 #define TOTAL_PINS NUM_DIGITAL_PINS // 19
796 #define MAX_SERVOS NUM_DIGITAL_PINS
797 #define VERSION_BLINK_PIN PIN_LED1
798 #define IS_PIN_DIGITAL(p) (((p) >= 2) && ((p) <= 3) || (((p) >= 8) && ((p) <= 13)) || (((p) >= 14) && ((p) <= 17)))
799 #define IS_PIN_ANALOG(p) ((p) >= 14 && (p) <= 17)
800 #define IS_PIN_PWM(p) IS_PIN_DIGITAL(p)
801 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
802 #define IS_PIN_I2C(p) ((p) == 16 || (p) == 17)
803 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
804 #define PIN_TO_DIGITAL(p) (p)
805 #define PIN_TO_ANALOG(p) ((p) <= 15 ? (p) - 14 : (p) - 12)
807 #define PIN_TO_PWM(p) (p)
808 #define PIN_TO_SERVO(p) (p)
813 #elif defined(ARDUINO_PINOCCIO)
814 #define TOTAL_ANALOG_PINS 8
815 #define TOTAL_PINS NUM_DIGITAL_PINS // 32
816 #define VERSION_BLINK_PIN 23
817 #define PIN_SERIAL1_RX 13
818 #define PIN_SERIAL1_TX 14
819 #define IS_PIN_DIGITAL(p) (((p) >= 2) && ((p) <= 16)) || (((p) >= 24) && ((p) <= 31))
820 #define IS_PIN_ANALOG(p) ((p) >= 24 && (p) <= 31)
821 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
822 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
823 #define IS_PIN_I2C(p) ((p) == SCL || (p) == SDA)
824 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
825 #define IS_PIN_SERIAL(p) ((p) == 13 || (p) == 14)
826 #define PIN_TO_DIGITAL(p) (p)
827 #define PIN_TO_ANALOG(p) ((p) - 24)
828 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
829 #define PIN_TO_SERVO(p) ((p) - 2)
833 #elif defined(ESP8266)
834 #define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS
835 #define TOTAL_PINS A0 + NUM_ANALOG_INPUTS
836 #define PIN_SERIAL_RX 3
837 #define PIN_SERIAL_TX 1
838 #define IS_PIN_DIGITAL(p) (((p) >= 0 && (p) <= 5) || ((p) >= 12 && (p) < A0))
839 #define IS_PIN_ANALOG(p) ((p) >= A0 && (p) < A0 + NUM_ANALOG_INPUTS)
840 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
841 #define IS_PIN_SERVO(p) (IS_PIN_DIGITAL(p) && (p) < MAX_SERVOS)
842 #define IS_PIN_I2C(p) ((p) == SDA || (p) == SCL)
843 #define IS_PIN_SPI(p) ((p) == SS || (p) == MOSI || (p) == MISO || (p) == SCK)
844 #define IS_PIN_INTERRUPT(p) (digitalPinToInterrupt(p) > NOT_AN_INTERRUPT)
845 #define IS_PIN_SERIAL(p) ((p) == PIN_SERIAL_RX || (p) == PIN_SERIAL_TX)
846 #define PIN_TO_DIGITAL(p) (p)
847 #define PIN_TO_ANALOG(p) ((p) - A0)
848 #define PIN_TO_PWM(p) PIN_TO_DIGITAL(p)
849 #define PIN_TO_SERVO(p) (p)
850 #define DEFAULT_PWM_RESOLUTION 10
853 #elif defined(ARDUINO_ARCH_STM32)
854 #define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS
855 #define TOTAL_PINS NUM_DIGITAL_PINS
856 #define TOTAL_PORTS MAX_NB_PORT
857 #define VERSION_BLINK_PIN LED_BUILTIN
859 #define IS_PIN_DIGITAL(p) (digitalPinIsValid(p) && !pinIsSerial(p))
860 #define IS_PIN_ANALOG(p) ((p >= A0) && (p < (A0 + TOTAL_ANALOG_PINS)) && !pinIsSerial(p))
861 #define IS_PIN_PWM(p) (IS_PIN_DIGITAL(p) && digitalPinHasPWM(p))
862 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
863 #define IS_PIN_I2C(p) (IS_PIN_DIGITAL(p) && digitalPinHasI2C(p))
864 #define IS_PIN_SPI(p) (IS_PIN_DIGITAL(p) && digitalPinHasSPI(p))
865 #define IS_PIN_INTERRUPT(p) (IS_PIN_DIGITAL(p) && (digitalPinToInterrupt(p) > NOT_AN_INTERRUPT)))
866 #define IS_PIN_SERIAL(p) (digitalPinHasSerial(p) && !pinIsSerial(p))
867 #define PIN_TO_DIGITAL(p) (p)
868 #define PIN_TO_ANALOG(p) (p-A0)
869 #define PIN_TO_PWM(p) (p)
870 #define PIN_TO_SERVO(p) (p)
871 #define DEFAULT_PWM_RESOLUTION PWM_RESOLUTION
874 #elif defined(ARDUINO_NRF52_ADAFRUIT)
875 #define TOTAL_ANALOG_PINS NUM_ANALOG_INPUTS
876 #define TOTAL_PINS NUM_DIGITAL_PINS
877 #define VERSION_BLINK_PIN LED_BUILTIN
878 #define IS_PIN_DIGITAL(p) ((p) >= 2 && (p) < TOTAL_PINS)
879 #define IS_PIN_ANALOG(p) ((p) == PIN_A0 || (p) == PIN_A1 || (p) == PIN_A2 || (p) == PIN_A3 || \
880 (p) == PIN_A4 || (p) == PIN_A5 || (p) == PIN_A6 || (p) == PIN_A7)
881 #define IS_PIN_PWM(p) digitalPinHasPWM(p)
882 #define IS_PIN_SERVO(p) IS_PIN_DIGITAL(p)
883 #define IS_PIN_I2C(p) ((p) == PIN_WIRE_SDA || (p) == PIN_WIRE_SCL)
884 #define IS_PIN_SPI(p) ((p) == SS || (p)== MOSI || (p) == MISO || (p == SCK))
885 #define PIN_TO_DIGITAL(p) (p)
886 #define PIN_TO_ANALOG(p) ( ((p) == PIN_A0) ? 0 : ((p) == PIN_A1) ? 1 : ((p) == PIN_A2) ? 2 : ((p) == PIN_A3) ? 3 : \
887 ((p) == PIN_A4) ? 4 : ((p) == PIN_A5) ? 5 : ((p) == PIN_A6) ? 6 : ((p) == PIN_A7) ? 7 : (127))
888 #define PIN_TO_PWM(p) (p)
889 #define PIN_TO_SERVO(p) (p)
893 #error "Please edit Boards.h with a hardware abstraction for this board"
898 #define IS_PIN_SPI(p) 0
901 #ifndef IS_PIN_SERIAL
902 #define IS_PIN_SERIAL(p) 0
905 #ifndef DEFAULT_PWM_RESOLUTION
906 #define DEFAULT_PWM_RESOLUTION 8
913 static inline unsigned char readPort(
byte,
byte) __attribute__((always_inline, unused));
914 static inline unsigned char readPort(
byte port,
byte bitmask)
916 #if defined(ARDUINO_PINOUT_OPTIMIZE)
917 if (port == 0)
return (PIND & 0xFC) & bitmask;
918 if (port == 1)
return ((PINB & 0x3F) | ((PINC & 0x03) << 6)) & bitmask;
919 if (port == 2)
return ((PINC & 0x3C) >> 2) & bitmask;
922 unsigned char out = 0, pin = port * 8;
923 if (IS_PIN_DIGITAL(pin + 0) && (bitmask & 0x01) && digitalRead(PIN_TO_DIGITAL(pin + 0))) out |= 0x01;
924 if (IS_PIN_DIGITAL(pin + 1) && (bitmask & 0x02) && digitalRead(PIN_TO_DIGITAL(pin + 1))) out |= 0x02;
925 if (IS_PIN_DIGITAL(pin + 2) && (bitmask & 0x04) && digitalRead(PIN_TO_DIGITAL(pin + 2))) out |= 0x04;
926 if (IS_PIN_DIGITAL(pin + 3) && (bitmask & 0x08) && digitalRead(PIN_TO_DIGITAL(pin + 3))) out |= 0x08;
927 if (IS_PIN_DIGITAL(pin + 4) && (bitmask & 0x10) && digitalRead(PIN_TO_DIGITAL(pin + 4))) out |= 0x10;
928 if (IS_PIN_DIGITAL(pin + 5) && (bitmask & 0x20) && digitalRead(PIN_TO_DIGITAL(pin + 5))) out |= 0x20;
929 if (IS_PIN_DIGITAL(pin + 6) && (bitmask & 0x40) && digitalRead(PIN_TO_DIGITAL(pin + 6))) out |= 0x40;
930 if (IS_PIN_DIGITAL(pin + 7) && (bitmask & 0x80) && digitalRead(PIN_TO_DIGITAL(pin + 7))) out |= 0x80;
939 static inline unsigned char writePort(
byte,
byte,
byte) __attribute__((always_inline, unused));
940 static inline unsigned char writePort(
byte port,
byte value,
byte bitmask)
942 #if defined(ARDUINO_PINOUT_OPTIMIZE)
944 bitmask = bitmask & 0xFC;
945 byte valD = value & bitmask;
946 byte maskD = ~bitmask;
948 PORTD = (PORTD & maskD) | valD;
950 }
else if (port == 1) {
951 byte valB = (value & bitmask) & 0x3F;
952 byte valC = (value & bitmask) >> 6;
953 byte maskB = ~(bitmask & 0x3F);
954 byte maskC = ~((bitmask & 0xC0) >> 6);
956 PORTB = (PORTB & maskB) | valB;
957 PORTC = (PORTC & maskC) | valC;
959 }
else if (port == 2) {
960 bitmask = bitmask & 0x0F;
961 byte valC = (value & bitmask) << 2;
962 byte maskC = ~(bitmask << 2);
964 PORTC = (PORTC & maskC) | valC;
970 if ((bitmask & 0x01)) digitalWrite(PIN_TO_DIGITAL(pin + 0), (value & 0x01));
971 if ((bitmask & 0x02)) digitalWrite(PIN_TO_DIGITAL(pin + 1), (value & 0x02));
972 if ((bitmask & 0x04)) digitalWrite(PIN_TO_DIGITAL(pin + 2), (value & 0x04));
973 if ((bitmask & 0x08)) digitalWrite(PIN_TO_DIGITAL(pin + 3), (value & 0x08));
974 if ((bitmask & 0x10)) digitalWrite(PIN_TO_DIGITAL(pin + 4), (value & 0x10));
975 if ((bitmask & 0x20)) digitalWrite(PIN_TO_DIGITAL(pin + 5), (value & 0x20));
976 if ((bitmask & 0x40)) digitalWrite(PIN_TO_DIGITAL(pin + 6), (value & 0x40));
977 if ((bitmask & 0x80)) digitalWrite(PIN_TO_DIGITAL(pin + 7), (value & 0x80));
986 #define TOTAL_PORTS ((TOTAL_PINS + 7) / 8)