Repetier-Firmware 0.2
Repetier/Sd2PinMap.h
Go to the documentation of this file.
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 <avr/io.h>
00024 
00025 //------------------------------------------------------------------------------
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__) || defined(__AVR_ATmega1284P__)
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 // Teensy 2.0
00170 
00171 // Two Wire (aka I2C) ports
00172 uint8_t const SDA_PIN = 6;
00173 uint8_t const SCL_PIN = 5;
00174 
00175 // SPI port
00176 uint8_t const SS_PIN = 0;
00177 uint8_t const MOSI_PIN = 2;
00178 uint8_t const MISO_PIN = 3;
00179 uint8_t const SCK_PIN = 1;
00180 
00181 static const pin_map_t digitalPinMap[] = {
00182   {&DDRB, &PINB, &PORTB, 0},  // B0  0
00183   {&DDRB, &PINB, &PORTB, 1},  // B1  1
00184   {&DDRB, &PINB, &PORTB, 2},  // B2  2
00185   {&DDRB, &PINB, &PORTB, 3},  // B3  3
00186   {&DDRB, &PINB, &PORTB, 7},  // B7  4
00187   {&DDRD, &PIND, &PORTD, 0},  // D0  5
00188   {&DDRD, &PIND, &PORTD, 1},  // D1  6
00189   {&DDRD, &PIND, &PORTD, 2},  // D2  7
00190   {&DDRD, &PIND, &PORTD, 3},  // D3  8
00191   {&DDRC, &PINC, &PORTC, 6},  // C6  9
00192   {&DDRC, &PINC, &PORTC, 7},  // C7 10
00193   {&DDRD, &PIND, &PORTD, 6},  // D6 11
00194   {&DDRD, &PIND, &PORTD, 7},  // D7 12
00195   {&DDRB, &PINB, &PORTB, 4},  // B4 13
00196   {&DDRB, &PINB, &PORTB, 5},  // B5 14
00197   {&DDRB, &PINB, &PORTB, 6},  // B6 15
00198   {&DDRF, &PINF, &PORTF, 7},  // F7 16
00199   {&DDRF, &PINF, &PORTF, 6},  // F6 17
00200   {&DDRF, &PINF, &PORTF, 5},  // F5 18
00201   {&DDRF, &PINF, &PORTF, 4},  // F4 19
00202   {&DDRF, &PINF, &PORTF, 1},  // F1 20
00203   {&DDRF, &PINF, &PORTF, 0},  // F0 21
00204   {&DDRD, &PIND, &PORTD, 4},  // D4 22
00205   {&DDRD, &PIND, &PORTD, 5},  // D5 23
00206   {&DDRE, &PINE, &PORTE, 6}   // E6 24
00207 };
00208 //------------------------------------------------------------------------------
00209 #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
00210 // Teensy++ 1.0 & 2.0
00211 
00212 // Two Wire (aka I2C) ports
00213 uint8_t const SDA_PIN = 1;
00214 uint8_t const SCL_PIN = 0;
00215 
00216 // SPI port
00217 uint8_t const SS_PIN = 20;
00218 uint8_t const MOSI_PIN = 22;
00219 uint8_t const MISO_PIN = 23;
00220 uint8_t const SCK_PIN = 21;
00221 
00222 static const pin_map_t digitalPinMap[] = {
00223   {&DDRD, &PIND, &PORTD, 0},  // D0  0
00224   {&DDRD, &PIND, &PORTD, 1},  // D1  1
00225   {&DDRD, &PIND, &PORTD, 2},  // D2  2
00226   {&DDRD, &PIND, &PORTD, 3},  // D3  3
00227   {&DDRD, &PIND, &PORTD, 4},  // D4  4
00228   {&DDRD, &PIND, &PORTD, 5},  // D5  5
00229   {&DDRD, &PIND, &PORTD, 6},  // D6  6
00230   {&DDRD, &PIND, &PORTD, 7},  // D7  7
00231   {&DDRE, &PINE, &PORTE, 0},  // E0  8
00232   {&DDRE, &PINE, &PORTE, 1},  // E1  9
00233   {&DDRC, &PINC, &PORTC, 0},  // C0 10
00234   {&DDRC, &PINC, &PORTC, 1},  // C1 11
00235   {&DDRC, &PINC, &PORTC, 2},  // C2 12
00236   {&DDRC, &PINC, &PORTC, 3},  // C3 13
00237   {&DDRC, &PINC, &PORTC, 4},  // C4 14
00238   {&DDRC, &PINC, &PORTC, 5},  // C5 15
00239   {&DDRC, &PINC, &PORTC, 6},  // C6 16
00240   {&DDRC, &PINC, &PORTC, 7},  // C7 17
00241   {&DDRE, &PINE, &PORTE, 6},  // E6 18
00242   {&DDRE, &PINE, &PORTE, 7},  // E7 19
00243   {&DDRB, &PINB, &PORTB, 0},  // B0 20
00244   {&DDRB, &PINB, &PORTB, 1},  // B1 21
00245   {&DDRB, &PINB, &PORTB, 2},  // B2 22
00246   {&DDRB, &PINB, &PORTB, 3},  // B3 23
00247   {&DDRB, &PINB, &PORTB, 4},  // B4 24
00248   {&DDRB, &PINB, &PORTB, 5},  // B5 25
00249   {&DDRB, &PINB, &PORTB, 6},  // B6 26
00250   {&DDRB, &PINB, &PORTB, 7},  // B7 27
00251   {&DDRA, &PINA, &PORTA, 0},  // A0 28
00252   {&DDRA, &PINA, &PORTA, 1},  // A1 29
00253   {&DDRA, &PINA, &PORTA, 2},  // A2 30
00254   {&DDRA, &PINA, &PORTA, 3},  // A3 31
00255   {&DDRA, &PINA, &PORTA, 4},  // A4 32
00256   {&DDRA, &PINA, &PORTA, 5},  // A5 33
00257   {&DDRA, &PINA, &PORTA, 6},  // A6 34
00258   {&DDRA, &PINA, &PORTA, 7},  // A7 35
00259   {&DDRE, &PINE, &PORTE, 4},  // E4 36
00260   {&DDRE, &PINE, &PORTE, 5},  // E5 37
00261   {&DDRF, &PINF, &PORTF, 0},  // F0 38
00262   {&DDRF, &PINF, &PORTF, 1},  // F1 39
00263   {&DDRF, &PINF, &PORTF, 2},  // F2 40
00264   {&DDRF, &PINF, &PORTF, 3},  // F3 41
00265   {&DDRF, &PINF, &PORTF, 4},  // F4 42
00266   {&DDRF, &PINF, &PORTF, 5},  // F5 43
00267   {&DDRF, &PINF, &PORTF, 6},  // F6 44
00268   {&DDRF, &PINF, &PORTF, 7}   // F7 45
00269 };
00270 //------------------------------------------------------------------------------
00271 #else  // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
00272 // 168 and 328 Arduinos
00273 
00274 // Two Wire (aka I2C) ports
00275 uint8_t const SDA_PIN = 18;
00276 uint8_t const SCL_PIN = 19;
00277 
00278 // SPI port
00279 uint8_t const SS_PIN = 10;
00280 uint8_t const MOSI_PIN = 11;
00281 uint8_t const MISO_PIN = 12;
00282 uint8_t const SCK_PIN = 13;
00283 
00284 static const pin_map_t digitalPinMap[] = {
00285   {&DDRD, &PIND, &PORTD, 0},  // D0  0
00286   {&DDRD, &PIND, &PORTD, 1},  // D1  1
00287   {&DDRD, &PIND, &PORTD, 2},  // D2  2
00288   {&DDRD, &PIND, &PORTD, 3},  // D3  3
00289   {&DDRD, &PIND, &PORTD, 4},  // D4  4
00290   {&DDRD, &PIND, &PORTD, 5},  // D5  5
00291   {&DDRD, &PIND, &PORTD, 6},  // D6  6
00292   {&DDRD, &PIND, &PORTD, 7},  // D7  7
00293   {&DDRB, &PINB, &PORTB, 0},  // B0  8
00294   {&DDRB, &PINB, &PORTB, 1},  // B1  9
00295   {&DDRB, &PINB, &PORTB, 2},  // B2 10
00296   {&DDRB, &PINB, &PORTB, 3},  // B3 11
00297   {&DDRB, &PINB, &PORTB, 4},  // B4 12
00298   {&DDRB, &PINB, &PORTB, 5},  // B5 13
00299   {&DDRC, &PINC, &PORTC, 0},  // C0 14
00300   {&DDRC, &PINC, &PORTC, 1},  // C1 15
00301   {&DDRC, &PINC, &PORTC, 2},  // C2 16
00302   {&DDRC, &PINC, &PORTC, 3},  // C3 17
00303   {&DDRC, &PINC, &PORTC, 4},  // C4 18
00304   {&DDRC, &PINC, &PORTC, 5}   // C5 19
00305 };
00306 #endif  // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
00307 //------------------------------------------------------------------------------
00308 static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);
00309 
00310 uint8_t badPinNumber(void)
00311   __attribute__((error("Pin number is too large or not a constant")));
00312 
00313 static inline __attribute__((always_inline))
00314   uint8_t getPinMode(uint8_t pin) {
00315   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
00316     return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1;
00317   } else {
00318     return badPinNumber();
00319   }
00320 }
00321 static inline __attribute__((always_inline))
00322   void setPinMode(uint8_t pin, uint8_t mode) {
00323   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
00324     if (mode) {
00325       *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;
00326     } else {
00327       *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit);
00328     }
00329   } else {
00330     badPinNumber();
00331   }
00332 }
00333 static inline __attribute__((always_inline))
00334   uint8_t fastDigitalRead(uint8_t pin) {
00335   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
00336     return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1;
00337   } else {
00338     return badPinNumber();
00339   }
00340 }
00341 static inline __attribute__((always_inline))
00342   void fastDigitalWrite(uint8_t pin, uint8_t value) {
00343   if (__builtin_constant_p(pin) && pin < digitalPinCount) {
00344     if (value) {
00345       *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;
00346     } else {
00347       *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit);
00348     }
00349   } else {
00350     badPinNumber();
00351   }
00352 }
00353 #endif  // Sd2PinMap_h
 All Data Structures Files Functions Variables Typedefs Friends Defines