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