選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

353 行
12KB

  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. // Leonardo
  163. // Two Wire (aka I2C) ports
  164. uint8_t const SDA_PIN = 2;
  165. uint8_t const SCL_PIN = 3;
  166. // SPI port
  167. uint8_t const SS_PIN = 17;
  168. uint8_t const MOSI_PIN = 16;
  169. uint8_t const MISO_PIN = 14;
  170. uint8_t const SCK_PIN = 15;
  171. static const pin_map_t digitalPinMap[] = {
  172. {&DDRD, &PIND, &PORTD, 2}, // D2 0
  173. {&DDRD, &PIND, &PORTD, 3}, // D3 1
  174. {&DDRD, &PIND, &PORTD, 1}, // D1 2
  175. {&DDRD, &PIND, &PORTD, 0}, // D0 3
  176. {&DDRD, &PIND, &PORTD, 4}, // D4 4
  177. {&DDRC, &PINC, &PORTC, 6}, // C6 5
  178. {&DDRD, &PIND, &PORTD, 7}, // D7 6
  179. {&DDRE, &PINE, &PORTE, 6}, // E6 7
  180. {&DDRB, &PINB, &PORTB, 4}, // B4 8
  181. {&DDRB, &PINB, &PORTB, 5}, // B5 9
  182. {&DDRB, &PINB, &PORTB, 6}, // B6 10
  183. {&DDRB, &PINB, &PORTB, 7}, // B7 11
  184. {&DDRD, &PIND, &PORTD, 6}, // D6 12
  185. {&DDRC, &PINC, &PORTC, 7}, // C7 13
  186. {&DDRB, &PINB, &PORTB, 3}, // B3 14
  187. {&DDRB, &PINB, &PORTB, 1}, // B1 15
  188. {&DDRB, &PINB, &PORTB, 2}, // B2 16
  189. {&DDRB, &PINB, &PORTB, 0}, // B0 17
  190. {&DDRF, &PINF, &PORTF, 7}, // F7 18
  191. {&DDRF, &PINF, &PORTF, 6}, // F6 19
  192. {&DDRF, &PINF, &PORTF, 5}, // F5 20
  193. {&DDRF, &PINF, &PORTF, 4}, // F4 21
  194. {&DDRF, &PINF, &PORTF, 1}, // F1 22
  195. {&DDRF, &PINF, &PORTF, 0}, // F0 23
  196. };
  197. //------------------------------------------------------------------------------
  198. #elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
  199. // Teensy++ 1.0 & 2.0
  200. // Two Wire (aka I2C) ports
  201. uint8_t const SDA_PIN = 1;
  202. uint8_t const SCL_PIN = 0;
  203. // SPI port
  204. uint8_t const SS_PIN = 20;
  205. uint8_t const MOSI_PIN = 22;
  206. uint8_t const MISO_PIN = 23;
  207. uint8_t const SCK_PIN = 21;
  208. static const pin_map_t digitalPinMap[] = {
  209. {&DDRD, &PIND, &PORTD, 0}, // D0 0
  210. {&DDRD, &PIND, &PORTD, 1}, // D1 1
  211. {&DDRD, &PIND, &PORTD, 2}, // D2 2
  212. {&DDRD, &PIND, &PORTD, 3}, // D3 3
  213. {&DDRD, &PIND, &PORTD, 4}, // D4 4
  214. {&DDRD, &PIND, &PORTD, 5}, // D5 5
  215. {&DDRD, &PIND, &PORTD, 6}, // D6 6
  216. {&DDRD, &PIND, &PORTD, 7}, // D7 7
  217. {&DDRE, &PINE, &PORTE, 0}, // E0 8
  218. {&DDRE, &PINE, &PORTE, 1}, // E1 9
  219. {&DDRC, &PINC, &PORTC, 0}, // C0 10
  220. {&DDRC, &PINC, &PORTC, 1}, // C1 11
  221. {&DDRC, &PINC, &PORTC, 2}, // C2 12
  222. {&DDRC, &PINC, &PORTC, 3}, // C3 13
  223. {&DDRC, &PINC, &PORTC, 4}, // C4 14
  224. {&DDRC, &PINC, &PORTC, 5}, // C5 15
  225. {&DDRC, &PINC, &PORTC, 6}, // C6 16
  226. {&DDRC, &PINC, &PORTC, 7}, // C7 17
  227. {&DDRE, &PINE, &PORTE, 6}, // E6 18
  228. {&DDRE, &PINE, &PORTE, 7}, // E7 19
  229. {&DDRB, &PINB, &PORTB, 0}, // B0 20
  230. {&DDRB, &PINB, &PORTB, 1}, // B1 21
  231. {&DDRB, &PINB, &PORTB, 2}, // B2 22
  232. {&DDRB, &PINB, &PORTB, 3}, // B3 23
  233. {&DDRB, &PINB, &PORTB, 4}, // B4 24
  234. {&DDRB, &PINB, &PORTB, 5}, // B5 25
  235. {&DDRB, &PINB, &PORTB, 6}, // B6 26
  236. {&DDRB, &PINB, &PORTB, 7}, // B7 27
  237. {&DDRA, &PINA, &PORTA, 0}, // A0 28
  238. {&DDRA, &PINA, &PORTA, 1}, // A1 29
  239. {&DDRA, &PINA, &PORTA, 2}, // A2 30
  240. {&DDRA, &PINA, &PORTA, 3}, // A3 31
  241. {&DDRA, &PINA, &PORTA, 4}, // A4 32
  242. {&DDRA, &PINA, &PORTA, 5}, // A5 33
  243. {&DDRA, &PINA, &PORTA, 6}, // A6 34
  244. {&DDRA, &PINA, &PORTA, 7}, // A7 35
  245. {&DDRE, &PINE, &PORTE, 4}, // E4 36
  246. {&DDRE, &PINE, &PORTE, 5}, // E5 37
  247. {&DDRF, &PINF, &PORTF, 0}, // F0 38
  248. {&DDRF, &PINF, &PORTF, 1}, // F1 39
  249. {&DDRF, &PINF, &PORTF, 2}, // F2 40
  250. {&DDRF, &PINF, &PORTF, 3}, // F3 41
  251. {&DDRF, &PINF, &PORTF, 4}, // F4 42
  252. {&DDRF, &PINF, &PORTF, 5}, // F5 43
  253. {&DDRF, &PINF, &PORTF, 6}, // F6 44
  254. {&DDRF, &PINF, &PORTF, 7} // F7 45
  255. };
  256. //------------------------------------------------------------------------------
  257. #else // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  258. // 168 and 328 Arduinos
  259. // Two Wire (aka I2C) ports
  260. uint8_t const SDA_PIN = 18;
  261. uint8_t const SCL_PIN = 19;
  262. // SPI port
  263. uint8_t const SS_PIN = 10;
  264. uint8_t const MOSI_PIN = 11;
  265. uint8_t const MISO_PIN = 12;
  266. uint8_t const SCK_PIN = 13;
  267. static const pin_map_t digitalPinMap[] = {
  268. {&DDRD, &PIND, &PORTD, 0}, // D0 0
  269. {&DDRD, &PIND, &PORTD, 1}, // D1 1
  270. {&DDRD, &PIND, &PORTD, 2}, // D2 2
  271. {&DDRD, &PIND, &PORTD, 3}, // D3 3
  272. {&DDRD, &PIND, &PORTD, 4}, // D4 4
  273. {&DDRD, &PIND, &PORTD, 5}, // D5 5
  274. {&DDRD, &PIND, &PORTD, 6}, // D6 6
  275. {&DDRD, &PIND, &PORTD, 7}, // D7 7
  276. {&DDRB, &PINB, &PORTB, 0}, // B0 8
  277. {&DDRB, &PINB, &PORTB, 1}, // B1 9
  278. {&DDRB, &PINB, &PORTB, 2}, // B2 10
  279. {&DDRB, &PINB, &PORTB, 3}, // B3 11
  280. {&DDRB, &PINB, &PORTB, 4}, // B4 12
  281. {&DDRB, &PINB, &PORTB, 5}, // B5 13
  282. {&DDRC, &PINC, &PORTC, 0}, // C0 14
  283. {&DDRC, &PINC, &PORTC, 1}, // C1 15
  284. {&DDRC, &PINC, &PORTC, 2}, // C2 16
  285. {&DDRC, &PINC, &PORTC, 3}, // C3 17
  286. {&DDRC, &PINC, &PORTC, 4}, // C4 18
  287. {&DDRC, &PINC, &PORTC, 5} // C5 19
  288. };
  289. #endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  290. //------------------------------------------------------------------------------
  291. static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t);
  292. uint8_t badPinNumber(void)
  293. __attribute__((error("Pin number is too large or not a constant")));
  294. static inline __attribute__((always_inline))
  295. uint8_t getPinMode(uint8_t pin) {
  296. if (__builtin_constant_p(pin) && pin < digitalPinCount) {
  297. return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1;
  298. } else {
  299. return badPinNumber();
  300. }
  301. }
  302. static inline __attribute__((always_inline))
  303. void setPinMode(uint8_t pin, uint8_t mode) {
  304. if (__builtin_constant_p(pin) && pin < digitalPinCount) {
  305. if (mode) {
  306. *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit;
  307. } else {
  308. *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit);
  309. }
  310. } else {
  311. badPinNumber();
  312. }
  313. }
  314. static inline __attribute__((always_inline))
  315. uint8_t fastDigitalRead(uint8_t pin) {
  316. if (__builtin_constant_p(pin) && pin < digitalPinCount) {
  317. return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1;
  318. } else {
  319. return badPinNumber();
  320. }
  321. }
  322. static inline __attribute__((always_inline))
  323. void fastDigitalWrite(uint8_t pin, uint8_t value) {
  324. if (__builtin_constant_p(pin) && pin < digitalPinCount) {
  325. if (value) {
  326. *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit;
  327. } else {
  328. *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit);
  329. }
  330. } else {
  331. badPinNumber();
  332. }
  333. }
  334. #endif // Sd2PinMap_h