Keyboard firmwares for Atmel AVR and Cortex-M
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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