Debian Codegraph @

variants/leonardo/pins_arduino.h

raw
1 /*
2 pins_arduino.h - Pin definition functions for Arduino
3 Part of Arduino - http://www.arduino.cc/
4
5 Copyright (c) 2007 David A. Mellis
6
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.
11
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.
16
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
21 */
22
23 #ifndef Pins_Arduino_h
24 #define Pins_Arduino_h
25
26 #include <avr/pgmspace.h>
27
28 // Workaround for wrong definitions in "iom32u4.h".
29 // This should be fixed in the AVR toolchain.
30 #undef UHCON
31 #undef UHINT
32 #undef UHIEN
33 #undef UHADDR
34 #undef UHFNUM
35 #undef UHFNUML
36 #undef UHFNUMH
37 #undef UHFLEN
38 #undef UPINRQX
39 #undef UPINTX
40 #undef UPNUM
41 #undef UPRST
42 #undef UPCONX
43 #undef UPCFG0X
44 #undef UPCFG1X
45 #undef UPSTAX
46 #undef UPCFG2X
47 #undef UPIENX
48 #undef UPDATX
49 #undef TCCR2A
50 #undef WGM20
51 #undef WGM21
52 #undef COM2B0
53 #undef COM2B1
54 #undef COM2A0
55 #undef COM2A1
56 #undef TCCR2B
57 #undef CS20
58 #undef CS21
59 #undef CS22
60 #undef WGM22
61 #undef FOC2B
62 #undef FOC2A
63 #undef TCNT2
64 #undef TCNT2_0
65 #undef TCNT2_1
66 #undef TCNT2_2
67 #undef TCNT2_3
68 #undef TCNT2_4
69 #undef TCNT2_5
70 #undef TCNT2_6
71 #undef TCNT2_7
72 #undef OCR2A
73 #undef OCR2_0
74 #undef OCR2_1
75 #undef OCR2_2
76 #undef OCR2_3
77 #undef OCR2_4
78 #undef OCR2_5
79 #undef OCR2_6
80 #undef OCR2_7
81 #undef OCR2B
82 #undef OCR2_0
83 #undef OCR2_1
84 #undef OCR2_2
85 #undef OCR2_3
86 #undef OCR2_4
87 #undef OCR2_5
88 #undef OCR2_6
89 #undef OCR2_7
90
91 #define NUM_DIGITAL_PINS 31
92 #define NUM_ANALOG_INPUTS 12
93
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)
99
100 #define PIN_WIRE_SDA (2)
101 #define PIN_WIRE_SCL (3)
102
103 static const uint8_t SDA = PIN_WIRE_SDA;
104 static const uint8_t SCL = PIN_WIRE_SCL;
105
106 #define LED_BUILTIN 13
107 #define LED_BUILTIN_RX 17
108 #define LED_BUILTIN_TX 30
109
110 // Map SPI port to 'new' pins D14..D17
111 #define PIN_SPI_SS (17)
112 #define PIN_SPI_MOSI (16)
113 #define PIN_SPI_MISO (14)
114 #define PIN_SPI_SCK (15)
115
116 static const uint8_t SS = PIN_SPI_SS;
117 static const uint8_t MOSI = PIN_SPI_MOSI;
118 static const uint8_t MISO = PIN_SPI_MISO;
119 static const uint8_t SCK = PIN_SPI_SCK;
120
121 // Mapping of analog pins as digital I/O
122 // A6-A11 share with digital pins
123 #define PIN_A0 (18)
124 #define PIN_A1 (19)
125 #define PIN_A2 (20)
126 #define PIN_A3 (21)
127 #define PIN_A4 (22)
128 #define PIN_A5 (23)
129 #define PIN_A6 (24)
130 #define PIN_A7 (25)
131 #define PIN_A8 (26)
132 #define PIN_A9 (27)
133 #define PIN_A10 (28)
134 #define PIN_A11 (29)
135
136 static const uint8_t A0 = PIN_A0;
137 static const uint8_t A1 = PIN_A1;
138 static const uint8_t A2 = PIN_A2;
139 static const uint8_t A3 = PIN_A3;
140 static const uint8_t A4 = PIN_A4;
141 static const uint8_t A5 = PIN_A5;
142 static const uint8_t A6 = PIN_A6; // D4
143 static const uint8_t A7 = PIN_A7; // D6
144 static const uint8_t A8 = PIN_A8; // D8
145 static const uint8_t A9 = PIN_A9; // D9
146 static const uint8_t A10 = PIN_A10; // D10
147 static const uint8_t A11 = PIN_A11; // D12
148
149 #define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0))
150 #define digitalPinToPCICRbit(p) 0
151 #define digitalPinToPCMSK(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0))
152 #define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4))))))
153
154 // __AVR_ATmega32U4__ has an unusual mapping of pins to channels
155 extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
156 #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
157
158 #define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11 || (p) == 13)
159
160 #define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
161
162 #ifdef ARDUINO_MAIN
163
164 // On the Arduino board, digital pins are also used
165 // for the analog output (software PWM). Analog input
166 // pins are a separate set.
167
168 // ATMEL ATMEGA32U4 / ARDUINO LEONARDO
169 //
170 // D0 PD2 RXD1/INT2
171 // D1 PD3 TXD1/INT3
172 // D2 PD1 SDA SDA/INT1
173 // D3# PD0 PWM8/SCL OC0B/SCL/INT0
174 // D4 A6 PD4 ADC8
175 // D5# PC6 ??? OC3A/#OC4A
176 // D6# A7 PD7 FastPWM #OC4D/ADC10
177 // D7 PE6 INT6/AIN0
178 //
179 // D8 A8 PB4 ADC11/PCINT4
180 // D9# A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5
181 // D10# A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6
182 // D11# PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7
183 // D12 A11 PD6 T1/#OC4D/ADC9
184 // D13# PC7 PWM10 CLK0/OC4A
185 //
186 // A0 D18 PF7 ADC7
187 // A1 D19 PF6 ADC6
188 // A2 D20 PF5 ADC5
189 // A3 D21 PF4 ADC4
190 // A4 D22 PF1 ADC1
191 // A5 D23 PF0 ADC0
192 //
193 // New pins D14..D17 to map SPI port to digital pins
194 //
195 // MISO D14 PB3 MISO,PCINT3
196 // SCK D15 PB1 SCK,PCINT1
197 // MOSI D16 PB2 MOSI,PCINT2
198 // SS D17 PB0 RXLED,SS/PCINT0
199 //
200 // TXLED D30 PD5 XCK1
201 // RXLED D17 PB0
202 // HWB PE2 HWB
203
204 // these arrays map port names (e.g. port B) to the
205 // appropriate addresses for various functions (e.g. reading
206 // and writing)
207 const uint16_t PROGMEM port_to_mode_PGM[] = {
208 NOT_A_PORT,
209 NOT_A_PORT,
210 (uint16_t) &DDRB,
211 (uint16_t) &DDRC,
212 (uint16_t) &DDRD,
213 (uint16_t) &DDRE,
214 (uint16_t) &DDRF,
215 };
216
217 const uint16_t PROGMEM port_to_output_PGM[] = {
218 NOT_A_PORT,
219 NOT_A_PORT,
220 (uint16_t) &PORTB,
221 (uint16_t) &PORTC,
222 (uint16_t) &PORTD,
223 (uint16_t) &PORTE,
224 (uint16_t) &PORTF,
225 };
226
227 const uint16_t PROGMEM port_to_input_PGM[] = {
228 NOT_A_PORT,
229 NOT_A_PORT,
230 (uint16_t) &PINB,
231 (uint16_t) &PINC,
232 (uint16_t) &PIND,
233 (uint16_t) &PINE,
234 (uint16_t) &PINF,
235 };
236
237 const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
238 PD, // D0 - PD2
239 PD, // D1 - PD3
240 PD, // D2 - PD1
241 PD, // D3 - PD0
242 PD, // D4 - PD4
243 PC, // D5 - PC6
244 PD, // D6 - PD7
245 PE, // D7 - PE6
246
247 PB, // D8 - PB4
248 PB, // D9 - PB5
249 PB, // D10 - PB6
250 PB, // D11 - PB7
251 PD, // D12 - PD6
252 PC, // D13 - PC7
253
254 PB, // D14 - MISO - PB3
255 PB, // D15 - SCK - PB1
256 PB, // D16 - MOSI - PB2
257 PB, // D17 - SS - PB0
258
259 PF, // D18 - A0 - PF7
260 PF, // D19 - A1 - PF6
261 PF, // D20 - A2 - PF5
262 PF, // D21 - A3 - PF4
263 PF, // D22 - A4 - PF1
264 PF, // D23 - A5 - PF0
265
266 PD, // D24 / D4 - A6 - PD4
267 PD, // D25 / D6 - A7 - PD7
268 PB, // D26 / D8 - A8 - PB4
269 PB, // D27 / D9 - A9 - PB5
270 PB, // D28 / D10 - A10 - PB6
271 PD, // D29 / D12 - A11 - PD6
272 PD, // D30 / TX Led - PD5
273 };
274
275 const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
276 _BV(2), // D0 - PD2
277 _BV(3), // D1 - PD3
278 _BV(1), // D2 - PD1
279 _BV(0), // D3 - PD0
280 _BV(4), // D4 - PD4
281 _BV(6), // D5 - PC6
282 _BV(7), // D6 - PD7
283 _BV(6), // D7 - PE6
284
285 _BV(4), // D8 - PB4
286 _BV(5), // D9 - PB5
287 _BV(6), // D10 - PB6
288 _BV(7), // D11 - PB7
289 _BV(6), // D12 - PD6
290 _BV(7), // D13 - PC7
291
292 _BV(3), // D14 - MISO - PB3
293 _BV(1), // D15 - SCK - PB1
294 _BV(2), // D16 - MOSI - PB2
295 _BV(0), // D17 - SS - PB0
296
297 _BV(7), // D18 - A0 - PF7
298 _BV(6), // D19 - A1 - PF6
299 _BV(5), // D20 - A2 - PF5
300 _BV(4), // D21 - A3 - PF4
301 _BV(1), // D22 - A4 - PF1
302 _BV(0), // D23 - A5 - PF0
303
304 _BV(4), // D24 / D4 - A6 - PD4
305 _BV(7), // D25 / D6 - A7 - PD7
306 _BV(4), // D26 / D8 - A8 - PB4
307 _BV(5), // D27 / D9 - A9 - PB5
308 _BV(6), // D28 / D10 - A10 - PB6
309 _BV(6), // D29 / D12 - A11 - PD6
310 _BV(5), // D30 / TX Led - PD5
311 };
312
313 const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
314 NOT_ON_TIMER,
315 NOT_ON_TIMER,
316 NOT_ON_TIMER,
317 TIMER0B, /* 3 */
318 NOT_ON_TIMER,
319 TIMER3A, /* 5 */
320 TIMER4D, /* 6 */
321 NOT_ON_TIMER,
322
323 NOT_ON_TIMER,
324 TIMER1A, /* 9 */
325 TIMER1B, /* 10 */
326 TIMER0A, /* 11 */
327
328 NOT_ON_TIMER,
329 TIMER4A, /* 13 */
330
331 NOT_ON_TIMER,
332 NOT_ON_TIMER,
333 NOT_ON_TIMER,
334 NOT_ON_TIMER,
335 NOT_ON_TIMER,
336 NOT_ON_TIMER,
337
338 NOT_ON_TIMER,
339 NOT_ON_TIMER,
340 NOT_ON_TIMER,
341 NOT_ON_TIMER,
342 NOT_ON_TIMER,
343 NOT_ON_TIMER,
344 NOT_ON_TIMER,
345 NOT_ON_TIMER,
346 NOT_ON_TIMER,
347 NOT_ON_TIMER,
348 NOT_ON_TIMER,
349 };
350
351 const uint8_t PROGMEM analog_pin_to_channel_PGM[] = {
352 7, // A0 PF7 ADC7
353 6, // A1 PF6 ADC6
354 5, // A2 PF5 ADC5
355 4, // A3 PF4 ADC4
356 1, // A4 PF1 ADC1
357 0, // A5 PF0 ADC0
358 8, // A6 D4 PD4 ADC8
359 10, // A7 D6 PD7 ADC10
360 11, // A8 D8 PB4 ADC11
361 12, // A9 D9 PB5 ADC12
362 13, // A10 D10 PB6 ADC13
363 9 // A11 D12 PD6 ADC9
364 };
365
366 #endif /* ARDUINO_MAIN */
367
368 // These serial port names are intended to allow libraries and architecture-neutral
369 // sketches to automatically default to the correct port name for a particular type
370 // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
371 // the first hardware serial port whose RX/TX pins are not dedicated to another use.
372 //
373 // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
374 //
375 // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
376 //
377 // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
378 //
379 // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
380 //
381 // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
382 // pins are NOT connected to anything by default.
383 #define SERIAL_PORT_MONITOR Serial
384 #define SERIAL_PORT_USBVIRTUAL Serial
385 #define SERIAL_PORT_HARDWARE Serial1
386 #define SERIAL_PORT_HARDWARE_OPEN Serial1
387
388 // Alias SerialUSB to Serial
389 #define SerialUSB SERIAL_PORT_USBVIRTUAL
390
391 #endif /* Pins_Arduino_h */