pins_arduino.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. Improvements by Kristian Lauszus, kristianl@tkjelectronics.dk
  23. */
  24. #ifndef Pins_Arduino_h
  25. #define Pins_Arduino_h
  26. #include <avr/pgmspace.h>
  27. const static uint8_t SS = 4;
  28. const static uint8_t MOSI = 5;
  29. const static uint8_t MISO = 6;
  30. const static uint8_t SCK = 7;
  31. static const uint8_t SDA = 17;
  32. static const uint8_t SCL = 16;
  33. #define LED_BUILTIN 0
  34. static const uint8_t A0 = 31;
  35. static const uint8_t A1 = 30;
  36. static const uint8_t A2 = 29;
  37. static const uint8_t A3 = 28;
  38. static const uint8_t A4 = 27;
  39. static const uint8_t A5 = 26;
  40. static const uint8_t A6 = 25;
  41. static const uint8_t A7 = 24;
  42. // ATMEL ATMEGA644/ATMEGA1284 / SANGUINO
  43. //
  44. // +---\/---+
  45. // (D 0) PB0 1| |40 PA0 (AI 0 / D31)
  46. // (D 1) PB1 2| |39 PA1 (AI 1 / D30)
  47. // INT2 (D 2) PB2 3| |38 PA2 (AI 2 / D29)
  48. // PWM (D 3) PB3 4| |37 PA3 (AI 3 / D28)
  49. // SS PWM (D 4) PB4 5| |36 PA4 (AI 4 / D27)
  50. // MOSI (D 5) PB5 6| |35 PA5 (AI 5 / D26)
  51. // MISO (D 6) PB6 7| |34 PA6 (AI 6 / D25)
  52. // SCK (D 7) PB7 8| |33 PA7 (AI 7 / D24)
  53. // RST 9| |32 AREF
  54. // VCC 10| |31 GND
  55. // GND 11| |30 AVCC
  56. // XTAL2 12| |29 PC7 (D 23)
  57. // XTAL1 13| |28 PC6 (D 22)
  58. // RX0 (D 8) PD0 14| |27 PC5 (D 21) TDI
  59. // TX0 (D 9) PD1 15| |26 PC4 (D 20) TDO
  60. // INT0 RX1 (D 10) PD2 16| |25 PC3 (D 19) TMS
  61. // INT1 TX1 (D 11) PD3 17| |24 PC2 (D 18) TCK
  62. // PWM (D 12) PD4 18| |23 PC1 (D 17) SDA
  63. // PWM (D 13) PD5 19| |22 PC0 (D 16) SCL
  64. // PWM (D 14) PD6 20| |21 PD7 (D 15) PWM
  65. // +--------+
  66. //
  67. #define NUM_DIGITAL_PINS 24
  68. #define NUM_ANALOG_INPUTS 8
  69. #define analogInputToDigitalPin(p) ((p < 8) ? 31 - (p): -1)
  70. #define analogPinToChannel(p) ((p < 8) ? (p) : 31 - (p))
  71. #define digitalPinHasPWM(p) ((p) == 3 || (p) == 4 || (p) == 12 || (p) == 13 || (p) == 14 || (p) == 15 )
  72. #define digitalPinToPCICR(p) ( (((p) >= 0) && ((p) <= 31)) ? (&PCICR) : ((uint8_t *)0) )
  73. #define digitalPinToPCICRbit(p) ( (((p) >= 24) && ((p) <= 31)) ? 0 : \
  74. ( (((p) >= 0) && ((p) <= 7)) ? 1 : \
  75. ( (((p) >= 16) && ((p) <= 23)) ? 2 : \
  76. ( (((p) >= 8) && ((p) <= 15)) ? 3 : \
  77. 0 ) ) ) )
  78. #define digitalPinToPCMSK(p) ( (((p) >= 24) && ((p) <= 31)) ? (&PCMSK0) : \
  79. ( (((p) >= 0) && ((p) <= 7)) ? (&PCMSK1) : \
  80. ( (((p) >= 16) && ((p) <= 23)) ? (&PCMSK2) : \
  81. ( (((p) >= 8) && ((p) <= 15)) ? (&PCMSK3) : \
  82. ((uint8_t *)0) ) ) ) )
  83. #define digitalPinToPCMSKbit(p) ( (((p) >= 24) && ((p) <= 31)) ? (31 - (p)) : \
  84. ( (((p) >= 0) && ((p) <= 7)) ? (p) : \
  85. ( (((p) >= 16) && ((p) <= 23)) ? ((p) - 16) : \
  86. ( (((p) >= 8) && ((p) <= 15)) ? ((p) - 8) : \
  87. 0 ) ) ) )
  88. #define digitalPinToInterrupt(p) ((p) == 10 ? 0 : ((p) == 11 ? 1 : ((p) == 2 ? 2 : NOT_AN_INTERRUPT)))
  89. #ifdef ARDUINO_MAIN
  90. // these arrays map port names (e.g. port B) to the
  91. // appropriate addresses for various functions (e.g. reading
  92. // and writing)
  93. const uint16_t PROGMEM port_to_mode_PGM[] =
  94. {
  95. NOT_A_PORT,
  96. (uint16_t) &DDRA,
  97. (uint16_t) &DDRB,
  98. (uint16_t) &DDRC,
  99. (uint16_t) &DDRD,
  100. };
  101. const uint16_t PROGMEM port_to_output_PGM[] =
  102. {
  103. NOT_A_PORT,
  104. (uint16_t) &PORTA,
  105. (uint16_t) &PORTB,
  106. (uint16_t) &PORTC,
  107. (uint16_t) &PORTD,
  108. };
  109. const uint16_t PROGMEM port_to_input_PGM[] =
  110. {
  111. NOT_A_PORT,
  112. (uint16_t) &PINA,
  113. (uint16_t) &PINB,
  114. (uint16_t) &PINC,
  115. (uint16_t) &PIND,
  116. };
  117. const uint8_t PROGMEM digital_pin_to_port_PGM[] =
  118. {
  119. PB, /* 0 */
  120. PB,
  121. PB,
  122. PB,
  123. PB,
  124. PB,
  125. PB,
  126. PB,
  127. PD, /* 8 */
  128. PD,
  129. PD,
  130. PD,
  131. PD,
  132. PD,
  133. PD,
  134. PD,
  135. PC, /* 16 */
  136. PC,
  137. PC,
  138. PC,
  139. PC,
  140. PC,
  141. PC,
  142. PC,
  143. PA, /* 24 */
  144. PA,
  145. PA,
  146. PA,
  147. PA,
  148. PA,
  149. PA,
  150. PA /* 31 */
  151. };
  152. const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
  153. {
  154. _BV(0), /* 0, port B */
  155. _BV(1),
  156. _BV(2),
  157. _BV(3),
  158. _BV(4),
  159. _BV(5),
  160. _BV(6),
  161. _BV(7),
  162. _BV(0), /* 8, port D */
  163. _BV(1),
  164. _BV(2),
  165. _BV(3),
  166. _BV(4),
  167. _BV(5),
  168. _BV(6),
  169. _BV(7),
  170. _BV(0), /* 16, port C */
  171. _BV(1),
  172. _BV(2),
  173. _BV(3),
  174. _BV(4),
  175. _BV(5),
  176. _BV(6),
  177. _BV(7),
  178. _BV(7), /* 24, port A */
  179. _BV(6),
  180. _BV(5),
  181. _BV(4),
  182. _BV(3),
  183. _BV(2),
  184. _BV(1),
  185. _BV(0)
  186. };
  187. const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
  188. {
  189. NOT_ON_TIMER, /* 0 - PB0 */
  190. NOT_ON_TIMER, /* 1 - PB1 */
  191. NOT_ON_TIMER, /* 2 - PB2 */
  192. TIMER0A, /* 3 - PB3 */
  193. TIMER0B, /* 4 - PB4 */
  194. NOT_ON_TIMER, /* 5 - PB5 */
  195. NOT_ON_TIMER, /* 6 - PB6 */
  196. NOT_ON_TIMER, /* 7 - PB7 */
  197. NOT_ON_TIMER, /* 8 - PD0 */
  198. NOT_ON_TIMER, /* 9 - PD1 */
  199. NOT_ON_TIMER, /* 10 - PD2 */
  200. NOT_ON_TIMER, /* 11 - PD3 */
  201. TIMER1B, /* 12 - PD4 */
  202. TIMER1A, /* 13 - PD5 */
  203. TIMER2B, /* 14 - PD6 */
  204. TIMER2A, /* 15 - PD7 */
  205. NOT_ON_TIMER, /* 16 - PC0 */
  206. NOT_ON_TIMER, /* 17 - PC1 */
  207. NOT_ON_TIMER, /* 18 - PC2 */
  208. NOT_ON_TIMER, /* 19 - PC3 */
  209. NOT_ON_TIMER, /* 20 - PC4 */
  210. NOT_ON_TIMER, /* 21 - PC5 */
  211. NOT_ON_TIMER, /* 22 - PC6 */
  212. NOT_ON_TIMER, /* 23 - PC7 */
  213. NOT_ON_TIMER, /* 24 - PA0 */
  214. NOT_ON_TIMER, /* 25 - PA1 */
  215. NOT_ON_TIMER, /* 26 - PA2 */
  216. NOT_ON_TIMER, /* 27 - PA3 */
  217. NOT_ON_TIMER, /* 28 - PA4 */
  218. NOT_ON_TIMER, /* 29 - PA5 */
  219. NOT_ON_TIMER, /* 30 - PA6 */
  220. NOT_ON_TIMER /* 31 - PA7 */
  221. };
  222. #endif
  223. // These serial port names are intended to allow libraries and architecture-neutral
  224. // sketches to automatically default to the correct port name for a particular type
  225. // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
  226. // the first hardware serial port whose RX/TX pins are not dedicated to another use.
  227. //
  228. // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
  229. //
  230. // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
  231. //
  232. // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
  233. //
  234. // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
  235. //
  236. // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
  237. // pins are NOT connected to anything by default.
  238. #define SERIAL_PORT_MONITOR Serial
  239. #define SERIAL_PORT_HARDWARE Serial
  240. #define SERIAL_PORT_HARDWARE1 Serial1
  241. #define SERIAL_PORT_HARDWARE_OPEN Serial1
  242. #endif