Sd2PinMap.h

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

mercurial