2 pins_arduino.h - Pin definition functions for Arduino Robot Control Board
3 Part of Arduino - http://www.arduino.cc/
5 Copyright (c) 2913 D. Cuartielles, X. Yang (Arduino Verkstad)
6 Copyright (c) 2012 D. Cuartielles, N. de la Riva, I. Gallego, E. Gallego
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General
19 Public License along with this library; if not, write to the
20 Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 Boston, MA 02111-1307 USA
24 #ifndef Pins_Arduino_h
25 #define Pins_Arduino_h
27 #include <avr/pgmspace.h>
29 #define ARDUINO_MODEL_USB_PID 0x0039
31 #define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0)
32 #define TXLED0 PORTD |= (1<<5)
33 #define TXLED1 PORTD &= ~(1<<5)
34 #define RXLED0 PORTB |= (1<<0)
35 #define RXLED1 PORTB &= ~(1<<0)
42 #define PIN_SERIAL_RX (0)
43 #define PIN_SERIAL_TX (1)
45 static const uint8_t RX = PIN_SERIAL_RX;
46 static const uint8_t TX = PIN_SERIAL_TX;
48 #define PIN_WIRE_SDA (2)
49 #define PIN_WIRE_SCL (3)
51 static const uint8_t SDA = PIN_WIRE_SDA;
52 static const uint8_t SCL = PIN_WIRE_SCL;
54 // Map SPI port to 'new' pins D14..D17
55 #define PIN_SPI_SS (17)
56 #define PIN_SPI_MOSI (16)
57 #define PIN_SPI_MISO (14)
58 #define PIN_SPI_SCK (15)
60 static const uint8_t SS = PIN_SPI_SS;
61 static const uint8_t MOSI = PIN_SPI_MOSI;
62 static const uint8_t MISO = PIN_SPI_MISO;
63 static const uint8_t SCK = PIN_SPI_SCK;
65 // Mapping of analog pins as digital I/O
66 // A6-A11 share with digital pins
80 static const uint8_t A0 = PIN_A0;
81 static const uint8_t A1 = PIN_A1;
82 static const uint8_t A2 = PIN_A2;
83 static const uint8_t A3 = PIN_A3;
84 static const uint8_t A4 = PIN_A4;
85 static const uint8_t A5 = PIN_A5;
86 static const uint8_t A6 = PIN_A6; // D4
87 static const uint8_t A7 = PIN_A7; // D6
88 static const uint8_t A8 = PIN_A8; // D8
89 static const uint8_t A9 = PIN_A9; // D9
90 static const uint8_t A10 = PIN_A10; // D10
91 static const uint8_t A11 = PIN_A11; // D12
93 // Specific Mapping for the Motor Board
94 static const uint8_t MUX_IN = 20; // A2
95 static const uint8_t MUXA = 7; // D7
96 static const uint8_t MUXB = 8; // D8
97 static const uint8_t MUXC = 11; // D11
98 static const uint8_t MUXI = 13; // D13
99 static const uint8_t TRIM = 21; // A3
100 static const uint8_t SENSE_A = 22; // A4
101 static const uint8_t SENSE_B = 23; // A5
102 static const uint8_t IN_A1 = 6; // D6 - A7
103 static const uint8_t IN_A2 = 5; // D5
104 static const uint8_t IN_B1 = 10; // D10
105 static const uint8_t IN_B2 = 9; // D9
106 static const uint8_t TK1 = 18; // A0
107 static const uint8_t TK2 = 19; // A1
108 static const uint8_t TK3 = 4; // A6
109 static const uint8_t TK4 = 12; // A11
111 // __AVR_ATmega32U4__ has an unusual mapping of pins to channels
112 extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
113 #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
115 #define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
119 // On the Arduino board, digital pins are also used
120 // for the analog output (software PWM). Analog input
121 // pins are a separate set.
123 // ARDUINO LEONARDO / ARDUINO ROBOT CONTROL / ATMEGA 32U4 / FUNCTION / REGISTER
125 // D0 RX PD2 RX RXD1/INT2
126 // D1 TX PD3 TX TXD1/INT3
127 // D2 SDA PD1 SDA SDA/INT1
128 // D3# SCL PD0 PWM8/SCL OC0B/SCL/INT0
129 // D4 TK3 A6 PD4 ADC8
130 // D5# INA2 PC6 ??? OC3A/#OC4A
131 // D6# INA1 A7 PD7 FastPWM #OC4D/ADC10
132 // D7 MUXA PE6 INT6/AIN0
134 // D8 MUXB A8 PB4 ADC11/PCINT4
135 // D9# INB2 A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5
136 // D10# INB1 A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6
137 // D11# MUXC PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7
138 // D12 TK4 A11 PD6 T1/#OC4D/ADC9
139 // D13# MUXI PC7 PWM10 CLK0/OC4A
141 // A0 TK1 D18 PF7 ADC7
142 // A1 TK2 D19 PF6 ADC6
143 // A2 MUX_IN D20 PF5 ADC5
144 // A3 TRIM D21 PF4 ADC4
145 // A4 SENSE_A D22 PF1 ADC1
146 // A5 SENSE_B D23 PF0 ADC0
148 // MISO MISO D14 PB3 MISO,PCINT3
149 // SCK SCK D15 PB1 SCK,PCINT1
150 // MOSI MOSI D16 PB2 MOSI,PCINT2
151 // SS RX_LED D17 PB0 RXLED,SS/PCINT0
156 // these arrays map port names (e.g. port B) to the
157 // appropriate addresses for various functions (e.g. reading
159 const uint16_t PROGMEM port_to_mode_PGM[] = {
169 const uint16_t PROGMEM port_to_output_PGM[] = {
179 const uint16_t PROGMEM port_to_input_PGM[] = {
189 const uint8_t PROGMEM digital_pin_to_port_PGM[30] = {
206 PB, // D14 - MISO - PB3
207 PB, // D15 - SCK - PB1
208 PB, // D16 - MOSI - PB2
209 PB, // D17 - SS - PB0
211 PF, // D18 - A0 - PF7
212 PF, // D19 - A1 - PF6
213 PF, // D20 - A2 - PF5
214 PF, // D21 - A3 - PF4
215 PF, // D22 - A4 - PF1
216 PF, // D23 - A5 - PF0
218 PD, // D24 / D4 - A6 - PD4
219 PD, // D25 / D6 - A7 - PD7
220 PB, // D26 / D8 - A8 - PB4
221 PB, // D27 / D9 - A9 - PB5
222 PB, // D28 / D10 - A10 - PB6
223 PD, // D29 / D12 - A11 - PD6
226 const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[30] = {
243 _BV(3), // D14 - MISO - PB3
244 _BV(1), // D15 - SCK - PB1
245 _BV(2), // D16 - MOSI - PB2
246 _BV(0), // D17 - SS - PB0
248 _BV(7), // D18 - A0 - PF7
249 _BV(6), // D19 - A1 - PF6
250 _BV(5), // D20 - A2 - PF5
251 _BV(4), // D21 - A3 - PF4
252 _BV(1), // D22 - A4 - PF1
253 _BV(0), // D23 - A5 - PF0
255 _BV(4), // D24 / D4 - A6 - PD4
256 _BV(7), // D25 / D6 - A7 - PD7
257 _BV(4), // D26 / D8 - A8 - PB4
258 _BV(5), // D27 / D9 - A9 - PB5
259 _BV(6), // D28 / D10 - A10 - PB6
260 _BV(6), // D29 / D12 - A11 - PD6
263 const uint8_t PROGMEM digital_pin_to_timer_PGM[18] = {
285 const uint8_t PROGMEM analog_pin_to_channel_PGM[12] = {
293 10, // A7 D6 PD7 ADC10
294 11, // A8 D8 PB4 ADC11
295 12, // A9 D9 PB5 ADC12
296 13, // A10 D10 PB6 ADC13
297 9 // A11 D12 PD6 ADC9
300 #endif /* ARDUINO_MAIN */
302 // These serial port names are intended to allow libraries and architecture-neutral
303 // sketches to automatically default to the correct port name for a particular type
304 // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
305 // the first hardware serial port whose RX/TX pins are not dedicated to another use.
307 // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
309 // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
311 // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
313 // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
315 // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
316 // pins are NOT connected to anything by default.
317 #define SERIAL_PORT_MONITOR Serial
318 #define SERIAL_PORT_USBVIRTUAL Serial
319 #define SERIAL_PORT_HARDWARE Serial1
321 #endif /* Pins_Arduino_h */