Debian Codegraph @

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