sanguino/cores/arduino/Arduino.h

Fri, 17 Nov 2017 10:13:31 +0100

author
mdd
date
Fri, 17 Nov 2017 10:13:31 +0100
changeset 3
770b218a4931
parent 2
b373b0288715
permissions
-rw-r--r--

proper configuration, homing and planner optimization

2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
1 #ifndef Arduino_h
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
2 #define Arduino_h
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
4 #include <stdlib.h>
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
5 #include <string.h>
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
6 #include <math.h>
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
7
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
8 #include <avr/pgmspace.h>
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
9 #include <avr/io.h>
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
10 #include <avr/interrupt.h>
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
11
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
12 #include "binary.h"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
13
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
14 #ifdef __cplusplus
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
15 extern "C"{
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
16 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
17
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
18 #define HIGH 0x1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
19 #define LOW 0x0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
20
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
21 #define INPUT 0x0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
22 #define OUTPUT 0x1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
23 #define INPUT_PULLUP 0x2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
24
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
25 #define true 0x1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
26 #define false 0x0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
27
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
28 #define PI 3.1415926535897932384626433832795
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
29 #define HALF_PI 1.5707963267948966192313216916398
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
30 #define TWO_PI 6.283185307179586476925286766559
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
31 #define DEG_TO_RAD 0.017453292519943295769236907684886
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
32 #define RAD_TO_DEG 57.295779513082320876798154814105
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
33
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
34 #define SERIAL 0x0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
35 #define DISPLAY 0x1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
36
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
37 #define LSBFIRST 0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
38 #define MSBFIRST 1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
39
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
40 #define CHANGE 1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
41 #define FALLING 2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
42 #define RISING 3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
43
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
44 #if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
45 #define DEFAULT 0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
46 #define EXTERNAL 1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
47 #define INTERNAL 2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
48 #else
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
49 #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
50 #define INTERNAL1V1 2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
51 #define INTERNAL2V56 3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
52 #else
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
53 #define INTERNAL 3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
54 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
55 #define DEFAULT 1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
56 #define EXTERNAL 0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
57 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
58
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
59 // undefine stdlib's abs if encountered
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
60 #ifdef abs
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
61 #undef abs
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
62 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
63
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
64 #define min(a,b) ((a)<(b)?(a):(b))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
65 #define max(a,b) ((a)>(b)?(a):(b))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
66 #define abs(x) ((x)>0?(x):-(x))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
67 #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
68 #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
69 #define radians(deg) ((deg)*DEG_TO_RAD)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
70 #define degrees(rad) ((rad)*RAD_TO_DEG)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
71 #define sq(x) ((x)*(x))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
72
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
73 #define interrupts() sei()
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
74 #define noInterrupts() cli()
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
75
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
76 #define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
77 #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
78 #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
79
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
80 #define lowByte(w) ((uint8_t) ((w) & 0xff))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
81 #define highByte(w) ((uint8_t) ((w) >> 8))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
82
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
83 #define bitRead(value, bit) (((value) >> (bit)) & 0x01)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
84 #define bitSet(value, bit) ((value) |= (1UL << (bit)))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
85 #define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
86 #define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
87
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
88
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
89 typedef unsigned int word;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
90
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
91 #define bit(b) (1UL << (b))
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
92
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
93 typedef uint8_t boolean;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
94 typedef uint8_t byte;
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
95
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
96 void init(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
97
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
98 void pinMode(uint8_t, uint8_t);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
99 void digitalWrite(uint8_t, uint8_t);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
100 int digitalRead(uint8_t);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
101 int analogRead(uint8_t);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
102 void analogReference(uint8_t mode);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
103 void analogWrite(uint8_t, int);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
104
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
105 unsigned long millis(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
106 unsigned long micros(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
107 void delay(unsigned long);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
108 void delayMicroseconds(unsigned int us);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
109 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
110
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
111 void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
112 uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
113
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
114 void attachInterrupt(uint8_t, void (*)(void), int mode);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
115 void detachInterrupt(uint8_t);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
116
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
117 void setup(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
118 void loop(void);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
119
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
120 // Get the bit location within the hardware port of the given virtual pin.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
121 // This comes from the pins_*.c file for the active board configuration.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
122
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
123 #define analogInPinToBit(P) (P)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
124
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
125 // On the ATmega1280, the addresses of some of the port registers are
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
126 // greater than 255, so we can't store them in uint8_t's.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
127 extern const uint16_t PROGMEM port_to_mode_PGM[];
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
128 extern const uint16_t PROGMEM port_to_input_PGM[];
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
129 extern const uint16_t PROGMEM port_to_output_PGM[];
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
130
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
131 extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
132 // extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
133 extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
134 extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
135
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
136 // Get the bit location within the hardware port of the given virtual pin.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
137 // This comes from the pins_*.c file for the active board configuration.
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
138 //
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
139 // These perform slightly better as macros compared to inline functions
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
140 //
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
141 #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
142 #define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
143 #define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
144 #define analogInPinToBit(P) (P)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
145 #define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
146 #define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
147 #define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
148
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
149 #define NOT_A_PIN 0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
150 #define NOT_A_PORT 0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
151
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
152 #ifdef ARDUINO_MAIN
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
153 #define PA 1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
154 #define PB 2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
155 #define PC 3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
156 #define PD 4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
157 #define PE 5
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
158 #define PF 6
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
159 #define PG 7
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
160 #define PH 8
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
161 #define PJ 10
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
162 #define PK 11
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
163 #define PL 12
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
164 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
165
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
166 #define NOT_ON_TIMER 0
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
167 #define TIMER0A 1
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
168 #define TIMER0B 2
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
169 #define TIMER1A 3
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
170 #define TIMER1B 4
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
171 #define TIMER2 5
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
172 #define TIMER2A 6
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
173 #define TIMER2B 7
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
174
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
175 #define TIMER3A 8
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
176 #define TIMER3B 9
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
177 #define TIMER3C 10
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
178 #define TIMER4A 11
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
179 #define TIMER4B 12
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
180 #define TIMER4C 13
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
181 #define TIMER4D 14
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
182 #define TIMER5A 15
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
183 #define TIMER5B 16
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
184 #define TIMER5C 17
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
185
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
186 #ifdef __cplusplus
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
187 } // extern "C"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
188 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
189
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
190 #ifdef __cplusplus
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
191 #include "WCharacter.h"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
192 #include "WString.h"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
193 #include "HardwareSerial.h"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
194
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
195 uint16_t makeWord(uint16_t w);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
196 uint16_t makeWord(byte h, byte l);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
197
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
198 #define word(...) makeWord(__VA_ARGS__)
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
199
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
200 unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
201
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
202 void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
203 void noTone(uint8_t _pin);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
204
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
205 // WMath prototypes
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
206 long random(long);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
207 long random(long, long);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
208 void randomSeed(unsigned int);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
209 long map(long, long, long, long, long);
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
210
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
211 #endif
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
212
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
213 #include "pins_arduino.h"
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
214
b373b0288715 added missing sanguino files
mbayer
parents:
diff changeset
215 #endif

mercurial