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