source: rtos_arduino/trunk/arduino_lib/libraries/SD/src/utility/Sd2PinMap.h@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

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