My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Sd2PinMap.h 13KB

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