pins_arduino.h 8.1 KB

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