sketchbook
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Arduino.h
Go to the documentation of this file.
1 #ifndef Arduino_h
2 #define Arduino_h
3 
4 #include <stdint.h>
5 #include <stdbool.h>
6 
7 // picorv32: work-a-round; for size_t only - original Arduino.h does NOT have this!
8 #include <cstddef>
9 
10 /*#ifdef __cplusplus
11 extern "C"{
12 #endif
13 
14 void yield(void);*/
15 
16 #define reg_spictrl (*(volatile uint32_t*)0x02000000)
17 #define reg_uart_clkdiv (*(volatile uint32_t*)0x02000004)
18 #define reg_uart_data (*(volatile uint32_t*)0x02000008)
19 #define reg_outp (*(volatile uint32_t*)0x03000000) // contains reg_leds also
20 //#define reg_inp_zero (*(volatile uint32_t*)0x04000000)
21 #define reg_inp (*(volatile uint32_t*)0x05000000)
22 //#define reg_outp2 (*(volatile uint32_t*)0x06000000) // more output...
23 
24 #define F_CPU 12000000 // 12MHz
25 
26 #define clk_div_s (F_CPU) // 1s
27 #define clk_div_ms (F_CPU/1000) // 1ms
28 #define clk_div_us (F_CPU/1000000) // 1us
29 
30 #define HIGH 0x1
31 #define LOW 0x0
32 
33 #define INPUT 0x0
34 #define OUTPUT 0x1
35 #define INPUT_PULLUP 0x2
36 
37 #define PI 3.1415926535897932384626433832795
38 #define HALF_PI 1.5707963267948966192313216916398
39 #define TWO_PI 6.283185307179586476925286766559
40 #define DEG_TO_RAD 0.017453292519943295769236907684886
41 #define RAD_TO_DEG 57.295779513082320876798154814105
42 #define EULER 2.718281828459045235360287471352
43 
44 /*#define SERIAL 0x0
45 #define DISPLAY 0x1
46 
47 #define LSBFIRST 0
48 #define MSBFIRST 1
49 
50 #define CHANGE 1
51 #define FALLING 2
52 #define RISING 3
53 
54 #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
55  #define DEFAULT 0
56  #define EXTERNAL 1
57  #define INTERNAL1V1 2
58  #define INTERNAL INTERNAL1V1
59 #elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
60  #define DEFAULT 0
61  #define EXTERNAL 4
62  #define INTERNAL1V1 8
63  #define INTERNAL INTERNAL1V1
64  #define INTERNAL2V56 9
65  #define INTERNAL2V56_EXTCAP 13
66 #else
67 #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__)
68 #define INTERNAL1V1 2
69 #define INTERNAL2V56 3
70 #else
71 #define INTERNAL 3
72 #endif
73 #define DEFAULT 1
74 #define EXTERNAL 0
75 #endif
76 
77 // undefine stdlib's abs if encountered
78 #ifdef abs
79 #undef abs
80 #endif*/
81 
82 #define min(a,b) ((a)<(b)?(a):(b))
83 #define max(a,b) ((a)>(b)?(a):(b))
84 #define abs(x) ((x)>0?(x):-(x))
85 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
86 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
87 #define radians(deg) ((deg)*DEG_TO_RAD)
88 #define degrees(rad) ((rad)*RAD_TO_DEG)
89 #define sq(x) ((x)*(x))
90 
91 /*#define interrupts() sei()
92 #define noInterrupts() cli()*/
93 
94 #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
95 /*#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
96 #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
97 
98 #define lowByte(w) ((uint8_t) ((w) & 0xff))
99 #define highByte(w) ((uint8_t) ((w) >> 8))
100 
101 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
102 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
103 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
104 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
105 
106 // avr-libc defines _NOP() since 1.6.2
107 #ifndef _NOP
108 #define _NOP() do { __asm__ volatile ("nop"); } while (0)
109 #endif
110 
111 typedef unsigned int word;
112 
113 #define bit(b) (1UL << (b))
114 
115 typedef bool boolean;
116 typedef uint8_t byte;
117 
118 void init(void);
119 void initVariant(void);
120 
121 int atexit(void (*func)()) __attribute__((weak));*/
122 
123 typedef uint8_t byte;
124 
125 void pinMode(uint8_t, uint8_t);
126 void digitalWrite(uint8_t, uint8_t);
127 int digitalRead(uint8_t);
128 int analogRead(uint8_t);
129 //void analogReference(uint8_t mode);
130 void analogWrite(uint8_t, int);
131 
132 unsigned long millis(void);
133 unsigned long micros(void);
134 void delay(unsigned long);
135 /*inline void delayMicroseconds(unsigned int us) // picorv32 work-a-round; inline for speedup, still slow
136 {
137  // delays below 66 and 113 microseconds are not possible and the resolution
138  // is about 16-21 microseconds. the type and value of us passed may add cycles too.
139 #if F_CPU >= 12000000L
140  // numbers here are empiric estimates
141  if (us<=92) return;
142  us /= 16;
143  us -= 4; // important to have us >= 1 for next step (asm loop)
144  // busy wait (1x is 256 cycles, every further iteration is +197 cycles -> steps of ~16-21 us)
145  __asm__ __volatile__ (
146  "1: addi %0,%0,-1" "\n\t" // ? cycles
147  "bnez %0,1b" : "=r" (us) : "r" (us) // ? cycles
148  );
149 
150 #else
151  #warning "delayMicroseconds supports 12MHz clock only"
152 
153 
154 #endif
155 
156  // busy wait
157  // ...
158  return;
159 }*/
160 /*unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
161 unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
162 
163 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
164 uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
165 
166 void attachInterrupt(uint8_t, void (*)(void), int mode);
167 void detachInterrupt(uint8_t);*/
168 
169 //#define ASSERT_NOT_IMPLEMENTED // picorv32 work-a-round
170 //#define HALT_ON_ASSERT // picorv32 work-a-round - strict; not compatible with some examples
171 #if defined(ASSERT_NOT_IMPLEMENTED)
172 #warning ASSERT_NOT_IMPLEMENTED enabled. Check serial output for assertions. Baudrate is the one choosen or 115200 per default.
173 void assert(const bool, const char *); // picorv32 work-a-round
174 #endif
175 
176 void setup(void);
177 void loop(void);
178 
179 /*// Get the bit location within the hardware port of the given virtual pin.
180 // This comes from the pins_*.c file for the active board configuration.
181 
182 #define analogInPinToBit(P) (P)
183 
184 // On the ATmega1280, the addresses of some of the port registers are
185 // greater than 255, so we can't store them in uint8_t's.
186 extern const uint16_t PROGMEM port_to_mode_PGM[];
187 extern const uint16_t PROGMEM port_to_input_PGM[];
188 extern const uint16_t PROGMEM port_to_output_PGM[];
189 
190 extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
191 // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
192 extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
193 extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
194 
195 // Get the bit location within the hardware port of the given virtual pin.
196 // This comes from the pins_*.c file for the active board configuration.
197 //
198 // These perform slightly better as macros compared to inline functions
199 //
200 #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
201 #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
202 #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
203 #define analogInPinToBit(P) (P)
204 #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
205 #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
206 #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
207 
208 #define NOT_A_PIN 0
209 #define NOT_A_PORT 0
210 
211 #define NOT_AN_INTERRUPT -1
212 
213 #ifdef ARDUINO_MAIN
214 #define PA 1
215 #define PB 2
216 #define PC 3
217 #define PD 4
218 #define PE 5
219 #define PF 6
220 #define PG 7
221 #define PH 8
222 #define PJ 10
223 #define PK 11
224 #define PL 12
225 #endif
226 
227 #define NOT_ON_TIMER 0
228 #define TIMER0A 1
229 #define TIMER0B 2
230 #define TIMER1A 3
231 #define TIMER1B 4
232 #define TIMER1C 5
233 #define TIMER2 6
234 #define TIMER2A 7
235 #define TIMER2B 8
236 
237 #define TIMER3A 9
238 #define TIMER3B 10
239 #define TIMER3C 11
240 #define TIMER4A 12
241 #define TIMER4B 13
242 #define TIMER4C 14
243 #define TIMER4D 15
244 #define TIMER5A 16
245 #define TIMER5B 17
246 #define TIMER5C 18
247 
248 #ifdef __cplusplus
249 } // extern "C"
250 #endif*/
251 
252 #ifdef __cplusplus
253 //#include "WCharacter.h"
254 //#include "WString.h"
255 #include "HardwareSerial.h"
256 //#include "USBAPI.h"
257 #if defined(HAVE_HWSERIAL0) && defined(HAVE_CDCSERIAL)
258 #error "Targets with both UART0 and CDC serial not supported"
259 #endif
260 
261 /*uint16_t makeWord(uint16_t w);
262 uint16_t makeWord(byte h, byte l);
263 
264 #define word(...) makeWord(__VA_ARGS__)
265 
266 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
267 unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
268 
269 void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
270 void noTone(uint8_t _pin);
271 
272 // WMath prototypes
273 long random(long);
274 long random(long, long);
275 void randomSeed(unsigned long);*/
276 long map(long, long, long, long, long);
277 
278 #endif
279 
280 #include "pins_arduino.h"
281 
282 #endif
void pinMode(uint8_t, uint8_t)
Definition: main.cpp:278
void loop(void)
Definition: Due_AS7265X_Spectrometer.ino:127
uint8_t byte
Definition: Arduino.h:123
unsigned long micros(void)
Definition: main.cpp:258
void analogWrite(uint8_t, int)
Definition: main.cpp:351
void setup(void)
Definition: Due_AS7265X_Spectrometer.ino:55
void delay(unsigned long)
Definition: main.cpp:265
unsigned long millis(void)
Definition: main.cpp:251
int digitalRead(uint8_t)
Definition: main.cpp:323
long map(long x, long in_min, long in_max, long out_min, long out_max)
Definition: WMath.cpp:52
void digitalWrite(uint8_t, uint8_t)
Definition: main.cpp:298
int analogRead(uint8_t)
Definition: main.cpp:339