From 50af89fef714bc271ac98bba3153210a8a61b275 Mon Sep 17 00:00:00 2001 From: repetier Date: Mon, 27 Apr 2015 15:35:27 +0200 Subject: [PATCH] Half stepping removed, speed improved, bluetooth bug and more fixed. --- src/ArduinoAVR/Repetier/Commands.cpp | 6 +- src/ArduinoAVR/Repetier/Configuration.h | 17 +- src/ArduinoAVR/Repetier/Extruder.cpp | 4 + src/ArduinoAVR/Repetier/HAL.cpp | 83 +- src/ArduinoAVR/Repetier/HAL.h | 5 + src/ArduinoAVR/Repetier/Printer.cpp | 2 - src/ArduinoAVR/Repetier/Printer.h | 202 +- src/ArduinoAVR/Repetier/motion.cpp | 661 ++--- src/ArduinoAVR/Repetier/motion.h | 51 +- src/ArduinoAVR/Repetier/ui.cpp | 55 + src/ArduinoAVR/Repetier/ui.h | 2 +- src/ArduinoDUE/Repetier/Commands.cpp | 6 +- src/ArduinoDUE/Repetier/Configuration.h | 21 +- src/ArduinoDUE/Repetier/Extruder.cpp | 4 + src/ArduinoDUE/Repetier/HAL.cpp | 113 +- src/ArduinoDUE/Repetier/HAL.h | 39 +- src/ArduinoDUE/Repetier/Printer.cpp | 2 - src/ArduinoDUE/Repetier/Printer.h | 202 +- src/ArduinoDUE/Repetier/fastio.h | 3301 ++--------------------- src/ArduinoDUE/Repetier/motion.cpp | 661 ++--- src/ArduinoDUE/Repetier/motion.h | 51 +- src/ArduinoDUE/Repetier/ui.cpp | 55 + src/ArduinoDUE/Repetier/ui.h | 2 +- 23 files changed, 1368 insertions(+), 4177 deletions(-) diff --git a/src/ArduinoAVR/Repetier/Commands.cpp b/src/ArduinoAVR/Repetier/Commands.cpp index 9a49a2c9a..172f74227 100644 --- a/src/ArduinoAVR/Repetier/Commands.cpp +++ b/src/ArduinoAVR/Repetier/Commands.cpp @@ -231,7 +231,11 @@ void Commands::setFanSpeed(int speed,bool wait) { Com::printFLN(Com::tFanspeed,speed); // send only new values to break update loops! #if FAN_KICKSTART_TIME - if(fanKickstart == 0 && speed > pwm_pos[NUM_EXTRUDER + 2]) fanKickstart = FAN_KICKSTART_TIME/100; + if(fanKickstart == 0 && speed > pwm_pos[NUM_EXTRUDER + 2] && speed < 85) + { + if(pwm_pos[NUM_EXTRUDER + 2]) fanKickstart = FAN_KICKSTART_TIME/100; + else fanKickstart = FAN_KICKSTART_TIME/25; + } #endif } pwm_pos[NUM_EXTRUDER + 2] = speed; diff --git a/src/ArduinoAVR/Repetier/Configuration.h b/src/ArduinoAVR/Repetier/Configuration.h index c2e09cb7b..63f2ae7a4 100644 --- a/src/ArduinoAVR/Repetier/Configuration.h +++ b/src/ArduinoAVR/Repetier/Configuration.h @@ -1001,13 +1001,7 @@ enabling this may cause to stall your moves when 20000Hz is reached. for some printers causing an early stall. */ -#define DOUBLE_STEP_DELAY 1 // time in microseconds - -/** The firmware supports trajectory smoothing. To achieve this, it divides the stepsize by 2, resulting in -the double computation cost. For slow movements this is not an issue, but for really fast moves this is -too much. The value specified here is the number of clock cycles between a step on the driving axis. -If the interval at full speed is below this value, smoothing is disabled for that line.*/ -#define MAX_HALFSTEP_INTERVAL 1999 +#define DOUBLE_STEP_DELAY 0 // time in microseconds //// Acceleration settings @@ -1406,13 +1400,20 @@ Select the language to use. */ #define UI_LANGUAGE 1 +/* Some displays loose their settings from time to time. Try uncommenting the +autorepair function if this is the case. It is not supported for all display +types. It creates a minimal flicker from time to time and also slows down +computations, so do not enable it if your display works stable! +*/ +//#define TRY_AUTOREPAIR_LCD_ERRORS + // This is line 2 of the status display at startup. Change to your like. #define UI_PRINTER_NAME "MyPrinter" #define UI_PRINTER_COMPANY "Self Made" /** Animate switches between menus etc. */ -#define UI_ANIMATION 1 +#define UI_ANIMATION 0 /** How many ms should a single page be shown, until it is switched to the next one.*/ #define UI_PAGES_DURATION 4000 diff --git a/src/ArduinoAVR/Repetier/Extruder.cpp b/src/ArduinoAVR/Repetier/Extruder.cpp index 45e6d74a3..00f4e1faf 100644 --- a/src/ArduinoAVR/Repetier/Extruder.cpp +++ b/src/ArduinoAVR/Repetier/Extruder.cpp @@ -1918,6 +1918,9 @@ const char ext5_select_cmd[] PROGMEM = EXT5_SELECT_COMMANDS; const char ext5_deselect_cmd[] PROGMEM = EXT5_DESELECT_COMMANDS; #endif +#if NUM_EXTRUDER == 0 +Extruder extruder[1]; +#else Extruder extruder[NUM_EXTRUDER] = { #if NUM_EXTRUDER > 0 @@ -2083,6 +2086,7 @@ Extruder extruder[NUM_EXTRUDER] = } #endif }; +#endif // NUM_EXTRUDER #if HAVE_HEATED_BED #define NUM_TEMPERATURE_LOOPS NUM_EXTRUDER+1 diff --git a/src/ArduinoAVR/Repetier/HAL.cpp b/src/ArduinoAVR/Repetier/HAL.cpp index 2e3b226ba..431819755 100644 --- a/src/ArduinoAVR/Repetier/HAL.cpp +++ b/src/ArduinoAVR/Repetier/HAL.cpp @@ -737,8 +737,8 @@ ISR(TIMER1_COMPA_vect) #if HEATER_PWM_SPEED < 0 #define HEATER_PWM_SPEED 0 #endif -#if HEATER_PWM_SPEED > 3 -#define HEATER_PWM_SPEED 3 +#if HEATER_PWM_SPEED > 2 +#define HEATER_PWM_SPEED 2 #endif #if HEATER_PWM_SPEED == 0 @@ -747,23 +747,44 @@ ISR(TIMER1_COMPA_vect) #elif HEATER_PWM_SPEED == 1 #define HEATER_PWM_STEP 2 #define HEATER_PWM_MASK 254 -#elif HEATER_PWM_SPEED == 2 -#define HEATER_PWM_STEP 4 -#define HEATER_PWM_MASK 252 #else #define HEATER_PWM_STEP 4 #define HEATER_PWM_MASK 252 #endif + +#if !defined(COOLER_PWM_SPEED) +#define COOLER_PWM_SPEED 0 +#endif +#if COOLER_PWM_SPEED < 0 +#define COOLER_PWM_SPEED 0 +#endif +#if COOLER_PWM_SPEED > 2 +#define COOLER_PWM_SPEED 2 +#endif + +#if COOLER_PWM_SPEED == 0 +#define COOLER_PWM_STEP 1 +#define COOLER_PWM_MASK 255 +#elif COOLER_PWM_SPEED == 1 +#define COOLER_PWM_STEP 2 +#define COOLER_PWM_MASK 254 +#else +#define COOLER_PWM_STEP 4 +#define COOLER_PWM_MASK 252 +#endif + #define pulseDensityModulate( pin, density,error,invert) {uint8_t carry;carry = error + (invert ? 255 - density : density); WRITE(pin, (carry < error)); error = carry;} /** This timer is called 3906 timer per second. It is used to update pwm values for heater and some other frequent jobs. */ ISR(PWM_TIMER_VECTOR) { - static uint8_t pwm_count = 0; + static uint8_t pwm_count_cooler = 0; static uint8_t pwm_count_heater = 0; static uint8_t pwm_pos_set[NUM_EXTRUDER + 3]; +#if NUM_EXTRUDER > 0 static uint8_t pwm_cooler_pos_set[NUM_EXTRUDER]; +#endif PWM_OCR += 64; if(pwm_count_heater == 0 && !PDM_FOR_EXTRUDER) { @@ -786,44 +807,44 @@ ISR(PWM_TIMER_VECTOR) if((pwm_pos_set[5] = (pwm_pos[5] & HEATER_PWM_MASK)) > 0) WRITE(EXT5_HEATER_PIN, !HEATER_PINS_INVERTED); #endif #if HEATED_BED_HEATER_PIN > -1 && HAVE_HEATED_BED - if((pwm_pos_set[NUM_EXTRUDER] = pwm_pos[NUM_EXTRUDER]) > 0) WRITE(HEATED_BED_HEATER_PIN, !HEATER_PINS_INVERTED); + if((pwm_pos_set[NUM_EXTRUDER] = (pwm_pos[NUM_EXTRUDER] & HEATER_PWM_MASK)) > 0) WRITE(HEATED_BED_HEATER_PIN, !HEATER_PINS_INVERTED); #endif } - if(pwm_count == 0 && !PDM_FOR_COOLER) + if(pwm_count_cooler == 0 && !PDM_FOR_COOLER) { #if defined(EXT0_HEATER_PIN) && EXT0_HEATER_PIN > -1 && EXT0_EXTRUDER_COOLER_PIN > -1 - if((pwm_cooler_pos_set[0] = extruder[0].coolerPWM) > 0) WRITE(EXT0_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[0] = (extruder[0].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT0_EXTRUDER_COOLER_PIN, 1); #endif #if !SHARED_COOLER && defined(EXT1_HEATER_PIN) && EXT1_HEATER_PIN > -1 && NUM_EXTRUDER > 1 #if EXT1_EXTRUDER_COOLER_PIN > -1 && EXT1_EXTRUDER_COOLER_PIN != EXT0_EXTRUDER_COOLER_PIN - if((pwm_cooler_pos_set[1] = extruder[1].coolerPWM) > 0) WRITE(EXT1_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[1] = (extruder[1].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT1_EXTRUDER_COOLER_PIN, 1); #endif #endif #if !SHARED_COOLER && defined(EXT2_HEATER_PIN) && EXT2_HEATER_PIN > -1 && NUM_EXTRUDER > 2 #if EXT2_EXTRUDER_COOLER_PIN > -1 - if((pwm_cooler_pos_set[2] = extruder[2].coolerPWM) > 0) WRITE(EXT2_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[2] = (extruder[2].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT2_EXTRUDER_COOLER_PIN, 1); #endif #endif #if !SHARED_COOLER && defined(EXT3_HEATER_PIN) && EXT3_HEATER_PIN > -1 && NUM_EXTRUDER > 3 #if EXT3_EXTRUDER_COOLER_PIN > -1 - if((pwm_cooler_pos_set[3] = extruder[3].coolerPWM) > 0) WRITE(EXT3_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[3] = (extruder[3].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT3_EXTRUDER_COOLER_PIN, 1); #endif #endif #if !SHARED_COOLER && defined(EXT4_HEATER_PIN) && EXT4_HEATER_PIN > -1 && NUM_EXTRUDER > 4 #if EXT4_EXTRUDER_COOLER_PIN > -1 - if((pwm_cooler_pos_set[4] = pwm_pos[4].coolerPWM) > 0) WRITE(EXT4_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[4] = (extruder[4].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT4_EXTRUDER_COOLER_PIN, 1); #endif #endif #if !SHARED_COOLER && defined(EXT5_HEATER_PIN) && EXT5_HEATER_PIN > -1 && NUM_EXTRUDER > 5 #if EXT5_EXTRUDER_COOLER_PIN > -1 - if((pwm_cooler_pos_set[5] = extruder[5].coolerPWM) > 0) WRITE(EXT5_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[5] = (extruder[5].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT5_EXTRUDER_COOLER_PIN, 1); #endif #endif #if FAN_BOARD_PIN > -1 && SHARED_COOLER_BOARD_EXT == 0 - if((pwm_pos_set[NUM_EXTRUDER + 1] = pwm_pos[NUM_EXTRUDER + 1]) > 0) WRITE(FAN_BOARD_PIN,1); + if((pwm_pos_set[NUM_EXTRUDER + 1] = (pwm_pos[NUM_EXTRUDER + 1] & COOLER_PWM_MASK)) > 0) WRITE(FAN_BOARD_PIN,1); #endif #if FAN_PIN > -1 && FEATURE_FAN_CONTROL - if((pwm_pos_set[NUM_EXTRUDER + 2] = pwm_pos[NUM_EXTRUDER + 2]) > 0) WRITE(FAN_PIN,1); + if((pwm_pos_set[NUM_EXTRUDER + 2] = (pwm_pos[NUM_EXTRUDER + 2] & COOLER_PWM_MASK)) > 0) WRITE(FAN_PIN,1); #endif } #if defined(EXT0_HEATER_PIN) && EXT0_HEATER_PIN > -1 @@ -836,7 +857,7 @@ ISR(PWM_TIMER_VECTOR) #if PDM_FOR_COOLER pulseDensityModulate(EXT0_EXTRUDER_COOLER_PIN, extruder[0].coolerPWM, pwm_cooler_pos_set[0], false); #else - if(pwm_cooler_pos_set[0] == pwm_count && pwm_cooler_pos_set[0] != 255) WRITE(EXT0_EXTRUDER_COOLER_PIN,0); + if(pwm_cooler_pos_set[0] == pwm_count_cooler && pwm_cooler_pos_set[0] != COOLER_PWM_MASK) WRITE(EXT0_EXTRUDER_COOLER_PIN,0); #endif #endif #endif @@ -850,25 +871,25 @@ ISR(PWM_TIMER_VECTOR) #if PDM_FOR_COOLER pulseDensityModulate(EXT1_EXTRUDER_COOLER_PIN, extruder[1].coolerPWM, pwm_cooler_pos_set[1], false); #else - if(pwm_cooler_pos_set[1] == pwm_count && pwm_cooler_pos_set[1] != 255) WRITE(EXT1_EXTRUDER_COOLER_PIN,0); + if(pwm_cooler_pos_set[1] == pwm_count_cooler && pwm_cooler_pos_set[1] != COOLER_PWM_MASK) WRITE(EXT1_EXTRUDER_COOLER_PIN,0); #endif #endif #endif -#if defined(EXT2_HEATER_PIN) && EXT2_HEATER_PIN>-1 && NUM_EXTRUDER>2 +#if defined(EXT2_HEATER_PIN) && EXT2_HEATER_PIN > -1 && NUM_EXTRUDER > 2 #if PDM_FOR_EXTRUDER pulseDensityModulate(EXT2_HEATER_PIN, pwm_pos[2], pwm_pos_set[2], HEATER_PINS_INVERTED); #else - if(pwm_pos_set[2] == pwm_count_heater && pwm_pos_set[2]!=HEATER_PWM_MASK) WRITE(EXT2_HEATER_PIN,HEATER_PINS_INVERTED); + if(pwm_pos_set[2] == pwm_count_heater && pwm_pos_set[2] != HEATER_PWM_MASK) WRITE(EXT2_HEATER_PIN,HEATER_PINS_INVERTED); #endif #if !SHARED_COOLER && EXT2_EXTRUDER_COOLER_PIN > -1 #if PDM_FOR_COOLER pulseDensityModulate(EXT2_EXTRUDER_COOLER_PIN, extruder[2].coolerPWM, pwm_cooler_pos_set[2], false); #else - if(pwm_cooler_pos_set[2] == pwm_count && pwm_cooler_pos_set[2] != 255) WRITE(EXT2_EXTRUDER_COOLER_PIN,0); + if(pwm_cooler_pos_set[2] == pwm_count_cooler && pwm_cooler_pos_set[2] != COOLER_PWM_MASK) WRITE(EXT2_EXTRUDER_COOLER_PIN,0); #endif #endif #endif -#if defined(EXT3_HEATER_PIN) && EXT3_HEATER_PIN>-1 && NUM_EXTRUDER>3 +#if defined(EXT3_HEATER_PIN) && EXT3_HEATER_PIN>-1 && NUM_EXTRUDER > 3 #if PDM_FOR_EXTRUDER pulseDensityModulate(EXT3_HEATER_PIN, pwm_pos[3], pwm_pos_set[3], HEATER_PINS_INVERTED); #else @@ -878,11 +899,11 @@ ISR(PWM_TIMER_VECTOR) #if PDM_FOR_COOLER pulseDensityModulate(EXT3_EXTRUDER_COOLER_PIN, extruder[3].coolerPWM, pwm_cooler_pos_set[3], false); #else - if(pwm_cooler_pos_set[3] == pwm_count && pwm_cooler_pos_set[3] != 255) WRITE(EXT3_EXTRUDER_COOLER_PIN,0); + if(pwm_cooler_pos_set[3] == pwm_count_cooler && pwm_cooler_pos_set[3] != COOLER_PWM_MASK) WRITE(EXT3_EXTRUDER_COOLER_PIN,0); #endif #endif #endif -#if defined(EXT4_HEATER_PIN) && EXT4_HEATER_PIN>-1 && NUM_EXTRUDER>4 +#if defined(EXT4_HEATER_PIN) && EXT4_HEATER_PIN > -1 && NUM_EXTRUDER > 4 #if PDM_FOR_EXTRUDER pulseDensityModulate(EXT4_HEATER_PIN, pwm_pos[4], pwm_pos_set[4], HEATER_PINS_INVERTED); #else @@ -892,11 +913,11 @@ ISR(PWM_TIMER_VECTOR) #if PDM_FOR_COOLER pulseDensityModulate(EXT4_EXTRUDER_COOLER_PIN, extruder[4].coolerPWM, pwm_cooler_pos_set[4], false); #else - if(pwm_cooler_pos_set[4] == pwm_count && pwm_cooler_pos_set[4]!=255) WRITE(EXT4_EXTRUDER_COOLER_PIN,0); + if(pwm_cooler_pos_set[4] == pwm_count_cooler && pwm_cooler_pos_set[4] != COOLER_PWM_MASK) WRITE(EXT4_EXTRUDER_COOLER_PIN,0); #endif #endif #endif -#if defined(EXT5_HEATER_PIN) && EXT5_HEATER_PIN>-1 && NUM_EXTRUDER>5 +#if defined(EXT5_HEATER_PIN) && EXT5_HEATER_PIN>-1 && NUM_EXTRUDER > 5 #if PDM_FOR_EXTRUDER pulseDensityModulate(EXT5_HEATER_PIN, pwm_pos[5], pwm_pos_set[5], HEATER_PINS_INVERTED); #else @@ -906,7 +927,7 @@ ISR(PWM_TIMER_VECTOR) #if PDM_FOR_COOLER pulseDensityModulate(EXT5_EXTRUDER_COOLER_PIN, extruder[5].coolerPWM, pwm_cooler_pos_set[5], false); #else - if(pwm_cooler_pos_set[5] == pwm_count && pwm_cooler_pos_set[5] != 255) WRITE(EXT5_EXTRUDER_COOLER_PIN,0); + if(pwm_cooler_pos_set[5] == pwm_count_cooler && pwm_cooler_pos_set[5] != COOLER_PWM_MASK) WRITE(EXT5_EXTRUDER_COOLER_PIN,0); #endif #endif #endif @@ -914,7 +935,7 @@ ISR(PWM_TIMER_VECTOR) #if PDM_FOR_COOLER pulseDensityModulate(FAN_BOARD_PIN, pwm_pos[NUM_EXTRUDER + 1], pwm_pos_set[NUM_EXTRUDER + 1], false); #else - if(pwm_pos_set[NUM_EXTRUDER + 1] == pwm_count && pwm_pos_set[NUM_EXTRUDER + 1] != 255) WRITE(FAN_BOARD_PIN,0); + if(pwm_pos_set[NUM_EXTRUDER + 1] == pwm_count_cooler && pwm_pos_set[NUM_EXTRUDER + 1] != COOLER_PWM_MASK) WRITE(FAN_BOARD_PIN,0); #endif #endif #if FAN_PIN > -1 && FEATURE_FAN_CONTROL @@ -923,7 +944,7 @@ if(fanKickstart == 0) #if PDM_FOR_COOLER pulseDensityModulate(FAN_PIN, pwm_pos[NUM_EXTRUDER + 2], pwm_pos_set[NUM_EXTRUDER + 2], false); #else - if(pwm_pos_set[NUM_EXTRUDER + 2] == pwm_count && pwm_pos_set[NUM_EXTRUDER + 2] != 255) WRITE(FAN_PIN,0); + if(pwm_pos_set[NUM_EXTRUDER + 2] == pwm_count_cooler && pwm_pos_set[NUM_EXTRUDER + 2] != COOLER_PWM_MASK) WRITE(FAN_PIN,0); #endif } #endif @@ -978,7 +999,7 @@ if(fanKickstart == 0) #endif UI_FAST; // Short timed user interface action - pwm_count++; + pwm_count_cooler += COOLER_PWM_STEP; pwm_count_heater += HEATER_PWM_STEP; } #if USE_ADVANCE @@ -1142,7 +1163,7 @@ ISR(USART_UDRE_vect) #endif #if defined(BLUETOOTH_SERIAL) && BLUETOOTH_SERIAL > 0 -#if !(defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1281__) defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__)) +#if !(defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1281__) || defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__)) #error BlueTooth option cannot be used with your mainboard #endif #if BLUETOOTH_SERIAL > 1 && !(defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)) diff --git a/src/ArduinoAVR/Repetier/HAL.h b/src/ArduinoAVR/Repetier/HAL.h index 32e26ab74..da22fdb57 100644 --- a/src/ArduinoAVR/Repetier/HAL.h +++ b/src/ArduinoAVR/Repetier/HAL.h @@ -32,6 +32,10 @@ #include #include + + +#define INLINE __attribute__((always_inline)) + #if CPU_ARCH == ARCH_AVR #include #else @@ -140,6 +144,7 @@ typedef uint32_t ticks_t; typedef uint32_t millis_t; typedef uint8_t flag8_t; typedef int8_t fast8_t; +typedef uint8_t ufast8_t; #define FAST_INTEGER_SQRT diff --git a/src/ArduinoAVR/Repetier/Printer.cpp b/src/ArduinoAVR/Repetier/Printer.cpp index ca890ba3b..6e10af140 100644 --- a/src/ArduinoAVR/Repetier/Printer.cpp +++ b/src/ArduinoAVR/Repetier/Printer.cpp @@ -128,7 +128,6 @@ float Printer::offsetY; ///< Y-offset for different extruder speed_t Printer::vMaxReached; ///< Maximumu reached speed uint32_t Printer::msecondsPrinting; ///< Milliseconds of printing time (means time with heated extruder) float Printer::filamentPrinted; ///< mm of filament printed since counting started -uint8_t Printer::wasLastHalfstepping; ///< Indicates if last move had halfstepping enabled #if ENABLE_BACKLASH_COMPENSATION float Printer::backlashX; float Printer::backlashY; @@ -875,7 +874,6 @@ void Printer::setup() #if NONLINEAR_SYSTEM radius0 = ROD_RADIUS; #endif - wasLastHalfstepping = 0; #if ENABLE_BACKLASH_COMPENSATION backlashX = X_BACKLASH; backlashY = Y_BACKLASH; diff --git a/src/ArduinoAVR/Repetier/Printer.h b/src/ArduinoAVR/Repetier/Printer.h index c725e7bf7..c0cf63f54 100644 --- a/src/ArduinoAVR/Repetier/Printer.h +++ b/src/ArduinoAVR/Repetier/Printer.h @@ -51,7 +51,8 @@ union floatLong #endif }; -union wizardVar { +union wizardVar +{ float f; int32_t l; uint32_t ul; @@ -125,11 +126,11 @@ class Distortion void updateDerived(); void reportStatus(); private: - inline int matrixIndex(fast8_t x, fast8_t y) const; - inline int32_t getMatrix(int index) const; - inline void setMatrix(int32_t val, int index); + INLINE int matrixIndex(fast8_t x, fast8_t y) const; + INLINE int32_t getMatrix(int index) const; + INLINE void setMatrix(int32_t val, int index); bool isCorner(fast8_t i, fast8_t j) const; - inline int32_t extrapolatePoint(fast8_t x1, fast8_t y1, fast8_t x2, fast8_t y2) const; + INLINE int32_t extrapolatePoint(fast8_t x1, fast8_t y1, fast8_t x2, fast8_t y2) const; void extrapolateCorner(fast8_t x, fast8_t y, fast8_t dx, fast8_t dy); void extrapolateCorners(); void resetCorrection(); @@ -246,7 +247,6 @@ class Printer static speed_t vMaxReached; ///< Maximumu reached speed static uint32_t msecondsPrinting; ///< Milliseconds of printing time (means time with heated extruder) static float filamentPrinted; ///< mm of filament printed since counting started - static uint8_t wasLastHalfstepping; ///< Indicates if last move had halfstepping enabled #if ENABLE_BACKLASH_COMPENSATION static float backlashX; static float backlashY; @@ -276,12 +276,13 @@ class Printer static void handleInterruptEvent(); - static inline void setInterruptEvent(uint8_t evt, bool highPriority) { + static INLINE void setInterruptEvent(uint8_t evt, bool highPriority) + { if(highPriority || interruptEvent == 0) interruptEvent = evt; } - static inline void setMenuMode(uint8_t mode,bool on) + static INLINE void setMenuMode(uint8_t mode,bool on) { if(on) menuMode |= mode; @@ -289,58 +290,58 @@ class Printer menuMode &= ~mode; } - static inline bool isMenuMode(uint8_t mode) + static INLINE bool isMenuMode(uint8_t mode) { return (menuMode & mode)==mode; } - static inline bool debugEcho() + static INLINE bool debugEcho() { return ((debugLevel & 1)!=0); } - static inline bool debugInfo() + static INLINE bool debugInfo() { return ((debugLevel & 2)!=0); } - static inline bool debugErrors() + static INLINE bool debugErrors() { return ((debugLevel & 4)!=0); } - static inline bool debugDryrun() + static INLINE bool debugDryrun() { return ((debugLevel & 8)!=0); } - static inline bool debugCommunication() + static INLINE bool debugCommunication() { return ((debugLevel & 16)!=0); } - static inline bool debugNoMoves() + static INLINE bool debugNoMoves() { return ((debugLevel & 32)!=0); } - static inline bool debugFlag(unsigned long flags) + static INLINE bool debugFlag(unsigned long flags) { return (debugLevel & flags); } - static inline void debugSet(unsigned long flags) + static INLINE void debugSet(unsigned long flags) { debugLevel |= flags; } - static inline void debugReset(unsigned long flags) + static INLINE void debugReset(unsigned long flags) { debugLevel &= ~flags; } /** \brief Disable stepper motor for x direction. */ - static inline void disableXStepper() + static INLINE void disableXStepper() { #if (X_ENABLE_PIN > -1) WRITE(X_ENABLE_PIN, !X_ENABLE_ON); @@ -351,7 +352,7 @@ class Printer } /** \brief Disable stepper motor for y direction. */ - static inline void disableYStepper() + static INLINE void disableYStepper() { #if (Y_ENABLE_PIN > -1) WRITE(Y_ENABLE_PIN, !Y_ENABLE_ON); @@ -361,7 +362,7 @@ class Printer #endif } /** \brief Disable stepper motor for z direction. */ - static inline void disableZStepper() + static INLINE void disableZStepper() { #if (Z_ENABLE_PIN > -1) WRITE(Z_ENABLE_PIN, !Z_ENABLE_ON); @@ -372,7 +373,7 @@ class Printer } /** \brief Enable stepper motor for x direction. */ - static inline void enableXStepper() + static INLINE void enableXStepper() { #if (X_ENABLE_PIN > -1) WRITE(X_ENABLE_PIN, X_ENABLE_ON); @@ -383,7 +384,7 @@ class Printer } /** \brief Enable stepper motor for y direction. */ - static inline void enableYStepper() + static INLINE void enableYStepper() { #if (Y_ENABLE_PIN > -1) WRITE(Y_ENABLE_PIN, Y_ENABLE_ON); @@ -393,7 +394,7 @@ class Printer #endif } /** \brief Enable stepper motor for z direction. */ - static inline void enableZStepper() + static INLINE void enableZStepper() { #if (Z_ENABLE_PIN > -1) WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); @@ -403,7 +404,7 @@ class Printer #endif } - static inline void setXDirection(bool positive) + static INLINE void setXDirection(bool positive) { if(positive) { @@ -421,7 +422,7 @@ class Printer } } - static inline void setYDirection(bool positive) + static INLINE void setYDirection(bool positive) { if(positive) { @@ -438,7 +439,7 @@ class Printer #endif } } - static inline void setZDirection(bool positive) + static INLINE void setZDirection(bool positive) { if(positive) { @@ -456,117 +457,117 @@ class Printer } } - static inline bool getZDirection() + static INLINE bool getZDirection() { return ((READ(Z_DIR_PIN) != 0) ^ INVERT_Z_DIR); } - static inline bool getYDirection() + static INLINE bool getYDirection() { return((READ(Y_DIR_PIN) != 0) ^ INVERT_Y_DIR); } - static inline bool getXDirection() + static INLINE bool getXDirection() { return((READ(X_DIR_PIN) != 0) ^ INVERT_X_DIR); } - static inline uint8_t isLargeMachine() + static INLINE uint8_t isLargeMachine() { return flag0 & PRINTER_FLAG0_LARGE_MACHINE; } - static inline void setLargeMachine(uint8_t b) + static INLINE void setLargeMachine(uint8_t b) { flag0 = (b ? flag0 | PRINTER_FLAG0_LARGE_MACHINE : flag0 & ~PRINTER_FLAG0_LARGE_MACHINE); } - static inline uint8_t isAdvanceActivated() + static INLINE uint8_t isAdvanceActivated() { return flag0 & PRINTER_FLAG0_SEPERATE_EXTRUDER_INT; } - static inline void setAdvanceActivated(uint8_t b) + static INLINE void setAdvanceActivated(uint8_t b) { flag0 = (b ? flag0 | PRINTER_FLAG0_SEPERATE_EXTRUDER_INT : flag0 & ~PRINTER_FLAG0_SEPERATE_EXTRUDER_INT); } - static inline uint8_t isHomed() + static INLINE uint8_t isHomed() { return flag1 & PRINTER_FLAG1_HOMED; } - static inline void setHomed(uint8_t b) + static INLINE void setHomed(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_HOMED : flag1 & ~PRINTER_FLAG1_HOMED); } - static inline uint8_t isAllKilled() + static INLINE uint8_t isAllKilled() { return flag1 & PRINTER_FLAG1_ALLKILLED; } - static inline void setAllKilled(uint8_t b) + static INLINE void setAllKilled(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_ALLKILLED : flag1 & ~PRINTER_FLAG1_ALLKILLED); } - static inline uint8_t isAutomount() + static INLINE uint8_t isAutomount() { return flag1 & PRINTER_FLAG1_AUTOMOUNT; } - static inline void setAutomount(uint8_t b) + static INLINE void setAutomount(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_AUTOMOUNT : flag1 & ~PRINTER_FLAG1_AUTOMOUNT); } - static inline uint8_t isAnimation() + static INLINE uint8_t isAnimation() { return flag1 & PRINTER_FLAG1_ANIMATION; } - static inline void setAnimation(uint8_t b) + static INLINE void setAnimation(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_ANIMATION : flag1 & ~PRINTER_FLAG1_ANIMATION); } - static inline uint8_t isUIErrorMessage() + static INLINE uint8_t isUIErrorMessage() { return flag1 & PRINTER_FLAG1_UI_ERROR_MESSAGE; } - static inline void setUIErrorMessage(uint8_t b) + static INLINE void setUIErrorMessage(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_UI_ERROR_MESSAGE : flag1 & ~PRINTER_FLAG1_UI_ERROR_MESSAGE); } - static inline uint8_t isNoDestinationCheck() + static INLINE uint8_t isNoDestinationCheck() { return flag1 & PRINTER_FLAG1_NO_DESTINATION_CHECK; } - static inline void setNoDestinationCheck(uint8_t b) + static INLINE void setNoDestinationCheck(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_NO_DESTINATION_CHECK : flag1 & ~PRINTER_FLAG1_NO_DESTINATION_CHECK); } - static inline uint8_t isPowerOn() + static INLINE uint8_t isPowerOn() { return flag1 & PRINTER_FLAG1_POWER_ON; } - static inline void setPowerOn(uint8_t b) + static INLINE void setPowerOn(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_POWER_ON : flag1 & ~PRINTER_FLAG1_POWER_ON); } - static inline uint8_t isColdExtrusionAllowed() + static INLINE uint8_t isColdExtrusionAllowed() { return flag1 & PRINTER_FLAG1_ALLOW_COLD_EXTRUSION; } - static inline void setColdExtrusionAllowed(uint8_t b) + static INLINE void setColdExtrusionAllowed(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_ALLOW_COLD_EXTRUSION : flag1 & ~PRINTER_FLAG1_ALLOW_COLD_EXTRUSION); if(b) @@ -575,63 +576,63 @@ class Printer Com::printFLN(PSTR("Cold extrusion disallowed")); } - static inline uint8_t isBlockingReceive() + static INLINE uint8_t isBlockingReceive() { return flag2 & PRINTER_FLAG2_BLOCK_RECEIVING; } - static inline void setBlockingReceive(uint8_t b) + static INLINE void setBlockingReceive(uint8_t b) { flag2 = (b ? flag2 | PRINTER_FLAG2_BLOCK_RECEIVING : flag2 & ~PRINTER_FLAG2_BLOCK_RECEIVING); } - static inline uint8_t isAutoretract() + static INLINE uint8_t isAutoretract() { return flag2 & PRINTER_FLAG2_AUTORETRACT; } - static inline void setAutoretract(uint8_t b) + static INLINE void setAutoretract(uint8_t b) { flag2 = (b ? flag2 | PRINTER_FLAG2_AUTORETRACT : flag2 & ~PRINTER_FLAG2_AUTORETRACT); Com::printFLN(PSTR("Autoretract:"),b); } - static inline uint8_t isDebugJam() + static INLINE uint8_t isDebugJam() { return (flag2 & PRINTER_FLAG2_DEBUG_JAM) != 0; } - static inline uint8_t isDebugJamOrDisabled() + static INLINE uint8_t isDebugJamOrDisabled() { return (flag2 & (PRINTER_FLAG2_DEBUG_JAM | PRINTER_FLAG2_JAMCONTROL_DISABLED)) != 0; } - static inline void setDebugJam(uint8_t b) + static INLINE void setDebugJam(uint8_t b) { flag2 = (b ? flag2 | PRINTER_FLAG2_DEBUG_JAM : flag2 & ~PRINTER_FLAG2_DEBUG_JAM); Com::printFLN(PSTR("Jam debugging:"),b); } - static inline uint8_t isJamcontrolDisabled() + static INLINE uint8_t isJamcontrolDisabled() { return (flag2 & PRINTER_FLAG2_JAMCONTROL_DISABLED) != 0; } - static inline void setJamcontrolDisabled(uint8_t b) + static INLINE void setJamcontrolDisabled(uint8_t b) { flag2 = (b ? flag2 | PRINTER_FLAG2_JAMCONTROL_DISABLED : flag2 & ~PRINTER_FLAG2_JAMCONTROL_DISABLED); Com::printFLN(PSTR("Jam control disabled:"),b); } - static inline void toggleAnimation() + static INLINE void toggleAnimation() { setAnimation(!isAnimation()); } - static inline float convertToMM(float x) + static INLINE float convertToMM(float x) { return (unitIsInches ? x*25.4 : x); } - static inline bool isXMinEndstopHit() + static INLINE bool isXMinEndstopHit() { #if X_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_X return READ(X_MIN_PIN) != ENDSTOP_X_MIN_INVERTING; @@ -639,7 +640,7 @@ class Printer return false; #endif } - static inline bool isYMinEndstopHit() + static INLINE bool isYMinEndstopHit() { #if Y_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_Y return READ(Y_MIN_PIN) != ENDSTOP_Y_MIN_INVERTING; @@ -647,7 +648,7 @@ class Printer return false; #endif } - static inline bool isZMinEndstopHit() + static INLINE bool isZMinEndstopHit() { #if Z_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_Z return READ(Z_MIN_PIN) != ENDSTOP_Z_MIN_INVERTING; @@ -655,7 +656,7 @@ class Printer return false; #endif } - static inline bool isXMaxEndstopHit() + static INLINE bool isXMaxEndstopHit() { #if X_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_X return READ(X_MAX_PIN) != ENDSTOP_X_MAX_INVERTING; @@ -663,7 +664,7 @@ class Printer return false; #endif } - static inline bool isYMaxEndstopHit() + static INLINE bool isYMaxEndstopHit() { #if Y_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_Y return READ(Y_MAX_PIN) != ENDSTOP_Y_MAX_INVERTING; @@ -671,7 +672,7 @@ class Printer return false; #endif } - static inline bool isZMaxEndstopHit() + static INLINE bool isZMaxEndstopHit() { #if Z_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_Z return READ(Z_MAX_PIN) != ENDSTOP_Z_MAX_INVERTING; @@ -679,55 +680,55 @@ class Printer return false; #endif } - static inline bool areAllSteppersDisabled() + static INLINE bool areAllSteppersDisabled() { return flag0 & PRINTER_FLAG0_STEPPER_DISABLED; } - static inline void setAllSteppersDiabled() + static INLINE void setAllSteppersDiabled() { flag0 |= PRINTER_FLAG0_STEPPER_DISABLED; } - static inline void unsetAllSteppersDisabled() + static INLINE void unsetAllSteppersDisabled() { flag0 &= ~PRINTER_FLAG0_STEPPER_DISABLED; #if FAN_BOARD_PIN>-1 pwm_pos[NUM_EXTRUDER + 1] = 255; #endif // FAN_BOARD_PIN } - static inline bool isAnyTempsensorDefect() + static INLINE bool isAnyTempsensorDefect() { return (flag0 & PRINTER_FLAG0_TEMPSENSOR_DEFECT); } - static inline void setAnyTempsensorDefect() + static INLINE void setAnyTempsensorDefect() { flag0 |= PRINTER_FLAG0_TEMPSENSOR_DEFECT; } - static inline void unsetAnyTempsensorDefect() + static INLINE void unsetAnyTempsensorDefect() { flag0 &= ~PRINTER_FLAG0_TEMPSENSOR_DEFECT; } - static inline bool isManualMoveMode() + static INLINE bool isManualMoveMode() { return (flag0 & PRINTER_FLAG0_MANUAL_MOVE_MODE); } - static inline void setManualMoveMode(bool on) + static INLINE void setManualMoveMode(bool on) { flag0 = (on ? flag0 | PRINTER_FLAG0_MANUAL_MOVE_MODE : flag0 & ~PRINTER_FLAG0_MANUAL_MOVE_MODE); } - static inline bool isAutolevelActive() + static INLINE bool isAutolevelActive() { return (flag0 & PRINTER_FLAG0_AUTOLEVEL_ACTIVE)!=0; } static void setAutolevelActive(bool on); - static inline void setZProbingActive(bool on) + static INLINE void setZProbingActive(bool on) { flag0 = (on ? flag0 | PRINTER_FLAG0_ZPROBEING : flag0 & ~PRINTER_FLAG0_ZPROBEING); } - static inline bool isZProbingActive() + static INLINE bool isZProbingActive() { return (flag0 & PRINTER_FLAG0_ZPROBEING); } - static inline bool isZProbeHit() + static INLINE bool isZProbeHit() { #if FEATURE_Z_PROBE return (Z_PROBE_ON_HIGH ? READ(Z_PROBE_PIN) : !READ(Z_PROBE_PIN)); @@ -735,7 +736,7 @@ class Printer return false; #endif } - static inline void executeXYGantrySteps() + static INLINE void executeXYGantrySteps() { #if (GANTRY) if(motorX <= -2) @@ -772,7 +773,7 @@ class Printer } #endif } - static inline void executeXZGantrySteps() + static INLINE void executeXZGantrySteps() { #if (GANTRY) if(motorX <= -2) @@ -811,22 +812,22 @@ class Printer } #endif } - static inline void endXYZSteps() + static INLINE void endXYZSteps() { WRITE(X_STEP_PIN,LOW); - WRITE(Y_STEP_PIN,LOW); - WRITE(Z_STEP_PIN,LOW); #if FEATURE_TWO_XSTEPPER WRITE(X2_STEP_PIN,LOW); #endif + WRITE(Y_STEP_PIN,LOW); #if FEATURE_TWO_YSTEPPER WRITE(Y2_STEP_PIN,LOW); #endif + WRITE(Z_STEP_PIN,LOW); #if FEATURE_TWO_ZSTEPPER WRITE(Z2_STEP_PIN,LOW); #endif } - static inline speed_t updateStepsPerTimerCall(speed_t vbase) + static INLINE speed_t updateStepsPerTimerCall(speed_t vbase) { if(vbase > STEP_DOUBLER_FREQUENCY) { @@ -852,7 +853,7 @@ class Printer } return vbase; } - static inline void disableAllowedStepper() + static INLINE void disableAllowedStepper() { #if DRIVE_SYSTEM == XZ_GANTRY || DRIVE_SYSTEM == ZX_GANTRY if(DISABLE_X && DISABLE_Z) @@ -875,27 +876,27 @@ class Printer if(DISABLE_Z) disableZStepper(); #endif } - static inline float realXPosition() + static INLINE float realXPosition() { return currentPosition[X_AXIS]; } - static inline float realYPosition() + static INLINE float realYPosition() { return currentPosition[Y_AXIS]; } - static inline float realZPosition() + static INLINE float realZPosition() { return currentPosition[Z_AXIS]; } - static inline void realPosition(float &xp, float &yp, float &zp) + static INLINE void realPosition(float &xp, float &yp, float &zp) { xp = currentPosition[X_AXIS]; yp = currentPosition[Y_AXIS]; zp = currentPosition[Z_AXIS]; } - static inline void insertStepperHighDelay() + static INLINE void insertStepperHighDelay() { #if STEPPER_HIGH_DELAY>0 HAL::delayMicroseconds(STEPPER_HIGH_DELAY); @@ -914,12 +915,12 @@ class Printer static void homeAxis(bool xaxis,bool yaxis,bool zaxis); /// Home axis static void setOrigin(float xOff,float yOff,float zOff); static bool isPositionAllowed(float x,float y,float z); - static inline int getFanSpeed() + static INLINE int getFanSpeed() { return (int)pwm_pos[NUM_EXTRUDER + 2]; } #if NONLINEAR_SYSTEM - static inline void setDeltaPositions(long xaxis, long yaxis, long zaxis) + static INLINE void setDeltaPositions(long xaxis, long yaxis, long zaxis) { currentDeltaPositionSteps[A_TOWER] = xaxis; currentDeltaPositionSteps[B_TOWER] = yaxis; @@ -950,9 +951,18 @@ class Printer static void GoToMemoryPosition(bool x,bool y,bool z,bool e,float feed); static void zBabystep(); - static inline void resetWizardStack() {wizardStackPos = 0;} - static inline void pushWizardVar(wizardVar v) {wizardStack[wizardStackPos++] = v;} - static inline wizardVar popWizardVar() {return wizardStack[--wizardStackPos];} + static INLINE void resetWizardStack() + { + wizardStackPos = 0; + } + static INLINE void pushWizardVar(wizardVar v) + { + wizardStack[wizardStackPos++] = v; + } + static INLINE wizardVar popWizardVar() + { + return wizardStack[--wizardStackPos]; + } static void showConfiguration(); static void setCaseLight(bool on); static void reportCaseLightStatus(); diff --git a/src/ArduinoAVR/Repetier/motion.cpp b/src/ArduinoAVR/Repetier/motion.cpp index 5c5a2680a..c3516f240 100644 --- a/src/ArduinoAVR/Repetier/motion.cpp +++ b/src/ArduinoAVR/Repetier/motion.cpp @@ -36,9 +36,6 @@ #ifdef EXTRUDER_SPEED #error EXTRUDER_SPEED is not used any more. Values are now taken from extruder definition. #endif -#if MAX_HALFSTEP_INTERVAL<=1900 -#error MAX_HALFSTEP_INTERVAL must be greater then 1900 -#endif #ifdef ENDSTOPPULLUPS #error ENDSTOPPULLUPS is now replaced by individual pullup configuration! #endif @@ -86,9 +83,9 @@ PrintLine *PrintLine::cur = 0; ///< Current printing line #if CPU_ARCH == ARCH_ARM volatile bool PrintLine::nlFlag = false; #endif -uint8_t PrintLine::linesWritePos = 0; ///< Position where we write the next cached line move. -volatile uint8_t PrintLine::linesCount = 0; ///< Number of lines cached 0 = nothing to do. -uint8_t PrintLine::linesPos = 0; ///< Position for executing line movement. +ufast8_t PrintLine::linesWritePos = 0; ///< Position where we write the next cached line move. +volatile ufast8_t PrintLine::linesCount = 0; ///< Number of lines cached 0 = nothing to do. +ufast8_t PrintLine::linesPos = 0; ///< Position for executing line movement. /** Move printer the given number of steps. Puts the move into the queue. Used by e.g. homing commands. @@ -420,19 +417,6 @@ void PrintLine::calculateMove(float axis_diff[], uint8_t pathOptimize) #endif #endif - // Correct integers for fixed point math used in bresenham_step - if(fullInterval < MAX_HALFSTEP_INTERVAL || critical) - halfStep = 4; - else - { - halfStep = 1; -#if NONLINEAR_SYSTEM - // Error 0-2 are used for the towers and set up in the timer - error[E_AXIS] = stepsRemaining; -#else - error[X_AXIS] = error[Y_AXIS] = error[Z_AXIS] = error[E_AXIS] = delta[primaryAxis]; -#endif - } #ifdef DEBUG_STEPCOUNT // Set in delta move calculation #if !NONLINEAR_SYSTEM @@ -651,8 +635,8 @@ void PrintLine::updateStepsParameter() Com::printFLN(Com::tSlash,(long)stepsRemaining); Com::printF(Com::tDBGStartEndSpeed,startSpeed,1); Com::printFLN(Com::tSlash,endSpeed,1); - Com::printFLN(Com::tDBGFlags,flags); - Com::printFLN(Com::tDBGJoinFlags,joinFlags); + Com::printFLN(Com::tDBGFlags,(uint32_t)flags); + Com::printFLN(Com::tDBGJoinFlags,(uint32_t)joinFlags); } #endif } @@ -853,8 +837,8 @@ void PrintLine::logLine() #ifdef DEBUG_QUEUE_MOVE Com::printFLN(Com::tDBGId,(int)this); Com::printArrayFLN(Com::tDBGDelta,delta); - Com::printFLN(Com::tDBGDir,dir); - Com::printFLN(Com::tDBGFlags,flags); + Com::printFLN(Com::tDBGDir,(uint32_t)dir); + Com::printFLN(Com::tDBGFlags,(uint32_t)flags); Com::printFLN(Com::tDBGFullSpeed,fullSpeed); Com::printFLN(Com::tDBGVMax,(int32_t)vMax); Com::printFLN(Com::tDBGAcceleration,accelerationDistance2); @@ -904,7 +888,8 @@ uint8_t transformCartesianStepsToDeltaSteps(int32_t cartesianPosSteps[], int32_t static int32_t lastZSteps = 9999999; static int32_t lastZCorrection = 0; cnt++; - if(cnt >= DISTORTION_UPDATE_FREQUENCY || lastZSteps != zSteps) { + if(cnt >= DISTORTION_UPDATE_FREQUENCY || lastZSteps != zSteps) + { cnt = 0; lastZSteps = zSteps; lastZCorrection = Printer::distortion.correct(cartesianPosSteps[X_AXIS], cartesianPosSteps[Y_AXIS], cartesianPosSteps[Z_AXIS]); @@ -915,8 +900,8 @@ uint8_t transformCartesianStepsToDeltaSteps(int32_t cartesianPosSteps[], int32_t if(Printer::isLargeMachine()) { #ifdef SUPPORT_64_BIT_MATH - // 64 bit is better for precision, so we use that if available. - // A TOWER height + // 64 bit is better for precision, so we use that if available. + // A TOWER height uint64_t temp = RMath::absLong(Printer::deltaAPosYSteps - cartesianPosSteps[Y_AXIS]); uint64_t opt = Printer::deltaDiagonalStepsSquaredA.L; @@ -1214,16 +1199,6 @@ void DeltaSegment::checkEndstops(PrintLine *cur,bool checkall) setYMoveFinished(); cur->setYMoveFinished(); } - if(isXPositiveMove() && Printer::isXMaxEndstopHit()) - { - setXMoveFinished(); - cur->setXMoveFinished(); - } - if(isYPositiveMove() && Printer::isYMaxEndstopHit()) - { - setYMoveFinished(); - cur->setYMoveFinished(); - } #if DRIVE_SYSTEM != DELTA if(isXNegativeMove() && Printer::isXMinEndstopHit()) { @@ -1253,7 +1228,7 @@ void DeltaSegment::checkEndstops(PrintLine *cur,bool checkall) } -void PrintLine::calculateDirectionAndDelta(int32_t difference[], flag8_t *dir, int32_t delta[]) +void PrintLine::calculateDirectionAndDelta(int32_t difference[], ufast8_t *dir, int32_t delta[]) { *dir = 0; //Find direction @@ -1320,7 +1295,7 @@ inline uint16_t PrintLine::calculateDeltaSubSegments(uint8_t softEndstop) } #else float segment = static_cast(numDeltaSegments - s + 1); - for(i=0; i < Z_AXIS_ARRAY; i++) // End of segment in cartesian steps + for(i = 0; i < Z_AXIS_ARRAY; i++) // End of segment in cartesian steps // Perfect approximation, but slower, so we limit it to faster processors like arm destinationSteps[i] = static_cast(floor(0.5 + dx[i] * segment)) + Printer::currentPositionSteps[i]; #endif @@ -1485,12 +1460,13 @@ uint8_t PrintLine::queueDeltaMove(uint8_t check_endstops,uint8_t pathOptimize, u axis_diff[E_AXIS] = difference[E_AXIS] * Printer::invAxisStepsPerMM[E_AXIS]; Printer::filamentPrinted += axis_diff[E_AXIS]; axis_diff[E_AXIS] = fabs(axis_diff[E_AXIS]); - } else + } + else axis_diff[axis] = fabs(difference[axis] * Printer::invAxisStepsPerMM[axis]); } float cartesianDistance; - flag8_t cartesianDir; + ufast8_t cartesianDir; int32_t cartesianDeltaSteps[E_AXIS_ARRAY]; calculateDirectionAndDelta(difference, &cartesianDir, cartesianDeltaSteps); if (!calculateDistance(axis_diff, cartesianDir, &cartesianDistance)) @@ -1676,7 +1652,7 @@ void PrintLine::arc(float *position, float *target, float *offset, float radius, long ytarget = Printer::destinationSteps[Y_AXIS]; long ztarget = Printer::destinationSteps[Z_AXIS]; long etarget = Printer::destinationSteps[E_AXIS]; -*/ + */ // CCW angle between position and target from circle center. Only one atan2() trig computation required. float angular_travel = atan2(r_axis0 * rt_axis1 - r_axis1 * rt_axis0, r_axis0 * rt_axis0 + r_axis1 * rt_axis1); if (angular_travel < 0) @@ -1822,7 +1798,7 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer { HAL::allowInterrupts(); lastblk = (int)cur; - Com::printFLN(Com::tBLK, linesCount); + Com::printFLN(Com::tBLK, (int32_t)linesCount); } cur = NULL; #if CPU_ARCH==ARCH_ARM @@ -1885,20 +1861,12 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer // Copy across movement into main direction flags so that endstops function correctly cur->dir |= curd->dir; // Initialize bresenham for the first segment - if (cur->isFullstepping()) - { - cur->error[X_AXIS] = cur->error[Y_AXIS] = cur->error[Z_AXIS] = cur->numPrimaryStepPerSegment >> 1; - curd_errupd = cur->numPrimaryStepPerSegment; - } - else - { - cur->error[X_AXIS] = cur->error[Y_AXIS] = cur->error[Z_AXIS] = cur->numPrimaryStepPerSegment; - curd_errupd = cur->numPrimaryStepPerSegment = cur->numPrimaryStepPerSegment << 1; - } + cur->error[X_AXIS] = cur->error[Y_AXIS] = cur->error[Z_AXIS] = cur->numPrimaryStepPerSegment >> 1; + curd_errupd = cur->numPrimaryStepPerSegment; stepsPerSegRemaining = cur->numPrimaryStepPerSegment; } else curd = NULL; - cur_errupd = (cur->isFullstepping() ? cur->stepsRemaining : cur->stepsRemaining << 1); + cur_errupd = cur->stepsRemaining; if(!cur->areParameterUpToDate()) // should never happen, but with bad timings??? { @@ -1928,262 +1896,228 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer #endif cur->updateAdvanceSteps(cur->vStart, 0, false); #endif - if(Printer::wasLastHalfstepping && cur->isFullstepping()) // Switch halfstepping -> full stepping - { - Printer::wasLastHalfstepping = 0; - return Printer::interval + Printer::interval + Printer::interval; // Wait an other 150% from last half step to make the 100% full - } - else if(!Printer::wasLastHalfstepping && !cur->isFullstepping()) // Switch full to half stepping - { - Printer::wasLastHalfstepping = 1; - } - else - return Printer::interval; // Wait an other 50% from last step to make the 100% full + return Printer::interval; // Wait an other 50% from last step to make the 100% full } // End cur=0 HAL::allowInterrupts(); - /* For halfstepping, we divide the actions into even and odd actions to split - time used per loop. */ - flag8_t doEven = cur->halfStep & 6; - flag8_t doOdd = cur->halfStep & 5; - if(cur->halfStep != 4) cur->halfStep = 3 - (cur->halfStep); - if(doEven && curd != NULL) + if(curd != NULL) { curd->checkEndstops(cur,(cur->isCheckEndstops())); } int maxLoops = (Printer::stepsPerTimerCall <= cur->stepsRemaining ? Printer::stepsPerTimerCall : cur->stepsRemaining); HAL::forbidInterrupts(); - if(cur->stepsRemaining > 0) + for(int loop = 0; loop < maxLoops; loop++) { - for(int loop = 0; loop 0) - HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY); + if(loop > 0) + HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY); #endif - if(cur->isEMove()) - { - if((cur->error[E_AXIS] -= cur->delta[E_AXIS]) < 0) - { + if((cur->error[E_AXIS] -= cur->delta[E_AXIS]) < 0) + { #if USE_ADVANCE - if(Printer::isAdvanceActivated()) // Use interrupt for movement - { - if(cur->isEPositiveMove()) - Printer::extruderStepsNeeded++; - else - Printer::extruderStepsNeeded--; - } - else -#endif - Extruder::step(); - cur->error[E_AXIS] += cur_errupd; - } - } - if (curd) + if(Printer::isAdvanceActivated()) // Use interrupt for movement { - // Take delta steps - if(curd->isXMove()) + if(cur->isEPositiveMove()) + Printer::extruderStepsNeeded++; + else + Printer::extruderStepsNeeded--; + } + else +#endif + Extruder::step(); + cur->error[E_AXIS] += cur_errupd; + } + if (curd) + { + // Take delta steps + if(curd->isXMove()) + if((cur->error[X_AXIS] -= curd->deltaSteps[A_TOWER]) < 0) { - if((cur->error[X_AXIS] -= curd->deltaSteps[A_TOWER]) < 0) - { - cur->startXStep(); - cur->error[X_AXIS] += curd_errupd; + cur->startXStep(); + cur->error[X_AXIS] += curd_errupd; #ifdef DEBUG_REAL_POSITION - Printer::realDeltaPositionSteps[A_TOWER] += curd->isXPositiveMove() ? 1 : -1; + Printer::realDeltaPositionSteps[A_TOWER] += curd->isXPositiveMove() ? 1 : -1; #endif #ifdef DEBUG_STEPCOUNT - cur->totalStepsRemaining--; + cur->totalStepsRemaining--; #endif - } } - if(curd->isYMove()) + if(curd->isYMove()) + if((cur->error[Y_AXIS] -= curd->deltaSteps[B_TOWER]) < 0) { - if((cur->error[Y_AXIS] -= curd->deltaSteps[B_TOWER]) < 0) - { - cur->startYStep(); - cur->error[Y_AXIS] += curd_errupd; + cur->startYStep(); + cur->error[Y_AXIS] += curd_errupd; #ifdef DEBUG_REAL_POSITION - Printer::realDeltaPositionSteps[B_TOWER] += curd->isYPositiveMove() ? 1 : -1; + Printer::realDeltaPositionSteps[B_TOWER] += curd->isYPositiveMove() ? 1 : -1; #endif #ifdef DEBUG_STEPCOUNT - cur->totalStepsRemaining--; + cur->totalStepsRemaining--; #endif - } } - if(curd->isZMove()) + if(curd->isZMove()) + if((cur->error[Z_AXIS] -= curd->deltaSteps[C_TOWER]) < 0) { - if((cur->error[Z_AXIS] -= curd->deltaSteps[C_TOWER]) < 0) - { - cur->startZStep(); - cur->error[Z_AXIS] += curd_errupd; - Printer::realDeltaPositionSteps[C_TOWER] += curd->isZPositiveMove() ? 1 : -1; + cur->startZStep(); + cur->error[Z_AXIS] += curd_errupd; + Printer::realDeltaPositionSteps[C_TOWER] += curd->isZPositiveMove() ? 1 : -1; #ifdef DEBUG_STEPCOUNT - cur->totalStepsRemaining--; + cur->totalStepsRemaining--; #endif - } } - stepsPerSegRemaining--; - if (!stepsPerSegRemaining) + stepsPerSegRemaining--; + if (!stepsPerSegRemaining) + { + if (cur->numDeltaSegments) { - if (cur->numDeltaSegments) - { - // Get the next delta segment - curd = &cur->segments[--cur->numDeltaSegments]; + // Get the next delta segment + curd = &cur->segments[--cur->numDeltaSegments]; - // Initialize bresenham for this segment (numPrimaryStepPerSegment is already correct for the half step setting) - cur->error[X_AXIS] = cur->error[Y_AXIS] = cur->error[Z_AXIS] = cur->numPrimaryStepPerSegment >> 1; + // Initialize bresenham for this segment (numPrimaryStepPerSegment is already correct for the half step setting) + cur->error[X_AXIS] = cur->error[Y_AXIS] = cur->error[Z_AXIS] = cur->numPrimaryStepPerSegment >> 1; - // Reset the counter of the primary steps. This is initialized in the line - // generation so don't have to do this the first time. - stepsPerSegRemaining = cur->numPrimaryStepPerSegment; + // Reset the counter of the primary steps. This is initialized in the line + // generation so don't have to do this the first time. + stepsPerSegRemaining = cur->numPrimaryStepPerSegment; - // Change direction if necessary - Printer::setXDirection(curd->dir & X_DIRPOS); - Printer::setYDirection(curd->dir & Y_DIRPOS); - Printer::setZDirection(curd->dir & Z_DIRPOS); + // Change direction if necessary + Printer::setXDirection(curd->dir & X_DIRPOS); + Printer::setYDirection(curd->dir & Y_DIRPOS); + Printer::setZDirection(curd->dir & Z_DIRPOS); #if defined(DIRECTION_DELAY) && DIRECTION_DELAY > 0 - HAL::delayMicroseconds(DIRECTION_DELAY); + HAL::delayMicroseconds(DIRECTION_DELAY); #endif - if(FEATURE_BABYSTEPPING && Printer::zBabystepsMissing && curd - && (curd->dir & XYZ_STEP) == XYZ_STEP) + if(FEATURE_BABYSTEPPING && Printer::zBabystepsMissing && curd + && (curd->dir & XYZ_STEP) == XYZ_STEP) + { + // execute a extra babystep + Printer::insertStepperHighDelay(); + Printer::endXYZSteps(); + HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY+1); + + if(Printer::zBabystepsMissing > 0) + { + if(curd->dir & X_DIRPOS) + cur->startXStep(); + else + cur->error[X_AXIS] += curd_errupd; + if(curd->dir & Y_DIRPOS) + cur->startYStep(); + else + cur->error[Y_AXIS] += curd_errupd; + if(curd->dir & Z_DIRPOS) + cur->startZStep(); + else + cur->error[Z_AXIS] += curd_errupd; + Printer::zBabystepsMissing--; + } + else { - // execute a extra babystep - Printer::insertStepperHighDelay(); - Printer::endXYZSteps(); - HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY+1); - - if(Printer::zBabystepsMissing > 0) - { - if(curd->dir & X_DIRPOS) - cur->startXStep(); - else - cur->error[X_AXIS] += curd_errupd; - if(curd->dir & Y_DIRPOS) - cur->startYStep(); - else - cur->error[Y_AXIS] += curd_errupd; - if(curd->dir & Z_DIRPOS) - cur->startZStep(); - else - cur->error[Z_AXIS] += curd_errupd; - Printer::zBabystepsMissing--; - } + if(curd->dir & X_DIRPOS) + cur->error[X_AXIS] += curd_errupd; else - { - if(curd->dir & X_DIRPOS) - cur->error[X_AXIS] += curd_errupd; - else - cur->startXStep(); - if(curd->dir & Y_DIRPOS) - cur->error[Y_AXIS] += curd_errupd; - else - cur->startYStep(); - if(curd->dir & Z_DIRPOS) - cur->error[Z_AXIS] += curd_errupd; - else - cur->startZStep(); - Printer::zBabystepsMissing++; - } - HAL::delayMicroseconds(1); + cur->startXStep(); + if(curd->dir & Y_DIRPOS) + cur->error[Y_AXIS] += curd_errupd; + else + cur->startYStep(); + if(curd->dir & Z_DIRPOS) + cur->error[Z_AXIS] += curd_errupd; + else + cur->startZStep(); + Printer::zBabystepsMissing++; } + HAL::delayMicroseconds(1); } - else - curd = 0;// Release the last segment - //deltaSegmentCount--; } + else + curd = 0;// Release the last segment + //deltaSegmentCount--; } + } #if CPU_ARCH != ARCH_AVR - if(loop < maxLoops-1) - { + if(loop < maxLoops - 1) + { #endif - Printer::insertStepperHighDelay(); - Printer::endXYZSteps(); + Printer::insertStepperHighDelay(); + Printer::endXYZSteps(); #if USE_ADVANCE - if(!Printer::isAdvanceActivated()) // Use interrupt for movement + if(!Printer::isAdvanceActivated()) // Use interrupt for movement #endif - Extruder::unstep(); + Extruder::unstep(); #if CPU_ARCH != ARCH_AVR - } + } #endif - } // for loop + } // for loop - if(doOdd) - { - HAL::allowInterrupts(); // Allow interrupts for other types, timer1 is still disabled + HAL::allowInterrupts(); // Allow interrupts for other types, timer1 is still disabled #if RAMP_ACCELERATION - //If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval - if (cur->moveAccelerating()) - { - Printer::vMaxReached = HAL::ComputeV(Printer::timer, cur->fAcceleration) + cur->vStart; - if(Printer::vMaxReached > cur->vMax) Printer::vMaxReached = cur->vMax; - speed_t v = Printer::updateStepsPerTimerCall(Printer::vMaxReached); - Printer::interval = HAL::CPUDivU2(v); - Printer::timer += Printer::interval; - cur->updateAdvanceSteps(Printer::vMaxReached, maxLoops, true); - } - else if (cur->moveDecelerating()) // time to slow down +//If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval + if (cur->moveAccelerating()) + { + Printer::vMaxReached = HAL::ComputeV(Printer::timer, cur->fAcceleration) + cur->vStart; + if(Printer::vMaxReached > cur->vMax) Printer::vMaxReached = cur->vMax; + speed_t v = Printer::updateStepsPerTimerCall(Printer::vMaxReached); + Printer::interval = HAL::CPUDivU2(v); + Printer::timer += Printer::interval; + cur->updateAdvanceSteps(Printer::vMaxReached, maxLoops, true); + Printer::stepNumber += maxLoops; // is only used by moveAccelerating + } + else if (cur->moveDecelerating()) // time to slow down + { + speed_t v = HAL::ComputeV(Printer::timer, cur->fAcceleration); + if (v > Printer::vMaxReached) // if deceleration goes too far it can become too large + v = cur->vEnd; + else + { + v = Printer::vMaxReached - v; + if (v < cur->vEnd) v = cur->vEnd; // extra steps at the end of desceleration due to rounding erros + } + cur->updateAdvanceSteps(v, maxLoops, false); + v = Printer::updateStepsPerTimerCall(v); + Printer::interval = HAL::CPUDivU2(v); + Printer::timer += Printer::interval; + } + else + { + // If we had acceleration, we need to use the latest vMaxReached and interval + // If we started full speed, we need to use cur->fullInterval and vMax + cur->updateAdvanceSteps((!cur->accelSteps ? cur->vMax : Printer::vMaxReached), 0, true); + if(!cur->accelSteps) + { + if(cur->vMax > STEP_DOUBLER_FREQUENCY) { - speed_t v = HAL::ComputeV(Printer::timer, cur->fAcceleration); - if (v > Printer::vMaxReached) // if deceleration goes too far it can become too large - v = cur->vEnd; +#if ALLOW_QUADSTEPPING + if(cur->vMax > STEP_DOUBLER_FREQUENCY * 2) + { + Printer::stepsPerTimerCall = 4; + Printer::interval = cur->fullInterval << 2; + } else { - v = Printer::vMaxReached - v; - if (vvEnd) v = cur->vEnd; // extra steps at the end of desceleration due to rounding erros + Printer::stepsPerTimerCall = 2; + Printer::interval = cur->fullInterval << 1; } - cur->updateAdvanceSteps(v, maxLoops, false); - v = Printer::updateStepsPerTimerCall(v); - Printer::interval = HAL::CPUDivU2(v); - Printer::timer += Printer::interval; +#else + Printer::stepsPerTimerCall = 2; + Printer::interval = cur->fullInterval << 1; +#endif } else { - // If we had acceleration, we need to use the latest vMaxReached and interval - // If we started full speed, we need to use cur->fullInterval and vMax - cur->updateAdvanceSteps((!cur->accelSteps ? cur->vMax : Printer::vMaxReached), 0, true); - if(!cur->accelSteps) - { - if(cur->vMax > STEP_DOUBLER_FREQUENCY) - { -#if ALLOW_QUADSTEPPING - if(cur->vMax > STEP_DOUBLER_FREQUENCY * 2) - { - Printer::stepsPerTimerCall = 4; - Printer::interval = cur->fullInterval << 2; - } - else - { - Printer::stepsPerTimerCall = 2; - Printer::interval = cur->fullInterval << 1; - } -#else - Printer::stepsPerTimerCall = 2; - Printer::interval = cur->fullInterval << 1; -#endif - } - else - { - Printer::stepsPerTimerCall = 1; - Printer::interval = cur->fullInterval; - } - } + Printer::stepsPerTimerCall = 1; + Printer::interval = cur->fullInterval; } + } + } #else - Printer::interval = cur->fullInterval; // without RAMPS always use full speed + Printer::interval = cur->fullInterval; // without RAMPS always use full speed #endif - } // doOdd - if(doEven) - { - Printer::stepNumber += maxLoops; - PrintLine::cur->stepsRemaining -= maxLoops; - } + PrintLine::cur->stepsRemaining -= maxLoops; - } // stepsRemaining - int32_t interval = (cur->isFullstepping() ? Printer::interval : Printer::interval >> 1); - if(doEven &&(cur->stepsRemaining <= 0 || cur->isNoMove())) // line finished + if(cur->stepsRemaining <= 0 || cur->isNoMove()) // line finished { // Release remaining delta segments #ifdef DEBUG_STEPCOUNT @@ -2192,7 +2126,6 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer Com::printFLN(PSTR("Missed steps:"), cur->totalStepsRemaining); Com::printFLN(PSTR("Step/seg r:"), stepsPerSegRemaining); Com::printFLN(PSTR("NDS:"), (int) cur->numDeltaSegments); - Com::printFLN(PSTR("HS:"), (int) cur->halfStep); } #endif //HAL::forbidInterrupts(); @@ -2200,7 +2133,7 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer removeCurrentLineForbidInterrupt(); Printer::disableAllowedStepper(); if(linesCount == 0) UI_STATUS(UI_TEXT_IDLE); - interval = Printer::interval = interval >> 1; // 50% of time to next call to do cur=0 + Printer::interval >>= 1; // 50% of time to next call to do cur=0 DEBUG_MEMORY; } // Do even #if CPU_ARCH != ARCH_AVR @@ -2211,7 +2144,7 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer #endif Extruder::unstep(); #endif - return interval; + return Printer::interval; } #else /** @@ -2297,7 +2230,7 @@ int32_t PrintLine::bresenhamStep() // version for cartesian printer if(cur->isEMove()) Extruder::enable(); cur->fixStartAndEndSpeed(); HAL::allowInterrupts(); - cur_errupd = (cur->isFullstepping() ? cur->delta[cur->primaryAxis] : cur->delta[cur->primaryAxis]<<1);; + cur_errupd = cur->delta[cur->primaryAxis]; if(!cur->areParameterUpToDate()) // should never happen, but with bad timings??? { cur->updateStepsParameter(); @@ -2346,173 +2279,135 @@ int32_t PrintLine::bresenhamStep() // version for cartesian printer #endif cur->updateAdvanceSteps(cur->vStart, 0, false); #endif - if(Printer::wasLastHalfstepping && cur->isFullstepping()) // Switch halfstepping -> full stepping - { - Printer::wasLastHalfstepping = 0; - return Printer::interval+Printer::interval+Printer::interval; // Wait an other 150% from last half step to make the 100% full - } - else if(!Printer::wasLastHalfstepping && !cur->isFullstepping()) // Switch full to half stepping - { - Printer::wasLastHalfstepping = 1; - } - else - return Printer::interval; // Wait an other 50% from last step to make the 100% full + return Printer::interval; // Wait an other 50% from last step to make the 100% full } // End cur=0 - HAL::allowInterrupts(); - /* For halfstepping, we divide the actions into even and odd actions to split - time used per loop. */ - uint8_t doEven = cur->halfStep & 6; - uint8_t doOdd = cur->halfStep & 5; - if(cur->halfStep != 4) cur->halfStep = 3 - (cur->halfStep); - HAL::forbidInterrupts(); - if(doEven) cur->checkEndstops(); - uint8_t max_loops = RMath::min((long)Printer::stepsPerTimerCall,cur->stepsRemaining); - if(cur->stepsRemaining > 0) + cur->checkEndstops(); + fast8_t max_loops = RMath::min((int32_t)Printer::stepsPerTimerCall,cur->stepsRemaining); + for(fast8_t loop = 0; loop < max_loops; loop++) { - for(uint8_t loop = 0; loop < max_loops; loop++) - { #if STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY > 0 - if(loop > 0) - HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY); + if(loop > 0) + HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY); #endif - if(cur->isEMove()) - { - if((cur->error[E_AXIS] -= cur->delta[E_AXIS]) < 0) - { + if((cur->error[E_AXIS] -= cur->delta[E_AXIS]) < 0) + { #if USE_ADVANCE - if(Printer::isAdvanceActivated()) // Use interrupt for movement - { - if(cur->isEPositiveMove()) - Printer::extruderStepsNeeded++; - else - Printer::extruderStepsNeeded--; - } - else -#endif - Extruder::step(); - cur->error[E_AXIS] += cur_errupd; - } + if(Printer::isAdvanceActivated()) // Use interrupt for movement + { + if(cur->isEPositiveMove()) + Printer::extruderStepsNeeded++; + else + Printer::extruderStepsNeeded--; } - if(cur->isXMove()) + else +#endif + Extruder::step(); + cur->error[E_AXIS] += cur_errupd; + } + if(cur->isXMove()) + if((cur->error[X_AXIS] -= cur->delta[X_AXIS]) < 0) { - if((cur->error[X_AXIS] -= cur->delta[X_AXIS]) < 0) - { - cur->startXStep(); - cur->error[X_AXIS] += cur_errupd; - } + cur->startXStep(); + cur->error[X_AXIS] += cur_errupd; } - if(cur->isYMove()) + if(cur->isYMove()) + if((cur->error[Y_AXIS] -= cur->delta[Y_AXIS]) < 0) { - if((cur->error[Y_AXIS] -= cur->delta[Y_AXIS]) < 0) - { - cur->startYStep(); - cur->error[Y_AXIS] += cur_errupd; - } + cur->startYStep(); + cur->error[Y_AXIS] += cur_errupd; } - if(cur->isZMove()) + if(cur->isZMove()) + if((cur->error[Z_AXIS] -= cur->delta[Z_AXIS]) < 0) { - if((cur->error[Z_AXIS] -= cur->delta[Z_AXIS]) < 0) - { - cur->startZStep(); - cur->error[Z_AXIS] += cur_errupd; + cur->startZStep(); + cur->error[Z_AXIS] += cur_errupd; #ifdef DEBUG_STEPCOUNT - cur->totalStepsRemaining--; + cur->totalStepsRemaining--; #endif - } } #if (GANTRY) #if DRIVE_SYSTEM == XY_GANTRY || DRIVE_SYSTEM == YX_GANTRY - Printer::executeXYGantrySteps(); + Printer::executeXYGantrySteps(); #else - Printer::executeXZGantrySteps(); + Printer::executeXZGantrySteps(); #endif #endif - Printer::insertStepperHighDelay(); + Printer::insertStepperHighDelay(); #if USE_ADVANCE - if(!Printer::isAdvanceActivated()) // Use interrupt for movement + if(!Printer::isAdvanceActivated()) // Use interrupt for movement #endif - Extruder::unstep(); - Printer::endXYZSteps(); - } // for loop - if(doOdd) // Update timings - { - HAL::allowInterrupts(); // Allow interrupts for other types, timer1 is still disabled + Extruder::unstep(); + Printer::endXYZSteps(); + } // for loop + HAL::allowInterrupts(); // Allow interrupts for other types, timer1 is still disabled #if RAMP_ACCELERATION - //If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval - if (cur->moveAccelerating()) // we are accelerating + //If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval + if (cur->moveAccelerating()) // we are accelerating + { + Printer::vMaxReached = HAL::ComputeV(Printer::timer,cur->fAcceleration) + cur->vStart; + if(Printer::vMaxReached > cur->vMax) Printer::vMaxReached = cur->vMax; + unsigned int v = Printer::updateStepsPerTimerCall(Printer::vMaxReached); + Printer::interval = HAL::CPUDivU2(v); + Printer::timer += Printer::interval; + cur->updateAdvanceSteps(Printer::vMaxReached, max_loops, true); + Printer::stepNumber += max_loops; // only used for moveAccelerating + } + else if (cur->moveDecelerating()) // time to slow down + { + unsigned int v = HAL::ComputeV(Printer::timer,cur->fAcceleration); + if (v > Printer::vMaxReached) // if deceleration goes too far it can become too large + v = cur->vEnd; + else + { + v = Printer::vMaxReached - v; + if (vvEnd) v = cur->vEnd; // extra steps at the end of desceleration due to rounding erros + } + cur->updateAdvanceSteps(v,max_loops,false); // needs original v + v = Printer::updateStepsPerTimerCall(v); + Printer::interval = HAL::CPUDivU2(v); + Printer::timer += Printer::interval; + } + else // full speed reached + { + cur->updateAdvanceSteps((!cur->accelSteps ? cur->vMax : Printer::vMaxReached), 0, true); + // constant speed reached + if(cur->vMax > STEP_DOUBLER_FREQUENCY) + { +#if ALLOW_QUADSTEPPING + if(cur->vMax > STEP_DOUBLER_FREQUENCY * 2) { - Printer::vMaxReached = HAL::ComputeV(Printer::timer,cur->fAcceleration)+cur->vStart; - if(Printer::vMaxReached>cur->vMax) Printer::vMaxReached = cur->vMax; - unsigned int v = Printer::updateStepsPerTimerCall(Printer::vMaxReached); - Printer::interval = HAL::CPUDivU2(v); - Printer::timer+=Printer::interval; - cur->updateAdvanceSteps(Printer::vMaxReached,max_loops,true); + Printer::stepsPerTimerCall = 4; + Printer::interval = cur->fullInterval << 2; } - else if (cur->moveDecelerating()) // time to slow down + else { - unsigned int v = HAL::ComputeV(Printer::timer,cur->fAcceleration); - if (v > Printer::vMaxReached) // if deceleration goes too far it can become too large - v = cur->vEnd; - else - { - v=Printer::vMaxReached - v; - if (vvEnd) v = cur->vEnd; // extra steps at the end of desceleration due to rounding erros - } - cur->updateAdvanceSteps(v,max_loops,false); // needs original v - v = Printer::updateStepsPerTimerCall(v); - Printer::interval = HAL::CPUDivU2(v); - Printer::timer += Printer::interval; + Printer::stepsPerTimerCall = 2; + Printer::interval = cur->fullInterval << 1; } - else // full speed reached - { - cur->updateAdvanceSteps((!cur->accelSteps ? cur->vMax : Printer::vMaxReached),0,true); - // constant speed reached - if(cur->vMax>STEP_DOUBLER_FREQUENCY) - { -#if ALLOW_QUADSTEPPING - if(cur->vMax>STEP_DOUBLER_FREQUENCY*2) - { - Printer::stepsPerTimerCall = 4; - Printer::interval = cur->fullInterval << 2; - } - else - { - Printer::stepsPerTimerCall = 2; - Printer::interval = cur->fullInterval << 1; - } #else - Printer::stepsPerTimerCall = 2; - Printer::interval = cur->fullInterval << 1; + Printer::stepsPerTimerCall = 2; + Printer::interval = cur->fullInterval << 1; #endif - } - else - { - Printer::stepsPerTimerCall = 1; - Printer::interval = cur->fullInterval; - } - } -#else - Printer::stepsPerTimerCall = 1; - Printer::interval = cur->fullInterval; // without RAMPS always use full speed -#endif // RAMP_ACCELERATION - } // doOdd - if(doEven) + } + else { - Printer::stepNumber += max_loops; - cur->stepsRemaining -= max_loops; + Printer::stepsPerTimerCall = 1; + Printer::interval = cur->fullInterval; } - - } // stepsRemaining - long interval; - if(!cur->isFullstepping()) interval = (Printer::interval>>1); // time to come back - else interval = Printer::interval; - if(doEven && (cur->stepsRemaining <= 0 || cur->isNoMove())) // line finished + } +#else + Printer::stepsPerTimerCall = 1; + Printer::interval = cur->fullInterval; // without RAMPS always use full speed +#endif // RAMP_ACCELERATION + cur->stepsRemaining -= max_loops; + long interval = Printer::interval; + if(cur->stepsRemaining <= 0 || cur->isNoMove()) // line finished { #ifdef DEBUG_STEPCOUNT if(cur->totalStepsRemaining) { - Com::printF(Com::tDBGMissedSteps,cur->totalStepsRemaining); - Com::printFLN(Com::tComma,cur->stepsRemaining); + Com::printF(Com::tDBGMissedSteps, cur->totalStepsRemaining); + Com::printFLN(Com::tComma, cur->stepsRemaining); } #endif removeCurrentLineForbidInterrupt(); diff --git a/src/ArduinoAVR/Repetier/motion.h b/src/ArduinoAVR/Repetier/motion.h index 5ee8e494e..97032dcae 100644 --- a/src/ArduinoAVR/Repetier/motion.h +++ b/src/ArduinoAVR/Repetier/motion.h @@ -136,7 +136,7 @@ typedef struct } inline bool isNoMove() { - return (dir & XYZE_STEP)==0; + return (dir & XYZE_STEP) == 0; } inline bool isXYZMove() { @@ -148,15 +148,15 @@ typedef struct } inline void setMoveOfAxis(uint8_t axis) { - dir |= XSTEP<= PRINTLINE_CACHE_SIZE) linesPos=0; + if(linesPos >= PRINTLINE_CACHE_SIZE) linesPos = 0; cur = NULL; -#if CPU_ARCH==ARCH_ARM +#if CPU_ARCH == ARCH_ARM nlFlag = false; #endif HAL::forbidInterrupts(); @@ -691,7 +684,7 @@ class PrintLine // RAM usage: 24*4+15 = 113 Byte static uint8_t queueDeltaMove(uint8_t check_endstops,uint8_t pathOptimize, uint8_t softEndstop); static inline void queueEMove(int32_t e_diff,uint8_t check_endstops,uint8_t pathOptimize); inline uint16_t calculateDeltaSubSegments(uint8_t softEndstop); - static inline void calculateDirectionAndDelta(int32_t difference[], flag8_t *dir, int32_t delta[]); + static inline void calculateDirectionAndDelta(int32_t difference[], ufast8_t *dir, int32_t delta[]); static inline uint8_t calculateDistance(float axis_diff[], uint8_t dir, float *distance); #if SOFTWARE_LEVELING && DRIVE_SYSTEM == DELTA static void calculatePlane(int32_t factors[], int32_t p1[], int32_t p2[], int32_t p3[]); diff --git a/src/ArduinoAVR/Repetier/ui.cpp b/src/ArduinoAVR/Repetier/ui.cpp index d72b7086d..5c884d026 100644 --- a/src/ArduinoAVR/Repetier/ui.cpp +++ b/src/ArduinoAVR/Repetier/ui.cpp @@ -453,6 +453,52 @@ void lcdWriteByte(uint8_t c,uint8_t rs) HAL::delayMicroseconds(100); } +#ifdef TRY_AUTOREPAIR_LCD_ERRORS +#define HAS_AUTOREPAIR +/* Fast repair function for displays loosing their settings. + Do not call this if your display has no problems. +*/ +void repairLCD() { + // Now we pull both RS and R/W low to begin commands + WRITE(UI_DISPLAY_RS_PIN, LOW); + WRITE(UI_DISPLAY_ENABLE_PIN, LOW); + + //put the LCD into 4 bit mode + // this is according to the hitachi HD44780 datasheet + // figure 24, pg 46 + + // we start in 8bit mode, try to set 4 bit mode + // at this point we are in 8 bit mode but of course in this + // interface 4 pins are dangling unconnected and the values + // on them don't matter for these instructions. + WRITE(UI_DISPLAY_RS_PIN, LOW); + HAL::delayMicroseconds(20); + lcdWriteNibble(0x03); + HAL::delayMicroseconds(5000); // I have one LCD for which 4500 here was not long enough. + // second try + //lcdWriteNibble(0x03); + //HAL::delayMicroseconds(5000); // wait + // third go! + //lcdWriteNibble(0x03); + //HAL::delayMicroseconds(160); + // finally, set to 4-bit interface + lcdWriteNibble(0x02); + HAL::delayMicroseconds(160); + // finally, set # lines, font size, etc. + lcdCommand(LCD_4BIT | LCD_2LINE | LCD_5X7); + lcdCommand(LCD_INCREASE | LCD_DISPLAYSHIFTOFF); //- Entrymode (Display Shift: off, Increment Address Counter) + lcdCommand(LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKINGOFF); //- Display on + uid.lastSwitch = uid.lastRefresh = HAL::timeInMilliseconds(); + uid.createChar(1, character_back); + uid.createChar(2, character_degree); + uid.createChar(3, character_selected); + uid.createChar(4, character_unselected); + uid.createChar(5, character_temperature); + uid.createChar(6, character_folder); + uid.createChar(7, character_ready); +} +#endif + void initializeLCD() { // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! @@ -3133,6 +3179,7 @@ int UIDisplay::executeAction(int action, bool allowMoves) #if FEATURE_RETRACTION case UI_ACTION_WIZARD_FILAMENTCHANGE: { + if(Printer::isBlockingReceive()) break; Printer::setJamcontrolDisabled(true); Com::printFLN(PSTR("important: Filament change required!")); Printer::setBlockingReceive(true); @@ -3487,6 +3534,14 @@ void UIDisplay::slowAction(bool allowMoves) } if(refresh) // does lcd need a refresh? { +#if defined(TRY_AUTOREPAIR_LCD_ERRORS) +#if defined(HAS_AUTOREPAIR) + repairLCD(); +#else + #error TRY_AUTOREPAIR_LCD_ERRORS is not supported for your display type! +#endif +#endif + if (menuLevel > 1 || Printer::isAutomount()) { shift++; diff --git a/src/ArduinoAVR/Repetier/ui.h b/src/ArduinoAVR/Repetier/ui.h index 722703440..870cd6864 100644 --- a/src/ArduinoAVR/Repetier/ui.h +++ b/src/ArduinoAVR/Repetier/ui.h @@ -1453,7 +1453,7 @@ void uiCheckSlowKeys(int &action) {} #endif #define UI_INITIALIZE uid.initialize(); -#define UI_FAST if(pwm_count & 4) {uid.fastAction();} +#define UI_FAST if((counterPeriodical & 3) == 3) {uid.fastAction();} #define UI_MEDIUM uid.mediumAction(); #define UI_SLOW(allowMoves) uid.slowAction(allowMoves); #define UI_STATUS(status) uid.setStatusP(PSTR(status)); diff --git a/src/ArduinoDUE/Repetier/Commands.cpp b/src/ArduinoDUE/Repetier/Commands.cpp index 9a49a2c9a..172f74227 100644 --- a/src/ArduinoDUE/Repetier/Commands.cpp +++ b/src/ArduinoDUE/Repetier/Commands.cpp @@ -231,7 +231,11 @@ void Commands::setFanSpeed(int speed,bool wait) { Com::printFLN(Com::tFanspeed,speed); // send only new values to break update loops! #if FAN_KICKSTART_TIME - if(fanKickstart == 0 && speed > pwm_pos[NUM_EXTRUDER + 2]) fanKickstart = FAN_KICKSTART_TIME/100; + if(fanKickstart == 0 && speed > pwm_pos[NUM_EXTRUDER + 2] && speed < 85) + { + if(pwm_pos[NUM_EXTRUDER + 2]) fanKickstart = FAN_KICKSTART_TIME/100; + else fanKickstart = FAN_KICKSTART_TIME/25; + } #endif } pwm_pos[NUM_EXTRUDER + 2] = speed; diff --git a/src/ArduinoDUE/Repetier/Configuration.h b/src/ArduinoDUE/Repetier/Configuration.h index 55cf56559..065b8d95a 100644 --- a/src/ArduinoDUE/Repetier/Configuration.h +++ b/src/ArduinoDUE/Repetier/Configuration.h @@ -94,7 +94,7 @@ If a motor turns in the wrong direction change INVERT_X_DIR or INVERT_Y_DIR. /** Drive settings for the Delta printers */ -#if DRIVE_SYSTEM==DELTA +#if DRIVE_SYSTEM == DELTA // *************************************************** // *** These parameter are only for Delta printers *** // *************************************************** @@ -792,8 +792,8 @@ on this endstop. /** \brief Number of segments to generate for delta conversions per second of move */ -#define DELTA_SEGMENTS_PER_SECOND_PRINT 180 // Move accurate setting for print moves -#define DELTA_SEGMENTS_PER_SECOND_MOVE 70 // Less accurate setting for other moves +#define DELTA_SEGMENTS_PER_SECOND_PRINT 600 // Move accurate setting for print moves +#define DELTA_SEGMENTS_PER_SECOND_MOVE 600 // Less accurate setting for other moves // Delta settings #if DRIVE_SYSTEM == DELTA @@ -950,7 +950,7 @@ This is like reducing your 1/16th microstepping to 1/8 or 1/4. It is much cheape additional stepper interrupts with all it's overhead. As a result you can go as high as 40000Hz. */ -#define STEP_DOUBLER_FREQUENCY 12000 +#define STEP_DOUBLER_FREQUENCY 80000 /** If you need frequencies off more then 30000 you definitely need to enable this. If you have only 1/8 stepping enabling this may cause to stall your moves when 20000Hz is reached. */ @@ -961,12 +961,6 @@ for some printers causing an early stall. */ #define DOUBLE_STEP_DELAY 1 // time in microseconds -/** The firmware supports trajectory smoothing. To achieve this, it divides the stepsize by 2, resulting in -the double computation cost. For slow movements this is not an issue, but for really fast moves this is -too much. The value specified here is the number of clock cycles between a step on the driving axis. -If the interval at full speed is below this value, smoothing is disabled for that line.*/ -#define MAX_HALFSTEP_INTERVAL 1999 - //// Acceleration settings /** \brief X, Y, Z max acceleration in mm/s^2 for printing moves or retracts. Make sure your printer can go that high! @@ -1359,6 +1353,13 @@ Select the language to use. */ #define UI_LANGUAGE 1 +/* Some displays loose their settings from time to time. Try uncommenting the +autorepair function if this is the case. It is not supported for all display +types. It creates a minimal flicker from time to time and also slows down +computations, so do not enable it if your display works stable! +*/ +//#define TRY_AUTOREPAIR_LCD_ERRORS + // This is line 2 of the status display at startup. Change to your like. #define UI_PRINTER_NAME "Ordbot" #define UI_PRINTER_COMPANY "RepRapDiscount" diff --git a/src/ArduinoDUE/Repetier/Extruder.cpp b/src/ArduinoDUE/Repetier/Extruder.cpp index 45e6d74a3..00f4e1faf 100644 --- a/src/ArduinoDUE/Repetier/Extruder.cpp +++ b/src/ArduinoDUE/Repetier/Extruder.cpp @@ -1918,6 +1918,9 @@ const char ext5_select_cmd[] PROGMEM = EXT5_SELECT_COMMANDS; const char ext5_deselect_cmd[] PROGMEM = EXT5_DESELECT_COMMANDS; #endif +#if NUM_EXTRUDER == 0 +Extruder extruder[1]; +#else Extruder extruder[NUM_EXTRUDER] = { #if NUM_EXTRUDER > 0 @@ -2083,6 +2086,7 @@ Extruder extruder[NUM_EXTRUDER] = } #endif }; +#endif // NUM_EXTRUDER #if HAVE_HEATED_BED #define NUM_TEMPERATURE_LOOPS NUM_EXTRUDER+1 diff --git a/src/ArduinoDUE/Repetier/HAL.cpp b/src/ArduinoDUE/Repetier/HAL.cpp index b24d82967..e5b05feb6 100644 --- a/src/ArduinoDUE/Repetier/HAL.cpp +++ b/src/ArduinoDUE/Repetier/HAL.cpp @@ -802,32 +802,31 @@ void SERVO_COMPA_VECTOR () #endif #endif +TcChannel *stepperChannel = (TIMER1_TIMER->TC_CHANNEL + TIMER1_TIMER_CHANNEL); /** \brief Sets the timer 1 compare value to delay ticks. */ -inline void setTimer(unsigned long delay) +INLINE void setTimer(unsigned long delay) { // convert old AVR timer delay value for SAM timers uint32_t timer_count = (delay * TIMER1_PRESCALE); - - if(timer_count < 210) timer_count = 210; - TC_SetRC(TIMER1_TIMER, TIMER1_TIMER_CHANNEL, timer_count); - if(TC_ReadCV(TIMER1_TIMER,TIMER1_TIMER_CHANNEL)>timer_count) - TC_Start(TIMER1_TIMER, TIMER1_TIMER_CHANNEL); + if(timer_count < 210) + timer_count = 210; + stepperChannel->TC_RC = timer_count; + if( stepperChannel->TC_CV > timer_count) { + stepperChannel->TC_CCR = TC_CCR_CLKEN | TC_CCR_SWTRG ; + } } /** \brief Timer interrupt routine to drive the stepper motors. */ void TIMER1_COMPA_VECTOR () { - InterruptProtectedBlock noInt; // apparently have to read status register - TC_GetStatus(TIMER1_TIMER, TIMER1_TIMER_CHANNEL); - if(HAL::insideTimer1) {return;} - HAL::insideTimer1 = 1; + stepperChannel->TC_SR; + InterruptProtectedBlock noInt; if(PrintLine::hasLines()) { setTimer(PrintLine::bresenhamStep()); - HAL::allowInterrupts(); } else if(Printer::zBabystepsMissing != 0) { @@ -835,7 +834,7 @@ void TIMER1_COMPA_VECTOR () setTimer(Printer::interval); } else { - if(waitRelax==0) + if(waitRelax == 0) { #if USE_ADVANCE if(Printer::advanceStepsSet) @@ -855,18 +854,16 @@ void TIMER1_COMPA_VECTOR () else waitRelax--; setTimer(10000); } - DEBUG_MEMORY; - HAL::insideTimer1=0; } #if !defined(HEATER_PWM_SPEED) #define HEATER_PWM_SPEED 0 #endif -#if HEATER_PWM_SPEED<0 +#if HEATER_PWM_SPEED < 0 #define HEATER_PWM_SPEED 0 #endif -#if HEATER_PWM_SPEED>3 -#define HEATER_PWM_SPEED 3 +#if HEATER_PWM_SPEED > 2 +#define HEATER_PWM_SPEED 2 #endif #if HEATER_PWM_SPEED == 0 @@ -875,13 +872,32 @@ void TIMER1_COMPA_VECTOR () #elif HEATER_PWM_SPEED == 1 #define HEATER_PWM_STEP 2 #define HEATER_PWM_MASK 254 -#elif HEATER_PWM_SPEED == 2 -#define HEATER_PWM_STEP 4 -#define HEATER_PWM_MASK 252 #else #define HEATER_PWM_STEP 4 #define HEATER_PWM_MASK 252 #endif + +#if !defined(COOLER_PWM_SPEED) +#define COOLER_PWM_SPEED 0 +#endif +#if COOLER_PWM_SPEED < 0 +#define COOLER_PWM_SPEED 0 +#endif +#if COOLER_PWM_SPEED > 2 +#define COOLER_PWM_SPEED 2 +#endif + +#if COOLER_PWM_SPEED == 0 +#define COOLER_PWM_STEP 1 +#define COOLER_PWM_MASK 255 +#elif COOLER_PWM_SPEED == 1 +#define COOLER_PWM_STEP 2 +#define COOLER_PWM_MASK 254 +#else +#define COOLER_PWM_STEP 4 +#define COOLER_PWM_MASK 252 +#endif + #define pulseDensityModulate( pin, density,error,invert) {uint8_t carry;carry = error + (invert ? 255 - density : density); WRITE(pin, (carry < error)); error = carry;} /** @@ -894,7 +910,7 @@ void PWM_TIMER_VECTOR () // apparently have to read status register TC_GetStatus(PWM_TIMER, PWM_TIMER_CHANNEL); - static uint8_t pwm_count = 0; + static uint8_t pwm_count_cooler = 0; static uint8_t pwm_count_heater = 0; static uint8_t pwm_pos_set[NUM_EXTRUDER + 3]; static uint8_t pwm_cooler_pos_set[NUM_EXTRUDER]; @@ -923,41 +939,41 @@ void PWM_TIMER_VECTOR () if((pwm_pos_set[NUM_EXTRUDER] = pwm_pos[NUM_EXTRUDER]) > 0) WRITE(HEATED_BED_HEATER_PIN,!HEATER_PINS_INVERTED); #endif } - if(pwm_count==0 && !PDM_FOR_COOLER) + if(pwm_count_cooler == 0 && !PDM_FOR_COOLER) { #if defined(EXT0_HEATER_PIN) && EXT0_HEATER_PIN > -1 && EXT0_EXTRUDER_COOLER_PIN > -1 - if((pwm_cooler_pos_set[0] = extruder[0].coolerPWM)>0) WRITE(EXT0_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[0] = (extruder[0].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT0_EXTRUDER_COOLER_PIN, 1); #endif #if !SHARED_COOLER && defined(EXT1_HEATER_PIN) && EXT1_HEATER_PIN > -1 && NUM_EXTRUDER > 1 #if EXT1_EXTRUDER_COOLER_PIN > -1 && EXT1_EXTRUDER_COOLER_PIN != EXT0_EXTRUDER_COOLER_PIN - if((pwm_cooler_pos_set[1] = extruder[1].coolerPWM) > 0) WRITE(EXT1_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[1] = (extruder[1].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT1_EXTRUDER_COOLER_PIN, 1); #endif #endif #if !SHARED_COOLER && defined(EXT2_HEATER_PIN) && EXT2_HEATER_PIN > -1 && NUM_EXTRUDER > 2 #if EXT2_EXTRUDER_COOLER_PIN>-1 - if((pwm_cooler_pos_set[2] = extruder[2].coolerPWM) > 0) WRITE(EXT2_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[2] = (extruder[2].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT2_EXTRUDER_COOLER_PIN, 1); #endif #endif #if !SHARED_COOLER && defined(EXT3_HEATER_PIN) && EXT3_HEATER_PIN > -1 && NUM_EXTRUDER > 3 #if EXT3_EXTRUDER_COOLER_PIN>-1 - if((pwm_cooler_pos_set[3] = extruder[3].coolerPWM)>0) WRITE(EXT3_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[3] = (extruder[3].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT3_EXTRUDER_COOLER_PIN, 1); #endif #endif #if !SHARED_COOLER && defined(EXT4_HEATER_PIN) && EXT4_HEATER_PIN > -1 && NUM_EXTRUDER > 4 #if EXT4_EXTRUDER_COOLER_PIN>-1 - if((pwm_cooler_pos_set[4] = pwm_pos[4].coolerPWM)>0) WRITE(EXT4_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[4] = (extruder[4].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT4_EXTRUDER_COOLER_PIN, 1); #endif #endif #if !SHARED_COOLER && defined(EXT5_HEATER_PIN) && EXT5_HEATER_PIN > -1 && NUM_EXTRUDER > 5 #if EXT5_EXTRUDER_COOLER_PIN>-1 - if((pwm_cooler_pos_set[5] = extruder[5].coolerPWM)>0) WRITE(EXT5_EXTRUDER_COOLER_PIN, 1); + if((pwm_cooler_pos_set[5] = (extruder[5].coolerPWM & COOLER_PWM_MASK)) > 0) WRITE(EXT5_EXTRUDER_COOLER_PIN, 1); #endif #endif #if FAN_BOARD_PIN > -1 && SHARED_COOLER_BOARD_EXT == 0 - if((pwm_pos_set[NUM_EXTRUDER + 1] = pwm_pos[NUM_EXTRUDER + 1]) > 0) WRITE(FAN_BOARD_PIN, 1); + if((pwm_pos_set[NUM_EXTRUDER + 1] = (pwm_pos[NUM_EXTRUDER + 1] & COOLER_PWM_MASK)) > 0) WRITE(FAN_BOARD_PIN,1); #endif -#if FAN_PIN>-1 && FEATURE_FAN_CONTROL - if((pwm_pos_set[NUM_EXTRUDER + 2] = pwm_pos[NUM_EXTRUDER + 2]) > 0) WRITE(FAN_PIN, 1); +#if FAN_PIN > -1 && FEATURE_FAN_CONTROL + if((pwm_pos_set[NUM_EXTRUDER + 2] = (pwm_pos[NUM_EXTRUDER + 2] & COOLER_PWM_MASK)) > 0) WRITE(FAN_PIN,1); #endif } #if defined(EXT0_HEATER_PIN) && EXT0_HEATER_PIN > -1 @@ -970,7 +986,7 @@ void PWM_TIMER_VECTOR () #if PDM_FOR_COOLER pulseDensityModulate(EXT0_EXTRUDER_COOLER_PIN, extruder[0].coolerPWM, pwm_cooler_pos_set[0], false); #else - if(pwm_cooler_pos_set[0] == pwm_count && pwm_cooler_pos_set[0] != 255) WRITE(EXT0_EXTRUDER_COOLER_PIN, 0); + if(pwm_cooler_pos_set[0] == pwm_count_cooler && pwm_cooler_pos_set[0] != COOLER_PWM_MASK) WRITE(EXT0_EXTRUDER_COOLER_PIN, 0); #endif #endif #endif @@ -984,7 +1000,7 @@ void PWM_TIMER_VECTOR () #if PDM_FOR_COOLER pulseDensityModulate(EXT1_EXTRUDER_COOLER_PIN, extruder[1].coolerPWM, pwm_cooler_pos_set[1], false); #else - if(pwm_cooler_pos_set[1] == pwm_count && pwm_cooler_pos_set[1] != 255) WRITE(EXT1_EXTRUDER_COOLER_PIN, 0); + if(pwm_cooler_pos_set[1] == pwm_count_cooler && pwm_cooler_pos_set[1] != COOLER_PWM_MASK) WRITE(EXT1_EXTRUDER_COOLER_PIN, 0); #endif #endif #endif @@ -998,7 +1014,7 @@ void PWM_TIMER_VECTOR () #if PDM_FOR_COOLER pulseDensityModulate(EXT2_EXTRUDER_COOLER_PIN, extruder[2].coolerPWM, pwm_cooler_pos_set[2], false); #else - if(pwm_cooler_pos_set[2] == pwm_count && pwm_cooler_pos_set[2]!=255) WRITE(EXT2_EXTRUDER_COOLER_PIN, 0); + if(pwm_cooler_pos_set[2] == pwm_count_cooler && pwm_cooler_pos_set[2] != COOLER_PWM_MASK) WRITE(EXT2_EXTRUDER_COOLER_PIN, 0); #endif #endif #endif @@ -1012,7 +1028,7 @@ void PWM_TIMER_VECTOR () #if PDM_FOR_COOLER pulseDensityModulate(EXT3_EXTRUDER_COOLER_PIN, extruder[3].coolerPWM, pwm_cooler_pos_set[3], false); #else - if(pwm_cooler_pos_set[3] == pwm_count && pwm_cooler_pos_set[3]!=255) WRITE(EXT3_EXTRUDER_COOLER_PIN, 0); + if(pwm_cooler_pos_set[3] == pwm_count_cooler && pwm_cooler_pos_set[3] != COOLER_PWM_MASK) WRITE(EXT3_EXTRUDER_COOLER_PIN, 0); #endif #endif #endif @@ -1026,7 +1042,7 @@ void PWM_TIMER_VECTOR () #if PDM_FOR_COOLER pulseDensityModulate(EXT4_EXTRUDER_COOLER_PIN, extruder[4].coolerPWM, pwm_cooler_pos_set[4], false); #else - if(pwm_cooler_pos_set[4] == pwm_count && pwm_cooler_pos_set[4] != 255) WRITE(EXT4_EXTRUDER_COOLER_PIN, 0); + if(pwm_cooler_pos_set[4] == pwm_count_cooler && pwm_cooler_pos_set[4] != COOLER_PWM_MASK) WRITE(EXT4_EXTRUDER_COOLER_PIN, 0); #endif #endif #endif @@ -1040,7 +1056,7 @@ void PWM_TIMER_VECTOR () #if PDM_FOR_COOLER pulseDensityModulate(EXT5_EXTRUDER_COOLER_PIN, extruder[5].coolerPWM, pwm_cooler_pos_set[5], false); #else - if(pwm_cooler_pos_set[5] == pwm_count && pwm_cooler_pos_set[5] != 255) WRITE(EXT5_EXTRUDER_COOLER_PIN, 0); + if(pwm_cooler_pos_set[5] == pwm_count_cooler && pwm_cooler_pos_set[5] != COOLER_PWM_MASK) WRITE(EXT5_EXTRUDER_COOLER_PIN, 0); #endif #endif #endif @@ -1048,16 +1064,16 @@ void PWM_TIMER_VECTOR () #if PDM_FOR_COOLER pulseDensityModulate(FAN_BOARD_PIN, pwm_pos[NUM_EXTRUDER + 1], pwm_pos_set[NUM_EXTRUDER + 1], false); #else - if(pwm_pos_set[NUM_EXTRUDER + 1] == pwm_count && pwm_pos_set[NUM_EXTRUDER+1] != 255) WRITE(FAN_BOARD_PIN, 0); + if(pwm_pos_set[NUM_EXTRUDER + 1] == pwm_count_cooler && pwm_pos_set[NUM_EXTRUDER+1] != COOLER_PWM_MASK) WRITE(FAN_BOARD_PIN, 0); #endif #endif #if FAN_PIN > -1 && FEATURE_FAN_CONTROL if(fanKickstart == 0) { #if PDM_FOR_COOLER - pulseDensityModulate(FAN_PIN, pwm_pos[NUM_EXTRUDER + 2], pwm_pos_set[NUM_EXTRUDER+2], false); + pulseDensityModulate(FAN_PIN, pwm_pos[NUM_EXTRUDER + 2], pwm_pos_set[NUM_EXTRUDER + 2], false); #else - if(pwm_pos_set[NUM_EXTRUDER + 2] == pwm_count && pwm_pos_set[NUM_EXTRUDER + 2] != 255) WRITE(FAN_PIN, 0); + if(pwm_pos_set[NUM_EXTRUDER + 2] == pwm_count_cooler && pwm_pos_set[NUM_EXTRUDER + 2] != COOLER_PWM_MASK) WRITE(FAN_PIN, 0); #endif } #endif @@ -1111,7 +1127,7 @@ void PWM_TIMER_VECTOR () } #endif // ANALOG_INPUTS > 0 UI_FAST; // Short timed user interface action - pwm_count++; + pwm_count_cooler += COOLER_PWM_STEP; pwm_count_heater += HEATER_PWM_STEP; } @@ -1175,19 +1191,6 @@ void BEEPER_TIMER_VECTOR () { TC_GetStatus(BEEPER_TIMER, BEEPER_TIMER_CHANNEL); - WRITE(tone_pin, toggle); + WRITE_VAR(tone_pin, toggle); toggle = !toggle; } - - - - - - - - - - - - - diff --git a/src/ArduinoDUE/Repetier/HAL.h b/src/ArduinoDUE/Repetier/HAL.h index d8b82124c..4418a7e11 100644 --- a/src/ArduinoDUE/Repetier/HAL.h +++ b/src/ArduinoDUE/Repetier/HAL.h @@ -36,6 +36,7 @@ #include #include "pins.h" #include "Print.h" +#include "fastio.h" // Hack to make 84 MHz Due clock work without changes to pre-existing code // which would otherwise have problems with int overflow. @@ -55,6 +56,8 @@ // Some structures assume no padding, need to add this attribute on ARM #define PACK __attribute__ ((packed)) +#define INLINE __attribute__((always_inline)) + // do not use program space memory with Due #define PROGMEM #define PGM_P const char * @@ -142,9 +145,14 @@ typedef char prog_char; #define COMPAT_PRE1 #endif -#define READ(pin) PIO_Get(g_APinDescription[pin].pPort, PIO_INPUT, g_APinDescription[pin].ulPin) -//#define WRITE(pin, v) PIO_SetOutput(g_APinDescription[pin].pPort, g_APinDescription[pin].ulPin, v, 0, PIO_PULLUP) -#define WRITE(pin, v) do{if(v) {g_APinDescription[pin].pPort->PIO_SODR = g_APinDescription[pin].ulPin;} else {g_APinDescription[pin].pPort->PIO_CODR = g_APinDescription[pin].ulPin; }}while(0) +//#define READ(pin) PIO_Get(g_APinDescription[pin].pPort, PIO_INPUT, g_APinDescription[pin].ulPin) +#define READ_VAR(pin) (g_APinDescription[pin].pPort->PIO_PDSR & g_APinDescription[pin].ulPin ? 1 : 0) // does return 0 or pin value +#define _READ(pin) (DIO ## pin ## _PORT->PIO_PDSR & DIO ## pin ## _PIN ? 1 : 0) // does return 0 or pin value +#define READ(pin) _READ(pin) +//#define WRITE_VAR(pin, v) PIO_SetOutput(g_APinDescription[pin].pPort, g_APinDescription[pin].ulPin, v, 0, PIO_PULLUP) +#define WRITE_VAR(pin, v) do{if(v) {g_APinDescription[pin].pPort->PIO_SODR = g_APinDescription[pin].ulPin;} else {g_APinDescription[pin].pPort->PIO_CODR = g_APinDescription[pin].ulPin; }}while(0) +#define _WRITE(port, v) do { if (v) {DIO ## port ## _PORT -> PIO_SODR = DIO ## port ## _PIN; } else {DIO ## port ## _PORT->PIO_CODR = DIO ## port ## _PIN; }; } while (0) +#define WRITE(pin,v) _WRITE(pin,v) #define SET_INPUT(pin) pmc_enable_periph_clk(g_APinDescription[pin].ulPeripheralId); \ PIO_Configure(g_APinDescription[pin].pPort, PIO_INPUT, g_APinDescription[pin].ulPin, 0) @@ -160,20 +168,20 @@ typedef char prog_char; #if 1 class InterruptProtectedBlock { public: - inline void protect() { + INLINE void protect() { __set_BASEPRI(NVIC_EncodePriority(4, 3, 0)); } - inline void unprotect() { + INLINE void unprotect() { __set_BASEPRI(0); } - inline InterruptProtectedBlock(bool later = false) { + INLINE InterruptProtectedBlock(bool later = false) { if(!later) __set_BASEPRI(NVIC_EncodePriority(4, 3, 0)); } - inline ~InterruptProtectedBlock() { + INLINE ~InterruptProtectedBlock() { __set_BASEPRI(0); } }; @@ -230,14 +238,15 @@ class InterruptProtectedBlock { static uint32_t tone_pin; /** Set max. frequency to 150000Hz */ -#define LIMIT_INTERVAL (F_CPU/150000) +#define LIMIT_INTERVAL (F_CPU/500000) typedef unsigned int speed_t; typedef unsigned long ticks_t; typedef unsigned long millis_t; -typedef int flag8_t; +typedef unsigned int flag8_t; typedef int fast8_t; +typedef unsigned int ufast8_t; #ifndef RFSERIAL #define RFSERIAL Serial // Programming port of the due @@ -293,13 +302,13 @@ class HAL #if EEPROM_AVAILABLE && EEPROM_MODE != 0 // Copy eeprom to ram for faster access int i,n = EEPROM_BYTES; - for(i=0;i -1) WRITE(X_ENABLE_PIN, !X_ENABLE_ON); @@ -351,7 +352,7 @@ class Printer } /** \brief Disable stepper motor for y direction. */ - static inline void disableYStepper() + static INLINE void disableYStepper() { #if (Y_ENABLE_PIN > -1) WRITE(Y_ENABLE_PIN, !Y_ENABLE_ON); @@ -361,7 +362,7 @@ class Printer #endif } /** \brief Disable stepper motor for z direction. */ - static inline void disableZStepper() + static INLINE void disableZStepper() { #if (Z_ENABLE_PIN > -1) WRITE(Z_ENABLE_PIN, !Z_ENABLE_ON); @@ -372,7 +373,7 @@ class Printer } /** \brief Enable stepper motor for x direction. */ - static inline void enableXStepper() + static INLINE void enableXStepper() { #if (X_ENABLE_PIN > -1) WRITE(X_ENABLE_PIN, X_ENABLE_ON); @@ -383,7 +384,7 @@ class Printer } /** \brief Enable stepper motor for y direction. */ - static inline void enableYStepper() + static INLINE void enableYStepper() { #if (Y_ENABLE_PIN > -1) WRITE(Y_ENABLE_PIN, Y_ENABLE_ON); @@ -393,7 +394,7 @@ class Printer #endif } /** \brief Enable stepper motor for z direction. */ - static inline void enableZStepper() + static INLINE void enableZStepper() { #if (Z_ENABLE_PIN > -1) WRITE(Z_ENABLE_PIN, Z_ENABLE_ON); @@ -403,7 +404,7 @@ class Printer #endif } - static inline void setXDirection(bool positive) + static INLINE void setXDirection(bool positive) { if(positive) { @@ -421,7 +422,7 @@ class Printer } } - static inline void setYDirection(bool positive) + static INLINE void setYDirection(bool positive) { if(positive) { @@ -438,7 +439,7 @@ class Printer #endif } } - static inline void setZDirection(bool positive) + static INLINE void setZDirection(bool positive) { if(positive) { @@ -456,117 +457,117 @@ class Printer } } - static inline bool getZDirection() + static INLINE bool getZDirection() { return ((READ(Z_DIR_PIN) != 0) ^ INVERT_Z_DIR); } - static inline bool getYDirection() + static INLINE bool getYDirection() { return((READ(Y_DIR_PIN) != 0) ^ INVERT_Y_DIR); } - static inline bool getXDirection() + static INLINE bool getXDirection() { return((READ(X_DIR_PIN) != 0) ^ INVERT_X_DIR); } - static inline uint8_t isLargeMachine() + static INLINE uint8_t isLargeMachine() { return flag0 & PRINTER_FLAG0_LARGE_MACHINE; } - static inline void setLargeMachine(uint8_t b) + static INLINE void setLargeMachine(uint8_t b) { flag0 = (b ? flag0 | PRINTER_FLAG0_LARGE_MACHINE : flag0 & ~PRINTER_FLAG0_LARGE_MACHINE); } - static inline uint8_t isAdvanceActivated() + static INLINE uint8_t isAdvanceActivated() { return flag0 & PRINTER_FLAG0_SEPERATE_EXTRUDER_INT; } - static inline void setAdvanceActivated(uint8_t b) + static INLINE void setAdvanceActivated(uint8_t b) { flag0 = (b ? flag0 | PRINTER_FLAG0_SEPERATE_EXTRUDER_INT : flag0 & ~PRINTER_FLAG0_SEPERATE_EXTRUDER_INT); } - static inline uint8_t isHomed() + static INLINE uint8_t isHomed() { return flag1 & PRINTER_FLAG1_HOMED; } - static inline void setHomed(uint8_t b) + static INLINE void setHomed(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_HOMED : flag1 & ~PRINTER_FLAG1_HOMED); } - static inline uint8_t isAllKilled() + static INLINE uint8_t isAllKilled() { return flag1 & PRINTER_FLAG1_ALLKILLED; } - static inline void setAllKilled(uint8_t b) + static INLINE void setAllKilled(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_ALLKILLED : flag1 & ~PRINTER_FLAG1_ALLKILLED); } - static inline uint8_t isAutomount() + static INLINE uint8_t isAutomount() { return flag1 & PRINTER_FLAG1_AUTOMOUNT; } - static inline void setAutomount(uint8_t b) + static INLINE void setAutomount(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_AUTOMOUNT : flag1 & ~PRINTER_FLAG1_AUTOMOUNT); } - static inline uint8_t isAnimation() + static INLINE uint8_t isAnimation() { return flag1 & PRINTER_FLAG1_ANIMATION; } - static inline void setAnimation(uint8_t b) + static INLINE void setAnimation(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_ANIMATION : flag1 & ~PRINTER_FLAG1_ANIMATION); } - static inline uint8_t isUIErrorMessage() + static INLINE uint8_t isUIErrorMessage() { return flag1 & PRINTER_FLAG1_UI_ERROR_MESSAGE; } - static inline void setUIErrorMessage(uint8_t b) + static INLINE void setUIErrorMessage(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_UI_ERROR_MESSAGE : flag1 & ~PRINTER_FLAG1_UI_ERROR_MESSAGE); } - static inline uint8_t isNoDestinationCheck() + static INLINE uint8_t isNoDestinationCheck() { return flag1 & PRINTER_FLAG1_NO_DESTINATION_CHECK; } - static inline void setNoDestinationCheck(uint8_t b) + static INLINE void setNoDestinationCheck(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_NO_DESTINATION_CHECK : flag1 & ~PRINTER_FLAG1_NO_DESTINATION_CHECK); } - static inline uint8_t isPowerOn() + static INLINE uint8_t isPowerOn() { return flag1 & PRINTER_FLAG1_POWER_ON; } - static inline void setPowerOn(uint8_t b) + static INLINE void setPowerOn(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_POWER_ON : flag1 & ~PRINTER_FLAG1_POWER_ON); } - static inline uint8_t isColdExtrusionAllowed() + static INLINE uint8_t isColdExtrusionAllowed() { return flag1 & PRINTER_FLAG1_ALLOW_COLD_EXTRUSION; } - static inline void setColdExtrusionAllowed(uint8_t b) + static INLINE void setColdExtrusionAllowed(uint8_t b) { flag1 = (b ? flag1 | PRINTER_FLAG1_ALLOW_COLD_EXTRUSION : flag1 & ~PRINTER_FLAG1_ALLOW_COLD_EXTRUSION); if(b) @@ -575,63 +576,63 @@ class Printer Com::printFLN(PSTR("Cold extrusion disallowed")); } - static inline uint8_t isBlockingReceive() + static INLINE uint8_t isBlockingReceive() { return flag2 & PRINTER_FLAG2_BLOCK_RECEIVING; } - static inline void setBlockingReceive(uint8_t b) + static INLINE void setBlockingReceive(uint8_t b) { flag2 = (b ? flag2 | PRINTER_FLAG2_BLOCK_RECEIVING : flag2 & ~PRINTER_FLAG2_BLOCK_RECEIVING); } - static inline uint8_t isAutoretract() + static INLINE uint8_t isAutoretract() { return flag2 & PRINTER_FLAG2_AUTORETRACT; } - static inline void setAutoretract(uint8_t b) + static INLINE void setAutoretract(uint8_t b) { flag2 = (b ? flag2 | PRINTER_FLAG2_AUTORETRACT : flag2 & ~PRINTER_FLAG2_AUTORETRACT); Com::printFLN(PSTR("Autoretract:"),b); } - static inline uint8_t isDebugJam() + static INLINE uint8_t isDebugJam() { return (flag2 & PRINTER_FLAG2_DEBUG_JAM) != 0; } - static inline uint8_t isDebugJamOrDisabled() + static INLINE uint8_t isDebugJamOrDisabled() { return (flag2 & (PRINTER_FLAG2_DEBUG_JAM | PRINTER_FLAG2_JAMCONTROL_DISABLED)) != 0; } - static inline void setDebugJam(uint8_t b) + static INLINE void setDebugJam(uint8_t b) { flag2 = (b ? flag2 | PRINTER_FLAG2_DEBUG_JAM : flag2 & ~PRINTER_FLAG2_DEBUG_JAM); Com::printFLN(PSTR("Jam debugging:"),b); } - static inline uint8_t isJamcontrolDisabled() + static INLINE uint8_t isJamcontrolDisabled() { return (flag2 & PRINTER_FLAG2_JAMCONTROL_DISABLED) != 0; } - static inline void setJamcontrolDisabled(uint8_t b) + static INLINE void setJamcontrolDisabled(uint8_t b) { flag2 = (b ? flag2 | PRINTER_FLAG2_JAMCONTROL_DISABLED : flag2 & ~PRINTER_FLAG2_JAMCONTROL_DISABLED); Com::printFLN(PSTR("Jam control disabled:"),b); } - static inline void toggleAnimation() + static INLINE void toggleAnimation() { setAnimation(!isAnimation()); } - static inline float convertToMM(float x) + static INLINE float convertToMM(float x) { return (unitIsInches ? x*25.4 : x); } - static inline bool isXMinEndstopHit() + static INLINE bool isXMinEndstopHit() { #if X_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_X return READ(X_MIN_PIN) != ENDSTOP_X_MIN_INVERTING; @@ -639,7 +640,7 @@ class Printer return false; #endif } - static inline bool isYMinEndstopHit() + static INLINE bool isYMinEndstopHit() { #if Y_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_Y return READ(Y_MIN_PIN) != ENDSTOP_Y_MIN_INVERTING; @@ -647,7 +648,7 @@ class Printer return false; #endif } - static inline bool isZMinEndstopHit() + static INLINE bool isZMinEndstopHit() { #if Z_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_Z return READ(Z_MIN_PIN) != ENDSTOP_Z_MIN_INVERTING; @@ -655,7 +656,7 @@ class Printer return false; #endif } - static inline bool isXMaxEndstopHit() + static INLINE bool isXMaxEndstopHit() { #if X_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_X return READ(X_MAX_PIN) != ENDSTOP_X_MAX_INVERTING; @@ -663,7 +664,7 @@ class Printer return false; #endif } - static inline bool isYMaxEndstopHit() + static INLINE bool isYMaxEndstopHit() { #if Y_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_Y return READ(Y_MAX_PIN) != ENDSTOP_Y_MAX_INVERTING; @@ -671,7 +672,7 @@ class Printer return false; #endif } - static inline bool isZMaxEndstopHit() + static INLINE bool isZMaxEndstopHit() { #if Z_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_Z return READ(Z_MAX_PIN) != ENDSTOP_Z_MAX_INVERTING; @@ -679,55 +680,55 @@ class Printer return false; #endif } - static inline bool areAllSteppersDisabled() + static INLINE bool areAllSteppersDisabled() { return flag0 & PRINTER_FLAG0_STEPPER_DISABLED; } - static inline void setAllSteppersDiabled() + static INLINE void setAllSteppersDiabled() { flag0 |= PRINTER_FLAG0_STEPPER_DISABLED; } - static inline void unsetAllSteppersDisabled() + static INLINE void unsetAllSteppersDisabled() { flag0 &= ~PRINTER_FLAG0_STEPPER_DISABLED; #if FAN_BOARD_PIN>-1 pwm_pos[NUM_EXTRUDER + 1] = 255; #endif // FAN_BOARD_PIN } - static inline bool isAnyTempsensorDefect() + static INLINE bool isAnyTempsensorDefect() { return (flag0 & PRINTER_FLAG0_TEMPSENSOR_DEFECT); } - static inline void setAnyTempsensorDefect() + static INLINE void setAnyTempsensorDefect() { flag0 |= PRINTER_FLAG0_TEMPSENSOR_DEFECT; } - static inline void unsetAnyTempsensorDefect() + static INLINE void unsetAnyTempsensorDefect() { flag0 &= ~PRINTER_FLAG0_TEMPSENSOR_DEFECT; } - static inline bool isManualMoveMode() + static INLINE bool isManualMoveMode() { return (flag0 & PRINTER_FLAG0_MANUAL_MOVE_MODE); } - static inline void setManualMoveMode(bool on) + static INLINE void setManualMoveMode(bool on) { flag0 = (on ? flag0 | PRINTER_FLAG0_MANUAL_MOVE_MODE : flag0 & ~PRINTER_FLAG0_MANUAL_MOVE_MODE); } - static inline bool isAutolevelActive() + static INLINE bool isAutolevelActive() { return (flag0 & PRINTER_FLAG0_AUTOLEVEL_ACTIVE)!=0; } static void setAutolevelActive(bool on); - static inline void setZProbingActive(bool on) + static INLINE void setZProbingActive(bool on) { flag0 = (on ? flag0 | PRINTER_FLAG0_ZPROBEING : flag0 & ~PRINTER_FLAG0_ZPROBEING); } - static inline bool isZProbingActive() + static INLINE bool isZProbingActive() { return (flag0 & PRINTER_FLAG0_ZPROBEING); } - static inline bool isZProbeHit() + static INLINE bool isZProbeHit() { #if FEATURE_Z_PROBE return (Z_PROBE_ON_HIGH ? READ(Z_PROBE_PIN) : !READ(Z_PROBE_PIN)); @@ -735,7 +736,7 @@ class Printer return false; #endif } - static inline void executeXYGantrySteps() + static INLINE void executeXYGantrySteps() { #if (GANTRY) if(motorX <= -2) @@ -772,7 +773,7 @@ class Printer } #endif } - static inline void executeXZGantrySteps() + static INLINE void executeXZGantrySteps() { #if (GANTRY) if(motorX <= -2) @@ -811,22 +812,22 @@ class Printer } #endif } - static inline void endXYZSteps() + static INLINE void endXYZSteps() { WRITE(X_STEP_PIN,LOW); - WRITE(Y_STEP_PIN,LOW); - WRITE(Z_STEP_PIN,LOW); #if FEATURE_TWO_XSTEPPER WRITE(X2_STEP_PIN,LOW); #endif + WRITE(Y_STEP_PIN,LOW); #if FEATURE_TWO_YSTEPPER WRITE(Y2_STEP_PIN,LOW); #endif + WRITE(Z_STEP_PIN,LOW); #if FEATURE_TWO_ZSTEPPER WRITE(Z2_STEP_PIN,LOW); #endif } - static inline speed_t updateStepsPerTimerCall(speed_t vbase) + static INLINE speed_t updateStepsPerTimerCall(speed_t vbase) { if(vbase > STEP_DOUBLER_FREQUENCY) { @@ -852,7 +853,7 @@ class Printer } return vbase; } - static inline void disableAllowedStepper() + static INLINE void disableAllowedStepper() { #if DRIVE_SYSTEM == XZ_GANTRY || DRIVE_SYSTEM == ZX_GANTRY if(DISABLE_X && DISABLE_Z) @@ -875,27 +876,27 @@ class Printer if(DISABLE_Z) disableZStepper(); #endif } - static inline float realXPosition() + static INLINE float realXPosition() { return currentPosition[X_AXIS]; } - static inline float realYPosition() + static INLINE float realYPosition() { return currentPosition[Y_AXIS]; } - static inline float realZPosition() + static INLINE float realZPosition() { return currentPosition[Z_AXIS]; } - static inline void realPosition(float &xp, float &yp, float &zp) + static INLINE void realPosition(float &xp, float &yp, float &zp) { xp = currentPosition[X_AXIS]; yp = currentPosition[Y_AXIS]; zp = currentPosition[Z_AXIS]; } - static inline void insertStepperHighDelay() + static INLINE void insertStepperHighDelay() { #if STEPPER_HIGH_DELAY>0 HAL::delayMicroseconds(STEPPER_HIGH_DELAY); @@ -914,12 +915,12 @@ class Printer static void homeAxis(bool xaxis,bool yaxis,bool zaxis); /// Home axis static void setOrigin(float xOff,float yOff,float zOff); static bool isPositionAllowed(float x,float y,float z); - static inline int getFanSpeed() + static INLINE int getFanSpeed() { return (int)pwm_pos[NUM_EXTRUDER + 2]; } #if NONLINEAR_SYSTEM - static inline void setDeltaPositions(long xaxis, long yaxis, long zaxis) + static INLINE void setDeltaPositions(long xaxis, long yaxis, long zaxis) { currentDeltaPositionSteps[A_TOWER] = xaxis; currentDeltaPositionSteps[B_TOWER] = yaxis; @@ -950,9 +951,18 @@ class Printer static void GoToMemoryPosition(bool x,bool y,bool z,bool e,float feed); static void zBabystep(); - static inline void resetWizardStack() {wizardStackPos = 0;} - static inline void pushWizardVar(wizardVar v) {wizardStack[wizardStackPos++] = v;} - static inline wizardVar popWizardVar() {return wizardStack[--wizardStackPos];} + static INLINE void resetWizardStack() + { + wizardStackPos = 0; + } + static INLINE void pushWizardVar(wizardVar v) + { + wizardStack[wizardStackPos++] = v; + } + static INLINE wizardVar popWizardVar() + { + return wizardStack[--wizardStackPos]; + } static void showConfiguration(); static void setCaseLight(bool on); static void reportCaseLightStatus(); diff --git a/src/ArduinoDUE/Repetier/fastio.h b/src/ArduinoDUE/Repetier/fastio.h index a99aabf02..1f15e1da5 100644 --- a/src/ArduinoDUE/Repetier/fastio.h +++ b/src/ArduinoDUE/Repetier/fastio.h @@ -3,3046 +3,279 @@ why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html 2012/3/10 AT90USB128x modified by lincomatic to match Teensyduino */ -#ifndef _ARDUINO_H -#define _ARDUINO_H +#ifndef _FASTIO_H +#define _FASTIO_H + +#include +#include + +// 0 .. 53 - Digital pins + // ---------------------- + // 0/1 - UART (Serial) +#define DIO0_PORT PIOA +#define DIO0_PIN PIO_PA8A_URXD // URXD + +#define DIO1_PORT PIOA +#define DIO1_PIN PIO_PA9A_UTXD // UTXD + + // 2 +#define DIO2_PORT PIOB +#define DIO2_PIN PIO_PB25B_TIOA0 // TIOA0 +#define DIO3_PORT PIOC +#define DIO3_PIN PIO_PC28B_TIOA7 // TIOA7 +#define DIO4_PORT PIOC +#define DIO4_PIN PIO_PC26B_TIOB6 // TIOB6 + + // 5 +#define DIO5_PORT PIOC +#define DIO5_PIN PIO_PC25B_TIOA6 // TIOA6 +#define DIO6_PORT PIOC +#define DIO6_PIN PIO_PC24B_PWML7 // PWML7 +#define DIO7_PORT PIOC +#define DIO7_PIN PIO_PC23B_PWML6 // PWML6 +#define DIO8_PORT PIOC +#define DIO8_PIN PIO_PC22B_PWML5 // PWML5 +#define DIO9_PORT PIOC +#define DIO9_PIN PIO_PC21B_PWML4 // PWML4 + // 10 +#define DIO10_PORT PIOC +#define DIO10_PIN PIO_PC29B_TIOB7 // TIOB7 +#define DIO11_PORT PIOD +#define DIO11_PIN PIO_PD7B_TIOA8 // TIOA8 +#define DIO12_PORT PIOD +#define DIO12_PIN PIO_PD8B_TIOB8 // TIOB8 + + // 13 - AMBER LED +#define DIO13_PORT PIOB +#define DIO13_PIN PIO_PB27B_TIOB0 // TIOB0 + + // 14/15 - USART3 (Serial3) +#define DIO14_PORT PIOD +#define DIO14_PIN PIO_PD4B_TXD3 // TXD3 +#define DIO15_PORT PIOD +#define DIO15_PIN PIO_PD5B_RXD3 // RXD3 + + // 16/17 - USART1 (Serial2) +#define DIO16_PORT PIOA +#define DIO16_PIN PIO_PA13A_TXD1 // TXD1 +#define DIO17_PORT PIOA +#define DIO17_PIN PIO_PA12A_RXD1 // RXD1 + + // 18/19 - USART0 (Serial1) +#define DIO18_PORT PIOA +#define DIO18_PIN PIO_PA11A_TXD0 // TXD0 +#define DIO19_PORT PIOA +#define DIO19_PIN PIO_PA10A_RXD0 // RXD0 + + // 20/21 - TWI1 +#define DIO20_PORT PIOB +#define DIO20_PIN PIO_PB12A_TWD1 // TWD1 - SDA0 +#define DIO21_PORT PIOB +#define DIO21_PIN PIO_PB13A_TWCK1 // TWCK1 - SCL0 + + // 22 +#define DIO22_PORT PIOB +#define DIO22_PIN PIO_PB26 // PIN 22 +#define DIO23_PORT PIOA +#define DIO23_PIN PIO_PA14 // PIN 23 +#define DIO24_PORT PIOA +#define DIO24_PIN PIO_PA15 // PIN 24 +#define DIO25_PORT PIOD +#define DIO25_PIN PIO_PD0 // PIN 25 + + // 26 +#define DIO26_PORT PIOD +#define DIO26_PIN PIO_PD1 // PIN 26 +#define DIO27_PORT PIOD +#define DIO27_PIN PIO_PD2 // PIN 27 +#define DIO28_PORT PIOD +#define DIO28_PIN PIO_PD3 // PIN 28 +#define DIO29_PORT PIOD +#define DIO29_PIN PIO_PD6 // PIN 29 + + // 30 +#define DIO30_PORT PIOD +#define DIO30_PIN PIO_PD9 // PIN 30 +#define DIO31_PORT PIOA +#define DIO31_PIN PIO_PA7 // PIN 31 +#define DIO32_PORT PIOD +#define DIO32_PIN PIO_PD10 // PIN 32 +#define DIO33_PORT PIOC +#define DIO33_PIN PIO_PC1 // PIN 33 + + // 34 +#define DIO34_PORT PIOC +#define DIO34_PIN PIO_PC2 // PIN 34 +#define DIO35_PORT PIOC +#define DIO35_PIN PIO_PC3 // PIN 35 +#define DIO36_PORT PIOC +#define DIO36_PIN PIO_PC4 // PIN 36 +#define DIO37_PORT PIOC +#define DIO37_PIN PIO_PC5 // PIN 37 + + // 38 +#define DIO38_PORT PIOC +#define DIO38_PIN PIO_PC6 // PIN 38 +#define DIO39_PORT PIOC +#define DIO39_PIN PIO_PC7 // PIN 39 +#define DIO40_PORT PIOC +#define DIO40_PIN PIO_PC8 // PIN 40 +#define DIO41_PORT PIOC +#define DIO41_PIN PIO_PC9 // PIN 41 + + // 42 +#define DIO42_PORT PIOA +#define DIO42_PIN PIO_PA19 // PIN 42 +#define DIO43_PORT PIOA +#define DIO43_PIN PIO_PA20 // PIN 43 +#define DIO44_PORT PIOC +#define DIO44_PIN PIO_PC19 // PIN 44 +#define DIO45_PORT PIOC +#define DIO45_PIN PIO_PC18 // PIN 45 + + // 46 +#define DIO46_PORT PIOC +#define DIO46_PIN PIO_PC17 // PIN 46 +#define DIO47_PORT PIOC +#define DIO47_PIN PIO_PC16 // PIN 47 +#define DIO48_PORT PIOC +#define DIO48_PIN PIO_PC15 // PIN 48 +#define DIO49_PORT PIOC +#define DIO49_PIN PIO_PC14 // PIN 49 + + // 50 +#define DIO50_PORT PIOC +#define DIO50_PIN PIO_PC13 // PIN 50 +#define DIO51_PORT PIOC +#define DIO51_PIN PIO_PC12 // PIN 51 +#define DIO52_PORT PIOB +#define DIO52_PIN PIO_PB21 // PIN 52 +#define DIO53_PORT PIOB +#define DIO53_PIN PIO_PB14 // PIN 53 + + + // 54 .. 65 - Analog pins + // ---------------------- +#define DIO54_PORT PIOA +#define DIO54_PIN PIO_PA16X1_AD7 // AD0 +#define DIO55_PORT PIOA +#define DIO55_PIN PIO_PA24X1_AD6 // AD1 +#define DIO56_PORT PIOA +#define DIO56_PIN PIO_PA23X1_AD5 // AD2 +#define DIO57_PORT PIOA +#define DIO57_PIN PIO_PA22X1_AD4 // AD3 + // 58 +#define DIO58_PORT PIOA +#define DIO58_PIN PIO_PA6X1_AD3 // AD4 +#define DIO59_PORT PIOA +#define DIO59_PIN PIO_PA4X1_AD2 // AD5 +#define DIO60_PORT PIOA +#define DIO60_PIN PIO_PA3X1_AD1 // AD6 +#define DIO61_PORT PIOA +#define DIO61_PIN PIO_PA2X1_AD0 // AD7 + // 62 +#define DIO62_PORT PIOB +#define DIO62_PIN PIO_PB17X1_AD10 // AD8 +#define DIO63_PORT PIOB +#define DIO63_PIN PIO_PB18X1_AD11 // AD9 +#define DIO64_PORT PIOB +#define DIO64_PIN PIO_PB19X1_AD12 // AD10 +#define DIO65_PORT PIOB +#define DIO65_PIN PIO_PB20X1_AD13 // AD11 + + // 66/67 - DAC0/DAC1 +#define DIO66_PORT PIOB +#define DIO66_PIN PIO_PB15X1_DAC0 // DAC0 +#define DIO67_PORT PIOB +#define DIO67_PIN PIO_PB16X1_DAC1 // DAC1 + + // 68/69 - CANRX0/CANTX0 +#define DIO68_PORT PIOA +#define DIO68_PIN PIO_PA1A_CANRX0 // CANRX +#define DIO69_PORT PIOA +#define DIO69_PIN PIO_PA0A_CANTX0 // CANTX + + // 70/71 - TWI0 +#define DIO70_PORT PIOA +#define DIO70_PIN PIO_PA17A_TWD0 // TWD0 - SDA1 +#define DIO71_PORT PIOA +#define DIO71_PIN PIO_PA18A_TWCK0 // TWCK0 - SCL1 + + // 72/73 - LEDs +#define DIO72_PORT PIOC +#define DIO72_PIN PIO_PC30 // LED AMBER RXL +#define DIO73_PORT PIOA +#define DIO73_PIN PIO_PA21 // LED AMBER TXL + + // 74/75/76 - SPI +#define DIO74_PORT PIOA +#define DIO74_PIN PIO_PA25A_SPI0_MISO // MISO +#define DIO75_PORT PIOA +#define DIO75_PIN PIO_PA26A_SPI0_MOSI // MOSI +#define DIO76_PORT PIOA +#define DIO76_PIN PIO_PA27A_SPI0_SPCK // SPCK + + // 77 - SPI CS0 +#define DIO77_PORT PIOA +#define DIO77_PIN PIO_PA28A_SPI0_NPCS0 // NPCS0 + + // 78 - SPI CS3 (unconnected) +#define DIO78_PORT PIOB +#define DIO78_PIN PIO_PB23B_SPI0_NPCS3 // NPCS3 + + // 79 .. 84 - "All pins" masks + + // 79 - TWI0 all pins +#define DIO79_PORT PIOA +#define DIO79_PIN PIO_PA17A_TWD0|PIO_PA18A_TWCK0 + // 80 - TWI1 all pins +#define DI80_PORT PIOB +#define DIO80_PIN PIO_PB12A_TWD1|PIO_PB13A_TWCK1 + // 81 - UART (Serial) all pins +#define DIO81_PORT PIOA +#define DIO81_PIN PIO_PA8A_URXD|PIO_PA9A_UTXD + // 82 - USART0 (Serial1) all pins +#define DIO82_PORT PIOA +#define DIO82_PIN PIO_PA11A_TXD0|PIO_PA10A_RXD0 + // 83 - USART1 (Serial2) all pins +#define DIO83_PORT PIOA +#define DIO83_PIN PIO_PA13A_TXD1|PIO_PA12A_RXD1 + // 84 - USART3 (Serial3) all pins +#define DIO84_PORT PIOD +#define DIO84_PIN PIO_PD4B_TXD3|PIO_PD5B_RXD3 + + // 85 - USB +#define DIO85_PORT PIOB +#define DIO85_PIN PIO_PB11A_UOTGID|PIO_PB10A_UOTGVBOF // ID - VBOF + + // 86 - SPI CS2 +#define DIO86_PORT PIOB +#define DIO86_PIN PIO_PB21B_SPI0_NPCS2 // NPCS2 + + // 87 - SPI CS1 +#define DIO87_PORT PIOA +#define DIO87_PIN PIO_PA29A_SPI0_NPCS1 // NPCS1 + + // 88/89 - CANRX1/CANTX1 (same physical pin for 66/53) +#define DIO88_PORT PIOB +#define DIO88_PIN PIO_PB15A_CANRX1 // CANRX1 +#define DIO89_PORT PIOB +#define DIO89_PIN PIO_PB14A_CANTX1 // CANTX1 + + // 90 .. 91 - "All CAN pins" masks + // 90 - CAN0 all pins +#define DIO90_PORT PIOA +#define DIO90_PIN PIO_PA1A_CANRX0|PIO_PA0A_CANTX0 + // 91 - CAN1 all pins +#define DIO91_PORT PIOB +#define DIO91_PIN PIO_PB15A_CANRX1|PIO_PB14A_CANTX1 -#include -/* - utility functions -*/ - -#ifndef MASK -/// MASKING- returns \f$2^PIN\f$ - #define MASK(PIN) (1 << PIN) -#endif - -/* - magic I/O routines - - now you can simply SET_OUTPUT(STEP); WRITE(STEP, 1); WRITE(STEP, 0); -*/ - -/// Read a pin -#define _READ(IO) ((bool)(DIO ## IO ## _RPORT & MASK(DIO ## IO ## _PIN))) -/// write to a pin -#define _WRITE(IO, v) do { if (v) {DIO ## IO ## _WPORT |= MASK(DIO ## IO ## _PIN); } else {DIO ## IO ## _WPORT &= ~MASK(DIO ## IO ## _PIN); }; } while (0) -/// toggle a pin -#define _TOGGLE(IO) do {DIO ## IO ## _RPORT = MASK(DIO ## IO ## _PIN); } while (0) - -/// set pin as input -#define _SET_INPUT(IO) do {DIO ## IO ## _DDR &= ~MASK(DIO ## IO ## _PIN); } while (0) -/// set pin as output -#define _SET_OUTPUT(IO) do {DIO ## IO ## _DDR |= MASK(DIO ## IO ## _PIN); } while (0) - -/// check if pin is an input -#define _GET_INPUT(IO) ((DIO ## IO ## _DDR & MASK(DIO ## IO ## _PIN)) == 0) -/// check if pin is an output -#define _GET_OUTPUT(IO) ((DIO ## IO ## _DDR & MASK(DIO ## IO ## _PIN)) != 0) - -// why double up on these macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html - -/// Read a pin wrapper -#define READ(IO) _READ(IO) -/// Write to a pin wrapper -#define WRITE(IO, v) _WRITE(IO, v) -#define PULLUP(IO,v) _WRITE(IO, v) -/// toggle a pin wrapper -#define TOGGLE(IO) _TOGGLE(IO) - -/// set pin as input wrapper -#define SET_INPUT(IO) _SET_INPUT(IO) -/// set pin as output wrapper -#define SET_OUTPUT(IO) _SET_OUTPUT(IO) - -/// check if pin is an input wrapper -#define GET_INPUT(IO) _GET_INPUT(IO) -/// check if pin is an output wrapper -#define GET_OUTPUT(IO) _GET_OUTPUT(IO) - -/* - ports and functions - - added as necessary or if I feel like it- not a comprehensive list! -*/ - -#if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__) -// UART -#define RXD DIO0 -#define TXD DIO1 - -// SPI -#define SCK 13 -#define MISO DIO12 -#define MOSI DIO11 -#define SS 10 - -// TWI (I2C) -#define SCL AIO5 -#define SDA AIO4 - -// timers and PWM -#define OC0A DIO6 -#define OC0B DIO5 -#define OC1A DIO9 -#define OC1B DIO10 -#define OC2A DIO11 -#define OC2B DIO3 - -#define DEBUG_LED AIO5 - -/* -pins -*/ - -#define DIO0_PIN PIND0 -#define DIO0_RPORT PIND -#define DIO0_WPORT PORTD -#define DIO0_DDR DDRD -#define DIO0_PWM NULL - -#define DIO1_PIN PIND1 -#define DIO1_RPORT PIND -#define DIO1_WPORT PORTD -#define DIO1_DDR DDRD -#define DIO1_PWM NULL - -#define DIO2_PIN PIND2 -#define DIO2_RPORT PIND -#define DIO2_WPORT PORTD -#define DIO2_DDR DDRD -#define DIO2_PWM NULL - -#define DIO3_PIN PIND3 -#define DIO3_RPORT PIND -#define DIO3_WPORT PORTD -#define DIO3_DDR DDRD -#define DIO3_PWM &OCR2B - -#define DIO4_PIN PIND4 -#define DIO4_RPORT PIND -#define DIO4_WPORT PORTD -#define DIO4_DDR DDRD -#define DIO4_PWM NULL - -#define DIO5_PIN PIND5 -#define DIO5_RPORT PIND -#define DIO5_WPORT PORTD -#define DIO5_DDR DDRD -#define DIO5_PWM &OCR0B - -#define DIO6_PIN PIND6 -#define DIO6_RPORT PIND -#define DIO6_WPORT PORTD -#define DIO6_DDR DDRD -#define DIO6_PWM &OCR0A - -#define DIO7_PIN PIND7 -#define DIO7_RPORT PIND -#define DIO7_WPORT PORTD -#define DIO7_DDR DDRD -#define DIO7_PWM NULL - -#define DIO8_PIN PINB0 -#define DIO8_RPORT PINB -#define DIO8_WPORT PORTB -#define DIO8_DDR DDRB -#define DIO8_PWM NULL - -#define DIO9_PIN PINB1 -#define DIO9_RPORT PINB -#define DIO9_WPORT PORTB -#define DIO9_DDR DDRB -#define DIO9_PWM NULL - -#define DIO10_PIN PINB2 -#define DIO10_RPORT PINB -#define DIO10_WPORT PORTB -#define DIO10_DDR DDRB -#define DIO10_PWM NULL - -#define DIO11_PIN PINB3 -#define DIO11_RPORT PINB -#define DIO11_WPORT PORTB -#define DIO11_DDR DDRB -#define DIO11_PWM &OCR2A - -#define DIO12_PIN PINB4 -#define DIO12_RPORT PINB -#define DIO12_WPORT PORTB -#define DIO12_DDR DDRB -#define DIO12_PWM NULL - -#define DIO13_PIN PINB5 -#define DIO13_RPORT PINB -#define DIO13_WPORT PORTB -#define DIO13_DDR DDRB -#define DIO13_PWM NULL - - -#define DIO14_PIN PINC0 -#define DIO14_RPORT PINC -#define DIO14_WPORT PORTC -#define DIO14_DDR DDRC -#define DIO14_PWM NULL - -#define DIO15_PIN PINC1 -#define DIO15_RPORT PINC -#define DIO15_WPORT PORTC -#define DIO15_DDR DDRC -#define DIO15_PWM NULL - -#define DIO16_PIN PINC2 -#define DIO16_RPORT PINC -#define DIO16_WPORT PORTC -#define DIO16_DDR DDRC -#define DIO16_PWM NULL - -#define DIO17_PIN PINC3 -#define DIO17_RPORT PINC -#define DIO17_WPORT PORTC -#define DIO17_DDR DDRC -#define DIO17_PWM NULL - -#define DIO18_PIN PINC4 -#define DIO18_RPORT PINC -#define DIO18_WPORT PORTC -#define DIO18_DDR DDRC -#define DIO18_PWM NULL - -#define DIO19_PIN PINC5 -#define DIO19_RPORT PINC -#define DIO19_WPORT PORTC -#define DIO19_DDR DDRC -#define DIO19_PWM NULL - -#define DIO20_PIN PINC6 -#define DIO20_RPORT PINC -#define DIO20_WPORT PORTC -#define DIO20_DDR DDRC -#define DIO20_PWM NULL - -#define DIO21_PIN PINC7 -#define DIO21_RPORT PINC -#define DIO21_WPORT PORTC -#define DIO21_DDR DDRC -#define DIO21_PWM NULL - - - -#undef PB0 -#define PB0_PIN PINB0 -#define PB0_RPORT PINB -#define PB0_WPORT PORTB -#define PB0_DDR DDRB -#define PB0_PWM NULL - -#undef PB1 -#define PB1_PIN PINB1 -#define PB1_RPORT PINB -#define PB1_WPORT PORTB -#define PB1_DDR DDRB -#define PB1_PWM NULL - -#undef PB2 -#define PB2_PIN PINB2 -#define PB2_RPORT PINB -#define PB2_WPORT PORTB -#define PB2_DDR DDRB -#define PB2_PWM NULL - -#undef PB3 -#define PB3_PIN PINB3 -#define PB3_RPORT PINB -#define PB3_WPORT PORTB -#define PB3_DDR DDRB -#define PB3_PWM &OCR2A - -#undef PB4 -#define PB4_PIN PINB4 -#define PB4_RPORT PINB -#define PB4_WPORT PORTB -#define PB4_DDR DDRB -#define PB4_PWM NULL - -#undef PB5 -#define PB5_PIN PINB5 -#define PB5_RPORT PINB -#define PB5_WPORT PORTB -#define PB5_DDR DDRB -#define PB5_PWM NULL - -#undef PB6 -#define PB6_PIN PINB6 -#define PB6_RPORT PINB -#define PB6_WPORT PORTB -#define PB6_DDR DDRB -#define PB6_PWM NULL - -#undef PB7 -#define PB7_PIN PINB7 -#define PB7_RPORT PINB -#define PB7_WPORT PORTB -#define PB7_DDR DDRB -#define PB7_PWM NULL - - -#undef PC0 -#define PC0_PIN PINC0 -#define PC0_RPORT PINC -#define PC0_WPORT PORTC -#define PC0_DDR DDRC -#define PC0_PWM NULL - -#undef PC1 -#define PC1_PIN PINC1 -#define PC1_RPORT PINC -#define PC1_WPORT PORTC -#define PC1_DDR DDRC -#define PC1_PWM NULL - -#undef PC2 -#define PC2_PIN PINC2 -#define PC2_RPORT PINC -#define PC2_WPORT PORTC -#define PC2_DDR DDRC -#define PC2_PWM NULL - -#undef PC3 -#define PC3_PIN PINC3 -#define PC3_RPORT PINC -#define PC3_WPORT PORTC -#define PC3_DDR DDRC -#define PC3_PWM NULL - -#undef PC4 -#define PC4_PIN PINC4 -#define PC4_RPORT PINC -#define PC4_WPORT PORTC -#define PC4_DDR DDRC -#define PC4_PWM NULL - -#undef PC5 -#define PC5_PIN PINC5 -#define PC5_RPORT PINC -#define PC5_WPORT PORTC -#define PC5_DDR DDRC -#define PC5_PWM NULL - -#undef PC6 -#define PC6_PIN PINC6 -#define PC6_RPORT PINC -#define PC6_WPORT PORTC -#define PC6_DDR DDRC -#define PC6_PWM NULL - -#undef PC7 -#define PC7_PIN PINC7 -#define PC7_RPORT PINC -#define PC7_WPORT PORTC -#define PC7_DDR DDRC -#define PC7_PWM NULL - - -#undef PD0 -#define PD0_PIN PIND0 -#define PD0_RPORT PIND -#define PD0_WPORT PORTD -#define PD0_DDR DDRD -#define PD0_PWM NULL - -#undef PD1 -#define PD1_PIN PIND1 -#define PD1_RPORT PIND -#define PD1_WPORT PORTD -#define PD1_DDR DDRD -#define PD1_PWM NULL - -#undef PD2 -#define PD2_PIN PIND2 -#define PD2_RPORT PIND -#define PD2_WPORT PORTD -#define PD2_DDR DDRD -#define PD2_PWM NULL - -#undef PD3 -#define PD3_PIN PIND3 -#define PD3_RPORT PIND -#define PD3_WPORT PORTD -#define PD3_DDR DDRD -#define PD3_PWM &OCR2B - -#undef PD4 -#define PD4_PIN PIND4 -#define PD4_RPORT PIND -#define PD4_WPORT PORTD -#define PD4_DDR DDRD -#define PD4_PWM NULL - -#undef PD5 -#define PD5_PIN PIND5 -#define PD5_RPORT PIND -#define PD5_WPORT PORTD -#define PD5_DDR DDRD -#define PD5_PWM &OCR0B - -#undef PD6 -#define PD6_PIN PIND6 -#define PD6_RPORT PIND -#define PD6_WPORT PORTD -#define PD6_DDR DDRD -#define PD6_PWM &OCR0A - -#undef PD7 -#define PD7_PIN PIND7 -#define PD7_RPORT PIND -#define PD7_WPORT PORTD -#define PD7_DDR DDRD -#define PD7_PWM NULL -#endif /* _AVR_ATmega{168,328,328P}__ */ - -#if defined (__AVR_ATmega644__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__) || defined (__AVR_ATmega1284P__) -// UART -#define RXD DIO8 -#define TXD DIO9 -#define RXD0 DIO8 -#define TXD0 DIO9 - -#define RXD1 DIO10 -#define TXD1 DIO11 - -// SPI -#define SCK 7 -#define MISO DIO6 -#define MOSI DIO5 -#define SS 4 - -// TWI (I2C) -#define SCL DIO16 -#define SDA DIO17 - -// timers and PWM -#define OC0A DIO3 -#define OC0B DIO4 -#define OC1A DIO13 -#define OC1B DIO12 -#define OC2A DIO15 -#define OC2B DIO14 - -#define DEBUG_LED DIO0 -/* -pins -*/ - -#define DIO0_PIN PINB0 -#define DIO0_RPORT PINB -#define DIO0_WPORT PORTB -#define DIO0_DDR DDRB -#define DIO0_PWM NULL - -#define DIO1_PIN PINB1 -#define DIO1_RPORT PINB -#define DIO1_WPORT PORTB -#define DIO1_DDR DDRB -#define DIO1_PWM NULL - -#define DIO2_PIN PINB2 -#define DIO2_RPORT PINB -#define DIO2_WPORT PORTB -#define DIO2_DDR DDRB -#define DIO2_PWM NULL - -#define DIO3_PIN PINB3 -#define DIO3_RPORT PINB -#define DIO3_WPORT PORTB -#define DIO3_DDR DDRB -#define DIO3_PWM &OCR0A - -#define DIO4_PIN PINB4 -#define DIO4_RPORT PINB -#define DIO4_WPORT PORTB -#define DIO4_DDR DDRB -#define DIO4_PWM &OCR0B - -#define DIO5_PIN PINB5 -#define DIO5_RPORT PINB -#define DIO5_WPORT PORTB -#define DIO5_DDR DDRB -#define DIO5_PWM NULL - -#define DIO6_PIN PINB6 -#define DIO6_RPORT PINB -#define DIO6_WPORT PORTB -#define DIO6_DDR DDRB -#define DIO6_PWM NULL - -#define DIO7_PIN PINB7 -#define DIO7_RPORT PINB -#define DIO7_WPORT PORTB -#define DIO7_DDR DDRB -#define DIO7_PWM NULL - -#define DIO8_PIN PIND0 -#define DIO8_RPORT PIND -#define DIO8_WPORT PORTD -#define DIO8_DDR DDRD -#define DIO8_PWM NULL - -#define DIO9_PIN PIND1 -#define DIO9_RPORT PIND -#define DIO9_WPORT PORTD -#define DIO9_DDR DDRD -#define DIO9_PWM NULL - -#define DIO10_PIN PIND2 -#define DIO10_RPORT PIND -#define DIO10_WPORT PORTD -#define DIO10_DDR DDRD -#define DIO10_PWM NULL - -#define DIO11_PIN PIND3 -#define DIO11_RPORT PIND -#define DIO11_WPORT PORTD -#define DIO11_DDR DDRD -#define DIO11_PWM NULL - -#define DIO12_PIN PIND4 -#define DIO12_RPORT PIND -#define DIO12_WPORT PORTD -#define DIO12_DDR DDRD -#define DIO12_PWM NULL - -#define DIO13_PIN PIND5 -#define DIO13_RPORT PIND -#define DIO13_WPORT PORTD -#define DIO13_DDR DDRD -#define DIO13_PWM NULL - -#define DIO14_PIN PIND6 -#define DIO14_RPORT PIND -#define DIO14_WPORT PORTD -#define DIO14_DDR DDRD -#define DIO14_PWM &OCR2B - -#define DIO15_PIN PIND7 -#define DIO15_RPORT PIND -#define DIO15_WPORT PORTD -#define DIO15_DDR DDRD -#define DIO15_PWM &OCR2A - -#define DIO16_PIN PINC0 -#define DIO16_RPORT PINC -#define DIO16_WPORT PORTC -#define DIO16_DDR DDRC -#define DIO16_PWM NULL - -#define DIO17_PIN PINC1 -#define DIO17_RPORT PINC -#define DIO17_WPORT PORTC -#define DIO17_DDR DDRC -#define DIO17_PWM NULL - -#define DIO18_PIN PINC2 -#define DIO18_RPORT PINC -#define DIO18_WPORT PORTC -#define DIO18_DDR DDRC -#define DIO18_PWM NULL - -#define DIO19_PIN PINC3 -#define DIO19_RPORT PINC -#define DIO19_WPORT PORTC -#define DIO19_DDR DDRC -#define DIO19_PWM NULL - -#define DIO20_PIN PINC4 -#define DIO20_RPORT PINC -#define DIO20_WPORT PORTC -#define DIO20_DDR DDRC -#define DIO20_PWM NULL - -#define DIO21_PIN PINC5 -#define DIO21_RPORT PINC -#define DIO21_WPORT PORTC -#define DIO21_DDR DDRC -#define DIO21_PWM NULL - -#define DIO22_PIN PINC6 -#define DIO22_RPORT PINC -#define DIO22_WPORT PORTC -#define DIO22_DDR DDRC -#define DIO22_PWM NULL - -#define DIO23_PIN PINC7 -#define DIO23_RPORT PINC -#define DIO23_WPORT PORTC -#define DIO23_DDR DDRC -#define DIO23_PWM NULL - -#define DIO24_PIN PINA7 -#define DIO24_RPORT PINA -#define DIO24_WPORT PORTA -#define DIO24_DDR DDRA -#define DIO24_PWM NULL - -#define DIO25_PIN PINA6 -#define DIO25_RPORT PINA -#define DIO25_WPORT PORTA -#define DIO25_DDR DDRA -#define DIO25_PWM NULL - -#define DIO26_PIN PINA5 -#define DIO26_RPORT PINA -#define DIO26_WPORT PORTA -#define DIO26_DDR DDRA -#define DIO26_PWM NULL - -#define DIO27_PIN PINA4 -#define DIO27_RPORT PINA -#define DIO27_WPORT PORTA -#define DIO27_DDR DDRA -#define DIO27_PWM NULL - -#define DIO28_PIN PINA3 -#define DIO28_RPORT PINA -#define DIO28_WPORT PORTA -#define DIO28_DDR DDRA -#define DIO28_PWM NULL - -#define DIO29_PIN PINA2 -#define DIO29_RPORT PINA -#define DIO29_WPORT PORTA -#define DIO29_DDR DDRA -#define DIO29_PWM NULL - -#define DIO30_PIN PINA1 -#define DIO30_RPORT PINA -#define DIO30_WPORT PORTA -#define DIO30_DDR DDRA -#define DIO30_PWM NULL - -#define DIO31_PIN PINA0 -#define DIO31_RPORT PINA -#define DIO31_WPORT PORTA -#define DIO31_DDR DDRA -#define DIO31_PWM NULL - -#define AIO0_PIN PINA0 -#define AIO0_RPORT PINA -#define AIO0_WPORT PORTA -#define AIO0_DDR DDRA -#define AIO0_PWM NULL - -#define AIO1_PIN PINA1 -#define AIO1_RPORT PINA -#define AIO1_WPORT PORTA -#define AIO1_DDR DDRA -#define AIO1_PWM NULL - -#define AIO2_PIN PINA2 -#define AIO2_RPORT PINA -#define AIO2_WPORT PORTA -#define AIO2_DDR DDRA -#define AIO2_PWM NULL - -#define AIO3_PIN PINA3 -#define AIO3_RPORT PINA -#define AIO3_WPORT PORTA -#define AIO3_DDR DDRA -#define AIO3_PWM NULL - -#define AIO4_PIN PINA4 -#define AIO4_RPORT PINA -#define AIO4_WPORT PORTA -#define AIO4_DDR DDRA -#define AIO4_PWM NULL - -#define AIO5_PIN PINA5 -#define AIO5_RPORT PINA -#define AIO5_WPORT PORTA -#define AIO5_DDR DDRA -#define AIO5_PWM NULL - -#define AIO6_PIN PINA6 -#define AIO6_RPORT PINA -#define AIO6_WPORT PORTA -#define AIO6_DDR DDRA -#define AIO6_PWM NULL - -#define AIO7_PIN PINA7 -#define AIO7_RPORT PINA -#define AIO7_WPORT PORTA -#define AIO7_DDR DDRA -#define AIO7_PWM NULL - - - -#undef PA0 -#define PA0_PIN PINA0 -#define PA0_RPORT PINA -#define PA0_WPORT PORTA -#define PA0_DDR DDRA -#define PA0_PWM NULL - -#undef PA1 -#define PA1_PIN PINA1 -#define PA1_RPORT PINA -#define PA1_WPORT PORTA -#define PA1_DDR DDRA -#define PA1_PWM NULL - -#undef PA2 -#define PA2_PIN PINA2 -#define PA2_RPORT PINA -#define PA2_WPORT PORTA -#define PA2_DDR DDRA -#define PA2_PWM NULL - -#undef PA3 -#define PA3_PIN PINA3 -#define PA3_RPORT PINA -#define PA3_WPORT PORTA -#define PA3_DDR DDRA -#define PA3_PWM NULL - -#undef PA4 -#define PA4_PIN PINA4 -#define PA4_RPORT PINA -#define PA4_WPORT PORTA -#define PA4_DDR DDRA -#define PA4_PWM NULL - -#undef PA5 -#define PA5_PIN PINA5 -#define PA5_RPORT PINA -#define PA5_WPORT PORTA -#define PA5_DDR DDRA -#define PA5_PWM NULL - -#undef PA6 -#define PA6_PIN PINA6 -#define PA6_RPORT PINA -#define PA6_WPORT PORTA -#define PA6_DDR DDRA -#define PA6_PWM NULL - -#undef PA7 -#define PA7_PIN PINA7 -#define PA7_RPORT PINA -#define PA7_WPORT PORTA -#define PA7_DDR DDRA -#define PA7_PWM NULL - - -#undef PB0 -#define PB0_PIN PINB0 -#define PB0_RPORT PINB -#define PB0_WPORT PORTB -#define PB0_DDR DDRB -#define PB0_PWM NULL - -#undef PB1 -#define PB1_PIN PINB1 -#define PB1_RPORT PINB -#define PB1_WPORT PORTB -#define PB1_DDR DDRB -#define PB1_PWM NULL - -#undef PB2 -#define PB2_PIN PINB2 -#define PB2_RPORT PINB -#define PB2_WPORT PORTB -#define PB2_DDR DDRB -#define PB2_PWM NULL - -#undef PB3 -#define PB3_PIN PINB3 -#define PB3_RPORT PINB -#define PB3_WPORT PORTB -#define PB3_DDR DDRB -#define PB3_PWM &OCR0A - -#undef PB4 -#define PB4_PIN PINB4 -#define PB4_RPORT PINB -#define PB4_WPORT PORTB -#define PB4_DDR DDRB -#define PB4_PWM &OCR0B - -#undef PB5 -#define PB5_PIN PINB5 -#define PB5_RPORT PINB -#define PB5_WPORT PORTB -#define PB5_DDR DDRB -#define PB5_PWM NULL - -#undef PB6 -#define PB6_PIN PINB6 -#define PB6_RPORT PINB -#define PB6_WPORT PORTB -#define PB6_DDR DDRB -#define PB6_PWM NULL - -#undef PB7 -#define PB7_PIN PINB7 -#define PB7_RPORT PINB -#define PB7_WPORT PORTB -#define PB7_DDR DDRB -#define PB7_PWM NULL - - -#undef PC0 -#define PC0_PIN PINC0 -#define PC0_RPORT PINC -#define PC0_WPORT PORTC -#define PC0_DDR DDRC -#define PC0_PWM NULL - -#undef PC1 -#define PC1_PIN PINC1 -#define PC1_RPORT PINC -#define PC1_WPORT PORTC -#define PC1_DDR DDRC -#define PC1_PWM NULL - -#undef PC2 -#define PC2_PIN PINC2 -#define PC2_RPORT PINC -#define PC2_WPORT PORTC -#define PC2_DDR DDRC -#define PC2_PWM NULL - -#undef PC3 -#define PC3_PIN PINC3 -#define PC3_RPORT PINC -#define PC3_WPORT PORTC -#define PC3_DDR DDRC -#define PC3_PWM NULL - -#undef PC4 -#define PC4_PIN PINC4 -#define PC4_RPORT PINC -#define PC4_WPORT PORTC -#define PC4_DDR DDRC -#define PC4_PWM NULL - -#undef PC5 -#define PC5_PIN PINC5 -#define PC5_RPORT PINC -#define PC5_WPORT PORTC -#define PC5_DDR DDRC -#define PC5_PWM NULL - -#undef PC6 -#define PC6_PIN PINC6 -#define PC6_RPORT PINC -#define PC6_WPORT PORTC -#define PC6_DDR DDRC -#define PC6_PWM NULL - -#undef PC7 -#define PC7_PIN PINC7 -#define PC7_RPORT PINC -#define PC7_WPORT PORTC -#define PC7_DDR DDRC -#define PC7_PWM NULL - - -#undef PD0 -#define PD0_PIN PIND0 -#define PD0_RPORT PIND -#define PD0_WPORT PORTD -#define PD0_DDR DDRD -#define PD0_PWM NULL - -#undef PD1 -#define PD1_PIN PIND1 -#define PD1_RPORT PIND -#define PD1_WPORT PORTD -#define PD1_DDR DDRD -#define PD1_PWM NULL - -#undef PD2 -#define PD2_PIN PIND2 -#define PD2_RPORT PIND -#define PD2_WPORT PORTD -#define PD2_DDR DDRD -#define PD2_PWM NULL - -#undef PD3 -#define PD3_PIN PIND3 -#define PD3_RPORT PIND -#define PD3_WPORT PORTD -#define PD3_DDR DDRD -#define PD3_PWM NULL - -#undef PD4 -#define PD4_PIN PIND4 -#define PD4_RPORT PIND -#define PD4_WPORT PORTD -#define PD4_DDR DDRD -#define PD4_PWM NULL - -#undef PD5 -#define PD5_PIN PIND5 -#define PD5_RPORT PIND -#define PD5_WPORT PORTD -#define PD5_DDR DDRD -#define PD5_PWM NULL - -#undef PD6 -#define PD6_PIN PIND6 -#define PD6_RPORT PIND -#define PD6_WPORT PORTD -#define PD6_DDR DDRD -#define PD6_PWM &OCR2B - -#undef PD7 -#define PD7_PIN PIND7 -#define PD7_RPORT PIND -#define PD7_WPORT PORTD -#define PD7_DDR DDRD -#define PD7_PWM &OCR2A -#endif /* _AVR_ATmega{644,644P,644PA}__ */ - -#if defined (__AVR_ATmega1280__) || defined (__AVR_ATmega2560__) -// UART -#define RXD DIO0 -#define TXD DIO1 - -// SPI -#define SCK 52 -#define MISO DIO50 -#define MOSI DIO51 -#define SS 53 - -// TWI (I2C) -#define SCL DIO21 -#define SDA DIO20 - -// timers and PWM -#define OC0A DIO13 -#define OC0B DIO4 -#define OC1A DIO11 -#define OC1B DIO12 -#define OC2A DIO10 -#define OC2B DIO9 -#define OC3A DIO5 -#define OC3B DIO2 -#define OC3C DIO3 -#define OC4A DIO6 -#define OC4B DIO7 -#define OC4C DIO8 -#define OC5A DIO46 -#define OC5B DIO45 -#define OC5C DIO44 - -// change for your board -#if MOTHERBOARD == 12 -#define DEBUG_LED DIO22 -#else -#define DEBUG_LED DIO21 -#endif -/* -pins -*/ -#define DIO0_PIN PINE0 -#define DIO0_RPORT PINE -#define DIO0_WPORT PORTE -#define DIO0_DDR DDRE -#define DIO0_PWM NULL - -#define DIO1_PIN PINE1 -#define DIO1_RPORT PINE -#define DIO1_WPORT PORTE -#define DIO1_DDR DDRE -#define DIO1_PWM NULL - -#define DIO2_PIN PINE4 -#define DIO2_RPORT PINE -#define DIO2_WPORT PORTE -#define DIO2_DDR DDRE -#define DIO2_PWM &OCR3BL - -#define DIO3_PIN PINE5 -#define DIO3_RPORT PINE -#define DIO3_WPORT PORTE -#define DIO3_DDR DDRE -#define DIO3_PWM &OCR3CL - -#define DIO4_PIN PING5 -#define DIO4_RPORT PING -#define DIO4_WPORT PORTG -#define DIO4_DDR DDRG -#define DIO4_PWM &OCR0B - -#define DIO5_PIN PINE3 -#define DIO5_RPORT PINE -#define DIO5_WPORT PORTE -#define DIO5_DDR DDRE -#define DIO5_PWM &OCR3AL - -#define DIO6_PIN PINH3 -#define DIO6_RPORT PINH -#define DIO6_WPORT PORTH -#define DIO6_DDR DDRH -#define DIO6_PWM &OCR4AL - -#define DIO7_PIN PINH4 -#define DIO7_RPORT PINH -#define DIO7_WPORT PORTH -#define DIO7_DDR DDRH -#define DIO7_PWM &OCR4BL - -#define DIO8_PIN PINH5 -#define DIO8_RPORT PINH -#define DIO8_WPORT PORTH -#define DIO8_DDR DDRH -#define DIO8_PWM &OCR4CL - -#define DIO9_PIN PINH6 -#define DIO9_RPORT PINH -#define DIO9_WPORT PORTH -#define DIO9_DDR DDRH -#define DIO9_PWM &OCR2B - -#define DIO10_PIN PINB4 -#define DIO10_RPORT PINB -#define DIO10_WPORT PORTB -#define DIO10_DDR DDRB -#define DIO10_PWM &OCR2A - -#define DIO11_PIN PINB5 -#define DIO11_RPORT PINB -#define DIO11_WPORT PORTB -#define DIO11_DDR DDRB -#define DIO11_PWM NULL - -#define DIO12_PIN PINB6 -#define DIO12_RPORT PINB -#define DIO12_WPORT PORTB -#define DIO12_DDR DDRB -#define DIO12_PWM NULL - -#define DIO13_PIN PINB7 -#define DIO13_RPORT PINB -#define DIO13_WPORT PORTB -#define DIO13_DDR DDRB -#define DIO13_PWM &OCR0A - -#define DIO14_PIN PINJ1 -#define DIO14_RPORT PINJ -#define DIO14_WPORT PORTJ -#define DIO14_DDR DDRJ -#define DIO14_PWM NULL - -#define DIO15_PIN PINJ0 -#define DIO15_RPORT PINJ -#define DIO15_WPORT PORTJ -#define DIO15_DDR DDRJ -#define DIO15_PWM NULL - -#define DIO16_PIN PINH1 -#define DIO16_RPORT PINH -#define DIO16_WPORT PORTH -#define DIO16_DDR DDRH -#define DIO16_PWM NULL - -#define DIO17_PIN PINH0 -#define DIO17_RPORT PINH -#define DIO17_WPORT PORTH -#define DIO17_DDR DDRH -#define DIO17_PWM NULL - -#define DIO18_PIN PIND3 -#define DIO18_RPORT PIND -#define DIO18_WPORT PORTD -#define DIO18_DDR DDRD -#define DIO18_PWM NULL - -#define DIO19_PIN PIND2 -#define DIO19_RPORT PIND -#define DIO19_WPORT PORTD -#define DIO19_DDR DDRD -#define DIO19_PWM NULL - -#define DIO20_PIN PIND1 -#define DIO20_RPORT PIND -#define DIO20_WPORT PORTD -#define DIO20_DDR DDRD -#define DIO20_PWM NULL - -#define DIO21_PIN PIND0 -#define DIO21_RPORT PIND -#define DIO21_WPORT PORTD -#define DIO21_DDR DDRD -#define DIO21_PWM NULL - -#define DIO22_PIN PINA0 -#define DIO22_RPORT PINA -#define DIO22_WPORT PORTA -#define DIO22_DDR DDRA -#define DIO22_PWM NULL - -#define DIO23_PIN PINA1 -#define DIO23_RPORT PINA -#define DIO23_WPORT PORTA -#define DIO23_DDR DDRA -#define DIO23_PWM NULL - -#define DIO24_PIN PINA2 -#define DIO24_RPORT PINA -#define DIO24_WPORT PORTA -#define DIO24_DDR DDRA -#define DIO24_PWM NULL - -#define DIO25_PIN PINA3 -#define DIO25_RPORT PINA -#define DIO25_WPORT PORTA -#define DIO25_DDR DDRA -#define DIO25_PWM NULL - -#define DIO26_PIN PINA4 -#define DIO26_RPORT PINA -#define DIO26_WPORT PORTA -#define DIO26_DDR DDRA -#define DIO26_PWM NULL - -#define DIO27_PIN PINA5 -#define DIO27_RPORT PINA -#define DIO27_WPORT PORTA -#define DIO27_DDR DDRA -#define DIO27_PWM NULL - -#define DIO28_PIN PINA6 -#define DIO28_RPORT PINA -#define DIO28_WPORT PORTA -#define DIO28_DDR DDRA -#define DIO28_PWM NULL - -#define DIO29_PIN PINA7 -#define DIO29_RPORT PINA -#define DIO29_WPORT PORTA -#define DIO29_DDR DDRA -#define DIO29_PWM NULL -#define DIO30_PIN PINC7 -#define DIO30_RPORT PINC -#define DIO30_WPORT PORTC -#define DIO30_DDR DDRC -#define DIO30_PWM NULL - -#define DIO31_PIN PINC6 -#define DIO31_RPORT PINC -#define DIO31_WPORT PORTC -#define DIO31_DDR DDRC -#define DIO31_PWM NULL - -#define DIO32_PIN PINC5 -#define DIO32_RPORT PINC -#define DIO32_WPORT PORTC -#define DIO32_DDR DDRC -#define DIO32_PWM NULL - -#define DIO33_PIN PINC4 -#define DIO33_RPORT PINC -#define DIO33_WPORT PORTC -#define DIO33_DDR DDRC -#define DIO33_PWM NULL - -#define DIO34_PIN PINC3 -#define DIO34_RPORT PINC -#define DIO34_WPORT PORTC -#define DIO34_DDR DDRC -#define DIO34_PWM NULL - -#define DIO35_PIN PINC2 -#define DIO35_RPORT PINC -#define DIO35_WPORT PORTC -#define DIO35_DDR DDRC -#define DIO35_PWM NULL - -#define DIO36_PIN PINC1 -#define DIO36_RPORT PINC -#define DIO36_WPORT PORTC -#define DIO36_DDR DDRC -#define DIO36_PWM NULL - -#define DIO37_PIN PINC0 -#define DIO37_RPORT PINC -#define DIO37_WPORT PORTC -#define DIO37_DDR DDRC -#define DIO37_PWM NULL - -#define DIO38_PIN PIND7 -#define DIO38_RPORT PIND -#define DIO38_WPORT PORTD -#define DIO38_DDR DDRD -#define DIO38_PWM NULL - -#define DIO39_PIN PING2 -#define DIO39_RPORT PING -#define DIO39_WPORT PORTG -#define DIO39_DDR DDRG -#define DIO39_PWM NULL - -#define DIO40_PIN PING1 -#define DIO40_RPORT PING -#define DIO40_WPORT PORTG -#define DIO40_DDR DDRG -#define DIO40_PWM NULL - -#define DIO41_PIN PING0 -#define DIO41_RPORT PING -#define DIO41_WPORT PORTG -#define DIO41_DDR DDRG -#define DIO41_PWM NULL - -#define DIO42_PIN PINL7 -#define DIO42_RPORT PINL -#define DIO42_WPORT PORTL -#define DIO42_DDR DDRL -#define DIO42_PWM NULL - -#define DIO43_PIN PINL6 -#define DIO43_RPORT PINL -#define DIO43_WPORT PORTL -#define DIO43_DDR DDRL -#define DIO43_PWM NULL - -#define DIO44_PIN PINL5 -#define DIO44_RPORT PINL -#define DIO44_WPORT PORTL -#define DIO44_DDR DDRL -#define DIO44_PWM &OCR5CL - -#define DIO45_PIN PINL4 -#define DIO45_RPORT PINL -#define DIO45_WPORT PORTL -#define DIO45_DDR DDRL -#define DIO45_PWM &OCR5BL - -#define DIO46_PIN PINL3 -#define DIO46_RPORT PINL -#define DIO46_WPORT PORTL -#define DIO46_DDR DDRL -#define DIO46_PWM &OCR5AL - -#define DIO47_PIN PINL2 -#define DIO47_RPORT PINL -#define DIO47_WPORT PORTL -#define DIO47_DDR DDRL -#define DIO47_PWM NULL - -#define DIO48_PIN PINL1 -#define DIO48_RPORT PINL -#define DIO48_WPORT PORTL -#define DIO48_DDR DDRL -#define DIO48_PWM NULL - -#define DIO49_PIN PINL0 -#define DIO49_RPORT PINL -#define DIO49_WPORT PORTL -#define DIO49_DDR DDRL -#define DIO49_PWM NULL - -#define DIO50_PIN PINB3 -#define DIO50_RPORT PINB -#define DIO50_WPORT PORTB -#define DIO50_DDR DDRB -#define DIO50_PWM NULL - -#define DIO51_PIN PINB2 -#define DIO51_RPORT PINB -#define DIO51_WPORT PORTB -#define DIO51_DDR DDRB -#define DIO51_PWM NULL - -#define DIO52_PIN PINB1 -#define DIO52_RPORT PINB -#define DIO52_WPORT PORTB -#define DIO52_DDR DDRB -#define DIO52_PWM NULL - -#define DIO53_PIN PINB0 -#define DIO53_RPORT PINB -#define DIO53_WPORT PORTB -#define DIO53_DDR DDRB -#define DIO53_PWM NULL - -#define DIO54_PIN PINF0 -#define DIO54_RPORT PINF -#define DIO54_WPORT PORTF -#define DIO54_DDR DDRF -#define DIO54_PWM NULL - -#define DIO55_PIN PINF1 -#define DIO55_RPORT PINF -#define DIO55_WPORT PORTF -#define DIO55_DDR DDRF -#define DIO55_PWM NULL - -#define DIO56_PIN PINF2 -#define DIO56_RPORT PINF -#define DIO56_WPORT PORTF -#define DIO56_DDR DDRF -#define DIO56_PWM NULL - -#define DIO57_PIN PINF3 -#define DIO57_RPORT PINF -#define DIO57_WPORT PORTF -#define DIO57_DDR DDRF -#define DIO57_PWM NULL - -#define DIO58_PIN PINF4 -#define DIO58_RPORT PINF -#define DIO58_WPORT PORTF -#define DIO58_DDR DDRF -#define DIO58_PWM NULL - -#define DIO59_PIN PINF5 -#define DIO59_RPORT PINF -#define DIO59_WPORT PORTF -#define DIO59_DDR DDRF -#define DIO59_PWM NULL - -#define DIO60_PIN PINF6 -#define DIO60_RPORT PINF -#define DIO60_WPORT PORTF -#define DIO60_DDR DDRF -#define DIO60_PWM NULL - -#define DIO61_PIN PINF7 -#define DIO61_RPORT PINF -#define DIO61_WPORT PORTF -#define DIO61_DDR DDRF -#define DIO61_PWM NULL - -#define DIO62_PIN PINK0 -#define DIO62_RPORT PINK -#define DIO62_WPORT PORTK -#define DIO62_DDR DDRK -#define DIO62_PWM NULL - -#define DIO63_PIN PINK1 -#define DIO63_RPORT PINK -#define DIO63_WPORT PORTK -#define DIO63_DDR DDRK -#define DIO63_PWM NULL - -#define DIO64_PIN PINK2 -#define DIO64_RPORT PINK -#define DIO64_WPORT PORTK -#define DIO64_DDR DDRK -#define DIO64_PWM NULL - -#define DIO65_PIN PINK3 -#define DIO65_RPORT PINK -#define DIO65_WPORT PORTK -#define DIO65_DDR DDRK -#define DIO65_PWM NULL - -#define DIO66_PIN PINK4 -#define DIO66_RPORT PINK -#define DIO66_WPORT PORTK -#define DIO66_DDR DDRK -#define DIO66_PWM NULL - -#define DIO67_PIN PINK5 -#define DIO67_RPORT PINK -#define DIO67_WPORT PORTK -#define DIO67_DDR DDRK -#define DIO67_PWM NULL - -#define DIO68_PIN PINK6 -#define DIO68_RPORT PINK -#define DIO68_WPORT PORTK -#define DIO68_DDR DDRK -#define DIO68_PWM NULL - -#define DIO69_PIN PINK7 -#define DIO69_RPORT PINK -#define DIO69_WPORT PORTK -#define DIO69_DDR DDRK -#define DIO69_PWM NULL - -#if MOTHERBOARD == 12 -#define DIO80_PIN PINJ2 -#define DIO80_RPORT PINJ -#define DIO80_WPORT PORTJ -#define DIO80_DDR DDRJ -#define DIO80_PWM NULL - -#define DIO81_PIN PINJ4 -#define DIO81_RPORT PINJ -#define DIO81_WPORT PORTJ -#define DIO81_DDR DDRJ -#define DIO81_PWM NULL - -#define DIO82_PIN PINJ5 -#define DIO82_RPORT PINJ -#define DIO82_WPORT PORTJ -#define DIO82_DDR DDRJ -#define DIO82_PWM NULL - -#define DIO83_PIN PINJ6 -#define DIO83_RPORT PINJ -#define DIO83_WPORT PORTJ -#define DIO83_DDR DDRJ -#define DIO83_PWM NULL - -#define DIO84_PIN PINJ7 -#define DIO84_RPORT PINJ -#define DIO84_WPORT PORTJ -#define DIO84_DDR DDRJ -#define DIO84_PWM NULL - -#define DIO85_PIN PINH7 -#define DIO85_RPORT PINH -#define DIO85_WPORT PORTH -#define DIO85_DDR DDRH -#define DIO85_PWM NULL - -#define DIO86_PIN PINH2 -#define DIO86_RPORT PINH -#define DIO86_WPORT PORTH -#define DIO86_DDR DDRH -#define DIO86_PWM NULL - -#define DIO90_PIN PINE7 -#define DIO90_RPORT PINE -#define DIO90_WPORT PORTE -#define DIO90_DDR DDRE -#define DIO90_PWM NULL - -#define DIO91_PIN PINE2 -#define DIO91_RPORT PINE -#define DIO91_WPORT PORTE -#define DIO91_DDR DDRE -#define DIO91_PWM NULL - -#define DIO92_PIN PIND4 -#define DIO92_RPORT PIND -#define DIO92_WPORT PORTD -#define DIO92_DDR DDRD -#define DIO92_PWM NULL - -#define DIO93_PIN PIND5 -#define DIO93_RPORT PIND -#define DIO93_WPORT PORTD -#define DIO93_DDR DDRD -#define DIO93_PWM NULL - -#define DIO94_PIN PIND6 -#define DIO94_RPORT PIND -#define DIO94_WPORT PORTD -#define DIO94_DDR DDRD -#define DIO94_PWM NULL -#else // MOTHERBOARD == 12 - -//added below DIO definitions for RAMBo support for LCD's etc... - -#define DIO70_PIN PING4 -#define DIO70_RPORT PING -#define DIO70_WPORT PORTG -#define DIO70_DDR DDRG -#define DIO70_PWM NULL -#define DIO71_PIN PING3 -#define DIO71_RPORT PING -#define DIO71_WPORT PORTG -#define DIO71_DDR DDRG -#define DIO71_PWM NULL -#define DIO72_PIN PINJ2 -#define DIO72_RPORT PINJ -#define DIO72_WPORT PORTJ -#define DIO72_DDR DDRJ -#define DIO72_PWM NULL -#define DIO73_PIN PINJ3 -#define DIO73_RPORT PINJ -#define DIO73_WPORT PORTJ -#define DIO73_DDR DDRJ -#define DIO73_PWM NULL -#define DIO74_PIN PINJ7 -#define DIO74_RPORT PINJ -#define DIO74_WPORT PORTJ -#define DIO74_DDR DDRJ -#define DIO74_PWM NULL -#define DIO75_PIN PINJ4 -#define DIO75_RPORT PINJ -#define DIO75_WPORT PORTJ -#define DIO75_DDR DDRJ -#define DIO75_PWM NULL - - -#define DIO76_PIN PINJ5 -#define DIO76_RPORT PINJ -#define DIO76_WPORT PORTJ -#define DIO76_DDR DDRJ -#define DIO76_PWM NULL -#define DIO77_PIN PINJ6 -#define DIO77_RPORT PINJ -#define DIO77_WPORT PORTJ -#define DIO77_DDR DDRJ -#define DIO77_PWM NULL -#define DIO78_PIN PINE2 -#define DIO78_RPORT PINE -#define DIO78_WPORT PORTE -#define DIO78_DDR DDRE -#define DIO78_PWM NULL -#define DIO79_PIN PINE6 -#define DIO79_RPORT PINE -#define DIO79_WPORT PORTE -#define DIO79_DDR DDRE -#define DIO79_PWM NULL -#define DIO80_PIN PINE7 -#define DIO80_RPORT PINE -#define DIO80_WPORT PORTE -#define DIO80_DDR DDRE -#define DIO80_PWM NULL -#define DIO81_PIN PIND4 -#define DIO81_RPORT PIND -#define DIO81_WPORT PORTD -#define DIO81_DDR DDRD -#define DIO81_PWM NULL - -#endif - -#undef PA0 -#define PA0_PIN PINA0 -#define PA0_RPORT PINA -#define PA0_WPORT PORTA -#define PA0_DDR DDRA -#define PA0_PWM NULL -#undef PA1 -#define PA1_PIN PINA1 -#define PA1_RPORT PINA -#define PA1_WPORT PORTA -#define PA1_DDR DDRA -#define PA1_PWM NULL -#undef PA2 -#define PA2_PIN PINA2 -#define PA2_RPORT PINA -#define PA2_WPORT PORTA -#define PA2_DDR DDRA -#define PA2_PWM NULL -#undef PA3 -#define PA3_PIN PINA3 -#define PA3_RPORT PINA -#define PA3_WPORT PORTA -#define PA3_DDR DDRA -#define PA3_PWM NULL -#undef PA4 -#define PA4_PIN PINA4 -#define PA4_RPORT PINA -#define PA4_WPORT PORTA -#define PA4_DDR DDRA -#define PA4_PWM NULL -#undef PA5 -#define PA5_PIN PINA5 -#define PA5_RPORT PINA -#define PA5_WPORT PORTA -#define PA5_DDR DDRA -#define PA5_PWM NULL -#undef PA6 -#define PA6_PIN PINA6 -#define PA6_RPORT PINA -#define PA6_WPORT PORTA -#define PA6_DDR DDRA -#define PA6_PWM NULL -#undef PA7 -#define PA7_PIN PINA7 -#define PA7_RPORT PINA -#define PA7_WPORT PORTA -#define PA7_DDR DDRA -#define PA7_PWM NULL - -#undef PB0 -#define PB0_PIN PINB0 -#define PB0_RPORT PINB -#define PB0_WPORT PORTB -#define PB0_DDR DDRB -#define PB0_PWM NULL -#undef PB1 -#define PB1_PIN PINB1 -#define PB1_RPORT PINB -#define PB1_WPORT PORTB -#define PB1_DDR DDRB -#define PB1_PWM NULL -#undef PB2 -#define PB2_PIN PINB2 -#define PB2_RPORT PINB -#define PB2_WPORT PORTB -#define PB2_DDR DDRB -#define PB2_PWM NULL -#undef PB3 -#define PB3_PIN PINB3 -#define PB3_RPORT PINB -#define PB3_WPORT PORTB -#define PB3_DDR DDRB -#define PB3_PWM NULL -#undef PB4 -#define PB4_PIN PINB4 -#define PB4_RPORT PINB -#define PB4_WPORT PORTB -#define PB4_DDR DDRB -#define PB4_PWM &OCR2A -#undef PB5 -#define PB5_PIN PINB5 -#define PB5_RPORT PINB -#define PB5_WPORT PORTB -#define PB5_DDR DDRB -#define PB5_PWM NULL -#undef PB6 -#define PB6_PIN PINB6 -#define PB6_RPORT PINB -#define PB6_WPORT PORTB -#define PB6_DDR DDRB -#define PB6_PWM NULL -#undef PB7 -#define PB7_PIN PINB7 -#define PB7_RPORT PINB -#define PB7_WPORT PORTB -#define PB7_DDR DDRB -#define PB7_PWM &OCR0A - -#undef PC0 -#define PC0_PIN PINC0 -#define PC0_RPORT PINC -#define PC0_WPORT PORTC -#define PC0_DDR DDRC -#define PC0_PWM NULL -#undef PC1 -#define PC1_PIN PINC1 -#define PC1_RPORT PINC -#define PC1_WPORT PORTC -#define PC1_DDR DDRC -#define PC1_PWM NULL -#undef PC2 -#define PC2_PIN PINC2 -#define PC2_RPORT PINC -#define PC2_WPORT PORTC -#define PC2_DDR DDRC -#define PC2_PWM NULL -#undef PC3 -#define PC3_PIN PINC3 -#define PC3_RPORT PINC -#define PC3_WPORT PORTC -#define PC3_DDR DDRC -#define PC3_PWM NULL -#undef PC4 -#define PC4_PIN PINC4 -#define PC4_RPORT PINC -#define PC4_WPORT PORTC -#define PC4_DDR DDRC -#define PC4_PWM NULL -#undef PC5 -#define PC5_PIN PINC5 -#define PC5_RPORT PINC -#define PC5_WPORT PORTC -#define PC5_DDR DDRC -#define PC5_PWM NULL -#undef PC6 -#define PC6_PIN PINC6 -#define PC6_RPORT PINC -#define PC6_WPORT PORTC -#define PC6_DDR DDRC -#define PC6_PWM NULL -#undef PC7 -#define PC7_PIN PINC7 -#define PC7_RPORT PINC -#define PC7_WPORT PORTC -#define PC7_DDR DDRC -#define PC7_PWM NULL - -#undef PD0 -#define PD0_PIN PIND0 -#define PD0_RPORT PIND -#define PD0_WPORT PORTD -#define PD0_DDR DDRD -#define PD0_PWM NULL -#undef PD1 -#define PD1_PIN PIND1 -#define PD1_RPORT PIND -#define PD1_WPORT PORTD -#define PD1_DDR DDRD -#define PD1_PWM NULL -#undef PD2 -#define PD2_PIN PIND2 -#define PD2_RPORT PIND -#define PD2_WPORT PORTD -#define PD2_DDR DDRD -#define PD2_PWM NULL -#undef PD3 -#define PD3_PIN PIND3 -#define PD3_RPORT PIND -#define PD3_WPORT PORTD -#define PD3_DDR DDRD -#define PD3_PWM NULL -#undef PD4 -#define PD4_PIN PIND4 -#define PD4_RPORT PIND -#define PD4_WPORT PORTD -#define PD4_DDR DDRD -#define PD4_PWM NULL -#undef PD5 -#define PD5_PIN PIND5 -#define PD5_RPORT PIND -#define PD5_WPORT PORTD -#define PD5_DDR DDRD -#define PD5_PWM NULL -#undef PD6 -#define PD6_PIN PIND6 -#define PD6_RPORT PIND -#define PD6_WPORT PORTD -#define PD6_DDR DDRD -#define PD6_PWM NULL -#undef PD7 -#define PD7_PIN PIND7 -#define PD7_RPORT PIND -#define PD7_WPORT PORTD -#define PD7_DDR DDRD -#define PD7_PWM NULL - -#undef PE0 -#define PE0_PIN PINE0 -#define PE0_RPORT PINE -#define PE0_WPORT PORTE -#define PE0_DDR DDRE -#define PE0_PWM NULL -#undef PE1 -#define PE1_PIN PINE1 -#define PE1_RPORT PINE -#define PE1_WPORT PORTE -#define PE1_DDR DDRE -#define PE1_PWM NULL -#undef PE2 -#define PE2_PIN PINE2 -#define PE2_RPORT PINE -#define PE2_WPORT PORTE -#define PE2_DDR DDRE -#define PE2_PWM NULL -#undef PE3 -#define PE3_PIN PINE3 -#define PE3_RPORT PINE -#define PE3_WPORT PORTE -#define PE3_DDR DDRE -#define PE3_PWM &OCR3AL -#undef PE4 -#define PE4_PIN PINE4 -#define PE4_RPORT PINE -#define PE4_WPORT PORTE -#define PE4_DDR DDRE -#define PE4_PWM &OCR3BL -#undef PE5 -#define PE5_PIN PINE5 -#define PE5_RPORT PINE -#define PE5_WPORT PORTE -#define PE5_DDR DDRE -#define PE5_PWM &OCR3CL -#undef PE6 -#define PE6_PIN PINE6 -#define PE6_RPORT PINE -#define PE6_WPORT PORTE -#define PE6_DDR DDRE -#define PE6_PWM NULL -#undef PE7 -#define PE7_PIN PINE7 -#define PE7_RPORT PINE -#define PE7_WPORT PORTE -#define PE7_DDR DDRE -#define PE7_PWM NULL - -#undef PF0 -#define PF0_PIN PINF0 -#define PF0_RPORT PINF -#define PF0_WPORT PORTF -#define PF0_DDR DDRF -#define PF0_PWM NULL -#undef PF1 -#define PF1_PIN PINF1 -#define PF1_RPORT PINF -#define PF1_WPORT PORTF -#define PF1_DDR DDRF -#define PF1_PWM NULL -#undef PF2 -#define PF2_PIN PINF2 -#define PF2_RPORT PINF -#define PF2_WPORT PORTF -#define PF2_DDR DDRF -#define PF2_PWM NULL -#undef PF3 -#define PF3_PIN PINF3 -#define PF3_RPORT PINF -#define PF3_WPORT PORTF -#define PF3_DDR DDRF -#define PF3_PWM NULL -#undef PF4 -#define PF4_PIN PINF4 -#define PF4_RPORT PINF -#define PF4_WPORT PORTF -#define PF4_DDR DDRF -#define PF4_PWM NULL -#undef PF5 -#define PF5_PIN PINF5 -#define PF5_RPORT PINF -#define PF5_WPORT PORTF -#define PF5_DDR DDRF -#define PF5_PWM NULL -#undef PF6 -#define PF6_PIN PINF6 -#define PF6_RPORT PINF -#define PF6_WPORT PORTF -#define PF6_DDR DDRF -#define PF6_PWM NULL -#undef PF7 -#define PF7_PIN PINF7 -#define PF7_RPORT PINF -#define PF7_WPORT PORTF -#define PF7_DDR DDRF -#define PF7_PWM NULL - -#undef PG0 -#define PG0_PIN PING0 -#define PG0_RPORT PING -#define PG0_WPORT PORTG -#define PG0_DDR DDRG -#define PG0_PWM NULL -#undef PG1 -#define PG1_PIN PING1 -#define PG1_RPORT PING -#define PG1_WPORT PORTG -#define PG1_DDR DDRG -#define PG1_PWM NULL -#undef PG2 -#define PG2_PIN PING2 -#define PG2_RPORT PING -#define PG2_WPORT PORTG -#define PG2_DDR DDRG -#define PG2_PWM NULL -#undef PG3 -#define PG3_PIN PING3 -#define PG3_RPORT PING -#define PG3_WPORT PORTG -#define PG3_DDR DDRG -#define PG3_PWM NULL -#undef PG4 -#define PG4_PIN PING4 -#define PG4_RPORT PING -#define PG4_WPORT PORTG -#define PG4_DDR DDRG -#define PG4_PWM NULL -#undef PG5 -#define PG5_PIN PING5 -#define PG5_RPORT PING -#define PG5_WPORT PORTG -#define PG5_DDR DDRG -#define PG5_PWM &OCR0B -#undef PG6 -#define PG6_PIN PING6 -#define PG6_RPORT PING -#define PG6_WPORT PORTG -#define PG6_DDR DDRG -#define PG6_PWM NULL -#undef PG7 -#define PG7_PIN PING7 -#define PG7_RPORT PING -#define PG7_WPORT PORTG -#define PG7_DDR DDRG -#define PG7_PWM NULL - -#undef PH0 -#define PH0_PIN PINH0 -#define PH0_RPORT PINH -#define PH0_WPORT PORTH -#define PH0_DDR DDRH -#define PH0_PWM NULL -#undef PH1 -#define PH1_PIN PINH1 -#define PH1_RPORT PINH -#define PH1_WPORT PORTH -#define PH1_DDR DDRH -#define PH1_PWM NULL -#undef PH2 -#define PH2_PIN PINH2 -#define PH2_RPORT PINH -#define PH2_WPORT PORTH -#define PH2_DDR DDRH -#define PH2_PWM NULL -#undef PH3 -#define PH3_PIN PINH3 -#define PH3_RPORT PINH -#define PH3_WPORT PORTH -#define PH3_DDR DDRH -#define PH3_PWM &OCR4AL -#undef PH4 -#define PH4_PIN PINH4 -#define PH4_RPORT PINH -#define PH4_WPORT PORTH -#define PH4_DDR DDRH -#define PH4_PWM &OCR4BL -#undef PH5 -#define PH5_PIN PINH5 -#define PH5_RPORT PINH -#define PH5_WPORT PORTH -#define PH5_DDR DDRH -#define PH5_PWM &OCR4CL -#undef PH6 -#define PH6_PIN PINH6 -#define PH6_RPORT PINH -#define PH6_WPORT PORTH -#define PH6_DDR DDRH -#define PH6_PWM &OCR2B -#undef PH7 -#define PH7_PIN PINH7 -#define PH7_RPORT PINH -#define PH7_WPORT PORTH -#define PH7_DDR DDRH -#define PH7_PWM NULL - -#undef PJ0 -#define PJ0_PIN PINJ0 -#define PJ0_RPORT PINJ -#define PJ0_WPORT PORTJ -#define PJ0_DDR DDRJ -#define PJ0_PWM NULL -#undef PJ1 -#define PJ1_PIN PINJ1 -#define PJ1_RPORT PINJ -#define PJ1_WPORT PORTJ -#define PJ1_DDR DDRJ -#define PJ1_PWM NULL -#undef PJ2 -#define PJ2_PIN PINJ2 -#define PJ2_RPORT PINJ -#define PJ2_WPORT PORTJ -#define PJ2_DDR DDRJ -#define PJ2_PWM NULL -#undef PJ3 -#define PJ3_PIN PINJ3 -#define PJ3_RPORT PINJ -#define PJ3_WPORT PORTJ -#define PJ3_DDR DDRJ -#define PJ3_PWM NULL -#undef PJ4 -#define PJ4_PIN PINJ4 -#define PJ4_RPORT PINJ -#define PJ4_WPORT PORTJ -#define PJ4_DDR DDRJ -#define PJ4_PWM NULL -#undef PJ5 -#define PJ5_PIN PINJ5 -#define PJ5_RPORT PINJ -#define PJ5_WPORT PORTJ -#define PJ5_DDR DDRJ -#define PJ5_PWM NULL -#undef PJ6 -#define PJ6_PIN PINJ6 -#define PJ6_RPORT PINJ -#define PJ6_WPORT PORTJ -#define PJ6_DDR DDRJ -#define PJ6_PWM NULL -#undef PJ7 -#define PJ7_PIN PINJ7 -#define PJ7_RPORT PINJ -#define PJ7_WPORT PORTJ -#define PJ7_DDR DDRJ -#define PJ7_PWM NULL - -#undef PK0 -#define PK0_PIN PINK0 -#define PK0_RPORT PINK -#define PK0_WPORT PORTK -#define PK0_DDR DDRK -#define PK0_PWM NULL -#undef PK1 -#define PK1_PIN PINK1 -#define PK1_RPORT PINK -#define PK1_WPORT PORTK -#define PK1_DDR DDRK -#define PK1_PWM NULL -#undef PK2 -#define PK2_PIN PINK2 -#define PK2_RPORT PINK -#define PK2_WPORT PORTK -#define PK2_DDR DDRK -#define PK2_PWM NULL -#undef PK3 -#define PK3_PIN PINK3 -#define PK3_RPORT PINK -#define PK3_WPORT PORTK -#define PK3_DDR DDRK -#define PK3_PWM NULL -#undef PK4 -#define PK4_PIN PINK4 -#define PK4_RPORT PINK -#define PK4_WPORT PORTK -#define PK4_DDR DDRK -#define PK4_PWM NULL -#undef PK5 -#define PK5_PIN PINK5 -#define PK5_RPORT PINK -#define PK5_WPORT PORTK -#define PK5_DDR DDRK -#define PK5_PWM NULL -#undef PK6 -#define PK6_PIN PINK6 -#define PK6_RPORT PINK -#define PK6_WPORT PORTK -#define PK6_DDR DDRK -#define PK6_PWM NULL -#undef PK7 -#define PK7_PIN PINK7 -#define PK7_RPORT PINK -#define PK7_WPORT PORTK -#define PK7_DDR DDRK -#define PK7_PWM NULL - -#undef PL0 -#define PL0_PIN PINL0 -#define PL0_RPORT PINL -#define PL0_WPORT PORTL -#define PL0_DDR DDRL -#define PL0_PWM NULL -#undef PL1 -#define PL1_PIN PINL1 -#define PL1_RPORT PINL -#define PL1_WPORT PORTL -#define PL1_DDR DDRL -#define PL1_PWM NULL -#undef PL2 -#define PL2_PIN PINL2 -#define PL2_RPORT PINL -#define PL2_WPORT PORTL -#define PL2_DDR DDRL -#define PL2_PWM NULL -#undef PL3 -#define PL3_PIN PINL3 -#define PL3_RPORT PINL -#define PL3_WPORT PORTL -#define PL3_DDR DDRL -#define PL3_PWM &OCR5AL -#undef PL4 -#define PL4_PIN PINL4 -#define PL4_RPORT PINL -#define PL4_WPORT PORTL -#define PL4_DDR DDRL -#define PL4_PWM &OCR5BL -#undef PL5 -#define PL5_PIN PINL5 -#define PL5_RPORT PINL -#define PL5_WPORT PORTL -#define PL5_DDR DDRL -#define PL5_PWM &OCR5CL -#undef PL6 -#define PL6_PIN PINL6 -#define PL6_RPORT PINL -#define PL6_WPORT PORTL -#define PL6_DDR DDRL -#define PL6_PWM NULL -#undef PL7 -#define PL7_PIN PINL7 -#define PL7_RPORT PINL -#define PL7_WPORT PORTL -#define PL7_DDR DDRL -#define PL7_PWM NULL - -#endif - -#if defined (__AVR_AT90USB1287__) || defined (__AVR_AT90USB1286__) -// SPI -#define SCK 9 -#define MISO DIO11 -#define MOSI DIO10 -#define SS 8 - -#if MOTHERBOARD!=8 && MOTHERBOARD!=9 -// change for your board -#define DEBUG_LED DIO31 /* led D5 red */ - -/* -pins -*/ -#define DIO0_PIN PINA0 -#define DIO0_RPORT PINA -#define DIO0_WPORT PORTA -#define DIO0_PWM NULL -#define DIO0_DDR DDRA - -#define DIO1_PIN PINA1 -#define DIO1_RPORT PINA -#define DIO1_WPORT PORTA -#define DIO1_PWM NULL -#define DIO1_DDR DDRA - -#define DIO2_PIN PINA2 -#define DIO2_RPORT PINA -#define DIO2_WPORT PORTA -#define DIO2_PWM NULL -#define DIO2_DDR DDRA - -#define DIO3_PIN PINA3 -#define DIO3_RPORT PINA -#define DIO3_WPORT PORTA -#define DIO3_PWM NULL -#define DIO3_DDR DDRA - -#define DIO4_PIN PINA4 -#define DIO4_RPORT PINA -#define DIO4_WPORT PORTA -#define DIO4_PWM NULL -#define DIO4_DDR DDRA - -#define DIO5_PIN PINA5 -#define DIO5_RPORT PINA -#define DIO5_WPORT PORTA -#define DIO5_PWM NULL -#define DIO5_DDR DDRA - -#define DIO6_PIN PINA6 -#define DIO6_RPORT PINA -#define DIO6_WPORT PORTA -#define DIO6_PWM NULL -#define DIO6_DDR DDRA - -#define DIO7_PIN PINA7 -#define DIO7_RPORT PINA -#define DIO7_WPORT PORTA -#define DIO7_PWM NULL -#define DIO7_DDR DDRA - -#define DIO8_PIN PINB0 -#define DIO8_RPORT PINB -#define DIO8_WPORT PORTB -#define DIO8_PWM NULL -#define DIO8_DDR DDRB - -#define DIO9_PIN PINB1 -#define DIO9_RPORT PINB -#define DIO9_WPORT PORTB -#define DIO9_PWM NULL -#define DIO9_DDR DDRB - -#define DIO10_PIN PINB2 -#define DIO10_RPORT PINB -#define DIO10_WPORT PORTB -#define DIO10_PWM NULL -#define DIO10_DDR DDRB - -#define DIO11_PIN PINB3 -#define DIO11_RPORT PINB -#define DIO11_WPORT PORTB -#define DIO11_PWM NULL -#define DIO11_DDR DDRB - -#define DIO12_PIN PINB4 -#define DIO12_RPORT PINB -#define DIO12_WPORT PORTB -#define DIO12_PWM NULL -#define DIO12_DDR DDRB - -#define DIO13_PIN PINB5 -#define DIO13_RPORT PINB -#define DIO13_WPORT PORTB -#define DIO13_PWM NULL -#define DIO13_DDR DDRB - -#define DIO14_PIN PINB6 -#define DIO14_RPORT PINB -#define DIO14_WPORT PORTB -#define DIO14_PWM NULL -#define DIO14_DDR DDRB - -#define DIO15_PIN PINB7 -#define DIO15_RPORT PINB -#define DIO15_WPORT PORTB -#define DIO15_PWM NULL -#define DIO15_DDR DDRB - -#define DIO16_PIN PINC0 -#define DIO16_RPORT PINC -#define DIO16_WPORT PORTC -#define DIO16_PWM NULL -#define DIO16_DDR DDRC - -#define DIO17_PIN PINC1 -#define DIO17_RPORT PINC -#define DIO17_WPORT PORTC -#define DIO17_PWM NULL -#define DIO17_DDR DDRC - -#define DIO18_PIN PINC2 -#define DIO18_RPORT PINC -#define DIO18_WPORT PORTC -#define DIO18_PWM NULL -#define DIO18_DDR DDRC - -#define DIO19_PIN PINC3 -#define DIO19_RPORT PINC -#define DIO19_WPORT PORTC -#define DIO19_PWM NULL -#define DIO19_DDR DDRC - -#define DIO20_PIN PINC4 -#define DIO20_RPORT PINC -#define DIO20_WPORT PORTC -#define DIO20_PWM NULL -#define DIO20_DDR DDRC - -#define DIO21_PIN PINC5 -#define DIO21_RPORT PINC -#define DIO21_WPORT PORTC -#define DIO21_PWM NULL -#define DIO21_DDR DDRC - -#define DIO22_PIN PINC6 -#define DIO22_RPORT PINC -#define DIO22_WPORT PORTC -#define DIO22_PWM NULL -#define DIO22_DDR DDRC - -#define DIO23_PIN PINC7 -#define DIO23_RPORT PINC -#define DIO23_WPORT PORTC -#define DIO23_PWM NULL -#define DIO23_DDR DDRC - -#define DIO24_PIN PIND0 -#define DIO24_RPORT PIND -#define DIO24_WPORT PORTD -#define DIO24_PWM NULL -#define DIO24_DDR DDRD - -#define DIO25_PIN PIND1 -#define DIO25_RPORT PIND -#define DIO25_WPORT PORTD -#define DIO25_PWM NULL -#define DIO25_DDR DDRD - -#define DIO26_PIN PIND2 -#define DIO26_RPORT PIND -#define DIO26_WPORT PORTD -#define DIO26_PWM NULL -#define DIO26_DDR DDRD - -#define DIO27_PIN PIND3 -#define DIO27_RPORT PIND -#define DIO27_WPORT PORTD -#define DIO27_PWM NULL -#define DIO27_DDR DDRD - -#define DIO28_PIN PIND4 -#define DIO28_RPORT PIND -#define DIO28_WPORT PORTD -#define DIO28_PWM NULL -#define DIO28_DDR DDRD - -#define DIO29_PIN PIND5 -#define DIO29_RPORT PIND -#define DIO29_WPORT PORTD -#define DIO29_PWM NULL -#define DIO29_DDR DDRD - -#define DIO30_PIN PIND6 -#define DIO30_RPORT PIND -#define DIO30_WPORT PORTD -#define DIO30_PWM NULL -#define DIO30_DDR DDRD - -#define DIO31_PIN PIND7 -#define DIO31_RPORT PIND -#define DIO31_WPORT PORTD -#define DIO31_PWM NULL -#define DIO31_DDR DDRD - - -#define DIO32_PIN PINE0 -#define DIO32_RPORT PINE -#define DIO32_WPORT PORTE -#define DIO32_PWM NULL -#define DIO32_DDR DDRE - -#define DIO33_PIN PINE1 -#define DIO33_RPORT PINE -#define DIO33_WPORT PORTE -#define DIO33_PWM NULL -#define DIO33_DDR DDRE - -#define DIO34_PIN PINE2 -#define DIO34_RPORT PINE -#define DIO34_WPORT PORTE -#define DIO34_PWM NULL -#define DIO34_DDR DDRE - -#define DIO35_PIN PINE3 -#define DIO35_RPORT PINE -#define DIO35_WPORT PORTE -#define DIO35_PWM NULL -#define DIO35_DDR DDRE - -#define DIO36_PIN PINE4 -#define DIO36_RPORT PINE -#define DIO36_WPORT PORTE -#define DIO36_PWM NULL -#define DIO36_DDR DDRE - -#define DIO37_PIN PINE5 -#define DIO37_RPORT PINE -#define DIO37_WPORT PORTE -#define DIO37_PWM NULL -#define DIO37_DDR DDRE - -#define DIO38_PIN PINE6 -#define DIO38_RPORT PINE -#define DIO38_WPORT PORTE -#define DIO38_PWM NULL -#define DIO38_DDR DDRE - -#define DIO39_PIN PINE7 -#define DIO39_RPORT PINE -#define DIO39_WPORT PORTE -#define DIO39_PWM NULL -#define DIO39_DDR DDRE - -#define AIO0_PIN PINF0 -#define AIO0_RPORT PINF -#define AIO0_WPORT PORTF -#define AIO0_PWM NULL -#define AIO0_DDR DDRF - -#define AIO1_PIN PINF1 -#define AIO1_RPORT PINF -#define AIO1_WPORT PORTF -#define AIO1_PWM NULL -#define AIO1_DDR DDRF - -#define AIO2_PIN PINF2 -#define AIO2_RPORT PINF -#define AIO2_WPORT PORTF -#define AIO2_PWM NULL -#define AIO2_DDR DDRF - -#define AIO3_PIN PINF3 -#define AIO3_RPORT PINF -#define AIO3_WPORT PORTF -#define AIO3_PWM NULL -#define AIO3_DDR DDRF - -#define AIO4_PIN PINF4 -#define AIO4_RPORT PINF -#define AIO4_WPORT PORTF -#define AIO4_PWM NULL -#define AIO4_DDR DDRF - -#define AIO5_PIN PINF5 -#define AIO5_RPORT PINF -#define AIO5_WPORT PORTF -#define AIO5_PWM NULL -#define AIO5_DDR DDRF - -#define AIO6_PIN PINF6 -#define AIO6_RPORT PINF -#define AIO6_WPORT PORTF -#define AIO6_PWM NULL -#define AIO6_DDR DDRF - -#define AIO7_PIN PINF7 -#define AIO7_RPORT PINF -#define AIO7_WPORT PORTF -#define AIO7_PWM NULL -#define AIO7_DDR DDRF - -#define DIO40_PIN PINF0 -#define DIO40_RPORT PINF -#define DIO40_WPORT PORTF -#define DIO40_PWM NULL -#define DIO40_DDR DDRF - -#define DIO41_PIN PINF1 -#define DIO41_RPORT PINF -#define DIO41_WPORT PORTF -#define DIO41_PWM NULL -#define DIO41_DDR DDRF - -#define DIO42_PIN PINF2 -#define DIO42_RPORT PINF -#define DIO42_WPORT PORTF -#define DIO42_PWM NULL -#define DIO42_DDR DDRF - -#define DIO43_PIN PINF3 -#define DIO43_RPORT PINF -#define DIO43_WPORT PORTF -#define DIO43_PWM NULL -#define DIO43_DDR DDRF - -#define DIO44_PIN PINF4 -#define DIO44_RPORT PINF -#define DIO44_WPORT PORTF -#define DIO44_PWM NULL -#define DIO44_DDR DDRF - -#define DIO45_PIN PINF5 -#define DIO45_RPORT PINF -#define DIO45_WPORT PORTF -#define DIO45_PWM NULL -#define DIO45_DDR DDRF - -#define DIO46_PIN PINF6 -#define DIO46_RPORT PINF -#define DIO46_WPORT PORTF -#define DIO46_PWM NULL -#define DIO46_DDR DDRF - -#define DIO47_PIN PINF7 -#define DIO47_RPORT PINF -#define DIO47_WPORT PORTF -#define DIO47_PWM NULL -#define DIO47_DDR DDRF - -#else -/* -pins -*/ -#define DIO0_PIN PIND0 -#define DIO0_RPORT PIND -#define DIO0_WPORT PORTD -#define DIO0_PWM NULL -#define DIO0_DDR DDRD - -#define DIO1_PIN PIND1 -#define DIO1_RPORT PIND -#define DIO1_WPORT PORTD -#define DIO1_PWM NULL -#define DIO1_DDR DDRD - -#define DIO2_PIN PIND2 -#define DIO2_RPORT PIND -#define DIO2_WPORT PORTD -#define DIO2_PWM NULL -#define DIO2_DDR DDRD - -#define DIO3_PIN PIND3 -#define DIO3_RPORT PIND -#define DIO3_WPORT PORTD -#define DIO3_PWM NULL -#define DIO3_DDR DDRD - -#define DIO4_PIN PIND4 -#define DIO4_RPORT PIND -#define DIO4_WPORT PORTD -#define DIO4_PWM NULL -#define DIO4_DDR DDRD - -#define DIO5_PIN PIND5 -#define DIO5_RPORT PIND -#define DIO5_WPORT PORTD -#define DIO5_PWM NULL -#define DIO5_DDR DDRD - -#define DIO6_PIN PIND6 -#define DIO6_RPORT PIND -#define DIO6_WPORT PORTD -#define DIO6_PWM NULL -#define DIO6_DDR DDRD - -#define DIO7_PIN PIND7 -#define DIO7_RPORT PIND -#define DIO7_WPORT PORTD -#define DIO7_PWM NULL -#define DIO7_DDR DDRD - -#define DIO8_PIN PINE0 -#define DIO8_RPORT PINE -#define DIO8_WPORT PORTE -#define DIO8_PWM NULL -#define DIO8_DDR DDRE - -#define DIO9_PIN PINE1 -#define DIO9_RPORT PINE -#define DIO9_WPORT PORTE -#define DIO9_PWM NULL -#define DIO9_DDR DDRE - -#define DIO10_PIN PINC0 -#define DIO10_RPORT PINC -#define DIO10_WPORT PORTC -#define DIO10_PWM NULL -#define DIO10_DDR DDRC - -#define DIO11_PIN PINC1 -#define DIO11_RPORT PINC -#define DIO11_WPORT PORTC -#define DIO11_PWM NULL -#define DIO11_DDR DDRC - -#define DIO12_PIN PINC2 -#define DIO12_RPORT PINC -#define DIO12_WPORT PORTC -#define DIO12_PWM NULL -#define DIO12_DDR DDRC - -#define DIO13_PIN PINC3 -#define DIO13_RPORT PINC -#define DIO13_WPORT PORTC -#define DIO13_PWM NULL -#define DIO13_DDR DDRC - -#define DIO14_PIN PINC4 -#define DIO14_RPORT PINC -#define DIO14_WPORT PORTC -#define DIO14_PWM NULL -#define DIO14_DDR DDRC - -#define DIO15_PIN PINC5 -#define DIO15_RPORT PINC -#define DIO15_WPORT PORTC -#define DIO15_PWM NULL -#define DIO15_DDR DDRC - -#define DIO16_PIN PINC6 -#define DIO16_RPORT PINC -#define DIO16_WPORT PORTC -#define DIO16_PWM NULL -#define DIO16_DDR DDRC - -#define DIO17_PIN PINC7 -#define DIO17_RPORT PINC -#define DIO17_WPORT PORTC -#define DIO17_PWM NULL -#define DIO17_DDR DDRC - -#define DIO18_PIN PINE6 -#define DIO18_RPORT PINE -#define DIO18_WPORT PORTE -#define DIO18_PWM NULL -#define DIO18_DDR DDRE - -#define DIO19_PIN PINE7 -#define DIO19_RPORT PINE -#define DIO19_WPORT PORTE -#define DIO19_PWM NULL -#define DIO19_DDR DDRE - -#define DIO20_PIN PINB0 -#define DIO20_RPORT PINB -#define DIO20_WPORT PORTB -#define DIO20_PWM NULL -#define DIO20_DDR DDRB - -#define DIO21_PIN PINB1 -#define DIO21_RPORT PINB -#define DIO21_WPORT PORTB -#define DIO21_PWM NULL -#define DIO21_DDR DDRB - -#define DIO22_PIN PINB2 -#define DIO22_RPORT PINB -#define DIO22_WPORT PORTB -#define DIO22_PWM NULL -#define DIO22_DDR DDRB - -#define DIO23_PIN PINB3 -#define DIO23_RPORT PINB -#define DIO23_WPORT PORTB -#define DIO23_PWM NULL -#define DIO23_DDR DDRB - -#define DIO24_PIN PINB4 -#define DIO24_RPORT PINB -#define DIO24_WPORT PORTB -#define DIO24_PWM NULL -#define DIO24_DDR DDRB - -#define DIO25_PIN PINB5 -#define DIO25_RPORT PINB -#define DIO25_WPORT PORTB -#define DIO25_PWM NULL -#define DIO25_DDR DDRB - -#define DIO26_PIN PINB6 -#define DIO26_RPORT PINB -#define DIO26_WPORT PORTB -#define DIO26_PWM NULL -#define DIO26_DDR DDRB - -#define DIO27_PIN PINB7 -#define DIO27_RPORT PINB -#define DIO27_WPORT PORTB -#define DIO27_PWM NULL -#define DIO27_DDR DDRB - -#define DIO28_PIN PINA0 -#define DIO28_RPORT PINA -#define DIO28_WPORT PORTA -#define DIO28_PWM NULL -#define DIO28_DDR DDRA - -#define DIO29_PIN PINA1 -#define DIO29_RPORT PINA -#define DIO29_WPORT PORTA -#define DIO29_PWM NULL -#define DIO29_DDR DDRA - -#define DIO30_PIN PINA2 -#define DIO30_RPORT PINA -#define DIO30_WPORT PORTA -#define DIO30_PWM NULL -#define DIO30_DDR DDRA - -#define DIO31_PIN PINA3 -#define DIO31_RPORT PINA -#define DIO31_WPORT PORTA -#define DIO31_PWM NULL -#define DIO31_DDR DDRA - - -#define DIO32_PIN PINA4 -#define DIO32_RPORT PINA -#define DIO32_WPORT PORTA -#define DIO32_PWM NULL -#define DIO32_DDR DDRA - -#define DIO33_PIN PINA5 -#define DIO33_RPORT PINA -#define DIO33_WPORT PORTA -#define DIO33_PWM NULL -#define DIO33_DDR DDRA - -#define DIO34_PIN PINA6 -#define DIO34_RPORT PINA -#define DIO34_WPORT PORTA -#define DIO34_PWM NULL -#define DIO34_DDR DDRA - -#define DIO35_PIN PINA7 -#define DIO35_RPORT PINA -#define DIO35_WPORT PORTA -#define DIO35_PWM NULL -#define DIO35_DDR DDRA - -#define DIO36_PIN PINE4 -#define DIO36_RPORT PINE -#define DIO36_WPORT PORTE -#define DIO36_PWM NULL -#define DIO36_DDR DDRE - -#define DIO37_PIN PINE5 -#define DIO37_RPORT PINE -#define DIO37_WPORT PORTE -#define DIO37_PWM NULL -#define DIO37_DDR DDRE - -#define DIO38_PIN PINF0 -#define DIO38_RPORT PINF -#define DIO38_WPORT PORTF -#define DIO38_PWM NULL -#define DIO38_DDR DDRF - -#define DIO39_PIN PINF1 -#define DIO39_RPORT PINF -#define DIO39_WPORT PORTF -#define DIO39_PWM NULL -#define DIO39_DDR DDRF - -#define DIO40_PIN PINF2 -#define DIO40_RPORT PINF -#define DIO40_WPORT PORTF -#define DIO40_PWM NULL -#define DIO40_DDR DDRF - -#define DIO41_PIN PINF3 -#define DIO41_RPORT PINF -#define DIO41_WPORT PORTF -#define DIO41_PWM NULL -#define DIO41_DDR DDRF - -#define DIO42_PIN PINF4 -#define DIO42_RPORT PINF -#define DIO42_WPORT PORTF -#define DIO42_PWM NULL -#define DIO42_DDR DDRF - -#define DIO43_PIN PINF5 -#define DIO43_RPORT PINF -#define DIO43_WPORT PORTF -#define DIO43_PWM NULL -#define DIO43_DDR DDRF - -#define DIO44_PIN PINF6 -#define DIO44_RPORT PINF -#define DIO44_WPORT PORTF -#define DIO44_PWM NULL -#define DIO44_DDR DDRF - -#define DIO45_PIN PINF7 -#define DIO45_RPORT PINF -#define DIO45_WPORT PORTF -#define DIO45_PWM NULL -#define DIO45_DDR DDRF - -#define AIO0_PIN PINF0 -#define AIO0_RPORT PINF -#define AIO0_WPORT PORTF -#define AIO0_PWM NULL -#define AIO0_DDR DDRF - -#define AIO1_PIN PINF1 -#define AIO1_RPORT PINF -#define AIO1_WPORT PORTF -#define AIO1_PWM NULL -#define AIO1_DDR DDRF - -#define AIO2_PIN PINF2 -#define AIO2_RPORT PINF -#define AIO2_WPORT PORTF -#define AIO2_PWM NULL -#define AIO2_DDR DDRF - -#define AIO3_PIN PINF3 -#define AIO3_RPORT PINF -#define AIO3_WPORT PORTF -#define AIO3_PWM NULL -#define AIO3_DDR DDRF - -#define AIO4_PIN PINF4 -#define AIO4_RPORT PINF -#define AIO4_WPORT PORTF -#define AIO4_PWM NULL -#define AIO4_DDR DDRF - -#define AIO5_PIN PINF5 -#define AIO5_RPORT PINF -#define AIO5_WPORT PORTF -#define AIO5_PWM NULL -#define AIO5_DDR DDRF - -#define AIO6_PIN PINF6 -#define AIO6_RPORT PINF -#define AIO6_WPORT PORTF -#define AIO6_PWM NULL -#define AIO6_DDR DDRF - -#define AIO7_PIN PINF7 -#define AIO7_RPORT PINF -#define AIO7_WPORT PORTF -#define AIO7_PWM NULL -#define AIO7_DDR DDRF - -//-- Begin not supported by Teensyduino -//-- don't use Arduino functions on these pins pinMode/digitalWrite/etc -#define DIO46_PIN PINE2 -#define DIO46_RPORT PINE -#define DIO46_WPORT PORTE -#define DIO46_PWM NULL -#define DIO46_DDR DDRE - -#define DIO47_PIN PINE3 -#define DIO47_RPORT PINE -#define DIO47_WPORT PORTE -#define DIO47_PWM NULL -#define DIO47_DDR DDRE -//-- end not supported by Teensyduino - -#endif - - -#undef PA0 -#define PA0_PIN PINA0 -#define PA0_RPORT PINA -#define PA0_WPORT PORTA -#define PA0_PWM NULL -#define PA0_DDR DDRA -#undef PA1 -#define PA1_PIN PINA1 -#define PA1_RPORT PINA -#define PA1_WPORT PORTA -#define PA1_PWM NULL -#define PA1_DDR DDRA -#undef PA2 -#define PA2_PIN PINA2 -#define PA2_RPORT PINA -#define PA2_WPORT PORTA -#define PA2_PWM NULL -#define PA2_DDR DDRA -#undef PA3 -#define PA3_PIN PINA3 -#define PA3_RPORT PINA -#define PA3_WPORT PORTA -#define PA3_PWM NULL -#define PA3_DDR DDRA -#undef PA4 -#define PA4_PIN PINA4 -#define PA4_RPORT PINA -#define PA4_WPORT PORTA -#define PA4_PWM NULL -#define PA4_DDR DDRA -#undef PA5 -#define PA5_PIN PINA5 -#define PA5_RPORT PINA -#define PA5_WPORT PORTA -#define PA5_PWM NULL -#define PA5_DDR DDRA -#undef PA6 -#define PA6_PIN PINA6 -#define PA6_RPORT PINA -#define PA6_WPORT PORTA -#define PA6_PWM NULL -#define PA6_DDR DDRA -#undef PA7 -#define PA7_PIN PINA7 -#define PA7_RPORT PINA -#define PA7_WPORT PORTA -#define PA7_PWM NULL -#define PA7_DDR DDRA - -#undef PB0 -#define PB0_PIN PINB0 -#define PB0_RPORT PINB -#define PB0_WPORT PORTB -#define PB0_PWM NULL -#define PB0_DDR DDRB -#undef PB1 -#define PB1_PIN PINB1 -#define PB1_RPORT PINB -#define PB1_WPORT PORTB -#define PB1_PWM NULL -#define PB1_DDR DDRB -#undef PB2 -#define PB2_PIN PINB2 -#define PB2_RPORT PINB -#define PB2_WPORT PORTB -#define PB2_PWM NULL -#define PB2_DDR DDRB -#undef PB3 -#define PB3_PIN PINB3 -#define PB3_RPORT PINB -#define PB3_WPORT PORTB -#define PB3_PWM NULL -#define PB3_DDR DDRB -#undef PB4 -#define PB4_PIN PINB4 -#define PB4_RPORT PINB -#define PB4_WPORT PORTB -#define PB4_PWM NULL -#define PB4_DDR DDRB -#undef PB5 -#define PB5_PIN PINB5 -#define PB5_RPORT PINB -#define PB5_WPORT PORTB -#define PB5_PWM NULL -#define PB5_DDR DDRB -#undef PB6 -#define PB6_PIN PINB6 -#define PB6_RPORT PINB -#define PB6_WPORT PORTB -#define PB6_PWM NULL -#define PB6_DDR DDRB -#undef PB7 -#define PB7_PIN PINB7 -#define PB7_RPORT PINB -#define PB7_WPORT PORTB -#define PB7_PWM NULL -#define PB7_DDR DDRB - -#undef PC0 -#define PC0_PIN PINC0 -#define PC0_RPORT PINC -#define PC0_WPORT PORTC -#define PC0_PWM NULL -#define PC0_DDR DDRC -#undef PC1 -#define PC1_PIN PINC1 -#define PC1_RPORT PINC -#define PC1_WPORT PORTC -#define PC1_PWM NULL -#define PC1_DDR DDRC -#undef PC2 -#define PC2_PIN PINC2 -#define PC2_RPORT PINC -#define PC2_WPORT PORTC -#define PC2_PWM NULL -#define PC2_DDR DDRC -#undef PC3 -#define PC3_PIN PINC3 -#define PC3_RPORT PINC -#define PC3_WPORT PORTC -#define PC3_PWM NULL -#define PC3_DDR DDRC -#undef PC4 -#define PC4_PIN PINC4 -#define PC4_RPORT PINC -#define PC4_WPORT PORTC -#define PC4_PWM NULL -#define PC4_DDR DDRC -#undef PC5 -#define PC5_PIN PINC5 -#define PC5_RPORT PINC -#define PC5_WPORT PORTC -#define PC5_PWM NULL -#define PC5_DDR DDRC -#undef PC6 -#define PC6_PIN PINC6 -#define PC6_RPORT PINC -#define PC6_WPORT PORTC -#define PC6_PWM NULL -#define PC6_DDR DDRC -#undef PC7 -#define PC7_PIN PINC7 -#define PC7_RPORT PINC -#define PC7_WPORT PORTC -#define PC7_PWM NULL -#define PC7_DDR DDRC - -#undef PD0 -#define PD0_PIN PIND0 -#define PD0_RPORT PIND -#define PD0_WPORT PORTD -#define PD0_PWM NULL -#define PD0_DDR DDRD -#undef PD1 -#define PD1_PIN PIND1 -#define PD1_RPORT PIND -#define PD1_WPORT PORTD -#define PD1_PWM NULL -#define PD1_DDR DDRD -#undef PD2 -#define PD2_PIN PIND2 -#define PD2_RPORT PIND -#define PD2_WPORT PORTD -#define PD2_PWM NULL -#define PD2_DDR DDRD -#undef PD3 -#define PD3_PIN PIND3 -#define PD3_RPORT PIND -#define PD3_WPORT PORTD -#define PD3_PWM NULL -#define PD3_DDR DDRD -#undef PD4 -#define PD4_PIN PIND4 -#define PD4_RPORT PIND -#define PD4_WPORT PORTD -#define PD4_PWM NULL -#define PD4_DDR DDRD -#undef PD5 -#define PD5_PIN PIND5 -#define PD5_RPORT PIND -#define PD5_WPORT PORTD -#define PD5_PWM NULL -#define PD5_DDR DDRD -#undef PD6 -#define PD6_PIN PIND6 -#define PD6_RPORT PIND -#define PD6_WPORT PORTD -#define PD6_PWM NULL -#define PD6_DDR DDRD -#undef PD7 -#define PD7_PIN PIND7 -#define PD7_RPORT PIND -#define PD7_WPORT PORTD -#define PD7_PWM NULL -#define PD7_DDR DDRD - -#undef PE0 -#define PE0_PIN PINE0 -#define PE0_RPORT PINE -#define PE0_WPORT PORTE -#define PE0_PWM NULL -#define PE0_DDR DDRE -#undef PE1 -#define PE1_PIN PINE1 -#define PE1_RPORT PINE -#define PE1_WPORT PORTE -#define PE1_PWM NULL -#define PE1_DDR DDRE -#undef PE2 -#define PE2_PIN PINE2 -#define PE2_RPORT PINE -#define PE2_WPORT PORTE -#define PE2_PWM NULL -#define PE2_DDR DDRE -#undef PE3 -#define PE3_PIN PINE3 -#define PE3_RPORT PINE -#define PE3_WPORT PORTE -#define PE3_PWM NULL -#define PE3_DDR DDRE -#undef PE4 -#define PE4_PIN PINE4 -#define PE4_RPORT PINE -#define PE4_WPORT PORTE -#define PE4_PWM NULL -#define PE4_DDR DDRE -#undef PE5 -#define PE5_PIN PINE5 -#define PE5_RPORT PINE -#define PE5_WPORT PORTE -#define PE5_PWM NULL -#define PE5_DDR DDRE -#undef PE6 -#define PE6_PIN PINE6 -#define PE6_RPORT PINE -#define PE6_WPORT PORTE -#define PE6_PWM NULL -#define PE6_DDR DDRE -#undef PE7 -#define PE7_PIN PINE7 -#define PE7_RPORT PINE -#define PE7_WPORT PORTE -#define PE7_PWM NULL -#define PE7_DDR DDRE - -#undef PF0 -#define PF0_PIN PINF0 -#define PF0_RPORT PINF -#define PF0_WPORT PORTF -#define PF0_PWM NULL -#define PF0_DDR DDRF -#undef PF1 -#define PF1_PIN PINF1 -#define PF1_RPORT PINF -#define PF1_WPORT PORTF -#define PF1_PWM NULL -#define PF1_DDR DDRF -#undef PF2 -#define PF2_PIN PINF2 -#define PF2_RPORT PINF -#define PF2_WPORT PORTF -#define PF2_PWM NULL -#define PF2_DDR DDRF -#undef PF3 -#define PF3_PIN PINF3 -#define PF3_RPORT PINF -#define PF3_WPORT PORTF -#define PF3_PWM NULL -#define PF3_DDR DDRF -#undef PF4 -#define PF4_PIN PINF4 -#define PF4_RPORT PINF -#define PF4_WPORT PORTF -#define PF4_PWM NULL -#define PF4_DDR DDRF -#undef PF5 -#define PF5_PIN PINF5 -#define PF5_RPORT PINF -#define PF5_WPORT PORTF -#define PF5_PWM NULL -#define PF5_DDR DDRF -#undef PF6 -#define PF6_PIN PINF6 -#define PF6_RPORT PINF -#define PF6_WPORT PORTF -#define PF6_PWM NULL -#define PF6_DDR DDRF -#undef PF7 -#define PF7_PIN PINF7 -#define PF7_RPORT PINF -#define PF7_WPORT PORTF -#define PF7_PWM NULL -#define PF7_DDR DDRF -#endif #ifndef DIO0_PIN #error pins for this chip not defined in arduino.h! If you write an appropriate pin definition and have this firmware work on your chip, please submit a pull request #endif -#endif /* _ARDUINO_H */ +#endif /* _FASTIO_H */ diff --git a/src/ArduinoDUE/Repetier/motion.cpp b/src/ArduinoDUE/Repetier/motion.cpp index 5c5a2680a..4778a3cc5 100644 --- a/src/ArduinoDUE/Repetier/motion.cpp +++ b/src/ArduinoDUE/Repetier/motion.cpp @@ -36,9 +36,6 @@ #ifdef EXTRUDER_SPEED #error EXTRUDER_SPEED is not used any more. Values are now taken from extruder definition. #endif -#if MAX_HALFSTEP_INTERVAL<=1900 -#error MAX_HALFSTEP_INTERVAL must be greater then 1900 -#endif #ifdef ENDSTOPPULLUPS #error ENDSTOPPULLUPS is now replaced by individual pullup configuration! #endif @@ -86,9 +83,9 @@ PrintLine *PrintLine::cur = 0; ///< Current printing line #if CPU_ARCH == ARCH_ARM volatile bool PrintLine::nlFlag = false; #endif -uint8_t PrintLine::linesWritePos = 0; ///< Position where we write the next cached line move. -volatile uint8_t PrintLine::linesCount = 0; ///< Number of lines cached 0 = nothing to do. -uint8_t PrintLine::linesPos = 0; ///< Position for executing line movement. +ufast8_t PrintLine::linesWritePos = 0; ///< Position where we write the next cached line move. +volatile ufast8_t PrintLine::linesCount = 0; ///< Number of lines cached 0 = nothing to do. +ufast8_t PrintLine::linesPos = 0; ///< Position for executing line movement. /** Move printer the given number of steps. Puts the move into the queue. Used by e.g. homing commands. @@ -420,19 +417,6 @@ void PrintLine::calculateMove(float axis_diff[], uint8_t pathOptimize) #endif #endif - // Correct integers for fixed point math used in bresenham_step - if(fullInterval < MAX_HALFSTEP_INTERVAL || critical) - halfStep = 4; - else - { - halfStep = 1; -#if NONLINEAR_SYSTEM - // Error 0-2 are used for the towers and set up in the timer - error[E_AXIS] = stepsRemaining; -#else - error[X_AXIS] = error[Y_AXIS] = error[Z_AXIS] = error[E_AXIS] = delta[primaryAxis]; -#endif - } #ifdef DEBUG_STEPCOUNT // Set in delta move calculation #if !NONLINEAR_SYSTEM @@ -651,8 +635,8 @@ void PrintLine::updateStepsParameter() Com::printFLN(Com::tSlash,(long)stepsRemaining); Com::printF(Com::tDBGStartEndSpeed,startSpeed,1); Com::printFLN(Com::tSlash,endSpeed,1); - Com::printFLN(Com::tDBGFlags,flags); - Com::printFLN(Com::tDBGJoinFlags,joinFlags); + Com::printFLN(Com::tDBGFlags,(uint32_t)flags); + Com::printFLN(Com::tDBGJoinFlags,(uint32_t)joinFlags); } #endif } @@ -853,8 +837,8 @@ void PrintLine::logLine() #ifdef DEBUG_QUEUE_MOVE Com::printFLN(Com::tDBGId,(int)this); Com::printArrayFLN(Com::tDBGDelta,delta); - Com::printFLN(Com::tDBGDir,dir); - Com::printFLN(Com::tDBGFlags,flags); + Com::printFLN(Com::tDBGDir,(uint32_t)dir); + Com::printFLN(Com::tDBGFlags,(uint32_t)flags); Com::printFLN(Com::tDBGFullSpeed,fullSpeed); Com::printFLN(Com::tDBGVMax,(int32_t)vMax); Com::printFLN(Com::tDBGAcceleration,accelerationDistance2); @@ -904,7 +888,8 @@ uint8_t transformCartesianStepsToDeltaSteps(int32_t cartesianPosSteps[], int32_t static int32_t lastZSteps = 9999999; static int32_t lastZCorrection = 0; cnt++; - if(cnt >= DISTORTION_UPDATE_FREQUENCY || lastZSteps != zSteps) { + if(cnt >= DISTORTION_UPDATE_FREQUENCY || lastZSteps != zSteps) + { cnt = 0; lastZSteps = zSteps; lastZCorrection = Printer::distortion.correct(cartesianPosSteps[X_AXIS], cartesianPosSteps[Y_AXIS], cartesianPosSteps[Z_AXIS]); @@ -915,8 +900,8 @@ uint8_t transformCartesianStepsToDeltaSteps(int32_t cartesianPosSteps[], int32_t if(Printer::isLargeMachine()) { #ifdef SUPPORT_64_BIT_MATH - // 64 bit is better for precision, so we use that if available. - // A TOWER height + // 64 bit is better for precision, so we use that if available. + // A TOWER height uint64_t temp = RMath::absLong(Printer::deltaAPosYSteps - cartesianPosSteps[Y_AXIS]); uint64_t opt = Printer::deltaDiagonalStepsSquaredA.L; @@ -1214,16 +1199,6 @@ void DeltaSegment::checkEndstops(PrintLine *cur,bool checkall) setYMoveFinished(); cur->setYMoveFinished(); } - if(isXPositiveMove() && Printer::isXMaxEndstopHit()) - { - setXMoveFinished(); - cur->setXMoveFinished(); - } - if(isYPositiveMove() && Printer::isYMaxEndstopHit()) - { - setYMoveFinished(); - cur->setYMoveFinished(); - } #if DRIVE_SYSTEM != DELTA if(isXNegativeMove() && Printer::isXMinEndstopHit()) { @@ -1253,7 +1228,7 @@ void DeltaSegment::checkEndstops(PrintLine *cur,bool checkall) } -void PrintLine::calculateDirectionAndDelta(int32_t difference[], flag8_t *dir, int32_t delta[]) +void PrintLine::calculateDirectionAndDelta(int32_t difference[], ufast8_t *dir, int32_t delta[]) { *dir = 0; //Find direction @@ -1320,7 +1295,7 @@ inline uint16_t PrintLine::calculateDeltaSubSegments(uint8_t softEndstop) } #else float segment = static_cast(numDeltaSegments - s + 1); - for(i=0; i < Z_AXIS_ARRAY; i++) // End of segment in cartesian steps + for(i = 0; i < Z_AXIS_ARRAY; i++) // End of segment in cartesian steps // Perfect approximation, but slower, so we limit it to faster processors like arm destinationSteps[i] = static_cast(floor(0.5 + dx[i] * segment)) + Printer::currentPositionSteps[i]; #endif @@ -1485,12 +1460,13 @@ uint8_t PrintLine::queueDeltaMove(uint8_t check_endstops,uint8_t pathOptimize, u axis_diff[E_AXIS] = difference[E_AXIS] * Printer::invAxisStepsPerMM[E_AXIS]; Printer::filamentPrinted += axis_diff[E_AXIS]; axis_diff[E_AXIS] = fabs(axis_diff[E_AXIS]); - } else + } + else axis_diff[axis] = fabs(difference[axis] * Printer::invAxisStepsPerMM[axis]); } float cartesianDistance; - flag8_t cartesianDir; + ufast8_t cartesianDir; int32_t cartesianDeltaSteps[E_AXIS_ARRAY]; calculateDirectionAndDelta(difference, &cartesianDir, cartesianDeltaSteps); if (!calculateDistance(axis_diff, cartesianDir, &cartesianDistance)) @@ -1676,7 +1652,7 @@ void PrintLine::arc(float *position, float *target, float *offset, float radius, long ytarget = Printer::destinationSteps[Y_AXIS]; long ztarget = Printer::destinationSteps[Z_AXIS]; long etarget = Printer::destinationSteps[E_AXIS]; -*/ + */ // CCW angle between position and target from circle center. Only one atan2() trig computation required. float angular_travel = atan2(r_axis0 * rt_axis1 - r_axis1 * rt_axis0, r_axis0 * rt_axis0 + r_axis1 * rt_axis1); if (angular_travel < 0) @@ -1822,7 +1798,7 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer { HAL::allowInterrupts(); lastblk = (int)cur; - Com::printFLN(Com::tBLK, linesCount); + Com::printFLN(Com::tBLK, (int32_t)linesCount); } cur = NULL; #if CPU_ARCH==ARCH_ARM @@ -1885,20 +1861,12 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer // Copy across movement into main direction flags so that endstops function correctly cur->dir |= curd->dir; // Initialize bresenham for the first segment - if (cur->isFullstepping()) - { - cur->error[X_AXIS] = cur->error[Y_AXIS] = cur->error[Z_AXIS] = cur->numPrimaryStepPerSegment >> 1; - curd_errupd = cur->numPrimaryStepPerSegment; - } - else - { - cur->error[X_AXIS] = cur->error[Y_AXIS] = cur->error[Z_AXIS] = cur->numPrimaryStepPerSegment; - curd_errupd = cur->numPrimaryStepPerSegment = cur->numPrimaryStepPerSegment << 1; - } + cur->error[X_AXIS] = cur->error[Y_AXIS] = cur->error[Z_AXIS] = cur->numPrimaryStepPerSegment >> 1; + curd_errupd = cur->numPrimaryStepPerSegment; stepsPerSegRemaining = cur->numPrimaryStepPerSegment; } else curd = NULL; - cur_errupd = (cur->isFullstepping() ? cur->stepsRemaining : cur->stepsRemaining << 1); + cur_errupd = cur->stepsRemaining; if(!cur->areParameterUpToDate()) // should never happen, but with bad timings??? { @@ -1928,262 +1896,228 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer #endif cur->updateAdvanceSteps(cur->vStart, 0, false); #endif - if(Printer::wasLastHalfstepping && cur->isFullstepping()) // Switch halfstepping -> full stepping - { - Printer::wasLastHalfstepping = 0; - return Printer::interval + Printer::interval + Printer::interval; // Wait an other 150% from last half step to make the 100% full - } - else if(!Printer::wasLastHalfstepping && !cur->isFullstepping()) // Switch full to half stepping - { - Printer::wasLastHalfstepping = 1; - } - else - return Printer::interval; // Wait an other 50% from last step to make the 100% full + return Printer::interval; // Wait an other 50% from last step to make the 100% full } // End cur=0 HAL::allowInterrupts(); - /* For halfstepping, we divide the actions into even and odd actions to split - time used per loop. */ - flag8_t doEven = cur->halfStep & 6; - flag8_t doOdd = cur->halfStep & 5; - if(cur->halfStep != 4) cur->halfStep = 3 - (cur->halfStep); - if(doEven && curd != NULL) + if(curd != NULL) { curd->checkEndstops(cur,(cur->isCheckEndstops())); } int maxLoops = (Printer::stepsPerTimerCall <= cur->stepsRemaining ? Printer::stepsPerTimerCall : cur->stepsRemaining); HAL::forbidInterrupts(); - if(cur->stepsRemaining > 0) + for(int loop = 0; loop < maxLoops; loop++) { - for(int loop = 0; loop 0) - HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY); + if(loop > 0) + HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY); #endif - if(cur->isEMove()) - { - if((cur->error[E_AXIS] -= cur->delta[E_AXIS]) < 0) - { + if((cur->error[E_AXIS] -= cur->delta[E_AXIS]) < 0) + { #if USE_ADVANCE - if(Printer::isAdvanceActivated()) // Use interrupt for movement - { - if(cur->isEPositiveMove()) - Printer::extruderStepsNeeded++; - else - Printer::extruderStepsNeeded--; - } - else -#endif - Extruder::step(); - cur->error[E_AXIS] += cur_errupd; - } - } - if (curd) + if(Printer::isAdvanceActivated()) // Use interrupt for movement { - // Take delta steps - if(curd->isXMove()) + if(cur->isEPositiveMove()) + Printer::extruderStepsNeeded++; + else + Printer::extruderStepsNeeded--; + } + else +#endif + Extruder::step(); + cur->error[E_AXIS] += cur_errupd; + } + if (curd) + { + // Take delta steps + if(cur->isXMove()) + if((cur->error[X_AXIS] -= curd->deltaSteps[A_TOWER]) < 0) { - if((cur->error[X_AXIS] -= curd->deltaSteps[A_TOWER]) < 0) - { - cur->startXStep(); - cur->error[X_AXIS] += curd_errupd; + cur->startXStep(); + cur->error[X_AXIS] += curd_errupd; #ifdef DEBUG_REAL_POSITION - Printer::realDeltaPositionSteps[A_TOWER] += curd->isXPositiveMove() ? 1 : -1; + Printer::realDeltaPositionSteps[A_TOWER] += curd->isXPositiveMove() ? 1 : -1; #endif #ifdef DEBUG_STEPCOUNT - cur->totalStepsRemaining--; + cur->totalStepsRemaining--; #endif - } } - if(curd->isYMove()) + if(cur->isYMove()) + if((cur->error[Y_AXIS] -= curd->deltaSteps[B_TOWER]) < 0) { - if((cur->error[Y_AXIS] -= curd->deltaSteps[B_TOWER]) < 0) - { - cur->startYStep(); - cur->error[Y_AXIS] += curd_errupd; + cur->startYStep(); + cur->error[Y_AXIS] += curd_errupd; #ifdef DEBUG_REAL_POSITION - Printer::realDeltaPositionSteps[B_TOWER] += curd->isYPositiveMove() ? 1 : -1; + Printer::realDeltaPositionSteps[B_TOWER] += curd->isYPositiveMove() ? 1 : -1; #endif #ifdef DEBUG_STEPCOUNT - cur->totalStepsRemaining--; + cur->totalStepsRemaining--; #endif - } } - if(curd->isZMove()) + if(cur->isZMove()) + if((cur->error[Z_AXIS] -= curd->deltaSteps[C_TOWER]) < 0) { - if((cur->error[Z_AXIS] -= curd->deltaSteps[C_TOWER]) < 0) - { - cur->startZStep(); - cur->error[Z_AXIS] += curd_errupd; - Printer::realDeltaPositionSteps[C_TOWER] += curd->isZPositiveMove() ? 1 : -1; + cur->startZStep(); + cur->error[Z_AXIS] += curd_errupd; + Printer::realDeltaPositionSteps[C_TOWER] += curd->isZPositiveMove() ? 1 : -1; #ifdef DEBUG_STEPCOUNT - cur->totalStepsRemaining--; + cur->totalStepsRemaining--; #endif - } } - stepsPerSegRemaining--; - if (!stepsPerSegRemaining) + stepsPerSegRemaining--; + if (!stepsPerSegRemaining) + { + if (cur->numDeltaSegments) { - if (cur->numDeltaSegments) - { - // Get the next delta segment - curd = &cur->segments[--cur->numDeltaSegments]; + // Get the next delta segment + curd = &cur->segments[--cur->numDeltaSegments]; - // Initialize bresenham for this segment (numPrimaryStepPerSegment is already correct for the half step setting) - cur->error[X_AXIS] = cur->error[Y_AXIS] = cur->error[Z_AXIS] = cur->numPrimaryStepPerSegment >> 1; + // Initialize bresenham for this segment (numPrimaryStepPerSegment is already correct for the half step setting) + cur->error[X_AXIS] = cur->error[Y_AXIS] = cur->error[Z_AXIS] = cur->numPrimaryStepPerSegment >> 1; - // Reset the counter of the primary steps. This is initialized in the line - // generation so don't have to do this the first time. - stepsPerSegRemaining = cur->numPrimaryStepPerSegment; + // Reset the counter of the primary steps. This is initialized in the line + // generation so don't have to do this the first time. + stepsPerSegRemaining = cur->numPrimaryStepPerSegment; - // Change direction if necessary - Printer::setXDirection(curd->dir & X_DIRPOS); - Printer::setYDirection(curd->dir & Y_DIRPOS); - Printer::setZDirection(curd->dir & Z_DIRPOS); + // Change direction if necessary + Printer::setXDirection(curd->dir & X_DIRPOS); + Printer::setYDirection(curd->dir & Y_DIRPOS); + Printer::setZDirection(curd->dir & Z_DIRPOS); #if defined(DIRECTION_DELAY) && DIRECTION_DELAY > 0 - HAL::delayMicroseconds(DIRECTION_DELAY); + HAL::delayMicroseconds(DIRECTION_DELAY); #endif - if(FEATURE_BABYSTEPPING && Printer::zBabystepsMissing && curd - && (curd->dir & XYZ_STEP) == XYZ_STEP) + if(FEATURE_BABYSTEPPING && Printer::zBabystepsMissing && curd + && (curd->dir & XYZ_STEP) == XYZ_STEP) + { + // execute a extra babystep + Printer::insertStepperHighDelay(); + Printer::endXYZSteps(); + HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY+1); + + if(Printer::zBabystepsMissing > 0) { - // execute a extra babystep - Printer::insertStepperHighDelay(); - Printer::endXYZSteps(); - HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY+1); - - if(Printer::zBabystepsMissing > 0) - { - if(curd->dir & X_DIRPOS) - cur->startXStep(); - else - cur->error[X_AXIS] += curd_errupd; - if(curd->dir & Y_DIRPOS) - cur->startYStep(); - else - cur->error[Y_AXIS] += curd_errupd; - if(curd->dir & Z_DIRPOS) - cur->startZStep(); - else - cur->error[Z_AXIS] += curd_errupd; - Printer::zBabystepsMissing--; - } + if(curd->dir & X_DIRPOS) + cur->startXStep(); else - { - if(curd->dir & X_DIRPOS) - cur->error[X_AXIS] += curd_errupd; - else - cur->startXStep(); - if(curd->dir & Y_DIRPOS) - cur->error[Y_AXIS] += curd_errupd; - else - cur->startYStep(); - if(curd->dir & Z_DIRPOS) - cur->error[Z_AXIS] += curd_errupd; - else - cur->startZStep(); - Printer::zBabystepsMissing++; - } - HAL::delayMicroseconds(1); + cur->error[X_AXIS] += curd_errupd; + if(curd->dir & Y_DIRPOS) + cur->startYStep(); + else + cur->error[Y_AXIS] += curd_errupd; + if(curd->dir & Z_DIRPOS) + cur->startZStep(); + else + cur->error[Z_AXIS] += curd_errupd; + Printer::zBabystepsMissing--; } + else + { + if(curd->dir & X_DIRPOS) + cur->error[X_AXIS] += curd_errupd; + else + cur->startXStep(); + if(curd->dir & Y_DIRPOS) + cur->error[Y_AXIS] += curd_errupd; + else + cur->startYStep(); + if(curd->dir & Z_DIRPOS) + cur->error[Z_AXIS] += curd_errupd; + else + cur->startZStep(); + Printer::zBabystepsMissing++; + } + HAL::delayMicroseconds(1); } - else - curd = 0;// Release the last segment - //deltaSegmentCount--; } + else + curd = 0;// Release the last segment + //deltaSegmentCount--; } + } #if CPU_ARCH != ARCH_AVR - if(loop < maxLoops-1) - { + if(loop < maxLoops - 1) + { #endif - Printer::insertStepperHighDelay(); - Printer::endXYZSteps(); + Printer::insertStepperHighDelay(); + Printer::endXYZSteps(); #if USE_ADVANCE - if(!Printer::isAdvanceActivated()) // Use interrupt for movement + if(!Printer::isAdvanceActivated()) // Use interrupt for movement #endif - Extruder::unstep(); + Extruder::unstep(); #if CPU_ARCH != ARCH_AVR - } + } #endif - } // for loop + } // for loop - if(doOdd) - { - HAL::allowInterrupts(); // Allow interrupts for other types, timer1 is still disabled + HAL::allowInterrupts(); // Allow interrupts for other types, timer1 is still disabled #if RAMP_ACCELERATION - //If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval - if (cur->moveAccelerating()) - { - Printer::vMaxReached = HAL::ComputeV(Printer::timer, cur->fAcceleration) + cur->vStart; - if(Printer::vMaxReached > cur->vMax) Printer::vMaxReached = cur->vMax; - speed_t v = Printer::updateStepsPerTimerCall(Printer::vMaxReached); - Printer::interval = HAL::CPUDivU2(v); - Printer::timer += Printer::interval; - cur->updateAdvanceSteps(Printer::vMaxReached, maxLoops, true); - } - else if (cur->moveDecelerating()) // time to slow down +//If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval + if (cur->moveAccelerating()) + { + Printer::vMaxReached = HAL::ComputeV(Printer::timer, cur->fAcceleration) + cur->vStart; + if(Printer::vMaxReached > cur->vMax) Printer::vMaxReached = cur->vMax; + speed_t v = Printer::updateStepsPerTimerCall(Printer::vMaxReached); + Printer::interval = HAL::CPUDivU2(v); + Printer::timer += Printer::interval; + cur->updateAdvanceSteps(Printer::vMaxReached, maxLoops, true); + Printer::stepNumber += maxLoops; // is only used by moveAccelerating + } + else if (cur->moveDecelerating()) // time to slow down + { + speed_t v = HAL::ComputeV(Printer::timer, cur->fAcceleration); + if (v > Printer::vMaxReached) // if deceleration goes too far it can become too large + v = cur->vEnd; + else + { + v = Printer::vMaxReached - v; + if (v < cur->vEnd) v = cur->vEnd; // extra steps at the end of desceleration due to rounding erros + } + cur->updateAdvanceSteps(v, maxLoops, false); + v = Printer::updateStepsPerTimerCall(v); + Printer::interval = HAL::CPUDivU2(v); + Printer::timer += Printer::interval; + } + else + { + // If we had acceleration, we need to use the latest vMaxReached and interval + // If we started full speed, we need to use cur->fullInterval and vMax + cur->updateAdvanceSteps((!cur->accelSteps ? cur->vMax : Printer::vMaxReached), 0, true); + if(!cur->accelSteps) + { + if(cur->vMax > STEP_DOUBLER_FREQUENCY) { - speed_t v = HAL::ComputeV(Printer::timer, cur->fAcceleration); - if (v > Printer::vMaxReached) // if deceleration goes too far it can become too large - v = cur->vEnd; +#if ALLOW_QUADSTEPPING + if(cur->vMax > STEP_DOUBLER_FREQUENCY * 2) + { + Printer::stepsPerTimerCall = 4; + Printer::interval = cur->fullInterval << 2; + } else { - v = Printer::vMaxReached - v; - if (vvEnd) v = cur->vEnd; // extra steps at the end of desceleration due to rounding erros + Printer::stepsPerTimerCall = 2; + Printer::interval = cur->fullInterval << 1; } - cur->updateAdvanceSteps(v, maxLoops, false); - v = Printer::updateStepsPerTimerCall(v); - Printer::interval = HAL::CPUDivU2(v); - Printer::timer += Printer::interval; +#else + Printer::stepsPerTimerCall = 2; + Printer::interval = cur->fullInterval << 1; +#endif } else { - // If we had acceleration, we need to use the latest vMaxReached and interval - // If we started full speed, we need to use cur->fullInterval and vMax - cur->updateAdvanceSteps((!cur->accelSteps ? cur->vMax : Printer::vMaxReached), 0, true); - if(!cur->accelSteps) - { - if(cur->vMax > STEP_DOUBLER_FREQUENCY) - { -#if ALLOW_QUADSTEPPING - if(cur->vMax > STEP_DOUBLER_FREQUENCY * 2) - { - Printer::stepsPerTimerCall = 4; - Printer::interval = cur->fullInterval << 2; - } - else - { - Printer::stepsPerTimerCall = 2; - Printer::interval = cur->fullInterval << 1; - } -#else - Printer::stepsPerTimerCall = 2; - Printer::interval = cur->fullInterval << 1; -#endif - } - else - { - Printer::stepsPerTimerCall = 1; - Printer::interval = cur->fullInterval; - } - } + Printer::stepsPerTimerCall = 1; + Printer::interval = cur->fullInterval; } + } + } #else - Printer::interval = cur->fullInterval; // without RAMPS always use full speed + Printer::interval = cur->fullInterval; // without RAMPS always use full speed #endif - } // doOdd - if(doEven) - { - Printer::stepNumber += maxLoops; - PrintLine::cur->stepsRemaining -= maxLoops; - } + PrintLine::cur->stepsRemaining -= maxLoops; - } // stepsRemaining - int32_t interval = (cur->isFullstepping() ? Printer::interval : Printer::interval >> 1); - if(doEven &&(cur->stepsRemaining <= 0 || cur->isNoMove())) // line finished + if(cur->stepsRemaining <= 0 || cur->isNoMove()) // line finished { // Release remaining delta segments #ifdef DEBUG_STEPCOUNT @@ -2192,7 +2126,6 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer Com::printFLN(PSTR("Missed steps:"), cur->totalStepsRemaining); Com::printFLN(PSTR("Step/seg r:"), stepsPerSegRemaining); Com::printFLN(PSTR("NDS:"), (int) cur->numDeltaSegments); - Com::printFLN(PSTR("HS:"), (int) cur->halfStep); } #endif //HAL::forbidInterrupts(); @@ -2200,7 +2133,7 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer removeCurrentLineForbidInterrupt(); Printer::disableAllowedStepper(); if(linesCount == 0) UI_STATUS(UI_TEXT_IDLE); - interval = Printer::interval = interval >> 1; // 50% of time to next call to do cur=0 + Printer::interval >>= 1; // 50% of time to next call to do cur=0 DEBUG_MEMORY; } // Do even #if CPU_ARCH != ARCH_AVR @@ -2211,7 +2144,7 @@ int32_t PrintLine::bresenhamStep() // Version for delta printer #endif Extruder::unstep(); #endif - return interval; + return Printer::interval; } #else /** @@ -2297,7 +2230,7 @@ int32_t PrintLine::bresenhamStep() // version for cartesian printer if(cur->isEMove()) Extruder::enable(); cur->fixStartAndEndSpeed(); HAL::allowInterrupts(); - cur_errupd = (cur->isFullstepping() ? cur->delta[cur->primaryAxis] : cur->delta[cur->primaryAxis]<<1);; + cur_errupd = cur->delta[cur->primaryAxis]; if(!cur->areParameterUpToDate()) // should never happen, but with bad timings??? { cur->updateStepsParameter(); @@ -2346,173 +2279,135 @@ int32_t PrintLine::bresenhamStep() // version for cartesian printer #endif cur->updateAdvanceSteps(cur->vStart, 0, false); #endif - if(Printer::wasLastHalfstepping && cur->isFullstepping()) // Switch halfstepping -> full stepping - { - Printer::wasLastHalfstepping = 0; - return Printer::interval+Printer::interval+Printer::interval; // Wait an other 150% from last half step to make the 100% full - } - else if(!Printer::wasLastHalfstepping && !cur->isFullstepping()) // Switch full to half stepping - { - Printer::wasLastHalfstepping = 1; - } - else - return Printer::interval; // Wait an other 50% from last step to make the 100% full + return Printer::interval; // Wait an other 50% from last step to make the 100% full } // End cur=0 - HAL::allowInterrupts(); - /* For halfstepping, we divide the actions into even and odd actions to split - time used per loop. */ - uint8_t doEven = cur->halfStep & 6; - uint8_t doOdd = cur->halfStep & 5; - if(cur->halfStep != 4) cur->halfStep = 3 - (cur->halfStep); - HAL::forbidInterrupts(); - if(doEven) cur->checkEndstops(); - uint8_t max_loops = RMath::min((long)Printer::stepsPerTimerCall,cur->stepsRemaining); - if(cur->stepsRemaining > 0) + cur->checkEndstops(); + fast8_t max_loops = RMath::min((int32_t)Printer::stepsPerTimerCall,cur->stepsRemaining); + for(fast8_t loop = 0; loop < max_loops; loop++) { - for(uint8_t loop = 0; loop < max_loops; loop++) - { #if STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY > 0 - if(loop > 0) - HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY); + if(loop > 0) + HAL::delayMicroseconds(STEPPER_HIGH_DELAY + DOUBLE_STEP_DELAY); #endif - if(cur->isEMove()) - { - if((cur->error[E_AXIS] -= cur->delta[E_AXIS]) < 0) - { + if((cur->error[E_AXIS] -= cur->delta[E_AXIS]) < 0) + { #if USE_ADVANCE - if(Printer::isAdvanceActivated()) // Use interrupt for movement - { - if(cur->isEPositiveMove()) - Printer::extruderStepsNeeded++; - else - Printer::extruderStepsNeeded--; - } - else -#endif - Extruder::step(); - cur->error[E_AXIS] += cur_errupd; - } + if(Printer::isAdvanceActivated()) // Use interrupt for movement + { + if(cur->isEPositiveMove()) + Printer::extruderStepsNeeded++; + else + Printer::extruderStepsNeeded--; } - if(cur->isXMove()) + else +#endif + Extruder::step(); + cur->error[E_AXIS] += cur_errupd; + } + if(cur->isXMove()) + if((cur->error[X_AXIS] -= cur->delta[X_AXIS]) < 0) { - if((cur->error[X_AXIS] -= cur->delta[X_AXIS]) < 0) - { - cur->startXStep(); - cur->error[X_AXIS] += cur_errupd; - } + cur->startXStep(); + cur->error[X_AXIS] += cur_errupd; } - if(cur->isYMove()) + if(cur->isYMove()) + if((cur->error[Y_AXIS] -= cur->delta[Y_AXIS]) < 0) { - if((cur->error[Y_AXIS] -= cur->delta[Y_AXIS]) < 0) - { - cur->startYStep(); - cur->error[Y_AXIS] += cur_errupd; - } + cur->startYStep(); + cur->error[Y_AXIS] += cur_errupd; } - if(cur->isZMove()) + if(cur->isZMove()) + if((cur->error[Z_AXIS] -= cur->delta[Z_AXIS]) < 0) { - if((cur->error[Z_AXIS] -= cur->delta[Z_AXIS]) < 0) - { - cur->startZStep(); - cur->error[Z_AXIS] += cur_errupd; + cur->startZStep(); + cur->error[Z_AXIS] += cur_errupd; #ifdef DEBUG_STEPCOUNT - cur->totalStepsRemaining--; + cur->totalStepsRemaining--; #endif - } } #if (GANTRY) #if DRIVE_SYSTEM == XY_GANTRY || DRIVE_SYSTEM == YX_GANTRY - Printer::executeXYGantrySteps(); + Printer::executeXYGantrySteps(); #else - Printer::executeXZGantrySteps(); + Printer::executeXZGantrySteps(); #endif #endif - Printer::insertStepperHighDelay(); + Printer::insertStepperHighDelay(); #if USE_ADVANCE - if(!Printer::isAdvanceActivated()) // Use interrupt for movement + if(!Printer::isAdvanceActivated()) // Use interrupt for movement #endif - Extruder::unstep(); - Printer::endXYZSteps(); - } // for loop - if(doOdd) // Update timings - { - HAL::allowInterrupts(); // Allow interrupts for other types, timer1 is still disabled + Extruder::unstep(); + Printer::endXYZSteps(); + } // for loop + HAL::allowInterrupts(); // Allow interrupts for other types, timer1 is still disabled #if RAMP_ACCELERATION - //If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval - if (cur->moveAccelerating()) // we are accelerating + //If acceleration is enabled on this move and we are in the acceleration segment, calculate the current interval + if (cur->moveAccelerating()) // we are accelerating + { + Printer::vMaxReached = HAL::ComputeV(Printer::timer,cur->fAcceleration) + cur->vStart; + if(Printer::vMaxReached > cur->vMax) Printer::vMaxReached = cur->vMax; + unsigned int v = Printer::updateStepsPerTimerCall(Printer::vMaxReached); + Printer::interval = HAL::CPUDivU2(v); + Printer::timer += Printer::interval; + cur->updateAdvanceSteps(Printer::vMaxReached, max_loops, true); + Printer::stepNumber += max_loops; // only used for moveAccelerating + } + else if (cur->moveDecelerating()) // time to slow down + { + unsigned int v = HAL::ComputeV(Printer::timer,cur->fAcceleration); + if (v > Printer::vMaxReached) // if deceleration goes too far it can become too large + v = cur->vEnd; + else + { + v = Printer::vMaxReached - v; + if (vvEnd) v = cur->vEnd; // extra steps at the end of desceleration due to rounding erros + } + cur->updateAdvanceSteps(v,max_loops,false); // needs original v + v = Printer::updateStepsPerTimerCall(v); + Printer::interval = HAL::CPUDivU2(v); + Printer::timer += Printer::interval; + } + else // full speed reached + { + cur->updateAdvanceSteps((!cur->accelSteps ? cur->vMax : Printer::vMaxReached), 0, true); + // constant speed reached + if(cur->vMax > STEP_DOUBLER_FREQUENCY) + { +#if ALLOW_QUADSTEPPING + if(cur->vMax > STEP_DOUBLER_FREQUENCY * 2) { - Printer::vMaxReached = HAL::ComputeV(Printer::timer,cur->fAcceleration)+cur->vStart; - if(Printer::vMaxReached>cur->vMax) Printer::vMaxReached = cur->vMax; - unsigned int v = Printer::updateStepsPerTimerCall(Printer::vMaxReached); - Printer::interval = HAL::CPUDivU2(v); - Printer::timer+=Printer::interval; - cur->updateAdvanceSteps(Printer::vMaxReached,max_loops,true); + Printer::stepsPerTimerCall = 4; + Printer::interval = cur->fullInterval << 2; } - else if (cur->moveDecelerating()) // time to slow down + else { - unsigned int v = HAL::ComputeV(Printer::timer,cur->fAcceleration); - if (v > Printer::vMaxReached) // if deceleration goes too far it can become too large - v = cur->vEnd; - else - { - v=Printer::vMaxReached - v; - if (vvEnd) v = cur->vEnd; // extra steps at the end of desceleration due to rounding erros - } - cur->updateAdvanceSteps(v,max_loops,false); // needs original v - v = Printer::updateStepsPerTimerCall(v); - Printer::interval = HAL::CPUDivU2(v); - Printer::timer += Printer::interval; + Printer::stepsPerTimerCall = 2; + Printer::interval = cur->fullInterval << 1; } - else // full speed reached - { - cur->updateAdvanceSteps((!cur->accelSteps ? cur->vMax : Printer::vMaxReached),0,true); - // constant speed reached - if(cur->vMax>STEP_DOUBLER_FREQUENCY) - { -#if ALLOW_QUADSTEPPING - if(cur->vMax>STEP_DOUBLER_FREQUENCY*2) - { - Printer::stepsPerTimerCall = 4; - Printer::interval = cur->fullInterval << 2; - } - else - { - Printer::stepsPerTimerCall = 2; - Printer::interval = cur->fullInterval << 1; - } #else - Printer::stepsPerTimerCall = 2; - Printer::interval = cur->fullInterval << 1; + Printer::stepsPerTimerCall = 2; + Printer::interval = cur->fullInterval << 1; #endif - } - else - { - Printer::stepsPerTimerCall = 1; - Printer::interval = cur->fullInterval; - } - } -#else - Printer::stepsPerTimerCall = 1; - Printer::interval = cur->fullInterval; // without RAMPS always use full speed -#endif // RAMP_ACCELERATION - } // doOdd - if(doEven) + } + else { - Printer::stepNumber += max_loops; - cur->stepsRemaining -= max_loops; + Printer::stepsPerTimerCall = 1; + Printer::interval = cur->fullInterval; } - - } // stepsRemaining - long interval; - if(!cur->isFullstepping()) interval = (Printer::interval>>1); // time to come back - else interval = Printer::interval; - if(doEven && (cur->stepsRemaining <= 0 || cur->isNoMove())) // line finished + } +#else + Printer::stepsPerTimerCall = 1; + Printer::interval = cur->fullInterval; // without RAMPS always use full speed +#endif // RAMP_ACCELERATION + cur->stepsRemaining -= max_loops; + long interval = Printer::interval; + if(cur->stepsRemaining <= 0 || cur->isNoMove()) // line finished { #ifdef DEBUG_STEPCOUNT if(cur->totalStepsRemaining) { - Com::printF(Com::tDBGMissedSteps,cur->totalStepsRemaining); - Com::printFLN(Com::tComma,cur->stepsRemaining); + Com::printF(Com::tDBGMissedSteps, cur->totalStepsRemaining); + Com::printFLN(Com::tComma, cur->stepsRemaining); } #endif removeCurrentLineForbidInterrupt(); diff --git a/src/ArduinoDUE/Repetier/motion.h b/src/ArduinoDUE/Repetier/motion.h index 5ee8e494e..97032dcae 100644 --- a/src/ArduinoDUE/Repetier/motion.h +++ b/src/ArduinoDUE/Repetier/motion.h @@ -136,7 +136,7 @@ typedef struct } inline bool isNoMove() { - return (dir & XYZE_STEP)==0; + return (dir & XYZE_STEP) == 0; } inline bool isXYZMove() { @@ -148,15 +148,15 @@ typedef struct } inline void setMoveOfAxis(uint8_t axis) { - dir |= XSTEP<= PRINTLINE_CACHE_SIZE) linesPos=0; + if(linesPos >= PRINTLINE_CACHE_SIZE) linesPos = 0; cur = NULL; -#if CPU_ARCH==ARCH_ARM +#if CPU_ARCH == ARCH_ARM nlFlag = false; #endif HAL::forbidInterrupts(); @@ -691,7 +684,7 @@ class PrintLine // RAM usage: 24*4+15 = 113 Byte static uint8_t queueDeltaMove(uint8_t check_endstops,uint8_t pathOptimize, uint8_t softEndstop); static inline void queueEMove(int32_t e_diff,uint8_t check_endstops,uint8_t pathOptimize); inline uint16_t calculateDeltaSubSegments(uint8_t softEndstop); - static inline void calculateDirectionAndDelta(int32_t difference[], flag8_t *dir, int32_t delta[]); + static inline void calculateDirectionAndDelta(int32_t difference[], ufast8_t *dir, int32_t delta[]); static inline uint8_t calculateDistance(float axis_diff[], uint8_t dir, float *distance); #if SOFTWARE_LEVELING && DRIVE_SYSTEM == DELTA static void calculatePlane(int32_t factors[], int32_t p1[], int32_t p2[], int32_t p3[]); diff --git a/src/ArduinoDUE/Repetier/ui.cpp b/src/ArduinoDUE/Repetier/ui.cpp index d72b7086d..5c884d026 100644 --- a/src/ArduinoDUE/Repetier/ui.cpp +++ b/src/ArduinoDUE/Repetier/ui.cpp @@ -453,6 +453,52 @@ void lcdWriteByte(uint8_t c,uint8_t rs) HAL::delayMicroseconds(100); } +#ifdef TRY_AUTOREPAIR_LCD_ERRORS +#define HAS_AUTOREPAIR +/* Fast repair function for displays loosing their settings. + Do not call this if your display has no problems. +*/ +void repairLCD() { + // Now we pull both RS and R/W low to begin commands + WRITE(UI_DISPLAY_RS_PIN, LOW); + WRITE(UI_DISPLAY_ENABLE_PIN, LOW); + + //put the LCD into 4 bit mode + // this is according to the hitachi HD44780 datasheet + // figure 24, pg 46 + + // we start in 8bit mode, try to set 4 bit mode + // at this point we are in 8 bit mode but of course in this + // interface 4 pins are dangling unconnected and the values + // on them don't matter for these instructions. + WRITE(UI_DISPLAY_RS_PIN, LOW); + HAL::delayMicroseconds(20); + lcdWriteNibble(0x03); + HAL::delayMicroseconds(5000); // I have one LCD for which 4500 here was not long enough. + // second try + //lcdWriteNibble(0x03); + //HAL::delayMicroseconds(5000); // wait + // third go! + //lcdWriteNibble(0x03); + //HAL::delayMicroseconds(160); + // finally, set to 4-bit interface + lcdWriteNibble(0x02); + HAL::delayMicroseconds(160); + // finally, set # lines, font size, etc. + lcdCommand(LCD_4BIT | LCD_2LINE | LCD_5X7); + lcdCommand(LCD_INCREASE | LCD_DISPLAYSHIFTOFF); //- Entrymode (Display Shift: off, Increment Address Counter) + lcdCommand(LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKINGOFF); //- Display on + uid.lastSwitch = uid.lastRefresh = HAL::timeInMilliseconds(); + uid.createChar(1, character_back); + uid.createChar(2, character_degree); + uid.createChar(3, character_selected); + uid.createChar(4, character_unselected); + uid.createChar(5, character_temperature); + uid.createChar(6, character_folder); + uid.createChar(7, character_ready); +} +#endif + void initializeLCD() { // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! @@ -3133,6 +3179,7 @@ int UIDisplay::executeAction(int action, bool allowMoves) #if FEATURE_RETRACTION case UI_ACTION_WIZARD_FILAMENTCHANGE: { + if(Printer::isBlockingReceive()) break; Printer::setJamcontrolDisabled(true); Com::printFLN(PSTR("important: Filament change required!")); Printer::setBlockingReceive(true); @@ -3487,6 +3534,14 @@ void UIDisplay::slowAction(bool allowMoves) } if(refresh) // does lcd need a refresh? { +#if defined(TRY_AUTOREPAIR_LCD_ERRORS) +#if defined(HAS_AUTOREPAIR) + repairLCD(); +#else + #error TRY_AUTOREPAIR_LCD_ERRORS is not supported for your display type! +#endif +#endif + if (menuLevel > 1 || Printer::isAutomount()) { shift++; diff --git a/src/ArduinoDUE/Repetier/ui.h b/src/ArduinoDUE/Repetier/ui.h index 722703440..870cd6864 100644 --- a/src/ArduinoDUE/Repetier/ui.h +++ b/src/ArduinoDUE/Repetier/ui.h @@ -1453,7 +1453,7 @@ void uiCheckSlowKeys(int &action) {} #endif #define UI_INITIALIZE uid.initialize(); -#define UI_FAST if(pwm_count & 4) {uid.fastAction();} +#define UI_FAST if((counterPeriodical & 3) == 3) {uid.fastAction();} #define UI_MEDIUM uid.mediumAction(); #define UI_SLOW(allowMoves) uid.slowAction(allowMoves); #define UI_STATUS(status) uid.setStatusP(PSTR(status));