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