utility

Dependents:   SD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Sd2PinMap.h Source File

Sd2PinMap.h

00001 /* Arduino SdFat Library
00002  * Copyright (C) 2010 by William Greiman
00003  *
00004  * This file is part of the Arduino SdFat Library
00005  *
00006  * This Library is free software: you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation, either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This Library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with the Arduino SdFat Library.  If not, see
00018  * <http://www.gnu.org/licenses/>.
00019  */
00020 // Warning this file was generated by a program.
00021 #ifndef Sd2PinMap_h
00022 #define Sd2PinMap_h
00023 #include "mbed.h"
00024 
00025 //------------------------------------------------------------------------------
00026 /** struct for mapping digital pins */
00027 struct pin_map_t {
00028   volatile uint8_t* ddr;
00029   volatile uint8_t* pin;
00030   volatile uint8_t* port;
00031   uint8_t bit;
00032 };
00033 //------------------------------------------------------------------------------
00034 /*#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
00035 // Mega
00036 
00037 // Two Wire (aka I2C) ports
00038 uint8_t const SDA_PIN = 20;
00039 uint8_t const SCL_PIN = 21;
00040 
00041 // SPI port
00042 uint8_t const SS_PIN = 53;
00043 uint8_t const MOSI_PIN = 51;
00044 uint8_t const MISO_PIN = 50;
00045 uint8_t const SCK_PIN = 52;
00046 
00047 static const pin_map_t digitalPinMap[] = {
00048   {&DDRE, &PINE, &PORTE, 0},  // E0  0
00049   {&DDRE, &PINE, &PORTE, 1},  // E1  1
00050   {&DDRE, &PINE, &PORTE, 4},  // E4  2
00051   {&DDRE, &PINE, &PORTE, 5},  // E5  3
00052   {&DDRG, &PING, &PORTG, 5},  // G5  4
00053   {&DDRE, &PINE, &PORTE, 3},  // E3  5
00054   {&DDRH, &PINH, &PORTH, 3},  // H3  6
00055   {&DDRH, &PINH, &PORTH, 4},  // H4  7
00056   {&DDRH, &PINH, &PORTH, 5},  // H5  8
00057   {&DDRH, &PINH, &PORTH, 6},  // H6  9
00058   {&DDRB, &PINB, &PORTB, 4},  // B4 10
00059   {&DDRB, &PINB, &PORTB, 5},  // B5 11
00060   {&DDRB, &PINB, &PORTB, 6},  // B6 12
00061   {&DDRB, &PINB, &PORTB, 7},  // B7 13
00062   {&DDRJ, &PINJ, &PORTJ, 1},  // J1 14
00063   {&DDRJ, &PINJ, &PORTJ, 0},  // J0 15
00064   {&DDRH, &PINH, &PORTH, 1},  // H1 16
00065   {&DDRH, &PINH, &PORTH, 0},  // H0 17
00066   {&DDRD, &PIND, &PORTD, 3},  // D3 18
00067   {&DDRD, &PIND, &PORTD, 2},  // D2 19
00068   {&DDRD, &PIND, &PORTD, 1},  // D1 20
00069   {&DDRD, &PIND, &PORTD, 0},  // D0 21
00070   {&DDRA, &PINA, &PORTA, 0},  // A0 22
00071   {&DDRA, &PINA, &PORTA, 1},  // A1 23
00072   {&DDRA, &PINA, &PORTA, 2},  // A2 24
00073   {&DDRA, &PINA, &PORTA, 3},  // A3 25
00074   {&DDRA, &PINA, &PORTA, 4},  // A4 26
00075   {&DDRA, &PINA, &PORTA, 5},  // A5 27
00076   {&DDRA, &PINA, &PORTA, 6},  // A6 28
00077   {&DDRA, &PINA, &PORTA, 7},  // A7 29
00078   {&DDRC, &PINC, &PORTC, 7},  // C7 30
00079   {&DDRC, &PINC, &PORTC, 6},  // C6 31
00080   {&DDRC, &PINC, &PORTC, 5},  // C5 32
00081   {&DDRC, &PINC, &PORTC, 4},  // C4 33
00082   {&DDRC, &PINC, &PORTC, 3},  // C3 34
00083   {&DDRC, &PINC, &PORTC, 2},  // C2 35
00084   {&DDRC, &PINC, &PORTC, 1},  // C1 36
00085   {&DDRC, &PINC, &PORTC, 0},  // C0 37
00086   {&DDRD, &PIND, &PORTD, 7},  // D7 38
00087   {&DDRG, &PING, &PORTG, 2},  // G2 39
00088   {&DDRG, &PING, &PORTG, 1},  // G1 40
00089   {&DDRG, &PING, &PORTG, 0},  // G0 41
00090   {&DDRL, &PINL, &PORTL, 7},  // L7 42
00091   {&DDRL, &PINL, &PORTL, 6},  // L6 43
00092   {&DDRL, &PINL, &PORTL, 5},  // L5 44
00093   {&DDRL, &PINL, &PORTL, 4},  // L4 45
00094   {&DDRL, &PINL, &PORTL, 3},  // L3 46
00095   {&DDRL, &PINL, &PORTL, 2},  // L2 47
00096   {&DDRL, &PINL, &PORTL, 1},  // L1 48
00097   {&DDRL, &PINL, &PORTL, 0},  // L0 49
00098   {&DDRB, &PINB, &PORTB, 3},  // B3 50
00099   {&DDRB, &PINB, &PORTB, 2},  // B2 51
00100   {&DDRB, &PINB, &PORTB, 1},  // B1 52
00101   {&DDRB, &PINB, &PORTB, 0},  // B0 53
00102   {&DDRF, &PINF, &PORTF, 0},  // F0 54
00103   {&DDRF, &PINF, &PORTF, 1},  // F1 55
00104   {&DDRF, &PINF, &PORTF, 2},  // F2 56
00105   {&DDRF, &PINF, &PORTF, 3},  // F3 57
00106   {&DDRF, &PINF, &PORTF, 4},  // F4 58
00107   {&DDRF, &PINF, &PORTF, 5},  // F5 59
00108   {&DDRF, &PINF, &PORTF, 6},  // F6 60
00109   {&DDRF, &PINF, &PORTF, 7},  // F7 61
00110   {&DDRK, &PINK, &PORTK, 0},  // K0 62
00111   {&DDRK, &PINK, &PORTK, 1},  // K1 63
00112   {&DDRK, &PINK, &PORTK, 2},  // K2 64
00113   {&DDRK, &PINK, &PORTK, 3},  // K3 65
00114   {&DDRK, &PINK, &PORTK, 4},  // K4 66
00115   {&DDRK, &PINK, &PORTK, 5},  // K5 67
00116   {&DDRK, &PINK, &PORTK, 6},  // K6 68
00117   {&DDRK, &PINK, &PORTK, 7}   // K7 69
00118 };
00119 //------------------------------------------------------------------------------
00120 #elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644__)
00121 // Sanguino
00122 
00123 // Two Wire (aka I2C) ports
00124 uint8_t const SDA_PIN = 17;
00125 uint8_t const SCL_PIN = 18;
00126 
00127 // SPI port
00128 uint8_t const SS_PIN = 4;
00129 uint8_t const MOSI_PIN = 5;
00130 uint8_t const MISO_PIN = 6;
00131 uint8_t const SCK_PIN = 7;
00132 
00133 static const pin_map_t digitalPinMap[] = {
00134   {&DDRB, &PINB, &PORTB, 0},  // B0  0
00135   {&DDRB, &PINB, &PORTB, 1},  // B1  1
00136   {&DDRB, &PINB, &PORTB, 2},  // B2  2
00137   {&DDRB, &PINB, &PORTB, 3},  // B3  3
00138   {&DDRB, &PINB, &PORTB, 4},  // B4  4
00139   {&DDRB, &PINB, &PORTB, 5},  // B5  5
00140   {&DDRB, &PINB, &PORTB, 6},  // B6  6
00141   {&DDRB, &PINB, &PORTB, 7},  // B7  7
00142   {&DDRD, &PIND, &PORTD, 0},  // D0  8
00143   {&DDRD, &PIND, &PORTD, 1},  // D1  9
00144   {&DDRD, &PIND, &PORTD, 2},  // D2 10
00145   {&DDRD, &PIND, &PORTD, 3},  // D3 11
00146   {&DDRD, &PIND, &PORTD, 4},  // D4 12
00147   {&DDRD, &PIND, &PORTD, 5},  // D5 13
00148   {&DDRD, &PIND, &PORTD, 6},  // D6 14
00149   {&DDRD, &PIND, &PORTD, 7},  // D7 15
00150   {&DDRC, &PINC, &PORTC, 0},  // C0 16
00151   {&DDRC, &PINC, &PORTC, 1},  // C1 17
00152   {&DDRC, &PINC, &PORTC, 2},  // C2 18
00153   {&DDRC, &PINC, &PORTC, 3},  // C3 19
00154   {&DDRC, &PINC, &PORTC, 4},  // C4 20
00155   {&DDRC, &PINC, &PORTC, 5},  // C5 21
00156   {&DDRC, &PINC, &PORTC, 6},  // C6 22
00157   {&DDRC, &PINC, &PORTC, 7},  // C7 23
00158   {&DDRA, &PINA, &PORTA, 7},  // A7 24
00159   {&DDRA, &PINA, &PORTA, 6},  // A6 25
00160   {&DDRA, &PINA, &PORTA, 5},  // A5 26
00161   {&DDRA, &PINA, &PORTA, 4},  // A4 27
00162   {&DDRA, &PINA, &PORTA, 3},  // A3 28
00163   {&DDRA, &PINA, &PORTA, 2},  // A2 29
00164   {&DDRA, &PINA, &PORTA, 1},  // A1 30
00165   {&DDRA, &PINA, &PORTA, 0}   // A0 31
00166 };
00167 //------------------------------------------------------------------------------
00168 #elif defined(__AVR_ATmega32U4__)
00169 // Leonardo
00170 
00171 // Two Wire (aka I2C) ports
00172 uint8_t const SDA_PIN = 2;
00173 uint8_t const SCL_PIN = 3;
00174 
00175 // SPI port
00176 uint8_t const SS_PIN = 17;
00177 uint8_t const MOSI_PIN = 16;
00178 uint8_t const MISO_PIN = 14;
00179 uint8_t const SCK_PIN = 15;
00180 
00181 static const pin_map_t digitalPinMap[] = {
00182   {&DDRD, &PIND, &PORTD, 2},  // D2  0
00183   {&DDRD, &PIND, &PORTD, 3},  // D3  1
00184   {&DDRD, &PIND, &PORTD, 1},  // D1  2
00185   {&DDRD, &PIND, &PORTD, 0},  // D0  3
00186   {&DDRD, &PIND, &PORTD, 4},  // D4  4
00187   {&DDRC, &PINC, &PORTC, 6},  // C6  5
00188   {&DDRD, &PIND, &PORTD, 7},  // D7  6
00189   {&DDRE, &PINE, &PORTE, 6},  // E6  7
00190   {&DDRB, &PINB, &PORTB, 4},  // B4  8
00191   {&DDRB, &PINB, &PORTB, 5},  // B5  9
00192   {&DDRB, &PINB, &PORTB, 6},  // B6 10
00193   {&DDRB, &PINB, &PORTB, 7},  // B7 11
00194   {&DDRD, &PIND, &PORTD, 6},  // D6 12
00195   {&DDRC, &PINC, &PORTC, 7},  // C7 13
00196   {&DDRB, &PINB, &PORTB, 3},  // B3 14
00197   {&DDRB, &PINB, &PORTB, 1},  // B1 15
00198   {&DDRB, &PINB, &PORTB, 2},  // B2 16
00199   {&DDRB, &PINB, &PORTB, 0},  // B0 17
00200   {&DDRF, &PINF, &PORTF, 7},  // F7 18
00201   {&DDRF, &PINF, &PORTF, 6},  // F6 19
00202   {&DDRF, &PINF, &PORTF, 5},  // F5 20
00203   {&DDRF, &PINF, &PORTF, 4},  // F4 21
00204   {&DDRF, &PINF, &PORTF, 1},  // F1 22
00205   {&DDRF, &PINF, &PORTF, 0},  // F0 23
00206 };
00207 //------------------------------------------------------------------------------
00208 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
00209 // Teensy++ 1.0 & 2.0
00210 
00211 // Two Wire (aka I2C) ports
00212 uint8_t const SDA_PIN = 1;
00213 uint8_t const SCL_PIN = 0;
00214 
00215 // SPI port
00216 uint8_t const SS_PIN = 20;
00217 uint8_t const MOSI_PIN = 22;
00218 uint8_t const MISO_PIN = 23;
00219 uint8_t const SCK_PIN = 21;
00220 
00221 static const pin_map_t digitalPinMap[] = {
00222   {&DDRD, &PIND, &PORTD, 0},  // D0  0
00223   {&DDRD, &PIND, &PORTD, 1},  // D1  1
00224   {&DDRD, &PIND, &PORTD, 2},  // D2  2
00225   {&DDRD, &PIND, &PORTD, 3},  // D3  3
00226   {&DDRD, &PIND, &PORTD, 4},  // D4  4
00227   {&DDRD, &PIND, &PORTD, 5},  // D5  5
00228   {&DDRD, &PIND, &PORTD, 6},  // D6  6
00229   {&DDRD, &PIND, &PORTD, 7},  // D7  7
00230   {&DDRE, &PINE, &PORTE, 0},  // E0  8
00231   {&DDRE, &PINE, &PORTE, 1},  // E1  9
00232   {&DDRC, &PINC, &PORTC, 0},  // C0 10
00233   {&DDRC, &PINC, &PORTC, 1},  // C1 11
00234   {&DDRC, &PINC, &PORTC, 2},  // C2 12
00235   {&DDRC, &PINC, &PORTC, 3},  // C3 13
00236   {&DDRC, &PINC, &PORTC, 4},  // C4 14
00237   {&DDRC, &PINC, &PORTC, 5},  // C5 15
00238   {&DDRC, &PINC, &PORTC, 6},  // C6 16
00239   {&DDRC, &PINC, &PORTC, 7},  // C7 17
00240   {&DDRE, &PINE, &PORTE, 6},  // E6 18
00241   {&DDRE, &PINE, &PORTE, 7},  // E7 19
00242   {&DDRB, &PINB, &PORTB, 0},  // B0 20
00243   {&DDRB, &PINB, &PORTB, 1},  // B1 21
00244   {&DDRB, &PINB, &PORTB, 2},  // B2 22
00245   {&DDRB, &PINB, &PORTB, 3},  // B3 23
00246   {&DDRB, &PINB, &PORTB, 4},  // B4 24
00247   {&DDRB, &PINB, &PORTB, 5},  // B5 25
00248   {&DDRB, &PINB, &PORTB, 6},  // B6 26
00249   {&DDRB, &PINB, &PORTB, 7},  // B7 27
00250   {&DDRA, &PINA, &PORTA, 0},  // A0 28
00251   {&DDRA, &PINA, &PORTA, 1},  // A1 29
00252   {&DDRA, &PINA, &PORTA, 2},  // A2 30
00253   {&DDRA, &PINA, &PORTA, 3},  // A3 31
00254   {&DDRA, &PINA, &PORTA, 4},  // A4 32
00255   {&DDRA, &PINA, &PORTA, 5},  // A5 33
00256   {&DDRA, &PINA, &PORTA, 6},  // A6 34
00257   {&DDRA, &PINA, &PORTA, 7},  // A7 35
00258   {&DDRE, &PINE, &PORTE, 4},  // E4 36
00259   {&DDRE, &PINE, &PORTE, 5},  // E5 37
00260   {&DDRF, &PINF, &PORTF, 0},  // F0 38
00261   {&DDRF, &PINF, &PORTF, 1},  // F1 39
00262   {&DDRF, &PINF, &PORTF, 2},  // F2 40
00263   {&DDRF, &PINF, &PORTF, 3},  // F3 41
00264   {&DDRF, &PINF, &PORTF, 4},  // F4 42
00265   {&DDRF, &PINF, &PORTF, 5},  // F5 43
00266   {&DDRF, &PINF, &PORTF, 6},  // F6 44
00267   {&DDRF, &PINF, &PORTF, 7}   // F7 45
00268 };
00269 //------------------------------------------------------------------------------
00270 #else  // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
00271 // 168 and 328 Arduinos
00272 
00273 // Two Wire (aka I2C) ports
00274 uint8_t const SDA_PIN = 18;
00275 uint8_t const SCL_PIN = 19;
00276 
00277 // SPI port
00278 uint8_t const SS_PIN = 10;
00279 uint8_t const MOSI_PIN = 11;
00280 uint8_t const MISO_PIN = 12;
00281 uint8_t const SCK_PIN = 13;
00282 
00283 static const pin_map_t digitalPinMap[] = {
00284   {&DDRD, &PIND, &PORTD, 0},  // D0  0
00285   {&DDRD, &PIND, &PORTD, 1},  // D1  1
00286   {&DDRD, &PIND, &PORTD, 2},  // D2  2
00287   {&DDRD, &PIND, &PORTD, 3},  // D3  3
00288   {&DDRD, &PIND, &PORTD, 4},  // D4  4
00289   {&DDRD, &PIND, &PORTD, 5},  // D5  5
00290   {&DDRD, &PIND, &PORTD, 6},  // D6  6
00291   {&DDRD, &PIND, &PORTD, 7},  // D7  7
00292   {&DDRB, &PINB, &PORTB, 0},  // B0  8
00293   {&DDRB, &PINB, &PORTB, 1},  // B1  9
00294   {&DDRB, &PINB, &PORTB, 2},  // B2 10
00295   {&DDRB, &PINB, &PORTB, 3},  // B3 11
00296   {&DDRB, &PINB, &PORTB, 4},  // B4 12
00297   {&DDRB, &PINB, &PORTB, 5},  // B5 13
00298   {&DDRC, &PINC, &PORTC, 0},  // C0 14
00299   {&DDRC, &PINC, &PORTC, 1},  // C1 15
00300   {&DDRC, &PINC, &PORTC, 2},  // C2 16
00301   {&DDRC, &PINC, &PORTC, 3},  // C3 17
00302   {&DDRC, &PINC, &PORTC, 4},  // C4 18
00303   {&DDRC, &PINC, &PORTC, 5}   // C5 19
00304 };
00305 #endif  // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
00306 //------------------------------------------------------------------------------
00307 static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);
00308 
00309 uint8_t badPinNumber(void)
00310   __attribute__((error("Pin number is too large or not a constant")));
00311 
00312 static inline __attribute__((always_inline))
00313   uint8_t getPinMode(uint8_t pin) {
00314   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
00315     return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1;
00316   } else {
00317     return badPinNumber();
00318   }
00319 }
00320 static inline __attribute__((always_inline))
00321   void setPinMode(uint8_t pin, uint8_t mode) {
00322   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
00323     if (mode) {
00324       *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;
00325     } else {
00326       *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit);
00327     }
00328   } else {
00329     badPinNumber();
00330   }
00331 }
00332 static inline __attribute__((always_inline))
00333   uint8_t fastDigitalRead(uint8_t pin) {
00334   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
00335     return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1;
00336   } else {
00337     return badPinNumber();
00338   }
00339 }
00340 static inline __attribute__((always_inline))
00341   void fastDigitalWrite(uint8_t pin, uint8_t value) {
00342   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
00343     if (value) {
00344       *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;
00345     } else {
00346       *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit);
00347     }
00348   } else {
00349     badPinNumber();
00350   }
00351 }*/
00352 
00353 // SPI port
00354 uint8_t const SS_PIN = 10;
00355 uint8_t const MOSI_PIN = SPI_MOSI;
00356 uint8_t const MISO_PIN = SPI_MISO;
00357 uint8_t const SCK_PIN = SPI_SCK;
00358 
00359 
00360 #endif  // Sd2PinMap_h