Repetier-Firmware
0.91
|
00001 /* 00002 This file is part of Repetier-Firmware. 00003 00004 Repetier-Firmware is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 00009 Repetier-Firmware is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>. 00016 00017 This firmware is a nearly complete rewrite of the sprinter firmware 00018 by kliment (https://github.com/kliment/Sprinter) 00019 which based on Tonokip RepRap firmware rewrite based off of Hydra-mmm firmware. 00020 */ 00021 00022 #ifndef _REPETIER_H 00023 #define _REPETIER_H 00024 00025 #define REPETIER_VERSION "0.91" 00026 00027 // ########################################################################################## 00028 // ## Debug configuration ## 00029 // ########################################################################################## 00030 00032 //#define DEBUG_QUEUE_MOVE 00035 #define INCLUDE_DEBUG_COMMUNICATION 00036 00038 #define INCLUDE_DEBUG_NO_MOVE 00039 00042 //#define DEBUG_FREE_MEMORY 00043 //#define DEBUG_ADVANCE 00045 //#define DEBUG_OPS 00047 //#define DEBUG_GENERIC 00049 //#define DEBUG_STEPCOUNT 00051 #define DEBUG_COM_ERRORS 00052 //#define DEBUG_DELTA_OVERFLOW 00053 // Add write debug to quicksettings menu to debug some vars during hang 00054 //#define DEBUG_PRINT 00055 //#define DEBUG_SPLIT 00056 00057 // Uncomment the following line to enable debugging. You can better control debugging below the following line 00058 //#define DEBUG 00059 00060 00061 // Uncomment if no analyzer is connected 00062 //#define ANALYZER 00063 // Channel->pin assignments 00064 #define ANALYZER_CH0 63 // New move 00065 #define ANALYZER_CH1 40 // Step loop 00066 #define ANALYZER_CH2 53 // X Step 00067 #define ANALYZER_CH3 65 // Y Step 00068 #define ANALYZER_CH4 59 // X Direction 00069 #define ANALYZER_CH5 64 // Y Direction 00070 #define ANALYZER_CH6 58 // xsig 00071 #define ANALYZER_CH7 57 // ysig 00072 00073 #ifdef ANALYZER 00074 #define ANALYZER_ON(a) {WRITE(a,HIGH);} 00075 #define ANALYZER_OFF(a) {WRITE(a,LOW);} 00076 #else 00077 #define ANALYZER_ON(a) 00078 #define ANALYZER_OFF(a) 00079 #endif 00080 00081 #define X_AXIS 0 00082 #define Y_AXIS 1 00083 #define Z_AXIS 2 00084 #define E_AXIS 3 00085 #define VIRTUAL_AXIS 4 00086 00087 00088 // Bits of the ADC converter 00089 #define ANALOG_INPUT_BITS 10 00090 // Build median from 2^ANALOG_INPUT_SAMPLE samples 00091 #define ANALOG_INPUT_SAMPLE 5 00092 #define ANALOG_REF_AREF 0 00093 #define ANALOG_REF_AVCC _BV(REFS0) 00094 #define ANALOG_REF_INT_1_1 _BV(REFS1) 00095 #define ANALOG_REF_INT_2_56 _BV(REFS0) | _BV(REFS1) 00096 #define ANALOG_REF ANALOG_REF_AVCC 00097 00098 // MS1 MS2 Stepper Driver Microstepping mode table 00099 #define MICROSTEP1 LOW,LOW 00100 #define MICROSTEP2 HIGH,LOW 00101 #define MICROSTEP4 LOW,HIGH 00102 #define MICROSTEP8 HIGH,HIGH 00103 #define MICROSTEP16 HIGH,HIGH 00104 00105 #define HOME_ORDER_XYZ 1 00106 #define HOME_ORDER_XZY 2 00107 #define HOME_ORDER_YXZ 3 00108 #define HOME_ORDER_YZX 4 00109 #define HOME_ORDER_ZXY 5 00110 #define HOME_ORDER_ZYX 6 00111 00112 #define TEMP_PID true // add pid control 00113 00114 00115 #include "Configuration.h" 00116 00117 #define SPEED_MIN_MILLIS 300 00118 #define SPEED_MAX_MILLIS 50 00119 #define SPEED_MAGNIFICATION 100.0f 00120 00121 #ifndef UI_SPEEDDEPENDENT_POSITIONING 00122 #define UI_SPEEDDEPENDENT_POSITIONING true 00123 #endif 00124 00125 #if DRIVE_SYSTEM==3 || DRIVE_SYSTEM==4 00126 #define NONLINEAR_SYSTEM true 00127 #else 00128 #define NONLINEAR_SYSTEM false 00129 #endif 00130 00131 #ifdef FEATURE_Z_PROBE 00132 #define MANUAL_CONTROL true 00133 #endif 00134 00135 #if DRIVE_SYSTEM==1 || DRIVE_SYSTEM==2 00136 #define XY_GANTRY 00137 #endif 00138 00139 //Step to split a cirrcle in small Lines 00140 #ifndef MM_PER_ARC_SEGMENT 00141 #define MM_PER_ARC_SEGMENT 1 00142 #define MM_PER_ARC_SEGMENT_BIG 3 00143 #else 00144 #define MM_PER_ARC_SEGMENT_BIG MM_PER_ARC_SEGMENT 00145 #endif 00146 //After this count of steps a new SIN / COS caluclation is startet to correct the circle interpolation 00147 #define N_ARC_CORRECTION 25 00148 00149 #if NUM_EXTRUDER>0 && EXT0_TEMPSENSOR_TYPE<101 00150 #define EXT0_ANALOG_INPUTS 1 00151 #define EXT0_SENSOR_INDEX 0 00152 #define EXT0_ANALOG_CHANNEL EXT0_TEMPSENSOR_PIN 00153 #define ACCOMMA0 , 00154 #else 00155 #define ACCOMMA0 00156 #define EXT0_ANALOG_INPUTS 0 00157 #define EXT0_SENSOR_INDEX EXT0_TEMPSENSOR_PIN 00158 #define EXT0_ANALOG_CHANNEL 00159 #endif 00160 00161 #if NUM_EXTRUDER>1 && EXT1_TEMPSENSOR_TYPE<101 00162 #define EXT1_ANALOG_INPUTS 1 00163 #define EXT1_SENSOR_INDEX EXT0_ANALOG_INPUTS 00164 #define EXT1_ANALOG_CHANNEL ACCOMMA0 EXT1_TEMPSENSOR_PIN 00165 #define ACCOMMA1 , 00166 #else 00167 #define ACCOMMA1 ACCOMMA0 00168 #define EXT1_ANALOG_INPUTS 0 00169 #define EXT1_SENSOR_INDEX EXT1_TEMPSENSOR_PIN 00170 #define EXT1_ANALOG_CHANNEL 00171 #endif 00172 00173 #if NUM_EXTRUDER>2 && EXT2_TEMPSENSOR_TYPE<101 00174 #define EXT2_ANALOG_INPUTS 1 00175 #define EXT2_SENSOR_INDEX EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS 00176 #define EXT2_ANALOG_CHANNEL ACCOMMA1 EXT2_TEMPSENSOR_PIN 00177 #define ACCOMMA2 , 00178 #else 00179 #define ACCOMMA2 ACCOMMA1 00180 #define EXT2_ANALOG_INPUTS 0 00181 #define EXT2_SENSOR_INDEX EXT2_TEMPSENSOR_PIN 00182 #define EXT2_ANALOG_CHANNEL 00183 #endif 00184 00185 #if NUM_EXTRUDER>3 && EXT3_TEMPSENSOR_TYPE<101 00186 #define EXT3_ANALOG_INPUTS 1 00187 #define EXT3_SENSOR_INDEX EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS 00188 #define EXT3_ANALOG_CHANNEL ACCOMMA2 EXT3_TEMPSENSOR_PIN 00189 #define ACCOMMA3 , 00190 #else 00191 #define ACCOMMA3 ACCOMMA2 00192 #define EXT3_ANALOG_INPUTS 0 00193 #define EXT3_SENSOR_INDEX EXT3_TEMPSENSOR_PIN 00194 #define EXT3_ANALOG_CHANNEL 00195 #endif 00196 00197 #if NUM_EXTRUDER>4 && EXT4_TEMPSENSOR_TYPE<101 00198 #define EXT4_ANALOG_INPUTS 1 00199 #define EXT4_SENSOR_INDEX EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS+EXT3_ANALOG_INPUTS 00200 #define EXT4_ANALOG_CHANNEL ACCOMMA3 EXT4_TEMPSENSOR_PIN 00201 #define ACCOMMA4 , 00202 #else 00203 #define ACCOMMA4 ACCOMMA3 00204 #define EXT4_ANALOG_INPUTS 0 00205 #define EXT4_SENSOR_INDEX EXT4_TEMPSENSOR_PIN 00206 #define EXT4_ANALOG_CHANNEL 00207 #endif 00208 00209 #if NUM_EXTRUDER>5 && EXT5_TEMPSENSOR_TYPE<101 00210 #define EXT5_ANALOG_INPUTS 1 00211 #define EXT5_SENSOR_INDEX EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS+EXT3_ANALOG_INPUTS+EXT4_ANALOG_INPUTS 00212 #define EXT5_ANALOG_CHANNEL ACCOMMA4 EXT5_TEMPSENSOR_PIN 00213 #define ACCOMMA5 , 00214 #else 00215 #define ACCOMMA5 ACCOMMA4 00216 #define EXT5_ANALOG_INPUTS 0 00217 #define EXT5_SENSOR_INDEX EXT5_TEMPSENSOR_PIN 00218 #define EXT5_ANALOG_CHANNEL 00219 #endif 00220 00221 #if HAVE_HEATED_BED==true && HEATED_BED_SENSOR_TYPE<101 00222 #define BED_ANALOG_INPUTS 1 00223 #define BED_SENSOR_INDEX EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS+EXT3_ANALOG_INPUTS+EXT4_ANALOG_INPUTS+EXT5_ANALOG_INPUTS 00224 #define BED_ANALOG_CHANNEL ACCOMMA5 HEATED_BED_SENSOR_PIN 00225 #undef KOMMA 00226 #define KOMMA , 00227 #else 00228 #define BED_ANALOG_INPUTS 0 00229 #define BED_SENSOR_INDEX HEATED_BED_SENSOR_PIN 00230 #define BED_ANALOG_CHANNEL 00231 #endif 00232 00233 #ifndef DEBUG_FREE_MEMORY 00234 #define DEBUG_MEMORY 00235 #else 00236 #define DEBUG_MEMORY Commands::checkFreeMemory(); 00237 #endif 00238 00240 #define ANALOG_INPUTS (EXT0_ANALOG_INPUTS+EXT1_ANALOG_INPUTS+EXT2_ANALOG_INPUTS+EXT3_ANALOG_INPUTS+EXT4_ANALOG_INPUTS+EXT5_ANALOG_INPUTS+BED_ANALOG_INPUTS) 00241 #if ANALOG_INPUTS>0 00242 00243 #define ANALOG_INPUT_CHANNELS {EXT0_ANALOG_CHANNEL EXT1_ANALOG_CHANNEL EXT2_ANALOG_CHANNEL EXT3_ANALOG_CHANNEL EXT4_ANALOG_CHANNEL EXT5_ANALOG_CHANNEL BED_ANALOG_CHANNEL} 00244 #endif 00245 00246 #define MENU_MODE_SD_MOUNTED 1 00247 #define MENU_MODE_SD_PRINTING 2 00248 #define MENU_MODE_SD_PAUSED 4 00249 #define MENU_MODE_FAN_RUNNING 8 00250 00251 #include "HAL.h" 00252 #include "gcode.h" 00253 #define MAX_VFAT_ENTRIES (2) 00254 00255 #define LONG_FILENAME_LENGTH (13*MAX_VFAT_ENTRIES+1) 00256 #define SD_MAX_FOLDER_DEPTH 2 00257 00258 #include "ui.h" 00259 #include "Communication.h" 00260 00261 #ifndef SDSUPPORT 00262 #define SDSUPPORT false 00263 #endif 00264 #if SDSUPPORT 00265 #include "SdFat.h" 00266 #endif 00267 #ifndef SDSUPPORT 00268 #define SDSUPPORT false 00269 #endif 00270 #if SDSUPPORT 00271 #include "SdFat.h" 00272 #endif 00273 00274 #if ENABLE_BACKLASH_COMPENSATION && DRIVE_SYSTEM!=0 00275 #undef ENABLE_BACKLASH_COMPENSATION 00276 #define ENABLE_BACKLASH_COMPENSATION false 00277 #endif 00278 00279 #define uint uint16_t 00280 #define uint8 uint8_t 00281 #define int8 int8_t 00282 #define uint32 uint32_t 00283 #define int32 int32_t 00284 00285 #define IGNORE_COORDINATE 99999 00286 00287 #undef min 00288 #undef max 00289 00290 class RMath { 00291 public: 00292 static inline float min(float a,float b) { 00293 if(a<b) return a; 00294 return b; 00295 } 00296 static inline float max(float a,float b) { 00297 if(a<b) return b; 00298 return a; 00299 } 00300 static inline long min(long a,long b) { 00301 if(a<b) return a; 00302 return b; 00303 } 00304 static inline long max(long a,long b) { 00305 if(a<b) return b; 00306 return a; 00307 } 00308 static inline int min(int a,int b) { 00309 if(a<b) return a; 00310 return b; 00311 } 00312 static inline int max(int a,int b) { 00313 if(a<b) return b; 00314 return a; 00315 } 00316 static inline unsigned int min(unsigned int a,unsigned int b) { 00317 if(a<b) return a; 00318 return b; 00319 } 00320 static inline unsigned int max(unsigned int a,unsigned int b) { 00321 if(a<b) return b; 00322 return a; 00323 } 00324 }; 00325 00326 extern const uint8 osAnalogInputChannels[] PROGMEM; 00327 extern uint8 osAnalogInputCounter[ANALOG_INPUTS]; 00328 extern uint osAnalogInputBuildup[ANALOG_INPUTS]; 00329 extern uint8 osAnalogInputPos; // Current sampling position 00330 extern volatile uint osAnalogInputValues[ANALOG_INPUTS]; 00331 extern uint8_t pwm_pos[NUM_EXTRUDER+3]; // 0-NUM_EXTRUDER = Heater 0-NUM_EXTRUDER of extruder, NUM_EXTRUDER = Heated bed, NUM_EXTRUDER+1 Board fan, NUM_EXTRUDER+2 = Fan 00332 #ifdef USE_ADVANCE 00333 #ifdef ENABLE_QUADRATIC_ADVANCE 00334 extern int maxadv; 00335 #endif 00336 extern int maxadv2; 00337 extern float maxadvspeed; 00338 #endif 00339 00340 00341 #include "Extruder.h" 00342 00343 void manage_inactivity(uint8_t debug); 00344 00345 extern void finishNextSegment(); 00346 #if NONLINEAR_SYSTEM 00347 extern uint8_t transformCartesianStepsToDeltaSteps(long cartesianPosSteps[], long deltaPosSteps[]); 00348 #ifdef SOFTWARE_LEVELING 00349 extern void calculatePlane(long factors[], long p1[], long p2[], long p3[]); 00350 extern float calcZOffset(long factors[], long pointX, long pointY); 00351 #endif 00352 #endif 00353 extern void linear_move(long steps_remaining[]); 00354 #ifndef FEATURE_DITTO_PRINTING 00355 #define FEATURE_DITTO_PRINTING false 00356 #endif 00357 #if FEATURE_DITTO_PRINTING && NUM_EXTRUDER!=2 00358 #error Ditto printing requires exactly 2 extruder. 00359 #endif 00360 00361 00362 extern millis_t previousMillisCmd; 00363 extern millis_t maxInactiveTime; 00364 extern millis_t stepperInactiveTime; 00365 00366 extern void setupTimerInterrupt(); 00367 extern void motorCurrentControlInit(); 00368 extern void microstepInit(); 00369 00370 #include "Printer.h" 00371 #include "motion.h" 00372 extern long baudrate; 00373 #if OS_ANALOG_INPUTS>0 00374 // Get last result for pin x 00375 extern volatile uint osAnalogInputValues[OS_ANALOG_INPUTS]; 00376 #endif 00377 00378 #include "HAL.h" 00379 00380 00381 extern unsigned int counterPeriodical; 00382 extern volatile uint8_t executePeriodical; 00383 extern uint8_t counter250ms; 00384 extern void writeMonitor(); 00385 00386 00387 00388 #if SDSUPPORT 00389 extern char tempLongFilename[LONG_FILENAME_LENGTH+1]; 00390 extern char fullName[LONG_FILENAME_LENGTH*SD_MAX_FOLDER_DEPTH+SD_MAX_FOLDER_DEPTH+1]; 00391 #define SHORT_FILENAME_LENGTH 14 00392 #include "SdFat.h" 00393 00394 enum LsAction {LS_SerialPrint,LS_Count,LS_GetFilename}; 00395 class SDCard { 00396 public: 00397 SdFat fat; 00398 //Sd2Card card; // ~14 Byte 00399 //SdVolume volume; 00400 //SdFile root; 00401 //SdFile dir[SD_MAX_FOLDER_DEPTH+1]; 00402 SdFile file; 00403 uint32_t filesize; 00404 uint32_t sdpos; 00405 //char fullName[13*SD_MAX_FOLDER_DEPTH+13]; // Fill name 00406 char *shortname; // Pointer to start of filename itself 00407 char *pathend; // File to char where pathname in fullname ends 00408 bool sdmode; // true if we are printing from sd card 00409 bool sdactive; 00410 //int16_t n; 00411 bool savetosd; 00412 SdBaseFile parentFound; 00413 00414 SDCard(); 00415 void initsd(); 00416 void writeCommand(GCode *code); 00417 bool selectFile(char *filename,bool silent=false); 00418 void mount(); 00419 void unmount(); 00420 void startPrint(); 00421 void pausePrint(bool intern = false); 00422 void continuePrint(bool intern=false); 00423 void stopPrint(); 00424 inline void setIndex(uint32_t newpos) { if(!sdactive) return; sdpos = newpos;file.seekSet(sdpos);} 00425 void printStatus(); 00426 void ls(); 00427 void startWrite(char *filename); 00428 void deleteFile(char *filename); 00429 void finishWrite(); 00430 char *createFilename(char *buffer,const dir_t &p); 00431 void makeDirectory(char *filename); 00432 bool showFilename(const uint8_t *name); 00433 void automount(); 00434 #ifdef GLENN_DEBUG 00435 void writeToFile(); 00436 #endif 00437 private: 00438 uint8_t lsRecursive(SdBaseFile *parent,uint8_t level,char *findFilename); 00439 // SdFile *getDirectory(char* name); 00440 }; 00441 00442 extern SDCard sd; 00443 #endif 00444 00445 extern volatile int waitRelax; // Delay filament relax at the end of print, could be a simple timeout 00446 extern void updateStepsParameter(PrintLine *p/*,uint8_t caller*/); 00447 00448 00449 #if NONLINEAR_SYSTEM 00450 #define NUM_AXIS 4 00451 #endif 00452 00453 #define STR(s) #s 00454 #define XSTR(s) STR(s) 00455 #include "Commands.h" 00456 #include "Eeprom.h" 00457 00458 #endif