pins_arduino.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. pins_arduino.h - Pin definition functions for mega1281
  3. Originally part of Arduino
  4. Copyright (c) 2007 David A. Mellis
  5. Modifications for mega1281 by Lubomir Rintel <lkundrak@v3.sk>
  6. and Minitronics: <https://reprap.org/wiki/File:MinitronicsArduinoAddon.zip>
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  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 GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General
  16. Public License along with this library; if not, write to the
  17. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  18. Boston, MA 02111-1307 USA
  19. */
  20. #ifndef Pins_Arduino_h
  21. #define Pins_Arduino_h
  22. #include <avr/pgmspace.h>
  23. #define NUM_DIGITAL_PINS 53
  24. #define NUM_ANALOG_INPUTS 8
  25. #define analogInputToDigitalPin(p) ((p < 16) ? (p) + 54 : -1)
  26. #define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 13) || ((p) >= 44 && (p)<= 46))
  27. #define PIN_SPI_SS (9)
  28. #define PIN_SPI_MOSI (11)
  29. #define PIN_SPI_MISO (12)
  30. #define PIN_SPI_SCK (10)
  31. static const uint8_t SS = PIN_SPI_SS;
  32. static const uint8_t MOSI = PIN_SPI_MOSI;
  33. static const uint8_t MISO = PIN_SPI_MISO;
  34. static const uint8_t SCK = PIN_SPI_SCK;
  35. #define PIN_WIRE_SDA (20)
  36. #define PIN_WIRE_SCL (21)
  37. static const uint8_t SDA = PIN_WIRE_SDA;
  38. static const uint8_t SCL = PIN_WIRE_SCL;
  39. #define LED_BUILTIN 46
  40. #define PIN_A0 (46)
  41. #define PIN_A1 (47)
  42. #define PIN_A2 (48)
  43. #define PIN_A3 (49)
  44. #define PIN_A4 (50)
  45. #define PIN_A5 (51)
  46. #define PIN_A6 (52)
  47. #define PIN_A7 (53)
  48. static const uint8_t A0 = PIN_A0;
  49. static const uint8_t A1 = PIN_A1;
  50. static const uint8_t A2 = PIN_A2;
  51. static const uint8_t A3 = PIN_A3;
  52. static const uint8_t A4 = PIN_A4;
  53. static const uint8_t A5 = PIN_A5;
  54. static const uint8_t A6 = PIN_A6;
  55. static const uint8_t A7 = PIN_A7;
  56. // A majority of the pins are NOT PCINTs, SO BE WARNED (i.e. you cannot use them as receive pins)
  57. // Only pins available for RECEIVE (TRANSMIT can be on any pin):
  58. // (I've deliberately left out pin mapping to the Hardware USARTs - seems senseless to me)
  59. // Pins: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69
  60. #define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 13)) || \
  61. (((p) >= 50) && ((p) <= 53)) || \
  62. (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
  63. #define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
  64. ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
  65. 0 ) )
  66. #define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
  67. ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
  68. ((uint8_t *)0) ) )
  69. #define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
  70. ( ((p) == 50) ? 3 : \
  71. ( ((p) == 51) ? 2 : \
  72. ( ((p) == 52) ? 1 : \
  73. ( ((p) == 53) ? 0 : \
  74. ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
  75. 0 ) ) ) ) ) )
  76. #define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : ((p) >= 18 && (p) <= 21 ? 23 - (p) : NOT_AN_INTERRUPT)))
  77. #ifdef ARDUINO_MAIN
  78. const uint16_t PROGMEM port_to_mode_PGM[] = {
  79. NOT_A_PORT,
  80. (uint16_t) &DDRA,
  81. (uint16_t) &DDRB,
  82. (uint16_t) &DDRC,
  83. (uint16_t) &DDRD,
  84. (uint16_t) &DDRE,
  85. (uint16_t) &DDRF,
  86. (uint16_t) &DDRG,
  87. };
  88. const uint16_t PROGMEM port_to_output_PGM[] = {
  89. NOT_A_PORT,
  90. (uint16_t) &PORTA,
  91. (uint16_t) &PORTB,
  92. (uint16_t) &PORTC,
  93. (uint16_t) &PORTD,
  94. (uint16_t) &PORTE,
  95. (uint16_t) &PORTF,
  96. (uint16_t) &PORTG,
  97. };
  98. const uint16_t PROGMEM port_to_input_PGM[] = {
  99. NOT_A_PIN,
  100. (uint16_t) &PINA,
  101. (uint16_t) &PINB,
  102. (uint16_t) &PINC,
  103. (uint16_t) &PIND,
  104. (uint16_t) &PINE,
  105. (uint16_t) &PINF,
  106. (uint16_t) &PING,
  107. };
  108. const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
  109. // PORTLIST
  110. // -------------------------------------------
  111. PE , // PE 0 ** 0 ** USART0_RX
  112. PE , // PE 1 ** 1 ** USART0_TX
  113. PE , // PE 4 ** 2 ** PWM0
  114. PE , // PE 5 ** 3 ** PWM1
  115. PG , // PG 5 ** 4 ** PWM2
  116. PE , // PE 3 ** 5 ** PWM3
  117. PB , // PB 4 ** 6 ** PWM4
  118. PB , // PB 5 ** 7 ** PWM5
  119. PB , // PB 6 ** 8 ** PWM6
  120. PB , // PB 7 ** 9 ** PWM7
  121. PB , // PB 1 ** 10 ** SPI_SCK
  122. PB , // PB 2 ** 11 ** SPI_MOSI
  123. PB , // PB 3 ** 12 ** SPI_MISO
  124. PE , // PE 2 ** 13 ** D13
  125. PE , // PE 6 ** 14 ** D14
  126. PE , // PE 7 ** 15 ** D15
  127. PB , // PB 0 ** 16 ** SPI_SS
  128. PD , // PD 0 ** 17 ** I2C_SCL
  129. PD , // PD 1 ** 18 ** I2C_SDA
  130. PD , // PD 2 ** 19 ** D19
  131. PD , // PD 3 ** 20 ** D20
  132. PD , // PD 4 ** 21 ** D21
  133. PD , // PD 5 ** 22 ** D22
  134. PD , // PD 6 ** 23 ** D23
  135. PD , // PD 7 ** 24 ** D24
  136. PG , // PG 0 ** 25 ** D25
  137. PG , // PG 1 ** 26 ** D26
  138. PG , // PG 2 ** 27 ** D27
  139. PG , // PG 3 ** 28 ** D28
  140. PG , // PG 4 ** 29 ** D29
  141. PC , // PC 0 ** 30 ** D30
  142. PC , // PC 1 ** 31 ** D31
  143. PC , // PC 2 ** 32 ** D32
  144. PC , // PC 3 ** 33 ** D33
  145. PC , // PC 4 ** 34 ** D34
  146. PC , // PC 5 ** 35 ** D35
  147. PC , // PC 6 ** 36 ** D36
  148. PC , // PC 7 ** 37 ** D37
  149. PA , // PA 0 ** 38 ** D38
  150. PA , // PA 1 ** 39 ** D39
  151. PA , // PA 2 ** 40 ** D40
  152. PA , // PA 3 ** 41 ** D41
  153. PA , // PA 4 ** 42 ** D42
  154. PA , // PA 5 ** 43 ** D43
  155. PA , // PA 6 ** 44 ** D44
  156. PA , // PA 7 ** 45 ** D45
  157. PF , // PF 0 ** 46 ** A0
  158. PF , // PF 1 ** 47 ** A1
  159. PF , // PF 2 ** 48 ** A2
  160. PF , // PF 3 ** 49 ** A3
  161. PF , // PF 4 ** 50 ** A4
  162. PF , // PF 5 ** 51 ** A5
  163. PF , // PF 6 ** 52 ** A6
  164. PF , // PF 7 ** 53 ** A7
  165. };
  166. const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
  167. // PIN IN PORT
  168. // -------------------------------------------
  169. _BV( 0 ) , // PE 0 ** 0 ** USART0_RX
  170. _BV( 1 ) , // PE 1 ** 1 ** USART0_TX
  171. _BV( 4 ) , // PE 4 ** 2 ** PWM0
  172. _BV( 5 ) , // PE 5 ** 3 ** PWM1
  173. _BV( 5 ) , // PG 5 ** 4 ** PWM2
  174. _BV( 3 ) , // PE 3 ** 5 ** PWM3
  175. _BV( 4 ) , // PB 4 ** 6 ** PWM4
  176. _BV( 5 ) , // PB 5 ** 7 ** PWM5
  177. _BV( 6 ) , // PB 6 ** 8 ** PWM6
  178. _BV( 7 ) , // PB 7 ** 9 ** PWM7
  179. _BV( 1 ) , // PB 1 ** 10 ** SPI_SCK
  180. _BV( 2 ) , // PB 2 ** 11 ** SPI_MOSI
  181. _BV( 3 ) , // PB 3 ** 12 ** SPI_MISO
  182. _BV( 2 ) , // PE 2 ** 13 ** D13
  183. _BV( 6 ) , // PE 6 ** 14 ** D14
  184. _BV( 7 ) , // PE 7 ** 15 ** D15
  185. _BV( 0 ) , // PB 0 ** 16 ** SPI_SS
  186. _BV( 0 ) , // PD 0 ** 17 ** I2C_SCL
  187. _BV( 1 ) , // PD 1 ** 18 ** I2C_SDA
  188. _BV( 2 ) , // PD 2 ** 19 ** D19
  189. _BV( 3 ) , // PD 3 ** 20 ** D20
  190. _BV( 4 ) , // PD 4 ** 21 ** D21
  191. _BV( 5 ) , // PA 5 ** 22 ** D22
  192. _BV( 6 ) , // PA 6 ** 23 ** D23
  193. _BV( 7 ) , // PA 7 ** 24 ** D24
  194. _BV( 0 ) , // PG 0 ** 25 ** D25
  195. _BV( 1 ) , // PG 1 ** 26 ** D26
  196. _BV( 2 ) , // PG 2 ** 27 ** D27
  197. _BV( 3 ) , // PG 3 ** 28 ** D28
  198. _BV( 4 ) , // PG 4 ** 29 ** D29
  199. _BV( 0 ) , // PC 0 ** 30 ** D30
  200. _BV( 1 ) , // PC 1 ** 31 ** D31
  201. _BV( 2 ) , // PC 2 ** 32 ** D32
  202. _BV( 3 ) , // PC 3 ** 33 ** D33
  203. _BV( 4 ) , // PC 4 ** 34 ** D34
  204. _BV( 5 ) , // PC 5 ** 35 ** D35
  205. _BV( 6 ) , // PC 6 ** 36 ** D36
  206. _BV( 7 ) , // PC 7 ** 37 ** D37
  207. _BV( 0 ) , // PA 0 ** 38 ** D38
  208. _BV( 1 ) , // PA 1 ** 39 ** D39
  209. _BV( 2 ) , // PA 2 ** 40 ** D40
  210. _BV( 3 ) , // PA 3 ** 41 ** D41
  211. _BV( 4 ) , // PA 4 ** 42 ** D42
  212. _BV( 5 ) , // PA 5 ** 43 ** D43
  213. _BV( 6 ) , // PA 6 ** 44 ** D44
  214. _BV( 7 ) , // PA 7 ** 45 ** D45
  215. _BV( 0 ) , // PF 0 ** 46 ** A0
  216. _BV( 1 ) , // PF 1 ** 47 ** A1
  217. _BV( 2 ) , // PF 2 ** 48 ** A2
  218. _BV( 3 ) , // PF 3 ** 49 ** A3
  219. _BV( 4 ) , // PF 4 ** 50 ** A4
  220. _BV( 5 ) , // PF 5 ** 51 ** A5
  221. _BV( 6 ) , // PF 6 ** 52 ** A6
  222. _BV( 7 ) , // PF 7 ** 53 ** A7
  223. };
  224. const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
  225. // TIMERS
  226. // -------------------------------------------
  227. NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX
  228. NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX
  229. TIMER3B , // PE 4 ** 2 ** PWM0
  230. TIMER3C , // PE 5 ** 3 ** PWM1
  231. TIMER0B , // PG 5 ** 4 ** PWM2
  232. TIMER3A , // PE 3 ** 5 ** PWM3
  233. TIMER2A , // PB 4 ** 6 ** PWM4
  234. TIMER1A , // PB 5 ** 7 ** PWM5
  235. TIMER1B , // PB 6 ** 8 ** PWM6
  236. TIMER0A , // PB 7 ** 9 ** PWM7
  237. NOT_ON_TIMER , // PB 1 ** 10 ** SPI_SCK
  238. NOT_ON_TIMER , // PB 2 ** 11 ** SPI_MOSI
  239. NOT_ON_TIMER , // PB 3 ** 12 ** SPI_MISO
  240. NOT_ON_TIMER , // PE 2 ** 13 ** D13
  241. NOT_ON_TIMER , // PE 6 ** 14 ** D14
  242. NOT_ON_TIMER , // PE 7 ** 15 ** D15
  243. NOT_ON_TIMER , // PB 0 ** 16 ** SPI_SS
  244. NOT_ON_TIMER , // PD 0 ** 17 ** I2C_SCL
  245. NOT_ON_TIMER , // PD 1 ** 18 ** I2C_SDA
  246. NOT_ON_TIMER , // PD 2 ** 19 ** D19
  247. NOT_ON_TIMER , // PD 3 ** 20 ** D20
  248. NOT_ON_TIMER , // PD 4 ** 21 ** D21
  249. NOT_ON_TIMER , // PA 5 ** 22 ** D22
  250. NOT_ON_TIMER , // PA 6 ** 23 ** D23
  251. NOT_ON_TIMER , // PA 7 ** 24 ** D24
  252. NOT_ON_TIMER , // PG 0 ** 25 ** D25
  253. NOT_ON_TIMER , // PG 1 ** 26 ** D26
  254. NOT_ON_TIMER , // PG 2 ** 27 ** D27
  255. NOT_ON_TIMER , // PG 3 ** 28 ** D28
  256. NOT_ON_TIMER , // PG 4 ** 29 ** D29
  257. NOT_ON_TIMER , // PC 0 ** 30 ** D30
  258. NOT_ON_TIMER , // PC 1 ** 31 ** D31
  259. NOT_ON_TIMER , // PC 2 ** 32 ** D32
  260. NOT_ON_TIMER , // PC 3 ** 33 ** D33
  261. NOT_ON_TIMER , // PC 4 ** 34 ** D34
  262. NOT_ON_TIMER , // PC 5 ** 35 ** D35
  263. NOT_ON_TIMER , // PC 6 ** 36 ** D36
  264. NOT_ON_TIMER , // PC 7 ** 37 ** D37
  265. NOT_ON_TIMER , // PA 0 ** 38 ** D38
  266. NOT_ON_TIMER , // PA 1 ** 39 ** D39
  267. NOT_ON_TIMER , // PA 2 ** 40 ** D40
  268. NOT_ON_TIMER , // PA 3 ** 41 ** D41
  269. NOT_ON_TIMER , // PA 4 ** 42 ** D42
  270. NOT_ON_TIMER , // PA 5 ** 43 ** D43
  271. NOT_ON_TIMER , // PA 6 ** 44 ** D44
  272. NOT_ON_TIMER , // PA 7 ** 45 ** D45
  273. NOT_ON_TIMER , // PF 0 ** 46 ** A0
  274. NOT_ON_TIMER , // PF 1 ** 47 ** A1
  275. NOT_ON_TIMER , // PF 2 ** 48 ** A2
  276. NOT_ON_TIMER , // PF 3 ** 49 ** A3
  277. NOT_ON_TIMER , // PF 4 ** 50 ** A4
  278. NOT_ON_TIMER , // PF 5 ** 51 ** A5
  279. NOT_ON_TIMER , // PF 6 ** 52 ** A6
  280. NOT_ON_TIMER , // PF 7 ** 53 ** A7
  281. };
  282. #endif
  283. // These serial port names are intended to allow libraries and architecture-neutral
  284. // sketches to automatically default to the correct port name for a particular type
  285. // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
  286. // the first hardware serial port whose RX/TX pins are not dedicated to another use.
  287. //
  288. // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
  289. //
  290. // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
  291. //
  292. // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
  293. //
  294. // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
  295. //
  296. // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
  297. // pins are NOT connected to anything by default.
  298. #define SERIAL_PORT_MONITOR Serial
  299. #define SERIAL_PORT_HARDWARE Serial
  300. #define SERIAL_PORT_HARDWARE1 Serial1
  301. #define SERIAL_PORT_HARDWARE2 Serial2
  302. #define SERIAL_PORT_HARDWARE_OPEN Serial1
  303. #define SERIAL_PORT_HARDWARE_OPEN1 Serial2
  304. #endif