My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Sd2PinMap.h 13KB

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