Arduino.h
Go to the documentation of this file.
1 /*
2  Arduino.h - Main include file for the Arduino SDK
3  Copyright (c) 2005-2013 Arduino Team. All right reserved.
4 
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 
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 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19 
20 #ifndef Arduino_h
21 #define Arduino_h
22 
23 #include <stdlib.h>
24 #include <stdbool.h>
25 #include <string.h>
26 #include <math.h>
27 
28 #include <avr/pgmspace.h>
29 #include <avr/io.h>
30 #include <avr/interrupt.h>
31 
32 #include "binary.h"
33 
34 #ifdef __cplusplus
35 extern "C"{
36 #endif
37 
38 void yield(void);
39 
40 #define HIGH 0x1
41 #define LOW 0x0
42 
43 #define INPUT 0x0
44 #define OUTPUT 0x1
45 #define INPUT_PULLUP 0x2
46 
47 #define PI 3.1415926535897932384626433832795
48 #define HALF_PI 1.5707963267948966192313216916398
49 #define TWO_PI 6.283185307179586476925286766559
50 #define DEG_TO_RAD 0.017453292519943295769236907684886
51 #define RAD_TO_DEG 57.295779513082320876798154814105
52 #define EULER 2.718281828459045235360287471352
53 
54 #define SERIAL 0x0
55 #define DISPLAY 0x1
56 
57 #define LSBFIRST 0
58 #define MSBFIRST 1
59 
60 #define CHANGE 1
61 #define FALLING 2
62 #define RISING 3
63 
64 #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
65  #define DEFAULT 0
66  #define EXTERNAL 1
67  #define INTERNAL1V1 2
68  #define INTERNAL INTERNAL1V1
69 #elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
70  #define DEFAULT 0
71  #define EXTERNAL 4
72  #define INTERNAL1V1 8
73  #define INTERNAL INTERNAL1V1
74  #define INTERNAL2V56 9
75  #define INTERNAL2V56_EXTCAP 13
76 #else
77 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
78 #define INTERNAL1V1 2
79 #define INTERNAL2V56 3
80 #else
81 #define INTERNAL 3
82 #endif
83 #define DEFAULT 1
84 #define EXTERNAL 0
85 #endif
86 
87 // undefine stdlib's abs if encountered
88 #ifdef abs
89 #undef abs
90 #endif
91 
92 #define min(a,b) ((a)<(b)?(a):(b))
93 #define max(a,b) ((a)>(b)?(a):(b))
94 #define abs(x) ((x)>0?(x):-(x))
95 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
96 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
97 #define radians(deg) ((deg)*DEG_TO_RAD)
98 #define degrees(rad) ((rad)*RAD_TO_DEG)
99 #define sq(x) ((x)*(x))
100 
101 #define interrupts() sei()
102 #define noInterrupts() cli()
103 
104 #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
105 #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
106 #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
107 
108 #define lowByte(w) ((uint8_t) ((w) & 0xff))
109 #define highByte(w) ((uint8_t) ((w) >> 8))
110 
111 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
112 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
113 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
114 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
115 
116 // avr-libc defines _NOP() since 1.6.2
117 #ifndef _NOP
118 #define _NOP() do { __asm__ volatile ("nop"); } while (0)
119 #endif
120 
121 typedef unsigned int word;
122 
123 #define bit(b) (1UL << (b))
124 
125 typedef bool boolean;
126 typedef uint8_t byte;
127 
128 void init(void);
129 void initVariant(void);
130 
131 int atexit(void (*func)()) __attribute__((weak));
132 
133 void pinMode(uint8_t, uint8_t);
134 void digitalWrite(uint8_t, uint8_t);
135 int digitalRead(uint8_t);
136 int analogRead(uint8_t);
137 void analogReference(uint8_t mode);
138 void analogWrite(uint8_t, int);
139 
140 unsigned long millis(void);
141 unsigned long micros(void);
142 void delay(unsigned long);
143 void delayMicroseconds(unsigned int us);
144 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
145 unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
146 
147 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
148 uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
149 
150 void attachInterrupt(uint8_t, void (*)(void), int mode);
151 void detachInterrupt(uint8_t);
152 
153 void setup(void);
154 void loop(void);
155 
156 // Get the bit location within the hardware port of the given virtual pin.
157 // This comes from the pins_*.c file for the active board configuration.
158 
159 #define analogInPinToBit(P) (P)
160 
161 // On the ATmega1280, the addresses of some of the port registers are
162 // greater than 255, so we can't store them in uint8_t's.
163 extern const uint16_t PROGMEM port_to_mode_PGM[];
164 extern const uint16_t PROGMEM port_to_input_PGM[];
165 extern const uint16_t PROGMEM port_to_output_PGM[];
166 
167 extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
168 // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
169 extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
170 extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
171 
172 // Get the bit location within the hardware port of the given virtual pin.
173 // This comes from the pins_*.c file for the active board configuration.
174 //
175 // These perform slightly better as macros compared to inline functions
176 //
177 #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
178 #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
179 #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
180 #define analogInPinToBit(P) (P)
181 #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
182 #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
183 #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
184 
185 #define NOT_A_PIN 0
186 #define NOT_A_PORT 0
187 
188 #define NOT_AN_INTERRUPT -1
189 
190 #ifdef ARDUINO_MAIN
191 #define PA 1
192 #define PB 2
193 #define PC 3
194 #define PD 4
195 #define PE 5
196 #define PF 6
197 #define PG 7
198 #define PH 8
199 #define PJ 10
200 #define PK 11
201 #define PL 12
202 #endif
203 
204 #define NOT_ON_TIMER 0
205 #define TIMER0A 1
206 #define TIMER0B 2
207 #define TIMER1A 3
208 #define TIMER1B 4
209 #define TIMER1C 5
210 #define TIMER2 6
211 #define TIMER2A 7
212 #define TIMER2B 8
213 
214 #define TIMER3A 9
215 #define TIMER3B 10
216 #define TIMER3C 11
217 #define TIMER4A 12
218 #define TIMER4B 13
219 #define TIMER4C 14
220 #define TIMER4D 15
221 #define TIMER5A 16
222 #define TIMER5B 17
223 #define TIMER5C 18
224 
225 #ifdef __cplusplus
226 } // extern "C"
227 #endif
228 
229 #ifdef __cplusplus
230 #include "WCharacter.h"
231 #include "WString.h"
232 #include "HardwareSerial.h"
233 #include "USBAPI.h"
234 #if defined(HAVE_HWSERIAL0) && defined(HAVE_CDCSERIAL)
235 #error "Targets with both UART0 and CDC serial not supported"
236 #endif
237 
238 uint16_t makeWord(uint16_t w);
239 uint16_t makeWord(byte h, byte l);
240 
241 #define word(...) makeWord(__VA_ARGS__)
242 
243 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
244 unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
245 
246 void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
247 void noTone(uint8_t _pin);
248 
249 // WMath prototypes
250 long random(long);
251 long random(long, long);
252 void randomSeed(unsigned long);
253 long map(long, long, long, long, long);
254 
255 #endif
256 
257 #include "pins_arduino.h"
258 
259 #endif
void pinMode(uint8_t, uint8_t)
void loop(void)
void delayMicroseconds(unsigned int us)
Definition: wiring.c:120
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
Definition: wiring_pulse.c:33
const uint8_t PROGMEM digital_pin_to_port_PGM[]
bool boolean
Definition: Arduino.h:125
GLubyte GLubyte GLubyte GLubyte w
void randomSeed(unsigned long seed)
Definition: WMath.cpp:28
uint8_t byte
Definition: Arduino.h:126
const uint16_t PROGMEM port_to_input_PGM[]
GLenum mode
void initVariant(void)
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
Definition: Tone.cpp:243
GLdouble l
void detachInterrupt(uint8_t)
Definition: WInterrupts.c:187
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder)
Definition: wiring_shift.c:25
unsigned long micros(void)
Definition: wiring.c:79
void analogWrite(uint8_t, int)
void attachInterrupt(uint8_t, void(*)(void), int mode)
Definition: WInterrupts.c:70
void analogReference(uint8_t mode)
Definition: wiring_analog.c:30
void noTone(uint8_t _pin)
Definition: Tone.cpp:480
long random(long howbig)
Definition: WMath.cpp:35
const uint8_t PROGMEM digital_pin_to_timer_PGM[]
unsigned int word
Definition: Arduino.h:121
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout)
Definition: wiring_pulse.c:63
const uint16_t PROGMEM port_to_output_PGM[]
void delay(unsigned long)
Definition: wiring.c:106
unsigned long millis(void)
Definition: wiring.c:65
int digitalRead(uint8_t)
long map(long x, long in_min, long in_max, long out_min, long out_max)
Definition: WMath.cpp:52
void init(void)
Definition: wiring.c:241
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[]
void digitalWrite(uint8_t, uint8_t)
const uint16_t PROGMEM port_to_mode_PGM[]
void yield(void)
int analogRead(uint8_t)
Definition: wiring_analog.c:38
GLuint GLfloat * val
int atexit(void(*func)()) __attribute__((weak))
unsigned int makeWord(unsigned int w)
Definition: WMath.cpp:57
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
Definition: wiring_shift.c:40


arduino_daq
Author(s):
autogenerated on Mon Jun 10 2019 12:46:03