pins_arduino.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. Changelog
  19. -----------
  20. 11/25/11 - ryan@ryanmsutton.com - Add pins for Sanguino 644P and 1284P
  21. 07/15/12 - ryan@ryanmsutton.com - Updated for arduino0101
  22. */
  23. #ifndef Pins_Arduino_h
  24. #define Pins_Arduino_h
  25. #include <avr/pgmspace.h>
  26. #define NOT_A_PIN 0
  27. #define NOT_A_PORT 0
  28. #define NOT_ON_TIMER 0
  29. #define TIMER0A 1
  30. #define TIMER0B 2
  31. #define TIMER1A 3
  32. #define TIMER1B 4
  33. #define TIMER2 5
  34. #define TIMER2A 6
  35. #define TIMER2B 7
  36. #define TIMER3A 8
  37. #define TIMER3B 9
  38. #define TIMER3C 10
  39. #define TIMER4A 11
  40. #define TIMER4B 12
  41. #define TIMER4C 13
  42. #define TIMER4D 14
  43. #define TIMER5A 15
  44. #define TIMER5B 16
  45. #define TIMER5C 17
  46. const static uint8_t SS = 4;
  47. const static uint8_t MOSI = 5;
  48. const static uint8_t MISO = 6;
  49. const static uint8_t SCK = 7;
  50. static const uint8_t SDA = 17;
  51. static const uint8_t SCL = 16;
  52. static const uint8_t LED_BUILTIN = 13;
  53. static const uint8_t A0 = 31;
  54. static const uint8_t A1 = 30;
  55. static const uint8_t A2 = 29;
  56. static const uint8_t A3 = 28;
  57. static const uint8_t A4 = 27;
  58. static const uint8_t A5 = 26;
  59. static const uint8_t A6 = 25;
  60. static const uint8_t A7 = 24;
  61. // On the ATmega1280, the addresses of some of the port registers are
  62. // greater than 255, so we can't store them in uint8_t's.
  63. // extern const uint16_t PROGMEM port_to_mode_PGM[];
  64. // extern const uint16_t PROGMEM port_to_input_PGM[];
  65. // extern const uint16_t PROGMEM port_to_output_PGM[];
  66. // extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
  67. // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
  68. // extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
  69. // extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
  70. // ATMEL ATMEGA644P / SANGUINO
  71. //
  72. // +---\/---+
  73. // INT0 (D 0) PB0 1| |40 PA0 (AI 0 / D31)
  74. // INT1 (D 1) PB1 2| |39 PA1 (AI 1 / D30)
  75. // INT2 (D 2) PB2 3| |38 PA2 (AI 2 / D29)
  76. // PWM (D 3) PB3 4| |37 PA3 (AI 3 / D28)
  77. // PWM (D 4) PB4 5| |36 PA4 (AI 4 / D27)
  78. // MOSI (D 5) PB5 6| |35 PA5 (AI 5 / D26)
  79. // MISO (D 6) PB6 7| |34 PA6 (AI 6 / D25)
  80. // SCK (D 7) PB7 8| |33 PA7 (AI 7 / D24)
  81. // RST 9| |32 AREF
  82. // VCC 10| |31 GND
  83. // GND 11| |30 AVCC
  84. // XTAL2 12| |29 PC7 (D 23)
  85. // XTAL1 13| |28 PC6 (D 22)
  86. // RX0 (D 8) PD0 14| |27 PC5 (D 21) TDI
  87. // TX0 (D 9) PD1 15| |26 PC4 (D 20) TDO
  88. // RX1 (D 10) PD2 16| |25 PC3 (D 19) TMS
  89. // TX1 (D 11) PD3 17| |24 PC2 (D 18) TCK
  90. // PWM (D 12) PD4 18| |23 PC1 (D 17) SDA
  91. // PWM (D 13) PD5 19| |22 PC0 (D 16) SCL
  92. // PWM (D 14) PD6 20| |21 PD7 (D 15) PWM
  93. // +--------+
  94. //
  95. #define NUM_DIGITAL_PINS 24
  96. #define NUM_ANALOG_INPUTS 8
  97. #define analogInputToDigitalPin(p) ((p < NUM_ANALOG_INPUTS) ? 31 - (p) : -1)
  98. #define digitalPinHasPWM(p) ((p) == 3 || (p) == 4 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15 )
  99. #define digitalPinToPCICR(p) ( (((p) >= 0) && ((p) <= 31)) ? (&PCICR) : ((uint8_t *)0) )
  100. #define digitalPinToPCICRbit(p) ( (((p) >= 24) && ((p) <= 31)) ? 0 : \
  101. ( (((p) >= 0) && ((p) <= 7)) ? 1 : \
  102. ( (((p) >= 16) && ((p) <= 23)) ? 2 : \
  103. ( (((p) >= 8) && ((p) <= 15)) ? 3 : \
  104. 0 ) ) ) )
  105. #define digitalPinToPCMSK(p) ( (((p) >= 24) && ((p) <= 31)) ? (&PCMSK0) : \
  106. ( (((p) >= 0) && ((p) <= 7)) ? (&PCMSK1) : \
  107. ( (((p) >= 16) && ((p) <= 23)) ? (&PCMSK2) : \
  108. ( (((p) >= 8) && ((p) <= 15)) ? (&PCMSK3) : \
  109. ((uint8_t *)0) ) ) ) )
  110. #define digitalPinToPCMSKbit(p) ( (((p) >= 24) && ((p) <= 31)) ? (31 - (p)) : \
  111. ( (((p) >= 0) && ((p) <= 7)) ? (p) : \
  112. ( (((p) >= 16) && ((p) <= 23)) ? ((p) - 16) : \
  113. ( (((p) >= 8) && ((p) <= 15)) ? ((p) - 8) : \
  114. 0 ) ) ) )
  115. #define PA 1
  116. #define PB 2
  117. #define PC 3
  118. #define PD 4
  119. #define PE 5
  120. #define PF 6
  121. #define PG 7
  122. #define PH 8
  123. #define PJ 10
  124. #define PK 11
  125. #define PL 12
  126. #ifdef ARDUINO_MAIN
  127. // these arrays map port names (e.g. port B) to the
  128. // appropriate addresses for various functions (e.g. reading
  129. // and writing)
  130. const uint16_t PROGMEM port_to_mode_PGM[] =
  131. {
  132. NOT_A_PORT,
  133. (uint16_t) &DDRA,
  134. (uint16_t) &DDRB,
  135. (uint16_t) &DDRC,
  136. (uint16_t) &DDRD,
  137. };
  138. const uint16_t PROGMEM port_to_output_PGM[] =
  139. {
  140. NOT_A_PORT,
  141. (uint16_t) &PORTA,
  142. (uint16_t) &PORTB,
  143. (uint16_t) &PORTC,
  144. (uint16_t) &PORTD,
  145. };
  146. const uint16_t PROGMEM port_to_input_PGM[] =
  147. {
  148. NOT_A_PORT,
  149. (uint16_t) &PINA,
  150. (uint16_t) &PINB,
  151. (uint16_t) &PINC,
  152. (uint16_t) &PIND,
  153. };
  154. const uint8_t PROGMEM digital_pin_to_port_PGM[] =
  155. {
  156. PB, /* 0 */
  157. PB,
  158. PB,
  159. PB,
  160. PB,
  161. PB,
  162. PB,
  163. PB,
  164. PD, /* 8 */
  165. PD,
  166. PD,
  167. PD,
  168. PD,
  169. PD,
  170. PD,
  171. PD,
  172. PC, /* 16 */
  173. PC,
  174. PC,
  175. PC,
  176. PC,
  177. PC,
  178. PC,
  179. PC,
  180. PA, /* 24 */
  181. PA,
  182. PA,
  183. PA,
  184. PA,
  185. PA,
  186. PA,
  187. PA /* 31 */
  188. };
  189. const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
  190. {
  191. _BV(0), /* 0, port B */
  192. _BV(1),
  193. _BV(2),
  194. _BV(3),
  195. _BV(4),
  196. _BV(5),
  197. _BV(6),
  198. _BV(7),
  199. _BV(0), /* 8, port D */
  200. _BV(1),
  201. _BV(2),
  202. _BV(3),
  203. _BV(4),
  204. _BV(5),
  205. _BV(6),
  206. _BV(7),
  207. _BV(0), /* 16, port C */
  208. _BV(1),
  209. _BV(2),
  210. _BV(3),
  211. _BV(4),
  212. _BV(5),
  213. _BV(6),
  214. _BV(7),
  215. _BV(7), /* 24, port A */
  216. _BV(6),
  217. _BV(5),
  218. _BV(4),
  219. _BV(3),
  220. _BV(2),
  221. _BV(1),
  222. _BV(0)
  223. };
  224. const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
  225. {
  226. NOT_ON_TIMER, /* 0 - PB0 */
  227. NOT_ON_TIMER, /* 1 - PB1 */
  228. NOT_ON_TIMER, /* 2 - PB2 */
  229. TIMER0A, /* 3 - PB3 */
  230. TIMER0B, /* 4 - PB4 */
  231. NOT_ON_TIMER, /* 5 - PB5 */
  232. NOT_ON_TIMER, /* 6 - PB6 */
  233. NOT_ON_TIMER, /* 7 - PB7 */
  234. NOT_ON_TIMER, /* 8 - PD0 */
  235. NOT_ON_TIMER, /* 9 - PD1 */
  236. NOT_ON_TIMER, /* 10 - PD2 */
  237. NOT_ON_TIMER, /* 11 - PD3 */
  238. TIMER1B, /* 12 - PD4 */
  239. TIMER1A, /* 13 - PD5 */
  240. TIMER2B, /* 14 - PD6 */
  241. TIMER2A, /* 15 - PD7 */
  242. NOT_ON_TIMER, /* 16 - PC0 */
  243. NOT_ON_TIMER, /* 17 - PC1 */
  244. NOT_ON_TIMER, /* 18 - PC2 */
  245. NOT_ON_TIMER, /* 19 - PC3 */
  246. NOT_ON_TIMER, /* 20 - PC4 */
  247. NOT_ON_TIMER, /* 21 - PC5 */
  248. NOT_ON_TIMER, /* 22 - PC6 */
  249. NOT_ON_TIMER, /* 23 - PC7 */
  250. NOT_ON_TIMER, /* 24 - PA0 */
  251. NOT_ON_TIMER, /* 25 - PA1 */
  252. NOT_ON_TIMER, /* 26 - PA2 */
  253. NOT_ON_TIMER, /* 27 - PA3 */
  254. NOT_ON_TIMER, /* 28 - PA4 */
  255. NOT_ON_TIMER, /* 29 - PA5 */
  256. NOT_ON_TIMER, /* 30 - PA6 */
  257. NOT_ON_TIMER /* 31 - PA7 */
  258. };
  259. #endif
  260. #endif