]> git.piffa.net Git - arduino/blob - books/pdummies/Libraries/SD/utility/Sd2PinMap.h
first commit
[arduino] / books / pdummies / Libraries / SD / utility / Sd2PinMap.h
1 /* Arduino SdFat Library
2  * Copyright (C) 2010 by William Greiman
3  *
4  * This file is part of the Arduino SdFat Library
5  *
6  * This Library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This Library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with the Arduino SdFat Library.  If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 // Warning this file was generated by a program.
21 #ifndef Sd2PinMap_h
22 #define Sd2PinMap_h
23 #include <avr/io.h>
24
25 #if (ARDUINO >= 100)
26 #include "Arduino.h"
27 #endif
28
29 //------------------------------------------------------------------------------
30 /** struct for mapping digital pins */
31 struct pin_map_t {
32   volatile uint8_t* ddr;
33   volatile uint8_t* pin;
34   volatile uint8_t* port;
35   uint8_t bit;
36 };
37 //------------------------------------------------------------------------------
38 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
39 // Mega
40
41 // Two Wire (aka I2C) ports
42 uint8_t const SDA_PIN = 20;
43 uint8_t const SCL_PIN = 21;
44
45 // SPI port
46 uint8_t const SS_PIN = 53;
47 uint8_t const MOSI_PIN = 51;
48 uint8_t const MISO_PIN = 50;
49 uint8_t const SCK_PIN = 52;
50
51 static const pin_map_t digitalPinMap[] = {
52   {&DDRE, &PINE, &PORTE, 0},  // E0  0
53   {&DDRE, &PINE, &PORTE, 1},  // E1  1
54   {&DDRE, &PINE, &PORTE, 4},  // E4  2
55   {&DDRE, &PINE, &PORTE, 5},  // E5  3
56   {&DDRG, &PING, &PORTG, 5},  // G5  4
57   {&DDRE, &PINE, &PORTE, 3},  // E3  5
58   {&DDRH, &PINH, &PORTH, 3},  // H3  6
59   {&DDRH, &PINH, &PORTH, 4},  // H4  7
60   {&DDRH, &PINH, &PORTH, 5},  // H5  8
61   {&DDRH, &PINH, &PORTH, 6},  // H6  9
62   {&DDRB, &PINB, &PORTB, 4},  // B4 10
63   {&DDRB, &PINB, &PORTB, 5},  // B5 11
64   {&DDRB, &PINB, &PORTB, 6},  // B6 12
65   {&DDRB, &PINB, &PORTB, 7},  // B7 13
66   {&DDRJ, &PINJ, &PORTJ, 1},  // J1 14
67   {&DDRJ, &PINJ, &PORTJ, 0},  // J0 15
68   {&DDRH, &PINH, &PORTH, 1},  // H1 16
69   {&DDRH, &PINH, &PORTH, 0},  // H0 17
70   {&DDRD, &PIND, &PORTD, 3},  // D3 18
71   {&DDRD, &PIND, &PORTD, 2},  // D2 19
72   {&DDRD, &PIND, &PORTD, 1},  // D1 20
73   {&DDRD, &PIND, &PORTD, 0},  // D0 21
74   {&DDRA, &PINA, &PORTA, 0},  // A0 22
75   {&DDRA, &PINA, &PORTA, 1},  // A1 23
76   {&DDRA, &PINA, &PORTA, 2},  // A2 24
77   {&DDRA, &PINA, &PORTA, 3},  // A3 25
78   {&DDRA, &PINA, &PORTA, 4},  // A4 26
79   {&DDRA, &PINA, &PORTA, 5},  // A5 27
80   {&DDRA, &PINA, &PORTA, 6},  // A6 28
81   {&DDRA, &PINA, &PORTA, 7},  // A7 29
82   {&DDRC, &PINC, &PORTC, 7},  // C7 30
83   {&DDRC, &PINC, &PORTC, 6},  // C6 31
84   {&DDRC, &PINC, &PORTC, 5},  // C5 32
85   {&DDRC, &PINC, &PORTC, 4},  // C4 33
86   {&DDRC, &PINC, &PORTC, 3},  // C3 34
87   {&DDRC, &PINC, &PORTC, 2},  // C2 35
88   {&DDRC, &PINC, &PORTC, 1},  // C1 36
89   {&DDRC, &PINC, &PORTC, 0},  // C0 37
90   {&DDRD, &PIND, &PORTD, 7},  // D7 38
91   {&DDRG, &PING, &PORTG, 2},  // G2 39
92   {&DDRG, &PING, &PORTG, 1},  // G1 40
93   {&DDRG, &PING, &PORTG, 0},  // G0 41
94   {&DDRL, &PINL, &PORTL, 7},  // L7 42
95   {&DDRL, &PINL, &PORTL, 6},  // L6 43
96   {&DDRL, &PINL, &PORTL, 5},  // L5 44
97   {&DDRL, &PINL, &PORTL, 4},  // L4 45
98   {&DDRL, &PINL, &PORTL, 3},  // L3 46
99   {&DDRL, &PINL, &PORTL, 2},  // L2 47
100   {&DDRL, &PINL, &PORTL, 1},  // L1 48
101   {&DDRL, &PINL, &PORTL, 0},  // L0 49
102   {&DDRB, &PINB, &PORTB, 3},  // B3 50
103   {&DDRB, &PINB, &PORTB, 2},  // B2 51
104   {&DDRB, &PINB, &PORTB, 1},  // B1 52
105   {&DDRB, &PINB, &PORTB, 0},  // B0 53
106   {&DDRF, &PINF, &PORTF, 0},  // F0 54
107   {&DDRF, &PINF, &PORTF, 1},  // F1 55
108   {&DDRF, &PINF, &PORTF, 2},  // F2 56
109   {&DDRF, &PINF, &PORTF, 3},  // F3 57
110   {&DDRF, &PINF, &PORTF, 4},  // F4 58
111   {&DDRF, &PINF, &PORTF, 5},  // F5 59
112   {&DDRF, &PINF, &PORTF, 6},  // F6 60
113   {&DDRF, &PINF, &PORTF, 7},  // F7 61
114   {&DDRK, &PINK, &PORTK, 0},  // K0 62
115   {&DDRK, &PINK, &PORTK, 1},  // K1 63
116   {&DDRK, &PINK, &PORTK, 2},  // K2 64
117   {&DDRK, &PINK, &PORTK, 3},  // K3 65
118   {&DDRK, &PINK, &PORTK, 4},  // K4 66
119   {&DDRK, &PINK, &PORTK, 5},  // K5 67
120   {&DDRK, &PINK, &PORTK, 6},  // K6 68
121   {&DDRK, &PINK, &PORTK, 7}   // K7 69
122 };
123 //------------------------------------------------------------------------------
124 #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
125 // Sanguino
126
127 // Two Wire (aka I2C) ports
128 uint8_t const SDA_PIN = 17;
129 uint8_t const SCL_PIN = 18;
130
131 // SPI port
132 uint8_t const SS_PIN = 4;
133 uint8_t const MOSI_PIN = 5;
134 uint8_t const MISO_PIN = 6;
135 uint8_t const SCK_PIN = 7;
136
137 static const pin_map_t digitalPinMap[] = {
138   {&DDRB, &PINB, &PORTB, 0},  // B0  0
139   {&DDRB, &PINB, &PORTB, 1},  // B1  1
140   {&DDRB, &PINB, &PORTB, 2},  // B2  2
141   {&DDRB, &PINB, &PORTB, 3},  // B3  3
142   {&DDRB, &PINB, &PORTB, 4},  // B4  4
143   {&DDRB, &PINB, &PORTB, 5},  // B5  5
144   {&DDRB, &PINB, &PORTB, 6},  // B6  6
145   {&DDRB, &PINB, &PORTB, 7},  // B7  7
146   {&DDRD, &PIND, &PORTD, 0},  // D0  8
147   {&DDRD, &PIND, &PORTD, 1},  // D1  9
148   {&DDRD, &PIND, &PORTD, 2},  // D2 10
149   {&DDRD, &PIND, &PORTD, 3},  // D3 11
150   {&DDRD, &PIND, &PORTD, 4},  // D4 12
151   {&DDRD, &PIND, &PORTD, 5},  // D5 13
152   {&DDRD, &PIND, &PORTD, 6},  // D6 14
153   {&DDRD, &PIND, &PORTD, 7},  // D7 15
154   {&DDRC, &PINC, &PORTC, 0},  // C0 16
155   {&DDRC, &PINC, &PORTC, 1},  // C1 17
156   {&DDRC, &PINC, &PORTC, 2},  // C2 18
157   {&DDRC, &PINC, &PORTC, 3},  // C3 19
158   {&DDRC, &PINC, &PORTC, 4},  // C4 20
159   {&DDRC, &PINC, &PORTC, 5},  // C5 21
160   {&DDRC, &PINC, &PORTC, 6},  // C6 22
161   {&DDRC, &PINC, &PORTC, 7},  // C7 23
162   {&DDRA, &PINA, &PORTA, 7},  // A7 24
163   {&DDRA, &PINA, &PORTA, 6},  // A6 25
164   {&DDRA, &PINA, &PORTA, 5},  // A5 26
165   {&DDRA, &PINA, &PORTA, 4},  // A4 27
166   {&DDRA, &PINA, &PORTA, 3},  // A3 28
167   {&DDRA, &PINA, &PORTA, 2},  // A2 29
168   {&DDRA, &PINA, &PORTA, 1},  // A1 30
169   {&DDRA, &PINA, &PORTA, 0}   // A0 31
170 };
171 //------------------------------------------------------------------------------
172 #elif defined(__AVR_ATmega32U4__)
173 // XXXXTeensy 2.0XXXX - this is not going to be the teensy pinout anymore!
174 // because we need to give priority to the leonardo 
175
176 // Two Wire (aka I2C) ports
177 uint8_t const SDA_PIN = 2;
178 uint8_t const SCL_PIN = 3;
179
180 // SPI port
181 uint8_t const SS_PIN = SS;
182 uint8_t const MOSI_PIN = MOSI;
183 uint8_t const MISO_PIN = MISO;
184 uint8_t const SCK_PIN = SCK;
185
186 static const pin_map_t digitalPinMap[] = {
187   {&DDRD, &PIND, &PORTD, 2},  // D2  0
188   {&DDRD, &PIND, &PORTD, 3},  // D3  1
189   {&DDRD, &PIND, &PORTD, 1},  // D1  2
190   {&DDRD, &PIND, &PORTD, 0},  // D0  3
191   {&DDRD, &PIND, &PORTD, 4},  // D4  4
192   {&DDRC, &PINC, &PORTC, 6},  // C6  5
193   {&DDRD, &PIND, &PORTD, 7},  // D7  6
194   {&DDRE, &PINE, &PORTE, 6},  // E6  7
195   {&DDRB, &PINB, &PORTB, 4},  // B4  8
196   {&DDRB, &PINB, &PORTB, 5},  // B5  9
197   {&DDRB, &PINB, &PORTB, 6},  // B6 10
198   {&DDRB, &PINB, &PORTB, 7},  // B7 11
199   {&DDRD, &PIND, &PORTD, 6},  // D6 12
200   {&DDRC, &PINC, &PORTC, 7},  // C7 13
201   /*
202   {&DDRB, &PINB, &PORTB, 5},  // B5 14
203   {&DDRB, &PINB, &PORTB, 6},  // B6 15
204   {&DDRF, &PINF, &PORTF, 7},  // F7 16
205   {&DDRF, &PINF, &PORTF, 6},  // F6 17
206   {&DDRF, &PINF, &PORTF, 5},  // F5 18
207   {&DDRF, &PINF, &PORTF, 4},  // F4 19
208   {&DDRF, &PINF, &PORTF, 1},  // F1 20
209   {&DDRF, &PINF, &PORTF, 0},  // F0 21
210   {&DDRD, &PIND, &PORTD, 4},  // D4 22
211   {&DDRD, &PIND, &PORTD, 5},  // D5 23
212   {&DDRE, &PINE, &PORTE, 6}   // E6 24
213   */
214 };
215 //------------------------------------------------------------------------------
216 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
217 // Teensy++ 1.0 & 2.0
218
219 // Two Wire (aka I2C) ports
220 uint8_t const SDA_PIN = 1;
221 uint8_t const SCL_PIN = 0;
222
223 // SPI port
224 uint8_t const SS_PIN = 20;
225 uint8_t const MOSI_PIN = 22;
226 uint8_t const MISO_PIN = 23;
227 uint8_t const SCK_PIN = 21;
228
229 static const pin_map_t digitalPinMap[] = {
230   {&DDRD, &PIND, &PORTD, 0},  // D0  0
231   {&DDRD, &PIND, &PORTD, 1},  // D1  1
232   {&DDRD, &PIND, &PORTD, 2},  // D2  2
233   {&DDRD, &PIND, &PORTD, 3},  // D3  3
234   {&DDRD, &PIND, &PORTD, 4},  // D4  4
235   {&DDRD, &PIND, &PORTD, 5},  // D5  5
236   {&DDRD, &PIND, &PORTD, 6},  // D6  6
237   {&DDRD, &PIND, &PORTD, 7},  // D7  7
238   {&DDRE, &PINE, &PORTE, 0},  // E0  8
239   {&DDRE, &PINE, &PORTE, 1},  // E1  9
240   {&DDRC, &PINC, &PORTC, 0},  // C0 10
241   {&DDRC, &PINC, &PORTC, 1},  // C1 11
242   {&DDRC, &PINC, &PORTC, 2},  // C2 12
243   {&DDRC, &PINC, &PORTC, 3},  // C3 13
244   {&DDRC, &PINC, &PORTC, 4},  // C4 14
245   {&DDRC, &PINC, &PORTC, 5},  // C5 15
246   {&DDRC, &PINC, &PORTC, 6},  // C6 16
247   {&DDRC, &PINC, &PORTC, 7},  // C7 17
248   {&DDRE, &PINE, &PORTE, 6},  // E6 18
249   {&DDRE, &PINE, &PORTE, 7},  // E7 19
250   {&DDRB, &PINB, &PORTB, 0},  // B0 20
251   {&DDRB, &PINB, &PORTB, 1},  // B1 21
252   {&DDRB, &PINB, &PORTB, 2},  // B2 22
253   {&DDRB, &PINB, &PORTB, 3},  // B3 23
254   {&DDRB, &PINB, &PORTB, 4},  // B4 24
255   {&DDRB, &PINB, &PORTB, 5},  // B5 25
256   {&DDRB, &PINB, &PORTB, 6},  // B6 26
257   {&DDRB, &PINB, &PORTB, 7},  // B7 27
258   {&DDRA, &PINA, &PORTA, 0},  // A0 28
259   {&DDRA, &PINA, &PORTA, 1},  // A1 29
260   {&DDRA, &PINA, &PORTA, 2},  // A2 30
261   {&DDRA, &PINA, &PORTA, 3},  // A3 31
262   {&DDRA, &PINA, &PORTA, 4},  // A4 32
263   {&DDRA, &PINA, &PORTA, 5},  // A5 33
264   {&DDRA, &PINA, &PORTA, 6},  // A6 34
265   {&DDRA, &PINA, &PORTA, 7},  // A7 35
266   {&DDRE, &PINE, &PORTE, 4},  // E4 36
267   {&DDRE, &PINE, &PORTE, 5},  // E5 37
268   {&DDRF, &PINF, &PORTF, 0},  // F0 38
269   {&DDRF, &PINF, &PORTF, 1},  // F1 39
270   {&DDRF, &PINF, &PORTF, 2},  // F2 40
271   {&DDRF, &PINF, &PORTF, 3},  // F3 41
272   {&DDRF, &PINF, &PORTF, 4},  // F4 42
273   {&DDRF, &PINF, &PORTF, 5},  // F5 43
274   {&DDRF, &PINF, &PORTF, 6},  // F6 44
275   {&DDRF, &PINF, &PORTF, 7}   // F7 45
276 };
277 //------------------------------------------------------------------------------
278 #else  // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
279 // 168 and 328 Arduinos
280
281 // Two Wire (aka I2C) ports
282 uint8_t const SDA_PIN = 18;
283 uint8_t const SCL_PIN = 19;
284
285 // SPI port
286 uint8_t const SS_PIN = 10;
287 uint8_t const MOSI_PIN = 11;
288 uint8_t const MISO_PIN = 12;
289 uint8_t const SCK_PIN = 13;
290
291 static const pin_map_t digitalPinMap[] = {
292   {&DDRD, &PIND, &PORTD, 0},  // D0  0
293   {&DDRD, &PIND, &PORTD, 1},  // D1  1
294   {&DDRD, &PIND, &PORTD, 2},  // D2  2
295   {&DDRD, &PIND, &PORTD, 3},  // D3  3
296   {&DDRD, &PIND, &PORTD, 4},  // D4  4
297   {&DDRD, &PIND, &PORTD, 5},  // D5  5
298   {&DDRD, &PIND, &PORTD, 6},  // D6  6
299   {&DDRD, &PIND, &PORTD, 7},  // D7  7
300   {&DDRB, &PINB, &PORTB, 0},  // B0  8
301   {&DDRB, &PINB, &PORTB, 1},  // B1  9
302   {&DDRB, &PINB, &PORTB, 2},  // B2 10
303   {&DDRB, &PINB, &PORTB, 3},  // B3 11
304   {&DDRB, &PINB, &PORTB, 4},  // B4 12
305   {&DDRB, &PINB, &PORTB, 5},  // B5 13
306   {&DDRC, &PINC, &PORTC, 0},  // C0 14
307   {&DDRC, &PINC, &PORTC, 1},  // C1 15
308   {&DDRC, &PINC, &PORTC, 2},  // C2 16
309   {&DDRC, &PINC, &PORTC, 3},  // C3 17
310   {&DDRC, &PINC, &PORTC, 4},  // C4 18
311   {&DDRC, &PINC, &PORTC, 5}   // C5 19
312 };
313 #endif  // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
314 //------------------------------------------------------------------------------
315 static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);
316
317 uint8_t badPinNumber(void)
318   __attribute__((error("Pin number is too large or not a constant")));
319
320 static inline __attribute__((always_inline))
321   uint8_t getPinMode(uint8_t pin) {
322   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
323     return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1;
324   } else {
325     return badPinNumber();
326   }
327 }
328 static inline __attribute__((always_inline))
329   void setPinMode(uint8_t pin, uint8_t mode) {
330   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
331     if (mode) {
332       *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;
333     } else {
334       *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit);
335     }
336   } else {
337     badPinNumber();
338   }
339 }
340 static inline __attribute__((always_inline))
341   uint8_t fastDigitalRead(uint8_t pin) {
342   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
343     return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1;
344   } else {
345     return badPinNumber();
346   }
347 }
348 static inline __attribute__((always_inline))
349   void fastDigitalWrite(uint8_t pin, uint8_t value) {
350   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
351     if (value) {
352       *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;
353     } else {
354       *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit);
355     }
356   } else {
357     badPinNumber();
358   }
359 }
360 #endif  // Sd2PinMap_h