You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

358 lines
10 KiB

  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. #pragma once
  20. #include <avr/pgmspace.h>
  21. // Workaround for wrong definitions in "iom32u4.h".
  22. // This should be fixed in the AVR toolchain.
  23. #undef UHCON
  24. #undef UHINT
  25. #undef UHIEN
  26. #undef UHADDR
  27. #undef UHFNUM
  28. #undef UHFNUML
  29. #undef UHFNUMH
  30. #undef UHFLEN
  31. #undef UPINRQX
  32. #undef UPINTX
  33. #undef UPNUM
  34. #undef UPRST
  35. #undef UPCONX
  36. #undef UPCFG0X
  37. #undef UPCFG1X
  38. #undef UPSTAX
  39. #undef UPCFG2X
  40. #undef UPIENX
  41. #undef UPDATX
  42. #undef TCCR2A
  43. #undef WGM20
  44. #undef WGM21
  45. #undef COM2B0
  46. #undef COM2B1
  47. #undef COM2A0
  48. #undef COM2A1
  49. #undef TCCR2B
  50. #undef CS20
  51. #undef CS21
  52. #undef CS22
  53. #undef WGM22
  54. #undef FOC2B
  55. #undef FOC2A
  56. #undef TCNT2
  57. #undef TCNT2_0
  58. #undef TCNT2_1
  59. #undef TCNT2_2
  60. #undef TCNT2_3
  61. #undef TCNT2_4
  62. #undef TCNT2_5
  63. #undef TCNT2_6
  64. #undef TCNT2_7
  65. #undef OCR2A
  66. #undef OCR2_0
  67. #undef OCR2_1
  68. #undef OCR2_2
  69. #undef OCR2_3
  70. #undef OCR2_4
  71. #undef OCR2_5
  72. #undef OCR2_6
  73. #undef OCR2_7
  74. #undef OCR2B
  75. #undef OCR2_0
  76. #undef OCR2_1
  77. #undef OCR2_2
  78. #undef OCR2_3
  79. #undef OCR2_4
  80. #undef OCR2_5
  81. #undef OCR2_6
  82. #undef OCR2_7
  83. #define NUM_DIGITAL_PINS 30
  84. #define NUM_ANALOG_INPUTS 12
  85. #define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0)
  86. #define TXLED0 PORTD |= (1<<5)
  87. #define TXLED1 PORTD &= ~(1<<5)
  88. #define RXLED0 PORTB |= (1<<0)
  89. #define RXLED1 PORTB &= ~(1<<0)
  90. static const uint8_t SDA = 2;
  91. static const uint8_t SCL = 3;
  92. #define LED_BUILTIN 13
  93. // Map SPI port to 'new' pins D14..D17
  94. static const uint8_t SS = 17;
  95. static const uint8_t MOSI = 16;
  96. static const uint8_t MISO = 14;
  97. static const uint8_t SCK = 15;
  98. // Mapping of analog pins as digital I/O
  99. // A6-A11 share with digital pins
  100. static const uint8_t ADC0 = 18;
  101. static const uint8_t ADC1 = 19;
  102. static const uint8_t ADC2 = 20;
  103. static const uint8_t ADC3 = 21;
  104. static const uint8_t ADC4 = 22;
  105. static const uint8_t ADC5 = 23;
  106. static const uint8_t ADC6 = 24; // D4
  107. static const uint8_t ADC7 = 25; // D6
  108. static const uint8_t ADC8 = 26; // D8
  109. static const uint8_t ADC9 = 27; // D9
  110. static const uint8_t ADC10 = 28; // D10
  111. static const uint8_t ADC11 = 29; // D12
  112. #define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0))
  113. #define digitalPinToPCICRbit(p) 0
  114. #define digitalPinToPCMSK(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0))
  115. #define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4))))))
  116. // __AVR_ATmega32U4__ has an unusual mapping of pins to channels
  117. extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
  118. #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
  119. #define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT)))))
  120. #ifdef ARDUINO_MAIN
  121. // On the Arduino board, digital pins are also used
  122. // for the analog output (software PWM). Analog input
  123. // pins are a separate set.
  124. // ATMEL ATMEGA32U4 / ARDUINO LEONARDO
  125. //
  126. // D0 PD2 RXD1/INT2
  127. // D1 PD3 TXD1/INT3
  128. // D2 PD1 SDA SDA/INT1
  129. // D3# PD0 PWM8/SCL OC0B/SCL/INT0
  130. // D4 A6 PD4 ADC8
  131. // D5# PC6 ??? OC3A/#OC4A
  132. // D6# A7 PD7 FastPWM #OC4D/ADC10
  133. // D7 PE6 INT6/AIN0
  134. //
  135. // D8 A8 PB4 ADC11/PCINT4
  136. // D9# A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5
  137. // D10# A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6
  138. // D11# PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7
  139. // D12 A11 PD6 T1/#OC4D/ADC9
  140. // D13# PC7 PWM10 CLK0/OC4A
  141. //
  142. // A0 D18 PF7 ADC7
  143. // A1 D19 PF6 ADC6
  144. // A2 D20 PF5 ADC5
  145. // A3 D21 PF4 ADC4
  146. // A4 D22 PF1 ADC1
  147. // A5 D23 PF0 ADC0
  148. //
  149. // New pins D14..D17 to map SPI port to digital pins
  150. //
  151. // MISO D14 PB3 MISO,PCINT3
  152. // SCK D15 PB1 SCK,PCINT1
  153. // MOSI D16 PB2 MOSI,PCINT2
  154. // SS D17 PB0 RXLED,SS/PCINT0
  155. //
  156. // Connected LEDs on board for TX and RX
  157. // TXLED D24 PD5 XCK1
  158. // RXLED D17 PB0
  159. // HWB PE2 HWB
  160. // these arrays map port names (e.g. port B) to the
  161. // appropriate addresses for various functions (e.g. reading
  162. // and writing)
  163. const uint16_t PROGMEM port_to_mode_PGM[] = {
  164. NOT_A_PORT,
  165. NOT_A_PORT,
  166. (uint16_t) &DDRB,
  167. (uint16_t) &DDRC,
  168. (uint16_t) &DDRD,
  169. (uint16_t) &DDRE,
  170. (uint16_t) &DDRF,
  171. };
  172. const uint16_t PROGMEM port_to_output_PGM[] = {
  173. NOT_A_PORT,
  174. NOT_A_PORT,
  175. (uint16_t) &PORTB,
  176. (uint16_t) &PORTC,
  177. (uint16_t) &PORTD,
  178. (uint16_t) &PORTE,
  179. (uint16_t) &PORTF,
  180. };
  181. const uint16_t PROGMEM port_to_input_PGM[] = {
  182. NOT_A_PORT,
  183. NOT_A_PORT,
  184. (uint16_t) &PINB,
  185. (uint16_t) &PINC,
  186. (uint16_t) &PIND,
  187. (uint16_t) &PINE,
  188. (uint16_t) &PINF,
  189. };
  190. const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
  191. PD, // D0 - PD2
  192. PD, // D1 - PD3
  193. PD, // D2 - PD1
  194. PD, // D3 - PD0
  195. PD, // D4 - PD4
  196. PC, // D5 - PC6
  197. PD, // D6 - PD7
  198. PE, // D7 - PE6
  199. PB, // D8 - PB4
  200. PB, // D9 - PB5
  201. PB, // D10 - PB6
  202. PB, // D11 - PB7
  203. PD, // D12 - PD6
  204. PC, // D13 - PC7
  205. PB, // D14 - MISO - PB3
  206. PB, // D15 - SCK - PB1
  207. PB, // D16 - MOSI - PB2
  208. PB, // D17 - SS - PB0
  209. PF, // D18 - A0 - PF7
  210. PF, // D19 - A1 - PF6
  211. PF, // D20 - A2 - PF5
  212. PF, // D21 - A3 - PF4
  213. PF, // D22 - A4 - PF1
  214. PF, // D23 - A5 - PF0
  215. PD, // D24 - PD5
  216. PD, // D25 / D6 - A7 - PD7
  217. PB, // D26 / D8 - A8 - PB4
  218. PB, // D27 / D9 - A9 - PB5
  219. PB, // D28 / D10 - A10 - PB6
  220. PD, // D29 / D12 - A11 - PD6
  221. };
  222. const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
  223. _BV(2), // D0 - PD2
  224. _BV(3), // D1 - PD3
  225. _BV(1), // D2 - PD1
  226. _BV(0), // D3 - PD0
  227. _BV(4), // D4 - PD4
  228. _BV(6), // D5 - PC6
  229. _BV(7), // D6 - PD7
  230. _BV(6), // D7 - PE6
  231. _BV(4), // D8 - PB4
  232. _BV(5), // D9 - PB5
  233. _BV(6), // D10 - PB6
  234. _BV(7), // D11 - PB7
  235. _BV(6), // D12 - PD6
  236. _BV(7), // D13 - PC7
  237. _BV(3), // D14 - MISO - PB3
  238. _BV(1), // D15 - SCK - PB1
  239. _BV(2), // D16 - MOSI - PB2
  240. _BV(0), // D17 - SS - PB0
  241. _BV(7), // D18 - A0 - PF7
  242. _BV(6), // D19 - A1 - PF6
  243. _BV(5), // D20 - A2 - PF5
  244. _BV(4), // D21 - A3 - PF4
  245. _BV(1), // D22 - A4 - PF1
  246. _BV(0), // D23 - A5 - PF0
  247. _BV(5), // D24 - PD5
  248. _BV(7), // D25 / D6 - A7 - PD7
  249. _BV(4), // D26 / D8 - A8 - PB4
  250. _BV(5), // D27 / D9 - A9 - PB5
  251. _BV(6), // D28 / D10 - A10 - PB6
  252. _BV(6), // D29 / D12 - A11 - PD6
  253. };
  254. const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
  255. NOT_ON_TIMER,
  256. NOT_ON_TIMER,
  257. NOT_ON_TIMER,
  258. TIMER0B, /* 3 */
  259. NOT_ON_TIMER,
  260. TIMER3A, /* 5 */
  261. TIMER4D, /* 6 */
  262. NOT_ON_TIMER,
  263. NOT_ON_TIMER,
  264. TIMER1A, /* 9 */
  265. TIMER1B, /* 10 */
  266. TIMER0A, /* 11 */
  267. NOT_ON_TIMER,
  268. TIMER4A, /* 13 */
  269. NOT_ON_TIMER,
  270. NOT_ON_TIMER,
  271. NOT_ON_TIMER,
  272. NOT_ON_TIMER,
  273. NOT_ON_TIMER,
  274. NOT_ON_TIMER,
  275. NOT_ON_TIMER,
  276. NOT_ON_TIMER,
  277. NOT_ON_TIMER,
  278. NOT_ON_TIMER,
  279. NOT_ON_TIMER,
  280. NOT_ON_TIMER,
  281. NOT_ON_TIMER,
  282. NOT_ON_TIMER,
  283. NOT_ON_TIMER,
  284. NOT_ON_TIMER,
  285. };
  286. const uint8_t PROGMEM analog_pin_to_channel_PGM[] = {
  287. 7, // A0 PF7 ADC7
  288. 6, // A1 PF6 ADC6
  289. 5, // A2 PF5 ADC5
  290. 4, // A3 PF4 ADC4
  291. 1, // A4 PF1 ADC1
  292. 0, // A5 PF0 ADC0
  293. 8, // A6 D4 PD4 ADC8
  294. 10, // A7 D6 PD7 ADC10
  295. 11, // A8 D8 PB4 ADC11
  296. 12, // A9 D9 PB5 ADC12
  297. 13, // A10 D10 PB6 ADC13
  298. 9 // A11 D12 PD6 ADC9
  299. };
  300. #endif /* ARDUINO_MAIN */
  301. // These serial port names are intended to allow libraries and architecture-neutral
  302. // sketches to automatically default to the correct port name for a particular type
  303. // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
  304. // the first hardware serial port whose RX/TX pins are not dedicated to another use.
  305. //
  306. // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
  307. //
  308. // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
  309. //
  310. // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
  311. //
  312. // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
  313. //
  314. // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
  315. // pins are NOT connected to anything by default.
  316. #define SERIAL_PORT_MONITOR Serial
  317. #define SERIAL_PORT_USBVIRTUAL Serial
  318. #define SERIAL_PORT_HARDWARE Serial1
  319. #define SERIAL_PORT_HARDWARE_OPEN Serial1