No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

414 líneas
14KB

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