My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Sd2PinMap.h 12KB

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