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
22 $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
26 #include <avr/pgmspace.h>
28 // Workaround for wrong definitions in "iom32u4.h".
29 // This should be fixed in the AVR toolchain.
91 #define NUM_DIGITAL_PINS 30
92 #define NUM_ANALOG_INPUTS 12
94 #define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0)
95 #define TXLED0 PORTD |= (1<<5)
96 #define TXLED1 PORTD &= ~(1<<5)
97 #define RXLED0 PORTB |= (1<<0)
98 #define RXLED1 PORTB &= ~(1<<0)
100 static const uint8_t SDA = 2;
101 static const uint8_t SCL = 3;
102 #define LED_BUILTIN 13
104 // Map SPI port to 'new' pins D14..D17
105 static const uint8_t SS = 17;
106 static const uint8_t MOSI = 16;
107 static const uint8_t MISO = 14;
108 static const uint8_t SCK = 15;
110 // Mapping of analog pins as digital I/O
111 // A6-A11 share with digital pins
112 static const uint8_t ADC0 = 18;
113 static const uint8_t ADC1 = 19;
114 static const uint8_t ADC2 = 20;
115 static const uint8_t ADC3 = 21;
116 static const uint8_t ADC4 = 22;
117 static const uint8_t ADC5 = 23;
118 static const uint8_t ADC6 = 24; // D4
119 static const uint8_t ADC7 = 25; // D6
120 static const uint8_t ADC8 = 26; // D8
121 static const uint8_t ADC9 = 27; // D9
122 static const uint8_t ADC10 = 28; // D10
123 static const uint8_t ADC11 = 29; // D12
125 #define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0))
126 #define digitalPinToPCICRbit(p) 0
127 #define digitalPinToPCMSK(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0))
128 #define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4))))))
130 // __AVR_ATmega32U4__ has an unusual mapping of pins to channels
131 extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
132 #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
134 #define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
138 // On the Arduino board, digital pins are also used
139 // for the analog output (software PWM). Analog input
140 // pins are a separate set.
142 // ATMEL ATMEGA32U4 / ARDUINO LEONARDO
146 // D2 PD1 SDA SDA/INT1
147 // D3# PD0 PWM8/SCL OC0B/SCL/INT0
149 // D5# PC6 ??? OC3A/#OC4A
150 // D6# A7 PD7 FastPWM #OC4D/ADC10
153 // D8 A8 PB4 ADC11/PCINT4
154 // D9# A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5
155 // D10# A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6
156 // D11# PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7
157 // D12 A11 PD6 T1/#OC4D/ADC9
158 // D13# PC7 PWM10 CLK0/OC4A
167 // New pins D14..D17 to map SPI port to digital pins
169 // MISO D14 PB3 MISO,PCINT3
170 // SCK D15 PB1 SCK,PCINT1
171 // MOSI D16 PB2 MOSI,PCINT2
172 // SS D17 PB0 RXLED,SS/PCINT0
174 // Connected LEDs on board for TX and RX
175 // TXLED D24 PD5 XCK1
179 // these arrays map port names (e.g. port B) to the
180 // appropriate addresses for various functions (e.g. reading
182 const uint16_t PROGMEM port_to_mode_PGM[] = {
192 const uint16_t PROGMEM port_to_output_PGM[] = {
202 const uint16_t PROGMEM port_to_input_PGM[] = {
212 const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
229 PB, // D14 - MISO - PB3
230 PB, // D15 - SCK - PB1
231 PB, // D16 - MOSI - PB2
232 PB, // D17 - SS - PB0
234 PF, // D18 - A0 - PF7
235 PF, // D19 - A1 - PF6
236 PF, // D20 - A2 - PF5
237 PF, // D21 - A3 - PF4
238 PF, // D22 - A4 - PF1
239 PF, // D23 - A5 - PF0
242 PD, // D25 / D6 - A7 - PD7
243 PB, // D26 / D8 - A8 - PB4
244 PB, // D27 / D9 - A9 - PB5
245 PB, // D28 / D10 - A10 - PB6
246 PD, // D29 / D12 - A11 - PD6
249 const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
266 _BV(3), // D14 - MISO - PB3
267 _BV(1), // D15 - SCK - PB1
268 _BV(2), // D16 - MOSI - PB2
269 _BV(0), // D17 - SS - PB0
271 _BV(7), // D18 - A0 - PF7
272 _BV(6), // D19 - A1 - PF6
273 _BV(5), // D20 - A2 - PF5
274 _BV(4), // D21 - A3 - PF4
275 _BV(1), // D22 - A4 - PF1
276 _BV(0), // D23 - A5 - PF0
279 _BV(7), // D25 / D6 - A7 - PD7
280 _BV(4), // D26 / D8 - A8 - PB4
281 _BV(5), // D27 / D9 - A9 - PB5
282 _BV(6), // D28 / D10 - A10 - PB6
283 _BV(6), // D29 / D12 - A11 - PD6
286 const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
323 const uint8_t PROGMEM analog_pin_to_channel_PGM[] = {
331 10, // A7 D6 PD7 ADC10
332 11, // A8 D8 PB4 ADC11
333 12, // A9 D9 PB5 ADC12
334 13, // A10 D10 PB6 ADC13
335 9 // A11 D12 PD6 ADC9
338 #endif /* ARDUINO_MAIN */
340 // These serial port names are intended to allow libraries and architecture-neutral
341 // sketches to automatically default to the correct port name for a particular type
342 // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
343 // the first hardware serial port whose RX/TX pins are not dedicated to another use.
345 // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
347 // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
349 // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
351 // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
353 // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
354 // pins are NOT connected to anything by default.
355 #define SERIAL_PORT_MONITOR Serial
356 #define SERIAL_PORT_USBVIRTUAL Serial
357 #define SERIAL_PORT_HARDWARE Serial1
358 #define SERIAL_PORT_HARDWARE_OPEN Serial1