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