1 // Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware.
7 #define HardwareSerial_h // trick to disable the standard HWserial
9 #define FORCE_INLINE __attribute__((always_inline)) inline
17 #include <util/delay.h>
18 #include <avr/pgmspace.h>
19 #include <avr/eeprom.h>
21 #include <avr/interrupt.h>
25 #include "Configuration.h"
29 #if defined(__AVR_ATmega644P__)
38 #include "MarlinSerial.h"
41 #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
44 #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
49 #if MOTHERBOARD == 8 // Teensylu
50 #define MYSERIAL Serial
52 #define MYSERIAL MSerial
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
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');}
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)
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)
87 #define SERIAL_ECHOPAIR(name,value) {SERIAL_ECHOPGM(name);SERIAL_ECHO(value);}
90 //things to write to serial from Programmemory. saves 400 to 2k of RAM.
91 #define SerialprintPGM(x) serialprintPGM(MYPGM(x))
92 FORCE_INLINE void serialprintPGM(const char *str)
94 char ch=pgm_read_byte(str);
98 ch=pgm_read_byte(++str);
104 void process_commands();
106 void manage_inactivity(byte debug);
108 #if X_ENABLE_PIN > -1
109 #define enable_x() WRITE(X_ENABLE_PIN, X_ENABLE_ON)
110 #define disable_x() WRITE(X_ENABLE_PIN,!X_ENABLE_ON)
113 #define disable_x() ;
116 #if Y_ENABLE_PIN > -1
117 #define enable_y() WRITE(Y_ENABLE_PIN, Y_ENABLE_ON)
118 #define disable_y() WRITE(Y_ENABLE_PIN,!Y_ENABLE_ON)
121 #define disable_y() ;
124 #if Z_ENABLE_PIN > -1
125 #define enable_z() WRITE(Z_ENABLE_PIN, Z_ENABLE_ON)
126 #define disable_z() WRITE(Z_ENABLE_PIN,!Z_ENABLE_ON)
129 #define disable_z() ;
132 #if defined(E0_ENABLE_PIN) && (E0_ENABLE_PIN > -1)
133 #define enable_e0() WRITE(E0_ENABLE_PIN, E_ENABLE_ON)
134 #define disable_e0() WRITE(E0_ENABLE_PIN,!E_ENABLE_ON)
136 #define enable_e0() /* nothing */
137 #define disable_e0() /* nothing */
140 #if (EXTRUDERS > 1) && defined(E1_ENABLE_PIN) && (E1_ENABLE_PIN > -1)
141 #define enable_e1() WRITE(E1_ENABLE_PIN, E_ENABLE_ON)
142 #define disable_e1() WRITE(E1_ENABLE_PIN,!E_ENABLE_ON)
144 #define enable_e1() /* nothing */
145 #define disable_e1() /* nothing */
148 #if (EXTRUDERS > 2) && defined(E2_ENABLE_PIN) && (E2_ENABLE_PIN > -1)
149 #define enable_e2() WRITE(E2_ENABLE_PIN, E_ENABLE_ON)
150 #define disable_e2() WRITE(E2_ENABLE_PIN,!E_ENABLE_ON)
152 #define enable_e2() /* nothing */
153 #define disable_e2() /* nothing */
157 enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3};
160 void FlushSerialRequestResend();
163 void get_coordinates();
170 void enquecommand(const char *cmd); //put an ascii command at the end of the current buffer.
171 void prepare_arc_move(char isclockwise);
173 #ifndef CRITICAL_SECTION_START
174 #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
175 #define CRITICAL_SECTION_END SREG = _sreg;
176 #endif //CRITICAL_SECTION_START
178 extern float homing_feedrate[];
179 extern bool axis_relative_modes[];
180 extern float current_position[NUM_AXIS] ;
181 extern float add_homeing[3];
182 extern unsigned char FanSpeed;
184 // Handling multiple extruders pins
185 extern uint8_t active_extruder;