Debian Codegraph @

variants/robot_control/pins_arduino.h

raw
1 /*
2 pins_arduino.h - Pin definition functions for Arduino Robot Control Board
3 Part of Arduino - http://www.arduino.cc/
4
5 Copyright (c) 2913 D. Cuartielles, X. Yang (Arduino Verkstad)
6 Copyright (c) 2012 D. Cuartielles, N. de la Riva, I. Gallego, E. Gallego
7
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.
12
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.
17
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
22 */
23
24 #ifndef Pins_Arduino_h
25 #define Pins_Arduino_h
26
27 #include <avr/pgmspace.h>
28
29 #define ARDUINO_MODEL_USB_PID 0x0038
30
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)
36
37 #define D0 TKD0
38 #define D1 TKD1
39 #define D2 TKD2
40 #define D3 TKD3
41 #define D4 TKD4
42 #define D5 TKD5
43
44 #define PIN_SERIAL_RX (0)
45 #define PIN_SERIAL_TX (1)
46
47 static const uint8_t RX = PIN_SERIAL_RX;
48 static const uint8_t TX = PIN_SERIAL_TX;
49
50 #define PIN_WIRE_SDA (2)
51 #define PIN_WIRE_SCL (3)
52
53 static const uint8_t SDA = PIN_WIRE_SDA;
54 static const uint8_t SCL = PIN_WIRE_SCL;
55
56 // Map SPI port to 'new' pins D14..D17
57 #define PIN_SPI_SS (17)
58 #define PIN_SPI_MOSI (16)
59 #define PIN_SPI_MISO (14)
60 #define PIN_SPI_SCK (15)
61
62 static const uint8_t SS = PIN_SPI_SS;
63 static const uint8_t MOSI = PIN_SPI_MOSI;
64 static const uint8_t MISO = PIN_SPI_MISO;
65 static const uint8_t SCK = PIN_SPI_SCK;
66
67 // Mapping of analog pins as digital I/O
68 // A6-A11 share with digital pins
69 #define PIN_A0 (18)
70 #define PIN_A1 (19)
71 #define PIN_A2 (20)
72 #define PIN_A3 (21)
73 #define PIN_A4 (22)
74 #define PIN_A5 (23)
75 #define PIN_A6 (24)
76 #define PIN_A7 (25)
77 #define PIN_A8 (26)
78 #define PIN_A9 (27)
79 #define PIN_A10 (28)
80 #define PIN_A11 (29)
81
82 static const uint8_t A0 = PIN_A0;
83 static const uint8_t A1 = PIN_A1;
84 static const uint8_t A2 = PIN_A2;
85 static const uint8_t A3 = PIN_A3;
86 static const uint8_t A4 = PIN_A4;
87 static const uint8_t A5 = PIN_A5;
88 static const uint8_t A6 = PIN_A6; // D4
89 static const uint8_t A7 = PIN_A7; // D6
90 static const uint8_t A8 = PIN_A8; // D8
91 static const uint8_t A9 = PIN_A9; // D9
92 static const uint8_t A10 = PIN_A10; // D10
93 static const uint8_t A11 = PIN_A11; // D12
94
95 // Specific Mapping for the Control Board
96 static const uint8_t KEY = 18; // AD0
97 static const uint8_t MUX_IN = 24; // ADC8 - A6
98 static const uint8_t MUXA = 6; // D5 - TKD4
99 static const uint8_t MUXB = 11; // D11
100 static const uint8_t MUXC = 12; // D12 - TKD5
101 static const uint8_t MUXD = 13; // D13
102 static const uint8_t BUZZ = 5; // D5
103 static const uint8_t POT = 23; // AD5
104 static const uint8_t DC_LCD = 10; // D10
105 static const uint8_t LCD_CS = 9; // D9
106 static const uint8_t RST_LCD = 7; // D6
107 static const uint8_t CARD_CS = 8; // D8
108 static const uint8_t TKD0 = 19; // ADC6 - A1
109 static const uint8_t TKD1 = 20; // ADC5 - A2
110 static const uint8_t TKD2 = 21; // ADC4 - A3
111 static const uint8_t TKD3 = 22; // ADC1 - A4
112 static const uint8_t TKD4 = 6; // D5 - MUXA
113 static const uint8_t TKD5 = 12; // D12 - MUXC
114 static const uint8_t LED1 = 17; // D17 - RX_Led
115
116 // __AVR_ATmega32U4__ has an unusual mapping of pins to channels
117 extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
118 #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
119
120 #define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
121
122 #ifdef ARDUINO_MAIN
123
124 // On the Arduino board, digital pins are also used
125 // for the analog output (software PWM). Analog input
126 // pins are a separate set.
127
128 // ARDUINO LEONARDO / ARDUINO ROBOT CONTROL / ATMEGA 32U4 / FUNCTION / REGISTER
129 //
130 // D0 RX PD2 RX RXD1/INT2
131 // D1 TX PD3 TX TXD1/INT3
132 // D2 SDA PD1 SDA SDA/INT1
133 // D3# SCL PD0 PWM8/SCL OC0B/SCL/INT0
134 // D4 MUX_IN A6 PD4 ADC8
135 // D5# BUZZ PC6 ??? OC3A/#OC4A
136 // D6# MUXA/TKD4 A7 PD7 FastPWM #OC4D/ADC10
137 // D7 RST_LCD PE6 INT6/AIN0
138 //
139 // D8 CARD_CS A8 PB4 ADC11/PCINT4
140 // D9# LCD_CS A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5
141 // D10# DC_LCD A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6
142 // D11# MUXB PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7
143 // D12 MUXC/TKD5 A11 PD6 T1/#OC4D/ADC9
144 // D13# MUXD PC7 PWM10 CLK0/OC4A
145 //
146 // A0 KEY D18 PF7 ADC7
147 // A1 TKD0 D19 PF6 ADC6
148 // A2 TKD1 D20 PF5 ADC5
149 // A3 TKD2 D21 PF4 ADC4
150 // A4 TKD3 D22 PF1 ADC1
151 // A5 POT D23 PF0 ADC0
152 //
153 // MISO MISO D14 PB3 MISO,PCINT3
154 // SCK SCK D15 PB1 SCK,PCINT1
155 // MOSI MOSI D16 PB2 MOSI,PCINT2
156 // SS RX_LED D17 PB0 RXLED,SS/PCINT0
157 //
158 // TXLED TX_LED PD5
159 // HWB PE2 HWB
160
161 // these arrays map port names (e.g. port B) to the
162 // appropriate addresses for various functions (e.g. reading
163 // and writing)
164 const uint16_t PROGMEM port_to_mode_PGM[] = {
165 NOT_A_PORT,
166 NOT_A_PORT,
167 (uint16_t) &DDRB,
168 (uint16_t) &DDRC,
169 (uint16_t) &DDRD,
170 (uint16_t) &DDRE,
171 (uint16_t) &DDRF,
172 };
173
174 const uint16_t PROGMEM port_to_output_PGM[] = {
175 NOT_A_PORT,
176 NOT_A_PORT,
177 (uint16_t) &PORTB,
178 (uint16_t) &PORTC,
179 (uint16_t) &PORTD,
180 (uint16_t) &PORTE,
181 (uint16_t) &PORTF,
182 };
183
184 const uint16_t PROGMEM port_to_input_PGM[] = {
185 NOT_A_PORT,
186 NOT_A_PORT,
187 (uint16_t) &PINB,
188 (uint16_t) &PINC,
189 (uint16_t) &PIND,
190 (uint16_t) &PINE,
191 (uint16_t) &PINF,
192 };
193
194 const uint8_t PROGMEM digital_pin_to_port_PGM[30] = {
195 PD, // D0 - PD2
196 PD, // D1 - PD3
197 PD, // D2 - PD1
198 PD, // D3 - PD0
199 PD, // D4 - PD4
200 PC, // D5 - PC6
201 PD, // D6 - PD7
202 PE, // D7 - PE6
203
204 PB, // D8 - PB4
205 PB, // D9 - PB5
206 PB, // D10 - PB6
207 PB, // D11 - PB7
208 PD, // D12 - PD6
209 PC, // D13 - PC7
210
211 PB, // D14 - MISO - PB3
212 PB, // D15 - SCK - PB1
213 PB, // D16 - MOSI - PB2
214 PB, // D17 - SS - PB0
215
216 PF, // D18 - A0 - PF7
217 PF, // D19 - A1 - PF6
218 PF, // D20 - A2 - PF5
219 PF, // D21 - A3 - PF4
220 PF, // D22 - A4 - PF1
221 PF, // D23 - A5 - PF0
222
223 PD, // D24 / D4 - A6 - PD4
224 PD, // D25 / D6 - A7 - PD7
225 PB, // D26 / D8 - A8 - PB4
226 PB, // D27 / D9 - A9 - PB5
227 PB, // D28 / D10 - A10 - PB6
228 PD, // D29 / D12 - A11 - PD6
229 };
230
231 const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[30] = {
232 _BV(2), // D0 - PD2
233 _BV(3), // D1 - PD3
234 _BV(1), // D2 - PD1
235 _BV(0), // D3 - PD0
236 _BV(4), // D4 - PD4
237 _BV(6), // D5 - PC6
238 _BV(7), // D6 - PD7
239 _BV(6), // D7 - PE6
240
241 _BV(4), // D8 - PB4
242 _BV(5), // D9 - PB5
243 _BV(6), // D10 - PB6
244 _BV(7), // D11 - PB7
245 _BV(6), // D12 - PD6
246 _BV(7), // D13 - PC7
247
248 _BV(3), // D14 - MISO - PB3
249 _BV(1), // D15 - SCK - PB1
250 _BV(2), // D16 - MOSI - PB2
251 _BV(0), // D17 - SS - PB0
252
253 _BV(7), // D18 - A0 - PF7
254 _BV(6), // D19 - A1 - PF6
255 _BV(5), // D20 - A2 - PF5
256 _BV(4), // D21 - A3 - PF4
257 _BV(1), // D22 - A4 - PF1
258 _BV(0), // D23 - A5 - PF0
259
260 _BV(4), // D24 / D4 - A6 - PD4
261 _BV(7), // D25 / D6 - A7 - PD7
262 _BV(4), // D26 / D8 - A8 - PB4
263 _BV(5), // D27 / D9 - A9 - PB5
264 _BV(6), // D28 / D10 - A10 - PB6
265 _BV(6), // D29 / D12 - A11 - PD6
266 };
267
268 const uint8_t PROGMEM digital_pin_to_timer_PGM[18] = {
269 NOT_ON_TIMER,
270 NOT_ON_TIMER,
271 NOT_ON_TIMER,
272 TIMER0B, /* 3 */
273 NOT_ON_TIMER,
274 TIMER3A, /* 5 */
275 TIMER4D, /* 6 */
276 NOT_ON_TIMER,
277
278 NOT_ON_TIMER,
279 TIMER1A, /* 9 */
280 TIMER1B, /* 10 */
281 TIMER0A, /* 11 */
282
283 NOT_ON_TIMER,
284 TIMER4A, /* 13 */
285
286 NOT_ON_TIMER,
287 NOT_ON_TIMER,
288 };
289
290 const uint8_t PROGMEM analog_pin_to_channel_PGM[12] = {
291 7, // A0 PF7 ADC7
292 6, // A1 PF6 ADC6
293 5, // A2 PF5 ADC5
294 4, // A3 PF4 ADC4
295 1, // A4 PF1 ADC1
296 0, // A5 PF0 ADC0
297 8, // A6 D4 PD4 ADC8
298 10, // A7 D6 PD7 ADC10
299 11, // A8 D8 PB4 ADC11
300 12, // A9 D9 PB5 ADC12
301 13, // A10 D10 PB6 ADC13
302 9 // A11 D12 PD6 ADC9
303 };
304
305 #endif /* ARDUINO_MAIN */
306
307 // These serial port names are intended to allow libraries and architecture-neutral
308 // sketches to automatically default to the correct port name for a particular type
309 // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
310 // the first hardware serial port whose RX/TX pins are not dedicated to another use.
311 //
312 // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
313 //
314 // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
315 //
316 // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
317 //
318 // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
319 //
320 // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
321 // pins are NOT connected to anything by default.
322 #define SERIAL_PORT_MONITOR Serial
323 #define SERIAL_PORT_USBVIRTUAL Serial
324 #define SERIAL_PORT_HARDWARE Serial1
325
326 #endif /* Pins_Arduino_h */