BayEOSArduino Library
pins_arduino.h
1 /*
2  pins_arduino.h - Pin definition functions for Arduino
3  Part of Arduino - http://www.arduino.cc/
4 
5  Copyright (c) 2007 David A. Mellis
6  Adjusted for BayEOS Low Power Arduino (c) 2017 Stefan Holzheu
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General
19  Public License along with this library; if not, write to the
20  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21  Boston, MA 02111-1307 USA
22 */
23 
24 #ifndef Pins_Arduino_h
25 #define Pins_Arduino_h
26 
27 #include <avr/pgmspace.h>
28 
29 #define NUM_DIGITAL_PINS 20
30 #define NUM_ANALOG_INPUTS 6
31 #define analogInputToDigitalPin(p) ((p < 6) ? (p) + 14 : -1)
32 
33 #if defined(__AVR_ATmega8__)
34 #define digitalPinHasPWM(p) ((p) == 9 || (p) == 10 || (p) == 11)
35 #else
36 #define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
37 #endif
38 
39 static const uint8_t SS = 10;
40 static const uint8_t MOSI = 11;
41 static const uint8_t MISO = 12;
42 static const uint8_t SCK = 13;
43 
44 static const uint8_t SDA = 18;
45 static const uint8_t SCL = 19;
46 #define LED_BUILTIN 5
47 
48 static const uint8_t A0 = 14;
49 static const uint8_t A1 = 15;
50 static const uint8_t A2 = 16;
51 static const uint8_t A3 = 17;
52 static const uint8_t A4 = 18;
53 static const uint8_t A5 = 19;
54 static const uint8_t A6 = 20;
55 static const uint8_t A7 = 21;
56 
57 #define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0))
58 #define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
59 #define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
60 #define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))
61 
62 #define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT))
63 
64 #ifdef ARDUINO_MAIN
65 
66 // On the Arduino board, digital pins are also used
67 // for the analog output (software PWM). Analog input
68 // pins are a separate set.
69 
70 // ATMEL ATMEGA8 & 168 / ARDUINO
71 //
72 // +-\/-+
73 // PC6 1| |28 PC5 (AI 5)
74 // (D 0) PD0 2| |27 PC4 (AI 4)
75 // (D 1) PD1 3| |26 PC3 (AI 3)
76 // (D 2) PD2 4| |25 PC2 (AI 2)
77 // PWM+ (D 3) PD3 5| |24 PC1 (AI 1)
78 // (D 4) PD4 6| |23 PC0 (AI 0)
79 // VCC 7| |22 GND
80 // GND 8| |21 AREF
81 // PB6 9| |20 AVCC
82 // PB7 10| |19 PB5 (D 13)
83 // PWM+ (D 5) PD5 11| |18 PB4 (D 12)
84 // PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM
85 // (D 7) PD7 13| |16 PB2 (D 10) PWM
86 // (D 8) PB0 14| |15 PB1 (D 9) PWM
87 // +----+
88 //
89 // (PWM+ indicates the additional PWM pins on the ATmega168.)
90 
91 // ATMEL ATMEGA1280 / ARDUINO
92 //
93 // 0-7 PE0-PE7 works
94 // 8-13 PB0-PB5 works
95 // 14-21 PA0-PA7 works
96 // 22-29 PH0-PH7 works
97 // 30-35 PG5-PG0 works
98 // 36-43 PC7-PC0 works
99 // 44-51 PJ7-PJ0 works
100 // 52-59 PL7-PL0 works
101 // 60-67 PD7-PD0 works
102 // A0-A7 PF0-PF7
103 // A8-A15 PK0-PK7
104 
105 
106 // these arrays map port names (e.g. port B) to the
107 // appropriate addresses for various functions (e.g. reading
108 // and writing)
109 const uint16_t PROGMEM port_to_mode_PGM[] = {
110  NOT_A_PORT,
111  NOT_A_PORT,
112  (uint16_t) &DDRB,
113  (uint16_t) &DDRC,
114  (uint16_t) &DDRD,
115 };
116 
117 const uint16_t PROGMEM port_to_output_PGM[] = {
118  NOT_A_PORT,
119  NOT_A_PORT,
120  (uint16_t) &PORTB,
121  (uint16_t) &PORTC,
122  (uint16_t) &PORTD,
123 };
124 
125 const uint16_t PROGMEM port_to_input_PGM[] = {
126  NOT_A_PORT,
127  NOT_A_PORT,
128  (uint16_t) &PINB,
129  (uint16_t) &PINC,
130  (uint16_t) &PIND,
131 };
132 
133 const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
134  PD, /* 0 */
135  PD,
136  PD,
137  PD,
138  PD,
139  PD,
140  PD,
141  PD,
142  PB, /* 8 */
143  PB,
144  PB,
145  PB,
146  PB,
147  PB,
148  PC, /* 14 */
149  PC,
150  PC,
151  PC,
152  PC,
153  PC,
154 };
155 
156 const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
157  _BV(0), /* 0, port D */
158  _BV(1),
159  _BV(2),
160  _BV(3),
161  _BV(4),
162  _BV(5),
163  _BV(6),
164  _BV(7),
165  _BV(0), /* 8, port B */
166  _BV(1),
167  _BV(2),
168  _BV(3),
169  _BV(4),
170  _BV(5),
171  _BV(0), /* 14, port C */
172  _BV(1),
173  _BV(2),
174  _BV(3),
175  _BV(4),
176  _BV(5),
177 };
178 
179 const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
180  NOT_ON_TIMER, /* 0 - port D */
181  NOT_ON_TIMER,
182  NOT_ON_TIMER,
183  // on the ATmega168, digital pin 3 has hardware pwm
184 #if defined(__AVR_ATmega8__)
185  NOT_ON_TIMER,
186 #else
187  TIMER2B,
188 #endif
189  NOT_ON_TIMER,
190  // on the ATmega168, digital pins 5 and 6 have hardware pwm
191 #if defined(__AVR_ATmega8__)
192  NOT_ON_TIMER,
193  NOT_ON_TIMER,
194 #else
195  TIMER0B,
196  TIMER0A,
197 #endif
198  NOT_ON_TIMER,
199  NOT_ON_TIMER, /* 8 - port B */
200  TIMER1A,
201  TIMER1B,
202 #if defined(__AVR_ATmega8__)
203  TIMER2,
204 #else
205  TIMER2A,
206 #endif
207  NOT_ON_TIMER,
208  NOT_ON_TIMER,
209  NOT_ON_TIMER,
210  NOT_ON_TIMER, /* 14 - port C */
211  NOT_ON_TIMER,
212  NOT_ON_TIMER,
213  NOT_ON_TIMER,
214  NOT_ON_TIMER,
215 };
216 
217 #endif
218 
219 // These serial port names are intended to allow libraries and architecture-neutral
220 // sketches to automatically default to the correct port name for a particular type
221 // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
222 // the first hardware serial port whose RX/TX pins are not dedicated to another use.
223 //
224 // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
225 //
226 // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
227 //
228 // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
229 //
230 // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
231 //
232 // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
233 // pins are NOT connected to anything by default.
234 #define SERIAL_PORT_MONITOR Serial
235 #define SERIAL_PORT_HARDWARE Serial
236 
237 #endif