pins_arduino.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. Modified 2012 by Fredrik Hubinette
  6. Modified 2014-2015 by Matthew Wilson
  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. $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
  20. */
  21. #ifndef Pins_Arduino_h
  22. #define Pins_Arduino_h
  23. #include <avr/pgmspace.h>
  24. #define NUM_DIGITAL_PINS 48
  25. #define NUM_ANALOG_INPUTS 8
  26. // PE7 is our status LED
  27. #define TX_RX_LED_INIT DDRE |= (1<<7)
  28. #define TXLED0 0
  29. #define TXLED1 0
  30. #define RXLED0 PORTE |= (1<<7)
  31. #define RXLED1 PORTE &= ~(1<<7)
  32. static const uint8_t SDA = 1;
  33. static const uint8_t SCL = 0;
  34. // Map SPI port to 'new' pins D14..D17
  35. static const uint8_t SS = 20;
  36. static const uint8_t MOSI = 22;
  37. static const uint8_t MISO = 23;
  38. static const uint8_t SCK = 21;
  39. // Mapping of analog pins as digital I/O
  40. // A6-A11 share with digital pins
  41. static const uint8_t A0 = 38; // F0
  42. static const uint8_t A1 = 39; // F1
  43. static const uint8_t A2 = 40; // F2
  44. static const uint8_t A3 = 41; // F3
  45. static const uint8_t A4 = 42; // F4
  46. static const uint8_t A5 = 43; // F5
  47. static const uint8_t A6 = 44; // F6
  48. static const uint8_t A7 = 45; // F7
  49. #define analogInputToDigitalPin(p) ((p < 8) ? (p) + 38 : -1)
  50. // Pins below still needs to be configured - Hubbe.
  51. #define digitalPinToPCICR(p) ((((p) >= 0 && (p) <= 3) || ((p) >= 18 && (p) <= 19) || ((p) >= 36 && (p) <= 37)) ? (&PCICR) : ((uint8_t *)0))
  52. #define digitalPinToPCICRbit(p) 0
  53. #define digitalPinToPCMSK(p) ((((p) >= 0 && (p) <= 3) || ((p) >= 18 && (p) <= 19) || ((p) >= 36 && (p) <= 37)) ? (&PCMSK0) : ((uint8_t *)0))
  54. #define digitalPinToPCMSKbit(p) ( ((p) >= 0 && (p) <= 3) ? (p) : ((p) == 18 ? 6 : ((p) == 19 ? 7 : ((p) == 36 ? 4 : ((p) == 37 ? 5 : (-1))))))
  55. #define digitalPinHasPWM(p) ((p) == 0 || (p) == 1 || (p) == 14 || (p) == 15 || (p) == 16 || (p) == 24 || (p) == 25 || (p) == 26 || (p) == 27)
  56. // __AVR_ATmega32U4__ has an unusual mapping of pins to channels
  57. extern const uint8_t PROGMEM analog_pin_to_channel_PGM[];
  58. #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) )
  59. #ifdef ARDUINO_MAIN
  60. // these arrays map port names (e.g. port B) to the
  61. // appropriate addresses for various functions (e.g. reading
  62. // and writing)
  63. // Note PA == 1, PB == 2, etc. (GAH!)
  64. const uint16_t PROGMEM port_to_mode_PGM[] = {
  65. NOT_A_PORT,
  66. (uint16_t) &DDRA,
  67. (uint16_t) &DDRB,
  68. (uint16_t) &DDRC,
  69. (uint16_t) &DDRD,
  70. (uint16_t) &DDRE,
  71. };
  72. const uint16_t PROGMEM port_to_output_PGM[] = {
  73. NOT_A_PORT,
  74. (uint16_t) &PORTA,
  75. (uint16_t) &PORTB,
  76. (uint16_t) &PORTC,
  77. (uint16_t) &PORTD,
  78. (uint16_t) &PORTE,
  79. };
  80. const uint16_t PROGMEM port_to_input_PGM[] = {
  81. NOT_A_PORT,
  82. (uint16_t) &PINA,
  83. (uint16_t) &PINB,
  84. (uint16_t) &PINC,
  85. (uint16_t) &PIND,
  86. (uint16_t) &PINE,
  87. };
  88. const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
  89. PD, // 0 - PD0 - INT0 - PWM
  90. PD, // 1 - PD1 - INT1 - PWM
  91. PD, // 2 - PD2 - INT2 - RX
  92. PD, // 3 - PD3 - INT3 - TX
  93. PD, // 4 - PD4
  94. PD, // 5 - PD5
  95. PD, // 6 - PD6
  96. PD, // 7 - PD7
  97. PE, // 8 - PE0
  98. PE, // 9 - PE1
  99. PC, // 10 - PC0
  100. PC, // 11 - PC1
  101. PC, // 12 - PC2
  102. PC, // 13 - PC3
  103. PC, // 14 - PC4 - PWM
  104. PC, // 15 - PC5 - PWM
  105. PC, // 16 - PC6 - PWM
  106. PC, // 17 - PC7
  107. PE, // 18 - PE6 - INT6
  108. PE, // 19 - PE7 - INT7
  109. PB, // 20 - PB0
  110. PB, // 21 - PB1
  111. PB, // 22 - PB2
  112. PB, // 23 - PB3
  113. PB, // 24 - PB4 - PWM
  114. PB, // 25 - PB5 - PWM
  115. PB, // 26 - PB6 - PWM
  116. PB, // 27 - PB7 - PWM
  117. PA, // 28 - PA0
  118. PA, // 29 - PA1
  119. PA, // 30 - PA2
  120. PA, // 31 - PA3
  121. PA, // 32 - PA4
  122. PA, // 33 - PA5
  123. PA, // 34 - PA6
  124. PA, // 35 - PA7
  125. PE, // 36 - PE4 - INT4
  126. PE, // 37 - PE5 - INT5
  127. PF, // 38 - PF0 - A0
  128. PF, // 39 - PF1 - A1
  129. PF, // 40 - PF2 - A2
  130. PF, // 41 - PF3 - A3
  131. PF, // 42 - PF4 - A4
  132. PF, // 43 - PF5 - A5
  133. PF, // 44 - PF6 - A6
  134. PF, // 45 - PF7 - A7
  135. PE, // 46 - PE2 (not defined in teensy)
  136. PE, // 47 - PE3 (not defined in teensy)
  137. };
  138. const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
  139. _BV(0), // 0 - PD0 - INT0 - PWM
  140. _BV(1), // 1 - PD1 - INT1 - PWM
  141. _BV(2), // 2 - PD2 - INT2 - RX
  142. _BV(3), // 3 - PD3 - INT3 - TX
  143. _BV(4), // 4 - PD4
  144. _BV(5), // 5 - PD5
  145. _BV(6), // 6 - PD6
  146. _BV(7), // 7 - PD7
  147. _BV(0), // 8 - PE0
  148. _BV(1), // 9 - PE1
  149. _BV(0), // 10 - PC0
  150. _BV(1), // 11 - PC1
  151. _BV(2), // 12 - PC2
  152. _BV(3), // 13 - PC3
  153. _BV(4), // 14 - PC4 - PWM
  154. _BV(5), // 15 - PC5 - PWM
  155. _BV(6), // 16 - PC6 - PWM
  156. _BV(7), // 17 - PC7
  157. _BV(6), // 18 - PE6 - INT6
  158. _BV(7), // 19 - PE7 - INT7
  159. _BV(0), // 20 - PB0
  160. _BV(1), // 21 - PB1
  161. _BV(2), // 22 - PB2
  162. _BV(3), // 23 - PB3
  163. _BV(4), // 24 - PB4 - PWM
  164. _BV(5), // 25 - PB5 - PWM
  165. _BV(6), // 26 - PB6 - PWM
  166. _BV(7), // 27 - PB7 - PWM
  167. _BV(0), // 28 - PA0
  168. _BV(1), // 29 - PA1
  169. _BV(2), // 30 - PA2
  170. _BV(3), // 31 - PA3
  171. _BV(4), // 32 - PA4
  172. _BV(5), // 33 - PA5
  173. _BV(6), // 34 - PA6
  174. _BV(7), // 35 - PA7
  175. _BV(4), // 36 - PE4 - INT4
  176. _BV(5), // 37 - PE5 - INT5
  177. _BV(0), // 38 - PF0 - A0
  178. _BV(1), // 39 - PF1 - A1
  179. _BV(2), // 40 - PF2 - A2
  180. _BV(3), // 41 - PF3 - A3
  181. _BV(4), // 42 - PF4 - A4
  182. _BV(5), // 43 - PF5 - A5
  183. _BV(6), // 44 - PF6 - A6
  184. _BV(7), // 45 - PF7 - A7
  185. _BV(2), // 46 - PE2 (not defined in teensy)
  186. _BV(3), // 47 - PE3 (not defined in teensy)
  187. };
  188. // TODO(unrepentantgeek) complete this map of PWM capable pins
  189. const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
  190. TIMER0A, // 0 - PD0 - INT0 - PWM
  191. TIMER2B, // 1 - PD1 - INT1 - PWM
  192. NOT_ON_TIMER, // 2 - PD2 - INT2 - RX
  193. NOT_ON_TIMER, // 3 - PD3 - INT3 - TX
  194. NOT_ON_TIMER, // 4 - PD4
  195. NOT_ON_TIMER, // 5 - PD5
  196. NOT_ON_TIMER, // 6 - PD6
  197. NOT_ON_TIMER, // 7 - PD7
  198. NOT_ON_TIMER, // 8 - PE0
  199. NOT_ON_TIMER, // 9 - PE1
  200. NOT_ON_TIMER, // 10 - PC0
  201. NOT_ON_TIMER, // 11 - PC1
  202. NOT_ON_TIMER, // 12 - PC2
  203. NOT_ON_TIMER, // 13 - PC3
  204. TIMER3C, // 14 - PC4 - PWM
  205. TIMER3B, // 15 - PC5 - PWM
  206. TIMER3A, // 16 - PC6 - PWM
  207. NOT_ON_TIMER, // 17 - PC7
  208. NOT_ON_TIMER, // 18 - PE6 - INT6
  209. NOT_ON_TIMER, // 19 - PE7 - INT7
  210. NOT_ON_TIMER, // 20 - PB0
  211. NOT_ON_TIMER, // 21 - PB1
  212. NOT_ON_TIMER, // 22 - PB2
  213. NOT_ON_TIMER, // 23 - PB3
  214. TIMER2A, // 24 - PB4 - PWM
  215. TIMER1A, // 25 - PB5 - PWM
  216. TIMER1B, // 26 - PB6 - PWM
  217. NOT_ON_TIMER, // 27 - PB7 - PWM // This should be on TIMER1C
  218. NOT_ON_TIMER, // 28 - PA0
  219. NOT_ON_TIMER, // 29 - PA1
  220. NOT_ON_TIMER, // 30 - PA2
  221. NOT_ON_TIMER, // 31 - PA3
  222. NOT_ON_TIMER, // 32 - PA4
  223. NOT_ON_TIMER, // 33 - PA5
  224. NOT_ON_TIMER, // 34 - PA6
  225. NOT_ON_TIMER, // 35 - PA7
  226. NOT_ON_TIMER, // 36 - PE4 - INT4
  227. NOT_ON_TIMER, // 37 - PE5 - INT5
  228. NOT_ON_TIMER, // 38 - PF0 - A0
  229. NOT_ON_TIMER, // 39 - PF1 - A1
  230. NOT_ON_TIMER, // 40 - PF2 - A2
  231. NOT_ON_TIMER, // 41 - PF3 - A3
  232. NOT_ON_TIMER, // 42 - PF4 - A4
  233. NOT_ON_TIMER, // 43 - PF5 - A5
  234. NOT_ON_TIMER, // 44 - PF6 - A6
  235. NOT_ON_TIMER, // 45 - PF7 - A7
  236. NOT_ON_TIMER, // 46 - PE2 (not defined in teensy)
  237. NOT_ON_TIMER, // 47 - PE3 (not defined in teensy)
  238. };
  239. const uint8_t PROGMEM analog_pin_to_channel_PGM[8] = {
  240. 0, // A0 PF0 ADC0
  241. 1, // A1 PF1 ADC1
  242. 2, // A2 PF2 ADC2
  243. 3, // A3 PF3 ADC3
  244. 4, // A4 PF4 ADC4
  245. 5, // A5 PF5 ADC5
  246. 6, // A6 PD6 ADC6
  247. 7, // A7 PD7 ADC7
  248. };
  249. #endif /* ARDUINO_MAIN */
  250. #endif /* Pins_Arduino_h */