Thu, 07 Jul 2016 12:23:34 +0200
added missing sanguino files
0 | 1 | // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. |
2 | // Licence: GPL | |
3 | ||
4 | #ifndef MARLIN_H | |
5 | #define MARLIN_H | |
6 | ||
7 | #define FORCE_INLINE __attribute__((always_inline)) inline | |
8 | ||
9 | #include <math.h> | |
10 | #include <stdio.h> | |
11 | #include <stdlib.h> | |
12 | #include <string.h> | |
13 | #include <inttypes.h> | |
14 | ||
15 | #include <util/delay.h> | |
16 | #include <avr/pgmspace.h> | |
17 | #include <avr/eeprom.h> | |
18 | #include <avr/wdt.h> | |
19 | #include <avr/interrupt.h> | |
20 | ||
21 | ||
22 | #include "fastio.h" | |
23 | ||
24 | #include "Configuration.h" | |
25 | ||
26 | #ifndef REPRAPPRO_MULTIMATERIALS | |
27 | #define HardwareSerial_h // trick to disable the standard HWserial | |
28 | #endif | |
29 | #include "pins.h" | |
30 | ||
31 | #if ARDUINO >= 100 | |
32 | #include "Arduino.h" | |
33 | #else | |
34 | #include "WProgram.h" | |
35 | #endif | |
36 | ||
37 | #include "MarlinSerial.h" | |
38 | ||
39 | #ifndef cbi | |
40 | #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit)) | |
41 | #endif | |
42 | #ifndef sbi | |
43 | #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit)) | |
44 | #endif | |
45 | ||
46 | #include "WString.h" | |
47 | ||
48 | #ifdef REPRAPPRO_MULTIMATERIALS | |
49 | #define MYSERIAL Serial | |
50 | #define MYSERIAL1 Serial1 | |
51 | #else | |
52 | ||
53 | #if MOTHERBOARD == 8 // Teensylu | |
54 | #define MYSERIAL Serial | |
55 | #define MYSERIAL1 Serial1 | |
56 | #else | |
57 | #define MYSERIAL MSerial | |
58 | #endif | |
59 | ||
60 | #endif | |
61 | ||
62 | //this is a unfinsihed attemp to removes a lot of warning messages, see: | |
63 | // http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=57011 | |
64 | //typedef char prog_char PROGMEM; | |
65 | // //#define PSTR (s ) ((const PROGMEM char *)(s)) | |
66 | // //# define MYPGM(s) (__extension__({static prog_char __c[] = (s); &__c[0];})) | |
67 | // //#define MYPGM(s) ((const prog_char *g PROGMEM=s)) | |
68 | #define MYPGM(s) PSTR(s) | |
69 | //#define MYPGM(s) (__extension__({static char __c[] __attribute__((__progmem__)) = (s); &__c[0];})) //This is the normal behaviour | |
70 | //#define MYPGM(s) (__extension__({static prog_char __c[] = (s); &__c[0];})) //this does not work but hides the warnings | |
71 | ||
72 | ||
73 | #define SERIAL_PROTOCOL(x) MYSERIAL.print(x); | |
74 | #define SERIAL_PROTOCOL_F(x,y) MYSERIAL.print(x,y); | |
75 | #define SERIAL_PROTOCOLPGM(x) serialprintPGM(MYPGM(x)); | |
76 | #define SERIAL_PROTOCOLLN(x) {MYSERIAL.print(x);MYSERIAL.write('\n');} | |
77 | #define SERIAL_PROTOCOLLNPGM(x) {serialprintPGM(MYPGM(x));MYSERIAL.write('\n');} | |
78 | ||
79 | ||
80 | const char errormagic[] PROGMEM ="Error:"; | |
81 | const char echomagic[] PROGMEM ="echo:"; | |
82 | #define SERIAL_ERROR_START serialprintPGM(errormagic); | |
83 | #define SERIAL_ERROR(x) SERIAL_PROTOCOL(x) | |
84 | #define SERIAL_ERRORPGM(x) SERIAL_PROTOCOLPGM(x) | |
85 | #define SERIAL_ERRORLN(x) SERIAL_PROTOCOLLN(x) | |
86 | #define SERIAL_ERRORLNPGM(x) SERIAL_PROTOCOLLNPGM(x) | |
87 | ||
88 | #define SERIAL_ECHO_START serialprintPGM(echomagic); | |
89 | #define SERIAL_ECHO(x) SERIAL_PROTOCOL(x) | |
90 | #define SERIAL_ECHOPGM(x) SERIAL_PROTOCOLPGM(x) | |
91 | #define SERIAL_ECHOLN(x) SERIAL_PROTOCOLLN(x) | |
92 | #define SERIAL_ECHOLNPGM(x) SERIAL_PROTOCOLLNPGM(x) | |
93 | ||
94 | #define SERIAL_ECHOPAIR(name,value) {SERIAL_ECHOPGM(name);SERIAL_ECHO(value);} | |
95 | ||
96 | ||
97 | //things to write to serial from Programmemory. saves 400 to 2k of RAM. | |
98 | #define SerialprintPGM(x) serialprintPGM(MYPGM(x)) | |
99 | FORCE_INLINE void serialprintPGM(const char *str) | |
100 | { | |
101 | char ch=pgm_read_byte(str); | |
102 | while(ch) | |
103 | { | |
104 | MYSERIAL.write(ch); | |
105 | ch=pgm_read_byte(++str); | |
106 | } | |
107 | } | |
108 | ||
109 | // printing floats to 3DP | |
110 | FORCE_INLINE void serialPrintFloat( float f){ | |
111 | SERIAL_ECHO((int)f); | |
112 | SERIAL_ECHOPGM("."); | |
113 | int mantissa = (f - (int)f) * 1000; | |
114 | SERIAL_ECHO( abs(mantissa) ); | |
115 | } | |
116 | ||
117 | void get_command(); | |
118 | void process_commands(); | |
119 | ||
120 | void manage_inactivity(byte debug); | |
121 | ||
122 | #if X_ENABLE_PIN > -1 | |
123 | #define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON) | |
124 | #define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON) | |
125 | #else | |
126 | #define enable_x() ; | |
127 | #define disable_x() ; | |
128 | #endif | |
129 | ||
130 | #if Y_ENABLE_PIN > -1 | |
131 | #define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON) | |
132 | #define disable_y() WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON) | |
133 | #else | |
134 | #define enable_y() ; | |
135 | #define disable_y() ; | |
136 | #endif | |
137 | ||
138 | #if Z_ENABLE_PIN > -1 | |
139 | #define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON) | |
140 | #define disable_z() WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON) | |
141 | #else | |
142 | #define enable_z() ; | |
143 | #define disable_z() ; | |
144 | #endif | |
145 | ||
146 | #if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1) | |
147 | #define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON) | |
148 | #define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON) | |
149 | #else | |
150 | #define enable_e0() /* nothing */ | |
151 | #define disable_e0() /* nothing */ | |
152 | #endif | |
153 | ||
154 | #if (EXTRUDERS > 1) && defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1) | |
155 | #define enable_e1() WRITE(E1_ENABLE_PIN, E_ENABLE_ON) | |
156 | #define disable_e1() WRITE(E1_ENABLE_PIN,!E_ENABLE_ON) | |
157 | #else | |
158 | #define enable_e1() /* nothing */ | |
159 | #define disable_e1() /* nothing */ | |
160 | #endif | |
161 | ||
162 | #if (EXTRUDERS > 2) && defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1) | |
163 | #define enable_e2() WRITE(E2_ENABLE_PIN, E_ENABLE_ON) | |
164 | #define disable_e2() WRITE(E2_ENABLE_PIN,!E_ENABLE_ON) | |
165 | #else | |
166 | #define enable_e2() /* nothing */ | |
167 | #define disable_e2() /* nothing */ | |
168 | #endif | |
169 | ||
170 | ||
171 | enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3}; | |
172 | ||
173 | ||
174 | void FlushSerialRequestResend(); | |
175 | void ClearToSend(); | |
176 | ||
177 | void get_coordinates(); | |
178 | void prepare_move(); | |
179 | void kill(); | |
180 | void Stop(); | |
181 | ||
182 | bool IsStopped(); | |
183 | ||
184 | void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer. | |
185 | void prepare_arc_move(char isclockwise); | |
186 | ||
187 | #ifndef CRITICAL_SECTION_START | |
188 | #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli(); | |
189 | #define CRITICAL_SECTION_END SREG = _sreg; | |
190 | #endif //CRITICAL_SECTION_START | |
191 | ||
192 | extern float homing_feedrate[]; | |
193 | extern float fast_home_feedrate[]; | |
194 | extern bool axis_relative_modes[]; | |
195 | extern volatile int feedmultiply; | |
196 | extern int saved_feedmultiply; | |
197 | extern float current_position[NUM_AXIS] ; | |
198 | extern float add_homeing[3]; | |
199 | extern float max_length[3]; | |
200 | #ifdef ADVANCE | |
201 | extern float advance_k; | |
202 | #endif | |
203 | extern unsigned char FanSpeed; | |
204 | extern bool m571_enabled; | |
205 | extern bool n571_enabled; | |
206 | ||
207 | extern float destination[NUM_AXIS]; | |
208 | extern float modified_destination[NUM_AXIS]; | |
209 | extern float offset[3]; | |
210 | extern float feedrate, next_feedrate, saved_feedrate; | |
211 | ||
212 | ||
213 | // Handling multiple extruders pins | |
214 | extern uint8_t active_extruder; | |
215 | ||
216 | #endif |