Sd2PinMap.h 12 KB

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