pins_arduino.h 6.3 KB

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