pins_arduino.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. pins_arduino.h - Pin definition functions for Arduino
  3. Modified to meet the ATmega644, ATmega644P and ATmega1284P.
  4. Copyright (c) 2007 David A. Mellis
  5. Copyright (c) 2012 Markus "Traumflug" Hitter <mah@jump-ing.de>
  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. */
  19. /*
  20. It should be noted the Gen7 board doesn't really have all those I/O pins,
  21. most of them are hardwired on the base board already. So this pin layout
  22. matches that of the Sanguino board, like the previous versions.
  23. */
  24. #ifndef Pins_Arduino_h
  25. #define Pins_Arduino_h
  26. #include <avr/pgmspace.h>
  27. #define NUM_DIGITAL_PINS 32
  28. #define NUM_ANALOG_INPUTS 8
  29. #define analogInputToDigitalPin(p) ((p < 8) ? (p) + 24 : -1)
  30. #define digitalPinHasPWM(p) ((p) == 3 || (p) == 4 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15)
  31. static const uint8_t SS = 4;
  32. static const uint8_t MOSI = 5;
  33. static const uint8_t MISO = 6;
  34. static const uint8_t SCK = 7;
  35. static const uint8_t SDA = 17;
  36. static const uint8_t SCL = 16;
  37. static const uint8_t LED_BUILTIN = -1;
  38. static const uint8_t A0 = 24;
  39. static const uint8_t A1 = 25;
  40. static const uint8_t A2 = 26;
  41. static const uint8_t A3 = 27;
  42. static const uint8_t A4 = 28;
  43. static const uint8_t A5 = 29;
  44. static const uint8_t A6 = 20;
  45. static const uint8_t A7 = 21;
  46. #define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 33) ? (&PCICR) : ((uint8_t *)0))
  47. #define digitalPinToPCICRbit(p) (((p) <= 9) ? 2 : (((p) <= 23) ? 0 : 1))
  48. #define digitalPinToPCMSK(p) (((p) <= 9) ? (&PCMSK2) : (((p) <= 23) ? (&PCMSK0) : (((p) <= 33) ? (&PCMSK1) : ((uint8_t *)0))))
  49. #define digitalPinToPCMSKbit(p) (((p) <= 9) ? (p) : (((p) <= 23) ? ((p) - 10) : ((p) - 24)))
  50. #ifdef ARDUINO_MAIN
  51. // On the Gen7 board, digital pins are also used
  52. // for the analog output (software PWM). Analog input
  53. // pins are a separate set.
  54. // ATMEL ATMEGA644P / SANGUINO
  55. //
  56. // +---\/---+
  57. // INT0 (D 0) PB0 1| |40 PA0 (AI 0 / D31)
  58. // INT1 (D 1) PB1 2| |39 PA1 (AI 1 / D30)
  59. // INT2 (D 2) PB2 3| |38 PA2 (AI 2 / D29)
  60. // PWM (D 3) PB3 4| |37 PA3 (AI 3 / D28)
  61. // PWM (D 4) PB4 5| |36 PA4 (AI 4 / D27)
  62. // MOSI (D 5) PB5 6| |35 PA5 (AI 5 / D26)
  63. // MISO (D 6) PB6 7| |34 PA6 (AI 6 / D25)
  64. // SCK (D 7) PB7 8| |33 PA7 (AI 7 / D24)
  65. // RST 9| |32 AREF
  66. // VCC 10| |31 GND
  67. // GND 11| |30 AVCC
  68. // XTAL2 12| |29 PC7 (D 23)
  69. // XTAL1 13| |28 PC6 (D 22)
  70. // RX0 (D 8) PD0 14| |27 PC5 (D 21) TDI
  71. // TX0 (D 9) PD1 15| |26 PC4 (D 20) TDO
  72. // RX1 (D 10) PD2 16| |25 PC3 (D 19) TMS
  73. // TX1 (D 11) PD3 17| |24 PC2 (D 18) TCK
  74. // PWM (D 12) PD4 18| |23 PC1 (D 17) SDA
  75. // PWM (D 13) PD5 19| |22 PC0 (D 16) SCL
  76. // PWM (D 14) PD6 20| |21 PD7 (D 15) PWM
  77. // +--------+
  78. //
  79. // TX1 and RX1 are not available on the ATmega644.
  80. // these arrays map port names (e.g. port B) to the
  81. // appropriate addresses for various functions (e.g. reading
  82. // and writing)
  83. const uint16_t PROGMEM port_to_mode_PGM[] = {
  84. NOT_A_PORT,
  85. &DDRA,
  86. &DDRB,
  87. &DDRC,
  88. &DDRD,
  89. };
  90. const uint16_t PROGMEM port_to_output_PGM[] = {
  91. NOT_A_PORT,
  92. &PORTA,
  93. &PORTB,
  94. &PORTC,
  95. &PORTD,
  96. };
  97. const uint16_t PROGMEM port_to_input_PGM[] = {
  98. NOT_A_PORT,
  99. &PINA,
  100. &PINB,
  101. &PINC,
  102. &PIND,
  103. };
  104. const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
  105. PB, /* 0 */
  106. PB,
  107. PB,
  108. PB,
  109. PB,
  110. PB,
  111. PB,
  112. PB,
  113. PD, /* 8 */
  114. PD,
  115. PD,
  116. PD,
  117. PD,
  118. PD,
  119. PD,
  120. PD,
  121. PC, /* 16 */
  122. PC,
  123. PC,
  124. PC,
  125. PC,
  126. PC,
  127. PC,
  128. PC,
  129. PA, /* 24 */
  130. PA,
  131. PA,
  132. PA,
  133. PA,
  134. PA,
  135. PA,
  136. PA /* 31 */
  137. };
  138. const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
  139. _BV(0), /* 0, port B */
  140. _BV(1),
  141. _BV(2),
  142. _BV(3),
  143. _BV(4),
  144. _BV(5),
  145. _BV(6),
  146. _BV(7),
  147. _BV(0), /* 8, port D */
  148. _BV(1),
  149. _BV(2),
  150. _BV(3),
  151. _BV(4),
  152. _BV(5),
  153. _BV(6),
  154. _BV(7),
  155. _BV(0), /* 16, port C */
  156. _BV(1),
  157. _BV(2),
  158. _BV(3),
  159. _BV(4),
  160. _BV(5),
  161. _BV(6),
  162. _BV(7),
  163. _BV(7), /* 24, port A */
  164. _BV(6),
  165. _BV(5),
  166. _BV(4),
  167. _BV(3),
  168. _BV(2),
  169. _BV(1),
  170. _BV(0)
  171. };
  172. const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
  173. NOT_ON_TIMER, /* 0 - PB0 */
  174. NOT_ON_TIMER, /* 1 - PB1 */
  175. NOT_ON_TIMER, /* 2 - PB2 */
  176. TIMER0A, /* 3 - PB3 */
  177. TIMER0B, /* 4 - PB4 */
  178. NOT_ON_TIMER, /* 5 - PB5 */
  179. NOT_ON_TIMER, /* 6 - PB6 */
  180. NOT_ON_TIMER, /* 7 - PB7 */
  181. NOT_ON_TIMER, /* 8 - PD0 */
  182. NOT_ON_TIMER, /* 9 - PD1 */
  183. NOT_ON_TIMER, /* 10 - PD2 */
  184. NOT_ON_TIMER, /* 11 - PD3 */
  185. TIMER1B, /* 12 - PD4 */
  186. TIMER1A, /* 13 - PD5 */
  187. TIMER2B, /* 14 - PD6 */
  188. TIMER2A, /* 15 - PD7 */
  189. NOT_ON_TIMER, /* 16 - PC0 */
  190. NOT_ON_TIMER, /* 17 - PC1 */
  191. NOT_ON_TIMER, /* 18 - PC2 */
  192. NOT_ON_TIMER, /* 19 - PC3 */
  193. NOT_ON_TIMER, /* 20 - PC4 */
  194. NOT_ON_TIMER, /* 21 - PC5 */
  195. NOT_ON_TIMER, /* 22 - PC6 */
  196. NOT_ON_TIMER, /* 23 - PC7 */
  197. NOT_ON_TIMER, /* 24 - PA0 */
  198. NOT_ON_TIMER, /* 25 - PA1 */
  199. NOT_ON_TIMER, /* 26 - PA2 */
  200. NOT_ON_TIMER, /* 27 - PA3 */
  201. NOT_ON_TIMER, /* 28 - PA4 */
  202. NOT_ON_TIMER, /* 29 - PA5 */
  203. NOT_ON_TIMER, /* 30 - PA6 */
  204. NOT_ON_TIMER /* 31 - PA7 */
  205. };
  206. #endif /* ARDUINO_MAIN */
  207. #endif /* Pins_Arduino_h */