pins_arduino.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. pins_arduino.h - Pin definition functions for Arduino
  3. Part of Arduino - http://www.arduino.cc/
  4. Copyright (c) 2007 David A. Mellis
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General
  14. Public License along with this library; if not, write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
  18. */
  19. #ifndef Pins_Arduino_h
  20. #define Pins_Arduino_h
  21. #include <avr/pgmspace.h>
  22. #define NUM_DIGITAL_PINS 70
  23. #define NUM_ANALOG_INPUTS 16
  24. #define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1)
  25. #define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46))
  26. static const uint8_t SS = 53;
  27. static const uint8_t MOSI = 51;
  28. static const uint8_t MISO = 50;
  29. static const uint8_t SCK = 52;
  30. static const uint8_t SDA = 20;
  31. static const uint8_t SCL = 21;
  32. #define LED_BUILTIN 13
  33. static const uint8_t A0 = 54;
  34. static const uint8_t A1 = 55;
  35. static const uint8_t A2 = 56;
  36. static const uint8_t A3 = 57;
  37. static const uint8_t A4 = 58;
  38. static const uint8_t A5 = 59;
  39. static const uint8_t A6 = 60;
  40. static const uint8_t A7 = 61;
  41. static const uint8_t A8 = 62;
  42. static const uint8_t A9 = 63;
  43. static const uint8_t A10 = 64;
  44. static const uint8_t A11 = 65;
  45. static const uint8_t A12 = 66;
  46. static const uint8_t A13 = 67;
  47. static const uint8_t A14 = 68;
  48. static const uint8_t A15 = 69;
  49. // A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
  50. // Only pins available for RECEIVE (TRANSMIT can be on any pin):
  51. // (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
  52. // Pins: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
  53. #define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \
  54. (((p) >= 50) && ((p) <= 53)) || \
  55. (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
  56. #define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
  57. ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
  58. 0 ) )
  59. #define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
  60. ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
  61. ((uint8_t *)0) ) )
  62. #define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
  63. ( ((p) == 50) ? 3 : \
  64. ( ((p) == 51) ? 2 : \
  65. ( ((p) == 52) ? 1 : \
  66. ( ((p) == 53) ? 0 : \
  67. ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
  68. 0 ) ) ) ) ) )
  69. #define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : ((p) >= 18 && (p) <= 21 ? 23 - (p) : NOT_AN_INTERRUPT)))
  70. #ifdef ARDUINO_MAIN
  71. const uint16_t PROGMEM port_to_mode_PGM[] = {
  72. NOT_A_PORT,
  73. (uint16_t) &DDRA,
  74. (uint16_t) &DDRB,
  75. (uint16_t) &DDRC,
  76. (uint16_t) &DDRD,
  77. (uint16_t) &DDRE,
  78. (uint16_t) &DDRF,
  79. (uint16_t) &DDRG,
  80. (uint16_t) &DDRH,
  81. NOT_A_PORT,
  82. (uint16_t) &DDRJ,
  83. (uint16_t) &DDRK,
  84. (uint16_t) &DDRL,
  85. };
  86. const uint16_t PROGMEM port_to_output_PGM[] = {
  87. NOT_A_PORT,
  88. (uint16_t) &PORTA,
  89. (uint16_t) &PORTB,
  90. (uint16_t) &PORTC,
  91. (uint16_t) &PORTD,
  92. (uint16_t) &PORTE,
  93. (uint16_t) &PORTF,
  94. (uint16_t) &PORTG,
  95. (uint16_t) &PORTH,
  96. NOT_A_PORT,
  97. (uint16_t) &PORTJ,
  98. (uint16_t) &PORTK,
  99. (uint16_t) &PORTL,
  100. };
  101. const uint16_t PROGMEM port_to_input_PGM[] = {
  102. NOT_A_PIN,
  103. (uint16_t) &PINA,
  104. (uint16_t) &PINB,
  105. (uint16_t) &PINC,
  106. (uint16_t) &PIND,
  107. (uint16_t) &PINE,
  108. (uint16_t) &PINF,
  109. (uint16_t) &PING,
  110. (uint16_t) &PINH,
  111. NOT_A_PIN,
  112. (uint16_t) &PINJ,
  113. (uint16_t) &PINK,
  114. (uint16_t) &PINL,
  115. };
  116. const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
  117. // PORTLIST
  118. // -------------------------------------------
  119. PE , // PE 0 ** 0 ** USART0_RX
  120. PE , // PE 1 ** 1 ** USART0_TX
  121. PE , // PE 4 ** 2 ** PWM2
  122. PE , // PE 5 ** 3 ** PWM3
  123. PG , // PG 5 ** 4 ** PWM4
  124. PE , // PE 3 ** 5 ** PWM5
  125. PH , // PH 3 ** 6 ** PWM6
  126. PH , // PH 4 ** 7 ** PWM7
  127. PH , // PH 5 ** 8 ** PWM8
  128. PH , // PH 6 ** 9 ** PWM9
  129. PB , // PB 4 ** 10 ** PWM10
  130. PB , // PB 5 ** 11 ** PWM11
  131. PB , // PB 6 ** 12 ** PWM12
  132. PB , // PB 7 ** 13 ** PWM13
  133. PJ , // PJ 1 ** 14 ** USART3_TX
  134. PJ , // PJ 0 ** 15 ** USART3_RX
  135. PH , // PH 1 ** 16 ** USART2_TX
  136. PH , // PH 0 ** 17 ** USART2_RX
  137. PD , // PD 3 ** 18 ** USART1_TX
  138. PD , // PD 2 ** 19 ** USART1_RX
  139. PD , // PD 1 ** 20 ** I2C_SDA
  140. PD , // PD 0 ** 21 ** I2C_SCL
  141. PA , // PA 0 ** 22 ** D22
  142. PA , // PA 1 ** 23 ** D23
  143. PA , // PA 2 ** 24 ** D24
  144. PA , // PA 3 ** 25 ** D25
  145. PA , // PA 4 ** 26 ** D26
  146. PA , // PA 5 ** 27 ** D27
  147. PA , // PA 6 ** 28 ** D28
  148. PA , // PA 7 ** 29 ** D29
  149. PC , // PC 7 ** 30 ** D30
  150. PC , // PC 6 ** 31 ** D31
  151. PC , // PC 5 ** 32 ** D32
  152. PC , // PC 4 ** 33 ** D33
  153. PC , // PC 3 ** 34 ** D34
  154. PC , // PC 2 ** 35 ** D35
  155. PC , // PC 1 ** 36 ** D36
  156. PC , // PC 0 ** 37 ** D37
  157. PD , // PD 7 ** 38 ** D38
  158. PG , // PG 2 ** 39 ** D39
  159. PG , // PG 1 ** 40 ** D40
  160. PG , // PG 0 ** 41 ** D41
  161. PL , // PL 7 ** 42 ** D42
  162. PL , // PL 6 ** 43 ** D43
  163. PL , // PL 5 ** 44 ** D44
  164. PL , // PL 4 ** 45 ** D45
  165. PL , // PL 3 ** 46 ** D46
  166. PL , // PL 2 ** 47 ** D47
  167. PL , // PL 1 ** 48 ** D48
  168. PL , // PL 0 ** 49 ** D49
  169. PB , // PB 3 ** 50 ** SPI_MISO
  170. PB , // PB 2 ** 51 ** SPI_MOSI
  171. PB , // PB 1 ** 52 ** SPI_SCK
  172. PB , // PB 0 ** 53 ** SPI_SS
  173. PF , // PF 0 ** 54 ** A0
  174. PF , // PF 1 ** 55 ** A1
  175. PF , // PF 2 ** 56 ** A2
  176. PF , // PF 3 ** 57 ** A3
  177. PF , // PF 4 ** 58 ** A4
  178. PF , // PF 5 ** 59 ** A5
  179. PF , // PF 6 ** 60 ** A6
  180. PF , // PF 7 ** 61 ** A7
  181. PK , // PK 0 ** 62 ** A8
  182. PK , // PK 1 ** 63 ** A9
  183. PK , // PK 2 ** 64 ** A10
  184. PK , // PK 3 ** 65 ** A11
  185. PK , // PK 4 ** 66 ** A12
  186. PK , // PK 5 ** 67 ** A13
  187. PK , // PK 6 ** 68 ** A14
  188. PK , // PK 7 ** 69 ** A15
  189. };
  190. const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
  191. // PIN IN PORT
  192. // -------------------------------------------
  193. _BV( 0 ) , // PE 0 ** 0 ** USART0_RX
  194. _BV( 1 ) , // PE 1 ** 1 ** USART0_TX
  195. _BV( 4 ) , // PE 4 ** 2 ** PWM2
  196. _BV( 5 ) , // PE 5 ** 3 ** PWM3
  197. _BV( 5 ) , // PG 5 ** 4 ** PWM4
  198. _BV( 3 ) , // PE 3 ** 5 ** PWM5
  199. _BV( 3 ) , // PH 3 ** 6 ** PWM6
  200. _BV( 4 ) , // PH 4 ** 7 ** PWM7
  201. _BV( 5 ) , // PH 5 ** 8 ** PWM8
  202. _BV( 6 ) , // PH 6 ** 9 ** PWM9
  203. _BV( 4 ) , // PB 4 ** 10 ** PWM10
  204. _BV( 5 ) , // PB 5 ** 11 ** PWM11
  205. _BV( 6 ) , // PB 6 ** 12 ** PWM12
  206. _BV( 7 ) , // PB 7 ** 13 ** PWM13
  207. _BV( 1 ) , // PJ 1 ** 14 ** USART3_TX
  208. _BV( 0 ) , // PJ 0 ** 15 ** USART3_RX
  209. _BV( 1 ) , // PH 1 ** 16 ** USART2_TX
  210. _BV( 0 ) , // PH 0 ** 17 ** USART2_RX
  211. _BV( 3 ) , // PD 3 ** 18 ** USART1_TX
  212. _BV( 2 ) , // PD 2 ** 19 ** USART1_RX
  213. _BV( 1 ) , // PD 1 ** 20 ** I2C_SDA
  214. _BV( 0 ) , // PD 0 ** 21 ** I2C_SCL
  215. _BV( 0 ) , // PA 0 ** 22 ** D22
  216. _BV( 1 ) , // PA 1 ** 23 ** D23
  217. _BV( 2 ) , // PA 2 ** 24 ** D24
  218. _BV( 3 ) , // PA 3 ** 25 ** D25
  219. _BV( 4 ) , // PA 4 ** 26 ** D26
  220. _BV( 5 ) , // PA 5 ** 27 ** D27
  221. _BV( 6 ) , // PA 6 ** 28 ** D28
  222. _BV( 7 ) , // PA 7 ** 29 ** D29
  223. _BV( 7 ) , // PC 7 ** 30 ** D30
  224. _BV( 6 ) , // PC 6 ** 31 ** D31
  225. _BV( 5 ) , // PC 5 ** 32 ** D32
  226. _BV( 4 ) , // PC 4 ** 33 ** D33
  227. _BV( 3 ) , // PC 3 ** 34 ** D34
  228. _BV( 2 ) , // PC 2 ** 35 ** D35
  229. _BV( 1 ) , // PC 1 ** 36 ** D36
  230. _BV( 0 ) , // PC 0 ** 37 ** D37
  231. _BV( 7 ) , // PD 7 ** 38 ** D38
  232. _BV( 2 ) , // PG 2 ** 39 ** D39
  233. _BV( 1 ) , // PG 1 ** 40 ** D40
  234. _BV( 0 ) , // PG 0 ** 41 ** D41
  235. _BV( 7 ) , // PL 7 ** 42 ** D42
  236. _BV( 6 ) , // PL 6 ** 43 ** D43
  237. _BV( 5 ) , // PL 5 ** 44 ** D44
  238. _BV( 4 ) , // PL 4 ** 45 ** D45
  239. _BV( 3 ) , // PL 3 ** 46 ** D46
  240. _BV( 2 ) , // PL 2 ** 47 ** D47
  241. _BV( 1 ) , // PL 1 ** 48 ** D48
  242. _BV( 0 ) , // PL 0 ** 49 ** D49
  243. _BV( 3 ) , // PB 3 ** 50 ** SPI_MISO
  244. _BV( 2 ) , // PB 2 ** 51 ** SPI_MOSI
  245. _BV( 1 ) , // PB 1 ** 52 ** SPI_SCK
  246. _BV( 0 ) , // PB 0 ** 53 ** SPI_SS
  247. _BV( 0 ) , // PF 0 ** 54 ** A0
  248. _BV( 1 ) , // PF 1 ** 55 ** A1
  249. _BV( 2 ) , // PF 2 ** 56 ** A2
  250. _BV( 3 ) , // PF 3 ** 57 ** A3
  251. _BV( 4 ) , // PF 4 ** 58 ** A4
  252. _BV( 5 ) , // PF 5 ** 59 ** A5
  253. _BV( 6 ) , // PF 6 ** 60 ** A6
  254. _BV( 7 ) , // PF 7 ** 61 ** A7
  255. _BV( 0 ) , // PK 0 ** 62 ** A8
  256. _BV( 1 ) , // PK 1 ** 63 ** A9
  257. _BV( 2 ) , // PK 2 ** 64 ** A10
  258. _BV( 3 ) , // PK 3 ** 65 ** A11
  259. _BV( 4 ) , // PK 4 ** 66 ** A12
  260. _BV( 5 ) , // PK 5 ** 67 ** A13
  261. _BV( 6 ) , // PK 6 ** 68 ** A14
  262. _BV( 7 ) , // PK 7 ** 69 ** A15
  263. };
  264. const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
  265. // TIMERS
  266. // -------------------------------------------
  267. NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX
  268. NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX
  269. TIMER3B , // PE 4 ** 2 ** PWM2
  270. TIMER3C , // PE 5 ** 3 ** PWM3
  271. TIMER0B , // PG 5 ** 4 ** PWM4
  272. TIMER3A , // PE 3 ** 5 ** PWM5
  273. TIMER4A , // PH 3 ** 6 ** PWM6
  274. TIMER4B , // PH 4 ** 7 ** PWM7
  275. TIMER4C , // PH 5 ** 8 ** PWM8
  276. TIMER2B , // PH 6 ** 9 ** PWM9
  277. TIMER2A , // PB 4 ** 10 ** PWM10
  278. TIMER1A , // PB 5 ** 11 ** PWM11
  279. TIMER1B , // PB 6 ** 12 ** PWM12
  280. TIMER0A , // PB 7 ** 13 ** PWM13
  281. NOT_ON_TIMER , // PJ 1 ** 14 ** USART3_TX
  282. NOT_ON_TIMER , // PJ 0 ** 15 ** USART3_RX
  283. NOT_ON_TIMER , // PH 1 ** 16 ** USART2_TX
  284. NOT_ON_TIMER , // PH 0 ** 17 ** USART2_RX
  285. NOT_ON_TIMER , // PD 3 ** 18 ** USART1_TX
  286. NOT_ON_TIMER , // PD 2 ** 19 ** USART1_RX
  287. NOT_ON_TIMER , // PD 1 ** 20 ** I2C_SDA
  288. NOT_ON_TIMER , // PD 0 ** 21 ** I2C_SCL
  289. NOT_ON_TIMER , // PA 0 ** 22 ** D22
  290. NOT_ON_TIMER , // PA 1 ** 23 ** D23
  291. NOT_ON_TIMER , // PA 2 ** 24 ** D24
  292. NOT_ON_TIMER , // PA 3 ** 25 ** D25
  293. NOT_ON_TIMER , // PA 4 ** 26 ** D26
  294. NOT_ON_TIMER , // PA 5 ** 27 ** D27
  295. NOT_ON_TIMER , // PA 6 ** 28 ** D28
  296. NOT_ON_TIMER , // PA 7 ** 29 ** D29
  297. NOT_ON_TIMER , // PC 7 ** 30 ** D30
  298. NOT_ON_TIMER , // PC 6 ** 31 ** D31
  299. NOT_ON_TIMER , // PC 5 ** 32 ** D32
  300. NOT_ON_TIMER , // PC 4 ** 33 ** D33
  301. NOT_ON_TIMER , // PC 3 ** 34 ** D34
  302. NOT_ON_TIMER , // PC 2 ** 35 ** D35
  303. NOT_ON_TIMER , // PC 1 ** 36 ** D36
  304. NOT_ON_TIMER , // PC 0 ** 37 ** D37
  305. NOT_ON_TIMER , // PD 7 ** 38 ** D38
  306. NOT_ON_TIMER , // PG 2 ** 39 ** D39
  307. NOT_ON_TIMER , // PG 1 ** 40 ** D40
  308. NOT_ON_TIMER , // PG 0 ** 41 ** D41
  309. NOT_ON_TIMER , // PL 7 ** 42 ** D42
  310. NOT_ON_TIMER , // PL 6 ** 43 ** D43
  311. TIMER5C , // PL 5 ** 44 ** D44
  312. TIMER5B , // PL 4 ** 45 ** D45
  313. TIMER5A , // PL 3 ** 46 ** D46
  314. NOT_ON_TIMER , // PL 2 ** 47 ** D47
  315. NOT_ON_TIMER , // PL 1 ** 48 ** D48
  316. NOT_ON_TIMER , // PL 0 ** 49 ** D49
  317. NOT_ON_TIMER , // PB 3 ** 50 ** SPI_MISO
  318. NOT_ON_TIMER , // PB 2 ** 51 ** SPI_MOSI
  319. NOT_ON_TIMER , // PB 1 ** 52 ** SPI_SCK
  320. NOT_ON_TIMER , // PB 0 ** 53 ** SPI_SS
  321. NOT_ON_TIMER , // PF 0 ** 54 ** A0
  322. NOT_ON_TIMER , // PF 1 ** 55 ** A1
  323. NOT_ON_TIMER , // PF 2 ** 56 ** A2
  324. NOT_ON_TIMER , // PF 3 ** 57 ** A3
  325. NOT_ON_TIMER , // PF 4 ** 58 ** A4
  326. NOT_ON_TIMER , // PF 5 ** 59 ** A5
  327. NOT_ON_TIMER , // PF 6 ** 60 ** A6
  328. NOT_ON_TIMER , // PF 7 ** 61 ** A7
  329. NOT_ON_TIMER , // PK 0 ** 62 ** A8
  330. NOT_ON_TIMER , // PK 1 ** 63 ** A9
  331. NOT_ON_TIMER , // PK 2 ** 64 ** A10
  332. NOT_ON_TIMER , // PK 3 ** 65 ** A11
  333. NOT_ON_TIMER , // PK 4 ** 66 ** A12
  334. NOT_ON_TIMER , // PK 5 ** 67 ** A13
  335. NOT_ON_TIMER , // PK 6 ** 68 ** A14
  336. NOT_ON_TIMER , // PK 7 ** 69 ** A15
  337. };
  338. #endif
  339. // These serial port names are intended to allow libraries and architecture-neutral
  340. // sketches to automatically default to the correct port name for a particular type
  341. // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
  342. // the first hardware serial port whose RX/TX pins are not dedicated to another use.
  343. //
  344. // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
  345. //
  346. // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
  347. //
  348. // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
  349. //
  350. // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
  351. //
  352. // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
  353. // pins are NOT connected to anything by default.
  354. #define SERIAL_PORT_MONITOR Serial
  355. #define SERIAL_PORT_HARDWARE Serial
  356. #define SERIAL_PORT_HARDWARE1 Serial1
  357. #define SERIAL_PORT_HARDWARE2 Serial2
  358. #define SERIAL_PORT_HARDWARE3 Serial3
  359. #define SERIAL_PORT_HARDWARE_OPEN Serial1
  360. #define SERIAL_PORT_HARDWARE_OPEN1 Serial2
  361. #define SERIAL_PORT_HARDWARE_OPEN2 Serial3
  362. #endif