2 pins_arduino.h - Pin definition functions for Arduino
3 Part of Arduino - http://www.arduino.cc/
5 Copyright (c) 2007 David A. Mellis
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General
18 Public License along with this library; if not, write to the
19 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 Boston, MA 02111-1307 USA
23 #ifndef Pins_Arduino_h
24 #define Pins_Arduino_h
26 #include <avr/pgmspace.h>
28 #define NUM_DIGITAL_PINS 70
29 #define NUM_ANALOG_INPUTS 16
30 #define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1)
31 #define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46))
33 #define PIN_SPI_SS (53)
34 #define PIN_SPI_MOSI (51)
35 #define PIN_SPI_MISO (50)
36 #define PIN_SPI_SCK (52)
38 static const uint8_t SS = PIN_SPI_SS;
39 static const uint8_t MOSI = PIN_SPI_MOSI;
40 static const uint8_t MISO = PIN_SPI_MISO;
41 static const uint8_t SCK = PIN_SPI_SCK;
43 #define PIN_WIRE_SDA (20)
44 #define PIN_WIRE_SCL (21)
46 static const uint8_t SDA = PIN_WIRE_SDA;
47 static const uint8_t SCL = PIN_WIRE_SCL;
49 #define LED_BUILTIN 13
68 static const uint8_t A0 = PIN_A0;
69 static const uint8_t A1 = PIN_A1;
70 static const uint8_t A2 = PIN_A2;
71 static const uint8_t A3 = PIN_A3;
72 static const uint8_t A4 = PIN_A4;
73 static const uint8_t A5 = PIN_A5;
74 static const uint8_t A6 = PIN_A6;
75 static const uint8_t A7 = PIN_A7;
76 static const uint8_t A8 = PIN_A8;
77 static const uint8_t A9 = PIN_A9;
78 static const uint8_t A10 = PIN_A10;
79 static const uint8_t A11 = PIN_A11;
80 static const uint8_t A12 = PIN_A12;
81 static const uint8_t A13 = PIN_A13;
82 static const uint8_t A14 = PIN_A14;
83 static const uint8_t A15 = PIN_A15;
85 // A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
86 // Only pins available for RECEIVE (TRANSMIT can be on any pin):
87 // (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
88 // Pins: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
90 #define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \
91 (((p) >= 50) && ((p) <= 53)) || \
92 (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
94 #define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
95 ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
98 #define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
99 ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
102 #define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
103 ( ((p) == 50) ? 3 : \
104 ( ((p) == 51) ? 2 : \
105 ( ((p) == 52) ? 1 : \
106 ( ((p) == 53) ? 0 : \
107 ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
110 #define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : ((p) >= 18 && (p) <= 21 ? 23 - (p) : NOT_AN_INTERRUPT)))
114 const uint16_t PROGMEM port_to_mode_PGM[] = {
130 const uint16_t PROGMEM port_to_output_PGM[] = {
146 const uint16_t PROGMEM port_to_input_PGM[] = {
162 const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
164 // -------------------------------------------
165 PE , // PE 0 ** 0 ** USART0_RX
166 PE , // PE 1 ** 1 ** USART0_TX
167 PE , // PE 4 ** 2 ** PWM2
168 PE , // PE 5 ** 3 ** PWM3
169 PG , // PG 5 ** 4 ** PWM4
170 PE , // PE 3 ** 5 ** PWM5
171 PH , // PH 3 ** 6 ** PWM6
172 PH , // PH 4 ** 7 ** PWM7
173 PH , // PH 5 ** 8 ** PWM8
174 PH , // PH 6 ** 9 ** PWM9
175 PB , // PB 4 ** 10 ** PWM10
176 PB , // PB 5 ** 11 ** PWM11
177 PB , // PB 6 ** 12 ** PWM12
178 PB , // PB 7 ** 13 ** PWM13
179 PJ , // PJ 1 ** 14 ** USART3_TX
180 PJ , // PJ 0 ** 15 ** USART3_RX
181 PH , // PH 1 ** 16 ** USART2_TX
182 PH , // PH 0 ** 17 ** USART2_RX
183 PD , // PD 3 ** 18 ** USART1_TX
184 PD , // PD 2 ** 19 ** USART1_RX
185 PD , // PD 1 ** 20 ** I2C_SDA
186 PD , // PD 0 ** 21 ** I2C_SCL
187 PA , // PA 0 ** 22 ** D22
188 PA , // PA 1 ** 23 ** D23
189 PA , // PA 2 ** 24 ** D24
190 PA , // PA 3 ** 25 ** D25
191 PA , // PA 4 ** 26 ** D26
192 PA , // PA 5 ** 27 ** D27
193 PA , // PA 6 ** 28 ** D28
194 PA , // PA 7 ** 29 ** D29
195 PC , // PC 7 ** 30 ** D30
196 PC , // PC 6 ** 31 ** D31
197 PC , // PC 5 ** 32 ** D32
198 PC , // PC 4 ** 33 ** D33
199 PC , // PC 3 ** 34 ** D34
200 PC , // PC 2 ** 35 ** D35
201 PC , // PC 1 ** 36 ** D36
202 PC , // PC 0 ** 37 ** D37
203 PD , // PD 7 ** 38 ** D38
204 PG , // PG 2 ** 39 ** D39
205 PG , // PG 1 ** 40 ** D40
206 PG , // PG 0 ** 41 ** D41
207 PL , // PL 7 ** 42 ** D42
208 PL , // PL 6 ** 43 ** D43
209 PL , // PL 5 ** 44 ** D44
210 PL , // PL 4 ** 45 ** D45
211 PL , // PL 3 ** 46 ** D46
212 PL , // PL 2 ** 47 ** D47
213 PL , // PL 1 ** 48 ** D48
214 PL , // PL 0 ** 49 ** D49
215 PB , // PB 3 ** 50 ** SPI_MISO
216 PB , // PB 2 ** 51 ** SPI_MOSI
217 PB , // PB 1 ** 52 ** SPI_SCK
218 PB , // PB 0 ** 53 ** SPI_SS
219 PF , // PF 0 ** 54 ** A0
220 PF , // PF 1 ** 55 ** A1
221 PF , // PF 2 ** 56 ** A2
222 PF , // PF 3 ** 57 ** A3
223 PF , // PF 4 ** 58 ** A4
224 PF , // PF 5 ** 59 ** A5
225 PF , // PF 6 ** 60 ** A6
226 PF , // PF 7 ** 61 ** A7
227 PK , // PK 0 ** 62 ** A8
228 PK , // PK 1 ** 63 ** A9
229 PK , // PK 2 ** 64 ** A10
230 PK , // PK 3 ** 65 ** A11
231 PK , // PK 4 ** 66 ** A12
232 PK , // PK 5 ** 67 ** A13
233 PK , // PK 6 ** 68 ** A14
234 PK , // PK 7 ** 69 ** A15
237 const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
239 // -------------------------------------------
240 _BV( 0 ) , // PE 0 ** 0 ** USART0_RX
241 _BV( 1 ) , // PE 1 ** 1 ** USART0_TX
242 _BV( 4 ) , // PE 4 ** 2 ** PWM2
243 _BV( 5 ) , // PE 5 ** 3 ** PWM3
244 _BV( 5 ) , // PG 5 ** 4 ** PWM4
245 _BV( 3 ) , // PE 3 ** 5 ** PWM5
246 _BV( 3 ) , // PH 3 ** 6 ** PWM6
247 _BV( 4 ) , // PH 4 ** 7 ** PWM7
248 _BV( 5 ) , // PH 5 ** 8 ** PWM8
249 _BV( 6 ) , // PH 6 ** 9 ** PWM9
250 _BV( 4 ) , // PB 4 ** 10 ** PWM10
251 _BV( 5 ) , // PB 5 ** 11 ** PWM11
252 _BV( 6 ) , // PB 6 ** 12 ** PWM12
253 _BV( 7 ) , // PB 7 ** 13 ** PWM13
254 _BV( 1 ) , // PJ 1 ** 14 ** USART3_TX
255 _BV( 0 ) , // PJ 0 ** 15 ** USART3_RX
256 _BV( 1 ) , // PH 1 ** 16 ** USART2_TX
257 _BV( 0 ) , // PH 0 ** 17 ** USART2_RX
258 _BV( 3 ) , // PD 3 ** 18 ** USART1_TX
259 _BV( 2 ) , // PD 2 ** 19 ** USART1_RX
260 _BV( 1 ) , // PD 1 ** 20 ** I2C_SDA
261 _BV( 0 ) , // PD 0 ** 21 ** I2C_SCL
262 _BV( 0 ) , // PA 0 ** 22 ** D22
263 _BV( 1 ) , // PA 1 ** 23 ** D23
264 _BV( 2 ) , // PA 2 ** 24 ** D24
265 _BV( 3 ) , // PA 3 ** 25 ** D25
266 _BV( 4 ) , // PA 4 ** 26 ** D26
267 _BV( 5 ) , // PA 5 ** 27 ** D27
268 _BV( 6 ) , // PA 6 ** 28 ** D28
269 _BV( 7 ) , // PA 7 ** 29 ** D29
270 _BV( 7 ) , // PC 7 ** 30 ** D30
271 _BV( 6 ) , // PC 6 ** 31 ** D31
272 _BV( 5 ) , // PC 5 ** 32 ** D32
273 _BV( 4 ) , // PC 4 ** 33 ** D33
274 _BV( 3 ) , // PC 3 ** 34 ** D34
275 _BV( 2 ) , // PC 2 ** 35 ** D35
276 _BV( 1 ) , // PC 1 ** 36 ** D36
277 _BV( 0 ) , // PC 0 ** 37 ** D37
278 _BV( 7 ) , // PD 7 ** 38 ** D38
279 _BV( 2 ) , // PG 2 ** 39 ** D39
280 _BV( 1 ) , // PG 1 ** 40 ** D40
281 _BV( 0 ) , // PG 0 ** 41 ** D41
282 _BV( 7 ) , // PL 7 ** 42 ** D42
283 _BV( 6 ) , // PL 6 ** 43 ** D43
284 _BV( 5 ) , // PL 5 ** 44 ** D44
285 _BV( 4 ) , // PL 4 ** 45 ** D45
286 _BV( 3 ) , // PL 3 ** 46 ** D46
287 _BV( 2 ) , // PL 2 ** 47 ** D47
288 _BV( 1 ) , // PL 1 ** 48 ** D48
289 _BV( 0 ) , // PL 0 ** 49 ** D49
290 _BV( 3 ) , // PB 3 ** 50 ** SPI_MISO
291 _BV( 2 ) , // PB 2 ** 51 ** SPI_MOSI
292 _BV( 1 ) , // PB 1 ** 52 ** SPI_SCK
293 _BV( 0 ) , // PB 0 ** 53 ** SPI_SS
294 _BV( 0 ) , // PF 0 ** 54 ** A0
295 _BV( 1 ) , // PF 1 ** 55 ** A1
296 _BV( 2 ) , // PF 2 ** 56 ** A2
297 _BV( 3 ) , // PF 3 ** 57 ** A3
298 _BV( 4 ) , // PF 4 ** 58 ** A4
299 _BV( 5 ) , // PF 5 ** 59 ** A5
300 _BV( 6 ) , // PF 6 ** 60 ** A6
301 _BV( 7 ) , // PF 7 ** 61 ** A7
302 _BV( 0 ) , // PK 0 ** 62 ** A8
303 _BV( 1 ) , // PK 1 ** 63 ** A9
304 _BV( 2 ) , // PK 2 ** 64 ** A10
305 _BV( 3 ) , // PK 3 ** 65 ** A11
306 _BV( 4 ) , // PK 4 ** 66 ** A12
307 _BV( 5 ) , // PK 5 ** 67 ** A13
308 _BV( 6 ) , // PK 6 ** 68 ** A14
309 _BV( 7 ) , // PK 7 ** 69 ** A15
312 const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
314 // -------------------------------------------
315 NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX
316 NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX
317 TIMER3B , // PE 4 ** 2 ** PWM2
318 TIMER3C , // PE 5 ** 3 ** PWM3
319 TIMER0B , // PG 5 ** 4 ** PWM4
320 TIMER3A , // PE 3 ** 5 ** PWM5
321 TIMER4A , // PH 3 ** 6 ** PWM6
322 TIMER4B , // PH 4 ** 7 ** PWM7
323 TIMER4C , // PH 5 ** 8 ** PWM8
324 TIMER2B , // PH 6 ** 9 ** PWM9
325 TIMER2A , // PB 4 ** 10 ** PWM10
326 TIMER1A , // PB 5 ** 11 ** PWM11
327 TIMER1B , // PB 6 ** 12 ** PWM12
328 TIMER0A , // PB 7 ** 13 ** PWM13
329 NOT_ON_TIMER , // PJ 1 ** 14 ** USART3_TX
330 NOT_ON_TIMER , // PJ 0 ** 15 ** USART3_RX
331 NOT_ON_TIMER , // PH 1 ** 16 ** USART2_TX
332 NOT_ON_TIMER , // PH 0 ** 17 ** USART2_RX
333 NOT_ON_TIMER , // PD 3 ** 18 ** USART1_TX
334 NOT_ON_TIMER , // PD 2 ** 19 ** USART1_RX
335 NOT_ON_TIMER , // PD 1 ** 20 ** I2C_SDA
336 NOT_ON_TIMER , // PD 0 ** 21 ** I2C_SCL
337 NOT_ON_TIMER , // PA 0 ** 22 ** D22
338 NOT_ON_TIMER , // PA 1 ** 23 ** D23
339 NOT_ON_TIMER , // PA 2 ** 24 ** D24
340 NOT_ON_TIMER , // PA 3 ** 25 ** D25
341 NOT_ON_TIMER , // PA 4 ** 26 ** D26
342 NOT_ON_TIMER , // PA 5 ** 27 ** D27
343 NOT_ON_TIMER , // PA 6 ** 28 ** D28
344 NOT_ON_TIMER , // PA 7 ** 29 ** D29
345 NOT_ON_TIMER , // PC 7 ** 30 ** D30
346 NOT_ON_TIMER , // PC 6 ** 31 ** D31
347 NOT_ON_TIMER , // PC 5 ** 32 ** D32
348 NOT_ON_TIMER , // PC 4 ** 33 ** D33
349 NOT_ON_TIMER , // PC 3 ** 34 ** D34
350 NOT_ON_TIMER , // PC 2 ** 35 ** D35
351 NOT_ON_TIMER , // PC 1 ** 36 ** D36
352 NOT_ON_TIMER , // PC 0 ** 37 ** D37
353 NOT_ON_TIMER , // PD 7 ** 38 ** D38
354 NOT_ON_TIMER , // PG 2 ** 39 ** D39
355 NOT_ON_TIMER , // PG 1 ** 40 ** D40
356 NOT_ON_TIMER , // PG 0 ** 41 ** D41
357 NOT_ON_TIMER , // PL 7 ** 42 ** D42
358 NOT_ON_TIMER , // PL 6 ** 43 ** D43
359 TIMER5C , // PL 5 ** 44 ** D44
360 TIMER5B , // PL 4 ** 45 ** D45
361 TIMER5A , // PL 3 ** 46 ** D46
362 NOT_ON_TIMER , // PL 2 ** 47 ** D47
363 NOT_ON_TIMER , // PL 1 ** 48 ** D48
364 NOT_ON_TIMER , // PL 0 ** 49 ** D49
365 NOT_ON_TIMER , // PB 3 ** 50 ** SPI_MISO
366 NOT_ON_TIMER , // PB 2 ** 51 ** SPI_MOSI
367 NOT_ON_TIMER , // PB 1 ** 52 ** SPI_SCK
368 NOT_ON_TIMER , // PB 0 ** 53 ** SPI_SS
369 NOT_ON_TIMER , // PF 0 ** 54 ** A0
370 NOT_ON_TIMER , // PF 1 ** 55 ** A1
371 NOT_ON_TIMER , // PF 2 ** 56 ** A2
372 NOT_ON_TIMER , // PF 3 ** 57 ** A3
373 NOT_ON_TIMER , // PF 4 ** 58 ** A4
374 NOT_ON_TIMER , // PF 5 ** 59 ** A5
375 NOT_ON_TIMER , // PF 6 ** 60 ** A6
376 NOT_ON_TIMER , // PF 7 ** 61 ** A7
377 NOT_ON_TIMER , // PK 0 ** 62 ** A8
378 NOT_ON_TIMER , // PK 1 ** 63 ** A9
379 NOT_ON_TIMER , // PK 2 ** 64 ** A10
380 NOT_ON_TIMER , // PK 3 ** 65 ** A11
381 NOT_ON_TIMER , // PK 4 ** 66 ** A12
382 NOT_ON_TIMER , // PK 5 ** 67 ** A13
383 NOT_ON_TIMER , // PK 6 ** 68 ** A14
384 NOT_ON_TIMER , // PK 7 ** 69 ** A15
389 // These serial port names are intended to allow libraries and architecture-neutral
390 // sketches to automatically default to the correct port name for a particular type
391 // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
392 // the first hardware serial port whose RX/TX pins are not dedicated to another use.
394 // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
396 // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
398 // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
400 // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
402 // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
403 // pins are NOT connected to anything by default.
404 #define SERIAL_PORT_MONITOR Serial
405 #define SERIAL_PORT_HARDWARE Serial
406 #define SERIAL_PORT_HARDWARE1 Serial1
407 #define SERIAL_PORT_HARDWARE2 Serial2
408 #define SERIAL_PORT_HARDWARE3 Serial3
409 #define SERIAL_PORT_HARDWARE_OPEN Serial1
410 #define SERIAL_PORT_HARDWARE_OPEN1 Serial2
411 #define SERIAL_PORT_HARDWARE_OPEN2 Serial3