diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 0dde53ace9cc..7ae787287053 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -44,30 +44,29 @@ //=========================================================================== /** - * Here are some standard links for getting your machine calibrated: + * Here are some useful links to help get your machine configured and calibrated: * - * https://reprap.org/wiki/Calibration - * https://youtu.be/wAL9d7FgInk - * http://calculator.josefprusa.cz - * https://reprap.org/wiki/Triffid_Hunter%27s_Calibration_Guide - * https://www.thingiverse.com/thing:5573 - * https://sites.google.com/site/repraplogphase/calibration-of-your-reprap - * https://www.thingiverse.com/thing:298812 + * Example Configs: https://github.com/MarlinFirmware/Configurations/branches/all + * + * Průša Calculator: https://blog.prusaprinters.org/calculator_3416/ + * + * Calibration Guides: https://reprap.org/wiki/Calibration + * https://reprap.org/wiki/Triffid_Hunter%27s_Calibration_Guide + * https://sites.google.com/site/repraplogphase/calibration-of-your-reprap + * https://youtu.be/wAL9d7FgInk + * + * Calibration Objects: https://www.thingiverse.com/thing:5573 + * https://www.thingiverse.com/thing:1278865 */ //=========================================================================== -//============================= DELTA Printer =============================== +//========================== DELTA / SCARA / TPARA ========================== //=========================================================================== -// For a Delta printer, start with one of the configuration files in the config/examples/delta directory -// from https://github.com/MarlinFirmware/Configurations/branches/all and customize for your machine. // - -//=========================================================================== -//============================= SCARA Printer =============================== -//=========================================================================== -// For a SCARA printer, start with one of the configuration files in the config/examples/SCARA directory -// from https://github.com/MarlinFirmware/Configurations/branches/all and customize for your machine. +// Download configurations from the link above and customize for your machine. +// Examples are located in config/examples/delta, .../SCARA, and .../TPARA. // +//=========================================================================== // @section info @@ -166,8 +165,8 @@ * PRUSA_MMU1 : Průša MMU1 (The "multiplexer" version) * PRUSA_MMU2 : Průša MMU2 * PRUSA_MMU2S : Průša MMU2S (Requires MK3S extruder with motion sensor, EXTRUDERS = 5) - * SMUFF_EMU_MMU2 : Technik Gegg SMUFF (Průša MMU2 emulation mode) - * SMUFF_EMU_MMU2S : Technik Gegg SMUFF (Průša MMU2S emulation mode) + * SMUFF_EMU_MMU2 : Technik Gegg SMuFF (Průša MMU2 emulation mode) + * SMUFF_EMU_MMU2S : Technik Gegg SMuFF (Průša MMU2S emulation mode) * * Requires NOZZLE_PARK_FEATURE to park print head in case MMU unit fails. * See additional options in Configuration_adv.h. @@ -445,6 +444,10 @@ #define TEMP_BED_WINDOW 1 // (°C) Temperature proximity for the "temperature reached" timer #define TEMP_BED_HYSTERESIS 3 // (°C) Temperature proximity considered "close enough" to the target +#define TEMP_CHAMBER_RESIDENCY_TIME 10 // (seconds) Time to wait for chamber to "settle" in M191 +#define TEMP_CHAMBER_WINDOW 1 // (°C) Temperature proximity for the "temperature reached" timer +#define TEMP_CHAMBER_HYSTERESIS 3 // (°C) Temperature proximity considered "close enough" to the target + // Below this temperature the heater will be switched off // because it probably indicates a broken thermistor wire. #define HEATER_0_MINTEMP 5 @@ -456,6 +459,7 @@ #define HEATER_6_MINTEMP 5 #define HEATER_7_MINTEMP 5 #define BED_MINTEMP 5 +#define CHAMBER_MINTEMP 5 // Above this temperature the heater will be switched off. // This can protect components from overheating, but NOT from shorts and failures. @@ -469,6 +473,7 @@ #define HEATER_6_MAXTEMP 275 #define HEATER_7_MAXTEMP 275 #define BED_MAXTEMP 125 +#define CHAMBER_MAXTEMP 60 //=========================================================================== //============================= PID Settings ================================ @@ -541,7 +546,51 @@ // FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles. #endif // PIDTEMPBED -#if EITHER(PIDTEMP, PIDTEMPBED) +//=========================================================================== +//==================== PID > Chamber Temperature Control ==================== +//=========================================================================== + +/** + * PID Chamber Heating + * + * If this option is enabled set PID constants below. + * If this option is disabled, bang-bang will be used and CHAMBER_LIMIT_SWITCHING will enable + * hysteresis. + * + * The PID frequency will be the same as the extruder PWM. + * If PID_dT is the default, and correct for the hardware/configuration, that means 7.689Hz, + * which is fine for driving a square wave into a resistive load and does not significantly + * impact FET heating. This also works fine on a Fotek SSR-10DA Solid State Relay into a 200W + * heater. If your configuration is significantly different than this and you don't understand + * the issues involved, don't use chamber PID until someone else verifies that your hardware works. + */ +//#define PIDTEMPCHAMBER +//#define CHAMBER_LIMIT_SWITCHING + +/** + * Max Chamber Power + * Applies to all forms of chamber control (PID, bang-bang, and bang-bang with hysteresis). + * When set to any value below 255, enables a form of PWM to the chamber heater that acts like a divider + * so don't use it unless you are OK with PWM on your heater. (See the comment on enabling PIDTEMPCHAMBER) + */ +#define MAX_CHAMBER_POWER 255 // limits duty cycle to chamber heater; 255=full current + +#if ENABLED(PIDTEMPCHAMBER) + #define MIN_CHAMBER_POWER 0 + //#define PID_CHAMBER_DEBUG // Sends debug data to the serial port. + + // Lasko "MyHeat Personal Heater" (200w) modified with a Fotek SSR-10DA to control only the heating element + // and placed inside the small Creality printer enclosure tent. + // + #define DEFAULT_chamberKp 37.04 + #define DEFAULT_chamberKi 1.40 + #define DEFAULT_chamberKd 655.17 + // M309 P37.04 I1.04 D655.17 + + // FIND YOUR OWN: "M303 E-2 C8 S50" to run autotune on the chamber at 50 degreesC for 8 cycles. +#endif // PIDTEMPCHAMBER + +#if ANY(PIDTEMP, PIDTEMPBED, PIDTEMPCHAMBER) //#define PID_DEBUG // Sends debug data to the serial port. Use 'M303 D' to toggle activation. //#define PID_OPENLOOP // Puts PID in open loop. M104/M140 sets the output power from 0 to PID_MAX //#define SLOW_PWM_HEATERS // PWM with very low frequency (roughly 0.125Hz=8s) and minimum state time of approximately 1s useful for heaters driven by a relay @@ -1000,13 +1049,13 @@ #define PROBING_MARGIN 10 // X and Y axis travel speed (mm/min) between probes -#define XY_PROBE_SPEED (133*60) +#define XY_PROBE_FEEDRATE (133*60) // Feedrate (mm/min) for the first approach when double-probing (MULTIPLE_PROBING == 2) -#define Z_PROBE_SPEED_FAST (4*60) +#define Z_PROBE_FEEDRATE_FAST (4*60) // Feedrate (mm/min) for the "accurate" probe of each point -#define Z_PROBE_SPEED_SLOW (Z_PROBE_SPEED_FAST / 2) +#define Z_PROBE_FEEDRATE_SLOW (Z_PROBE_FEEDRATE_FAST / 2) /** * Probe Activation Switch @@ -1091,7 +1140,7 @@ //#define PROBING_HEATERS_OFF // Turn heaters off when probing #if ENABLED(PROBING_HEATERS_OFF) //#define WAIT_FOR_BED_HEATER // Wait for bed to heat back up between probes (to improve accuracy) - //#define WAIT_FOR_HOTEND // Wait for hotend to heat back up between probes (to improve accuracy & prevent undertemp extrudes) + //#define WAIT_FOR_HOTEND // Wait for hotend to heat back up between probes (to improve accuracy & prevent cold extrude) #endif //#define PROBING_FANS_OFF // Turn fans off when probing //#define PROBING_STEPPERS_OFF // Turn steppers off (unless needed to hold position) when probing @@ -1148,7 +1197,13 @@ //#define NO_MOTION_BEFORE_HOMING // Inhibit movement until all axes have been homed. Also enable HOME_AFTER_DEACTIVATE for extra safety. //#define HOME_AFTER_DEACTIVATE // Require rehoming after steppers are deactivated. Also enable NO_MOTION_BEFORE_HOMING for extra safety. -//#define UNKNOWN_Z_NO_RAISE // Don't raise Z (lower the bed) if Z is "unknown." For beds that fall when Z is powered off. + +/** + * Set Z_IDLE_HEIGHT if the Z-Axis moves on its own when steppers are disabled. + * - Use a low value (i.e., Z_MIN_POS) if the nozzle falls down to the bed. + * - Use a large value (i.e., Z_MAX_POS) if the bed falls down, away from the nozzle. + */ +//#define Z_IDLE_HEIGHT Z_HOME_POS //#define Z_HOMING_HEIGHT 4 // (mm) Minimal Z height before homing (G28) for Z clearance above the bed, clamps, ... // Be sure to have this much clearance over your Z_MAX_POS to prevent grinding. @@ -1225,6 +1280,8 @@ #define FIL_RUNOUT_STATE HIGH // Pin state indicating that filament is NOT present. #define FIL_RUNOUT_PULLUP // Use internal pullup for filament runout pins. //#define FIL_RUNOUT_PULLDOWN // Use internal pulldown for filament runout pins. + //#define WATCH_ALL_RUNOUT_SENSORS // Execute runout script on any triggering sensor, not only for the active extruder. + // This is automatically enabled for MIXING_EXTRUDERs. // Override individually if the runout sensors vary #define FIL_RUNOUT1_STATE HIGH @@ -1259,9 +1316,10 @@ //#define FIL_RUNOUT8_PULLUP //#define FIL_RUNOUT8_PULLDOWN - // Set one or more commands to execute on filament runout. - // (After 'M412 H' Marlin will ask the host to handle the process.) - #define FILAMENT_RUNOUT_SCRIPT "M600" + // Commands to execute on filament runout. + // With multiple runout sensors use the %c placeholder for the current tool in commands (e.g., "M600 T%c") + // NOTE: After 'M412 H1' the host handles filament runout and this script does not apply. + #define FILAMENT_RUNOUT_SCRIPT "M600 T%c" // After a runout is detected, continue printing this length of filament // before executing the runout script. Useful for a sensor at the end of @@ -1957,6 +2015,14 @@ // //#define REPRAP_DISCOUNT_SMART_CONTROLLER +// +// GT2560 (YHCB2004) LCD Display +// +// Requires Testato, Koepel softwarewire library and +// Andriy Golovnya's LiquidCrystal_AIP31068 library. +// +//#define YHCB2004 + // // Original RADDS LCD Display+Encoder+SDCardReader // http://doku.radds.org/dokumentation/lcd-display/ @@ -2286,6 +2352,7 @@ //#define DGUS_LCD_UI_ORIGIN //#define DGUS_LCD_UI_FYSETC //#define DGUS_LCD_UI_HIPRECY +//#define DGUS_LCD_UI_MKS // // CR-6 OEM touch screen. A DWIN display with touch. diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index cf41511727c3..54c35c965f51 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -145,13 +145,17 @@ // // Heated Chamber options // +#if DISABLED(PIDTEMPCHAMBER) + #define CHAMBER_CHECK_INTERVAL 5000 // (ms) Interval between checks in bang-bang control + #if ENABLED(CHAMBER_LIMIT_SWITCHING) + #define CHAMBER_HYSTERESIS 2 // (°C) Only set the relevant heater state when ABS(T-target) > CHAMBER_HYSTERESIS + #endif +#endif + #if TEMP_SENSOR_CHAMBER - #define CHAMBER_MINTEMP 5 - #define CHAMBER_MAXTEMP 60 - #define TEMP_CHAMBER_HYSTERESIS 1 // (°C) Temperature proximity considered "close enough" to the target - //#define CHAMBER_LIMIT_SWITCHING - //#define HEATER_CHAMBER_PIN 44 // Chamber heater on/off pin + //#define HEATER_CHAMBER_PIN P2_04 // Required heater on/off pin (example: SKR 1.4 Turbo HE1 plug) //#define HEATER_CHAMBER_INVERTING false + //#define FAN1_PIN -1 // Remove the fan signal on pin P2_04 (example: SKR 1.4 Turbo HE1 plug) //#define CHAMBER_FAN // Enable a fan on the chamber #if ENABLED(CHAMBER_FAN) @@ -745,8 +749,8 @@ /** * Use "HIGH SPEED" mode for probing. * Danger: Disable if your probe sometimes fails. Only suitable for stable well-adjusted systems. - * This feature was designed for Delta's with very fast Z moves however higher speed cartesians may function - * If the machine cannot raise the probe fast enough after a trigger, it may enter a fault state. + * This feature was designed for Deltabots with very fast Z moves; however, higher speed Cartesians + * might be able to use it. If the machine can't raise Z fast enough the BLTouch may go into ALARM. */ //#define BLTOUCH_HS_MODE @@ -871,9 +875,6 @@ #define DISABLE_INACTIVE_Z true // Set 'false' if the nozzle could fall onto your printed part! #define DISABLE_INACTIVE_E true -// If the Nozzle or Bed falls when the Z stepper is disabled, set its resting position here. -//#define Z_AFTER_DEACTIVATE Z_HOME_POS - // Default Minimum Feedrates for printing and travel moves #define DEFAULT_MINIMUMFEEDRATE 0.0 // (mm/s) Minimum feedrate. Set with M205 S. #define DEFAULT_MINTRAVELFEEDRATE 0.0 // (mm/s) Minimum travel feedrate. Set with M205 T. @@ -932,7 +933,7 @@ // increments while checking for the contact to be broken. #define BACKLASH_MEASUREMENT_LIMIT 0.5 // (mm) #define BACKLASH_MEASUREMENT_RESOLUTION 0.005 // (mm) - #define BACKLASH_MEASUREMENT_FEEDRATE Z_PROBE_SPEED_SLOW // (mm/min) + #define BACKLASH_MEASUREMENT_FEEDRATE Z_PROBE_FEEDRATE_SLOW // (mm/min) #endif #endif #endif @@ -1152,6 +1153,9 @@ #endif #endif + // Insert a menu for preheating at the top level to allow for quick access + //#define PREHEAT_SHORTCUT_MENU_ITEM + #endif // HAS_LCD_MENU #if HAS_DISPLAY @@ -1256,7 +1260,6 @@ #if ENABLED(POWER_LOSS_RECOVERY) #define PLR_ENABLED_DEFAULT false // Power Loss Recovery enabled by default. (Set with 'M413 Sn' & M500) //#define BACKUP_POWER_SUPPLY // Backup power / UPS to move the steppers on power loss - //#define POWER_LOSS_RECOVER_ZHOME // Z homing is needed for proper recovery. 99.9% of the time this should be disabled! //#define POWER_LOSS_ZRAISE 2 // (mm) Z axis raise on resume (on power loss with UPS) //#define POWER_LOSS_PIN 44 // Pin to detect power loss. Set to -1 to disable default pin on boards without module. //#define POWER_LOSS_STATE HIGH // State of pin indicating power loss @@ -1268,6 +1271,12 @@ // Without a POWER_LOSS_PIN the following option helps reduce wear on the SD card, // especially with "vase mode" printing. Set too high and vases cannot be continued. #define POWER_LOSS_MIN_Z_CHANGE 0.05 // (mm) Minimum Z change before saving power-loss data + + // Enable if Z homing is needed for proper recovery. 99.9% of the time this should be disabled! + //#define POWER_LOSS_RECOVER_ZHOME + #if ENABLED(POWER_LOSS_RECOVER_ZHOME) + //#define POWER_LOSS_ZHOME_POS { 0, 0 } // Safe XY position to home Z while avoiding objects on the bed + #endif #endif /** @@ -1520,12 +1529,12 @@ #define DGUS_UPDATE_INTERVAL_MS 500 // (ms) Interval between automatic screen updates - #if EITHER(DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_HIPRECY) + #if ANY(DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_MKS, DGUS_LCD_UI_HIPRECY) #define DGUS_PRINT_FILENAME // Display the filename during printing #define DGUS_PREHEAT_UI // Display a preheat screen during heatup - #if ENABLED(DGUS_LCD_UI_FYSETC) - //#define DGUS_UI_MOVE_DIS_OPTION // Disabled by default for UI_FYSETC + #if EITHER(DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_MKS) + //#define DGUS_UI_MOVE_DIS_OPTION // Disabled by default for FYSETC and MKS #else #define DGUS_UI_MOVE_DIS_OPTION // Enabled by default for UI_HIPRECY #endif @@ -1568,6 +1577,8 @@ //#define LCD_HAOYU_FT810CB // Haoyu with 5" (800x480) //#define LCD_ALEPHOBJECTS_CLCD_UI // Aleph Objects Color LCD UI //#define LCD_FYSETC_TFT81050 // FYSETC with 5" (800x480) + //#define LCD_EVE3_50G // Matrix Orbital 5.0", 800x480, BT815 + //#define LCD_EVE2_50G // Matrix Orbital 5.0", 800x480, FT813 // Correct the resolution if not using the stock TFT panel. //#define TOUCH_UI_320x240 @@ -2024,6 +2035,12 @@ //#define SERIAL_STATS_DROPPED_RX #endif +// Monitor RX buffer usage +// Dump an error to the serial port if the serial receive buffer overflows. +// If you see these errors, increase the RX_BUFFER_SIZE value. +// Not supported on all platforms. +//#define RX_BUFFER_MONITOR + /** * Emergency Command Parser * @@ -2239,7 +2256,7 @@ #if AXIS_DRIVER_TYPE_X2(TMC26X) #define X2_MAX_CURRENT 1000 #define X2_SENSE_RESISTOR 91 - #define X2_MICROSTEPS 16 + #define X2_MICROSTEPS X_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_Y(TMC26X) @@ -2251,7 +2268,7 @@ #if AXIS_DRIVER_TYPE_Y2(TMC26X) #define Y2_MAX_CURRENT 1000 #define Y2_SENSE_RESISTOR 91 - #define Y2_MICROSTEPS 16 + #define Y2_MICROSTEPS Y_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_Z(TMC26X) @@ -2263,19 +2280,19 @@ #if AXIS_DRIVER_TYPE_Z2(TMC26X) #define Z2_MAX_CURRENT 1000 #define Z2_SENSE_RESISTOR 91 - #define Z2_MICROSTEPS 16 + #define Z2_MICROSTEPS Z_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_Z3(TMC26X) #define Z3_MAX_CURRENT 1000 #define Z3_SENSE_RESISTOR 91 - #define Z3_MICROSTEPS 16 + #define Z3_MICROSTEPS Z_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_Z4(TMC26X) #define Z4_MAX_CURRENT 1000 #define Z4_SENSE_RESISTOR 91 - #define Z4_MICROSTEPS 16 + #define Z4_MICROSTEPS Z_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_E0(TMC26X) @@ -2287,43 +2304,43 @@ #if AXIS_DRIVER_TYPE_E1(TMC26X) #define E1_MAX_CURRENT 1000 #define E1_SENSE_RESISTOR 91 - #define E1_MICROSTEPS 16 + #define E1_MICROSTEPS E0_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_E2(TMC26X) #define E2_MAX_CURRENT 1000 #define E2_SENSE_RESISTOR 91 - #define E2_MICROSTEPS 16 + #define E2_MICROSTEPS E0_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_E3(TMC26X) #define E3_MAX_CURRENT 1000 #define E3_SENSE_RESISTOR 91 - #define E3_MICROSTEPS 16 + #define E3_MICROSTEPS E0_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_E4(TMC26X) #define E4_MAX_CURRENT 1000 #define E4_SENSE_RESISTOR 91 - #define E4_MICROSTEPS 16 + #define E4_MICROSTEPS E0_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_E5(TMC26X) #define E5_MAX_CURRENT 1000 #define E5_SENSE_RESISTOR 91 - #define E5_MICROSTEPS 16 + #define E5_MICROSTEPS E0_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_E6(TMC26X) #define E6_MAX_CURRENT 1000 #define E6_SENSE_RESISTOR 91 - #define E6_MICROSTEPS 16 + #define E6_MICROSTEPS E0_MICROSTEPS #endif #if AXIS_DRIVER_TYPE_E7(TMC26X) #define E7_MAX_CURRENT 1000 #define E7_SENSE_RESISTOR 91 - #define E7_MICROSTEPS 16 + #define E7_MICROSTEPS E0_MICROSTEPS #endif #endif // TMC26X @@ -2368,7 +2385,7 @@ #if AXIS_IS_TMC(X2) #define X2_CURRENT 800 #define X2_CURRENT_HOME X2_CURRENT - #define X2_MICROSTEPS 16 + #define X2_MICROSTEPS X_MICROSTEPS #define X2_RSENSE 0.11 #define X2_CHAIN_POS -1 //#define X2_INTERPOLATE true @@ -2386,7 +2403,7 @@ #if AXIS_IS_TMC(Y2) #define Y2_CURRENT 800 #define Y2_CURRENT_HOME Y2_CURRENT - #define Y2_MICROSTEPS 16 + #define Y2_MICROSTEPS Y_MICROSTEPS #define Y2_RSENSE 0.11 #define Y2_CHAIN_POS -1 //#define Y2_INTERPOLATE true @@ -2404,7 +2421,7 @@ #if AXIS_IS_TMC(Z2) #define Z2_CURRENT 800 #define Z2_CURRENT_HOME Z2_CURRENT - #define Z2_MICROSTEPS 16 + #define Z2_MICROSTEPS Z_MICROSTEPS #define Z2_RSENSE 0.11 #define Z2_CHAIN_POS -1 //#define Z2_INTERPOLATE true @@ -2413,7 +2430,7 @@ #if AXIS_IS_TMC(Z3) #define Z3_CURRENT 800 #define Z3_CURRENT_HOME Z3_CURRENT - #define Z3_MICROSTEPS 16 + #define Z3_MICROSTEPS Z_MICROSTEPS #define Z3_RSENSE 0.11 #define Z3_CHAIN_POS -1 //#define Z3_INTERPOLATE true @@ -2422,7 +2439,7 @@ #if AXIS_IS_TMC(Z4) #define Z4_CURRENT 800 #define Z4_CURRENT_HOME Z4_CURRENT - #define Z4_MICROSTEPS 16 + #define Z4_MICROSTEPS Z_MICROSTEPS #define Z4_RSENSE 0.11 #define Z4_CHAIN_POS -1 //#define Z4_INTERPOLATE true @@ -2437,16 +2454,16 @@ #endif #if AXIS_IS_TMC(E1) - #define E1_CURRENT 650 - #define E1_MICROSTEPS 16 - #define E1_RSENSE 0.11 - #define E1_CHAIN_POS -1 - //#define E1_INTERPOLATE true + #define E1_CURRENT E0_CURRENT + #define E1_MICROSTEPS E0_MICROSTEPS + #define E1_RSENSE E0_RSENSE + #define E1_CHAIN_POS E0_CHAIN_POS + //#define E1_INTERPOLATE E0_INTERPOLATE #endif #if AXIS_IS_TMC(E2) #define E2_CURRENT 800 - #define E2_MICROSTEPS 16 + #define E2_MICROSTEPS E0_MICROSTEPS #define E2_RSENSE 0.11 #define E2_CHAIN_POS -1 //#define E2_INTERPOLATE true @@ -2454,7 +2471,7 @@ #if AXIS_IS_TMC(E3) #define E3_CURRENT 800 - #define E3_MICROSTEPS 16 + #define E3_MICROSTEPS E0_MICROSTEPS #define E3_RSENSE 0.11 #define E3_CHAIN_POS -1 //#define E3_INTERPOLATE true @@ -2462,7 +2479,7 @@ #if AXIS_IS_TMC(E4) #define E4_CURRENT 800 - #define E4_MICROSTEPS 16 + #define E4_MICROSTEPS E0_MICROSTEPS #define E4_RSENSE 0.11 #define E4_CHAIN_POS -1 //#define E4_INTERPOLATE true @@ -2470,7 +2487,7 @@ #if AXIS_IS_TMC(E5) #define E5_CURRENT 800 - #define E5_MICROSTEPS 16 + #define E5_MICROSTEPS E0_MICROSTEPS #define E5_RSENSE 0.11 #define E5_CHAIN_POS -1 //#define E5_INTERPOLATE true @@ -2478,7 +2495,7 @@ #if AXIS_IS_TMC(E6) #define E6_CURRENT 800 - #define E6_MICROSTEPS 16 + #define E6_MICROSTEPS E0_MICROSTEPS #define E6_RSENSE 0.11 #define E6_CHAIN_POS -1 //#define E6_INTERPOLATE true @@ -2486,7 +2503,7 @@ #if AXIS_IS_TMC(E7) #define E7_CURRENT 800 - #define E7_MICROSTEPS 16 + #define E7_MICROSTEPS E0_MICROSTEPS #define E7_RSENSE 0.11 #define E7_CHAIN_POS -1 //#define E7_INTERPOLATE true @@ -2761,138 +2778,138 @@ #endif #if AXIS_IS_L64XX(X2) - #define X2_MICROSTEPS 128 - #define X2_OVERCURRENT 2000 - #define X2_STALLCURRENT 1500 - #define X2_MAX_VOLTAGE 127 - #define X2_CHAIN_POS -1 - #define X2_SLEW_RATE 1 + #define X2_MICROSTEPS X_MICROSTEPS + #define X2_OVERCURRENT 2000 + #define X2_STALLCURRENT 1500 + #define X2_MAX_VOLTAGE 127 + #define X2_CHAIN_POS -1 + #define X2_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(Y) - #define Y_MICROSTEPS 128 - #define Y_OVERCURRENT 2000 - #define Y_STALLCURRENT 1500 - #define Y_MAX_VOLTAGE 127 - #define Y_CHAIN_POS -1 - #define Y_SLEW_RATE 1 + #define Y_MICROSTEPS 128 + #define Y_OVERCURRENT 2000 + #define Y_STALLCURRENT 1500 + #define Y_MAX_VOLTAGE 127 + #define Y_CHAIN_POS -1 + #define Y_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(Y2) - #define Y2_MICROSTEPS 128 - #define Y2_OVERCURRENT 2000 - #define Y2_STALLCURRENT 1500 - #define Y2_MAX_VOLTAGE 127 - #define Y2_CHAIN_POS -1 - #define Y2_SLEW_RATE 1 + #define Y2_MICROSTEPS Y_MICROSTEPS + #define Y2_OVERCURRENT 2000 + #define Y2_STALLCURRENT 1500 + #define Y2_MAX_VOLTAGE 127 + #define Y2_CHAIN_POS -1 + #define Y2_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(Z) - #define Z_MICROSTEPS 128 - #define Z_OVERCURRENT 2000 - #define Z_STALLCURRENT 1500 - #define Z_MAX_VOLTAGE 127 - #define Z_CHAIN_POS -1 - #define Z_SLEW_RATE 1 + #define Z_MICROSTEPS 128 + #define Z_OVERCURRENT 2000 + #define Z_STALLCURRENT 1500 + #define Z_MAX_VOLTAGE 127 + #define Z_CHAIN_POS -1 + #define Z_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(Z2) - #define Z2_MICROSTEPS 128 - #define Z2_OVERCURRENT 2000 - #define Z2_STALLCURRENT 1500 - #define Z2_MAX_VOLTAGE 127 - #define Z2_CHAIN_POS -1 - #define Z2_SLEW_RATE 1 + #define Z2_MICROSTEPS Z_MICROSTEPS + #define Z2_OVERCURRENT 2000 + #define Z2_STALLCURRENT 1500 + #define Z2_MAX_VOLTAGE 127 + #define Z2_CHAIN_POS -1 + #define Z2_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(Z3) - #define Z3_MICROSTEPS 128 - #define Z3_OVERCURRENT 2000 - #define Z3_STALLCURRENT 1500 - #define Z3_MAX_VOLTAGE 127 - #define Z3_CHAIN_POS -1 - #define Z3_SLEW_RATE 1 + #define Z3_MICROSTEPS Z_MICROSTEPS + #define Z3_OVERCURRENT 2000 + #define Z3_STALLCURRENT 1500 + #define Z3_MAX_VOLTAGE 127 + #define Z3_CHAIN_POS -1 + #define Z3_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(Z4) - #define Z4_MICROSTEPS 128 - #define Z4_OVERCURRENT 2000 - #define Z4_STALLCURRENT 1500 - #define Z4_MAX_VOLTAGE 127 - #define Z4_CHAIN_POS -1 - #define Z4_SLEW_RATE 1 + #define Z4_MICROSTEPS Z_MICROSTEPS + #define Z4_OVERCURRENT 2000 + #define Z4_STALLCURRENT 1500 + #define Z4_MAX_VOLTAGE 127 + #define Z4_CHAIN_POS -1 + #define Z4_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(E0) - #define E0_MICROSTEPS 128 - #define E0_OVERCURRENT 2000 - #define E0_STALLCURRENT 1500 - #define E0_MAX_VOLTAGE 127 - #define E0_CHAIN_POS -1 - #define E0_SLEW_RATE 1 + #define E0_MICROSTEPS 128 + #define E0_OVERCURRENT 2000 + #define E0_STALLCURRENT 1500 + #define E0_MAX_VOLTAGE 127 + #define E0_CHAIN_POS -1 + #define E0_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(E1) - #define E1_MICROSTEPS 128 - #define E1_OVERCURRENT 2000 - #define E1_STALLCURRENT 1500 - #define E1_MAX_VOLTAGE 127 - #define E1_CHAIN_POS -1 - #define E1_SLEW_RATE 1 + #define E1_MICROSTEPS E0_MICROSTEPS + #define E1_OVERCURRENT 2000 + #define E1_STALLCURRENT 1500 + #define E1_MAX_VOLTAGE 127 + #define E1_CHAIN_POS -1 + #define E1_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(E2) - #define E2_MICROSTEPS 128 - #define E2_OVERCURRENT 2000 - #define E2_STALLCURRENT 1500 - #define E2_MAX_VOLTAGE 127 - #define E2_CHAIN_POS -1 - #define E2_SLEW_RATE 1 + #define E2_MICROSTEPS E0_MICROSTEPS + #define E2_OVERCURRENT 2000 + #define E2_STALLCURRENT 1500 + #define E2_MAX_VOLTAGE 127 + #define E2_CHAIN_POS -1 + #define E2_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(E3) - #define E3_MICROSTEPS 128 - #define E3_OVERCURRENT 2000 - #define E3_STALLCURRENT 1500 - #define E3_MAX_VOLTAGE 127 - #define E3_CHAIN_POS -1 - #define E3_SLEW_RATE 1 + #define E3_MICROSTEPS E0_MICROSTEPS + #define E3_OVERCURRENT 2000 + #define E3_STALLCURRENT 1500 + #define E3_MAX_VOLTAGE 127 + #define E3_CHAIN_POS -1 + #define E3_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(E4) - #define E4_MICROSTEPS 128 - #define E4_OVERCURRENT 2000 - #define E4_STALLCURRENT 1500 - #define E4_MAX_VOLTAGE 127 - #define E4_CHAIN_POS -1 - #define E4_SLEW_RATE 1 + #define E4_MICROSTEPS E0_MICROSTEPS + #define E4_OVERCURRENT 2000 + #define E4_STALLCURRENT 1500 + #define E4_MAX_VOLTAGE 127 + #define E4_CHAIN_POS -1 + #define E4_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(E5) - #define E5_MICROSTEPS 128 - #define E5_OVERCURRENT 2000 - #define E5_STALLCURRENT 1500 - #define E5_MAX_VOLTAGE 127 - #define E5_CHAIN_POS -1 - #define E5_SLEW_RATE 1 + #define E5_MICROSTEPS E0_MICROSTEPS + #define E5_OVERCURRENT 2000 + #define E5_STALLCURRENT 1500 + #define E5_MAX_VOLTAGE 127 + #define E5_CHAIN_POS -1 + #define E5_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(E6) - #define E6_MICROSTEPS 128 - #define E6_OVERCURRENT 2000 - #define E6_STALLCURRENT 1500 - #define E6_MAX_VOLTAGE 127 - #define E6_CHAIN_POS -1 - #define E6_SLEW_RATE 1 + #define E6_MICROSTEPS E0_MICROSTEPS + #define E6_OVERCURRENT 2000 + #define E6_STALLCURRENT 1500 + #define E6_MAX_VOLTAGE 127 + #define E6_CHAIN_POS -1 + #define E6_SLEW_RATE 1 #endif #if AXIS_IS_L64XX(E7) - #define E7_MICROSTEPS 128 - #define E7_OVERCURRENT 2000 - #define E7_STALLCURRENT 1500 - #define E7_MAX_VOLTAGE 127 - #define E7_CHAIN_POS -1 - #define E7_SLEW_RATE 1 + #define E7_MICROSTEPS E0_MICROSTEPS + #define E7_OVERCURRENT 2000 + #define E7_STALLCURRENT 1500 + #define E7_MAX_VOLTAGE 127 + #define E7_CHAIN_POS -1 + #define E7_SLEW_RATE 1 #endif /** @@ -3369,6 +3386,37 @@ #define GCODE_MACROS_SLOT_SIZE 50 // Maximum length of a single macro #endif +/** + * User-defined buttons to run custom G-code. + * Up to 25 may be defined. + */ +//#define CUSTOM_USER_BUTTONS +#if ENABLED(CUSTOM_USER_BUTTONS) + //#define BUTTON1_PIN -1 + #if PIN_EXISTS(BUTTON1_PIN) + #define BUTTON1_HIT_STATE LOW // State of the triggered button. NC=LOW. NO=HIGH. + #define BUTTON1_WHEN_PRINTING false // Button allowed to trigger during printing? + #define BUTTON1_GCODE "G28" + #define BUTTON1_DESC "Homing" // Optional string to set the LCD status + #endif + + //#define BUTTON2_PIN -1 + #if PIN_EXISTS(BUTTON2_PIN) + #define BUTTON2_HIT_STATE LOW + #define BUTTON2_WHEN_PRINTING false + #define BUTTON2_GCODE "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) + #define BUTTON2_DESC "Preheat for " PREHEAT_1_LABEL + #endif + + //#define BUTTON3_PIN -1 + #if PIN_EXISTS(BUTTON3_PIN) + #define BUTTON3_HIT_STATE LOW + #define BUTTON3_WHEN_PRINTING false + #define BUTTON3_GCODE "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) + #define BUTTON3_DESC "Preheat for " PREHEAT_2_LABEL + #endif +#endif + /** * User-defined menu items to run custom G-code. * Up to 25 may be defined, but the actual number is LCD-dependent. @@ -3754,3 +3802,10 @@ // Enable Marlin dev mode which adds some special commands //#define MARLIN_DEV_MODE + +/** + * Postmortem Debugging captures misbehavior and outputs the CPU status and backtrace to serial. + * When running in the debugger it will break for debugging. This is useful to help understand + * a crash from a remote location. Requires ~400 bytes of SRAM and 5Kb of flash. + */ +//#define POSTMORTEM_DEBUGGING diff --git a/Marlin/Makefile b/Marlin/Makefile index 49cb960b92fe..19c2d0b329a7 100644 --- a/Marlin/Makefile +++ b/Marlin/Makefile @@ -323,6 +323,8 @@ else ifeq ($(HARDWARE_MOTHERBOARD),1203) else ifeq ($(HARDWARE_MOTHERBOARD),1204) # abee Scoovo X9H else ifeq ($(HARDWARE_MOTHERBOARD),1205) +# Rambo ThinkerV2 +else ifeq ($(HARDWARE_MOTHERBOARD),1206) # # Other ATmega1280, ATmega2560 diff --git a/Marlin/src/HAL/AVR/MarlinSerial.cpp b/Marlin/src/HAL/AVR/MarlinSerial.cpp index 562a70ced7a9..81503e1fe936 100644 --- a/Marlin/src/HAL/AVR/MarlinSerial.cpp +++ b/Marlin/src/HAL/AVR/MarlinSerial.cpp @@ -566,7 +566,7 @@ ISR(SERIAL_REGNAME(USART, SERIAL_PORT, _UDRE_vect)) { MarlinSerial>::_tx_udr_empty_irq(); } -// Because of the template definition above, it's required to instantiate the template to have all method generated +// Because of the template definition above, it's required to instantiate the template to have all methods generated template class MarlinSerial< MarlinSerialCfg >; MSerialT customizedSerial1(MSerialT::HasEmergencyParser); diff --git a/Marlin/src/HAL/AVR/inc/SanityCheck.h b/Marlin/src/HAL/AVR/inc/SanityCheck.h index 731cf9286582..51ba247953b4 100644 --- a/Marlin/src/HAL/AVR/inc/SanityCheck.h +++ b/Marlin/src/HAL/AVR/inc/SanityCheck.h @@ -56,3 +56,10 @@ #if BOTH(HAS_TMC_SW_SERIAL, MONITOR_DRIVER_STATUS) #error "MONITOR_DRIVER_STATUS causes performance issues when used with SoftwareSerial-connected drivers. Disable MONITOR_DRIVER_STATUS or use hardware serial to continue." #endif + +/** + * Postmortem debugging + */ +#if ENABLED(POSTMORTEM_DEBUGGING) + #error "POSTMORTEM_DEBUGGING is not supported on AVR boards." +#endif diff --git a/Marlin/src/HAL/DUE/DebugMonitor.cpp b/Marlin/src/HAL/DUE/DebugMonitor.cpp deleted file mode 100644 index 79759151d891..000000000000 --- a/Marlin/src/HAL/DUE/DebugMonitor.cpp +++ /dev/null @@ -1,342 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -#ifdef ARDUINO_ARCH_SAM - -#include "../../core/macros.h" -#include "../../core/serial.h" - -#include "../shared/backtrace/unwinder.h" -#include "../shared/backtrace/unwmemaccess.h" - -#include - -// Debug monitor that dumps to the Programming port all status when -// an exception or WDT timeout happens - And then resets the board - -// All the Monitor routines must run with interrupts disabled and -// under an ISR execution context. That is why we cannot reuse the -// Serial interrupt routines or any C runtime, as we don't know the -// state we are when running them - -// A SW memory barrier, to ensure GCC does not overoptimize loops -#define sw_barrier() __asm__ volatile("": : :"memory"); - -// (re)initialize UART0 as a monitor output to 250000,n,8,1 -static void TXBegin() { - - // Disable UART interrupt in NVIC - NVIC_DisableIRQ( UART_IRQn ); - - // We NEED memory barriers to ensure Interrupts are actually disabled! - // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the ) - __DSB(); - __ISB(); - - // Disable clock - pmc_disable_periph_clk( ID_UART ); - - // Configure PMC - pmc_enable_periph_clk( ID_UART ); - - // Disable PDC channel - UART->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS; - - // Reset and disable receiver and transmitter - UART->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS; - - // Configure mode: 8bit, No parity, 1 bit stop - UART->UART_MR = UART_MR_CHMODE_NORMAL | US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_NO; - - // Configure baudrate (asynchronous, no oversampling) to BAUDRATE bauds - UART->UART_BRGR = (SystemCoreClock / (BAUDRATE << 4)); - - // Enable receiver and transmitter - UART->UART_CR = UART_CR_RXEN | UART_CR_TXEN; -} - -// Send character through UART with no interrupts -static void TX(char c) { - while (!(UART->UART_SR & UART_SR_TXRDY)) { WDT_Restart(WDT); sw_barrier(); }; - UART->UART_THR = c; -} - -// Send String through UART -static void TX(const char* s) { - while (*s) TX(*s++); -} - -static void TXDigit(uint32_t d) { - if (d < 10) TX((char)(d+'0')); - else if (d < 16) TX((char)(d+'A'-10)); - else TX('?'); -} - -// Send Hex number thru UART -static void TXHex(uint32_t v) { - TX("0x"); - for (uint8_t i = 0; i < 8; i++, v <<= 4) - TXDigit((v >> 28) & 0xF); -} - -// Send Decimal number thru UART -static void TXDec(uint32_t v) { - if (!v) { - TX('0'); - return; - } - - char nbrs[14]; - char *p = &nbrs[0]; - while (v != 0) { - *p++ = '0' + (v % 10); - v /= 10; - } - do { - p--; - TX(*p); - } while (p != &nbrs[0]); -} - -// Dump a backtrace entry -static bool UnwReportOut(void* ctx, const UnwReport* bte) { - int* p = (int*)ctx; - - (*p)++; - TX('#'); TXDec(*p); TX(" : "); - TX(bte->name?bte->name:"unknown"); TX('@'); TXHex(bte->function); - TX('+'); TXDec(bte->address - bte->function); - TX(" PC:");TXHex(bte->address); TX('\n'); - return true; -} - -#ifdef UNW_DEBUG - void UnwPrintf(const char* format, ...) { - char dest[256]; - va_list argptr; - va_start(argptr, format); - vsprintf(dest, format, argptr); - va_end(argptr); - TX(&dest[0]); - } -#endif - -/* Table of function pointers for passing to the unwinder */ -static const UnwindCallbacks UnwCallbacks = { - UnwReportOut, - UnwReadW, - UnwReadH, - UnwReadB - #ifdef UNW_DEBUG - , UnwPrintf - #endif -}; - -/** - * HardFaultHandler_C: - * This is called from the HardFault_HandlerAsm with a pointer the Fault stack - * as the parameter. We can then read the values from the stack and place them - * into local variables for ease of reading. - * We then read the various Fault Status and Address Registers to help decode - * cause of the fault. - * The function ends with a BKPT instruction to force control back into the debugger - */ -extern "C" -void HardFault_HandlerC(unsigned long *sp, unsigned long lr, unsigned long cause) { - - static const char* causestr[] = { - "NMI","Hard","Mem","Bus","Usage","Debug","WDT","RSTC" - }; - - UnwindFrame btf; - - // Dump report to the Programming port (interrupts are DISABLED) - TXBegin(); - TX("\n\n## Software Fault detected ##\n"); - TX("Cause: "); TX(causestr[cause]); TX('\n'); - - TX("R0 : "); TXHex(((unsigned long)sp[0])); TX('\n'); - TX("R1 : "); TXHex(((unsigned long)sp[1])); TX('\n'); - TX("R2 : "); TXHex(((unsigned long)sp[2])); TX('\n'); - TX("R3 : "); TXHex(((unsigned long)sp[3])); TX('\n'); - TX("R12 : "); TXHex(((unsigned long)sp[4])); TX('\n'); - TX("LR : "); TXHex(((unsigned long)sp[5])); TX('\n'); - TX("PC : "); TXHex(((unsigned long)sp[6])); TX('\n'); - TX("PSR : "); TXHex(((unsigned long)sp[7])); TX('\n'); - - // Configurable Fault Status Register - // Consists of MMSR, BFSR and UFSR - TX("CFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED28)))); TX('\n'); - - // Hard Fault Status Register - TX("HFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED2C)))); TX('\n'); - - // Debug Fault Status Register - TX("DFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED30)))); TX('\n'); - - // Auxiliary Fault Status Register - TX("AFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED3C)))); TX('\n'); - - // Read the Fault Address Registers. These may not contain valid values. - // Check BFARVALID/MMARVALID to see if they are valid values - // MemManage Fault Address Register - TX("MMAR : "); TXHex((*((volatile unsigned long *)(0xE000ED34)))); TX('\n'); - - // Bus Fault Address Register - TX("BFAR : "); TXHex((*((volatile unsigned long *)(0xE000ED38)))); TX('\n'); - - TX("ExcLR: "); TXHex(lr); TX('\n'); - TX("ExcSP: "); TXHex((unsigned long)sp); TX('\n'); - - btf.sp = ((unsigned long)sp) + 8*4; // The original stack pointer - btf.fp = btf.sp; - btf.lr = ((unsigned long)sp[5]); - btf.pc = ((unsigned long)sp[6]) | 1; // Force Thumb, as CORTEX only support it - - // Perform a backtrace - TX("\nBacktrace:\n\n"); - int ctr = 0; - UnwindStart(&btf, &UnwCallbacks, &ctr); - - // Disable all NVIC interrupts - NVIC->ICER[0] = 0xFFFFFFFF; - NVIC->ICER[1] = 0xFFFFFFFF; - - // Relocate VTOR table to default position - SCB->VTOR = 0; - - // Disable USB - otg_disable(); - - // Restart watchdog - WDT_Restart(WDT); - - // Reset controller - NVIC_SystemReset(); - for (;;) WDT_Restart(WDT); -} - -__attribute__((naked)) void NMI_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#0") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void HardFault_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#1") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void MemManage_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#2") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void BusFault_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#3") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void UsageFault_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#4") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void DebugMon_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#5") - A("b HardFault_HandlerC") - ); -} - -/* This is NOT an exception, it is an interrupt handler - Nevertheless, the framing is the same */ -__attribute__((naked)) void WDT_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#6") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void RSTC_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#7") - A("b HardFault_HandlerC") - ); -} - -#endif // ARDUINO_ARCH_SAM diff --git a/Marlin/src/HAL/DUE/HAL.cpp b/Marlin/src/HAL/DUE/HAL.cpp index 2ae70843f0c7..034b86ccb07c 100644 --- a/Marlin/src/HAL/DUE/HAL.cpp +++ b/Marlin/src/HAL/DUE/HAL.cpp @@ -40,6 +40,8 @@ uint16_t HAL_adc_result; // Public functions // ------------------------ +TERN_(POSTMORTEM_DEBUGGING, extern void install_min_serial()); + // HAL initialization task void HAL_init() { // Initialize the USB stack @@ -47,6 +49,7 @@ void HAL_init() { OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up #endif usb_task_init(); + TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler } // HAL idle task @@ -102,11 +105,18 @@ uint16_t HAL_adc_get_result() { return HAL_adc_result; } -// Forward the default serial port -DefaultSerial MSerial(false, Serial); - -DefaultSerial1 MSerial1(false, Serial1); -DefaultSerial2 MSerial2(false, Serial2); -DefaultSerial3 MSerial3(false, Serial3); +// Forward the default serial ports +#if ANY_SERIAL_IS(0) + DefaultSerial MSerial(false, Serial); +#endif +#if ANY_SERIAL_IS(1) + DefaultSerial1 MSerial1(false, Serial1); +#endif +#if ANY_SERIAL_IS(2) + DefaultSerial2 MSerial2(false, Serial2); +#endif +#if ANY_SERIAL_IS(3) + DefaultSerial3 MSerial3(false, Serial3); +#endif #endif // ARDUINO_ARCH_SAM diff --git a/Marlin/src/HAL/DUE/HAL.h b/Marlin/src/HAL/DUE/HAL.h index 78c8a800b9d6..b1c6a38c0fe5 100644 --- a/Marlin/src/HAL/DUE/HAL.h +++ b/Marlin/src/HAL/DUE/HAL.h @@ -37,12 +37,12 @@ #include #include "../../core/serial_hook.h" -typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial; -extern DefaultSerial MSerial; +typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial; typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1; typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2; typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3; +extern DefaultSerial MSerial; extern DefaultSerial1 MSerial1; extern DefaultSerial2 MSerial2; extern DefaultSerial3 MSerial3; diff --git a/Marlin/src/HAL/DUE/HAL_MinSerial.cpp b/Marlin/src/HAL/DUE/HAL_MinSerial.cpp new file mode 100644 index 000000000000..93c4ed67d63c --- /dev/null +++ b/Marlin/src/HAL/DUE/HAL_MinSerial.cpp @@ -0,0 +1,91 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#ifdef ARDUINO_ARCH_SAM + +#include "../../inc/MarlinConfigPre.h" + +#if ENABLED(POSTMORTEM_DEBUGGING) + +#include "../shared/HAL_MinSerial.h" + +#include + +static void TXBegin() { + // Disable UART interrupt in NVIC + NVIC_DisableIRQ( UART_IRQn ); + + // We NEED memory barriers to ensure Interrupts are actually disabled! + // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the ) + __DSB(); + __ISB(); + + // Disable clock + pmc_disable_periph_clk( ID_UART ); + + // Configure PMC + pmc_enable_periph_clk( ID_UART ); + + // Disable PDC channel + UART->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS; + + // Reset and disable receiver and transmitter + UART->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX | UART_CR_RXDIS | UART_CR_TXDIS; + + // Configure mode: 8bit, No parity, 1 bit stop + UART->UART_MR = UART_MR_CHMODE_NORMAL | US_MR_CHRL_8_BIT | US_MR_NBSTOP_1_BIT | UART_MR_PAR_NO; + + // Configure baudrate (asynchronous, no oversampling) to BAUDRATE bauds + UART->UART_BRGR = (SystemCoreClock / (BAUDRATE << 4)); + + // Enable receiver and transmitter + UART->UART_CR = UART_CR_RXEN | UART_CR_TXEN; +} + +// A SW memory barrier, to ensure GCC does not overoptimize loops +#define sw_barrier() __asm__ volatile("": : :"memory"); +static void TX(char c) { + while (!(UART->UART_SR & UART_SR_TXRDY)) { WDT_Restart(WDT); sw_barrier(); }; + UART->UART_THR = c; +} + +void install_min_serial() { + HAL_min_serial_init = &TXBegin; + HAL_min_serial_out = &TX; +} + +#if DISABLED(DYNAMIC_VECTORTABLE) +extern "C" { + __attribute__((naked)) void JumpHandler_ASM() { + __asm__ __volatile__ ( + "b CommonHandler_ASM\n" + ); + } + void __attribute__((naked, alias("JumpHandler_ASM"))) HardFault_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"))) BusFault_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"))) UsageFault_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"))) MemManage_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"))) NMI_Handler(); +} +#endif + +#endif // POSTMORTEM_DEBUGGING +#endif // ARDUINO_ARCH_SAM diff --git a/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp b/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp index a04993ca35ed..fca677c7981e 100644 --- a/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp +++ b/Marlin/src/HAL/DUE/MarlinSerialUSB.cpp @@ -92,12 +92,11 @@ int MarlinSerialUSB::read() { return c; } -bool MarlinSerialUSB::available() { - /* If Pending chars */ - return pending_char >= 0 || - /* or USB CDC enumerated and configured on the PC side and some - bytes where sent to us */ - (usb_task_cdc_isenabled() && udi_cdc_is_rx_ready()); +int MarlinSerialUSB::available() { + if (pending_char > 0) return pending_char; + return pending_char == 0 || + // or USB CDC enumerated and configured on the PC side and some bytes where sent to us */ + (usb_task_cdc_isenabled() && udi_cdc_is_rx_ready()); } void MarlinSerialUSB::flush() { } diff --git a/Marlin/src/HAL/DUE/MarlinSerialUSB.h b/Marlin/src/HAL/DUE/MarlinSerialUSB.h index 5281a006b155..f9cea2986960 100644 --- a/Marlin/src/HAL/DUE/MarlinSerialUSB.h +++ b/Marlin/src/HAL/DUE/MarlinSerialUSB.h @@ -39,7 +39,7 @@ struct MarlinSerialUSB { int peek(); int read(); void flush(); - bool available(); + int available(); size_t write(const uint8_t c); #if ENABLED(SERIAL_STATS_DROPPED_RX) diff --git a/Marlin/src/HAL/DUE/inc/SanityCheck.h b/Marlin/src/HAL/DUE/inc/SanityCheck.h index 26fb44f3980b..87b09cf29257 100644 --- a/Marlin/src/HAL/DUE/inc/SanityCheck.h +++ b/Marlin/src/HAL/DUE/inc/SanityCheck.h @@ -57,5 +57,5 @@ #endif #if HAS_TMC_SW_SERIAL - #error "TMC220x Software Serial is not supported on this platform." + #error "TMC220x Software Serial is not supported on the DUE platform." #endif diff --git a/Marlin/src/HAL/ESP32/inc/SanityCheck.h b/Marlin/src/HAL/ESP32/inc/SanityCheck.h index f57a6c591028..8bbc68d8715b 100644 --- a/Marlin/src/HAL/ESP32/inc/SanityCheck.h +++ b/Marlin/src/HAL/ESP32/inc/SanityCheck.h @@ -30,9 +30,13 @@ #endif #if HAS_TMC_SW_SERIAL - #error "TMC220x Software Serial is not supported on this platform." + #error "TMC220x Software Serial is not supported on ESP32." #endif #if BOTH(WIFISUPPORT, ESP3D_WIFISUPPORT) #error "Only enable one WiFi option, either WIFISUPPORT or ESP3D_WIFISUPPORT." #endif + +#if ENABLED(POSTMORTEM_DEBUGGING) + #error "POSTMORTEM_DEBUGGING is not yet supported on ESP32." +#endif diff --git a/Marlin/src/HAL/LINUX/inc/SanityCheck.h b/Marlin/src/HAL/LINUX/inc/SanityCheck.h index 84167c97a144..45bb2662ace5 100644 --- a/Marlin/src/HAL/LINUX/inc/SanityCheck.h +++ b/Marlin/src/HAL/LINUX/inc/SanityCheck.h @@ -35,5 +35,9 @@ #endif #if HAS_TMC_SW_SERIAL - #error "TMC220x Software Serial is not supported on this platform." + #error "TMC220x Software Serial is not supported on LINUX." +#endif + +#if ENABLED(POSTMORTEM_DEBUGGING) + #error "POSTMORTEM_DEBUGGING is not yet supported on LINUX." #endif diff --git a/Marlin/src/HAL/LPC1768/DebugMonitor.cpp b/Marlin/src/HAL/LPC1768/DebugMonitor.cpp deleted file mode 100644 index 783b10cfac16..000000000000 --- a/Marlin/src/HAL/LPC1768/DebugMonitor.cpp +++ /dev/null @@ -1,322 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -#ifdef TARGET_LPC1768 - -#include "../../core/macros.h" -#include "../../core/serial.h" -#include - -#include "../shared/backtrace/unwinder.h" -#include "../shared/backtrace/unwmemaccess.h" -#include "watchdog.h" -#include - - -// Debug monitor that dumps to the Programming port all status when -// an exception or WDT timeout happens - And then resets the board - -// All the Monitor routines must run with interrupts disabled and -// under an ISR execution context. That is why we cannot reuse the -// Serial interrupt routines or any C runtime, as we don't know the -// state we are when running them - -// A SW memory barrier, to ensure GCC does not overoptimize loops -#define sw_barrier() __asm__ volatile("": : :"memory"); - -// (re)initialize UART0 as a monitor output to 250000,n,8,1 -static void TXBegin() { -} - -// Send character through UART with no interrupts -static void TX(char c) { - _DBC(c); -} - -// Send String through UART -static void TX(const char* s) { - while (*s) TX(*s++); -} - -static void TXDigit(uint32_t d) { - if (d < 10) TX((char)(d+'0')); - else if (d < 16) TX((char)(d+'A'-10)); - else TX('?'); -} - -// Send Hex number thru UART -static void TXHex(uint32_t v) { - TX("0x"); - for (uint8_t i = 0; i < 8; i++, v <<= 4) - TXDigit((v >> 28) & 0xF); -} - -// Send Decimal number thru UART -static void TXDec(uint32_t v) { - if (!v) { - TX('0'); - return; - } - - char nbrs[14]; - char *p = &nbrs[0]; - while (v != 0) { - *p++ = '0' + (v % 10); - v /= 10; - } - do { - p--; - TX(*p); - } while (p != &nbrs[0]); -} - -// Dump a backtrace entry -static bool UnwReportOut(void* ctx, const UnwReport* bte) { - int* p = (int*)ctx; - - (*p)++; - TX('#'); TXDec(*p); TX(" : "); - TX(bte->name?bte->name:"unknown"); TX('@'); TXHex(bte->function); - TX('+'); TXDec(bte->address - bte->function); - TX(" PC:");TXHex(bte->address); TX('\n'); - return true; -} - -#ifdef UNW_DEBUG - void UnwPrintf(const char* format, ...) { - char dest[256]; - va_list argptr; - va_start(argptr, format); - vsprintf(dest, format, argptr); - va_end(argptr); - TX(&dest[0]); - } -#endif - -/* Table of function pointers for passing to the unwinder */ -static const UnwindCallbacks UnwCallbacks = { - UnwReportOut, - UnwReadW, - UnwReadH, - UnwReadB - #ifdef UNW_DEBUG - ,UnwPrintf - #endif -}; - - -/** - * HardFaultHandler_C: - * This is called from the HardFault_HandlerAsm with a pointer the Fault stack - * as the parameter. We can then read the values from the stack and place them - * into local variables for ease of reading. - * We then read the various Fault Status and Address Registers to help decode - * cause of the fault. - * The function ends with a BKPT instruction to force control back into the debugger - */ -extern "C" -void HardFault_HandlerC(unsigned long *sp, unsigned long lr, unsigned long cause) { - - static const char* causestr[] = { - "NMI","Hard","Mem","Bus","Usage","Debug","WDT","RSTC" - }; - - UnwindFrame btf; - - // Dump report to the Programming port (interrupts are DISABLED) - TXBegin(); - TX("\n\n## Software Fault detected ##\n"); - TX("Cause: "); TX(causestr[cause]); TX('\n'); - - TX("R0 : "); TXHex(((unsigned long)sp[0])); TX('\n'); - TX("R1 : "); TXHex(((unsigned long)sp[1])); TX('\n'); - TX("R2 : "); TXHex(((unsigned long)sp[2])); TX('\n'); - TX("R3 : "); TXHex(((unsigned long)sp[3])); TX('\n'); - TX("R12 : "); TXHex(((unsigned long)sp[4])); TX('\n'); - TX("LR : "); TXHex(((unsigned long)sp[5])); TX('\n'); - TX("PC : "); TXHex(((unsigned long)sp[6])); TX('\n'); - TX("PSR : "); TXHex(((unsigned long)sp[7])); TX('\n'); - - // Configurable Fault Status Register - // Consists of MMSR, BFSR and UFSR - TX("CFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED28)))); TX('\n'); - - // Hard Fault Status Register - TX("HFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED2C)))); TX('\n'); - - // Debug Fault Status Register - TX("DFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED30)))); TX('\n'); - - // Auxiliary Fault Status Register - TX("AFSR : "); TXHex((*((volatile unsigned long *)(0xE000ED3C)))); TX('\n'); - - // Read the Fault Address Registers. These may not contain valid values. - // Check BFARVALID/MMARVALID to see if they are valid values - // MemManage Fault Address Register - TX("MMAR : "); TXHex((*((volatile unsigned long *)(0xE000ED34)))); TX('\n'); - - // Bus Fault Address Register - TX("BFAR : "); TXHex((*((volatile unsigned long *)(0xE000ED38)))); TX('\n'); - - TX("ExcLR: "); TXHex(lr); TX('\n'); - TX("ExcSP: "); TXHex((unsigned long)sp); TX('\n'); - - btf.sp = ((unsigned long)sp) + 8*4; // The original stack pointer - btf.fp = btf.sp; - btf.lr = ((unsigned long)sp[5]); - btf.pc = ((unsigned long)sp[6]) | 1; // Force Thumb, as CORTEX only support it - - // Perform a backtrace - TX("\nBacktrace:\n\n"); - int ctr = 0; - UnwindStart(&btf, &UnwCallbacks, &ctr); - - // Disable all NVIC interrupts - NVIC->ICER[0] = 0xFFFFFFFF; - NVIC->ICER[1] = 0xFFFFFFFF; - - // Relocate VTOR table to default position - SCB->VTOR = 0; - - // Clear cause of reset to prevent entering smoothie bootstrap - HAL_clear_reset_source(); - - // Restart watchdog - #if ENABLED(USE_WATCHDOG) - //WDT_Restart(WDT); - watchdog_init(); - #endif - - // Reset controller - NVIC_SystemReset(); - - // Nothing below here is compiled because NVIC_SystemReset loops forever - - for (;;) { TERN_(USE_WATCHDOG, watchdog_init()); } -} - -extern "C" { -__attribute__((naked)) void NMI_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#0") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void HardFault_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#1") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void MemManage_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#2") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void BusFault_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#3") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void UsageFault_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#4") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void DebugMon_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#5") - A("b HardFault_HandlerC") - ); -} - -/* This is NOT an exception, it is an interrupt handler - Nevertheless, the framing is the same */ -__attribute__((naked)) void WDT_IRQHandler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#6") - A("b HardFault_HandlerC") - ); -} - -__attribute__((naked)) void RSTC_Handler() { - __asm__ __volatile__ ( - ".syntax unified" "\n\t" - A("tst lr, #4") - A("ite eq") - A("mrseq r0, msp") - A("mrsne r0, psp") - A("mov r1,lr") - A("mov r2,#7") - A("b HardFault_HandlerC") - ); -} -} -#endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/LPC1768/HAL_MinSerial.cpp b/Marlin/src/HAL/LPC1768/HAL_MinSerial.cpp new file mode 100644 index 000000000000..ab9af1fe002e --- /dev/null +++ b/Marlin/src/HAL/LPC1768/HAL_MinSerial.cpp @@ -0,0 +1,50 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#ifdef TARGET_LPC1768 + +#include "HAL.h" + +#if ENABLED(POSTMORTEM_DEBUGGING) + +#include "../shared/HAL_MinSerial.h" +#include + +static void TX(char c) { _DBC(c); } +void install_min_serial() { HAL_min_serial_out = &TX; } + +#if DISABLED(DYNAMIC_VECTORTABLE) +extern "C" { + __attribute__((naked)) void JumpHandler_ASM() { + __asm__ __volatile__ ( + "b CommonHandler_ASM\n" + ); + } + void __attribute__((naked, alias("JumpHandler_ASM"))) HardFault_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"))) BusFault_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"))) UsageFault_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"))) MemManage_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"))) NMI_Handler(); +} +#endif + +#endif // POSTMORTEM_DEBUGGING +#endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp index c636a40a120c..b0dfc0ae901c 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.cpp +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.cpp @@ -25,20 +25,46 @@ #include "MarlinSerial.h" #if ANY_SERIAL_IS(0) - MSerialT MSerial(true, LPC_UART0); - extern "C" void UART0_IRQHandler() { MSerial.IRQHandler(); } + MarlinSerial _MSerial(LPC_UART0); + MSerialT MSerial(true, _MSerial); + extern "C" void UART0_IRQHandler() { _MSerial.IRQHandler(); } #endif #if ANY_SERIAL_IS(1) - MSerialT MSerial1(true, (LPC_UART_TypeDef *) LPC_UART1); - extern "C" void UART1_IRQHandler() { MSerial1.IRQHandler(); } + MarlinSerial _MSerial1((LPC_UART_TypeDef *) LPC_UART1); + MSerialT MSerial1(true, _MSerial1); + extern "C" void UART1_IRQHandler() { _MSerial1.IRQHandler(); } #endif #if ANY_SERIAL_IS(2) - MSerialT MSerial2(true, LPC_UART2); - extern "C" void UART2_IRQHandler() { MSerial2.IRQHandler(); } + MarlinSerial _MSerial2(LPC_UART2); + MSerialT MSerial2(true, _MSerial2); + extern "C" void UART2_IRQHandler() { _MSerial2.IRQHandler(); } #endif #if ANY_SERIAL_IS(3) - MSerialT MSerial3(true, LPC_UART3); - extern "C" void UART3_IRQHandler() { MSerial3.IRQHandler(); } + MarlinSerial _MSerial3(LPC_UART3); + MSerialT MSerial3(true, _MSerial3); + extern "C" void UART3_IRQHandler() { _MSerial3.IRQHandler(); } +#endif + +#if ENABLED(EMERGENCY_PARSER) + + bool MarlinSerial::recv_callback(const char c) { + // Need to figure out which serial port we are and react in consequence (Marlin does not have CONTAINER_OF macro) + if (false) {} + #if ANY_SERIAL_IS(0) + else if (this == &_MSerial) emergency_parser.update(MSerial.emergency_state, c); + #endif + #if ANY_SERIAL_IS(1) + else if (this == &_MSerial1) emergency_parser.update(MSerial1.emergency_state, c); + #endif + #if ANY_SERIAL_IS(2) + else if (this == &_MSerial2) emergency_parser.update(MSerial2.emergency_state, c); + #endif + #if ANY_SERIAL_IS(3) + else if (this == &_MSerial3) emergency_parser.update(MSerial3.emergency_state, c); + #endif + return true; + } + #endif #endif // TARGET_LPC1768 diff --git a/Marlin/src/HAL/LPC1768/MarlinSerial.h b/Marlin/src/HAL/LPC1768/MarlinSerial.h index de0f62f006d2..35c9362b9fb1 100644 --- a/Marlin/src/HAL/LPC1768/MarlinSerial.h +++ b/Marlin/src/HAL/LPC1768/MarlinSerial.h @@ -47,15 +47,21 @@ class MarlinSerial : public HardwareSerial { void end() {} #if ENABLED(EMERGENCY_PARSER) - bool recv_callback(const char c) override { - emergency_parser.update(static_cast *>(this)->emergency_state, c); - return true; // do not discard character - } + bool recv_callback(const char c) override; #endif }; -typedef Serial0Type MSerialT; +// On LPC176x framework, HardwareSerial does not implement the same interface as Arduino's Serial, so overloads +// of 'available' and 'read' method are not used in this multiple inheritance scenario. +// Instead, use a ForwardSerial here that adapts the interface. +typedef ForwardSerial0Type MSerialT; extern MSerialT MSerial; extern MSerialT MSerial1; extern MSerialT MSerial2; extern MSerialT MSerial3; + +// Consequently, we can't use a RuntimeSerial either. The workaround would be to use a RuntimeSerial> type here +// Right now, let's ignore this until it's actually required. +#if ENABLED(SERIAL_RUNTIME_HOOK) + #error "SERIAL_RUNTIME_HOOK is not yet supported for LPC176x." +#endif diff --git a/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp b/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp index b97b161dc94c..70395251df25 100644 --- a/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp +++ b/Marlin/src/HAL/LPC1768/eeprom_sdcard.cpp @@ -83,14 +83,13 @@ bool PersistentStore::access_finish() { static void debug_rw(const bool write, int &pos, const uint8_t *value, const size_t size, const FRESULT s, const size_t total=0) { PGM_P const rw_str = write ? PSTR("write") : PSTR("read"); SERIAL_CHAR(' '); - serialprintPGM(rw_str); + SERIAL_ECHOPGM_P(rw_str); SERIAL_ECHOLNPAIR("_data(", pos, ",", value, ",", size, ", ...)"); if (total) { SERIAL_ECHOPGM(" f_"); - serialprintPGM(rw_str); + SERIAL_ECHOPGM_P(rw_str); SERIAL_ECHOPAIR("()=", s, "\n size=", size, "\n bytes_"); - serialprintPGM(write ? PSTR("written=") : PSTR("read=")); - SERIAL_ECHOLN(total); + SERIAL_ECHOLNPAIR_P(write ? PSTR("written=") : PSTR("read="), total); } else SERIAL_ECHOLNPAIR(" f_lseek()=", s); diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h index 94e4ce134170..be574a96e4ed 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h @@ -30,6 +30,5 @@ // LPC1768 boards seem to lose steps when saving to EEPROM during print (issue #20785) // TODO: Which other boards are incompatible? #if defined(MCU_LPC1768) && PRINTCOUNTER_SAVE_INTERVAL > 0 - #warning "To prevent step loss, motion will pause for PRINTCOUNTER auto-save." #define PRINTCOUNTER_SYNC 1 #endif diff --git a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h index 10d673771472..dda1c640fa73 100644 --- a/Marlin/src/HAL/LPC1768/inc/SanityCheck.h +++ b/Marlin/src/HAL/LPC1768/inc/SanityCheck.h @@ -270,7 +270,7 @@ static_assert(DISABLED(BAUD_RATE_GCODE), "BAUD_RATE_GCODE is not yet supported o #endif #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED) - #error "SERIAL_STATS_MAX_RX_QUEUED is not supported on this platform." + #error "SERIAL_STATS_MAX_RX_QUEUED is not supported on LPC176x." #elif ENABLED(SERIAL_STATS_DROPPED_RX) - #error "SERIAL_STATS_DROPPED_RX is not supported on this platform." + #error "SERIAL_STATS_DROPPED_RX is not supported on LPX176x." #endif diff --git a/Marlin/src/HAL/LPC1768/main.cpp b/Marlin/src/HAL/LPC1768/main.cpp index 1fbeddd9ea64..08fb1a1ed5d9 100644 --- a/Marlin/src/HAL/LPC1768/main.cpp +++ b/Marlin/src/HAL/LPC1768/main.cpp @@ -46,6 +46,8 @@ extern "C" { void SysTick_Callback() { disk_timerproc(); } +TERN_(POSTMORTEM_DEBUGGING, extern void install_min_serial()); + void HAL_init() { // Init LEDs @@ -123,9 +125,7 @@ void HAL_init() { delay(1000); // Give OS time to notice USB_Connect(true); - #if HAS_SD_HOST_DRIVE - MSC_SD_Init(0); // Enable USB SD card access - #endif + TERN_(HAS_SD_HOST_DRIVE, MSC_SD_Init(0)); // Enable USB SD card access const millis_t usb_timeout = millis() + 2000; while (!USB_Configuration && PENDING(millis(), usb_timeout)) { @@ -137,6 +137,8 @@ void HAL_init() { } HAL_timer_init(); + + TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler } // HAL idle task diff --git a/Marlin/src/HAL/LPC1768/upload_extra_script.py b/Marlin/src/HAL/LPC1768/upload_extra_script.py index 1daaa883ed6b..5967a9970f4c 100755 --- a/Marlin/src/HAL/LPC1768/upload_extra_script.py +++ b/Marlin/src/HAL/LPC1768/upload_extra_script.py @@ -8,9 +8,7 @@ target_filename = "FIRMWARE.CUR" target_drive = "REARM" -import os -import getpass -import platform +import os,getpass,platform current_OS = platform.system() Import("env") @@ -33,9 +31,8 @@ def print_error(e): # # platformio.ini will accept this for a Windows upload port designation: 'upload_port = L:' # Windows - doesn't care about the disk's name, only cares about the drive letter - import subprocess + import subprocess,string from ctypes import windll - import string # getting list of drives # https://stackoverflow.com/questions/827371/is-there-a-way-to-list-all-the-available-drive-letters-in-python diff --git a/Marlin/src/HAL/LPC1768/usb_serial.cpp b/Marlin/src/HAL/LPC1768/usb_serial.cpp index d225ce418860..3c1fce54f95f 100644 --- a/Marlin/src/HAL/LPC1768/usb_serial.cpp +++ b/Marlin/src/HAL/LPC1768/usb_serial.cpp @@ -29,8 +29,8 @@ EmergencyParser::State emergency_state; -bool CDC_RecvCallback(const char buffer) { - emergency_parser.update(emergency_state, buffer); +bool CDC_RecvCallback(const char c) { + emergency_parser.update(emergency_state, c); return true; } diff --git a/Marlin/src/HAL/SAMD51/HAL.cpp b/Marlin/src/HAL/SAMD51/HAL.cpp index a413c4cd80e7..17e89c723ff1 100644 --- a/Marlin/src/HAL/SAMD51/HAL.cpp +++ b/Marlin/src/HAL/SAMD51/HAL.cpp @@ -25,8 +25,21 @@ #include #ifdef ADAFRUIT_GRAND_CENTRAL_M4 - DefaultSerial MSerial(false, Serial); - DefaultSerial1 MSerial1(false, Serial1); + #if ANY_SERIAL_IS(-1) + DefaultSerial MSerial(false, Serial); + #endif + #if ANY_SERIAL_IS(0) + DefaultSerial1 MSerial1(false, Serial1); + #endif + #if ANY_SERIAL_IS(1) + DefaultSerial2 MSerial2(false, Serial2); + #endif + #if ANY_SERIAL_IS(2) + DefaultSerial3 MSerial3(false, Serial3); + #endif + #if ANY_SERIAL_IS(3) + DefaultSerial4 MSerial4(false, Serial4); + #endif #endif // ------------------------ diff --git a/Marlin/src/HAL/SAMD51/HAL.h b/Marlin/src/HAL/SAMD51/HAL.h index f28583c771be..7b272af84247 100644 --- a/Marlin/src/HAL/SAMD51/HAL.h +++ b/Marlin/src/HAL/SAMD51/HAL.h @@ -33,9 +33,15 @@ // Serial ports typedef ForwardSerial0Type< decltype(Serial) > DefaultSerial; - extern DefaultSerial MSerial; typedef ForwardSerial0Type< decltype(Serial1) > DefaultSerial1; + typedef ForwardSerial0Type< decltype(Serial2) > DefaultSerial2; + typedef ForwardSerial0Type< decltype(Serial3) > DefaultSerial3; + typedef ForwardSerial0Type< decltype(Serial4) > DefaultSerial4; + extern DefaultSerial MSerial; extern DefaultSerial1 MSerial1; + extern DefaultSerial2 MSerial2; + extern DefaultSerial3 MSerial3; + extern DefaultSerial4 MSerial4; // MYSERIAL0 required before MarlinSerial includes! diff --git a/Marlin/src/HAL/SAMD51/inc/SanityCheck.h b/Marlin/src/HAL/SAMD51/inc/SanityCheck.h index 5d610acac85c..2a4bde98e6cb 100644 --- a/Marlin/src/HAL/SAMD51/inc/SanityCheck.h +++ b/Marlin/src/HAL/SAMD51/inc/SanityCheck.h @@ -50,3 +50,7 @@ #if ENABLED(FAST_PWM_FAN) || SPINDLE_LASER_FREQUENCY #error "Features requiring Hardware PWM (FAST_PWM_FAN, SPINDLE_LASER_FREQUENCY) are not yet supported on SAMD51." #endif + +#if ENABLED(POSTMORTEM_DEBUGGING) + #error "POSTMORTEM_DEBUGGING is not yet supported on AGCM4." +#endif diff --git a/Marlin/src/HAL/STM32/HAL.cpp b/Marlin/src/HAL/STM32/HAL.cpp index e694a16a820d..d13be1a21a3a 100644 --- a/Marlin/src/HAL/STM32/HAL.cpp +++ b/Marlin/src/HAL/STM32/HAL.cpp @@ -57,10 +57,18 @@ uint16_t HAL_adc_result; // Public functions // ------------------------ +TERN_(POSTMORTEM_DEBUGGING, extern void install_min_serial()); + // HAL initialization task void HAL_init() { FastIO_init(); + // Ensure F_CPU is a constant expression. + // If the compiler breaks here, it means that delay code that should compute at compile time will not work. + // So better safe than sorry here. + constexpr int cpuFreq = F_CPU; + UNUSED(cpuFreq); + #if ENABLED(SDSUPPORT) && DISABLED(SDIO_SUPPORT) && (defined(SDSS) && SDSS != -1) OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up #endif @@ -83,6 +91,8 @@ void HAL_init() { USB_Hook_init(); #endif + TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the min serial handler + #if HAS_SD_HOST_DRIVE MSC_SD_init(); // Enable USB SD card access #endif diff --git a/Marlin/src/HAL/STM32/HAL_MinSerial.cpp b/Marlin/src/HAL/STM32/HAL_MinSerial.cpp new file mode 100644 index 000000000000..823bb6e8f5e7 --- /dev/null +++ b/Marlin/src/HAL/STM32/HAL_MinSerial.cpp @@ -0,0 +1,152 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * Copyright (c) 2017 Victor Perez + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#if defined(ARDUINO_ARCH_STM32) && !defined(STM32GENERIC) + +#include "../../inc/MarlinConfigPre.h" + +#if ENABLED(POSTMORTEM_DEBUGGING) + +#include "../shared/HAL_MinSerial.h" +#include "watchdog.h" + +/* Instruction Synchronization Barrier */ +#define isb() __asm__ __volatile__ ("isb" : : : "memory") + +/* Data Synchronization Barrier */ +#define dsb() __asm__ __volatile__ ("dsb" : : : "memory") + +// Dumb mapping over the registers of a USART device on STM32 +struct USARTMin { + volatile uint32_t SR; + volatile uint32_t DR; + volatile uint32_t BRR; + volatile uint32_t CR1; + volatile uint32_t CR2; +}; + +#if WITHIN(SERIAL_PORT, 1, 6) + // Depending on the CPU, the serial port is different for USART1 + static const uintptr_t regsAddr[] = { + TERN(STM32F1xx, 0x40013800, 0x40011000), // USART1 + 0x40004400, // USART2 + 0x40004800, // USART3 + 0x40004C00, // UART4_BASE + 0x40005000, // UART5_BASE + 0x40011400 // USART6 + }; + static USARTMin * regs = (USARTMin*)regsAddr[SERIAL_PORT - 1]; +#endif + +static void TXBegin() { + #if !WITHIN(SERIAL_PORT, 1, 6) + #warning "Using POSTMORTEM_DEBUGGING requires a physical U(S)ART hardware in case of severe error." + #warning "Disabling the severe error reporting feature currently because the used serial port is not a HW port." + #else + // This is common between STM32F1/STM32F2 and STM32F4 + const int nvicUART[] = { /* NVIC_USART1 */ 37, /* NVIC_USART2 */ 38, /* NVIC_USART3 */ 39, /* NVIC_UART4 */ 52, /* NVIC_UART5 */ 53, /* NVIC_USART6 */ 71 }; + int nvicIndex = nvicUART[SERIAL_PORT - 1]; + + struct NVICMin { + volatile uint32_t ISER[32]; + volatile uint32_t ICER[32]; + }; + + NVICMin * nvicBase = (NVICMin*)0xE000E100; + nvicBase->ICER[nvicIndex / 32] |= _BV32(nvicIndex % 32); + + // We NEED memory barriers to ensure Interrupts are actually disabled! + // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the ) + dsb(); + isb(); + + // Example for USART1 disable: (RCC->APB2ENR &= ~(RCC_APB2ENR_USART1EN)) + // Too difficult to reimplement here, let's query the STM32duino macro here + #if SERIAL_PORT == 1 + __HAL_RCC_USART1_CLK_DISABLE(); + __HAL_RCC_USART1_CLK_ENABLE(); + #elif SERIAL_PORT == 2 + __HAL_RCC_USART2_CLK_DISABLE(); + __HAL_RCC_USART2_CLK_ENABLE(); + #elif SERIAL_PORT == 3 + __HAL_RCC_USART3_CLK_DISABLE(); + __HAL_RCC_USART3_CLK_ENABLE(); + #elif SERIAL_PORT == 4 + __HAL_RCC_UART4_CLK_DISABLE(); // BEWARE: UART4 and not USART4 here + __HAL_RCC_UART4_CLK_ENABLE(); + #elif SERIAL_PORT == 5 + __HAL_RCC_UART5_CLK_DISABLE(); // BEWARE: UART5 and not USART5 here + __HAL_RCC_UART5_CLK_ENABLE(); + #elif SERIAL_PORT == 6 + __HAL_RCC_USART6_CLK_DISABLE(); + __HAL_RCC_USART6_CLK_ENABLE(); + #endif + + uint32_t brr = regs->BRR; + regs->CR1 = 0; // Reset the USART + regs->CR2 = 0; // 1 stop bit + + // If we don't touch the BRR (baudrate register), we don't need to recompute. + regs->BRR = brr; + + regs->CR1 = _BV(3) | _BV(13); // 8 bits, no parity, 1 stop bit (TE | UE) + #endif +} + +// A SW memory barrier, to ensure GCC does not overoptimize loops +#define sw_barrier() __asm__ volatile("": : :"memory"); +static void TX(char c) { + #if WITHIN(SERIAL_PORT, 1, 6) + constexpr uint32_t usart_sr_txe = _BV(7); + while (!(regs->SR & usart_sr_txe)) { + TERN_(USE_WATCHDOG, HAL_watchdog_refresh()); + sw_barrier(); + } + regs->DR = c; + #else + // Let's hope a mystical guru will fix this, one day by writting interrupt-free USB CDC ACM code (or, at least, by polling the registers since interrupt will be queued but will never trigger) + // For now, it's completely lost to oblivion. + #endif +} + +void install_min_serial() { + HAL_min_serial_init = &TXBegin; + HAL_min_serial_out = &TX; +} + +#if DISABLED(DYNAMIC_VECTORTABLE) && DISABLED(STM32F0xx) // Cortex M0 can't jump to a symbol that's too far from the current function, so we work around this in exception_arm.cpp +extern "C" { + __attribute__((naked)) void JumpHandler_ASM() { + __asm__ __volatile__ ( + "b CommonHandler_ASM\n" + ); + } + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) HardFault_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) BusFault_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) UsageFault_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) MemManage_Handler(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) NMI_Handler(); +} +#endif + +#endif // POSTMORTEM_DEBUGGING +#endif // ARDUINO_ARCH_STM32 diff --git a/Marlin/src/HAL/STM32/eeprom_flash.cpp b/Marlin/src/HAL/STM32/eeprom_flash.cpp index 633a286dc8dd..5862090f1ba4 100644 --- a/Marlin/src/HAL/STM32/eeprom_flash.cpp +++ b/Marlin/src/HAL/STM32/eeprom_flash.cpp @@ -48,7 +48,7 @@ #include "stm32_def.h" #define DEBUG_OUT ENABLED(EEPROM_CHITCHAT) - #include "src/core/debug_out.h" + #include "../../core/debug_out.h" #ifndef MARLIN_EEPROM_SIZE #define MARLIN_EEPROM_SIZE 0x1000 // 4KB diff --git a/Marlin/src/HAL/STM32/inc/Conditionals_adv.h b/Marlin/src/HAL/STM32/inc/Conditionals_adv.h index 672d405d6b84..9c9a7014c7b4 100644 --- a/Marlin/src/HAL/STM32/inc/Conditionals_adv.h +++ b/Marlin/src/HAL/STM32/inc/Conditionals_adv.h @@ -24,3 +24,9 @@ #if defined(USBD_USE_CDC_MSC) && DISABLED(NO_SD_HOST_DRIVE) #define HAS_SD_HOST_DRIVE 1 #endif + +// Fix F_CPU not being a compile-time constant in STSTM32 framework +#ifdef BOARD_F_CPU + #undef F_CPU + #define F_CPU BOARD_F_CPU +#endif diff --git a/Marlin/src/HAL/STM32/inc/SanityCheck.h b/Marlin/src/HAL/STM32/inc/SanityCheck.h index 4df75a050558..7ee606af7f37 100644 --- a/Marlin/src/HAL/STM32/inc/SanityCheck.h +++ b/Marlin/src/HAL/STM32/inc/SanityCheck.h @@ -47,9 +47,9 @@ #endif #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED) - #error "SERIAL_STATS_MAX_RX_QUEUED is not supported on this platform." + #error "SERIAL_STATS_MAX_RX_QUEUED is not supported on STM32." #elif ENABLED(SERIAL_STATS_DROPPED_RX) - #error "SERIAL_STATS_DROPPED_RX is not supported on this platform." + #error "SERIAL_STATS_DROPPED_RX is not supported on STM32." #endif #if ANY(TFT_COLOR_UI, TFT_LVGL_UI, TFT_CLASSIC_UI) && NOT_TARGET(STM32F4xx, STM32F1xx) diff --git a/Marlin/src/HAL/STM32/tft/tft_spi.cpp b/Marlin/src/HAL/STM32/tft/tft_spi.cpp index 3cb797d5f2a9..32af67d158c4 100644 --- a/Marlin/src/HAL/STM32/tft/tft_spi.cpp +++ b/Marlin/src/HAL/STM32/tft/tft_spi.cpp @@ -207,12 +207,12 @@ void TFT_SPI::Transmit(uint16_t Data) { while ((SPIx.Instance->SR & SPI_FLAG_BSY) == SPI_FLAG_BSY) {} if (TFT_MISO_PIN != TFT_MOSI_PIN) - __HAL_SPI_CLEAR_OVRFLAG(&SPIx); /* Clear overrun flag in 2 Lines communication mode because received is not read */ + __HAL_SPI_CLEAR_OVRFLAG(&SPIx); // Clear overrun flag in 2 Lines communication mode because received is not read } void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Count) { // Wait last dma finish, to start another - while(isBusy()) { } + while (isBusy()) { /* nada */ } DMAtx.Init.MemInc = MemoryIncrease; HAL_DMA_Init(&DMAtx); @@ -225,7 +225,7 @@ void TFT_SPI::TransmitDMA(uint32_t MemoryIncrease, uint16_t *Data, uint16_t Coun HAL_DMA_Start(&DMAtx, (uint32_t)Data, (uint32_t)&(SPIx.Instance->DR), Count); __HAL_SPI_ENABLE(&SPIx); - SET_BIT(SPIx.Instance->CR2, SPI_CR2_TXDMAEN); /* Enable Tx DMA Request */ + SET_BIT(SPIx.Instance->CR2, SPI_CR2_TXDMAEN); // Enable Tx DMA Request HAL_DMA_PollForTransfer(&DMAtx, HAL_DMA_FULL_TRANSFER, HAL_MAX_DELAY); Abort(); diff --git a/Marlin/src/HAL/STM32F1/HAL.cpp b/Marlin/src/HAL/STM32F1/HAL.cpp index 2f29b9b0e36d..020c623b77a9 100644 --- a/Marlin/src/HAL/STM32F1/HAL.cpp +++ b/Marlin/src/HAL/STM32F1/HAL.cpp @@ -272,6 +272,8 @@ static void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) { } } #endif +TERN_(POSTMORTEM_DEBUGGING, extern void install_min_serial()); + void HAL_init() { NVIC_SetPriorityGrouping(0x3); #if PIN_EXISTS(LED) @@ -287,6 +289,7 @@ void HAL_init() { delay(1000); // Give OS time to notice OUT_WRITE(USB_CONNECT_PIN, USB_CONNECT_INVERTING); #endif + TERN_(POSTMORTEM_DEBUGGING, install_min_serial()); // Install the minimal serial handler } // HAL idle task diff --git a/Marlin/src/HAL/STM32F1/HAL_MinSerial.cpp b/Marlin/src/HAL/STM32F1/HAL_MinSerial.cpp new file mode 100644 index 000000000000..e6b89f1105c7 --- /dev/null +++ b/Marlin/src/HAL/STM32F1/HAL_MinSerial.cpp @@ -0,0 +1,118 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * Copyright (c) 2017 Victor Perez + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#ifdef __STM32F1__ + +#include "../../inc/MarlinConfigPre.h" + +#if ENABLED(POSTMORTEM_DEBUGGING) + +#include "../shared/HAL_MinSerial.h" +#include "watchdog.h" + +#include +#include +#include + +/* Instruction Synchronization Barrier */ +#define isb() __asm__ __volatile__ ("isb" : : : "memory") + +/* Data Synchronization Barrier */ +#define dsb() __asm__ __volatile__ ("dsb" : : : "memory") + +static void TXBegin() { + #if !WITHIN(SERIAL_PORT, 1, 6) + #warning "Using POSTMORTEM_DEBUGGING requires a physical U(S)ART hardware in case of severe error." + #warning "Disabling the severe error reporting feature currently because the used serial port is not a HW port." + #else + // We use MYSERIAL0 here, so we need to figure out how to get the linked register + struct usart_dev* dev = MYSERIAL0.c_dev(); + + // Or use this if removing libmaple + // int irq = dev->irq_num; + // int nvicUART[] = { NVIC_USART1 /* = 37 */, NVIC_USART2 /* = 38 */, NVIC_USART3 /* = 39 */, NVIC_UART4 /* = 52 */, NVIC_UART5 /* = 53 */ }; + // Disabling irq means setting the bit in the NVIC ICER register located at + // Disable UART interrupt in NVIC + nvic_irq_disable(dev->irq_num); + + // Use this if removing libmaple + //NVIC_BASE->ICER[1] |= _BV(irq - 32); + + // We NEED memory barriers to ensure Interrupts are actually disabled! + // ( https://dzone.com/articles/nvic-disabling-interrupts-on-arm-cortex-m-and-the ) + dsb(); + isb(); + + rcc_clk_disable(dev->clk_id); + rcc_clk_enable(dev->clk_id); + + usart_reg_map *regs = dev->regs; + regs->CR1 = 0; // Reset the USART + regs->CR2 = 0; // 1 stop bit + + // If we don't touch the BRR (baudrate register), we don't need to recompute. Else we would need to call + usart_set_baud_rate(dev, 0, BAUDRATE); + + regs->CR1 = (USART_CR1_TE | USART_CR1_UE); // 8 bits, no parity, 1 stop bit + #endif +} + +// A SW memory barrier, to ensure GCC does not overoptimize loops +#define sw_barrier() __asm__ volatile("": : :"memory"); +static void TX(char c) { + #if WITHIN(SERIAL_PORT, 1, 6) + struct usart_dev* dev = MYSERIAL0.c_dev(); + while (!(dev->regs->SR & USART_SR_TXE)) { + TERN_(USE_WATCHDOG, HAL_watchdog_refresh()); + sw_barrier(); + } + dev->regs->DR = c; + #endif +} + +void install_min_serial() { + HAL_min_serial_init = &TXBegin; + HAL_min_serial_out = &TX; +} + +#if DISABLED(DYNAMIC_VECTORTABLE) && DISABLED(STM32F0xx) // Cortex M0 can't branch to a symbol that's too far, so we have a specific hack for them +extern "C" { + __attribute__((naked)) void JumpHandler_ASM() { + __asm__ __volatile__ ( + "b CommonHandler_ASM\n" + ); + } + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) __exc_hardfault(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) __exc_busfault(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) __exc_usagefault(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) __exc_memmanage(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) __exc_nmi(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) __stm32reservedexception7(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) __stm32reservedexception8(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) __stm32reservedexception9(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) __stm32reservedexception10(); + void __attribute__((naked, alias("JumpHandler_ASM"), nothrow)) __stm32reservedexception13(); +} +#endif + +#endif // POSTMORTEM_DEBUGGING +#endif // __STM32F1__ diff --git a/Marlin/src/HAL/STM32F1/inc/SanityCheck.h b/Marlin/src/HAL/STM32F1/inc/SanityCheck.h index 8d4c54ec0fd4..89ee66d6464b 100644 --- a/Marlin/src/HAL/STM32F1/inc/SanityCheck.h +++ b/Marlin/src/HAL/STM32F1/inc/SanityCheck.h @@ -34,9 +34,9 @@ #endif #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED) - #error "SERIAL_STATS_MAX_RX_QUEUED is not supported on this platform." + #error "SERIAL_STATS_MAX_RX_QUEUED is not supported on the STM32F1 platform." #elif ENABLED(SERIAL_STATS_DROPPED_RX) - #error "SERIAL_STATS_DROPPED_RX is not supported on this platform." + #error "SERIAL_STATS_DROPPED_RX is not supported on the STM32F1 platform." #endif #if ENABLED(NEOPIXEL_LED) diff --git a/Marlin/src/HAL/TEENSY31_32/inc/SanityCheck.h b/Marlin/src/HAL/TEENSY31_32/inc/SanityCheck.h index 3932ee6a76c1..1efa76b1e9df 100644 --- a/Marlin/src/HAL/TEENSY31_32/inc/SanityCheck.h +++ b/Marlin/src/HAL/TEENSY31_32/inc/SanityCheck.h @@ -34,5 +34,9 @@ #endif #if HAS_TMC_SW_SERIAL - #error "TMC220x Software Serial is not supported on this platform." + #error "TMC220x Software Serial is not supported on Teensy 3.1/3.2." +#endif + +#if ENABLED(POSTMORTEM_DEBUGGING) + #error "POSTMORTEM_DEBUGGING is not yet supported on Teensy 3.1/3.2." #endif diff --git a/Marlin/src/HAL/TEENSY35_36/inc/SanityCheck.h b/Marlin/src/HAL/TEENSY35_36/inc/SanityCheck.h index ee80e42696fa..eef2850550eb 100644 --- a/Marlin/src/HAL/TEENSY35_36/inc/SanityCheck.h +++ b/Marlin/src/HAL/TEENSY35_36/inc/SanityCheck.h @@ -34,5 +34,9 @@ #endif #if HAS_TMC_SW_SERIAL - #error "TMC220x Software Serial is not supported on this platform." + #error "TMC220x Software Serial is not supported on Teensy 3.5/3.6." +#endif + +#if ENABLED(POSTMORTEM_DEBUGGING) + #error "POSTMORTEM_DEBUGGING is not yet supported on Teensy 3.5/3.6." #endif diff --git a/Marlin/src/HAL/TEENSY40_41/inc/SanityCheck.h b/Marlin/src/HAL/TEENSY40_41/inc/SanityCheck.h index fbfe7b0fc3d4..3d2668d749bc 100644 --- a/Marlin/src/HAL/TEENSY40_41/inc/SanityCheck.h +++ b/Marlin/src/HAL/TEENSY40_41/inc/SanityCheck.h @@ -34,5 +34,9 @@ #endif #if HAS_TMC_SW_SERIAL - #error "TMC220x Software Serial is not supported on this platform." + #error "TMC220x Software Serial is not supported on Teensy 4.0/4.1." +#endif + +#if ENABLED(POSTMORTEM_DEBUGGING) + #error "POSTMORTEM_DEBUGGING is not yet supported on Teensy 4.0/4.1." #endif diff --git a/Marlin/src/HAL/shared/Delay.cpp b/Marlin/src/HAL/shared/Delay.cpp index 1ae1b3e381fd..129698fd306d 100644 --- a/Marlin/src/HAL/shared/Delay.cpp +++ b/Marlin/src/HAL/shared/Delay.cpp @@ -51,7 +51,7 @@ // Use hardware cycle counter instead, it's much safer void delay_dwt(uint32_t count) { // Reuse the ASM_CYCLES_PER_ITERATION variable to avoid wasting another useless variable - register uint32_t start = HW_REG(_DWT_CYCCNT) - ASM_CYCLES_PER_ITERATION, elapsed; + uint32_t start = HW_REG(_DWT_CYCCNT) - ASM_CYCLES_PER_ITERATION, elapsed; do { elapsed = HW_REG(_DWT_CYCCNT) - start; } while (elapsed < count); @@ -106,13 +106,15 @@ } #if ENABLED(MARLIN_DEV_MODE) - void dump_delay_accuracy_check() - { - auto report_call_time = [](PGM_P const name, const uint32_t cycles, const uint32_t total, const bool do_flush=true) { + void dump_delay_accuracy_check() { + auto report_call_time = [](PGM_P const name, PGM_P const unit, const uint32_t cycles, const uint32_t total, const bool do_flush=true) { SERIAL_ECHOPGM("Calling "); - serialprintPGM(name); - SERIAL_ECHOLNPAIR(" for ", cycles, "cycles took: ", total, "cycles"); - if (do_flush) SERIAL_FLUSH(); + SERIAL_ECHOPGM_P(name); + SERIAL_ECHOLNPAIR(" for ", cycles); + SERIAL_ECHOPGM_P(unit); + SERIAL_ECHOLNPAIR(" took: ", total); + SERIAL_ECHOPGM_P(unit); + if (do_flush) SERIAL_FLUSHTX(); }; uint32_t s, e; @@ -123,41 +125,41 @@ constexpr uint32_t testValues[] = { 1, 5, 10, 20, 50, 100, 150, 200, 350, 500, 750, 1000 }; for (auto i : testValues) { s = micros(); DELAY_US(i); e = micros(); - report_call_time(PSTR("delay"), i, e - s); + report_call_time(PSTR("delay"), PSTR("us"), i, e - s); } if (HW_REG(_DWT_CTRL)) { for (auto i : testValues) { s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(i); e = HW_REG(_DWT_CYCCNT); - report_call_time(PSTR("delay"), i, e - s); + report_call_time(PSTR("runtime delay"), PSTR("cycles"), i, e - s); } // Measure the delay to call a real function compared to a function pointer s = HW_REG(_DWT_CYCCNT); delay_dwt(1); e = HW_REG(_DWT_CYCCNT); - report_call_time(PSTR("delay_dwt"), 1, e - s); + report_call_time(PSTR("delay_dwt"), PSTR("cycles"), 1, e - s); static PGMSTR(dcd, "DELAY_CYCLES directly "); s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES( 1); e = HW_REG(_DWT_CYCCNT); - report_call_time(dcd, 1, e - s, false); + report_call_time(dcd, PSTR("cycles"), 1, e - s, false); s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES( 5); e = HW_REG(_DWT_CYCCNT); - report_call_time(dcd, 5, e - s, false); + report_call_time(dcd, PSTR("cycles"), 5, e - s, false); s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(10); e = HW_REG(_DWT_CYCCNT); - report_call_time(dcd, 10, e - s, false); + report_call_time(dcd, PSTR("cycles"), 10, e - s, false); s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(20); e = HW_REG(_DWT_CYCCNT); - report_call_time(dcd, 20, e - s, false); + report_call_time(dcd, PSTR("cycles"), 20, e - s, false); s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(50); e = HW_REG(_DWT_CYCCNT); - report_call_time(dcd, 50, e - s, false); + report_call_time(dcd, PSTR("cycles"), 50, e - s, false); s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(100); e = HW_REG(_DWT_CYCCNT); - report_call_time(dcd, 100, e - s, false); + report_call_time(dcd, PSTR("cycles"), 100, e - s, false); s = HW_REG(_DWT_CYCCNT); DELAY_CYCLES(200); e = HW_REG(_DWT_CYCCNT); - report_call_time(dcd, 200, e - s, false); + report_call_time(dcd, PSTR("cycles"), 200, e - s, false); } } #endif // MARLIN_DEV_MODE @@ -167,10 +169,7 @@ void calibrate_delay_loop() {} #if ENABLED(MARLIN_DEV_MODE) - void dump_delay_accuracy_check() { - static PGMSTR(none, "N/A on this platform"); - serialprintPGM(none); - } + void dump_delay_accuracy_check() { SERIAL_ECHOPGM_P(PSTR("N/A on this platform")); } #endif #endif diff --git a/Marlin/src/HAL/shared/HAL_MinSerial.cpp b/Marlin/src/HAL/shared/HAL_MinSerial.cpp new file mode 100644 index 000000000000..9dda5fdf8c67 --- /dev/null +++ b/Marlin/src/HAL/shared/HAL_MinSerial.cpp @@ -0,0 +1,33 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#include "HAL_MinSerial.h" + +#if ENABLED(POSTMORTEM_DEBUGGING) + +void HAL_min_serial_init_default() {} +void HAL_min_serial_out_default(char ch) { SERIAL_CHAR(ch); } +void (*HAL_min_serial_init)() = &HAL_min_serial_init_default; +void (*HAL_min_serial_out)(char) = &HAL_min_serial_out_default; + +bool MinSerial::force_using_default_output = false; + +#endif diff --git a/Marlin/src/HAL/shared/HAL_MinSerial.h b/Marlin/src/HAL/shared/HAL_MinSerial.h new file mode 100644 index 000000000000..04643c1ab36d --- /dev/null +++ b/Marlin/src/HAL/shared/HAL_MinSerial.h @@ -0,0 +1,79 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "../../core/serial.h" +#include + +// Serial stuff here +// Inside an exception handler, the CPU state is not safe, we can't expect the handler to resume +// and the software to continue. UART communication can't rely on later callback/interrupt as it might never happen. +// So, you need to provide some method to send one byte to the usual UART with the interrupts disabled +// By default, the method uses SERIAL_CHAR but it's 100% guaranteed to break (couldn't be worse than nothing...)7 +extern void (*HAL_min_serial_init)(); +extern void (*HAL_min_serial_out)(char ch); + +struct MinSerial { + static bool force_using_default_output; + // Serial output + static void TX(char ch) { + if (force_using_default_output) + SERIAL_CHAR(ch); + else + HAL_min_serial_out(ch); + } + // Send String through UART + static void TX(const char* s) { while (*s) TX(*s++); } + // Send a digit through UART + static void TXDigit(uint32_t d) { + if (d < 10) TX((char)(d+'0')); + else if (d < 16) TX((char)(d+'A'-10)); + else TX('?'); + } + + // Send Hex number through UART + static void TXHex(uint32_t v) { + TX("0x"); + for (uint8_t i = 0; i < 8; i++, v <<= 4) + TXDigit((v >> 28) & 0xF); + } + + // Send Decimal number through UART + static void TXDec(uint32_t v) { + if (!v) { + TX('0'); + return; + } + + char nbrs[14]; + char *p = &nbrs[0]; + while (v != 0) { + *p++ = '0' + (v % 10); + v /= 10; + } + do { + p--; + TX(*p); + } while (p != &nbrs[0]); + } + static void init() { if (!force_using_default_output) HAL_min_serial_init(); } +}; diff --git a/Marlin/src/HAL/shared/backtrace/backtrace.cpp b/Marlin/src/HAL/shared/backtrace/backtrace.cpp index 4a8990c00b83..8320f475096a 100644 --- a/Marlin/src/HAL/shared/backtrace/backtrace.cpp +++ b/Marlin/src/HAL/shared/backtrace/backtrace.cpp @@ -25,7 +25,7 @@ #include "unwinder.h" #include "unwmemaccess.h" -#include "../../../core/serial.h" +#include "../HAL_MinSerial.h" #include // Dump a backtrace entry @@ -34,10 +34,12 @@ static bool UnwReportOut(void* ctx, const UnwReport* bte) { (*p)++; - SERIAL_CHAR('#'); SERIAL_ECHO(*p); SERIAL_ECHOPGM(" : "); - SERIAL_ECHOPGM(bte->name ? bte->name : "unknown"); SERIAL_ECHOPGM("@0x"); SERIAL_PRINT(bte->function, PrintBase::Hex); - SERIAL_CHAR('+'); SERIAL_ECHO(bte->address - bte->function); - SERIAL_ECHOPGM(" PC:"); SERIAL_PRINT(bte->address, PrintBase::Hex); SERIAL_CHAR('\n'); + const uint32_t a = bte->address, f = bte->function; + MinSerial::TX('#'); MinSerial::TXDec(*p); MinSerial::TX(" : "); + MinSerial::TX(bte->name?:"unknown"); MinSerial::TX('@'); MinSerial::TXHex(f); + MinSerial::TX('+'); MinSerial::TXDec(a - f); + MinSerial::TX(" PC:"); MinSerial::TXHex(a); + MinSerial::TX('\n'); return true; } @@ -48,7 +50,7 @@ static bool UnwReportOut(void* ctx, const UnwReport* bte) { va_start(argptr, format); vsprintf(dest, format, argptr); va_end(argptr); - TX(&dest[0]); + MinSerial::TX(&dest[0]); } #endif @@ -63,10 +65,10 @@ static const UnwindCallbacks UnwCallbacks = { #endif }; +// Perform a backtrace to the serial port void backtrace() { - UnwindFrame btf; - uint32_t sp = 0, lr = 0, pc = 0; + unsigned long sp = 0, lr = 0, pc = 0; // Capture the values of the registers to perform the traceback __asm__ __volatile__ ( @@ -79,6 +81,12 @@ void backtrace() { :: ); + backtrace_ex(sp, lr, pc); +} + +void backtrace_ex(unsigned long sp, unsigned long lr, unsigned long pc) { + UnwindFrame btf; + // Fill the traceback structure btf.sp = sp; btf.fp = btf.sp; @@ -86,7 +94,7 @@ void backtrace() { btf.pc = pc | 1; // Force Thumb, as CORTEX only support it // Perform a backtrace - SERIAL_ERROR_MSG("Backtrace:"); + MinSerial::TX("Backtrace:"); int ctr = 0; UnwindStart(&btf, &UnwCallbacks, &ctr); } @@ -95,4 +103,4 @@ void backtrace() { void backtrace() {} -#endif +#endif // __arm__ || __thumb__ diff --git a/Marlin/src/HAL/shared/backtrace/backtrace.h b/Marlin/src/HAL/shared/backtrace/backtrace.h index fccadedaa543..5d2ba601a071 100644 --- a/Marlin/src/HAL/shared/backtrace/backtrace.h +++ b/Marlin/src/HAL/shared/backtrace/backtrace.h @@ -23,3 +23,6 @@ // Perform a backtrace to the serial port void backtrace(); + +// Perform a backtrace to the serial port +void backtrace_ex(unsigned long sp, unsigned long lr, unsigned long pc); diff --git a/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp b/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp index 5ca46f98865b..2bde1e208d95 100644 --- a/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp +++ b/Marlin/src/HAL/shared/backtrace/unwmemaccess.cpp @@ -41,27 +41,16 @@ #define START_FLASH_ADDR 0x00000000 #define END_FLASH_ADDR 0x00080000 -#elif 0 - - // For STM32F103CBT6 - // SRAM (0x20000000 - 0x20005000) (20kb) - // FLASH (0x00000000 - 0x00020000) (128kb) - // - #define START_SRAM_ADDR 0x20000000 - #define END_SRAM_ADDR 0x20005000 - #define START_FLASH_ADDR 0x00000000 - #define END_FLASH_ADDR 0x00020000 - #elif defined(__STM32F1__) || defined(STM32F1xx) || defined(STM32F0xx) // For STM32F103ZET6/STM32F103VET6/STM32F0xx // SRAM (0x20000000 - 0x20010000) (64kb) - // FLASH (0x00000000 - 0x00080000) (512kb) + // FLASH (0x08000000 - 0x08080000) (512kb) // #define START_SRAM_ADDR 0x20000000 #define END_SRAM_ADDR 0x20010000 - #define START_FLASH_ADDR 0x00000000 - #define END_FLASH_ADDR 0x00080000 + #define START_FLASH_ADDR 0x08000000 + #define END_FLASH_ADDR 0x08080000 #elif defined(STM32F4) || defined(STM32F4xx) @@ -142,20 +131,57 @@ #define START_FLASH_ADDR 0x00000000 #define END_FLASH_ADDR 0x00100000 +#else + // Generic ARM code, that's testing if an access to the given address would cause a fault or not + // It can't guarantee an address is in RAM or Flash only, but we usually don't care + + #define NVIC_FAULT_STAT 0xE000ED28 // Configurable Fault Status Reg. + #define NVIC_CFG_CTRL 0xE000ED14 // Configuration Control Register + #define NVIC_FAULT_STAT_BFARV 0x00008000 // BFAR is valid + #define NVIC_CFG_CTRL_BFHFNMIGN 0x00000100 // Ignore bus fault in NMI/fault + #define HW_REG(X) (*((volatile unsigned long *)(X))) + + static bool validate_addr(uint32_t read_address) { + bool works = true; + uint32_t intDisabled = 0; + // Read current interrupt state + __asm__ __volatile__ ("MRS %[result], PRIMASK\n\t" : [result]"=r"(intDisabled) :: ); // 0 is int enabled, 1 for disabled + + // Clear bus fault indicator first (write 1 to clear) + HW_REG(NVIC_FAULT_STAT) |= NVIC_FAULT_STAT_BFARV; + // Ignore bus fault interrupt + HW_REG(NVIC_CFG_CTRL) |= NVIC_CFG_CTRL_BFHFNMIGN; + // Disable interrupts if not disabled previously + if (!intDisabled) __asm__ __volatile__ ("CPSID f"); + // Probe address + *(volatile uint32_t*)read_address; + // Check if a fault happened + if ((HW_REG(NVIC_FAULT_STAT) & NVIC_FAULT_STAT_BFARV) != 0) + works = false; + // Enable interrupts again if previously disabled + if (!intDisabled) __asm__ __volatile__ ("CPSIE f"); + // Enable fault interrupt flag + HW_REG(NVIC_CFG_CTRL) &= ~NVIC_CFG_CTRL_BFHFNMIGN; + + return works; + } + #endif -static bool validate_addr(uint32_t addr) { +#ifdef START_SRAM_ADDR + static bool validate_addr(uint32_t addr) { - // Address must be in SRAM range - if (addr >= START_SRAM_ADDR && addr < END_SRAM_ADDR) - return true; + // Address must be in SRAM range + if (addr >= START_SRAM_ADDR && addr < END_SRAM_ADDR) + return true; - // Or in FLASH range - if (addr >= START_FLASH_ADDR && addr < END_FLASH_ADDR) - return true; + // Or in FLASH range + if (addr >= START_FLASH_ADDR && addr < END_FLASH_ADDR) + return true; - return false; -} + return false; + } +#endif bool UnwReadW(const uint32_t a, uint32_t *v) { if (!validate_addr(a)) diff --git a/Marlin/src/HAL/shared/cpu_exception/exception_arm.cpp b/Marlin/src/HAL/shared/cpu_exception/exception_arm.cpp new file mode 100644 index 000000000000..ae9600038a3f --- /dev/null +++ b/Marlin/src/HAL/shared/cpu_exception/exception_arm.cpp @@ -0,0 +1,379 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * Copyright (c) 2020 Cyril Russo + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/*************************************************************************** + * ARM CPU Exception handler + ***************************************************************************/ + +#if defined(__arm__) || defined(__thumb__) + + +/* + On ARM CPUs exception handling is quite powerful. + + By default, upon a crash, the CPU enters the handlers that have a higher priority than any other interrupts, + so, in effect, no (real) interrupt can "interrupt" the handler (it's acting like if interrupts were disabled). + + If the handler is not called as re-entrant (that is, if the crash is not happening inside an interrupt or an handler), + then it'll patch the return address to a dumping function (resume_from_fault) and save the crash state. + The CPU will exit the handler and, as such, re-allow the other interrupts, and jump to the dumping function. + In this function, the usual serial port (USB / HW) will be used to dump the crash (no special configuration required). + + The only case where it requires hardware UART is when it's crashing in an interrupt or a crash handler. + In that case, instead of returning to the resume_from_fault function (and thus, re-enabling interrupts), + it jumps to this function directly (so with interrupts disabled), after changing the behavior of the serial output + wrapper to use the HW uart (and in effect, calling MinSerial::init which triggers a warning if you are using + a USB serial port). + + In the case you have a USB serial port, this part will be disabled, and only that part (so that's the reason for + the warning). + This means that you can't have a crash report if the crash happens in an interrupt or an handler if you are using + a USB serial port since it's physically impossible. + You will get a crash report in all other cases. +*/ + +#include "exception_hook.h" +#include "../backtrace/backtrace.h" +#include "../HAL_MinSerial.h" + +#define HW_REG(X) (*((volatile unsigned long *)(X))) + +// Default function use the CPU VTOR register to get the vector table. +// Accessing the CPU VTOR register is done in assembly since it's the only way that's common to all current tool +unsigned long get_vtor() { return HW_REG(0xE000ED08); } // Even if it looks like an error, it is not an error +void * hook_get_hardfault_vector_address(unsigned vtor) { return (void*)(vtor + 0x03); } +void * hook_get_memfault_vector_address(unsigned vtor) { return (void*)(vtor + 0x04); } +void * hook_get_busfault_vector_address(unsigned vtor) { return (void*)(vtor + 0x05); } +void * hook_get_usagefault_vector_address(unsigned vtor) { return (void*)(vtor + 0x06); } +void * hook_get_reserved_vector_address(unsigned vtor) { return (void*)(vtor + 0x07); } + +// Common exception frame for ARM, should work for all ARM CPU +// Described here (modified for convenience): https://interrupt.memfault.com/blog/cortex-m-fault-debug +struct __attribute__((packed)) ContextStateFrame { + uint32_t r0; + uint32_t r1; + uint32_t r2; + uint32_t r3; + uint32_t r12; + uint32_t lr; + uint32_t pc; + uint32_t xpsr; +}; + +struct __attribute__((packed)) ContextSavedFrame { + uint32_t R0; + uint32_t R1; + uint32_t R2; + uint32_t R3; + uint32_t R12; + uint32_t LR; + uint32_t PC; + uint32_t XPSR; + + uint32_t CFSR; + uint32_t HFSR; + uint32_t DFSR; + uint32_t AFSR; + uint32_t MMAR; + uint32_t BFAR; + + uint32_t ESP; + uint32_t ELR; +}; + +#if DISABLED(STM32F0xx) + extern "C" + __attribute__((naked)) void CommonHandler_ASM() { + __asm__ __volatile__ ( + // Bit 2 of LR tells which stack pointer to use (either main or process, only main should be used anyway) + "tst lr, #4\n" + "ite eq\n" + "mrseq r0, msp\n" + "mrsne r0, psp\n" + // Save the LR in use when being interrupted + "mov r1, lr\n" + // Get the exception number from the ICSR register + "ldr r2, =0xE000ED00\n" + "ldr r2, [r2, #4]\n" + "b CommonHandler_C\n" + ); + } +#else // Cortex M0 does not support conditional mov and testing with a constant, so let's have a specific handler for it + extern "C" + __attribute__((naked)) void CommonHandler_ASM() { + __asm__ __volatile__ ( + ".syntax unified\n" + // Save the LR in use when being interrupted + "mov r1, lr\n" + // Get the exception number from the ICSR register + "ldr r2, =0xE000ED00\n" + "ldr r2, [r2, #4]\n" + "movs r0, #4\n" + "tst r1, r0\n" + "beq _MSP\n" + "mrs r0, psp\n" + "b CommonHandler_C\n" + "_MSP:\n" + "mrs r0, msp\n" + "b CommonHandler_C\n" + ); + } + + #if DISABLED(DYNAMIC_VECTORTABLE) // Cortex M0 requires the handler's address to be within 32kB to the actual function to be able to branch to it + extern "C" { + void __attribute__((naked, alias("CommonHandler_ASM"), nothrow)) __exc_hardfault(); + void __attribute__((naked, alias("CommonHandler_ASM"), nothrow)) __exc_busfault(); + void __attribute__((naked, alias("CommonHandler_ASM"), nothrow)) __exc_usagefault(); + void __attribute__((naked, alias("CommonHandler_ASM"), nothrow)) __exc_memmanage(); + void __attribute__((naked, alias("CommonHandler_ASM"), nothrow)) __exc_nmi(); + void __attribute__((naked, alias("CommonHandler_ASM"), nothrow)) __stm32reservedexception7(); + void __attribute__((naked, alias("CommonHandler_ASM"), nothrow)) __stm32reservedexception8(); + void __attribute__((naked, alias("CommonHandler_ASM"), nothrow)) __stm32reservedexception9(); + void __attribute__((naked, alias("CommonHandler_ASM"), nothrow)) __stm32reservedexception10(); + void __attribute__((naked, alias("CommonHandler_ASM"), nothrow)) __stm32reservedexception13(); + } + //TODO When going off from libmaple, you'll need to replace those by the one from STM32/HAL_MinSerial.cpp + #endif +#endif + +// Must be a macro to avoid creating a function frame +#define HALT_IF_DEBUGGING() \ + do { \ + if (HW_REG(0xE000EDF0) & _BV(0)) { \ + __asm("bkpt 1"); \ + } \ +} while (0) + +// Resume from a fault (if possible) so we can still use interrupt based code for serial output +// In that case, we will not jump back to the faulty code, but instead to a dumping code and then a +// basic loop with watchdog calling or manual resetting +static ContextSavedFrame savedFrame; +static uint8_t lastCause; +bool resume_from_fault() { + static const char* causestr[] = { "Thread", "Rsvd", "NMI", "Hard", "Mem", "Bus", "Usage", "7", "8", "9", "10", "SVC", "Dbg", "13", "PendSV", "SysTk", "IRQ" }; + // Reinit the serial link (might only work if implemented in each of your boards) + MinSerial::init(); + + MinSerial::TX("\n\n## Software Fault detected ##\n"); + MinSerial::TX("Cause: "); MinSerial::TX(causestr[min(lastCause, (uint8_t)16)]); MinSerial::TX('\n'); + + MinSerial::TX("R0 : "); MinSerial::TXHex(savedFrame.R0); MinSerial::TX('\n'); + MinSerial::TX("R1 : "); MinSerial::TXHex(savedFrame.R1); MinSerial::TX('\n'); + MinSerial::TX("R2 : "); MinSerial::TXHex(savedFrame.R2); MinSerial::TX('\n'); + MinSerial::TX("R3 : "); MinSerial::TXHex(savedFrame.R3); MinSerial::TX('\n'); + MinSerial::TX("R12 : "); MinSerial::TXHex(savedFrame.R12); MinSerial::TX('\n'); + MinSerial::TX("LR : "); MinSerial::TXHex(savedFrame.LR); MinSerial::TX('\n'); + MinSerial::TX("PC : "); MinSerial::TXHex(savedFrame.PC); MinSerial::TX('\n'); + MinSerial::TX("PSR : "); MinSerial::TXHex(savedFrame.XPSR); MinSerial::TX('\n'); + + // Configurable Fault Status Register + // Consists of MMSR, BFSR and UFSR + MinSerial::TX("CFSR : "); MinSerial::TXHex(savedFrame.CFSR); MinSerial::TX('\n'); + + // Hard Fault Status Register + MinSerial::TX("HFSR : "); MinSerial::TXHex(savedFrame.HFSR); MinSerial::TX('\n'); + + // Debug Fault Status Register + MinSerial::TX("DFSR : "); MinSerial::TXHex(savedFrame.DFSR); MinSerial::TX('\n'); + + // Auxiliary Fault Status Register + MinSerial::TX("AFSR : "); MinSerial::TXHex(savedFrame.AFSR); MinSerial::TX('\n'); + + // Read the Fault Address Registers. These may not contain valid values. + // Check BFARVALID/MMARVALID to see if they are valid values + // MemManage Fault Address Register + MinSerial::TX("MMAR : "); MinSerial::TXHex(savedFrame.MMAR); MinSerial::TX('\n'); + + // Bus Fault Address Register + MinSerial::TX("BFAR : "); MinSerial::TXHex(savedFrame.BFAR); MinSerial::TX('\n'); + + MinSerial::TX("ExcLR: "); MinSerial::TXHex(savedFrame.ELR); MinSerial::TX('\n'); + MinSerial::TX("ExcSP: "); MinSerial::TXHex(savedFrame.ESP); MinSerial::TX('\n'); + + // The stack pointer is pushed by 8 words upon entering an exception, so we need to revert this + backtrace_ex(savedFrame.ESP + 8*4, savedFrame.LR, savedFrame.PC); + + // Call the last resort function here + hook_last_resort_func(); + + const uint32_t start = millis(), end = start + 100; // 100ms should be enough + // We need to wait for the serial buffers to be output but we don't know for how long + // So we'll just need to refresh the watchdog for a while and then stop for the system to reboot + uint32_t last = start; + while (PENDING(last, end)) { + watchdog_refresh(); + while (millis() == last) { /* nada */ } + last = millis(); + MinSerial::TX('.'); + } + + // Reset now by reinstantiating the bootloader's vector table + HW_REG(0xE000ED08) = 0; + // Restart watchdog + #if DISABLED(USE_WATCHDOG) + // No watchdog, let's perform ARMv7 reset instead by writing to AIRCR register with VECTKEY set to SYSRESETREQ + HW_REG(0xE000ED0C) = (HW_REG(0xE000ED0C) & 0x0000FFFF) | 0x05FA0004; + #endif + + while(1) {} // Bad luck, nothing worked +} + +// Make sure the compiler does not optimize the frame argument away +extern "C" +__attribute__((optimize("O0"))) +void CommonHandler_C(ContextStateFrame * frame, unsigned long lr, unsigned long cause) { + + // If you are using it'll stop here + HALT_IF_DEBUGGING(); + + // Save the state to backtrace later on (don't call memcpy here since the stack can be corrupted) + savedFrame.R0 = frame->r0; + savedFrame.R1 = frame->r1; + savedFrame.R2 = frame->r2; + savedFrame.R3 = frame->r3; + savedFrame.R12 = frame->r12; + savedFrame.LR = frame->lr; + savedFrame.PC = frame->pc; + savedFrame.XPSR= frame->xpsr; + lastCause = cause & 0x1FF; + + volatile uint32_t &CFSR = HW_REG(0xE000ED28); + savedFrame.CFSR = CFSR; + savedFrame.HFSR = HW_REG(0xE000ED2C); + savedFrame.DFSR = HW_REG(0xE000ED30); + savedFrame.AFSR = HW_REG(0xE000ED3C); + savedFrame.MMAR = HW_REG(0xE000ED34); + savedFrame.BFAR = HW_REG(0xE000ED38); + savedFrame.ESP = (unsigned long)frame; // Even on return, this should not be overwritten by the CPU + savedFrame.ELR = lr; + + // First check if we can resume from this exception to our own handler safely + // If we can, then we don't need to disable interrupts and the usual serial code + // can be used + + //const uint32_t non_usage_fault_mask = 0x0000FFFF; + //const bool non_usage_fault_occurred = (CFSR & non_usage_fault_mask) != 0; + // the bottom 8 bits of the xpsr hold the exception number of the + // executing exception or 0 if the processor is in Thread mode + const bool faulted_from_exception = ((frame->xpsr & 0xFF) != 0); + if (!faulted_from_exception) { // Not sure about the non_usage_fault, we want to try anyway, don't we ? && !non_usage_fault_occurred) + // Try to resume to our handler here + CFSR |= CFSR; // The ARM programmer manual says you must write to 1 all fault bits to clear them so this instruction is correct + // The frame will not be valid when returning anymore, let's clean it + savedFrame.CFSR = 0; + + frame->pc = (uint32_t)resume_from_fault; // Patch where to return to + frame->lr = 0xDEADBEEF; // If our handler returns (it shouldn't), let's make it trigger an exception immediately + frame->xpsr = _BV(24); // Need to clean the PSR register to thumb II only + MinSerial::force_using_default_output = true; + return; // The CPU will resume in our handler hopefully, and we'll try to use default serial output + } + + // Sorry, we need to emergency code here since the fault is too dangerous to recover from + MinSerial::force_using_default_output = false; + resume_from_fault(); +} + +void hook_cpu_exceptions() { + #if ENABLED(DYNAMIC_VECTORTABLE) + // On ARM 32bits CPU, the vector table is like this: + // 0x0C => Hardfault + // 0x10 => MemFault + // 0x14 => BusFault + // 0x18 => UsageFault + + // Unfortunately, it's usually run from flash, and we can't write to flash here directly to hook our instruction + // We could set an hardware breakpoint, and hook on the fly when it's being called, but this + // is hard to get right and would probably break debugger when attached + + // So instead, we'll allocate a new vector table filled with the previous value except + // for the fault we are interested in. + // Now, comes the issue to figure out what is the current vector table size + // There is nothing telling us what is the vector table as it's per-cpu vendor specific. + // BUT: we are being called at the end of the setup, so we assume the setup is done + // Thus, we can read the current vector table until we find an address that's not in flash, and it would mark the + // end of the vector table (skipping the fist entry obviously) + // The position of the program in flash is expected to be at 0x08xxx xxxx on all known platform for ARM and the + // flash size is available via register 0x1FFFF7E0 on STM32 family, but it's not the case for all ARM boards + // (accessing this register might trigger a fault if it's not implemented). + + // So we'll simply mask the top 8 bits of the first handler as an hint of being in the flash or not -that's poor and will + // probably break if the flash happens to be more than 128MB, but in this case, we are not magician, we need help from outside. + + unsigned long * vecAddr = (unsigned long*)get_vtor(); + SERIAL_ECHO("Vector table addr: "); + SERIAL_PRINTLN(get_vtor(), HEX); + + #ifdef VECTOR_TABLE_SIZE + uint32_t vec_size = VECTOR_TABLE_SIZE; + alignas(128) static unsigned long vectable[VECTOR_TABLE_SIZE] ; + #else + #ifndef IS_IN_FLASH + #define IS_IN_FLASH(X) (((unsigned long)X & 0xFF000000) == 0x08000000) + #endif + + // When searching for the end of the vector table, this acts as a limit not to overcome + #ifndef VECTOR_TABLE_SENTINEL + #define VECTOR_TABLE_SENTINEL 80 + #endif + + // Find the vector table size + uint32_t vec_size = 1; + while (IS_IN_FLASH(vecAddr[vec_size]) && vec_size < VECTOR_TABLE_SENTINEL) + vec_size++; + + // We failed to find a valid vector table size, let's abort hooking up + if (vec_size == VECTOR_TABLE_SENTINEL) return; + // Poor method that's wasting RAM here, but allocating with malloc and alignment would be worst + // 128 bytes alignement is required for writing the VTOR register + alignas(128) static unsigned long vectable[VECTOR_TABLE_SENTINEL]; + + SERIAL_ECHO("Detected vector table size: "); + SERIAL_PRINTLN(vec_size, HEX); + #endif + + uint32_t defaultFaultHandler = vecAddr[(unsigned)7]; + // Copy the current vector table into the new table + for (uint32_t i = 0; i < vec_size; i++) { + vectable[i] = vecAddr[i]; + // Replace all default handler by our own handler + if (vectable[i] == defaultFaultHandler) + vectable[i] = (unsigned long)&CommonHandler_ASM; + } + + // Let's hook now with our functions + vectable[(unsigned long)hook_get_hardfault_vector_address(0)] = (unsigned long)&CommonHandler_ASM; + vectable[(unsigned long)hook_get_memfault_vector_address(0)] = (unsigned long)&CommonHandler_ASM; + vectable[(unsigned long)hook_get_busfault_vector_address(0)] = (unsigned long)&CommonHandler_ASM; + vectable[(unsigned long)hook_get_usagefault_vector_address(0)] = (unsigned long)&CommonHandler_ASM; + + // Finally swap with our own vector table + // This is supposed to be atomic, but let's do that with interrupt disabled + + HW_REG(0xE000ED08) = (unsigned long)vectable | _BV32(29); // 29th bit is for telling the CPU the table is now in SRAM (should be present already) + + SERIAL_ECHOLN("Installed fault handlers"); + #endif +} + +#endif // __arm__ || __thumb__ diff --git a/Marlin/src/HAL/shared/cpu_exception/exception_hook.cpp b/Marlin/src/HAL/shared/cpu_exception/exception_hook.cpp new file mode 100644 index 000000000000..93e80f3e8524 --- /dev/null +++ b/Marlin/src/HAL/shared/cpu_exception/exception_hook.cpp @@ -0,0 +1,28 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#include "exception_hook.h" + +void * __attribute__((weak)) hook_get_hardfault_vector_address(unsigned) { return 0; } +void * __attribute__((weak)) hook_get_memfault_vector_address(unsigned) { return 0; } +void * __attribute__((weak)) hook_get_busfault_vector_address(unsigned) { return 0; } +void * __attribute__((weak)) hook_get_usagefault_vector_address(unsigned) { return 0; } +void __attribute__((weak)) hook_last_resort_func() {} diff --git a/Marlin/src/HAL/shared/cpu_exception/exception_hook.h b/Marlin/src/HAL/shared/cpu_exception/exception_hook.h new file mode 100644 index 000000000000..70d943470457 --- /dev/null +++ b/Marlin/src/HAL/shared/cpu_exception/exception_hook.h @@ -0,0 +1,54 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +/* Here is the expected behavior of a system producing a CPU exception with this hook installed: + 1. Before the system is crashed + 1.1 Upon validation (not done yet in this code, but we could be using DEBUG flags here to allow/disallow hooking) + 1.2 Install the hook by overwriting the vector table exception handler with the hooked function + 2. Upon system crash (for example, by a dereference of a NULL pointer or anything else) + 2.1 The CPU triggers its exception and jump into the vector table for the exception type + 2.2 Instead of finding the default handler, it finds the updated pointer to our hook + 2.3 The CPU jumps into our hook function (likely a naked function to keep all information about crash point intact) + 2.4 The hook (naked) function saves the important registers (stack pointer, program counter, current mode) and jumps to a common exception handler (in C) + 2.5 The common exception handler dumps the registers on the serial link and perform a backtrace around the crashing point + 2.6 Once the backtrace is performed the last resort function is called (platform specific). + On some platform with a LCD screen, this might display the crash information as a QR code or as text for the + user to capture by taking a picture + 2.7 The CPU is reset and/or halted by triggering a debug breakpoint if a debugger is attached */ + +// Hook into CPU exception interrupt table to call the backtracing code upon an exception +// Most platform will simply do nothing here, but those who can will install/overwrite the default exception handler +// with a more performant exception handler +void hook_cpu_exceptions(); + +// Some platform might deal without a hard fault handler, in that case, return 0 in your platform here or skip implementing it +void * __attribute__((weak)) hook_get_hardfault_vector_address(unsigned base_address); +// Some platform might deal without a memory management fault handler, in that case, return 0 in your platform here or skip implementing it +void * __attribute__((weak)) hook_get_memfault_vector_address(unsigned base_address); +// Some platform might deal without a bus fault handler, in that case, return 0 in your platform here or skip implementing it +void * __attribute__((weak)) hook_get_busfault_vector_address(unsigned base_address); +// Some platform might deal without a usage fault handler, in that case, return 0 in your platform here or skip implementing it +void * __attribute__((weak)) hook_get_usagefault_vector_address(unsigned base_address); + +// Last resort function that can be called after the exception handler was called. +void __attribute__((weak)) hook_last_resort_func(); diff --git a/Marlin/src/HAL/shared/eeprom_if_i2c.cpp b/Marlin/src/HAL/shared/eeprom_if_i2c.cpp index cc22bf7d986f..da70af277246 100644 --- a/Marlin/src/HAL/shared/eeprom_if_i2c.cpp +++ b/Marlin/src/HAL/shared/eeprom_if_i2c.cpp @@ -32,7 +32,13 @@ #include "eeprom_if.h" #include -void eeprom_init() { Wire.begin(); } +void eeprom_init() { + Wire.begin( + #if PINS_EXIST(I2C_SCL, I2C_SDA) + uint8_t(I2C_SDA_PIN), uint8_t(I2C_SCL_PIN) + #endif + ); +} #if ENABLED(USE_SHARED_EEPROM) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index b085e6145a51..689650c6ab45 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -36,6 +36,7 @@ #include "HAL/shared/Delay.h" #include "HAL/shared/esp_wifi.h" +#include "HAL/shared/cpu_exception/exception_hook.h" #ifdef ARDUINO #include @@ -230,6 +231,10 @@ #include "feature/password/password.h" #endif +#if ENABLED(DGUS_LCD_UI_MKS) + #include "lcd/extui/lib/dgus/DGUSScreenHandler.h" +#endif + PGMSTR(M112_KILL_STR, "M112 Shutdown"); MarlinState marlin_state = MF_INITIALIZING; @@ -387,6 +392,7 @@ void startOrResumeJob() { if (queue.enqueue_one_P(PSTR("M1001"))) { marlin_state = MF_RUNNING; TERN_(PASSWORD_AFTER_SD_PRINT_END, password.lock_machine()); + TERN_(DGUS_LCD_UI_MKS, ScreenHandler.SDPrintingFinished()); } } @@ -400,13 +406,14 @@ void startOrResumeJob() { * - Check if CHDK_PIN needs to go LOW * - Check for KILL button held down * - Check for HOME button held down + * - Check for CUSTOM USER button held down * - Check if cooling fan needs to be switched on * - Check if an idle but hot extruder needs filament extruded (EXTRUDER_RUNOUT_PREVENT) * - Pulse FET_SAFETY_PIN if it exists */ inline void manage_inactivity(const bool ignore_stepper_queue=false) { - if (queue.length < BUFSIZE) queue.get_available_commands(); + queue.get_available_commands(); const millis_t ms = millis(); @@ -492,6 +499,102 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) { } #endif + #if ENABLED(CUSTOM_USER_BUTTONS) + // Handle a custom user button if defined + const bool printer_not_busy = !printingIsActive(); + #define HAS_CUSTOM_USER_BUTTON(N) (PIN_EXISTS(BUTTON##N) && defined(BUTTON##N##_HIT_STATE) && defined(BUTTON##N##_GCODE) && defined(BUTTON##N##_DESC)) + #define CHECK_CUSTOM_USER_BUTTON(N) do{ \ + constexpr millis_t CUB_DEBOUNCE_DELAY_##N = 250UL; \ + static millis_t next_cub_ms_##N; \ + if (BUTTON##N##_HIT_STATE == READ(BUTTON##N##_PIN) \ + && (ENABLED(BUTTON##N##_WHEN_PRINTING) || printer_not_busy)) { \ + const millis_t ms = millis(); \ + if (ELAPSED(ms, next_cub_ms_##N)) { \ + next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N; \ + if (strlen(BUTTON##N##_DESC)) \ + LCD_MESSAGEPGM_P(PSTR(BUTTON##N##_DESC)); \ + queue.inject_P(PSTR(BUTTON##N##_GCODE)); \ + } \ + } \ + }while(0) + + #if HAS_CUSTOM_USER_BUTTON(1) + CHECK_CUSTOM_USER_BUTTON(1); + #endif + #if HAS_CUSTOM_USER_BUTTON(2) + CHECK_CUSTOM_USER_BUTTON(2); + #endif + #if HAS_CUSTOM_USER_BUTTON(3) + CHECK_CUSTOM_USER_BUTTON(3); + #endif + #if HAS_CUSTOM_USER_BUTTON(4) + CHECK_CUSTOM_USER_BUTTON(4); + #endif + #if HAS_CUSTOM_USER_BUTTON(5) + CHECK_CUSTOM_USER_BUTTON(5); + #endif + #if HAS_CUSTOM_USER_BUTTON(6) + CHECK_CUSTOM_USER_BUTTON(6); + #endif + #if HAS_CUSTOM_USER_BUTTON(7) + CHECK_CUSTOM_USER_BUTTON(7); + #endif + #if HAS_CUSTOM_USER_BUTTON(8) + CHECK_CUSTOM_USER_BUTTON(8); + #endif + #if HAS_CUSTOM_USER_BUTTON(9) + CHECK_CUSTOM_USER_BUTTON(9); + #endif + #if HAS_CUSTOM_USER_BUTTON(10) + CHECK_CUSTOM_USER_BUTTON(10); + #endif + #if HAS_CUSTOM_USER_BUTTON(11) + CHECK_CUSTOM_USER_BUTTON(11); + #endif + #if HAS_CUSTOM_USER_BUTTON(12) + CHECK_CUSTOM_USER_BUTTON(12); + #endif + #if HAS_CUSTOM_USER_BUTTON(13) + CHECK_CUSTOM_USER_BUTTON(13); + #endif + #if HAS_CUSTOM_USER_BUTTON(14) + CHECK_CUSTOM_USER_BUTTON(14); + #endif + #if HAS_CUSTOM_USER_BUTTON(15) + CHECK_CUSTOM_USER_BUTTON(15); + #endif + #if HAS_CUSTOM_USER_BUTTON(16) + CHECK_CUSTOM_USER_BUTTON(16); + #endif + #if HAS_CUSTOM_USER_BUTTON(17) + CHECK_CUSTOM_USER_BUTTON(17); + #endif + #if HAS_CUSTOM_USER_BUTTON(18) + CHECK_CUSTOM_USER_BUTTON(18); + #endif + #if HAS_CUSTOM_USER_BUTTON(19) + CHECK_CUSTOM_USER_BUTTON(19); + #endif + #if HAS_CUSTOM_USER_BUTTON(20) + CHECK_CUSTOM_USER_BUTTON(20); + #endif + #if HAS_CUSTOM_USER_BUTTON(21) + CHECK_CUSTOM_USER_BUTTON(21); + #endif + #if HAS_CUSTOM_USER_BUTTON(22) + CHECK_CUSTOM_USER_BUTTON(22); + #endif + #if HAS_CUSTOM_USER_BUTTON(23) + CHECK_CUSTOM_USER_BUTTON(23); + #endif + #if HAS_CUSTOM_USER_BUTTON(24) + CHECK_CUSTOM_USER_BUTTON(24); + #endif + #if HAS_CUSTOM_USER_BUTTON(25) + CHECK_CUSTOM_USER_BUTTON(25); + #endif + #endif + TERN_(USE_CONTROLLER_FAN, controllerFan.update()); // Check if fan should be turned on to cool stepper drivers down TERN_(AUTO_POWER_CONTROL, powerManager.check()); @@ -851,7 +954,7 @@ inline void tmc_standby_setup() { /** * Marlin entry-point: Set up before the program loop - * - Set up the kill pin, filament runout, power hold + * - Set up the kill pin, filament runout, power hold, custom user buttons * - Start the serial port * - Print startup messages and diagnostics * - Get EEPROM or default settings @@ -869,6 +972,9 @@ inline void tmc_standby_setup() { * • Max7219 */ void setup() { + #ifdef BOARD_PREINIT + BOARD_PREINIT(); // Low-level init (before serial init) + #endif tmc_standby_setup(); // TMC Low Power Standby pins must be set early or they're not usable @@ -876,8 +982,7 @@ void setup() { auto log_current_ms = [&](PGM_P const msg) { SERIAL_ECHO_START(); SERIAL_CHAR('['); SERIAL_ECHO(millis()); SERIAL_ECHOPGM("] "); - serialprintPGM(msg); - SERIAL_EOL(); + SERIAL_ECHOLNPGM_P(msg); }; #define SETUP_LOG(M) log_current_ms(PSTR(M)) #else @@ -911,12 +1016,6 @@ void setup() { OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING); #endif - #if ENABLED(PSU_CONTROL) - SETUP_LOG("PSU_CONTROL"); - powersupply_on = ENABLED(PSU_DEFAULT_OFF); - if (ENABLED(PSU_DEFAULT_OFF)) PSU_OFF(); else PSU_ON(); - #endif - #if EITHER(DISABLE_DEBUG, DISABLE_JTAG) // Disable any hardware debug to free up pins for IO #if ENABLED(DISABLE_DEBUG) && defined(JTAGSWD_DISABLE) @@ -935,6 +1034,8 @@ void setup() { while (/*!WIFISERIAL && */PENDING(millis(), serial_connect_timeout)) { /*nada*/ } #endif + TERN_(DYNAMIC_VECTORTABLE, hook_cpu_exceptions()); // If supported, install Marlin exception handlers at runtime + SETUP_RUN(HAL_init()); // Init and disable SPI thermocouples; this is still needed @@ -945,10 +1046,6 @@ void setup() { OUT_WRITE(MAX6675_SS2_PIN, HIGH); // Disable #endif - #if HAS_L64XX - SETUP_RUN(L64xxManager.init()); // Set up SPI, init drivers - #endif - #if ENABLED(DUET_SMART_EFFECTOR) && PIN_EXISTS(SMART_EFFECTOR_MOD) OUT_WRITE(SMART_EFFECTOR_MOD_PIN, LOW); // Put Smart Effector into NORMAL mode #endif @@ -957,10 +1054,20 @@ void setup() { SETUP_RUN(runout.setup()); #endif + #if ENABLED(PSU_CONTROL) + SETUP_LOG("PSU_CONTROL"); + powersupply_on = ENABLED(PSU_DEFAULT_OFF); + if (ENABLED(PSU_DEFAULT_OFF)) PSU_OFF(); else PSU_ON(); + #endif + #if ENABLED(POWER_LOSS_RECOVERY) SETUP_RUN(recovery.setup()); #endif + #if HAS_L64XX + SETUP_RUN(L64xxManager.init()); // Set up SPI, init drivers + #endif + #if HAS_TMC220x SETUP_RUN(tmc_serial_begin()); #endif @@ -992,7 +1099,7 @@ void setup() { if (mcu & RST_SOFTWARE) SERIAL_ECHOLNPGM(STR_SOFTWARE_RESET); HAL_clear_reset_source(); - serialprintPGM(GET_TEXT(MSG_MARLIN)); + SERIAL_ECHOPGM_P(GET_TEXT(MSG_MARLIN)); SERIAL_CHAR(' '); SERIAL_ECHOLNPGM(SHORT_BUILD_VERSION); SERIAL_EOL(); @@ -1121,6 +1228,86 @@ void setup() { SET_INPUT_PULLUP(HOME_PIN); #endif + #if ENABLED(CUSTOM_USER_BUTTONS) + #define INIT_CUSTOM_USER_BUTTON_PIN(N) do{ SET_INPUT(BUTTON##N##_PIN); WRITE(BUTTON##N##_PIN, !BUTTON##N##_HIT_STATE); }while(0) + + #if HAS_CUSTOM_USER_BUTTON(1) + INIT_CUSTOM_USER_BUTTON_PIN(1); + #endif + #if HAS_CUSTOM_USER_BUTTON(2) + INIT_CUSTOM_USER_BUTTON_PIN(2); + #endif + #if HAS_CUSTOM_USER_BUTTON(3) + INIT_CUSTOM_USER_BUTTON_PIN(3); + #endif + #if HAS_CUSTOM_USER_BUTTON(4) + INIT_CUSTOM_USER_BUTTON_PIN(4); + #endif + #if HAS_CUSTOM_USER_BUTTON(5) + INIT_CUSTOM_USER_BUTTON_PIN(5); + #endif + #if HAS_CUSTOM_USER_BUTTON(6) + INIT_CUSTOM_USER_BUTTON_PIN(6); + #endif + #if HAS_CUSTOM_USER_BUTTON(7) + INIT_CUSTOM_USER_BUTTON_PIN(7); + #endif + #if HAS_CUSTOM_USER_BUTTON(8) + INIT_CUSTOM_USER_BUTTON_PIN(8); + #endif + #if HAS_CUSTOM_USER_BUTTON(9) + INIT_CUSTOM_USER_BUTTON_PIN(9); + #endif + #if HAS_CUSTOM_USER_BUTTON(10) + INIT_CUSTOM_USER_BUTTON_PIN(10); + #endif + #if HAS_CUSTOM_USER_BUTTON(11) + INIT_CUSTOM_USER_BUTTON_PIN(11); + #endif + #if HAS_CUSTOM_USER_BUTTON(12) + INIT_CUSTOM_USER_BUTTON_PIN(12); + #endif + #if HAS_CUSTOM_USER_BUTTON(13) + INIT_CUSTOM_USER_BUTTON_PIN(13); + #endif + #if HAS_CUSTOM_USER_BUTTON(14) + INIT_CUSTOM_USER_BUTTON_PIN(14); + #endif + #if HAS_CUSTOM_USER_BUTTON(15) + INIT_CUSTOM_USER_BUTTON_PIN(15); + #endif + #if HAS_CUSTOM_USER_BUTTON(16) + INIT_CUSTOM_USER_BUTTON_PIN(16); + #endif + #if HAS_CUSTOM_USER_BUTTON(17) + INIT_CUSTOM_USER_BUTTON_PIN(17); + #endif + #if HAS_CUSTOM_USER_BUTTON(18) + INIT_CUSTOM_USER_BUTTON_PIN(18); + #endif + #if HAS_CUSTOM_USER_BUTTON(19) + INIT_CUSTOM_USER_BUTTON_PIN(19); + #endif + #if HAS_CUSTOM_USER_BUTTON(20) + INIT_CUSTOM_USER_BUTTON_PIN(20); + #endif + #if HAS_CUSTOM_USER_BUTTON(21) + INIT_CUSTOM_USER_BUTTON_PIN(21); + #endif + #if HAS_CUSTOM_USER_BUTTON(22) + INIT_CUSTOM_USER_BUTTON_PIN(22); + #endif + #if HAS_CUSTOM_USER_BUTTON(23) + INIT_CUSTOM_USER_BUTTON_PIN(23); + #endif + #if HAS_CUSTOM_USER_BUTTON(24) + INIT_CUSTOM_USER_BUTTON_PIN(24); + #endif + #if HAS_CUSTOM_USER_BUTTON(25) + INIT_CUSTOM_USER_BUTTON_PIN(25); + #endif + #endif + #if PIN_EXISTS(STAT_LED_RED) OUT_WRITE(STAT_LED_RED_PIN, LOW); // OFF #endif @@ -1130,10 +1317,7 @@ void setup() { #endif #if ENABLED(CASE_LIGHT_ENABLE) - #if DISABLED(CASE_LIGHT_USE_NEOPIXEL) - if (PWM_PIN(CASE_LIGHT_PIN)) SET_PWM(CASE_LIGHT_PIN); else SET_OUTPUT(CASE_LIGHT_PIN); - #endif - SETUP_RUN(caselight.update_brightness()); + SETUP_RUN(caselight.init()); #endif #if HAS_PRUSA_MMU1 diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h index 0f076b1b2aa7..cfde52ddb918 100644 --- a/Marlin/src/core/boards.h +++ b/Marlin/src/core/boards.h @@ -126,6 +126,7 @@ #define BOARD_EINSY_RAMBO 1203 // Einsy Rambo #define BOARD_EINSY_RETRO 1204 // Einsy Retro #define BOARD_SCOOVO_X9H 1205 // abee Scoovo X9H +#define BOARD_RAMBO_THINKERV2 1206 // ThinkerV2 // // Other ATmega1280, ATmega2560 @@ -327,7 +328,7 @@ #define BOARD_LONGER3D_LK 4034 // Alfawise U20/U20+/U30 (Longer3D LK1/2) / STM32F103VET6 #define BOARD_CCROBOT_MEEB_3DP 4035 // ccrobot-online.com MEEB_3DP (STM32F103RC) #define BOARD_CHITU3D_V5 4036 // Chitu3D TronXY X5SA V5 Board -#define BOARD_CHITU3D_V6 4037 // Chitu3D TronXY X5SA V5 Board +#define BOARD_CHITU3D_V6 4037 // Chitu3D TronXY X5SA V6 Board #define BOARD_CREALITY_V4 4038 // Creality v4.x (STM32F103RE) #define BOARD_CREALITY_V427 4039 // Creality v4.2.7 (STM32F103RE) #define BOARD_CREALITY_V4210 4040 // Creality v4.2.10 (STM32F103RE) as found in the CR-30 diff --git a/Marlin/src/core/bug_on.h b/Marlin/src/core/bug_on.h new file mode 100644 index 000000000000..8869be8d284f --- /dev/null +++ b/Marlin/src/core/bug_on.h @@ -0,0 +1,37 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Copyright (c) 2021 X-Ryl669 [https://blog.cyril.by] + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +// We need SERIAL_ECHOPAIR and macros.h +#include "serial.h" + +#if ENABLED(POSTMORTEM_DEBUGGING) + // Useful macro for stopping the CPU on an unexpected condition + // This is used like SERIAL_ECHOPAIR, that is: a key-value call of the local variables you want + // to dump to the serial port before stopping the CPU. + #define BUG_ON(V...) do { SERIAL_ECHOPAIR(ONLY_FILENAME, __LINE__, ": "); SERIAL_ECHOLNPAIR(V); SERIAL_FLUSHTX(); *(char*)0 = 42; } while(0) +#elif ENABLED(MARLIN_DEV_MODE) + // Don't stop the CPU here, but at least dump the bug on the serial port + #define BUG_ON(V...) do { SERIAL_ECHOPAIR(ONLY_FILENAME, __LINE__, ": BUG!\n"); SERIAL_ECHOLNPAIR(V); SERIAL_FLUSHTX(); } while(0) +#else + // Release mode, let's ignore the bug + #define BUG_ON(V...) NOOP +#endif diff --git a/Marlin/src/core/debug_out.h b/Marlin/src/core/debug_out.h index 6ae1b9d8bb97..d93decf7acc2 100644 --- a/Marlin/src/core/debug_out.h +++ b/Marlin/src/core/debug_out.h @@ -59,7 +59,7 @@ #include "debug_section.h" #define DEBUG_SECTION(N,S,D) SectionLog N(PSTR(S),D) - #define DEBUG_PRINT_P(P) serialprintPGM(P) + #define DEBUG_ECHOPGM_P(P) SERIAL_ECHOPGM_P(P) #define DEBUG_ECHO_START SERIAL_ECHO_START #define DEBUG_ERROR_START SERIAL_ERROR_START #define DEBUG_CHAR SERIAL_CHAR @@ -89,7 +89,7 @@ #else #define DEBUG_SECTION(...) NOOP - #define DEBUG_PRINT_P(P) NOOP + #define DEBUG_ECHOPGM_P(P) NOOP #define DEBUG_ECHO_START() NOOP #define DEBUG_ERROR_START() NOOP #define DEBUG_CHAR(...) NOOP diff --git a/Marlin/src/core/debug_section.h b/Marlin/src/core/debug_section.h index 7f39bc7424e7..2862d35af132 100644 --- a/Marlin/src/core/debug_section.h +++ b/Marlin/src/core/debug_section.h @@ -38,10 +38,10 @@ class SectionLog { bool debug; void echo_msg(PGM_P const pre) { - serialprintPGM(pre); + SERIAL_ECHOPGM_P(pre); if (the_msg) { SERIAL_CHAR(' '); - serialprintPGM(the_msg); + SERIAL_ECHOPGM_P(the_msg); } SERIAL_CHAR(' '); print_xyz(current_position); diff --git a/Marlin/src/core/language.h b/Marlin/src/core/language.h index 923ad903cb55..c9c3fd015341 100644 --- a/Marlin/src/core/language.h +++ b/Marlin/src/core/language.h @@ -131,6 +131,7 @@ #define STR_WATCHDOG_FIRED "Watchdog timeout. Reset required." #define STR_ERR_KILLED "Printer halted. kill() called!" #define STR_ERR_STOPPED "Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)" +#define STR_ERR_SERIAL_MISMATCH "Serial status mismatch" #define STR_BUSY_PROCESSING "busy: processing" #define STR_BUSY_PAUSED_FOR_USER "busy: paused for user" #define STR_BUSY_PAUSED_FOR_INPUT "busy: paused for input" @@ -221,7 +222,7 @@ // temperature.cpp strings #define STR_PID_AUTOTUNE_START "PID Autotune start" -#define STR_PID_BAD_EXTRUDER_NUM "PID Autotune failed! Bad extruder number" +#define STR_PID_BAD_HEATER_ID "PID Autotune failed! Bad heater id" #define STR_PID_TEMP_TOO_HIGH "PID Autotune failed! Temperature too high" #define STR_PID_TIMEOUT "PID Autotune failed! timeout" #define STR_BIAS " bias: " diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 16e18ac9023d..d7043ba5234d 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -104,6 +104,7 @@ #define RADIANS(d) ((d)*float(M_PI)/180.0f) #define DEGREES(r) ((r)*180.0f/float(M_PI)) #define HYPOT2(x,y) (sq(x)+sq(y)) +#define NORMSQ(x,y,z) (sq(x)+sq(y)+sq(z)) #define CIRCLE_AREA(R) (float(M_PI) * sq(float(R))) #define CIRCLE_CIRC(R) (2 * float(M_PI) * float(R)) @@ -349,6 +350,31 @@ #define CALL_IF_EXISTS(Return, That, Method, ...) \ static_cast(Private::Call_ ## Method(That, ##__VA_ARGS__)) + // Compile-time string manipulation + namespace CompileTimeString { + // Simple compile-time parser to find the position of the end of a string + constexpr const char* findStringEnd(const char *str) { + return *str ? findStringEnd(str + 1) : str; + } + + // Check whether a string contains a slash + constexpr bool containsSlash(const char *str) { + return *str == '/' ? true : (*str ? containsSlash(str + 1) : false); + } + // Find the last position of the slash + constexpr const char* findLastSlashPos(const char* str) { + return *str == '/' ? (str + 1) : findLastSlashPos(str - 1); + } + // Compile-time evaluation of the last part of a file path + // Typically used to shorten the path to file in compiled strings + // CompileTimeString::baseName(__FILE__) returns "macros.h" and not /path/to/Marlin/src/core/macros.h + constexpr const char* baseName(const char* str) { + return containsSlash(str) ? findLastSlashPos(findStringEnd(str)) : str; + } + } + + #define ONLY_FILENAME CompileTimeString::baseName(__FILE__) + #else #define MIN_2(a,b) ((a)<(b)?(a):(b)) diff --git a/Marlin/src/core/serial.cpp b/Marlin/src/core/serial.cpp index 31f6d67e326e..01f850ba566b 100644 --- a/Marlin/src/core/serial.cpp +++ b/Marlin/src/core/serial.cpp @@ -52,6 +52,10 @@ PGMSTR(SP_X_LBL, " X:"); PGMSTR(SP_Y_LBL, " Y:"); PGMSTR(SP_Z_LBL, " Z:"); PGMST #endif #endif +#if ENABLED(MEATPACK) + MeatpackSerial mpSerial(false, _SERIAL_IMPL); +#endif + void serialprintPGM(PGM_P str) { while (const char c = pgm_read_byte(str++)) SERIAL_CHAR(c); } diff --git a/Marlin/src/core/serial.h b/Marlin/src/core/serial.h index c422f8e25b26..ec955a8deab9 100644 --- a/Marlin/src/core/serial.h +++ b/Marlin/src/core/serial.h @@ -24,6 +24,10 @@ #include "../inc/MarlinConfig.h" #include "serial_hook.h" +#if ENABLED(MEATPACK) + #include "../feature/meatpack.h" +#endif + // Commonly-used strings in serial output extern const char NUL_STR[], SP_P_STR[], SP_T_STR[], X_STR[], Y_STR[], Z_STR[], E_STR[], @@ -58,10 +62,10 @@ extern uint8_t marlin_debug_flags; // // Serial redirection // -typedef int8_t serial_index_t; #define SERIAL_ALL 0x7F #if HAS_MULTI_SERIAL #define _PORT_REDIRECT(n,p) REMEMBER(n,multiSerial.portMask,p) + #define _PORT_RESTORE(n,p) RESTORE(n) #define SERIAL_ASSERT(P) if(multiSerial.portMask!=(P)){ debugger(); } #ifdef SERIAL_CATCHALL typedef MultiSerial SerialOutputT; @@ -69,16 +73,25 @@ typedef int8_t serial_index_t; typedef MultiSerial, decltype(MYSERIAL1)), 0> SerialOutputT; #endif extern SerialOutputT multiSerial; - #define SERIAL_IMPL multiSerial + #define _SERIAL_IMPL multiSerial #else #define _PORT_REDIRECT(n,p) NOOP + #define _PORT_RESTORE(n) NOOP #define SERIAL_ASSERT(P) NOOP - #define SERIAL_IMPL MYSERIAL0 + #define _SERIAL_IMPL MYSERIAL0 +#endif + +#if ENABLED(MEATPACK) + extern MeatpackSerial mpSerial; + #define SERIAL_IMPL mpSerial +#else + #define SERIAL_IMPL _SERIAL_IMPL #endif #define SERIAL_OUT(WHAT, V...) (void)SERIAL_IMPL.WHAT(V) #define PORT_REDIRECT(p) _PORT_REDIRECT(1,p) +#define PORT_RESTORE() _PORT_RESTORE(1) #define SERIAL_PORTMASK(P) _BV(P) // @@ -292,7 +305,7 @@ void serialprintPGM(PGM_P str); #endif #define SERIAL_ECHOPGM_P(P) (serialprintPGM(P)) -#define SERIAL_ECHOLNPGM_P(P) (serialprintPGM(P "\n")) +#define SERIAL_ECHOLNPGM_P(P) do{ serialprintPGM(P); SERIAL_EOL(); }while(0) #define SERIAL_ECHOPGM(S) (serialprintPGM(PSTR(S))) #define SERIAL_ECHOLNPGM(S) (serialprintPGM(PSTR(S "\n"))) diff --git a/Marlin/src/core/serial_base.h b/Marlin/src/core/serial_base.h index 81403b55f29e..418bb557e7cb 100644 --- a/Marlin/src/core/serial_base.h +++ b/Marlin/src/core/serial_base.h @@ -29,7 +29,7 @@ #endif // flushTX is not implemented in all HAL, so use SFINAE to call the method where it is. -CALL_IF_EXISTS_IMPL(void, flushTX ); +CALL_IF_EXISTS_IMPL(void, flushTX); CALL_IF_EXISTS_IMPL(bool, connected, true); // In order to catch usage errors in code, we make the base to encode number explicit @@ -42,14 +42,14 @@ enum class PrintBase { Bin = 2 }; -// A simple forward struct that prevent the compiler to select print(double, int) as a default overload for any type different than +// A simple forward struct that prevent the compiler to select print(double, int) as a default overload for any type different than // double or float. For double or float, a conversion exists so the call will be transparent struct EnsureDouble { double a; FORCE_INLINE operator double() { return a; } // If the compiler breaks on ambiguity here, it's likely because you're calling print(X, base) with X not a double or a float, and a // base that's not one of PrintBase's value. This exact code is made to detect such error, you NEED to set a base explicitely like this: - // SERIAL_PRINT(v, PrintBase::Hex) + // SERIAL_PRINT(v, PrintBase::Hex) FORCE_INLINE EnsureDouble(double a) : a(a) {} FORCE_INLINE EnsureDouble(float a) : a(a) {} }; @@ -79,7 +79,7 @@ struct SerialBase { void end() { static_cast(this)->end(); } /** Check for available data from the port @param index The port index, usually 0 */ - bool available(uint8_t index = 0) { return static_cast(this)->available(index); } + int available(uint8_t index = 0) { return static_cast(this)->available(index); } /** Read a value from the port @param index The port index, usually 0 */ int read(uint8_t index = 0) { return static_cast(this)->read(index); } @@ -147,13 +147,13 @@ struct SerialBase { else write('0'); } void printNumber(signed long n, const uint8_t base) { - if (base == 10 && n < 0) { + if (base == 10 && n < 0) { n = -n; // This works because all platforms Marlin's builds on are using 2-complement encoding for negative number // On such CPU, changing the sign of a number is done by inverting the bits and adding one, so if n = 0x80000000 = -2147483648 then // -n = 0x7FFFFFFF + 1 => 0x80000000 = 2147483648 (if interpreted as unsigned) or -2147483648 if interpreted as signed. // On non 2-complement CPU, there would be no possible representation for 2147483648. - write('-'); - } + write('-'); + } printNumber((unsigned long)n , base); } diff --git a/Marlin/src/core/serial_hook.h b/Marlin/src/core/serial_hook.h index ad8ec12b6e95..afd43892c720 100644 --- a/Marlin/src/core/serial_hook.h +++ b/Marlin/src/core/serial_hook.h @@ -24,6 +24,9 @@ #include "macros.h" #include "serial_base.h" +// Used in multiple places +typedef int8_t serial_index_t; + // The most basic serial class: it dispatch to the base serial class with no hook whatsoever. This will compile to nothing but the base serial class template struct BaseSerial : public SerialBase< BaseSerial >, public SerialT { @@ -35,10 +38,11 @@ struct BaseSerial : public SerialBase< BaseSerial >, public SerialT { void msgDone() {} - bool available(uint8_t index) { return index == 0 && SerialT::available(); } - int read(uint8_t index) { return index == 0 ? SerialT::read() : -1; } - bool connected() { return CALL_IF_EXISTS(bool, static_cast(this), connected);; } - void flushTX() { CALL_IF_EXISTS(void, static_cast(this), flushTX); } + // We don't care about indices here, since if one can call us, it's the right index anyway + int available(uint8_t) { return (int)SerialT::available(); } + int read(uint8_t) { return (int)SerialT::read(); } + bool connected() { return CALL_IF_EXISTS(bool, static_cast(this), connected);; } + void flushTX() { CALL_IF_EXISTS(void, static_cast(this), flushTX); } // We have 2 implementation of the same method in both base class, let's say which one we want using SerialT::available; @@ -65,18 +69,19 @@ struct ConditionalSerial : public SerialBase< ConditionalSerial > { bool & condition; SerialT & out; NO_INLINE size_t write(uint8_t c) { if (condition) return out.write(c); return 0; } - void flush() { if (condition) out.flush(); } - void begin(long br) { out.begin(br); } - void end() { out.end(); } + void flush() { if (condition) out.flush(); } + void begin(long br) { out.begin(br); } + void end() { out.end(); } void msgDone() {} - bool connected() { return CALL_IF_EXISTS(bool, &out, connected); } - void flushTX() { CALL_IF_EXISTS(void, &out, flushTX); } + bool connected() { return CALL_IF_EXISTS(bool, &out, connected); } + void flushTX() { CALL_IF_EXISTS(void, &out, flushTX); } + + int available(uint8_t ) { return (int)out.available(); } + int read(uint8_t ) { return (int)out.read(); } + int available() { return (int)out.available(); } + int read() { return (int)out.read(); } - bool available(uint8_t index) { return index == 0 && out.available(); } - int read(uint8_t index) { return index == 0 ? out.read() : -1; } - using BaseClassT::available; - using BaseClassT::read; ConditionalSerial(bool & conditionVariable, SerialT & out, const bool e) : BaseClassT(e), condition(conditionVariable), out(out) {} }; @@ -97,10 +102,10 @@ struct ForwardSerial : public SerialBase< ForwardSerial > { bool connected() { return Private::HasMember_connected::value ? CALL_IF_EXISTS(bool, &out, connected) : (bool)out; } void flushTX() { CALL_IF_EXISTS(void, &out, flushTX); } - bool available(uint8_t index) { return index == 0 && out.available(); } - int read(uint8_t index) { return index == 0 ? out.read() : -1; } - bool available() { return out.available(); } - int read() { return out.read(); } + int available(uint8_t) { return (int)out.available(); } + int read(uint8_t) { return (int)out.read(); } + int available() { return (int)out.available(); } + int read() { return (int)out.read(); } ForwardSerial(const bool e, SerialT & out) : BaseClassT(e), out(out) {} }; @@ -125,8 +130,8 @@ struct RuntimeSerial : public SerialBase< RuntimeSerial >, public Seria if (eofHook) eofHook(userPointer); } - bool available(uint8_t index) { return index == 0 && SerialT::available(); } - int read(uint8_t index) { return index == 0 ? SerialT::read() : -1; } + int available(uint8_t) { return (int)SerialT::available(); } + int read(uint8_t) { return (int)SerialT::read(); } using SerialT::available; using SerialT::read; using SerialT::flush; @@ -157,21 +162,22 @@ struct RuntimeSerial : public SerialBase< RuntimeSerial >, public Seria // Forward constructor template - RuntimeSerial(const bool e, Args... args) : BaseClassT(e), SerialT(args...) {} + RuntimeSerial(const bool e, Args... args) : BaseClassT(e), SerialT(args...), writeHook(0), eofHook(0), userPointer(0) {} }; // A class that's duplicating its output conditionally to 2 serial interface -template -struct MultiSerial : public SerialBase< MultiSerial > { - typedef SerialBase< MultiSerial > BaseClassT; +template +struct MultiSerial : public SerialBase< MultiSerial > { + typedef SerialBase< MultiSerial > BaseClassT; uint8_t portMask; Serial0T & serial0; Serial1T & serial1; enum Masks { - FirstOutputMask = (1 << offset), - SecondOutputMask = (1 << (offset + 1)), + UsageMask = ((1 << step) - 1), // A bit mask containing as many bits as step + FirstOutputMask = (UsageMask << offset), + SecondOutputMask = (UsageMask << (offset + step)), AllMask = FirstOutputMask | SecondOutputMask, }; @@ -185,19 +191,19 @@ struct MultiSerial : public SerialBase< MultiSerial if (portMask & FirstOutputMask) serial0.msgDone(); if (portMask & SecondOutputMask) serial1.msgDone(); } - bool available(uint8_t index) { - switch(index) { - case 0 + offset: return serial0.available(); - case 1 + offset: return serial1.available(); - default: return false; - } + int available(uint8_t index) { + if (index >= 0 + offset && index < step + offset) + return serial0.available(index); + else if (index >= step + offset && index < 2 * step + offset) + return serial1.available(index); + return false; } - NO_INLINE int read(uint8_t index) { - switch(index) { - case 0 + offset: return serial0.read(); - case 1 + offset: return serial1.read(); - default: return -1; - } + int read(uint8_t index) { + if (index >= 0 + offset && index < step + offset) + return serial0.read(index); + else if (index >= step + offset && index < 2 * step + offset) + return serial1.read(index); + return -1; } void begin(const long br) { if (portMask & FirstOutputMask) serial0.begin(br); diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp index f99956816778..3d7897f95a0a 100644 --- a/Marlin/src/core/utility.cpp +++ b/Marlin/src/core/utility.cpp @@ -92,9 +92,9 @@ void safe_delay(millis_t ms) { SERIAL_ECHOPGM(" (Aligned With"); if (probe.offset_xy.y > 0) - serialprintPGM(ENABLED(IS_SCARA) ? PSTR("-Distal") : PSTR("-Back")); + SERIAL_ECHOPGM_P(ENABLED(IS_SCARA) ? PSTR("-Distal") : PSTR("-Back")); else if (probe.offset_xy.y < 0) - serialprintPGM(ENABLED(IS_SCARA) ? PSTR("-Proximal") : PSTR("-Front")); + SERIAL_ECHOPGM_P(ENABLED(IS_SCARA) ? PSTR("-Proximal") : PSTR("-Front")); else if (probe.offset_xy.x != 0) SERIAL_ECHOPGM("-Center"); @@ -102,7 +102,7 @@ void safe_delay(millis_t ms) { #endif - serialprintPGM(probe.offset.z < 0 ? PSTR("Below") : probe.offset.z > 0 ? PSTR("Above") : PSTR("Same Z as")); + SERIAL_ECHOPGM_P(probe.offset.z < 0 ? PSTR("Below") : probe.offset.z > 0 ? PSTR("Above") : PSTR("Same Z as")); SERIAL_ECHOLNPGM(" Nozzle)"); #endif diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.cpp b/Marlin/src/feature/bedlevel/ubl/ubl.cpp index ef3289f73282..05b96daefa83 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl.cpp @@ -24,234 +24,234 @@ #if ENABLED(AUTO_BED_LEVELING_UBL) - #include "../bedlevel.h" +#include "../bedlevel.h" - unified_bed_leveling ubl; +unified_bed_leveling ubl; - #include "../../../MarlinCore.h" - #include "../../../gcode/gcode.h" +#include "../../../MarlinCore.h" +#include "../../../gcode/gcode.h" - #include "../../../module/settings.h" - #include "../../../module/planner.h" - #include "../../../module/motion.h" - #include "../../../module/probe.h" +#include "../../../module/settings.h" +#include "../../../module/planner.h" +#include "../../../module/motion.h" +#include "../../../module/probe.h" - #if ENABLED(EXTENSIBLE_UI) - #include "../../../lcd/extui/ui_api.h" - #endif - - #include "math.h" +#if ENABLED(EXTENSIBLE_UI) + #include "../../../lcd/extui/ui_api.h" +#endif - void unified_bed_leveling::echo_name() { SERIAL_ECHOPGM("Unified Bed Leveling"); } +#include "math.h" - void unified_bed_leveling::report_current_mesh() { - if (!leveling_is_valid()) return; - SERIAL_ECHO_MSG(" G29 I999"); - GRID_LOOP(x, y) - if (!isnan(z_values[x][y])) { - SERIAL_ECHO_START(); - SERIAL_ECHOPAIR(" M421 I", x, " J", y); - SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, z_values[x][y], 4); - serial_delay(75); // Prevent Printrun from exploding - } - } +void unified_bed_leveling::echo_name() { SERIAL_ECHOPGM("Unified Bed Leveling"); } - void unified_bed_leveling::report_state() { - echo_name(); - SERIAL_ECHO_TERNARY(planner.leveling_active, " System v" UBL_VERSION " ", "", "in", "active\n"); - serial_delay(50); +void unified_bed_leveling::report_current_mesh() { + if (!leveling_is_valid()) return; + SERIAL_ECHO_MSG(" G29 I999"); + GRID_LOOP(x, y) + if (!isnan(z_values[x][y])) { + SERIAL_ECHO_START(); + SERIAL_ECHOPAIR(" M421 I", x, " J", y); + SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, z_values[x][y], 4); + serial_delay(75); // Prevent Printrun from exploding + } +} + +void unified_bed_leveling::report_state() { + echo_name(); + SERIAL_ECHO_TERNARY(planner.leveling_active, " System v" UBL_VERSION " ", "", "in", "active\n"); + serial_delay(50); +} + +int8_t unified_bed_leveling::storage_slot; + +float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; + +#define _GRIDPOS(A,N) (MESH_MIN_##A + N * (MESH_##A##_DIST)) + +const float +unified_bed_leveling::_mesh_index_to_xpos[GRID_MAX_POINTS_X] PROGMEM = ARRAY_N(GRID_MAX_POINTS_X, + _GRIDPOS(X, 0), _GRIDPOS(X, 1), _GRIDPOS(X, 2), _GRIDPOS(X, 3), + _GRIDPOS(X, 4), _GRIDPOS(X, 5), _GRIDPOS(X, 6), _GRIDPOS(X, 7), + _GRIDPOS(X, 8), _GRIDPOS(X, 9), _GRIDPOS(X, 10), _GRIDPOS(X, 11), + _GRIDPOS(X, 12), _GRIDPOS(X, 13), _GRIDPOS(X, 14), _GRIDPOS(X, 15) +), +unified_bed_leveling::_mesh_index_to_ypos[GRID_MAX_POINTS_Y] PROGMEM = ARRAY_N(GRID_MAX_POINTS_Y, + _GRIDPOS(Y, 0), _GRIDPOS(Y, 1), _GRIDPOS(Y, 2), _GRIDPOS(Y, 3), + _GRIDPOS(Y, 4), _GRIDPOS(Y, 5), _GRIDPOS(Y, 6), _GRIDPOS(Y, 7), + _GRIDPOS(Y, 8), _GRIDPOS(Y, 9), _GRIDPOS(Y, 10), _GRIDPOS(Y, 11), + _GRIDPOS(Y, 12), _GRIDPOS(Y, 13), _GRIDPOS(Y, 14), _GRIDPOS(Y, 15) +); + +volatile int16_t unified_bed_leveling::encoder_diff; + +unified_bed_leveling::unified_bed_leveling() { reset(); } + +void unified_bed_leveling::reset() { + const bool was_enabled = planner.leveling_active; + set_bed_leveling_enabled(false); + storage_slot = -1; + ZERO(z_values); + #if ENABLED(EXTENSIBLE_UI) + GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0); + #endif + if (was_enabled) report_current_position(); +} + +void unified_bed_leveling::invalidate() { + set_bed_leveling_enabled(false); + set_all_mesh_points_to_value(NAN); +} + +void unified_bed_leveling::set_all_mesh_points_to_value(const float value) { + GRID_LOOP(x, y) { + z_values[x][y] = value; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, value)); } - - int8_t unified_bed_leveling::storage_slot; - - float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; - - #define _GRIDPOS(A,N) (MESH_MIN_##A + N * (MESH_##A##_DIST)) - - const float - unified_bed_leveling::_mesh_index_to_xpos[GRID_MAX_POINTS_X] PROGMEM = ARRAY_N(GRID_MAX_POINTS_X, - _GRIDPOS(X, 0), _GRIDPOS(X, 1), _GRIDPOS(X, 2), _GRIDPOS(X, 3), - _GRIDPOS(X, 4), _GRIDPOS(X, 5), _GRIDPOS(X, 6), _GRIDPOS(X, 7), - _GRIDPOS(X, 8), _GRIDPOS(X, 9), _GRIDPOS(X, 10), _GRIDPOS(X, 11), - _GRIDPOS(X, 12), _GRIDPOS(X, 13), _GRIDPOS(X, 14), _GRIDPOS(X, 15) - ), - unified_bed_leveling::_mesh_index_to_ypos[GRID_MAX_POINTS_Y] PROGMEM = ARRAY_N(GRID_MAX_POINTS_Y, - _GRIDPOS(Y, 0), _GRIDPOS(Y, 1), _GRIDPOS(Y, 2), _GRIDPOS(Y, 3), - _GRIDPOS(Y, 4), _GRIDPOS(Y, 5), _GRIDPOS(Y, 6), _GRIDPOS(Y, 7), - _GRIDPOS(Y, 8), _GRIDPOS(Y, 9), _GRIDPOS(Y, 10), _GRIDPOS(Y, 11), - _GRIDPOS(Y, 12), _GRIDPOS(Y, 13), _GRIDPOS(Y, 14), _GRIDPOS(Y, 15) - ); - - volatile int16_t unified_bed_leveling::encoder_diff; - - unified_bed_leveling::unified_bed_leveling() { reset(); } - - void unified_bed_leveling::reset() { - const bool was_enabled = planner.leveling_active; - set_bed_leveling_enabled(false); - storage_slot = -1; - ZERO(z_values); - #if ENABLED(EXTENSIBLE_UI) - GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0); - #endif - if (was_enabled) report_current_position(); +} + +#if ENABLED(OPTIMIZED_MESH_STORAGE) + + constexpr float mesh_store_scaling = 1000; + constexpr int16_t Z_STEPS_NAN = INT16_MAX; + + void unified_bed_leveling::set_store_from_mesh(const bed_mesh_t &in_values, mesh_store_t &stored_values) { + auto z_to_store = [](const float &z) { + if (isnan(z)) return Z_STEPS_NAN; + const int32_t z_scaled = TRUNC(z * mesh_store_scaling); + if (z_scaled == Z_STEPS_NAN || !WITHIN(z_scaled, INT16_MIN, INT16_MAX)) + return Z_STEPS_NAN; // If Z is out of range, return our custom 'NaN' + return int16_t(z_scaled); + }; + GRID_LOOP(x, y) stored_values[x][y] = z_to_store(in_values[x][y]); } - void unified_bed_leveling::invalidate() { - set_bed_leveling_enabled(false); - set_all_mesh_points_to_value(NAN); + void unified_bed_leveling::set_mesh_from_store(const mesh_store_t &stored_values, bed_mesh_t &out_values) { + auto store_to_z = [](const int16_t z_scaled) { + return z_scaled == Z_STEPS_NAN ? NAN : z_scaled / mesh_store_scaling; + }; + GRID_LOOP(x, y) out_values[x][y] = store_to_z(stored_values[x][y]); } - void unified_bed_leveling::set_all_mesh_points_to_value(const float value) { - GRID_LOOP(x, y) { - z_values[x][y] = value; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, value)); - } +#endif // OPTIMIZED_MESH_STORAGE + +static void serial_echo_xy(const uint8_t sp, const int16_t x, const int16_t y) { + SERIAL_ECHO_SP(sp); + SERIAL_CHAR('('); + if (x < 100) { SERIAL_CHAR(' '); if (x < 10) SERIAL_CHAR(' '); } + SERIAL_ECHO(x); + SERIAL_CHAR(','); + if (y < 100) { SERIAL_CHAR(' '); if (y < 10) SERIAL_CHAR(' '); } + SERIAL_ECHO(y); + SERIAL_CHAR(')'); + serial_delay(5); +} + +static void serial_echo_column_labels(const uint8_t sp) { + SERIAL_ECHO_SP(7); + LOOP_L_N(i, GRID_MAX_POINTS_X) { + if (i < 10) SERIAL_CHAR(' '); + SERIAL_ECHO(i); + SERIAL_ECHO_SP(sp); } + serial_delay(10); +} - #if ENABLED(OPTIMIZED_MESH_STORAGE) - - constexpr float mesh_store_scaling = 1000; - constexpr int16_t Z_STEPS_NAN = INT16_MAX; - - void unified_bed_leveling::set_store_from_mesh(const bed_mesh_t &in_values, mesh_store_t &stored_values) { - auto z_to_store = [](const float &z) { - if (isnan(z)) return Z_STEPS_NAN; - const int32_t z_scaled = TRUNC(z * mesh_store_scaling); - if (z_scaled == Z_STEPS_NAN || !WITHIN(z_scaled, INT16_MIN, INT16_MAX)) - return Z_STEPS_NAN; // If Z is out of range, return our custom 'NaN' - return int16_t(z_scaled); - }; - GRID_LOOP(x, y) stored_values[x][y] = z_to_store(in_values[x][y]); - } +/** + * Produce one of these mesh maps: + * 0: Human-readable + * 1: CSV format for spreadsheet import + * 2: TODO: Display on Graphical LCD + * 4: Compact Human-Readable + */ +void unified_bed_leveling::display_map(const int map_type) { + const bool was = gcode.set_autoreport_paused(true); - void unified_bed_leveling::set_mesh_from_store(const mesh_store_t &stored_values, bed_mesh_t &out_values) { - auto store_to_z = [](const int16_t z_scaled) { - return z_scaled == Z_STEPS_NAN ? NAN : z_scaled / mesh_store_scaling; - }; - GRID_LOOP(x, y) out_values[x][y] = store_to_z(stored_values[x][y]); - } + constexpr uint8_t eachsp = 1 + 6 + 1, // [-3.567] + twixt = eachsp * (GRID_MAX_POINTS_X) - 9 * 2; // Leading 4sp, Coordinates 9sp each - #endif // OPTIMIZED_MESH_STORAGE + const bool human = !(map_type & 0x3), csv = map_type == 1, lcd = map_type == 2, comp = map_type & 0x4; - static void serial_echo_xy(const uint8_t sp, const int16_t x, const int16_t y) { - SERIAL_ECHO_SP(sp); - SERIAL_CHAR('('); - if (x < 100) { SERIAL_CHAR(' '); if (x < 10) SERIAL_CHAR(' '); } - SERIAL_ECHO(x); - SERIAL_CHAR(','); - if (y < 100) { SERIAL_CHAR(' '); if (y < 10) SERIAL_CHAR(' '); } - SERIAL_ECHO(y); - SERIAL_CHAR(')'); - serial_delay(5); + SERIAL_ECHOPGM("\nBed Topography Report"); + if (human) { + SERIAL_ECHOLNPGM(":\n"); + serial_echo_xy(4, MESH_MIN_X, MESH_MAX_Y); + serial_echo_xy(twixt, MESH_MAX_X, MESH_MAX_Y); + SERIAL_EOL(); + serial_echo_column_labels(eachsp - 2); } - - static void serial_echo_column_labels(const uint8_t sp) { - SERIAL_ECHO_SP(7); - LOOP_L_N(i, GRID_MAX_POINTS_X) { - if (i < 10) SERIAL_CHAR(' '); - SERIAL_ECHO(i); - SERIAL_ECHO_SP(sp); - } - serial_delay(10); + else { + SERIAL_ECHOPGM(" for "); + SERIAL_ECHOPGM_P(csv ? PSTR("CSV:\n") : PSTR("LCD:\n")); } - /** - * Produce one of these mesh maps: - * 0: Human-readable - * 1: CSV format for spreadsheet import - * 2: TODO: Display on Graphical LCD - * 4: Compact Human-Readable - */ - void unified_bed_leveling::display_map(const int map_type) { - const bool was = gcode.set_autoreport_paused(true); + // Add XY probe offset from extruder because probe.probe_at_point() subtracts them when + // moving to the XY position to be measured. This ensures better agreement between + // the current Z position after G28 and the mesh values. + const xy_int8_t curr = closest_indexes(xy_pos_t(current_position) + probe.offset_xy); - constexpr uint8_t eachsp = 1 + 6 + 1, // [-3.567] - twixt = eachsp * (GRID_MAX_POINTS_X) - 9 * 2; // Leading 4sp, Coordinates 9sp each + if (!lcd) SERIAL_EOL(); + for (int8_t j = GRID_MAX_POINTS_Y - 1; j >= 0; j--) { - const bool human = !(map_type & 0x3), csv = map_type == 1, lcd = map_type == 2, comp = map_type & 0x4; - - SERIAL_ECHOPGM("\nBed Topography Report"); + // Row Label (J index) if (human) { - SERIAL_ECHOLNPGM(":\n"); - serial_echo_xy(4, MESH_MIN_X, MESH_MAX_Y); - serial_echo_xy(twixt, MESH_MAX_X, MESH_MAX_Y); - SERIAL_EOL(); - serial_echo_column_labels(eachsp - 2); - } - else { - SERIAL_ECHOPGM(" for "); - serialprintPGM(csv ? PSTR("CSV:\n") : PSTR("LCD:\n")); + if (j < 10) SERIAL_CHAR(' '); + SERIAL_ECHO(j); + SERIAL_ECHOPGM(" |"); } - // Add XY probe offset from extruder because probe.probe_at_point() subtracts them when - // moving to the XY position to be measured. This ensures better agreement between - // the current Z position after G28 and the mesh values. - const xy_int8_t curr = closest_indexes(xy_pos_t(current_position) + probe.offset_xy); + // Row Values (I indexes) + LOOP_L_N(i, GRID_MAX_POINTS_X) { - if (!lcd) SERIAL_EOL(); - for (int8_t j = GRID_MAX_POINTS_Y - 1; j >= 0; j--) { + // Opening Brace or Space + const bool is_current = i == curr.x && j == curr.y; + if (human) SERIAL_CHAR(is_current ? '[' : ' '); - // Row Label (J index) - if (human) { - if (j < 10) SERIAL_CHAR(' '); - SERIAL_ECHO(j); - SERIAL_ECHOPGM(" |"); + // Z Value at current I, J + const float f = z_values[i][j]; + if (lcd) { + // TODO: Display on Graphical LCD } - - // Row Values (I indexes) - LOOP_L_N(i, GRID_MAX_POINTS_X) { - - // Opening Brace or Space - const bool is_current = i == curr.x && j == curr.y; - if (human) SERIAL_CHAR(is_current ? '[' : ' '); - - // Z Value at current I, J - const float f = z_values[i][j]; - if (lcd) { - // TODO: Display on Graphical LCD - } - else if (isnan(f)) - serialprintPGM(human ? PSTR(" . ") : PSTR("NAN")); - else if (human || csv) { - if (human && f >= 0.0) SERIAL_CHAR(f > 0 ? '+' : ' '); // Display sign also for positive numbers (' ' for 0) - SERIAL_ECHO_F(f, 3); // Positive: 5 digits, Negative: 6 digits - } - if (csv && i < GRID_MAX_POINTS_X - 1) SERIAL_CHAR('\t'); - - // Closing Brace or Space - if (human) SERIAL_CHAR(is_current ? ']' : ' '); - - SERIAL_FLUSHTX(); - idle_no_sleep(); + else if (isnan(f)) + SERIAL_ECHOPGM_P(human ? PSTR(" . ") : PSTR("NAN")); + else if (human || csv) { + if (human && f >= 0.0) SERIAL_CHAR(f > 0 ? '+' : ' '); // Display sign also for positive numbers (' ' for 0) + SERIAL_ECHO_F(f, 3); // Positive: 5 digits, Negative: 6 digits } - if (!lcd) SERIAL_EOL(); + if (csv && i < GRID_MAX_POINTS_X - 1) SERIAL_CHAR('\t'); - // A blank line between rows (unless compact) - if (j && human && !comp) SERIAL_ECHOLNPGM(" |"); - } + // Closing Brace or Space + if (human) SERIAL_CHAR(is_current ? ']' : ' '); - if (human) { - serial_echo_column_labels(eachsp - 2); - SERIAL_EOL(); - serial_echo_xy(4, MESH_MIN_X, MESH_MIN_Y); - serial_echo_xy(twixt, MESH_MAX_X, MESH_MIN_Y); - SERIAL_EOL(); - SERIAL_EOL(); + SERIAL_FLUSHTX(); + idle_no_sleep(); } + if (!lcd) SERIAL_EOL(); - gcode.set_autoreport_paused(was); + // A blank line between rows (unless compact) + if (j && human && !comp) SERIAL_ECHOLNPGM(" |"); } - bool unified_bed_leveling::sanity_check() { - uint8_t error_flag = 0; + if (human) { + serial_echo_column_labels(eachsp - 2); + SERIAL_EOL(); + serial_echo_xy(4, MESH_MIN_X, MESH_MIN_Y); + serial_echo_xy(twixt, MESH_MAX_X, MESH_MIN_Y); + SERIAL_EOL(); + SERIAL_EOL(); + } - if (settings.calc_num_meshes() < 1) { - SERIAL_ECHOLNPGM("?Mesh too big for EEPROM."); - error_flag++; - } + gcode.set_autoreport_paused(was); +} - return !!error_flag; +bool unified_bed_leveling::sanity_check() { + uint8_t error_flag = 0; + + if (settings.calc_num_meshes() < 1) { + SERIAL_ECHOLNPGM("?Mesh too big for EEPROM."); + error_flag++; } + return !!error_flag; +} + #endif // AUTO_BED_LEVELING_UBL diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.h b/Marlin/src/feature/bedlevel/ubl/ubl.h index 876063c8787c..d5da43a6a26a 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.h +++ b/Marlin/src/feature/bedlevel/ubl/ubl.h @@ -46,275 +46,275 @@ struct mesh_index_pair; #endif class unified_bed_leveling { - private: - - static int g29_verbose_level, - g29_phase_value, - g29_repetition_cnt, - g29_storage_slot, - g29_map_type; - static bool g29_c_flag; - static float g29_card_thickness, - g29_constant; - static xy_pos_t g29_pos; - static xy_bool_t xy_seen; - - #if HAS_BED_PROBE - static int g29_grid_size; - #endif - - #if IS_NEWPANEL - static void move_z_with_encoder(const float &multiplier); - static float measure_point_with_encoder(); - static float measure_business_card_thickness(); - static void manually_probe_remaining_mesh(const xy_pos_t&, const float&, const float&, const bool) _O0; - static void fine_tune_mesh(const xy_pos_t &pos, const bool do_ubl_mesh_map) _O0; - #endif +private: + + static int g29_verbose_level, + g29_phase_value, + g29_repetition_cnt, + g29_storage_slot, + g29_map_type; + static bool g29_c_flag; + static float g29_card_thickness, + g29_constant; + static xy_pos_t g29_pos; + static xy_bool_t xy_seen; + + #if HAS_BED_PROBE + static int g29_grid_size; + #endif + + #if IS_NEWPANEL + static void move_z_with_encoder(const float &multiplier); + static float measure_point_with_encoder(); + static float measure_business_card_thickness(); + static void manually_probe_remaining_mesh(const xy_pos_t&, const float&, const float&, const bool) _O0; + static void fine_tune_mesh(const xy_pos_t &pos, const bool do_ubl_mesh_map) _O0; + #endif + + static bool g29_parameter_parsing() _O0; + static void shift_mesh_height(); + static void probe_entire_mesh(const xy_pos_t &near, const bool do_ubl_mesh_map, const bool stow_probe, const bool do_furthest) _O0; + static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3); + static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map); + static bool smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir); + static inline bool smart_fill_one(const xy_uint8_t &pos, const xy_uint8_t &dir) { + return smart_fill_one(pos.x, pos.y, dir.x, dir.y); + } + static void smart_fill_mesh(); + + #if ENABLED(UBL_DEVEL_DEBUGGING) + static void g29_what_command(); + static void g29_eeprom_dump(); + static void g29_compare_current_mesh_to_stored_mesh(); + #endif + +public: + + static void echo_name(); + static void report_current_mesh(); + static void report_state(); + static void save_ubl_active_state_and_disable(); + static void restore_ubl_active_state_and_leave(); + static void display_map(const int) _O0; + static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const xy_pos_t&, const bool=false, MeshFlags *done_flags=nullptr) _O0; + static mesh_index_pair find_furthest_invalid_mesh_point() _O0; + static void reset(); + static void invalidate(); + static void set_all_mesh_points_to_value(const float value); + static void adjust_mesh_to_mean(const bool cflag, const float value); + static bool sanity_check(); + + static void G29() _O0; // O0 for no optimization + static void smart_fill_wlsf(const float &) _O2; // O2 gives smaller code than Os on A2560 + + static int8_t storage_slot; + + static bed_mesh_t z_values; + #if ENABLED(OPTIMIZED_MESH_STORAGE) + static void set_store_from_mesh(const bed_mesh_t &in_values, mesh_store_t &stored_values); + static void set_mesh_from_store(const mesh_store_t &stored_values, bed_mesh_t &out_values); + #endif + static const float _mesh_index_to_xpos[GRID_MAX_POINTS_X], + _mesh_index_to_ypos[GRID_MAX_POINTS_Y]; + + #if HAS_LCD_MENU + static bool lcd_map_control; + static void steppers_were_disabled(); + #else + static inline void steppers_were_disabled() {} + #endif + + static volatile int16_t encoder_diff; // Volatile because buttons may changed it at interrupt time + + unified_bed_leveling(); + + FORCE_INLINE static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; } + + static int8_t cell_index_x_raw(const float &x) { + return FLOOR((x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST)); + } + + static int8_t cell_index_y_raw(const float &y) { + return FLOOR((y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST)); + } + + static int8_t cell_index_x_valid(const float &x) { + return WITHIN(cell_index_x_raw(x), 0, (GRID_MAX_POINTS_X - 2)); + } + + static int8_t cell_index_y_valid(const float &y) { + return WITHIN(cell_index_y_raw(y), 0, (GRID_MAX_POINTS_Y - 2)); + } + + static int8_t cell_index_x(const float &x) { + return constrain(cell_index_x_raw(x), 0, (GRID_MAX_POINTS_X) - 2); + } + + static int8_t cell_index_y(const float &y) { + return constrain(cell_index_y_raw(y), 0, (GRID_MAX_POINTS_Y) - 2); + } + + static inline xy_int8_t cell_indexes(const float &x, const float &y) { + return { cell_index_x(x), cell_index_y(y) }; + } + static inline xy_int8_t cell_indexes(const xy_pos_t &xy) { return cell_indexes(xy.x, xy.y); } + + static int8_t closest_x_index(const float &x) { + const int8_t px = (x - (MESH_MIN_X) + (MESH_X_DIST) * 0.5) * RECIPROCAL(MESH_X_DIST); + return WITHIN(px, 0, GRID_MAX_POINTS_X - 1) ? px : -1; + } + static int8_t closest_y_index(const float &y) { + const int8_t py = (y - (MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * RECIPROCAL(MESH_Y_DIST); + return WITHIN(py, 0, GRID_MAX_POINTS_Y - 1) ? py : -1; + } + static inline xy_int8_t closest_indexes(const xy_pos_t &xy) { + return { closest_x_index(xy.x), closest_y_index(xy.y) }; + } + + /** + * z2 --| + * z0 | | + * | | + (z2-z1) + * z1 | | | + * ---+-------------+--------+-- --| + * a1 a0 a2 + * |<---delta_a---------->| + * + * calc_z0 is the basis for all the Mesh Based correction. It is used to + * find the expected Z Height at a position between two known Z-Height locations. + * + * It is fairly expensive with its 4 floating point additions and 2 floating point + * multiplications. + */ + FORCE_INLINE static float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) { + return z1 + (z2 - z1) * (a0 - a1) / (a2 - a1); + } + + #ifdef UBL_Z_RAISE_WHEN_OFF_MESH + #define _UBL_OUTER_Z_RAISE UBL_Z_RAISE_WHEN_OFF_MESH + #else + #define _UBL_OUTER_Z_RAISE NAN + #endif + + /** + * z_correction_for_x_on_horizontal_mesh_line is an optimization for + * the case where the printer is making a vertical line that only crosses horizontal mesh lines. + */ + static inline float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) { + if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) { + + if (DEBUGGING(LEVELING)) { + if (WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1)) DEBUG_ECHOPGM("yi"); else DEBUG_ECHOPGM("x1_i"); + DEBUG_ECHOLNPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0, ",x1_i=", x1_i, ",yi=", yi, ")"); + } - static bool g29_parameter_parsing() _O0; - static void shift_mesh_height(); - static void probe_entire_mesh(const xy_pos_t &near, const bool do_ubl_mesh_map, const bool stow_probe, const bool do_furthest) _O0; - static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3); - static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map); - static bool smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir); - static inline bool smart_fill_one(const xy_uint8_t &pos, const xy_uint8_t &dir) { - return smart_fill_one(pos.x, pos.y, dir.x, dir.y); + // The requested location is off the mesh. Return UBL_Z_RAISE_WHEN_OFF_MESH or NAN. + return _UBL_OUTER_Z_RAISE; } - static void smart_fill_mesh(); - - #if ENABLED(UBL_DEVEL_DEBUGGING) - static void g29_what_command(); - static void g29_eeprom_dump(); - static void g29_compare_current_mesh_to_stored_mesh(); - #endif - public: - - static void echo_name(); - static void report_current_mesh(); - static void report_state(); - static void save_ubl_active_state_and_disable(); - static void restore_ubl_active_state_and_leave(); - static void display_map(const int) _O0; - static mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType, const xy_pos_t&, const bool=false, MeshFlags *done_flags=nullptr) _O0; - static mesh_index_pair find_furthest_invalid_mesh_point() _O0; - static void reset(); - static void invalidate(); - static void set_all_mesh_points_to_value(const float value); - static void adjust_mesh_to_mean(const bool cflag, const float value); - static bool sanity_check(); - - static void G29() _O0; // O0 for no optimization - static void smart_fill_wlsf(const float &) _O2; // O2 gives smaller code than Os on A2560 - - static int8_t storage_slot; - - static bed_mesh_t z_values; - #if ENABLED(OPTIMIZED_MESH_STORAGE) - static void set_store_from_mesh(const bed_mesh_t &in_values, mesh_store_t &stored_values); - static void set_mesh_from_store(const mesh_store_t &stored_values, bed_mesh_t &out_values); - #endif - static const float _mesh_index_to_xpos[GRID_MAX_POINTS_X], - _mesh_index_to_ypos[GRID_MAX_POINTS_Y]; - - #if HAS_LCD_MENU - static bool lcd_map_control; - static void steppers_were_disabled(); - #else - static inline void steppers_were_disabled() {} - #endif - - static volatile int16_t encoder_diff; // Volatile because buttons may changed it at interrupt time + const float xratio = (rx0 - mesh_index_to_xpos(x1_i)) * RECIPROCAL(MESH_X_DIST), + z1 = z_values[x1_i][yi]; - unified_bed_leveling(); + return z1 + xratio * (z_values[_MIN(x1_i, GRID_MAX_POINTS_X - 2) + 1][yi] - z1); // Don't allow x1_i+1 to be past the end of the array + // If it is, it is clamped to the last element of the + // z_values[][] array and no correction is applied. + } - FORCE_INLINE static void set_z(const int8_t px, const int8_t py, const float &z) { z_values[px][py] = z; } + // + // See comments above for z_correction_for_x_on_horizontal_mesh_line + // + static inline float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) { + if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 1)) { - static int8_t cell_index_x_raw(const float &x) { - return FLOOR((x - (MESH_MIN_X)) * RECIPROCAL(MESH_X_DIST)); - } - - static int8_t cell_index_y_raw(const float &y) { - return FLOOR((y - (MESH_MIN_Y)) * RECIPROCAL(MESH_Y_DIST)); - } - - static int8_t cell_index_x_valid(const float &x) { - return WITHIN(cell_index_x_raw(x), 0, (GRID_MAX_POINTS_X - 2)); - } + if (DEBUGGING(LEVELING)) { + if (WITHIN(xi, 0, GRID_MAX_POINTS_X - 1)) DEBUG_ECHOPGM("y1_i"); else DEBUG_ECHOPGM("xi"); + DEBUG_ECHOLNPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0, ", xi=", xi, ", y1_i=", y1_i, ")"); + } - static int8_t cell_index_y_valid(const float &y) { - return WITHIN(cell_index_y_raw(y), 0, (GRID_MAX_POINTS_Y - 2)); + // The requested location is off the mesh. Return UBL_Z_RAISE_WHEN_OFF_MESH or NAN. + return _UBL_OUTER_Z_RAISE; } - static int8_t cell_index_x(const float &x) { - return constrain(cell_index_x_raw(x), 0, (GRID_MAX_POINTS_X) - 2); - } + const float yratio = (ry0 - mesh_index_to_ypos(y1_i)) * RECIPROCAL(MESH_Y_DIST), + z1 = z_values[xi][y1_i]; - static int8_t cell_index_y(const float &y) { - return constrain(cell_index_y_raw(y), 0, (GRID_MAX_POINTS_Y) - 2); - } + return z1 + yratio * (z_values[xi][_MIN(y1_i, GRID_MAX_POINTS_Y - 2) + 1] - z1); // Don't allow y1_i+1 to be past the end of the array + // If it is, it is clamped to the last element of the + // z_values[][] array and no correction is applied. + } - static inline xy_int8_t cell_indexes(const float &x, const float &y) { - return { cell_index_x(x), cell_index_y(y) }; - } - static inline xy_int8_t cell_indexes(const xy_pos_t &xy) { return cell_indexes(xy.x, xy.y); } - - static int8_t closest_x_index(const float &x) { - const int8_t px = (x - (MESH_MIN_X) + (MESH_X_DIST) * 0.5) * RECIPROCAL(MESH_X_DIST); - return WITHIN(px, 0, GRID_MAX_POINTS_X - 1) ? px : -1; - } - static int8_t closest_y_index(const float &y) { - const int8_t py = (y - (MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * RECIPROCAL(MESH_Y_DIST); - return WITHIN(py, 0, GRID_MAX_POINTS_Y - 1) ? py : -1; - } - static inline xy_int8_t closest_indexes(const xy_pos_t &xy) { - return { closest_x_index(xy.x), closest_y_index(xy.y) }; - } + /** + * This is the generic Z-Correction. It works anywhere within a Mesh Cell. It first + * does a linear interpolation along both of the bounding X-Mesh-Lines to find the + * Z-Height at both ends. Then it does a linear interpolation of these heights based + * on the Y position within the cell. + */ + static float get_z_correction(const float &rx0, const float &ry0) { + const int8_t cx = cell_index_x(rx0), cy = cell_index_y(ry0); // return values are clamped /** - * z2 --| - * z0 | | - * | | + (z2-z1) - * z1 | | | - * ---+-------------+--------+-- --| - * a1 a0 a2 - * |<---delta_a---------->| - * - * calc_z0 is the basis for all the Mesh Based correction. It is used to - * find the expected Z Height at a position between two known Z-Height locations. - * - * It is fairly expensive with its 4 floating point additions and 2 floating point - * multiplications. + * Check if the requested location is off the mesh. If so, and + * UBL_Z_RAISE_WHEN_OFF_MESH is specified, that value is returned. */ - FORCE_INLINE static float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) { - return z1 + (z2 - z1) * (a0 - a1) / (a2 - a1); - } - #ifdef UBL_Z_RAISE_WHEN_OFF_MESH - #define _UBL_OUTER_Z_RAISE UBL_Z_RAISE_WHEN_OFF_MESH - #else - #define _UBL_OUTER_Z_RAISE NAN + if (!WITHIN(rx0, MESH_MIN_X, MESH_MAX_X) || !WITHIN(ry0, MESH_MIN_Y, MESH_MAX_Y)) + return UBL_Z_RAISE_WHEN_OFF_MESH; #endif - /** - * z_correction_for_x_on_horizontal_mesh_line is an optimization for - * the case where the printer is making a vertical line that only crosses horizontal mesh lines. - */ - static inline float z_correction_for_x_on_horizontal_mesh_line(const float &rx0, const int x1_i, const int yi) { - if (!WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(yi, 0, GRID_MAX_POINTS_Y - 1)) { - - if (DEBUGGING(LEVELING)) { - if (WITHIN(x1_i, 0, GRID_MAX_POINTS_X - 1)) DEBUG_ECHOPGM("yi"); else DEBUG_ECHOPGM("x1_i"); - DEBUG_ECHOLNPAIR(" out of bounds in z_correction_for_x_on_horizontal_mesh_line(rx0=", rx0, ",x1_i=", x1_i, ",yi=", yi, ")"); - } + const float z1 = calc_z0(rx0, + mesh_index_to_xpos(cx), z_values[cx][cy], + mesh_index_to_xpos(cx + 1), z_values[_MIN(cx, GRID_MAX_POINTS_X - 2) + 1][cy]); - // The requested location is off the mesh. Return UBL_Z_RAISE_WHEN_OFF_MESH or NAN. - return _UBL_OUTER_Z_RAISE; - } + const float z2 = calc_z0(rx0, + mesh_index_to_xpos(cx), z_values[cx][_MIN(cy, GRID_MAX_POINTS_Y - 2) + 1], + mesh_index_to_xpos(cx + 1), z_values[_MIN(cx, GRID_MAX_POINTS_X - 2) + 1][_MIN(cy, GRID_MAX_POINTS_Y - 2) + 1]); - const float xratio = (rx0 - mesh_index_to_xpos(x1_i)) * RECIPROCAL(MESH_X_DIST), - z1 = z_values[x1_i][yi]; + float z0 = calc_z0(ry0, + mesh_index_to_ypos(cy), z1, + mesh_index_to_ypos(cy + 1), z2); - return z1 + xratio * (z_values[_MIN(x1_i, GRID_MAX_POINTS_X - 2) + 1][yi] - z1); // Don't allow x1_i+1 to be past the end of the array - // If it is, it is clamped to the last element of the - // z_values[][] array and no correction is applied. + if (DEBUGGING(MESH_ADJUST)) { + DEBUG_ECHOPAIR(" raw get_z_correction(", rx0); + DEBUG_CHAR(','); DEBUG_ECHO(ry0); + DEBUG_ECHOPAIR_F(") = ", z0, 6); + DEBUG_ECHOLNPAIR_F(" >>>---> ", z0, 6); } - // - // See comments above for z_correction_for_x_on_horizontal_mesh_line - // - static inline float z_correction_for_y_on_vertical_mesh_line(const float &ry0, const int xi, const int y1_i) { - if (!WITHIN(xi, 0, GRID_MAX_POINTS_X - 1) || !WITHIN(y1_i, 0, GRID_MAX_POINTS_Y - 1)) { - - if (DEBUGGING(LEVELING)) { - if (WITHIN(xi, 0, GRID_MAX_POINTS_X - 1)) DEBUG_ECHOPGM("y1_i"); else DEBUG_ECHOPGM("xi"); - DEBUG_ECHOLNPAIR(" out of bounds in z_correction_for_y_on_vertical_mesh_line(ry0=", ry0, ", xi=", xi, ", y1_i=", y1_i, ")"); - } - - // The requested location is off the mesh. Return UBL_Z_RAISE_WHEN_OFF_MESH or NAN. - return _UBL_OUTER_Z_RAISE; - } - - const float yratio = (ry0 - mesh_index_to_ypos(y1_i)) * RECIPROCAL(MESH_Y_DIST), - z1 = z_values[xi][y1_i]; - - return z1 + yratio * (z_values[xi][_MIN(y1_i, GRID_MAX_POINTS_Y - 2) + 1] - z1); // Don't allow y1_i+1 to be past the end of the array - // If it is, it is clamped to the last element of the - // z_values[][] array and no correction is applied. - } - - /** - * This is the generic Z-Correction. It works anywhere within a Mesh Cell. It first - * does a linear interpolation along both of the bounding X-Mesh-Lines to find the - * Z-Height at both ends. Then it does a linear interpolation of these heights based - * on the Y position within the cell. - */ - static float get_z_correction(const float &rx0, const float &ry0) { - const int8_t cx = cell_index_x(rx0), cy = cell_index_y(ry0); // return values are clamped - - /** - * Check if the requested location is off the mesh. If so, and - * UBL_Z_RAISE_WHEN_OFF_MESH is specified, that value is returned. - */ - #ifdef UBL_Z_RAISE_WHEN_OFF_MESH - if (!WITHIN(rx0, MESH_MIN_X, MESH_MAX_X) || !WITHIN(ry0, MESH_MIN_Y, MESH_MAX_Y)) - return UBL_Z_RAISE_WHEN_OFF_MESH; - #endif - - const float z1 = calc_z0(rx0, - mesh_index_to_xpos(cx), z_values[cx][cy], - mesh_index_to_xpos(cx + 1), z_values[_MIN(cx, GRID_MAX_POINTS_X - 2) + 1][cy]); - - const float z2 = calc_z0(rx0, - mesh_index_to_xpos(cx), z_values[cx][_MIN(cy, GRID_MAX_POINTS_Y - 2) + 1], - mesh_index_to_xpos(cx + 1), z_values[_MIN(cx, GRID_MAX_POINTS_X - 2) + 1][_MIN(cy, GRID_MAX_POINTS_Y - 2) + 1]); - - float z0 = calc_z0(ry0, - mesh_index_to_ypos(cy), z1, - mesh_index_to_ypos(cy + 1), z2); + if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN + z0 = 0.0; // in ubl.z_values[][] and propagate through the + // calculations. If our correction is NAN, we throw it out + // because part of the Mesh is undefined and we don't have the + // information we need to complete the height correction. if (DEBUGGING(MESH_ADJUST)) { - DEBUG_ECHOPAIR(" raw get_z_correction(", rx0); - DEBUG_CHAR(','); DEBUG_ECHO(ry0); - DEBUG_ECHOPAIR_F(") = ", z0, 6); - DEBUG_ECHOLNPAIR_F(" >>>---> ", z0, 6); - } - - if (isnan(z0)) { // if part of the Mesh is undefined, it will show up as NAN - z0 = 0.0; // in ubl.z_values[][] and propagate through the - // calculations. If our correction is NAN, we throw it out - // because part of the Mesh is undefined and we don't have the - // information we need to complete the height correction. - - if (DEBUGGING(MESH_ADJUST)) { - DEBUG_ECHOPAIR("??? Yikes! NAN in get_z_correction(", rx0); - DEBUG_CHAR(','); - DEBUG_ECHO(ry0); - DEBUG_CHAR(')'); - DEBUG_EOL(); - } + DEBUG_ECHOPAIR("??? Yikes! NAN in get_z_correction(", rx0); + DEBUG_CHAR(','); + DEBUG_ECHO(ry0); + DEBUG_CHAR(')'); + DEBUG_EOL(); } - return z0; - } - static inline float get_z_correction(const xy_pos_t &pos) { return get_z_correction(pos.x, pos.y); } - - static inline float mesh_index_to_xpos(const uint8_t i) { - return i < GRID_MAX_POINTS_X ? pgm_read_float(&_mesh_index_to_xpos[i]) : MESH_MIN_X + i * (MESH_X_DIST); - } - static inline float mesh_index_to_ypos(const uint8_t i) { - return i < GRID_MAX_POINTS_Y ? pgm_read_float(&_mesh_index_to_ypos[i]) : MESH_MIN_Y + i * (MESH_Y_DIST); - } - - #if UBL_SEGMENTED - static bool line_to_destination_segmented(const feedRate_t &scaled_fr_mm_s); - #else - static void line_to_destination_cartesian(const feedRate_t &scaled_fr_mm_s, const uint8_t e); - #endif - - static inline bool mesh_is_valid() { - GRID_LOOP(x, y) if (isnan(z_values[x][y])) return false; - return true; } + return z0; + } + static inline float get_z_correction(const xy_pos_t &pos) { return get_z_correction(pos.x, pos.y); } + + static inline float mesh_index_to_xpos(const uint8_t i) { + return i < GRID_MAX_POINTS_X ? pgm_read_float(&_mesh_index_to_xpos[i]) : MESH_MIN_X + i * (MESH_X_DIST); + } + static inline float mesh_index_to_ypos(const uint8_t i) { + return i < GRID_MAX_POINTS_Y ? pgm_read_float(&_mesh_index_to_ypos[i]) : MESH_MIN_Y + i * (MESH_Y_DIST); + } + + #if UBL_SEGMENTED + static bool line_to_destination_segmented(const feedRate_t &scaled_fr_mm_s); + #else + static void line_to_destination_cartesian(const feedRate_t &scaled_fr_mm_s, const uint8_t e); + #endif + + static inline bool mesh_is_valid() { + GRID_LOOP(x, y) if (isnan(z_values[x][y])) return false; + return true; + } }; // class unified_bed_leveling diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index 36acc96d6e5c..8c70feb6616a 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -24,1760 +24,1767 @@ #if ENABLED(AUTO_BED_LEVELING_UBL) - #include "../bedlevel.h" - - #include "../../../MarlinCore.h" - #include "../../../HAL/shared/eeprom_api.h" - #include "../../../libs/hex_print.h" - #include "../../../module/settings.h" - #include "../../../lcd/marlinui.h" - #include "../../../module/stepper.h" - #include "../../../module/planner.h" - #include "../../../module/motion.h" - #include "../../../module/probe.h" - #include "../../../gcode/gcode.h" - #include "../../../libs/least_squares_fit.h" - - #if HAS_MULTI_HOTEND - #include "../../../module/tool_change.h" - #endif +#include "../bedlevel.h" - #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) - #include "../../../core/debug_out.h" +#include "../../../MarlinCore.h" +#include "../../../HAL/shared/eeprom_api.h" +#include "../../../libs/hex_print.h" +#include "../../../module/settings.h" +#include "../../../lcd/marlinui.h" +#include "../../../module/stepper.h" +#include "../../../module/planner.h" +#include "../../../module/motion.h" +#include "../../../module/probe.h" +#include "../../../gcode/gcode.h" +#include "../../../libs/least_squares_fit.h" - #if ENABLED(EXTENSIBLE_UI) - #include "../../../lcd/extui/ui_api.h" - #endif +#if HAS_MULTI_HOTEND + #include "../../../module/tool_change.h" +#endif - #include +#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) +#include "../../../core/debug_out.h" - #define UBL_G29_P31 +#if ENABLED(EXTENSIBLE_UI) + #include "../../../lcd/extui/ui_api.h" +#endif - #if HAS_LCD_MENU +#include - bool unified_bed_leveling::lcd_map_control = false; +#define UBL_G29_P31 - void unified_bed_leveling::steppers_were_disabled() { - if (lcd_map_control) { - lcd_map_control = false; - ui.defer_status_screen(false); - } +#if HAS_LCD_MENU + + bool unified_bed_leveling::lcd_map_control = false; + + void unified_bed_leveling::steppers_were_disabled() { + if (lcd_map_control) { + lcd_map_control = false; + ui.defer_status_screen(false); } + } - void ubl_map_screen(); + void ubl_map_screen(); - #endif +#endif - #define SIZE_OF_LITTLE_RAISE 1 - #define BIG_RAISE_NOT_NEEDED 0 +#define SIZE_OF_LITTLE_RAISE 1 +#define BIG_RAISE_NOT_NEEDED 0 - int unified_bed_leveling::g29_verbose_level, - unified_bed_leveling::g29_phase_value, - unified_bed_leveling::g29_repetition_cnt, - unified_bed_leveling::g29_storage_slot = 0, - unified_bed_leveling::g29_map_type; - bool unified_bed_leveling::g29_c_flag; - float unified_bed_leveling::g29_card_thickness = 0, - unified_bed_leveling::g29_constant = 0; - xy_bool_t unified_bed_leveling::xy_seen; - xy_pos_t unified_bed_leveling::g29_pos; +int unified_bed_leveling::g29_verbose_level, + unified_bed_leveling::g29_phase_value, + unified_bed_leveling::g29_repetition_cnt, + unified_bed_leveling::g29_storage_slot = 0, + unified_bed_leveling::g29_map_type; +bool unified_bed_leveling::g29_c_flag; +float unified_bed_leveling::g29_card_thickness = 0, + unified_bed_leveling::g29_constant = 0; +xy_bool_t unified_bed_leveling::xy_seen; +xy_pos_t unified_bed_leveling::g29_pos; - #if HAS_BED_PROBE - int unified_bed_leveling::g29_grid_size; - #endif +#if HAS_BED_PROBE + int unified_bed_leveling::g29_grid_size; +#endif - /** - * G29: Unified Bed Leveling by Roxy - * - * Parameters understood by this leveling system: - * - * A Activate Activate the Unified Bed Leveling system. - * - * B # Business Use the 'Business Card' mode of the Manual Probe subsystem with P2. - * Note: A non-compressible Spark Gap feeler gauge is recommended over a business card. - * In this mode of G29 P2, a business or index card is used as a shim that the nozzle can - * grab onto as it is lowered. In principle, the nozzle-bed distance is the same when the - * same resistance is felt in the shim. You can omit the numerical value on first invocation - * of G29 P2 B to measure shim thickness. Subsequent use of 'B' will apply the previously- - * measured thickness by default. - * - * C Continue G29 P1 C continues the generation of a partially-constructed Mesh without invalidating - * previous measurements. - * - * C G29 P2 C tells the Manual Probe subsystem to not use the current nozzle - * location in its search for the closest unmeasured Mesh Point. Instead, attempt to - * start at one end of the uprobed points and Continue sequentially. - * - * G29 P3 C specifies the Constant for the fill. Otherwise, uses a "reasonable" value. - * - * C Current G29 Z C uses the Current location (instead of bed center or nearest edge). - * - * D Disable Disable the Unified Bed Leveling system. - * - * E Stow_probe Stow the probe after each sampled point. - * - * F # Fade Fade the amount of Mesh Based Compensation over a specified height. At the - * specified height, no correction is applied and natural printer kenimatics take over. If no - * number is specified for the command, 10mm is assumed to be reasonable. - * - * H # Height With P2, 'H' specifies the Height to raise the nozzle after each manual probe of the bed. - * If omitted, the nozzle will raise by Z_CLEARANCE_BETWEEN_PROBES. - * - * H # Offset With P4, 'H' specifies the Offset above the mesh height to place the nozzle. - * If omitted, Z_CLEARANCE_BETWEEN_PROBES will be used. - * - * I # Invalidate Invalidate the specified number of Mesh Points near the given 'X' 'Y'. If X or Y are omitted, - * the nozzle location is used. If no 'I' value is given, only the point nearest to the location - * is invalidated. Use 'T' to produce a map afterward. This command is useful to invalidate a - * portion of the Mesh so it can be adjusted using other UBL tools. When attempting to invalidate - * an isolated bad mesh point, the 'T' option shows the nozzle position in the Mesh with (#). You - * can move the nozzle around and use this feature to select the center of the area (or cell) to - * invalidate. - * - * J # Grid Perform a Grid Based Leveling of the current Mesh using a grid with n points on a side. - * Not specifying a grid size will invoke the 3-Point leveling function. - * - * L Load Load Mesh from the previously activated location in the EEPROM. - * - * L # Load Load Mesh from the specified location in the EEPROM. Set this location as activated - * for subsequent Load and Store operations. - * - * The P or Phase commands are used for the bulk of the work to setup a Mesh. In general, your Mesh will - * start off being initialized with a G29 P0 or a G29 P1. Further refinement of the Mesh happens with - * each additional Phase that processes it. - * - * P0 Phase 0 Zero Mesh Data and turn off the Mesh Compensation System. This reverts the - * 3D Printer to the same state it was in before the Unified Bed Leveling Compensation - * was turned on. Setting the entire Mesh to Zero is a special case that allows - * a subsequent G or T leveling operation for backward compatibility. - * - * P1 Phase 1 Invalidate entire Mesh and continue with automatic generation of the Mesh data using - * the Z-Probe. Usually the probe can't reach all areas that the nozzle can reach. For delta - * printers only the areas where the probe and nozzle can both reach will be automatically probed. - * - * Unreachable points will be handled in Phase 2 and Phase 3. - * - * Use 'C' to leave the previous mesh intact and automatically probe needed points. This allows you - * to invalidate parts of the Mesh but still use Automatic Probing. - * - * The 'X' and 'Y' parameters prioritize where to try and measure points. If omitted, the current - * probe position is used. - * - * Use 'T' (Topology) to generate a report of mesh generation. - * - * P1 will suspend Mesh generation if the controller button is held down. Note that you may need - * to press and hold the switch for several seconds if moves are underway. - * - * P2 Phase 2 Probe unreachable points. - * - * Use 'H' to set the height between Mesh points. If omitted, Z_CLEARANCE_BETWEEN_PROBES is used. - * Smaller values will be quicker. Move the nozzle down till it barely touches the bed. Make sure the - * nozzle is clean and unobstructed. Use caution and move slowly. This can damage your printer! - * (Uses SIZE_OF_LITTLE_RAISE mm if the nozzle is moving less than BIG_RAISE_NOT_NEEDED mm.) - * - * The 'H' value can be negative if the Mesh dips in a large area. Press and hold the - * controller button to terminate the current Phase 2 command. You can then re-issue "G29 P 2" - * with an 'H' parameter more suitable for the area you're manually probing. Note that the command - * tries to start in a corner of the bed where movement will be predictable. Override the distance - * calculation location with the X and Y parameters. You can print a Mesh Map (G29 T) to see where - * the mesh is invalidated and where the nozzle needs to move to complete the command. Use 'C' to - * indicate that the search should be based on the current position. - * - * The 'B' parameter for this command is described above. It places the manual probe subsystem into - * Business Card mode where the thickness of a business card is measured and then used to accurately - * set the nozzle height in all manual probing for the duration of the command. A Business card can - * be used, but you'll get better results with a flexible Shim that doesn't compress. This makes it - * easier to produce similar amounts of force and get more accurate measurements. Google if you're - * not sure how to use a shim. - * - * The 'T' (Map) parameter helps track Mesh building progress. - * - * NOTE: P2 requires an LCD controller! - * - * P3 Phase 3 Fill the unpopulated regions of the Mesh with a fixed value. There are two different paths to - * go down: - * - * - If a 'C' constant is specified, the closest invalid mesh points to the nozzle will be filled, - * and a repeat count can then also be specified with 'R'. - * - * - Leaving out 'C' invokes Smart Fill, which scans the mesh from the edges inward looking for - * invalid mesh points. Adjacent points are used to determine the bed slope. If the bed is sloped - * upward from the invalid point, it takes the value of the nearest point. If sloped downward, it's - * replaced by a value that puts all three points in a line. This version of G29 P3 is a quick, easy - * and (usually) safe way to populate unprobed mesh regions before continuing to G26 Mesh Validation - * Pattern. Note that this populates the mesh with unverified values. Pay attention and use caution. - * - * P4 Phase 4 Fine tune the Mesh. The Delta Mesh Compensation System assumes the existence of - * an LCD Panel. It is possible to fine tune the mesh without an LCD Panel using - * G42 and M421. See the UBL documentation for further details. - * - * Phase 4 is meant to be used with G26 Mesh Validation to fine tune the mesh by direct editing - * of Mesh Points. Raise and lower points to fine tune the mesh until it gives consistently reliable - * adhesion. - * - * P4 moves to the closest Mesh Point (and/or the given X Y), raises the nozzle above the mesh height - * by the given 'H' offset (or default 0), and waits while the controller is used to adjust the nozzle - * height. On click the displayed height is saved in the mesh. - * - * Start Phase 4 at a specific location with X and Y. Adjust a specific number of Mesh Points with - * the 'R' (Repeat) parameter. (If 'R' is left out, the whole matrix is assumed.) This command can be - * terminated early (e.g., after editing the area of interest) by pressing and holding the encoder button. - * - * The general form is G29 P4 [R points] [X position] [Y position] - * - * The H [offset] parameter is useful if a shim is used to fine-tune the mesh. For a 0.4mm shim the - * command would be G29 P4 H0.4. The nozzle is moved to the shim height, you adjust height to the shim, - * and on click the height minus the shim thickness will be saved in the mesh. - * - * !!Use with caution, as a very poor mesh could cause the nozzle to crash into the bed!! - * - * NOTE: P4 is not available unless you have LCD support enabled! - * - * P5 Phase 5 Find Mean Mesh Height and Standard Deviation. Typically, it is easier to use and - * work with the Mesh if it is Mean Adjusted. You can specify a C parameter to - * Correct the Mesh to a 0.00 Mean Height. Adding a C parameter will automatically - * execute a G29 P6 C . - * - * P6 Phase 6 Shift Mesh height. The entire Mesh's height is adjusted by the height specified - * with the C parameter. Being able to adjust the height of a Mesh is useful tool. It - * can be used to compensate for poorly calibrated Z-Probes and other errors. Ideally, - * you should have the Mesh adjusted for a Mean Height of 0.00 and the Z-Probe measuring - * 0.000 at the Z Home location. - * - * Q Test Load specified Test Pattern to assist in checking correct operation of system. This - * command is not anticipated to be of much value to the typical user. It is intended - * for developers to help them verify correct operation of the Unified Bed Leveling System. - * - * R # Repeat Repeat this command the specified number of times. If no number is specified the - * command will be repeated GRID_MAX_POINTS_X * GRID_MAX_POINTS_Y times. - * - * S Store Store the current Mesh in the Activated area of the EEPROM. It will also store the - * current state of the Unified Bed Leveling system in the EEPROM. - * - * S # Store Store the current Mesh at the specified location in EEPROM. Activate this location - * for subsequent Load and Store operations. Valid storage slot numbers begin at 0 and - * extend to a limit related to the available EEPROM storage. - * - * S -1 Store Print the current Mesh as G-code that can be used to restore the mesh anytime. - * - * T Topology Display the Mesh Map Topology. - * 'T' can be used alone (e.g., G29 T) or in combination with most of the other commands. - * This option works with all Phase commands (e.g., G29 P4 R 5 T X 50 Y100 C -.1 O) - * This parameter can also specify a Map Type. T0 (the default) is user-readable. T1 - * is suitable to paste into a spreadsheet for a 3D graph of the mesh. - * - * U Unlevel Perform a probe of the outer perimeter to assist in physically leveling unlevel beds. - * Only used for G29 P1 T U. This speeds up the probing of the edge of the bed. Useful - * when the entire bed doesn't need to be probed because it will be adjusted. - * - * V # Verbosity Set the verbosity level (0-4) for extra details. (Default 0) - * - * X # X Location for this command - * - * Y # Y Location for this command - * - * With UBL_DEVEL_DEBUGGING: - * - * K # Kompare Kompare current Mesh with stored Mesh #, replacing current Mesh with the result. - * This command literally performs a diff between two Meshes. - * - * Q-1 Dump EEPROM Dump the UBL contents stored in EEPROM as HEX format. Useful for developers to help - * verify correct operation of the UBL. - * - * W What? Display valuable UBL data. - * - * - * Release Notes: - * You MUST do M502, M500 to initialize the storage. Failure to do this will cause all - * kinds of problems. Enabling EEPROM Storage is required. - * - * When you do a G28 and G29 P1 to automatically build your first mesh, you are going to notice that - * UBL probes points increasingly further from the starting location. (The starting location defaults - * to the center of the bed.) In contrast, ABL and MBL follow a zigzag pattern. The spiral pattern is - * especially better for Delta printers, since it populates the center of the mesh first, allowing for - * a quicker test print to verify settings. You don't need to populate the entire mesh to use it. - * After all, you don't want to spend a lot of time generating a mesh only to realize the resolution - * or probe offsets are incorrect. Mesh-generation gathers points starting closest to the nozzle unless - * an (X,Y) coordinate pair is given. - * - * Unified Bed Leveling uses a lot of EEPROM storage to hold its data, and it takes some effort to get - * the mesh just right. To prevent this valuable data from being destroyed as the EEPROM structure - * evolves, UBL stores all mesh data at the end of EEPROM. - * - * UBL is founded on Edward Patel's Mesh Bed Leveling code. A big 'Thanks!' to him and the creators of - * 3-Point and Grid Based leveling. Combining their contributions we now have the functionality and - * features of all three systems combined. - */ +/** + * G29: Unified Bed Leveling by Roxy + * + * Parameters understood by this leveling system: + * + * A Activate Activate the Unified Bed Leveling system. + * + * B # Business Use the 'Business Card' mode of the Manual Probe subsystem with P2. + * Note: A non-compressible Spark Gap feeler gauge is recommended over a business card. + * In this mode of G29 P2, a business or index card is used as a shim that the nozzle can + * grab onto as it is lowered. In principle, the nozzle-bed distance is the same when the + * same resistance is felt in the shim. You can omit the numerical value on first invocation + * of G29 P2 B to measure shim thickness. Subsequent use of 'B' will apply the previously- + * measured thickness by default. + * + * C Continue G29 P1 C continues the generation of a partially-constructed Mesh without invalidating + * previous measurements. + * + * C G29 P2 C tells the Manual Probe subsystem to not use the current nozzle + * location in its search for the closest unmeasured Mesh Point. Instead, attempt to + * start at one end of the uprobed points and Continue sequentially. + * + * G29 P3 C specifies the Constant for the fill. Otherwise, uses a "reasonable" value. + * + * C Current G29 Z C uses the Current location (instead of bed center or nearest edge). + * + * D Disable Disable the Unified Bed Leveling system. + * + * E Stow_probe Stow the probe after each sampled point. + * + * F # Fade Fade the amount of Mesh Based Compensation over a specified height. At the + * specified height, no correction is applied and natural printer kenimatics take over. If no + * number is specified for the command, 10mm is assumed to be reasonable. + * + * H # Height With P2, 'H' specifies the Height to raise the nozzle after each manual probe of the bed. + * If omitted, the nozzle will raise by Z_CLEARANCE_BETWEEN_PROBES. + * + * H # Offset With P4, 'H' specifies the Offset above the mesh height to place the nozzle. + * If omitted, Z_CLEARANCE_BETWEEN_PROBES will be used. + * + * I # Invalidate Invalidate the specified number of Mesh Points near the given 'X' 'Y'. If X or Y are omitted, + * the nozzle location is used. If no 'I' value is given, only the point nearest to the location + * is invalidated. Use 'T' to produce a map afterward. This command is useful to invalidate a + * portion of the Mesh so it can be adjusted using other UBL tools. When attempting to invalidate + * an isolated bad mesh point, the 'T' option shows the nozzle position in the Mesh with (#). You + * can move the nozzle around and use this feature to select the center of the area (or cell) to + * invalidate. + * + * J # Grid Perform a Grid Based Leveling of the current Mesh using a grid with n points on a side. + * Not specifying a grid size will invoke the 3-Point leveling function. + * + * L Load Load Mesh from the previously activated location in the EEPROM. + * + * L # Load Load Mesh from the specified location in the EEPROM. Set this location as activated + * for subsequent Load and Store operations. + * + * The P or Phase commands are used for the bulk of the work to setup a Mesh. In general, your Mesh will + * start off being initialized with a G29 P0 or a G29 P1. Further refinement of the Mesh happens with + * each additional Phase that processes it. + * + * P0 Phase 0 Zero Mesh Data and turn off the Mesh Compensation System. This reverts the + * 3D Printer to the same state it was in before the Unified Bed Leveling Compensation + * was turned on. Setting the entire Mesh to Zero is a special case that allows + * a subsequent G or T leveling operation for backward compatibility. + * + * P1 Phase 1 Invalidate entire Mesh and continue with automatic generation of the Mesh data using + * the Z-Probe. Usually the probe can't reach all areas that the nozzle can reach. For delta + * printers only the areas where the probe and nozzle can both reach will be automatically probed. + * + * Unreachable points will be handled in Phase 2 and Phase 3. + * + * Use 'C' to leave the previous mesh intact and automatically probe needed points. This allows you + * to invalidate parts of the Mesh but still use Automatic Probing. + * + * The 'X' and 'Y' parameters prioritize where to try and measure points. If omitted, the current + * probe position is used. + * + * Use 'T' (Topology) to generate a report of mesh generation. + * + * P1 will suspend Mesh generation if the controller button is held down. Note that you may need + * to press and hold the switch for several seconds if moves are underway. + * + * P2 Phase 2 Probe unreachable points. + * + * Use 'H' to set the height between Mesh points. If omitted, Z_CLEARANCE_BETWEEN_PROBES is used. + * Smaller values will be quicker. Move the nozzle down till it barely touches the bed. Make sure the + * nozzle is clean and unobstructed. Use caution and move slowly. This can damage your printer! + * (Uses SIZE_OF_LITTLE_RAISE mm if the nozzle is moving less than BIG_RAISE_NOT_NEEDED mm.) + * + * The 'H' value can be negative if the Mesh dips in a large area. Press and hold the + * controller button to terminate the current Phase 2 command. You can then re-issue "G29 P 2" + * with an 'H' parameter more suitable for the area you're manually probing. Note that the command + * tries to start in a corner of the bed where movement will be predictable. Override the distance + * calculation location with the X and Y parameters. You can print a Mesh Map (G29 T) to see where + * the mesh is invalidated and where the nozzle needs to move to complete the command. Use 'C' to + * indicate that the search should be based on the current position. + * + * The 'B' parameter for this command is described above. It places the manual probe subsystem into + * Business Card mode where the thickness of a business card is measured and then used to accurately + * set the nozzle height in all manual probing for the duration of the command. A Business card can + * be used, but you'll get better results with a flexible Shim that doesn't compress. This makes it + * easier to produce similar amounts of force and get more accurate measurements. Google if you're + * not sure how to use a shim. + * + * The 'T' (Map) parameter helps track Mesh building progress. + * + * NOTE: P2 requires an LCD controller! + * + * P3 Phase 3 Fill the unpopulated regions of the Mesh with a fixed value. There are two different paths to + * go down: + * + * - If a 'C' constant is specified, the closest invalid mesh points to the nozzle will be filled, + * and a repeat count can then also be specified with 'R'. + * + * - Leaving out 'C' invokes Smart Fill, which scans the mesh from the edges inward looking for + * invalid mesh points. Adjacent points are used to determine the bed slope. If the bed is sloped + * upward from the invalid point, it takes the value of the nearest point. If sloped downward, it's + * replaced by a value that puts all three points in a line. This version of G29 P3 is a quick, easy + * and (usually) safe way to populate unprobed mesh regions before continuing to G26 Mesh Validation + * Pattern. Note that this populates the mesh with unverified values. Pay attention and use caution. + * + * P4 Phase 4 Fine tune the Mesh. The Delta Mesh Compensation System assumes the existence of + * an LCD Panel. It is possible to fine tune the mesh without an LCD Panel using + * G42 and M421. See the UBL documentation for further details. + * + * Phase 4 is meant to be used with G26 Mesh Validation to fine tune the mesh by direct editing + * of Mesh Points. Raise and lower points to fine tune the mesh until it gives consistently reliable + * adhesion. + * + * P4 moves to the closest Mesh Point (and/or the given X Y), raises the nozzle above the mesh height + * by the given 'H' offset (or default 0), and waits while the controller is used to adjust the nozzle + * height. On click the displayed height is saved in the mesh. + * + * Start Phase 4 at a specific location with X and Y. Adjust a specific number of Mesh Points with + * the 'R' (Repeat) parameter. (If 'R' is left out, the whole matrix is assumed.) This command can be + * terminated early (e.g., after editing the area of interest) by pressing and holding the encoder button. + * + * The general form is G29 P4 [R points] [X position] [Y position] + * + * The H [offset] parameter is useful if a shim is used to fine-tune the mesh. For a 0.4mm shim the + * command would be G29 P4 H0.4. The nozzle is moved to the shim height, you adjust height to the shim, + * and on click the height minus the shim thickness will be saved in the mesh. + * + * !!Use with caution, as a very poor mesh could cause the nozzle to crash into the bed!! + * + * NOTE: P4 is not available unless you have LCD support enabled! + * + * P5 Phase 5 Find Mean Mesh Height and Standard Deviation. Typically, it is easier to use and + * work with the Mesh if it is Mean Adjusted. You can specify a C parameter to + * Correct the Mesh to a 0.00 Mean Height. Adding a C parameter will automatically + * execute a G29 P6 C . + * + * P6 Phase 6 Shift Mesh height. The entire Mesh's height is adjusted by the height specified + * with the C parameter. Being able to adjust the height of a Mesh is useful tool. It + * can be used to compensate for poorly calibrated Z-Probes and other errors. Ideally, + * you should have the Mesh adjusted for a Mean Height of 0.00 and the Z-Probe measuring + * 0.000 at the Z Home location. + * + * Q Test Load specified Test Pattern to assist in checking correct operation of system. This + * command is not anticipated to be of much value to the typical user. It is intended + * for developers to help them verify correct operation of the Unified Bed Leveling System. + * + * R # Repeat Repeat this command the specified number of times. If no number is specified the + * command will be repeated GRID_MAX_POINTS_X * GRID_MAX_POINTS_Y times. + * + * S Store Store the current Mesh in the Activated area of the EEPROM. It will also store the + * current state of the Unified Bed Leveling system in the EEPROM. + * + * S # Store Store the current Mesh at the specified location in EEPROM. Activate this location + * for subsequent Load and Store operations. Valid storage slot numbers begin at 0 and + * extend to a limit related to the available EEPROM storage. + * + * S -1 Store Print the current Mesh as G-code that can be used to restore the mesh anytime. + * + * T Topology Display the Mesh Map Topology. + * 'T' can be used alone (e.g., G29 T) or in combination with most of the other commands. + * This option works with all Phase commands (e.g., G29 P4 R 5 T X 50 Y100 C -.1 O) + * This parameter can also specify a Map Type. T0 (the default) is user-readable. T1 + * is suitable to paste into a spreadsheet for a 3D graph of the mesh. + * + * U Unlevel Perform a probe of the outer perimeter to assist in physically leveling unlevel beds. + * Only used for G29 P1 T U. This speeds up the probing of the edge of the bed. Useful + * when the entire bed doesn't need to be probed because it will be adjusted. + * + * V # Verbosity Set the verbosity level (0-4) for extra details. (Default 0) + * + * X # X Location for this command + * + * Y # Y Location for this command + * + * With UBL_DEVEL_DEBUGGING: + * + * K # Kompare Kompare current Mesh with stored Mesh #, replacing current Mesh with the result. + * This command literally performs a diff between two Meshes. + * + * Q-1 Dump EEPROM Dump the UBL contents stored in EEPROM as HEX format. Useful for developers to help + * verify correct operation of the UBL. + * + * W What? Display valuable UBL data. + * + * + * Release Notes: + * You MUST do M502, M500 to initialize the storage. Failure to do this will cause all + * kinds of problems. Enabling EEPROM Storage is required. + * + * When you do a G28 and G29 P1 to automatically build your first mesh, you are going to notice that + * UBL probes points increasingly further from the starting location. (The starting location defaults + * to the center of the bed.) In contrast, ABL and MBL follow a zigzag pattern. The spiral pattern is + * especially better for Delta printers, since it populates the center of the mesh first, allowing for + * a quicker test print to verify settings. You don't need to populate the entire mesh to use it. + * After all, you don't want to spend a lot of time generating a mesh only to realize the resolution + * or probe offsets are incorrect. Mesh-generation gathers points starting closest to the nozzle unless + * an (X,Y) coordinate pair is given. + * + * Unified Bed Leveling uses a lot of EEPROM storage to hold its data, and it takes some effort to get + * the mesh just right. To prevent this valuable data from being destroyed as the EEPROM structure + * evolves, UBL stores all mesh data at the end of EEPROM. + * + * UBL is founded on Edward Patel's Mesh Bed Leveling code. A big 'Thanks!' to him and the creators of + * 3-Point and Grid Based leveling. Combining their contributions we now have the functionality and + * features of all three systems combined. + */ - void unified_bed_leveling::G29() { +void unified_bed_leveling::G29() { - bool probe_deployed = false; - if (g29_parameter_parsing()) return; // Abort on parameter error + bool probe_deployed = false; + if (g29_parameter_parsing()) return; // Abort on parameter error - const int8_t p_val = parser.intval('P', -1); - const bool may_move = p_val == 1 || p_val == 2 || p_val == 4 || parser.seen('J'); - TERN_(HAS_MULTI_HOTEND, const uint8_t old_tool_index = active_extruder); + const int8_t p_val = parser.intval('P', -1); + const bool may_move = p_val == 1 || p_val == 2 || p_val == 4 || parser.seen('J'); + TERN_(HAS_MULTI_HOTEND, const uint8_t old_tool_index = active_extruder); - // Check for commands that require the printer to be homed - if (may_move) { - planner.synchronize(); - // Send 'N' to force homing before G29 (internal only) - if (axes_should_home() || parser.seen('N')) gcode.home_all_axes(); - TERN_(HAS_MULTI_HOTEND, if (active_extruder) tool_change(0)); - } + // Check for commands that require the printer to be homed + if (may_move) { + planner.synchronize(); + // Send 'N' to force homing before G29 (internal only) + if (axes_should_home() || parser.seen('N')) gcode.home_all_axes(); + TERN_(HAS_MULTI_HOTEND, if (active_extruder) tool_change(0)); + } - // Invalidate Mesh Points. This command is a little bit asymmetrical because - // it directly specifies the repetition count and does not use the 'R' parameter. - if (parser.seen('I')) { - uint8_t cnt = 0; - g29_repetition_cnt = parser.has_value() ? parser.value_int() : 1; - if (g29_repetition_cnt >= GRID_MAX_POINTS) { - set_all_mesh_points_to_value(NAN); - } - else { - while (g29_repetition_cnt--) { - if (cnt > 20) { cnt = 0; idle(); } - const mesh_index_pair closest = find_closest_mesh_point_of_type(REAL, g29_pos); - const xy_int8_t &cpos = closest.pos; - if (cpos.x < 0) { - // No more REAL mesh points to invalidate, so we ASSUME the user - // meant to invalidate the ENTIRE mesh, which cannot be done with - // find_closest_mesh_point loop which only returns REAL points. - set_all_mesh_points_to_value(NAN); - SERIAL_ECHOLNPGM("Entire Mesh invalidated.\n"); - break; // No more invalid Mesh Points to populate - } - z_values[cpos.x][cpos.y] = NAN; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(cpos, 0.0f)); - cnt++; + // Invalidate Mesh Points. This command is a little bit asymmetrical because + // it directly specifies the repetition count and does not use the 'R' parameter. + if (parser.seen('I')) { + uint8_t cnt = 0; + g29_repetition_cnt = parser.has_value() ? parser.value_int() : 1; + if (g29_repetition_cnt >= GRID_MAX_POINTS) { + set_all_mesh_points_to_value(NAN); + } + else { + while (g29_repetition_cnt--) { + if (cnt > 20) { cnt = 0; idle(); } + const mesh_index_pair closest = find_closest_mesh_point_of_type(REAL, g29_pos); + const xy_int8_t &cpos = closest.pos; + if (cpos.x < 0) { + // No more REAL mesh points to invalidate, so we ASSUME the user + // meant to invalidate the ENTIRE mesh, which cannot be done with + // find_closest_mesh_point loop which only returns REAL points. + set_all_mesh_points_to_value(NAN); + SERIAL_ECHOLNPGM("Entire Mesh invalidated.\n"); + break; // No more invalid Mesh Points to populate } + z_values[cpos.x][cpos.y] = NAN; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(cpos, 0.0f)); + cnt++; } - SERIAL_ECHOLNPGM("Locations invalidated.\n"); } + SERIAL_ECHOLNPGM("Locations invalidated.\n"); + } - if (parser.seen('Q')) { - const int test_pattern = parser.has_value() ? parser.value_int() : -99; - if (!WITHIN(test_pattern, -1, 2)) { - SERIAL_ECHOLNPGM("Invalid test_pattern value. (-1 to 2)\n"); - return; - } - SERIAL_ECHOLNPGM("Loading test_pattern values.\n"); - switch (test_pattern) { - - #if ENABLED(UBL_DEVEL_DEBUGGING) - case -1: - g29_eeprom_dump(); - break; - #endif + if (parser.seen('Q')) { + const int test_pattern = parser.has_value() ? parser.value_int() : -99; + if (!WITHIN(test_pattern, -1, 2)) { + SERIAL_ECHOLNPGM("Invalid test_pattern value. (-1 to 2)\n"); + return; + } + SERIAL_ECHOLNPGM("Loading test_pattern values.\n"); + switch (test_pattern) { - case 0: - GRID_LOOP(x, y) { // Create a bowl shape similar to a poorly-calibrated Delta - const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x, - p2 = 0.5f * (GRID_MAX_POINTS_Y) - y; - z_values[x][y] += 2.0f * HYPOT(p1, p2); - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); - } + #if ENABLED(UBL_DEVEL_DEBUGGING) + case -1: + g29_eeprom_dump(); break; + #endif - case 1: - LOOP_L_N(x, GRID_MAX_POINTS_X) { // Create a diagonal line several Mesh cells thick that is raised - z_values[x][x] += 9.999f; - z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick - #if ENABLED(EXTENSIBLE_UI) - ExtUI::onMeshUpdate(x, x, z_values[x][x]); - ExtUI::onMeshUpdate(x, (x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1), z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1]); - #endif + case 0: + GRID_LOOP(x, y) { // Create a bowl shape similar to a poorly-calibrated Delta + const float p1 = 0.5f * (GRID_MAX_POINTS_X) - x, + p2 = 0.5f * (GRID_MAX_POINTS_Y) - y; + z_values[x][y] += 2.0f * HYPOT(p1, p2); + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); + } + break; + + case 1: + LOOP_L_N(x, GRID_MAX_POINTS_X) { // Create a diagonal line several Mesh cells thick that is raised + z_values[x][x] += 9.999f; + z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1] += 9.999f; // We want the altered line several mesh points thick + #if ENABLED(EXTENSIBLE_UI) + ExtUI::onMeshUpdate(x, x, z_values[x][x]); + ExtUI::onMeshUpdate(x, (x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1), z_values[x][x + (x < (GRID_MAX_POINTS_Y) - 1) ? 1 : -1]); + #endif + + } + break; + case 2: + // Allow the user to specify the height because 10mm is a little extreme in some cases. + for (uint8_t x = (GRID_MAX_POINTS_X) / 3; x < 2 * (GRID_MAX_POINTS_X) / 3; x++) // Create a rectangular raised area in + for (uint8_t y = (GRID_MAX_POINTS_Y) / 3; y < 2 * (GRID_MAX_POINTS_Y) / 3; y++) { // the center of the bed + z_values[x][y] += parser.seen('C') ? g29_constant : 9.99f; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); } - break; + break; + } + } - case 2: - // Allow the user to specify the height because 10mm is a little extreme in some cases. - for (uint8_t x = (GRID_MAX_POINTS_X) / 3; x < 2 * (GRID_MAX_POINTS_X) / 3; x++) // Create a rectangular raised area in - for (uint8_t y = (GRID_MAX_POINTS_Y) / 3; y < 2 * (GRID_MAX_POINTS_Y) / 3; y++) { // the center of the bed - z_values[x][y] += parser.seen('C') ? g29_constant : 9.99f; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); - } - break; - } + #if HAS_BED_PROBE + + if (parser.seen('J')) { + save_ubl_active_state_and_disable(); + tilt_mesh_based_on_probed_grid(g29_grid_size == 0); // Zero size does 3-Point + restore_ubl_active_state_and_leave(); + #if ENABLED(UBL_G29_J_RECENTER) + do_blocking_move_to_xy(0.5f * ((MESH_MIN_X) + (MESH_MAX_X)), 0.5f * ((MESH_MIN_Y) + (MESH_MAX_Y))); + #endif + report_current_position(); + probe_deployed = true; } - #if HAS_BED_PROBE + #endif // HAS_BED_PROBE - if (parser.seen('J')) { - save_ubl_active_state_and_disable(); - tilt_mesh_based_on_probed_grid(g29_grid_size == 0); // Zero size does 3-Point - restore_ubl_active_state_and_leave(); - #if ENABLED(UBL_G29_J_RECENTER) - do_blocking_move_to_xy(0.5f * ((MESH_MIN_X) + (MESH_MAX_X)), 0.5f * ((MESH_MIN_Y) + (MESH_MAX_Y))); - #endif - report_current_position(); - probe_deployed = true; - } + if (parser.seen('P')) { + if (WITHIN(g29_phase_value, 0, 1) && storage_slot == -1) { + storage_slot = 0; + SERIAL_ECHOLNPGM("Default storage slot 0 selected."); + } - #endif // HAS_BED_PROBE + switch (g29_phase_value) { + case 0: + // + // Zero Mesh Data + // + reset(); + SERIAL_ECHOLNPGM("Mesh zeroed."); + break; - if (parser.seen('P')) { - if (WITHIN(g29_phase_value, 0, 1) && storage_slot == -1) { - storage_slot = 0; - SERIAL_ECHOLNPGM("Default storage slot 0 selected."); - } + #if HAS_BED_PROBE - switch (g29_phase_value) { - case 0: + case 1: { // - // Zero Mesh Data + // Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe // - reset(); - SERIAL_ECHOLNPGM("Mesh zeroed."); - break; - - #if HAS_BED_PROBE + if (!parser.seen('C')) { + invalidate(); + SERIAL_ECHOLNPGM("Mesh invalidated. Probing mesh."); + } + if (g29_verbose_level > 1) { + SERIAL_ECHOPAIR("Probing around (", g29_pos.x); + SERIAL_CHAR(','); + SERIAL_DECIMAL(g29_pos.y); + SERIAL_ECHOLNPGM(").\n"); + } + const xy_pos_t near_probe_xy = g29_pos + probe.offset_xy; + probe_entire_mesh(near_probe_xy, parser.seen('T'), parser.seen('E'), parser.seen('U')); - case 1: { - // - // Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe - // - if (!parser.seen('C')) { - invalidate(); - SERIAL_ECHOLNPGM("Mesh invalidated. Probing mesh."); - } - if (g29_verbose_level > 1) { - SERIAL_ECHOPAIR("Probing around (", g29_pos.x); - SERIAL_CHAR(','); - SERIAL_DECIMAL(g29_pos.y); - SERIAL_ECHOLNPGM(").\n"); - } - const xy_pos_t near_probe_xy = g29_pos + probe.offset_xy; - probe_entire_mesh(near_probe_xy, parser.seen('T'), parser.seen('E'), parser.seen('U')); + report_current_position(); + probe_deployed = true; + } break; - report_current_position(); - probe_deployed = true; - } break; - - #endif // HAS_BED_PROBE - - case 2: { - #if HAS_LCD_MENU - // - // Manually Probe Mesh in areas that can't be reached by the probe - // - SERIAL_ECHOLNPGM("Manually probing unreachable points."); - do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES); - - if (parser.seen('C') && !xy_seen) { - - /** - * Use a good default location for the path. - * The flipped > and < operators in these comparisons is intentional. - * It should cause the probed points to follow a nice path on Cartesian printers. - * It may make sense to have Delta printers default to the center of the bed. - * Until that is decided, this can be forced with the X and Y parameters. - */ - g29_pos.set( - #if IS_KINEMATIC - X_HOME_POS, Y_HOME_POS - #else - probe.offset_xy.x > 0 ? X_BED_SIZE : 0, - probe.offset_xy.y < 0 ? Y_BED_SIZE : 0 - #endif - ); - } + #endif // HAS_BED_PROBE - if (parser.seen('B')) { - g29_card_thickness = parser.has_value() ? parser.value_float() : measure_business_card_thickness(); - if (ABS(g29_card_thickness) > 1.5f) { - SERIAL_ECHOLNPGM("?Error in Business Card measurement."); - return; - } - probe_deployed = true; - } + case 2: { + #if HAS_LCD_MENU + // + // Manually Probe Mesh in areas that can't be reached by the probe + // + SERIAL_ECHOLNPGM("Manually probing unreachable points."); + do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES); + + if (parser.seen('C') && !xy_seen) { + + /** + * Use a good default location for the path. + * The flipped > and < operators in these comparisons is intentional. + * It should cause the probed points to follow a nice path on Cartesian printers. + * It may make sense to have Delta printers default to the center of the bed. + * Until that is decided, this can be forced with the X and Y parameters. + */ + g29_pos.set( + #if IS_KINEMATIC + X_HOME_POS, Y_HOME_POS + #else + probe.offset_xy.x > 0 ? X_BED_SIZE : 0, + probe.offset_xy.y < 0 ? Y_BED_SIZE : 0 + #endif + ); + } - if (!position_is_reachable(g29_pos)) { - SERIAL_ECHOLNPGM("XY outside printable radius."); + if (parser.seen('B')) { + g29_card_thickness = parser.has_value() ? parser.value_float() : measure_business_card_thickness(); + if (ABS(g29_card_thickness) > 1.5f) { + SERIAL_ECHOLNPGM("?Error in Business Card measurement."); return; } + probe_deployed = true; + } - const float height = parser.floatval('H', Z_CLEARANCE_BETWEEN_PROBES); - manually_probe_remaining_mesh(g29_pos, height, g29_card_thickness, parser.seen('T')); + if (!position_is_reachable(g29_pos)) { + SERIAL_ECHOLNPGM("XY outside printable radius."); + return; + } - SERIAL_ECHOLNPGM("G29 P2 finished."); + const float height = parser.floatval('H', Z_CLEARANCE_BETWEEN_PROBES); + manually_probe_remaining_mesh(g29_pos, height, g29_card_thickness, parser.seen('T')); - report_current_position(); + SERIAL_ECHOLNPGM("G29 P2 finished."); - #else + report_current_position(); - SERIAL_ECHOLNPGM("?P2 is only available when an LCD is present."); - return; + #else - #endif - } break; + SERIAL_ECHOLNPGM("?P2 is only available when an LCD is present."); + return; - case 3: { - /** - * Populate invalid mesh areas. Proceed with caution. - * Two choices are available: - * - Specify a constant with the 'C' parameter. - * - Allow 'G29 P3' to choose a 'reasonable' constant. - */ - - if (g29_c_flag) { - if (g29_repetition_cnt >= GRID_MAX_POINTS) { - set_all_mesh_points_to_value(g29_constant); - } - else { - while (g29_repetition_cnt--) { // this only populates reachable mesh points near - const mesh_index_pair closest = find_closest_mesh_point_of_type(INVALID, g29_pos); - const xy_int8_t &cpos = closest.pos; - if (cpos.x < 0) { - // No more REAL INVALID mesh points to populate, so we ASSUME - // user meant to populate ALL INVALID mesh points to value - GRID_LOOP(x, y) if (isnan(z_values[x][y])) z_values[x][y] = g29_constant; - break; // No more invalid Mesh Points to populate - } - else { - z_values[cpos.x][cpos.y] = g29_constant; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(cpos, g29_constant)); - } - } - } + #endif + } break; + + case 3: { + /** + * Populate invalid mesh areas. Proceed with caution. + * Two choices are available: + * - Specify a constant with the 'C' parameter. + * - Allow 'G29 P3' to choose a 'reasonable' constant. + */ + + if (g29_c_flag) { + if (g29_repetition_cnt >= GRID_MAX_POINTS) { + set_all_mesh_points_to_value(g29_constant); } else { - const float cvf = parser.value_float(); - switch ((int)TRUNC(cvf * 10.0f) - 30) { // 3.1 -> 1 - #if ENABLED(UBL_G29_P31) - case 1: { - - // P3.1 use least squares fit to fill missing mesh values - // P3.10 zero weighting for distance, all grid points equal, best fit tilted plane - // P3.11 10X weighting for nearest grid points versus farthest grid points - // P3.12 100X distance weighting - // P3.13 1000X distance weighting, approaches simple average of nearest points - - const float weight_power = (cvf - 3.10f) * 100.0f, // 3.12345 -> 2.345 - weight_factor = weight_power ? POW(10.0f, weight_power) : 0; - smart_fill_wlsf(weight_factor); - } - break; - #endif - case 0: // P3 or P3.0 - default: // and anything P3.x that's not P3.1 - smart_fill_mesh(); // Do a 'Smart' fill using nearby known values - break; + while (g29_repetition_cnt--) { // this only populates reachable mesh points near + const mesh_index_pair closest = find_closest_mesh_point_of_type(INVALID, g29_pos); + const xy_int8_t &cpos = closest.pos; + if (cpos.x < 0) { + // No more REAL INVALID mesh points to populate, so we ASSUME + // user meant to populate ALL INVALID mesh points to value + GRID_LOOP(x, y) if (isnan(z_values[x][y])) z_values[x][y] = g29_constant; + break; // No more invalid Mesh Points to populate + } + else { + z_values[cpos.x][cpos.y] = g29_constant; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(cpos, g29_constant)); + } } } - break; } - - case 4: // Fine Tune (i.e., Edit) the Mesh - #if HAS_LCD_MENU - fine_tune_mesh(g29_pos, parser.seen('T')); - #else - SERIAL_ECHOLNPGM("?P4 is only available when an LCD is present."); - return; - #endif - break; - - case 5: adjust_mesh_to_mean(g29_c_flag, g29_constant); break; - - case 6: shift_mesh_height(); break; + else { + const float cvf = parser.value_float(); + switch ((int)TRUNC(cvf * 10.0f) - 30) { // 3.1 -> 1 + #if ENABLED(UBL_G29_P31) + case 1: { + + // P3.1 use least squares fit to fill missing mesh values + // P3.10 zero weighting for distance, all grid points equal, best fit tilted plane + // P3.11 10X weighting for nearest grid points versus farthest grid points + // P3.12 100X distance weighting + // P3.13 1000X distance weighting, approaches simple average of nearest points + + const float weight_power = (cvf - 3.10f) * 100.0f, // 3.12345 -> 2.345 + weight_factor = weight_power ? POW(10.0f, weight_power) : 0; + smart_fill_wlsf(weight_factor); + } + break; + #endif + case 0: // P3 or P3.0 + default: // and anything P3.x that's not P3.1 + smart_fill_mesh(); // Do a 'Smart' fill using nearby known values + break; + } + } + break; } - } - - #if ENABLED(UBL_DEVEL_DEBUGGING) - // - // Much of the 'What?' command can be eliminated. But until we are fully debugged, it is - // good to have the extra information. Soon... we prune this to just a few items - // - if (parser.seen('W')) g29_what_command(); + case 4: // Fine Tune (i.e., Edit) the Mesh + #if HAS_LCD_MENU + fine_tune_mesh(g29_pos, parser.seen('T')); + #else + SERIAL_ECHOLNPGM("?P4 is only available when an LCD is present."); + return; + #endif + break; - // - // When we are fully debugged, this may go away. But there are some valid - // use cases for the users. So we can wait and see what to do with it. - // + case 5: adjust_mesh_to_mean(g29_c_flag, g29_constant); break; - if (parser.seen('K')) // Kompare Current Mesh Data to Specified Stored Mesh - g29_compare_current_mesh_to_stored_mesh(); + case 6: shift_mesh_height(); break; + } + } - #endif // UBL_DEVEL_DEBUGGING + #if ENABLED(UBL_DEVEL_DEBUGGING) + // + // Much of the 'What?' command can be eliminated. But until we are fully debugged, it is + // good to have the extra information. Soon... we prune this to just a few items + // + if (parser.seen('W')) g29_what_command(); // - // Load a Mesh from the EEPROM + // When we are fully debugged, this may go away. But there are some valid + // use cases for the users. So we can wait and see what to do with it. // - if (parser.seen('L')) { // Load Current Mesh Data - g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot; + if (parser.seen('K')) // Kompare Current Mesh Data to Specified Stored Mesh + g29_compare_current_mesh_to_stored_mesh(); + + #endif // UBL_DEVEL_DEBUGGING - int16_t a = settings.calc_num_meshes(); - if (!a) { - SERIAL_ECHOLNPGM("?EEPROM storage not available."); - return; - } + // + // Load a Mesh from the EEPROM + // - if (!WITHIN(g29_storage_slot, 0, a - 1)) { - SERIAL_ECHOLNPAIR("?Invalid storage slot.\n?Use 0 to ", a - 1); - return; - } + if (parser.seen('L')) { // Load Current Mesh Data + g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot; - settings.load_mesh(g29_storage_slot); - storage_slot = g29_storage_slot; + int16_t a = settings.calc_num_meshes(); - SERIAL_ECHOLNPGM("Done."); + if (!a) { + SERIAL_ECHOLNPGM("?EEPROM storage not available."); + return; } - // - // Store a Mesh in the EEPROM - // + if (!WITHIN(g29_storage_slot, 0, a - 1)) { + SERIAL_ECHOLNPAIR("?Invalid storage slot.\n?Use 0 to ", a - 1); + return; + } - if (parser.seen('S')) { // Store (or Save) Current Mesh Data - g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot; + settings.load_mesh(g29_storage_slot); + storage_slot = g29_storage_slot; - if (g29_storage_slot == -1) // Special case, the user wants to 'Export' the mesh to the - return report_current_mesh(); // host program to be saved on the user's computer + SERIAL_ECHOLNPGM("Done."); + } - int16_t a = settings.calc_num_meshes(); + // + // Store a Mesh in the EEPROM + // - if (!a) { - SERIAL_ECHOLNPGM("?EEPROM storage not available."); - goto LEAVE; - } + if (parser.seen('S')) { // Store (or Save) Current Mesh Data + g29_storage_slot = parser.has_value() ? parser.value_int() : storage_slot; - if (!WITHIN(g29_storage_slot, 0, a - 1)) { - SERIAL_ECHOLNPAIR("?Invalid storage slot.\n?Use 0 to ", a - 1); - goto LEAVE; - } + if (g29_storage_slot == -1) // Special case, the user wants to 'Export' the mesh to the + return report_current_mesh(); // host program to be saved on the user's computer - settings.store_mesh(g29_storage_slot); - storage_slot = g29_storage_slot; + int16_t a = settings.calc_num_meshes(); - SERIAL_ECHOLNPGM("Done."); + if (!a) { + SERIAL_ECHOLNPGM("?EEPROM storage not available."); + goto LEAVE; } - if (parser.seen('T')) - display_map(g29_map_type); + if (!WITHIN(g29_storage_slot, 0, a - 1)) { + SERIAL_ECHOLNPAIR("?Invalid storage slot.\n?Use 0 to ", a - 1); + goto LEAVE; + } - LEAVE: + settings.store_mesh(g29_storage_slot); + storage_slot = g29_storage_slot; - #if HAS_LCD_MENU - ui.reset_alert_level(); - ui.quick_feedback(); - ui.reset_status(); - ui.release(); - #endif + SERIAL_ECHOLNPGM("Done."); + } - #ifdef Z_PROBE_END_SCRIPT - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Z Probe End Script: ", Z_PROBE_END_SCRIPT); - if (probe_deployed) { - planner.synchronize(); - gcode.process_subcommands_now_P(PSTR(Z_PROBE_END_SCRIPT)); - } - #else - UNUSED(probe_deployed); - #endif + if (parser.seen('T')) + display_map(g29_map_type); - TERN_(HAS_MULTI_HOTEND, tool_change(old_tool_index)); - return; - } + LEAVE: - void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) { - float sum = 0; - int n = 0; - GRID_LOOP(x, y) - if (!isnan(z_values[x][y])) { - sum += z_values[x][y]; - n++; - } + #if HAS_LCD_MENU + ui.reset_alert_level(); + ui.quick_feedback(); + ui.reset_status(); + ui.release(); + #endif - const float mean = sum / n; + #ifdef Z_PROBE_END_SCRIPT + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Z Probe End Script: ", Z_PROBE_END_SCRIPT); + if (probe_deployed) { + planner.synchronize(); + gcode.process_subcommands_now_P(PSTR(Z_PROBE_END_SCRIPT)); + } + #else + UNUSED(probe_deployed); + #endif - // - // Sum the squares of difference from mean - // - float sum_of_diff_squared = 0; - GRID_LOOP(x, y) - if (!isnan(z_values[x][y])) - sum_of_diff_squared += sq(z_values[x][y] - mean); + TERN_(HAS_MULTI_HOTEND, tool_change(old_tool_index)); + return; +} + +void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) { + float sum = 0; + int n = 0; + GRID_LOOP(x, y) + if (!isnan(z_values[x][y])) { + sum += z_values[x][y]; + n++; + } - SERIAL_ECHOLNPAIR("# of samples: ", n); - SERIAL_ECHOLNPAIR_F("Mean Mesh Height: ", mean, 6); + const float mean = sum / n; - const float sigma = SQRT(sum_of_diff_squared / (n + 1)); - SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6); + // + // Sum the squares of difference from mean + // + float sum_of_diff_squared = 0; + GRID_LOOP(x, y) + if (!isnan(z_values[x][y])) + sum_of_diff_squared += sq(z_values[x][y] - mean); - if (cflag) - GRID_LOOP(x, y) - if (!isnan(z_values[x][y])) { - z_values[x][y] -= mean + value; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); - } - } + SERIAL_ECHOLNPAIR("# of samples: ", n); + SERIAL_ECHOLNPAIR_F("Mean Mesh Height: ", mean, 6); + + const float sigma = SQRT(sum_of_diff_squared / (n + 1)); + SERIAL_ECHOLNPAIR_F("Standard Deviation: ", sigma, 6); - void unified_bed_leveling::shift_mesh_height() { + if (cflag) GRID_LOOP(x, y) if (!isnan(z_values[x][y])) { - z_values[x][y] += g29_constant; + z_values[x][y] -= mean + value; TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); } - } +} - #if HAS_BED_PROBE - /** - * Probe all invalidated locations of the mesh that can be reached by the probe. - * This attempts to fill in locations closest to the nozzle's start location first. - */ - void unified_bed_leveling::probe_entire_mesh(const xy_pos_t &nearby, const bool do_ubl_mesh_map, const bool stow_probe, const bool do_furthest) { - probe.deploy(); // Deploy before ui.capture() to allow for PAUSE_BEFORE_DEPLOY_STOW +void unified_bed_leveling::shift_mesh_height() { + GRID_LOOP(x, y) + if (!isnan(z_values[x][y])) { + z_values[x][y] += g29_constant; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); + } +} - TERN_(HAS_LCD_MENU, ui.capture()); +#if HAS_BED_PROBE + /** + * Probe all invalidated locations of the mesh that can be reached by the probe. + * This attempts to fill in locations closest to the nozzle's start location first. + */ + void unified_bed_leveling::probe_entire_mesh(const xy_pos_t &nearby, const bool do_ubl_mesh_map, const bool stow_probe, const bool do_furthest) { + probe.deploy(); // Deploy before ui.capture() to allow for PAUSE_BEFORE_DEPLOY_STOW - save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained - uint8_t count = GRID_MAX_POINTS; + TERN_(HAS_LCD_MENU, ui.capture()); - mesh_index_pair best; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::MESH_START)); - do { - if (do_ubl_mesh_map) display_map(g29_map_type); + save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained + uint8_t count = GRID_MAX_POINTS; - const int point_num = (GRID_MAX_POINTS) - count + 1; - SERIAL_ECHOLNPAIR("Probing mesh point ", point_num, "/", GRID_MAX_POINTS, "."); - TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_MESH), point_num, int(GRID_MAX_POINTS))); + mesh_index_pair best; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::MESH_START)); + do { + if (do_ubl_mesh_map) display_map(g29_map_type); - #if HAS_LCD_MENU - if (ui.button_pressed()) { - ui.quick_feedback(false); // Preserve button state for click-and-hold - SERIAL_ECHOLNPGM("\nMesh only partially populated.\n"); - ui.wait_for_release(); - ui.quick_feedback(); - ui.release(); - probe.stow(); // Release UI before stow to allow for PAUSE_BEFORE_DEPLOY_STOW - return restore_ubl_active_state_and_leave(); - } + const int point_num = (GRID_MAX_POINTS) - count + 1; + SERIAL_ECHOLNPAIR("Probing mesh point ", point_num, "/", GRID_MAX_POINTS, "."); + TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_PROBING_MESH), point_num, int(GRID_MAX_POINTS))); + + #if HAS_LCD_MENU + if (ui.button_pressed()) { + ui.quick_feedback(false); // Preserve button state for click-and-hold + SERIAL_ECHOLNPGM("\nMesh only partially populated.\n"); + ui.wait_for_release(); + ui.quick_feedback(); + ui.release(); + probe.stow(); // Release UI before stow to allow for PAUSE_BEFORE_DEPLOY_STOW + return restore_ubl_active_state_and_leave(); + } + #endif + + best = do_furthest + ? find_furthest_invalid_mesh_point() + : find_closest_mesh_point_of_type(INVALID, nearby, true); + + if (best.pos.x >= 0) { // mesh point found and is reachable by probe + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::PROBE_START)); + const float measured_z = probe.probe_at_point( + best.meshpos(), + stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level + ); + z_values[best.pos.x][best.pos.y] = measured_z; + #if ENABLED(EXTENSIBLE_UI) + ExtUI::onMeshUpdate(best.pos, ExtUI::PROBE_FINISH); + ExtUI::onMeshUpdate(best.pos, measured_z); #endif + } + SERIAL_FLUSH(); // Prevent host M105 buffer overrun. - best = do_furthest - ? find_furthest_invalid_mesh_point() - : find_closest_mesh_point_of_type(INVALID, nearby, true); - - if (best.pos.x >= 0) { // mesh point found and is reachable by probe - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::PROBE_START)); - const float measured_z = probe.probe_at_point( - best.meshpos(), - stow_probe ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level - ); - z_values[best.pos.x][best.pos.y] = measured_z; - #if ENABLED(EXTENSIBLE_UI) - ExtUI::onMeshUpdate(best.pos, ExtUI::PROBE_FINISH); - ExtUI::onMeshUpdate(best.pos, measured_z); - #endif - } - SERIAL_FLUSH(); // Prevent host M105 buffer overrun. + } while (best.pos.x >= 0 && --count); - } while (best.pos.x >= 0 && --count); + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::MESH_FINISH)); - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(best.pos, ExtUI::MESH_FINISH)); + // Release UI during stow to allow for PAUSE_BEFORE_DEPLOY_STOW + TERN_(HAS_LCD_MENU, ui.release()); + probe.stow(); + TERN_(HAS_LCD_MENU, ui.capture()); - // Release UI during stow to allow for PAUSE_BEFORE_DEPLOY_STOW - TERN_(HAS_LCD_MENU, ui.release()); - probe.stow(); - TERN_(HAS_LCD_MENU, ui.capture()); + probe.move_z_after_probing(); - probe.move_z_after_probing(); + restore_ubl_active_state_and_leave(); - restore_ubl_active_state_and_leave(); + do_blocking_move_to_xy( + constrain(nearby.x - probe.offset_xy.x, MESH_MIN_X, MESH_MAX_X), + constrain(nearby.y - probe.offset_xy.y, MESH_MIN_Y, MESH_MAX_Y) + ); + } - do_blocking_move_to_xy( - constrain(nearby.x - probe.offset_xy.x, MESH_MIN_X, MESH_MAX_X), - constrain(nearby.y - probe.offset_xy.y, MESH_MIN_Y, MESH_MAX_Y) - ); - } +#endif // HAS_BED_PROBE - #endif // HAS_BED_PROBE +#if HAS_LCD_MENU - #if HAS_LCD_MENU + typedef void (*clickFunc_t)(); - typedef void (*clickFunc_t)(); - - bool click_and_hold(const clickFunc_t func=nullptr) { - if (ui.button_pressed()) { - ui.quick_feedback(false); // Preserve button state for click-and-hold - const millis_t nxt = millis() + 1500UL; - while (ui.button_pressed()) { // Loop while the encoder is pressed. Uses hardware flag! - idle(); // idle, of course - if (ELAPSED(millis(), nxt)) { // After 1.5 seconds - ui.quick_feedback(); - if (func) (*func)(); - ui.wait_for_release(); - return true; - } + bool click_and_hold(const clickFunc_t func=nullptr) { + if (ui.button_pressed()) { + ui.quick_feedback(false); // Preserve button state for click-and-hold + const millis_t nxt = millis() + 1500UL; + while (ui.button_pressed()) { // Loop while the encoder is pressed. Uses hardware flag! + idle(); // idle, of course + if (ELAPSED(millis(), nxt)) { // After 1.5 seconds + ui.quick_feedback(); + if (func) (*func)(); + ui.wait_for_release(); + return true; } } - serial_delay(15); - return false; } + serial_delay(15); + return false; + } - void unified_bed_leveling::move_z_with_encoder(const float &multiplier) { - ui.wait_for_release(); - while (!ui.button_pressed()) { - idle(); - gcode.reset_stepper_timeout(); // Keep steppers powered - if (encoder_diff) { - do_blocking_move_to_z(current_position.z + float(encoder_diff) * multiplier); - encoder_diff = 0; - } + void unified_bed_leveling::move_z_with_encoder(const float &multiplier) { + ui.wait_for_release(); + while (!ui.button_pressed()) { + idle(); + gcode.reset_stepper_timeout(); // Keep steppers powered + if (encoder_diff) { + do_blocking_move_to_z(current_position.z + float(encoder_diff) * multiplier); + encoder_diff = 0; } } + } - float unified_bed_leveling::measure_point_with_encoder() { - KEEPALIVE_STATE(PAUSED_FOR_USER); - move_z_with_encoder(0.01f); - return current_position.z; - } - - static void echo_and_take_a_measurement() { SERIAL_ECHOLNPGM(" and take a measurement."); } - - float unified_bed_leveling::measure_business_card_thickness() { - ui.capture(); - save_ubl_active_state_and_disable(); // Disable bed level correction for probing + float unified_bed_leveling::measure_point_with_encoder() { + KEEPALIVE_STATE(PAUSED_FOR_USER); + move_z_with_encoder(0.01f); + return current_position.z; + } - do_blocking_move_to(0.5f * (MESH_MAX_X - (MESH_MIN_X)), 0.5f * (MESH_MAX_Y - (MESH_MIN_Y)), MANUAL_PROBE_START_Z); - //, _MIN(planner.settings.max_feedrate_mm_s[X_AXIS], planner.settings.max_feedrate_mm_s[Y_AXIS]) * 0.5f); - planner.synchronize(); + static void echo_and_take_a_measurement() { SERIAL_ECHOLNPGM(" and take a measurement."); } - SERIAL_ECHOPGM("Place shim under nozzle"); - LCD_MESSAGEPGM(MSG_UBL_BC_INSERT); - ui.return_to_status(); - echo_and_take_a_measurement(); + float unified_bed_leveling::measure_business_card_thickness() { + ui.capture(); + save_ubl_active_state_and_disable(); // Disable bed level correction for probing - const float z1 = measure_point_with_encoder(); - do_blocking_move_to_z(current_position.z + SIZE_OF_LITTLE_RAISE); - planner.synchronize(); + do_blocking_move_to(0.5f * (MESH_MAX_X - (MESH_MIN_X)), 0.5f * (MESH_MAX_Y - (MESH_MIN_Y)), MANUAL_PROBE_START_Z); + //, _MIN(planner.settings.max_feedrate_mm_s[X_AXIS], planner.settings.max_feedrate_mm_s[Y_AXIS]) * 0.5f); + planner.synchronize(); - SERIAL_ECHOPGM("Remove shim"); - LCD_MESSAGEPGM(MSG_UBL_BC_REMOVE); - echo_and_take_a_measurement(); + SERIAL_ECHOPGM("Place shim under nozzle"); + LCD_MESSAGEPGM(MSG_UBL_BC_INSERT); + ui.return_to_status(); + echo_and_take_a_measurement(); - const float z2 = measure_point_with_encoder(); - do_blocking_move_to_z(current_position.z + Z_CLEARANCE_BETWEEN_PROBES); + const float z1 = measure_point_with_encoder(); + do_blocking_move_to_z(current_position.z + SIZE_OF_LITTLE_RAISE); + planner.synchronize(); - const float thickness = ABS(z1 - z2); + SERIAL_ECHOPGM("Remove shim"); + LCD_MESSAGEPGM(MSG_UBL_BC_REMOVE); + echo_and_take_a_measurement(); - if (g29_verbose_level > 1) { - SERIAL_ECHOPAIR_F("Business Card is ", thickness, 4); - SERIAL_ECHOLNPGM("mm thick."); - } + const float z2 = measure_point_with_encoder(); + do_blocking_move_to_z(current_position.z + Z_CLEARANCE_BETWEEN_PROBES); - restore_ubl_active_state_and_leave(); + const float thickness = ABS(z1 - z2); - return thickness; + if (g29_verbose_level > 1) { + SERIAL_ECHOPAIR_F("Business Card is ", thickness, 4); + SERIAL_ECHOLNPGM("mm thick."); } - void unified_bed_leveling::manually_probe_remaining_mesh(const xy_pos_t &pos, const float &z_clearance, const float &thick, const bool do_ubl_mesh_map) { - ui.capture(); + restore_ubl_active_state_and_leave(); - save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained - do_blocking_move_to_xy_z(current_position, z_clearance); + return thickness; + } - ui.return_to_status(); + void unified_bed_leveling::manually_probe_remaining_mesh(const xy_pos_t &pos, const float &z_clearance, const float &thick, const bool do_ubl_mesh_map) { + ui.capture(); - mesh_index_pair location; - const xy_int8_t &lpos = location.pos; - do { - location = find_closest_mesh_point_of_type(INVALID, pos); - // It doesn't matter if the probe can't reach the NAN location. This is a manual probe. - if (!location.valid()) continue; - - const xyz_pos_t ppos = { - mesh_index_to_xpos(lpos.x), - mesh_index_to_ypos(lpos.y), - Z_CLEARANCE_BETWEEN_PROBES - }; + save_ubl_active_state_and_disable(); // No bed level correction so only raw data is obtained + do_blocking_move_to_xy_z(current_position, z_clearance); - if (!position_is_reachable(ppos)) break; // SHOULD NOT OCCUR (find_closest_mesh_point only returns reachable points) + ui.return_to_status(); - LCD_MESSAGEPGM(MSG_UBL_MOVING_TO_NEXT); + mesh_index_pair location; + const xy_int8_t &lpos = location.pos; + do { + location = find_closest_mesh_point_of_type(INVALID, pos); + // It doesn't matter if the probe can't reach the NAN location. This is a manual probe. + if (!location.valid()) continue; - do_blocking_move_to(ppos); - do_z_clearance(z_clearance); + const xyz_pos_t ppos = { + mesh_index_to_xpos(lpos.x), + mesh_index_to_ypos(lpos.y), + z_clearance + }; - KEEPALIVE_STATE(PAUSED_FOR_USER); - ui.capture(); + if (!position_is_reachable(ppos)) break; // SHOULD NOT OCCUR (find_closest_mesh_point only returns reachable points) - if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing + LCD_MESSAGEPGM(MSG_UBL_MOVING_TO_NEXT); - serialprintPGM(parser.seen('B') ? GET_TEXT(MSG_UBL_BC_INSERT) : GET_TEXT(MSG_UBL_BC_INSERT2)); + do_blocking_move_to(ppos); + do_z_clearance(z_clearance); - const float z_step = 0.01f; // existing behavior: 0.01mm per click, occasionally step - //const float z_step = planner.steps_to_mm[Z_AXIS]; // approx one step each click + KEEPALIVE_STATE(PAUSED_FOR_USER); + ui.capture(); - move_z_with_encoder(z_step); + if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing - if (click_and_hold()) { - SERIAL_ECHOLNPGM("\nMesh only partially populated."); - do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE); - return restore_ubl_active_state_and_leave(); - } + if (parser.seen('B')) { + SERIAL_ECHOPGM_P(GET_TEXT(MSG_UBL_BC_INSERT)); + LCD_MESSAGEPGM(MSG_UBL_BC_INSERT); + } + else { + SERIAL_ECHOPGM_P(GET_TEXT(MSG_UBL_BC_INSERT2)); + LCD_MESSAGEPGM(MSG_UBL_BC_INSERT2); + } - z_values[lpos.x][lpos.y] = current_position.z - thick; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location, z_values[lpos.x][lpos.y])); + const float z_step = 0.01f; // existing behavior: 0.01mm per click, occasionally step + //const float z_step = planner.steps_to_mm[Z_AXIS]; // approx one step each click - if (g29_verbose_level > 2) - SERIAL_ECHOLNPAIR_F("Mesh Point Measured at: ", z_values[lpos.x][lpos.y], 6); - SERIAL_FLUSH(); // Prevent host M105 buffer overrun. - } while (location.valid()); + move_z_with_encoder(z_step); - if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing + if (click_and_hold()) { + SERIAL_ECHOLNPGM("\nMesh only partially populated."); + do_z_clearance(Z_CLEARANCE_DEPLOY_PROBE); + return restore_ubl_active_state_and_leave(); + } - restore_ubl_active_state_and_leave(); - do_blocking_move_to_xy_z(pos, Z_CLEARANCE_DEPLOY_PROBE); - } + z_values[lpos.x][lpos.y] = current_position.z - thick; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location, z_values[lpos.x][lpos.y])); - inline void set_message_with_feedback(PGM_P const msg_P) { - ui.set_status_P(msg_P); - ui.quick_feedback(); - } + if (g29_verbose_level > 2) + SERIAL_ECHOLNPAIR_F("Mesh Point Measured at: ", z_values[lpos.x][lpos.y], 6); + SERIAL_FLUSH(); // Prevent host M105 buffer overrun. + } while (location.valid()); - void abort_fine_tune() { - ui.return_to_status(); - do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES); - set_message_with_feedback(GET_TEXT(MSG_EDITING_STOPPED)); - } + if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing - void unified_bed_leveling::fine_tune_mesh(const xy_pos_t &pos, const bool do_ubl_mesh_map) { - if (!parser.seen('R')) // fine_tune_mesh() is special. If no repetition count flag is specified - g29_repetition_cnt = 1; // do exactly one mesh location. Otherwise use what the parser decided. + restore_ubl_active_state_and_leave(); + do_blocking_move_to_xy_z(pos, Z_CLEARANCE_DEPLOY_PROBE); + } - #if ENABLED(UBL_MESH_EDIT_MOVES_Z) - const float h_offset = parser.seenval('H') ? parser.value_linear_units() : MANUAL_PROBE_START_Z; - if (!WITHIN(h_offset, 0, 10)) { - SERIAL_ECHOLNPGM("Offset out of bounds. (0 to 10mm)\n"); - return; - } - #endif + inline void set_message_with_feedback(PGM_P const msg_P) { + ui.set_status_P(msg_P); + ui.quick_feedback(); + } + + void abort_fine_tune() { + ui.return_to_status(); + do_z_clearance(Z_CLEARANCE_BETWEEN_PROBES); + set_message_with_feedback(GET_TEXT(MSG_EDITING_STOPPED)); + } - mesh_index_pair location; + void unified_bed_leveling::fine_tune_mesh(const xy_pos_t &pos, const bool do_ubl_mesh_map) { + if (!parser.seen('R')) // fine_tune_mesh() is special. If no repetition count flag is specified + g29_repetition_cnt = 1; // do exactly one mesh location. Otherwise use what the parser decided. - if (!position_is_reachable(pos)) { - SERIAL_ECHOLNPGM("(X,Y) outside printable radius."); + #if ENABLED(UBL_MESH_EDIT_MOVES_Z) + const float h_offset = parser.seenval('H') ? parser.value_linear_units() : MANUAL_PROBE_START_Z; + if (!WITHIN(h_offset, 0, 10)) { + SERIAL_ECHOLNPGM("Offset out of bounds. (0 to 10mm)\n"); return; } + #endif + + mesh_index_pair location; + + if (!position_is_reachable(pos)) { + SERIAL_ECHOLNPGM("(X,Y) outside printable radius."); + return; + } - save_ubl_active_state_and_disable(); + save_ubl_active_state_and_disable(); - LCD_MESSAGEPGM(MSG_UBL_FINE_TUNE_MESH); - ui.capture(); // Take over control of the LCD encoder + LCD_MESSAGEPGM(MSG_UBL_FINE_TUNE_MESH); + ui.capture(); // Take over control of the LCD encoder - do_blocking_move_to_xy_z(pos, Z_CLEARANCE_BETWEEN_PROBES); // Move to the given XY with probe clearance + do_blocking_move_to_xy_z(pos, Z_CLEARANCE_BETWEEN_PROBES); // Move to the given XY with probe clearance - MeshFlags done_flags{0}; - const xy_int8_t &lpos = location.pos; + MeshFlags done_flags{0}; + const xy_int8_t &lpos = location.pos; - #if IS_TFTGLCD_PANEL - lcd_mesh_edit_setup(0); // Change current screen before calling ui.ubl_plot - safe_delay(50); - #endif + #if IS_TFTGLCD_PANEL + lcd_mesh_edit_setup(0); // Change current screen before calling ui.ubl_plot + safe_delay(50); + #endif - do { - location = find_closest_mesh_point_of_type(SET_IN_BITMAP, pos, false, &done_flags); + do { + location = find_closest_mesh_point_of_type(SET_IN_BITMAP, pos, false, &done_flags); - if (lpos.x < 0) break; // Stop when there are no more reachable points + if (lpos.x < 0) break; // Stop when there are no more reachable points - done_flags.mark(lpos); // Mark this location as 'adjusted' so a new - // location is used on the next loop - const xyz_pos_t raw = { - mesh_index_to_xpos(lpos.x), - mesh_index_to_ypos(lpos.y), - Z_CLEARANCE_BETWEEN_PROBES - }; + done_flags.mark(lpos); // Mark this location as 'adjusted' so a new + // location is used on the next loop + const xyz_pos_t raw = { + mesh_index_to_xpos(lpos.x), + mesh_index_to_ypos(lpos.y), + Z_CLEARANCE_BETWEEN_PROBES + }; - if (!position_is_reachable(raw)) break; // SHOULD NOT OCCUR (find_closest_mesh_point_of_type only returns reachable) + if (!position_is_reachable(raw)) break; // SHOULD NOT OCCUR (find_closest_mesh_point_of_type only returns reachable) - do_blocking_move_to(raw); // Move the nozzle to the edit point with probe clearance + do_blocking_move_to(raw); // Move the nozzle to the edit point with probe clearance - TERN_(UBL_MESH_EDIT_MOVES_Z, do_blocking_move_to_z(h_offset)); // Move Z to the given 'H' offset before editing + TERN_(UBL_MESH_EDIT_MOVES_Z, do_blocking_move_to_z(h_offset)); // Move Z to the given 'H' offset before editing - KEEPALIVE_STATE(PAUSED_FOR_USER); + KEEPALIVE_STATE(PAUSED_FOR_USER); - if (do_ubl_mesh_map) display_map(g29_map_type); // Display the current point + if (do_ubl_mesh_map) display_map(g29_map_type); // Display the current point - #if IS_TFTGLCD_PANEL - ui.ubl_plot(lpos.x, lpos.y); // update plot screen - #endif + #if IS_TFTGLCD_PANEL + ui.ubl_plot(lpos.x, lpos.y); // update plot screen + #endif - ui.refresh(); + ui.refresh(); - float new_z = z_values[lpos.x][lpos.y]; - if (isnan(new_z)) new_z = 0; // Invalid points begin at 0 - new_z = FLOOR(new_z * 1000) * 0.001f; // Chop off digits after the 1000ths place + float new_z = z_values[lpos.x][lpos.y]; + if (isnan(new_z)) new_z = 0; // Invalid points begin at 0 + new_z = FLOOR(new_z * 1000) * 0.001f; // Chop off digits after the 1000ths place - lcd_mesh_edit_setup(new_z); + lcd_mesh_edit_setup(new_z); - SET_SOFT_ENDSTOP_LOOSE(true); + SET_SOFT_ENDSTOP_LOOSE(true); - do { - idle(); - new_z = lcd_mesh_edit(); - TERN_(UBL_MESH_EDIT_MOVES_Z, do_blocking_move_to_z(h_offset + new_z)); // Move the nozzle as the point is edited - SERIAL_FLUSH(); // Prevent host M105 buffer overrun. - } while (!ui.button_pressed()); + do { + idle(); + new_z = lcd_mesh_edit(); + TERN_(UBL_MESH_EDIT_MOVES_Z, do_blocking_move_to_z(h_offset + new_z)); // Move the nozzle as the point is edited + SERIAL_FLUSH(); // Prevent host M105 buffer overrun. + } while (!ui.button_pressed()); - SET_SOFT_ENDSTOP_LOOSE(false); + SET_SOFT_ENDSTOP_LOOSE(false); - if (!lcd_map_control) ui.return_to_status(); // Just editing a single point? Return to status + if (!lcd_map_control) ui.return_to_status(); // Just editing a single point? Return to status - if (click_and_hold(abort_fine_tune)) break; // Button held down? Abort editing + if (click_and_hold(abort_fine_tune)) break; // Button held down? Abort editing - z_values[lpos.x][lpos.y] = new_z; // Save the updated Z value - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location, new_z)); + z_values[lpos.x][lpos.y] = new_z; // Save the updated Z value + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(location, new_z)); - serial_delay(20); // No switch noise - ui.refresh(); + serial_delay(20); // No switch noise + ui.refresh(); - } while (lpos.x >= 0 && --g29_repetition_cnt > 0); + } while (lpos.x >= 0 && --g29_repetition_cnt > 0); - if (do_ubl_mesh_map) display_map(g29_map_type); - restore_ubl_active_state_and_leave(); + if (do_ubl_mesh_map) display_map(g29_map_type); + restore_ubl_active_state_and_leave(); - do_blocking_move_to_xy_z(pos, Z_CLEARANCE_BETWEEN_PROBES); + do_blocking_move_to_xy_z(pos, Z_CLEARANCE_BETWEEN_PROBES); - LCD_MESSAGEPGM(MSG_UBL_DONE_EDITING_MESH); - SERIAL_ECHOLNPGM("Done Editing Mesh"); + LCD_MESSAGEPGM(MSG_UBL_DONE_EDITING_MESH); + SERIAL_ECHOLNPGM("Done Editing Mesh"); - if (lcd_map_control) - ui.goto_screen(ubl_map_screen); - else - ui.return_to_status(); - } + if (lcd_map_control) + ui.goto_screen(ubl_map_screen); + else + ui.return_to_status(); + } - #endif // HAS_LCD_MENU +#endif // HAS_LCD_MENU - bool unified_bed_leveling::g29_parameter_parsing() { - bool err_flag = false; +bool unified_bed_leveling::g29_parameter_parsing() { + bool err_flag = false; - TERN_(HAS_LCD_MENU, set_message_with_feedback(GET_TEXT(MSG_UBL_DOING_G29))); + TERN_(HAS_LCD_MENU, set_message_with_feedback(GET_TEXT(MSG_UBL_DOING_G29))); - g29_constant = 0; - g29_repetition_cnt = 0; + g29_constant = 0; + g29_repetition_cnt = 0; - if (parser.seen('R')) { - g29_repetition_cnt = parser.has_value() ? parser.value_int() : GRID_MAX_POINTS; - NOMORE(g29_repetition_cnt, GRID_MAX_POINTS); - if (g29_repetition_cnt < 1) { - SERIAL_ECHOLNPGM("?(R)epetition count invalid (1+).\n"); - return UBL_ERR; - } + if (parser.seen('R')) { + g29_repetition_cnt = parser.has_value() ? parser.value_int() : GRID_MAX_POINTS; + NOMORE(g29_repetition_cnt, GRID_MAX_POINTS); + if (g29_repetition_cnt < 1) { + SERIAL_ECHOLNPGM("?(R)epetition count invalid (1+).\n"); + return UBL_ERR; } + } - g29_verbose_level = parser.seen('V') ? parser.value_int() : 0; - if (!WITHIN(g29_verbose_level, 0, 4)) { - SERIAL_ECHOLNPGM("?(V)erbose level implausible (0-4).\n"); - err_flag = true; - } + g29_verbose_level = parser.seen('V') ? parser.value_int() : 0; + if (!WITHIN(g29_verbose_level, 0, 4)) { + SERIAL_ECHOLNPGM("?(V)erbose level implausible (0-4).\n"); + err_flag = true; + } - if (parser.seen('P')) { - const int pv = parser.value_int(); - #if !HAS_BED_PROBE - if (pv == 1) { - SERIAL_ECHOLNPGM("G29 P1 requires a probe.\n"); + if (parser.seen('P')) { + const int pv = parser.value_int(); + #if !HAS_BED_PROBE + if (pv == 1) { + SERIAL_ECHOLNPGM("G29 P1 requires a probe.\n"); + err_flag = true; + } + else + #endif + { + g29_phase_value = pv; + if (!WITHIN(g29_phase_value, 0, 6)) { + SERIAL_ECHOLNPGM("?(P)hase value invalid (0-6).\n"); err_flag = true; } - else - #endif - { - g29_phase_value = pv; - if (!WITHIN(g29_phase_value, 0, 6)) { - SERIAL_ECHOLNPGM("?(P)hase value invalid (0-6).\n"); - err_flag = true; - } - } - } + } + } - if (parser.seen('J')) { - #if HAS_BED_PROBE - g29_grid_size = parser.has_value() ? parser.value_int() : 0; - if (g29_grid_size && !WITHIN(g29_grid_size, 2, 9)) { - SERIAL_ECHOLNPGM("?Invalid grid size (J) specified (2-9).\n"); - err_flag = true; - } - #else - SERIAL_ECHOLNPGM("G29 J action requires a probe.\n"); + if (parser.seen('J')) { + #if HAS_BED_PROBE + g29_grid_size = parser.has_value() ? parser.value_int() : 0; + if (g29_grid_size && !WITHIN(g29_grid_size, 2, 9)) { + SERIAL_ECHOLNPGM("?Invalid grid size (J) specified (2-9).\n"); err_flag = true; - #endif - } - - xy_seen.x = parser.seenval('X'); - float sx = xy_seen.x ? parser.value_float() : current_position.x; - xy_seen.y = parser.seenval('Y'); - float sy = xy_seen.y ? parser.value_float() : current_position.y; - - if (xy_seen.x != xy_seen.y) { - SERIAL_ECHOLNPGM("Both X & Y locations must be specified.\n"); + } + #else + SERIAL_ECHOLNPGM("G29 J action requires a probe.\n"); err_flag = true; - } - - // If X or Y are not valid, use center of the bed values - if (!WITHIN(sx, X_MIN_BED, X_MAX_BED)) sx = X_CENTER; - if (!WITHIN(sy, Y_MIN_BED, Y_MAX_BED)) sy = Y_CENTER; + #endif + } - if (err_flag) return UBL_ERR; + xy_seen.x = parser.seenval('X'); + float sx = xy_seen.x ? parser.value_float() : current_position.x; + xy_seen.y = parser.seenval('Y'); + float sy = xy_seen.y ? parser.value_float() : current_position.y; - g29_pos.set(sx, sy); + if (xy_seen.x != xy_seen.y) { + SERIAL_ECHOLNPGM("Both X & Y locations must be specified.\n"); + err_flag = true; + } - /** - * Activate or deactivate UBL - * Note: UBL's G29 restores the state set here when done. - * Leveling is being enabled here with old data, possibly - * none. Error handling should disable for safety... - */ - if (parser.seen('A')) { - if (parser.seen('D')) { - SERIAL_ECHOLNPGM("?Can't activate and deactivate at the same time.\n"); - return UBL_ERR; - } - set_bed_leveling_enabled(true); - report_state(); - } - else if (parser.seen('D')) { - set_bed_leveling_enabled(false); - report_state(); - } + // If X or Y are not valid, use center of the bed values + if (!COORDINATE_OKAY(sx, X_MIN_BED, X_MAX_BED)) sx = X_CENTER; + if (!COORDINATE_OKAY(sy, Y_MIN_BED, Y_MAX_BED)) sy = Y_CENTER; - // Set global 'C' flag and its value - if ((g29_c_flag = parser.seen('C'))) - g29_constant = parser.value_float(); + if (err_flag) return UBL_ERR; - #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - if (parser.seenval('F')) { - const float fh = parser.value_float(); - if (!WITHIN(fh, 0, 100)) { - SERIAL_ECHOLNPGM("?(F)ade height for Bed Level Correction not plausible.\n"); - return UBL_ERR; - } - set_z_fade_height(fh); - } - #endif + g29_pos.set(sx, sy); - g29_map_type = parser.intval('T'); - if (!WITHIN(g29_map_type, 0, 2)) { - SERIAL_ECHOLNPGM("Invalid map type.\n"); + /** + * Activate or deactivate UBL + * Note: UBL's G29 restores the state set here when done. + * Leveling is being enabled here with old data, possibly + * none. Error handling should disable for safety... + */ + if (parser.seen('A')) { + if (parser.seen('D')) { + SERIAL_ECHOLNPGM("?Can't activate and deactivate at the same time.\n"); return UBL_ERR; } - return UBL_OK; + set_bed_leveling_enabled(true); + report_state(); + } + else if (parser.seen('D')) { + set_bed_leveling_enabled(false); + report_state(); } - static uint8_t ubl_state_at_invocation = 0; + // Set global 'C' flag and its value + if ((g29_c_flag = parser.seen('C'))) + g29_constant = parser.value_float(); - #if ENABLED(UBL_DEVEL_DEBUGGING) - static uint8_t ubl_state_recursion_chk = 0; + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + if (parser.seenval('F')) { + const float fh = parser.value_float(); + if (!WITHIN(fh, 0, 100)) { + SERIAL_ECHOLNPGM("?(F)ade height for Bed Level Correction not plausible.\n"); + return UBL_ERR; + } + set_z_fade_height(fh); + } #endif - void unified_bed_leveling::save_ubl_active_state_and_disable() { - #if ENABLED(UBL_DEVEL_DEBUGGING) - ubl_state_recursion_chk++; - if (ubl_state_recursion_chk != 1) { - SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row."); - TERN_(HAS_LCD_MENU, set_message_with_feedback(GET_TEXT(MSG_UBL_SAVE_ERROR))); - return; - } - #endif - ubl_state_at_invocation = planner.leveling_active; - set_bed_leveling_enabled(false); + g29_map_type = parser.intval('T'); + if (!WITHIN(g29_map_type, 0, 2)) { + SERIAL_ECHOLNPGM("Invalid map type.\n"); + return UBL_ERR; } + return UBL_OK; +} - void unified_bed_leveling::restore_ubl_active_state_and_leave() { - TERN_(HAS_LCD_MENU, ui.release()); - #if ENABLED(UBL_DEVEL_DEBUGGING) - if (--ubl_state_recursion_chk) { - SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times."); - TERN_(HAS_LCD_MENU, set_message_with_feedback(GET_TEXT(MSG_UBL_RESTORE_ERROR))); - return; - } - #endif - set_bed_leveling_enabled(ubl_state_at_invocation); - } +static uint8_t ubl_state_at_invocation = 0; - mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() { +#if ENABLED(UBL_DEVEL_DEBUGGING) + static uint8_t ubl_state_recursion_chk = 0; +#endif + +void unified_bed_leveling::save_ubl_active_state_and_disable() { + #if ENABLED(UBL_DEVEL_DEBUGGING) + ubl_state_recursion_chk++; + if (ubl_state_recursion_chk != 1) { + SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row."); + TERN_(HAS_LCD_MENU, set_message_with_feedback(GET_TEXT(MSG_UBL_SAVE_ERROR))); + return; + } + #endif + ubl_state_at_invocation = planner.leveling_active; + set_bed_leveling_enabled(false); +} - bool found_a_NAN = false, found_a_real = false; +void unified_bed_leveling::restore_ubl_active_state_and_leave() { + TERN_(HAS_LCD_MENU, ui.release()); + #if ENABLED(UBL_DEVEL_DEBUGGING) + if (--ubl_state_recursion_chk) { + SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times."); + TERN_(HAS_LCD_MENU, set_message_with_feedback(GET_TEXT(MSG_UBL_RESTORE_ERROR))); + return; + } + #endif + set_bed_leveling_enabled(ubl_state_at_invocation); +} - mesh_index_pair farthest { -1, -1, -99999.99 }; +mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() { - GRID_LOOP(i, j) { - if (!isnan(z_values[i][j])) continue; // Skip valid mesh points + bool found_a_NAN = false, found_a_real = false; - // Skip unreachable points - if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j))) - continue; + mesh_index_pair farthest { -1, -1, -99999.99 }; - found_a_NAN = true; + GRID_LOOP(i, j) { + if (!isnan(z_values[i][j])) continue; // Skip valid mesh points - xy_int8_t nearby { -1, -1 }; - float d1, d2 = 99999.9f; - GRID_LOOP(k, l) { - if (isnan(z_values[k][l])) continue; + // Skip unreachable points + if (!probe.can_reach(mesh_index_to_xpos(i), mesh_index_to_ypos(j))) + continue; - found_a_real = true; + found_a_NAN = true; - // Add in a random weighting factor that scrambles the probing of the - // last half of the mesh (when every unprobed mesh point is one index - // from a probed location). + xy_int8_t nearby { -1, -1 }; + float d1, d2 = 99999.9f; + GRID_LOOP(k, l) { + if (isnan(z_values[k][l])) continue; - d1 = HYPOT(i - k, j - l) + (1.0f / ((millis() % 47) + 13)); + found_a_real = true; - if (d1 < d2) { // Invalid mesh point (i,j) is closer to the defined point (k,l) - d2 = d1; - nearby.set(i, j); - } - } + // Add in a random weighting factor that scrambles the probing of the + // last half of the mesh (when every unprobed mesh point is one index + // from a probed location). - // - // At this point d2 should have the near defined mesh point to invalid mesh point (i,j) - // + d1 = HYPOT(i - k, j - l) + (1.0f / ((millis() % 47) + 13)); - if (found_a_real && nearby.x >= 0 && d2 > farthest.distance) { - farthest.pos = nearby; // Found an invalid location farther from the defined mesh point - farthest.distance = d2; + if (d1 < d2) { // Invalid mesh point (i,j) is closer to the defined point (k,l) + d2 = d1; + nearby.set(i, j); } - } // GRID_LOOP + } + + // + // At this point d2 should have the near defined mesh point to invalid mesh point (i,j) + // - if (!found_a_real && found_a_NAN) { // if the mesh is totally unpopulated, start the probing - farthest.pos.set((GRID_MAX_POINTS_X) / 2, (GRID_MAX_POINTS_Y) / 2); - farthest.distance = 1; + if (found_a_real && nearby.x >= 0 && d2 > farthest.distance) { + farthest.pos = nearby; // Found an invalid location farther from the defined mesh point + farthest.distance = d2; } - return farthest; + } // GRID_LOOP + + if (!found_a_real && found_a_NAN) { // if the mesh is totally unpopulated, start the probing + farthest.pos.set((GRID_MAX_POINTS_X) / 2, (GRID_MAX_POINTS_Y) / 2); + farthest.distance = 1; } + return farthest; +} - mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const xy_pos_t &pos, const bool probe_relative/*=false*/, MeshFlags *done_flags/*=nullptr*/) { - mesh_index_pair closest; - closest.invalidate(); - closest.distance = -99999.9f; +mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const xy_pos_t &pos, const bool probe_relative/*=false*/, MeshFlags *done_flags/*=nullptr*/) { + mesh_index_pair closest; + closest.invalidate(); + closest.distance = -99999.9f; - // Get the reference position, either nozzle or probe - const xy_pos_t ref = probe_relative ? pos + probe.offset_xy : pos; + // Get the reference position, either nozzle or probe + const xy_pos_t ref = probe_relative ? pos + probe.offset_xy : pos; - float best_so_far = 99999.99f; + float best_so_far = 99999.99f; - GRID_LOOP(i, j) { - if ( (type == (isnan(z_values[i][j]) ? INVALID : REAL)) - || (type == SET_IN_BITMAP && !done_flags->marked(i, j)) - ) { - // Found a Mesh Point of the specified type! - const xy_pos_t mpos = { mesh_index_to_xpos(i), mesh_index_to_ypos(j) }; - - // If using the probe as the reference there are some unreachable locations. - // Also for round beds, there are grid points outside the bed the nozzle can't reach. - // Prune them from the list and ignore them till the next Phase (manual nozzle probing). - - if (!(probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos))) - continue; - - // Reachable. Check if it's the best_so_far location to the nozzle. - - const xy_pos_t diff = current_position - mpos; - const float distance = (ref - mpos).magnitude() + diff.magnitude() * 0.1f; - - // factor in the distance from the current location for the normal case - // so the nozzle isn't running all over the bed. - if (distance < best_so_far) { - best_so_far = distance; // Found a closer location with the desired value type. - closest.pos.set(i, j); - closest.distance = best_so_far; - } - } - } // GRID_LOOP + GRID_LOOP(i, j) { + if ( (type == (isnan(z_values[i][j]) ? INVALID : REAL)) + || (type == SET_IN_BITMAP && !done_flags->marked(i, j)) + ) { + // Found a Mesh Point of the specified type! + const xy_pos_t mpos = { mesh_index_to_xpos(i), mesh_index_to_ypos(j) }; - return closest; - } + // If using the probe as the reference there are some unreachable locations. + // Also for round beds, there are grid points outside the bed the nozzle can't reach. + // Prune them from the list and ignore them till the next Phase (manual nozzle probing). - /** - * 'Smart Fill': Scan from the outward edges of the mesh towards the center. - * If an invalid location is found, use the next two points (if valid) to - * calculate a 'reasonable' value for the unprobed mesh point. - */ + if (!(probe_relative ? probe.can_reach(mpos) : position_is_reachable(mpos))) + continue; - bool unified_bed_leveling::smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir) { - const float v = z_values[x][y]; - if (isnan(v)) { // A NAN... - const int8_t dx = x + xdir, dy = y + ydir; - const float v1 = z_values[dx][dy]; - if (!isnan(v1)) { // ...next to a pair of real values? - const float v2 = z_values[dx + xdir][dy + ydir]; - if (!isnan(v2)) { - z_values[x][y] = v1 < v2 ? v1 : v1 + v1 - v2; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); - return true; - } + // Reachable. Check if it's the best_so_far location to the nozzle. + + const xy_pos_t diff = current_position - mpos; + const float distance = (ref - mpos).magnitude() + diff.magnitude() * 0.1f; + + // factor in the distance from the current location for the normal case + // so the nozzle isn't running all over the bed. + if (distance < best_so_far) { + best_so_far = distance; // Found a closer location with the desired value type. + closest.pos.set(i, j); + closest.distance = best_so_far; } } - return false; - } + } // GRID_LOOP - typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info; - - void unified_bed_leveling::smart_fill_mesh() { - static const smart_fill_info - info0 PROGMEM = { 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false }, // Bottom of the mesh looking up - info1 PROGMEM = { 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false }, // Top of the mesh looking down - info2 PROGMEM = { 0, GRID_MAX_POINTS_X - 2, 0, GRID_MAX_POINTS_Y, true }, // Left side of the mesh looking right - info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true }; // Right side of the mesh looking left - static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 }; - - LOOP_L_N(i, COUNT(info)) { - const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]); - const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy), - ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey); - if (pgm_read_byte(&f->yfirst)) { - const int8_t dir = ex > sx ? 1 : -1; - for (uint8_t y = sy; y != ey; ++y) - for (uint8_t x = sx; x != ex; x += dir) - if (smart_fill_one(x, y, dir, 0)) break; - } - else { - const int8_t dir = ey > sy ? 1 : -1; - for (uint8_t x = sx; x != ex; ++x) - for (uint8_t y = sy; y != ey; y += dir) - if (smart_fill_one(x, y, 0, dir)) break; + return closest; +} + +/** + * 'Smart Fill': Scan from the outward edges of the mesh towards the center. + * If an invalid location is found, use the next two points (if valid) to + * calculate a 'reasonable' value for the unprobed mesh point. + */ + +bool unified_bed_leveling::smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir) { + const float v = z_values[x][y]; + if (isnan(v)) { // A NAN... + const int8_t dx = x + xdir, dy = y + ydir; + const float v1 = z_values[dx][dy]; + if (!isnan(v1)) { // ...next to a pair of real values? + const float v2 = z_values[dx + xdir][dy + ydir]; + if (!isnan(v2)) { + z_values[x][y] = v1 < v2 ? v1 : v1 + v1 - v2; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); + return true; } } } + return false; +} + +typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info; + +void unified_bed_leveling::smart_fill_mesh() { + static const smart_fill_info + info0 PROGMEM = { 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false }, // Bottom of the mesh looking up + info1 PROGMEM = { 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false }, // Top of the mesh looking down + info2 PROGMEM = { 0, GRID_MAX_POINTS_X - 2, 0, GRID_MAX_POINTS_Y, true }, // Left side of the mesh looking right + info3 PROGMEM = { GRID_MAX_POINTS_X - 1, 0, 0, GRID_MAX_POINTS_Y, true }; // Right side of the mesh looking left + static const smart_fill_info * const info[] PROGMEM = { &info0, &info1, &info2, &info3 }; + + LOOP_L_N(i, COUNT(info)) { + const smart_fill_info *f = (smart_fill_info*)pgm_read_ptr(&info[i]); + const int8_t sx = pgm_read_byte(&f->sx), sy = pgm_read_byte(&f->sy), + ex = pgm_read_byte(&f->ex), ey = pgm_read_byte(&f->ey); + if (pgm_read_byte(&f->yfirst)) { + const int8_t dir = ex > sx ? 1 : -1; + for (uint8_t y = sy; y != ey; ++y) + for (uint8_t x = sx; x != ex; x += dir) + if (smart_fill_one(x, y, dir, 0)) break; + } + else { + const int8_t dir = ey > sy ? 1 : -1; + for (uint8_t x = sx; x != ex; ++x) + for (uint8_t y = sy; y != ey; y += dir) + if (smart_fill_one(x, y, 0, dir)) break; + } + } +} - #if HAS_BED_PROBE +#if HAS_BED_PROBE - //#define VALIDATE_MESH_TILT + //#define VALIDATE_MESH_TILT - #include "../../../libs/vector_3.h" + #include "../../../libs/vector_3.h" - void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_3_pt_leveling) { - const float x_min = probe.min_x(), x_max = probe.max_x(), - y_min = probe.min_y(), y_max = probe.max_y(), - dx = (x_max - x_min) / (g29_grid_size - 1), - dy = (y_max - y_min) / (g29_grid_size - 1); + void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_3_pt_leveling) { + const float x_min = probe.min_x(), x_max = probe.max_x(), + y_min = probe.min_y(), y_max = probe.max_y(), + dx = (x_max - x_min) / (g29_grid_size - 1), + dy = (y_max - y_min) / (g29_grid_size - 1); - xy_float_t points[3]; - probe.get_three_points(points); + xy_float_t points[3]; + probe.get_three_points(points); - float measured_z; - bool abort_flag = false; + float measured_z; + bool abort_flag = false; - #ifdef VALIDATE_MESH_TILT - float z1, z2, z3; // Needed for algorithm validation below - #endif + #ifdef VALIDATE_MESH_TILT + float z1, z2, z3; // Needed for algorithm validation below + #endif + + struct linear_fit_data lsf_results; + incremental_LSF_reset(&lsf_results); + + if (do_3_pt_leveling) { + SERIAL_ECHOLNPGM("Tilting mesh (1/3)"); + TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " 1/3"), GET_TEXT(MSG_LCD_TILTING_MESH))); - struct linear_fit_data lsf_results; - incremental_LSF_reset(&lsf_results); + measured_z = probe.probe_at_point(points[0], PROBE_PT_RAISE, g29_verbose_level); + if (isnan(measured_z)) + abort_flag = true; + else { + measured_z -= get_z_correction(points[0]); + #ifdef VALIDATE_MESH_TILT + z1 = measured_z; + #endif + if (g29_verbose_level > 3) { + serial_spaces(16); + SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z); + } + incremental_LSF(&lsf_results, points[0], measured_z); + } - if (do_3_pt_leveling) { - SERIAL_ECHOLNPGM("Tilting mesh (1/3)"); - TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " 1/3"), GET_TEXT(MSG_LCD_TILTING_MESH))); + if (!abort_flag) { + SERIAL_ECHOLNPGM("Tilting mesh (2/3)"); + TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " 2/3"), GET_TEXT(MSG_LCD_TILTING_MESH))); - measured_z = probe.probe_at_point(points[0], PROBE_PT_RAISE, g29_verbose_level); + measured_z = probe.probe_at_point(points[1], PROBE_PT_RAISE, g29_verbose_level); + #ifdef VALIDATE_MESH_TILT + z2 = measured_z; + #endif if (isnan(measured_z)) abort_flag = true; else { - measured_z -= get_z_correction(points[0]); - #ifdef VALIDATE_MESH_TILT - z1 = measured_z; - #endif + measured_z -= get_z_correction(points[1]); if (g29_verbose_level > 3) { serial_spaces(16); SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z); } - incremental_LSF(&lsf_results, points[0], measured_z); - } - - if (!abort_flag) { - SERIAL_ECHOLNPGM("Tilting mesh (2/3)"); - TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " 2/3"), GET_TEXT(MSG_LCD_TILTING_MESH))); - - measured_z = probe.probe_at_point(points[1], PROBE_PT_RAISE, g29_verbose_level); - #ifdef VALIDATE_MESH_TILT - z2 = measured_z; - #endif - if (isnan(measured_z)) - abort_flag = true; - else { - measured_z -= get_z_correction(points[1]); - if (g29_verbose_level > 3) { - serial_spaces(16); - SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z); - } - incremental_LSF(&lsf_results, points[1], measured_z); - } + incremental_LSF(&lsf_results, points[1], measured_z); } + } - if (!abort_flag) { - SERIAL_ECHOLNPGM("Tilting mesh (3/3)"); - TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " 3/3"), GET_TEXT(MSG_LCD_TILTING_MESH))); + if (!abort_flag) { + SERIAL_ECHOLNPGM("Tilting mesh (3/3)"); + TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " 3/3"), GET_TEXT(MSG_LCD_TILTING_MESH))); - measured_z = probe.probe_at_point(points[2], PROBE_PT_STOW, g29_verbose_level); - #ifdef VALIDATE_MESH_TILT - z3 = measured_z; - #endif - if (isnan(measured_z)) - abort_flag = true; - else { - measured_z -= get_z_correction(points[2]); - if (g29_verbose_level > 3) { - serial_spaces(16); - SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z); - } - incremental_LSF(&lsf_results, points[2], measured_z); + measured_z = probe.probe_at_point(points[2], PROBE_PT_STOW, g29_verbose_level); + #ifdef VALIDATE_MESH_TILT + z3 = measured_z; + #endif + if (isnan(measured_z)) + abort_flag = true; + else { + measured_z -= get_z_correction(points[2]); + if (g29_verbose_level > 3) { + serial_spaces(16); + SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z); } + incremental_LSF(&lsf_results, points[2], measured_z); } + } - probe.stow(); - probe.move_z_after_probing(); + probe.stow(); + probe.move_z_after_probing(); - if (abort_flag) { - SERIAL_ECHOLNPGM("?Error probing point. Aborting operation."); - return; - } + if (abort_flag) { + SERIAL_ECHOLNPGM("?Error probing point. Aborting operation."); + return; } - else { // !do_3_pt_leveling - - bool zig_zag = false; - - const uint16_t total_points = sq(g29_grid_size); - uint16_t point_num = 1; - - xy_pos_t rpos; - LOOP_L_N(ix, g29_grid_size) { - rpos.x = x_min + ix * dx; - LOOP_L_N(iy, g29_grid_size) { - rpos.y = y_min + dy * (zig_zag ? g29_grid_size - 1 - iy : iy); - - if (!abort_flag) { - SERIAL_ECHOLNPAIR("Tilting mesh point ", point_num, "/", total_points, "\n"); - TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_LCD_TILTING_MESH), point_num, total_points)); - - measured_z = probe.probe_at_point(rpos, parser.seen('E') ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling - - abort_flag = isnan(measured_z); - - #if ENABLED(DEBUG_LEVELING_FEATURE) - if (DEBUGGING(LEVELING)) { - const xy_pos_t lpos = rpos.asLogical(); - DEBUG_CHAR('('); - DEBUG_ECHO_F(rpos.x, 7); - DEBUG_CHAR(','); - DEBUG_ECHO_F(rpos.y, 7); - DEBUG_ECHOPAIR_F(") logical: (", lpos.x, 7); - DEBUG_CHAR(','); - DEBUG_ECHO_F(lpos.y, 7); - DEBUG_ECHOPAIR_F(") measured: ", measured_z, 7); - DEBUG_ECHOPAIR_F(" correction: ", get_z_correction(rpos), 7); - } - #endif + } + else { // !do_3_pt_leveling + + bool zig_zag = false; + + const uint16_t total_points = sq(g29_grid_size); + uint16_t point_num = 1; + + xy_pos_t rpos; + LOOP_L_N(ix, g29_grid_size) { + rpos.x = x_min + ix * dx; + LOOP_L_N(iy, g29_grid_size) { + rpos.y = y_min + dy * (zig_zag ? g29_grid_size - 1 - iy : iy); + + if (!abort_flag) { + SERIAL_ECHOLNPAIR("Tilting mesh point ", point_num, "/", total_points, "\n"); + TERN_(HAS_DISPLAY, ui.status_printf_P(0, PSTR(S_FMT " %i/%i"), GET_TEXT(MSG_LCD_TILTING_MESH), point_num, total_points)); + + measured_z = probe.probe_at_point(rpos, parser.seen('E') ? PROBE_PT_STOW : PROBE_PT_RAISE, g29_verbose_level); // TODO: Needs error handling + + abort_flag = isnan(measured_z); + + #if ENABLED(DEBUG_LEVELING_FEATURE) + if (DEBUGGING(LEVELING)) { + const xy_pos_t lpos = rpos.asLogical(); + DEBUG_CHAR('('); + DEBUG_ECHO_F(rpos.x, 7); + DEBUG_CHAR(','); + DEBUG_ECHO_F(rpos.y, 7); + DEBUG_ECHOPAIR_F(") logical: (", lpos.x, 7); + DEBUG_CHAR(','); + DEBUG_ECHO_F(lpos.y, 7); + DEBUG_ECHOPAIR_F(") measured: ", measured_z, 7); + DEBUG_ECHOPAIR_F(" correction: ", get_z_correction(rpos), 7); + } + #endif - measured_z -= get_z_correction(rpos) /* + probe.offset.z */ ; + measured_z -= get_z_correction(rpos) /* + probe.offset.z */ ; - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR_F(" final >>>---> ", measured_z, 7); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR_F(" final >>>---> ", measured_z, 7); - if (g29_verbose_level > 3) { - serial_spaces(16); - SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z); - } - incremental_LSF(&lsf_results, rpos, measured_z); + if (g29_verbose_level > 3) { + serial_spaces(16); + SERIAL_ECHOLNPAIR("Corrected_Z=", measured_z); } - - point_num++; + incremental_LSF(&lsf_results, rpos, measured_z); } - zig_zag ^= true; + point_num++; } - } - probe.stow(); - probe.move_z_after_probing(); - if (abort_flag || finish_incremental_LSF(&lsf_results)) { - SERIAL_ECHOPGM("Could not complete LSF!"); - return; + zig_zag ^= true; } + } + probe.stow(); + probe.move_z_after_probing(); - vector_3 normal = vector_3(lsf_results.A, lsf_results.B, 1).get_normal(); + if (abort_flag || finish_incremental_LSF(&lsf_results)) { + SERIAL_ECHOPGM("Could not complete LSF!"); + return; + } - if (g29_verbose_level > 2) { - SERIAL_ECHOPAIR_F("bed plane normal = [", normal.x, 7); - SERIAL_CHAR(','); - SERIAL_ECHO_F(normal.y, 7); - SERIAL_CHAR(','); - SERIAL_ECHO_F(normal.z, 7); - SERIAL_ECHOLNPGM("]"); - } + vector_3 normal = vector_3(lsf_results.A, lsf_results.B, 1).get_normal(); - matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1)); - - GRID_LOOP(i, j) { - float mx = mesh_index_to_xpos(i), - my = mesh_index_to_ypos(j), - mz = z_values[i][j]; - - if (DEBUGGING(LEVELING)) { - DEBUG_ECHOPAIR_F("before rotation = [", mx, 7); - DEBUG_CHAR(','); - DEBUG_ECHO_F(my, 7); - DEBUG_CHAR(','); - DEBUG_ECHO_F(mz, 7); - DEBUG_ECHOPGM("] ---> "); - DEBUG_DELAY(20); - } + if (g29_verbose_level > 2) { + SERIAL_ECHOPAIR_F("bed plane normal = [", normal.x, 7); + SERIAL_CHAR(','); + SERIAL_ECHO_F(normal.y, 7); + SERIAL_CHAR(','); + SERIAL_ECHO_F(normal.z, 7); + SERIAL_ECHOLNPGM("]"); + } - apply_rotation_xyz(rotation, mx, my, mz); + matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1)); - if (DEBUGGING(LEVELING)) { - DEBUG_ECHOPAIR_F("after rotation = [", mx, 7); - DEBUG_CHAR(','); - DEBUG_ECHO_F(my, 7); - DEBUG_CHAR(','); - DEBUG_ECHO_F(mz, 7); - DEBUG_ECHOLNPGM("]"); - DEBUG_DELAY(20); - } + GRID_LOOP(i, j) { + float mx = mesh_index_to_xpos(i), + my = mesh_index_to_ypos(j), + mz = z_values[i][j]; - z_values[i][j] = mz - lsf_results.D; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, z_values[i][j])); + if (DEBUGGING(LEVELING)) { + DEBUG_ECHOPAIR_F("before rotation = [", mx, 7); + DEBUG_CHAR(','); + DEBUG_ECHO_F(my, 7); + DEBUG_CHAR(','); + DEBUG_ECHO_F(mz, 7); + DEBUG_ECHOPGM("] ---> "); + DEBUG_DELAY(20); } - if (DEBUGGING(LEVELING)) { - rotation.debug(PSTR("rotation matrix:\n")); - DEBUG_ECHOPAIR_F("LSF Results A=", lsf_results.A, 7); - DEBUG_ECHOPAIR_F(" B=", lsf_results.B, 7); - DEBUG_ECHOLNPAIR_F(" D=", lsf_results.D, 7); - DEBUG_DELAY(55); + apply_rotation_xyz(rotation, mx, my, mz); - DEBUG_ECHOPAIR_F("bed plane normal = [", normal.x, 7); + if (DEBUGGING(LEVELING)) { + DEBUG_ECHOPAIR_F("after rotation = [", mx, 7); DEBUG_CHAR(','); - DEBUG_ECHO_F(normal.y, 7); + DEBUG_ECHO_F(my, 7); DEBUG_CHAR(','); - DEBUG_ECHO_F(normal.z, 7); + DEBUG_ECHO_F(mz, 7); DEBUG_ECHOLNPGM("]"); - DEBUG_EOL(); - - /** - * Use the code below to check the validity of the mesh tilting algorithm. - * 3-Point Mesh Tilt uses the same algorithm as grid-based tilting, but only - * three points are used in the calculation. This guarantees that each probed point - * has an exact match when get_z_correction() for that location is calculated. - * The Z error between the probed point locations and the get_z_correction() - * numbers for those locations should be 0. - */ - #ifdef VALIDATE_MESH_TILT - auto d_from = []{ DEBUG_ECHOPGM("D from "); }; - auto normed = [&](const xy_pos_t &pos, const float &zadd) { - return normal.x * pos.x + normal.y * pos.y + zadd; - }; - auto debug_pt = [](PGM_P const pre, const xy_pos_t &pos, const float &zadd) { - d_from(); serialprintPGM(pre); - DEBUG_ECHO_F(normed(pos, zadd), 6); - DEBUG_ECHOLNPAIR_F(" Z error = ", zadd - get_z_correction(pos), 6); - }; - debug_pt(PSTR("1st point: "), probe_pt[0], normal.z * z1); - debug_pt(PSTR("2nd point: "), probe_pt[1], normal.z * z2); - debug_pt(PSTR("3rd point: "), probe_pt[2], normal.z * z3); - d_from(); DEBUG_ECHOPGM("safe home with Z="); - DEBUG_ECHOLNPAIR_F("0 : ", normed(safe_homing_xy, 0), 6); - d_from(); DEBUG_ECHOPGM("safe home with Z="); - DEBUG_ECHOLNPAIR_F("mesh value ", normed(safe_homing_xy, get_z_correction(safe_homing_xy)), 6); - DEBUG_ECHOPAIR(" Z error = (", Z_SAFE_HOMING_X_POINT, ",", Z_SAFE_HOMING_Y_POINT); - DEBUG_ECHOLNPAIR_F(") = ", get_z_correction(safe_homing_xy), 6); - #endif - } // DEBUGGING(LEVELING) + DEBUG_DELAY(20); + } + z_values[i][j] = mz - lsf_results.D; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(i, j, z_values[i][j])); } - #endif // HAS_BED_PROBE + if (DEBUGGING(LEVELING)) { + rotation.debug(PSTR("rotation matrix:\n")); + DEBUG_ECHOPAIR_F("LSF Results A=", lsf_results.A, 7); + DEBUG_ECHOPAIR_F(" B=", lsf_results.B, 7); + DEBUG_ECHOLNPAIR_F(" D=", lsf_results.D, 7); + DEBUG_DELAY(55); + + DEBUG_ECHOPAIR_F("bed plane normal = [", normal.x, 7); + DEBUG_CHAR(','); + DEBUG_ECHO_F(normal.y, 7); + DEBUG_CHAR(','); + DEBUG_ECHO_F(normal.z, 7); + DEBUG_ECHOLNPGM("]"); + DEBUG_EOL(); + + /** + * Use the code below to check the validity of the mesh tilting algorithm. + * 3-Point Mesh Tilt uses the same algorithm as grid-based tilting, but only + * three points are used in the calculation. This guarantees that each probed point + * has an exact match when get_z_correction() for that location is calculated. + * The Z error between the probed point locations and the get_z_correction() + * numbers for those locations should be 0. + */ + #ifdef VALIDATE_MESH_TILT + auto d_from = []{ DEBUG_ECHOPGM("D from "); }; + auto normed = [&](const xy_pos_t &pos, const float &zadd) { + return normal.x * pos.x + normal.y * pos.y + zadd; + }; + auto debug_pt = [](PGM_P const pre, const xy_pos_t &pos, const float &zadd) { + d_from(); SERIAL_ECHOPGM_P(pre); + DEBUG_ECHO_F(normed(pos, zadd), 6); + DEBUG_ECHOLNPAIR_F(" Z error = ", zadd - get_z_correction(pos), 6); + }; + debug_pt(PSTR("1st point: "), probe_pt[0], normal.z * z1); + debug_pt(PSTR("2nd point: "), probe_pt[1], normal.z * z2); + debug_pt(PSTR("3rd point: "), probe_pt[2], normal.z * z3); + d_from(); DEBUG_ECHOPGM("safe home with Z="); + DEBUG_ECHOLNPAIR_F("0 : ", normed(safe_homing_xy, 0), 6); + d_from(); DEBUG_ECHOPGM("safe home with Z="); + DEBUG_ECHOLNPAIR_F("mesh value ", normed(safe_homing_xy, get_z_correction(safe_homing_xy)), 6); + DEBUG_ECHOPAIR(" Z error = (", Z_SAFE_HOMING_X_POINT, ",", Z_SAFE_HOMING_Y_POINT); + DEBUG_ECHOLNPAIR_F(") = ", get_z_correction(safe_homing_xy), 6); + #endif + } // DEBUGGING(LEVELING) + + } - #if ENABLED(UBL_G29_P31) - void unified_bed_leveling::smart_fill_wlsf(const float &weight_factor) { - - // For each undefined mesh point, compute a distance-weighted least squares fit - // from all the originally populated mesh points, weighted toward the point - // being extrapolated so that nearby points will have greater influence on - // the point being extrapolated. Then extrapolate the mesh point from WLSF. - - static_assert((GRID_MAX_POINTS_Y) <= 16, "GRID_MAX_POINTS_Y too big"); - uint16_t bitmap[GRID_MAX_POINTS_X] = { 0 }; - struct linear_fit_data lsf_results; - - SERIAL_ECHOPGM("Extrapolating mesh..."); - - const float weight_scaled = weight_factor * _MAX(MESH_X_DIST, MESH_Y_DIST); - - GRID_LOOP(jx, jy) if (!isnan(z_values[jx][jy])) SBI(bitmap[jx], jy); - - xy_pos_t ppos; - LOOP_L_N(ix, GRID_MAX_POINTS_X) { - ppos.x = mesh_index_to_xpos(ix); - LOOP_L_N(iy, GRID_MAX_POINTS_Y) { - ppos.y = mesh_index_to_ypos(iy); - if (isnan(z_values[ix][iy])) { - // undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points. - incremental_LSF_reset(&lsf_results); - xy_pos_t rpos; - LOOP_L_N(jx, GRID_MAX_POINTS_X) { - rpos.x = mesh_index_to_xpos(jx); - LOOP_L_N(jy, GRID_MAX_POINTS_Y) { - if (TEST(bitmap[jx], jy)) { - rpos.y = mesh_index_to_ypos(jy); - const float rz = z_values[jx][jy], - w = 1.0f + weight_scaled / (rpos - ppos).magnitude(); - incremental_WLSF(&lsf_results, rpos, rz, w); - } +#endif // HAS_BED_PROBE + +#if ENABLED(UBL_G29_P31) + void unified_bed_leveling::smart_fill_wlsf(const float &weight_factor) { + + // For each undefined mesh point, compute a distance-weighted least squares fit + // from all the originally populated mesh points, weighted toward the point + // being extrapolated so that nearby points will have greater influence on + // the point being extrapolated. Then extrapolate the mesh point from WLSF. + + static_assert((GRID_MAX_POINTS_Y) <= 16, "GRID_MAX_POINTS_Y too big"); + uint16_t bitmap[GRID_MAX_POINTS_X] = { 0 }; + struct linear_fit_data lsf_results; + + SERIAL_ECHOPGM("Extrapolating mesh..."); + + const float weight_scaled = weight_factor * _MAX(MESH_X_DIST, MESH_Y_DIST); + + GRID_LOOP(jx, jy) if (!isnan(z_values[jx][jy])) SBI(bitmap[jx], jy); + + xy_pos_t ppos; + LOOP_L_N(ix, GRID_MAX_POINTS_X) { + ppos.x = mesh_index_to_xpos(ix); + LOOP_L_N(iy, GRID_MAX_POINTS_Y) { + ppos.y = mesh_index_to_ypos(iy); + if (isnan(z_values[ix][iy])) { + // undefined mesh point at (ppos.x,ppos.y), compute weighted LSF from original valid mesh points. + incremental_LSF_reset(&lsf_results); + xy_pos_t rpos; + LOOP_L_N(jx, GRID_MAX_POINTS_X) { + rpos.x = mesh_index_to_xpos(jx); + LOOP_L_N(jy, GRID_MAX_POINTS_Y) { + if (TEST(bitmap[jx], jy)) { + rpos.y = mesh_index_to_ypos(jy); + const float rz = z_values[jx][jy], + w = 1.0f + weight_scaled / (rpos - ppos).magnitude(); + incremental_WLSF(&lsf_results, rpos, rz, w); } } - if (finish_incremental_LSF(&lsf_results)) { - SERIAL_ECHOLNPGM("Insufficient data"); - return; - } - const float ez = -lsf_results.D - lsf_results.A * ppos.x - lsf_results.B * ppos.y; - z_values[ix][iy] = ez; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, z_values[ix][iy])); - idle(); // housekeeping } + if (finish_incremental_LSF(&lsf_results)) { + SERIAL_ECHOLNPGM("Insufficient data"); + return; + } + const float ez = -lsf_results.D - lsf_results.A * ppos.x - lsf_results.B * ppos.y; + z_values[ix][iy] = ez; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(ix, iy, z_values[ix][iy])); + idle(); // housekeeping } } - - SERIAL_ECHOLNPGM("done"); } - #endif // UBL_G29_P31 - #if ENABLED(UBL_DEVEL_DEBUGGING) - /** - * Much of the 'What?' command can be eliminated. But until we are fully debugged, it is - * good to have the extra information. Soon... we prune this to just a few items - */ - void unified_bed_leveling::g29_what_command() { - report_state(); - - if (storage_slot == -1) - SERIAL_ECHOPGM("No Mesh Loaded."); - else - SERIAL_ECHOPAIR("Mesh ", storage_slot, " Loaded."); - SERIAL_EOL(); - serial_delay(50); + SERIAL_ECHOLNPGM("done"); + } +#endif // UBL_G29_P31 - #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) - SERIAL_ECHOLNPAIR_F("Fade Height M420 Z", planner.z_fade_height, 4); - #endif +#if ENABLED(UBL_DEVEL_DEBUGGING) + /** + * Much of the 'What?' command can be eliminated. But until we are fully debugged, it is + * good to have the extra information. Soon... we prune this to just a few items + */ + void unified_bed_leveling::g29_what_command() { + report_state(); - adjust_mesh_to_mean(g29_c_flag, g29_constant); + if (storage_slot == -1) + SERIAL_ECHOPGM("No Mesh Loaded."); + else + SERIAL_ECHOPAIR("Mesh ", storage_slot, " Loaded."); + SERIAL_EOL(); + serial_delay(50); - #if HAS_BED_PROBE - SERIAL_ECHOLNPAIR_F("Probe Offset M851 Z", probe.offset.z, 7); - #endif + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) + SERIAL_ECHOLNPAIR_F("Fade Height M420 Z", planner.z_fade_height, 4); + #endif - SERIAL_ECHOLNPAIR("MESH_MIN_X " STRINGIFY(MESH_MIN_X) "=", MESH_MIN_X); serial_delay(50); - SERIAL_ECHOLNPAIR("MESH_MIN_Y " STRINGIFY(MESH_MIN_Y) "=", MESH_MIN_Y); serial_delay(50); - SERIAL_ECHOLNPAIR("MESH_MAX_X " STRINGIFY(MESH_MAX_X) "=", MESH_MAX_X); serial_delay(50); - SERIAL_ECHOLNPAIR("MESH_MAX_Y " STRINGIFY(MESH_MAX_Y) "=", MESH_MAX_Y); serial_delay(50); - SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X ", GRID_MAX_POINTS_X); serial_delay(50); - SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_Y ", GRID_MAX_POINTS_Y); serial_delay(50); - SERIAL_ECHOLNPAIR("MESH_X_DIST ", MESH_X_DIST); - SERIAL_ECHOLNPAIR("MESH_Y_DIST ", MESH_Y_DIST); serial_delay(50); - - SERIAL_ECHOPGM("X-Axis Mesh Points at: "); - LOOP_L_N(i, GRID_MAX_POINTS_X) { - SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3); - SERIAL_ECHOPGM(" "); - serial_delay(25); - } - SERIAL_EOL(); + adjust_mesh_to_mean(g29_c_flag, g29_constant); - SERIAL_ECHOPGM("Y-Axis Mesh Points at: "); - LOOP_L_N(i, GRID_MAX_POINTS_Y) { - SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3); - SERIAL_ECHOPGM(" "); - serial_delay(25); - } - SERIAL_EOL(); + #if HAS_BED_PROBE + SERIAL_ECHOLNPAIR_F("Probe Offset M851 Z", probe.offset.z, 7); + #endif - #if HAS_KILL - SERIAL_ECHOLNPAIR("Kill pin on :", KILL_PIN, " state:", kill_state()); - #endif + SERIAL_ECHOLNPAIR("MESH_MIN_X " STRINGIFY(MESH_MIN_X) "=", MESH_MIN_X); serial_delay(50); + SERIAL_ECHOLNPAIR("MESH_MIN_Y " STRINGIFY(MESH_MIN_Y) "=", MESH_MIN_Y); serial_delay(50); + SERIAL_ECHOLNPAIR("MESH_MAX_X " STRINGIFY(MESH_MAX_X) "=", MESH_MAX_X); serial_delay(50); + SERIAL_ECHOLNPAIR("MESH_MAX_Y " STRINGIFY(MESH_MAX_Y) "=", MESH_MAX_Y); serial_delay(50); + SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_X ", GRID_MAX_POINTS_X); serial_delay(50); + SERIAL_ECHOLNPAIR("GRID_MAX_POINTS_Y ", GRID_MAX_POINTS_Y); serial_delay(50); + SERIAL_ECHOLNPAIR("MESH_X_DIST ", MESH_X_DIST); + SERIAL_ECHOLNPAIR("MESH_Y_DIST ", MESH_Y_DIST); serial_delay(50); + + SERIAL_ECHOPGM("X-Axis Mesh Points at: "); + LOOP_L_N(i, GRID_MAX_POINTS_X) { + SERIAL_ECHO_F(LOGICAL_X_POSITION(mesh_index_to_xpos(i)), 3); + SERIAL_ECHOPGM(" "); + serial_delay(25); + } + SERIAL_EOL(); - SERIAL_EOL(); - serial_delay(50); + SERIAL_ECHOPGM("Y-Axis Mesh Points at: "); + LOOP_L_N(i, GRID_MAX_POINTS_Y) { + SERIAL_ECHO_F(LOGICAL_Y_POSITION(mesh_index_to_ypos(i)), 3); + SERIAL_ECHOPGM(" "); + serial_delay(25); + } + SERIAL_EOL(); - #if ENABLED(UBL_DEVEL_DEBUGGING) - SERIAL_ECHOLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation, "\nubl_state_recursion_chk :", ubl_state_recursion_chk); - serial_delay(50); + #if HAS_KILL + SERIAL_ECHOLNPAIR("Kill pin on :", KILL_PIN, " state:", kill_state()); + #endif + + SERIAL_EOL(); + serial_delay(50); - SERIAL_ECHOLNPAIR("Meshes go from ", hex_address((void*)settings.meshes_start_index()), " to ", hex_address((void*)settings.meshes_end_index())); - serial_delay(50); + #if ENABLED(UBL_DEVEL_DEBUGGING) + SERIAL_ECHOLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation, "\nubl_state_recursion_chk :", ubl_state_recursion_chk); + serial_delay(50); + + SERIAL_ECHOLNPAIR("Meshes go from ", hex_address((void*)settings.meshes_start_index()), " to ", hex_address((void*)settings.meshes_end_index())); + serial_delay(50); - SERIAL_ECHOLNPAIR("sizeof(ubl) : ", sizeof(ubl)); SERIAL_EOL(); - SERIAL_ECHOLNPAIR("z_value[][] size: ", sizeof(z_values)); SERIAL_EOL(); - serial_delay(25); + SERIAL_ECHOLNPAIR("sizeof(ubl) : ", sizeof(ubl)); SERIAL_EOL(); + SERIAL_ECHOLNPAIR("z_value[][] size: ", sizeof(z_values)); SERIAL_EOL(); + serial_delay(25); - SERIAL_ECHOLNPAIR("EEPROM free for UBL: ", hex_address((void*)(settings.meshes_end_index() - settings.meshes_start_index()))); - serial_delay(50); + SERIAL_ECHOLNPAIR("EEPROM free for UBL: ", hex_address((void*)(settings.meshes_end_index() - settings.meshes_start_index()))); + serial_delay(50); - SERIAL_ECHOLNPAIR("EEPROM can hold ", settings.calc_num_meshes(), " meshes.\n"); - serial_delay(25); - #endif // UBL_DEVEL_DEBUGGING + SERIAL_ECHOLNPAIR("EEPROM can hold ", settings.calc_num_meshes(), " meshes.\n"); + serial_delay(25); + #endif // UBL_DEVEL_DEBUGGING - if (!sanity_check()) { - echo_name(); - SERIAL_ECHOLNPGM(" sanity checks passed."); - } + if (!sanity_check()) { + echo_name(); + SERIAL_ECHOLNPGM(" sanity checks passed."); } + } - /** - * When we are fully debugged, the EEPROM dump command will get deleted also. But - * right now, it is good to have the extra information. Soon... we prune this. - */ - void unified_bed_leveling::g29_eeprom_dump() { - uint8_t cccc; - - SERIAL_ECHO_MSG("EEPROM Dump:"); - persistentStore.access_start(); - for (uint16_t i = 0; i < persistentStore.capacity(); i += 16) { - if (!(i & 0x3)) idle(); - print_hex_word(i); - SERIAL_ECHOPGM(": "); - for (uint16_t j = 0; j < 16; j++) { - persistentStore.read_data(i + j, &cccc, sizeof(uint8_t)); - print_hex_byte(cccc); - SERIAL_CHAR(' '); - } - SERIAL_EOL(); + /** + * When we are fully debugged, the EEPROM dump command will get deleted also. But + * right now, it is good to have the extra information. Soon... we prune this. + */ + void unified_bed_leveling::g29_eeprom_dump() { + uint8_t cccc; + + SERIAL_ECHO_MSG("EEPROM Dump:"); + persistentStore.access_start(); + for (uint16_t i = 0; i < persistentStore.capacity(); i += 16) { + if (!(i & 0x3)) idle(); + print_hex_word(i); + SERIAL_ECHOPGM(": "); + for (uint16_t j = 0; j < 16; j++) { + persistentStore.read_data(i + j, &cccc, sizeof(uint8_t)); + print_hex_byte(cccc); + SERIAL_CHAR(' '); } SERIAL_EOL(); - persistentStore.access_finish(); } + SERIAL_EOL(); + persistentStore.access_finish(); + } - /** - * When we are fully debugged, this may go away. But there are some valid - * use cases for the users. So we can wait and see what to do with it. - */ - void unified_bed_leveling::g29_compare_current_mesh_to_stored_mesh() { - const int16_t a = settings.calc_num_meshes(); + /** + * When we are fully debugged, this may go away. But there are some valid + * use cases for the users. So we can wait and see what to do with it. + */ + void unified_bed_leveling::g29_compare_current_mesh_to_stored_mesh() { + const int16_t a = settings.calc_num_meshes(); - if (!a) { - SERIAL_ECHOLNPGM("?EEPROM storage not available."); - return; - } + if (!a) { + SERIAL_ECHOLNPGM("?EEPROM storage not available."); + return; + } - if (!parser.has_value() || !WITHIN(g29_storage_slot, 0, a - 1)) { - SERIAL_ECHOLNPAIR("?Invalid storage slot.\n?Use 0 to ", a - 1); - return; - } + if (!parser.has_value() || !WITHIN(g29_storage_slot, 0, a - 1)) { + SERIAL_ECHOLNPAIR("?Invalid storage slot.\n?Use 0 to ", a - 1); + return; + } - g29_storage_slot = parser.value_int(); + g29_storage_slot = parser.value_int(); - float tmp_z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; - settings.load_mesh(g29_storage_slot, &tmp_z_values); + float tmp_z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; + settings.load_mesh(g29_storage_slot, &tmp_z_values); - SERIAL_ECHOLNPAIR("Subtracting mesh in slot ", g29_storage_slot, " from current mesh."); + SERIAL_ECHOLNPAIR("Subtracting mesh in slot ", g29_storage_slot, " from current mesh."); - GRID_LOOP(x, y) { - z_values[x][y] -= tmp_z_values[x][y]; - TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); - } + GRID_LOOP(x, y) { + z_values[x][y] -= tmp_z_values[x][y]; + TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y])); } + } - #endif // UBL_DEVEL_DEBUGGING +#endif // UBL_DEVEL_DEBUGGING #endif // AUTO_BED_LEVELING_UBL diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp index 8b7cd15a3c6d..33b4f03ac290 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp @@ -335,7 +335,7 @@ #if IS_KINEMATIC const float seconds = cart_xy_mm / scaled_fr_mm_s; // Duration of XY move at requested rate - uint16_t segments = LROUND(delta_segments_per_second * seconds), // Preferred number of segments for distance @ feedrate + uint16_t segments = LROUND(segments_per_second * seconds), // Preferred number of segments for distance @ feedrate seglimit = LROUND(cart_xy_mm * RECIPROCAL(DELTA_SEGMENT_MIN_LENGTH)); // Number of segments at minimum segment length NOMORE(segments, seglimit); // Limit to minimum segment length (fewer segments) #else diff --git a/Marlin/src/feature/caselight.cpp b/Marlin/src/feature/caselight.cpp index 0eba102a04b2..d4cc6b150466 100644 --- a/Marlin/src/feature/caselight.cpp +++ b/Marlin/src/feature/caselight.cpp @@ -28,6 +28,10 @@ CaseLight caselight; +#if CASE_LIGHT_IS_COLOR_LED + #include "leds/leds.h" +#endif + #if CASELIGHT_USES_BRIGHTNESS && !defined(CASE_LIGHT_DEFAULT_BRIGHTNESS) #define CASE_LIGHT_DEFAULT_BRIGHTNESS 0 // For use on PWM pin as non-PWM just sets a default #endif @@ -38,10 +42,10 @@ CaseLight caselight; bool CaseLight::on = CASE_LIGHT_DEFAULT_ON; -#if ENABLED(CASE_LIGHT_USE_NEOPIXEL) +#if CASE_LIGHT_IS_COLOR_LED LEDColor CaseLight::color = - #ifdef CASE_LIGHT_NEOPIXEL_COLOR - CASE_LIGHT_NEOPIXEL_COLOR + #ifdef CASE_LIGHT_DEFAULT_COLOR + CASE_LIGHT_DEFAULT_COLOR #else { 255, 255, 255, 255 } #endif @@ -71,17 +75,17 @@ void CaseLight::update(const bool sflag) { const uint8_t i = on ? brightness : 0, n10ct = INVERT_CASE_LIGHT ? 255 - i : i; #endif - #if ENABLED(CASE_LIGHT_USE_NEOPIXEL) + #if CASE_LIGHT_IS_COLOR_LED leds.set_color( MakeLEDColor(color.r, color.g, color.b, color.w, n10ct), false ); - #else // !CASE_LIGHT_USE_NEOPIXEL + #else // !CASE_LIGHT_IS_COLOR_LED #if CASELIGHT_USES_BRIGHTNESS - if (PWM_PIN(CASE_LIGHT_PIN)) + if (pin_is_pwm()) analogWrite(pin_t(CASE_LIGHT_PIN), ( #if CASE_LIGHT_MAX_PWM == 255 n10ct @@ -96,7 +100,11 @@ void CaseLight::update(const bool sflag) { WRITE(CASE_LIGHT_PIN, s ? HIGH : LOW); } - #endif // !CASE_LIGHT_USE_NEOPIXEL + #endif // !CASE_LIGHT_IS_COLOR_LED + + #if ENABLED(CASE_LIGHT_USE_RGB_LED) + if (leds.lights_on) leds.update(); else leds.set_off(); + #endif } #endif // CASE_LIGHT_ENABLE diff --git a/Marlin/src/feature/caselight.h b/Marlin/src/feature/caselight.h index 2198c85f2a8e..25bcb486faaf 100644 --- a/Marlin/src/feature/caselight.h +++ b/Marlin/src/feature/caselight.h @@ -21,10 +21,10 @@ */ #pragma once -#include "../inc/MarlinConfigPre.h" +#include "../inc/MarlinConfig.h" -#if ENABLED(CASE_LIGHT_USE_NEOPIXEL) - #include "leds/leds.h" +#if CASE_LIGHT_IS_COLOR_LED + #include "leds/leds.h" // for LEDColor #endif #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) || ENABLED(CASE_LIGHT_USE_NEOPIXEL) @@ -33,19 +33,25 @@ class CaseLight { public: - #if CASELIGHT_USES_BRIGHTNESS - static uint8_t brightness; - #endif static bool on; + TERN_(CASELIGHT_USES_BRIGHTNESS, static uint8_t brightness); + + static bool pin_is_pwm() { return TERN0(NEED_CASE_LIGHT_PIN, PWM_PIN(CASE_LIGHT_PIN)); } + static bool has_brightness() { return TERN0(CASELIGHT_USES_BRIGHTNESS, TERN(CASE_LIGHT_USE_NEOPIXEL, true, pin_is_pwm())); } + + static void init() { + #if NEED_CASE_LIGHT_PIN + if (pin_is_pwm()) SET_PWM(CASE_LIGHT_PIN); else SET_OUTPUT(CASE_LIGHT_PIN); + #endif + update_brightness(); + } static void update(const bool sflag); static inline void update_brightness() { update(false); } - static inline void update_enabled() { update(true); } + static inline void update_enabled() { update(true); } private: - #if ENABLED(CASE_LIGHT_USE_NEOPIXEL) - static LEDColor color; - #endif + TERN_(CASE_LIGHT_IS_COLOR_LED, static LEDColor color); }; extern CaseLight caselight; diff --git a/Marlin/src/feature/host_actions.cpp b/Marlin/src/feature/host_actions.cpp index c194fb7a5b47..2a0b3dc3d5b9 100644 --- a/Marlin/src/feature/host_actions.cpp +++ b/Marlin/src/feature/host_actions.cpp @@ -40,7 +40,7 @@ void host_action(PGM_P const pstr, const bool eol) { PORT_REDIRECT(SERIAL_ALL); SERIAL_ECHOPGM("//action:"); - serialprintPGM(pstr); + SERIAL_ECHOPGM_P(pstr); if (eol) SERIAL_EOL(); } @@ -86,14 +86,13 @@ void host_action(PGM_P const pstr, const bool eol) { void host_action_notify_P(PGM_P const message) { PORT_REDIRECT(SERIAL_ALL); host_action(PSTR("notification "), false); - serialprintPGM(message); - SERIAL_EOL(); + SERIAL_ECHOLNPGM_P(message); } void host_action_prompt(PGM_P const ptype, const bool eol=true) { PORT_REDIRECT(SERIAL_ALL); host_action(PSTR("prompt_"), false); - serialprintPGM(ptype); + SERIAL_ECHOPGM_P(ptype); if (eol) SERIAL_EOL(); } @@ -101,7 +100,7 @@ void host_action(PGM_P const pstr, const bool eol) { host_action_prompt(ptype, false); PORT_REDIRECT(SERIAL_ALL); SERIAL_CHAR(' '); - serialprintPGM(pstr); + SERIAL_ECHOPGM_P(pstr); if (extra_char != '\0') SERIAL_CHAR(extra_char); SERIAL_EOL(); } @@ -143,24 +142,16 @@ void host_action(PGM_P const pstr, const bool eol) { // - Dismissal of info // void host_response_handler(const uint8_t response) { - #ifdef DEBUG_HOST_ACTIONS - static PGMSTR(m876_prefix, "M876 Handle Re"); - serialprintPGM(m876_prefix); SERIAL_ECHOLNPAIR("ason: ", host_prompt_reason); - serialprintPGM(m876_prefix); SERIAL_ECHOLNPAIR("sponse: ", response); - #endif - PGM_P msg = PSTR("UNKNOWN STATE"); const PromptReason hpr = host_prompt_reason; host_prompt_reason = PROMPT_NOT_DEFINED; // Reset now ahead of logic switch (hpr) { case PROMPT_FILAMENT_RUNOUT: - msg = PSTR("FILAMENT_RUNOUT"); switch (response) { case 0: // "Purge More" button #if BOTH(HAS_LCD_MENU, ADVANCED_PAUSE_FEATURE) pause_menu_response = PAUSE_RESPONSE_EXTRUDE_MORE; // Simulate menu selection (menu exits, doesn't extrude more) #endif - filament_load_host_prompt(); // Initiate another host prompt. (NOTE: The loop in load_filament may also do this!) break; case 1: // "Continue" / "Disable Runout" button @@ -178,23 +169,17 @@ void host_action(PGM_P const pstr, const bool eol) { break; case PROMPT_USER_CONTINUE: TERN_(HAS_RESUME_CONTINUE, wait_for_user = false); - msg = PSTR("FILAMENT_RUNOUT_CONTINUE"); break; case PROMPT_PAUSE_RESUME: - msg = PSTR("LCD_PAUSE_RESUME"); #if BOTH(ADVANCED_PAUSE_FEATURE, SDSUPPORT) extern const char M24_STR[]; queue.inject_P(M24_STR); #endif break; case PROMPT_INFO: - msg = PSTR("GCODE_INFO"); break; default: break; } - SERIAL_ECHOPGM("M876 Responding PROMPT_"); - serialprintPGM(msg); - SERIAL_EOL(); } #endif // HOST_PROMPT_SUPPORT diff --git a/Marlin/src/feature/leds/leds.cpp b/Marlin/src/feature/leds/leds.cpp index c8cbdec33be6..ef0561a435f2 100644 --- a/Marlin/src/feature/leds/leds.cpp +++ b/Marlin/src/feature/leds/leds.cpp @@ -42,6 +42,10 @@ #include "pca9533.h" #endif +#if ENABLED(CASE_LIGHT_USE_RGB_LED) + #include "../../feature/caselight.h" +#endif + #if ENABLED(LED_COLOR_PRESETS) const LEDColor LEDLights::defaultLEDColor = MakeLEDColor( LED_USER_PRESET_RED, LED_USER_PRESET_GREEN, LED_USER_PRESET_BLUE, @@ -85,8 +89,11 @@ void LEDLights::set_color(const LEDColor &incol #ifdef NEOPIXEL_BKGD_LED_INDEX if (NEOPIXEL_BKGD_LED_INDEX == nextLed) { - if (++nextLed >= neo.pixels()) nextLed = 0; - return; + neo.set_color_background(); + if (++nextLed >= neo.pixels()) { + nextLed = 0; + return; + } } #endif @@ -114,12 +121,13 @@ void LEDLights::set_color(const LEDColor &incol // This variant uses 3-4 separate pins for the RGB(W) components. // If the pins can do PWM then their intensity will be set. - #define UPDATE_RGBW(C,c) do { \ - if (PWM_PIN(RGB_LED_##C##_PIN)) \ - analogWrite(pin_t(RGB_LED_##C##_PIN), incol.c); \ - else \ - WRITE(RGB_LED_##C##_PIN, incol.c ? HIGH : LOW); \ + #define _UPDATE_RGBW(C,c) do { \ + if (PWM_PIN(RGB_LED_##C##_PIN)) \ + analogWrite(pin_t(RGB_LED_##C##_PIN), c); \ + else \ + WRITE(RGB_LED_##C##_PIN, c ? HIGH : LOW); \ }while(0) + #define UPDATE_RGBW(C,c) _UPDATE_RGBW(C, TERN1(CASE_LIGHT_USE_RGB_LED, caselight.on) ? incol.c : 0) UPDATE_RGBW(R,r); UPDATE_RGBW(G,g); UPDATE_RGBW(B,b); #if ENABLED(RGBW_LED) UPDATE_RGBW(W,w); diff --git a/Marlin/src/feature/leds/leds.h b/Marlin/src/feature/leds/leds.h index d41c61144aca..c34eb57f4493 100644 --- a/Marlin/src/feature/leds/leds.h +++ b/Marlin/src/feature/leds/leds.h @@ -194,6 +194,8 @@ class LEDLights { #if ENABLED(LED_CONTROL_MENU) static void toggle(); // swap "off" with color + #endif + #if EITHER(LED_CONTROL_MENU, CASE_LIGHT_USE_RGB_LED) static inline void update() { set_color(color); } #endif diff --git a/Marlin/src/feature/leds/neopixel.cpp b/Marlin/src/feature/leds/neopixel.cpp index 27bbeb348c5d..bdd22837ada5 100644 --- a/Marlin/src/feature/leds/neopixel.cpp +++ b/Marlin/src/feature/leds/neopixel.cpp @@ -60,7 +60,7 @@ void Marlin_NeoPixel::set_color(const uint32_t color) { else { for (uint16_t i = 0; i < pixels(); ++i) { #ifdef NEOPIXEL_BKGD_LED_INDEX - if (i == NEOPIXEL_BKGD_LED_INDEX && color != 0x000000) { + if (i == NEOPIXEL_BKGD_LED_INDEX && TERN(NEOPIXEL_BKGD_ALWAYS_ON, true, color != 0x000000)) { set_color_background(); continue; } diff --git a/Marlin/src/feature/leds/printer_event_leds.cpp b/Marlin/src/feature/leds/printer_event_leds.cpp index 3a6b91a258b9..32c68627045c 100644 --- a/Marlin/src/feature/leds/printer_event_leds.cpp +++ b/Marlin/src/feature/leds/printer_event_leds.cpp @@ -77,6 +77,19 @@ PrinterEventLEDs printerEventLEDs; pel_set_rgb(red, 0, 255); } } + +#endif + +#if HAS_HEATED_CHAMBER + + void PrinterEventLEDs::onChamberHeating(const float &start, const float ¤t, const float &target) { + const uint8_t green = pel_intensity(start, current, target); + if (green != old_intensity) { + old_intensity = green; + pel_set_rgb(255, green, 255); + } + } + #endif #endif // PRINTER_EVENT_LEDS diff --git a/Marlin/src/feature/leds/printer_event_leds.h b/Marlin/src/feature/leds/printer_event_leds.h index 86ec292aa3da..668c9c969be0 100644 --- a/Marlin/src/feature/leds/printer_event_leds.h +++ b/Marlin/src/feature/leds/printer_event_leds.h @@ -55,7 +55,12 @@ class PrinterEventLEDs { static void onBedHeating(const float &start, const float ¤t, const float &target); #endif - #if HAS_TEMP_HOTEND || HAS_HEATED_BED + #if HAS_HEATED_CHAMBER + static inline LEDColor onChamberHeatingStart() { old_intensity = 127; return leds.get_color(); } + static void onChamberHeating(const float &start, const float ¤t, const float &target); + #endif + + #if HAS_TEMP_HOTEND || HAS_HEATED_BED || HAS_HEATED_CHAMBER static inline void onHeatingDone() { leds.set_white(); } static inline void onPidTuningDone(LEDColor c) { leds.set_color(c); } #endif diff --git a/Marlin/src/feature/max7219.cpp b/Marlin/src/feature/max7219.cpp index ebcb56490d4f..d7433cb7d93d 100644 --- a/Marlin/src/feature/max7219.cpp +++ b/Marlin/src/feature/max7219.cpp @@ -127,7 +127,7 @@ uint8_t Max7219::suspended; // = 0; void Max7219::error(const char * const func, const int32_t v1, const int32_t v2/*=-1*/) { #if ENABLED(MAX7219_ERRORS) SERIAL_ECHOPGM("??? Max7219::"); - serialprintPGM(func); + SERIAL_ECHOPGM_P(func); SERIAL_CHAR('('); SERIAL_ECHO(v1); if (v2 > 0) SERIAL_ECHOPAIR(", ", v2); diff --git a/Marlin/src/feature/meatpack.cpp b/Marlin/src/feature/meatpack.cpp index cd6d8ce6b971..7e81dbed79df 100644 --- a/Marlin/src/feature/meatpack.cpp +++ b/Marlin/src/feature/meatpack.cpp @@ -110,7 +110,7 @@ void MeatPack::handle_rx_char_inner(const uint8_t c) { if (TEST(state, MPConfig_Bit_Active)) { // Is MeatPack active? if (!full_char_count) { // No literal characters to fetch? uint8_t buf[2] = { 0, 0 }; - register const uint8_t res = unpack_chars(c, buf); // Decode the byte into one or two characters. + const uint8_t res = unpack_chars(c, buf); // Decode the byte into one or two characters. if (res & kFirstCharIsLiteral) { // The 1st character couldn't be packed. ++full_char_count; // So the next stream byte is a full character. if (res & kSecondCharIsLiteral) ++full_char_count; // The 2nd character couldn't be packed. Another stream byte is a full character. @@ -147,9 +147,7 @@ void MeatPack::handle_output_char(const uint8_t c) { #if ENABLED(MP_DEBUG) if (chars_decoded < 1024) { ++chars_decoded; - DEBUG_ECHOPGM("RB: "); - MYSERIAL.print((char)c); - DEBUG_EOL(); + DEBUG_ECHOLNPAIR("RB: ", AS_CHAR(c)); } #endif } @@ -181,7 +179,7 @@ void MeatPack::report_state() { SERIAL_ECHOPGM("[MP] "); SERIAL_ECHOPGM(MeatPack_ProtocolVersion " "); serialprint_onoff(TEST(state, MPConfig_Bit_Active)); - serialprintPGM(TEST(state, MPConfig_Bit_NoSpaces) ? PSTR(" NSP\n") : PSTR(" ESP\n")); + SERIAL_ECHOPGM_P(TEST(state, MPConfig_Bit_NoSpaces) ? PSTR(" NSP\n") : PSTR(" ESP\n")); } /** @@ -200,7 +198,7 @@ void MeatPack::handle_rx_char(const uint8_t c, const serial_index_t serial_ind) } if (cmd_is_next) { // Were two command bytes received? - PORT_REDIRECT(serial_ind); + PORT_REDIRECT(SERIAL_PORTMASK(serial_ind)); handle_command((MeatPack_Command)c); // Then the byte is a MeatPack command cmd_is_next = false; return; @@ -219,7 +217,7 @@ uint8_t MeatPack::get_result_char(char* const __restrict out) { if (char_out_count) { res = char_out_count; char_out_count = 0; - for (register uint8_t i = 0; i < res; ++i) + for (uint8_t i = 0; i < res; ++i) out[i] = (char)char_out_buf[i]; } return res; diff --git a/Marlin/src/feature/meatpack.h b/Marlin/src/feature/meatpack.h index 2641130bd880..e30a5ac979c1 100644 --- a/Marlin/src/feature/meatpack.h +++ b/Marlin/src/feature/meatpack.h @@ -49,6 +49,7 @@ #pragma once #include +#include "../core/serial_hook.h" /** * Commands sent to MeatPack to control its behavior. @@ -78,8 +79,6 @@ enum MeatPack_ConfigStateBits : uint8_t { }; class MeatPack { -private: - friend class GCodeQueue; // Utility definitions static const uint8_t kCommandByte = 0b11111111, @@ -99,6 +98,7 @@ class MeatPack { char_out_count; // Stores number of characters to be read out. static uint8_t char_out_buf[2]; // Output buffer for caching up to 2 characters +public: // Pass in a character rx'd by SD card or serial. Automatically parses command/ctrl sequences, // and will control state internally. static void handle_rx_char(const uint8_t c, const serial_index_t serial_ind); @@ -113,7 +113,6 @@ class MeatPack { static void reset_state(); static void report_state(); - static uint8_t unpacked_char(register const uint8_t in); static uint8_t unpack_chars(const uint8_t pk, uint8_t* __restrict const chars_out); static void handle_command(const MeatPack_Command c); static void handle_output_char(const uint8_t c); @@ -121,3 +120,57 @@ class MeatPack { }; extern MeatPack meatpack; + +// Implement the MeatPack serial class so it's transparent to rest of the code +template +struct MeatpackSerial : public SerialBase > { + typedef SerialBase< MeatpackSerial > BaseClassT; + + SerialT & out; + + char serialBuffer[2]; + uint8_t charCount; + uint8_t readIndex; + + NO_INLINE size_t write(uint8_t c) { return out.write(c); } + void flush() { out.flush(); } + void begin(long br) { out.begin(br); readIndex = 0; } + void end() { out.end(); } + + void msgDone() { out.msgDone(); } + // Existing instances implement Arduino's operator bool, so use that if it's available + bool connected() { return Private::HasMember_connected::value ? CALL_IF_EXISTS(bool, &out, connected) : (bool)out; } + void flushTX() { CALL_IF_EXISTS(void, &out, flushTX); } + + int available(uint8_t index) { + // There is a potential issue here with multiserial, since it'll return its decoded buffer whatever the serial index here. + // So, instead of doing MeatpackSerial> we should do MultiSerial, MeatpackSerial<...>> + // TODO, let's fix this later on + + if (charCount) return charCount; // The buffer still has data + if (out.available(index) <= 0) return 0; // No data to read + + // Don't read in read method, instead do it here, so we can make progress in the read method + const int r = out.read(index); + if (r == -1) return 0; // This is an error from the underlying serial code + meatpack.handle_rx_char((uint8_t)r, index); + charCount = meatpack.get_result_char(serialBuffer); + readIndex = 0; + + return charCount; + } + + int readImpl(const uint8_t index) { + // Not enough char to make progress? + if (charCount == 0 && available(index) == 0) return -1; + + charCount--; + return serialBuffer[readIndex++]; + } + + int read(uint8_t index) { return readImpl(index); } + int available() { return available(0); } + int read() { return readImpl(0); } + + MeatpackSerial(const bool e, SerialT & out) : BaseClassT(e), out(out) {} +}; diff --git a/Marlin/src/feature/mmu/mmu2.cpp b/Marlin/src/feature/mmu/mmu2.cpp index 1aa53ef5eb95..a1bec36e4578 100644 --- a/Marlin/src/feature/mmu/mmu2.cpp +++ b/Marlin/src/feature/mmu/mmu2.cpp @@ -62,29 +62,13 @@ MMU2 mmu2; #endif #define MMU_CMD_NONE 0 -#define MMU_CMD_T0 0x10 -#define MMU_CMD_T1 0x11 -#define MMU_CMD_T2 0x12 -#define MMU_CMD_T3 0x13 -#define MMU_CMD_T4 0x14 -#define MMU_CMD_L0 0x20 -#define MMU_CMD_L1 0x21 -#define MMU_CMD_L2 0x22 -#define MMU_CMD_L3 0x23 -#define MMU_CMD_L4 0x24 +#define MMU_CMD_T0 0x10 // up to supported filaments +#define MMU_CMD_L0 0x20 // up to supported filaments #define MMU_CMD_C0 0x30 #define MMU_CMD_U0 0x40 -#define MMU_CMD_E0 0x50 -#define MMU_CMD_E1 0x51 -#define MMU_CMD_E2 0x52 -#define MMU_CMD_E3 0x53 -#define MMU_CMD_E4 0x54 +#define MMU_CMD_E0 0x50 // up to supported filaments #define MMU_CMD_R0 0x60 -#define MMU_CMD_F0 0x70 -#define MMU_CMD_F1 0x71 -#define MMU_CMD_F2 0x72 -#define MMU_CMD_F3 0x73 -#define MMU_CMD_F4 0x74 +#define MMU_CMD_F0 0x70 // up to supported filaments #define MMU_REQUIRED_FW_BUILDNR TERN(MMU2_MODE_12V, 132, 126) @@ -243,7 +227,7 @@ void MMU2::mmu_loop() { case 1: if (cmd) { - if (WITHIN(cmd, MMU_CMD_T0, MMU_CMD_T4)) { + if (WITHIN(cmd, MMU_CMD_T0, MMU_CMD_T0 + EXTRUDERS - 1)) { // tool change int filament = cmd - MMU_CMD_T0; DEBUG_ECHOLNPAIR("MMU <= T", filament); @@ -251,7 +235,7 @@ void MMU2::mmu_loop() { TERN_(MMU_EXTRUDER_SENSOR, mmu_idl_sens = 1); // enable idler sensor, if any state = 3; // wait for response } - else if (WITHIN(cmd, MMU_CMD_L0, MMU_CMD_L4)) { + else if (WITHIN(cmd, MMU_CMD_L0, MMU_CMD_L0 + EXTRUDERS - 1)) { // load int filament = cmd - MMU_CMD_L0; DEBUG_ECHOLNPAIR("MMU <= L", filament); @@ -271,7 +255,7 @@ void MMU2::mmu_loop() { MMU2_COMMAND("U0"); state = 3; // wait for response } - else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E4)) { + else if (WITHIN(cmd, MMU_CMD_E0, MMU_CMD_E0 + EXTRUDERS - 1)) { // eject filament int filament = cmd - MMU_CMD_E0; DEBUG_ECHOLNPAIR("MMU <= E", filament); @@ -284,12 +268,10 @@ void MMU2::mmu_loop() { MMU2_COMMAND("R0"); state = 3; // wait for response } - else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F4)) { + else if (WITHIN(cmd, MMU_CMD_F0, MMU_CMD_F0 + EXTRUDERS - 1)) { // filament type int filament = cmd - MMU_CMD_F0; - DEBUG_ECHOPAIR("MMU <= F", filament, " "); - DEBUG_ECHO_F(cmd_arg, DEC); - DEBUG_EOL(); + DEBUG_ECHOLNPAIR("MMU <= F", filament, " ", cmd_arg); tx_printf_P(PSTR("F%d %d\n"), filament, cmd_arg); state = 3; // wait for response } diff --git a/Marlin/src/feature/pause.cpp b/Marlin/src/feature/pause.cpp index 012e6c6e50ab..a6a28925edaf 100644 --- a/Marlin/src/feature/pause.cpp +++ b/Marlin/src/feature/pause.cpp @@ -192,11 +192,7 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l KEEPALIVE_STATE(PAUSED_FOR_USER); wait_for_user = true; // LCD click or M108 will clear this #if ENABLED(HOST_PROMPT_SUPPORT) - const char tool = '0' - #if NUM_RUNOUT_SENSORS > 1 - + active_extruder - #endif - ; + const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, active_extruder); host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Load Filament T"), tool, CONTINUE_STR); #endif @@ -259,7 +255,7 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l unscaled_e_move(purge_length, ADVANCED_PAUSE_PURGE_FEEDRATE); } - TERN_(HOST_PROMPT_SUPPORT, filament_load_host_prompt()); // Initiate another host prompt. (NOTE: host_response_handler may also do this!) + TERN_(HOST_PROMPT_SUPPORT, filament_load_host_prompt()); // Initiate another host prompt. #if HAS_LCD_MENU if (show_lcd) { @@ -460,7 +456,7 @@ void show_continue_prompt(const bool is_reload) { ui.pause_show_message(is_reload ? PAUSE_MESSAGE_INSERT : PAUSE_MESSAGE_WAITING); SERIAL_ECHO_START(); - serialprintPGM(is_reload ? PSTR(_PMSG(STR_FILAMENT_CHANGE_INSERT) "\n") : PSTR(_PMSG(STR_FILAMENT_CHANGE_WAIT) "\n")); + SERIAL_ECHOPGM_P(is_reload ? PSTR(_PMSG(STR_FILAMENT_CHANGE_INSERT) "\n") : PSTR(_PMSG(STR_FILAMENT_CHANGE_WAIT) "\n")); } void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep_count/*=0*/ DXC_ARGS) { diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index 46b94dbc1103..1bb3a7e91531 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -384,18 +384,25 @@ void PrintJobRecovery::resume() { // Home safely with no Z raise gcode.process_subcommands_now_P(PSTR( "G28R0" // No raise during G28 - #if IS_CARTESIAN && DISABLED(POWER_LOSS_RECOVER_ZHOME) + #if IS_CARTESIAN && (DISABLED(POWER_LOSS_RECOVER_ZHOME) || defined(POWER_LOSS_ZHOME_POS)) "XY" // Don't home Z on Cartesian unless overridden #endif )); #endif - // Pretend that all axes are homed + #ifdef POWER_LOSS_ZHOME_POS + // If defined move to a safe Z homing position that avoids the print + constexpr xy_pos_t p = POWER_LOSS_ZHOME_POS; + sprintf_P(cmd, PSTR("G1 X%s Y%s F1000\nG28Z"), dtostrf(p.x, 1, 3, str_1), dtostrf(p.y, 1, 3, str_2)); + gcode.process_subcommands_now(cmd); + #endif + + // Ensure that all axes are marked as homed set_all_homed(); #if ENABLED(POWER_LOSS_RECOVER_ZHOME) - // Z has been homed so restore Z to ZsavedPos + POWER_LOSS_ZRAISE + // Now move to ZsavedPos + POWER_LOSS_ZRAISE sprintf_P(cmd, PSTR("G1 F500 Z%s"), dtostrf(info.current_position.z + POWER_LOSS_ZRAISE, 1, 3, str_1)); gcode.process_subcommands_now(cmd); #endif @@ -467,7 +474,7 @@ void PrintJobRecovery::resume() { // Additional purge if configured #if POWER_LOSS_PURGE_LEN - sprintf_P(cmd, PSTR("G1 E%d F200"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN)); + sprintf_P(cmd, PSTR("G1 E%d F3000"), (POWER_LOSS_PURGE_LEN) + (POWER_LOSS_RETRACT_LEN)); gcode.process_subcommands_now(cmd); #endif @@ -485,7 +492,7 @@ void PrintJobRecovery::resume() { // Move back to the saved Z dtostrf(info.current_position.z, 1, 3, str_1); #if Z_HOME_DIR > 0 || ENABLED(POWER_LOSS_RECOVER_ZHOME) - sprintf_P(cmd, PSTR("G1 Z%s F200"), str_1); + sprintf_P(cmd, PSTR("G1 Z%s F500"), str_1); #else gcode.process_subcommands_now_P(PSTR("G1 Z0 F200")); sprintf_P(cmd, PSTR("G92.9 Z%s"), str_1); @@ -531,7 +538,7 @@ void PrintJobRecovery::resume() { #if ENABLED(DEBUG_POWER_LOSS_RECOVERY) void PrintJobRecovery::debug(PGM_P const prefix) { - DEBUG_PRINT_P(prefix); + DEBUG_ECHOPGM_P(prefix); DEBUG_ECHOLNPAIR(" Job Recovery Info...\nvalid_head:", info.valid_head, " valid_foot:", info.valid_foot); if (info.valid_head) { if (info.valid_head == info.valid_foot) { diff --git a/Marlin/src/feature/probe_temp_comp.cpp b/Marlin/src/feature/probe_temp_comp.cpp index af8039d8b110..8fdf160d0fef 100644 --- a/Marlin/src/feature/probe_temp_comp.cpp +++ b/Marlin/src/feature/probe_temp_comp.cpp @@ -73,7 +73,7 @@ void ProbeTempComp::print_offsets() { LOOP_L_N(s, TSI_COUNT) { float temp = cali_info[s].start_temp; for (int16_t i = -1; i < cali_info[s].measurements; ++i) { - serialprintPGM(s == TSI_BED ? PSTR("Bed") : + SERIAL_ECHOPGM_P(s == TSI_BED ? PSTR("Bed") : #if ENABLED(USE_TEMP_EXT_COMPENSATION) s == TSI_EXT ? PSTR("Extruder") : #endif diff --git a/Marlin/src/feature/runout.cpp b/Marlin/src/feature/runout.cpp index be769d2dc82f..531ca1081f0b 100644 --- a/Marlin/src/feature/runout.cpp +++ b/Marlin/src/feature/runout.cpp @@ -47,12 +47,12 @@ bool FilamentMonitorBase::enabled = true, #if HAS_FILAMENT_RUNOUT_DISTANCE float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM; - volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS]; + volatile float RunoutResponseDelayed::runout_mm_countdown[NUM_RUNOUT_SENSORS]; #if ENABLED(FILAMENT_MOTION_SENSOR) uint8_t FilamentSensorEncoder::motion_detected; #endif #else - int8_t RunoutResponseDebounced::runout_count; // = 0 + int8_t RunoutResponseDebounced::runout_count[NUM_RUNOUT_SENSORS]; // = 0 #endif // @@ -70,7 +70,7 @@ bool FilamentMonitorBase::enabled = true, #include "../lcd/extui/ui_api.h" #endif -void event_filament_runout() { +void event_filament_runout(const uint8_t extruder) { if (did_pause_print) return; // Action already in progress. Purge triggered repeated runout. @@ -85,14 +85,10 @@ void event_filament_runout() { } #endif - TERN_(EXTENSIBLE_UI, ExtUI::onFilamentRunout(ExtUI::getActiveTool())); + TERN_(EXTENSIBLE_UI, ExtUI::onFilamentRunout(ExtUI::getTool(extruder))); - #if EITHER(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS) - const char tool = '0' - #if NUM_RUNOUT_SENSORS > 1 - + active_extruder - #endif - ; + #if ANY(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS, MULTI_FILAMENT_SENSOR) + const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, extruder); #endif //action:out_of_filament @@ -128,8 +124,22 @@ void event_filament_runout() { SERIAL_EOL(); #endif // HOST_ACTION_COMMANDS - if (run_runout_script) - queue.inject_P(PSTR(FILAMENT_RUNOUT_SCRIPT)); + if (run_runout_script) { + #if MULTI_FILAMENT_SENSOR + char script[strlen(FILAMENT_RUNOUT_SCRIPT) + 1]; + sprintf_P(script, PSTR(FILAMENT_RUNOUT_SCRIPT), tool); + #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG) + SERIAL_ECHOLNPAIR("Runout Command: ", script); + #endif + queue.inject(script); + #else + #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG) + SERIAL_ECHOPGM("Runout Command: "); + SERIAL_ECHOLNPGM(FILAMENT_RUNOUT_SCRIPT); + #endif + queue.inject_P(PSTR(FILAMENT_RUNOUT_SCRIPT)); + #endif + } } #endif // HAS_FILAMENT_SENSOR diff --git a/Marlin/src/feature/runout.h b/Marlin/src/feature/runout.h index 60154c5e43ef..34ae67899bc6 100644 --- a/Marlin/src/feature/runout.h +++ b/Marlin/src/feature/runout.h @@ -43,7 +43,7 @@ #define FILAMENT_RUNOUT_THRESHOLD 5 #endif -void event_filament_runout(); +void event_filament_runout(const uint8_t extruder); template class TFilamentMonitor; @@ -119,11 +119,41 @@ class TFilamentMonitor : public FilamentMonitorBase { TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, cli()); // Prevent RunoutResponseDelayed::block_completed from accumulating here response.run(); sensor.run(); - const bool ran_out = response.has_run_out(); + const uint8_t runout_flags = response.has_run_out(); TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, sei()); + #if MULTI_FILAMENT_SENSOR + #if ENABLED(WATCH_ALL_RUNOUT_SENSORS) + const bool ran_out = !!runout_flags; // any sensor triggers + uint8_t extruder = 0; + if (ran_out) { + uint8_t bitmask = runout_flags; + while (!(bitmask & 1)) { + bitmask >>= 1; + extruder++; + } + } + #else + const bool ran_out = TEST(runout_flags, active_extruder); // suppress non active extruders + uint8_t extruder = active_extruder; + #endif + #else + const bool ran_out = !!runout_flags; + uint8_t extruder = active_extruder; + #endif + + #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG) + if (runout_flags) { + SERIAL_ECHOPGM("Runout Sensors: "); + LOOP_L_N(i, 8) SERIAL_ECHO('0' + TEST(runout_flags, i)); + SERIAL_ECHOPAIR(" -> ", extruder); + if (ran_out) SERIAL_ECHOPGM(" RUN OUT"); + SERIAL_EOL(); + } + #endif + if (ran_out) { filament_ran_out = true; - event_filament_runout(); + event_filament_runout(extruder); planner.synchronize(); } } @@ -230,7 +260,7 @@ class FilamentSensorBase { change = old_state ^ new_state; old_state = new_state; - #ifdef FILAMENT_RUNOUT_SENSOR_DEBUG + #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG) if (change) { SERIAL_ECHOPGM("Motion detected:"); LOOP_L_N(e, NUM_RUNOUT_SENSORS) @@ -266,12 +296,12 @@ class FilamentSensorBase { private: static inline bool poll_runout_state(const uint8_t extruder) { const uint8_t runout_states = poll_runout_states(); - #if NUM_RUNOUT_SENSORS == 1 - UNUSED(extruder); - #else + #if MULTI_FILAMENT_SENSOR if ( !TERN0(DUAL_X_CARRIAGE, idex_is_duplicating()) && !TERN0(MULTI_NOZZLE_DUPLICATION, extruder_duplication_enabled) ) return TEST(runout_states, extruder); // A specific extruder ran out + #else + UNUSED(extruder); #endif return !!runout_states; // Any extruder ran out } @@ -280,16 +310,17 @@ class FilamentSensorBase { static inline void block_completed(const block_t* const) {} static inline void run() { - const bool out = poll_runout_state(active_extruder); - if (!out) filament_present(active_extruder); - #ifdef FILAMENT_RUNOUT_SENSOR_DEBUG - static bool was_out = false; - if (out != was_out) { - was_out = out; - SERIAL_ECHOPGM("Filament "); - serialprintPGM(out ? PSTR("OUT\n") : PSTR("IN\n")); - } - #endif + LOOP_L_N(s, NUM_RUNOUT_SENSORS) { + const bool out = poll_runout_state(s); + if (!out) filament_present(s); + #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG) + static uint8_t was_out; // = 0 + if (out != TEST(was_out, s)) { + TBI(was_out, s); + SERIAL_ECHOLNPAIR_P(PSTR("Filament Sensor "), '0' + s, out ? PSTR(" OUT") : PSTR(" IN")); + } + #endif + } } }; @@ -305,32 +336,32 @@ class FilamentSensorBase { // during a runout condition. class RunoutResponseDelayed { private: - static volatile float runout_mm_countdown[EXTRUDERS]; + static volatile float runout_mm_countdown[NUM_RUNOUT_SENSORS]; public: static float runout_distance_mm; static inline void reset() { - LOOP_L_N(i, EXTRUDERS) filament_present(i); + LOOP_L_N(i, NUM_RUNOUT_SENSORS) filament_present(i); } static inline void run() { - #ifdef FILAMENT_RUNOUT_SENSOR_DEBUG + #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG) static millis_t t = 0; const millis_t ms = millis(); if (ELAPSED(ms, t)) { t = millis() + 1000UL; - LOOP_L_N(i, EXTRUDERS) { - serialprintPGM(i ? PSTR(", ") : PSTR("Remaining mm: ")); - SERIAL_ECHO(runout_mm_countdown[i]); - } + LOOP_L_N(i, NUM_RUNOUT_SENSORS) + SERIAL_ECHOPAIR_P(i ? PSTR(", ") : PSTR("Remaining mm: "), runout_mm_countdown[i]); SERIAL_EOL(); } #endif } - static inline bool has_run_out() { - return runout_mm_countdown[active_extruder] < 0; + static inline uint8_t has_run_out() { + uint8_t runout_flags = 0; + LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_mm_countdown[i] < 0) SBI(runout_flags, i); + return runout_flags; } static inline void filament_present(const uint8_t extruder) { @@ -355,13 +386,28 @@ class FilamentSensorBase { class RunoutResponseDebounced { private: static constexpr int8_t runout_threshold = FILAMENT_RUNOUT_THRESHOLD; - static int8_t runout_count; + static int8_t runout_count[NUM_RUNOUT_SENSORS]; + public: - static inline void reset() { runout_count = runout_threshold; } - static inline void run() { if (runout_count >= 0) runout_count--; } - static inline bool has_run_out() { return runout_count < 0; } - static inline void block_completed(const block_t* const) { } - static inline void filament_present(const uint8_t) { runout_count = runout_threshold; } + static inline void reset() { + LOOP_L_N(i, NUM_RUNOUT_SENSORS) filament_present(i); + } + + static inline void run() { + LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_count[i] >= 0) runout_count[i]--; + } + + static inline uint8_t has_run_out() { + uint8_t runout_flags = 0; + LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_count[i] < 0) SBI(runout_flags, i); + return runout_flags; + } + + static inline void block_completed(const block_t* const) { } + + static inline void filament_present(const uint8_t extruder) { + runout_count[extruder] = runout_threshold; + } }; #endif // !HAS_FILAMENT_RUNOUT_DISTANCE diff --git a/Marlin/src/feature/tmc_util.cpp b/Marlin/src/feature/tmc_util.cpp index a16af31e5570..a4f71414a6b6 100644 --- a/Marlin/src/feature/tmc_util.cpp +++ b/Marlin/src/feature/tmc_util.cpp @@ -546,7 +546,7 @@ }; template - static void print_vsense(TMC &st) { serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); } + static void print_vsense(TMC &st) { SERIAL_ECHOPGM_P(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); } #if HAS_DRIVER(TMC2130) || HAS_DRIVER(TMC5130) static void _tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) { @@ -717,7 +717,7 @@ SERIAL_ECHO(st.cs()); SERIAL_ECHOPGM("/31"); break; - case TMC_VSENSE: serialprintPGM(st.vsense() ? PSTR("1=.165") : PSTR("0=.310")); break; + case TMC_VSENSE: SERIAL_ECHOPGM_P(st.vsense() ? PSTR("1=.165") : PSTR("0=.310")); break; case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break; //case TMC_OTPW: serialprint_truefalse(st.otpw()); break; //case TMC_OTPW_TRIGGERED: serialprint_truefalse(st.getOTPW()); break; @@ -1208,7 +1208,7 @@ static bool test_connection(TMC &st) { case 1: stat = PSTR("HIGH"); break; case 2: stat = PSTR("LOW"); break; } - serialprintPGM(stat); + SERIAL_ECHOPGM_P(stat); SERIAL_EOL(); return test_result; diff --git a/Marlin/src/feature/twibus.cpp b/Marlin/src/feature/twibus.cpp index 855a3188d10c..755224544c6e 100644 --- a/Marlin/src/feature/twibus.cpp +++ b/Marlin/src/feature/twibus.cpp @@ -83,7 +83,7 @@ void TWIBus::send() { // static void TWIBus::echoprefix(uint8_t bytes, const char pref[], uint8_t adr) { SERIAL_ECHO_START(); - serialprintPGM(pref); + SERIAL_ECHOPGM_P(pref); SERIAL_ECHOPAIR(": from:", adr, " bytes:", bytes, " data:"); } @@ -172,7 +172,7 @@ void TWIBus::flush() { // static void TWIBus::prefix(const char func[]) { SERIAL_ECHOPGM("TWIBus::"); - serialprintPGM(func); + SERIAL_ECHOPGM_P(func); SERIAL_ECHOPGM(": "); } void TWIBus::debug(const char func[], uint32_t adr) { diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index 9e3cad34f298..ed2995905589 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -319,9 +319,13 @@ inline bool look_for_lines_to_connect() { s.x = _GET_MESH_X( i ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge e.x = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge - LIMIT(s.x, X_MIN_POS + 1, X_MAX_POS - 1); - s.y = e.y = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1); - LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1); + #if HAS_ENDSTOPS + LIMIT(s.x, X_MIN_POS + 1, X_MAX_POS - 1); + s.y = e.y = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1); + LIMIT(e.x, X_MIN_POS + 1, X_MAX_POS - 1); + #else + s.y = e.y = _GET_MESH_Y(j); + #endif if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y)) print_line_from_here_to_there(s, e); @@ -339,9 +343,13 @@ inline bool look_for_lines_to_connect() { s.y = _GET_MESH_Y( j ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // top edge e.y = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge - s.x = e.x = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1); - LIMIT(s.y, Y_MIN_POS + 1, Y_MAX_POS - 1); - LIMIT(e.y, Y_MIN_POS + 1, Y_MAX_POS - 1); + #if HAS_ENDSTOPS + s.x = e.x = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1); + LIMIT(s.y, Y_MIN_POS + 1, Y_MAX_POS - 1); + LIMIT(e.y, Y_MIN_POS + 1, Y_MAX_POS - 1); + #else + s.x = e.x = _GET_MESH_X(i); + #endif if (position_is_reachable(s.x, s.y) && position_is_reachable(e.x, e.y)) print_line_from_here_to_there(s, e); @@ -826,7 +834,7 @@ void GcodeSuite::G26() { #if IS_KINEMATIC // Check to make sure this segment is entirely on the bed, skip if not. if (!position_is_reachable(p) || !position_is_reachable(q)) continue; - #else + #elif HAS_ENDSTOPS LIMIT(p.x, X_MIN_POS + 1, X_MAX_POS - 1); // Prevent hitting the endstops LIMIT(p.y, Y_MIN_POS + 1, Y_MAX_POS - 1); LIMIT(q.x, X_MIN_POS + 1, X_MAX_POS - 1); diff --git a/Marlin/src/gcode/bedlevel/G35.cpp b/Marlin/src/gcode/bedlevel/G35.cpp index 5195ff87c05b..88f02e6de2f9 100644 --- a/Marlin/src/gcode/bedlevel/G35.cpp +++ b/Marlin/src/gcode/bedlevel/G35.cpp @@ -114,7 +114,7 @@ void GcodeSuite::G35() { if (DEBUGGING(LEVELING)) { DEBUG_ECHOPAIR("Probing point ", i, " ("); - DEBUG_PRINT_P((char *)pgm_read_ptr(&tramming_point_name[i])); + DEBUG_ECHOPGM_P((char *)pgm_read_ptr(&tramming_point_name[i])); DEBUG_CHAR(')'); DEBUG_ECHOLNPAIR_P(SP_X_STR, screws_tilt_adjust_pos[i].x, SP_Y_STR, screws_tilt_adjust_pos[i].y, SP_Z_STR, z_probed_height); } diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index b1e9fcedaa4f..e642c1ccf256 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -359,7 +359,7 @@ G29_TYPE GcodeSuite::G29() { #if ABL_GRID - xy_probe_feedrate_mm_s = MMM_TO_MMS(parser.linearval('S', XY_PROBE_SPEED)); + xy_probe_feedrate_mm_s = MMM_TO_MMS(parser.linearval('S', XY_PROBE_FEEDRATE)); const float x_min = probe.min_x(), x_max = probe.max_x(), y_min = probe.min_y(), y_max = probe.max_y(); @@ -786,7 +786,7 @@ G29_TYPE GcodeSuite::G29() { float min_diff = 999; auto print_topo_map = [&](PGM_P const title, const bool get_min) { - serialprintPGM(title); + SERIAL_ECHOPGM_P(title); for (int8_t yy = abl_grid_points.y - 1; yy >= 0; yy--) { LOOP_L_N(xx, abl_grid_points.x) { const int ind = indexIntoAB[xx][yy]; diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp index 2de029a08b0f..947067887237 100644 --- a/Marlin/src/gcode/calibrate/G28.cpp +++ b/Marlin/src/gcode/calibrate/G28.cpp @@ -96,7 +96,7 @@ }; #endif - do_blocking_move_to_xy(1.5 * mlx * x_axis_home_dir, 1.5 * mly * home_dir(Y_AXIS), fr_mm_s); + do_blocking_move_to_xy(1.5 * mlx * x_axis_home_dir, 1.5 * mly * Y_HOME_DIR, fr_mm_s); endstops.validate_homing_move(); @@ -259,7 +259,7 @@ void GcodeSuite::G28() { #if HAS_HOMING_CURRENT auto debug_current = [](PGM_P const s, const int16_t a, const int16_t b){ - serialprintPGM(s); DEBUG_ECHOLNPAIR(" current: ", a, " -> ", b); + DEBUG_ECHOPGM_P(s); DEBUG_ECHOLNPAIR(" current: ", a, " -> ", b); }; #if HAS_CURRENT_HOME(X) const int16_t tmc_save_current_X = stepperX.getMilliamps(); @@ -311,7 +311,13 @@ void GcodeSuite::G28() { TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(slow_homing)); - #else // NOT DELTA + #elif ENABLED(AXEL_TPARA) + + constexpr bool doZ = true; // for NANODLP_Z_SYNC if your DLP is on a TPARA + + home_TPARA(); + + #else const bool homeZ = parser.seen('Z'), needX = homeZ && TERN0(Z_SAFE_HOMING, axes_should_home(_BV(X_AXIS))), @@ -326,14 +332,13 @@ void GcodeSuite::G28() { #endif - const float z_homing_height = TERN1(UNKNOWN_Z_NO_RAISE, axis_is_trusted(Z_AXIS)) - ? (parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT) - : 0; + const float z_homing_height = parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT; if (z_homing_height && (doX || doY || TERN0(Z_SAFE_HOMING, doZ))) { // Raise Z before homing any other axes and z is not already high enough (never lower z) if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Raise Z (before homing) by ", z_homing_height); - do_z_clearance(z_homing_height, axis_is_trusted(Z_AXIS), DISABLED(UNKNOWN_Z_NO_RAISE)); + do_z_clearance(z_homing_height); + TERN_(BLTOUCH, bltouch.init()); } #if ENABLED(QUICK_HOME) @@ -386,7 +391,6 @@ void GcodeSuite::G28() { stepper.set_separate_multi_axis(false); #endif - TERN_(BLTOUCH, bltouch.init()); TERN(Z_SAFE_HOMING, home_z_safely(), homeaxis(Z_AXIS)); probe.move_z_after_homing(); } @@ -394,7 +398,7 @@ void GcodeSuite::G28() { sync_plan_position(); - #endif // !DELTA (G28) + #endif /** * Preserve DXC mode across a G28 for IDEX printers in DXC_DUPLICATION_MODE. diff --git a/Marlin/src/gcode/calibrate/G33.cpp b/Marlin/src/gcode/calibrate/G33.cpp index 77cc45771cc8..5530bc708971 100644 --- a/Marlin/src/gcode/calibrate/G33.cpp +++ b/Marlin/src/gcode/calibrate/G33.cpp @@ -93,7 +93,7 @@ void ac_cleanup(TERN_(HAS_MULTI_HOTEND, const uint8_t old_tool_index)) { void print_signed_float(PGM_P const prefix, const float &f) { SERIAL_ECHOPGM(" "); - serialprintPGM(prefix); + SERIAL_ECHOPGM_P(prefix); SERIAL_CHAR(':'); if (f >= 0) SERIAL_CHAR('+'); SERIAL_ECHO_F(f, 2); @@ -449,7 +449,7 @@ void GcodeSuite::G33() { // Report settings PGM_P const checkingac = PSTR("Checking... AC"); - serialprintPGM(checkingac); + SERIAL_ECHOPGM_P(checkingac); if (verbose_level == 0) SERIAL_ECHOPGM(" (DRY-RUN)"); SERIAL_EOL(); ui.set_status_P(checkingac); @@ -625,7 +625,7 @@ void GcodeSuite::G33() { } else { // dry run PGM_P const enddryrun = PSTR("End DRY-RUN"); - serialprintPGM(enddryrun); + SERIAL_ECHOPGM_P(enddryrun); SERIAL_ECHO_SP(35); SERIAL_ECHOLNPAIR_F("std dev:", zero_std_dev, 3); diff --git a/Marlin/src/gcode/calibrate/M100.cpp b/Marlin/src/gcode/calibrate/M100.cpp index 9ac2380e7964..ee572e033d75 100644 --- a/Marlin/src/gcode/calibrate/M100.cpp +++ b/Marlin/src/gcode/calibrate/M100.cpp @@ -51,7 +51,7 @@ * Also, there are two support functions that can be called from a developer's C code. * * uint16_t check_for_free_memory_corruption(PGM_P const free_memory_start); - * void M100_dump_routine(PGM_P const title, const char * const start, const char * const end); + * void M100_dump_routine(PGM_P const title, const char * const start, const uintptr_t size); * * Initial version by Roxy-3D */ @@ -151,7 +151,7 @@ inline int32_t count_test_bytes(const char * const start_free_memory) { * the block. If so, it may indicate memory corruption due to a bad pointer. * Unexpected bytes are flagged in the right column. */ - inline void dump_free_memory(char *start_free_memory, char *end_free_memory) { + void dump_free_memory(char *start_free_memory, char *end_free_memory) { // // Start and end the dump on a nice 16 byte boundary // (even though the values are not 16-byte aligned). @@ -182,12 +182,12 @@ inline int32_t count_test_bytes(const char * const start_free_memory) { } } - void M100_dump_routine(PGM_P const title, const char * const start, const char * const end) { - serialprintPGM(title); - SERIAL_EOL(); + void M100_dump_routine(PGM_P const title, const char * const start, const uintptr_t size) { + SERIAL_ECHOLNPGM_P(title); // // Round the start and end locations to produce full lines of output // + const char * const end = start + size - 1; dump_free_memory( (char*)(uintptr_t(uint32_t(start) & ~0xFUL)), // Align to 16-byte boundary (char*)(uintptr_t(uint32_t(end) | 0xFUL)) // Align end_free_memory to the 15th byte (at or above end_free_memory) @@ -197,27 +197,27 @@ inline int32_t count_test_bytes(const char * const start_free_memory) { #endif // M100_FREE_MEMORY_DUMPER inline int check_for_free_memory_corruption(PGM_P const title) { - serialprintPGM(title); + SERIAL_ECHOPGM_P(title); char *start_free_memory = free_memory_start, *end_free_memory = free_memory_end; int n = end_free_memory - start_free_memory; - SERIAL_ECHOPAIR("\nfmc() n=", n); - SERIAL_ECHOPAIR("\nfree_memory_start=", hex_address(free_memory_start)); - SERIAL_ECHOLNPAIR(" end_free_memory=", hex_address(end_free_memory)); + SERIAL_ECHOLNPAIR("\nfmc() n=", n, + "\nfree_memory_start=", hex_address(free_memory_start), + " end=", hex_address(end_free_memory)); if (end_free_memory < start_free_memory) { SERIAL_ECHOPGM(" end_free_memory < Heap "); - // SET_INPUT_PULLUP(63); // if the developer has a switch wired up to their controller board - // safe_delay(5); // this code can be enabled to pause the display as soon as the - // while ( READ(63)) // malfunction is detected. It is currently defaulting to a switch - // idle(); // being on pin-63 which is unassigend and available on most controller - // safe_delay(20); // boards. - // while ( !READ(63)) - // idle(); + //SET_INPUT_PULLUP(63); // if the developer has a switch wired up to their controller board + //safe_delay(5); // this code can be enabled to pause the display as soon as the + //while ( READ(63)) // malfunction is detected. It is currently defaulting to a switch + // idle(); // being on pin-63 which is unassigend and available on most controller + //safe_delay(20); // boards. + //while ( !READ(63)) + // idle(); serial_delay(20); #if ENABLED(M100_FREE_MEMORY_DUMPER) - M100_dump_routine(PSTR(" Memory corruption detected with end_free_memory 8) { - // SERIAL_ECHOPAIR("Found ", j); - // SERIAL_ECHOLNPAIR(" bytes free at ", hex_address(start_free_memory + i)); + //SERIAL_ECHOPAIR("Found ", j); + //SERIAL_ECHOLNPAIR(" bytes free at ", hex_address(start_free_memory + i)); i += j; block_cnt++; - SERIAL_ECHOPAIR(" (", block_cnt); - SERIAL_ECHOPAIR(") found=", j); - SERIAL_ECHOLNPGM(" "); + SERIAL_ECHOLNPAIR(" (", block_cnt, ") found=", j); } } } @@ -269,8 +267,7 @@ inline void free_memory_pool_report(char * const start_free_memory, const int32_ if (*addr == TEST_BYTE) { const int32_t j = count_test_bytes(addr); if (j > 8) { - SERIAL_ECHOPAIR("Found ", j); - SERIAL_ECHOLNPAIR(" bytes free at ", hex_address(addr)); + SERIAL_ECHOLNPAIR("Found ", j, " bytes free at ", hex_address(addr)); if (j > max_cnt) { max_cnt = j; max_addr = addr; @@ -280,11 +277,10 @@ inline void free_memory_pool_report(char * const start_free_memory, const int32_ } } } - if (block_cnt > 1) { - SERIAL_ECHOLNPGM("\nMemory Corruption detected in free memory area."); - SERIAL_ECHOPAIR("\nLargest free block is ", max_cnt); - SERIAL_ECHOLNPAIR(" bytes at ", hex_address(max_addr)); - } + if (block_cnt > 1) SERIAL_ECHOLNPAIR( + "\nMemory Corruption detected in free memory area." + "\nLargest free block is ", max_cnt, " bytes at ", hex_address(max_addr) + ); SERIAL_ECHOLNPAIR("check_for_free_memory_corruption() = ", check_for_free_memory_corruption(PSTR("M100 F "))); } @@ -294,12 +290,12 @@ inline void free_memory_pool_report(char * const start_free_memory, const int32_ * Corrupt locations in the free memory pool and report the corrupt addresses. * This is useful to check the correctness of the M100 D and the M100 F commands. */ - inline void corrupt_free_memory(char *start_free_memory, const uint32_t size) { + inline void corrupt_free_memory(char *start_free_memory, const uintptr_t size) { start_free_memory += 8; const uint32_t near_top = top_of_stack() - start_free_memory - 250, // -250 to avoid interrupt activity that's altered the stack. j = near_top / (size + 1); - SERIAL_ECHOLNPGM("Corrupting free memory block.\n"); + SERIAL_ECHOLNPGM("Corrupting free memory block."); for (uint32_t i = 1; i <= size; i++) { char * const addr = start_free_memory + i * j; *addr = i; @@ -322,8 +318,8 @@ inline void init_free_memory(char *start_free_memory, int32_t size) { return; } - start_free_memory += 8; // move a few bytes away from the heap just because we don't want - // to be altering memory that close to it. + start_free_memory += 8; // move a few bytes away from the heap just because we + // don't want to be altering memory that close to it. memset(start_free_memory, TEST_BYTE, size); SERIAL_ECHO(size); @@ -342,16 +338,16 @@ inline void init_free_memory(char *start_free_memory, int32_t size) { * M100: Free Memory Check */ void GcodeSuite::M100() { - char *sp = top_of_stack(); if (!free_memory_end) free_memory_end = sp - MEMORY_END_CORRECTION; - SERIAL_ECHOPAIR("\nbss_end : ", hex_address(end_bss)); - if (heaplimit) SERIAL_ECHOPAIR("\n__heaplimit : ", hex_address(heaplimit)); - SERIAL_ECHOPAIR("\nfree_memory_start : ", hex_address(free_memory_start)); + SERIAL_ECHOPAIR("\nbss_end : ", hex_address(end_bss)); + if (heaplimit) SERIAL_ECHOPAIR("\n__heaplimit : ", hex_address(heaplimit)); + SERIAL_ECHOPAIR("\nfree_memory_start : ", hex_address(free_memory_start)); if (stacklimit) SERIAL_ECHOPAIR("\n__stacklimit : ", hex_address(stacklimit)); - SERIAL_ECHOPAIR("\nfree_memory_end : ", hex_address(free_memory_end)); - if (MEMORY_END_CORRECTION) SERIAL_ECHOPAIR("\nMEMORY_END_CORRECTION: ", MEMORY_END_CORRECTION); - SERIAL_ECHOLNPAIR("\nStack Pointer : ", hex_address(sp)); + SERIAL_ECHOPAIR("\nfree_memory_end : ", hex_address(free_memory_end)); + if (MEMORY_END_CORRECTION) + SERIAL_ECHOPAIR("\nMEMORY_END_CORRECTION : ", MEMORY_END_CORRECTION); + SERIAL_ECHOLNPAIR("\nStack Pointer : ", hex_address(sp)); // Always init on the first invocation of M100 static bool m100_not_initialized = true; @@ -369,10 +365,8 @@ void GcodeSuite::M100() { return free_memory_pool_report(free_memory_start, free_memory_end - free_memory_start); #if ENABLED(M100_FREE_MEMORY_CORRUPTOR) - if (parser.seen('C')) return corrupt_free_memory(free_memory_start, parser.value_int()); - #endif } diff --git a/Marlin/src/gcode/calibrate/M48.cpp b/Marlin/src/gcode/calibrate/M48.cpp index 63d23706974c..0c6176173c3e 100644 --- a/Marlin/src/gcode/calibrate/M48.cpp +++ b/Marlin/src/gcode/calibrate/M48.cpp @@ -202,7 +202,7 @@ void GcodeSuite::M48() { if (verbose_level > 3) SERIAL_ECHOLNPAIR_P(PSTR("Moving inward: X"), next_pos.x, SP_Y_STR, next_pos.y); } - #else + #elif HAS_ENDSTOPS // For a rectangular bed just keep the probe in bounds LIMIT(next_pos.x, X_MIN_POS, X_MAX_POS); LIMIT(next_pos.y, Y_MIN_POS, Y_MAX_POS); diff --git a/Marlin/src/gcode/calibrate/M665.cpp b/Marlin/src/gcode/calibrate/M665.cpp index 557204cc1102..0d0c4146d931 100644 --- a/Marlin/src/gcode/calibrate/M665.cpp +++ b/Marlin/src/gcode/calibrate/M665.cpp @@ -40,21 +40,21 @@ * X = Alpha (Tower 1) angle trim * Y = Beta (Tower 2) angle trim * Z = Gamma (Tower 3) angle trim - * A = Alpha (Tower 1) digonal rod trim - * B = Beta (Tower 2) digonal rod trim - * C = Gamma (Tower 3) digonal rod trim + * A = Alpha (Tower 1) diagonal rod trim + * B = Beta (Tower 2) diagonal rod trim + * C = Gamma (Tower 3) diagonal rod trim */ void GcodeSuite::M665() { - if (parser.seen('H')) delta_height = parser.value_linear_units(); - if (parser.seen('L')) delta_diagonal_rod = parser.value_linear_units(); - if (parser.seen('R')) delta_radius = parser.value_linear_units(); - if (parser.seen('S')) delta_segments_per_second = parser.value_float(); - if (parser.seen('X')) delta_tower_angle_trim.a = parser.value_float(); - if (parser.seen('Y')) delta_tower_angle_trim.b = parser.value_float(); - if (parser.seen('Z')) delta_tower_angle_trim.c = parser.value_float(); - if (parser.seen('A')) delta_diagonal_rod_trim.a = parser.value_float(); - if (parser.seen('B')) delta_diagonal_rod_trim.b = parser.value_float(); - if (parser.seen('C')) delta_diagonal_rod_trim.c = parser.value_float(); + if (parser.seenval('H')) delta_height = parser.value_linear_units(); + if (parser.seenval('L')) delta_diagonal_rod = parser.value_linear_units(); + if (parser.seenval('R')) delta_radius = parser.value_linear_units(); + if (parser.seenval('S')) segments_per_second = parser.value_float(); + if (parser.seenval('X')) delta_tower_angle_trim.a = parser.value_float(); + if (parser.seenval('Y')) delta_tower_angle_trim.b = parser.value_float(); + if (parser.seenval('Z')) delta_tower_angle_trim.c = parser.value_float(); + if (parser.seenval('A')) delta_diagonal_rod_trim.a = parser.value_float(); + if (parser.seenval('B')) delta_diagonal_rod_trim.b = parser.value_float(); + if (parser.seenval('C')) delta_diagonal_rod_trim.c = parser.value_float(); recalc_delta_settings(); } @@ -76,7 +76,7 @@ * B, T, and Y are all aliases for the elbow angle */ void GcodeSuite::M665() { - if (parser.seenval('S')) delta_segments_per_second = parser.value_float(); + if (parser.seenval('S')) segments_per_second = parser.value_float(); #if HAS_SCARA_OFFSET diff --git a/Marlin/src/gcode/calibrate/M852.cpp b/Marlin/src/gcode/calibrate/M852.cpp index b60f41748fec..e52f03b86c4e 100644 --- a/Marlin/src/gcode/calibrate/M852.cpp +++ b/Marlin/src/gcode/calibrate/M852.cpp @@ -93,7 +93,7 @@ void GcodeSuite::M852() { if (!ijk) { SERIAL_ECHO_START(); - serialprintPGM(GET_TEXT(MSG_SKEW_FACTOR)); + SERIAL_ECHOPGM_P(GET_TEXT(MSG_SKEW_FACTOR)); SERIAL_ECHOPAIR_F(" XY: ", planner.skew_factor.xy, 6); #if ENABLED(SKEW_CORRECTION_FOR_Z) SERIAL_ECHOPAIR_F(" XZ: ", planner.skew_factor.xz, 6); diff --git a/Marlin/src/gcode/config/M217.cpp b/Marlin/src/gcode/config/M217.cpp index ebe1dbc03c60..2035ae55abeb 100644 --- a/Marlin/src/gcode/config/M217.cpp +++ b/Marlin/src/gcode/config/M217.cpp @@ -36,7 +36,7 @@ void M217_report(const bool eeprom=false) { #if ENABLED(TOOLCHANGE_FILAMENT_SWAP) - serialprintPGM(eeprom ? PSTR(" M217") : PSTR("Toolchange:")); + SERIAL_ECHOPGM_P(eeprom ? PSTR(" M217") : PSTR("Toolchange:")); SERIAL_ECHOPAIR(" S", LINEAR_UNIT(toolchange_settings.swap_length)); SERIAL_ECHOPAIR_P(SP_B_STR, LINEAR_UNIT(toolchange_settings.extra_resume), SP_E_STR, LINEAR_UNIT(toolchange_settings.extra_prime), diff --git a/Marlin/src/gcode/config/M302.cpp b/Marlin/src/gcode/config/M302.cpp index afdc6c9e8506..e3ce5a10ef0e 100644 --- a/Marlin/src/gcode/config/M302.cpp +++ b/Marlin/src/gcode/config/M302.cpp @@ -55,7 +55,7 @@ void GcodeSuite::M302() { // Report current state SERIAL_ECHO_START(); SERIAL_ECHOPGM("Cold extrudes are "); - serialprintPGM(thermalManager.allow_cold_extrude ? PSTR("en") : PSTR("dis")); + SERIAL_ECHOPGM_P(thermalManager.allow_cold_extrude ? PSTR("en") : PSTR("dis")); SERIAL_ECHOLNPAIR("abled (min temp ", thermalManager.extrude_min_temp, "C)"); } } diff --git a/Marlin/src/gcode/config/M309.cpp b/Marlin/src/gcode/config/M309.cpp new file mode 100644 index 000000000000..2247481b2579 --- /dev/null +++ b/Marlin/src/gcode/config/M309.cpp @@ -0,0 +1,48 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../inc/MarlinConfig.h" + +#if ENABLED(PIDTEMPCHAMBER) + +#include "../gcode.h" +#include "../../module/temperature.h" + +/** + * M309 - Set and/or Report the current Chamber PID values + * + * P - Set the P value + * I - Set the I value + * D - Set the D value + */ +void GcodeSuite::M309() { + if (parser.seen('P')) thermalManager.temp_chamber.pid.Kp = parser.value_float(); + if (parser.seen('I')) thermalManager.temp_chamber.pid.Ki = scalePID_i(parser.value_float()); + if (parser.seen('D')) thermalManager.temp_chamber.pid.Kd = scalePID_d(parser.value_float()); + + SERIAL_ECHO_START(); + SERIAL_ECHOLNPAIR(" p:", thermalManager.temp_chamber.pid.Kp, + " i:", unscalePID_i(thermalManager.temp_chamber.pid.Ki), + " d:", unscalePID_d(thermalManager.temp_chamber.pid.Kd)); +} + +#endif // PIDTEMPCHAMBER diff --git a/Marlin/src/gcode/config/M43.cpp b/Marlin/src/gcode/config/M43.cpp index 42a74fb54f8b..4009721a57ed 100644 --- a/Marlin/src/gcode/config/M43.cpp +++ b/Marlin/src/gcode/config/M43.cpp @@ -303,7 +303,7 @@ void GcodeSuite::M43() { if (parser.seen('E')) { endstops.monitor_flag = parser.value_bool(); SERIAL_ECHOPGM("endstop monitor "); - serialprintPGM(endstops.monitor_flag ? PSTR("en") : PSTR("dis")); + SERIAL_ECHOPGM_P(endstops.monitor_flag ? PSTR("en") : PSTR("dis")); SERIAL_ECHOLNPGM("abled"); return; } diff --git a/Marlin/src/gcode/control/M111.cpp b/Marlin/src/gcode/control/M111.cpp index 38cb06532241..8e677080e0b3 100644 --- a/Marlin/src/gcode/control/M111.cpp +++ b/Marlin/src/gcode/control/M111.cpp @@ -49,7 +49,7 @@ void GcodeSuite::M111() { LOOP_L_N(i, COUNT(debug_strings)) { if (TEST(marlin_debug_flags, i)) { if (comma++) SERIAL_CHAR(','); - serialprintPGM((char*)pgm_read_ptr(&debug_strings[i])); + SERIAL_ECHOPGM_P((char*)pgm_read_ptr(&debug_strings[i])); } } } diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp index 394b06d8ac30..1b5ea2f7eff0 100644 --- a/Marlin/src/gcode/control/M80_M81.cpp +++ b/Marlin/src/gcode/control/M80_M81.cpp @@ -56,7 +56,7 @@ // S: Report the current power supply state and exit if (parser.seen('S')) { - serialprintPGM(powersupply_on ? PSTR("PS:1\n") : PSTR("PS:0\n")); + SERIAL_ECHOPGM_P(powersupply_on ? PSTR("PS:1\n") : PSTR("PS:0\n")); return; } diff --git a/Marlin/src/gcode/control/M999.cpp b/Marlin/src/gcode/control/M999.cpp index 7487b4cf6e74..b7219673a3d6 100644 --- a/Marlin/src/gcode/control/M999.cpp +++ b/Marlin/src/gcode/control/M999.cpp @@ -41,5 +41,5 @@ void GcodeSuite::M999() { if (parser.boolval('S')) return; - queue.flush_and_request_resend(); + queue.flush_and_request_resend(queue.ring_buffer.command_port()); } diff --git a/Marlin/src/gcode/feature/L6470/M122.cpp b/Marlin/src/gcode/feature/L6470/M122.cpp index d2b7f73997f8..cfac42764278 100644 --- a/Marlin/src/gcode/feature/L6470/M122.cpp +++ b/Marlin/src/gcode/feature/L6470/M122.cpp @@ -41,16 +41,16 @@ inline void L6470_say_status(const L64XX_axis_t axis) { SERIAL_ECHO(temp_buf); print_bin(sh.STATUS_AXIS_RAW); switch (sh.STATUS_AXIS_LAYOUT) { - case L6470_STATUS_LAYOUT: serialprintPGM(PSTR(" L6470")); break; - case L6474_STATUS_LAYOUT: serialprintPGM(PSTR(" L6474")); break; - case L6480_STATUS_LAYOUT: serialprintPGM(PSTR(" L6480/powerSTEP01")); break; + case L6470_STATUS_LAYOUT: SERIAL_ECHOPGM(" L6470"); break; + case L6474_STATUS_LAYOUT: SERIAL_ECHOPGM(" L6474"); break; + case L6480_STATUS_LAYOUT: SERIAL_ECHOPGM(" L6480/powerSTEP01"); break; } #endif SERIAL_ECHOPGM("\n...OUTPUT: "); - serialprintPGM(sh.STATUS_AXIS & STATUS_HIZ ? PSTR("OFF") : PSTR("ON ")); + SERIAL_ECHOPGM_P(sh.STATUS_AXIS & STATUS_HIZ ? PSTR("OFF") : PSTR("ON ")); SERIAL_ECHOPGM(" BUSY: "); echo_yes_no((sh.STATUS_AXIS & STATUS_BUSY) == 0); SERIAL_ECHOPGM(" DIR: "); - serialprintPGM((((sh.STATUS_AXIS & STATUS_DIR) >> 4) ^ L64xxManager.index_to_dir[axis]) ? PSTR("FORWARD") : PSTR("REVERSE")); + SERIAL_ECHOPGM_P((((sh.STATUS_AXIS & STATUS_DIR) >> 4) ^ L64xxManager.index_to_dir[axis]) ? PSTR("FORWARD") : PSTR("REVERSE")); if (sh.STATUS_AXIS_LAYOUT == L6480_STATUS_LAYOUT) { SERIAL_ECHOPGM(" Last Command: "); if (sh.STATUS_AXIS & sh.STATUS_AXIS_WRONG_CMD) SERIAL_ECHOPGM("VALID"); @@ -67,7 +67,7 @@ inline void L6470_say_status(const L64XX_axis_t axis) { SERIAL_ECHOPGM(" Last Command: "); if (!(sh.STATUS_AXIS & sh.STATUS_AXIS_WRONG_CMD)) SERIAL_ECHOPGM("IN"); SERIAL_ECHOPGM("VALID "); - serialprintPGM(sh.STATUS_AXIS & sh.STATUS_AXIS_NOTPERF_CMD ? PSTR("COMPLETED ") : PSTR("Not PERFORMED")); + SERIAL_ECHOPGM_P(sh.STATUS_AXIS & sh.STATUS_AXIS_NOTPERF_CMD ? PSTR("COMPLETED ") : PSTR("Not PERFORMED")); SERIAL_ECHOPAIR("\n...THERMAL: ", !(sh.STATUS_AXIS & sh.STATUS_AXIS_TH_SD) ? "SHUTDOWN " : !(sh.STATUS_AXIS & sh.STATUS_AXIS_TH_WRN) ? "WARNING " : "OK "); } SERIAL_ECHOPGM(" OVERCURRENT:"); echo_yes_no((sh.STATUS_AXIS & sh.STATUS_AXIS_OCD) == 0); diff --git a/Marlin/src/gcode/feature/L6470/M906.cpp b/Marlin/src/gcode/feature/L6470/M906.cpp index 7bd446a1ab77..3638fae45b5c 100644 --- a/Marlin/src/gcode/feature/L6470/M906.cpp +++ b/Marlin/src/gcode/feature/L6470/M906.cpp @@ -132,7 +132,7 @@ void L64XX_report_current(L64XX &motor, const L64XX_axis_t axis) { SERIAL_ECHOPAIR("...MicroSteps: ", MicroSteps, " ADC_OUT: ", L6470_ADC_out); SERIAL_ECHOPGM(" Vs_compensation: "); - serialprintPGM((motor.GetParam(sh.L6470_AXIS_CONFIG) & CONFIG_EN_VSCOMP) ? PSTR("ENABLED ") : PSTR("DISABLED")); + SERIAL_ECHOPGM_P((motor.GetParam(sh.L6470_AXIS_CONFIG) & CONFIG_EN_VSCOMP) ? PSTR("ENABLED ") : PSTR("DISABLED")); SERIAL_ECHOLNPAIR(" Compensation coefficient: ~", comp_coef * 0.01f); SERIAL_ECHOPAIR("...KVAL_HOLD: ", motor.GetParam(L6470_KVAL_HOLD), diff --git a/Marlin/src/gcode/feature/caselight/M355.cpp b/Marlin/src/gcode/feature/caselight/M355.cpp index 12ae5cff1ddc..b0d94e7cd88a 100644 --- a/Marlin/src/gcode/feature/caselight/M355.cpp +++ b/Marlin/src/gcode/feature/caselight/M355.cpp @@ -61,7 +61,7 @@ void GcodeSuite::M355() { SERIAL_ECHOLNPGM(STR_OFF); else { #if CASELIGHT_USES_BRIGHTNESS - if (PWM_PIN(CASE_LIGHT_PIN)) { + if (TERN(CASE_LIGHT_USE_NEOPIXEL, true, PWM_PIN(CASE_LIGHT_PIN))) { SERIAL_ECHOLN(int(caselight.brightness)); return; } diff --git a/Marlin/src/gcode/feature/pause/M600.cpp b/Marlin/src/gcode/feature/pause/M600.cpp index 1c282f2052c7..1033025fe343 100644 --- a/Marlin/src/gcode/feature/pause/M600.cpp +++ b/Marlin/src/gcode/feature/pause/M600.cpp @@ -83,7 +83,7 @@ void GcodeSuite::M600() { int8_t DXC_ext = target_extruder; if (!parser.seen('T')) { // If no tool index is specified, M600 was (probably) sent in response to filament runout. // In this case, for duplicating modes set DXC_ext to the extruder that ran out. - #if HAS_FILAMENT_SENSOR && NUM_RUNOUT_SENSORS > 1 + #if MULTI_FILAMENT_SENSOR if (idex_is_duplicating()) DXC_ext = (READ(FIL_RUNOUT2_PIN) == FIL_RUNOUT2_STATE) ? 1 : 0; #else diff --git a/Marlin/src/gcode/feature/powerloss/M1000.cpp b/Marlin/src/gcode/feature/powerloss/M1000.cpp index 14c92531fa0b..a31b7732f47c 100644 --- a/Marlin/src/gcode/feature/powerloss/M1000.cpp +++ b/Marlin/src/gcode/feature/powerloss/M1000.cpp @@ -40,7 +40,7 @@ void menu_job_recovery(); inline void plr_error(PGM_P const prefix) { #if ENABLED(DEBUG_POWER_LOSS_RECOVERY) DEBUG_ECHO_START(); - serialprintPGM(prefix); + DEBUG_ECHOPGM_P(prefix); DEBUG_ECHOLNPGM(" Job Recovery Data"); #else UNUSED(prefix); diff --git a/Marlin/src/gcode/feature/powerloss/M413.cpp b/Marlin/src/gcode/feature/powerloss/M413.cpp index 64573e5dff2a..e6e3ac3b3c82 100644 --- a/Marlin/src/gcode/feature/powerloss/M413.cpp +++ b/Marlin/src/gcode/feature/powerloss/M413.cpp @@ -54,8 +54,8 @@ void GcodeSuite::M413() { #if PIN_EXISTS(POWER_LOSS) if (parser.seen('O')) recovery._outage(); #endif - if (parser.seen('E')) serialprintPGM(recovery.exists() ? PSTR("PLR Exists\n") : PSTR("No PLR\n")); - if (parser.seen('V')) serialprintPGM(recovery.valid() ? PSTR("Valid\n") : PSTR("Invalid\n")); + if (parser.seen('E')) SERIAL_ECHOPGM_P(recovery.exists() ? PSTR("PLR Exists\n") : PSTR("No PLR\n")); + if (parser.seen('V')) SERIAL_ECHOPGM_P(recovery.valid() ? PSTR("Valid\n") : PSTR("Invalid\n")); #endif } diff --git a/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp b/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp index 31d076337a44..bca2013e88ba 100644 --- a/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp +++ b/Marlin/src/gcode/feature/prusa_MMU2/M403.cpp @@ -40,7 +40,7 @@ void GcodeSuite::M403() { int8_t index = parser.intval('E', -1), type = parser.intval('F', -1); - if (WITHIN(index, 0, 4) && WITHIN(type, 0, 2)) + if (WITHIN(index, 0, EXTRUDERS - 1) && WITHIN(type, 0, 2)) mmu2.set_filament_type(index, type); else SERIAL_ECHO_MSG("M403 - bad arguments."); diff --git a/Marlin/src/gcode/feature/trinamic/M569.cpp b/Marlin/src/gcode/feature/trinamic/M569.cpp index 6b379f119051..a92812004fb8 100644 --- a/Marlin/src/gcode/feature/trinamic/M569.cpp +++ b/Marlin/src/gcode/feature/trinamic/M569.cpp @@ -32,8 +32,7 @@ template void tmc_say_stealth_status(TMC &st) { st.printLabel(); SERIAL_ECHOPGM(" driver mode:\t"); - serialprintPGM(st.get_stealthChop() ? PSTR("stealthChop") : PSTR("spreadCycle")); - SERIAL_EOL(); + SERIAL_ECHOLNPGM_P(st.get_stealthChop() ? PSTR("stealthChop") : PSTR("spreadCycle")); } template void tmc_set_stealthChop(TMC &st, const bool enable) { diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 77ac1fbff86b..e9a6d4aa2a52 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -260,13 +260,6 @@ void GcodeSuite::dwell(millis_t time) { #endif // HAS_LEVELING && G29_RETRY_AND_RECOVER -// -// Placeholders for non-migrated codes -// -#if ENABLED(M100_FREE_MEMORY_WATCHER) - extern void M100_dump_routine(PGM_P const title, const char * const start, const char * const end); -#endif - /** * Process the parsed command and dispatch it to its handler */ @@ -371,6 +364,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { break; #endif + #if HAS_MESH + case 42: G42(); break; // G42: Coordinated move to a mesh point + #endif + #if ENABLED(CNC_COORDINATE_SYSTEMS) case 53: G53(); break; // G53: (prefix) Apply native workspace case 54: G54(); break; // G54: Switch to Workspace 1 @@ -399,10 +396,6 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 92: G92(); break; // G92: Set current axis position(s) - #if HAS_MESH - case 42: G42(); break; // G42: Coordinated move to a mesh point - #endif - #if ENABLED(CALIBRATION_GCODE) case 425: G425(); break; // G425: Perform calibration with calibration cube #endif @@ -682,6 +675,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { case 304: M304(); break; // M304: Set bed PID parameters #endif + #if ENABLED(PIDTEMPCHAMBER) + case 309: M309(); break; // M309: Set chamber PID parameters + #endif + #if ENABLED(PHOTO_GCODE) case 240: M240(); break; // M240: Trigger a camera #endif @@ -990,30 +987,32 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { SERIAL_OUT(msgDone); // Call the msgDone serial hook to signal command processing done } +#if ENABLED(M100_FREE_MEMORY_DUMPER) + void M100_dump_routine(PGM_P const title, const char * const start, const uintptr_t size); +#endif + /** * Process a single command and dispatch it to its handler * This is called from the main loop() */ void GcodeSuite::process_next_command() { - char * const current_command = queue.command_buffer[queue.index_r]; + GCodeQueue::CommandLine &command = queue.ring_buffer.peek_next_command(); - PORT_REDIRECT(SERIAL_PORTMASK(queue.port[queue.index_r])); + PORT_REDIRECT(SERIAL_PORTMASK(command.port)); - #if ENABLED(POWER_LOSS_RECOVERY) - recovery.queue_index_r = queue.index_r; - #endif + TERN_(POWER_LOSS_RECOVERY, recovery.queue_index_r = queue.ring_buffer.index_r); if (DEBUGGING(ECHO)) { SERIAL_ECHO_START(); - SERIAL_ECHOLN(current_command); + SERIAL_ECHOLN(command.buffer); #if ENABLED(M100_FREE_MEMORY_DUMPER) - SERIAL_ECHOPAIR("slot:", queue.index_r); - M100_dump_routine(PSTR(" Command Queue:"), &queue.command_buffer[0][0], &queue.command_buffer[BUFSIZE - 1][MAX_CMD_SIZE - 1]); + SERIAL_ECHOPAIR("slot:", queue.ring_buffer.index_r); + M100_dump_routine(PSTR(" Command Queue:"), (const char*)&queue.ring_buffer, sizeof(queue.ring_buffer)); #endif } // Parse the next command in the queue - parser.parse(current_command); + parser.parse(command.buffer); process_parsed_command(); } diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 7fd8d6904afb..123b648f9031 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -197,6 +197,7 @@ * M303 - PID relay autotune S sets the target temperature. Default 150C. (Requires PIDTEMP) * M304 - Set bed PID parameters P I and D. (Requires PIDTEMPBED) * M305 - Set user thermistor parameters R T and P. (Requires TEMP_SENSOR_x 1000) + * M309 - Set chamber PID parameters P I and D. (Requires PIDTEMPCHAMBER) * M350 - Set microstepping mode. (Requires digital microstepping pins.) * M351 - Toggle MS1 MS2 pins directly. (Requires digital microstepping pins.) * M355 - Set Case Light on/off and set brightness. (Requires CASE_LIGHT_PIN) @@ -711,6 +712,8 @@ class GcodeSuite { TERN_(HAS_USER_THERMISTORS, static void M305()); + TERN_(PIDTEMPCHAMBER, static void M309()); + #if HAS_MICROSTEPS static void M350(); static void M351(); diff --git a/Marlin/src/gcode/gcode_d.cpp b/Marlin/src/gcode/gcode_d.cpp index 653ae6a553f3..a683a330f10d 100644 --- a/Marlin/src/gcode/gcode_d.cpp +++ b/Marlin/src/gcode/gcode_d.cpp @@ -152,8 +152,7 @@ NOMORE(len, FLASH_SIZE - addr); if (parser.seenval('X')) { // TODO: Write the hex bytes after the X - //while (len--) { - //} + //while (len--) {} } else { // while (len--) { @@ -166,7 +165,7 @@ case 6: // D6 Check delay loop accuracy dump_delay_accuracy_check(); - break; + break; case 100: { // D100 Disable heaters and attempt a hard hang (Watchdog Test) SERIAL_ECHOLNPGM("Disabling heaters and attempting to trigger Watchdog"); @@ -180,7 +179,25 @@ for (int i = 10000; i--;) DELAY_US(1000UL); ENABLE_ISRS(); SERIAL_ECHOLNPGM("FAILURE: Watchdog did not trigger board reset."); + } break; + + #if ENABLED(POSTMORTEM_DEBUGGING) + case 451: { // Trigger all kind of faults to test exception catcher + SERIAL_ECHOLNPGM("Disabling heaters"); + thermalManager.disable_all_heaters(); + delay(1000); // Allow time to print + volatile uint8_t type[5] = { parser.byteval('T', 1) }; + + // The code below is obviously wrong and it's full of quirks to fool the compiler from optimizing away the code + switch (type[0]) { + case 1: default: *(int*)0 = 451; break; // Write at bad address + case 2: { volatile int a = 0; volatile int b = 452 / a; *(int*)&a = b; } break; // Divide by zero (some CPUs accept this, like ARM) + case 3: { *(uint32_t*)&type[1] = 453; volatile int a = *(int*)&type[1]; type[0] = a / 255; } break; // Unaligned access (some CPUs accept this) + case 4: { volatile void (*func)() = (volatile void (*)()) 0xE0000000; func(); } break; // Invalid instruction + } + break; } + #endif } } diff --git a/Marlin/src/gcode/geometry/G17-G19.cpp b/Marlin/src/gcode/geometry/G17-G19.cpp index 7510eaba8c3d..0154598ccb22 100644 --- a/Marlin/src/gcode/geometry/G17-G19.cpp +++ b/Marlin/src/gcode/geometry/G17-G19.cpp @@ -29,7 +29,7 @@ inline void report_workspace_plane() { SERIAL_ECHO_START(); SERIAL_ECHOPGM("Workspace Plane "); - serialprintPGM( + SERIAL_ECHOPGM_P( gcode.workspace_plane == GcodeSuite::PLANE_YZ ? PSTR("YZ\n") : gcode.workspace_plane == GcodeSuite::PLANE_ZX ? PSTR("ZX\n") : PSTR("XY\n") diff --git a/Marlin/src/gcode/geometry/G92.cpp b/Marlin/src/gcode/geometry/G92.cpp index 1a0382ed7c2b..30620be6f958 100644 --- a/Marlin/src/gcode/geometry/G92.cpp +++ b/Marlin/src/gcode/geometry/G92.cpp @@ -29,77 +29,90 @@ #endif /** - * G92: Set current position to given X Y Z E + * G92: Set the Current Position to the given X Y Z E values. + * + * Behind the scenes the G92 command may modify the Current Position + * or the Position Shift depending on settings and sub-commands. + * + * Since E has no Workspace Offset, it is always set directly. + * + * Without Workspace Offsets (e.g., with NO_WORKSPACE_OFFSETS): + * G92 : Set NATIVE Current Position to the given X Y Z E. + * + * Using Workspace Offsets (default Marlin behavior): + * G92 : Modify Workspace Offsets so the reported position shows the given X Y Z E. + * G92.1 : Zero XYZ Workspace Offsets (so the reported position = the native position). + * + * With POWER_LOSS_RECOVERY: + * G92.9 : Set NATIVE Current Position to the given X Y Z E. */ void GcodeSuite::G92() { - bool sync_E = false, sync_XYZ = false; + bool sync_E = false, sync_XYZE = false; - #if ENABLED(USE_GCODE_SUBCODES) + #if USE_GCODE_SUBCODES const uint8_t subcode_G92 = parser.subcode; #else constexpr uint8_t subcode_G92 = 0; #endif switch (subcode_G92) { - default: break; - #if ENABLED(CNC_COORDINATE_SYSTEMS) - case 1: { - // Zero the G92 values and restore current position - #if !IS_SCARA - LOOP_XYZ(i) if (position_shift[i]) { - position_shift[i] = 0; - update_workspace_offset((AxisEnum)i); - } - #endif // Not SCARA - } return; + default: return; // Ignore unknown G92.x + + #if ENABLED(CNC_COORDINATE_SYSTEMS) && !IS_SCARA + case 1: // G92.1 - Zero the Workspace Offset + LOOP_XYZ(i) if (position_shift[i]) { + position_shift[i] = 0; + update_workspace_offset((AxisEnum)i); + } + break; #endif + #if ENABLED(POWER_LOSS_RECOVERY) - case 9: { + case 9: // G92.9 - Set Current Position directly (like Marlin 1.0) LOOP_XYZE(i) { if (parser.seenval(axis_codes[i])) { + if (i == E_AXIS) sync_E = true; else sync_XYZE = true; current_position[i] = parser.value_axis_units((AxisEnum)i); - if (i == E_AXIS) sync_E = true; else sync_XYZ = true; } } - } break; + break; #endif - case 0: { + + case 0: LOOP_XYZE(i) { if (parser.seenval(axis_codes[i])) { - const float l = parser.value_axis_units((AxisEnum)i), - v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i), - d = v - current_position[i]; + const float l = parser.value_axis_units((AxisEnum)i), // Given axis coordinate value, converted to millimeters + v = i == E_AXIS ? l : LOGICAL_TO_NATIVE(l, i), // Axis position in NATIVE space (applying the existing offset) + d = v - current_position[i]; // How much is the current axis position altered by? if (!NEAR_ZERO(d)) { - #if IS_SCARA || !HAS_POSITION_SHIFT - if (i == E_AXIS) sync_E = true; else sync_XYZ = true; - current_position[i] = v; // Without workspaces revert to Marlin 1.0 behavior - #elif HAS_POSITION_SHIFT + #if HAS_POSITION_SHIFT && !IS_SCARA // When using workspaces... if (i == E_AXIS) { sync_E = true; - current_position.e = v; // When using coordinate spaces, only E is set directly + current_position.e = v; // ...E is still set directly } else { - position_shift[i] += d; // Other axes simply offset the coordinate space + position_shift[i] += d; // ...but other axes offset the workspace. update_workspace_offset((AxisEnum)i); } + #else // Without workspaces... + if (i == E_AXIS) sync_E = true; else sync_XYZE = true; + current_position[i] = v; // ...set Current Position directly (like Marlin 1.0) #endif } } } - } break; + break; } #if ENABLED(CNC_COORDINATE_SYSTEMS) - // Apply workspace offset to the active coordinate system + // Apply Workspace Offset to the active coordinate system if (WITHIN(active_coordinate_system, 0, MAX_COORDINATE_SYSTEMS - 1)) coordinate_system[active_coordinate_system] = position_shift; #endif - if (sync_XYZ) sync_plan_position(); + if (sync_XYZE) sync_plan_position(); else if (sync_E) sync_plan_position_e(); - #if DISABLED(DIRECT_STEPPING) - report_current_position(); - #endif + IF_DISABLED(DIRECT_STEPPING, report_current_position()); } diff --git a/Marlin/src/gcode/host/M110.cpp b/Marlin/src/gcode/host/M110.cpp index b12b38ea0f12..2634b198978d 100644 --- a/Marlin/src/gcode/host/M110.cpp +++ b/Marlin/src/gcode/host/M110.cpp @@ -29,6 +29,6 @@ void GcodeSuite::M110() { if (parser.seenval('N')) - queue.last_N[queue.command_port()] = parser.value_long(); + queue.set_current_line_number(parser.value_long()); } diff --git a/Marlin/src/gcode/host/M115.cpp b/Marlin/src/gcode/host/M115.cpp index 0501f3f60bcc..ac712aea07e0 100644 --- a/Marlin/src/gcode/host/M115.cpp +++ b/Marlin/src/gcode/host/M115.cpp @@ -34,8 +34,8 @@ #if ENABLED(EXTENDED_CAPABILITIES_REPORT) static void cap_line(PGM_P const name, bool ena=false) { SERIAL_ECHOPGM("Cap:"); - serialprintPGM(name); - SERIAL_CHAR(':', ena ? '1' : '0'); + SERIAL_ECHOPGM_P(name); + SERIAL_CHAR(':', '0' + ena); SERIAL_EOL(); } #endif @@ -106,7 +106,7 @@ void GcodeSuite::M115() { // TOGGLE_LIGHTS (M355) cap_line(PSTR("TOGGLE_LIGHTS"), ENABLED(CASE_LIGHT_ENABLE)); - cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, TERN0(CASELIGHT_USES_BRIGHTNESS, TERN(CASE_LIGHT_USE_NEOPIXEL, true, PWM_PIN(CASE_LIGHT_PIN))))); + cap_line(PSTR("CASE_LIGHT_BRIGHTNESS"), TERN0(CASE_LIGHT_ENABLE, caselight.has_brightness())); // EMERGENCY_PARSER (M108, M112, M410, M876) cap_line(PSTR("EMERGENCY_PARSER"), ENABLED(EMERGENCY_PARSER)); diff --git a/Marlin/src/gcode/host/M118.cpp b/Marlin/src/gcode/host/M118.cpp index 73115d5c0afb..9982492f9348 100644 --- a/Marlin/src/gcode/host/M118.cpp +++ b/Marlin/src/gcode/host/M118.cpp @@ -52,15 +52,9 @@ void GcodeSuite::M118() { while (*p == ' ') ++p; } - #if HAS_MULTI_SERIAL - const int8_t old_serial = multiSerial.portMask; - if (WITHIN(port, 0, NUM_SERIAL)) - multiSerial.portMask = port ? _BV(port - 1) : SERIAL_ALL; - #endif + PORT_REDIRECT(WITHIN(port, 0, NUM_SERIAL) ? (port ? SERIAL_PORTMASK(port - 1) : SERIAL_ALL) : multiSerial.portMask); if (hasE) SERIAL_ECHO_START(); if (hasA) SERIAL_ECHOPGM("//"); SERIAL_ECHOLN(p); - - TERN_(HAS_MULTI_SERIAL, multiSerial.portMask = old_serial); } diff --git a/Marlin/src/gcode/host/M360.cpp b/Marlin/src/gcode/host/M360.cpp index b0bd4a3b8ee6..50a4e4542659 100644 --- a/Marlin/src/gcode/host/M360.cpp +++ b/Marlin/src/gcode/host/M360.cpp @@ -34,10 +34,9 @@ static void config_prefix(PGM_P const name, PGM_P const pref=nullptr, const int8_t ind=-1) { SERIAL_ECHOPGM("Config:"); - if (pref) serialprintPGM(pref); + if (pref) SERIAL_ECHOPGM_P(pref); if (ind >= 0) { SERIAL_ECHO(ind); SERIAL_CHAR(':'); } - serialprintPGM(name); - SERIAL_CHAR(':'); + SERIAL_ECHOPAIR_P(name, AS_CHAR(':')); } static void config_line(PGM_P const name, const float val, PGM_P const pref=nullptr, const int8_t ind=-1) { config_prefix(name, pref, ind); diff --git a/Marlin/src/gcode/parser.cpp b/Marlin/src/gcode/parser.cpp index 6408b2ce2de5..ebe9d3b2cd67 100644 --- a/Marlin/src/gcode/parser.cpp +++ b/Marlin/src/gcode/parser.cpp @@ -47,13 +47,13 @@ char *GCodeParser::command_ptr, char GCodeParser::command_letter; uint16_t GCodeParser::codenum; -#if ENABLED(USE_GCODE_SUBCODES) +#if USE_GCODE_SUBCODES uint8_t GCodeParser::subcode; #endif #if ENABLED(GCODE_MOTION_MODES) int16_t GCodeParser::motion_mode_codenum = -1; - #if ENABLED(USE_GCODE_SUBCODES) + #if USE_GCODE_SUBCODES uint8_t GCodeParser::motion_mode_subcode; #endif #endif @@ -189,7 +189,7 @@ void GCodeParser::parse(char *p) { } // Allow for decimal point in command - #if ENABLED(USE_GCODE_SUBCODES) + #if USE_GCODE_SUBCODES if (*p == '.') { p++; while (NUMERIC(*p)) diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index d60b21a90619..5a31a9943e29 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -85,13 +85,13 @@ class GCodeParser { *string_arg, // string of command line command_letter; // G, M, or T static uint16_t codenum; // 123 - #if ENABLED(USE_GCODE_SUBCODES) + #if USE_GCODE_SUBCODES static uint8_t subcode; // .1 #endif #if ENABLED(GCODE_MOTION_MODES) static int16_t motion_mode_codenum; - #if ENABLED(USE_GCODE_SUBCODES) + #if USE_GCODE_SUBCODES static uint8_t motion_mode_subcode; #endif FORCE_INLINE static void cancel_motion_mode() { motion_mode_codenum = -1; } diff --git a/Marlin/src/gcode/queue.cpp b/Marlin/src/gcode/queue.cpp index c49247912c06..93deac0566de 100644 --- a/Marlin/src/gcode/queue.cpp +++ b/Marlin/src/gcode/queue.cpp @@ -35,6 +35,7 @@ GCodeQueue queue; #include "../module/planner.h" #include "../module/temperature.h" #include "../MarlinCore.h" +#include "../core/bug_on.h" #if ENABLED(PRINTER_EVENT_LEDS) #include "../feature/leds/printer_event_leds.h" @@ -48,10 +49,6 @@ GCodeQueue queue; #include "../feature/binary_stream.h" #endif -#if ENABLED(MEATPACK) - #include "../feature/meatpack.h" -#endif - #if ENABLED(POWER_LOSS_RECOVERY) #include "../feature/powerloss.h" #endif @@ -63,44 +60,17 @@ GCodeQueue queue; // Frequently used G-code strings PGMSTR(G28_STR, "G28"); -/** - * GCode line number handling. Hosts may opt to include line numbers when - * sending commands to Marlin, and lines will be checked for sequentiality. - * M110 N sets the current line number. - */ -long GCodeQueue::last_N[NUM_SERIAL]; - -/** - * GCode Command Queue - * A simple ring buffer of BUFSIZE command strings. - * - * Commands are copied into this buffer by the command injectors - * (immediate, serial, sd card) and they are processed sequentially by - * the main loop. The gcode.process_next_command method parses the next - * command and hands off execution to individual handler functions. - */ -uint8_t GCodeQueue::length = 0, // Count of commands in the queue - GCodeQueue::index_r = 0, // Ring buffer read position - GCodeQueue::index_w = 0; // Ring buffer write position - -char GCodeQueue::command_buffer[BUFSIZE][MAX_CMD_SIZE]; +GCodeQueue::SerialState GCodeQueue::serial_state[NUM_SERIAL] = { 0 }; +GCodeQueue::RingBuffer GCodeQueue::ring_buffer = { 0 }; -/* - * The port that the command was received on - */ -#if HAS_MULTI_SERIAL - serial_index_t GCodeQueue::port[BUFSIZE]; +#if NO_TIMEOUTS > 0 + static millis_t last_command_time = 0; #endif /** * Serial command injection */ -// Number of characters read in the current line of serial input -static int serial_count[NUM_SERIAL] = { 0 }; - -bool send_ok[BUFSIZE]; - /** * Next Injected PROGMEM Command pointer. (nullptr == empty) * Internal commands are enqueued ahead of serial / SD commands. @@ -112,38 +82,16 @@ PGM_P GCodeQueue::injected_commands_P; // = nullptr */ char GCodeQueue::injected_commands[64]; // = { 0 } -GCodeQueue::GCodeQueue() { - // Send "ok" after commands by default - LOOP_L_N(i, COUNT(send_ok)) send_ok[i] = true; -} - -/** - * Check whether there are any commands yet to be executed - */ -bool GCodeQueue::has_commands_queued() { - return queue.length || injected_commands_P || injected_commands[0]; -} -/** - * Clear the Marlin command queue - */ -void GCodeQueue::clear() { - index_r = index_w = length = 0; -} - -/** - * Once a new command is in the ring buffer, call this to commit it - */ -void GCodeQueue::_commit_command(bool say_ok +void GCodeQueue::RingBuffer::commit_command(bool skip_ok #if HAS_MULTI_SERIAL , serial_index_t serial_ind/*=-1*/ #endif ) { - send_ok[index_w] = say_ok; - TERN_(HAS_MULTI_SERIAL, port[index_w] = serial_ind); + commands[index_w].skip_ok = skip_ok; + TERN_(HAS_MULTI_SERIAL, commands[index_w].port = serial_ind); TERN_(POWER_LOSS_RECOVERY, recovery.commit_sdpos(index_w)); - if (++index_w >= BUFSIZE) index_w = 0; - length++; + advance_pos(index_w, 1); } /** @@ -151,14 +99,14 @@ void GCodeQueue::_commit_command(bool say_ok * Return true if the command was successfully added. * Return false for a full buffer, or if the 'command' is a comment. */ -bool GCodeQueue::_enqueue(const char* cmd, bool say_ok/*=false*/ +bool GCodeQueue::RingBuffer::enqueue(const char* cmd, bool skip_ok/*=true*/ #if HAS_MULTI_SERIAL , serial_index_t serial_ind/*=-1*/ #endif ) { if (*cmd == ';' || length >= BUFSIZE) return false; - strcpy(command_buffer[index_w], cmd); - _commit_command(say_ok + strcpy(commands[index_w].buffer, cmd); + commit_command(skip_ok #if HAS_MULTI_SERIAL , serial_ind #endif @@ -171,14 +119,11 @@ bool GCodeQueue::_enqueue(const char* cmd, bool say_ok/*=false*/ * Return true if the command was consumed */ bool GCodeQueue::enqueue_one(const char* cmd) { - - //SERIAL_ECHOPGM("enqueue_one(\""); - //SERIAL_ECHO(cmd); - //SERIAL_ECHOPGM("\") \n"); + //SERIAL_ECHOLNPAIR("enqueue_one(\"", cmd, "\")"); if (*cmd == 0 || ISEOL(*cmd)) return true; - if (_enqueue(cmd)) { + if (ring_buffer.enqueue(cmd)) { SERIAL_ECHO_MSG(STR_ENQUEUEING, cmd, "\""); return true; } @@ -256,7 +201,7 @@ bool GCodeQueue::enqueue_one_P(PGM_P const pgcode) { char cmd[i + 1]; memcpy_P(cmd, p, i); cmd[i] = '\0'; - return _enqueue(cmd); + return ring_buffer.enqueue(cmd); } /** @@ -287,16 +232,21 @@ void GCodeQueue::enqueue_now_P(PGM_P const pgcode) { * P Planner space remaining * B Block queue space remaining */ -void GCodeQueue::ok_to_send() { +void GCodeQueue::RingBuffer::ok_to_send() { + #if NO_TIMEOUTS > 0 + // Start counting from the last command's execution + last_command_time = millis(); + #endif + CommandLine &command = commands[index_r]; #if HAS_MULTI_SERIAL - const serial_index_t serial_ind = command_port(); + const serial_index_t serial_ind = command.port; if (serial_ind < 0) return; PORT_REDIRECT(SERIAL_PORTMASK(serial_ind)); // Reply to the serial port that sent the command #endif - if (!send_ok[index_r]) return; + if (command.skip_ok) return; SERIAL_ECHOPGM(STR_OK); #if ENABLED(ADVANCED_OK) - char* p = command_buffer[index_r]; + char* p = command.buffer; if (*p == 'N') { SERIAL_CHAR(' ', *p++); while (NUMERIC_SIGNED(*p)) @@ -312,49 +262,51 @@ void GCodeQueue::ok_to_send() { * Send a "Resend: nnn" message to the host to * indicate that a command needs to be re-sent. */ -void GCodeQueue::flush_and_request_resend() { - const serial_index_t serial_ind = command_port(); +void GCodeQueue::flush_and_request_resend(const serial_index_t serial_ind) { #if HAS_MULTI_SERIAL if (serial_ind < 0) return; // Never mind. Command came from SD or Flash Drive PORT_REDIRECT(SERIAL_PORTMASK(serial_ind)); // Reply to the serial port that sent the command #endif SERIAL_FLUSH(); SERIAL_ECHOPGM(STR_RESEND); - SERIAL_ECHOLN(last_N[serial_ind] + 1); - ok_to_send(); -} - -inline bool serial_data_available() { - byte data_available = 0; - if (MYSERIAL0.available()) data_available++; - #ifdef SERIAL_PORT_2 - const bool port2_open = TERN1(HAS_ETHERNET, ethernet.have_telnet_client); - if (port2_open && MYSERIAL1.available()) data_available++; - #endif - return data_available > 0; + SERIAL_ECHOLN(serial_state[serial_ind].last_N + 1); } -inline int read_serial(const uint8_t index) { - switch (index) { - case 0: return MYSERIAL0.read(); - case 1: { - #if HAS_MULTI_SERIAL - const bool port2_open = TERN1(HAS_ETHERNET, ethernet.have_telnet_client); - if (port2_open) return MYSERIAL1.read(); +// Multiserial already handle the dispatch to/from multiple port by itself +inline bool serial_data_available(uint8_t index = SERIAL_ALL) { + if (index == SERIAL_ALL) { + for (index = 0; index < NUM_SERIAL; index++) { + const int a = SERIAL_IMPL.available(index); + #if BOTH(RX_BUFFER_MONITOR, RX_BUFFER_SIZE) + if (a > RX_BUFFER_SIZE - 2) { + PORT_REDIRECT(SERIAL_PORTMASK(index)); + SERIAL_ERROR_MSG("RX BUF overflow, increase RX_BUFFER_SIZE: ", a); + } #endif + if (a > 0) return true; } - default: return -1; + return false; } + const int a = SERIAL_IMPL.available(index); + #if BOTH(RX_BUFFER_MONITOR, RX_BUFFER_SIZE) + if (a > RX_BUFFER_SIZE - 2) { + PORT_REDIRECT(SERIAL_PORTMASK(index)); + SERIAL_ERROR_MSG("RX BUF overflow, increase RX_BUFFER_SIZE: ", a); + } + #endif + + return a > 0; } +inline int read_serial(const uint8_t index) { return SERIAL_IMPL.read(index); } + void GCodeQueue::gcode_line_error(PGM_P const err, const serial_index_t serial_ind) { PORT_REDIRECT(SERIAL_PORTMASK(serial_ind)); // Reply to the serial port that sent the command SERIAL_ERROR_START(); - serialprintPGM(err); - SERIAL_ECHOLN(last_N[serial_ind]); - while (read_serial(serial_ind) != -1); // Clear out the RX buffer - flush_and_request_resend(); - serial_count[serial_ind] = 0; + SERIAL_ECHOLNPAIR_P(err, serial_state[serial_ind].last_N); + while (read_serial(serial_ind) != -1) { /* nada */ } // Clear out the RX buffer. Why don't use flush here ? + flush_and_request_resend(serial_ind); + serial_state[serial_ind].count = 0; } FORCE_INLINE bool is_M29(const char * const cmd) { // matches "M29" & "M29 ", but not "M290", etc @@ -441,10 +393,6 @@ inline bool process_line_done(uint8_t &sis, char (&buff)[MAX_CMD_SIZE], int &ind * left on the serial port. */ void GCodeQueue::get_serial_commands() { - static char serial_line_buffer[NUM_SERIAL][MAX_CMD_SIZE]; - - static uint8_t serial_input_state[NUM_SERIAL] = { PS_NORMAL }; - #if ENABLED(BINARY_FILE_TRANSFER) if (card.flag.binary_mode) { /** @@ -452,7 +400,7 @@ void GCodeQueue::get_serial_commands() { * receive buffer (which limits the packet size to MAX_CMD_SIZE). * The receive buffer also limits the packet size for reliable transmission. */ - binaryStream[card.transfer_port_index].receive(serial_line_buffer[card.transfer_port_index]); + binaryStream[card.transfer_port_index].receive(serial_state[card.transfer_port_index].line_buffer); return; } #endif @@ -460,124 +408,141 @@ void GCodeQueue::get_serial_commands() { // If the command buffer is empty for too long, // send "wait" to indicate Marlin is still waiting. #if NO_TIMEOUTS > 0 - static millis_t last_command_time = 0; const millis_t ms = millis(); - if (length == 0 && !serial_data_available() && ELAPSED(ms, last_command_time + NO_TIMEOUTS)) { + if (ring_buffer.empty() && !serial_data_available() && ELAPSED(ms, last_command_time + NO_TIMEOUTS)) { SERIAL_ECHOLNPGM(STR_WAIT); last_command_time = ms; } #endif - /** - * Loop while serial characters are incoming and the queue is not full - */ - while (length < BUFSIZE && serial_data_available()) { + // Loop while serial characters are incoming and the queue is not full + for (bool hadData = true; hadData;) { + // Unless a serial port has data, this will exit on next iteration + hadData = false; + LOOP_L_N(p, NUM_SERIAL) { + // Check if the queue is full and exit if it is. + if (ring_buffer.full()) return; - const int c = read_serial(p); - if (c < 0) continue; - - #if ENABLED(MEATPACK) - meatpack.handle_rx_char(uint8_t(c), p); - char c_res[2] = { 0, 0 }; - const uint8_t char_count = meatpack.get_result_char(c_res); - #else - constexpr uint8_t char_count = 1; - #endif + // No data for this port ? Skip it + if (!serial_data_available(p)) continue; - LOOP_L_N(char_index, char_count) { - const char serial_char = TERN(MEATPACK, c_res[char_index], c); + // Ok, we have some data to process, let's make progress here + hadData = true; - if (ISEOL(serial_char)) { + const int c = read_serial(p); + if (c < 0) { + // This should never happen, let's log it + PORT_REDIRECT(SERIAL_PORTMASK(p)); // Reply to the serial port that sent the command + // Crash here to get more information why it failed + BUG_ON("SP available but read -1"); + SERIAL_ERROR_MSG(STR_ERR_SERIAL_MISMATCH); + SERIAL_FLUSH(); + continue; + } - // Reset our state, continue if the line was empty - if (process_line_done(serial_input_state[p], serial_line_buffer[p], serial_count[p])) - continue; + const char serial_char = (char)c; + SerialState &serial = serial_state[p]; - char* command = serial_line_buffer[p]; + if (ISEOL(serial_char)) { - while (*command == ' ') command++; // Skip leading spaces - char *npos = (*command == 'N') ? command : nullptr; // Require the N parameter to start the line + // Reset our state, continue if the line was empty + if (process_line_done(serial.input_state, serial.line_buffer, serial.count)) + continue; - if (npos) { + char* command = serial.line_buffer; - const bool M110 = !!strstr_P(command, PSTR("M110")); + while (*command == ' ') command++; // Skip leading spaces + char *npos = (*command == 'N') ? command : nullptr; // Require the N parameter to start the line - if (M110) { - char* n2pos = strchr(command + 4, 'N'); - if (n2pos) npos = n2pos; - } + if (npos) { - const long gcode_N = strtol(npos + 1, nullptr, 10); + const bool M110 = !!strstr_P(command, PSTR("M110")); - if (gcode_N != last_N[p] + 1 && !M110) - return gcode_line_error(PSTR(STR_ERR_LINE_NO), p); + if (M110) { + char* n2pos = strchr(command + 4, 'N'); + if (n2pos) npos = n2pos; + } - char *apos = strrchr(command, '*'); - if (apos) { - uint8_t checksum = 0, count = uint8_t(apos - command); - while (count) checksum ^= command[--count]; - if (strtol(apos + 1, nullptr, 10) != checksum) - return gcode_line_error(PSTR(STR_ERR_CHECKSUM_MISMATCH), p); - } - else - return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), p); + const long gcode_N = strtol(npos + 1, nullptr, 10); - last_N[p] = gcode_N; + if (gcode_N != serial.last_N + 1 && !M110) { + // In case of error on a serial port, don't prevent other serial port from making progress + gcode_line_error(PSTR(STR_ERR_LINE_NO), p); + break; } - #if ENABLED(SDSUPPORT) - // Pronterface "M29" and "M29 " has no line number - else if (card.flag.saving && !is_M29(command)) - return gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), p); - #endif - // - // Movement commands give an alert when the machine is stopped - // - - if (IsStopped()) { - char* gpos = strchr(command, 'G'); - if (gpos) { - switch (strtol(gpos + 1, nullptr, 10)) { - case 0: case 1: - #if ENABLED(ARC_SUPPORT) - case 2: case 3: - #endif - #if ENABLED(BEZIER_CURVE_SUPPORT) - case 5: - #endif - PORT_REDIRECT(SERIAL_PORTMASK(p)); // Reply to the serial port that sent the command - SERIAL_ECHOLNPGM(STR_ERR_STOPPED); - LCD_MESSAGEPGM(MSG_STOPPED); - break; - } + char *apos = strrchr(command, '*'); + if (apos) { + uint8_t checksum = 0, count = uint8_t(apos - command); + while (count) checksum ^= command[--count]; + if (strtol(apos + 1, nullptr, 10) != checksum) { + // In case of error on a serial port, don't prevent other serial port from making progress + gcode_line_error(PSTR(STR_ERR_CHECKSUM_MISMATCH), p); + break; } } + else { + // In case of error on a serial port, don't prevent other serial port from making progress + gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), p); + break; + } - #if DISABLED(EMERGENCY_PARSER) - // Process critical commands early - if (command[0] == 'M') switch (command[3]) { - case '8': if (command[2] == '0' && command[1] == '1') { wait_for_heatup = false; TERN_(HAS_LCD_MENU, wait_for_user = false); } break; - case '2': if (command[2] == '1' && command[1] == '1') kill(M112_KILL_STR, nullptr, true); break; - case '0': if (command[1] == '4' && command[2] == '1') quickstop_stepper(); break; + serial.last_N = gcode_N; + } + #if ENABLED(SDSUPPORT) + // Pronterface "M29" and "M29 " has no line number + else if (card.flag.saving && !is_M29(command)) { + gcode_line_error(PSTR(STR_ERR_NO_CHECKSUM), p); + break; + } + #endif + + // + // Movement commands give an alert when the machine is stopped + // + + if (IsStopped()) { + char* gpos = strchr(command, 'G'); + if (gpos) { + switch (strtol(gpos + 1, nullptr, 10)) { + case 0: case 1: + #if ENABLED(ARC_SUPPORT) + case 2: case 3: + #endif + #if ENABLED(BEZIER_CURVE_SUPPORT) + case 5: + #endif + PORT_REDIRECT(SERIAL_PORTMASK(p)); // Reply to the serial port that sent the command + SERIAL_ECHOLNPGM(STR_ERR_STOPPED); + LCD_MESSAGEPGM(MSG_STOPPED); + break; } - #endif + } + } - #if defined(NO_TIMEOUTS) && NO_TIMEOUTS > 0 - last_command_time = ms; - #endif + #if DISABLED(EMERGENCY_PARSER) + // Process critical commands early + if (command[0] == 'M') switch (command[3]) { + case '8': if (command[2] == '0' && command[1] == '1') { wait_for_heatup = false; TERN_(HAS_LCD_MENU, wait_for_user = false); } break; + case '2': if (command[2] == '1' && command[1] == '1') kill(M112_KILL_STR, nullptr, true); break; + case '0': if (command[1] == '4' && command[2] == '1') quickstop_stepper(); break; + } + #endif - // Add the command to the queue - _enqueue(serial_line_buffer[p], true - #if HAS_MULTI_SERIAL - , p - #endif - ); - } - else - process_stream_char(serial_char, serial_input_state[p], serial_line_buffer[p], serial_count[p]); + #if NO_TIMEOUTS > 0 + last_command_time = ms; + #endif - } // char_count loop + // Add the command to the queue + ring_buffer.enqueue(serial.line_buffer, false + #if HAS_MULTI_SERIAL + , p + #endif + ); + } + else + process_stream_char(serial_char, serial.input_state, serial.line_buffer, serial.count); } // NUM_SERIAL loop } // queue has space, serial has data @@ -597,33 +562,35 @@ void GCodeQueue::get_serial_commands() { if (!IS_SD_PRINTING()) return; int sd_count = 0; - while (length < BUFSIZE && !card.eof()) { + while (!ring_buffer.full() && !card.eof()) { const int16_t n = card.get(); const bool card_eof = card.eof(); if (n < 0 && !card_eof) { SERIAL_ERROR_MSG(STR_SD_ERR_READ); continue; } + CommandLine &command = ring_buffer.commands[ring_buffer.index_w]; const char sd_char = (char)n; const bool is_eol = ISEOL(sd_char); if (is_eol || card_eof) { + // Reset stream state, terminate the buffer, and commit a non-empty command if (!is_eol && sd_count) ++sd_count; // End of file with no newline - if (!process_line_done(sd_input_state, command_buffer[index_w], sd_count)) { + if (!process_line_done(sd_input_state, command.buffer, sd_count)) { // M808 L saves the sdpos of the next line. M808 loops to a new sdpos. - TERN_(GCODE_REPEAT_MARKERS, repeat.early_parse_M808(command_buffer[index_w])); + TERN_(GCODE_REPEAT_MARKERS, repeat.early_parse_M808(command.buffer)); // Put the new command into the buffer (no "ok" sent) - _commit_command(false); + ring_buffer.commit_command(true); - // Prime Power-Loss Recovery for the NEXT _commit_command + // Prime Power-Loss Recovery for the NEXT commit_command TERN_(POWER_LOSS_RECOVERY, recovery.cmd_sdpos = card.getIndex()); } if (card.eof()) card.fileHasFinished(); // Handle end of file reached } else - process_stream_char(sd_char, sd_input_state, command_buffer[index_w], sd_count); + process_stream_char(sd_char, sd_input_state, command.buffer, sd_count); } } @@ -636,6 +603,7 @@ void GCodeQueue::get_serial_commands() { * - The SD card file being actively printed */ void GCodeQueue::get_available_commands() { + if (ring_buffer.full()) return; get_serial_commands(); @@ -651,13 +619,13 @@ void GCodeQueue::advance() { if (process_injected_command_P() || process_injected_command()) return; // Return if the G-code buffer is empty - if (!length) return; + if (ring_buffer.empty()) return; #if ENABLED(SDSUPPORT) if (card.flag.saving) { - char* command = command_buffer[index_r]; - if (is_M29(command)) { + char * const cmd = ring_buffer.peek_next_command_string(); + if (is_M29(cmd)) { // M29 closes the file card.closefile(); SERIAL_ECHOLNPGM(STR_FILE_SAVED); @@ -675,7 +643,7 @@ void GCodeQueue::advance() { } else { // Write the string from the read buffer to SD - card.write_command(command); + card.write_command(cmd); if (card.flag.logging) gcode.process_next_command(); // The card is saving because it's logging else @@ -692,7 +660,5 @@ void GCodeQueue::advance() { #endif // SDSUPPORT // The queue may be reset by a command handler or by code invoked by idle() within a handler - --length; - if (++index_r >= BUFSIZE) index_r = 0; - + ring_buffer.advance_pos(ring_buffer.index_r, -1); } diff --git a/Marlin/src/gcode/queue.h b/Marlin/src/gcode/queue.h index d677146a7dbe..7bc3bfdbe5ae 100644 --- a/Marlin/src/gcode/queue.h +++ b/Marlin/src/gcode/queue.h @@ -31,41 +31,84 @@ class GCodeQueue { public: /** - * GCode line number handling. Hosts may include line numbers when sending - * commands to Marlin, and lines will be checked for sequentiality. - * M110 N sets the current line number. + * The buffers per serial port. */ + struct SerialState { + /** + * GCode line number handling. Hosts may include line numbers when sending + * commands to Marlin, and lines will be checked for sequentiality. + * M110 N sets the current line number. + */ + long last_N; + int count; //!< Number of characters read in the current line of serial input + char line_buffer[MAX_CMD_SIZE]; //!< The current line accumulator + uint8_t input_state; //!< The input state + }; - static long last_N[NUM_SERIAL]; + static SerialState serial_state[NUM_SERIAL]; //!< Serial states for each serial port /** * GCode Command Queue - * A simple ring buffer of BUFSIZE command strings. + * A simple (circular) ring buffer of BUFSIZE command strings. * * Commands are copied into this buffer by the command injectors * (immediate, serial, sd card) and they are processed sequentially by * the main loop. The gcode.process_next_command method parses the next * command and hands off execution to individual handler functions. */ - static uint8_t length, // Count of commands in the queue - index_r; // Ring buffer read position - - static char command_buffer[BUFSIZE][MAX_CMD_SIZE]; + struct CommandLine { + char buffer[MAX_CMD_SIZE]; //!< The command buffer + bool skip_ok; //!< Skip sending ok when command is processed? + TERN_(HAS_MULTI_SERIAL, serial_index_t port); //!< Serial port the command was received on + }; /** - * The port that the command was received on + * A handy ring buffer type */ - #if HAS_MULTI_SERIAL - static serial_index_t port[BUFSIZE]; - #endif - static inline serial_index_t command_port() { return TERN0(HAS_MULTI_SERIAL, port[index_r]); } + struct RingBuffer { + uint8_t length, //!< Number of commands in the queue + index_r, //!< Ring buffer's read position + index_w; //!< Ring buffer's write position + CommandLine commands[BUFSIZE]; //!< The ring buffer of commands + + inline serial_index_t command_port() const { return TERN0(HAS_MULTI_SERIAL, commands[index_r].port); } + + inline void clear() { length = index_r = index_w = 0; } + + void advance_pos(uint8_t &p, const int inc) { if (++p >= BUFSIZE) p = 0; length += inc; } + + void commit_command(bool skip_ok + #if HAS_MULTI_SERIAL + , serial_index_t serial_ind=-1 + #endif + ); + + bool enqueue(const char* cmd, bool skip_ok = true + #if HAS_MULTI_SERIAL + , serial_index_t serial_ind=-1 + #endif + ); + + void ok_to_send(); + + inline bool full(uint8_t cmdCount=1) const { return length > (BUFSIZE - cmdCount); } + + inline bool empty() const { return length == 0; } - GCodeQueue(); + inline CommandLine& peek_next_command() { return commands[index_r]; } + + inline char* peek_next_command_string() { return peek_next_command().buffer; } + }; + + /** + * The ring buffer of commands + */ + static RingBuffer ring_buffer; /** * Clear the Marlin command queue */ - static void clear(); + static void clear() { ring_buffer.clear(); } /** * Next Injected Command (PROGMEM) pointer. (nullptr == empty) @@ -112,7 +155,7 @@ class GCodeQueue { /** * Check whether there are any commands yet to be executed */ - static bool has_commands_queued(); + static bool has_commands_queued() { return ring_buffer.length || injected_commands_P || injected_commands[0]; } /** * Get the next command in the queue, optionally log it to SD, then dispatch it @@ -136,17 +179,20 @@ class GCodeQueue { * P Planner space remaining * B Block queue space remaining */ - static void ok_to_send(); + static inline void ok_to_send() { ring_buffer.ok_to_send(); } /** * Clear the serial line and request a resend of * the next expected line number. */ - static void flush_and_request_resend(); + static void flush_and_request_resend(const serial_index_t serial_ind); -private: + /** + * (Re)Set the current line number for the last received command + */ + static inline void set_current_line_number(long n) { serial_state[ring_buffer.command_port()].last_N = n; } - static uint8_t index_w; // Ring buffer write position +private: static void get_serial_commands(); @@ -154,18 +200,6 @@ class GCodeQueue { static void get_sdcard_commands(); #endif - static void _commit_command(bool say_ok - #if HAS_MULTI_SERIAL - , serial_index_t serial_ind=-1 - #endif - ); - - static bool _enqueue(const char* cmd, bool say_ok=false - #if HAS_MULTI_SERIAL - , serial_index_t serial_ind=-1 - #endif - ); - // Process the next "immediate" command (PROGMEM) static bool process_injected_command_P(); @@ -180,6 +214,7 @@ class GCodeQueue { static void gcode_line_error(PGM_P const err, const serial_index_t serial_ind); + friend class GcodeSuite; }; extern GCodeQueue queue; diff --git a/Marlin/src/gcode/scara/M360-M364.cpp b/Marlin/src/gcode/scara/M360-M364.cpp index 562beee4f98e..f32fa09de071 100644 --- a/Marlin/src/gcode/scara/M360-M364.cpp +++ b/Marlin/src/gcode/scara/M360-M364.cpp @@ -31,7 +31,7 @@ inline bool SCARA_move_to_cal(const uint8_t delta_a, const uint8_t delta_b) { if (IsRunning()) { - forward_kinematics_SCARA(delta_a, delta_b); + forward_kinematics(delta_a, delta_b); do_blocking_move_to_xy(cartes); return true; } diff --git a/Marlin/src/gcode/sd/M24_M25.cpp b/Marlin/src/gcode/sd/M24_M25.cpp index 611ba17c55bc..8fb529dcaaba 100644 --- a/Marlin/src/gcode/sd/M24_M25.cpp +++ b/Marlin/src/gcode/sd/M24_M25.cpp @@ -41,6 +41,10 @@ #include "../../feature/powerloss.h" #endif +#if ENABLED(DGUS_LCD_UI_MKS) + #include "../../lcd/extui/lib/dgus/DGUSDisplayDef.h" +#endif + #include "../../MarlinCore.h" // for startOrResumeJob /** @@ -48,6 +52,11 @@ */ void GcodeSuite::M24() { + #if ENABLED(DGUS_LCD_UI_MKS) + if ((print_job_timer.isPaused() || print_job_timer.isRunning()) && !parser.seen("ST")) + MKS_resume_print_move(); + #endif + #if ENABLED(POWER_LOSS_RECOVERY) if (parser.seenval('S')) card.setIndex(parser.value_long()); if (parser.seenval('T')) print_job_timer.resume(parser.value_long()); @@ -98,9 +107,9 @@ void GcodeSuite::M25() { print_job_timer.pause(); - #if DISABLED(DWIN_CREALITY_LCD) - ui.reset_status(); - #endif + TERN_(DGUS_LCD_UI_MKS, MKS_pause_print_move()); + + IF_DISABLED(DWIN_CREALITY_LCD, ui.reset_status()); #if ENABLED(HOST_ACTION_COMMANDS) TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_PAUSE_RESUME, PSTR("Pause SD"), PSTR("Resume"))); diff --git a/Marlin/src/gcode/sd/M28_M29.cpp b/Marlin/src/gcode/sd/M28_M29.cpp index 6f3f2450a195..f34edb6f7c7a 100644 --- a/Marlin/src/gcode/sd/M28_M29.cpp +++ b/Marlin/src/gcode/sd/M28_M29.cpp @@ -49,7 +49,7 @@ void GcodeSuite::M28() { // Binary transfer mode if ((card.flag.binary_mode = binary_mode)) { SERIAL_ECHO_MSG("Switching to Binary Protocol"); - TERN_(HAS_MULTI_SERIAL, card.transfer_port_index = queue.port[queue.index_r]); + TERN_(HAS_MULTI_SERIAL, card.transfer_port_index = queue.ring_buffer.command_port()); } else card.openFileWrite(p); diff --git a/Marlin/src/gcode/temp/M106_M107.cpp b/Marlin/src/gcode/temp/M106_M107.cpp index 9c70f1ebc782..b7d64c99ea3e 100644 --- a/Marlin/src/gcode/temp/M106_M107.cpp +++ b/Marlin/src/gcode/temp/M106_M107.cpp @@ -81,6 +81,9 @@ void GcodeSuite::M106() { // Set speed, with constraint thermalManager.set_fan_speed(pfan, speed); + + if (TERN0(DUAL_X_CARRIAGE, idex_is_duplicating())) // pfan == 0 when duplicating + thermalManager.set_fan_speed(1 - pfan, speed); } } @@ -88,8 +91,13 @@ void GcodeSuite::M106() { * M107: Fan Off */ void GcodeSuite::M107() { - const uint8_t p = parser.byteval('P', _ALT_P); - thermalManager.set_fan_speed(p, 0); + const uint8_t pfan = parser.byteval('P', _ALT_P); + if (pfan < _CNT_P) { + thermalManager.set_fan_speed(pfan, 0); + + if (TERN0(DUAL_X_CARRIAGE, idex_is_duplicating())) // pfan == 0 when duplicating + thermalManager.set_fan_speed(1 - pfan, 0); + } } #endif // HAS_FAN diff --git a/Marlin/src/gcode/temp/M303.cpp b/Marlin/src/gcode/temp/M303.cpp index a066ddc88df5..159a52bf2626 100644 --- a/Marlin/src/gcode/temp/M303.cpp +++ b/Marlin/src/gcode/temp/M303.cpp @@ -40,19 +40,15 @@ * C Number of times to repeat the procedure. (Minimum: 3, Default: 5) * U Flag to apply the result to the current PID values * - * With PID_DEBUG: + * With PID_DEBUG, PID_BED_DEBUG, or PID_CHAMBER_DEBUG: * D Toggle PID debugging and EXIT without further action. */ -#if ENABLED(PID_DEBUG) - bool pid_debug_flag = 0; -#endif - void GcodeSuite::M303() { - #if ENABLED(PID_DEBUG) + #if ANY(PID_DEBUG, PID_BED_DEBUG, PID_CHAMBER_DEBUG) if (parser.seen('D')) { - pid_debug_flag = !pid_debug_flag; + thermalManager.pid_debug_flag ^= true; SERIAL_ECHO_START(); SERIAL_ECHOPGM("PID Debug "); serialprintln_onoff(pid_debug_flag); @@ -60,25 +56,34 @@ void GcodeSuite::M303() { } #endif - #define SI TERN(PIDTEMPBED, H_BED, H_E0) - #define EI TERN(PIDTEMP, HOTENDS - 1, H_BED) - const heater_id_t e = (heater_id_t)parser.intval('E'); - if (!WITHIN(e, SI, EI)) { - SERIAL_ECHOLNPGM(STR_PID_BAD_EXTRUDER_NUM); - TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_EXTRUDER_NUM)); - return; + const heater_id_t hid = (heater_id_t)parser.intval('E'); + int16_t default_temp; + switch (hid) { + #if ENABLED(PIDTEMP) + case 0 ... HOTENDS - 1: default_temp = PREHEAT_1_TEMP_HOTEND; break; + #endif + #if ENABLED(PIDTEMPBED) + case H_BED: default_temp = PREHEAT_1_TEMP_BED; break; + #endif + #if ENABLED(PIDTEMPCHAMBER) + case H_CHAMBER: default_temp = PREHEAT_1_TEMP_CHAMBER; break; + #endif + default: + SERIAL_ECHOLNPGM(STR_PID_BAD_HEATER_ID); + TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_BAD_EXTRUDER_NUM)); + return; } + const int16_t temp = parser.celsiusval('S', default_temp); const int c = parser.intval('C', 5); const bool u = parser.boolval('U'); - const int16_t temp = parser.celsiusval('S', e < 0 ? PREHEAT_1_TEMP_BED : PREHEAT_1_TEMP_HOTEND); #if DISABLED(BUSY_WHILE_HEATING) KEEPALIVE_STATE(NOT_BUSY); #endif LCD_MESSAGEPGM(MSG_PID_AUTOTUNE); - thermalManager.PID_autotune(temp, e, c, u); + thermalManager.PID_autotune(temp, hid, c, u); ui.reset_status(); } diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 712ed39cf141..e5f7441e77de 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -50,6 +50,10 @@ #define MINIPANEL +#elif ENABLED(YHCB2004) + + #define IS_ULTIPANEL 1 + #elif ENABLED(CARTESIO_UI) #define DOGLCD @@ -447,7 +451,7 @@ #endif // Aliases for LCD features -#if ANY(DGUS_LCD_UI_ORIGIN, DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_HIPRECY) +#if ANY(DGUS_LCD_UI_ORIGIN, DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_HIPRECY,DGUS_LCD_UI_MKS) #define HAS_DGUS_LCD 1 #endif @@ -509,7 +513,7 @@ #define HAS_PRUSA_MMU2 1 #define HAS_PRUSA_MMU2S 1 #endif - #if MMU_MODEL >= SMUFF_EMU_MMU2 + #if MMU_MODEL == SMUFF_EMU_MMU2 || MMU_MODEL == SMUFF_EMU_MMU2S #define HAS_SMUFF 1 #endif #endif @@ -571,7 +575,7 @@ #undef DISABLE_INACTIVE_EXTRUDER #endif -// Průša MMU1, MMU 2.0, MMUS 2.0 and SMUFF force SINGLENOZZLE +// Průša MMU1, MMU 2.0, MMUS 2.0 and SMuFF force SINGLENOZZLE #if HAS_MMU #define SINGLENOZZLE #endif @@ -818,22 +822,6 @@ #define TOTAL_PROBING MULTIPLE_PROBING #endif #endif - #if ENABLED(PREHEAT_BEFORE_PROBING) - #ifndef PROBING_NOZZLE_TEMP - #define PROBING_NOZZLE_TEMP 0 - #endif - #ifndef PROBING_BED_TEMP - #define PROBING_BED_TEMP 0 - #endif - #endif - #if ENABLED(PREHEAT_BEFORE_LEVELING) - #ifndef LEVELING_NOZZLE_TEMP - #define LEVELING_NOZZLE_TEMP 0 - #endif - #ifndef LEVELING_BED_TEMP - #define LEVELING_BED_TEMP 0 - #endif - #endif #else // Clear probe pin settings when no probe is selected #undef Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN @@ -936,7 +924,7 @@ #define NORMAL_AXIS Z_AXIS #endif -#if ENABLED(MORGAN_SCARA) +#if EITHER(MORGAN_SCARA, AXEL_TPARA) #define IS_SCARA 1 #define IS_KINEMATIC 1 #elif ENABLED(DELTA) @@ -1207,3 +1195,10 @@ #define TOUCH_ORIENTATION TOUCH_LANDSCAPE #endif #endif + +#if ANY(USE_XMIN_PLUG, USE_YMIN_PLUG, USE_ZMIN_PLUG, USE_XMAX_PLUG, USE_YMAX_PLUG, USE_ZMAX_PLUG) + #define HAS_ENDSTOPS 1 + #define COORDINATE_OKAY(N,L,H) WITHIN(N,L,H) +#else + #define COORDINATE_OKAY(N,L,H) true +#endif diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index c2ba04f0bc9e..43f20b6dfda7 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -128,9 +128,15 @@ #if ENABLED(FILAMENT_RUNOUT_SENSOR) #define HAS_FILAMENT_SENSOR 1 + #if NUM_RUNOUT_SENSORS > 1 + #define MULTI_FILAMENT_SENSOR 1 + #endif #ifdef FILAMENT_RUNOUT_DISTANCE_MM #define HAS_FILAMENT_RUNOUT_DISTANCE 1 #endif + #if ENABLED(MIXING_EXTRUDER) + #define WATCH_ALL_RUNOUT_SENSORS + #endif #endif // Let SD_FINISHED_RELEASECOMMAND stand in for SD_FINISHED_STEPPERRELEASE @@ -506,6 +512,15 @@ #define NEED_HEX_PRINT 1 #endif +// Flags for Case Light having a color property or a single pin +#if ENABLED(CASE_LIGHT_ENABLE) + #if EITHER(CASE_LIGHT_USE_NEOPIXEL, CASE_LIGHT_USE_RGB_LED) + #define CASE_LIGHT_IS_COLOR_LED 1 + #else + #define NEED_CASE_LIGHT_PIN 1 + #endif +#endif + // Flag whether least_squares_fit.cpp is used #if ANY(AUTO_BED_LEVELING_UBL, AUTO_BED_LEVELING_LINEAR, Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS) #define NEED_LSF 1 diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 949885eab7ec..be04341200e3 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -143,7 +143,9 @@ */ #if IS_SCARA #undef SLOWDOWN - #define QUICK_HOME + #if DISABLED(AXEL_TPARA) + #define QUICK_HOME + #endif #define SCARA_PRINTABLE_RADIUS (SCARA_LINKAGE_1 + SCARA_LINKAGE_2) #endif @@ -1992,27 +1994,31 @@ #define BED_OVERSHOOT 10 #endif #define BED_MAX_TARGET (BED_MAXTEMP - (BED_OVERSHOOT)) +#else + #undef PIDTEMPBED #endif + #if HAS_HEATED_BED || HAS_TEMP_CHAMBER #define BED_OR_CHAMBER 1 #endif #if HAS_TEMP_HOTEND || BED_OR_CHAMBER || HAS_TEMP_PROBE #define HAS_TEMP_SENSOR 1 #endif + #if HAS_TEMP_CHAMBER && PIN_EXISTS(HEATER_CHAMBER) #define HAS_HEATED_CHAMBER 1 + #ifndef CHAMBER_OVERSHOOT + #define CHAMBER_OVERSHOOT 10 + #endif + #define CHAMBER_MAX_TARGET (CHAMBER_MAXTEMP - (CHAMBER_OVERSHOOT)) +#else + #undef PIDTEMPCHAMBER #endif // PID heating -#if !HAS_HEATED_BED - #undef PIDTEMPBED -#endif -#if EITHER(PIDTEMP, PIDTEMPBED) +#if ANY(PIDTEMP, PIDTEMPBED, PIDTEMPCHAMBER) #define HAS_PID_HEATING 1 #endif -#if BOTH(PIDTEMP, PIDTEMPBED) - #define HAS_PID_FOR_BOTH 1 -#endif // Thermal protection #if BOTH(HAS_HEATED_BED, THERMAL_PROTECTION_BED) @@ -2346,6 +2352,9 @@ * Heated chamber requires settings */ #if HAS_HEATED_CHAMBER + #ifndef MIN_CHAMBER_POWER + #define MIN_CHAMBER_POWER 0 + #endif #ifndef MAX_CHAMBER_POWER #define MAX_CHAMBER_POWER 255 #endif @@ -2373,6 +2382,10 @@ #endif #endif +#if !PREHEAT_COUNT + #undef PREHEAT_SHORTCUT_MENU_ITEM +#endif + /** * Up to 3 PWM fans */ @@ -2468,8 +2481,8 @@ #ifndef Z_PROBE_OFFSET_RANGE_MAX #define Z_PROBE_OFFSET_RANGE_MAX 20 #endif - #ifndef XY_PROBE_SPEED - #define XY_PROBE_SPEED ((homing_feedrate_mm_m.x + homing_feedrate_mm_m.y) / 2) + #ifndef XY_PROBE_FEEDRATE + #define XY_PROBE_FEEDRATE ((homing_feedrate_mm_m.x + homing_feedrate_mm_m.y) / 2) #endif #ifndef NOZZLE_TO_PROBE_OFFSET #define NOZZLE_TO_PROBE_OFFSET { 0, 0, 0 } @@ -2758,7 +2771,7 @@ // Add commands that need sub-codes to this list #if ANY(G38_PROBE_TARGET, CNC_COORDINATE_SYSTEMS, POWER_LOSS_RECOVERY) - #define USE_GCODE_SUBCODES + #define USE_GCODE_SUBCODES 1 #endif // Parking Extruder diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 2ff5293de21f..4da25d091686 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -131,7 +131,13 @@ #elif defined(DEFAULT_XYJERK) #error "DEFAULT_XYJERK is deprecated. Use DEFAULT_XJERK and DEFAULT_YJERK instead." #elif defined(XY_TRAVEL_SPEED) - #error "XY_TRAVEL_SPEED is deprecated. Use XY_PROBE_SPEED instead." + #error "XY_TRAVEL_SPEED is now XY_PROBE_FEEDRATE." +#elif defined(XY_PROBE_SPEED) + #error "XY_PROBE_SPEED is now XY_PROBE_FEEDRATE." +#elif defined(Z_PROBE_SPEED_FAST) + #error "Z_PROBE_SPEED_FAST is now Z_PROBE_FEEDRATE_FAST." +#elif defined(Z_PROBE_SPEED_SLOW) + #error "Z_PROBE_SPEED_SLOW is now Z_PROBE_FEEDRATE_SLOW." #elif defined(PROBE_SERVO_DEACTIVATION_DELAY) #error "PROBE_SERVO_DEACTIVATION_DELAY is deprecated. Use DEACTIVATE_SERVOS_AFTER_MOVE instead." #elif defined(SERVO_DEACTIVATION_DELAY) @@ -431,6 +437,8 @@ #error "DUAL_NOZZLE_DUPLICATION_MODE is now MULTI_NOZZLE_DUPLICATION." #elif defined(MENU_ITEM_CASE_LIGHT) #error "MENU_ITEM_CASE_LIGHT is now CASE_LIGHT_MENU." +#elif defined(CASE_LIGHT_NEOPIXEL_COLOR) + #error "CASE_LIGHT_NEOPIXEL_COLOR is now CASE_LIGHT_DEFAULT_COLOR." #elif defined(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) #error "ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED is now SD_ABORT_ON_ENDSTOP_HIT." #elif defined(LPC_SD_LCD) || defined(LPC_SD_ONBOARD) || defined(LPC_SD_CUSTOM_CABLE) @@ -539,6 +547,10 @@ #endif #elif defined(ASSISTED_TRAMMING_MENU_ITEM) #error "ASSISTED_TRAMMING_MENU_ITEM is deprecated and should be removed." +#elif defined(UNKNOWN_Z_NO_RAISE) + #error "UNKNOWN_Z_NO_RAISE is replaced by setting Z_IDLE_HEIGHT to Z_MAX_POS." +#elif defined(Z_AFTER_DEACTIVATE) + #error "Z_AFTER_DEACTIVATE is replaced by Z_IDLE_HEIGHT." #endif /** @@ -811,26 +823,24 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #if HAS_FILAMENT_SENSOR #if !PIN_EXISTS(FIL_RUNOUT) #error "FILAMENT_RUNOUT_SENSOR requires FIL_RUNOUT_PIN." - #elif NUM_RUNOUT_SENSORS > E_STEPPERS - #if HAS_PRUSA_MMU2 + #elif HAS_PRUSA_MMU2 && NUM_RUNOUT_SENSORS != 1 #error "NUM_RUNOUT_SENSORS must be 1 with MMU2 / MMU2S." - #else - #error "NUM_RUNOUT_SENSORS cannot exceed the number of E steppers." - #endif - #elif NUM_RUNOUT_SENSORS >= 2 && !PIN_EXISTS(FIL_RUNOUT2) - #error "FIL_RUNOUT2_PIN is required with NUM_RUNOUT_SENSORS >= 2." - #elif NUM_RUNOUT_SENSORS >= 3 && !PIN_EXISTS(FIL_RUNOUT3) - #error "FIL_RUNOUT3_PIN is required with NUM_RUNOUT_SENSORS >= 3." - #elif NUM_RUNOUT_SENSORS >= 4 && !PIN_EXISTS(FIL_RUNOUT4) - #error "FIL_RUNOUT4_PIN is required with NUM_RUNOUT_SENSORS >= 4." - #elif NUM_RUNOUT_SENSORS >= 5 && !PIN_EXISTS(FIL_RUNOUT5) - #error "FIL_RUNOUT5_PIN is required with NUM_RUNOUT_SENSORS >= 5." - #elif NUM_RUNOUT_SENSORS >= 6 && !PIN_EXISTS(FIL_RUNOUT6) - #error "FIL_RUNOUT6_PIN is required with NUM_RUNOUT_SENSORS >= 6." - #elif NUM_RUNOUT_SENSORS >= 7 && !PIN_EXISTS(FIL_RUNOUT7) - #error "FIL_RUNOUT7_PIN is required with NUM_RUNOUT_SENSORS >= 7." + #elif NUM_RUNOUT_SENSORS != 1 && NUM_RUNOUT_SENSORS != E_STEPPERS + #error "NUM_RUNOUT_SENSORS must be either 1 or number of E steppers." #elif NUM_RUNOUT_SENSORS >= 8 && !PIN_EXISTS(FIL_RUNOUT8) #error "FIL_RUNOUT8_PIN is required with NUM_RUNOUT_SENSORS >= 8." + #elif NUM_RUNOUT_SENSORS >= 7 && !PIN_EXISTS(FIL_RUNOUT7) + #error "FIL_RUNOUT7_PIN is required with NUM_RUNOUT_SENSORS >= 7." + #elif NUM_RUNOUT_SENSORS >= 6 && !PIN_EXISTS(FIL_RUNOUT6) + #error "FIL_RUNOUT6_PIN is required with NUM_RUNOUT_SENSORS >= 6." + #elif NUM_RUNOUT_SENSORS >= 5 && !PIN_EXISTS(FIL_RUNOUT5) + #error "FIL_RUNOUT5_PIN is required with NUM_RUNOUT_SENSORS >= 5." + #elif NUM_RUNOUT_SENSORS >= 4 && !PIN_EXISTS(FIL_RUNOUT4) + #error "FIL_RUNOUT4_PIN is required with NUM_RUNOUT_SENSORS >= 4." + #elif NUM_RUNOUT_SENSORS >= 3 && !PIN_EXISTS(FIL_RUNOUT3) + #error "FIL_RUNOUT3_PIN is required with NUM_RUNOUT_SENSORS >= 3." + #elif NUM_RUNOUT_SENSORS >= 2 && !PIN_EXISTS(FIL_RUNOUT2) + #error "FIL_RUNOUT2_PIN is required with NUM_RUNOUT_SENSORS >= 2." #elif BOTH(FIL_RUNOUT1_PULLUP, FIL_RUNOUT1_PULLDOWN) #error "You can't enable FIL_RUNOUT1_PULLUP and FIL_RUNOUT1_PULLDOWN at the same time." #elif BOTH(FIL_RUNOUT2_PULLUP, FIL_RUNOUT2_PULLDOWN) @@ -909,7 +919,7 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #endif /** - * Multi-Material-Unit 2 / SMUFF requirements + * Multi-Material-Unit 2 / SMuFF requirements */ #if HAS_PRUSA_MMU2 #if EXTRUDERS != 5 @@ -1203,6 +1213,13 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #error "To use BED_LIMIT_SWITCHING you must disable PIDTEMPBED." #endif +/** + * Chamber Heating Options - PID vs Limit Switching + */ +#if BOTH(PIDTEMPCHAMBER, CHAMBER_LIMIT_SWITCHING) + #error "To use CHAMBER_LIMIT_SWITCHING you must disable PIDTEMPCHAMBER." +#endif + /** * Kinematics */ @@ -1210,8 +1227,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS /** * Allow only one kinematic type to be defined */ -#if MANY(DELTA, MORGAN_SCARA, COREXY, COREXZ, COREYZ, COREYX, COREZX, COREZY, MARKFORGED_XY) - #error "Please enable only one of DELTA, MORGAN_SCARA, COREXY, COREYX, COREXZ, COREZX, COREYZ, COREZY, or MARKFORGED_XY." +#if MANY(DELTA, MORGAN_SCARA, AXEL_TPARA, COREXY, COREXZ, COREYZ, COREYX, COREZX, COREZY, MARKFORGED_XY) + #error "Please enable only one of DELTA, MORGAN_SCARA, AXEL_TPARA, COREXY, COREYX, COREXZ, COREZX, COREYZ, COREZY, or MARKFORGED_XY." #endif /** @@ -1624,7 +1641,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal * Allen Key * Deploying the Allen Key probe uses big moves in z direction. Too dangerous for an unhomed z-axis. */ -#if BOTH(Z_PROBE_ALLEN_KEY, Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) && (Z_HOME_DIR < 0) +#if BOTH(Z_PROBE_ALLEN_KEY, Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) && Z_HOME_DIR < 0 #error "You can't home to a Z min endstop with a Z_PROBE_ALLEN_KEY." #endif @@ -1687,9 +1704,9 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal /** * Case Light requirements */ -#if ENABLED(CASE_LIGHT_ENABLE) +#if NEED_CASE_LIGHT_PIN #if !PIN_EXISTS(CASE_LIGHT) - #error "CASE_LIGHT_ENABLE requires CASE_LIGHT_PIN to be defined." + #error "CASE_LIGHT_ENABLE requires CASE_LIGHT_PIN, CASE_LIGHT_USE_NEOPIXEL, or CASE_LIGHT_USE_RGB_LED." #elif CASE_LIGHT_PIN == FAN_PIN #error "CASE_LIGHT_PIN conflicts with FAN_PIN. Resolve before continuing." #endif @@ -2009,39 +2026,41 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal && !(ENABLED(A##_MULTI_ENDSTOPS) && WITHIN(A##2_USE_ENDSTOP, _##P##MAX_, _##P##MIN_)) ) #define _AXIS_PLUG_UNUSED_TEST(A) (_PLUG_UNUSED_TEST(A,X) && _PLUG_UNUSED_TEST(A,Y) && _PLUG_UNUSED_TEST(A,Z)) -// At least 3 endstop plugs must be used -#if _AXIS_PLUG_UNUSED_TEST(X) - #error "You must enable USE_XMIN_PLUG or USE_XMAX_PLUG." -#endif -#if _AXIS_PLUG_UNUSED_TEST(Y) - #error "You must enable USE_YMIN_PLUG or USE_YMAX_PLUG." -#endif -#if _AXIS_PLUG_UNUSED_TEST(Z) - #error "You must enable USE_ZMIN_PLUG or USE_ZMAX_PLUG." -#endif +// A machine with endstops must have a minimum of 3 +#if HAS_ENDSTOPS + #if _AXIS_PLUG_UNUSED_TEST(X) + #error "You must enable USE_XMIN_PLUG or USE_XMAX_PLUG." + #endif + #if _AXIS_PLUG_UNUSED_TEST(Y) + #error "You must enable USE_YMIN_PLUG or USE_YMAX_PLUG." + #endif + #if _AXIS_PLUG_UNUSED_TEST(Z) + #error "You must enable USE_ZMIN_PLUG or USE_ZMAX_PLUG." + #endif -// Delta and Cartesian use 3 homing endstops -#if NONE(IS_SCARA, SPI_ENDSTOPS) - #if X_HOME_DIR < 0 && DISABLED(USE_XMIN_PLUG) - #error "Enable USE_XMIN_PLUG when homing X to MIN." - #elif X_HOME_DIR > 0 && DISABLED(USE_XMAX_PLUG) - #error "Enable USE_XMAX_PLUG when homing X to MAX." - #elif Y_HOME_DIR < 0 && DISABLED(USE_YMIN_PLUG) - #error "Enable USE_YMIN_PLUG when homing Y to MIN." - #elif Y_HOME_DIR > 0 && DISABLED(USE_YMAX_PLUG) - #error "Enable USE_YMAX_PLUG when homing Y to MAX." + // Delta and Cartesian use 3 homing endstops + #if NONE(IS_SCARA, SPI_ENDSTOPS) + #if X_HOME_DIR < 0 && DISABLED(USE_XMIN_PLUG) + #error "Enable USE_XMIN_PLUG when homing X to MIN." + #elif X_HOME_DIR > 0 && DISABLED(USE_XMAX_PLUG) + #error "Enable USE_XMAX_PLUG when homing X to MAX." + #elif Y_HOME_DIR < 0 && DISABLED(USE_YMIN_PLUG) + #error "Enable USE_YMIN_PLUG when homing Y to MIN." + #elif Y_HOME_DIR > 0 && DISABLED(USE_YMAX_PLUG) + #error "Enable USE_YMAX_PLUG when homing Y to MAX." + #endif #endif -#endif -// Z homing direction and plug usage flags -#if Z_HOME_DIR < 0 && NONE(USE_ZMIN_PLUG, HOMING_Z_WITH_PROBE) - #error "Enable USE_ZMIN_PLUG when homing Z to MIN." -#elif Z_HOME_DIR > 0 && ENABLED(USE_PROBE_FOR_Z_HOMING) - #error "Z_HOME_DIR must be -1 when homing Z with the probe." -#elif BOTH(HOMING_Z_WITH_PROBE, Z_MULTI_ENDSTOPS) - #error "Z_MULTI_ENDSTOPS is incompatible with USE_PROBE_FOR_Z_HOMING." -#elif Z_HOME_DIR > 0 && DISABLED(USE_ZMAX_PLUG) - #error "Enable USE_ZMAX_PLUG when homing Z to MAX." + // Z homing direction and plug usage flags + #if Z_HOME_DIR < 0 && NONE(USE_ZMIN_PLUG, HOMING_Z_WITH_PROBE) + #error "Enable USE_ZMIN_PLUG when homing Z to MIN." + #elif Z_HOME_DIR > 0 && ENABLED(USE_PROBE_FOR_Z_HOMING) + #error "Z_HOME_DIR must be -1 when homing Z with the probe." + #elif BOTH(HOMING_Z_WITH_PROBE, Z_MULTI_ENDSTOPS) + #error "Z_MULTI_ENDSTOPS is incompatible with USE_PROBE_FOR_Z_HOMING." + #elif Z_HOME_DIR > 0 && DISABLED(USE_ZMAX_PLUG) + #error "Enable USE_ZMAX_PLUG when homing Z to MAX." + #endif #endif #if BOTH(HOME_Z_FIRST, USE_PROBE_FOR_Z_HOMING) @@ -2296,8 +2315,6 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal #if 1 < 0 \ + ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) \ + ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) \ - + ENABLED(ULTIPANEL) \ - + ENABLED(ULTRA_LCD) \ + (ENABLED(U8GLIB_SSD1306) && DISABLED(IS_U8GLIB_SSD1306)) \ + (ENABLED(MINIPANEL) && NONE(MKS_MINI_12864, ENDER2_STOCKDISPLAY)) \ + (ENABLED(MKS_MINI_12864) && DISABLED(MKS_LCD12864)) \ @@ -2305,7 +2322,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal + (DISABLED(IS_LEGACY_TFT) && ENABLED(TFT_GENERIC)) \ + (ENABLED(IS_LEGACY_TFT) && COUNT_ENABLED(TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI)) \ + COUNT_ENABLED(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON, ANYCUBIC_TFT35) \ - + COUNT_ENABLED(DGUS_LCD_UI_ORIGIN, DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_HIPRECY) \ + + COUNT_ENABLED(DGUS_LCD_UI_ORIGIN, DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_HIPRECY,DGUS_LCD_UI_MKS) \ + COUNT_ENABLED(ENDER2_STOCKDISPLAY, CR10_STOCKDISPLAY, DWIN_CREALITY_LCD) \ + COUNT_ENABLED(FYSETC_MINI_12864_X_X, FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1, FYSETC_GENERIC_12864_1_1) \ + COUNT_ENABLED(LCD_SAINSMART_I2C_1602, LCD_SAINSMART_I2C_2004) \ @@ -2346,6 +2363,9 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal + ENABLED(U8GLIB_SH1106_EINSTART) \ + ENABLED(ULTI_CONTROLLER) \ + ENABLED(ULTIMAKERCONTROLLER) \ + + ENABLED(ULTIPANEL) \ + + ENABLED(ULTRA_LCD) \ + + ENABLED(YHCB2004) \ + ENABLED(ZONESTAR_LCD) #error "Please select only one LCD controller option." #endif @@ -2893,12 +2913,16 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #endif #endif -#if ENABLED(BACKUP_POWER_SUPPLY) && !PIN_EXISTS(POWER_LOSS) - #error "BACKUP_POWER_SUPPLY requires a POWER_LOSS_PIN." -#endif - -#if BOTH(POWER_LOSS_PULLUP, POWER_LOSS_PULLDOWN) - #error "You can't enable POWER_LOSS_PULLUP and POWER_LOSS_PULLDOWN at the same time." +#if ENABLED(POWER_LOSS_RECOVERY) + #if ENABLED(BACKUP_POWER_SUPPLY) && !PIN_EXISTS(POWER_LOSS) + #error "BACKUP_POWER_SUPPLY requires a POWER_LOSS_PIN." + #elif BOTH(POWER_LOSS_RECOVER_ZHOME, Z_SAFE_HOMING) + #error "POWER_LOSS_RECOVER_ZHOME cannot be used with Z_SAFE_HOMING." + #elif BOTH(POWER_LOSS_PULLUP, POWER_LOSS_PULLDOWN) + #error "You can't enable POWER_LOSS_PULLUP and POWER_LOSS_PULLDOWN at the same time." + #elif BOTH(IS_CARTESIAN, POWER_LOSS_RECOVER_ZHOME) && Z_HOME_DIR < 0 && !defined(POWER_LOSS_ZHOME_POS) + #error "POWER_LOSS_RECOVER_ZHOME requires POWER_LOSS_ZHOME_POS for a Cartesian that homes to ZMIN." + #endif #endif #if ENABLED(Z_STEPPER_AUTO_ALIGN) @@ -3239,6 +3263,12 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2) #undef _PIN_CONFLICT #endif +#if ENABLED(COOLANT_MIST) && !PIN_EXISTS(COOLANT_MIST) + #error "COOLANT_MIST requires COOLANT_MIST_PIN to be defined." +#elif ENABLED(COOLANT_FLOOD) && !PIN_EXISTS(COOLANT_FLOOD) + #error "COOLANT_FLOOD requires COOLANT_FLOOD_PIN to be defined." +#endif + #if NONE(HAS_MARLINUI_U8GLIB, EXTENSIBLE_UI) && ENABLED(PRINT_PROGRESS_SHOW_DECIMALS) #error "PRINT_PROGRESS_SHOW_DECIMALS currently requires a Graphical LCD." #endif diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 0d72d6ebe89e..e57a3485d9c1 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2021-02-11" + #define STRING_DISTRIBUTION_DATE "2021-03-05" #endif /** diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp index 635751b3f5c3..15b3d8bfb321 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.cpp @@ -93,6 +93,10 @@ LCD_CLASS lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); +#elif ENABLED(YHCB2004) + + LCD_CLASS lcd(YHCB2004_CLK, 20, 4, YHCB2004_MOSI, YHCB2004_MISO); // CLK, cols, rows, MOSI, MISO + #else // Standard direct-connected LCD implementations diff --git a/Marlin/src/lcd/HD44780/marlinui_HD44780.h b/Marlin/src/lcd/HD44780/marlinui_HD44780.h index 604d26a029b4..62c0c7620220 100644 --- a/Marlin/src/lcd/HD44780/marlinui_HD44780.h +++ b/Marlin/src/lcd/HD44780/marlinui_HD44780.h @@ -90,6 +90,11 @@ #include #define LCD_CLASS LiquidCrystal_I2C +#elif ENABLED(YHCB2004) + + #include + #define LCD_CLASS LiquidCrystal_AIP31068_SPI + #else // Standard directly connected LCD implementations diff --git a/Marlin/src/lcd/buttons.h b/Marlin/src/lcd/buttons.h index 07a4524def18..f39cb0a9aa03 100644 --- a/Marlin/src/lcd/buttons.h +++ b/Marlin/src/lcd/buttons.h @@ -45,8 +45,37 @@ #define ENCODER_PHASE_3 1 #endif -#if EITHER(HAS_DIGITAL_BUTTONS, DWIN_CREALITY_LCD) +#if IS_RRW_KEYPAD + #define BTN_OFFSET 0 // Bit offset into buttons for shift register values + + #define BLEN_KEYPAD_F3 0 + #define BLEN_KEYPAD_F2 1 + #define BLEN_KEYPAD_F1 2 + #define BLEN_KEYPAD_DOWN 3 + #define BLEN_KEYPAD_RIGHT 4 + #define BLEN_KEYPAD_MIDDLE 5 + #define BLEN_KEYPAD_UP 6 + #define BLEN_KEYPAD_LEFT 7 + #define EN_KEYPAD_F1 _BV(BTN_OFFSET + BLEN_KEYPAD_F1) + #define EN_KEYPAD_F2 _BV(BTN_OFFSET + BLEN_KEYPAD_F2) + #define EN_KEYPAD_F3 _BV(BTN_OFFSET + BLEN_KEYPAD_F3) + #define EN_KEYPAD_DOWN _BV(BTN_OFFSET + BLEN_KEYPAD_DOWN) + #define EN_KEYPAD_RIGHT _BV(BTN_OFFSET + BLEN_KEYPAD_RIGHT) + #define EN_KEYPAD_MIDDLE _BV(BTN_OFFSET + BLEN_KEYPAD_MIDDLE) + #define EN_KEYPAD_UP _BV(BTN_OFFSET + BLEN_KEYPAD_UP) + #define EN_KEYPAD_LEFT _BV(BTN_OFFSET + BLEN_KEYPAD_LEFT) + + #define RRK(B) (keypad_buttons & (B)) + + #ifdef EN_C + #define BUTTON_CLICK() ((buttons & EN_C) || RRK(EN_KEYPAD_MIDDLE)) + #else + #define BUTTON_CLICK() RRK(EN_KEYPAD_MIDDLE) + #endif +#endif + +#if EITHER(HAS_DIGITAL_BUTTONS, DWIN_CREALITY_LCD) // Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes) #define BLEN_A 0 #define BLEN_B 1 @@ -62,9 +91,7 @@ #endif #if ENABLED(LCD_I2C_VIKI) - #include - #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C) // button and encoder bit positions within 'buttons' @@ -84,21 +111,15 @@ // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update #elif ENABLED(LCD_I2C_PANELOLU2) - #if !BUTTON_EXISTS(ENC) // Use I2C if not directly connected to a pin - #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C) #define B_MI (PANELOLU2_ENCODER_C << B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later #define BUTTON_CLICK() (buttons & B_MI) - #endif - #endif - #else - #undef BUTTON_EXISTS #define BUTTON_EXISTS(...) false @@ -122,37 +143,6 @@ #ifndef BUTTON_CLICK #define BUTTON_CLICK() (buttons & (B_MI|B_ST)) #endif - -#endif - -#if IS_RRW_KEYPAD - #define BTN_OFFSET 0 // Bit offset into buttons for shift register values - - #define BLEN_KEYPAD_F3 0 - #define BLEN_KEYPAD_F2 1 - #define BLEN_KEYPAD_F1 2 - #define BLEN_KEYPAD_DOWN 3 - #define BLEN_KEYPAD_RIGHT 4 - #define BLEN_KEYPAD_MIDDLE 5 - #define BLEN_KEYPAD_UP 6 - #define BLEN_KEYPAD_LEFT 7 - - #define EN_KEYPAD_F1 _BV(BTN_OFFSET + BLEN_KEYPAD_F1) - #define EN_KEYPAD_F2 _BV(BTN_OFFSET + BLEN_KEYPAD_F2) - #define EN_KEYPAD_F3 _BV(BTN_OFFSET + BLEN_KEYPAD_F3) - #define EN_KEYPAD_DOWN _BV(BTN_OFFSET + BLEN_KEYPAD_DOWN) - #define EN_KEYPAD_RIGHT _BV(BTN_OFFSET + BLEN_KEYPAD_RIGHT) - #define EN_KEYPAD_MIDDLE _BV(BTN_OFFSET + BLEN_KEYPAD_MIDDLE) - #define EN_KEYPAD_UP _BV(BTN_OFFSET + BLEN_KEYPAD_UP) - #define EN_KEYPAD_LEFT _BV(BTN_OFFSET + BLEN_KEYPAD_LEFT) - - #define RRK(B) (keypad_buttons & (B)) - - #ifdef EN_C - #define BUTTON_CLICK() ((buttons & EN_C) || RRK(EN_KEYPAD_MIDDLE)) - #else - #define BUTTON_CLICK() RRK(EN_KEYPAD_MIDDLE) - #endif #endif #ifndef EN_A diff --git a/Marlin/src/lcd/dogm/marlinui_DOGM.h b/Marlin/src/lcd/dogm/marlinui_DOGM.h index e5229cd08845..e5862d670fb1 100644 --- a/Marlin/src/lcd/dogm/marlinui_DOGM.h +++ b/Marlin/src/lcd/dogm/marlinui_DOGM.h @@ -88,7 +88,8 @@ #define SMART_RAMPS MB(RAMPS_SMART_EFB, RAMPS_SMART_EEB, RAMPS_SMART_EFF, RAMPS_SMART_EEF, RAMPS_SMART_SF) #define U8G_CLASS U8GLIB_64128N_2X_HAL // 4 stripes (HW-SPI) - #if SMART_RAMPS || DOGLCD_SCK != SD_SCK_PIN || DOGLCD_MOSI != SD_MOSI_PIN + + #if (SMART_RAMPS && defined(__SAM3X8E__)) || DOGLCD_SCK != SD_SCK_PIN || DOGLCD_MOSI != SD_MOSI_PIN #define FORCE_SOFT_SPI // SW-SPI #endif diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.cpp b/Marlin/src/lcd/dwin/e3v2/dwin.cpp index 04171b9d798f..e046bb90f558 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.cpp +++ b/Marlin/src/lcd/dwin/e3v2/dwin.cpp @@ -88,16 +88,14 @@ #ifndef MACHINE_SIZE #define MACHINE_SIZE STRINGIFY(X_BED_SIZE) "x" STRINGIFY(Y_BED_SIZE) "x" STRINGIFY(Z_MAX_POS) #endif -#ifndef CORP_WEBSITE_C - #define CORP_WEBSITE_C "www.cxsw3d.com" -#endif -#ifndef CORP_WEBSITE_E - #define CORP_WEBSITE_E "www.creality.com" +#ifndef CORP_WEBSITE + #define CORP_WEBSITE WEBSITE_URL #endif #define PAUSE_HEAT #define USE_STRING_HEADINGS +//#define USE_STRING_TITLES #define DWIN_FONT_MENU font8x16 #define DWIN_FONT_STAT font10x20 @@ -136,9 +134,10 @@ #define UNITFDIGITS 1 #define MINUNITMULT pow(10, UNITFDIGITS) -#define ENCODER_WAIT 20 -#define DWIN_SCROLL_UPDATE_INTERVAL 2000 -#define DWIN_REMAIN_TIME_UPDATE_INTERVAL 20000 +#define ENCODER_WAIT_MS 20 +#define DWIN_VAR_UPDATE_INTERVAL 1024 +#define DWIN_SCROLL_UPDATE_INTERVAL SEC_TO_MS(2) +#define DWIN_REMAIN_TIME_UPDATE_INTERVAL SEC_TO_MS(20) constexpr uint16_t TROWS = 6, MROWS = TROWS - 1, // Total rows, and other-than-Back TITLE_HEIGHT = 30, // Title bar height @@ -400,28 +399,28 @@ void ICON_Stop() { } } -inline void Clear_Title_Bar() { +void Clear_Title_Bar() { DWIN_Draw_Rectangle(1, Color_Bg_Blue, 0, 0, DWIN_WIDTH, 30); } -inline void Draw_Title(const char * const title) { +void Draw_Title(const char * const title) { DWIN_Draw_String(false, false, DWIN_FONT_HEAD, Color_White, Color_Bg_Blue, 14, 4, (char*)title); } -inline void Draw_Title(const __FlashStringHelper * title) { +void Draw_Title(const __FlashStringHelper * title) { DWIN_Draw_String(false, false, DWIN_FONT_HEAD, Color_White, Color_Bg_Blue, 14, 4, (char*)title); } -inline void Clear_Menu_Area() { +void Clear_Menu_Area() { DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, 31, DWIN_WIDTH, STATUS_Y); } -inline void Clear_Main_Window() { +void Clear_Main_Window() { Clear_Title_Bar(); Clear_Menu_Area(); } -inline void Clear_Popup_Area() { +void Clear_Popup_Area() { Clear_Title_Bar(); DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, 31, DWIN_WIDTH, DWIN_HEIGHT); } @@ -430,30 +429,30 @@ void Draw_Popup_Bkgd_105() { DWIN_Draw_Rectangle(1, Color_Bg_Window, 14, 105, 258, 374); } -inline void Draw_More_Icon(const uint8_t line) { +void Draw_More_Icon(const uint8_t line) { DWIN_ICON_Show(ICON, ICON_More, 226, MBASE(line) - 3); } -inline void Draw_Menu_Cursor(const uint8_t line) { +void Draw_Menu_Cursor(const uint8_t line) { // DWIN_ICON_Show(ICON,ICON_Rectangle, 0, MBASE(line) - 18); DWIN_Draw_Rectangle(1, Rectangle_Color, 0, MBASE(line) - 18, 14, MBASE(line + 1) - 20); } -inline void Erase_Menu_Cursor(const uint8_t line) { +void Erase_Menu_Cursor(const uint8_t line) { DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, MBASE(line) - 18, 14, MBASE(line + 1) - 20); } -inline void Move_Highlight(const int16_t from, const uint16_t newline) { +void Move_Highlight(const int16_t from, const uint16_t newline) { Erase_Menu_Cursor(newline - from); Draw_Menu_Cursor(newline); } -inline void Add_Menu_Line() { +void Add_Menu_Line() { Move_Highlight(1, MROWS); DWIN_Draw_Line(Line_Color, 16, MBASE(MROWS + 1) - 20, 256, MBASE(MROWS + 1) - 19); } -inline void Scroll_Menu(const uint8_t dir) { +void Scroll_Menu(const uint8_t dir) { DWIN_Frame_AreaMove(1, dir, MLINE, Color_Bg_Black, 0, 31, DWIN_WIDTH, 349); switch (dir) { case DWIN_SCROLL_DOWN: Move_Highlight(-1, 0); break; @@ -465,22 +464,22 @@ inline uint16_t nr_sd_menu_items() { return card.get_num_Files() + !card.flag.workDirIsRoot; } -inline void Draw_Menu_Icon(const uint8_t line, const uint8_t icon) { +void Draw_Menu_Icon(const uint8_t line, const uint8_t icon) { DWIN_ICON_Show(ICON, icon, 26, MBASE(line) - 3); } -inline void Erase_Menu_Text(const uint8_t line) { +void Erase_Menu_Text(const uint8_t line) { DWIN_Draw_Rectangle(1, Color_Bg_Black, LBLX, MBASE(line) - 14, 271, MBASE(line) + 28); } -inline void Draw_Menu_Line(const uint8_t line, const uint8_t icon=0, const char * const label=nullptr) { +void Draw_Menu_Line(const uint8_t line, const uint8_t icon=0, const char * const label=nullptr) { if (label) DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(line) - 1, (char*)label); if (icon) Draw_Menu_Icon(line, icon); DWIN_Draw_Line(Line_Color, 16, MBASE(line) + 33, 256, MBASE(line) + 34); } // The "Back" label is always on the first line -inline void Draw_Back_Label() { +void Draw_Back_Label() { if (HMI_IsChinese()) DWIN_Frame_AreaCopy(1, 129, 72, 156, 84, LBLX, MBASE(0)); else @@ -488,7 +487,7 @@ inline void Draw_Back_Label() { } // Draw "Back" line at the top -inline void Draw_Back_First(const bool is_sel=true) { +void Draw_Back_First(const bool is_sel=true) { Draw_Menu_Line(0, ICON_Back); Draw_Back_Label(); if (is_sel) Draw_Menu_Cursor(0); @@ -554,40 +553,61 @@ inline bool Apply_Encoder(const ENCODER_DiffState &encoder_diffState, auto &valr // Draw Menus // -inline void draw_move_en(const uint16_t line) { - DWIN_Frame_AreaCopy(1, 69, 61, 102, 71, LBLX, line); // "Move" +void DWIN_Draw_Label(const uint16_t y, char *string) { + DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, y, string); +} +void DWIN_Draw_Label(const uint16_t y, const __FlashStringHelper *title) { + DWIN_Draw_Label(y, (char*)title); +} + +void draw_move_en(const uint16_t line) { + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(line, F("Move")); + #else + DWIN_Frame_AreaCopy(1, 69, 61, 102, 71, LBLX, line); // "Move" + #endif } -inline void DWIN_Frame_TitleCopy(uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { DWIN_Frame_AreaCopy(id, x1, y1, x2, y2, 14, 8); } +void DWIN_Frame_TitleCopy(uint8_t id, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2) { DWIN_Frame_AreaCopy(id, x1, y1, x2, y2, 14, 8); } -inline void Item_Prepare_Move(const uint8_t row) { +void Item_Prepare_Move(const uint8_t row) { if (HMI_IsChinese()) DWIN_Frame_AreaCopy(1, 159, 70, 200, 84, LBLX, MBASE(row)); else - draw_move_en(MBASE(row)); // "Move >" + draw_move_en(MBASE(row)); // "Move" Draw_Menu_Line(row, ICON_Axis); Draw_More_Icon(row); } -inline void Item_Prepare_Disable(const uint8_t row) { +void Item_Prepare_Disable(const uint8_t row) { if (HMI_IsChinese()) DWIN_Frame_AreaCopy(1, 204, 70, 259, 82, LBLX, MBASE(row)); - else - DWIN_Frame_AreaCopy(1, 103, 59, 200, 74, LBLX, MBASE(row)); // "Disable Stepper" + else { + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(row), GET_TEXT_F(MSG_DISABLE_STEPPERS)); + #else + DWIN_Frame_AreaCopy(1, 103, 59, 200, 74, LBLX, MBASE(row)); // "Disable Stepper" + #endif + } Draw_Menu_Line(row, ICON_CloseMotor); } -inline void Item_Prepare_Home(const uint8_t row) { +void Item_Prepare_Home(const uint8_t row) { if (HMI_IsChinese()) DWIN_Frame_AreaCopy(1, 0, 89, 41, 101, LBLX, MBASE(row)); - else - DWIN_Frame_AreaCopy(1, 202, 61, 271, 71, LBLX, MBASE(row)); // "Auto Home" + else { + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(row), GET_TEXT_F(MSG_AUTO_HOME)); + #else + DWIN_Frame_AreaCopy(1, 202, 61, 271, 71, LBLX, MBASE(row)); // "Auto Home" + #endif + } Draw_Menu_Line(row, ICON_Homing); } #if HAS_ZOFFSET_ITEM - inline void Item_Prepare_Offset(const uint8_t row) { + void Item_Prepare_Offset(const uint8_t row) { if (HMI_IsChinese()) { #if HAS_BED_PROBE DWIN_Frame_AreaCopy(1, 174, 164, 223, 177, LBLX, MBASE(row)); @@ -598,10 +618,18 @@ inline void Item_Prepare_Home(const uint8_t row) { } else { #if HAS_BED_PROBE - DWIN_Frame_AreaCopy(1, 93, 179, 141, 189, LBLX, MBASE(row)); // "Z-Offset" + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(row), GET_TEXT_F(MSG_ZPROBE_ZOFFSET)); + #else + DWIN_Frame_AreaCopy(1, 93, 179, 141, 189, LBLX, MBASE(row)); // "Z-Offset" + #endif DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 2, 2, 202, MBASE(row), probe.offset.z * 100); #else - DWIN_Frame_AreaCopy(1, 1, 76, 106, 86, LBLX, MBASE(row)); // "..." + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(row), GET_TEXT_F(MSG_SET_HOME_OFFSETS)); + #else + DWIN_Frame_AreaCopy(1, 1, 76, 106, 86, LBLX, MBASE(row)); // "Set home offsets" + #endif #endif } Draw_Menu_Line(row, ICON_SetHome); @@ -610,52 +638,67 @@ inline void Item_Prepare_Home(const uint8_t row) { #endif #if HAS_HOTEND - inline void Item_Prepare_PLA(const uint8_t row) { + void Item_Prepare_PLA(const uint8_t row) { if (HMI_IsChinese()) { DWIN_Frame_AreaCopy(1, 100, 89, 151, 101, LBLX, MBASE(row)); } else { - DWIN_Frame_AreaCopy(1, 107, 76, 156, 86, LBLX, MBASE(row)); // "Preheat" - DWIN_Frame_AreaCopy(1, 157, 76, 181, 86, LBLX + 52, MBASE(row)); // "PLA" + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(row), F("Preheat " PREHEAT_1_LABEL)); + #else + DWIN_Frame_AreaCopy(1, 107, 76, 156, 86, LBLX, MBASE(row)); // "Preheat" + DWIN_Frame_AreaCopy(1, 157, 76, 181, 86, LBLX + 52, MBASE(row)); // "PLA" + #endif } Draw_Menu_Line(row, ICON_PLAPreheat); } - inline void Item_Prepare_ABS(const uint8_t row) { + void Item_Prepare_ABS(const uint8_t row) { if (HMI_IsChinese()) { DWIN_Frame_AreaCopy(1, 180, 89, 233, 100, LBLX, MBASE(row)); } else { - DWIN_Frame_AreaCopy(1, 107, 76, 156, 86, LBLX, MBASE(row)); // "Preheat" - DWIN_Frame_AreaCopy(1, 172, 76, 198, 86, LBLX + 52, MBASE(row)); // "ABS" + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(row), F("Preheat " PREHEAT_2_LABEL)); + #else + DWIN_Frame_AreaCopy(1, 107, 76, 156, 86, LBLX, MBASE(row)); // "Preheat" + DWIN_Frame_AreaCopy(1, 172, 76, 198, 86, LBLX + 52, MBASE(row)); // "ABS" + #endif } Draw_Menu_Line(row, ICON_ABSPreheat); } #endif #if HAS_PREHEAT - inline void Item_Prepare_Cool(const uint8_t row) { + void Item_Prepare_Cool(const uint8_t row) { if (HMI_IsChinese()) DWIN_Frame_AreaCopy(1, 1, 104, 56, 117, LBLX, MBASE(row)); - else - DWIN_Frame_AreaCopy(1, 200, 76, 264, 86, LBLX, MBASE(row)); // "Cooldown" + else { + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(row), GET_TEXT_F(MSG_COOLDOWN)); + #else + DWIN_Frame_AreaCopy(1, 200, 76, 264, 86, LBLX, MBASE(row)); // "Cooldown" + #endif + } Draw_Menu_Line(row, ICON_Cool); } #endif -inline void Item_Prepare_Lang(const uint8_t row) { - if (HMI_IsChinese()) { +void Item_Prepare_Lang(const uint8_t row) { + if (HMI_IsChinese()) DWIN_Frame_AreaCopy(1, 239, 134, 266, 146, LBLX, MBASE(row)); - DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, 226, MBASE(row), F("CN")); - } else { - DWIN_Frame_AreaCopy(1, 0, 194, 121, 207, LBLX, MBASE(row)); // "Language selection" - DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, 226, MBASE(row), F("EN")); + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(row), F("UI Language")); + #else + DWIN_Frame_AreaCopy(1, 0, 194, 121, 207, LBLX, MBASE(row)); // "Language selection" + #endif } + DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, 226, MBASE(row), HMI_IsChinese() ? F("CN") : F("EN")); Draw_Menu_Icon(row, ICON_Language); } -inline void Draw_Prepare_Menu() { +void Draw_Prepare_Menu() { Clear_Main_Window(); const int16_t scroll = MROWS - index_prepare; // Scrolled-up lines @@ -692,7 +735,19 @@ inline void Draw_Prepare_Menu() { if (select_prepare.now) Draw_Menu_Cursor(PSCROL(select_prepare.now)); } -inline void Draw_Control_Menu() { +void Item_Control_Info(const uint16_t line) { + if (HMI_IsChinese()) + DWIN_Frame_AreaCopy(1, 231, 104, 258, 116, LBLX, line); + else { + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(line, F("Info")); + #else + DWIN_Frame_AreaCopy(1, 0, 104, 24, 114, LBLX, line); + #endif + } +} + +void Draw_Control_Menu() { Clear_Main_Window(); #if CONTROL_CASE_TOTAL >= 6 @@ -717,36 +772,36 @@ inline void Draw_Control_Menu() { DWIN_Frame_AreaCopy(1, 174, 103, 229, 116, LBLX, CLINE(CONTROL_CASE_LOAD)); // Read Configuration DWIN_Frame_AreaCopy(1, 1, 118, 56, 131, LBLX, CLINE(CONTROL_CASE_RESET)); // Reset Configuration #endif - - if (CVISI(CONTROL_CASE_INFO)) - DWIN_Frame_AreaCopy(1, 231, 104, 258, 116, LBLX, CLINE(CONTROL_CASE_TEMP)); // Info > } else { #ifdef USE_STRING_HEADINGS Draw_Title(GET_TEXT_F(MSG_CONTROL)); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, CLINE(CONTROL_CASE_TEMP), GET_TEXT_F(MSG_TEMPERATURE)); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, CLINE(CONTROL_CASE_MOVE), GET_TEXT_F(MSG_MOTION)); + #else + DWIN_Frame_TitleCopy(1, 128, 2, 176, 12); // "Control" + #endif + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(CLINE(CONTROL_CASE_TEMP), GET_TEXT_F(MSG_TEMPERATURE)); + DWIN_Draw_Label(CLINE(CONTROL_CASE_MOVE), GET_TEXT_F(MSG_MOTION)); #if ENABLED(EEPROM_SETTINGS) - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, CLINE(CONTROL_CASE_SAVE), GET_TEXT_F(MSG_STORE_EEPROM)); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, CLINE(CONTROL_CASE_LOAD), GET_TEXT_F(MSG_LOAD_EEPROM)); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, CLINE(CONTROL_CASE_RESET), GET_TEXT_F(MSG_RESTORE_DEFAULTS)); + DWIN_Draw_Label(CLINE(CONTROL_CASE_SAVE), GET_TEXT_F(MSG_STORE_EEPROM)); + DWIN_Draw_Label(CLINE(CONTROL_CASE_LOAD), GET_TEXT_F(MSG_LOAD_EEPROM)); + DWIN_Draw_Label(CLINE(CONTROL_CASE_RESET), GET_TEXT_F(MSG_RESTORE_DEFAULTS)); #endif - if (CVISI(CONTROL_CASE_INFO)) DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, CLINE(CONTROL_CASE_INFO), F("Info")); #else - DWIN_Frame_TitleCopy(1, 128, 2, 176, 12); // "Control" DWIN_Frame_AreaCopy(1, 1, 89, 83, 101, LBLX, CLINE(CONTROL_CASE_TEMP)); // Temperature > DWIN_Frame_AreaCopy(1, 84, 89, 128, 99, LBLX, CLINE(CONTROL_CASE_MOVE)); // Motion > #if ENABLED(EEPROM_SETTINGS) - DWIN_Frame_AreaCopy(1, 148, 89, 268, 101, LBLX , CLINE(CONTROL_CASE_SAVE // "Store Configuration" + DWIN_Frame_AreaCopy(1, 148, 89, 268, 101, LBLX , CLINE(CONTROL_CASE_SAVE)); // "Store Configuration" DWIN_Frame_AreaCopy(1, 26, 104, 57, 114, LBLX , CLINE(CONTROL_CASE_LOAD)); // "Read" DWIN_Frame_AreaCopy(1, 182, 89, 268, 101, LBLX + 34, CLINE(CONTROL_CASE_LOAD)); // "Configuration" DWIN_Frame_AreaCopy(1, 59, 104, 93, 114, LBLX , CLINE(CONTROL_CASE_RESET)); // "Reset" DWIN_Frame_AreaCopy(1, 182, 89, 268, 101, LBLX + 37, CLINE(CONTROL_CASE_RESET)); // "Configuration" #endif - if (CVISI(CONTROL_CASE_INFO)) DWIN_Frame_AreaCopy(1, 0, 104, 25, 115, LBLX, CLINE(CONTROL_CASE_INFO)); // Info > #endif } + if (CVISI(CONTROL_CASE_INFO)) Item_Control_Info(CLINE(CONTROL_CASE_INFO)); + if (select_control.now && CVISI(select_control.now)) Draw_Menu_Cursor(CSCROL(select_control.now)); @@ -770,7 +825,7 @@ inline void Draw_Control_Menu() { if (CVISI(CONTROL_CASE_INFO)) Draw_More_Icon(CSCROL(i)); } -inline void Draw_Tune_Menu() { +void Draw_Tune_Menu() { Clear_Main_Window(); if (HMI_IsChinese()) { @@ -792,19 +847,22 @@ inline void Draw_Tune_Menu() { else { #ifdef USE_STRING_HEADINGS Draw_Title(GET_TEXT_F(MSG_TUNE)); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(TUNE_CASE_SPEED), GET_TEXT_F(MSG_SPEED)); + #else + DWIN_Frame_AreaCopy(1, 94, 2, 126, 12, 14, 9); + #endif + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(TUNE_CASE_SPEED), GET_TEXT_F(MSG_SPEED)); #if HAS_HOTEND - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(TUNE_CASE_TEMP), GET_TEXT_F(MSG_UBL_SET_TEMP_HOTEND)); + DWIN_Draw_Label(MBASE(TUNE_CASE_TEMP), GET_TEXT_F(MSG_UBL_SET_TEMP_HOTEND)); #endif #if HAS_HEATED_BED - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(TUNE_CASE_BED), GET_TEXT_F(MSG_UBL_SET_TEMP_BED)); + DWIN_Draw_Label(MBASE(TUNE_CASE_BED), GET_TEXT_F(MSG_UBL_SET_TEMP_BED)); #endif #if HAS_FAN - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(TUNE_CASE_FAN), GET_TEXT_F(MSG_FAN_SPEED)); + DWIN_Draw_Label(MBASE(TUNE_CASE_FAN), GET_TEXT_F(MSG_FAN_SPEED)); #endif - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(TUNE_CASE_ZOFF), GET_TEXT_F(MSG_ZPROBE_ZOFFSET)); + DWIN_Draw_Label(MBASE(TUNE_CASE_ZOFF), GET_TEXT_F(MSG_ZPROBE_ZOFFSET)); #else - DWIN_Frame_AreaCopy(1, 94, 2, 126, 12, 14, 9); DWIN_Frame_AreaCopy(1, 1, 179, 92, 190, LBLX, MBASE(TUNE_CASE_SPEED)); // Print speed #if HAS_HOTEND DWIN_Frame_AreaCopy(1, 197, 104, 238, 114, LBLX, MBASE(TUNE_CASE_TEMP)); // Hotend... @@ -847,36 +905,36 @@ inline void Draw_Tune_Menu() { #endif } -inline void draw_max_en(const uint16_t line) { +void draw_max_en(const uint16_t line) { DWIN_Frame_AreaCopy(1, 245, 119, 269, 129, LBLX, line); // "Max" } -inline void draw_max_accel_en(const uint16_t line) { +void draw_max_accel_en(const uint16_t line) { draw_max_en(line); DWIN_Frame_AreaCopy(1, 1, 135, 79, 145, LBLX + 27, line); // "Acceleration" } -inline void draw_speed_en(const uint16_t inset, const uint16_t line) { +void draw_speed_en(const uint16_t inset, const uint16_t line) { DWIN_Frame_AreaCopy(1, 184, 119, 224, 132, LBLX + inset, line); // "Speed" } -inline void draw_jerk_en(const uint16_t line) { +void draw_jerk_en(const uint16_t line) { DWIN_Frame_AreaCopy(1, 64, 119, 106, 129, LBLX + 27, line); // "Jerk" } -inline void draw_steps_per_mm(const uint16_t line) { +void draw_steps_per_mm(const uint16_t line) { DWIN_Frame_AreaCopy(1, 1, 151, 101, 161, LBLX, line); // "Steps-per-mm" } -inline void say_x(const uint16_t inset, const uint16_t line) { +void say_x(const uint16_t inset, const uint16_t line) { DWIN_Frame_AreaCopy(1, 95, 104, 102, 114, LBLX + inset, line); // "X" } -inline void say_y(const uint16_t inset, const uint16_t line) { +void say_y(const uint16_t inset, const uint16_t line) { DWIN_Frame_AreaCopy(1, 104, 104, 110, 114, LBLX + inset, line); // "Y" } -inline void say_z(const uint16_t inset, const uint16_t line) { +void say_z(const uint16_t inset, const uint16_t line) { DWIN_Frame_AreaCopy(1, 112, 104, 120, 114, LBLX + inset, line); // "Z" } -inline void say_e(const uint16_t inset, const uint16_t line) { +void say_e(const uint16_t inset, const uint16_t line) { DWIN_Frame_AreaCopy(1, 237, 119, 244, 129, LBLX + inset, line); // "E" } -inline void Draw_Motion_Menu() { +void Draw_Motion_Menu() { Clear_Main_Window(); if (HMI_IsChinese()) { @@ -894,14 +952,17 @@ inline void Draw_Motion_Menu() { else { #ifdef USE_STRING_HEADINGS Draw_Title(GET_TEXT_F(MSG_MOTION)); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(MOTION_CASE_RATE), F("Feedrate")); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(MOTION_CASE_ACCEL), GET_TEXT_F(MSG_ACCELERATION)); + #else + DWIN_Frame_TitleCopy(1, 144, 16, 189, 26); // "Motion" + #endif + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(MOTION_CASE_RATE), F("Feedrate")); + DWIN_Draw_Label(MBASE(MOTION_CASE_ACCEL), GET_TEXT_F(MSG_ACCELERATION)); #if HAS_CLASSIC_JERK - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(MOTION_CASE_JERK), GET_TEXT_F(MSG_JERK)); + DWIN_Draw_Label(MBASE(MOTION_CASE_JERK), GET_TEXT_F(MSG_JERK)); #endif - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(MOTION_CASE_STEPS), GET_TEXT_F(MSG_STEPS_PER_MM)); + DWIN_Draw_Label(MBASE(MOTION_CASE_STEPS), GET_TEXT_F(MSG_STEPS_PER_MM)); #else - DWIN_Frame_TitleCopy(1, 144, 16, 189, 26); // "Motion" draw_max_en(MBASE(MOTION_CASE_RATE)); draw_speed_en(27, MBASE(MOTION_CASE_RATE)); // "Max Speed" draw_max_accel_en(MBASE(MOTION_CASE_ACCEL)); // "Max Acceleration" #if HAS_CLASSIC_JERK @@ -959,7 +1020,7 @@ inline void Draw_Motion_Menu() { #endif -inline void Draw_Popup_Bkgd_60() { +void Draw_Popup_Bkgd_60() { DWIN_Draw_Rectangle(1, Color_Bg_Window, 14, 60, 258, 330); } @@ -1147,73 +1208,61 @@ inline ENCODER_DiffState get_encoder_state() { const millis_t ms = millis(); if (PENDING(ms, Encoder_ms)) return ENCODER_DIFF_NO; const ENCODER_DiffState state = Encoder_ReceiveAnalyze(); - if (state != ENCODER_DIFF_NO) Encoder_ms = ms + ENCODER_WAIT; + if (state != ENCODER_DIFF_NO) Encoder_ms = ms + ENCODER_WAIT_MS; return state; } +void HMI_Plan_Move(const feedRate_t fr_mm_s) { + if (!planner.is_full()) { + planner.synchronize(); + planner.buffer_line(current_position, fr_mm_s, active_extruder); + DWIN_UpdateLCD(); + } +} + +void HMI_Move_Done(const AxisEnum axis) { + EncoderRate.enabled = false; + planner.synchronize(); + checkkey = AxisMove; + DWIN_UpdateLCD(); +} + void HMI_Move_X() { ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); if (encoder_diffState != ENCODER_DIFF_NO) { - if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_X_scaled)) { - checkkey = AxisMove; - EncoderRate.enabled = false; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(1), HMI_ValueStruct.Move_X_scaled); - if (!planner.is_full()) { - // Wait for planner moves to finish! - planner.synchronize(); - planner.buffer_line(current_position, homing_feedrate(X_AXIS), active_extruder); - } - DWIN_UpdateLCD(); - return; - } + if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_X_scaled)) + return HMI_Move_Done(X_AXIS); LIMIT(HMI_ValueStruct.Move_X_scaled, (X_MIN_POS) * MINUNITMULT, (X_MAX_POS) * MINUNITMULT); current_position.x = HMI_ValueStruct.Move_X_scaled / MINUNITMULT; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 216, MBASE(1), HMI_ValueStruct.Move_X_scaled); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(1), HMI_ValueStruct.Move_X_scaled); DWIN_UpdateLCD(); + HMI_Plan_Move(homing_feedrate(X_AXIS)); } } void HMI_Move_Y() { ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); if (encoder_diffState != ENCODER_DIFF_NO) { - if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_Y_scaled)) { - checkkey = AxisMove; - EncoderRate.enabled = false; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(2), HMI_ValueStruct.Move_Y_scaled); - if (!planner.is_full()) { - // Wait for planner moves to finish! - planner.synchronize(); - planner.buffer_line(current_position, homing_feedrate(Y_AXIS), active_extruder); - } - DWIN_UpdateLCD(); - return; - } + if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_Y_scaled)) + return HMI_Move_Done(Y_AXIS); LIMIT(HMI_ValueStruct.Move_Y_scaled, (Y_MIN_POS) * MINUNITMULT, (Y_MAX_POS) * MINUNITMULT); current_position.y = HMI_ValueStruct.Move_Y_scaled / MINUNITMULT; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 216, MBASE(2), HMI_ValueStruct.Move_Y_scaled); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(2), HMI_ValueStruct.Move_Y_scaled); DWIN_UpdateLCD(); + HMI_Plan_Move(homing_feedrate(Y_AXIS)); } } void HMI_Move_Z() { ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); if (encoder_diffState != ENCODER_DIFF_NO) { - if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_Z_scaled)) { - checkkey = AxisMove; - EncoderRate.enabled = false; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(3), HMI_ValueStruct.Move_Z_scaled); - if (!planner.is_full()) { - // Wait for planner moves to finish! - planner.synchronize(); - planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder); - } - DWIN_UpdateLCD(); - return; - } - LIMIT(HMI_ValueStruct.Move_Z_scaled, Z_MIN_POS * MINUNITMULT, Z_MAX_POS * MINUNITMULT); + if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_Z_scaled)) + return HMI_Move_Done(Z_AXIS); + LIMIT(HMI_ValueStruct.Move_Z_scaled, (Z_MIN_POS) * MINUNITMULT, (Z_MAX_POS) * MINUNITMULT); current_position.z = HMI_ValueStruct.Move_Z_scaled / MINUNITMULT; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 216, MBASE(3), HMI_ValueStruct.Move_Z_scaled); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(3), HMI_ValueStruct.Move_Z_scaled); DWIN_UpdateLCD(); + HMI_Plan_Move(homing_feedrate(Z_AXIS)); } } @@ -1224,24 +1273,14 @@ void HMI_Move_Z() { ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); if (encoder_diffState != ENCODER_DIFF_NO) { if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_E_scaled)) { - checkkey = AxisMove; - EncoderRate.enabled = false; last_E_scaled = HMI_ValueStruct.Move_E_scaled; - DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(4), HMI_ValueStruct.Move_E_scaled); - if (!planner.is_full()) { - planner.synchronize(); // Wait for planner moves to finish! - planner.buffer_line(current_position, MMM_TO_MMS(FEEDRATE_E), active_extruder); - } - DWIN_UpdateLCD(); - return; + return HMI_Move_Done(E_AXIS); } - if ((HMI_ValueStruct.Move_E_scaled - last_E_scaled) > (EXTRUDE_MAXLENGTH) * MINUNITMULT) - HMI_ValueStruct.Move_E_scaled = last_E_scaled + (EXTRUDE_MAXLENGTH) * MINUNITMULT; - else if ((last_E_scaled - HMI_ValueStruct.Move_E_scaled) > (EXTRUDE_MAXLENGTH) * MINUNITMULT) - HMI_ValueStruct.Move_E_scaled = last_E_scaled - (EXTRUDE_MAXLENGTH) * MINUNITMULT; + LIMIT(HMI_ValueStruct.Move_E_scaled, last_E_scaled - (EXTRUDE_MAXLENGTH) * MINUNITMULT, last_E_scaled + (EXTRUDE_MAXLENGTH) * MINUNITMULT); current_position.e = HMI_ValueStruct.Move_E_scaled / MINUNITMULT; - DWIN_Draw_Signed_Float(font8x16, Select_Color, 3, UNITFDIGITS, 216, MBASE(4), HMI_ValueStruct.Move_E_scaled); + DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(4), HMI_ValueStruct.Move_E_scaled); DWIN_UpdateLCD(); + HMI_Plan_Move(MMM_TO_MMS(FEEDRATE_E)); } } @@ -1369,7 +1408,7 @@ void HMI_Move_Z() { #endif // HAS_HEATED_BED -#if HAS_PREHEAT +#if HAS_PREHEAT && HAS_FAN void HMI_FanSpeed() { ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); @@ -1411,7 +1450,7 @@ void HMI_Move_Z() { } } -#endif // HAS_PREHEAT +#endif // HAS_PREHEAT && HAS_FAN void HMI_PrintSpeed() { ENCODER_DiffState encoder_diffState = Encoder_ReceiveAnalyze(); @@ -1518,89 +1557,144 @@ void HMI_StepXYZE() { } } +// Draw X, Y, Z and blink if in an un-homed or un-trusted state +void _update_axis_value(const AxisEnum axis, const uint16_t x, const uint16_t y, const bool blink, const bool force) { + const bool draw_qmark = axis_should_home(axis), + draw_empty = NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !draw_qmark && !axis_is_trusted(axis); + + // Check for a position change + static xyz_pos_t oldpos = { -1, -1, -1 }; + const float p = current_position[axis]; + const bool changed = oldpos[axis] != p; + if (changed) oldpos[axis] = p; + + if (force || changed || draw_qmark || draw_empty) { + if (blink && draw_qmark) + DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, x, y, F("???.?")); + else if (blink && draw_empty) + DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, x, y, F(" ")); + else + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, x, y, p * 10); + } +} + +void _draw_xyz_position(const bool force) { + //SERIAL_ECHOPGM("Draw XYZ:"); + static bool _blink = false; + const bool blink = !!(millis() & 0x400UL); + if (force || blink != _blink) { + _blink = blink; + //SERIAL_ECHOPGM(" (blink)"); + _update_axis_value(X_AXIS, 35, 459, blink, true); + _update_axis_value(Y_AXIS, 120, 459, blink, true); + _update_axis_value(Z_AXIS, 205, 459, blink, true); + } + //SERIAL_EOL(); +} + void update_variable() { - TERN_(HAS_HOTEND, static float last_temp_hotend_target = 0); - TERN_(HAS_HEATED_BED, static float last_temp_bed_target = 0); - TERN_(HAS_FAN, static uint8_t last_fan_speed = 0); + #if HAS_HOTEND + static float _hotendtemp = 0; + const bool _new_hotend_temp = _hotendtemp != thermalManager.temp_hotend[0].celsius; + if (_new_hotend_temp) _hotendtemp = thermalManager.temp_hotend[0].celsius; + static int16_t _hotendtarget = 0; + const bool _new_hotend_target = _hotendtarget != thermalManager.temp_hotend[0].target; + if (_new_hotend_target) _hotendtarget = thermalManager.temp_hotend[0].target; + #endif + #if HAS_HEATED_BED + static float _bedtemp = 0; + const bool _new_bed_temp = _bedtemp != thermalManager.temp_bed.celsius; + if (_new_bed_temp) _bedtemp = thermalManager.temp_bed.celsius; + static int16_t _bedtarget = 0; + const bool _new_bed_target = _bedtarget != thermalManager.temp_bed.target; + if (_new_bed_target) _bedtarget = thermalManager.temp_bed.target; + #endif + #if HAS_FAN + static uint8_t _fanspeed = 0; + const bool _new_fanspeed = _fanspeed != thermalManager.fan_speed[0]; + if (_new_fanspeed) _fanspeed = thermalManager.fan_speed[0]; + #endif - /* Tune page temperature update */ if (checkkey == Tune) { + // Tune page temperature update #if HAS_HOTEND - if (last_temp_hotend_target != thermalManager.temp_hotend[0].target) { - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TUNE_CASE_TEMP + MROWS - index_tune), thermalManager.temp_hotend[0].target); - last_temp_hotend_target = thermalManager.temp_hotend[0].target; - } + if (_new_hotend_target) + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TUNE_CASE_TEMP + MROWS - index_tune), _hotendtarget); #endif #if HAS_HEATED_BED - if (last_temp_bed_target != thermalManager.temp_bed.target) { - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TUNE_CASE_BED + MROWS - index_tune), thermalManager.temp_bed.target); - last_temp_bed_target = thermalManager.temp_bed.target; - } + if (_new_bed_target) + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TUNE_CASE_BED + MROWS - index_tune), _bedtarget); #endif #if HAS_FAN - if (last_fan_speed != thermalManager.fan_speed[0]) { - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TUNE_CASE_FAN + MROWS - index_tune), thermalManager.fan_speed[0]); - last_fan_speed = thermalManager.fan_speed[0]; - } + if (_new_fanspeed) + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TUNE_CASE_FAN + MROWS - index_tune), _fanspeed); #endif } - - /* Temperature page temperature update */ - if (checkkey == TemperatureID) { + else if (checkkey == TemperatureID) { + // Temperature page temperature update #if HAS_HOTEND - if (last_temp_hotend_target != thermalManager.temp_hotend[0].target) { - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TEMP_CASE_TEMP), thermalManager.temp_hotend[0].target); - last_temp_hotend_target = thermalManager.temp_hotend[0].target; - } + if (_new_hotend_target) + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TEMP_CASE_TEMP), _hotendtarget); #endif #if HAS_HEATED_BED - if (last_temp_bed_target != thermalManager.temp_bed.target) { - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TEMP_CASE_BED), thermalManager.temp_bed.target); - last_temp_bed_target = thermalManager.temp_bed.target; - } + if (_new_bed_target) + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TEMP_CASE_BED), _bedtarget); #endif #if HAS_FAN - if (last_fan_speed != thermalManager.fan_speed[0]) { - DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TEMP_CASE_FAN), thermalManager.fan_speed[0]); - last_fan_speed = thermalManager.fan_speed[0]; - } + if (_new_fanspeed) + DWIN_Draw_IntValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 216, MBASE(TEMP_CASE_FAN), _fanspeed); #endif } - /* Bottom temperature update */ + // Bottom temperature update + #if HAS_HOTEND - static float _hotendtemp = 0; - if (_hotendtemp != thermalManager.temp_hotend[0].celsius) { - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 33, 382, thermalManager.temp_hotend[0].celsius); - _hotendtemp = thermalManager.temp_hotend[0].celsius; - } - if (last_temp_hotend_target != thermalManager.temp_hotend[0].target) { - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 33 + 4 * STAT_CHR_W + 6, 382, thermalManager.temp_hotend[0].target); - last_temp_hotend_target = thermalManager.temp_hotend[0].target; + if (_new_hotend_temp) + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 28, 384, _hotendtemp); + if (_new_hotend_target) + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 384, _hotendtarget); + + static int16_t _flow = planner.flow_percentage[0]; + if (_flow != planner.flow_percentage[0]) { + _flow = planner.flow_percentage[0]; + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 116 + 2 * STAT_CHR_W, 417, _flow); } #endif + #if HAS_HEATED_BED - static float _bedtemp = 0; - if (_bedtemp != thermalManager.temp_bed.celsius) { - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 178, 382, thermalManager.temp_bed.celsius); - _bedtemp = thermalManager.temp_bed.celsius; - } - if (last_temp_bed_target != thermalManager.temp_bed.target) { - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 178 + 4 * STAT_CHR_W + 6, 382, thermalManager.temp_bed.target); - last_temp_bed_target = thermalManager.temp_bed.target; - } + if (_new_bed_temp) + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 28, 417, _bedtemp); + if (_new_bed_target) + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 417, _bedtarget); #endif - static uint16_t last_speed = 0; - if (last_speed != feedrate_percentage) { - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 33 + 2 * STAT_CHR_W, 429, feedrate_percentage); - last_speed = feedrate_percentage; + + static int16_t _feedrate = 100; + if (_feedrate != feedrate_percentage) { + _feedrate = feedrate_percentage; + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 116 + 2 * STAT_CHR_W, 384, _feedrate); } - #if HAS_ZOFFSET_ITEM - if (last_zoffset != BABY_Z_VAR) { - DWIN_Draw_Signed_Float(DWIN_FONT_STAT, Color_Bg_Black, 2, 2, 178 + STAT_CHR_W, 429, BABY_Z_VAR * 100); - last_zoffset = BABY_Z_VAR; + + #if HAS_FAN + if (_new_fanspeed) { + _fanspeed = thermalManager.fan_speed[0]; + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 195 + 2 * STAT_CHR_W, 384, _fanspeed); } #endif + + static float _offset = 0; + if (BABY_Z_VAR != _offset) { + _offset = BABY_Z_VAR; + if (BABY_Z_VAR < 0) { + DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 2, 2, 207, 417, -_offset * 100); + DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, 205, 419, F("-")); + } + else { + DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 2, 2, 207, 417, _offset * 100); + DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, 205, 419, F(" ")); + } + } + + _draw_xyz_position(false); } /** @@ -1615,7 +1709,7 @@ void update_variable() { #define strcasecmp_P(a, b) strcasecmp((a), (b)) #endif -inline void make_name_without_ext(char *dst, char *src, size_t maxlen=MENU_CHAR_LIMIT) { +void make_name_without_ext(char *dst, char *src, size_t maxlen=MENU_CHAR_LIMIT) { char * const name = card.longest_filename(); size_t pos = strlen(name); // index of ending nul @@ -1638,7 +1732,7 @@ inline void make_name_without_ext(char *dst, char *src, size_t maxlen=MENU_CHAR_ while (pos--) dst[pos] = src[pos]; } -inline void HMI_SDCardInit() { card.cdroot(); } +void HMI_SDCardInit() { card.cdroot(); } void MarlinUI::refresh() { /* Nothing to see here */ } @@ -1651,7 +1745,7 @@ void MarlinUI::refresh() { /* Nothing to see here */ } millis_t shift_ms; // = 0 // Init the shift name based on the highlighted item - inline void Init_Shift_Name() { + void Init_Shift_Name() { const bool is_subdir = !card.flag.workDirIsRoot; const int8_t filenum = select_file.now - 1 - is_subdir; // Skip "Back" and ".." const uint16_t fileCnt = card.get_num_Files(); @@ -1662,7 +1756,7 @@ void MarlinUI::refresh() { /* Nothing to see here */ } } } - inline void Init_SDItem_Shift() { + void Init_SDItem_Shift() { shift_amt = 0; shift_ms = select_file.now > 0 && strlen(shift_name) > MENU_CHAR_LIMIT ? millis() + 750UL : 0; @@ -1673,7 +1767,7 @@ void MarlinUI::refresh() { /* Nothing to see here */ } /** * Display an SD item, adding a CDUP for subfolders. */ -inline void Draw_SDItem(const uint16_t item, int16_t row=-1) { +void Draw_SDItem(const uint16_t item, int16_t row=-1) { if (row < 0) row = item + 1 + MROWS - index_file; const bool is_subdir = !card.flag.workDirIsRoot; if (is_subdir && item == 0) { @@ -1701,7 +1795,7 @@ inline void Draw_SDItem(const uint16_t item, int16_t row=-1) { #if ENABLED(SCROLL_LONG_FILENAMES) - inline void Draw_SDItem_Shifted(int8_t &shift) { + void Draw_SDItem_Shifted(int8_t &shift) { // Limit to the number of chars past the cutoff const size_t len = strlen(shift_name); NOMORE(shift, _MAX(len - MENU_CHAR_LIMIT, 0U)); @@ -1722,7 +1816,7 @@ inline void Draw_SDItem(const uint16_t item, int16_t row=-1) { #endif // Redraw the first set of SD Files -inline void Redraw_SD_List() { +void Redraw_SD_List() { select_file.reset(); index_file = MROWS; @@ -1745,13 +1839,13 @@ inline void Redraw_SD_List() { bool DWIN_lcd_sd_status = false; -inline void SDCard_Up() { +void SDCard_Up() { card.cdup(); Redraw_SD_List(); DWIN_lcd_sd_status = false; // On next DWIN_Update } -inline void SDCard_Folder(char * const dirname) { +void SDCard_Folder(char * const dirname) { card.cd(dirname); Redraw_SD_List(); DWIN_lcd_sd_status = false; // On next DWIN_Update @@ -1764,7 +1858,7 @@ void HMI_SDCardUpdate() { if (HMI_flag.home_flag) return; if (DWIN_lcd_sd_status != card.isMounted()) { DWIN_lcd_sd_status = card.isMounted(); - // SERIAL_ECHOLNPAIR("HMI_SDCardUpdate: ", DWIN_lcd_sd_status); + //SERIAL_ECHOLNPAIR("HMI_SDCardUpdate: ", DWIN_lcd_sd_status); if (DWIN_lcd_sd_status) { if (checkkey == SelectFile) Redraw_SD_List(); @@ -1792,39 +1886,55 @@ void HMI_SDCardUpdate() { // void Draw_Status_Area(const bool with_update) { - // Clear the bottom area of the screen DWIN_Draw_Rectangle(1, Color_Bg_Black, 0, STATUS_Y, DWIN_WIDTH, DWIN_HEIGHT - 1); - // - // Status Area - // #if HAS_HOTEND - DWIN_ICON_Show(ICON, ICON_HotendTemp, 13, 381); - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 33, 382, thermalManager.temp_hotend[0].celsius); - DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 33 + 3 * STAT_CHR_W + 5, 383, F("/")); - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 33 + 4 * STAT_CHR_W + 6, 382, thermalManager.temp_hotend[0].target); - #endif - #if HOTENDS > 1 - // DWIN_ICON_Show(ICON,ICON_HotendTemp, 13, 381); + DWIN_ICON_Show(ICON, ICON_HotendTemp, 10, 383); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 28, 384, thermalManager.temp_hotend[0].celsius); + DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 384, F("/")); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 384, thermalManager.temp_hotend[0].target); + + DWIN_ICON_Show(ICON, ICON_StepE, 112, 417); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 116 + 2 * STAT_CHR_W, 417, planner.flow_percentage[0]); + DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 116 + 5 * STAT_CHR_W + 2, 417, F("%")); #endif #if HAS_HEATED_BED - DWIN_ICON_Show(ICON, ICON_BedTemp, 158, 381); - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 178, 382, thermalManager.temp_bed.celsius); - DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 178 + 3 * STAT_CHR_W + 5, 383, F("/")); - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 178 + 4 * STAT_CHR_W + 6, 382, thermalManager.temp_bed.target); + DWIN_ICON_Show(ICON, ICON_BedTemp, 10, 416); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 28, 417, thermalManager.temp_bed.celsius); + DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 25 + 3 * STAT_CHR_W + 5, 417, F("/")); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 25 + 4 * STAT_CHR_W + 6, 417, thermalManager.temp_bed.target); #endif - DWIN_ICON_Show(ICON, ICON_Speed, 13, 429); - DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 33 + 2 * STAT_CHR_W, 429, feedrate_percentage); - DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 33 + 5 * STAT_CHR_W + 2, 429, F("%")); + DWIN_ICON_Show(ICON, ICON_Speed, 113, 383); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 116 + 2 * STAT_CHR_W, 384, feedrate_percentage); + DWIN_Draw_String(false, false, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 116 + 5 * STAT_CHR_W + 2, 384, F("%")); + + #if HAS_FAN + DWIN_ICON_Show(ICON, ICON_FanSpeed, 187, 383); + DWIN_Draw_IntValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 3, 195 + 2 * STAT_CHR_W, 384, thermalManager.fan_speed[0]); + #endif #if HAS_ZOFFSET_ITEM - DWIN_ICON_Show(ICON, ICON_Zoffset, 158, 428); - dwin_zoffset = BABY_Z_VAR; - DWIN_Draw_Signed_Float(DWIN_FONT_STAT, Color_Bg_Black, 2, 2, 178, 429, dwin_zoffset * 100); + DWIN_ICON_Show(ICON, ICON_Zoffset, 187, 416); #endif + if (BABY_Z_VAR < 0) { + DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 2, 2, 207, 417, -BABY_Z_VAR * 100); + DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, 205, 419, F("-")); + } + else { + DWIN_Draw_FloatValue(true, true, 0, DWIN_FONT_STAT, Color_White, Color_Bg_Black, 2, 2, 207, 417, BABY_Z_VAR * 100); + DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, 205, 419, F(" ")); + } + + DWIN_Draw_Rectangle(1, Line_Color, 0, 449, DWIN_WIDTH, 451); + + DWIN_ICON_Show(ICON, ICON_MaxSpeedX, 10, 456); + DWIN_ICON_Show(ICON, ICON_MaxSpeedY, 95, 456); + DWIN_ICON_Show(ICON, ICON_MaxSpeedZ, 180, 456); + _draw_xyz_position(true); + if (with_update) { DWIN_UpdateLCD(); delay(5); @@ -1836,11 +1946,11 @@ void HMI_StartFrame(const bool with_update) { Draw_Status_Area(with_update); } -inline void Draw_Info_Menu() { +void Draw_Info_Menu() { Clear_Main_Window(); - DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, (DWIN_WIDTH - strlen(MACHINE_SIZE) * MENU_CHR_W) / 2, 122, (char*)MACHINE_SIZE); - DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, (DWIN_WIDTH - strlen(SHORT_BUILD_VERSION) * MENU_CHR_W) / 2, 195, (char*)SHORT_BUILD_VERSION); + DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, (DWIN_WIDTH - strlen(MACHINE_SIZE) * MENU_CHR_W) / 2, 122, F(MACHINE_SIZE)); + DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, (DWIN_WIDTH - strlen(SHORT_BUILD_VERSION) * MENU_CHR_W) / 2, 195, F(SHORT_BUILD_VERSION)); if (HMI_IsChinese()) { DWIN_Frame_TitleCopy(1, 30, 17, 57, 29); // "Info" @@ -1848,7 +1958,6 @@ inline void Draw_Info_Menu() { DWIN_Frame_AreaCopy(1, 197, 149, 252, 161, 108, 102); DWIN_Frame_AreaCopy(1, 1, 164, 56, 176, 108, 175); DWIN_Frame_AreaCopy(1, 58, 164, 113, 176, 105, 248); - DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, (DWIN_WIDTH - strlen(CORP_WEBSITE_C) * MENU_CHR_W) / 2, 268, (char*)CORP_WEBSITE_C); } else { #ifdef USE_STRING_HEADINGS @@ -1860,8 +1969,8 @@ inline void Draw_Info_Menu() { DWIN_Frame_AreaCopy(1, 120, 150, 146, 161, 124, 102); DWIN_Frame_AreaCopy(1, 146, 151, 254, 161, 82, 175); DWIN_Frame_AreaCopy(1, 0, 165, 94, 175, 89, 248); - DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, (DWIN_WIDTH - strlen(CORP_WEBSITE_E) * MENU_CHR_W) / 2, 268, (char*)CORP_WEBSITE_E); } + DWIN_Draw_String(false, false, font8x16, Color_White, Color_Bg_Black, (DWIN_WIDTH - strlen(CORP_WEBSITE) * MENU_CHR_W) / 2, 268, F(CORP_WEBSITE)); Draw_Back_First(); LOOP_L_N(i, 3) { @@ -1870,7 +1979,7 @@ inline void Draw_Info_Menu() { } } -inline void Draw_Print_File_Menu() { +void Draw_Print_File_Menu() { Clear_Title_Bar(); if (HMI_IsChinese()) { @@ -2199,7 +2308,7 @@ void HMI_PauseOrStop() { DWIN_UpdateLCD(); } -inline void Draw_Move_Menu() { +void Draw_Move_Menu() { Clear_Main_Window(); if (HMI_IsChinese()) { @@ -2340,19 +2449,17 @@ void HMI_Prepare() { #endif break; #endif - #if HAS_HOTEND + #if HAS_PREHEAT case PREPARE_CASE_PLA: // PLA preheat - thermalManager.setTargetHotend(ui.material_preset[0].hotend_temp, 0); - thermalManager.setTargetBed(ui.material_preset[0].bed_temp); - thermalManager.set_fan_speed(0, ui.material_preset[0].fan_speed); + TERN_(HAS_HOTEND, thermalManager.setTargetHotend(ui.material_preset[0].hotend_temp, 0)); + TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(ui.material_preset[0].bed_temp)); + TERN_(HAS_FAN, thermalManager.set_fan_speed(0, ui.material_preset[0].fan_speed)); break; case PREPARE_CASE_ABS: // ABS preheat - thermalManager.setTargetHotend(ui.material_preset[1].hotend_temp, 0); - thermalManager.setTargetBed(ui.material_preset[1].bed_temp); - thermalManager.set_fan_speed(0, ui.material_preset[1].fan_speed); + TERN_(HAS_HOTEND, thermalManager.setTargetHotend(ui.material_preset[1].hotend_temp, 0)); + TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(ui.material_preset[1].bed_temp)); + TERN_(HAS_FAN, thermalManager.set_fan_speed(0, ui.material_preset[1].fan_speed)); break; - #endif - #if HAS_PREHEAT case PREPARE_CASE_COOL: // Cool TERN_(HAS_FAN, thermalManager.zero_fan_speeds()); #if HAS_HOTEND || HAS_HEATED_BED @@ -2392,21 +2499,24 @@ void Draw_Temperature_Menu() { else { #ifdef USE_STRING_HEADINGS Draw_Title(GET_TEXT_F(MSG_TEMPERATURE)); + #else + DWIN_Frame_TitleCopy(1, 56, 16, 141, 28); // "Temperature" + #endif + #ifdef USE_STRING_TITLES #if HAS_HOTEND - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(TEMP_CASE_TEMP), GET_TEXT_F(MSG_UBL_SET_TEMP_HOTEND)); + DWIN_Draw_Label(MBASE(TEMP_CASE_TEMP), GET_TEXT_F(MSG_UBL_SET_TEMP_HOTEND)); #endif #if HAS_HEATED_BED - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(TEMP_CASE_BED), GET_TEXT_F(MSG_UBL_SET_TEMP_BED)); + DWIN_Draw_Label(MBASE(TEMP_CASE_BED), GET_TEXT_F(MSG_UBL_SET_TEMP_BED)); #endif #if HAS_FAN - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(TEMP_CASE_FAN), GET_TEXT_F(MSG_FAN_SPEED)); + DWIN_Draw_Label(MBASE(TEMP_CASE_FAN), GET_TEXT_F(MSG_FAN_SPEED)); #endif #if HAS_HOTEND - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(TEMP_CASE_PLA), F("PLA Preheat Settings")); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(TEMP_CASE_ABS), F("ABS Preheat Settings")); + DWIN_Draw_Label(MBASE(TEMP_CASE_PLA), F("PLA Preheat Settings")); + DWIN_Draw_Label(MBASE(TEMP_CASE_ABS), F("ABS Preheat Settings")); #endif #else - DWIN_Frame_TitleCopy(1, 56, 16, 141, 28); // "Temperature" #if HAS_HOTEND DWIN_Frame_AreaCopy(1, 197, 104, 238, 114, LBLX, MBASE(TEMP_CASE_TEMP)); // Nozzle... DWIN_Frame_AreaCopy(1, 1, 89, 83, 101, LBLX + 44, MBASE(TEMP_CASE_TEMP)); // ...Temperature @@ -2472,10 +2582,7 @@ void HMI_Control() { Draw_More_Icon(CONTROL_CASE_MOVE + MROWS - index_control); // Motion > if (index_control > MROWS) { Draw_More_Icon(CONTROL_CASE_INFO + MROWS - index_control); // Info > - if (HMI_IsChinese()) - DWIN_Frame_AreaCopy(1, 231, 104, 258, 116, LBLX, MBASE(CONTROL_CASE_INFO - 1)); - else - DWIN_Frame_AreaCopy(1, 0, 104, 24, 114, LBLX, MBASE(CONTROL_CASE_INFO - 1)); + Item_Control_Info(MBASE(CONTROL_CASE_INFO - 1)); } } else { @@ -2701,18 +2808,21 @@ void HMI_Temperature() { else { #ifdef USE_STRING_HEADINGS Draw_Title("PLA Settings"); // TODO: GET_TEXT_F - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(PREHEAT_CASE_TEMP), F("Nozzle Temp")); + #else + DWIN_Frame_TitleCopy(1, 56, 16, 141, 28); // "PLA Settings" + #endif + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(PREHEAT_CASE_TEMP), F("Nozzle Temp")); #if HAS_HEATED_BED - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(PREHEAT_CASE_BED), F("Bed Temp")); + DWIN_Draw_Label(MBASE(PREHEAT_CASE_BED), F("Bed Temp")); #endif #if HAS_FAN - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(PREHEAT_CASE_FAN), GET_TEXT_F(MSG_FAN_SPEED)); + DWIN_Draw_Label(MBASE(PREHEAT_CASE_FAN), GET_TEXT_F(MSG_FAN_SPEED)); #endif #if ENABLED(EEPROM_SETTINGS) - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(PREHEAT_CASE_SAVE), GET_TEXT_F(MSG_STORE_EEPROM)); + DWIN_Draw_Label(MBASE(PREHEAT_CASE_SAVE), GET_TEXT_F(MSG_STORE_EEPROM)); #endif #else - DWIN_Frame_TitleCopy(1, 56, 16, 141, 28); // "PLA Settings" DWIN_Frame_AreaCopy(1, 157, 76, 181, 86, LBLX, MBASE(PREHEAT_CASE_TEMP)); DWIN_Frame_AreaCopy(1, 197, 104, 238, 114, LBLX + 27, MBASE(PREHEAT_CASE_TEMP)); DWIN_Frame_AreaCopy(1, 1, 89, 83, 101, LBLX + 71, MBASE(PREHEAT_CASE_TEMP)); // PLA nozzle temp @@ -2777,18 +2887,21 @@ void HMI_Temperature() { else { #ifdef USE_STRING_HEADINGS Draw_Title("ABS Settings"); // TODO: GET_TEXT_F - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(PREHEAT_CASE_TEMP), F("Nozzle Temp")); + #else + DWIN_Frame_TitleCopy(1, 56, 16, 141, 28); // "ABS Settings" + #endif + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(PREHEAT_CASE_TEMP), F("Nozzle Temp")); #if HAS_HEATED_BED - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(PREHEAT_CASE_BED), F("Bed Temp")); + DWIN_Draw_Label(MBASE(PREHEAT_CASE_BED), F("Bed Temp")); #endif #if HAS_FAN - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(PREHEAT_CASE_FAN), GET_TEXT_F(MSG_FAN_SPEED)); + DWIN_Draw_Label(MBASE(PREHEAT_CASE_FAN), GET_TEXT_F(MSG_FAN_SPEED)); #endif #if ENABLED(EEPROM_SETTINGS) - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(PREHEAT_CASE_SAVE), GET_TEXT_F(MSG_STORE_EEPROM)); + DWIN_Draw_Label(MBASE(PREHEAT_CASE_SAVE), GET_TEXT_F(MSG_STORE_EEPROM)); #endif #else - DWIN_Frame_TitleCopy(1, 56, 16, 141, 28); // "ABS Settings" DWIN_Frame_AreaCopy(1, 172, 76, 198, 86, LBLX, MBASE(PREHEAT_CASE_TEMP)); DWIN_Frame_AreaCopy(1, 197, 104, 238, 114, LBLX + 27, MBASE(PREHEAT_CASE_TEMP)); DWIN_Frame_AreaCopy(1, 1, 89, 83, 101, LBLX + 71, MBASE(PREHEAT_CASE_TEMP)); // ABS nozzle temp @@ -2833,7 +2946,7 @@ void HMI_Temperature() { DWIN_UpdateLCD(); } -inline void Draw_Max_Speed_Menu() { +void Draw_Max_Speed_Menu() { Clear_Main_Window(); if (HMI_IsChinese()) { @@ -2857,15 +2970,17 @@ inline void Draw_Max_Speed_Menu() { else { #ifdef USE_STRING_HEADINGS Draw_Title("Max Speed (mm/s)"); // TODO: GET_TEXT_F - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(1), F("Max Feedrate X")); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(2), F("Max Feedrate Y")); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(3), F("Max Feedrate Z")); + #else + DWIN_Frame_TitleCopy(1, 144, 16, 189, 26); // "Max Speed (mm/s)" + #endif + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(1), F("Max Feedrate X")); + DWIN_Draw_Label(MBASE(2), F("Max Feedrate Y")); + DWIN_Draw_Label(MBASE(3), F("Max Feedrate Z")); #if HAS_HOTEND - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(4), F("Max Feedrate E")); + DWIN_Draw_Label(MBASE(4), F("Max Feedrate E")); #endif #else - DWIN_Frame_TitleCopy(1, 144, 16, 189, 26); // "Max Speed (mm/s)" - draw_max_en(MBASE(1)); // "Max" DWIN_Frame_AreaCopy(1, 184, 119, 234, 132, LBLX + 27, MBASE(1)); // "Speed X" @@ -2895,7 +3010,7 @@ inline void Draw_Max_Speed_Menu() { #endif } -inline void Draw_Max_Accel_Menu() { +void Draw_Max_Accel_Menu() { Clear_Main_Window(); if (HMI_IsChinese()) { @@ -2919,14 +3034,17 @@ inline void Draw_Max_Accel_Menu() { else { #ifdef USE_STRING_HEADINGS Draw_Title(GET_TEXT_F(MSG_ACCELERATION)); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(1), F("Max Accel X")); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(2), F("Max Accel Y")); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(3), F("Max Accel Z")); + #else + DWIN_Frame_TitleCopy(1, 144, 16, 189, 26); // "Acceleration" + #endif + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(1), F("Max Accel X")); + DWIN_Draw_Label(MBASE(2), F("Max Accel Y")); + DWIN_Draw_Label(MBASE(3), F("Max Accel Z")); #if HAS_HOTEND - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(4), F("Max Accel E")); + DWIN_Draw_Label(MBASE(4), F("Max Accel E")); #endif #else - DWIN_Frame_TitleCopy(1, 144, 16, 189, 26); // "Acceleration" draw_max_accel_en(MBASE(1)); say_x(108, MBASE(1)); // "Max Acceleration X" draw_max_accel_en(MBASE(2)); say_y(108, MBASE(2)); // "Max Acceleration Y" draw_max_accel_en(MBASE(3)); say_z(108, MBASE(3)); // "Max Acceleration Z" @@ -2947,7 +3065,7 @@ inline void Draw_Max_Accel_Menu() { } #if HAS_CLASSIC_JERK - inline void Draw_Max_Jerk_Menu() { + void Draw_Max_Jerk_Menu() { Clear_Main_Window(); if (HMI_IsChinese()) { @@ -2975,14 +3093,17 @@ inline void Draw_Max_Accel_Menu() { else { #ifdef USE_STRING_HEADINGS Draw_Title(GET_TEXT_F(MSG_JERK)); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(1), F("Max Jerk X")); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(2), F("Max Jerk Y")); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(3), F("Max Jerk Z")); + #else + DWIN_Frame_TitleCopy(1, 144, 16, 189, 26); // "Jerk" + #endif + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(1), F("Max Jerk X")); + DWIN_Draw_Label(MBASE(2), F("Max Jerk Y")); + DWIN_Draw_Label(MBASE(3), F("Max Jerk Z")); #if HAS_HOTEND - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(4), F("Max Jerk E")); + DWIN_Draw_Label(MBASE(4), F("Max Jerk E")); #endif #else - DWIN_Frame_TitleCopy(1, 144, 16, 189, 26); // "Jerk" draw_max_en(MBASE(1)); // "Max" draw_jerk_en(MBASE(1)); // "Jerk" draw_speed_en(72, MBASE(1)); // "Speed" @@ -3018,7 +3139,7 @@ inline void Draw_Max_Accel_Menu() { } #endif -inline void Draw_Steps_Menu() { +void Draw_Steps_Menu() { Clear_Main_Window(); if (HMI_IsChinese()) { @@ -3038,14 +3159,17 @@ inline void Draw_Steps_Menu() { else { #ifdef USE_STRING_HEADINGS Draw_Title(GET_TEXT_F(MSG_STEPS_PER_MM)); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(1), F("Steps/mm X")); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(2), F("Steps/mm Y")); - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(3), F("Steps/mm Z")); + #else + DWIN_Frame_TitleCopy(1, 144, 16, 189, 26); // "Steps per mm" + #endif + #ifdef USE_STRING_TITLES + DWIN_Draw_Label(MBASE(1), F("Steps/mm X")); + DWIN_Draw_Label(MBASE(2), F("Steps/mm Y")); + DWIN_Draw_Label(MBASE(3), F("Steps/mm Z")); #if HAS_HOTEND - DWIN_Draw_String(false, true, font8x16, Color_White, Color_Bg_Black, LBLX, MBASE(4), F("Steps/mm E")); + DWIN_Draw_Label(MBASE(4), F("Steps/mm E")); #endif #else - DWIN_Frame_TitleCopy(1, 144, 16, 189, 26); // "Steps per mm" draw_steps_per_mm(MBASE(1)); say_x(103, MBASE(1)); // "Steps-per-mm X" draw_steps_per_mm(MBASE(2)); say_y(103, MBASE(2)); // "Y" draw_steps_per_mm(MBASE(3)); say_z(103, MBASE(3)); // "Z" @@ -3470,14 +3594,17 @@ void DWIN_Update() { } void EachMomentUpdate() { - static millis_t next_rts_update_ms = 0; + static millis_t next_var_update_ms = 0, next_rts_update_ms = 0; + const millis_t ms = millis(); + if (ELAPSED(ms, next_var_update_ms)) { + next_var_update_ms = ms + DWIN_VAR_UPDATE_INTERVAL; + update_variable(); + } + if (PENDING(ms, next_rts_update_ms)) return; next_rts_update_ms = ms + DWIN_SCROLL_UPDATE_INTERVAL; - // variable update - update_variable(); - if (checkkey == PrintProcess) { // if print done if (HMI_flag.print_finish && !HMI_flag.done_confirm_flag) { @@ -3539,7 +3666,7 @@ void EachMomentUpdate() { static millis_t next_remain_time_update = 0; if (_card_percent > 1 && ELAPSED(ms, next_remain_time_update) && !HMI_flag.heat_flag) { _remain_time = (elapsed.value - dwin_heat_time) / (_card_percent * 0.01f) - (elapsed.value - dwin_heat_time); - next_remain_time_update += SEC_TO_MS(20); + next_remain_time_update += DWIN_REMAIN_TIME_UPDATE_INTERVAL; Draw_Print_ProgressRemain(); } } @@ -3602,6 +3729,7 @@ void EachMomentUpdate() { Draw_Status_Area(true); } #endif + DWIN_UpdateLCD(); } @@ -3642,7 +3770,7 @@ void DWIN_HandleScreen() { #if HAS_HEATED_BED case BedTemp: HMI_BedTemp(); break; #endif - #if HAS_PREHEAT + #if HAS_PREHEAT && HAS_FAN case FanSpeed: HMI_FanSpeed(); break; #endif case PrintSpeed: HMI_PrintSpeed(); break; diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.h b/Marlin/src/lcd/dwin/e3v2/dwin.h index 57f987314586..217127ed11b1 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.h +++ b/Marlin/src/lcd/dwin/e3v2/dwin.h @@ -236,7 +236,7 @@ extern millis_t dwin_heat_time; typedef struct { TERN_(HAS_HOTEND, int16_t E_Temp = 0); TERN_(HAS_HEATED_BED, int16_t Bed_Temp = 0); - TERN_(HAS_PREHEAT, int16_t Fan_speed = 0); + TERN_(HAS_FAN, int16_t Fan_speed = 0); int16_t print_speed = 100; float Max_Feedspeed = 0; float Max_Acceleration = 0; @@ -270,10 +270,7 @@ typedef struct { #if HAS_LEVELING bool leveling_offset_flag:1; #endif - #if HAS_FAN - AxisEnum feedspeed_axis; - #endif - AxisEnum acc_axis, jerk_axis, step_axis; + AxisEnum feedspeed_axis, acc_axis, jerk_axis, step_axis; } HMI_Flag_t; extern HMI_value_t HMI_ValueStruct; diff --git a/Marlin/src/lcd/extui/dgus_lcd.cpp b/Marlin/src/lcd/extui/dgus_lcd.cpp index 9fcb6c8d1328..9e6ca1b64cab 100644 --- a/Marlin/src/lcd/extui/dgus_lcd.cpp +++ b/Marlin/src/lcd/extui/dgus_lcd.cpp @@ -21,9 +21,7 @@ */ /** - * dgus_lcd.cpp - * - * DGUS implementation for Marlin by coldtobi, Feb-May 2019 + * lcd/extui/dgus_lcd.cpp */ #include "../../inc/MarlinConfigPre.h" @@ -125,11 +123,10 @@ namespace ExtUI { #if ENABLED(POWER_LOSS_RECOVERY) void onPowerLossResume() { // Called on resume from power-loss - ScreenHandler.GotoScreen(DGUSLCD_SCREEN_POWER_LOSS); + IF_DISABLED(DGUS_LCD_UI_MKS, ScreenHandler.GotoScreen(DGUSLCD_SCREEN_POWER_LOSS)); } #endif - #if HAS_PID_HEATING void onPidTuning(const result_t rst) { // Called for temperature PID tuning result diff --git a/Marlin/src/lcd/extui/lib/anycubic_chiron/FileNavigator.cpp b/Marlin/src/lcd/extui/lib/anycubic_chiron/FileNavigator.cpp index 19f8ec81bc5b..7d813a6ab09e 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_chiron/FileNavigator.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic_chiron/FileNavigator.cpp @@ -114,7 +114,7 @@ namespace Anycubic { } else { // Logical Name - TFTSer.print("/"); + TFTSer.write('/'); if (folderdepth > 0) TFTSer.print(currentfoldername); TFTSer.println(filelist.shortFilename()); diff --git a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp index 61057b5b10e7..97149a407e21 100644 --- a/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp +++ b/Marlin/src/lcd/extui/lib/anycubic_chiron/chiron_tft.cpp @@ -290,9 +290,9 @@ namespace Anycubic { void ChironTFT::SendtoTFT(PGM_P str) { // A helper to print PROGMEN string to the panel #if ACDEBUG(AC_SOME) - serialprintPGM(str); + SERIAL_ECHOPGM_P(str); #endif - while (const char c = pgm_read_byte(str++)) TFTSer.print(c); + while (const char c = pgm_read_byte(str++)) TFTSer.write(c); } void ChironTFT::SendtoTFTLN(PGM_P str = nullptr) { @@ -305,12 +305,12 @@ namespace Anycubic { SERIAL_EOL(); #endif } - TFTSer.println(""); + TFTSer.println(); } bool ChironTFT::ReadTFTCommand() { bool command_ready = false; - while(TFTSer.available() > 0 && command_len < MAX_CMND_LEN) { + while (TFTSer.available() > 0 && command_len < MAX_CMND_LEN) { panel_command[command_len] = TFTSer.read(); if (panel_command[command_len] == '\n') { command_ready = true; @@ -338,7 +338,7 @@ namespace Anycubic { int8_t ChironTFT::Findcmndpos(const char * buff, char q) { int8_t pos = 0; - do { if (buff[pos] == q) return pos; } while(++pos < MAX_CMND_LEN); + do { if (buff[pos] == q) return pos; } while (++pos < MAX_CMND_LEN); return -1; } @@ -578,8 +578,8 @@ namespace Anycubic { case 15: // A15 Resuming from outage if (printer_state == AC_printer_resuming_from_power_outage) { // Need to home here to restore the Z position - injectCommands(AC_cmnd_power_loss_recovery); - injectCommands("M1000"); // home and start recovery + injectCommands_P(AC_cmnd_power_loss_recovery); + injectCommands_P(PSTR("M1000")); // home and start recovery } break; @@ -840,7 +840,7 @@ namespace Anycubic { // Ignore request if printing //if (isPrinting()) break; //injectCommands_P(PSTR("M500\nM420 S1\nG1 Z10 F240\nG1 X0 Y0 F6000")); - //TFTSer.println(""); + //TFTSer.println(); } break; // A33 firmware info request seet PanelInfo() diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp index c7cd76733fc1..702c5cc47ec4 100644 --- a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp @@ -20,14 +20,12 @@ * */ -/* DGUS implementation written by coldtobi in 2019 for Marlin */ - #include "../../../../inc/MarlinConfigPre.h" #if HAS_DGUS_LCD #if HOTENDS > 2 - #error "More than 2 hotends not implemented on the Display UI design." + #warning "More than 2 hotends not implemented on DGUS Display UI." #endif #include "../../ui_api.h" @@ -46,6 +44,8 @@ #include "DGUSVPVariable.h" #include "DGUSDisplayDef.h" +DGUSDisplay dgusdisplay; + // Preamble... 2 Bytes, usually 0x5A 0xA5, but configurable constexpr uint8_t DGUS_HEADER1 = 0x5A; constexpr uint8_t DGUS_HEADER2 = 0xA5; @@ -62,8 +62,10 @@ void DGUSDisplay::InitDisplay() { #define LCD_BAUDRATE 115200 #endif LCD_SERIAL.begin(LCD_BAUDRATE); - if (TERN1(POWER_LOSS_RECOVERY, !recovery.valid())) - RequestScreen(TERN(SHOW_BOOTSCREEN, DGUSLCD_SCREEN_BOOT, DGUSLCD_SCREEN_MAIN)); + #if BOTH(DGUS_LCD_UI_MKS, POWER_LOSS_RECOVERY) + if (!recovery.valid()) delay(LOGO_TIME_DELAY); + #endif + RequestScreen(TERN(SHOW_BOOTSCREEN, DGUSLCD_SCREEN_BOOT, DGUSLCD_SCREEN_MAIN)); } void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t valueslen, bool isstr) { @@ -82,12 +84,12 @@ void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t values } void DGUSDisplay::WriteVariable(uint16_t adr, uint16_t value) { - value = (value & 0xffU) << 8U | (value >> 8U); + value = (value & 0xFFU) << 8U | (value >> 8U); WriteVariable(adr, static_cast(&value), sizeof(uint16_t)); } void DGUSDisplay::WriteVariable(uint16_t adr, int16_t value) { - value = (value & 0xffU) << 8U | (value >> 8U); + value = (value & 0xFFU) << 8U | (value >> 8U); WriteVariable(adr, static_cast(&value), sizeof(uint16_t)); } @@ -99,15 +101,21 @@ void DGUSDisplay::WriteVariable(uint16_t adr, int8_t value) { WriteVariable(adr, static_cast(&value), sizeof(int8_t)); } +#if ENABLED(DGUS_LCD_UI_MKS) + void DGUSDisplay::MKS_WriteVariable(uint16_t adr, uint8_t value) { + WriteVariable(adr, static_cast(&value), sizeof(uint8_t)); + } +#endif + void DGUSDisplay::WriteVariable(uint16_t adr, long value) { - union { long l; char lb[4]; } endian; - char tmp[4]; - endian.l = value; - tmp[0] = endian.lb[3]; - tmp[1] = endian.lb[2]; - tmp[2] = endian.lb[1]; - tmp[3] = endian.lb[0]; - WriteVariable(adr, static_cast(&tmp), sizeof(long)); + union { long l; char lb[4]; } endian; + char tmp[4]; + endian.l = value; + tmp[0] = endian.lb[3]; + tmp[1] = endian.lb[2]; + tmp[2] = endian.lb[1]; + tmp[3] = endian.lb[0]; + WriteVariable(adr, static_cast(&tmp), sizeof(long)); } void DGUSDisplay::WriteVariablePGM(uint16_t adr, const void* values, uint8_t valueslen, bool isstr) { diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h index 88c119566cc1..6e0ee3053fd6 100644 --- a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h +++ b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.h @@ -21,7 +21,9 @@ */ #pragma once -/* DGUS implementation written by coldtobi in 2019 for Marlin */ +/** + * lcd/extui/lib/dgus/DGUSDisplay.h + */ #include "../../../../inc/MarlinConfigPre.h" @@ -34,6 +36,7 @@ enum DGUSLCD_Screens : uint8_t; +//#define DEBUG_DGUSLCD #define DEBUG_OUT ENABLED(DEBUG_DGUSLCD) #include "../../../../core/debug_out.h" @@ -60,6 +63,8 @@ class DGUSDisplay { static void WriteVariable(uint16_t adr, uint8_t value); static void WriteVariable(uint16_t adr, int8_t value); static void WriteVariable(uint16_t adr, long value); + static void MKS_WriteVariable(uint16_t adr, uint8_t value); + // Utility functions for bridging ui_api and dbus template diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplayDef.h b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplayDef.h index b34a04875d1a..0b6894359334 100644 --- a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplayDef.h +++ b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplayDef.h @@ -21,15 +21,16 @@ */ #pragma once -/* DGUS implementation written by coldtobi in 2019 for Marlin */ +/** + * lcd/extui/lib/dgus/DGUSDisplayDef.h + * Defines the interaction between Marlin and the display firmware + */ #include "DGUSVPVariable.h" #include -// This file defines the interaction between Marlin and the display firmware. - -// information on which screen which VP is displayed +// Information on which screen which VP is displayed. // As this is a sparse table, two arrays are needed: // one to list the VPs of one screen and one to map screens to the lists. // (Strictly this would not be necessary, but allows to only send data the display needs and reducing load on Marlin) @@ -47,6 +48,8 @@ extern const struct DGUS_VP_Variable ListOfVP[]; #if ENABLED(DGUS_LCD_UI_ORIGIN) #include "origin/DGUSDisplayDef.h" +#elif ENABLED(DGUS_LCD_UI_MKS) + #include "mks/DGUSDisplayDef.h" #elif ENABLED(DGUS_LCD_UI_FYSETC) #include "fysetc/DGUSDisplayDef.h" #elif ENABLED(DGUS_LCD_UI_HIPRECY) diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp index 77feacf4a942..9b0c329de2b5 100644 --- a/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp @@ -25,35 +25,24 @@ #if HAS_DGUS_LCD #include "DGUSScreenHandler.h" -#include "DGUSDisplay.h" -#include "DGUSVPVariable.h" -#include "DGUSDisplayDef.h" -#include "../../ui_api.h" #include "../../../../MarlinCore.h" +#include "../../../../gcode/queue.h" +#include "../../../../libs/duration_t.h" +#include "../../../../module/settings.h" #include "../../../../module/temperature.h" #include "../../../../module/motion.h" -#include "../../../../gcode/queue.h" #include "../../../../module/planner.h" -#include "../../../../sd/cardreader.h" -#include "../../../../libs/duration_t.h" #include "../../../../module/printcounter.h" +#include "../../../../sd/cardreader.h" #if ENABLED(POWER_LOSS_RECOVERY) #include "../../../../feature/powerloss.h" #endif -uint16_t DGUSScreenHandler::ConfirmVP; - -#if ENABLED(SDSUPPORT) - int16_t DGUSScreenHandler::top_file = 0; - int16_t DGUSScreenHandler::file_to_print = 0; - static ExtUI::FileList filelist; -#endif - -void (*DGUSScreenHandler::confirm_action_cb)() = nullptr; +DGUSScreenHandler ScreenHandler; -//DGUSScreenHandler ScreenHandler; +uint16_t DGUSScreenHandler::ConfirmVP; DGUSLCD_Screens DGUSScreenHandler::current_screen; DGUSLCD_Screens DGUSScreenHandler::past_screens[NUM_PAST_SCREENS]; @@ -61,10 +50,17 @@ uint8_t DGUSScreenHandler::update_ptr; uint16_t DGUSScreenHandler::skipVP; bool DGUSScreenHandler::ScreenComplete; -//DGUSDisplay dgusdisplay; +void (*DGUSScreenHandler::confirm_action_cb)() = nullptr; -// endianness swap -uint16_t swap16(const uint16_t value) { return (value & 0xffU) << 8U | (value >> 8U); } +#if ENABLED(SDSUPPORT) + int16_t DGUSScreenHandler::top_file = 0, + DGUSScreenHandler::file_to_print = 0; + static ExtUI::FileList filelist; +#endif + +#if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + filament_data_t filament_data; +#endif void DGUSScreenHandler::sendinfoscreen(const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool l4inflash) { DGUS_VP_Variable ramcopy; @@ -87,14 +83,12 @@ void DGUSScreenHandler::sendinfoscreen(const char* line1, const char* line2, con } void DGUSScreenHandler::HandleUserConfirmationPopUp(uint16_t VP, const char* line1, const char* line2, const char* line3, const char* line4, bool l1, bool l2, bool l3, bool l4) { - if (current_screen == DGUSLCD_SCREEN_CONFIRM) { - // Already showing a pop up, so we need to cancel that first. + if (current_screen == DGUSLCD_SCREEN_CONFIRM) // Already showing a pop up, so we need to cancel that first. PopToOldScreen(); - } ConfirmVP = VP; sendinfoscreen(line1, line2, line3, line4, l1, l2, l3, l4); - ScreenHandler.GotoScreen(DGUSLCD_SCREEN_CONFIRM); + GotoScreen(DGUSLCD_SCREEN_CONFIRM); } void DGUSScreenHandler::setstatusmessage(const char *msg) { @@ -130,7 +124,7 @@ void DGUSScreenHandler::DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var) { if (var.memadr) { //DEBUG_ECHOPAIR(" DGUS_LCD_SendWordValueToDisplay ", var.VP); //DEBUG_ECHOLNPAIR(" data ", *(uint16_t *)var.memadr); - uint16_t tmp = *(uint8_t *) var.memadr +1 ; // +1 -> avoid rounding issues for the display. + uint16_t tmp = *(uint8_t *) var.memadr + 1; // +1 -> avoid rounding issues for the display. tmp = map(tmp, 0, 255, 0, 100); dgusdisplay.WriteVariable(var.VP, tmp); } @@ -157,7 +151,9 @@ void DGUSScreenHandler::DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var) { void DGUSScreenHandler::DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr) { if (var.memadr) { uint16_t value = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("FAN value get:", value); *(uint8_t*)var.memadr = map(constrain(value, 0, 100), 0, 100, 0, 255); + DEBUG_ECHOLNPAIR("FAN value change:", *(uint8_t*)var.memadr); } } @@ -234,6 +230,7 @@ void DGUSScreenHandler::DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var) { // Send fan status value to the display. #if HAS_FAN + void DGUSScreenHandler::DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var) { if (var.memadr) { DEBUG_ECHOPAIR(" DGUSLCD_SendFanStatusToDisplay ", var.VP); @@ -243,6 +240,7 @@ void DGUSScreenHandler::DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var) { dgusdisplay.WriteVariable(var.VP, data_to_send); } } + #endif // Send heater status value to the display. @@ -257,6 +255,7 @@ void DGUSScreenHandler::DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var) } #if ENABLED(DGUS_UI_WAITING) + void DGUSScreenHandler::DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var) { // In FYSETC UI design there are 10 statuses to loop static uint16_t period = 0; @@ -270,6 +269,7 @@ void DGUSScreenHandler::DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var) period = 0; } } + #endif #if ENABLED(SDSUPPORT) @@ -319,7 +319,7 @@ void DGUSScreenHandler::DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var) DEBUG_ECHOPAIR("new topfile adjusted:", top_file); } else if (!filelist.isAtRootDir()) { - filelist.upDir(); + IF_DISABLED(DGUS_LCD_UI_MKS, filelist.upDir()); top_file = 0; ForceCompleteUpdate(); } @@ -327,54 +327,6 @@ void DGUSScreenHandler::DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var) if (old_top != top_file) ForceCompleteUpdate(); } - void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file; - if (touched_nr > filelist.count()) return; - if (!filelist.seek(touched_nr)) return; - if (filelist.isDir()) { - filelist.changeDir(filelist.filename()); - top_file = 0; - ForceCompleteUpdate(); - return; - } - - #if ENABLED(DGUS_PRINT_FILENAME) - // Send print filename - dgusdisplay.WriteVariable(VP_SD_Print_Filename, filelist.filename(), VP_SD_FileName_LEN, true); - #endif - - // Setup Confirmation screen - file_to_print = touched_nr; - HandleUserConfirmationPopUp(VP_SD_FileSelectConfirm, nullptr, PSTR("Print file"), filelist.filename(), PSTR("from SD Card?"), true, true, false, true); - } - - void DGUSScreenHandler::DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr) { - if (!filelist.seek(file_to_print)) return; - ExtUI::printFile(filelist.shortFilename()); - ScreenHandler.GotoScreen( - #if ENABLED(DGUS_LCD_UI_ORIGIN) - DGUSLCD_SCREEN_STATUS - #else - DGUSLCD_SCREEN_SDPRINTMANIPULATION - #endif - ); - } - - void DGUSScreenHandler::DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr) { - if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes. - switch (swap16(*(uint16_t*)val_ptr)) { - case 0: // Resume - if (ExtUI::isPrintingFromMediaPaused()) ExtUI::resumePrint(); - break; - case 1: // Pause - if (!ExtUI::isPrintingFromMediaPaused()) ExtUI::pausePrint(); - break; - case 2: // Abort - ScreenHandler.HandleUserConfirmationPopUp(VP_SD_AbortPrintConfirmed, nullptr, PSTR("Abort printing"), filelist.filename(), PSTR("?"), true, true, false, true); - break; - } - } - void DGUSScreenHandler::DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr) { ExtUI::stopPrint(); GotoScreen(DGUSLCD_SCREEN_MAIN); @@ -385,36 +337,11 @@ void DGUSScreenHandler::DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var) GotoScreen(DGUSLCD_SCREEN_SDPRINTTUNE); } - void DGUSScreenHandler::DGUSLCD_SD_SendFilename(DGUS_VP_Variable& var) { - uint16_t target_line = (var.VP - VP_SD_FileName0) / VP_SD_FileName_LEN; - if (target_line > DGUS_SD_FILESPERSCREEN) return; - char tmpfilename[VP_SD_FileName_LEN + 1] = ""; - var.memadr = (void*)tmpfilename; - if (filelist.seek(top_file + target_line)) - snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s%c"), filelist.filename(), filelist.isDir() ? '/' : 0); - DGUSLCD_SendStringToDisplay(var); - } - - void DGUSScreenHandler::SDCardInserted() { - top_file = 0; - filelist.refresh(); - auto cs = ScreenHandler.getCurrentScreen(); - if (cs == DGUSLCD_SCREEN_MAIN || cs == DGUSLCD_SCREEN_STATUS) - ScreenHandler.GotoScreen(DGUSLCD_SCREEN_SDFILELIST); - } - - void DGUSScreenHandler::SDCardRemoved() { - if (current_screen == DGUSLCD_SCREEN_SDFILELIST - || (current_screen == DGUSLCD_SCREEN_CONFIRM && (ConfirmVP == VP_SD_AbortPrintConfirmed || ConfirmVP == VP_SD_FileSelectConfirm)) - || current_screen == DGUSLCD_SCREEN_SDPRINTMANIPULATION - ) ScreenHandler.GotoScreen(DGUSLCD_SCREEN_MAIN); - } - void DGUSScreenHandler::SDCardError() { DGUSScreenHandler::SDCardRemoved(); - ScreenHandler.sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("SD card error"), nullptr, true, true, true, true); - ScreenHandler.SetupConfirmAction(nullptr); - ScreenHandler.GotoScreen(DGUSLCD_SCREEN_POPUP); + sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("SD card error"), nullptr, true, true, true, true); + SetupConfirmAction(nullptr); + GotoScreen(DGUSLCD_SCREEN_POPUP); } #endif // SDSUPPORT @@ -428,7 +355,7 @@ void DGUSScreenHandler::ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr) const uint16_t* DGUSLCD_FindScreenVPMapList(uint8_t screen) { const uint16_t *ret; const struct VPMapping *map = VPMap; - while (ret = (uint16_t*) pgm_read_ptr(&(map->VPList))) { + while ((ret = (uint16_t*) pgm_read_ptr(&(map->VPList)))) { if (pgm_read_byte(&(map->screen)) == screen) return ret; map++; } @@ -455,31 +382,9 @@ void DGUSScreenHandler::ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ } } -void DGUSScreenHandler::ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr) { - uint8_t *tmp = (uint8_t*)val_ptr; - - // The keycode in target is coded as , so 0x0100A means - // from screen 1 (main) to 10 (temperature). DGUSLCD_SCREEN_POPUP is special, - // meaning "return to previous screen" - DGUSLCD_Screens target = (DGUSLCD_Screens)tmp[1]; - - if (target == DGUSLCD_SCREEN_POPUP) { - // special handling for popup is to return to previous menu - if (current_screen == DGUSLCD_SCREEN_POPUP && confirm_action_cb) confirm_action_cb(); - PopToOldScreen(); - return; - } - - UpdateNewScreen(target); - - #ifdef DEBUG_DGUSLCD - if (!DGUSLCD_FindScreenVPMapList(target)) DEBUG_ECHOLNPAIR("WARNING: No screen Mapping found for ", target); - #endif -} - void DGUSScreenHandler::HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr) { thermalManager.disable_all_heaters(); - ScreenHandler.ForceCompleteUpdate(); // hint to send all data. + ForceCompleteUpdate(); // hint to send all data. } void DGUSScreenHandler::HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr) { @@ -498,7 +403,7 @@ void DGUSScreenHandler::HandleTemperatureChanged(DGUS_VP_Variable &var, void *va case VP_T_E1_Set: thermalManager.setTargetHotend(newvalue, 1); acceptedvalue = thermalManager.temp_hotend[1].target; - break; + break; #endif #if HAS_HEATED_BED case VP_T_Bed_Set: @@ -510,7 +415,7 @@ void DGUSScreenHandler::HandleTemperatureChanged(DGUS_VP_Variable &var, void *va // reply to display the new value to update the view if the new value was rejected by the Thermal Manager. if (newvalue != acceptedvalue && var.send_to_display_handler) var.send_to_display_handler(var); - ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel } void DGUSScreenHandler::HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr) { @@ -528,7 +433,7 @@ void DGUSScreenHandler::HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_p } planner.set_flow(target_extruder, newvalue); - ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel #else UNUSED(var); UNUSED(val_ptr); #endif @@ -563,97 +468,6 @@ void DGUSScreenHandler::HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr } #endif -void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { - DEBUG_ECHOLNPGM("HandleManualMove"); - - int16_t movevalue = swap16(*(uint16_t*)val_ptr); - #if ENABLED(DGUS_UI_MOVE_DIS_OPTION) - if (movevalue) { - const uint16_t choice = *(uint16_t*)var.memadr; - movevalue = movevalue < 0 ? -choice : choice; - } - #endif - char axiscode; - unsigned int speed = 1500; //FIXME: get default feedrate for manual moves, dont hardcode. - - switch (var.VP) { - default: return; - - case VP_MOVE_X: - axiscode = 'X'; - if (!ExtUI::canMove(ExtUI::axis_t::X)) goto cannotmove; - break; - - case VP_MOVE_Y: - axiscode = 'Y'; - if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove; - break; - - case VP_MOVE_Z: - axiscode = 'Z'; - speed = 300; // default to 5mm/s - if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove; - break; - - case VP_HOME_ALL: // only used for homing - axiscode = '\0'; - movevalue = 0; // ignore value sent from display, this VP is _ONLY_ for homing. - break; - } - - if (!movevalue) { - // homing - DEBUG_ECHOPAIR(" homing ", axiscode); - char buf[6] = "G28 X"; - buf[4] = axiscode; - //DEBUG_ECHOPAIR(" ", buf); - queue.enqueue_one_now(buf); - //DEBUG_ECHOLNPGM(" ✓"); - ScreenHandler.ForceCompleteUpdate(); - return; - } - else { - //movement - DEBUG_ECHOPAIR(" move ", axiscode); - bool old_relative_mode = relative_mode; - if (!relative_mode) { - //DEBUG_ECHOPGM(" G91"); - queue.enqueue_now_P(PSTR("G91")); - //DEBUG_ECHOPGM(" ✓ "); - } - char buf[32]; // G1 X9999.99 F12345 - unsigned int backup_speed = MMS_TO_MMM(feedrate_mm_s); - char sign[]="\0"; - int16_t value = movevalue / 100; - if (movevalue < 0) { value = -value; sign[0] = '-'; } - int16_t fraction = ABS(movevalue) % 100; - snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed); - //DEBUG_ECHOPAIR(" ", buf); - queue.enqueue_one_now(buf); - //DEBUG_ECHOLNPGM(" ✓ "); - if (backup_speed != speed) { - snprintf_P(buf, 32, PSTR("G0 F%d"), backup_speed); - queue.enqueue_one_now(buf); - //DEBUG_ECHOPAIR(" ", buf); - } - //while (!enqueue_and_echo_command(buf)) idle(); - //DEBUG_ECHOLNPGM(" ✓ "); - if (!old_relative_mode) { - //DEBUG_ECHOPGM("G90"); - queue.enqueue_now_P(PSTR("G90")); - //DEBUG_ECHOPGM(" ✓ "); - } - } - - ScreenHandler.ForceCompleteUpdate(); - DEBUG_ECHOLNPGM("manmv done."); - return; - - cannotmove: - DEBUG_ECHOLNPAIR(" cannot move ", axiscode); - return; -} - void DGUSScreenHandler::HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("HandleMotorLockUnlock"); @@ -665,22 +479,6 @@ void DGUSScreenHandler::HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_p queue.enqueue_one_now(buf); } -#if ENABLED(POWER_LOSS_RECOVERY) - - void DGUSScreenHandler::HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t value = swap16(*(uint16_t*)val_ptr); - if (value) { - queue.inject_P(PSTR("M1000")); - ScreenHandler.GotoScreen(DGUSLCD_SCREEN_SDPRINTMANIPULATION); - } - else { - recovery.cancel(); - ScreenHandler.GotoScreen(DGUSLCD_SCREEN_STATUS); - } - } - -#endif - void DGUSScreenHandler::HandleSettings(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("HandleSettings"); uint16_t value = swap16(*(uint16_t*)val_ptr); @@ -688,10 +486,11 @@ void DGUSScreenHandler::HandleSettings(DGUS_VP_Variable &var, void *val_ptr) { default: break; case 1: TERN_(PRINTCOUNTER, print_job_timer.initStats()); - queue.inject_P(PSTR("M502\nM500")); + settings.reset(); + settings.save(); break; - case 2: queue.inject_P(PSTR("M501")); break; - case 3: queue.inject_P(PSTR("M500")); break; + case 2: settings.load(); break; + case 3: settings.save(); break; } } @@ -700,7 +499,7 @@ void DGUSScreenHandler::HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ uint16_t value_raw = swap16(*(uint16_t*)val_ptr); DEBUG_ECHOLNPAIR("value_raw:", value_raw); - float value = (float)value_raw/10; + float value = (float)value_raw / 10; ExtUI::axis_t axis; switch (var.VP) { case VP_X_STEP_PER_MM: axis = ExtUI::axis_t::X; break; @@ -711,7 +510,7 @@ void DGUSScreenHandler::HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ DEBUG_ECHOLNPAIR_F("value:", value); ExtUI::setAxisSteps_per_mm(value, axis); DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisSteps_per_mm(axis)); - ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel return; } @@ -720,56 +519,24 @@ void DGUSScreenHandler::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, vo uint16_t value_raw = swap16(*(uint16_t*)val_ptr); DEBUG_ECHOLNPAIR("value_raw:", value_raw); - float value = (float)value_raw/10; + float value = (float)value_raw / 10; ExtUI::extruder_t extruder; switch (var.VP) { default: return; - #if HOTENDS >= 1 - case VP_E0_STEP_PER_MM: extruder = ExtUI::extruder_t::E0; break; - #endif - #if HOTENDS >= 2 - case VP_E1_STEP_PER_MM: extruder = ExtUI::extruder_t::E1; break; - #endif - } - DEBUG_ECHOLNPAIR_F("value:", value); - ExtUI::setAxisSteps_per_mm(value,extruder); - DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisSteps_per_mm(extruder)); - ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; -} - -#if HAS_PID_HEATING - void DGUSScreenHandler::HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr) { - uint16_t rawvalue = swap16(*(uint16_t*)val_ptr); - DEBUG_ECHOLNPAIR("V1:", rawvalue); - float value = (float)rawvalue / 10; - DEBUG_ECHOLNPAIR("V2:", value); - float newvalue = 0; - - switch (var.VP) { - default: return; #if HOTENDS >= 1 - case VP_E0_PID_P: newvalue = value; break; - case VP_E0_PID_I: newvalue = scalePID_i(value); break; - case VP_E0_PID_D: newvalue = scalePID_d(value); break; + case VP_E0_STEP_PER_MM: extruder = ExtUI::extruder_t::E0; break; #endif #if HOTENDS >= 2 - case VP_E1_PID_P: newvalue = value; break; - case VP_E1_PID_I: newvalue = scalePID_i(value); break; - case VP_E1_PID_D: newvalue = scalePID_d(value); break; + case VP_E1_STEP_PER_MM: extruder = ExtUI::extruder_t::E1; break; #endif - #if HAS_HEATED_BED - case VP_BED_PID_P: newvalue = value; break; - case VP_BED_PID_I: newvalue = scalePID_i(value); break; - case VP_BED_PID_D: newvalue = scalePID_d(value); break; - #endif - } - - DEBUG_ECHOLNPAIR_F("V3:", newvalue); - *(float *)var.memadr = newvalue; - ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel } + DEBUG_ECHOLNPAIR_F("value:", value); + ExtUI::setAxisSteps_per_mm(value, extruder); + DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisSteps_per_mm(extruder)); + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel +} +#if HAS_PID_HEATING void DGUSScreenHandler::HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr) { DEBUG_ECHOLNPGM("HandlePIDAutotune"); @@ -777,23 +544,23 @@ void DGUSScreenHandler::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, vo switch (var.VP) { default: break; - #if ENABLED(PIDTEMP) - #if HOTENDS >= 1 - case VP_PID_AUTOTUNE_E0: // Autotune Extruder 0 - sprintf(buf, "M303 E%d C5 S210 U1", ExtUI::extruder_t::E0); - break; + #if ENABLED(PIDTEMP) + #if HOTENDS >= 1 + case VP_PID_AUTOTUNE_E0: // Autotune Extruder 0 + sprintf_P(buf, PSTR("M303 E%d C5 S210 U1"), ExtUI::extruder_t::E0); + break; + #endif + #if HOTENDS >= 2 + case VP_PID_AUTOTUNE_E1: + sprintf_P(buf, PSTR("M303 E%d C5 S210 U1"), ExtUI::extruder_t::E1); + break; + #endif #endif - #if HOTENDS >= 2 - case VP_PID_AUTOTUNE_E1: - sprintf(buf, "M303 E%d C5 S210 U1", ExtUI::extruder_t::E1); + #if ENABLED(PIDTEMPBED) + case VP_PID_AUTOTUNE_BED: + sprintf_P(buf, PSTR("M303 E-1 C5 S70 U1")); break; #endif - #endif - #if ENABLED(PIDTEMPBED) - case VP_PID_AUTOTUNE_BED: - sprintf(buf, "M303 E-1 C5 S70 U1"); - break; - #endif } if (buf[0]) queue.enqueue_one_now(buf); @@ -803,7 +570,7 @@ void DGUSScreenHandler::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, vo GotoScreen(DGUSLCD_SCREEN_WAITING); #endif } -#endif +#endif // HAS_PID_HEATING #if HAS_BED_PROBE void DGUSScreenHandler::HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr) { @@ -811,19 +578,7 @@ void DGUSScreenHandler::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, vo const float offset = float(int16_t(swap16(*(uint16_t*)val_ptr))) / 100.0f; ExtUI::setZOffset_mm(offset); - ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel - return; - } -#endif - -#if ENABLED(BABYSTEPPING) - void DGUSScreenHandler::HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr) { - DEBUG_ECHOLNPGM("HandleLiveAdjustZ"); - - int16_t flag = swap16(*(uint16_t*)val_ptr); - int16_t steps = flag ? -20 : 20; - ExtUI::smartAdjustAxis_steps(steps, ExtUI::axis_t::Z, true); - ScreenHandler.ForceCompleteUpdate(); + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel return; } #endif @@ -849,8 +604,8 @@ void DGUSScreenHandler::HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr #if HOTENDS >= 3 case VP_E2_CONTROL: #endif - preheat_temp = PREHEAT_1_TEMP_HOTEND; - break; + preheat_temp = PREHEAT_1_TEMP_HOTEND; + break; case VP_BED_CONTROL: preheat_temp = PREHEAT_1_TEMP_BED; @@ -900,149 +655,49 @@ void DGUSScreenHandler::HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr switch (var.VP) { default: return; - #if HOTENDS >= 1 - case VP_E0_BED_PREHEAT: - thermalManager.setTargetHotend(e_temp, 0); - TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(bed_temp)); - break; - #endif - #if HOTENDS >= 2 - case VP_E1_BED_PREHEAT: - thermalManager.setTargetHotend(e_temp, 1); - TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(bed_temp)); - break; - #endif + #if HOTENDS >= 1 + case VP_E0_BED_PREHEAT: + thermalManager.setTargetHotend(e_temp, 0); + TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(bed_temp)); + break; + #endif + #if HOTENDS >= 2 + case VP_E1_BED_PREHEAT: + thermalManager.setTargetHotend(e_temp, 1); + TERN_(HAS_HEATED_BED, thermalManager.setTargetBed(bed_temp)); + break; + #endif } // Go to the preheat screen to show the heating progress GotoScreen(DGUSLCD_SCREEN_PREHEAT); } -#endif - -#if ENABLED(DGUS_FILAMENT_LOADUNLOAD) - - typedef struct { - ExtUI::extruder_t extruder; // which extruder to operate - uint8_t action; // load or unload - bool heated; // heating done ? - float purge_length; // the length to extrude before unload, prevent filament jam - } filament_data_t; - - static filament_data_t filament_data; +#endif // DGUS_PREHEAT_UI - void DGUSScreenHandler::HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr) { - DEBUG_ECHOLNPGM("HandleFilamentOption"); - - uint8_t e_temp = 0; - filament_data.heated = false; - uint16_t preheat_option = swap16(*(uint16_t*)val_ptr); - if (preheat_option <= 8) // Load filament type - filament_data.action = 1; - else if (preheat_option >= 10) { // Unload filament type - preheat_option -= 10; - filament_data.action = 2; - filament_data.purge_length = DGUS_FILAMENT_PURGE_LENGTH; - } - else // Cancel filament operation - filament_data.action = 0; - - switch (preheat_option) { - case 0: // Load PLA - #ifdef PREHEAT_1_TEMP_HOTEND - e_temp = PREHEAT_1_TEMP_HOTEND; - #endif - break; - case 1: // Load ABS - TERN_(PREHEAT_2_TEMP_HOTEND, e_temp = PREHEAT_2_TEMP_HOTEND); - break; - case 2: // Load PET - #ifdef PREHEAT_3_TEMP_HOTEND - e_temp = PREHEAT_3_TEMP_HOTEND; - #endif - break; - case 3: // Load FLEX - #ifdef PREHEAT_4_TEMP_HOTEND - e_temp = PREHEAT_4_TEMP_HOTEND; - #endif - break; - case 9: // Cool down - default: - e_temp = 0; - break; - } +#if ENABLED(POWER_LOSS_RECOVERY) - if (filament_data.action == 0) { // Go back to utility screen - #if HOTENDS >= 1 - thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E0); - #endif - #if HOTENDS >= 2 - thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E1); - #endif - GotoScreen(DGUSLCD_SCREEN_UTILITY); + void DGUSScreenHandler::HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t value = swap16(*(uint16_t*)val_ptr); + if (value) { + queue.inject_P(PSTR("M1000")); + dgusdisplay.WriteVariable(VP_SD_Print_Filename, filelist.filename(), 32, true); + GotoScreen(PLR_SCREEN_RECOVER); } - else { // Go to the preheat screen to show the heating progress - switch (var.VP) { - default: return; - #if HOTENDS >= 1 - case VP_E0_FILAMENT_LOAD_UNLOAD: - filament_data.extruder = ExtUI::extruder_t::E0; - thermalManager.setTargetHotend(e_temp, filament_data.extruder); - break; - #endif - #if HOTENDS >= 2 - case VP_E1_FILAMENT_LOAD_UNLOAD: - filament_data.extruder = ExtUI::extruder_t::E1; - thermalManager.setTargetHotend(e_temp, filament_data.extruder); - break; - #endif - } - GotoScreen(DGUSLCD_SCREEN_FILAMENT_HEATING); + else { + recovery.cancel(); + GotoScreen(PLR_SCREEN_CANCEL); } } - void DGUSScreenHandler::HandleFilamentLoadUnload(DGUS_VP_Variable &var) { - DEBUG_ECHOLNPGM("HandleFilamentLoadUnload"); - if (filament_data.action <= 0) return; - - // If we close to the target temperature, we can start load or unload the filament - if (thermalManager.hotEnoughToExtrude(filament_data.extruder) && \ - thermalManager.targetHotEnoughToExtrude(filament_data.extruder)) { - float movevalue = DGUS_FILAMENT_LOAD_LENGTH_PER_TIME; - - if (filament_data.action == 1) { // load filament - if (!filament_data.heated) { - GotoScreen(DGUSLCD_SCREEN_FILAMENT_LOADING); - filament_data.heated = true; - } - movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder)+movevalue; - } - else { // unload filament - if (!filament_data.heated) { - GotoScreen(DGUSLCD_SCREEN_FILAMENT_UNLOADING); - filament_data.heated = true; - } - // Before unloading extrude to prevent jamming - if (filament_data.purge_length >= 0) { - movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue; - filament_data.purge_length -= movevalue; - } - else - movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) - movevalue; - } - ExtUI::setAxisPosition_mm(movevalue, filament_data.extruder); - } - } #endif void DGUSScreenHandler::UpdateNewScreen(DGUSLCD_Screens newscreen, bool popup) { DEBUG_ECHOLNPAIR("SetNewScreen: ", newscreen); - if (!popup) { memmove(&past_screens[1], &past_screens[0], sizeof(past_screens) - 1); past_screens[0] = current_screen; } - current_screen = newscreen; skipVP = 0; ForceCompleteUpdate(); @@ -1062,7 +717,7 @@ void DGUSScreenHandler::UpdateScreenVPData() { if (!VPList) { DEBUG_ECHOLNPAIR(" NO SCREEN FOR: ", current_screen); ScreenComplete = true; - return; // nothing to do, likely a bug or boring screen. + return; // nothing to do, likely a bug or boring screen. } // Round-robin updating of all VPs. @@ -1076,14 +731,14 @@ void DGUSScreenHandler::UpdateScreenVPData() { update_ptr = 0; DEBUG_ECHOLNPGM(" UpdateScreenVPData done"); ScreenComplete = true; - return; // Screen completed. + return; // Screen completed. } if (VP == skipVP) { skipVP = 0; continue; } DGUS_VP_Variable rcpy; if (populate_VPVar(VP, &rcpy)) { - uint8_t expected_tx = 6 + rcpy.size; // expected overhead is 6 bytes + payload. + uint8_t expected_tx = 6 + rcpy.size; // expected overhead is 6 bytes + payload. // Send the VP to the display, but try to avoid overrunning the Tx Buffer. // But send at least one VP, to avoid getting stalled. if (rcpy.send_to_display_handler && (!sent_one || expected_tx <= dgusdisplay.GetFreeTxBuffer())) { @@ -1092,11 +747,11 @@ void DGUSScreenHandler::UpdateScreenVPData() { rcpy.send_to_display_handler(rcpy); } else { - //auto x=dgusdisplay.GetFreeTxBuffer(); + // auto x=dgusdisplay.GetFreeTxBuffer(); //DEBUG_ECHOLNPAIR(" tx almost full: ", x); //DEBUG_ECHOPAIR(" update_ptr ", update_ptr); ScreenComplete = false; - return; // please call again! + return; // please call again! } } @@ -1108,29 +763,6 @@ void DGUSScreenHandler::GotoScreen(DGUSLCD_Screens screen, bool ispopup) { UpdateNewScreen(screen, ispopup); } -bool DGUSScreenHandler::loop() { - dgusdisplay.loop(); - - const millis_t ms = millis(); - static millis_t next_event_ms = 0; - - if (!IsScreenComplete() || ELAPSED(ms, next_event_ms)) { - next_event_ms = ms + DGUS_UPDATE_INTERVAL_MS; - UpdateScreenVPData(); - } - - #if ENABLED(SHOW_BOOTSCREEN) - static bool booted = false; - if (!booted && TERN0(POWER_LOSS_RECOVERY, recovery.valid())) - booted = true; - if (!booted && ELAPSED(ms, BOOTSCREEN_TIMEOUT)) { - booted = true; - GotoScreen(DGUSLCD_SCREEN_MAIN); - } - #endif - return IsScreenComplete(); -} - void DGUSDisplay::RequestScreen(DGUSLCD_Screens screen) { DEBUG_ECHOLNPAIR("GotoScreen ", screen); const unsigned char gotoscreen[] = { 0x5A, 0x01, (unsigned char) (screen >> 8U), (unsigned char) (screen & 0xFFU) }; diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.h b/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.h index df738dbfd144..21e25b3b8856 100644 --- a/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.h +++ b/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.h @@ -21,212 +21,38 @@ */ #pragma once -#include "DGUSDisplay.h" -#include "DGUSVPVariable.h" - -#include "../../../../inc/MarlinConfig.h" - -enum DGUSLCD_Screens : uint8_t; - -class DGUSScreenHandler { -public: - DGUSScreenHandler() = default; - - static bool loop(); - - /// Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen - /// The bools specifing whether the strings are in RAM or FLASH. - static void sendinfoscreen(const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash); - - static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash); - - /// "M117" Message -- msg is a RAM ptr. - static void setstatusmessage(const char* msg); - /// The same for messages from Flash - static void setstatusmessagePGM(PGM_P const msg); - // Callback for VP "Display wants to change screen on idle printer" - static void ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr); - // Callback for VP "Screen has been changed" - static void ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr); - // Callback for VP "All Heaters Off" - static void HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr); - // Hook for "Change this temperature" - static void HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr); - // Hook for "Change Flowrate" - static void HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr); - #if ENABLED(DGUS_UI_MOVE_DIS_OPTION) - // Hook for manual move option - static void HandleManualMoveOption(DGUS_VP_Variable &var, void *val_ptr); - #endif - // Hook for manual move. - static void HandleManualMove(DGUS_VP_Variable &var, void *val_ptr); - // Hook for manual extrude. - static void HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr); - // Hook for motor lock and unlook - static void HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr); - #if ENABLED(POWER_LOSS_RECOVERY) - // Hook for power loss recovery. - static void HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr); - #endif - // Hook for settings - static void HandleSettings(DGUS_VP_Variable &var, void *val_ptr); - static void HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr); - static void HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr); - #if HAS_PID_HEATING - // Hook for "Change this temperature PID para" - static void HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr); - // Hook for PID autotune - static void HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr); - #endif - #if HAS_BED_PROBE - // Hook for "Change probe offset z" - static void HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr); - #endif - #if ENABLED(BABYSTEPPING) - // Hook for live z adjust action - static void HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr); - #endif - #if HAS_FAN - // Hook for fan control - static void HandleFanControl(DGUS_VP_Variable &var, void *val_ptr); - #endif - // Hook for heater control - static void HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr); - #if ENABLED(DGUS_PREHEAT_UI) - // Hook for preheat - static void HandlePreheat(DGUS_VP_Variable &var, void *val_ptr); - #endif - #if ENABLED(DGUS_FILAMENT_LOADUNLOAD) - // Hook for filament load and unload filament option - static void HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr); - // Hook for filament load and unload - static void HandleFilamentLoadUnload(DGUS_VP_Variable &var); - #endif - - #if ENABLED(SDSUPPORT) - // Callback for VP "Display wants to change screen when there is a SD card" - static void ScreenChangeHookIfSD(DGUS_VP_Variable &var, void *val_ptr); - /// Scroll buttons on the file listing screen. - static void DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable &var, void *val_ptr); - /// File touched. - static void DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr); - /// start print after confirmation received. - static void DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr); - /// User hit the pause, resume or abort button. - static void DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr); - /// User confirmed the abort action - static void DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr); - /// User hit the tune button - static void DGUSLCD_SD_PrintTune(DGUS_VP_Variable &var, void *val_ptr); - /// Send a single filename to the display. - static void DGUSLCD_SD_SendFilename(DGUS_VP_Variable &var); - /// Marlin informed us that a new SD has been inserted. - static void SDCardInserted(); - /// Marlin informed us that the SD Card has been removed(). - static void SDCardRemoved(); - /// Marlin informed us about a bad SD Card. - static void SDCardError(); - #endif - - // OK Button the Confirm screen. - static void ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr); - - // Update data after went to new screen (by display or by GotoScreen) - // remember: store the last-displayed screen, so it can get returned to. - // (e.g for pop up messages) - static void UpdateNewScreen(DGUSLCD_Screens newscreen, bool popup=false); - - // Recall the remembered screen. - static void PopToOldScreen(); - - // Make the display show the screen and update all VPs in it. - static void GotoScreen(DGUSLCD_Screens screen, bool ispopup = false); - - static void UpdateScreenVPData(); - - // Helpers to convert and transfer data to the display. - static void DGUSLCD_SendWordValueToDisplay(DGUS_VP_Variable &var); - static void DGUSLCD_SendStringToDisplay(DGUS_VP_Variable &var); - static void DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var); - static void DGUSLCD_SendTemperaturePID(DGUS_VP_Variable &var); - static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var); - static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var); - static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var); - #if ENABLED(PRINTCOUNTER) - static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var); - static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var); - #endif - #if HAS_FAN - static void DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var); - #endif - static void DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var); - #if ENABLED(DGUS_UI_WAITING) - static void DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var); - #endif - - /// Send a value from 0..100 to a variable with a range from 0..255 - static void DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr); - - template - static void DGUSLCD_SetValueDirectly(DGUS_VP_Variable &var, void *val_ptr) { - if (!var.memadr) return; - union { unsigned char tmp[sizeof(T)]; T t; } x; - unsigned char *ptr = (unsigned char*)val_ptr; - LOOP_L_N(i, sizeof(T)) x.tmp[i] = ptr[sizeof(T) - i - 1]; - *(T*)var.memadr = x.t; - } - - /// Send a float value to the display. - /// Display will get a 4-byte integer scaled to the number of digits: - /// Tell the display the number of digits and it cheats by displaying a dot between... - template - static void DGUSLCD_SendFloatAsLongValueToDisplay(DGUS_VP_Variable &var) { - if (var.memadr) { - float f = *(float *)var.memadr; - f *= cpow(10, decimals); - dgusdisplay.WriteVariable(var.VP, (long)f); - } - } - - /// Send a float value to the display. - /// Display will get a 2-byte integer scaled to the number of digits: - /// Tell the display the number of digits and it cheats by displaying a dot between... - template - static void DGUSLCD_SendFloatAsIntValueToDisplay(DGUS_VP_Variable &var) { - if (var.memadr) { - float f = *(float *)var.memadr; - DEBUG_ECHOLNPAIR_F(" >> ", f, 6); - f *= cpow(10, decimals); - dgusdisplay.WriteVariable(var.VP, (int16_t)f); - } - } +/** + * lcd/extui/lib/dgus/DGUSScreenHandler.h + */ - /// Force an update of all VP on the current screen. - static inline void ForceCompleteUpdate() { update_ptr = 0; ScreenComplete = false; } - /// Has all VPs sent to the screen - static inline bool IsScreenComplete() { return ScreenComplete; } +#include "../../../../inc/MarlinConfigPre.h" - static inline DGUSLCD_Screens getCurrentScreen() { return current_screen; } +#include "../../ui_api.h" - static inline void SetupConfirmAction( void (*f)()) { confirm_action_cb = f; } +#if ENABLED(DGUS_FILAMENT_LOADUNLOAD) -private: - static DGUSLCD_Screens current_screen; ///< currently on screen - static constexpr uint8_t NUM_PAST_SCREENS = 4; - static DGUSLCD_Screens past_screens[NUM_PAST_SCREENS]; ///< LIFO with past screens for the "back" button. + typedef struct { + ExtUI::extruder_t extruder; // which extruder to operate + uint8_t action; // load or unload + bool heated; // heating done ? + float purge_length; // the length to extrude before unload, prevent filament jam + } filament_data_t; - static uint8_t update_ptr; ///< Last sent entry in the VPList for the actual screen. - static uint16_t skipVP; ///< When updating the screen data, skip this one, because the user is interacting with it. - static bool ScreenComplete; ///< All VPs sent to screen? + extern filament_data_t filament_data; - static uint16_t ConfirmVP; ///< context for confirm screen (VP that will be emulated-sent on "OK"). +#endif - #if ENABLED(SDSUPPORT) - static int16_t top_file; ///< file on top of file chooser - static int16_t file_to_print; ///< touched file to be confirmed - #endif +// endianness swap +inline uint16_t swap16(const uint16_t value) { return (value & 0xFFU) << 8U | (value >> 8U); } - static void (*confirm_action_cb)(); -}; +#if ENABLED(DGUS_LCD_UI_ORIGIN) + #include "origin/DGUSScreenHandler.h" +#elif ENABLED(DGUS_LCD_UI_MKS) + #include "mks/DGUSScreenHandler.h" +#elif ENABLED(DGUS_LCD_UI_FYSETC) + #include "fysetc/DGUSScreenHandler.h" +#elif ENABLED(DGUS_LCD_UI_HIPRECY) + #include "hiprecy/DGUSScreenHandler.h" +#endif extern DGUSScreenHandler ScreenHandler; diff --git a/Marlin/src/lcd/extui/lib/dgus/fysetc/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus/fysetc/DGUSScreenHandler.cpp new file mode 100644 index 000000000000..c43243b39d3e --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus/fysetc/DGUSScreenHandler.cpp @@ -0,0 +1,418 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../../../../inc/MarlinConfigPre.h" + +#if ENABLED(DGUS_LCD_UI_FYSETC) + +#include "../DGUSScreenHandler.h" + +#include "../../../../../MarlinCore.h" +#include "../../../../../gcode/queue.h" +#include "../../../../../libs/duration_t.h" +#include "../../../../../module/settings.h" +#include "../../../../../module/temperature.h" +#include "../../../../../module/motion.h" +#include "../../../../../module/planner.h" +#include "../../../../../module/printcounter.h" +#include "../../../../../sd/cardreader.h" + +#if ENABLED(POWER_LOSS_RECOVERY) + #include "../../../../feature/powerloss.h" +#endif + +#if ENABLED(SDSUPPORT) + + void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file; + if (touched_nr > filelist.count()) return; + if (!filelist.seek(touched_nr)) return; + + if (filelist.isDir()) { + filelist.changeDir(filelist.filename()); + top_file = 0; + ForceCompleteUpdate(); + return; + } + + #if ENABLED(DGUS_PRINT_FILENAME) + // Send print filename + dgusdisplay.WriteVariable(VP_SD_Print_Filename, filelist.filename(), VP_SD_FileName_LEN, true); + #endif + + // Setup Confirmation screen + file_to_print = touched_nr; + + HandleUserConfirmationPopUp(VP_SD_FileSelectConfirm, nullptr, PSTR("Print file"), filelist.filename(), PSTR("from SD Card?"), true, true, false, true); + } + + void DGUSScreenHandler::DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr) { + if (!filelist.seek(file_to_print)) return; + ExtUI::printFile(filelist.shortFilename()); + GotoScreen(DGUSLCD_SCREEN_SDPRINTMANIPULATION); + } + + void DGUSScreenHandler::DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr) { + + if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes. + switch (swap16(*(uint16_t*)val_ptr)) { + case 0: { // Resume + if (ExtUI::isPrintingFromMediaPaused()) { + ExtUI::resumePrint(); + } + } break; + + case 1: // Pause + + GotoScreen(MKSLCD_SCREEN_PAUSE); + if (!ExtUI::isPrintingFromMediaPaused()) { + ExtUI::pausePrint(); + //ExtUI::mks_pausePrint(); + } + break; + case 2: // Abort + HandleUserConfirmationPopUp(VP_SD_AbortPrintConfirmed, nullptr, PSTR("Abort printing"), filelist.filename(), PSTR("?"), true, true, false, true); + break; + } + } + + void DGUSScreenHandler::DGUSLCD_SD_SendFilename(DGUS_VP_Variable& var) { + uint16_t target_line = (var.VP - VP_SD_FileName0) / VP_SD_FileName_LEN; + if (target_line > DGUS_SD_FILESPERSCREEN) return; + char tmpfilename[VP_SD_FileName_LEN + 1] = ""; + var.memadr = (void*)tmpfilename; + + if (filelist.seek(top_file + target_line)) { + snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s%c"), filelist.filename(), filelist.isDir() ? '/' : 0); // snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s"), filelist.filename()); + } + DGUSLCD_SendStringToDisplay(var); + } + + void DGUSScreenHandler::SDCardInserted() { + top_file = 0; + filelist.refresh(); + auto cs = getCurrentScreen(); + if (cs == DGUSLCD_SCREEN_MAIN || cs == DGUSLCD_SCREEN_STATUS) + GotoScreen(DGUSLCD_SCREEN_SDFILELIST); + } + + void DGUSScreenHandler::SDCardRemoved() { + if (current_screen == DGUSLCD_SCREEN_SDFILELIST + || (current_screen == DGUSLCD_SCREEN_CONFIRM && (ConfirmVP == VP_SD_AbortPrintConfirmed || ConfirmVP == VP_SD_FileSelectConfirm)) + || current_screen == DGUSLCD_SCREEN_SDPRINTMANIPULATION + ) GotoScreen(DGUSLCD_SCREEN_MAIN); + } + +#endif // SDSUPPORT + +void DGUSScreenHandler::ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr) { + uint8_t *tmp = (uint8_t*)val_ptr; + + // The keycode in target is coded as , so 0x0100A means + // from screen 1 (main) to 10 (temperature). DGUSLCD_SCREEN_POPUP is special, + // meaning "return to previous screen" + DGUSLCD_Screens target = (DGUSLCD_Screens)tmp[1]; + + DEBUG_ECHOLNPAIR("\n DEBUG target", target); + + if (target == DGUSLCD_SCREEN_POPUP) { + // Special handling for popup is to return to previous menu + if (current_screen == DGUSLCD_SCREEN_POPUP && confirm_action_cb) confirm_action_cb(); + PopToOldScreen(); + return; + } + + UpdateNewScreen(target); + + #ifdef DEBUG_DGUSLCD + if (!DGUSLCD_FindScreenVPMapList(target)) DEBUG_ECHOLNPAIR("WARNING: No screen Mapping found for ", target); + #endif +} + +void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleManualMove"); + + int16_t movevalue = swap16(*(uint16_t*)val_ptr); + #if ENABLED(DGUS_UI_MOVE_DIS_OPTION) + if (movevalue) { + const uint16_t choice = *(uint16_t*)var.memadr; + movevalue = movevalue < 0 ? -choice : choice; + } + #endif + char axiscode; + unsigned int speed = 1500; // FIXME: get default feedrate for manual moves, dont hardcode. + + switch (var.VP) { + default: return; + + case VP_MOVE_X: + axiscode = 'X'; + if (!ExtUI::canMove(ExtUI::axis_t::X)) goto cannotmove; + break; + + case VP_MOVE_Y: + axiscode = 'Y'; + if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove; + break; + + case VP_MOVE_Z: + axiscode = 'Z'; + speed = 300; // default to 5mm/s + if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove; + break; + + case VP_HOME_ALL: // only used for homing + axiscode = '\0'; + movevalue = 0; // ignore value sent from display, this VP is _ONLY_ for homing. + break; + } + + if (!movevalue) { + // homing + DEBUG_ECHOPAIR(" homing ", axiscode); + char buf[6] = "G28 X"; + buf[4] = axiscode; + //DEBUG_ECHOPAIR(" ", buf); + queue.enqueue_one_now(buf); + //DEBUG_ECHOLNPGM(" ✓"); + ForceCompleteUpdate(); + return; + } + else { + // movement + DEBUG_ECHOPAIR(" move ", axiscode); + bool old_relative_mode = relative_mode; + if (!relative_mode) { + //DEBUG_ECHOPGM(" G91"); + queue.enqueue_now_P(PSTR("G91")); + //DEBUG_ECHOPGM(" ✓ "); + } + char buf[32]; // G1 X9999.99 F12345 + unsigned int backup_speed = MMS_TO_MMM(feedrate_mm_s); + char sign[] = "\0"; + int16_t value = movevalue / 100; + if (movevalue < 0) { value = -value; sign[0] = '-'; } + int16_t fraction = ABS(movevalue) % 100; + snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed); + //DEBUG_ECHOPAIR(" ", buf); + queue.enqueue_one_now(buf); + //DEBUG_ECHOLNPGM(" ✓ "); + if (backup_speed != speed) { + snprintf_P(buf, 32, PSTR("G0 F%d"), backup_speed); + queue.enqueue_one_now(buf); + //DEBUG_ECHOPAIR(" ", buf); + } + // while (!enqueue_and_echo_command(buf)) idle(); + //DEBUG_ECHOLNPGM(" ✓ "); + if (!old_relative_mode) { + //DEBUG_ECHOPGM("G90"); + queue.enqueue_now_P(PSTR("G90")); + //DEBUG_ECHOPGM(" ✓ "); + } + } + + ForceCompleteUpdate(); + DEBUG_ECHOLNPGM("manmv done."); + return; + + cannotmove: + DEBUG_ECHOLNPAIR(" cannot move ", axiscode); + return; +} + +#if HAS_PID_HEATING + void DGUSScreenHandler::HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t rawvalue = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("V1:", rawvalue); + float value = (float)rawvalue / 10; + DEBUG_ECHOLNPAIR("V2:", value); + float newvalue = 0; + + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_PID_P: newvalue = value; break; + case VP_E0_PID_I: newvalue = scalePID_i(value); break; + case VP_E0_PID_D: newvalue = scalePID_d(value); break; + #endif + #if HOTENDS >= 2 + case VP_E1_PID_P: newvalue = value; break; + case VP_E1_PID_I: newvalue = scalePID_i(value); break; + case VP_E1_PID_D: newvalue = scalePID_d(value); break; + #endif + #if HAS_HEATED_BED + case VP_BED_PID_P: newvalue = value; break; + case VP_BED_PID_I: newvalue = scalePID_i(value); break; + case VP_BED_PID_D: newvalue = scalePID_d(value); break; + #endif + } + + DEBUG_ECHOLNPAIR_F("V3:", newvalue); + *(float *)var.memadr = newvalue; + + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + } +#endif // HAS_PID_HEATING + +#if ENABLED(BABYSTEPPING) + void DGUSScreenHandler::HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleLiveAdjustZ"); + int16_t flag = swap16(*(uint16_t*)val_ptr), + steps = flag ? -20 : 20; + ExtUI::smartAdjustAxis_steps(steps, ExtUI::axis_t::Z, true); + ForceCompleteUpdate(); + } +#endif + +#if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + + void DGUSScreenHandler::HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleFilamentOption"); + + uint8_t e_temp = 0; + filament_data.heated = false; + uint16_t preheat_option = swap16(*(uint16_t*)val_ptr); + if (preheat_option <= 8) { // Load filament type + filament_data.action = 1; + } + else if (preheat_option >= 10) { // Unload filament type + preheat_option -= 10; + filament_data.action = 2; + filament_data.purge_length = DGUS_FILAMENT_PURGE_LENGTH; + } + else { // Cancel filament operation + filament_data.action = 0; + } + + switch (preheat_option) { + case 0: // Load PLA + #ifdef PREHEAT_1_TEMP_HOTEND + e_temp = PREHEAT_1_TEMP_HOTEND; + #endif + break; + case 1: // Load ABS + TERN_(PREHEAT_2_TEMP_HOTEND, e_temp = PREHEAT_2_TEMP_HOTEND); + break; + case 2: // Load PET + #ifdef PREHEAT_3_TEMP_HOTEND + e_temp = PREHEAT_3_TEMP_HOTEND; + #endif + break; + case 3: // Load FLEX + #ifdef PREHEAT_4_TEMP_HOTEND + e_temp = PREHEAT_4_TEMP_HOTEND; + #endif + break; + case 9: // Cool down + default: + e_temp = 0; + break; + } + + if (filament_data.action == 0) { // Go back to utility screen + #if HOTENDS >= 1 + thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E0); + #endif + #if HOTENDS >= 2 + thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E1); + #endif + GotoScreen(DGUSLCD_SCREEN_UTILITY); + } + else { // Go to the preheat screen to show the heating progress + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_FILAMENT_LOAD_UNLOAD: + filament_data.extruder = ExtUI::extruder_t::E0; + thermalManager.setTargetHotend(e_temp, filament_data.extruder); + break; + #endif + #if HOTENDS >= 2 + case VP_E1_FILAMENT_LOAD_UNLOAD: + filament_data.extruder = ExtUI::extruder_t::E1; + thermalManager.setTargetHotend(e_temp, filament_data.extruder); + break; + #endif + } + GotoScreen(DGUSLCD_SCREEN_FILAMENT_HEATING); + } + } + + void DGUSScreenHandler::HandleFilamentLoadUnload(DGUS_VP_Variable &var) { + DEBUG_ECHOLNPGM("HandleFilamentLoadUnload"); + if (filament_data.action <= 0) return; + + // If we close to the target temperature, we can start load or unload the filament + if (thermalManager.hotEnoughToExtrude(filament_data.extruder) && \ + thermalManager.targetHotEnoughToExtrude(filament_data.extruder)) { + float movevalue = DGUS_FILAMENT_LOAD_LENGTH_PER_TIME; + + if (filament_data.action == 1) { // load filament + if (!filament_data.heated) { + //GotoScreen(DGUSLCD_SCREEN_FILAMENT_LOADING); + filament_data.heated = true; + } + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue; + } + else { // unload filament + if (!filament_data.heated) { + GotoScreen(DGUSLCD_SCREEN_FILAMENT_UNLOADING); + filament_data.heated = true; + } + // Before unloading extrude to prevent jamming + if (filament_data.purge_length >= 0) { + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue; + filament_data.purge_length -= movevalue; + } + else { + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) - movevalue; + } + } + ExtUI::setAxisPosition_mm(movevalue, filament_data.extruder); + } + } +#endif // DGUS_FILAMENT_LOADUNLOAD + +bool DGUSScreenHandler::loop() { + dgusdisplay.loop(); + + const millis_t ms = millis(); + static millis_t next_event_ms = 0; + + if (!IsScreenComplete() || ELAPSED(ms, next_event_ms)) { + next_event_ms = ms + DGUS_UPDATE_INTERVAL_MS; + UpdateScreenVPData(); + } + + #if ENABLED(SHOW_BOOTSCREEN) + static bool booted = false; + + if (!booted && TERN0(POWER_LOSS_RECOVERY, recovery.valid())) + booted = true; + + if (!booted && ELAPSED(ms, TERN(USE_MKS_GREEN_UI, 1000, BOOTSCREEN_TIMEOUT))) + booted = true; + #endif + return IsScreenComplete(); +} + +#endif // DGUS_LCD_UI_FYSETC diff --git a/Marlin/src/lcd/extui/lib/dgus/fysetc/DGUSScreenHandler.h b/Marlin/src/lcd/extui/lib/dgus/fysetc/DGUSScreenHandler.h new file mode 100644 index 000000000000..28ab952e53f8 --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus/fysetc/DGUSScreenHandler.h @@ -0,0 +1,240 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "../DGUSDisplay.h" +#include "../DGUSVPVariable.h" +#include "../DGUSDisplayDef.h" + +#include "../../../../../inc/MarlinConfig.h" + +enum DGUSLCD_Screens : uint8_t; + +class DGUSScreenHandler { +public: + DGUSScreenHandler() = default; + + static bool loop(); + + // Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen + // The bools specifing whether the strings are in RAM or FLASH. + static void sendinfoscreen(const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash); + + static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash); + + // "M117" Message -- msg is a RAM ptr. + static void setstatusmessage(const char* msg); + // The same for messages from Flash + static void setstatusmessagePGM(PGM_P const msg); + // Callback for VP "Display wants to change screen on idle printer" + static void ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr); + // Callback for VP "Screen has been changed" + static void ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr); + + // Callback for VP "All Heaters Off" + static void HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr); + // Hook for "Change this temperature" + static void HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr); + // Hook for "Change Flowrate" + static void HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(DGUS_UI_MOVE_DIS_OPTION) + // Hook for manual move option + static void HandleManualMoveOption(DGUS_VP_Variable &var, void *val_ptr); + #endif + + // Hook for manual move. + static void HandleManualMove(DGUS_VP_Variable &var, void *val_ptr); + // Hook for manual extrude. + static void HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr); + // Hook for motor lock and unlook + static void HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(POWER_LOSS_RECOVERY) + // Hook for power loss recovery. + static void HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr); + #endif + // Hook for settings + static void HandleSettings(DGUS_VP_Variable &var, void *val_ptr); + static void HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr); + static void HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr); + + #if HAS_PID_HEATING + // Hook for "Change this temperature PID para" + static void HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr); + // Hook for PID autotune + static void HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if HAS_BED_PROBE + // Hook for "Change probe offset z" + static void HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if ENABLED(BABYSTEPPING) + // Hook for live z adjust action + static void HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if HAS_FAN + // Hook for fan control + static void HandleFanControl(DGUS_VP_Variable &var, void *val_ptr); + #endif + // Hook for heater control + static void HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(DGUS_PREHEAT_UI) + // Hook for preheat + static void HandlePreheat(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + // Hook for filament load and unload filament option + static void HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr); + // Hook for filament load and unload + static void HandleFilamentLoadUnload(DGUS_VP_Variable &var); + #endif + + #if ENABLED(SDSUPPORT) + // Callback for VP "Display wants to change screen when there is a SD card" + static void ScreenChangeHookIfSD(DGUS_VP_Variable &var, void *val_ptr); + // Scroll buttons on the file listing screen. + static void DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable &var, void *val_ptr); + // File touched. + static void DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr); + // start print after confirmation received. + static void DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr); + // User hit the pause, resume or abort button. + static void DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr); + // User confirmed the abort action + static void DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr); + // User hit the tune button + static void DGUSLCD_SD_PrintTune(DGUS_VP_Variable &var, void *val_ptr); + // Send a single filename to the display. + static void DGUSLCD_SD_SendFilename(DGUS_VP_Variable &var); + // Marlin informed us that a new SD has been inserted. + static void SDCardInserted(); + // Marlin informed us that the SD Card has been removed(). + static void SDCardRemoved(); + // Marlin informed us about a bad SD Card. + static void SDCardError(); + #endif + + // OK Button the Confirm screen. + static void ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr); + + // Update data after went to new screen (by display or by GotoScreen) + // remember: store the last-displayed screen, so it can get returned to. + // (e.g for pop up messages) + static void UpdateNewScreen(DGUSLCD_Screens newscreen, bool popup=false); + + // Recall the remembered screen. + static void PopToOldScreen(); + + // Make the display show the screen and update all VPs in it. + static void GotoScreen(DGUSLCD_Screens screen, bool ispopup = false); + + static void UpdateScreenVPData(); + + // Helpers to convert and transfer data to the display. + static void DGUSLCD_SendWordValueToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendStringToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var); + static void DGUSLCD_SendTemperaturePID(DGUS_VP_Variable &var); + static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var); + + #if ENABLED(PRINTCOUNTER) + static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var); + #endif + #if HAS_FAN + static void DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var); + #endif + static void DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var); + #if ENABLED(DGUS_UI_WAITING) + static void DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var); + #endif + + // Send a value from 0..100 to a variable with a range from 0..255 + static void DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr); + + template + static void DGUSLCD_SetValueDirectly(DGUS_VP_Variable &var, void *val_ptr) { + if (!var.memadr) return; + union { unsigned char tmp[sizeof(T)]; T t; } x; + unsigned char *ptr = (unsigned char*)val_ptr; + LOOP_L_N(i, sizeof(T)) x.tmp[i] = ptr[sizeof(T) - i - 1]; + *(T*)var.memadr = x.t; + } + + // Send a float value to the display. + // Display will get a 4-byte integer scaled to the number of digits: + // Tell the display the number of digits and it cheats by displaying a dot between... + template + static void DGUSLCD_SendFloatAsLongValueToDisplay(DGUS_VP_Variable &var) { + if (var.memadr) { + float f = *(float *)var.memadr; + f *= cpow(10, decimals); + dgusdisplay.WriteVariable(var.VP, (long)f); + } + } + + // Send a float value to the display. + // Display will get a 2-byte integer scaled to the number of digits: + // Tell the display the number of digits and it cheats by displaying a dot between... + template + static void DGUSLCD_SendFloatAsIntValueToDisplay(DGUS_VP_Variable &var) { + if (var.memadr) { + float f = *(float *)var.memadr; + DEBUG_ECHOLNPAIR_F(" >> ", f, 6); + f *= cpow(10, decimals); + dgusdisplay.WriteVariable(var.VP, (int16_t)f); + } + } + + // Force an update of all VP on the current screen. + static inline void ForceCompleteUpdate() { update_ptr = 0; ScreenComplete = false; } + // Has all VPs sent to the screen + static inline bool IsScreenComplete() { return ScreenComplete; } + + static inline DGUSLCD_Screens getCurrentScreen() { return current_screen; } + + static inline void SetupConfirmAction( void (*f)()) { confirm_action_cb = f; } + +private: + static DGUSLCD_Screens current_screen; //< currently on screen + static constexpr uint8_t NUM_PAST_SCREENS = 4; + static DGUSLCD_Screens past_screens[NUM_PAST_SCREENS]; //< LIFO with past screens for the "back" button. + + static uint8_t update_ptr; //< Last sent entry in the VPList for the actual screen. + static uint16_t skipVP; //< When updating the screen data, skip this one, because the user is interacting with it. + static bool ScreenComplete; //< All VPs sent to screen? + + static uint16_t ConfirmVP; //< context for confirm screen (VP that will be emulated-sent on "OK"). + + #if ENABLED(SDSUPPORT) + static int16_t top_file; //< file on top of file chooser + static int16_t file_to_print; //< touched file to be confirmed + #endif + + static void (*confirm_action_cb)(); +}; + +#if ENABLED(POWER_LOSS_RECOVERY) + #define PLR_SCREEN_RECOVER DGUSLCD_SCREEN_SDPRINTMANIPULATION + #define PLR_SCREEN_CANCEL DGUSLCD_SCREEN_STATUS +#endif diff --git a/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSScreenHandler.cpp new file mode 100644 index 000000000000..90cfae7f0997 --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSScreenHandler.cpp @@ -0,0 +1,418 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../../../../inc/MarlinConfigPre.h" + +#if ENABLED(DGUS_LCD_UI_HYPRECY) + +#include "../DGUSScreenHandler.h" + +#include "../../../../../MarlinCore.h" +#include "../../../../../gcode/queue.h" +#include "../../../../../libs/duration_t.h" +#include "../../../../../module/settings.h" +#include "../../../../../module/temperature.h" +#include "../../../../../module/motion.h" +#include "../../../../../module/planner.h" +#include "../../../../../module/printcounter.h" +#include "../../../../../sd/cardreader.h" + +#if ENABLED(POWER_LOSS_RECOVERY) + #include "../../../../feature/powerloss.h" +#endif + +#if ENABLED(SDSUPPORT) + + void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file; + if (touched_nr > filelist.count()) return; + if (!filelist.seek(touched_nr)) return; + + if (filelist.isDir()) { + filelist.changeDir(filelist.filename()); + top_file = 0; + ForceCompleteUpdate(); + return; + } + + #if ENABLED(DGUS_PRINT_FILENAME) + // Send print filename + dgusdisplay.WriteVariable(VP_SD_Print_Filename, filelist.filename(), VP_SD_FileName_LEN, true); + #endif + + // Setup Confirmation screen + file_to_print = touched_nr; + + HandleUserConfirmationPopUp(VP_SD_FileSelectConfirm, nullptr, PSTR("Print file"), filelist.filename(), PSTR("from SD Card?"), true, true, false, true); + } + + void DGUSScreenHandler::DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr) { + if (!filelist.seek(file_to_print)) return; + ExtUI::printFile(filelist.shortFilename()); + GotoScreen(DGUSLCD_SCREEN_SDPRINTMANIPULATION); + } + + void DGUSScreenHandler::DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr) { + + if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes. + switch (swap16(*(uint16_t*)val_ptr)) { + case 0: { // Resume + if (ExtUI::isPrintingFromMediaPaused()) { + ExtUI::resumePrint(); + } + } break; + + case 1: // Pause + + GotoScreen(MKSLCD_SCREEN_PAUSE); + if (!ExtUI::isPrintingFromMediaPaused()) { + ExtUI::pausePrint(); + //ExtUI::mks_pausePrint(); + } + break; + case 2: // Abort + HandleUserConfirmationPopUp(VP_SD_AbortPrintConfirmed, nullptr, PSTR("Abort printing"), filelist.filename(), PSTR("?"), true, true, false, true); + break; + } + } + + void DGUSScreenHandler::DGUSLCD_SD_SendFilename(DGUS_VP_Variable& var) { + uint16_t target_line = (var.VP - VP_SD_FileName0) / VP_SD_FileName_LEN; + if (target_line > DGUS_SD_FILESPERSCREEN) return; + char tmpfilename[VP_SD_FileName_LEN + 1] = ""; + var.memadr = (void*)tmpfilename; + + if (filelist.seek(top_file + target_line)) { + snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s%c"), filelist.filename(), filelist.isDir() ? '/' : 0); // snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s"), filelist.filename()); + } + DGUSLCD_SendStringToDisplay(var); + } + + void DGUSScreenHandler::SDCardInserted() { + top_file = 0; + filelist.refresh(); + auto cs = getCurrentScreen(); + if (cs == DGUSLCD_SCREEN_MAIN || cs == DGUSLCD_SCREEN_STATUS) + GotoScreen(DGUSLCD_SCREEN_SDFILELIST); + } + + void DGUSScreenHandler::SDCardRemoved() { + if (current_screen == DGUSLCD_SCREEN_SDFILELIST + || (current_screen == DGUSLCD_SCREEN_CONFIRM && (ConfirmVP == VP_SD_AbortPrintConfirmed || ConfirmVP == VP_SD_FileSelectConfirm)) + || current_screen == DGUSLCD_SCREEN_SDPRINTMANIPULATION + ) GotoScreen(DGUSLCD_SCREEN_MAIN); + } + +#endif // SDSUPPORT + +void DGUSScreenHandler::ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr) { + uint8_t *tmp = (uint8_t*)val_ptr; + + // The keycode in target is coded as , so 0x0100A means + // from screen 1 (main) to 10 (temperature). DGUSLCD_SCREEN_POPUP is special, + // meaning "return to previous screen" + DGUSLCD_Screens target = (DGUSLCD_Screens)tmp[1]; + + DEBUG_ECHOLNPAIR("\n DEBUG target", target); + + if (target == DGUSLCD_SCREEN_POPUP) { + // Special handling for popup is to return to previous menu + if (current_screen == DGUSLCD_SCREEN_POPUP && confirm_action_cb) confirm_action_cb(); + PopToOldScreen(); + return; + } + + UpdateNewScreen(target); + + #ifdef DEBUG_DGUSLCD + if (!DGUSLCD_FindScreenVPMapList(target)) DEBUG_ECHOLNPAIR("WARNING: No screen Mapping found for ", target); + #endif +} + +void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleManualMove"); + + int16_t movevalue = swap16(*(uint16_t*)val_ptr); + #if ENABLED(DGUS_UI_MOVE_DIS_OPTION) + if (movevalue) { + const uint16_t choice = *(uint16_t*)var.memadr; + movevalue = movevalue < 0 ? -choice : choice; + } + #endif + char axiscode; + unsigned int speed = 1500; // FIXME: get default feedrate for manual moves, dont hardcode. + + switch (var.VP) { + default: return; + + case VP_MOVE_X: + axiscode = 'X'; + if (!ExtUI::canMove(ExtUI::axis_t::X)) goto cannotmove; + break; + + case VP_MOVE_Y: + axiscode = 'Y'; + if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove; + break; + + case VP_MOVE_Z: + axiscode = 'Z'; + speed = 300; // default to 5mm/s + if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove; + break; + + case VP_HOME_ALL: // only used for homing + axiscode = '\0'; + movevalue = 0; // ignore value sent from display, this VP is _ONLY_ for homing. + break; + } + + if (!movevalue) { + // homing + DEBUG_ECHOPAIR(" homing ", axiscode); + char buf[6] = "G28 X"; + buf[4] = axiscode; + //DEBUG_ECHOPAIR(" ", buf); + queue.enqueue_one_now(buf); + //DEBUG_ECHOLNPGM(" ✓"); + ForceCompleteUpdate(); + return; + } + else { + // movement + DEBUG_ECHOPAIR(" move ", axiscode); + bool old_relative_mode = relative_mode; + if (!relative_mode) { + //DEBUG_ECHOPGM(" G91"); + queue.enqueue_now_P(PSTR("G91")); + //DEBUG_ECHOPGM(" ✓ "); + } + char buf[32]; // G1 X9999.99 F12345 + unsigned int backup_speed = MMS_TO_MMM(feedrate_mm_s); + char sign[] = "\0"; + int16_t value = movevalue / 100; + if (movevalue < 0) { value = -value; sign[0] = '-'; } + int16_t fraction = ABS(movevalue) % 100; + snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed); + //DEBUG_ECHOPAIR(" ", buf); + queue.enqueue_one_now(buf); + //DEBUG_ECHOLNPGM(" ✓ "); + if (backup_speed != speed) { + snprintf_P(buf, 32, PSTR("G0 F%d"), backup_speed); + queue.enqueue_one_now(buf); + //DEBUG_ECHOPAIR(" ", buf); + } + // while (!enqueue_and_echo_command(buf)) idle(); + //DEBUG_ECHOLNPGM(" ✓ "); + if (!old_relative_mode) { + //DEBUG_ECHOPGM("G90"); + queue.enqueue_now_P(PSTR("G90")); + //DEBUG_ECHOPGM(" ✓ "); + } + } + + ForceCompleteUpdate(); + DEBUG_ECHOLNPGM("manmv done."); + return; + + cannotmove: + DEBUG_ECHOLNPAIR(" cannot move ", axiscode); + return; +} + +#if HAS_PID_HEATING + void DGUSScreenHandler::HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t rawvalue = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("V1:", rawvalue); + float value = (float)rawvalue / 10; + DEBUG_ECHOLNPAIR("V2:", value); + float newvalue = 0; + + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_PID_P: newvalue = value; break; + case VP_E0_PID_I: newvalue = scalePID_i(value); break; + case VP_E0_PID_D: newvalue = scalePID_d(value); break; + #endif + #if HOTENDS >= 2 + case VP_E1_PID_P: newvalue = value; break; + case VP_E1_PID_I: newvalue = scalePID_i(value); break; + case VP_E1_PID_D: newvalue = scalePID_d(value); break; + #endif + #if HAS_HEATED_BED + case VP_BED_PID_P: newvalue = value; break; + case VP_BED_PID_I: newvalue = scalePID_i(value); break; + case VP_BED_PID_D: newvalue = scalePID_d(value); break; + #endif + } + + DEBUG_ECHOLNPAIR_F("V3:", newvalue); + *(float *)var.memadr = newvalue; + + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + } +#endif // HAS_PID_HEATING + +#if ENABLED(BABYSTEPPING) + void DGUSScreenHandler::HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleLiveAdjustZ"); + int16_t flag = swap16(*(uint16_t*)val_ptr), + steps = flag ? -20 : 20; + ExtUI::smartAdjustAxis_steps(steps, ExtUI::axis_t::Z, true); + ForceCompleteUpdate(); + } +#endif + +#if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + + void DGUSScreenHandler::HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleFilamentOption"); + + uint8_t e_temp = 0; + filament_data.heated = false; + uint16_t preheat_option = swap16(*(uint16_t*)val_ptr); + if (preheat_option <= 8) { // Load filament type + filament_data.action = 1; + } + else if (preheat_option >= 10) { // Unload filament type + preheat_option -= 10; + filament_data.action = 2; + filament_data.purge_length = DGUS_FILAMENT_PURGE_LENGTH; + } + else { // Cancel filament operation + filament_data.action = 0; + } + + switch (preheat_option) { + case 0: // Load PLA + #ifdef PREHEAT_1_TEMP_HOTEND + e_temp = PREHEAT_1_TEMP_HOTEND; + #endif + break; + case 1: // Load ABS + TERN_(PREHEAT_2_TEMP_HOTEND, e_temp = PREHEAT_2_TEMP_HOTEND); + break; + case 2: // Load PET + #ifdef PREHEAT_3_TEMP_HOTEND + e_temp = PREHEAT_3_TEMP_HOTEND; + #endif + break; + case 3: // Load FLEX + #ifdef PREHEAT_4_TEMP_HOTEND + e_temp = PREHEAT_4_TEMP_HOTEND; + #endif + break; + case 9: // Cool down + default: + e_temp = 0; + break; + } + + if (filament_data.action == 0) { // Go back to utility screen + #if HOTENDS >= 1 + thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E0); + #endif + #if HOTENDS >= 2 + thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E1); + #endif + GotoScreen(DGUSLCD_SCREEN_UTILITY); + } + else { // Go to the preheat screen to show the heating progress + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_FILAMENT_LOAD_UNLOAD: + filament_data.extruder = ExtUI::extruder_t::E0; + thermalManager.setTargetHotend(e_temp, filament_data.extruder); + break; + #endif + #if HOTENDS >= 2 + case VP_E1_FILAMENT_LOAD_UNLOAD: + filament_data.extruder = ExtUI::extruder_t::E1; + thermalManager.setTargetHotend(e_temp, filament_data.extruder); + break; + #endif + } + GotoScreen(DGUSLCD_SCREEN_FILAMENT_HEATING); + } + } + + void DGUSScreenHandler::HandleFilamentLoadUnload(DGUS_VP_Variable &var) { + DEBUG_ECHOLNPGM("HandleFilamentLoadUnload"); + if (filament_data.action <= 0) return; + + // If we close to the target temperature, we can start load or unload the filament + if (thermalManager.hotEnoughToExtrude(filament_data.extruder) && \ + thermalManager.targetHotEnoughToExtrude(filament_data.extruder)) { + float movevalue = DGUS_FILAMENT_LOAD_LENGTH_PER_TIME; + + if (filament_data.action == 1) { // load filament + if (!filament_data.heated) { + //GotoScreen(DGUSLCD_SCREEN_FILAMENT_LOADING); + filament_data.heated = true; + } + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue; + } + else { // unload filament + if (!filament_data.heated) { + GotoScreen(DGUSLCD_SCREEN_FILAMENT_UNLOADING); + filament_data.heated = true; + } + // Before unloading extrude to prevent jamming + if (filament_data.purge_length >= 0) { + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue; + filament_data.purge_length -= movevalue; + } + else { + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) - movevalue; + } + } + ExtUI::setAxisPosition_mm(movevalue, filament_data.extruder); + } + } +#endif // DGUS_FILAMENT_LOADUNLOAD + +bool DGUSScreenHandler::loop() { + dgusdisplay.loop(); + + const millis_t ms = millis(); + static millis_t next_event_ms = 0; + + if (!IsScreenComplete() || ELAPSED(ms, next_event_ms)) { + next_event_ms = ms + DGUS_UPDATE_INTERVAL_MS; + UpdateScreenVPData(); + } + + #if ENABLED(SHOW_BOOTSCREEN) + static bool booted = false; + + if (!booted && TERN0(POWER_LOSS_RECOVERY, recovery.valid())) + booted = true; + + if (!booted && ELAPSED(ms, TERN(USE_MKS_GREEN_UI, 1000, BOOTSCREEN_TIMEOUT))) + booted = true; + #endif + return IsScreenComplete(); +} + +#endif // DGUS_LCD_UI_HYPRECY diff --git a/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSScreenHandler.h b/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSScreenHandler.h new file mode 100644 index 000000000000..28ab952e53f8 --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSScreenHandler.h @@ -0,0 +1,240 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "../DGUSDisplay.h" +#include "../DGUSVPVariable.h" +#include "../DGUSDisplayDef.h" + +#include "../../../../../inc/MarlinConfig.h" + +enum DGUSLCD_Screens : uint8_t; + +class DGUSScreenHandler { +public: + DGUSScreenHandler() = default; + + static bool loop(); + + // Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen + // The bools specifing whether the strings are in RAM or FLASH. + static void sendinfoscreen(const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash); + + static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash); + + // "M117" Message -- msg is a RAM ptr. + static void setstatusmessage(const char* msg); + // The same for messages from Flash + static void setstatusmessagePGM(PGM_P const msg); + // Callback for VP "Display wants to change screen on idle printer" + static void ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr); + // Callback for VP "Screen has been changed" + static void ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr); + + // Callback for VP "All Heaters Off" + static void HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr); + // Hook for "Change this temperature" + static void HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr); + // Hook for "Change Flowrate" + static void HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(DGUS_UI_MOVE_DIS_OPTION) + // Hook for manual move option + static void HandleManualMoveOption(DGUS_VP_Variable &var, void *val_ptr); + #endif + + // Hook for manual move. + static void HandleManualMove(DGUS_VP_Variable &var, void *val_ptr); + // Hook for manual extrude. + static void HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr); + // Hook for motor lock and unlook + static void HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(POWER_LOSS_RECOVERY) + // Hook for power loss recovery. + static void HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr); + #endif + // Hook for settings + static void HandleSettings(DGUS_VP_Variable &var, void *val_ptr); + static void HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr); + static void HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr); + + #if HAS_PID_HEATING + // Hook for "Change this temperature PID para" + static void HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr); + // Hook for PID autotune + static void HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if HAS_BED_PROBE + // Hook for "Change probe offset z" + static void HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if ENABLED(BABYSTEPPING) + // Hook for live z adjust action + static void HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if HAS_FAN + // Hook for fan control + static void HandleFanControl(DGUS_VP_Variable &var, void *val_ptr); + #endif + // Hook for heater control + static void HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(DGUS_PREHEAT_UI) + // Hook for preheat + static void HandlePreheat(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + // Hook for filament load and unload filament option + static void HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr); + // Hook for filament load and unload + static void HandleFilamentLoadUnload(DGUS_VP_Variable &var); + #endif + + #if ENABLED(SDSUPPORT) + // Callback for VP "Display wants to change screen when there is a SD card" + static void ScreenChangeHookIfSD(DGUS_VP_Variable &var, void *val_ptr); + // Scroll buttons on the file listing screen. + static void DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable &var, void *val_ptr); + // File touched. + static void DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr); + // start print after confirmation received. + static void DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr); + // User hit the pause, resume or abort button. + static void DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr); + // User confirmed the abort action + static void DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr); + // User hit the tune button + static void DGUSLCD_SD_PrintTune(DGUS_VP_Variable &var, void *val_ptr); + // Send a single filename to the display. + static void DGUSLCD_SD_SendFilename(DGUS_VP_Variable &var); + // Marlin informed us that a new SD has been inserted. + static void SDCardInserted(); + // Marlin informed us that the SD Card has been removed(). + static void SDCardRemoved(); + // Marlin informed us about a bad SD Card. + static void SDCardError(); + #endif + + // OK Button the Confirm screen. + static void ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr); + + // Update data after went to new screen (by display or by GotoScreen) + // remember: store the last-displayed screen, so it can get returned to. + // (e.g for pop up messages) + static void UpdateNewScreen(DGUSLCD_Screens newscreen, bool popup=false); + + // Recall the remembered screen. + static void PopToOldScreen(); + + // Make the display show the screen and update all VPs in it. + static void GotoScreen(DGUSLCD_Screens screen, bool ispopup = false); + + static void UpdateScreenVPData(); + + // Helpers to convert and transfer data to the display. + static void DGUSLCD_SendWordValueToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendStringToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var); + static void DGUSLCD_SendTemperaturePID(DGUS_VP_Variable &var); + static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var); + + #if ENABLED(PRINTCOUNTER) + static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var); + #endif + #if HAS_FAN + static void DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var); + #endif + static void DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var); + #if ENABLED(DGUS_UI_WAITING) + static void DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var); + #endif + + // Send a value from 0..100 to a variable with a range from 0..255 + static void DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr); + + template + static void DGUSLCD_SetValueDirectly(DGUS_VP_Variable &var, void *val_ptr) { + if (!var.memadr) return; + union { unsigned char tmp[sizeof(T)]; T t; } x; + unsigned char *ptr = (unsigned char*)val_ptr; + LOOP_L_N(i, sizeof(T)) x.tmp[i] = ptr[sizeof(T) - i - 1]; + *(T*)var.memadr = x.t; + } + + // Send a float value to the display. + // Display will get a 4-byte integer scaled to the number of digits: + // Tell the display the number of digits and it cheats by displaying a dot between... + template + static void DGUSLCD_SendFloatAsLongValueToDisplay(DGUS_VP_Variable &var) { + if (var.memadr) { + float f = *(float *)var.memadr; + f *= cpow(10, decimals); + dgusdisplay.WriteVariable(var.VP, (long)f); + } + } + + // Send a float value to the display. + // Display will get a 2-byte integer scaled to the number of digits: + // Tell the display the number of digits and it cheats by displaying a dot between... + template + static void DGUSLCD_SendFloatAsIntValueToDisplay(DGUS_VP_Variable &var) { + if (var.memadr) { + float f = *(float *)var.memadr; + DEBUG_ECHOLNPAIR_F(" >> ", f, 6); + f *= cpow(10, decimals); + dgusdisplay.WriteVariable(var.VP, (int16_t)f); + } + } + + // Force an update of all VP on the current screen. + static inline void ForceCompleteUpdate() { update_ptr = 0; ScreenComplete = false; } + // Has all VPs sent to the screen + static inline bool IsScreenComplete() { return ScreenComplete; } + + static inline DGUSLCD_Screens getCurrentScreen() { return current_screen; } + + static inline void SetupConfirmAction( void (*f)()) { confirm_action_cb = f; } + +private: + static DGUSLCD_Screens current_screen; //< currently on screen + static constexpr uint8_t NUM_PAST_SCREENS = 4; + static DGUSLCD_Screens past_screens[NUM_PAST_SCREENS]; //< LIFO with past screens for the "back" button. + + static uint8_t update_ptr; //< Last sent entry in the VPList for the actual screen. + static uint16_t skipVP; //< When updating the screen data, skip this one, because the user is interacting with it. + static bool ScreenComplete; //< All VPs sent to screen? + + static uint16_t ConfirmVP; //< context for confirm screen (VP that will be emulated-sent on "OK"). + + #if ENABLED(SDSUPPORT) + static int16_t top_file; //< file on top of file chooser + static int16_t file_to_print; //< touched file to be confirmed + #endif + + static void (*confirm_action_cb)(); +}; + +#if ENABLED(POWER_LOSS_RECOVERY) + #define PLR_SCREEN_RECOVER DGUSLCD_SCREEN_SDPRINTMANIPULATION + #define PLR_SCREEN_CANCEL DGUSLCD_SCREEN_STATUS +#endif diff --git a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.cpp new file mode 100644 index 000000000000..14b7394aaa1a --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.cpp @@ -0,0 +1,795 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../../../../inc/MarlinConfigPre.h" + +#if ENABLED(DGUS_LCD_UI_MKS) + +#include "DGUSDisplayDef.h" +#include "../DGUSDisplay.h" +#include "../DGUSScreenHandler.h" + +#include "../../../../../module/temperature.h" +#include "../../../../../module/motion.h" +#include "../../../../../module/planner.h" + +#include "../../../ui_api.h" +#include "../../../../marlinui.h" + +#if ENABLED(HAS_STEALTHCHOP) + #include "../../../../module/stepper/trinamic.h" +#endif + +#if ENABLED(DGUS_UI_MOVE_DIS_OPTION) + uint16_t distanceToMove = 10; +#endif + +uint16_t distanceMove = 1; +float distanceFilament = 10; +uint16_t FilamentSpeed = 25; +float ZOffset_distance = 0.1; +float mesh_adj_distance = 0.1; +float Z_distance = 0.1; + +int16_t level_1_x_point = 20; +int16_t level_1_y_point = 20; + +int16_t level_2_x_point = 20; +int16_t level_2_y_point = 20; + +int16_t level_3_x_point = 20; +int16_t level_3_y_point = 20; + +int16_t level_4_x_point = 20; +int16_t level_4_y_point = 20; +int16_t level_5_x_point = X_MAX_POS / 2; +int16_t level_5_y_point = Y_MAX_POS / 2; + +uint16_t tim_h; +uint16_t tim_m; +uint16_t tim_s; + +uint16_t x_park_pos = 20; +uint16_t y_park_pos = 20; +uint16_t z_park_pos = 10; + +xyz_pos_t position_before_pause; + +void MKS_pause_print_move() { + planner.synchronize(); + position_before_pause = current_position; + do_blocking_move_to(X_MIN_POS + x_park_pos, Y_MIN_POS + y_park_pos, current_position.z + z_park_pos); +} + +void MKS_resume_print_move() { do_blocking_move_to(position_before_pause); } + +uint16_t min_ex_temp = 0; + +float z_offset_add = 0; + +#if ENABLED(SENSORLESS_HOMING) + uint16_t tmc_x_step = 0; + uint16_t tmc_y_step = 0; + uint16_t tmc_z_step = 0; +#else + uint16_t tmc_x_step = 0; + uint16_t tmc_y_step = 0; + uint16_t tmc_z_step = 0; +#endif + +uint16_t lcd_default_light = 50; + +EX_FILAMENT_DEF ex_filament; +RUNOUT_MKS_DEF runout_mks; +NOZZLE_PARK_DEF nozzle_park_mks; + +const uint16_t VPList_Boot[] PROGMEM = { + VP_MARLIN_VERSION, + 0x0000 +}; + +#define MKSLIST_E_ITEM(N) VP_T_E##N##_Is, VP_T_E##N##_Set, + +const uint16_t VPList_Main[] PROGMEM = { + // VP_M117, for completeness, but it cannot be auto-uploaded. + #if HOTENDS >= 1 + MKSLIST_E_ITEM(0) VP_E0_STATUS, + #endif + #if HOTENDS >= 2 + MKSLIST_E_ITEM(1) + #endif + #if HAS_HEATED_BED + VP_T_Bed_Is, VP_T_Bed_Set, VP_BED_STATUS, + #endif + #if HAS_FAN + VP_Fan0_Percentage, VP_FAN0_STATUS, + #endif + VP_XPos, VP_YPos, VP_ZPos, + VP_Fan0_Percentage, + VP_Feedrate_Percentage, + #if ENABLED(LCD_SET_PROGRESS_MANUALLY) + VP_PrintProgress_Percentage, + #endif + 0x0000 +}; + +const uint16_t MKSList_Home[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + // Language + // VP_HOME_Dis, + + 0x0000 +}; + +const uint16_t MKSList_Setting[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + // Language + VP_Setting_Dis, + 0x0000 +}; + +const uint16_t MKSList_Tool[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + // Language + VP_Tool_Dis, + // LCD BLK + VP_LCD_BLK, + 0x0000 +}; + +const uint16_t MKSList_EXTRUE[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + + VP_Filament_distance, + VP_Filament_speed, + + 0x0000 +}; + +const uint16_t MKSList_LEVEL[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + + 0x0000 +}; + +const uint16_t MKSList_MOVE[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + + 0x0000 +}; + +const uint16_t MKSList_Print[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + // Print Percent + VP_PrintProgress_Percentage, + + VP_PrintTime, + + VP_Flowrate_E0, + VP_Flowrate_E1, + VP_Feedrate_Percentage, + + VP_PrintTime_H, + VP_PrintTime_M, + VP_PrintTime_S, + + VP_XPos, + VP_YPos, + VP_ZPos, + + 0x0000 +}; + +const uint16_t MKSList_SD_File[] PROGMEM = { + VP_SD_FileName0, VP_SD_FileName1, + VP_SD_FileName2, VP_SD_FileName3, + VP_SD_FileName4, VP_SD_FileName5, + VP_SD_FileName6, VP_SD_FileName7, + VP_SD_FileName8, VP_SD_FileName9, + + 0x0000 +}; + +const uint16_t MKSList_TempOnly[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + // LCD BLK + VP_LCD_BLK, + 0x0000 +}; + +const uint16_t MKSList_Pluse[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + + // Pluse + VP_X_STEP_PER_MM, + VP_Y_STEP_PER_MM, + VP_Z_STEP_PER_MM, + VP_E0_STEP_PER_MM, + VP_E1_STEP_PER_MM, + + 0x0000 +}; + +const uint16_t MKSList_MaxSpeed[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + + // Pluse + VP_X_MAX_SPEED, + VP_Y_MAX_SPEED, + VP_Z_MAX_SPEED, + VP_E0_MAX_SPEED, + VP_E1_MAX_SPEED, + + 0x0000 +}; + +const uint16_t MKSList_MaxAcc[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + + // ACC + VP_ACC_SPEED, + VP_X_ACC_MAX_SPEED, + VP_Y_ACC_MAX_SPEED, + VP_Z_ACC_MAX_SPEED, + VP_E0_ACC_MAX_SPEED, + VP_E1_ACC_MAX_SPEED, + + 0x0000 +}; + +const uint16_t MKSList_PID[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + + // PID + VP_E0_PID_P, + VP_E0_PID_I, + VP_E0_PID_D, + + 0x0000 +}; + +const uint16_t MKSList_Level_Point[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + // FAN + VP_Fan0_Percentage, + + // Level Point + VP_Level_Point_One_X, + VP_Level_Point_One_Y, + VP_Level_Point_Two_X, + VP_Level_Point_Two_Y, + VP_Level_Point_Three_X, + VP_Level_Point_Three_Y, + VP_Level_Point_Four_X, + VP_Level_Point_Four_Y, + VP_Level_Point_Five_X, + VP_Level_Point_Five_Y, + + 0x0000 +}; + +const uint16_t MKSList_Level_PrintConfig[] PROGMEM = { + VP_T_E0_Set, + VP_T_E1_Set, + VP_T_Bed_Set, + VP_Flowrate_E0, + VP_Flowrate_E1, + VP_Fan0_Percentage, + VP_Feedrate_Percentage, + + 0x0000 +}; + +const uint16_t MKSList_PrintPauseConfig[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + + VP_X_PARK_POS, + VP_Y_PARK_POS, + VP_Z_PARK_POS, + + 0x0000 +}; + +const uint16_t MKSList_MotoConfig[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + + VP_TRAVEL_SPEED, + VP_FEEDRATE_MIN_SPEED, + VP_T_F_SPEED, + + 0x0000 +}; + +const uint16_t MKSList_EX_Config[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + VP_MIN_EX_T,VP_Min_EX_T_E, + 0x0000 +}; + +const uint16_t MKSTMC_Config[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + // HB Temp + VP_T_Bed_Is, VP_T_Bed_Set, + VP_MIN_EX_T, + + VP_TMC_X_STEP, + VP_TMC_Y_STEP, + VP_TMC_Z_STEP, + VP_TMC_X1_Current, + VP_TMC_Y1_Current, + VP_TMC_X_Current, + VP_TMC_Y_Current, + VP_TMC_Z_Current, + VP_TMC_E0_Current, + VP_TMC_E1_Current, + VP_TMC_Z1_Current, + + 0x0000 +}; + +const uint16_t MKSAuto_Level[] PROGMEM = { + VP_MESH_LEVEL_POINT_DIS, + VP_ZPos, + 0x0000 +}; + +const uint16_t MKSOffset_Config[] PROGMEM = { + // E Temp + REPEAT(EXTRUDERS, MKSLIST_E_ITEM) + VP_OFFSET_X, + VP_OFFSET_Y, + VP_OFFSET_Z, + 0x0000 +}; + +const uint16_t MKSBabyStep[] PROGMEM = { + VP_ZOffset_DE_DIS, + 0x0000 +}; + +const uint16_t MKSList_About[] PROGMEM = { + // Marlin version + VP_MARLIN_VERSION, + // H43 Version + VP_MKS_H43_VERSION, + VP_MKS_H43_UpdataVERSION, + 0x0000 +}; + +// Page data updata +const struct VPMapping VPMap[] PROGMEM = { + { MKSLCD_SCREEN_BOOT, VPList_Boot }, // Boot Page to show logo 0 + { MKSLCD_SCREEN_HOME, MKSList_Home }, // Home, Page 1 + { MKSLCD_SCREEN_SETTING, MKSList_Setting }, // Setting, Page 2 + { MKSLCD_SCREEM_TOOL, MKSList_Tool }, // Page 3 + { MKSLCD_SCREEN_EXTRUDE_P1, MKSList_EXTRUE }, // Page 4 + { MKSLCD_SCREEN_EXTRUDE_P2, MKSList_EXTRUE }, // Page 11 + { MKSLCD_PAUSE_SETTING_EX, MKSList_EXTRUE }, // Page 57 + { MKSLCD_PAUSE_SETTING_EX2, MKSList_EXTRUE }, // Page 61 + { MKSLCD_SCREEN_LEVEL, MKSList_LEVEL }, // Page 5 + { MKSLCD_SCREEN_MOVE, MKSList_MOVE }, // Page 6 + { MKSLCD_SCREEN_PRINT, MKSList_Print }, // Page 7 + { MKSLCD_SCREEN_PAUSE, MKSList_Print }, // Page 26 + { MKSLCD_SCREEN_CHOOSE_FILE, MKSList_SD_File }, // Page 15 + { MKSLCD_SCREEN_MOTOR_PLUSE, MKSList_Pluse }, // Page 51 + { MKSLCD_SCREEN_MOTOR_SPEED, MKSList_MaxSpeed }, // Page 55 + { MKSLCD_SCREEN_MOTOR_ACC_MAX, MKSList_MaxAcc }, // Page 53 + { MKSLCD_SCREEN_LEVEL_DATA, MKSList_Level_Point }, // Page 48 + { MKSLCD_PrintPause_SET, MKSList_PrintPauseConfig }, // Page 49 + { MKSLCD_FILAMENT_DATA, MKSList_SD_File }, // Page 50 + { MKSLCD_SCREEN_Config, MKSList_TempOnly }, // Page 46 + { MKSLCD_SCREEN_Config_MOTOR, MKSList_MotoConfig }, // Page 47 + { MKSLCD_PID, MKSList_PID }, // Page 56 + { MKSLCD_ABOUT, MKSList_About }, // Page 36 + { MKSLCD_SCREEN_PRINT_CONFIG, MKSList_Level_PrintConfig }, // Page 60 + { MKSLCD_SCREEN_EX_CONFIG, MKSList_EX_Config }, // Page 65 + { MKSLCD_SCREEN_TMC_Config, MKSTMC_Config }, // Page 70 + { MKSLCD_AUTO_LEVEL, MKSAuto_Level }, // Page 73 + { MKSLCD_Screen_Offset_Config, MKSOffset_Config }, // Page 30 + { MKSLCD_Screen_PMove, MKSList_MOVE }, // Page 64 + { MKSLCD_Screen_Baby, MKSBabyStep }, // Page 71 + //{ MKSLCD_SCREEN_LEVEL_DATA, MKSList_SD_File}, + //{ MKSLCD_SCREEN_HOME, VPList_Boot }, + { 0, nullptr } // List is terminated with an nullptr as table entry. +}; + +const char MarlinVersion[] PROGMEM = SHORT_BUILD_VERSION; +const char H43Version[] PROGMEM = "MKS H43_V1.30"; +const char Updata_Time[] PROGMEM = STRING_DISTRIBUTION_DATE; + +// Helper to define a DGUS_VP_Variable for common use cases. +#define VPHELPER(VPADR, VPADRVAR, RXFPTR, TXFPTR) \ + { \ + .VP = VPADR, .memadr = VPADRVAR, .size = sizeof(VPADRVAR), \ + .set_by_display_handler = RXFPTR, .send_to_display_handler = TXFPTR \ + } + +// Helper to define a DGUS_VP_Variable when the sizeo of the var cannot be determined automaticalyl (eg. a string) +#define VPHELPER_STR(VPADR, VPADRVAR, STRLEN, RXFPTR, TXFPTR) \ + { \ + .VP = VPADR, .memadr = VPADRVAR, .size = STRLEN, \ + .set_by_display_handler = RXFPTR, .send_to_display_handler = TXFPTR \ + } + +const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { + // Helper to detect touch events + VPHELPER(VP_SCREENCHANGE, nullptr, ScreenHandler.ScreenChangeHook, nullptr), + VPHELPER(VP_SCREENCHANGE_ASK, nullptr, ScreenHandler.ScreenChangeHookIfIdle, nullptr), + #if ENABLED(SDSUPPORT) + VPHELPER(VP_SCREENCHANGE_WHENSD, nullptr, ScreenHandler.ScreenChangeHookIfSD, nullptr), + #endif + VPHELPER(VP_CONFIRMED, nullptr, ScreenHandler.ScreenConfirmedOK, nullptr), + + // Back Button + VPHELPER(VP_BACK_PAGE, nullptr, &ScreenHandler.ScreenBackChange, nullptr), + VPHELPER(VP_TEMP_ALL_OFF, nullptr, &ScreenHandler.HandleAllHeatersOff, nullptr), + + VPHELPER(VP_MOVE_X, nullptr, &ScreenHandler.HandleManualMove, nullptr), + VPHELPER(VP_MOVE_Y, nullptr, &ScreenHandler.HandleManualMove, nullptr), + VPHELPER(VP_MOVE_Z, nullptr, &ScreenHandler.HandleManualMove, nullptr), + VPHELPER(VP_HOME_ALL, nullptr, &ScreenHandler.HandleManualMove, nullptr), + + VPHELPER(VP_X_HOME, nullptr, &ScreenHandler.HandleManualMove, nullptr), + VPHELPER(VP_Y_HOME, nullptr, &ScreenHandler.HandleManualMove, nullptr), + VPHELPER(VP_Z_HOME, nullptr, &ScreenHandler.HandleManualMove, nullptr), + + VPHELPER(VP_MOVE_DISTANCE, &distanceMove, &ScreenHandler.GetManualMovestep, nullptr), + + VPHELPER(VP_MOTOR_LOCK_UNLOK, nullptr, &ScreenHandler.HandleManualMove, nullptr), + VPHELPER(VP_LEVEL_POINT, nullptr, &ScreenHandler.ManualAssistLeveling, nullptr), + + #if ENABLED(POWER_LOSS_RECOVERY) + VPHELPER(VP_POWER_LOSS_RECOVERY, nullptr, &ScreenHandler.HandlePowerLossRecovery, nullptr), + #endif + VPHELPER(VP_SETTINGS, nullptr, &ScreenHandler.HandleSettings, nullptr), + #if ENABLED(SINGLE_Z_CALIBRATION) + VPHELPER(VP_Z_CALIBRATE, nullptr, &ScreenHandler.HandleZCalibration, nullptr), + #endif + #if ENABLED(FIRST_LAYER_CAL) + VPHELPER(VP_Z_FIRST_LAYER_CAL, nullptr, &ScreenHandler.HandleFirstLayerCal, nullptr), + #endif + {.VP = VP_MARLIN_VERSION, .memadr = (void *)MarlinVersion, .size = VP_MARLIN_VERSION_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM}, + // M117 LCD String (We don't need the string in memory but "just" push it to the display on demand, hence the nullptr + {.VP = VP_M117, .memadr = nullptr, .size = VP_M117_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplay}, + {.VP = VP_MKS_H43_VERSION, .memadr = (void *)H43Version, .size = VP_MKS_H43_VERSION_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM}, + {.VP = VP_MKS_H43_UpdataVERSION, .memadr = (void *)Updata_Time, .size = VP_MKS_H43_VERSION_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM}, + + // Temperature Data + #if HOTENDS >= 1 + VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Flowrate_E0, &planner.flow_percentage[ExtUI::extruder_t::E0], ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_EPos, &destination.e, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_MOVE_E0, nullptr, &ScreenHandler.HandleManualExtrude, nullptr), + VPHELPER(VP_E0_CONTROL, &thermalManager.temp_hotend[0].target, &ScreenHandler.HandleHeaterControl, nullptr), + VPHELPER(VP_E0_STATUS, &thermalManager.temp_hotend[0].target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay), + #if ENABLED(DGUS_PREHEAT_UI) + VPHELPER(VP_E0_BED_PREHEAT, nullptr, &ScreenHandler.HandlePreheat, nullptr), + #endif + #if ENABLED(PIDTEMP) + VPHELPER(VP_E0_PID_P, &thermalManager.temp_hotend[0].pid.Kp, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID), + VPHELPER(VP_E0_PID_I, &thermalManager.temp_hotend[0].pid.Ki, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID), + VPHELPER(VP_E0_PID_D, &thermalManager.temp_hotend[0].pid.Kd, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID), + VPHELPER(VP_PID_AUTOTUNE_E0, nullptr, &ScreenHandler.HandlePIDAutotune, nullptr), + #endif + #if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + VPHELPER(VP_LOAD_Filament, nullptr, &ScreenHandler.MKS_FilamentLoad, nullptr), + VPHELPER(VP_UNLOAD_Filament, nullptr, &ScreenHandler.MKS_FilamentUnLoad, nullptr), + VPHELPER(VP_Filament_distance, &distanceFilament, &ScreenHandler.GetManualFilament, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + VPHELPER(VP_Filament_speed, &FilamentSpeed, &ScreenHandler.GetManualFilamentSpeed, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + #endif + + #if HOTENDS >= 2 + VPHELPER(VP_T_E1_Is, &thermalManager.temp_hotend[1].celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_E1_Set, &thermalManager.temp_hotend[1].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Flowrate_E1, &planner.flow_percentage[ExtUI::extruder_t::E1], ScreenHandler.HandleFlowRateChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_MOVE_E1, nullptr, &ScreenHandler.HandleManualExtrude, nullptr), + VPHELPER(VP_E1_CONTROL, &thermalManager.temp_hotend[1].target, &ScreenHandler.HandleHeaterControl, nullptr), + VPHELPER(VP_E1_STATUS, &thermalManager.temp_hotend[1].target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay), + + #if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + VPHELPER(VP_Filament_distance, &distanceFilament, &ScreenHandler.GetManualFilament, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + VPHELPER(VP_Filament_speed, &FilamentSpeed, &ScreenHandler.GetManualFilamentSpeed, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + + #if ENABLED(PIDTEMP) + VPHELPER(VP_PID_AUTOTUNE_E1, nullptr, &ScreenHandler.HandlePIDAutotune, nullptr), + #endif + + VPHELPER(VP_E1_FILAMENT_LOAD_UNLOAD, nullptr, &ScreenHandler.HandleFilamentOption, &ScreenHandler.HandleFilamentLoadUnload), + #endif + + #if HAS_HEATED_BED + VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<0>), + VPHELPER(VP_T_Bed_Set, &thermalManager.temp_bed.target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_BED_CONTROL, &thermalManager.temp_bed.target, &ScreenHandler.HandleHeaterControl, nullptr), + VPHELPER(VP_BED_STATUS, &thermalManager.temp_bed.target, nullptr, &ScreenHandler.DGUSLCD_SendHeaterStatusToDisplay), + #if ENABLED(PIDTEMPBED) + VPHELPER(VP_BED_PID_P, &thermalManager.temp_bed.pid.Kp, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID), + VPHELPER(VP_BED_PID_I, &thermalManager.temp_bed.pid.Ki, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID), + VPHELPER(VP_BED_PID_D, &thermalManager.temp_bed.pid.Kd, ScreenHandler.HandleTemperaturePIDChanged, ScreenHandler.DGUSLCD_SendTemperaturePID), + VPHELPER(VP_PID_AUTOTUNE_BED, nullptr, &ScreenHandler.HandlePIDAutotune, nullptr), + #endif + #endif + + // Fan Data + #if HAS_FAN + #define FAN_VPHELPER(N) \ + VPHELPER(VP_Fan##N##_Percentage, &thermalManager.fan_speed[N], ScreenHandler.DGUSLCD_SetUint8, &ScreenHandler.DGUSLCD_SendFanToDisplay), \ + VPHELPER(VP_FAN##N##_CONTROL, &thermalManager.fan_speed[N], &ScreenHandler.HandleFanControl, nullptr), \ + VPHELPER(VP_FAN##N##_STATUS, &thermalManager.fan_speed[N], nullptr, &ScreenHandler.DGUSLCD_SendFanStatusToDisplay), + REPEAT(FAN_COUNT, FAN_VPHELPER) + #endif + + // Feedrate + VPHELPER(VP_Feedrate_Percentage, &feedrate_percentage, ScreenHandler.DGUSLCD_SetValueDirectly, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), + + // Position Data + VPHELPER(VP_XPos, ¤t_position.x, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_YPos, ¤t_position.y, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_ZPos, ¤t_position.z, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), + + // Level Point Set + VPHELPER(VP_Level_Point_One_X, &level_1_x_point, ScreenHandler.HandleChangeLevelPoint_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Level_Point_One_Y, &level_1_y_point, ScreenHandler.HandleChangeLevelPoint_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Level_Point_Two_X, &level_2_x_point, ScreenHandler.HandleChangeLevelPoint_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Level_Point_Two_Y, &level_2_y_point, ScreenHandler.HandleChangeLevelPoint_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Level_Point_Three_X, &level_3_x_point, ScreenHandler.HandleChangeLevelPoint_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Level_Point_Three_Y, &level_3_y_point, ScreenHandler.HandleChangeLevelPoint_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Level_Point_Four_X, &level_4_x_point, ScreenHandler.HandleChangeLevelPoint_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Level_Point_Four_Y, &level_4_y_point, ScreenHandler.HandleChangeLevelPoint_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Level_Point_Five_X, &level_5_x_point, ScreenHandler.HandleChangeLevelPoint_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Level_Point_Five_Y, &level_5_y_point, ScreenHandler.HandleChangeLevelPoint_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + + // Print Progress + VPHELPER(VP_PrintProgress_Percentage, nullptr, nullptr, ScreenHandler.DGUSLCD_SendPrintProgressToDisplay), + + //LCD Control + VPHELPER(VP_LCD_BLK, &lcd_default_light, &ScreenHandler.LCD_BLK_Adjust, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + + // Print Time + VPHELPER_STR(VP_PrintTime, nullptr, VP_PrintTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeToDisplay_MKS), + + #if ENABLED(PRINTCOUNTER) + VPHELPER_STR(VP_PrintAccTime, nullptr, VP_PrintAccTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintAccTimeToDisplay), + VPHELPER_STR(VP_PrintsTotal, nullptr, VP_PrintsTotal_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintsTotalToDisplay), + #endif + + VPHELPER(VP_X_STEP_PER_MM, &planner.settings.axis_steps_per_mm[X_AXIS], ScreenHandler.HandleStepPerMMChanged_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + VPHELPER(VP_Y_STEP_PER_MM, &planner.settings.axis_steps_per_mm[Y_AXIS], ScreenHandler.HandleStepPerMMChanged_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + VPHELPER(VP_Z_STEP_PER_MM, &planner.settings.axis_steps_per_mm[Z_AXIS], ScreenHandler.HandleStepPerMMChanged_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + + VPHELPER(VP_X_MAX_SPEED, &planner.settings.max_feedrate_mm_s[X_AXIS], ScreenHandler.HandleMaxSpeedChange_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + VPHELPER(VP_Y_MAX_SPEED, &planner.settings.max_feedrate_mm_s[Y_AXIS], ScreenHandler.HandleMaxSpeedChange_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + VPHELPER(VP_Z_MAX_SPEED, &planner.settings.max_feedrate_mm_s[Z_AXIS], ScreenHandler.HandleMaxSpeedChange_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + + #if HOTENDS >= 1 + VPHELPER(VP_E0_MAX_SPEED, &planner.settings.max_feedrate_mm_s[E0_AXIS], ScreenHandler.HandleExtruderMaxSpeedChange_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + #endif + #if HOTENDS >= 2 + VPHELPER(VP_E1_MAX_SPEED, &planner.settings.max_feedrate_mm_s[E1_AXIS], ScreenHandler.HandleExtruderMaxSpeedChange_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + #endif + + VPHELPER(VP_X_ACC_MAX_SPEED, (uint16_t *)&planner.settings.max_acceleration_mm_per_s2[X_AXIS], ScreenHandler.HandleMaxAccChange_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Y_ACC_MAX_SPEED, (uint16_t *)&planner.settings.max_acceleration_mm_per_s2[Y_AXIS], ScreenHandler.HandleMaxAccChange_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Z_ACC_MAX_SPEED, (uint16_t *)&planner.settings.max_acceleration_mm_per_s2[Z_AXIS], ScreenHandler.HandleMaxAccChange_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + + #if HOTENDS >= 1 + VPHELPER(VP_E0_ACC_MAX_SPEED, (uint16_t *)&planner.settings.max_acceleration_mm_per_s2[E0_AXIS], ScreenHandler.HandleExtruderAccChange_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + #if HOTENDS >= 2 + VPHELPER(VP_E1_ACC_MAX_SPEED, (uint16_t *)&planner.settings.max_acceleration_mm_per_s2[E1_AXIS], ScreenHandler.HandleExtruderAccChange_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + + VPHELPER(VP_TRAVEL_SPEED, (uint16_t *)&planner.settings.travel_acceleration, ScreenHandler.HandleTravelAccChange_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + VPHELPER(VP_FEEDRATE_MIN_SPEED, (uint16_t *)&planner.settings.min_feedrate_mm_s, ScreenHandler.HandleFeedRateMinChange_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + VPHELPER(VP_T_F_SPEED, (uint16_t *)&planner.settings.min_travel_feedrate_mm_s, ScreenHandler.HandleMin_T_F_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + VPHELPER(VP_ACC_SPEED, (uint16_t *)&planner.settings.acceleration, ScreenHandler.HandleAccChange_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + + VPHELPER(VP_X_PARK_POS, &x_park_pos, ScreenHandler.GetParkPos_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Y_PARK_POS, &y_park_pos, ScreenHandler.GetParkPos_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_Z_PARK_POS, &z_park_pos, ScreenHandler.GetParkPos_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_MIN_EX_T, &thermalManager.extrude_min_temp, ScreenHandler.HandleGetExMinTemp_MKS, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + + #if ENABLED(SENSORLESS_HOMING) // TMC SENSORLESS Setting + #if AXIS_HAS_STEALTHCHOP(X) + VPHELPER(VP_TMC_X_STEP, &tmc_x_step, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendTMCStepValue), + #endif + #if AXIS_HAS_STEALTHCHOP(Y) + VPHELPER(VP_TMC_Y_STEP, &tmc_y_step, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendTMCStepValue), + #endif + #if AXIS_HAS_STEALTHCHOP(Z) + VPHELPER(VP_TMC_Z_STEP, &tmc_z_step, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendTMCStepValue), + #endif + #endif + + #if HAS_TRINAMIC_CONFIG // TMC Current Setting + #if AXIS_IS_TMC(X) + VPHELPER(VP_TMC_X_Current, &stepperX.val_mA, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + #if AXIS_IS_TMC(Y) + VPHELPER(VP_TMC_Y_Current, &stepperY.val_mA, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + #if AXIS_IS_TMC(Z) + VPHELPER(VP_TMC_Z_Current, &stepperZ.val_mA, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + #if AXIS_IS_TMC(E0) + VPHELPER(VP_TMC_E0_Current, &stepperE0.val_mA, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + #if AXIS_IS_TMC(E1) + VPHELPER(VP_TMC_E1_Current, &stepperE1.val_mA, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + #if AXIS_IS_TMC(X2) + VPHELPER(VP_TMC_X1_Current, &stepperX2.val_mA, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + #if AXIS_IS_TMC(Y2) + VPHELPER(VP_TMC_Y1_Current, &stepperY2.val_mA, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + #if AXIS_IS_TMC(Z2) + VPHELPER(VP_TMC_Z1_Current, &stepperZ2.val_mA, ScreenHandler.TMC_ChangeConfig, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + #endif + #endif + + VPHELPER(VP_EEPROM_CTRL, nullptr, ScreenHandler.EEPROM_CTRL, nullptr), + VPHELPER(VP_LEVEL_BUTTON, nullptr, ScreenHandler.Level_Ctrl_MKS, nullptr), + VPHELPER(VP_LANGUAGE_CHANGE, nullptr, ScreenHandler.LanguageChange_MKS, nullptr), + + //VPHELPER(VP_SD_Print_LiveAdjustZ, nullptr, ScreenHandler.HandleLiveAdjustZ, nullptr), + + VPHELPER(VP_SD_Print_LiveAdjustZ_Confirm, nullptr, ScreenHandler.ZoffsetConfirm, nullptr), + + VPHELPER(VP_ZOffset_Distance,nullptr ,ScreenHandler.GetZoffsetDistance, nullptr), + VPHELPER(VP_MESH_LEVEL_ADJUST, nullptr, ScreenHandler.MeshLevelDistanceConfig, nullptr), + VPHELPER(VP_MESH_LEVEL_POINT,nullptr, ScreenHandler.MeshLevel,nullptr), + VPHELPER(VP_Min_EX_T_E, &thermalManager.extrude_min_temp, &ScreenHandler.GetMinExtrudeTemp, &ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_AutoTurnOffSw, nullptr, &ScreenHandler.GetTurnOffCtrl, nullptr), + + #if HOTENDS >= 1 + VPHELPER(VP_E0_STEP_PER_MM, &planner.settings.axis_steps_per_mm[E_AXIS_N(0)], ScreenHandler.HandleStepPerMMExtruderChanged_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + #endif + #if HOTENDS >= 2 + VPHELPER(VP_E1_STEP_PER_MM, &planner.settings.axis_steps_per_mm[E_AXIS_N(1)], ScreenHandler.HandleStepPerMMExtruderChanged_MKS, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>), + #endif + + + // SDCard File listing + #if ENABLED(SDSUPPORT) + VPHELPER(VP_SD_ScrollEvent, nullptr, ScreenHandler.DGUSLCD_SD_ScrollFilelist, nullptr), + VPHELPER(VP_SD_FileSelected, nullptr, ScreenHandler.DGUSLCD_SD_FileSelected, nullptr), + VPHELPER(VP_SD_FileSelectConfirm, nullptr, ScreenHandler.DGUSLCD_SD_StartPrint, nullptr), + VPHELPER_STR(VP_SD_FileName0, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename), + VPHELPER_STR(VP_SD_FileName1, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename), + VPHELPER_STR(VP_SD_FileName2, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename), + VPHELPER_STR(VP_SD_FileName3, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename), + VPHELPER_STR(VP_SD_FileName4, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename), + VPHELPER_STR(VP_SD_FileName5, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename), + VPHELPER_STR(VP_SD_FileName6, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename), + VPHELPER_STR(VP_SD_FileName7, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename), + VPHELPER_STR(VP_SD_FileName8, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename), + VPHELPER_STR(VP_SD_FileName9, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename), + VPHELPER(VP_SD_ResumePauseAbort, nullptr, ScreenHandler.DGUSLCD_SD_ResumePauseAbort, nullptr), + VPHELPER(VP_SD_AbortPrintConfirmed, nullptr, ScreenHandler.DGUSLCD_SD_ReallyAbort, nullptr), + VPHELPER(VP_SD_Print_Setting, nullptr, ScreenHandler.DGUSLCD_SD_PrintTune, nullptr), + #if ENABLED(BABYSTEPPING) + VPHELPER(VP_SD_Print_LiveAdjustZ,nullptr, ScreenHandler.HandleLiveAdjustZ, &ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<2>), + VPHELPER(VP_ZOffset_DE_DIS,&z_offset_add,nullptr, &ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), + #endif + #if HAS_BED_PROBE + VPHELPER(VP_OFFSET_X, &probe.offset.x, ScreenHandler.GetOffsetValue,ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_OFFSET_Y, &probe.offset.y, ScreenHandler.GetOffsetValue,ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), + VPHELPER(VP_OFFSET_Z, &probe.offset.z, ScreenHandler.GetOffsetValue,ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>), + #endif + #endif + + #if ENABLED(DGUS_UI_WAITING) + VPHELPER(VP_WAITING_STATUS, nullptr, nullptr, ScreenHandler.DGUSLCD_SendWaitingStatusToDisplay), + #endif + + // Messages for the User, shared by the popup and the kill screen. They cant be autouploaded as we do not buffer content. + //{.VP = VP_MSGSTR1, .memadr = nullptr, .size = VP_MSGSTR1_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM}, + //{.VP = VP_MSGSTR2, .memadr = nullptr, .size = VP_MSGSTR2_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM}, + //{.VP = VP_MSGSTR3, .memadr = nullptr, .size = VP_MSGSTR3_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM}, + //{.VP = VP_MSGSTR4, .memadr = nullptr, .size = VP_MSGSTR4_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM}, + + {.VP = VP_MSGSTR1, .memadr = nullptr, .size = VP_MSGSTR1_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplay_Language_MKS}, + {.VP = VP_MSGSTR2, .memadr = nullptr, .size = VP_MSGSTR2_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplay_Language_MKS}, + {.VP = VP_MSGSTR3, .memadr = nullptr, .size = VP_MSGSTR3_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplay_Language_MKS}, + {.VP = VP_MSGSTR4, .memadr = nullptr, .size = VP_MSGSTR4_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplay_Language_MKS}, + + VPHELPER(0, 0, 0, 0) // must be last entry. +}; + +#endif // DGUS_LCD_UI_MKS diff --git a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.h b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.h new file mode 100644 index 000000000000..47695edf0fbd --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSDisplayDef.h @@ -0,0 +1,908 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "../DGUSDisplayDef.h" + +//#define USE_MKS_GREEN_UI +//#define DGUS_MKS_RUNOUT_SENSOR + +#define LOGO_TIME_DELAY TERN(USE_MKS_GREEN_UI, 5000, 1500) + +#if ENABLED(DGUS_MKS_RUNOUT_SENSOR) + #define MT_DET_1_PIN 1 + #define MT_DET_2_PIN 2 + #define MT_DET_PIN_INVERTING false +#endif + +#define MKS_FINSH + +extern uint16_t distanceMove; +extern float distanceFilament; +extern uint16_t FilamentSpeed; +extern float ZOffset_distance; +extern float mesh_adj_distance; +extern float Z_distance; + +extern int16_t level_1_x_point; +extern int16_t level_1_y_point; +extern int16_t level_2_x_point; +extern int16_t level_2_y_point; +extern int16_t level_3_x_point; +extern int16_t level_3_y_point; +extern int16_t level_4_x_point; +extern int16_t level_4_y_point; +extern int16_t level_5_x_point; +extern int16_t level_5_y_point; + +extern uint16_t tim_h; +extern uint16_t tim_m; +extern uint16_t tim_s; + +extern uint16_t x_park_pos; +extern uint16_t y_park_pos; +extern uint16_t z_park_pos; + +extern xyz_pos_t position_before_pause; +void MKS_pause_print_move(); +void MKS_resume_print_move(); + +extern uint16_t min_ex_temp; + +extern float z_offset_add; + +extern uint16_t tmc_x_step; +extern uint16_t tmc_y_step; +extern uint16_t tmc_z_step; + +extern uint16_t lcd_default_light; + +#if AXIS_HAS_STEALTHCHOP(X) + extern uint16_t tmc_x_current; +#endif +#if AXIS_HAS_STEALTHCHOP(Y) + extern uint16_t tmc_y_current; +#endif +#if AXIS_HAS_STEALTHCHOP(Z) + extern uint16_t tmc_z_current; +#endif +#if AXIS_HAS_STEALTHCHOP(E0) + extern uint16_t tmc_e0_current; +#endif +#if AXIS_HAS_STEALTHCHOP(E1) + extern uint16_t tmc_e1_current; +#endif + +typedef enum { + EX_HEATING, + EX_HEAT_STARUS, + EX_CHANGING, + EX_CHANGE_STATUS, + EX_NONE, +} EX_STATUS_DEF; + +typedef struct { + //uint8_t ex_change_flag:1; + //uint8_t ex_heat_flag:1; + uint8_t ex_load_unload_flag:1; //0:unload 1:load + EX_STATUS_DEF ex_status; + uint32_t ex_tick_start; + uint32_t ex_tick_end; + uint32_t ex_speed; + uint32_t ex_length; + uint32_t ex_need_time; +} EX_FILAMENT_DEF; + +extern EX_FILAMENT_DEF ex_filament; + +typedef enum { + UNRUNOUT_STATUS, + RUNOUT_STATUS, + RUNOUT_WAITTING_STATUS, + RUNOUT_BEGIN_STATUS, +} RUNOUT_MKS_STATUS_DEF; + +typedef struct { + RUNOUT_MKS_STATUS_DEF runout_status; + uint8_t pin_status; + uint8_t de_count; + uint8_t de_times; +} RUNOUT_MKS_DEF; + +extern RUNOUT_MKS_DEF runout_mks; + +typedef struct { + uint8_t print_pause_start_flag:1; + uint8_t runout_flag:1; + bool blstatus; + uint16_t x_pos; + uint16_t y_pos; + uint16_t z_pos; +} NOZZLE_PARK_DEF; + +extern NOZZLE_PARK_DEF nozzle_park_mks; + +enum DGUSLCD_Screens : uint8_t { + #if ENABLED(USE_MKS_GREEN_UI) + + DGUSLCD_SCREEN_BOOT = 33, + DGUSLCD_SCREEN_MAIN = 60, + DGUSLCD_SCREEN_STATUS = 60, + DGUSLCD_SCREEN_STATUS2 = 60, + DGUSLCD_SCREEN_PREHEAT = 18, + DGUSLCD_SCREEN_POWER_LOSS = 100, + DGUSLCD_SCREEN_MANUALMOVE = 192, + DGUSLCD_SCREEN_UTILITY = 120, + DGUSLCD_SCREEN_FILAMENT_UNLOADING = 158, + DGUSLCD_SCREEN_SDFILELIST = 15, + DGUSLCD_SCREEN_SDPRINTMANIPULATION = 15, + DGUSLCD_SCREEN_SDPRINTTUNE = 17, + + MKSLCD_SCREEN_BOOT = 33, + MKSLCD_SCREEN_HOME = 60, // MKS main page + MKSLCD_SCREEN_SETTING = 62, // MKS Setting page / no wifi whit + MKSLCD_SCREEM_TOOL = 64, // MKS Tool page + MKSLCD_SCREEN_EXTRUDE_P1 = 75, + MKSLCD_SCREEN_EXTRUDE_P2 = 77, + MKSLCD_SCREEN_LEVEL = 73, + MKSLCD_AUTO_LEVEL = 81, + MKSLCD_SCREEN_MOVE = 66, + MKSLCD_SCREEN_PRINT = 68, + MKSLCD_SCREEN_PAUSE = 70, + MKSLCD_SCREEN_CHOOSE_FILE = 87, + MKSLCD_SCREEN_NO_CHOOSE_FILE = 88, + MKSLCD_SCREEN_Config = 101, + MKSLCD_SCREEN_Config_MOTOR = 103, + MKSLCD_SCREEN_MOTOR_PLUSE = 104, + MKSLCD_SCREEN_MOTOR_SPEED = 102, + MKSLCD_SCREEN_MOTOR_ACC_MAX = 105, + MKSLCD_SCREEN_PRINT_CONFIG = 72, + MKSLCD_SCREEN_LEVEL_DATA = 106, + MKSLCD_PrintPause_SET = 107, + //MKSLCD_FILAMENT_DATA = 50, + MKSLCD_ABOUT = 83, + MKSLCD_PID = 108, + MKSLCD_PAUSE_SETTING_MOVE = 98, + MKSLCD_PAUSE_SETTING_EX = 96, + MKSLCD_PAUSE_SETTING_EX2 = 97, + MKSLCD_SCREEN_PRINT_CONFIRM = 94, + MKSLCD_SCREEN_EX_CONFIG = 112, + MKSLCD_SCREEN_EEP_Config = 89, + MKSLCD_SCREEN_PrintDone = 92, + MKSLCD_SCREEN_TMC_Config = 111, + MKSLCD_Screen_Offset_Config = 109, + MKSLCD_Screen_PMove = 98, + MKSLCD_Screen_Baby = 79, + + #else + + DGUSLCD_SCREEN_BOOT = 120, + DGUSLCD_SCREEN_MAIN = 1, + + DGUSLCD_SCREEN_STATUS = 1, + DGUSLCD_SCREEN_STATUS2 = 1, + DGUSLCD_SCREEN_PREHEAT = 18, + DGUSLCD_SCREEN_POWER_LOSS = 100, + DGUSLCD_SCREEN_MANUALMOVE = 192, + DGUSLCD_SCREEN_UTILITY = 120, + DGUSLCD_SCREEN_FILAMENT_UNLOADING = 158, + DGUSLCD_SCREEN_SDFILELIST = 15, + DGUSLCD_SCREEN_SDPRINTMANIPULATION = 15, + DGUSLCD_SCREEN_SDPRINTTUNE = 17, + + MKSLCD_SCREEN_BOOT = 0, + MKSLCD_SCREEN_HOME = 1, // MKS main page + MKSLCD_SCREEN_SETTING = 2, // MKS Setting page / no wifi whit + MKSLCD_SCREEM_TOOL = 3, // MKS Tool page + MKSLCD_SCREEN_EXTRUDE_P1 = 4, + MKSLCD_SCREEN_EXTRUDE_P2 = 11, + MKSLCD_SCREEN_LEVEL = 5, + MKSLCD_AUTO_LEVEL = 73, + MKSLCD_SCREEN_LEVEL_PRESS = 9, + MKSLCD_SCREEN_MOVE = 6, + MKSLCD_SCREEN_PRINT = 7, + MKSLCD_SCREEN_PRINT_PRESS = 13, + MKSLCD_SCREEN_PAUSE = 26, + MKSLCD_SCREEN_PAUSE_PRESS = 26, + MKSLCD_SCREEN_CHOOSE_FILE = 15, + MKSLCD_SCREEN_NO_CHOOSE_FILE = 17, + MKSLCD_SCREEN_Config = 46, + MKSLCD_SCREEN_Config_MOTOR = 47, + MKSLCD_SCREEN_MOTOR_PLUSE = 51, + MKSLCD_SCREEN_MOTOR_SPEED = 55, + MKSLCD_SCREEN_MOTOR_ACC_MAX = 53, + MKSLCD_SCREEN_PRINT_CONFIG = 60, + MKSLCD_SCREEN_LEVEL_DATA = 48, + MKSLCD_PrintPause_SET = 49, + MKSLCD_FILAMENT_DATA = 50, + MKSLCD_ABOUT = 36, + MKSLCD_PID = 56, + MKSLCD_PAUSE_SETTING_MOVE = 58, + MKSLCD_PAUSE_SETTING_EX = 57, + MKSLCD_PAUSE_SETTING_EX2 = 61, + MKSLCD_SCREEN_NO_FILE = 42, + MKSLCD_SCREEN_PRINT_CONFIRM = 43, + MKSLCD_SCREEN_EX_CONFIG = 65, + MKSLCD_SCREEN_EEP_Config = 20, + MKSLCD_SCREEN_PrintDone = 25, + MKSLCD_SCREEN_TMC_Config = 70, + MKSLCD_Screen_Offset_Config = 30, + MKSLCD_Screen_PMove = 64, + MKSLCD_Screen_Baby = 71, + + #endif + + DGUSLCD_SCREEN_CONFIRM = 240, + DGUSLCD_SCREEN_KILL = 250, ///< Kill Screen. Must always be 250 (to be able to display "Error wrong LCD Version") + DGUSLCD_SCREEN_WAITING = 251, + DGUSLCD_SCREEN_POPUP = 252, ///< special target, popup screen will also return this code to say "return to previous screen" + DGUSLDC_SCREEN_UNUSED = 255 +}; + +// Display Memory layout used (T5UID) +// Except system variables this is arbitrary, just to organize stuff.... + +// 0x0000 .. 0x0FFF -- System variables and reserved by the display +// 0x1000 .. 0x1FFF -- Variables to never change location, regardless of UI Version +// 0x2000 .. 0x2FFF -- Controls (VPs that will trigger some action) +// 0x3000 .. 0x4FFF -- Marlin Data to be displayed +// 0x5000 .. -- SPs (if we want to modify display elements, e.g change color or like) -- currently unused + +// As there is plenty of space (at least most displays have >8k RAM), we do not pack them too tight, +// so that we can keep variables nicely together in the address space. + +// UI Version always on 0x1000...0x1002 so that the firmware can check this and bail out. + +// constexpr uint16_t VP_UI_VERSION_MAJOR = 0x1000; // Major -- incremented when incompatible +// constexpr uint16_t VP_UI_VERSION_MINOR = 0x1001; // Minor -- incremented on new features, but compatible +// constexpr uint16_t VP_UI_VERSION_PATCH = 0x1002; // Patch -- fixed which do not change functionality. +// constexpr uint16_t VP_UI_FLAVOUR = 0x1010; // lets reserve 16 bytes here to determine if UI is suitable for this Marlin. tbd. + +// Storage space for the Killscreen messages. 0x1100 - 0x1200 . Reused for the popup. +// constexpr uint16_t VP_MSGSTR1 = 0x1100; +// constexpr uint8_t VP_MSGSTR1_LEN = 0x20; // might be more place for it... +// constexpr uint16_t VP_MSGSTR2 = 0x1140; +// constexpr uint8_t VP_MSGSTR2_LEN = 0x20; +// constexpr uint16_t VP_MSGSTR3 = 0x1180; +// constexpr uint8_t VP_MSGSTR3_LEN = 0x20; +// constexpr uint16_t VP_MSGSTR4 = 0x11C0; +// constexpr uint8_t VP_MSGSTR4_LEN = 0x20; + +// Screenchange request for screens that only make sense when printer is idle. +// e.g movement is only allowed if printer is not printing. +// Marlin must confirm by setting the screen manually. +// constexpr uint16_t VP_SCREENCHANGE_ASK = 0x2000; +// constexpr uint16_t VP_SCREENCHANGE = 0x2001; // Key-Return button to new menu pressed. Data contains target screen in low byte and info in high byte. +// constexpr uint16_t VP_TEMP_ALL_OFF = 0x2002; // Turn all heaters off. Value arbitrary ;)= +// constexpr uint16_t VP_SCREENCHANGE_WHENSD = 0x2003; // "Print" Button touched -- go only there if there is an SD Card. +// constexpr uint16_t VP_CONFIRMED = 0x2010; // OK on confirm screen. + +// // Buttons on the SD-Card File listing. +// constexpr uint16_t VP_SD_ScrollEvent = 0x2020; // Data: 0 for "up a directory", numbers are the amount to scroll, e.g -1 one up, 1 one down +// constexpr uint16_t VP_SD_FileSelected = 0x2022; // Number of file field selected. +// constexpr uint16_t VP_SD_FileSelectConfirm = 0x2024; // (This is a virtual VP and emulated by the Confirm Screen when a file has been confirmed) + +// constexpr uint16_t VP_SD_ResumePauseAbort = 0x2026; // Resume(Data=0), Pause(Data=1), Abort(Data=2) SD Card prints +// constexpr uint16_t VP_SD_AbortPrintConfirmed = 0x2028; // Abort print confirmation (virtual, will be injected by the confirm dialog) +// constexpr uint16_t VP_SD_Print_Setting = 0x2040; +// constexpr uint16_t VP_SD_Print_LiveAdjustZ = 0x2050; // Data: 0 down, 1 up + +// Controls for movement (we can't use the incremental / decremental feature of the display at this feature works only with 16 bit values +// (which would limit us to 655.35mm, which is likely not a problem for common setups, but i don't want to rule out hangprinters support) +// A word about the coding: The VP will be per axis and the return code will be an signed 16 bit value in 0.01 mm resolution, telling us +// the relative travel amount t he user wants to do. So eg. if the display sends us VP=2100 with value 100, the user wants us to move X by +1 mm. +// constexpr uint16_t VP_MOVE_X = 0x2100; +// constexpr uint16_t VP_MOVE_Y = 0x2102; +// constexpr uint16_t VP_MOVE_Z = 0x2104; +// constexpr uint16_t VP_MOVE_E0 = 0x2110; +// constexpr uint16_t VP_MOVE_E1 = 0x2112; +// //constexpr uint16_t VP_MOVE_E2 = 0x2114; +// //constexpr uint16_t VP_MOVE_E3 = 0x2116; +// //constexpr uint16_t VP_MOVE_E4 = 0x2118; +// //constexpr uint16_t VP_MOVE_E5 = 0x211A; +// constexpr uint16_t VP_HOME_ALL = 0x2120; +// constexpr uint16_t VP_MOTOR_LOCK_UNLOK = 0x2130; +// constexpr uint16_t VP_XYZ_HOME = 0x2132; + +// Power loss recovery +// constexpr uint16_t VP_POWER_LOSS_RECOVERY = 0x2180; + +// // Fan Control Buttons , switch between "off" and "on" +// constexpr uint16_t VP_FAN0_CONTROL = 0x2200; +// constexpr uint16_t VP_FAN1_CONTROL = 0x2202; +// constexpr uint16_t VP_FAN2_CONTROL = 0x2204; +// constexpr uint16_t VP_FAN3_CONTROL = 0x2206; + +// // Heater Control Buttons , triged between "cool down" and "heat PLA" state +// constexpr uint16_t VP_E0_CONTROL = 0x2210; +// constexpr uint16_t VP_E1_CONTROL = 0x2212; +// //constexpr uint16_t VP_E2_CONTROL = 0x2214; +// //constexpr uint16_t VP_E3_CONTROL = 0x2216; +// //constexpr uint16_t VP_E4_CONTROL = 0x2218; +// //constexpr uint16_t VP_E5_CONTROL = 0x221A; +// constexpr uint16_t VP_BED_CONTROL = 0x221C; + +// // Preheat +// constexpr uint16_t VP_E0_BED_PREHEAT = 0x2220; +// constexpr uint16_t VP_E1_BED_PREHEAT = 0x2222; +// //constexpr uint16_t VP_E2_BED_PREHEAT = 0x2224; +// //constexpr uint16_t VP_E3_BED_PREHEAT = 0x2226; +// //constexpr uint16_t VP_E4_BED_PREHEAT = 0x2228; +// //constexpr uint16_t VP_E5_BED_PREHEAT = 0x222A; + +// // Filament load and unload +// // constexpr uint16_t VP_E0_FILAMENT_LOAD_UNLOAD = 0x2300; +// // constexpr uint16_t VP_E1_FILAMENT_LOAD_UNLOAD = 0x2302; + +// // Settings store , reset + +// // PID autotune +// constexpr uint16_t VP_PID_AUTOTUNE_E0 = 0x2410; +// constexpr uint16_t VP_PID_AUTOTUNE_E1 = 0x2412; +// //constexpr uint16_t VP_PID_AUTOTUNE_E2 = 0x2414; +// //constexpr uint16_t VP_PID_AUTOTUNE_E3 = 0x2416; +// //constexpr uint16_t VP_PID_AUTOTUNE_E4 = 0x2418; +// //constexpr uint16_t VP_PID_AUTOTUNE_E5 = 0x241A; +// constexpr uint16_t VP_PID_AUTOTUNE_BED = 0x2420; +// // Calibrate Z +// constexpr uint16_t VP_Z_CALIBRATE = 0x2430; + +// First layer cal +// constexpr uint16_t VP_Z_FIRST_LAYER_CAL = 0x2500; // Data: 0 - Cancel first layer cal progress, >0 filament type have loaded + +// Firmware version on the boot screen. +// constexpr uint16_t VP_MARLIN_VERSION = 0x3000; +// constexpr uint8_t VP_MARLIN_VERSION_LEN = 16; // there is more space on the display, if needed. + +// Place for status messages. +constexpr uint16_t VP_M117 = 0x7020; +constexpr uint8_t VP_M117_LEN = 0x20; + +// // Temperatures. +// constexpr uint16_t VP_T_E0_Is = 0x3060; // 4 Byte Integer +// constexpr uint16_t VP_T_E0_Set = 0x3062; // 2 Byte Integer +// constexpr uint16_t VP_T_E1_Is = 0x3064; // 4 Byte Integer +// // reserved to support up to 6 Extruders: +// constexpr uint16_t VP_T_E1_Set = 0x3066; // 2 Byte Integer +// constexpr uint16_t VP_T_E2_Is = 0x3068; // 4 Byte Integer +// constexpr uint16_t VP_T_E2_Set = 0x306A; // 2 Byte Integer +// constexpr uint16_t VP_T_E3_Is = 0x306C; // 4 Byte Integer +// constexpr uint16_t VP_T_E3_Set = 0x306E; // 2 Byte Integer +// constexpr uint16_t VP_T_E4_Is = 0x3070; // 4 Byte Integer +// constexpr uint16_t VP_T_E4_Set = 0x3072; // 2 Byte Integer +// constexpr uint16_t VP_T_E5_Is = 0x3074; // 4 Byte Integer +// constexpr uint16_t VP_T_E5_Set = 0x3076; // 2 Byte Integer +// constexpr uint16_t VP_T_E6_Is = 0x3078; // 4 Byte Integer +// constexpr uint16_t VP_T_E6_Set = 0x307A; // 2 Byte Integer +// constexpr uint16_t VP_T_E7_Is = 0x3078; // 4 Byte Integer +// constexpr uint16_t VP_T_E7_Set = 0x307A; // 2 Byte Integer + + +// constexpr uint16_t VP_T_Bed_Is = 0x3080; // 4 Byte Integer +// constexpr uint16_t VP_T_Bed_Set = 0x3082; // 2 Byte Integer + +// constexpr uint16_t VP_Flowrate_E0 = 0x3090; // 2 Byte Integer +// constexpr uint16_t VP_Flowrate_E1 = 0x3092; // 2 Byte Integer +// // reserved for up to 6 Extruders: +// constexpr uint16_t VP_Flowrate_E2 = 0x3094; +// constexpr uint16_t VP_Flowrate_E3 = 0x3096; +// constexpr uint16_t VP_Flowrate_E4 = 0x3098; +// constexpr uint16_t VP_Flowrate_E5 = 0x309A; + +// constexpr uint16_t VP_Fan0_Percentage = 0x3100; // 2 Byte Integer (0..100) +// constexpr uint16_t VP_Fan1_Percentage = 0x3102; // 2 Byte Integer (0..100) +// constexpr uint16_t VP_Fan2_Percentage = 0x3104; // 2 Byte Integer (0..100) +// constexpr uint16_t VP_Fan3_Percentage = 0x3106; // 2 Byte Integer (0..100) +// constexpr uint16_t VP_Feedrate_Percentage = 0x3108; // 2 Byte Integer (0..100) + +// Actual Position +// constexpr uint16_t VP_XPos = 0x3110; // 4 Byte Fixed point number; format xxx.yy +// constexpr uint16_t VP_YPos = 0x3112; // 4 Byte Fixed point number; format xxx.yy +// constexpr uint16_t VP_ZPos = 0x3114; // 4 Byte Fixed point number; format xxx.yy +// constexpr uint16_t VP_EPos = 0x3120; // 4 Byte Fixed point number; format xxx.yy + +// constexpr uint16_t VP_PrintProgress_Percentage = 0x3130; // 2 Byte Integer (0..100) + +// constexpr uint16_t VP_PrintTime = 0x3140; +// constexpr uint16_t VP_PrintTime_LEN = 32; + +// constexpr uint16_t VP_PrintAccTime = 0x3160; +// constexpr uint16_t VP_PrintAccTime_LEN = 32; + +// constexpr uint16_t VP_PrintsTotal = 0x3180; +// constexpr uint16_t VP_PrintsTotal_LEN = 16; + +// // SDCard File Listing +// constexpr uint16_t VP_SD_FileName_LEN = 32; // LEN is shared for all entries. +// constexpr uint16_t DGUS_SD_FILESPERSCREEN = 8; // FIXME move that info to the display and read it from there. +// constexpr uint16_t VP_SD_FileName0 = 0x3200; +// constexpr uint16_t VP_SD_FileName1 = 0x3220; +// constexpr uint16_t VP_SD_FileName2 = 0x3240; +// constexpr uint16_t VP_SD_FileName3 = 0x3260; +// constexpr uint16_t VP_SD_FileName4 = 0x3280; +// constexpr uint16_t VP_SD_FileName5 = 0x32A0; +// constexpr uint16_t VP_SD_FileName6 = 0x32C0; +// constexpr uint16_t VP_SD_FileName7 = 0x32E0; + +// Heater status +constexpr uint16_t VP_E0_STATUS = 0x3410; +constexpr uint16_t VP_E1_STATUS = 0x3412; +//constexpr uint16_t VP_E2_STATUS = 0x3414; +//constexpr uint16_t VP_E3_STATUS = 0x3416; +//constexpr uint16_t VP_E4_STATUS = 0x3418; +//constexpr uint16_t VP_E5_STATUS = 0x341A; +constexpr uint16_t VP_MOVE_OPTION = 0x3500; + +// // PIDs +// constexpr uint16_t VP_E0_PID_P = 0x3700; // at the moment , 2 byte unsigned int , 0~1638.4 +// constexpr uint16_t VP_E0_PID_I = 0x3702; +// constexpr uint16_t VP_E0_PID_D = 0x3704; +// constexpr uint16_t VP_E1_PID_P = 0x3706; // at the moment , 2 byte unsigned int , 0~1638.4 +// constexpr uint16_t VP_E1_PID_I = 0x3708; +// constexpr uint16_t VP_E1_PID_D = 0x370A; +// constexpr uint16_t VP_BED_PID_P = 0x3710; +// constexpr uint16_t VP_BED_PID_I = 0x3712; +// constexpr uint16_t VP_BED_PID_D = 0x3714; + +// Wating screen status +constexpr uint16_t VP_WAITING_STATUS = 0x3800; + +// SPs for certain variables... +// located at 0x5000 and up +// Not used yet! +// This can be used e.g to make controls / data display invisible +constexpr uint16_t SP_T_E0_Is = 0x5000; +constexpr uint16_t SP_T_E0_Set = 0x5010; +constexpr uint16_t SP_T_E1_Is = 0x5020; +constexpr uint16_t SP_T_Bed_Is = 0x5030; +constexpr uint16_t SP_T_Bed_Set = 0x5040; + +/************************************************************************************************************************* + ************************************************************************************************************************* + * DGUS for MKS Mem layout + ************************************************************************************************************************ + ************************************************************************************************************************/ + +#if ENABLED(MKS_FINSH) + /* -------------------------------0x1000-0x1FFF------------------------------- */ + constexpr uint16_t VP_MSGSTR1 = 0x1100; + constexpr uint8_t VP_MSGSTR1_LEN = 0x20; // might be more place for it... + constexpr uint16_t VP_MSGSTR2 = 0x1140; + constexpr uint8_t VP_MSGSTR2_LEN = 0x20; + constexpr uint16_t VP_MSGSTR3 = 0x1180; + constexpr uint8_t VP_MSGSTR3_LEN = 0x20; + constexpr uint16_t VP_MSGSTR4 = 0x11C0; + constexpr uint8_t VP_MSGSTR4_LEN = 0x20; + + constexpr uint16_t VP_MARLIN_VERSION = 0x1A00; + constexpr uint8_t VP_MARLIN_VERSION_LEN = 16; // there is more space on the display, if needed. + + + constexpr uint16_t VP_SCREENCHANGE_ASK = 0x1500; + constexpr uint16_t VP_SCREENCHANGE = 0x1501; // Key-Return button to new menu pressed. Data contains target screen in low byte and info in high byte. + constexpr uint16_t VP_TEMP_ALL_OFF = 0x1502; // Turn all heaters off. Value arbitrary ;)= + constexpr uint16_t VP_SCREENCHANGE_WHENSD = 0x1503; // "Print" Button touched -- go only there if there is an SD Card. + constexpr uint16_t VP_CONFIRMED = 0x1510; // OK on confirm screen. + + constexpr uint16_t VP_BACK_PAGE = 0x1600; + constexpr uint16_t VP_SETTINGS = 0x1620; + // Power loss recovery + constexpr uint16_t VP_POWER_LOSS_RECOVERY = 0x1680; + /* -------------------------------0x2000-0x2FFF------------------------------- */ + // Temperatures. + constexpr uint16_t VP_T_E0_Is = 0x2000; // 4 Byte Integer + constexpr uint16_t VP_T_E0_Set = 0x2004; // 2 Byte Integer + constexpr uint16_t VP_T_E1_Is = 0x2008; // 4 Byte Integer + constexpr uint16_t VP_T_E1_Set = 0x200B; // 2 Byte Integer + constexpr uint16_t VP_T_E2_Is = 0x2010; // 4 Byte Integer + constexpr uint16_t VP_T_E2_Set = 0x2014; // 2 Byte Integer + constexpr uint16_t VP_T_E3_Is = 0x2018; // 4 Byte Integer + constexpr uint16_t VP_T_E3_Set = 0x201B; // 2 Byte Integer + constexpr uint16_t VP_T_E4_Is = 0x2020; // 4 Byte Integer + constexpr uint16_t VP_T_E4_Set = 0x2024; // 2 Byte Integer + constexpr uint16_t VP_T_E5_Is = 0x2028; // 4 Byte Integer + constexpr uint16_t VP_T_E5_Set = 0x202B; // 2 Byte Integer + constexpr uint16_t VP_T_E6_Is = 0x2030; // 4 Byte Integer + constexpr uint16_t VP_T_E6_Set = 0x2034; // 2 Byte Integer + constexpr uint16_t VP_T_E7_Is = 0x2038; // 4 Byte Integer + constexpr uint16_t VP_T_E7_Set = 0x203B; // 2 Byte Integer + + constexpr uint16_t VP_T_Bed_Is = 0x2040; // 4 Byte Integer + constexpr uint16_t VP_T_Bed_Set = 0x2044; // 2 Byte Integer + + constexpr uint16_t VP_Min_EX_T_E = 0x2100; + + constexpr uint16_t VP_Flowrate_E0 = 0x2200; // 2 Byte Integer + constexpr uint16_t VP_Flowrate_E1 = 0x2202; // 2 Byte Integer + constexpr uint16_t VP_Flowrate_E2 = 0x2204; + constexpr uint16_t VP_Flowrate_E3 = 0x2206; + constexpr uint16_t VP_Flowrate_E4 = 0x2208; + constexpr uint16_t VP_Flowrate_E5 = 0x220A; + constexpr uint16_t VP_Flowrate_E6 = 0x220C; + constexpr uint16_t VP_Flowrate_E7 = 0x220E; + + // Move + constexpr uint16_t VP_MOVE_X = 0x2300; + constexpr uint16_t VP_MOVE_Y = 0x2302; + constexpr uint16_t VP_MOVE_Z = 0x2304; + constexpr uint16_t VP_MOVE_E0 = 0x2310; + constexpr uint16_t VP_MOVE_E1 = 0x2312; + constexpr uint16_t VP_MOVE_E2 = 0x2314; + constexpr uint16_t VP_MOVE_E3 = 0x2316; + constexpr uint16_t VP_MOVE_E4 = 0x2318; + constexpr uint16_t VP_MOVE_E5 = 0x231A; + constexpr uint16_t VP_MOVE_E6 = 0x231C; + constexpr uint16_t VP_MOVE_E7 = 0x231E; + constexpr uint16_t VP_HOME_ALL = 0x2320; + constexpr uint16_t VP_MOTOR_LOCK_UNLOK = 0x2330; + constexpr uint16_t VP_MOVE_DISTANCE = 0x2334; + constexpr uint16_t VP_X_HOME = 0x2336; + constexpr uint16_t VP_Y_HOME = 0x2338; + constexpr uint16_t VP_Z_HOME = 0x233A; + + // Fan Control Buttons , switch between "off" and "on" + constexpr uint16_t VP_FAN0_CONTROL = 0x2350; + constexpr uint16_t VP_FAN1_CONTROL = 0x2352; + constexpr uint16_t VP_FAN2_CONTROL = 0x2354; + constexpr uint16_t VP_FAN3_CONTROL = 0x2356; + constexpr uint16_t VP_FAN4_CONTROL = 0x2358; + constexpr uint16_t VP_FAN5_CONTROL = 0x235A; + + constexpr uint16_t VP_LANGUAGE_CHANGE = 0x2380; + constexpr uint16_t VP_LANGUAGE_CHANGE1 = 0x2382; + constexpr uint16_t VP_LANGUAGE_CHANGE2 = 0x2384; + constexpr uint16_t VP_LANGUAGE_CHANGE3 = 0x2386; + constexpr uint16_t VP_LANGUAGE_CHANGE4 = 0x2388; + constexpr uint16_t VP_LANGUAGE_CHANGE5 = 0x238A; + + // LEVEL + constexpr uint16_t VP_LEVEL_POINT = 0x2400; + constexpr uint16_t VP_MESH_LEVEL_POINT = 0x2410; + constexpr uint16_t VP_MESH_LEVEL_ADJUST = 0x2412; + constexpr uint16_t VP_MESH_LEVEL_DIP = 0x2414; + constexpr uint16_t VP_MESH_LEVEL_POINT_X = 0x2416; + constexpr uint16_t VP_MESH_LEVEL_POINT_Y = 0x2418; + constexpr uint16_t VP_LEVEL_BUTTON = 0x2420; + constexpr uint16_t VP_MESH_LEVEL_POINT_DIS = 0x2422; + constexpr uint16_t VP_MESH_LEVEL_BACK = 0x2424; + + constexpr uint16_t VP_E0_FILAMENT_LOAD_UNLOAD = 0x2500; + constexpr uint16_t VP_E1_FILAMENT_LOAD_UNLOAD = 0x2504; + constexpr uint16_t VP_LOAD_Filament = 0x2508; + // constexpr uint16_t VP_LOAD_UNLOAD_Cancle = 0x250A; + constexpr uint16_t VP_UNLOAD_Filament = 0x250B; + constexpr uint16_t VP_Filament_distance = 0x2600; + constexpr uint16_t VP_Filament_speed = 0x2604; + constexpr uint16_t VP_MIN_EX_T = 0x2606; + + constexpr uint16_t VP_E1_Filament_distance = 0x2614; + constexpr uint16_t VP_E1_Filament_speed = 0x2616; + constexpr uint16_t VP_E1_MIN_EX_T = 0x2618; + + constexpr uint16_t VP_Fan0_Percentage = 0x2700; // 2 Byte Integer (0..100) + constexpr uint16_t VP_Fan1_Percentage = 0x2702; // 2 Byte Integer (0..100) + constexpr uint16_t VP_Fan2_Percentage = 0x2704; // 2 Byte Integer (0..100) + constexpr uint16_t VP_Fan3_Percentage = 0x2706; // 2 Byte Integer (0..100) + constexpr uint16_t VP_Feedrate_Percentage = 0x2708; // 2 Byte Integer (0..100) + + // Fan status + constexpr uint16_t VP_FAN0_STATUS = 0x2710; + constexpr uint16_t VP_FAN1_STATUS = 0x2712; + constexpr uint16_t VP_FAN2_STATUS = 0x2714; + constexpr uint16_t VP_FAN3_STATUS = 0x2716; + + // Step per mm + constexpr uint16_t VP_X_STEP_PER_MM = 0x2900; // at the moment , 2 byte unsigned int , 0~1638.4 + constexpr uint16_t VP_Y_STEP_PER_MM = 0x2904; + constexpr uint16_t VP_Z_STEP_PER_MM = 0x2908; + constexpr uint16_t VP_E0_STEP_PER_MM = 0x2910; + constexpr uint16_t VP_E1_STEP_PER_MM = 0x2912; + constexpr uint16_t VP_E2_STEP_PER_MM = 0x2914; + constexpr uint16_t VP_E3_STEP_PER_MM = 0x2916; + constexpr uint16_t VP_E4_STEP_PER_MM = 0x2918; + constexpr uint16_t VP_E5_STEP_PER_MM = 0x291A; + constexpr uint16_t VP_E6_STEP_PER_MM = 0x291C; + constexpr uint16_t VP_E7_STEP_PER_MM = 0x291E; + + constexpr uint16_t VP_X_MAX_SPEED = 0x2A00; + constexpr uint16_t VP_Y_MAX_SPEED = 0x2A04; + constexpr uint16_t VP_Z_MAX_SPEED = 0x2A08; + constexpr uint16_t VP_E0_MAX_SPEED = 0x2A0C; + constexpr uint16_t VP_E1_MAX_SPEED = 0x2A10; + + constexpr uint16_t VP_X_ACC_MAX_SPEED = 0x2A28; + constexpr uint16_t VP_Y_ACC_MAX_SPEED = 0x2A2C; + constexpr uint16_t VP_Z_ACC_MAX_SPEED = 0x2A30; + constexpr uint16_t VP_E0_ACC_MAX_SPEED = 0x2A34; + constexpr uint16_t VP_E1_ACC_MAX_SPEED = 0x2A38; + + constexpr uint16_t VP_TRAVEL_SPEED = 0x2A3C; + constexpr uint16_t VP_FEEDRATE_MIN_SPEED = 0x2A40; + constexpr uint16_t VP_T_F_SPEED = 0x2A44; + constexpr uint16_t VP_ACC_SPEED = 0x2A48; + + /* -------------------------------0x3000-0x3FFF------------------------------- */ + // Buttons on the SD-Card File listing. + constexpr uint16_t VP_SD_ScrollEvent = 0x3020; // Data: 0 for "up a directory", numbers are the amount to scroll, e.g -1 one up, 1 one down + constexpr uint16_t VP_SD_FileSelected = 0x3022; // Number of file field selected. + constexpr uint16_t VP_SD_FileSelectConfirm = 0x3024; // (This is a virtual VP and emulated by the Confirm Screen when a file has been confirmed) + constexpr uint16_t VP_SD_ResumePauseAbort = 0x3026; // Resume(Data=0), Pause(Data=1), Abort(Data=2) SD Card prints + constexpr uint16_t VP_SD_AbortPrintConfirmed = 0x3028; // Abort print confirmation (virtual, will be injected by the confirm dialog) + constexpr uint16_t VP_SD_Print_Setting = 0x3040; + constexpr uint16_t VP_SD_Print_LiveAdjustZ = 0x3050; // Data: 0 down, 1 up + constexpr uint16_t VP_SD_Print_LiveAdjustZ_Confirm = 0x3060; + constexpr uint16_t VP_ZOffset_Distance = 0x3070; + constexpr uint16_t VP_ZOffset_DE_DIS = 0x3080; + // SDCard File Listing + constexpr uint16_t VP_SD_FileName_LEN = 32; // LEN is shared for all entries. + constexpr uint16_t DGUS_SD_FILESPERSCREEN = 10; // FIXME move that info to the display and read it from there. + constexpr uint16_t VP_SD_FileName0 = 0x3100; + constexpr uint16_t VP_SD_FileName1 = 0x3120; + constexpr uint16_t VP_SD_FileName2 = 0x3140; + constexpr uint16_t VP_SD_FileName3 = 0x3160; + constexpr uint16_t VP_SD_FileName4 = 0x3180; + constexpr uint16_t VP_SD_FileName5 = 0x31A0; + constexpr uint16_t VP_SD_FileName6 = 0x31C0; + constexpr uint16_t VP_SD_FileName7 = 0x31E0; + constexpr uint16_t VP_SD_FileName8 = 0x3200; + constexpr uint16_t VP_SD_FileName9 = 0x3220; + + constexpr uint16_t VP_SD_Print_ProbeOffsetZ = 0x32A0; + constexpr uint16_t VP_SD_Print_Baby = 0x32B0; + constexpr uint16_t VP_SD_Print_Filename = 0x32C0; + + // X Y Z Point + constexpr uint16_t VP_XPos = 0x3300; // 4 Byte Fixed point number; format xxx.yy + constexpr uint16_t VP_YPos = 0x3302; // 4 Byte Fixed point number; format xxx.yy + constexpr uint16_t VP_ZPos = 0x3304; // 4 Byte Fixed point number; format xxx.yy + constexpr uint16_t VP_EPos = 0x3306; // 4 Byte Fixed point number; format xxx.yy + + // Print + constexpr uint16_t VP_PrintProgress_Percentage = 0x3330; // 2 Byte Integer (0..100) + constexpr uint16_t VP_PrintTime = 0x3340; + constexpr uint16_t VP_PrintTime_LEN = 32; + constexpr uint16_t VP_PrintAccTime = 0x3360; + constexpr uint16_t VP_PrintAccTime_LEN = 32; + constexpr uint16_t VP_PrintsTotal = 0x3380; + constexpr uint16_t VP_PrintsTotal_LEN = 16; + + constexpr uint16_t VP_File_Pictutr0 = 0x3400; + constexpr uint16_t VP_File_Pictutr1 = 0x3402; + constexpr uint16_t VP_File_Pictutr2 = 0x3404; + constexpr uint16_t VP_File_Pictutr3 = 0x3406; + constexpr uint16_t VP_File_Pictutr4 = 0x3408; + constexpr uint16_t VP_File_Pictutr5 = 0x340A; + constexpr uint16_t VP_File_Pictutr6 = 0x340C; + constexpr uint16_t VP_File_Pictutr7 = 0x340E; + constexpr uint16_t VP_File_Pictutr8 = 0x3410; + constexpr uint16_t VP_File_Pictutr9 = 0x3412; + + constexpr uint16_t VP_BED_STATUS = 0x341C; + + constexpr uint16_t VP_TMC_X_STEP = 0x3430; + constexpr uint16_t VP_TMC_Y_STEP = 0x3432; + constexpr uint16_t VP_TMC_Z_STEP = 0x3434; + + constexpr uint16_t VP_TMC_X1_Current = 0x3436; + constexpr uint16_t VP_TMC_Y1_Current = 0x3438; + constexpr uint16_t VP_TMC_X_Current = 0x343A; + constexpr uint16_t VP_TMC_Y_Current = 0x343C; + constexpr uint16_t VP_TMC_Z_Current = 0x343E; + constexpr uint16_t VP_TMC_E0_Current = 0x3440; + constexpr uint16_t VP_TMC_E1_Current = 0x3442; + constexpr uint16_t VP_TMC_Z1_Current = 0x3444; + + + constexpr uint16_t VP_PrintTime_H = 0x3500; + constexpr uint16_t VP_PrintTime_M = 0x3502; + constexpr uint16_t VP_PrintTime_S = 0x3504; + + // PIDs + constexpr uint16_t VP_E0_PID_P = 0x3700; // at the moment , 2 byte unsigned int , 0~1638.4 + constexpr uint16_t VP_E0_PID_I = 0x3702; + constexpr uint16_t VP_E0_PID_D = 0x3704; + constexpr uint16_t VP_E1_PID_P = 0x3706; // at the moment , 2 byte unsigned int , 0~1638.4 + constexpr uint16_t VP_E1_PID_I = 0x3708; + constexpr uint16_t VP_E1_PID_D = 0x370A; + constexpr uint16_t VP_BED_PID_P = 0x3710; + constexpr uint16_t VP_BED_PID_I = 0x3712; + constexpr uint16_t VP_BED_PID_D = 0x3714; + + constexpr uint16_t VP_EEPROM_CTRL = 0x3720; + + constexpr uint16_t VP_OFFSET_X = 0x3724; + constexpr uint16_t VP_OFFSET_Y = 0x3728; + constexpr uint16_t VP_OFFSET_Z = 0x372B; + + // PID autotune + constexpr uint16_t VP_PID_AUTOTUNE_E0 = 0x3800; + constexpr uint16_t VP_PID_AUTOTUNE_E1 = 0x3802; + constexpr uint16_t VP_PID_AUTOTUNE_E2 = 0x3804; + constexpr uint16_t VP_PID_AUTOTUNE_E3 = 0x3806; + constexpr uint16_t VP_PID_AUTOTUNE_E4 = 0x3808; + constexpr uint16_t VP_PID_AUTOTUNE_E5 = 0x380A; + constexpr uint16_t VP_PID_AUTOTUNE_BED = 0x380C; + // Calibrate Z + constexpr uint16_t VP_Z_CALIBRATE = 0x3810; + + constexpr uint16_t VP_AutoTurnOffSw = 0x3812; + constexpr uint16_t VP_LCD_BLK = 0x3814; + + constexpr uint16_t VP_X_PARK_POS = 0x3900; + constexpr uint16_t VP_Y_PARK_POS = 0x3902; + constexpr uint16_t VP_Z_PARK_POS = 0x3904; + + /* -------------------------------0x4000-0x4FFF------------------------------- */ + // Heater Control Buttons , triged between "cool down" and "heat PLA" state + constexpr uint16_t VP_E0_CONTROL = 0x4010; + constexpr uint16_t VP_E1_CONTROL = 0x4012; + //constexpr uint16_t VP_E2_CONTROL = 0x2214; + //constexpr uint16_t VP_E3_CONTROL = 0x2216; + //constexpr uint16_t VP_E4_CONTROL = 0x2218; + //constexpr uint16_t VP_E5_CONTROL = 0x221A; + constexpr uint16_t VP_BED_CONTROL = 0x401C; + + // Preheat + constexpr uint16_t VP_E0_BED_PREHEAT = 0x4020; + constexpr uint16_t VP_E1_BED_PREHEAT = 0x4022; + //constexpr uint16_t VP_E2_BED_PREHEAT = 0x4024; + //constexpr uint16_t VP_E3_BED_PREHEAT = 0x4026; + //constexpr uint16_t VP_E4_BED_PREHEAT = 0x4028; + //constexpr uint16_t VP_E5_BED_PREHEAT = 0x402A; + + // Filament load and unload + // constexpr uint16_t VP_E0_FILAMENT_LOAD_UNLOAD = 0x4030; + // constexpr uint16_t VP_E1_FILAMENT_LOAD_UNLOAD = 0x4032; + + // Settings store , reset + + // Level data + constexpr uint16_t VP_Level_Point_One_X = 0x4100; + constexpr uint16_t VP_Level_Point_One_Y = 0x4102; + constexpr uint16_t VP_Level_Point_Two_X = 0x4104; + constexpr uint16_t VP_Level_Point_Two_Y = 0x4106; + constexpr uint16_t VP_Level_Point_Three_X = 0x4108; + constexpr uint16_t VP_Level_Point_Three_Y = 0x410A; + constexpr uint16_t VP_Level_Point_Four_X = 0x410C; + constexpr uint16_t VP_Level_Point_Four_Y = 0x410E; + constexpr uint16_t VP_Level_Point_Five_X = 0x4110; + constexpr uint16_t VP_Level_Point_Five_Y = 0x4112; + + + /* H43 Version */ + constexpr uint16_t VP_MKS_H43_VERSION = 0x4A00; // MKS H43 V1.0.0 + constexpr uint16_t VP_MKS_H43_VERSION_LEN = 16; + constexpr uint16_t VP_MKS_H43_UpdataVERSION = 0x4A10; // MKS H43 V1.0.0 + constexpr uint16_t VP_MKS_H43_UpdataVERSION_LEN = 16; + + /* -------------------------------0x5000-0xFFFF------------------------------- */ + constexpr uint16_t VP_HOME_Dis = 0x5000; + constexpr uint16_t VP_Setting_Dis = 0x5010; + constexpr uint16_t VP_Tool_Dis = 0x5020; + constexpr uint16_t VP_Printing_Dis = 0x5030; + + constexpr uint16_t VP_Language_Dis = 0x5080; + constexpr uint16_t VP_LossPoint_Dis = 0x5090; + + constexpr uint16_t VP_PrintPauseConfig_Dis = 0x5120; + constexpr uint16_t VP_MotorPluse_Dis = 0x5140; + constexpr uint16_t VP_MotorMaxSpeed_Dis = 0x5150; + constexpr uint16_t VP_MotorMaxAcc_Dis = 0x5160; + + constexpr uint16_t VP_X_Pluse_Dis = 0x5170; + constexpr uint16_t VP_Y_Pluse_Dis = 0x5180; + constexpr uint16_t VP_Z_Pluse_Dis = 0x5190; + constexpr uint16_t VP_E0_Pluse_Dis = 0x51A0; + constexpr uint16_t VP_E1_Pluse_Dis = 0x51B0; + + constexpr uint16_t VP_X_Max_Speed_Dis = 0x5280; + constexpr uint16_t VP_Y_Max_Speed_Dis = 0x5290; + constexpr uint16_t VP_Z_Max_Speed_Dis = 0x52A0; + constexpr uint16_t VP_E0_Max_Speed_Dis = 0x52B0; + constexpr uint16_t VP_E1_Max_Speed_Dis = 0x52C0; + + constexpr uint16_t VP_X_Max_Acc_Speed_Dis = 0x51E0; + constexpr uint16_t VP_Y_Max_Acc_Speed_Dis = 0x51F0; + constexpr uint16_t VP_Z_Max_Acc_Speed_Dis = 0x5200; + constexpr uint16_t VP_E0_Max_Acc_Speed_Dis = 0x5210; + constexpr uint16_t VP_E1_Max_Acc_Speed_Dis = 0x5220; + + + constexpr uint16_t VP_PrintTime_Dis = 0x5470; + constexpr uint16_t VP_E0_Temp_Dis = 0x5310; + constexpr uint16_t VP_E1_Temp_Dis = 0x5320; + constexpr uint16_t VP_HB_Temp_Dis = 0x5330; + constexpr uint16_t VP_Feedrate_Dis = 0x5350; + constexpr uint16_t VP_PrintAcc_Dis = 0x5340; + constexpr uint16_t VP_Fan_Speed_Dis = 0x5360; + + constexpr uint16_t VP_Min_Ex_Temp_Dis = 0x5380; + + + constexpr uint16_t VP_X_PARK_POS_Dis = 0x53E0; + constexpr uint16_t VP_Y_PARK_POS_Dis = 0x53F0; + constexpr uint16_t VP_Z_PARK_POS_Dis = 0x5400; + + + constexpr uint16_t VP_TravelAcc_Dis = 0x5440; + constexpr uint16_t VP_FeedRateMin_Dis = 0x5450; + constexpr uint16_t VP_TravelFeeRateMin_Dis = 0x5460; + constexpr uint16_t VP_ACC_Dis = 0x5480; + + constexpr uint16_t VP_Extrusion_Dis = 0x5230; + constexpr uint16_t VP_HeatBed_Dis = 0x5240; + + constexpr uint16_t VP_Printting_Dis = 0x5430; + constexpr uint16_t VP_FactoryDefaults_Dis = 0x54C0; + constexpr uint16_t VP_StoreSetting_Dis = 0x54B0; + constexpr uint16_t VP_Info_EEPROM_2_Dis = 0x54D0; + constexpr uint16_t VP_Info_EEPROM_1_Dis = 0x54E0; + + constexpr uint16_t VP_AutoLevel_1_Dis = 0x55F0; + + constexpr uint16_t VP_TMC_X_Step_Dis = 0x5530; + constexpr uint16_t VP_TMC_Y_Step_Dis = 0x5540; + constexpr uint16_t VP_TMC_Z_Step_Dis = 0x5550; + constexpr uint16_t VP_TMC_X1_Current_Dis = 0x5560; + constexpr uint16_t VP_TMC_Y1_Current_Dis = 0x5570; + constexpr uint16_t VP_TMC_X_Current_Dis = 0x5580; + constexpr uint16_t VP_TMC_Y_Current_Dis = 0x5590; + constexpr uint16_t VP_TMC_Z_Current_Dis = 0x55A0; + constexpr uint16_t VP_TMC_E0_Current_Dis = 0x55B0; + constexpr uint16_t VP_TMC_E1_Current_Dis = 0x55C0; + constexpr uint16_t VP_TMC_Z1_Current_Dis = 0x55E0; + + constexpr uint16_t VP_AutoLEVEL_INFO1 = 0x5600; + constexpr uint16_t VP_EX_TEMP_INFO1_Dis = 0x5610; + constexpr uint16_t VP_EX_TEMP_INFO2_Dis = 0x5620; + constexpr uint16_t VP_EX_TEMP_INFO3_Dis = 0x5630; + constexpr uint16_t VP_LCD_BLK_Dis = 0x56A0; + constexpr uint16_t VP_Info_PrinfFinsh_1_Dis = 0x5C00; + constexpr uint16_t VP_Info_PrinfFinsh_2_Dis = 0x5C10; + + constexpr uint16_t VP_Length_Dis = 0x5B00; + + constexpr uint16_t VP_PrintConfrim_Info_Dis = 0x5B90; + constexpr uint16_t VP_StopPrintConfrim_Info_Dis = 0x5B80; + + constexpr uint16_t VP_Point_One_Dis = 0x5BA0; + constexpr uint16_t VP_Point_Two_Dis = 0x5BB0; + constexpr uint16_t VP_Point_Three_Dis = 0x5BC0; + constexpr uint16_t VP_Point_Four_Dis = 0x5BD0; + constexpr uint16_t VP_Point_Five_Dis = 0x5BE0; + + constexpr uint16_t VP_Print_Dis = 0x5250; + + constexpr uint16_t VP_About_Dis = 0x5A00; + constexpr uint16_t VP_Config_Dis = 0x5A10; + constexpr uint16_t VP_Filament_Dis = 0x5A20; + constexpr uint16_t VP_Move_Dis = 0x5A30; + constexpr uint16_t VP_Level_Dis = 0x5A50; + constexpr uint16_t VP_Speed_Dis = 0x5A70; + constexpr uint16_t VP_InOut_Dis = 0x5A80; + + constexpr uint16_t VP_MotorConfig_Dis = 0x5100; + constexpr uint16_t VP_LevelConfig_Dis = 0x5110; + constexpr uint16_t VP_Advance_Dis = 0x5130; + constexpr uint16_t VP_TemperatureConfig_Dis = 0x5390; + +#endif // MKS_FINSH diff --git a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp new file mode 100644 index 000000000000..9fc56acf100a --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.cpp @@ -0,0 +1,2117 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../../../../inc/MarlinConfigPre.h" + +#if ENABLED(DGUS_LCD_UI_MKS) + +#include "../DGUSScreenHandler.h" + +#include "../../../../../MarlinCore.h" +#include "../../../../../gcode/queue.h" +#include "../../../../../libs/duration_t.h" +#include "../../../../../module/settings.h" +#include "../../../../../module/temperature.h" +#include "../../../../../module/motion.h" +#include "../../../../../module/planner.h" +#include "../../../../../module/printcounter.h" +#include "../../../../../sd/cardreader.h" + +#include "../../../../../gcode/gcode.h" +#include "../../../../../pins/pins.h" +#include "../../../../../libs/nozzle.h" +#if ENABLED(HAS_STEALTHCHOP) + #include "../../../../../module/stepper/trinamic.h" + #include "../../../../../module/stepper/indirection.h" +#endif +#include "../../../../../module/probe.h" + +#if ENABLED(POWER_LOSS_RECOVERY) + #include "../../../../../feature/powerloss.h" +#endif + +#if ENABLED(SDSUPPORT) + static ExtUI::FileList filelist; +#endif + +bool DGUSAutoTurnOff = false; +uint8_t DGUSLanguageSwitch = 0; // Switch language for MKS DGUS + +// endianness swap +uint32_t swap32(const uint32_t value) { return (value & 0x000000FFU) << 24U | (value & 0x0000FF00U) << 8U | (value & 0x00FF0000U) >> 8U | (value & 0xFF000000U) >> 24U; } + +#if 0 + +void DGUSScreenHandler::sendinfoscreen_ch_mks(const uint16_t* line1, const uint16_t* line2, const uint16_t* line3, const uint16_t* line4) { + dgusdisplay.WriteVariable(VP_MSGSTR1, line1, 32, true); + dgusdisplay.WriteVariable(VP_MSGSTR2, line2, 32, true); + dgusdisplay.WriteVariable(VP_MSGSTR3, line3, 32, true); + dgusdisplay.WriteVariable(VP_MSGSTR4, line4, 32, true); +} + +void DGUSScreenHandler::sendinfoscreen_en_mks(const char* line1, const char* line2, const char* line3, const char* line4) { + dgusdisplay.WriteVariable(VP_MSGSTR1, line1, 32, true); + dgusdisplay.WriteVariable(VP_MSGSTR2, line2, 32, true); + dgusdisplay.WriteVariable(VP_MSGSTR3, line3, 32, true); + dgusdisplay.WriteVariable(VP_MSGSTR4, line4, 32, true); +} + +void DGUSScreenHandler::sendinfoscreen_mks(const void* line1, const void* line2, const void* line3, const void* line4, uint16_t language) { + if (language == MKS_English) + DGUSScreenHandler::sendinfoscreen_en_mks((char *)line1, (char *)line2, (char *)line3, (char *)line4); + else if (language == MKS_SimpleChinese) + DGUSScreenHandler::sendinfoscreen_ch_mks((uint16_t *)line1, (uint16_t *)line2, (uint16_t *)line3, (uint16_t *)line4); +} + +#endif + +void DGUSScreenHandler::DGUSLCD_SendFanToDisplay(DGUS_VP_Variable &var) { + if (var.memadr) { + //DEBUG_ECHOPAIR(" DGUS_LCD_SendWordValueToDisplay ", var.VP); + //DEBUG_ECHOLNPAIR(" data ", *(uint16_t *)var.memadr); + uint16_t tmp = *(uint8_t *) var.memadr; // +1 -> avoid rounding issues for the display. + // tmp = map(tmp, 0, 255, 0, 100); + dgusdisplay.WriteVariable(var.VP, tmp); + } +} + +void DGUSScreenHandler::DGUSLCD_SendBabyStepToDisplay_MKS(DGUS_VP_Variable &var) { + float value = current_position.z; + DEBUG_ECHOLNPAIR_F(" >> ", value, 6); + value *= cpow(10, 2); + dgusdisplay.WriteVariable(VP_SD_Print_Baby, (uint16_t)value); +} + +void DGUSScreenHandler::DGUSLCD_SendPrintTimeToDisplay_MKS(DGUS_VP_Variable &var) { + duration_t elapsed = print_job_timer.duration(); + uint32_t time = elapsed.value; + dgusdisplay.WriteVariable(VP_PrintTime_H, uint16_t(time / 3600)); + dgusdisplay.WriteVariable(VP_PrintTime_M, uint16_t(time % 3600 / 60)); + dgusdisplay.WriteVariable(VP_PrintTime_S, uint16_t((time % 3600) % 60)); +} + +void DGUSScreenHandler::DGUSLCD_SetUint8(DGUS_VP_Variable &var, void *val_ptr) { + if (var.memadr) { + uint16_t value = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("FAN value get:", value); + *(uint8_t*)var.memadr = map(constrain(value, 0, 255), 0, 255, 0, 255); + DEBUG_ECHOLNPAIR("FAN value change:", *(uint8_t*)var.memadr); + } +} + +void DGUSScreenHandler::DGUSLCD_SendGbkToDisplay(DGUS_VP_Variable &var) { + DEBUG_ECHOLNPAIR(" data ", *(uint16_t *)var.memadr); + uint16_t *tmp = (uint16_t*) var.memadr; + dgusdisplay.WriteVariable(var.VP, tmp, var.size, true); +} + +void DGUSScreenHandler::DGUSLCD_SendStringToDisplay_Language_MKS(DGUS_VP_Variable &var) { + if (DGUSLanguageSwitch == MKS_English) { + char *tmp = (char*) var.memadr; + dgusdisplay.WriteVariable(var.VP, tmp, var.size, true); + } + else if (DGUSLanguageSwitch == MKS_SimpleChinese) { + uint16_t *tmp = (uint16_t *)var.memadr; + dgusdisplay.WriteVariable(var.VP, tmp, var.size, true); + } +} + +void DGUSScreenHandler::DGUSLCD_SendTMCStepValue(DGUS_VP_Variable &var) { + #if ENABLED(SENSORLESS_HOMING) + #if AXIS_HAS_STEALTHCHOP(X) + tmc_x_step = stepperX.homing_threshold(); + dgusdisplay.WriteVariable(var.VP, *(int16_t*)var.memadr); + #endif + #if AXIS_HAS_STEALTHCHOP(Y) + tmc_y_step = stepperY.homing_threshold(); + dgusdisplay.WriteVariable(var.VP, *(int16_t*)var.memadr); + #endif + #if AXIS_HAS_STEALTHCHOP(Z) + tmc_z_step = stepperZ.homing_threshold(); + dgusdisplay.WriteVariable(var.VP, *(int16_t*)var.memadr); + #endif + #endif +} + +#if ENABLED(SDSUPPORT) + + void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file; + if (touched_nr != 0x0F && touched_nr > filelist.count()) return; + if (!filelist.seek(touched_nr) && touched_nr != 0x0F) return; + + if (touched_nr == 0x0F) { + if (filelist.isAtRootDir()) + GotoScreen(DGUSLCD_SCREEN_MAIN); + else + filelist.upDir(); + return; + } + + if (filelist.isDir()) { + filelist.changeDir(filelist.filename()); + top_file = 0; + ForceCompleteUpdate(); + return; + } + + #if ENABLED(DGUS_PRINT_FILENAME) + // Send print filename + dgusdisplay.WriteVariable(VP_SD_Print_Filename, filelist.filename(), VP_SD_FileName_LEN, true); + #endif + + // Setup Confirmation screen + file_to_print = touched_nr; + GotoScreen(MKSLCD_SCREEN_PRINT_CONFIRM); + } + + void DGUSScreenHandler::DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr) { + if (!filelist.seek(file_to_print)) return; + ExtUI::printFile(filelist.shortFilename()); + GotoScreen(MKSLCD_SCREEN_PRINT); + z_offset_add = 0; + } + + void DGUSScreenHandler::DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr) { + + if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes. + switch (swap16(*(uint16_t*)val_ptr)) { + case 0: { // Resume + + auto cs = getCurrentScreen(); + if (runout_mks.runout_status != RUNOUT_WAITTING_STATUS && runout_mks.runout_status != UNRUNOUT_STATUS) { + if (cs == MKSLCD_SCREEN_PRINT || cs == MKSLCD_SCREEN_PAUSE) + GotoScreen(MKSLCD_SCREEN_PAUSE); + return; + } + else + runout_mks.runout_status = UNRUNOUT_STATUS; + + GotoScreen(MKSLCD_SCREEN_PRINT); + + if (ExtUI::isPrintingFromMediaPaused()) { + nozzle_park_mks.print_pause_start_flag = 0; + nozzle_park_mks.blstatus = true; + ExtUI::resumePrint(); + } + } break; + + case 1: // Pause + + GotoScreen(MKSLCD_SCREEN_PAUSE); + if (!ExtUI::isPrintingFromMediaPaused()) { + nozzle_park_mks.print_pause_start_flag = 1; + nozzle_park_mks.blstatus = true; + ExtUI::pausePrint(); + //ExtUI::mks_pausePrint(); + } + break; + case 2: // Abort + HandleUserConfirmationPopUp(VP_SD_AbortPrintConfirmed, nullptr, PSTR("Abort printing"), filelist.filename(), PSTR("?"), true, true, false, true); + break; + } + } + + void DGUSScreenHandler::DGUSLCD_SD_SendFilename(DGUS_VP_Variable& var) { + uint16_t target_line = (var.VP - VP_SD_FileName0) / VP_SD_FileName_LEN; + if (target_line > DGUS_SD_FILESPERSCREEN) return; + char tmpfilename[VP_SD_FileName_LEN + 1] = ""; + var.memadr = (void*)tmpfilename; + + uint16_t dir_icon_val = 25; + if (filelist.seek(top_file + target_line)) { + snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s%c"), filelist.filename(), filelist.isDir() ? '/' : 0); // snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s"), filelist.filename()); + dir_icon_val = filelist.isDir() ? 0 : 1; + } + DGUSLCD_SendStringToDisplay(var); + + dgusdisplay.WriteVariable(VP_File_Pictutr0 + target_line * 2, dir_icon_val); + } + + void DGUSScreenHandler::SDCardInserted() { + top_file = 0; + filelist.refresh(); + auto cs = getCurrentScreen(); + if (cs == DGUSLCD_SCREEN_MAIN || cs == DGUSLCD_SCREEN_STATUS) + GotoScreen(MKSLCD_SCREEN_CHOOSE_FILE); + } + + void DGUSScreenHandler::SDCardRemoved() { + if (current_screen == DGUSLCD_SCREEN_SDFILELIST + || (current_screen == DGUSLCD_SCREEN_CONFIRM && (ConfirmVP == VP_SD_AbortPrintConfirmed || ConfirmVP == VP_SD_FileSelectConfirm)) + || current_screen == DGUSLCD_SCREEN_SDPRINTMANIPULATION + ) filelist.refresh(); + } + + void DGUSScreenHandler::SDPrintingFinished() { + if (DGUSAutoTurnOff) { + while (!queue.ring_buffer.empty()) queue.advance(); + gcode.process_subcommands_now_P(PSTR("M81")); + } + GotoScreen(MKSLCD_SCREEN_PrintDone); + } + +#endif // SDSUPPORT + +void DGUSScreenHandler::ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr) { + uint8_t *tmp = (uint8_t*)val_ptr; + + // The keycode in target is coded as , so 0x0100A means + // from screen 1 (main) to 10 (temperature). DGUSLCD_SCREEN_POPUP is special, + // meaning "return to previous screen" + DGUSLCD_Screens target = (DGUSLCD_Screens)tmp[1]; + + DEBUG_ECHOLNPAIR("\n DEBUG target", target); + + // when the dgus had reboot, it will enter the DGUSLCD_SCREEN_MAIN page, + // so user can change any page to use this function, an it will check + // if robin nano is printing. when it is, dgus will enter the printing + // page to continue print; + // + //if (print_job_timer.isRunning() || print_job_timer.isPaused()) { + // if (target == MKSLCD_PAUSE_SETTING_MOVE || target == MKSLCD_PAUSE_SETTING_EX + // || target == MKSLCD_SCREEN_PRINT || target == MKSLCD_SCREEN_PAUSE + // ) { + // } + // else + // GotoScreen(MKSLCD_SCREEN_PRINT); + // return; + //} + + if (target == DGUSLCD_SCREEN_POPUP) { + SetupConfirmAction(ExtUI::setUserConfirmed); + + // Special handling for popup is to return to previous menu + if (current_screen == DGUSLCD_SCREEN_POPUP && confirm_action_cb) confirm_action_cb(); + PopToOldScreen(); + return; + } + + UpdateNewScreen(target); + + #ifdef DEBUG_DGUSLCD + if (!DGUSLCD_FindScreenVPMapList(target)) DEBUG_ECHOLNPAIR("WARNING: No screen Mapping found for ", target); + #endif +} + +void DGUSScreenHandler::ScreenBackChange(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t target = swap16(*(uint16_t *)val_ptr); + DEBUG_ECHOLNPAIR(" back = 0x%x", target); + switch (target) { + } +} + +void DGUSScreenHandler::ZoffsetConfirm(DGUS_VP_Variable &var, void *val_ptr) { + settings.save(); + if (print_job_timer.isRunning()) + GotoScreen(MKSLCD_SCREEN_PRINT); + else if (print_job_timer.isPaused) + GotoScreen(MKSLCD_SCREEN_PAUSE); +} + +void DGUSScreenHandler::GetTurnOffCtrl(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("ctrl turn off\n"); + uint16_t value = swap16(*(uint16_t *)val_ptr); + switch (value) { + case 0 ... 1: DGUSAutoTurnOff = (bool)value; break; + default: break; + } +} + +void DGUSScreenHandler::GetMinExtrudeTemp(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("MinExtrudeTempChange DistanceChange"); + uint16_t value = swap16(*(uint16_t *)val_ptr); + thermalManager.extrude_min_temp = value; + min_ex_temp = value; + settings.save(); +} + +void DGUSScreenHandler::GetZoffsetDistance(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("Zoffset DistanceChange"); + uint16_t value = swap16(*(uint16_t *)val_ptr); + float val_distance = 0; + switch (value) { + case 0: val_distance = 0.01; break; + case 1: val_distance = 0.1; break; + case 2: val_distance = 0.5; break; + case 3: val_distance = 1; break; + default: val_distance = 0.01; break; + } + ZOffset_distance = val_distance; +} + +void DGUSScreenHandler::GetManualMovestep(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("\nMove DistanceChange"); + *(uint16_t *)var.memadr = swap16(*(uint16_t *)val_ptr); +} + +void DGUSScreenHandler::EEPROM_CTRL(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t eep_flag = swap16(*(uint16_t *)val_ptr); + switch (eep_flag) { + case 0: + settings.save(); + settings.load(); // load eeprom data to check the data is right + GotoScreen(MKSLCD_SCREEN_EEP_Config); + break; + + case 1: + settings.reset(); + GotoScreen(MKSLCD_SCREEN_EEP_Config); + break; + + default: break; + } +} + +void DGUSScreenHandler::Z_offset_select(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t z_value = swap16(*(uint16_t *)val_ptr); + switch (z_value) { + case 0: Z_distance = 0.01; break; + case 1: Z_distance = 0.1; break; + case 2: Z_distance = 0.5; break; + default: Z_distance = 1; break; + } +} + +void DGUSScreenHandler::GetOffsetValue(DGUS_VP_Variable &var, void *val_ptr) { + + #if ENABLED(HAS_BED_PROBE) + int32_t value = swap32(*(int32_t *)val_ptr); + float Offset = value / 100.0f; + DEBUG_ECHOLNPAIR_F("\nget int6 offset >> ", value, 6); + #endif + + switch (var.VP) { + case VP_OFFSET_X: TERN_(HAS_BED_PROBE, probe.offset.x = Offset); break; + case VP_OFFSET_Y: TERN_(HAS_BED_PROBE, probe.offset.y = Offset); break; + case VP_OFFSET_Z: TERN_(HAS_BED_PROBE, probe.offset.z = Offset); break; + default: break; + } + settings.save(); +} + +void DGUSScreenHandler::LanguageChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t lag_flag = swap16(*(uint16_t *)val_ptr); + switch (lag_flag) { + case MKS_SimpleChinese: + DGUS_LanguageDisplay(MKS_SimpleChinese); + DGUSLanguageSwitch = MKS_SimpleChinese; + dgusdisplay.MKS_WriteVariable(VP_LANGUAGE_CHANGE1, MKS_Language_Choose); + dgusdisplay.MKS_WriteVariable(VP_LANGUAGE_CHANGE2, MKS_Language_NoChoose); + settings.save(); + break; + case MKS_English: + DGUS_LanguageDisplay(MKS_English); + DGUSLanguageSwitch = MKS_English; + dgusdisplay.MKS_WriteVariable(VP_LANGUAGE_CHANGE1, MKS_Language_NoChoose); + dgusdisplay.MKS_WriteVariable(VP_LANGUAGE_CHANGE2, MKS_Language_Choose); + settings.save(); + break; + default: break; + } +} + +#if ENABLED(MESH_BED_LEVELING) + uint8_t mesh_point_count = GRID_MAX_POINTS; +#endif + +void DGUSScreenHandler::Level_Ctrl_MKS(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t lev_but = swap16(*(uint16_t *)val_ptr); + #if ENABLED(MESH_BED_LEVELING) + auto cs = getCurrentScreen(); + #endif + switch (lev_but) { + case 0: + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + + static uint8_t a_first_level = 1; + if (a_first_level == 1) { + a_first_level = 0; + queue.enqueue_now_P(G28_STR); + } + queue.enqueue_now_P(PSTR("G29")); + + #elif ENABLED(MESH_BED_LEVELING) + + mesh_point_count = GRID_MAX_POINTS; + + if (DGUSLanguageSwitch == MKS_English) { + const char level_buf_en[] = "Start Level"; + dgusdisplay.WriteVariable(VP_AutoLevel_1_Dis, level_buf_en, 32, true); + } + else if (DGUSLanguageSwitch == MKS_SimpleChinese) { + const uint16_t level_buf_ch[] = {0xAABF, 0xBCCA, 0xF7B5, 0xBDC6, 0x2000}; + dgusdisplay.WriteVariable(VP_AutoLevel_1_Dis, level_buf_ch, 32, true); + } + + cs = getCurrentScreen(); + if (cs != MKSLCD_AUTO_LEVEL) GotoScreen(MKSLCD_AUTO_LEVEL); + + #else + + GotoScreen(MKSLCD_SCREEN_LEVEL); + + #endif + break; + + case 1: + soft_endstop._enabled = true; + GotoScreen(MKSLCD_SCREEM_TOOL); + break; + + default: break; + } +} + +void DGUSScreenHandler::MeshLevelDistanceConfig(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t mesh_dist = swap16(*(uint16_t *)val_ptr); + switch (mesh_dist) { + case 0: mesh_adj_distance = 0.01; break; + case 1: mesh_adj_distance = 0.1; break; + case 2: mesh_adj_distance = 1; break; + default: mesh_adj_distance = 0.1; break; + } +} + +void DGUSScreenHandler::MeshLevel(DGUS_VP_Variable &var, void *val_ptr) { + #if ENABLED(MESH_BED_LEVELING) + uint16_t mesh_value = swap16(*(uint16_t *)val_ptr); + // static uint8_t a_first_level = 1; + char cmd_buf[30]; + float offset = mesh_adj_distance; + int16_t integer, Deci, Deci2; + // float f3 = current_position.z; + // float f4 = current_position.z; + switch (mesh_value) { + case 0: + offset = mesh_adj_distance; + integer = offset; // get int + Deci = (offset * 100); + Deci = Deci % 100; + Deci2 = offset * 100; + Deci2 = Deci2 % 10; + soft_endstop._enabled = false; + queue.enqueue_now_P(PSTR("G91")); + snprintf_P(cmd_buf, 30, PSTR("G1 Z%d.%d%d"), integer, Deci, Deci2); + queue.enqueue_one_now(cmd_buf); + queue.enqueue_now_P(PSTR("G90")); + //soft_endstop._enabled = true; + break; + + case 1: + offset = mesh_adj_distance; + integer = offset; // get int + Deci = (offset * 100); + Deci = Deci % 100; + Deci2 = offset * 100; + Deci2 = Deci2 % 10; + soft_endstop._enabled = false; + queue.enqueue_now_P(PSTR("G91")); + snprintf_P(cmd_buf, 30, PSTR("G1 Z-%d.%d%d"), integer, Deci, Deci2); + queue.enqueue_one_now(cmd_buf); + queue.enqueue_now_P(PSTR("G90")); + break; + + case 2: + if (mesh_point_count == GRID_MAX_POINTS) { // 第1个点 + queue.enqueue_now_P(PSTR("G29S1")); + mesh_point_count--; + + if (DGUSLanguageSwitch == MKS_English) { + const char level_buf_en1[] = "Next Point"; + dgusdisplay.WriteVariable(VP_AutoLevel_1_Dis, level_buf_en1, 32, true); + } + else if (DGUSLanguageSwitch == MKS_SimpleChinese) { + const uint16_t level_buf_ch1[] = {0xC2CF, 0xBBD2, 0xE3B5, 0x2000}; + dgusdisplay.WriteVariable(VP_AutoLevel_1_Dis, level_buf_ch1, 32, true); + } + } + else if (mesh_point_count > 1) { // 倒数第二个点 + queue.enqueue_now_P(PSTR("G29S2")); + mesh_point_count--; + if (DGUSLanguageSwitch == MKS_English) { + const char level_buf_en2[] = "Next Point"; + dgusdisplay.WriteVariable(VP_AutoLevel_1_Dis, level_buf_en2, 32, true); + } + else if (DGUSLanguageSwitch == MKS_SimpleChinese) { + const uint16_t level_buf_ch2[] = {0xC2CF, 0xBBD2, 0xE3B5, 0x2000}; + dgusdisplay.WriteVariable(VP_AutoLevel_1_Dis, level_buf_ch2, 32, true); + } + } + else if (mesh_point_count == 1) { + queue.enqueue_now_P(PSTR("G29S2")); + mesh_point_count--; + if (DGUSLanguageSwitch == MKS_English) { + const char level_buf_en2[] = "Level Finsh"; + dgusdisplay.WriteVariable(VP_AutoLevel_1_Dis, level_buf_en2, 32, true); + } + else if (DGUSLanguageSwitch == MKS_SimpleChinese) { + const uint16_t level_buf_ch2[] = {0xF7B5, 0xBDC6, 0xEACD, 0xC9B3, 0x2000}; + dgusdisplay.WriteVariable(VP_AutoLevel_1_Dis, level_buf_ch2, 32, true); + } + settings.save(); + } + else if (mesh_point_count == 0) { + + mesh_point_count = GRID_MAX_POINTS; + soft_endstop._enabled = true; + settings.save(); + GotoScreen(MKSLCD_SCREEM_TOOL); + } + break; + + default: + break; + } + #endif // MESH_BED_LEVELING +} + +void DGUSScreenHandler::LCD_BLK_Adjust(DGUS_VP_Variable &var, void *val_ptr) { + + uint16_t lcd_value = swap16(*(uint16_t *)val_ptr); + + if(lcd_value > 100) lcd_value = 100; + else if(lcd_value < 10) lcd_value = 10; + + lcd_default_light = lcd_value; + + const uint16_t lcd_data[2] = {lcd_default_light, lcd_default_light}; + dgusdisplay.WriteVariable(0x0082, &lcd_data, 5, true); +} + +void DGUSScreenHandler::ManualAssistLeveling(DGUS_VP_Variable &var, void *val_ptr) { + int16_t point_value = swap16(*(uint16_t *)val_ptr); + + int16_t level_x_pos, level_y_pos; + char buf_level[32] = {0}; + unsigned int level_speed = 1500; + static bool first_level_flag = false; + + if (!first_level_flag) + queue.enqueue_now_P(G28_STR); + + switch (point_value) { + case 0x0001: + if (first_level_flag) + queue.enqueue_now_P(G28_STR); + queue.enqueue_now_P(PSTR("G1 Z10")); + //level_x_pos = X_MIN_POS + 20; + //level_y_pos = Y_MIN_POS + 20; + level_x_pos = X_MIN_POS + abs(level_1_x_point); + level_y_pos = Y_MIN_POS + abs(level_1_y_point); + + memset(buf_level, 0, sizeof(buf_level)); + sprintf_P(buf_level, "G0 X%d Y%d F%d", level_x_pos, level_y_pos, level_speed); + queue.enqueue_one_now(buf_level); + queue.enqueue_now_P(PSTR("G28 Z")); + break; + case 0x0002: + queue.enqueue_now_P(PSTR("G1 Z10")); + + //level_x_pos = X_MAX_POS - 20; + //level_y_pos = Y_MIN_POS + 20; + + level_x_pos = X_MAX_POS - abs(level_2_x_point); + level_y_pos = Y_MIN_POS + abs(level_2_y_point); + + sprintf_P(buf_level, "G0 X%d Y%d F%d", level_x_pos, level_y_pos, level_speed); + queue.enqueue_one_now(buf_level); + //queue.enqueue_now_P(PSTR("G28Z")); + queue.enqueue_now_P(PSTR("G1 Z-10")); + break; + case 0x0003: + queue.enqueue_now_P(PSTR("G1 Z10")); + + //level_x_pos = X_MAX_POS - 20; + //level_y_pos = Y_MAX_POS - 20; + + level_x_pos = X_MAX_POS - abs(level_3_x_point); + level_y_pos = Y_MAX_POS - abs(level_3_y_point); + + sprintf_P(buf_level, "G0 X%d Y%d F%d", level_x_pos, level_y_pos, level_speed); + queue.enqueue_one_now(buf_level); + //sprintf_P(buf_level, PSTR("G28 Z")); + queue.enqueue_now_P(PSTR("G1 Z-10")); + break; + case 0x0004: + queue.enqueue_now_P(PSTR("G1 Z10")); + + //level_x_pos = X_MIN_POS + 20; + //level_y_pos = Y_MAX_POS - 20; + level_x_pos = X_MIN_POS + abs(level_4_x_point); + level_y_pos = Y_MAX_POS - abs(level_4_y_point); + + sprintf_P(buf_level, "G0 X%d Y%d F%d", level_x_pos, level_y_pos, level_speed); + queue.enqueue_one_now(buf_level); + //sprintf_P(buf_level, PSTR("G28 Z")); + queue.enqueue_now_P(PSTR("G1 Z-10")); + break; + case 0x0005: + queue.enqueue_now_P(PSTR("G1 Z10")); + //level_x_pos = (uint16_t)(X_MAX_POS / 2); + //level_y_pos = (uint16_t)(Y_MAX_POS / 2); + level_x_pos = abs(level_5_x_point); + level_y_pos = abs(level_5_y_point); + + sprintf_P(buf_level, "G0 X%d Y%d F%d", level_x_pos, level_y_pos, level_speed); + queue.enqueue_one_now(buf_level); + queue.enqueue_now_P(PSTR("G1 Z-10")); + break; + } + + // Only once + first_level_flag = true; +} + +#define mks_min(a, b) ((a) < (b)) ? (a) : (b) +#define mks_max(a, b) ((a) > (b)) ? (a) : (b) +void DGUSScreenHandler::TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr) { + #if EITHER(HAS_TRINAMIC_CONFIG, HAS_STEALTHCHOP) + uint16_t tmc_value = swap16(*(uint16_t*)val_ptr); + #endif + + switch (var.VP) { + case VP_TMC_X_STEP: + #if USE_SENSORLESS + #if AXIS_HAS_STEALTHCHOP(X) + stepperX.homing_threshold(mks_min(tmc_value, 255)); + settings.save(); + //tmc_x_step = stepperX.homing_threshold(); + #endif + #endif + break; + case VP_TMC_Y_STEP: + #if USE_SENSORLESS + #if AXIS_HAS_STEALTHCHOP(Y) + stepperY.homing_threshold(mks_min(tmc_value, 255)); + settings.save(); + //tmc_y_step = stepperY.homing_threshold(); + #endif + #endif + break; + case VP_TMC_Z_STEP: + #if USE_SENSORLESS + #if AXIS_HAS_STEALTHCHOP(Z) + stepperZ.homing_threshold(mks_min(tmc_value, 255)); + settings.save(); + //tmc_z_step = stepperZ.homing_threshold(); + #endif + #endif + break; + case VP_TMC_X_Current: + #if AXIS_IS_TMC(X) + stepperX.rms_current(tmc_value); + settings.save(); + #endif + break; + case VP_TMC_X1_Current: + #if AXIS_IS_TMC(X2) + stepperX2.rms_current(tmc_value); + settings.save(); + #endif + break; + case VP_TMC_Y_Current: + #if AXIS_IS_TMC(Y) + stepperY.rms_current(tmc_value); + settings.save(); + #endif + break; + case VP_TMC_Y1_Current: + #if AXIS_IS_TMC(X2) + stepperY2.rms_current(tmc_value); + settings.save(); + #endif + break; + case VP_TMC_Z_Current: + #if AXIS_IS_TMC(Z) + stepperZ.rms_current(tmc_value); + settings.save(); + #endif + break; + case VP_TMC_Z1_Current: + #if AXIS_IS_TMC(Z2) + stepperZ2.rms_current(tmc_value); + settings.save(); + #endif + break; + case VP_TMC_E0_Current: + #if AXIS_IS_TMC(E0) + stepperE0.rms_current(tmc_value); + settings.save(); + #endif + break; + case VP_TMC_E1_Current: + #if AXIS_IS_TMC(E1) + stepperE1.rms_current(tmc_value); + settings.save(); + #endif + break; + + default: + break; + } + #if USE_SENSORLESS + #if AXIS_HAS_STEALTHCHOP(X) + tmc_x_step = stepperX.homing_threshold(); + #endif + #if AXIS_HAS_STEALTHCHOP(Y) + tmc_y_step = stepperY.homing_threshold(); + #endif + #if AXIS_HAS_STEALTHCHOP(Z) + tmc_z_step = stepperZ.homing_threshold(); + #endif + #endif +} + +void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleManualMove"); + + int16_t movevalue = swap16(*(uint16_t*)val_ptr); + + // Choose Move distance + if (distanceMove == 0x01) distanceMove = 10; + else if (distanceMove == 0x02) distanceMove = 100; + else if (distanceMove == 0x03) distanceMove = 1000; + + DEBUG_ECHOLNPAIR("QUEUE LEN:", queue.length); + + if (!print_job_timer.isPaused() && queue.ring_buffer.full(1)) + return; + + char axiscode; + unsigned int speed = 1500; // FIXME: get default feedrate for manual moves, dont hardcode. + + switch (var.VP) { // switch X Y Z or Home + default: return; + case VP_MOVE_X: + DEBUG_ECHOLNPGM("X Move"); + axiscode = 'X'; + if (!ExtUI::canMove(ExtUI::axis_t::X)) goto cannotmove; + break; + + case VP_MOVE_Y: + DEBUG_ECHOLNPGM("Y Move"); + axiscode = 'Y'; + if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove; + break; + + case VP_MOVE_Z: + DEBUG_ECHOLNPGM("Z Move"); + axiscode = 'Z'; + speed = 300; // default to 5mm/s + if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove; + break; + + case VP_MOTOR_LOCK_UNLOK: + DEBUG_ECHOLNPGM("Motor Unlock"); + movevalue = 5; + axiscode = '\0'; + // return ; + break; + + case VP_HOME_ALL: // only used for homing + DEBUG_ECHOLNPGM("Home all"); + axiscode = '\0'; + movevalue = 0; // ignore value sent from display, this VP is _ONLY_ for homing. + //return; + break; + + case VP_X_HOME: + DEBUG_ECHOLNPGM("X Home"); + axiscode = 'X'; + movevalue = 0; + break; + + case VP_Y_HOME: + DEBUG_ECHOLNPGM("Y Home"); + axiscode = 'Y'; + movevalue = 0; + break; + + case VP_Z_HOME: + DEBUG_ECHOLNPGM("Z Home"); + axiscode = 'Z'; + movevalue = 0; + break; + } + + DEBUG_ECHOPAIR("movevalue = ", movevalue); + if (movevalue != 0 && movevalue != 5) { // get move distance + switch (movevalue) { + case 0x0001: movevalue = distanceMove; break; + case 0x0002: movevalue = -distanceMove; break; + default: movevalue = 0; break; + } + } + + if (!movevalue) { + // homing + DEBUG_ECHOPAIR(" homing ", axiscode); + // char buf[6] = "G28 X"; + // buf[4] = axiscode; + + char buf[6]; + sprintf(buf,"G28 %c",axiscode); + //DEBUG_ECHOPAIR(" ", buf); + queue.enqueue_one_now(buf); + //DEBUG_ECHOLNPGM(" ✓"); + ForceCompleteUpdate(); + return; + } + else if (movevalue == 5) { + DEBUG_ECHOPAIR("send M84"); + char buf[6]; + snprintf_P(buf,6,PSTR("M84 %c"),axiscode); + queue.enqueue_one_now(buf); + ForceCompleteUpdate(); + return; + } + else { + // movement + DEBUG_ECHOPAIR(" move ", axiscode); + bool old_relative_mode = relative_mode; + + if (!relative_mode) { + //DEBUG_ECHOPGM(" G91"); + queue.enqueue_now_P(PSTR("G91")); + //DEBUG_ECHOPGM(" ✓ "); + } + char buf[32]; // G1 X9999.99 F12345 + // unsigned int backup_speed = MMS_TO_MMM(feedrate_mm_s); + char sign[] = "\0"; + int16_t value = movevalue / 100; + if (movevalue < 0) { value = -value; sign[0] = '-'; } + int16_t fraction = ABS(movevalue) % 100; + snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed); + queue.enqueue_one_now(buf); + + //if (backup_speed != speed) { + // snprintf_P(buf, 32, PSTR("G0 F%d"), backup_speed); + // queue.enqueue_one_now(buf); + // //DEBUG_ECHOPAIR(" ", buf); + //} + + //while (!enqueue_and_echo_command(buf)) idle(); + //DEBUG_ECHOLNPGM(" ✓ "); + if (!old_relative_mode) { + //DEBUG_ECHOPGM("G90"); + //queue.enqueue_now_P(PSTR("G90")); + queue.enqueue_now_P(PSTR("G90")); + //DEBUG_ECHOPGM(" ✓ "); + } + } + + ForceCompleteUpdate(); + DEBUG_ECHOLNPGM("manmv done."); + return; + + cannotmove: + DEBUG_ECHOLNPAIR(" cannot move ", axiscode); + return; +} + +void DGUSScreenHandler::GetParkPos_MKS(DGUS_VP_Variable &var, void *val_ptr) { + int16_t value_pos = swap16(*(int16_t*)val_ptr); + + switch (var.VP) { + case VP_X_PARK_POS: x_park_pos = value_pos; break; + case VP_Y_PARK_POS: y_park_pos = value_pos; break; + case VP_Z_PARK_POS: z_park_pos = value_pos; break; + default: break; + } + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleChangeLevelPoint_MKS(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleStepPerMMChanged"); + + int16_t value_raw = swap16(*(int16_t*)val_ptr); + + DEBUG_ECHOLNPAIR_F("value:", value_raw); + + *(int16_t*)var.memadr = value_raw; + + settings.save(); + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleStepPerMMChanged_MKS(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleStepPerMMChanged"); + + uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + + DEBUG_ECHOLNPAIR("value_raw:", value_raw); + float value = (float)value_raw; + ExtUI::axis_t axis; + switch (var.VP) { + case VP_X_STEP_PER_MM: axis = ExtUI::axis_t::X; break; + case VP_Y_STEP_PER_MM: axis = ExtUI::axis_t::Y; break; + case VP_Z_STEP_PER_MM: axis = ExtUI::axis_t::Z; break; + default: return; + } + DEBUG_ECHOLNPAIR_F("value:", value); + ExtUI::setAxisSteps_per_mm(value, axis); + DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisSteps_per_mm(axis)); + settings.save(); + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleStepPerMMExtruderChanged_MKS(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleStepPerMMExtruderChanged"); + + uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("value_raw:", value_raw); + float value = (float)value_raw; + ExtUI::extruder_t extruder; + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_STEP_PER_MM: extruder = ExtUI::extruder_t::E0; break; + #endif + #if HOTENDS >= 2 + #endif + case VP_E1_STEP_PER_MM: extruder = ExtUI::extruder_t::E1; break; + } + DEBUG_ECHOLNPAIR_F("value:", value); + ExtUI::setAxisSteps_per_mm(value, extruder); + DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisSteps_per_mm(extruder)); + settings.save(); + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleMaxSpeedChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleMaxSpeedChange_MKS"); + + uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("value_raw:", value_raw); + float value = (float)value_raw; + ExtUI::axis_t axis; + switch (var.VP) { + case VP_X_MAX_SPEED: axis = ExtUI::axis_t::X; break; + case VP_Y_MAX_SPEED: axis = ExtUI::axis_t::Y; break; + case VP_Z_MAX_SPEED: axis = ExtUI::axis_t::Z; break; + default: return; + } + DEBUG_ECHOLNPAIR_F("value:", value); + // ExtUI::setAxisSteps_per_mm(value,extruder); + ExtUI::setAxisMaxFeedrate_mm_s(value, axis); + DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisMaxFeedrate_mm_s(axis)); + settings.save(); + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleExtruderMaxSpeedChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleMaxSpeedChange_MKS"); + + uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("value_raw:", value_raw); + float value = (float)value_raw; + ExtUI::extruder_t extruder; + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_MAX_SPEED: extruder = ExtUI::extruder_t::E0; break; + #endif + #if HOTENDS >= 2 + #endif + case VP_E1_MAX_SPEED: extruder = ExtUI::extruder_t::E1; break; + } + DEBUG_ECHOLNPAIR_F("value:", value); + // ExtUI::setAxisSteps_per_mm(value,extruder); + ExtUI::setAxisMaxFeedrate_mm_s(value, extruder); + DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisMaxFeedrate_mm_s(extruder)); + settings.save(); + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleMaxAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleMaxSpeedChange_MKS"); + + uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("value_raw:", value_raw); + float value = (float)value_raw; + ExtUI::axis_t axis; + switch (var.VP) { + case VP_X_ACC_MAX_SPEED: axis = ExtUI::axis_t::X; break; + case VP_Y_ACC_MAX_SPEED: axis = ExtUI::axis_t::Y; break; + case VP_Z_ACC_MAX_SPEED: axis = ExtUI::axis_t::Z; break; + default: return; + } + DEBUG_ECHOLNPAIR_F("value:", value); + ExtUI::setAxisMaxAcceleration_mm_s2(value, axis); + DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisMaxAcceleration_mm_s2(axis)); + settings.save(); + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleExtruderAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleMaxSpeedChange_MKS"); + + uint16_t value_raw = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("value_raw:", value_raw); + float value = (float)value_raw; + ExtUI::extruder_t extruder; + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_ACC_MAX_SPEED: extruder = ExtUI::extruder_t::E0; settings.load(); break; + #endif + #if HOTENDS >= 2 + #endif + case VP_E1_ACC_MAX_SPEED: extruder = ExtUI::extruder_t::E1; settings.load(); break; + } + DEBUG_ECHOLNPAIR_F("value:", value); + // ExtUI::setAxisSteps_per_mm(value,extruder); + ExtUI::setAxisMaxAcceleration_mm_s2(value, extruder); + DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisMaxAcceleration_mm_s2(extruder)); + settings.save(); + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleTravelAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t value_travel = swap16(*(uint16_t*)val_ptr); + float value = (float)value_travel; + planner.settings.travel_acceleration = value; + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleFeedRateMinChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t value_t = swap16(*(uint16_t*)val_ptr); + float value = (float)value_t; + planner.settings.min_feedrate_mm_s = value; + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleMin_T_F_MKS(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t value_t_f = swap16(*(uint16_t*)val_ptr); + float value = (float)value_t_f; + planner.settings.min_travel_feedrate_mm_s = value; + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t value_acc = swap16(*(uint16_t*)val_ptr); + float value = (float)value_acc; + planner.settings.acceleration = value; + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::HandleGetExMinTemp_MKS(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t value_ex_min_temp = swap16(*(uint16_t*)val_ptr); + thermalManager.extrude_min_temp = value_ex_min_temp; + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel +} + +#if HAS_PID_HEATING + void DGUSScreenHandler::HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t rawvalue = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("V1:", rawvalue); + float value = (float)rawvalue / 10; + DEBUG_ECHOLNPAIR("V2:", value); + float newvalue = 0; + + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_PID_P: newvalue = value; break; + case VP_E0_PID_I: newvalue = scalePID_i(value); break; + case VP_E0_PID_D: newvalue = scalePID_d(value); break; + #endif + #if HOTENDS >= 2 + case VP_E1_PID_P: newvalue = value; break; + case VP_E1_PID_I: newvalue = scalePID_i(value); break; + case VP_E1_PID_D: newvalue = scalePID_d(value); break; + #endif + #if HAS_HEATED_BED + case VP_BED_PID_P: newvalue = value; break; + case VP_BED_PID_I: newvalue = scalePID_i(value); break; + case VP_BED_PID_D: newvalue = scalePID_d(value); break; + #endif + } + + DEBUG_ECHOLNPAIR_F("V3:", newvalue); + *(float *)var.memadr = newvalue; + + settings.save(); + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + } +#endif // HAS_PID_HEATING + +#if ENABLED(BABYSTEPPING) + void DGUSScreenHandler::HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleLiveAdjustZ"); + char babystep_buf[30]; + float step = ZOffset_distance; + + uint16_t flag = swap16(*(uint16_t*)val_ptr); + switch (flag) { + case 0: + if (step == 0.01) + queue.inject_P(PSTR("M290 Z-0.01")); + else if (step == 0.1) + queue.inject_P(PSTR("M290 Z-0.1")); + else if (step == 0.5) + queue.inject_P(PSTR("M290 Z-0.5")); + else if (step == 1) + queue.inject_P(PSTR("M290 Z-1")); + else + queue.inject_P(PSTR("M290 Z-0.01")); + + z_offset_add = z_offset_add - ZOffset_distance; + break; + + case 1: + if (step == 0.01) + queue.inject_P(PSTR("M290 Z0.01")); + else if (step == 0.1) + queue.inject_P(PSTR("M290 Z0.1")); + else if (step == 0.5) + queue.inject_P(PSTR("M290 Z0.5")); + else if (step == 1) + queue.inject_P(PSTR("M290 Z1")); + else + queue.inject_P(PSTR("M290 Z-0.01")); + + z_offset_add = z_offset_add + ZOffset_distance; + break; + + default: + break; + } + ForceCompleteUpdate(); + } +#endif // BABYSTEPPING + +void DGUSScreenHandler::GetManualFilament(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleGetFilament"); + + uint16_t value_len = swap16(*(uint16_t*)val_ptr); + + float value = (float)value_len; + + DEBUG_ECHOLNPAIR_F("Get Filament len value:", value); + distanceFilament = value; + + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::GetManualFilamentSpeed(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleGetFilamentSpeed"); + + uint16_t value_len = swap16(*(uint16_t*)val_ptr); + + DEBUG_ECHOLNPAIR_F("FilamentSpeed value:", value_len); + + FilamentSpeed = value_len; + + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + return; +} + +void DGUSScreenHandler::MKS_FilamentLoad(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("Load Filament"); + char buf[40]; + + uint16_t val_t = swap16(*(uint16_t*)val_ptr); + + switch (val_t) { + case 0: + #if HOTENDS >= 1 + if (thermalManager.temp_hotend[0].celsius < thermalManager.extrude_min_temp) { + if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) + thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 0); + sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); + SetupConfirmAction(nullptr); + GotoScreen(DGUSLCD_SCREEN_POPUP); + } + else { + queue.enqueue_now_P(PSTR("T0")); + queue.enqueue_now_P(PSTR("G91")); + snprintf_P(buf,40,PSTR("G1 E%d F%d"),(int)distanceFilament,FilamentSpeed * 60); + queue.enqueue_one_now(buf); + queue.enqueue_now_P(PSTR("G90")); + } + #endif + break; + + case 1: + #if HOTENDS >= 2 + if (thermalManager.temp_hotend[1].celsius < thermalManager.extrude_min_temp) { + if (thermalManager.temp_hotend[1].target < thermalManager.extrude_min_temp) + thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 1); + sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); + SetupConfirmAction(nullptr); + GotoScreen(DGUSLCD_SCREEN_POPUP); + } + else { + queue.enqueue_now_P(PSTR("T1")); + queue.enqueue_now_P(PSTR("G91")); + snprintf_P(buf,40,PSTR("G1 E%d F%d"),(int)distanceFilament,FilamentSpeed * 60); + queue.enqueue_one_now(buf); + queue.enqueue_now_P(PSTR("G90")); + } + #endif + #if ENABLED(SINGLENOZZLE) + if (thermalManager.temp_hotend[0].celsius < thermalManager.extrude_min_temp) { + if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) + thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 0); + sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); + SetupConfirmAction(nullptr); + GotoScreen(DGUSLCD_SCREEN_POPUP); + } + else { + queue.enqueue_now_P(PSTR("T1")); + queue.enqueue_now_P(PSTR("G91")); + snprintf_P(buf,40,PSTR("G1 E%d F%d"),(int)distanceFilament,FilamentSpeed * 60); + queue.enqueue_one_now(buf); + queue.enqueue_now_P(PSTR("G90")); + } + #endif + break; + + default: + break; + } +} + +void DGUSScreenHandler::MKS_FilamentUnLoad(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("UnLoad Filament"); + char buf[40]; + uint16_t val_t = swap16(*(uint16_t*)val_ptr); + switch (val_t) { + case 0: + #if HOTENDS >= 1 + if (thermalManager.temp_hotend[0].celsius < thermalManager.extrude_min_temp) { + if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) + thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 0); + sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); + SetupConfirmAction(nullptr); + GotoScreen(DGUSLCD_SCREEN_POPUP); + } + else { + queue.enqueue_now_P(PSTR("T0")); + queue.enqueue_now_P(PSTR("G91")); + snprintf_P(buf,40,PSTR("G1 E-%d F%d"),(int)distanceFilament,FilamentSpeed * 60); + queue.enqueue_one_now(buf); + queue.enqueue_now_P(PSTR("G90")); + } + #endif + break; + case 1: + #if HOTENDS >= 2 + if (thermalManager.temp_hotend[1].celsius < thermalManager.extrude_min_temp) { + if (thermalManager.temp_hotend[1].target < thermalManager.extrude_min_temp) + thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 1); + sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); + SetupConfirmAction(nullptr); + GotoScreen(DGUSLCD_SCREEN_POPUP); + } + else { + queue.enqueue_now_P(PSTR("T1")); + queue.enqueue_now_P(PSTR("G91")); + snprintf_P(buf,40,PSTR("G1 E-%d F%d"),(int)distanceFilament,FilamentSpeed * 60); + queue.enqueue_one_now(buf); + queue.enqueue_now_P(PSTR("G90")); + } + #endif + + #if ENABLED(SINGLENOZZLE) + if (thermalManager.temp_hotend[0].celsius < thermalManager.extrude_min_temp) { + if (thermalManager.temp_hotend[0].target < thermalManager.extrude_min_temp) + thermalManager.setTargetHotend(thermalManager.extrude_min_temp, 0); + sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please wait."), PSTR("Nozzle heating!"), true, true, true, true); + SetupConfirmAction(nullptr); + GotoScreen(DGUSLCD_SCREEN_POPUP); + } + else { + queue.enqueue_now_P(PSTR("T1")); + queue.enqueue_now_P(PSTR("G91")); + snprintf_P(buf,40,PSTR("G1 E-%d F%d"),(int)distanceFilament,FilamentSpeed * 60); + queue.enqueue_one_now(buf); + queue.enqueue_now_P(PSTR("G90")); + } + #endif + break; + } +} + +#if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + + void DGUSScreenHandler::HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleFilamentOption"); + + uint8_t e_temp = 0; + filament_data.heated = false; + uint16_t preheat_option = swap16(*(uint16_t*)val_ptr); + if (preheat_option <= 8) { // Load filament type + filament_data.action = 1; + } + else if (preheat_option >= 10) { // Unload filament type + preheat_option -= 10; + filament_data.action = 2; + filament_data.purge_length = DGUS_FILAMENT_PURGE_LENGTH; + } + else { // Cancel filament operation + filament_data.action = 0; + } + + switch (preheat_option) { + case 0: // Load PLA + #ifdef PREHEAT_1_TEMP_HOTEND + e_temp = PREHEAT_1_TEMP_HOTEND; + #endif + break; + case 1: // Load ABS + TERN_(PREHEAT_2_TEMP_HOTEND, e_temp = PREHEAT_2_TEMP_HOTEND); + break; + case 2: // Load PET + #ifdef PREHEAT_3_TEMP_HOTEND + e_temp = PREHEAT_3_TEMP_HOTEND; + #endif + break; + case 3: // Load FLEX + #ifdef PREHEAT_4_TEMP_HOTEND + e_temp = PREHEAT_4_TEMP_HOTEND; + #endif + break; + case 9: // Cool down + default: + e_temp = 0; + break; + } + + if (filament_data.action == 0) { // Go back to utility screen + #if HOTENDS >= 1 + thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E0); + #endif + #if HOTENDS >= 2 + thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E1); + #endif + GotoScreen(DGUSLCD_SCREEN_UTILITY); + } + else { // Go to the preheat screen to show the heating progress + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_FILAMENT_LOAD_UNLOAD: + filament_data.extruder = ExtUI::extruder_t::E0; + thermalManager.setTargetHotend(e_temp, filament_data.extruder); + break; + #endif + #if HOTENDS >= 2 + case VP_E1_FILAMENT_LOAD_UNLOAD: + filament_data.extruder = ExtUI::extruder_t::E1; + thermalManager.setTargetHotend(e_temp, filament_data.extruder); + break; + #endif + } + } + } + + void DGUSScreenHandler::HandleFilamentLoadUnload(DGUS_VP_Variable &var) { + DEBUG_ECHOLNPGM("HandleFilamentLoadUnload"); + if (filament_data.action <= 0) return; + + // If we close to the target temperature, we can start load or unload the filament + if (thermalManager.hotEnoughToExtrude(filament_data.extruder) && \ + thermalManager.targetHotEnoughToExtrude(filament_data.extruder)) { + float movevalue = DGUS_FILAMENT_LOAD_LENGTH_PER_TIME; + + if (filament_data.action == 1) { // load filament + if (!filament_data.heated) { + filament_data.heated = true; + } + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue; + } + else { // unload filament + if (!filament_data.heated) { + GotoScreen(DGUSLCD_SCREEN_FILAMENT_UNLOADING); + filament_data.heated = true; + } + // Before unloading extrude to prevent jamming + if (filament_data.purge_length >= 0) { + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue; + filament_data.purge_length -= movevalue; + } + else { + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) - movevalue; + } + } + ExtUI::setAxisPosition_mm(movevalue, filament_data.extruder); + } + } +#endif // DGUS_FILAMENT_LOADUNLOAD + +bool DGUSScreenHandler::loop() { + dgusdisplay.loop(); + + const millis_t ms = millis(); + static millis_t next_event_ms = 0; + + static uint8_t language_times = 2; + + if (!IsScreenComplete() || ELAPSED(ms, next_event_ms)) { + next_event_ms = ms + DGUS_UPDATE_INTERVAL_MS; + UpdateScreenVPData(); + } + + if (language_times != 0) { + LanguagePInit(); + DGUS_LanguageDisplay(DGUSLanguageSwitch); + language_times--; + } + + #if ENABLED(SHOW_BOOTSCREEN) + static bool booted = false; + if (!booted && ELAPSED(ms, TERN(USE_MKS_GREEN_UI, 1000, BOOTSCREEN_TIMEOUT))) { + booted = true; + #if ANY_AXIS_HAS(STEALTHCHOP) + #if AXIS_HAS_STEALTHCHOP(X) + tmc_x_step = stepperX.homing_threshold(); + #endif + #if AXIS_HAS_STEALTHCHOP(Y) + tmc_y_step = stepperY.homing_threshold(); + #endif + #if AXIS_HAS_STEALTHCHOP(Z) + tmc_z_step = stepperZ.homing_threshold(); + #endif + #endif + + if (min_ex_temp != 0) + thermalManager.extrude_min_temp = min_ex_temp; + + DGUS_ExtrudeLoadInit(); + + TERN_(DGUS_MKS_RUNOUT_SENSOR, DGUS_RunoutInit()); + + if (TERN0(POWER_LOSS_RECOVERY, recovery.valid())) + GotoScreen(DGUSLCD_SCREEN_POWER_LOSS); + else + GotoScreen(DGUSLCD_SCREEN_MAIN); + } + + #if ENABLED(DGUS_MKS_RUNOUT_SENSOR) + if (booted && (IS_SD_PRINTING() || IS_SD_PAUSED())) + DGUS_Runout_Idle(); + #endif + #endif // SHOW_BOOTSCREEN + + return IsScreenComplete(); +} + +void DGUSScreenHandler::LanguagePInit() { + switch (DGUSLanguageSwitch) { + case MKS_SimpleChinese: + dgusdisplay.MKS_WriteVariable(VP_LANGUAGE_CHANGE1, MKS_Language_Choose); + dgusdisplay.MKS_WriteVariable(VP_LANGUAGE_CHANGE2, MKS_Language_NoChoose); + break; + case MKS_English: + dgusdisplay.MKS_WriteVariable(VP_LANGUAGE_CHANGE1, MKS_Language_NoChoose); + dgusdisplay.MKS_WriteVariable(VP_LANGUAGE_CHANGE2, MKS_Language_Choose); + break; + default: + break; + } +} + +void DGUSScreenHandler::DGUS_ExtrudeLoadInit(void) { + ex_filament.ex_length = distanceFilament; + ex_filament.ex_load_unload_flag = 0; + ex_filament.ex_need_time = FilamentSpeed; + ex_filament.ex_speed = 0; + ex_filament.ex_status = EX_NONE; + ex_filament.ex_tick_end = 0; + ex_filament.ex_tick_start = 0; +} + +void DGUSScreenHandler::DGUS_RunoutInit(void) { + #if PIN_EXISTS(MT_DET_1) + pinMode(MT_DET_1_PIN, INPUT_PULLUP); + #endif + runout_mks.de_count = 0; + runout_mks.de_times = 10; + runout_mks.pin_status = 1; + runout_mks.runout_status = UNRUNOUT_STATUS; +} + +void DGUSScreenHandler::DGUS_Runout_Idle(void) { + #if ENABLED(DGUS_MKS_RUNOUT_SENSOR) + // scanf runout pin + switch (runout_mks.runout_status) { + + case RUNOUT_STATUS: + runout_mks.runout_status = RUNOUT_BEGIN_STATUS; + queue.inject_P(PSTR("M25")); + GotoScreen(MKSLCD_SCREEN_PAUSE); + + sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("Please change filament!"), nullptr, true, true, true, true); + // SetupConfirmAction(nullptr); + GotoScreen(DGUSLCD_SCREEN_POPUP); + break; + + case UNRUNOUT_STATUS: + if (READ(MT_DET_1_PIN) == LOW) + runout_mks.runout_status = RUNOUT_STATUS; + break; + + case RUNOUT_BEGIN_STATUS: + if (READ(MT_DET_1_PIN) == HIGH) + runout_mks.runout_status = RUNOUT_WAITTING_STATUS; + break; + + case RUNOUT_WAITTING_STATUS: + if (READ(MT_DET_1_PIN) == LOW) + runout_mks.runout_status = RUNOUT_BEGIN_STATUS; + break; + + default: break; + } + #endif +} + +void DGUSScreenHandler::DGUS_LanguageDisplay(uint8_t var) { + if (var == MKS_English) { + const char home_buf_en[] = "Home"; + dgusdisplay.WriteVariable(VP_HOME_Dis, home_buf_en, 32, true); + + const char setting_buf_en[] = "Setting"; + dgusdisplay.WriteVariable(VP_Setting_Dis, setting_buf_en, 32, true); + + const char Tool_buf_en[] = "Tool"; + dgusdisplay.WriteVariable(VP_Tool_Dis, Tool_buf_en, 32, true); + + const char Print_buf_en[] = "Print"; + dgusdisplay.WriteVariable(VP_Print_Dis, Print_buf_en, 32, true); + + const char Language_buf_en[] = "Language"; + dgusdisplay.WriteVariable(VP_Language_Dis, Language_buf_en, 32, true); + + const char About_buf_en[] = "About"; + dgusdisplay.WriteVariable(VP_About_Dis, About_buf_en, 32, true); + + const char Config_buf_en[] = "Config"; + dgusdisplay.WriteVariable(VP_Config_Dis, Config_buf_en, 32, true); + + const char MotorConfig_buf_en[] = "MotorConfig"; + dgusdisplay.WriteVariable(VP_MotorConfig_Dis, MotorConfig_buf_en, 32, true); + + const char LevelConfig_buf_en[] = "LevelConfig"; + dgusdisplay.WriteVariable(VP_LevelConfig_Dis, LevelConfig_buf_en, 32, true); + + const char TemperatureConfig_buf_en[] = "Temperature"; + dgusdisplay.WriteVariable(VP_TemperatureConfig_Dis, TemperatureConfig_buf_en, 32, true); + + const char Advance_buf_en[] = "Advance"; + dgusdisplay.WriteVariable(VP_Advance_Dis, Advance_buf_en, 32, true); + + const char Filament_buf_en[] = "Extrude"; + dgusdisplay.WriteVariable(VP_Filament_Dis, Filament_buf_en, 32, true); + + const char Move_buf_en[] = "Move"; + dgusdisplay.WriteVariable(VP_Move_Dis, Move_buf_en, 32, true); + + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + const char Level_buf_en[] = "AutoLevel"; + dgusdisplay.WriteVariable(VP_Level_Dis, Level_buf_en, 32, true); + #elif ENABLED(MESH_BED_LEVELING) + const char Level_buf_en[] = "MeshLevel"; + dgusdisplay.WriteVariable(VP_Level_Dis, Level_buf_en, 32, true); + #else + const char Level_buf_en[] = "Level"; + dgusdisplay.WriteVariable(VP_Level_Dis, Level_buf_en, 32, true); + #endif + + const char MotorPluse_buf_en[] = "MotorPluse"; + dgusdisplay.WriteVariable(VP_MotorPluse_Dis, MotorPluse_buf_en, 32, true); + + const char MotorMaxSpeed_buf_en[] = "MotorMaxSpeed"; + dgusdisplay.WriteVariable(VP_MotorMaxSpeed_Dis, MotorMaxSpeed_buf_en, 32, true); + + const char MotorMaxAcc_buf_en[] = "MotorAcc"; + dgusdisplay.WriteVariable(VP_MotorMaxAcc_Dis, MotorMaxAcc_buf_en, 32, true); + + const char TravelAcc_buf_en[] = "TravelAcc"; + dgusdisplay.WriteVariable(VP_TravelAcc_Dis, TravelAcc_buf_en, 32, true); + + const char FeedRateMin_buf_en[] = "FeedRateMin"; + dgusdisplay.WriteVariable(VP_FeedRateMin_Dis, FeedRateMin_buf_en, 32, true); + + const char TravelFeeRateMin_buf_en[] = "TravelFeedRateMin"; + dgusdisplay.WriteVariable(VP_TravelFeeRateMin_Dis, TravelFeeRateMin_buf_en, 32, true); + + const char Acc_buf_en[] = "Acc"; + dgusdisplay.WriteVariable(VP_ACC_Dis, Acc_buf_en, 32, true); + + const char Point_One_buf_en[] = "Point_First"; + dgusdisplay.WriteVariable(VP_Point_One_Dis, Point_One_buf_en, 32, true); + + const char Point_Two_buf_en[] = "Point_Second"; + dgusdisplay.WriteVariable(VP_Point_Two_Dis, Point_Two_buf_en, 32, true); + + const char Point_Three_buf_en[] = "Point_Third"; + dgusdisplay.WriteVariable(VP_Point_Three_Dis, Point_Three_buf_en, 32, true); + + const char Point_Four_buf_en[] = "Point_Fourth"; + dgusdisplay.WriteVariable(VP_Point_Four_Dis, Point_Four_buf_en, 32, true); + + const char Point_Five_buf_en[] = "Point_Fifth"; + dgusdisplay.WriteVariable(VP_Point_Five_Dis, Point_Five_buf_en, 32, true); + + const char Extrusion_buf_en[] = "Extrusion"; + dgusdisplay.WriteVariable(VP_Extrusion_Dis, Extrusion_buf_en, 32, true); + + const char HeatBed_buf_en[] = "HeatBed"; + dgusdisplay.WriteVariable(VP_HeatBed_Dis, HeatBed_buf_en, 32, true); + + const char FactoryDefaults_buf_en[] = "FactoryDefaults"; + dgusdisplay.WriteVariable(VP_FactoryDefaults_Dis, FactoryDefaults_buf_en, 32, true); + + const char StoreSetting_buf_en[] = "StoreSetting"; + dgusdisplay.WriteVariable(VP_StoreSetting_Dis, StoreSetting_buf_en, 32, true); + + const char PrintPauseConfig_buf_en[] = "PrintPauseConfig"; + dgusdisplay.WriteVariable(VP_PrintPauseConfig_Dis, PrintPauseConfig_buf_en, 32, true); + + const char X_Pluse_buf_en[] = "X_Pluse"; + dgusdisplay.WriteVariable(VP_X_Pluse_Dis, X_Pluse_buf_en, 32, true); + + const char Y_Pluse_buf_en[] = "Y_Pluse"; + dgusdisplay.WriteVariable(VP_Y_Pluse_Dis, Y_Pluse_buf_en, 32, true); + + const char Z_Pluse_buf_en[] = "Z_Pluse"; + dgusdisplay.WriteVariable(VP_Z_Pluse_Dis, Z_Pluse_buf_en, 32, true); + + const char E0_Pluse_buf_en[] = "E0_Pluse"; + dgusdisplay.WriteVariable(VP_E0_Pluse_Dis, E0_Pluse_buf_en, 32, true); + + const char E1_Pluse_buf_en[] = "E1_Pluse"; + dgusdisplay.WriteVariable(VP_E1_Pluse_Dis, E1_Pluse_buf_en, 32, true); + + const char X_Max_Speed_buf_en[] = "X_Max_Speed"; + dgusdisplay.WriteVariable(VP_X_Max_Speed_Dis, X_Max_Speed_buf_en, 32, true); + + const char Y_Max_Speed_buf_en[] = "Y_Max_Speed"; + dgusdisplay.WriteVariable(VP_Y_Max_Speed_Dis, Y_Max_Speed_buf_en, 32, true); + + const char Z_Max_Speed_buf_en[] = "Z_Max_Speed"; + dgusdisplay.WriteVariable(VP_Z_Max_Speed_Dis, Z_Max_Speed_buf_en, 32, true); + + const char E0_Max_Speed_buf_en[] = "E0_Max_Speed"; + dgusdisplay.WriteVariable(VP_E0_Max_Speed_Dis, E0_Max_Speed_buf_en, 32, true); + + const char E1_Max_Speed_buf_en[] = "E1_Max_Speed"; + dgusdisplay.WriteVariable(VP_E1_Max_Speed_Dis, E1_Max_Speed_buf_en, 32, true); + + const char X_Max_Acc_Speed_buf_en[] = "X_Max_Acc_Speed"; + dgusdisplay.WriteVariable(VP_X_Max_Acc_Speed_Dis, X_Max_Acc_Speed_buf_en, 32, true); + + const char Y_Max_Acc_Speed_buf_en[] = "Y_Max_Acc_Speed"; + dgusdisplay.WriteVariable(VP_Y_Max_Acc_Speed_Dis, Y_Max_Acc_Speed_buf_en, 32, true); + + const char Z_Max_Acc_Speed_buf_en[] = "Z_Max_Acc_Speed"; + dgusdisplay.WriteVariable(VP_Z_Max_Acc_Speed_Dis, Z_Max_Acc_Speed_buf_en, 32, true); + + const char E0_Max_Acc_Speed_buf_en[] = "E0_Max_Acc_Speed"; + dgusdisplay.WriteVariable(VP_E0_Max_Acc_Speed_Dis, E0_Max_Acc_Speed_buf_en, 32, true); + + const char E1_Max_Acc_Speed_buf_en[] = "E1_Max_Acc_Speed"; + dgusdisplay.WriteVariable(VP_E1_Max_Acc_Speed_Dis, E1_Max_Acc_Speed_buf_en, 32, true); + + const char X_PARK_POS_buf_en[] = "X_PARK_POS"; + dgusdisplay.WriteVariable(VP_X_PARK_POS_Dis, X_PARK_POS_buf_en, 32, true); + + const char Y_PARK_POS_buf_en[] = "Y_PARK_POS"; + dgusdisplay.WriteVariable(VP_Y_PARK_POS_Dis, Y_PARK_POS_buf_en, 32, true); + + const char Z_PARK_POS_buf_en[] = "Z_PARK_POS"; + dgusdisplay.WriteVariable(VP_Z_PARK_POS_Dis, Z_PARK_POS_buf_en, 32, true); + + const char Length_buf_en[] = "Length"; + dgusdisplay.WriteVariable(VP_Length_Dis, Length_buf_en, 32, true); + + const char Speed_buf_en[] = "Speed"; + dgusdisplay.WriteVariable(VP_Speed_Dis, Speed_buf_en, 32, true); + + const char InOut_buf_en[] = "InOut"; + dgusdisplay.WriteVariable(VP_InOut_Dis, InOut_buf_en, 32, true); + + const char PrintTimet_buf_en[] = "PrintTime"; + dgusdisplay.WriteVariable(VP_PrintTime_Dis, PrintTimet_buf_en, 32, true); + + const char E0_Temp_buf_en[] = "E0_Temp"; + dgusdisplay.WriteVariable(VP_E0_Temp_Dis, E0_Temp_buf_en, 32, true); + + const char E1_Temp_buf_en[] = "E1_Temp"; + dgusdisplay.WriteVariable(VP_E1_Temp_Dis, E1_Temp_buf_en, 32, true); + + const char HB_Temp_buf_en[] = "HB_Temp"; + dgusdisplay.WriteVariable(VP_HB_Temp_Dis, HB_Temp_buf_en, 32, true); + + const char Feedrate_buf_en[] = "Feedrate"; + dgusdisplay.WriteVariable(VP_Feedrate_Dis, Feedrate_buf_en, 32, true); + + const char PrintAcc_buf_en[] = "PrintSpeed"; + dgusdisplay.WriteVariable(VP_PrintAcc_Dis, PrintAcc_buf_en, 32, true); + + const char FAN_Speed_buf_en[] = "FAN_Speed"; + dgusdisplay.WriteVariable(VP_Fan_Speed_Dis, FAN_Speed_buf_en, 32, true); + + const char Printing_buf_en[] = "Printing"; + dgusdisplay.WriteVariable(VP_Printing_Dis, Printing_buf_en, 32, true); + + const char Info_EEPROM_1_buf_en[] = "Store setting?"; + dgusdisplay.WriteVariable(VP_Info_EEPROM_1_Dis, Info_EEPROM_1_buf_en, 32, true); + + const char Info_EEPROM_2_buf_en[] = "Revert setting?"; + dgusdisplay.WriteVariable(VP_Info_EEPROM_2_Dis, Info_EEPROM_2_buf_en, 32, true); + + const char Info_PrinfFinsh_1_buf_en[] = "Print Done"; + dgusdisplay.WriteVariable(VP_Info_PrinfFinsh_1_Dis, Info_PrinfFinsh_1_buf_en, 32, true); + + const char TMC_X_Step_buf_en[] = "X_SenSitivity"; + dgusdisplay.WriteVariable(VP_TMC_X_Step_Dis, TMC_X_Step_buf_en, 32, true); + + const char TMC_Y_Step_buf_en[] = "Y_SenSitivity"; + dgusdisplay.WriteVariable(VP_TMC_Y_Step_Dis, TMC_Y_Step_buf_en, 32, true); + + const char TMC_Z_Step_buf_en[] = "Z_SenSitivity"; + dgusdisplay.WriteVariable(VP_TMC_Z_Step_Dis, TMC_Z_Step_buf_en, 32, true); + + const char TMC_X_Current_buf_en[] = "X_Current"; + dgusdisplay.WriteVariable(VP_TMC_X_Current_Dis, TMC_X_Current_buf_en, 32, true); + + const char TMC_Y_Current_buf_en[] = "Y_Current"; + dgusdisplay.WriteVariable(VP_TMC_Y_Current_Dis, TMC_Y_Current_buf_en, 32, true); + + const char TMC_Z_Current_buf_en[] = "Z_Current"; + dgusdisplay.WriteVariable(VP_TMC_Z_Current_Dis, TMC_Z_Current_buf_en, 32, true); + + const char TMC_E0_Current_buf_en[] = "E0_Current"; + dgusdisplay.WriteVariable(VP_TMC_E0_Current_Dis, TMC_E0_Current_buf_en, 32, true); + + const char TMC_X1_Current_buf_en[] = "X1_Current"; + dgusdisplay.WriteVariable(VP_TMC_X1_Current_Dis, TMC_X1_Current_buf_en, 32, true); + + const char TMC_Y1_Current_buf_en[] = "Y1_Current"; + dgusdisplay.WriteVariable(VP_TMC_Y1_Current_Dis, TMC_Y1_Current_buf_en, 32, true); + + const char TMC_Z1_Current_buf_en[] = "Z1_Current"; + dgusdisplay.WriteVariable(VP_TMC_Z1_Current_Dis, TMC_Z1_Current_buf_en, 32, true); + + const char TMC_E1_Current_buf_en[] = "E1_Current"; + dgusdisplay.WriteVariable(VP_TMC_E1_Current_Dis, TMC_E1_Current_buf_en, 32, true); + + const char Min_Ex_Temp_buf_en[] = "Min_Ex_Temp"; + dgusdisplay.WriteVariable(VP_Min_Ex_Temp_Dis, Min_Ex_Temp_buf_en, 32, true); + + const char AutoLEVEL_INFO1_buf_en[] = "Please Press Button!"; + dgusdisplay.WriteVariable(VP_AutoLEVEL_INFO1, AutoLEVEL_INFO1_buf_en, 32, true); + + const char EX_TEMP_INFO2_buf_en[] = "Please wait a monent"; + dgusdisplay.WriteVariable(VP_EX_TEMP_INFO2_Dis, EX_TEMP_INFO2_buf_en, 32, true); + + const char EX_TEMP_INFO3_buf_en[] = "Cancle"; + dgusdisplay.WriteVariable(VP_EX_TEMP_INFO3_Dis, EX_TEMP_INFO3_buf_en, 32, true); + + const char PrintConfrim_Info_buf_en[] = "Start Print?"; + dgusdisplay.WriteVariable(VP_PrintConfrim_Info_Dis, PrintConfrim_Info_buf_en, 32, true); + + const char StopPrintConfrim_Info_buf_en[] = "Stop Print?"; + dgusdisplay.WriteVariable(VP_StopPrintConfrim_Info_Dis, StopPrintConfrim_Info_buf_en, 32, true); + + const char Printting_buf_en[] = "Printing"; + dgusdisplay.WriteVariable(VP_Printting_Dis, Printting_buf_en, 32, true); + + const char LCD_BLK_buf_en[] = "Backlight"; + dgusdisplay.WriteVariable(VP_LCD_BLK_Dis, LCD_BLK_buf_en, 32, true); + } + else if (var == MKS_SimpleChinese) { + uint16_t home_buf_ch[] = { 0xF7D6, 0xB3D2 }; + dgusdisplay.WriteVariable(VP_HOME_Dis, home_buf_ch, 4, true); + + const uint16_t Setting_Dis[] = { 0xE8C9, 0xC3D6, 0x2000, 0x2000, 0x2000 }; + dgusdisplay.WriteVariable(VP_Setting_Dis, Setting_Dis, 7, true); + + const uint16_t Tool_Dis[] = { 0xA4B9, 0xDFBE }; + dgusdisplay.WriteVariable(VP_Tool_Dis, Tool_Dis, 4, true); + + const uint16_t Print_buf_ch[] = { 0xF2B4, 0xA1D3, 0x2000 }; + dgusdisplay.WriteVariable(VP_Print_Dis, Print_buf_ch, 6, true); + + const uint16_t Language_buf_ch[] = { 0xEFD3, 0xD4D1, 0x2000, 0x2000 }; + dgusdisplay.WriteVariable(VP_Language_Dis, Language_buf_ch, 8, true); + + const uint16_t About_buf_ch[] = { 0xD8B9, 0xDAD3, 0x2000 }; + dgusdisplay.WriteVariable(VP_About_Dis, About_buf_ch, 6, true); + + const uint16_t Config_buf_ch[] = { 0xE4C5, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Config_Dis, Config_buf_ch, 6, true); + + const uint16_t MotorConfig_buf_ch[] = { 0xE7B5, 0xFABB, 0xE4C5, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_MotorConfig_Dis, MotorConfig_buf_ch, 12, true); + + const uint16_t LevelConfig_buf_ch[] = { 0xD6CA, 0xAFB6, 0xF7B5, 0xBDC6, 0xE8C9, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_LevelConfig_Dis, LevelConfig_buf_ch, 32, true); + + const uint16_t TemperatureConfig_buf_ch[] = { 0xC2CE, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_TemperatureConfig_Dis, TemperatureConfig_buf_ch, 11, true); + + const uint16_t Advance_buf_ch[] = { 0xDFB8, 0xB6BC, 0xE8C9, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Advance_Dis, Advance_buf_ch, 16, true); + + const uint16_t Filament_buf_ch[] = { 0xB7BC, 0xF6B3, 0x2000 }; + dgusdisplay.WriteVariable(VP_Filament_Dis, Filament_buf_ch, 8, true); + + const uint16_t Move_buf_ch[] = { 0xC6D2, 0xAFB6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Move_Dis, Move_buf_ch, 4, true); + + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + const uint16_t Level_buf_ch[] = { 0xD4D7, 0xAFB6, 0xF7B5, 0xBDC6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Level_Dis, Level_buf_ch, 32, true); + #elif ENABLED(MESH_BED_LEVELING) + const uint16_t Level_buf_ch[] = { 0xF8CD, 0xF1B8, 0xF7B5, 0xBDC6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Level_Dis, Level_buf_ch, 32, true); + #else + const uint16_t Level_buf_ch[] = { 0xD6CA, 0xAFB6, 0xF7B5, 0xBDC6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Level_Dis, Level_buf_ch, 32, true); + #endif + + const uint16_t MotorPluse_buf_ch[] = { 0xF6C2, 0xE5B3, 0x2000 }; + dgusdisplay.WriteVariable(VP_MotorPluse_Dis, MotorPluse_buf_ch, 16, true); + + const uint16_t MotorMaxSpeed_buf_ch[] = { 0xEED7, 0xF3B4, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_MotorMaxSpeed_Dis, MotorMaxSpeed_buf_ch, 16, true); + + const uint16_t MotorMaxAcc_buf_ch[] = { 0xEED7, 0xF3B4, 0xD3BC, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_MotorMaxAcc_Dis, MotorMaxAcc_buf_ch, 16, true); + + const uint16_t TravelAcc_buf_ch[] = { 0xD5BF, 0xD0D0, 0xD3BC, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_TravelAcc_Dis, TravelAcc_buf_ch, 16, true); + + const uint16_t FeedRateMin_buf_ch[] = { 0xEED7, 0xA1D0, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_FeedRateMin_Dis, FeedRateMin_buf_ch, 12, true); + + const uint16_t TravelFeeRateMin_buf_ch[] = { 0xD5BF, 0xD0D0, 0xEED7, 0xA1D0, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_TravelFeeRateMin_Dis, TravelFeeRateMin_buf_ch, 24, true); + + const uint16_t Acc_buf_ch[] = { 0xD3BC, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_ACC_Dis, Acc_buf_ch, 16, true); + + const uint16_t Point_One_buf_ch[] = { 0xDAB5, 0xBBD2, 0xE3B5, 0x2000 }; + dgusdisplay.WriteVariable(VP_Point_One_Dis, Point_One_buf_ch, 12, true); + + const uint16_t Point_Two_buf_ch[] = { 0xDAB5, 0xFEB6, 0xE3B5, 0x2000 }; + dgusdisplay.WriteVariable(VP_Point_Two_Dis, Point_Two_buf_ch, 12, true); + + const uint16_t Point_Three_buf_ch[] = { 0xDAB5, 0xFDC8, 0xE3B5, 0x2000 }; + dgusdisplay.WriteVariable(VP_Point_Three_Dis, Point_Three_buf_ch, 12, true); + + const uint16_t Point_Four_buf_ch[] = { 0xDAB5, 0xC4CB, 0xE3B5, 0x2000 }; + dgusdisplay.WriteVariable(VP_Point_Four_Dis, Point_Four_buf_ch, 12, true); + + const uint16_t Point_Five_buf_ch[] = { 0xDAB5, 0xE5CE, 0xE3B5, 0x2000 }; + dgusdisplay.WriteVariable(VP_Point_Five_Dis, Point_Five_buf_ch, 12, true); + + const uint16_t Extrusion_buf_ch[] = { 0xB7BC, 0xF6B3, 0xB7CD, 0x2000 }; + dgusdisplay.WriteVariable(VP_Extrusion_Dis, Extrusion_buf_ch, 12, true); + + const uint16_t HeatBed_buf_ch[] = { 0xC8C8, 0xB2B4, 0x2000 }; + dgusdisplay.WriteVariable(VP_HeatBed_Dis, HeatBed_buf_ch, 12, true); + + const uint16_t FactoryDefaults_buf_ch[] = { 0xD6BB, 0xB4B8, 0xF6B3, 0xA7B3, 0xE8C9, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_FactoryDefaults_Dis, FactoryDefaults_buf_ch, 16, true); + + const uint16_t StoreSetting_buf_ch[] = { 0xA3B1, 0xE6B4, 0xE8C9, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_StoreSetting_Dis, StoreSetting_buf_ch, 16, true); + + const uint16_t PrintPauseConfig_buf_ch[] = { 0xDDD4, 0xA3CD, 0xBBCE, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_PrintPauseConfig_Dis, PrintPauseConfig_buf_ch, 32, true); + + const uint16_t X_Pluse_buf_ch[] = { 0x2058, 0xE1D6, 0xF6C2, 0xE5B3, 0x2000 }; + dgusdisplay.WriteVariable(VP_X_Pluse_Dis, X_Pluse_buf_ch, 16, true); + + const uint16_t Y_Pluse_buf_ch[] = { 0x2059, 0xE1D6, 0xF6C2, 0xE5B3, 0x2000 }; + dgusdisplay.WriteVariable(VP_Y_Pluse_Dis, Y_Pluse_buf_ch, 16, true); + + const uint16_t Z_Pluse_buf_ch[] = { 0x205A, 0xE1D6, 0xF6C2, 0xE5B3, 0x2000 }; + dgusdisplay.WriteVariable(VP_Z_Pluse_Dis, Z_Pluse_buf_ch, 16, true); + + const uint16_t E0_Pluse_buf_ch[] = { 0x3045, 0xE1D6, 0xF6C2, 0xE5B3, 0x2000 }; + dgusdisplay.WriteVariable(VP_E0_Pluse_Dis, E0_Pluse_buf_ch, 16, true); + + const uint16_t E1_Pluse_buf_ch[] = { 0x3145, 0xE1D6, 0xF6C2, 0xE5B3, 0x2000 }; + dgusdisplay.WriteVariable(VP_E1_Pluse_Dis, E1_Pluse_buf_ch, 16, true); + + const uint16_t X_Max_Speed_buf_ch[] = { 0x2058, 0xEED7, 0xF3B4, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_X_Max_Speed_Dis, X_Max_Speed_buf_ch, 16, true); + + const uint16_t Y_Max_Speed_buf_ch[] = { 0x2059, 0xEED7, 0xF3B4, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Y_Max_Speed_Dis, Y_Max_Speed_buf_ch, 16, true); + + const uint16_t Z_Max_Speed_buf_ch[] = { 0x205A, 0xEED7, 0xF3B4, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Z_Max_Speed_Dis, Z_Max_Speed_buf_ch, 16, true); + + const uint16_t E0_Max_Speed_buf_ch[] = { 0x3045, 0xEED7, 0xF3B4, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_E0_Max_Speed_Dis, E0_Max_Speed_buf_ch, 16, true); + + const uint16_t E1_Max_Speed_buf_ch[] = { 0x3145, 0xEED7, 0xF3B4, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_E1_Max_Speed_Dis, E1_Max_Speed_buf_ch, 16, true); + + const uint16_t X_Max_Acc_Speed_buf_ch[] = { 0x2058, 0xEED7, 0xF3B4, 0xD3BC, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_X_Max_Acc_Speed_Dis, X_Max_Acc_Speed_buf_ch, 16, true); + + const uint16_t Y_Max_Acc_Speed_buf_ch[] = { 0x2059, 0xEED7, 0xF3B4, 0xD3BC, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Y_Max_Acc_Speed_Dis, Y_Max_Acc_Speed_buf_ch, 16, true); + + const uint16_t Z_Max_Acc_Speed_buf_ch[] = { 0x205A, 0xEED7, 0xF3B4, 0xD3BC, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Z_Max_Acc_Speed_Dis, Z_Max_Acc_Speed_buf_ch, 16, true); + + const uint16_t E0_Max_Acc_Speed_buf_ch[] = { 0x3045, 0xEED7, 0xF3B4, 0xD3BC, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_E0_Max_Acc_Speed_Dis, E0_Max_Acc_Speed_buf_ch, 16, true); + + const uint16_t E1_Max_Acc_Speed_buf_ch[] = { 0x3145, 0xEED7, 0xF3B4, 0xD3BC, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_E1_Max_Acc_Speed_Dis, E1_Max_Acc_Speed_buf_ch, 16, true); + + const uint16_t X_PARK_POS_buf_ch[] = { 0x2058, 0xDDD4, 0xA3CD, 0xBBCE, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_X_PARK_POS_Dis, X_PARK_POS_buf_ch, 16, true); + + const uint16_t Y_PARK_POS_buf_ch[] = { 0x2059, 0xDDD4, 0xA3CD, 0xBBCE, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Y_PARK_POS_Dis, Y_PARK_POS_buf_ch, 16, true); + + const uint16_t Z_PARK_POS_buf_ch[] = { 0x205A, 0xDDD4, 0xA3CD, 0xBBCE, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Z_PARK_POS_Dis, Z_PARK_POS_buf_ch, 16, true); + + const uint16_t Length_buf_ch[] = { 0xBDB2, 0xA4B3, 0x2000 }; + dgusdisplay.WriteVariable(VP_Length_Dis, Length_buf_ch, 8, true); + + const uint16_t Speed_buf_ch[] = { 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Speed_Dis, Speed_buf_ch, 8, true); + + const uint16_t InOut_buf_ch[] = { 0xF8BD, 0xF6B3, 0x2000 }; + dgusdisplay.WriteVariable(VP_InOut_Dis, InOut_buf_ch, 8, true); + + const uint16_t PrintTimet_buf_en[] = { 0xF2B4, 0xA1D3, 0xB1CA, 0xE4BC, 0x2000 }; + dgusdisplay.WriteVariable(VP_PrintTime_Dis, PrintTimet_buf_en, 16, true); + + const uint16_t E0_Temp_buf_ch[] = { 0x3045, 0xC2CE, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_E0_Temp_Dis, E0_Temp_buf_ch, 16, true); + + const uint16_t E1_Temp_buf_ch[] = { 0x3145, 0xC2CE, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_E1_Temp_Dis, E1_Temp_buf_ch, 16, true); + + const uint16_t HB_Temp_buf_ch[] = { 0xC8C8, 0xB2B4, 0xC2CE, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_HB_Temp_Dis, HB_Temp_buf_ch, 16, true); + + const uint16_t Feedrate_buf_ch[] = { 0xB7BC, 0xF6B3, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Feedrate_Dis, Feedrate_buf_ch, 16, true); + + const uint16_t PrintAcc_buf_ch[] = { 0xF2B4, 0xA1D3, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_PrintAcc_Dis, PrintAcc_buf_ch, 16, true); + + const uint16_t FAN_Speed_buf_ch[] = { 0xE7B7, 0xC8C9, 0xD9CB, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Fan_Speed_Dis, FAN_Speed_buf_ch, 16, true); + + const uint16_t Printing_buf_ch[] = { 0xF2B4, 0xA1D3, 0xD0D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Printing_Dis, Printing_buf_ch, 16, true); + + const uint16_t Info_EEPROM_1_buf_ch[] = { 0xC7CA, 0xF1B7, 0xA3B1, 0xE6B4, 0xE8C9, 0xC3D6, 0xBFA3, 0x2000 }; + dgusdisplay.WriteVariable(VP_Info_EEPROM_1_Dis, Info_EEPROM_1_buf_ch, 32, true); + + const uint16_t Info_EEPROM_2_buf_ch[] = { 0xC7CA, 0xF1B7, 0xD6BB, 0xB4B8, 0xF6B3, 0xA7B3, 0xE8C9, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Info_EEPROM_2_Dis, Info_EEPROM_2_buf_ch, 32, true); + + const uint16_t TMC_X_Step_buf_ch[] = { 0x2058, 0xE9C1, 0xF4C3, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_X_Step_Dis, TMC_X_Step_buf_ch, 16, true); + + const uint16_t TMC_Y_Step_buf_ch[] = { 0x2059, 0xE9C1, 0xF4C3, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_Y_Step_Dis, TMC_Y_Step_buf_ch, 16, true); + + const uint16_t TMC_Z_Step_buf_ch[] = { 0x205A, 0xE9C1, 0xF4C3, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_Z_Step_Dis, TMC_Z_Step_buf_ch, 16, true); + + const uint16_t Info_PrinfFinsh_1_buf_ch[] = { 0xF2B4, 0xA1D3, 0xEACD, 0xC9B3, 0x2000 }; + dgusdisplay.WriteVariable(VP_Info_PrinfFinsh_1_Dis, Info_PrinfFinsh_1_buf_ch, 32, true); + + const uint16_t TMC_X_Current_buf_ch[] = { 0x2058, 0xE1D6, 0xE7B5, 0xF7C1, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_X_Current_Dis, TMC_X_Current_buf_ch, 16, true); + + const uint16_t TMC_Y_Current_buf_ch[] = { 0x2059, 0xE1D6, 0xE7B5, 0xF7C1, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_Y_Current_Dis, TMC_Y_Current_buf_ch, 16, true); + + const uint16_t TMC_Z_Current_buf_ch[] = { 0x205A, 0xE1D6, 0xE7B5, 0xF7C1, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_Z_Current_Dis, TMC_Z_Current_buf_ch, 16, true); + + const uint16_t TMC_E0_Current_buf_ch[] = { 0x3045, 0xE1D6, 0xE7B5, 0xF7C1, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_E0_Current_Dis, TMC_E0_Current_buf_ch, 16, true); + + const uint16_t TMC_X1_Current_buf_ch[] = { 0x3158, 0xE1D6, 0xE7B5, 0xF7C1, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_X1_Current_Dis, TMC_X1_Current_buf_ch, 16, true); + + const uint16_t TMC_Y1_Current_buf_ch[] = { 0x3159, 0xE1D6, 0xE7B5, 0xF7C1, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_Y1_Current_Dis, TMC_Y1_Current_buf_ch, 16, true); + + const uint16_t TMC_Z1_Current_buf_ch[] = { 0x315A, 0xE1D6, 0xE7B5, 0xF7C1, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_Z1_Current_Dis, TMC_Z1_Current_buf_ch, 16, true); + + const uint16_t TMC_E1_Current_buf_ch[] = { 0x3145, 0xE1D6, 0xE7B5, 0xF7C1, 0x2000 }; + dgusdisplay.WriteVariable(VP_TMC_E1_Current_Dis, TMC_E1_Current_buf_ch, 16, true); + + const uint16_t Min_Ex_Temp_buf_ch[] = { 0xEED7, 0xA1D0, 0xB7BC, 0xF6B3, 0xC2CE, 0xC8B6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Min_Ex_Temp_Dis, Min_Ex_Temp_buf_ch, 32, true); + + const uint16_t AutoLEVEL_INFO1_buf_ch[] = { 0xEBC7, 0xB4B0, 0xC2CF, 0xB4B0, 0xA5C5, 0x2000 }; + dgusdisplay.WriteVariable(VP_AutoLEVEL_INFO1, AutoLEVEL_INFO1_buf_ch, 32, true); + + const uint16_t EX_TEMP_INFO2_buf_ch[] = { 0xEBC7, 0xD4C9, 0xC8B5, 0x2000 }; + dgusdisplay.WriteVariable(VP_EX_TEMP_INFO2_Dis, EX_TEMP_INFO2_buf_ch, 32, true); + + const uint16_t EX_TEMP_INFO3_buf_ch[] = { 0xA1C8, 0xFBCF, 0xD3BC, 0xC8C8, 0x2000 }; + dgusdisplay.WriteVariable(VP_EX_TEMP_INFO3_Dis, EX_TEMP_INFO3_buf_ch, 32, true); + + const uint16_t PrintConfrim_Info_buf_ch[] = { 0xC7CA, 0xF1B7, 0xAABF, 0xBCCA, 0xF2B4, 0xA1D3, 0x2000 }; + dgusdisplay.WriteVariable(VP_PrintConfrim_Info_Dis, PrintConfrim_Info_buf_ch, 32, true); + + const uint16_t StopPrintConfrim_Info_buf_ch[] = { 0xC7CA, 0xF1B7, 0xA3CD, 0xB9D6, 0xF2B4, 0xA1D3, 0x2000 }; + dgusdisplay.WriteVariable(VP_StopPrintConfrim_Info_Dis, StopPrintConfrim_Info_buf_ch, 32, true); + + const uint16_t Printting_buf_ch[] = { 0xF2B4, 0xA1D3, 0xD0D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_Printting_Dis, Printting_buf_ch, 32, true); + + const uint16_t LCD_BLK_buf_ch[] = { 0xB3B1, 0xE2B9, 0xE8C9, 0xC3D6, 0x2000 }; + dgusdisplay.WriteVariable(VP_LCD_BLK_Dis, LCD_BLK_buf_ch, 32, true); + } +} + +#endif // DGUS_LCD_UI_MKS diff --git a/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h new file mode 100644 index 000000000000..15e232e413b5 --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus/mks/DGUSScreenHandler.h @@ -0,0 +1,309 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "../DGUSDisplay.h" +#include "../DGUSVPVariable.h" +#include "../DGUSDisplayDef.h" + +#include "../../../../../inc/MarlinConfig.h" + +enum DGUSLCD_Screens : uint8_t; + +class DGUSScreenHandler { +public: + DGUSScreenHandler() = default; + + static bool loop(); + + // Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen + // The bools specifing whether the strings are in RAM or FLASH. + static void sendinfoscreen(const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash); + + static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash); + + #if 0 + static void sendinfoscreen_ch_mks(const uint16_t* line1, const uint16_t* line2, const uint16_t* line3, const uint16_t* line4); + static void sendinfoscreen_en_mks(const char* line1, const char* line2, const char* line3, const char* line4) ; + static void sendinfoscreen_mks(const void* line1, const void* line2, const void* line3, const void* line4,uint16_t language); + #endif + + // "M117" Message -- msg is a RAM ptr. + static void setstatusmessage(const char* msg); + // The same for messages from Flash + static void setstatusmessagePGM(PGM_P const msg); + // Callback for VP "Display wants to change screen on idle printer" + static void ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr); + // Callback for VP "Screen has been changed" + static void ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr); + + static void ScreenBackChange(DGUS_VP_Variable &var, void *val_ptr); + + // Callback for VP "All Heaters Off" + static void HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr); + // Hook for "Change this temperature" + static void HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr); + // Hook for "Change Flowrate" + static void HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(DGUS_UI_MOVE_DIS_OPTION) + // Hook for manual move option + static void HandleManualMoveOption(DGUS_VP_Variable &var, void *val_ptr); + #endif + + static void EEPROM_CTRL(DGUS_VP_Variable &var, void *val_ptr); + static void LanguageChange_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void GetOffsetValue(DGUS_VP_Variable &var, void *val_ptr); + static void Level_Ctrl_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void MeshLevel(DGUS_VP_Variable &var, void *val_ptr); + static void MeshLevelDistanceConfig(DGUS_VP_Variable &var, void *val_ptr); + static void ManualAssistLeveling(DGUS_VP_Variable &var, void *val_ptr); + static void ZoffsetConfirm(DGUS_VP_Variable &var, void *val_ptr); + static void Z_offset_select(DGUS_VP_Variable &var, void *val_ptr); + static void GetManualMovestep(DGUS_VP_Variable &var, void *val_ptr); + static void GetZoffsetDistance(DGUS_VP_Variable &var, void *val_ptr); + static void GetMinExtrudeTemp(DGUS_VP_Variable &var, void *val_ptr); + static void GetParkPos_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleGetExMinTemp_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void DGUS_LanguageDisplay(uint8_t var); + static void TMC_ChangeConfig(DGUS_VP_Variable &var, void *val_ptr); + static void GetTurnOffCtrl(DGUS_VP_Variable &var, void *val_ptr); + static void LanguagePInit(void); + static void DGUS_Runout_Idle(void); + static void DGUS_RunoutInit(void); + static void DGUS_ExtrudeLoadInit(void); + static void LCD_BLK_Adjust(DGUS_VP_Variable &var, void *val_ptr); + + // Hook for manual move. + static void HandleManualMove(DGUS_VP_Variable &var, void *val_ptr); + // Hook for manual extrude. + static void HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr); + // Hook for motor lock and unlook + static void HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(POWER_LOSS_RECOVERY) + // Hook for power loss recovery. + static void HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr); + #endif + // Hook for settings + static void HandleSettings(DGUS_VP_Variable &var, void *val_ptr); + static void HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr); + static void HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr); + + static void HandleStepPerMMChanged_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleStepPerMMExtruderChanged_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleMaxSpeedChange_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleExtruderMaxSpeedChange_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleMaxAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleExtruderAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleChangeLevelPoint_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleTravelAccChange_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleFeedRateMinChange_MKS(DGUS_VP_Variable &var, void *val_ptr); + static void HandleMin_T_F_MKS(DGUS_VP_Variable &var, void *val_ptr); + + #if HAS_PID_HEATING + // Hook for "Change this temperature PID para" + static void HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr); + // Hook for PID autotune + static void HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if HAS_BED_PROBE + // Hook for "Change probe offset z" + static void HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if ENABLED(BABYSTEPPING) + // Hook for live z adjust action + static void HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if HAS_FAN + // Hook for fan control + static void HandleFanControl(DGUS_VP_Variable &var, void *val_ptr); + #endif + // Hook for heater control + static void HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(DGUS_PREHEAT_UI) + // Hook for preheat + static void HandlePreheat(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + // Hook for filament load and unload filament option + static void HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr); + // Hook for filament load and unload + static void HandleFilamentLoadUnload(DGUS_VP_Variable &var); + + static void MKS_FilamentLoad(DGUS_VP_Variable &var, void *val_ptr); + static void MKS_FilamentUnLoad(DGUS_VP_Variable &var, void *val_ptr); + static void MKS_LOAD_UNLOAD_IDLE(); + static void MKS_LOAD_Cancle(DGUS_VP_Variable &var, void *val_ptr); + static void GetManualFilament(DGUS_VP_Variable &var, void *val_ptr); + static void GetManualFilamentSpeed(DGUS_VP_Variable &var, void *val_ptr); + #endif + + #if ENABLED(SDSUPPORT) + // Callback for VP "Display wants to change screen when there is a SD card" + static void ScreenChangeHookIfSD(DGUS_VP_Variable &var, void *val_ptr); + // Scroll buttons on the file listing screen. + static void DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable &var, void *val_ptr); + // File touched. + static void DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr); + // start print after confirmation received. + static void DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr); + // User hit the pause, resume or abort button. + static void DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr); + // User confirmed the abort action + static void DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr); + // User hit the tune button + static void DGUSLCD_SD_PrintTune(DGUS_VP_Variable &var, void *val_ptr); + // Send a single filename to the display. + static void DGUSLCD_SD_SendFilename(DGUS_VP_Variable &var); + // Marlin informed us that a new SD has been inserted. + static void SDCardInserted(); + // Marlin informed us that the SD Card has been removed(). + static void SDCardRemoved(); + // Marlin informed us about a bad SD Card. + static void SDCardError(); + // Marlin informed us about SD print completion. + static void SDPrintingFinished(); + #endif + + // OK Button the Confirm screen. + static void ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr); + + // Update data after went to new screen (by display or by GotoScreen) + // remember: store the last-displayed screen, so it can get returned to. + // (e.g for pop up messages) + static void UpdateNewScreen(DGUSLCD_Screens newscreen, bool popup=false); + + // Recall the remembered screen. + static void PopToOldScreen(); + + // Make the display show the screen and update all VPs in it. + static void GotoScreen(DGUSLCD_Screens screen, bool ispopup = false); + + static void UpdateScreenVPData(); + + // Helpers to convert and transfer data to the display. + static void DGUSLCD_SendWordValueToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendStringToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var); + static void DGUSLCD_SendTemperaturePID(DGUS_VP_Variable &var); + static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var); + + static void DGUSLCD_SendPrintTimeToDisplay_MKS(DGUS_VP_Variable &var); + static void DGUSLCD_SendBabyStepToDisplay_MKS(DGUS_VP_Variable &var); + static void DGUSLCD_SendFanToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendGbkToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendStringToDisplay_Language_MKS(DGUS_VP_Variable &var); + static void DGUSLCD_SendTMCStepValue(DGUS_VP_Variable &var); + + #if ENABLED(PRINTCOUNTER) + static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var); + #endif + #if HAS_FAN + static void DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var); + #endif + static void DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var); + #if ENABLED(DGUS_UI_WAITING) + static void DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var); + #endif + + // Send a value from 0..100 to a variable with a range from 0..255 + static void DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr); + + static void DGUSLCD_SetUint8(DGUS_VP_Variable &var, void *val_ptr); + + template + static void DGUSLCD_SetValueDirectly(DGUS_VP_Variable &var, void *val_ptr) { + if (!var.memadr) return; + union { unsigned char tmp[sizeof(T)]; T t; } x; + unsigned char *ptr = (unsigned char*)val_ptr; + LOOP_L_N(i, sizeof(T)) x.tmp[i] = ptr[sizeof(T) - i - 1]; + *(T*)var.memadr = x.t; + } + + // Send a float value to the display. + // Display will get a 4-byte integer scaled to the number of digits: + // Tell the display the number of digits and it cheats by displaying a dot between... + template + static void DGUSLCD_SendFloatAsLongValueToDisplay(DGUS_VP_Variable &var) { + if (var.memadr) { + float f = *(float *)var.memadr; + f *= cpow(10, decimals); + dgusdisplay.WriteVariable(var.VP, (long)f); + } + } + + // Send a float value to the display. + // Display will get a 2-byte integer scaled to the number of digits: + // Tell the display the number of digits and it cheats by displaying a dot between... + template + static void DGUSLCD_SendFloatAsIntValueToDisplay(DGUS_VP_Variable &var) { + if (var.memadr) { + float f = *(float *)var.memadr; + DEBUG_ECHOLNPAIR_F(" >> ", f, 6); + f *= cpow(10, decimals); + dgusdisplay.WriteVariable(var.VP, (int16_t)f); + } + } + + // Force an update of all VP on the current screen. + static inline void ForceCompleteUpdate() { update_ptr = 0; ScreenComplete = false; } + // Has all VPs sent to the screen + static inline bool IsScreenComplete() { return ScreenComplete; } + + static inline DGUSLCD_Screens getCurrentScreen() { return current_screen; } + + static inline void SetupConfirmAction( void (*f)()) { confirm_action_cb = f; } + +private: + static DGUSLCD_Screens current_screen; //< currently on screen + static constexpr uint8_t NUM_PAST_SCREENS = 4; + static DGUSLCD_Screens past_screens[NUM_PAST_SCREENS]; //< LIFO with past screens for the "back" button. + + static uint8_t update_ptr; //< Last sent entry in the VPList for the actual screen. + static uint16_t skipVP; //< When updating the screen data, skip this one, because the user is interacting with it. + static bool ScreenComplete; //< All VPs sent to screen? + + static uint16_t ConfirmVP; //< context for confirm screen (VP that will be emulated-sent on "OK"). + + #if ENABLED(SDSUPPORT) + static int16_t top_file; //< file on top of file chooser + static int16_t file_to_print; //< touched file to be confirmed + #endif + + static void (*confirm_action_cb)(); +}; + +#define MKS_Language_Choose 0x00 +#define MKS_Language_NoChoose 0x01 + +#define MKS_SimpleChinese 0 +#define MKS_English 1 +extern uint8_t DGUSLanguageSwitch; +extern bool DGUSAutoTurnOff; + +#if ENABLED(POWER_LOSS_RECOVERY) + #define PLR_SCREEN_RECOVER MKSLCD_SCREEN_PRINT + #define PLR_SCREEN_CANCEL MKSLCD_SCREEN_HOME +#endif diff --git a/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp index 28e66e5d7ce4..8d89de3e335d 100644 --- a/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp +++ b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp @@ -20,7 +20,9 @@ * */ -/* DGUS implementation written by coldtobi in 2019 for Marlin */ +/** + * lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp + */ #include "../../../../../inc/MarlinConfigPre.h" @@ -87,7 +89,7 @@ const uint16_t VPList_Status[] PROGMEM = { }; const uint16_t VPList_Status2[] PROGMEM = { - /* VP_M117, for completeness, but it cannot be auto-uploaded */ + // VP_M117, for completeness, but it cannot be auto-uploaded #if HOTENDS >= 1 VP_Flowrate_E0, #endif diff --git a/Marlin/src/lcd/extui/lib/dgus/origin/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSScreenHandler.cpp new file mode 100644 index 000000000000..f1d91371c238 --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSScreenHandler.cpp @@ -0,0 +1,418 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../../../../inc/MarlinConfigPre.h" + +#if ENABLED(DGUS_LCD_UI_ORIGIN) + +#include "../DGUSScreenHandler.h" + +#include "../../../../../MarlinCore.h" +#include "../../../../../gcode/queue.h" +#include "../../../../../libs/duration_t.h" +#include "../../../../../module/settings.h" +#include "../../../../../module/temperature.h" +#include "../../../../../module/motion.h" +#include "../../../../../module/planner.h" +#include "../../../../../module/printcounter.h" +#include "../../../../../sd/cardreader.h" + +#if ENABLED(POWER_LOSS_RECOVERY) + #include "../../../../feature/powerloss.h" +#endif + +#if ENABLED(SDSUPPORT) + + void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file; + if (touched_nr > filelist.count()) return; + if (!filelist.seek(touched_nr)) return; + + if (filelist.isDir()) { + filelist.changeDir(filelist.filename()); + top_file = 0; + ForceCompleteUpdate(); + return; + } + + #if ENABLED(DGUS_PRINT_FILENAME) + // Send print filename + dgusdisplay.WriteVariable(VP_SD_Print_Filename, filelist.filename(), VP_SD_FileName_LEN, true); + #endif + + // Setup Confirmation screen + file_to_print = touched_nr; + + HandleUserConfirmationPopUp(VP_SD_FileSelectConfirm, nullptr, PSTR("Print file"), filelist.filename(), PSTR("from SD Card?"), true, true, false, true); + } + + void DGUSScreenHandler::DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr) { + if (!filelist.seek(file_to_print)) return; + ExtUI::printFile(filelist.shortFilename()); + GotoScreen(DGUSLCD_SCREEN_STATUS); + } + + void DGUSScreenHandler::DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr) { + + if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes. + switch (swap16(*(uint16_t*)val_ptr)) { + case 0: { // Resume + if (ExtUI::isPrintingFromMediaPaused()) { + ExtUI::resumePrint(); + } + } break; + + case 1: // Pause + + GotoScreen(MKSLCD_SCREEN_PAUSE); + if (!ExtUI::isPrintingFromMediaPaused()) { + ExtUI::pausePrint(); + //ExtUI::mks_pausePrint(); + } + break; + case 2: // Abort + HandleUserConfirmationPopUp(VP_SD_AbortPrintConfirmed, nullptr, PSTR("Abort printing"), filelist.filename(), PSTR("?"), true, true, false, true); + break; + } + } + + void DGUSScreenHandler::DGUSLCD_SD_SendFilename(DGUS_VP_Variable& var) { + uint16_t target_line = (var.VP - VP_SD_FileName0) / VP_SD_FileName_LEN; + if (target_line > DGUS_SD_FILESPERSCREEN) return; + char tmpfilename[VP_SD_FileName_LEN + 1] = ""; + var.memadr = (void*)tmpfilename; + + if (filelist.seek(top_file + target_line)) { + snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s%c"), filelist.filename(), filelist.isDir() ? '/' : 0); // snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s"), filelist.filename()); + } + DGUSLCD_SendStringToDisplay(var); + } + + void DGUSScreenHandler::SDCardInserted() { + top_file = 0; + filelist.refresh(); + auto cs = getCurrentScreen(); + if (cs == DGUSLCD_SCREEN_MAIN || cs == DGUSLCD_SCREEN_STATUS) + GotoScreen(DGUSLCD_SCREEN_SDFILELIST); + } + + void DGUSScreenHandler::SDCardRemoved() { + if (current_screen == DGUSLCD_SCREEN_SDFILELIST + || (current_screen == DGUSLCD_SCREEN_CONFIRM && (ConfirmVP == VP_SD_AbortPrintConfirmed || ConfirmVP == VP_SD_FileSelectConfirm)) + || current_screen == DGUSLCD_SCREEN_SDPRINTMANIPULATION + ) GotoScreen(DGUSLCD_SCREEN_MAIN); + } + +#endif // SDSUPPORT + +void DGUSScreenHandler::ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr) { + uint8_t *tmp = (uint8_t*)val_ptr; + + // The keycode in target is coded as , so 0x0100A means + // from screen 1 (main) to 10 (temperature). DGUSLCD_SCREEN_POPUP is special, + // meaning "return to previous screen" + DGUSLCD_Screens target = (DGUSLCD_Screens)tmp[1]; + + DEBUG_ECHOLNPAIR("\n DEBUG target", target); + + if (target == DGUSLCD_SCREEN_POPUP) { + // Special handling for popup is to return to previous menu + if (current_screen == DGUSLCD_SCREEN_POPUP && confirm_action_cb) confirm_action_cb(); + PopToOldScreen(); + return; + } + + UpdateNewScreen(target); + + #ifdef DEBUG_DGUSLCD + if (!DGUSLCD_FindScreenVPMapList(target)) DEBUG_ECHOLNPAIR("WARNING: No screen Mapping found for ", target); + #endif +} + +void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleManualMove"); + + int16_t movevalue = swap16(*(uint16_t*)val_ptr); + #if ENABLED(DGUS_UI_MOVE_DIS_OPTION) + if (movevalue) { + const uint16_t choice = *(uint16_t*)var.memadr; + movevalue = movevalue < 0 ? -choice : choice; + } + #endif + char axiscode; + unsigned int speed = 1500; // FIXME: get default feedrate for manual moves, dont hardcode. + + switch (var.VP) { + default: return; + + case VP_MOVE_X: + axiscode = 'X'; + if (!ExtUI::canMove(ExtUI::axis_t::X)) goto cannotmove; + break; + + case VP_MOVE_Y: + axiscode = 'Y'; + if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove; + break; + + case VP_MOVE_Z: + axiscode = 'Z'; + speed = 300; // default to 5mm/s + if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove; + break; + + case VP_HOME_ALL: // only used for homing + axiscode = '\0'; + movevalue = 0; // ignore value sent from display, this VP is _ONLY_ for homing. + break; + } + + if (!movevalue) { + // homing + DEBUG_ECHOPAIR(" homing ", axiscode); + char buf[6] = "G28 X"; + buf[4] = axiscode; + //DEBUG_ECHOPAIR(" ", buf); + queue.enqueue_one_now(buf); + //DEBUG_ECHOLNPGM(" ✓"); + ForceCompleteUpdate(); + return; + } + else { + // movement + DEBUG_ECHOPAIR(" move ", axiscode); + bool old_relative_mode = relative_mode; + if (!relative_mode) { + //DEBUG_ECHOPGM(" G91"); + queue.enqueue_now_P(PSTR("G91")); + //DEBUG_ECHOPGM(" ✓ "); + } + char buf[32]; // G1 X9999.99 F12345 + unsigned int backup_speed = MMS_TO_MMM(feedrate_mm_s); + char sign[] = "\0"; + int16_t value = movevalue / 100; + if (movevalue < 0) { value = -value; sign[0] = '-'; } + int16_t fraction = ABS(movevalue) % 100; + snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed); + //DEBUG_ECHOPAIR(" ", buf); + queue.enqueue_one_now(buf); + //DEBUG_ECHOLNPGM(" ✓ "); + if (backup_speed != speed) { + snprintf_P(buf, 32, PSTR("G0 F%d"), backup_speed); + queue.enqueue_one_now(buf); + //DEBUG_ECHOPAIR(" ", buf); + } + // while (!enqueue_and_echo_command(buf)) idle(); + //DEBUG_ECHOLNPGM(" ✓ "); + if (!old_relative_mode) { + //DEBUG_ECHOPGM("G90"); + queue.enqueue_now_P(PSTR("G90")); + //DEBUG_ECHOPGM(" ✓ "); + } + } + + ForceCompleteUpdate(); + DEBUG_ECHOLNPGM("manmv done."); + return; + + cannotmove: + DEBUG_ECHOLNPAIR(" cannot move ", axiscode); + return; +} + +#if HAS_PID_HEATING + void DGUSScreenHandler::HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr) { + uint16_t rawvalue = swap16(*(uint16_t*)val_ptr); + DEBUG_ECHOLNPAIR("V1:", rawvalue); + float value = (float)rawvalue / 10; + DEBUG_ECHOLNPAIR("V2:", value); + float newvalue = 0; + + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_PID_P: newvalue = value; break; + case VP_E0_PID_I: newvalue = scalePID_i(value); break; + case VP_E0_PID_D: newvalue = scalePID_d(value); break; + #endif + #if HOTENDS >= 2 + case VP_E1_PID_P: newvalue = value; break; + case VP_E1_PID_I: newvalue = scalePID_i(value); break; + case VP_E1_PID_D: newvalue = scalePID_d(value); break; + #endif + #if HAS_HEATED_BED + case VP_BED_PID_P: newvalue = value; break; + case VP_BED_PID_I: newvalue = scalePID_i(value); break; + case VP_BED_PID_D: newvalue = scalePID_d(value); break; + #endif + } + + DEBUG_ECHOLNPAIR_F("V3:", newvalue); + *(float *)var.memadr = newvalue; + + skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel + } +#endif // HAS_PID_HEATING + +#if ENABLED(BABYSTEPPING) + void DGUSScreenHandler::HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleLiveAdjustZ"); + int16_t flag = swap16(*(uint16_t*)val_ptr), + steps = flag ? -20 : 20; + ExtUI::smartAdjustAxis_steps(steps, ExtUI::axis_t::Z, true); + ForceCompleteUpdate(); + } +#endif + +#if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + + void DGUSScreenHandler::HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr) { + DEBUG_ECHOLNPGM("HandleFilamentOption"); + + uint8_t e_temp = 0; + filament_data.heated = false; + uint16_t preheat_option = swap16(*(uint16_t*)val_ptr); + if (preheat_option <= 8) { // Load filament type + filament_data.action = 1; + } + else if (preheat_option >= 10) { // Unload filament type + preheat_option -= 10; + filament_data.action = 2; + filament_data.purge_length = DGUS_FILAMENT_PURGE_LENGTH; + } + else { // Cancel filament operation + filament_data.action = 0; + } + + switch (preheat_option) { + case 0: // Load PLA + #ifdef PREHEAT_1_TEMP_HOTEND + e_temp = PREHEAT_1_TEMP_HOTEND; + #endif + break; + case 1: // Load ABS + TERN_(PREHEAT_2_TEMP_HOTEND, e_temp = PREHEAT_2_TEMP_HOTEND); + break; + case 2: // Load PET + #ifdef PREHEAT_3_TEMP_HOTEND + e_temp = PREHEAT_3_TEMP_HOTEND; + #endif + break; + case 3: // Load FLEX + #ifdef PREHEAT_4_TEMP_HOTEND + e_temp = PREHEAT_4_TEMP_HOTEND; + #endif + break; + case 9: // Cool down + default: + e_temp = 0; + break; + } + + if (filament_data.action == 0) { // Go back to utility screen + #if HOTENDS >= 1 + thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E0); + #endif + #if HOTENDS >= 2 + thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E1); + #endif + GotoScreen(DGUSLCD_SCREEN_UTILITY); + } + else { // Go to the preheat screen to show the heating progress + switch (var.VP) { + default: return; + #if HOTENDS >= 1 + case VP_E0_FILAMENT_LOAD_UNLOAD: + filament_data.extruder = ExtUI::extruder_t::E0; + thermalManager.setTargetHotend(e_temp, filament_data.extruder); + break; + #endif + #if HOTENDS >= 2 + case VP_E1_FILAMENT_LOAD_UNLOAD: + filament_data.extruder = ExtUI::extruder_t::E1; + thermalManager.setTargetHotend(e_temp, filament_data.extruder); + break; + #endif + } + GotoScreen(DGUSLCD_SCREEN_FILAMENT_HEATING); + } + } + + void DGUSScreenHandler::HandleFilamentLoadUnload(DGUS_VP_Variable &var) { + DEBUG_ECHOLNPGM("HandleFilamentLoadUnload"); + if (filament_data.action <= 0) return; + + // If we close to the target temperature, we can start load or unload the filament + if (thermalManager.hotEnoughToExtrude(filament_data.extruder) && \ + thermalManager.targetHotEnoughToExtrude(filament_data.extruder)) { + float movevalue = DGUS_FILAMENT_LOAD_LENGTH_PER_TIME; + + if (filament_data.action == 1) { // load filament + if (!filament_data.heated) { + //GotoScreen(DGUSLCD_SCREEN_FILAMENT_LOADING); + filament_data.heated = true; + } + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue; + } + else { // unload filament + if (!filament_data.heated) { + GotoScreen(DGUSLCD_SCREEN_FILAMENT_UNLOADING); + filament_data.heated = true; + } + // Before unloading extrude to prevent jamming + if (filament_data.purge_length >= 0) { + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue; + filament_data.purge_length -= movevalue; + } + else { + movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) - movevalue; + } + } + ExtUI::setAxisPosition_mm(movevalue, filament_data.extruder); + } + } +#endif // DGUS_FILAMENT_LOADUNLOAD + +bool DGUSScreenHandler::loop() { + dgusdisplay.loop(); + + const millis_t ms = millis(); + static millis_t next_event_ms = 0; + + if (!IsScreenComplete() || ELAPSED(ms, next_event_ms)) { + next_event_ms = ms + DGUS_UPDATE_INTERVAL_MS; + UpdateScreenVPData(); + } + + #if ENABLED(SHOW_BOOTSCREEN) + static bool booted = false; + + if (!booted && TERN0(POWER_LOSS_RECOVERY, recovery.valid())) + booted = true; + + if (!booted && ELAPSED(ms, TERN(USE_MKS_GREEN_UI, 1000, BOOTSCREEN_TIMEOUT))) + booted = true; + #endif + return IsScreenComplete(); +} + +#endif // DGUS_LCD_UI_ORIGIN diff --git a/Marlin/src/lcd/extui/lib/dgus/origin/DGUSScreenHandler.h b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSScreenHandler.h new file mode 100644 index 000000000000..28ab952e53f8 --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSScreenHandler.h @@ -0,0 +1,240 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "../DGUSDisplay.h" +#include "../DGUSVPVariable.h" +#include "../DGUSDisplayDef.h" + +#include "../../../../../inc/MarlinConfig.h" + +enum DGUSLCD_Screens : uint8_t; + +class DGUSScreenHandler { +public: + DGUSScreenHandler() = default; + + static bool loop(); + + // Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen + // The bools specifing whether the strings are in RAM or FLASH. + static void sendinfoscreen(const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash); + + static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash); + + // "M117" Message -- msg is a RAM ptr. + static void setstatusmessage(const char* msg); + // The same for messages from Flash + static void setstatusmessagePGM(PGM_P const msg); + // Callback for VP "Display wants to change screen on idle printer" + static void ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr); + // Callback for VP "Screen has been changed" + static void ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr); + + // Callback for VP "All Heaters Off" + static void HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr); + // Hook for "Change this temperature" + static void HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr); + // Hook for "Change Flowrate" + static void HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(DGUS_UI_MOVE_DIS_OPTION) + // Hook for manual move option + static void HandleManualMoveOption(DGUS_VP_Variable &var, void *val_ptr); + #endif + + // Hook for manual move. + static void HandleManualMove(DGUS_VP_Variable &var, void *val_ptr); + // Hook for manual extrude. + static void HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr); + // Hook for motor lock and unlook + static void HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(POWER_LOSS_RECOVERY) + // Hook for power loss recovery. + static void HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr); + #endif + // Hook for settings + static void HandleSettings(DGUS_VP_Variable &var, void *val_ptr); + static void HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr); + static void HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr); + + #if HAS_PID_HEATING + // Hook for "Change this temperature PID para" + static void HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr); + // Hook for PID autotune + static void HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if HAS_BED_PROBE + // Hook for "Change probe offset z" + static void HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if ENABLED(BABYSTEPPING) + // Hook for live z adjust action + static void HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if HAS_FAN + // Hook for fan control + static void HandleFanControl(DGUS_VP_Variable &var, void *val_ptr); + #endif + // Hook for heater control + static void HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr); + #if ENABLED(DGUS_PREHEAT_UI) + // Hook for preheat + static void HandlePreheat(DGUS_VP_Variable &var, void *val_ptr); + #endif + #if ENABLED(DGUS_FILAMENT_LOADUNLOAD) + // Hook for filament load and unload filament option + static void HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr); + // Hook for filament load and unload + static void HandleFilamentLoadUnload(DGUS_VP_Variable &var); + #endif + + #if ENABLED(SDSUPPORT) + // Callback for VP "Display wants to change screen when there is a SD card" + static void ScreenChangeHookIfSD(DGUS_VP_Variable &var, void *val_ptr); + // Scroll buttons on the file listing screen. + static void DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable &var, void *val_ptr); + // File touched. + static void DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr); + // start print after confirmation received. + static void DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr); + // User hit the pause, resume or abort button. + static void DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr); + // User confirmed the abort action + static void DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr); + // User hit the tune button + static void DGUSLCD_SD_PrintTune(DGUS_VP_Variable &var, void *val_ptr); + // Send a single filename to the display. + static void DGUSLCD_SD_SendFilename(DGUS_VP_Variable &var); + // Marlin informed us that a new SD has been inserted. + static void SDCardInserted(); + // Marlin informed us that the SD Card has been removed(). + static void SDCardRemoved(); + // Marlin informed us about a bad SD Card. + static void SDCardError(); + #endif + + // OK Button the Confirm screen. + static void ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr); + + // Update data after went to new screen (by display or by GotoScreen) + // remember: store the last-displayed screen, so it can get returned to. + // (e.g for pop up messages) + static void UpdateNewScreen(DGUSLCD_Screens newscreen, bool popup=false); + + // Recall the remembered screen. + static void PopToOldScreen(); + + // Make the display show the screen and update all VPs in it. + static void GotoScreen(DGUSLCD_Screens screen, bool ispopup = false); + + static void UpdateScreenVPData(); + + // Helpers to convert and transfer data to the display. + static void DGUSLCD_SendWordValueToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendStringToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var); + static void DGUSLCD_SendTemperaturePID(DGUS_VP_Variable &var); + static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var); + + #if ENABLED(PRINTCOUNTER) + static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var); + static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var); + #endif + #if HAS_FAN + static void DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var); + #endif + static void DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var); + #if ENABLED(DGUS_UI_WAITING) + static void DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var); + #endif + + // Send a value from 0..100 to a variable with a range from 0..255 + static void DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr); + + template + static void DGUSLCD_SetValueDirectly(DGUS_VP_Variable &var, void *val_ptr) { + if (!var.memadr) return; + union { unsigned char tmp[sizeof(T)]; T t; } x; + unsigned char *ptr = (unsigned char*)val_ptr; + LOOP_L_N(i, sizeof(T)) x.tmp[i] = ptr[sizeof(T) - i - 1]; + *(T*)var.memadr = x.t; + } + + // Send a float value to the display. + // Display will get a 4-byte integer scaled to the number of digits: + // Tell the display the number of digits and it cheats by displaying a dot between... + template + static void DGUSLCD_SendFloatAsLongValueToDisplay(DGUS_VP_Variable &var) { + if (var.memadr) { + float f = *(float *)var.memadr; + f *= cpow(10, decimals); + dgusdisplay.WriteVariable(var.VP, (long)f); + } + } + + // Send a float value to the display. + // Display will get a 2-byte integer scaled to the number of digits: + // Tell the display the number of digits and it cheats by displaying a dot between... + template + static void DGUSLCD_SendFloatAsIntValueToDisplay(DGUS_VP_Variable &var) { + if (var.memadr) { + float f = *(float *)var.memadr; + DEBUG_ECHOLNPAIR_F(" >> ", f, 6); + f *= cpow(10, decimals); + dgusdisplay.WriteVariable(var.VP, (int16_t)f); + } + } + + // Force an update of all VP on the current screen. + static inline void ForceCompleteUpdate() { update_ptr = 0; ScreenComplete = false; } + // Has all VPs sent to the screen + static inline bool IsScreenComplete() { return ScreenComplete; } + + static inline DGUSLCD_Screens getCurrentScreen() { return current_screen; } + + static inline void SetupConfirmAction( void (*f)()) { confirm_action_cb = f; } + +private: + static DGUSLCD_Screens current_screen; //< currently on screen + static constexpr uint8_t NUM_PAST_SCREENS = 4; + static DGUSLCD_Screens past_screens[NUM_PAST_SCREENS]; //< LIFO with past screens for the "back" button. + + static uint8_t update_ptr; //< Last sent entry in the VPList for the actual screen. + static uint16_t skipVP; //< When updating the screen data, skip this one, because the user is interacting with it. + static bool ScreenComplete; //< All VPs sent to screen? + + static uint16_t ConfirmVP; //< context for confirm screen (VP that will be emulated-sent on "OK"). + + #if ENABLED(SDSUPPORT) + static int16_t top_file; //< file on top of file chooser + static int16_t file_to_print; //< touched file to be confirmed + #endif + + static void (*confirm_action_cb)(); +}; + +#if ENABLED(POWER_LOSS_RECOVERY) + #define PLR_SCREEN_RECOVER DGUSLCD_SCREEN_SDPRINTMANIPULATION + #define PLR_SCREEN_CANCEL DGUSLCD_SCREEN_STATUS +#endif diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/boards.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/boards.h index 6bb920885a5b..19f926d8e086 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/boards.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/boards.h @@ -112,7 +112,7 @@ } /** - * Settings for the 4D Systems, 4.3" Embedded SPI Display 480x272, SPI, FT800 (4DLCD-FT843) + * Settings for the 4D Systems, 4.3" Embedded SPI Display 480x272, SPI, FT800 (4DLCD-FT843) * https://4dsystems.com.au/4dlcd-ft843 * Datasheet: * https://4dsystems.com.au/mwdownloads/download/link/id/52/ @@ -177,8 +177,105 @@ constexpr uint8_t CSpread = 0; constexpr uint16_t touch_threshold = 2000; /* touch-sensitivity */ } + +/** + * Settings for EVE3-50G - Matrix Orbital 5.0" 800x480, BT815 + * https://www.matrixorbital.com/ftdi-eve/eve-bt815-bt816/eve3-50g + * use for example with: https://github.com/RudolphRiedel/EVE_display-adapter + */ +#elif defined(LCD_EVE3_50G) + #if !HAS_RESOLUTION + #define TOUCH_UI_800x480 + #define TOUCH_UI_800x480_GENERIC // use more common timing parameters as the original set + #endif + #ifndef FTDI_API_LEVEL + #define FTDI_API_LEVEL 810 + #endif + namespace FTDI { + IS_FT810 + constexpr bool Use_Crystal = true; // 0 = use internal oscillator, 1 = module has a crystal populated + constexpr bool GPIO_0_Audio_Enable = false; + constexpr bool GPIO_1_Audio_Shutdown = false; + #define USE_GT911 // this display uses an alternative touch-controller and we need to tell the init function to switch + constexpr uint8_t Swizzle = 0; + constexpr uint8_t CSpread = 1; + constexpr uint8_t Pclkpol = 1; + constexpr uint16_t touch_threshold = 1200; /* touch-sensitivity */ + + constexpr uint32_t default_transform_a = 0x000109E4; + constexpr uint32_t default_transform_b = 0x000007A6; + constexpr uint32_t default_transform_c = 0xFFEC1EBA; + constexpr uint32_t default_transform_d = 0x0000072C; + constexpr uint32_t default_transform_e = 0x0001096A; + constexpr uint32_t default_transform_f = 0xFFF469CF; + } + +/** + * Settings for EVE2-50G - Matrix Orbital 5.0" 800x480, FT813 + * https://www.matrixorbital.com/ftdi-eve/eve-bt815-bt816/eve3-50g + * use for example with: https://github.com/RudolphRiedel/EVE_display-adapter + */ +#elif defined(LCD_EVE2_50G) + #if !HAS_RESOLUTION + #define TOUCH_UI_800x480 + #define TOUCH_UI_800x480_GENERIC // use more common timing parameters as the original set + #endif + #ifndef FTDI_API_LEVEL + #define FTDI_API_LEVEL 810 + #endif + namespace FTDI { + IS_FT810 + constexpr bool Use_Crystal = false; // 0 = use internal oscillator, 1 = module has a crystal populated + constexpr bool GPIO_0_Audio_Enable = false; + constexpr bool GPIO_1_Audio_Shutdown = false; + #define PATCH_GT911 // this display uses an alternative touch-controller and we need to tell the init function to patch the FT813 for it + constexpr uint8_t Pclkpol = 1; + constexpr uint8_t Swizzle = 0; + constexpr uint8_t CSpread = 1; + constexpr uint16_t touch_threshold = 1200; /* touch-sensitivity */ + + constexpr uint32_t default_transform_a = 0x000109E4; + constexpr uint32_t default_transform_b = 0x000007A6; + constexpr uint32_t default_transform_c = 0xFFEC1EBA; + constexpr uint32_t default_transform_d = 0x0000072C; + constexpr uint32_t default_transform_e = 0x0001096A; + constexpr uint32_t default_transform_f = 0xFFF469CF; + } + #else #error "Unknown or no TOUCH_UI_FTDI_EVE board specified. To add a new board, modify this file." #endif + + +/* this data is used to patch FT813 displays that use a GT911 as a touch-controller */ +#ifdef PATCH_GT911 + constexpr PROGMEM unsigned char GT911_data[] = { + 26,255,255,255,32,32,48,0,4,0,0,0,2,0,0,0, + 34,255,255,255,0,176,48,0,120,218,237,84,221,111,84,69,20,63,51,179,93,160,148,101,111,76,5,44,141,123,111,161,11,219,154,16,9,16,17,229,156,75,26,11,13,21,227,3,16,252,184,179, + 45,219,143,45,41,125,144,72,67,100,150,71,189,113,18,36,17,165,100,165,198,16,32,17,149,196,240,128,161,16,164,38,54,240,0,209,72,130,15,38,125,48,66,82,30,76,19,31,172,103,46, + 139,24,255,4,227,157,204,156,51,115,102,206,231,239,220,5,170,94,129,137,75,194,216,98,94,103,117,115,121,76,131,177,125,89,125,82,123,60,243,58,142,242,204,185,243,188,118,156, + 227,155,203,238,238,195,251,205,229,71,92,28,169,190,184,84,143,113,137,53,244,103,181,237,87,253,113,137,233,48,12,198,165,181,104,139,25,84,253,155,114,74,191,0,54,138,163, + 12,62,131,207,129,23,217,34,91,31,128,65,246,163,175,213,8,147,213,107,35,203,94,108,3,111,40,171,83,24,15,165,177,222,116,97,23,188,140,206,150,42,102,181,87,78,86,182,170,134, + 215,241,121,26,243,252,2,76,115,217,139,222,206,173,136,132,81,61,35,185,39,113,23,46,199,76,178,54,151,183,224,0,40,189,28,149,182,58,131,79,152,30,76,34,98,234,162,216,133,141, + 102,39,170,40,192,101,53,201,146,191,37,77,44,177,209,74,211,5,206,187,5,6,216,47,53,96,123,22,50,103,251,192,84,17,74,227,185,56,106,51,91,161,96,182,163,48,171,141,139,65,152, + 66,66,11,102,43,158,75,36,80,147,184,147,139,112,17,235,216,103,111,239,245,92,10,175,194,40,44,58,125,5,59,112,50,103,245,4,78,192,5,156,194,51,60,191,134,75,110,173,237,46,192, + 121,156,192,115,184,218,120,67,63,115,46,11,102,10,97,232,50,235,114,182,148,118,178,41,188,12,135,77,202,124,12,96,238,35,161,234,189,129,23,249,212,139,230,25,53,48,205,52,93, + 163,117,53,154,170,81,85,163,178,70,69,66,167,241,14,46,241,1,226,136,152,179,197,59,184,148,254,49,132,48,15,176,137,192,76,131,196,105,104,162,86,81,160,165,255,26,173,162,137, + 86,145,210,183,192,55,175,194,211,60,91,120,230,184,174,27,41,131,155,40,224,29,87,179,232,16,55,55,7,165,147,81,23,165,49,101,54,224,75,180,81,108,18,29,226,69,225,110,175,224, + 42,212,25,47,130,193,110,234,192,215,252,56,74,162,24,46,251,174,54,106,68,245,14,9,155,160,22,120,207,104,240,29,90,178,140,28,24,220,47,166,112,61,251,208,192,111,56,239,238, + 93,255,251,62,99,32,193,75,61,190,235,123,229,110,218,194,85,79,225,59,98,20,238,227,235,220,11,221,149,25,180,116,194,159,111,96,192,24,213,59,139,179,156,215,69,230,19,24,35, + 135,117,206,171,206,162,67,129,234,61,235,11,104,103,84,64,223,167,254,40,163,101,92,84,43,150,46,249,219,205,7,116,11,91,104,61,57,75,223,8,48,25,28,119,252,222,113,49,86,249, + 74,180,211,156,181,61,215,168,157,7,251,199,150,242,250,91,58,132,94,121,7,53,151,139,98,6,165,153,69,214,32,110,211,100,101,31,89,45,81,98,23,205,205,197,209,109,186,198,35, + 141,191,249,25,60,132,223,153,251,98,20,239,146,139,20,217,250,41,250,137,58,177,90,57,79,51,108,233,20,253,194,187,49,222,205,114,141,96,48,175,219,107,54,111,138,22,154,103, + 108,79,58,252,179,178,79,164,195,2,153,36,39,170,199,201,167,197,85,106,8,59,177,81,46,56,2,230,75,114,17,55,112,188,65,208,137,77,114,10,115,55,58,208,197,173,122,87,6,140, + 110,42,208,124,163,70,108,241,104,18,245,98,214,187,134,53,42,221,22,182,133,211,116,148,177,194,209,192,85,90,199,58,55,203,2,229,19,137,187,161,228,154,112,203,145,125,244, + 188,220,118,228,41,201,181,41,195,144,215,183,51,80,250,21,217,16,217,200,235,109,227,188,122,218,142,60,170,224,112,240,184,130,229,224,113,5,223,148,163,80,165,183,130,187, + 132,116,64,238,161,85,220,115,139,205,98,227,244,29,102,125,7,37,243,123,223,11,26,92,63,243,116,61,191,138,123,244,160,84,186,74,31,5,174,247,119,135,199,248,253,135,242,97, + 102,145,190,144,14,85,238,221,231,193,158,48,205,25,120,248,15,220,29,158,9,70,185,30,103,229,33,254,23,237,160,172,62,193,90,222,224,232,14,200,56,90,104,142,227,120,110,6, + 21,211,203,65,150,99,151,220,247,87,164,50,159,49,239,234,58,142,0,109,108,123,18,79,227,36,100,248,222,205,96,127,120,26,171,228,69,63,36,17,252,200,17,116,242,187,227,88,143, + 247,2,75,191,6,130,59,188,11,55,240,31,243,122,152,226,183,207,154,73,188,39,219,43,105,222,87,41,143,141,140,175,73,112,184,252,61,184,16,90,250,35,168,82,119,176,57,116,94, + 200,150,22,190,179,44,104,12,235,84,149,102,252,89,154,193,99,228,106,242,125,248,64,194,255,223,127,242,83,11,255,2,70,214,226,128,0,0 + }; +#endif // PATCH_GT911 diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.cpp index 77d870fd4ce1..736809323b6c 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/commands.cpp @@ -1073,37 +1073,48 @@ void CLCD::init() { for (counter = 0; counter < 250; counter++) { uint8_t device_id = mem_read_8(REG::ID); // Read Device ID, Should Be 0x7C; if (device_id == 0x7C) { - #if ENABLED(TOUCH_UI_DEBUG) - SERIAL_ECHO_MSG("FTDI chip initialized"); - #endif + if (ENABLED(TOUCH_UI_DEBUG)) SERIAL_ECHO_MSG("FTDI chip initialized "); break; } else delay(1); - if (counter == 249) { - #if ENABLED(TOUCH_UI_DEBUG) - SERIAL_ECHO_MSG("Timeout waiting for device ID, should be 124, got ", device_id); - #endif - } + if (TERN0(TOUCH_UI_DEBUG, counter > 248)) + SERIAL_ECHO_MSG("Timeout waiting for device ID, should be 124, got ", device_id); } - /* make sure that all units are in working conditions, usually the touch-controller needs a little more time */ + /* Ensure all units are in working condition, usually the touch-controller needs a little more time */ for (counter = 0; counter < 100; counter++) { uint8_t reset_status = mem_read_8(REG::CPURESET) & 0x03; if (reset_status == 0x00) { - #if ENABLED(TOUCH_UI_DEBUG) - SERIAL_ECHO_MSG("FTDI chip all units running "); - #endif + if (ENABLED(TOUCH_UI_DEBUG)) SERIAL_ECHO_MSG("FTDI chip all units running "); break; } else delay(1); - if (ENABLED(TOUCH_UI_DEBUG) && counter == 99) + if (TERN0(TOUCH_UI_DEBUG, counter > 98)) SERIAL_ECHO_MSG("Timeout waiting for reset status. Should be 0x00, got ", reset_status); } + #if ENABLED(USE_GT911) /* switch BT815 to use Goodix GT911 touch controller */ + mem_write_32(REG::TOUCH_CONFIG, 0x000005D1); + #endif + + #if ENABLED(PATCH_GT911) /* patch FT813 use Goodix GT911 touch controller */ + mem_write_pgm(REG::CMDB_WRITE, GT911_data, sizeof(GT911_data)); /* write binary blob to command-fifo */ + delay(10); + mem_write_8(REG::TOUCH_OVERSAMPLE, 0x0F); /* setup oversample to 0x0f as "hidden" in binary-blob for AN_336 */ + mem_write_16(REG::TOUCH_CONFIG, 0x05d0); /* write magic cookie as requested by AN_336 */ + + /* specific to the EVE2 modules from Matrix-Orbital we have to use GPIO3 to reset GT911 */ + mem_write_16(REG::GPIOX_DIR,0x8008); /* Reset-Value is 0x8000, adding 0x08 sets GPIO3 to output, default-value for REG_GPIOX is 0x8000 -> Low output on GPIO3 */ + delay(1); /* wait more than 100µs */ + mem_write_8(REG::CPURESET, 0x00); /* clear all resets */ + delay(56); /* wait more than 55ms */ + mem_write_16(REG::GPIOX_DIR,0x8000); /* setting GPIO3 back to input */ + #endif + mem_write_8(REG::PWM_DUTY, 0); // turn off Backlight, Frequency already is set to 250Hz default /* Configure the FT8xx Registers */ @@ -1140,13 +1151,13 @@ void CLCD::init() { if (GPIO_1_Audio_Shutdown) { mem_write_8(REG::GPIO_DIR, GPIO_DISP | GPIO_GP1); mem_write_8(REG::GPIO, GPIO_DISP | GPIO_GP1); - } else if (GPIO_0_Audio_Enable) { + } + else if (GPIO_0_Audio_Enable) { mem_write_8(REG::GPIO_DIR, GPIO_DISP | GPIO_GP0); mem_write_8(REG::GPIO, GPIO_DISP | GPIO_GP0); } - else { + else mem_write_8(REG::GPIO, GPIO_DISP); /* REG::GPIO_DIR is set to output for GPIO_DISP by default */ - } mem_write_8(REG::PCLK, Pclk); // Turns on Clock by setting PCLK Register to the value necessary for the module diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/resolutions.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/resolutions.h index 5b29816429f3..0c600fa0a580 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/resolutions.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/basic/resolutions.h @@ -43,7 +43,7 @@ constexpr uint16_t Vsync0 = tvfp - 1; \ constexpr uint16_t Vsync1 = tvfp + tvpw - 1; \ static_assert(thfp + thb + Hsize == th, "Mismatch in display th"); \ - static_assert(tvfp + tvb + Vsize == tv, "Mismatch in display tv"); + static_assert(tvfp + tvb + Vsize == tv, "Mismatch in display tv") #if ENABLED(TOUCH_UI_320x240) namespace FTDI { @@ -85,7 +85,7 @@ constexpr uint16_t tvb = 2; // VS Back porch (blanking) constexpr uint16_t tvpw = 10; // VS pulse width - COMPUTE_REGS_FROM_DATASHEET + COMPUTE_REGS_FROM_DATASHEET; constexpr uint32_t default_transform_a = 0x00008100; constexpr uint32_t default_transform_b = 0x00000000; @@ -97,29 +97,44 @@ #elif defined(TOUCH_UI_800x480) namespace FTDI { - constexpr uint8_t Pclk = 3; - constexpr uint8_t Pclkpol = 1; - constexpr uint16_t Hsize = 800; - constexpr uint16_t Vsize = 480; - - constexpr uint16_t th = 1056; // One horizontal line - constexpr uint16_t thfp = 210; // HS Front porch - constexpr uint16_t thb = 46; // HS Back porch (blanking) - constexpr uint16_t thpw = 23; // HS pulse width - - constexpr uint16_t tv = 525; // Vertical period time - constexpr uint16_t tvfp = 22; // VS Front porch - constexpr uint16_t tvb = 23; // VS Back porch (blanking) - constexpr uint16_t tvpw = 10; // VS pulse width - - COMPUTE_REGS_FROM_DATASHEET - - constexpr uint32_t default_transform_a = 0x0000D8B9; - constexpr uint32_t default_transform_b = 0x00000124; - constexpr uint32_t default_transform_c = 0xFFE23926; - constexpr uint32_t default_transform_d = 0xFFFFFF51; - constexpr uint32_t default_transform_e = 0xFFFF7E4F; - constexpr uint32_t default_transform_f = 0x01F0AF70; + #if defined(TOUCH_UI_800x480_GENERIC) + constexpr uint8_t Pclk = 2; + constexpr uint16_t Hsize = 800; + constexpr uint16_t Vsize = 480; + + constexpr uint16_t Vsync0 = 0; + constexpr uint16_t Vsync1 = 3; + constexpr uint16_t Voffset = 32; + constexpr uint16_t Vcycle = 525; + constexpr uint16_t Hsync0 = 0; + constexpr uint16_t Hsync1 = 48; + constexpr uint16_t Hoffset = 88; + constexpr uint16_t Hcycle = 928; + #else + constexpr uint8_t Pclk = 3; + constexpr uint8_t Pclkpol = 1; + constexpr uint16_t Hsize = 800; + constexpr uint16_t Vsize = 480; + + constexpr uint16_t th = 1056; // One horizontal line + constexpr uint16_t thfp = 210; // HS Front porch + constexpr uint16_t thb = 46; // HS Back porch (blanking) + constexpr uint16_t thpw = 23; // HS pulse width + + constexpr uint16_t tv = 525; // Vertical period time + constexpr uint16_t tvfp = 22; // VS Front porch + constexpr uint16_t tvb = 23; // VS Back porch (blanking) + constexpr uint16_t tvpw = 10; // VS pulse width + + COMPUTE_REGS_FROM_DATASHEET; + + constexpr uint32_t default_transform_a = 0x0000D8B9; + constexpr uint32_t default_transform_b = 0x00000124; + constexpr uint32_t default_transform_c = 0xFFE23926; + constexpr uint32_t default_transform_d = 0xFFFFFF51; + constexpr uint32_t default_transform_e = 0xFFFF7E4F; + constexpr uint32_t default_transform_f = 0x01F0AF70; + #endif } #else diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extras/svg2cpp.py b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extras/svg2cpp.py index c6eba3946c63..aa702ca4b4d5 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extras/svg2cpp.py +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/ftdi_eve_lib/extras/svg2cpp.py @@ -16,7 +16,7 @@ # location: . from __future__ import print_function -import argparse, re, sys +import argparse,re,sys usage = ''' This program extracts line segments from a SVG file and writes diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/language/language_en.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/language/language_en.h index c898e7b73751..e57858aa3f80 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/language/language_en.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/language/language_en.h @@ -157,13 +157,13 @@ namespace Language_en { #ifdef TOUCH_UI_COCOA_PRESS PROGMEM Language_Str MSG_BODY = u8"Body"; - PROGMEM Language_Str MSG_INTERNAL = u8"Internal"; + PROGMEM Language_Str MSG_SELECT_CHOCOLATE_TYPE = u8"Select Chocolate Type"; PROGMEM Language_Str MSG_EXTERNAL = u8"External"; PROGMEM Language_Str MSG_CHOCOLATE = u8"Chocolate"; PROGMEM Language_Str MSG_UNLOAD_CARTRIDGE = u8"Unload Cartridge"; - PROGMEM Language_Str MSG_LOAD_CHOCOLATE = u8"Load Chocolate"; - PROGMEM Language_Str MSG_CARTRIDGE_IN = u8"Cartridge In"; - PROGMEM Language_Str MSG_CARTRIDGE_OUT = u8"Cartridge Out"; + PROGMEM Language_Str MSG_LOAD_UNLOAD = u8"Load/Unload"; + PROGMEM Language_Str MSG_FULL_LOAD = u8"Full Load"; + PROGMEM Language_Str MSG_FULL_UNLOAD = u8"Full Unload"; PROGMEM Language_Str MSG_PREHEAT_CHOCOLATE = u8"Preheat Chocolate"; PROGMEM Language_Str MSG_PREHEAT_FINISHED = u8"Preheat finished"; PROGMEM Language_Str MSG_PREHEAT = u8"Preheat"; diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp index b62a9bf01bdb..6de573da8c94 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/bed_mesh_screen.cpp @@ -271,7 +271,7 @@ void BedMeshScreen::onRedraw(draw_mode_t what) { .cmd(CLEAR(true,true,true)); // Draw the shadow and tags - cmd.cmd(COLOR_RGB(0x444444)); + cmd.cmd(COLOR_RGB(Theme::bed_mesh_shadow_rgb)); BedMeshScreen::drawMesh(INSET_POS(MESH_POS), nullptr, USE_POINTS | USE_TAGS); cmd.cmd(COLOR_RGB(bg_text_enabled)); } @@ -282,6 +282,8 @@ void BedMeshScreen::onRedraw(draw_mode_t what) { if (gotAllPoints) { drawHighlightedPointValue(); } + CommandProcessor cmd; + cmd.cmd(COLOR_RGB(Theme::bed_mesh_lines_rgb)); const float levelingProgress = sq(float(mydata.count) / GRID_MAX_POINTS); BedMeshScreen::drawMesh(INSET_POS(MESH_POS), ExtUI::getMeshArray(), USE_POINTS | USE_HIGHLIGHT | USE_AUTOSCALE | (gotAllPoints ? USE_COLORS : 0), diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_load_chocolate.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_load_chocolate.cpp index 23ad1b5da6f9..d9c01366b939 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_load_chocolate.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_load_chocolate.cpp @@ -27,69 +27,179 @@ #ifdef FTDI_COCOA_LOAD_CHOCOLATE_SCREEN +#include "../ftdi_eve_lib/extras/poly_ui.h" + +#include "cocoa_press_ui.h" + +#define POLY(A) PolyUI::poly_reader_t(A, sizeof(A)/sizeof(A[0])) + +const uint8_t shadow_depth = 5; + using namespace ExtUI; using namespace FTDI; using namespace Theme; -#define GRID_COLS 2 -#define GRID_ROWS 6 +constexpr static LoadChocolateScreenData &mydata = screen_data.LoadChocolateScreen; -#define TITLE_POS BTN_POS(1,1), BTN_SIZE(2,1) -#define DESCRIPTION_POS BTN_POS(1,2), BTN_SIZE(2,3) -#define CARTRIDGE_OUT_BTN_POS BTN_POS(1,5), BTN_SIZE(1,1) -#define CARTRIDGE_IN_BTN_POS BTN_POS(2,5), BTN_SIZE(1,1) -#define BACK_BTN_POS BTN_POS(1,6), BTN_SIZE(2,1) +void LoadChocolateScreen::draw_syringe(draw_mode_t what) { + #if ENABLED(COCOA_PRESS_CHOCOLATE_LEVEL_SENSOR) + const float fill_level = get_chocolate_fill_level(); + #else + constexpr float fill_level = 1.0f; + #endif -void LoadChocolateScreen::onRedraw(draw_mode_t what) { CommandProcessor cmd; + PolyUI ui(cmd, what); if (what & BACKGROUND) { - cmd.cmd(CLEAR_COLOR_RGB(bg_color)) - .cmd(CLEAR(true,true,true)) - .cmd(COLOR_RGB(bg_text_enabled)) - .tag(0) - .font(font_large) - .text(TITLE_POS, GET_TEXT_F(MSG_LOAD_CHOCOLATE)); - draw_text_box(cmd, DESCRIPTION_POS, F( - "Drop your chocolate refill into the cartridge. " - "Press and hold the Cartridge Out button until " - "the plunger adapter is visible at the bottom of " - "the extruder. Securely attach a red plunger to " - "the plunger adapter and load the cartridge onto " - "the plunger. Press and hold Cartridge In button " - "until cartridge is fully loaded into the extruder, " - "and use the buttons to help follow the locking path " - "to lock"), - OPT_CENTERY, font_medium); + // Paint the shadow for the syringe + ui.color(shadow_rgb); + ui.shadow(POLY(syringe_outline), shadow_depth); } if (what & FOREGROUND) { - cmd.font(font_medium) - .colors(normal_btn) - .tag(2).button(CARTRIDGE_OUT_BTN_POS, GET_TEXT_F(MSG_CARTRIDGE_OUT)) - .tag(3).button(CARTRIDGE_IN_BTN_POS, GET_TEXT_F(MSG_CARTRIDGE_IN)) - .colors(action_btn) - .tag(1).button(BACK_BTN_POS, GET_TEXT_F(MSG_BACK)); + int16_t x, y, h, v; + + // Paint the syringe icon + ui.color(syringe_rgb); + ui.fill(POLY(syringe_outline)); + + ui.color(fluid_rgb); + ui.bounds(POLY(syringe_fluid), x, y, h, v); + cmd.cmd(SAVE_CONTEXT()); + cmd.cmd(SCISSOR_XY(x,y + v * (1.0 - fill_level))); + cmd.cmd(SCISSOR_SIZE(h, v * fill_level)); + ui.fill(POLY(syringe_fluid), false); + cmd.cmd(RESTORE_CONTEXT()); + + ui.color(stroke_rgb); + ui.fill(POLY(syringe)); } } +void LoadChocolateScreen::draw_buttons(draw_mode_t what) { + int16_t x, y, h, v; + + CommandProcessor cmd; + PolyUI ui(cmd, what); + + cmd.font(font_medium).colors(normal_btn); + + ui.bounds(POLY(load_screen_unload_btn), x, y, h, v); + cmd.tag(2).button(x, y, h, v, GET_TEXT_F(MSG_FULL_UNLOAD)); + + ui.bounds(POLY(load_screen_load_btn), x, y, h, v); + cmd.tag(3).button(x, y, h, v, GET_TEXT_F(MSG_FULL_LOAD)); + + ui.bounds(POLY(load_screen_back_btn), x, y, h, v); + cmd.tag(1).colors(action_btn).button(x, y, h, v, GET_TEXT_F(MSG_BACK)); +} + +void LoadChocolateScreen::draw_text(draw_mode_t what) { + if (what & BACKGROUND) { + int16_t x, y, h, v; + + CommandProcessor cmd; + PolyUI ui(cmd, what); + + cmd.font(font_medium).cmd(COLOR_RGB(bg_text_enabled)); + + ui.bounds(POLY(load_sreen_title), x, y, h, v); + cmd.tag(2).text(x, y, h, v, GET_TEXT_F(MSG_LOAD_UNLOAD)); + + ui.bounds(POLY(load_screen_increment), x, y, h, v); + cmd.tag(3).text(x, y, h, v, GET_TEXT_F(MSG_INCREMENT)); + } +} + +void LoadChocolateScreen::draw_arrows(draw_mode_t what) { + CommandProcessor cmd; + PolyUI ui(cmd, what); + + ui.button_fill (fill_rgb); + ui.button_stroke(stroke_rgb, 28); + ui.button_shadow(shadow_rgb, shadow_depth); + + constexpr uint8_t style = PolyUI::REGULAR; + + ui.button(4, POLY(load_screen_extrude), style); + ui.button(5, POLY(load_screen_retract), style); +} + +void LoadChocolateScreen::onEntry() { + mydata.repeat_tag = 0; +} + +void LoadChocolateScreen::onRedraw(draw_mode_t what) { + if (what & BACKGROUND) { + CommandProcessor cmd; + cmd.cmd(CLEAR_COLOR_RGB(bg_color)) + .cmd(CLEAR(true,true,true)) + .tag(0); + } + + draw_syringe(what); + draw_arrows(what); + draw_buttons(what); + draw_text(what); +} + +bool LoadChocolateScreen::onTouchStart(uint8_t) { + mydata.repeat_tag = 0; + return true; +} + bool LoadChocolateScreen::onTouchEnd(uint8_t tag) { using namespace ExtUI; switch (tag) { + case 2: + mydata.repeat_tag = (mydata.repeat_tag == 2) ? 0 : 2; + break; + case 3: + mydata.repeat_tag = (mydata.repeat_tag == 3) ? 0 : 3; + break; case 1: GOTO_PREVIOUS(); break; } return true; } +void LoadChocolateScreen::setManualFeedrateAndIncrement(float feedrate_mm_s, float &increment_mm) { + // Compute increment so feedrate so that the tool lags the adjuster when it is + // being held down, this allows enough margin for the planner to + // connect segments and even out the motion. + ExtUI::setFeedrate_mm_s(feedrate_mm_s); + increment_mm = feedrate_mm_s / ((TOUCH_REPEATS_PER_SECOND) * 0.80f); +} + bool LoadChocolateScreen::onTouchHeld(uint8_t tag) { if (ExtUI::isMoving()) return false; // Don't allow moves to accumulate - constexpr float increment = 0.25; - MoveAxisScreen::setManualFeedrate(E0, increment); + float increment; + setManualFeedrateAndIncrement(20, increment); #define UI_INCREMENT_AXIS(axis) UI_INCREMENT(AxisPosition_mm, axis); #define UI_DECREMENT_AXIS(axis) UI_DECREMENT(AxisPosition_mm, axis); switch (tag) { - case 2: UI_DECREMENT_AXIS(E0); break; - case 3: UI_INCREMENT_AXIS(E0); break; + case 2: { + if (get_chocolate_fill_level() < 0.1) { + mydata.repeat_tag = 0; + return false; + } + UI_INCREMENT_AXIS(E0); + break; + } + case 3: { + if (get_chocolate_fill_level() > 0.75) { + mydata.repeat_tag = 0; + return false; + } + UI_DECREMENT_AXIS(E0); + break; + } + case 4: + UI_INCREMENT_AXIS(E0); + break; + case 5: + UI_DECREMENT_AXIS(E0); + break; default: return false; } #undef UI_DECREMENT_AXIS @@ -97,4 +207,14 @@ bool LoadChocolateScreen::onTouchHeld(uint8_t tag) { return false; } +void LoadChocolateScreen::onIdle() { + reset_menu_timeout(); + if (mydata.repeat_tag) onTouchHeld(mydata.repeat_tag); + if (refresh_timer.elapsed(STATUS_UPDATE_INTERVAL)) { + if (!EventLoop::is_touch_held()) + onRefresh(); + refresh_timer.start(); + } + BaseScreen::onIdle(); +} #endif // FTDI_COCOA_LOAD_CHOCOLATE_SCREEN diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_load_chocolate.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_load_chocolate.h index 262a6c9802bb..819464495b67 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_load_chocolate.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_load_chocolate.h @@ -26,9 +26,22 @@ #define FTDI_COCOA_LOAD_CHOCOLATE_SCREEN #define FTDI_COCOA_LOAD_CHOCOLATE_SCREEN_CLASS LoadChocolateScreen +struct LoadChocolateScreenData { + uint8_t repeat_tag; +}; + class LoadChocolateScreen : public BaseScreen, public CachedScreen { + private: + static void draw_syringe(draw_mode_t what); + static void draw_arrows(draw_mode_t what); + static void draw_buttons(draw_mode_t what); + static void draw_text(draw_mode_t what); public: + static void setManualFeedrateAndIncrement(float feedrate_mm_s, float &increment); + static void onEntry(); + static void onIdle(); static void onRedraw(draw_mode_t); + static bool onTouchStart(uint8_t tag); static bool onTouchEnd(uint8_t tag); static bool onTouchHeld(uint8_t tag); }; diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_main_menu.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_main_menu.cpp index 56981e308468..f35b3296d8e4 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_main_menu.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_main_menu.cpp @@ -29,17 +29,19 @@ using namespace FTDI; using namespace Theme; -#define GRID_ROWS 4 +#define GRID_ROWS 5 #define GRID_COLS 2 -#define MOVE_XYZ_POS BTN_POS(1,1), BTN_SIZE(1,1) +#define ZPROBE_ZOFFSET_POS BTN_POS(1,1), BTN_SIZE(1,1) +#define MOVE_XYZ_POS BTN_POS(1,2), BTN_SIZE(1,1) #define TEMPERATURE_POS BTN_POS(2,1), BTN_SIZE(1,1) -#define ZPROBE_ZOFFSET_POS BTN_POS(1,2), BTN_SIZE(1,1) #define MOVE_E_POS BTN_POS(2,2), BTN_SIZE(1,1) #define SPEED_POS BTN_POS(1,3), BTN_SIZE(1,1) #define ADVANCED_SETTINGS_POS BTN_POS(2,3), BTN_SIZE(1,1) -#define ABOUT_PRINTER_POS BTN_POS(1,4), BTN_SIZE(1,1) -#define BACK_POS BTN_POS(2,4), BTN_SIZE(1,1) +#define DISABLE_STEPPERS_POS BTN_POS(1,4), BTN_SIZE(1,1) +#define LEVELING_POS BTN_POS(2,4), BTN_SIZE(1,1) +#define ABOUT_PRINTER_POS BTN_POS(1,5), BTN_SIZE(1,1) +#define BACK_POS BTN_POS(2,5), BTN_SIZE(1,1) void MainMenu::onRedraw(draw_mode_t what) { if (what & BACKGROUND) { @@ -52,16 +54,19 @@ void MainMenu::onRedraw(draw_mode_t what) { CommandProcessor cmd; cmd.colors(normal_btn) .font(Theme::font_medium) - .tag(2).button(MOVE_XYZ_POS, GET_TEXT_F(MSG_XYZ_MOVE)) - .tag(3).button(TEMPERATURE_POS, GET_TEXT_F(MSG_TEMPERATURE)) + .tag( 2).button(MOVE_XYZ_POS, GET_TEXT_F(MSG_XYZ_MOVE)) + .tag( 3).button(TEMPERATURE_POS, GET_TEXT_F(MSG_TEMPERATURE)) .enabled(BOTH(HAS_LEVELING, HAS_BED_PROBE)) - .tag(4).button(ZPROBE_ZOFFSET_POS, GET_TEXT_F(MSG_ZPROBE_ZOFFSET)) - .tag(5).button(MOVE_E_POS, GET_TEXT_F(MSG_E_MOVE)) - .tag(6).button(SPEED_POS, GET_TEXT_F(MSG_PRINT_SPEED)) - .tag(7).button(ADVANCED_SETTINGS_POS, GET_TEXT_F(MSG_ADVANCED_SETTINGS)) - .tag(8).button(ABOUT_PRINTER_POS, GET_TEXT_F(MSG_INFO_MENU)) + .tag( 4).button(ZPROBE_ZOFFSET_POS, GET_TEXT_F(MSG_ZPROBE_ZOFFSET)) + .tag( 5).button(MOVE_E_POS, GET_TEXT_F(MSG_E_MOVE)) + .tag( 6).button(SPEED_POS, GET_TEXT_F(MSG_PRINT_SPEED)) + .tag( 7).button(ADVANCED_SETTINGS_POS, GET_TEXT_F(MSG_ADVANCED_SETTINGS)) + .tag( 8).button(DISABLE_STEPPERS_POS, GET_TEXT_F(MSG_DISABLE_STEPPERS)) + .enabled(HAS_LEVELING) + .tag( 9).button(LEVELING_POS, GET_TEXT_F(MSG_LEVELING)) + .tag(10).button(ABOUT_PRINTER_POS, GET_TEXT_F(MSG_INFO_MENU)) .colors(action_btn) - .tag(1).button(BACK_POS, GET_TEXT_F(MSG_BACK)); + .tag(1).button(BACK_POS, GET_TEXT_F(MSG_BACK)); } } @@ -69,16 +74,20 @@ bool MainMenu::onTouchEnd(uint8_t tag) { using namespace ExtUI; switch (tag) { - case 1: SaveSettingsDialogBox::promptToSaveSettings(); break; - case 2: GOTO_SCREEN(MoveXYZScreen); break; - case 3: GOTO_SCREEN(TemperatureScreen); break; + case 1: SaveSettingsDialogBox::promptToSaveSettings(); break; + case 2: GOTO_SCREEN(MoveXYZScreen); break; + case 3: GOTO_SCREEN(TemperatureScreen); break; #if BOTH(HAS_LEVELING, HAS_BED_PROBE) - case 4: GOTO_SCREEN(ZOffsetScreen); break; + case 4: GOTO_SCREEN(ZOffsetScreen); break; #endif - case 5: GOTO_SCREEN(MoveEScreen); break; - case 6: GOTO_SCREEN(FeedratePercentScreen); break; - case 7: GOTO_SCREEN(AdvancedSettingsMenu); break; - case 8: GOTO_SCREEN(AboutScreen); break; + case 5: GOTO_SCREEN(MoveEScreen); break; + case 6: GOTO_SCREEN(FeedratePercentScreen); break; + case 7: GOTO_SCREEN(AdvancedSettingsMenu); break; + case 8: injectCommands_P(PSTR("M84")); break; + #if HAS_LEVELING + case 9: GOTO_SCREEN(LevelingMenu); break; + #endif + case 10: GOTO_SCREEN(AboutScreen); break; default: return false; } diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_move_e_screen.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_move_e_screen.cpp index 10660736fafe..2621ef64fe2a 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_move_e_screen.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_move_e_screen.cpp @@ -30,22 +30,24 @@ using namespace FTDI; using namespace ExtUI; +constexpr static MoveAxisScreenData &mydata = screen_data.MoveAxisScreen; + void MoveEScreen::onRedraw(draw_mode_t what) { widgets_t w(what); - w.precision(1); + w.precision(1, DEFAULT_MIDRANGE); w.units(GET_TEXT_F(MSG_UNITS_MM)); w.heading( GET_TEXT_F(MSG_E_MOVE)); w.color(Theme::e_axis); #if EXTRUDERS == 1 - w.adjuster( 8, GET_TEXT_F(MSG_AXIS_E), screen_data.MoveAxis.e_rel[0], canMove(E0)); + w.adjuster( 8, GET_TEXT_F(MSG_AXIS_E), mydata.e_rel[0], canMove(E0)); #elif HAS_MULTI_EXTRUDER - w.adjuster( 8, GET_TEXT_F(MSG_AXIS_E1), screen_data.MoveAxis.e_rel[0], canMove(E0)); - w.adjuster( 10, GET_TEXT_F(MSG_AXIS_E2), screen_data.MoveAxis.e_rel[1], canMove(E1)); + w.adjuster( 8, GET_TEXT_F(MSG_AXIS_E1), mydata.e_rel[0], canMove(E0)); + w.adjuster( 10, GET_TEXT_F(MSG_AXIS_E2), mydata.e_rel[1], canMove(E1)); #if EXTRUDERS > 2 - w.adjuster( 12, GET_TEXT_F(MSG_AXIS_E3), screen_data.MoveAxis.e_rel[2], canMove(E2)); + w.adjuster( 12, GET_TEXT_F(MSG_AXIS_E3), mydata.e_rel[2], canMove(E2)); #endif #if EXTRUDERS > 3 - w.adjuster( 14, GET_TEXT_F(MSG_AXIS_E4), screen_data.MoveAxis.e_rel[3], canMove(E3)); + w.adjuster( 14, GET_TEXT_F(MSG_AXIS_E4), mydata.e_rel[3], canMove(E3)); #endif #endif w.increments(); diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_preheat_menu.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_preheat_menu.cpp index d515b2a27b02..92d152236079 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_preheat_menu.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_preheat_menu.cpp @@ -32,7 +32,7 @@ using namespace Theme; #define GRID_COLS 2 void PreheatMenu::onRedraw(draw_mode_t what) { - const int16_t w = has_extra_heater() ? BTN_W(1) : BTN_W(2); + const int16_t w = TERN0(COCOA_PRESS_EXTRA_HEATER, has_extra_heater() ? BTN_W(1) : BTN_W(2)); const int16_t h = BTN_H(1); if (what & BACKGROUND) { @@ -42,10 +42,12 @@ void PreheatMenu::onRedraw(draw_mode_t what) { .tag(0) .cmd(COLOR_RGB(bg_text_enabled)) .font(Theme::font_medium) - .text ( BTN_POS(1,1), w, h, GET_TEXT_F(MSG_INTERNAL)); - if (has_extra_heater()) { + .text( BTN_POS(1,1), w, h, GET_TEXT_F(MSG_SELECT_CHOCOLATE_TYPE)); + #if ENABLED(COCOA_PRESS_EXTRA_HEATER) + if (has_extra_heater()) { cmd.text( BTN_POS(2,1), w, h, GET_TEXT_F(MSG_EXTERNAL)); - } + } + #endif } if (what & FOREGROUND) { @@ -55,11 +57,13 @@ void PreheatMenu::onRedraw(draw_mode_t what) { .tag(2).button(BTN_POS(1,2), w, h, F("Dark Chocolate")) .tag(3).button(BTN_POS(1,3), w, h, F("Milk Chocolate")) .tag(4).button(BTN_POS(1,4), w, h, F("White Chocolate")); - if (has_extra_heater()) { + #if ENABLED(COCOA_PRESS_EXTRA_HEATER) + if (has_extra_heater()) { cmd.tag(5).button(BTN_POS(2,2), w, h, F("Dark Chocolate")) .tag(6).button(BTN_POS(2,3), w, h, F("Milk Chocolate")) .tag(7).button(BTN_POS(2,4), w, h, F("White Chocolate")); - } + } + #endif cmd.colors(action_btn) .tag(1) .button(BTN_POS(1,5), BTN_SIZE(2,1), GET_TEXT_F(MSG_BACK)); } diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_preheat_screen.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_preheat_screen.cpp index abea9dcdfe89..66256ab46f94 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_preheat_screen.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_preheat_screen.cpp @@ -101,7 +101,7 @@ void PreheatTimerScreen::draw_adjuster(draw_mode_t what, uint8_t tag, progmem_st cmd.tag(0) .font(font_small); if (what & BACKGROUND) { - cmd.text( SUB_POS(1,1), SUB_SIZE(9,1), label) + cmd.text( SUB_POS(1,1), SUB_SIZE(9,1), label) .button(SUB_POS(1,2), SUB_SIZE(5,1), F(""), OPT_FLAT); } @@ -126,20 +126,20 @@ void PreheatTimerScreen::onRedraw(draw_mode_t what) { draw_message(what); draw_time_remaining(what); draw_interaction_buttons(what); - draw_adjuster(what, 1, GET_TEXT_F(MSG_NOZZLE), getTargetTemp_celsius(E0), NOZZLE_ADJ_POS); - draw_adjuster(what, 3, GET_TEXT_F(MSG_BODY), getTargetTemp_celsius(E1), BODY_ADJ_POS); - draw_adjuster(what, 5, GET_TEXT_F(MSG_CHAMBER), getTargetTemp_celsius(CHAMBER), CHAMBER_ADJ_POS); + draw_adjuster(what, 2, GET_TEXT_F(MSG_NOZZLE), getTargetTemp_celsius(E0), NOZZLE_ADJ_POS); + draw_adjuster(what, 4, GET_TEXT_F(MSG_BODY), getTargetTemp_celsius(E1), BODY_ADJ_POS); + draw_adjuster(what, 6, GET_TEXT_F(MSG_CHAMBER), getTargetTemp_celsius(CHAMBER), CHAMBER_ADJ_POS); } bool PreheatTimerScreen::onTouchHeld(uint8_t tag) { - const float increment = (tag == 5 || tag == 6) ? 1 : 0.1; + const float increment = (tag == 6 || tag == 7) ? 1 : 0.1; switch (tag) { - case 1: UI_DECREMENT(TargetTemp_celsius, E0); break; - case 2: UI_INCREMENT(TargetTemp_celsius, E0); break; - case 3: UI_DECREMENT(TargetTemp_celsius, E1); break; - case 4: UI_INCREMENT(TargetTemp_celsius, E1); break; - case 5: UI_DECREMENT(TargetTemp_celsius, CHAMBER); break; - case 6: UI_INCREMENT(TargetTemp_celsius, CHAMBER); break; + case 2: UI_DECREMENT(TargetTemp_celsius, E0); break; + case 3: UI_INCREMENT(TargetTemp_celsius, E0); break; + case 4: UI_DECREMENT(TargetTemp_celsius, E1); break; + case 5: UI_INCREMENT(TargetTemp_celsius, E1); break; + case 6: UI_DECREMENT(TargetTemp_celsius, CHAMBER); break; + case 7: UI_INCREMENT(TargetTemp_celsius, CHAMBER); break; default: return false; } @@ -149,7 +149,7 @@ bool PreheatTimerScreen::onTouchHeld(uint8_t tag) { bool PreheatTimerScreen::onTouchEnd(uint8_t tag) { switch (tag) { case 1: GOTO_PREVIOUS(); return true; - default: break; + default: return current_screen.onTouchHeld(tag); } return false; } diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_status_screen.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_status_screen.cpp index f7d44e293607..5a0fe485f833 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_status_screen.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_status_screen.cpp @@ -86,10 +86,8 @@ void StatusScreen::draw_temperature(draw_mode_t what) { int16_t x, y, h, v; if (what & BACKGROUND) { - cmd.cmd(COLOR_RGB(bg_color)); - cmd.cmd(COLOR_RGB(fluid_rgb)); - cmd.font(font_medium); + cmd.font(font_medium).tag(10); ui.bounds(POLY(chocolate_label), x, y, h, v); cmd.text(x, y, h, v, GET_TEXT_F(MSG_CHOCOLATE)); @@ -119,7 +117,7 @@ void StatusScreen::draw_temperature(draw_mode_t what) { char str[15]; cmd.cmd(COLOR_RGB(fluid_rgb)); - cmd.font(font_large); + cmd.font(font_large).tag(10); format_temp(str, getActualTemp_celsius(E0)); ui.bounds(POLY(h0_temp), x, y, h, v); @@ -144,11 +142,8 @@ void StatusScreen::draw_temperature(draw_mode_t what) { } void StatusScreen::draw_syringe(draw_mode_t what) { - #if NUM_SERVOS < 2 - // Note, this requires a new pin 108 to be added to to access ADC9 - // "ArduinoAddons/arduino-1.8.5/packages/ultimachine/hardware/sam/1.6.9-b/variants/archim/variant.cpp" - const int val = analogRead(108); - const float fill_level = float(val) / 1024; + #if ENABLED(COCOA_PRESS_CHOCOLATE_LEVEL_SENSOR) + const float fill_level = get_chocolate_fill_level(); #else constexpr float fill_level = 1.0f; #endif @@ -192,15 +187,13 @@ void StatusScreen::draw_buttons(draw_mode_t what) { CommandProcessor cmd; PolyUI ui(cmd, what); - ui.bounds(POLY(unload_cartridge_btn), x, y, h, v); - cmd.font(font_medium).colors(normal_btn); - ui.bounds(POLY(unload_cartridge_btn), x, y, h, v); - cmd.tag(1).button(x, y, h, v, GET_TEXT_F(MSG_UNLOAD_CARTRIDGE)); + ui.bounds(POLY(park_btn), x, y, h, v); + cmd.tag(1).button(x, y, h, v, GET_TEXT_F(MSG_FILAMENT_PARK_ENABLED)); ui.bounds(POLY(load_chocolate_btn), x, y, h, v); - cmd.tag(2).button(x, y, h, v, GET_TEXT_F(MSG_LOAD_CHOCOLATE)); + cmd.tag(2).button(x, y, h, v, GET_TEXT_F(MSG_LOAD_UNLOAD)); ui.bounds(POLY(preheat_chocolate_btn), x, y, h, v); cmd.tag(3).button(x, y, h, v, GET_TEXT_F(MSG_PREHEAT_CHOCOLATE)); @@ -242,7 +235,7 @@ bool StatusScreen::onTouchStart(uint8_t) { bool StatusScreen::onTouchEnd(uint8_t tag) { switch (tag) { - case 1: GOTO_SCREEN(UnloadCartridgeScreen); break; + case 1: SpinnerDialogBox::enqueueAndWait_P(F("G28 O\nG27")); break; case 2: GOTO_SCREEN(LoadChocolateScreen); break; case 3: GOTO_SCREEN(PreheatMenu); break; case 4: GOTO_SCREEN(MainMenu); break; @@ -270,6 +263,7 @@ bool StatusScreen::onTouchEnd(uint8_t tag) { PUSH_SCREEN(StatusScreen); break; case 9: GOTO_SCREEN(FilesScreen); break; + case 10: GOTO_SCREEN(TemperatureScreen); break; default: return false; } // If a passcode is enabled, the LockScreen will prevent the @@ -280,8 +274,7 @@ bool StatusScreen::onTouchEnd(uint8_t tag) { bool StatusScreen::onTouchHeld(uint8_t tag) { if (tag == 8 && !ExtUI::isMoving()) { - increment = 0.05; - MoveAxisScreen::setManualFeedrate(E0, increment); + LoadChocolateScreen::setManualFeedrateAndIncrement(1, increment); UI_INCREMENT(AxisPosition_mm, E0); current_screen.onRefresh(); } diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_ui.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_ui.h index 5cbaced7f6b5..f67961830fd8 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_ui.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/cocoa_press_ui.h @@ -11,7 +11,7 @@ * GNU General Public License for more details. * * * * To view a copy of the GNU General Public License, go to the following * - * location: . * + * location: . * ****************************************************************************/ /** @@ -32,7 +32,7 @@ constexpr float y_max = 272.000000; const PROGMEM uint16_t syringe_outline[] = {0xED96, 0x14F0, 0xE65D, 0x10E9, 0xDED2, 0x0F9C, 0xD74B, 0x110E, 0xD01B, 0x1543, 0xCE80, 0x1836, 0xCE0A, 0x1C3A, 0xCE0F, 0x27AD, 0xCF0A, 0x2BD3, 0xD127, 0x2E5B, 0xD2A1, 0x2FF0, 0xD2A2, 0x9FC9, 0xD407, 0xA97A, 0xD7B9, 0xB10C, 0xD7BF, 0xBB58, 0xD978, 0xC2BE, 0xDD55, 0xC6EB, 0xDD58, 0xD159, 0xDE3B, 0xD3A8, 0xDFCF, 0xD3AF, 0xE0B8, 0xD04C, 0xE0B8, 0xC6EB, 0xE4A7, 0xC299, 0xE652, 0xBAF6, 0xE652, 0xB10C, 0xEA2E, 0xA8EA, 0xEB6C, 0x9E86, 0xEB6C, 0x2F58, 0xEF3C, 0x2B4E, 0xF003, 0x2583, 0xEFFD, 0x1AC2, 0xED96, 0x14F0, 0xED96, 0x14F0}; const PROGMEM uint16_t syringe_fluid[] = {0xDE73, 0x2512, 0xDA0C, 0x261D, 0xD5B8, 0x29A0, 0xD4AE, 0x2D87, 0xD4AE, 0x9F60, 0xD585, 0xA63B, 0xDE44, 0xA9DE, 0xE32A, 0xA942, 0xE7E3, 0xA6A5, 0xE930, 0xA342, 0xE95D, 0x9C1D, 0xE95B, 0x31B8, 0xE955, 0x2B63, 0xE867, 0x2A67, 0xE790, 0x28DE, 0xE342, 0x25CB, 0xDE73, 0x2512}; const PROGMEM uint16_t syringe[] = {0xED91, 0x1502, 0xE658, 0x10FB, 0xDECE, 0x0FAE, 0xD746, 0x1120, 0xD016, 0x1555, 0xCE7B, 0x1848, 0xCE05, 0x1C4D, 0xCE0A, 0x27BF, 0xCF05, 0x2BE5, 0xD122, 0x2E6E, 0xD29C, 0x3002, 0xD29D, 0x9FDB, 0xD402, 0xA98C, 0xD7B4, 0xB11F, 0xD7BA, 0xBB6A, 0xD973, 0xC2D1, 0xDD50, 0xC6FD, 0xDD53, 0xD16C, 0xDE36, 0xD3BA, 0xDFCA, 0xD3C2, 0xE0B3, 0xD05E, 0xE0B3, 0xC6FD, 0xE4A2, 0xC2AB, 0xE64D, 0xBB09, 0xE64D, 0xB11F, 0xEA29, 0xA8FC, 0xEB67, 0x9E98, 0xEB67, 0x2F6B, 0xEF37, 0x2B60, 0xEFFE, 0x2595, 0xEFF8, 0x1AD5, 0xED91, 0x1502, 0xED91, 0x1502, 0xFFFF, 0xD1CF, 0x1A7E, 0xD84F, 0x16DB, 0xDF19, 0x15A9, 0xE5E0, 0x16EA, 0xEC5B, 0x1AA4, 0xEC9D, 0x1D34, 0xEC9D, 0x20CC, 0xE5F1, 0x1D41, 0xDF02, 0x1C12, 0xD812, 0x1D41, 0xD166, 0x20CC, 0xD16C, 0x1B45, 0xD1CF, 0x1A7E, 0xFFFF, 0xE3BD, 0xACFD, 0xDE8E, 0xAF4F, 0xD988, 0xAC0F, 0xD7CC, 0xA8CD, 0xDD1C, 0xAAA9, 0xE287, 0xAA5B, 0xE655, 0xA8BE, 0xE3BD, 0xACFD, 0xFFFF, 0xE802, 0x2DC5, 0xE809, 0x343C, 0xE808, 0x9FC8, 0xE7E3, 0xA296, 0xE70D, 0xA4B1, 0xE2C9, 0xA70E, 0xDE4E, 0xA790, 0xD6A1, 0xA457, 0xD5FF, 0x9F2B, 0xD5FF, 0x2DFD, 0xD6B2, 0x2B72, 0xDA78, 0x2861, 0xDE9D, 0x276F, 0xE300, 0x2824, 0xE70D, 0x2B13, 0xE7FF, 0x2DB6, 0xE800, 0x2DC5, 0xE802, 0x2DC5, 0xFFFF, 0xE2ED, 0xBA8B, 0xE1CC, 0xBF52, 0xDF1C, 0xC165, 0xDC64, 0xBF99, 0xDB1B, 0xBAFF, 0xDB19, 0xB433, 0xDF04, 0xB552, 0xE2EF, 0xB438, 0xE2ED, 0xBA8B, 0xFFFF, 0xEC09, 0x2893, 0xE925, 0x2A08, 0xE57D, 0x261D, 0xE149, 0x246F, 0xDBDE, 0x24A0, 0xD6BC, 0x2795, 0xD484, 0x2A46, 0xD1C0, 0x2853, 0xD166, 0x251E, 0xD80D, 0x2151, 0xDF02, 0x200C, 0xE5F6, 0x2151, 0xEC9D, 0x251E, 0xEC09, 0x2893}; -const PROGMEM uint16_t unload_cartridge_btn[] = {0x0AAA, 0x0E1E, 0x57FF, 0x0E1E, 0x57FF, 0x33C3, 0x0AAA, 0x33C3, 0x0AAA, 0x0E1E}; +const PROGMEM uint16_t park_btn[] = {0x0AAA, 0x0E1E, 0x57FF, 0x0E1E, 0x57FF, 0x33C3, 0x0AAA, 0x33C3, 0x0AAA, 0x0E1E}; const PROGMEM uint16_t pause_btn[] = {0x47FF, 0xCA58, 0x7FFF, 0xCA58, 0x7FFF, 0xEFFE, 0x47FF, 0xEFFE, 0x47FF, 0xCA58}; const PROGMEM uint16_t load_chocolate_btn[] = {0x0AAA, 0x3D2C, 0x57FF, 0x3D2C, 0x57FF, 0x62D2, 0x0AAA, 0x62D2, 0x0AAA, 0x3D2C}; const PROGMEM uint16_t preheat_chocolate_btn[] = {0x0AAA, 0x6C3B, 0x57FF, 0x6C3B, 0x57FF, 0x91E0, 0x0AAA, 0x91E0, 0x0AAA, 0x6C3B}; @@ -49,6 +49,13 @@ const PROGMEM uint16_t h0_label[] = {0x62A9, 0x2A5A, 0x8FFE, 0x2A5A, 0x8FFE, 0x4 const PROGMEM uint16_t h0_temp[] = {0x62A9, 0x41E1, 0x8FFE, 0x41E1, 0x8FFE, 0x5968, 0x62A9, 0x5968, 0x62A9, 0x41E1}; const PROGMEM uint16_t h1_label[] = {0x8FFE, 0x2A5A, 0xBD53, 0x2A5A, 0xBD53, 0x41E1, 0x8FFE, 0x41E1, 0x8FFE, 0x2A5A}; const PROGMEM uint16_t h1_temp[] = {0x8FFE, 0x41E1, 0xBD53, 0x41E1, 0xBD53, 0x5968, 0x8FFE, 0x5968, 0x8FFE, 0x41E1}; -const PROGMEM uint16_t extrude_btn[] = {0xC859, 0xDD2B, 0xF5AE, 0xDD2B, 0xF5AE, 0xEFFE, 0xC859, 0xEFFE, 0xC859, 0xDD2B}; const PROGMEM uint16_t h2_label[] = {0x8FFE, 0x5E1D, 0xBD53, 0x5E1D, 0xBD53, 0x75A4, 0x8FFE, 0x75A4, 0x8FFE, 0x5E1D}; const PROGMEM uint16_t h2_temp[] = {0x8FFE, 0x75A4, 0xBD53, 0x75A4, 0xBD53, 0x8D2C, 0x8FFE, 0x8D2C, 0x8FFE, 0x75A4}; +const PROGMEM uint16_t extrude_btn[] = {0xC859, 0xDD2B, 0xF5AE, 0xDD2B, 0xF5AE, 0xEFFE, 0xC859, 0xEFFE, 0xC859, 0xDD2B}; +const PROGMEM uint16_t load_screen_extrude[] = {0x25FB, 0x89AE, 0x2F58, 0x89AE, 0x2F58, 0xAAF6, 0x3406, 0xAAF6, 0x2AAA, 0xBB9A, 0x214D, 0xAAF6, 0x25FB, 0xAAF6, 0x25FB, 0x89AE}; +const PROGMEM uint16_t load_screen_retract[] = {0x25FC, 0x790A, 0x2F58, 0x790A, 0x2F58, 0x57C2, 0x3406, 0x57C2, 0x2AAA, 0x471D, 0x214D, 0x57C2, 0x25FC, 0x57C2, 0x25FC, 0x790A}; +const PROGMEM uint16_t load_screen_back_btn[] = {0x1555, 0xCA58, 0xC553, 0xCA58, 0xC553, 0xEFFE, 0x1555, 0xEFFE, 0x1555, 0xCA58}; +const PROGMEM uint16_t load_screen_unload_btn[] = {0x4AAA, 0x8EBD, 0xC553, 0x8EBD, 0xC553, 0xB463, 0x4AAA, 0xB463, 0x4AAA, 0x8EBD}; +const PROGMEM uint16_t load_screen_load_btn[] = {0x4AAA, 0x5322, 0xC553, 0x5322, 0xC553, 0x78C7, 0x4AAA, 0x78C7, 0x4AAA, 0x5322}; +const PROGMEM uint16_t load_sreen_title[] = {0x4AAA, 0x1787, 0xC553, 0x1787, 0xC553, 0x3D2C, 0x4AAA, 0x3D2C, 0x4AAA, 0x1787}; +const PROGMEM uint16_t load_screen_increment[] = {0x1555, 0x2E1D, 0x3FFF, 0x2E1D, 0x3FFF, 0x3D2C, 0x1555, 0x3D2C, 0x1555, 0x2E1D}; diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/confirm_user_request_alert_box.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/confirm_user_request_alert_box.cpp index 957c95f047c3..e3892217a556 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/confirm_user_request_alert_box.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/confirm_user_request_alert_box.cpp @@ -50,6 +50,12 @@ bool ConfirmUserRequestAlertBox::onTouchEnd(uint8_t tag) { } } +void ConfirmUserRequestAlertBox::onIdle() { + if (!ExtUI::awaitingUserConfirm()) { + hide(); + } +} + void ConfirmUserRequestAlertBox::show(const char* msg) { drawMessage(msg); storeBackground(); diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/move_axis_screen.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/move_axis_screen.cpp index 5f5971458a1f..7edf8e16401c 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/move_axis_screen.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/move_axis_screen.cpp @@ -70,8 +70,8 @@ void MoveAxisScreen::onRedraw(draw_mode_t what) { } bool BaseMoveAxisScreen::onTouchHeld(uint8_t tag) { - #define UI_INCREMENT_AXIS(axis) UI_INCREMENT(AxisPosition_mm, axis); - #define UI_DECREMENT_AXIS(axis) UI_DECREMENT(AxisPosition_mm, axis); + #define UI_INCREMENT_AXIS(axis) setManualFeedrate(axis, increment); UI_INCREMENT(AxisPosition_mm, axis); + #define UI_DECREMENT_AXIS(axis) setManualFeedrate(axis, increment); UI_DECREMENT(AxisPosition_mm, axis); const float increment = getIncrement(); switch (tag) { case 2: UI_DECREMENT_AXIS(X); break; diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screen_data.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screen_data.h index e725a237978d..06368f0ce75c 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screen_data.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screen_data.h @@ -58,6 +58,7 @@ union screen_data_t { DECL_DATA_IF_INCLUDED(FTDI_BED_MESH_SCREEN) DECL_DATA_IF_INCLUDED(FTDI_STRESS_TEST_SCREEN) DECL_DATA_IF_INCLUDED(FTDI_COCOA_PREHEAT_SCREEN) + DECL_DATA_IF_INCLUDED(FTDI_COCOA_LOAD_CHOCOLATE_SCREEN) DECL_DATA_IF_INCLUDED(FTDI_NUDGE_NOZZLE_SCREEN) DECL_DATA_IF_INCLUDED(FTDI_BASE_NUMERIC_ADJ_SCREEN) DECL_DATA_IF_INCLUDED(FTDI_ALERT_DIALOG_BOX) diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screens.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screens.cpp index ab3c3d71148c..889ed734cc92 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screens.cpp +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screens.cpp @@ -98,6 +98,9 @@ SCREEN_TABLE { DECL_SCREEN_IF_INCLUDED(FTDI_BIO_PRINTING_DIALOG_BOX) DECL_SCREEN_IF_INCLUDED(FTDI_BIO_CONFIRMOME_XYZ) DECL_SCREEN_IF_INCLUDED(FTDI_BIO_CONFIRMOME_E) + DECL_SCREEN_IF_INCLUDED(FTDI_COCOA_STATUS_SCREEN) + DECL_SCREEN_IF_INCLUDED(FTDI_COCOA_MAIN_MENU) + DECL_SCREEN_IF_INCLUDED(FTDI_COCOA_ADVANCED_SETTINGS_MENU) DECL_SCREEN_IF_INCLUDED(FTDI_COCOA_PREHEAT_MENU) DECL_SCREEN_IF_INCLUDED(FTDI_COCOA_PREHEAT_SCREEN) DECL_SCREEN_IF_INCLUDED(FTDI_COCOA_UNLOAD_CARTRIDGE_SCREEN) diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screens.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screens.h index a82d8988dada..61d702ebafba 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screens.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/screens/screens.h @@ -100,7 +100,6 @@ enum { #if ENABLED(TOUCH_UI_COCOA_PRESS) PREHEAT_MENU_CACHE, PREHEAT_TIMER_SCREEN_CACHE, - UNLOAD_CARTRIDGE_SCREEN_CACHE, LOAD_CHOCOLATE_SCREEN_CACHE, MOVE_XYZ_SCREEN_CACHE, MOVE_E_SCREEN_CACHE, @@ -145,11 +144,11 @@ enum { #elif ENABLED(TOUCH_UI_COCOA_PRESS) #include "cocoa_press_status_screen.h" #include "cocoa_press_main_menu.h" - #include "cocoa_press_advanced_settings.h" + #include "cocoa_press_advanced_settings_menu.h" #include "cocoa_press_preheat_menu.h" #include "cocoa_press_preheat_screen.h" - #include "cocoa_press_unload_cartridge.h" #include "cocoa_press_load_chocolate.h" + #include "move_axis_screen.h" #include "cocoa_press_move_xyz_screen.h" #include "cocoa_press_move_e_screen.h" #include "tune_menu.h" @@ -176,7 +175,6 @@ enum { #include "change_filament_screen.h" #include "move_axis_screen.h" #include "steps_screen.h" -#include "stepper_current_screen.h" #include "feedrate_percent_screen.h" #include "max_velocity_screen.h" #include "max_acceleration_screen.h" diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/theme/colors.h b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/theme/colors.h index cdcf00a21b25..1649675122e9 100644 --- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/theme/colors.h +++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/theme/colors.h @@ -85,6 +85,9 @@ namespace Theme { constexpr uint32_t logo_bg_rgb = accent_color_1; constexpr uint32_t logo_fill_rgb = accent_color_0; constexpr uint32_t logo_stroke_rgb = accent_color_4; + + constexpr uint32_t bed_mesh_lines_rgb = 0xFFFFFF; + constexpr uint32_t bed_mesh_shadow_rgb = 0x444444; #elif ANY(TOUCH_UI_COCOA_THEME, TOUCH_UI_FROZEN_THEME) constexpr uint32_t theme_darkest = accent_color_1; constexpr uint32_t theme_dark = accent_color_4; @@ -102,6 +105,9 @@ namespace Theme { constexpr uint32_t logo_bg_rgb = accent_color_5; constexpr uint32_t logo_fill_rgb = accent_color_6; constexpr uint32_t logo_stroke_rgb = accent_color_2; + + constexpr uint32_t bed_mesh_lines_rgb = accent_color_6; + constexpr uint32_t bed_mesh_shadow_rgb = 0x444444; #else constexpr uint32_t theme_darkest = gray_color_1; constexpr uint32_t theme_dark = gray_color_2; @@ -119,6 +125,9 @@ namespace Theme { constexpr uint32_t logo_bg_rgb = accent_color_4; constexpr uint32_t logo_fill_rgb = accent_color_3; constexpr uint32_t logo_stroke_rgb = 0x000000; + + constexpr uint32_t bed_mesh_lines_rgb = 0xFFFFFF; + constexpr uint32_t bed_mesh_shadow_rgb = 0x444444; #endif constexpr uint32_t shadow_rgb = gray_color_6; diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp index 2cf6f05a99ac..6e0d7814d02c 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_keyboard.cpp @@ -162,7 +162,7 @@ static void lv_kb_event_cb(lv_obj_t *kb, lv_event_t event) { draw_return_ui(); break; case GCodeCommand: - if (queue.length <= (BUFSIZE - 3)) { + if (!queue.ring_buffer.full(3)) { // Hook anything that goes to the serial port MYSERIAL0.setHook(lv_serial_capt_hook, lv_eom_hook, 0); queue.enqueue_one_now(ret_ta_txt); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp index 495acda06bda..039591b03ed2 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_manuaLevel.cpp @@ -29,6 +29,8 @@ #include "../../../../gcode/queue.h" #include "../../../../inc/MarlinConfig.h" +extern const char G28_STR[]; + extern lv_group_t *g; static lv_obj_t *scr; @@ -46,7 +48,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { switch (obj->mks_obj_id) { case ID_M_POINT1 ... ID_M_POINT5: - if (queue.length == 0) { + if (queue.ring_buffer.empty()) { if (uiCfg.leveling_first_time) { uiCfg.leveling_first_time = false; queue.inject_P(G28_STR); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp index 1c07583d53c1..34c716130007 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_move_motor.cpp @@ -38,8 +38,6 @@ static lv_task_t *updatePosTask; static char cur_label = 'Z'; static float cur_pos = 0; -void disp_cur_pos(); - enum { ID_M_X_P = 1, ID_M_X_N, @@ -51,10 +49,16 @@ enum { ID_M_RETURN }; +void disp_cur_pos() { + char str_1[16]; + sprintf_P(public_buf_l, PSTR("%c:%s mm"), cur_label, dtostrf(cur_pos, 1, 1, str_1)); + if (labelP) lv_label_set_text(labelP, public_buf_l); +} + static void event_handler(lv_obj_t *obj, lv_event_t event) { char str_1[16]; if (event != LV_EVENT_RELEASED) return; - if (queue.length <= (BUFSIZE - 3)) { + if (!queue.ring_buffer.full(3)) { bool do_inject = true; float dist = uiCfg.move_dist; switch (obj->mks_obj_id) { @@ -125,12 +129,6 @@ void lv_draw_move_motor() { disp_cur_pos(); } -void disp_cur_pos() { - char str_1[16]; - sprintf_P(public_buf_l, PSTR("%c:%s mm"), cur_label, dtostrf(cur_pos, 1, 1, str_1)); - if (labelP) lv_label_set_text(labelP, public_buf_l); -} - void disp_move_dist() { if ((int)(10 * uiCfg.move_dist) == 1) lv_imgbtn_set_src_both(buttonV, "F:/bmp_step_move0_1.bin"); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp index 0a8f81ea86a2..d32851f76167 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_print_file.cpp @@ -66,8 +66,10 @@ uint8_t sel_id = 0; //root2.rewind(); //SERIAL_ECHOLN(list_file.curDirPath); - if (curDirLever != 0) card.cd(list_file.curDirPath); - else card.cdroot(); // while(card.cdup()); + if (curDirLever != 0) + card.cd(list_file.curDirPath); + else + card.cdroot(); const uint16_t fileCnt = card.get_num_Files(); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp b/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp index 97200efb08fb..047a6cdb70d1 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/draw_ready_print.cpp @@ -152,9 +152,9 @@ void lv_draw_ready_print() { limit_info = lv_label_create_empty(scr); lv_style_copy(&limit_style, &lv_style_scr); - limit_style.body.main_color.full = 0X0000; - limit_style.body.grad_color.full = 0X0000; - limit_style.text.color.full = 0Xffff; + limit_style.body.main_color.full = 0x0000; + limit_style.body.grad_color.full = 0x0000; + limit_style.text.color.full = 0xffff; lv_obj_set_style(limit_info, &limit_style); lv_obj_set_pos(limit_info, 20, 120); @@ -163,9 +163,9 @@ void lv_draw_ready_print() { det_info = lv_label_create_empty(scr); lv_style_copy(&det_style, &lv_style_scr); - det_style.body.main_color.full = 0X0000; - det_style.body.grad_color.full = 0X0000; - det_style.text.color.full = 0Xffff; + det_style.body.main_color.full = 0x0000; + det_style.body.grad_color.full = 0x0000; + det_style.text.color.full = 0xffff; lv_obj_set_style(det_info, &det_style); lv_obj_set_pos(det_info, 20, 145); diff --git a/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.h b/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.h index 0abfd7834a3d..19c93468e4aa 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.h +++ b/Marlin/src/lcd/extui/lib/mks_ui/pic_manager.h @@ -116,7 +116,7 @@ #endif // Flash flag -#define REFLSHE_FLGA_ADD (0X800000-32) +#define REFLSHE_FLGA_ADD (0x800000-32) // SD card information first addr #define VAR_INF_ADDR 0x000000 diff --git a/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp b/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp index 71cdb0f7d4d0..02ca16e00797 100644 --- a/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp +++ b/Marlin/src/lcd/extui/lib/mks_ui/wifi_module.cpp @@ -1231,13 +1231,13 @@ void utf8_2_unicode(uint8_t *source, uint8_t Len) { while (1) { char_byte_num = source[i] & 0xF0; - if (source[i] < 0X80) { + if (source[i] < 0x80) { //ASCII --1byte FileName_unicode[char_i] = source[i]; i += 1; char_i += 1; } - else if (char_byte_num == 0XC0 || char_byte_num == 0XD0) { + else if (char_byte_num == 0xC0 || char_byte_num == 0xD0) { //--2byte u16_h = (((uint16_t)source[i] << 8) & 0x1F00) >> 2; u16_l = ((uint16_t)source[i + 1] & 0x003F); @@ -1247,7 +1247,7 @@ void utf8_2_unicode(uint8_t *source, uint8_t Len) { i += 2; char_i += 2; } - else if (char_byte_num == 0XE0) { + else if (char_byte_num == 0xE0) { //--3byte u16_h = (((uint16_t)source[i] << 8) & 0x0F00) << 4; u16_m = (((uint16_t)source[i + 1] << 8) & 0x3F00) >> 2; @@ -1258,7 +1258,7 @@ void utf8_2_unicode(uint8_t *source, uint8_t Len) { i += 3; char_i += 2; } - else if (char_byte_num == 0XF0) { + else if (char_byte_num == 0xF0) { //--4byte i += 4; //char_i += 3; @@ -1613,7 +1613,7 @@ void wifi_rcv_handle() { if (wifiTransError.flag != 0x1) WIFI_IO1_RESET(); getDataF = 1; } - if (need_ok_later && (queue.length < BUFSIZE)) { + if (need_ok_later && !queue.ring_buffer.full()) { need_ok_later = false; send_to_wifi((uint8_t *)"ok\r\n", strlen("ok\r\n")); } @@ -1772,7 +1772,7 @@ void get_wifi_commands() { static int wifi_read_count = 0; if (espGcodeFifo.wait_tick > 5) { - while ((queue.length < BUFSIZE) && (espGcodeFifo.r != espGcodeFifo.w)) { + while (!queue.ring_buffer.full() && (espGcodeFifo.r != espGcodeFifo.w)) { espGcodeFifo.wait_tick = 0; diff --git a/Marlin/src/lcd/extui/ui_api.cpp b/Marlin/src/lcd/extui/ui_api.cpp index d1ffb4c4379b..7c178a0339bd 100644 --- a/Marlin/src/lcd/extui/ui_api.cpp +++ b/Marlin/src/lcd/extui/ui_api.cpp @@ -340,8 +340,10 @@ namespace ExtUI { #endif } - extruder_t getActiveTool() { - switch (active_extruder) { + extruder_t getTool(const uint8_t extruder) { + switch (extruder) { + case 7: return E7; + case 6: return E6; case 5: return E5; case 4: return E4; case 3: return E3; @@ -351,6 +353,8 @@ namespace ExtUI { } } + extruder_t getActiveTool() { return getTool(active_extruder); } + bool isMoving() { return planner.has_blocks_queued(); } bool canMove(const axis_t axis) { diff --git a/Marlin/src/lcd/extui/ui_api.h b/Marlin/src/lcd/extui/ui_api.h index bfd658b0d9b0..4214ba5821dc 100644 --- a/Marlin/src/lcd/extui/ui_api.h +++ b/Marlin/src/lcd/extui/ui_api.h @@ -215,6 +215,7 @@ namespace ExtUI { void setAxisMaxJerk_mm_s(const float, const extruder_t); #endif + extruder_t getTool(const uint8_t extruder); extruder_t getActiveTool(); void setActiveTool(const extruder_t, bool no_move); diff --git a/Marlin/src/lcd/language/language_sk.h b/Marlin/src/lcd/language/language_sk.h index 1900f5371945..a9df28382e8e 100644 --- a/Marlin/src/lcd/language/language_sk.h +++ b/Marlin/src/lcd/language/language_sk.h @@ -30,6 +30,13 @@ * * Translated by Michal Holeš, Farma MaM * https://www.facebook.com/farmamam + * + * Substitutions are applied for the following characters when used + * in menu items that call lcd_put_u8str_ind_P with an index: + * + * = displays '0'....'10' for indexes 0 - 10 + * ~ displays '1'....'11' for indexes 0 - 10 + * * displays 'E1'...'E11' for indexes 0 - 10 (By default. Uses LCD_FIRST_TOOL) */ #define DISPLAY_CHARSET_ISO10646_SK @@ -37,7 +44,7 @@ namespace Language_sk { using namespace Language_en; // Inherit undefined strings from English constexpr uint8_t CHARSIZE = 2; - PROGMEM Language_Str LANGUAGE = _UxGT("Slovak"); + PROGMEM Language_Str LANGUAGE = _UxGT("Slovenčina"); PROGMEM Language_Str WELCOME_MSG = MACHINE_NAME _UxGT(" pripravená."); PROGMEM Language_Str MSG_YES = _UxGT("ÁNO"); @@ -100,12 +107,19 @@ namespace Language_sk { #endif PROGMEM Language_Str MSG_PREHEAT_CUSTOM = _UxGT("Vlastná teplota"); PROGMEM Language_Str MSG_COOLDOWN = _UxGT("Schladiť"); + PROGMEM Language_Str MSG_CUTTER_FREQUENCY = _UxGT("Frekvencia"); PROGMEM Language_Str MSG_LASER_MENU = _UxGT("Nastavenie lasera"); - PROGMEM Language_Str MSG_LASER_POWER = _UxGT("Výkon lasera"); PROGMEM Language_Str MSG_SPINDLE_MENU = _UxGT("Nastavenie vretena"); + PROGMEM Language_Str MSG_LASER_POWER = _UxGT("Výkon lasera"); PROGMEM Language_Str MSG_SPINDLE_POWER = _UxGT("Výkon vretena"); + PROGMEM Language_Str MSG_LASER_TOGGLE = _UxGT("Prepnúť laser"); + PROGMEM Language_Str MSG_LASER_PULSE_MS = _UxGT("Test. impulz ms"); + PROGMEM Language_Str MSG_LASER_FIRE_PULSE = _UxGT("Vystreliť impulz"); + PROGMEM Language_Str MSG_SPINDLE_TOGGLE = _UxGT("Prepnúť vreteno"); + PROGMEM Language_Str MSG_SPINDLE_FORWARD = _UxGT("Dopredný chod"); PROGMEM Language_Str MSG_SPINDLE_REVERSE = _UxGT("Spätný chod"); + PROGMEM Language_Str MSG_SWITCH_PS_ON = _UxGT("Zapnúť napájanie"); PROGMEM Language_Str MSG_SWITCH_PS_OFF = _UxGT("Vypnúť napájanie"); PROGMEM Language_Str MSG_EXTRUDE = _UxGT("Vytlačiť (extr.)"); @@ -114,6 +128,10 @@ namespace Language_sk { PROGMEM Language_Str MSG_BED_LEVELING = _UxGT("Vyrovnanie podložky"); PROGMEM Language_Str MSG_LEVEL_BED = _UxGT("Vyrovnať podložku"); PROGMEM Language_Str MSG_LEVEL_CORNERS = _UxGT("Vyrovnať rohy"); + PROGMEM Language_Str MSG_LEVEL_CORNERS_RAISE = _UxGT("Zdvyhnite podl., kým sa nezopne sonda"); + PROGMEM Language_Str MSG_LEVEL_CORNERS_IN_RANGE = _UxGT("Rohy sú vrámci odchyl. Vyrovnajte podl."); + PROGMEM Language_Str MSG_LEVEL_CORNERS_GOOD_POINTS = _UxGT("Dobré body: "); + PROGMEM Language_Str MSG_LEVEL_CORNERS_LAST_Z = _UxGT("Posl. Z: "); PROGMEM Language_Str MSG_NEXT_CORNER = _UxGT("Ďalší roh"); PROGMEM Language_Str MSG_MESH_EDITOR = _UxGT("Editor sieťe bodov"); PROGMEM Language_Str MSG_EDIT_MESH = _UxGT("Upraviť sieť bodov"); @@ -247,6 +265,9 @@ namespace Language_sk { PROGMEM Language_Str MSG_MOVE_01MM = _UxGT("Posunúť o 0,1mm"); PROGMEM Language_Str MSG_MOVE_1MM = _UxGT("Posunúť o 1mm"); PROGMEM Language_Str MSG_MOVE_10MM = _UxGT("Posunúť o 10mm"); + PROGMEM Language_Str MSG_MOVE_0001IN = _UxGT("Posunúť o 0,001in"); + PROGMEM Language_Str MSG_MOVE_001IN = _UxGT("Posunúť o 0,01in"); + PROGMEM Language_Str MSG_MOVE_01IN = _UxGT("Posunúť o 0,1in"); PROGMEM Language_Str MSG_SPEED = _UxGT("Rýchlosť"); PROGMEM Language_Str MSG_BED_Z = _UxGT("Výška podl."); PROGMEM Language_Str MSG_NOZZLE = _UxGT("Tryska"); @@ -355,11 +376,13 @@ namespace Language_sk { PROGMEM Language_Str MSG_BUTTON_DONE = _UxGT("Hotovo"); PROGMEM Language_Str MSG_BUTTON_BACK = _UxGT("Naspäť"); PROGMEM Language_Str MSG_BUTTON_PROCEED = _UxGT("Pokračovať"); + PROGMEM Language_Str MSG_BUTTON_SKIP = _UxGT("Preskočiť"); PROGMEM Language_Str MSG_PAUSING = _UxGT("Pozastavujem..."); PROGMEM Language_Str MSG_PAUSE_PRINT = _UxGT("Pozastaviť tlač"); PROGMEM Language_Str MSG_RESUME_PRINT = _UxGT("Obnoviť tlač"); PROGMEM Language_Str MSG_HOST_START_PRINT = _UxGT("Spustiť z hosta"); PROGMEM Language_Str MSG_STOP_PRINT = _UxGT("Zastaviť tlač"); + PROGMEM Language_Str MSG_END_LOOPS = _UxGT("Koniec opak. sluč."); PROGMEM Language_Str MSG_PRINTING_OBJECT = _UxGT("Tlačím objekt"); PROGMEM Language_Str MSG_CANCEL_OBJECT = _UxGT("Zrušiť objekt"); PROGMEM Language_Str MSG_CANCEL_OBJECT_N = _UxGT("Zrušiť objekt ="); @@ -649,6 +672,8 @@ namespace Language_sk { PROGMEM Language_Str MSG_REHEATING = _UxGT("Zohrievanie..."); PROGMEM Language_Str MSG_PROBE_WIZARD = _UxGT("Sprievodca sondy Z"); + PROGMEM Language_Str MSG_PROBE_WIZARD_PROBING = _UxGT("Referencia Z"); + PROGMEM Language_Str MSG_PROBE_WIZARD_MOVING = _UxGT("Presúvam na pozíciu"); PROGMEM Language_Str MSG_SOUND = _UxGT("Zvuk"); diff --git a/Marlin/src/lcd/marlinui.h b/Marlin/src/lcd/marlinui.h index 2e55c9ad1d29..1c9e80c75e8e 100644 --- a/Marlin/src/lcd/marlinui.h +++ b/Marlin/src/lcd/marlinui.h @@ -248,7 +248,7 @@ class MarlinUI { static inline uint32_t _calculated_remaining_time() { const duration_t elapsed = print_job_timer.duration(); const progress_t progress = _get_progress(); - return elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress; + return progress ? elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress : 0; } #if ENABLED(USE_M73_REMAINING_TIME) static uint32_t remaining_time; diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index cb7827168b9e..aab93c3bdda5 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -177,18 +177,25 @@ void menu_backlash(); #if ENABLED(PIDTEMPBED) int16_t autotune_temp_bed = PREHEAT_1_TEMP_BED; #endif + #if ENABLED(PIDTEMPCHAMBER) + int16_t autotune_temp_chamber = PREHEAT_1_TEMP_CHAMBER; + #endif #include "../../gcode/queue.h" - void _lcd_autotune(const int16_t e) { + void _lcd_autotune(const heater_id_t hid) { char cmd[30]; - sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e, - #if HAS_PID_FOR_BOTH - e < 0 ? autotune_temp_bed : autotune_temp[e] - #else - TERN(PIDTEMPBED, autotune_temp_bed, autotune_temp[e]) + int16_t tune_temp; + switch (hid) { + #if ENABLED(PIDTEMPBED) + case H_BED: tune_temp = autotune_temp_bed; break; #endif - ); + #if ENABLED(PIDTEMPCHAMBER) + case H_CHAMBER: tune_temp = autotune_temp_chamber; break; + #endif + default: tune_temp = autotune_temp[hid]; break; + } + sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), hid, tune_temp); queue.inject(cmd); ui.return_to_status(); } @@ -225,7 +232,7 @@ void menu_backlash(); #if ENABLED(PID_AUTOTUNE_MENU) #define DEFINE_PIDTEMP_FUNCS(N) \ _DEFINE_PIDTEMP_BASE_FUNCS(N); \ - void lcd_autotune_callback_E##N() { _lcd_autotune(N); } + void lcd_autotune_callback_E##N() { _lcd_autotune(heater_id_t(N)); } #else #define DEFINE_PIDTEMP_FUNCS(N) _DEFINE_PIDTEMP_BASE_FUNCS(N); #endif @@ -269,56 +276,70 @@ void menu_backlash(); // #if ENABLED(PID_EDIT_MENU) - #define __PID_BASE_MENU_ITEMS(N) \ - raw_Ki = unscalePID_i(TERN(PID_BED_MENU_SECTION, thermalManager.temp_bed.pid.Ki, PID_PARAM(Ki, N))); \ - raw_Kd = unscalePID_d(TERN(PID_BED_MENU_SECTION, thermalManager.temp_bed.pid.Kd, PID_PARAM(Kd, N))); \ - EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_P_E, &TERN(PID_BED_MENU_SECTION, thermalManager.temp_bed.pid.Kp, PID_PARAM(Kp, N)), 1, 9990); \ + #define _PID_EDIT_ITEMS_TMPL(N,T) \ + raw_Ki = unscalePID_i(T.pid.Ki); \ + raw_Kd = unscalePID_d(T.pid.Kd); \ + EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_P_E, &T.pid.Kp, 1, 9990); \ + EDIT_ITEM_FAST_N(float52sign, N, MSG_PID_I_E, &raw_Ki, 0.01f, 9990, []{ copy_and_scalePID_i(N); }); \ + EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_D_E, &raw_Kd, 1, 9990, []{ copy_and_scalePID_d(N); }) + + #define __PID_HOTEND_MENU_ITEMS(N) \ + raw_Ki = unscalePID_i(PID_PARAM(Ki, N)); \ + raw_Kd = unscalePID_d(PID_PARAM(Kd, N)); \ + EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_P_E, &PID_PARAM(Kp, N), 1, 9990); \ EDIT_ITEM_FAST_N(float52sign, N, MSG_PID_I_E, &raw_Ki, 0.01f, 9990, []{ copy_and_scalePID_i(N); }); \ EDIT_ITEM_FAST_N(float41sign, N, MSG_PID_D_E, &raw_Kd, 1, 9990, []{ copy_and_scalePID_d(N); }) #if ENABLED(PID_EXTRUSION_SCALING) - #define _PID_BASE_MENU_ITEMS(N) \ - __PID_BASE_MENU_ITEMS(N); \ + #define _PID_HOTEND_MENU_ITEMS(N) \ + __PID_HOTEND_MENU_ITEMS(N); \ EDIT_ITEM_N(float4, N, MSG_PID_C_E, &PID_PARAM(Kc, N), 1, 9990) #else - #define _PID_BASE_MENU_ITEMS(N) __PID_BASE_MENU_ITEMS(N) + #define _PID_HOTEND_MENU_ITEMS(N) __PID_HOTEND_MENU_ITEMS(N) #endif #if ENABLED(PID_FAN_SCALING) - #define _PID_EDIT_MENU_ITEMS(N) \ - _PID_BASE_MENU_ITEMS(N); \ + #define _HOTEND_PID_EDIT_MENU_ITEMS(N) \ + _PID_HOTEND_MENU_ITEMS(N); \ EDIT_ITEM_N(float4, N, MSG_PID_F_E, &PID_PARAM(Kf, N), 1, 9990) #else - #define _PID_EDIT_MENU_ITEMS(N) _PID_BASE_MENU_ITEMS(N) + #define _HOTEND_PID_EDIT_MENU_ITEMS(N) _PID_HOTEND_MENU_ITEMS(N) #endif #else - #define _PID_EDIT_MENU_ITEMS(N) NOOP + #define _HOTEND_PID_EDIT_MENU_ITEMS(N) NOOP #endif #if ENABLED(PID_AUTOTUNE_MENU) - #define PID_EDIT_MENU_ITEMS(N) \ - _PID_EDIT_MENU_ITEMS(N); \ - EDIT_ITEM_FAST_N(int3, N, MSG_PID_AUTOTUNE_E, &autotune_temp[N], 150, thermalManager.heater_maxtemp[N] - HOTEND_OVERSHOOT, []{ _lcd_autotune(MenuItemBase::itemIndex); }); + #define HOTEND_PID_EDIT_MENU_ITEMS(N) \ + _HOTEND_PID_EDIT_MENU_ITEMS(N); \ + EDIT_ITEM_FAST_N(int3, N, MSG_PID_AUTOTUNE_E, &autotune_temp[N], 150, thermalManager.heater_maxtemp[N] - HOTEND_OVERSHOOT, []{ _lcd_autotune(heater_id_t(MenuItemBase::itemIndex)); }); #else - #define PID_EDIT_MENU_ITEMS(N) _PID_EDIT_MENU_ITEMS(N); + #define HOTEND_PID_EDIT_MENU_ITEMS(N) _HOTEND_PID_EDIT_MENU_ITEMS(N); #endif - PID_EDIT_MENU_ITEMS(0); + HOTEND_PID_EDIT_MENU_ITEMS(0); #if ENABLED(PID_PARAMS_PER_HOTEND) - REPEAT_S(1, HOTENDS, PID_EDIT_MENU_ITEMS) + REPEAT_S(1, HOTENDS, HOTEND_PID_EDIT_MENU_ITEMS) #endif #if ENABLED(PIDTEMPBED) #if ENABLED(PID_EDIT_MENU) - #define PID_BED_MENU_SECTION - __PID_BASE_MENU_ITEMS(-1); - #undef PID_BED_MENU_SECTION + _PID_EDIT_ITEMS_TMPL(H_BED, thermalManager.temp_bed); + #endif + #if ENABLED(PID_AUTOTUNE_MENU) + EDIT_ITEM_FAST_N(int3, H_BED, MSG_PID_AUTOTUNE_E, &autotune_temp_bed, PREHEAT_1_TEMP_BED, BED_MAX_TARGET, []{ _lcd_autotune(H_BED); }); + #endif + #endif + + #if ENABLED(PIDTEMPCHAMBER) + #if ENABLED(PID_EDIT_MENU) + _PID_EDIT_ITEMS_TMPL(H_CHAMBER, thermalManager.temp_chamber); #endif #if ENABLED(PID_AUTOTUNE_MENU) - EDIT_ITEM_FAST_N(int3, -1, MSG_PID_AUTOTUNE_E, &autotune_temp_bed, PREHEAT_1_TEMP_BED, BED_MAX_TARGET, []{ _lcd_autotune(-1); }); + EDIT_ITEM_FAST_N(int3, H_CHAMBER, MSG_PID_AUTOTUNE_E, &autotune_temp_chamber, PREHEAT_1_TEMP_CHAMBER, CHAMBER_MAX_TARGET, []{ _lcd_autotune(H_CHAMBER); }); #endif #endif diff --git a/Marlin/src/lcd/menu/menu_bed_corners.cpp b/Marlin/src/lcd/menu/menu_bed_corners.cpp index 751be18600f6..0dae8dbf41fc 100644 --- a/Marlin/src/lcd/menu/menu_bed_corners.cpp +++ b/Marlin/src/lcd/menu/menu_bed_corners.cpp @@ -224,7 +224,7 @@ static inline void _lcd_level_bed_corners_get_next_position() { bool _lcd_level_bed_corners_probe(bool verify=false) { if (verify) do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP); // do clearance if needed TERN_(BLTOUCH_SLOW_MODE, bltouch.deploy()); // Deploy in LOW SPEED MODE on every probe action - do_blocking_move_to_z(last_z - LEVEL_CORNERS_PROBE_TOLERANCE, MMM_TO_MMS(Z_PROBE_SPEED_SLOW)); // Move down to lower tolerance + do_blocking_move_to_z(last_z - LEVEL_CORNERS_PROBE_TOLERANCE, MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW)); // Move down to lower tolerance if (TEST(endstops.trigger_state(), TERN(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, Z_MIN, Z_MIN_PROBE))) { // check if probe triggered endstops.hit_on_purpose(); set_current_from_steppers_for_axis(Z_AXIS); @@ -269,12 +269,13 @@ static inline void _lcd_level_bed_corners_get_next_position() { do { ui.refresh(LCDVIEW_REDRAW_NOW); _lcd_draw_probing(); // update screen with # of good points - do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP); // clearance + do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP + TERN0(BLTOUCH_HS_MODE, 7)); // clearance _lcd_level_bed_corners_get_next_position(); // Select next corner coordinates current_position -= probe.offset_xy; // Account for probe offsets do_blocking_move_to_xy(current_position); // Goto corner + TERN_(BLTOUCH_HS_MODE, bltouch.deploy()); // Deploy in HIGH SPEED MODE if (!_lcd_level_bed_corners_probe()) { // Probe down to tolerance if (_lcd_level_bed_corners_raise()) { // Prompt user to raise bed if needed #if ENABLED(LEVEL_CORNERS_VERIFY_RAISED) // Verify @@ -295,6 +296,9 @@ static inline void _lcd_level_bed_corners_get_next_position() { } while (good_points < nr_edge_points); // loop until all points within tolerance + TERN_(BLTOUCH_HS_MODE, do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP)); // Do clearance in HIGH SPEED MODE at the very end + TERN_(BLTOUCH_HS_MODE, bltouch.stow()); // Stow in HIGH SPEED MODE at the very end + ui.goto_screen(_lcd_draw_level_prompt); // prompt for bed leveling ui.set_selection(true); } diff --git a/Marlin/src/lcd/menu/menu_led.cpp b/Marlin/src/lcd/menu/menu_led.cpp index de57502788d4..5ab5e8a9d8dc 100644 --- a/Marlin/src/lcd/menu/menu_led.cpp +++ b/Marlin/src/lcd/menu/menu_led.cpp @@ -105,12 +105,14 @@ #if ENABLED(CASE_LIGHT_MENU) #include "../../feature/caselight.h" + #define CASELIGHT_TOGGLE_ITEM() EDIT_ITEM(bool, MSG_CASE_LIGHT, (bool*)&caselight.on, caselight.update_enabled) + #if CASELIGHT_USES_BRIGHTNESS void menu_case_light() { START_MENU(); BACK_ITEM(MSG_CONFIGURATION); EDIT_ITEM(percent, MSG_CASE_LIGHT_BRIGHTNESS, &caselight.brightness, 0, 255, caselight.update_brightness, true); - EDIT_ITEM(bool, MSG_CASE_LIGHT, (bool*)&caselight.on, caselight.update_enabled); + CASELIGHT_TOGGLE_ITEM(); END_MENU(); } #endif @@ -155,13 +157,14 @@ void menu_led() { // Set Case light on/off/brightness // #if ENABLED(CASE_LIGHT_MENU) - #if DISABLED(CASE_LIGHT_NO_BRIGHTNESS) - if (TERN1(CASE_LIGHT_USE_NEOPIXEL, PWM_PIN(CASE_LIGHT_PIN))) + #if CASELIGHT_USES_BRIGHTNESS + if (caselight.has_brightness()) SUBMENU(MSG_CASE_LIGHT, menu_case_light); else #endif - EDIT_ITEM(bool, MSG_CASE_LIGHT, (bool*)&caselight.on, caselight.update_enabled); + CASELIGHT_TOGGLE_ITEM(); #endif + END_MENU(); } diff --git a/Marlin/src/lcd/menu/menu_main.cpp b/Marlin/src/lcd/menu/menu_main.cpp index 878ac83a5a32..1e864e35be0a 100644 --- a/Marlin/src/lcd/menu/menu_main.cpp +++ b/Marlin/src/lcd/menu/menu_main.cpp @@ -97,6 +97,10 @@ void menu_configuration(); void menu_spindle_laser(); #endif +#if ENABLED(PREHEAT_SHORTCUT_MENU_ITEM) + void menu_preheat_only(); +#endif + #if HAS_MULTI_LANGUAGE void menu_language(); #endif @@ -177,6 +181,10 @@ void menu_main() { ACTION_ITEM(MSG_HOST_START_PRINT, host_action_start); #endif + #if ENABLED(PREHEAT_SHORTCUT_MENU_ITEM) + SUBMENU(MSG_PREHEAT_CUSTOM, menu_preheat_only); + #endif + SUBMENU(MSG_MOTION, menu_motion); } diff --git a/Marlin/src/lcd/menu/menu_probe_offset.cpp b/Marlin/src/lcd/menu/menu_probe_offset.cpp index 2f0c37b4338f..3b3fa0fd2a3f 100644 --- a/Marlin/src/lcd/menu/menu_probe_offset.cpp +++ b/Marlin/src/lcd/menu/menu_probe_offset.cpp @@ -145,7 +145,7 @@ void prepare_for_probe_offset_wizard() { // Move Nozzle to Probing/Homing Position ui.wait_for_move = true; current_position += probe.offset_xy; - line_to_current_position(MMM_TO_MMS(XY_PROBE_SPEED)); + line_to_current_position(MMM_TO_MMS(XY_PROBE_FEEDRATE)); ui.synchronize(GET_TEXT(MSG_PROBE_WIZARD_MOVING)); ui.wait_for_move = false; diff --git a/Marlin/src/lcd/menu/menu_temperature.cpp b/Marlin/src/lcd/menu/menu_temperature.cpp index 01c1f8f5472f..f347efe6db80 100644 --- a/Marlin/src/lcd/menu/menu_temperature.cpp +++ b/Marlin/src/lcd/menu/menu_temperature.cpp @@ -226,7 +226,7 @@ void menu_temperature() { #if PREHEAT_COUNT // - // Preheat for Materials 1 to 5 + // Preheat for all Materials // LOOP_L_N(m, PREHEAT_COUNT) { editable.int8 = m; @@ -249,4 +249,24 @@ void menu_temperature() { END_MENU(); } +#if ENABLED(PREHEAT_SHORTCUT_MENU_ITEM) + + void menu_preheat_only() { + START_MENU(); + BACK_ITEM(MSG_MAIN); + + LOOP_L_N(m, PREHEAT_COUNT) { + editable.int8 = m; + #if HOTENDS > 1 || HAS_HEATED_BED + SUBMENU_S(ui.get_preheat_label(m), MSG_PREHEAT_M, menu_preheat_m); + #else + ACTION_ITEM_S(ui.get_preheat_label(m), MSG_PREHEAT_M, do_preheat_end_m); + #endif + } + + END_MENU(); + } + +#endif + #endif // HAS_LCD_MENU && HAS_TEMPERATURE diff --git a/Marlin/src/lcd/menu/menu_ubl.cpp b/Marlin/src/lcd/menu/menu_ubl.cpp index 95e64a0d82ff..79bedb9ea522 100644 --- a/Marlin/src/lcd/menu/menu_ubl.cpp +++ b/Marlin/src/lcd/menu/menu_ubl.cpp @@ -476,7 +476,7 @@ void ubl_map_screen() { if (position_is_reachable(xy)) break; // Found a valid point ui.encoderPosition += step_dir; // Test the next point #endif - } while(ENABLED(IS_KINEMATIC)); + } while (ENABLED(IS_KINEMATIC)); // Determine number of points to edit #if IS_KINEMATIC diff --git a/Marlin/src/libs/L64XX/L64XX_Marlin.cpp b/Marlin/src/libs/L64XX/L64XX_Marlin.cpp index 7d36a02d673f..d079e0b4b3e2 100644 --- a/Marlin/src/libs/L64XX/L64XX_Marlin.cpp +++ b/Marlin/src/libs/L64XX/L64XX_Marlin.cpp @@ -37,8 +37,6 @@ L64XX_Marlin L64xxManager; #include "../../module/planner.h" #include "../../HAL/shared/Delay.h" -void echo_yes_no(const bool yes) { serialprintPGM(yes ? PSTR(" YES") : PSTR(" NO ")); } - static const char str_X[] PROGMEM = "X ", str_Y[] PROGMEM = "Y ", str_Z[] PROGMEM = "Z ", str_X2[] PROGMEM = "X2", str_Y2[] PROGMEM = "Y2", str_Z2[] PROGMEM = "Z2", str_Z3[] PROGMEM = "Z3", str_Z4[] PROGMEM = "Z4", @@ -56,6 +54,8 @@ PGM_P const L64XX_Marlin::index_to_axis[] PROGMEM = { #define DEBUG_OUT ENABLED(L6470_CHITCHAT) #include "../../core/debug_out.h" +void echo_yes_no(const bool yes) { DEBUG_ECHOPGM_P(yes ? PSTR(" YES") : PSTR(" NO ")); UNUSED(yes); } + uint8_t L64XX_Marlin::dir_commands[MAX_L64XX]; // array to hold direction command for each driver const uint8_t L64XX_Marlin::index_to_dir[MAX_L64XX] = { @@ -375,7 +375,7 @@ inline void echo_min_max(const char a, const float &min, const float &max) { } inline void echo_oct_used(const float &oct, const uint8_t stall) { DEBUG_ECHOPAIR("over_current_threshold used : ", oct); - serialprintPGM(stall ? PSTR(" (Stall") : PSTR(" (OCD")); + DEBUG_ECHOPGM_P(stall ? PSTR(" (Stall") : PSTR(" (OCD")); DEBUG_ECHOLNPGM(" threshold)"); } inline void err_out_of_bounds() { DEBUG_ECHOLNPGM("Test aborted - motion out of bounds"); } @@ -446,10 +446,8 @@ uint8_t L64XX_Marlin::get_user_input(uint8_t &driver_count, L64XX_axis_t axis_in position_max = X_center + displacement; echo_min_max('X', position_min, position_max); if (false - #ifdef X_MIN_POS + #if HAS_ENDSTOPS || position_min < (X_MIN_POS) - #endif - #ifdef X_MAX_POS || position_max > (X_MAX_POS) #endif ) { @@ -463,10 +461,8 @@ uint8_t L64XX_Marlin::get_user_input(uint8_t &driver_count, L64XX_axis_t axis_in position_max = Y_center + displacement; echo_min_max('Y', position_min, position_max); if (false - #ifdef Y_MIN_POS + #if HAS_ENDSTOPS || position_min < (Y_MIN_POS) - #endif - #ifdef Y_MAX_POS || position_max > (Y_MAX_POS) #endif ) { @@ -480,10 +476,8 @@ uint8_t L64XX_Marlin::get_user_input(uint8_t &driver_count, L64XX_axis_t axis_in position_max = Z_center + displacement; echo_min_max('Z', position_min, position_max); if (false - #ifdef Z_MIN_POS + #if HAS_ENDSTOPS || position_min < (Z_MIN_POS) - #endif - #ifdef Z_MAX_POS || position_max > (Z_MAX_POS) #endif ) { @@ -658,7 +652,7 @@ void L64XX_Marlin::say_axis(const L64XX_axis_t axis, const uint8_t label/*=true* ) { say_axis(axis); DEBUG_ECHOPGM(" THERMAL: "); - serialprintPGM((status & _status_axis_th_sd) ? PSTR("SHUTDOWN") : (status & _status_axis_th_wrn) ? PSTR("WARNING ") : PSTR("OK ")); + DEBUG_ECHOPGM_P((status & _status_axis_th_sd) ? PSTR("SHUTDOWN") : (status & _status_axis_th_wrn) ? PSTR("WARNING ") : PSTR("OK ")); DEBUG_ECHOPGM(" OVERCURRENT: "); echo_yes_no((status & _status_axis_ocd) != 0); if (!(_status_axis_layout == L6474_STATUS_LAYOUT)) { // L6474 doesn't have these bits diff --git a/Marlin/src/libs/autoreport.h b/Marlin/src/libs/autoreport.h index 2c0a043fbf7b..232216578fb8 100644 --- a/Marlin/src/libs/autoreport.h +++ b/Marlin/src/libs/autoreport.h @@ -42,8 +42,9 @@ struct AutoReporter { const millis_t ms = millis(); if (ELAPSED(ms, next_report_ms)) { next_report_ms = ms + SEC_TO_MS(report_interval); - TERN_(HAS_MULTI_SERIAL, PORT_REDIRECT(report_port_mask)); + PORT_REDIRECT(report_port_mask); Helper::report(); + //PORT_RESTORE(); } } }; diff --git a/Marlin/src/libs/stopwatch.cpp b/Marlin/src/libs/stopwatch.cpp index 601efe55178f..adfaa3b043e5 100644 --- a/Marlin/src/libs/stopwatch.cpp +++ b/Marlin/src/libs/stopwatch.cpp @@ -98,7 +98,7 @@ millis_t Stopwatch::duration() { void Stopwatch::debug(const char func[]) { if (DEBUGGING(INFO)) { SERIAL_ECHOPGM("Stopwatch::"); - serialprintPGM(func); + SERIAL_ECHOPGM_P(func); SERIAL_ECHOLNPGM("()"); } } diff --git a/Marlin/src/libs/vector_3.cpp b/Marlin/src/libs/vector_3.cpp index 6f87a523e0ad..0ef29f33bd31 100644 --- a/Marlin/src/libs/vector_3.cpp +++ b/Marlin/src/libs/vector_3.cpp @@ -77,7 +77,7 @@ void vector_3::apply_rotation(const matrix_3x3 &matrix) { } void vector_3::debug(PGM_P const title) { - serialprintPGM(title); + SERIAL_ECHOPGM_P(title); SERIAL_ECHOPAIR_F_P(SP_X_STR, x, 6); SERIAL_ECHOPAIR_F_P(SP_Y_STR, y, 6); SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, z, 6); @@ -139,10 +139,7 @@ matrix_3x3 matrix_3x3::transpose(const matrix_3x3 &original) { } void matrix_3x3::debug(PGM_P const title) { - if (title) { - serialprintPGM(title); - SERIAL_EOL(); - } + if (title) SERIAL_ECHOLNPGM_P(title); LOOP_L_N(i, 3) { LOOP_L_N(j, 3) { if (vectors[i][j] >= 0.0) SERIAL_CHAR('+'); diff --git a/Marlin/src/module/delta.cpp b/Marlin/src/module/delta.cpp index 93238a69e364..a1676b3ba346 100644 --- a/Marlin/src/module/delta.cpp +++ b/Marlin/src/module/delta.cpp @@ -54,7 +54,7 @@ float delta_height; abc_float_t delta_endstop_adj{0}; float delta_radius, delta_diagonal_rod, - delta_segments_per_second; + segments_per_second; abc_float_t delta_tower_angle_trim; xy_float_t delta_tower[ABC]; abc_float_t delta_diagonal_rod_2_tower; @@ -177,7 +177,7 @@ float delta_safe_distance_from_top() { * * The result is stored in the cartes[] array. */ -void forward_kinematics_DELTA(const float &z1, const float &z2, const float &z3) { +void forward_kinematics(const float &z1, const float &z2, const float &z3) { // Create a vector in old coordinates along x axis of new coordinate const float p12[3] = { delta_tower[B_AXIS].x - delta_tower[A_AXIS].x, delta_tower[B_AXIS].y - delta_tower[A_AXIS].y, z2 - z1 }, @@ -242,9 +242,9 @@ void home_delta() { // Disable stealthChop if used. Enable diag1 pin on driver. #if ENABLED(SENSORLESS_HOMING) - TERN_(X_SENSORLESS, sensorless_t stealth_states_x = start_sensorless_homing_per_axis(X_AXIS)); - TERN_(Y_SENSORLESS, sensorless_t stealth_states_y = start_sensorless_homing_per_axis(Y_AXIS)); - TERN_(Z_SENSORLESS, sensorless_t stealth_states_z = start_sensorless_homing_per_axis(Z_AXIS)); + TERN_(X_SENSORLESS, sensorless_t stealth_states_x = start_sensorless_homing_per_axis(X_AXIS)); + TERN_(Y_SENSORLESS, sensorless_t stealth_states_y = start_sensorless_homing_per_axis(Y_AXIS)); + TERN_(Z_SENSORLESS, sensorless_t stealth_states_z = start_sensorless_homing_per_axis(Z_AXIS)); #endif // Move all carriages together linearly until an endstop is hit. @@ -254,9 +254,9 @@ void home_delta() { // Re-enable stealthChop if used. Disable diag1 pin on driver. #if ENABLED(SENSORLESS_HOMING) - TERN_(X_SENSORLESS, end_sensorless_homing_per_axis(X_AXIS, stealth_states_x)); - TERN_(Y_SENSORLESS, end_sensorless_homing_per_axis(Y_AXIS, stealth_states_y)); - TERN_(Z_SENSORLESS, end_sensorless_homing_per_axis(Z_AXIS, stealth_states_z)); + TERN_(X_SENSORLESS, end_sensorless_homing_per_axis(X_AXIS, stealth_states_x)); + TERN_(Y_SENSORLESS, end_sensorless_homing_per_axis(Y_AXIS, stealth_states_y)); + TERN_(Z_SENSORLESS, end_sensorless_homing_per_axis(Z_AXIS, stealth_states_z)); #endif endstops.validate_homing_move(); diff --git a/Marlin/src/module/delta.h b/Marlin/src/module/delta.h index 5e9a78bd8672..9caec530288a 100644 --- a/Marlin/src/module/delta.h +++ b/Marlin/src/module/delta.h @@ -32,7 +32,7 @@ extern float delta_height; extern abc_float_t delta_endstop_adj; extern float delta_radius, delta_diagonal_rod, - delta_segments_per_second; + segments_per_second; extern abc_float_t delta_tower_angle_trim; extern xy_float_t delta_tower[ABC]; extern abc_float_t delta_diagonal_rod_2_tower; @@ -120,10 +120,10 @@ float delta_safe_distance_from_top(); * * The result is stored in the cartes[] array. */ -void forward_kinematics_DELTA(const float &z1, const float &z2, const float &z3); +void forward_kinematics(const float &z1, const float &z2, const float &z3); -FORCE_INLINE void forward_kinematics_DELTA(const abc_float_t &point) { - forward_kinematics_DELTA(point.a, point.b, point.c); +FORCE_INLINE void forward_kinematics(const abc_float_t &point) { + forward_kinematics(point.a, point.b, point.c); } void home_delta(); diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index b9d2c1cdf561..4192b444bb9e 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -405,10 +405,9 @@ void Endstops::event_handler() { } static void print_es_state(const bool is_hit, PGM_P const label=nullptr) { - if (label) serialprintPGM(label); + if (label) SERIAL_ECHOPGM_P(label); SERIAL_ECHOPGM(": "); - serialprintPGM(is_hit ? PSTR(STR_ENDSTOP_HIT) : PSTR(STR_ENDSTOP_OPEN)); - SERIAL_EOL(); + SERIAL_ECHOLNPGM_P(is_hit ? PSTR(STR_ENDSTOP_HIT) : PSTR(STR_ENDSTOP_OPEN)); } void _O2 Endstops::report_states() { @@ -469,24 +468,22 @@ void _O2 Endstops::report_states() { #if HAS_CUSTOM_PROBE_PIN print_es_state(PROBE_TRIGGERED(), PSTR(STR_Z_PROBE)); #endif - #if HAS_FILAMENT_SENSOR - #if NUM_RUNOUT_SENSORS == 1 - print_es_state(READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE, PSTR(STR_FILAMENT_RUNOUT_SENSOR)); - #else - #define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; state = FIL_RUNOUT##N##_STATE; break; - LOOP_S_LE_N(i, 1, NUM_RUNOUT_SENSORS) { - pin_t pin; - uint8_t state; - switch (i) { - default: continue; - REPEAT_S(1, INCREMENT(NUM_RUNOUT_SENSORS), _CASE_RUNOUT) - } - SERIAL_ECHOPGM(STR_FILAMENT_RUNOUT_SENSOR); - if (i > 1) SERIAL_CHAR(' ', '0' + i); - print_es_state(extDigitalRead(pin) != state); + #if MULTI_FILAMENT_SENSOR + #define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; state = FIL_RUNOUT##N##_STATE; break; + LOOP_S_LE_N(i, 1, NUM_RUNOUT_SENSORS) { + pin_t pin; + uint8_t state; + switch (i) { + default: continue; + REPEAT_S(1, INCREMENT(NUM_RUNOUT_SENSORS), _CASE_RUNOUT) } - #undef _CASE_RUNOUT - #endif + SERIAL_ECHOPGM(STR_FILAMENT_RUNOUT_SENSOR); + if (i > 1) SERIAL_CHAR(' ', '0' + i); + print_es_state(extDigitalRead(pin) != state); + } + #undef _CASE_RUNOUT + #elif HAS_FILAMENT_SENSOR + print_es_state(READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE, PSTR(STR_FILAMENT_RUNOUT_SENSOR)); #endif TERN_(BLTOUCH, bltouch._reset_SW_mode()); diff --git a/Marlin/src/module/endstops.h b/Marlin/src/module/endstops.h index 05936a6bf34d..c0cc9cdb8eea 100644 --- a/Marlin/src/module/endstops.h +++ b/Marlin/src/module/endstops.h @@ -38,7 +38,7 @@ enum EndstopEnum : char { Z4_MIN, Z4_MAX }; -#define X_ENDSTOP (X_HOME_DIR < 0 ? X_MIN : X_MAX) +#define X_ENDSTOP (x_home_dir(active_extruder) < 0 ? X_MIN : X_MAX) #define Y_ENDSTOP (Y_HOME_DIR < 0 ? Y_MIN : Y_MAX) #define Z_ENDSTOP (Z_HOME_DIR < 0 ? TERN(HOMING_Z_WITH_PROBE, Z_MIN, Z_MIN_PROBE) : Z_MAX) diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 8dc84c33d69d..2f4f5e283a34 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -74,17 +74,6 @@ #define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE) #include "../core/debug_out.h" -/** - * axis_homed - * Flags that each linear axis was homed. - * XYZ on cartesian, ABC on delta, ABZ on SCARA. - * - * axis_trusted - * Flags that the position is trusted in each linear axis. Set when homed. - * Cleared whenever a stepper powers off, potentially losing its position. - */ -uint8_t axis_homed, axis_trusted; // = 0 - // Relative Mode. Enable with G91, disable with G90. bool relative_mode; // = false; @@ -94,7 +83,13 @@ bool relative_mode; // = false; * Used by 'line_to_current_position' to do a move after changing it. * Used by 'sync_plan_position' to update 'planner.position'. */ -xyze_pos_t current_position = { X_HOME_POS, Y_HOME_POS, Z_HOME_POS }; +xyze_pos_t current_position = { X_HOME_POS, Y_HOME_POS, + #ifdef Z_IDLE_HEIGHT + Z_IDLE_HEIGHT + #else + Z_HOME_POS + #endif +}; /** * Cartesian Destination @@ -185,7 +180,7 @@ xyz_pos_t cartes; #endif #if HAS_ABL_NOT_UBL - feedRate_t xy_probe_feedrate_mm_s = MMM_TO_MMS(XY_PROBE_SPEED); + feedRate_t xy_probe_feedrate_mm_s = MMM_TO_MMS(XY_PROBE_FEEDRATE); #endif /** @@ -268,15 +263,19 @@ void sync_plan_position_e() { planner.set_e_position_mm(current_position.e); } */ void get_cartesian_from_steppers() { #if ENABLED(DELTA) - forward_kinematics_DELTA(planner.get_axis_positions_mm()); + forward_kinematics(planner.get_axis_positions_mm()); #else #if IS_SCARA - forward_kinematics_SCARA( - planner.get_axis_position_degrees(A_AXIS), - planner.get_axis_position_degrees(B_AXIS) + forward_kinematics( + planner.get_axis_position_degrees(A_AXIS) + , planner.get_axis_position_degrees(B_AXIS) + #if ENABLED(AXEL_TPARA) + , planner.get_axis_position_degrees(C_AXIS) + #endif ); #else - cartes.set(planner.get_axis_position_mm(X_AXIS), planner.get_axis_position_mm(Y_AXIS)); + cartes.x = planner.get_axis_position_mm(X_AXIS); + cartes.y = planner.get_axis_position_mm(Y_AXIS); #endif cartes.z = planner.get_axis_position_mm(Z_AXIS); #endif @@ -505,9 +504,8 @@ void do_blocking_move_to_xy_z(const xy_pos_t &raw, const float &z, const feedRat do_blocking_move_to(raw.x, raw.y, z, fr_mm_s); } -void do_z_clearance(const float &zclear, const bool z_trusted/*=true*/, const bool raise_on_untrusted/*=true*/, const bool lower_allowed/*=false*/) { - const bool rel = raise_on_untrusted && !z_trusted; - float zdest = zclear + (rel ? current_position.z : 0.0f); +void do_z_clearance(const float &zclear, const bool lower_allowed/*=false*/) { + float zdest = zclear; if (!lower_allowed) NOLESS(zdest, current_position.z); do_blocking_move_to_z(_MIN(zdest, Z_MAX_POS), TERN(HAS_BED_PROBE, z_probe_fast_mm_s, homing_feedrate(Z_AXIS))); } @@ -765,7 +763,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) { // The number of segments-per-second times the duration // gives the number of segments - uint16_t segments = delta_segments_per_second * seconds; + uint16_t segments = segments_per_second * seconds; // For SCARA enforce a minimum segment size #if IS_SCARA @@ -951,7 +949,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) { float x_home_pos(const uint8_t extruder) { if (extruder == 0) - return base_home_pos(X_AXIS); + return X_HOME_POS; else /** * In dual carriage mode the extruder offset provides an override of the @@ -1122,760 +1120,774 @@ void prepare_line_to_destination() { current_position = destination; } -uint8_t axes_should_home(uint8_t axis_bits/*=0x07*/) { - #define SHOULD_HOME(A) TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(A) - // Clear test bits that are trusted - if (TEST(axis_bits, X_AXIS) && SHOULD_HOME(X_AXIS)) CBI(axis_bits, X_AXIS); - if (TEST(axis_bits, Y_AXIS) && SHOULD_HOME(Y_AXIS)) CBI(axis_bits, Y_AXIS); - if (TEST(axis_bits, Z_AXIS) && SHOULD_HOME(Z_AXIS)) CBI(axis_bits, Z_AXIS); - return axis_bits; -} +#if HAS_ENDSTOPS -bool homing_needed_error(uint8_t axis_bits/*=0x07*/) { - if ((axis_bits = axes_should_home(axis_bits))) { - PGM_P home_first = GET_TEXT(MSG_HOME_FIRST); - char msg[strlen_P(home_first)+1]; - sprintf_P(msg, home_first, - TEST(axis_bits, X_AXIS) ? "X" : "", - TEST(axis_bits, Y_AXIS) ? "Y" : "", - TEST(axis_bits, Z_AXIS) ? "Z" : "" - ); - SERIAL_ECHO_START(); - SERIAL_ECHOLN(msg); - TERN_(HAS_DISPLAY, ui.set_status(msg)); - return true; + uint8_t axis_homed, axis_trusted; // = 0 + + uint8_t axes_should_home(uint8_t axis_bits/*=0x07*/) { + #define SHOULD_HOME(A) TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(A) + // Clear test bits that are trusted + if (TEST(axis_bits, X_AXIS) && SHOULD_HOME(X_AXIS)) CBI(axis_bits, X_AXIS); + if (TEST(axis_bits, Y_AXIS) && SHOULD_HOME(Y_AXIS)) CBI(axis_bits, Y_AXIS); + if (TEST(axis_bits, Z_AXIS) && SHOULD_HOME(Z_AXIS)) CBI(axis_bits, Z_AXIS); + return axis_bits; } - return false; -} -/** - * Homing bump feedrate (mm/s) - */ -feedRate_t get_homing_bump_feedrate(const AxisEnum axis) { - #if HOMING_Z_WITH_PROBE - if (axis == Z_AXIS) return MMM_TO_MMS(Z_PROBE_SPEED_SLOW); - #endif - static const uint8_t homing_bump_divisor[] PROGMEM = HOMING_BUMP_DIVISOR; - uint8_t hbd = pgm_read_byte(&homing_bump_divisor[axis]); - if (hbd < 1) { - hbd = 10; - SERIAL_ECHO_MSG("Warning: Homing Bump Divisor < 1"); + bool homing_needed_error(uint8_t axis_bits/*=0x07*/) { + if ((axis_bits = axes_should_home(axis_bits))) { + PGM_P home_first = GET_TEXT(MSG_HOME_FIRST); + char msg[strlen_P(home_first)+1]; + sprintf_P(msg, home_first, + TEST(axis_bits, X_AXIS) ? "X" : "", + TEST(axis_bits, Y_AXIS) ? "Y" : "", + TEST(axis_bits, Z_AXIS) ? "Z" : "" + ); + SERIAL_ECHO_START(); + SERIAL_ECHOLN(msg); + TERN_(HAS_DISPLAY, ui.set_status(msg)); + return true; + } + return false; } - return homing_feedrate(axis) / float(hbd); -} -#if ENABLED(SENSORLESS_HOMING) /** - * Set sensorless homing if the axis has it, accounting for Core Kinematics. + * Homing bump feedrate (mm/s) */ - sensorless_t start_sensorless_homing_per_axis(const AxisEnum axis) { - sensorless_t stealth_states { false }; - - switch (axis) { - default: break; - #if X_SENSORLESS - case X_AXIS: - stealth_states.x = tmc_enable_stallguard(stepperX); - #if AXIS_HAS_STALLGUARD(X2) - stealth_states.x2 = tmc_enable_stallguard(stepperX2); - #endif - #if EITHER(CORE_IS_XY, MARKFORGED_XY) && Y_SENSORLESS - stealth_states.y = tmc_enable_stallguard(stepperY); - #elif CORE_IS_XZ && Z_SENSORLESS - stealth_states.z = tmc_enable_stallguard(stepperZ); - #endif - break; - #endif - #if Y_SENSORLESS - case Y_AXIS: - stealth_states.y = tmc_enable_stallguard(stepperY); - #if AXIS_HAS_STALLGUARD(Y2) - stealth_states.y2 = tmc_enable_stallguard(stepperY2); - #endif - #if EITHER(CORE_IS_XY, MARKFORGED_XY) && X_SENSORLESS - stealth_states.x = tmc_enable_stallguard(stepperX); - #elif CORE_IS_YZ && Z_SENSORLESS - stealth_states.z = tmc_enable_stallguard(stepperZ); - #endif - break; - #endif - #if Z_SENSORLESS - case Z_AXIS: - stealth_states.z = tmc_enable_stallguard(stepperZ); - #if AXIS_HAS_STALLGUARD(Z2) - stealth_states.z2 = tmc_enable_stallguard(stepperZ2); - #endif - #if AXIS_HAS_STALLGUARD(Z3) - stealth_states.z3 = tmc_enable_stallguard(stepperZ3); - #endif - #if AXIS_HAS_STALLGUARD(Z4) - stealth_states.z4 = tmc_enable_stallguard(stepperZ4); - #endif - #if CORE_IS_XZ && X_SENSORLESS - stealth_states.x = tmc_enable_stallguard(stepperX); - #elif CORE_IS_YZ && Y_SENSORLESS - stealth_states.y = tmc_enable_stallguard(stepperY); - #endif - break; - #endif + feedRate_t get_homing_bump_feedrate(const AxisEnum axis) { + #if HOMING_Z_WITH_PROBE + if (axis == Z_AXIS) return MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW); + #endif + static const uint8_t homing_bump_divisor[] PROGMEM = HOMING_BUMP_DIVISOR; + uint8_t hbd = pgm_read_byte(&homing_bump_divisor[axis]); + if (hbd < 1) { + hbd = 10; + SERIAL_ECHO_MSG("Warning: Homing Bump Divisor < 1"); } + return homing_feedrate(axis) / float(hbd); + } + + #if ENABLED(SENSORLESS_HOMING) + /** + * Set sensorless homing if the axis has it, accounting for Core Kinematics. + */ + sensorless_t start_sensorless_homing_per_axis(const AxisEnum axis) { + sensorless_t stealth_states { false }; - #if ENABLED(SPI_ENDSTOPS) switch (axis) { - case X_AXIS: if (ENABLED(X_SPI_SENSORLESS)) endstops.tmc_spi_homing.x = true; break; - case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = true; break; - case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = true; break; default: break; + #if X_SENSORLESS + case X_AXIS: + stealth_states.x = tmc_enable_stallguard(stepperX); + #if AXIS_HAS_STALLGUARD(X2) + stealth_states.x2 = tmc_enable_stallguard(stepperX2); + #endif + #if EITHER(CORE_IS_XY, MARKFORGED_XY) && Y_SENSORLESS + stealth_states.y = tmc_enable_stallguard(stepperY); + #elif CORE_IS_XZ && Z_SENSORLESS + stealth_states.z = tmc_enable_stallguard(stepperZ); + #endif + break; + #endif + #if Y_SENSORLESS + case Y_AXIS: + stealth_states.y = tmc_enable_stallguard(stepperY); + #if AXIS_HAS_STALLGUARD(Y2) + stealth_states.y2 = tmc_enable_stallguard(stepperY2); + #endif + #if EITHER(CORE_IS_XY, MARKFORGED_XY) && X_SENSORLESS + stealth_states.x = tmc_enable_stallguard(stepperX); + #elif CORE_IS_YZ && Z_SENSORLESS + stealth_states.z = tmc_enable_stallguard(stepperZ); + #endif + break; + #endif + #if Z_SENSORLESS + case Z_AXIS: + stealth_states.z = tmc_enable_stallguard(stepperZ); + #if AXIS_HAS_STALLGUARD(Z2) + stealth_states.z2 = tmc_enable_stallguard(stepperZ2); + #endif + #if AXIS_HAS_STALLGUARD(Z3) + stealth_states.z3 = tmc_enable_stallguard(stepperZ3); + #endif + #if AXIS_HAS_STALLGUARD(Z4) + stealth_states.z4 = tmc_enable_stallguard(stepperZ4); + #endif + #if CORE_IS_XZ && X_SENSORLESS + stealth_states.x = tmc_enable_stallguard(stepperX); + #elif CORE_IS_YZ && Y_SENSORLESS + stealth_states.y = tmc_enable_stallguard(stepperY); + #endif + break; + #endif } - #endif - TERN_(IMPROVE_HOMING_RELIABILITY, sg_guard_period = millis() + default_sg_guard_duration); + #if ENABLED(SPI_ENDSTOPS) + switch (axis) { + case X_AXIS: if (ENABLED(X_SPI_SENSORLESS)) endstops.tmc_spi_homing.x = true; break; + case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = true; break; + case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = true; break; + default: break; + } + #endif - return stealth_states; - } + TERN_(IMPROVE_HOMING_RELIABILITY, sg_guard_period = millis() + default_sg_guard_duration); - void end_sensorless_homing_per_axis(const AxisEnum axis, sensorless_t enable_stealth) { - switch (axis) { - default: break; - #if X_SENSORLESS - case X_AXIS: - tmc_disable_stallguard(stepperX, enable_stealth.x); - #if AXIS_HAS_STALLGUARD(X2) - tmc_disable_stallguard(stepperX2, enable_stealth.x2); - #endif - #if EITHER(CORE_IS_XY, MARKFORGED_XY) && Y_SENSORLESS - tmc_disable_stallguard(stepperY, enable_stealth.y); - #elif CORE_IS_XZ && Z_SENSORLESS - tmc_disable_stallguard(stepperZ, enable_stealth.z); - #endif - break; - #endif - #if Y_SENSORLESS - case Y_AXIS: - tmc_disable_stallguard(stepperY, enable_stealth.y); - #if AXIS_HAS_STALLGUARD(Y2) - tmc_disable_stallguard(stepperY2, enable_stealth.y2); - #endif - #if EITHER(CORE_IS_XY, MARKFORGED_XY) && X_SENSORLESS - tmc_disable_stallguard(stepperX, enable_stealth.x); - #elif CORE_IS_YZ && Z_SENSORLESS - tmc_disable_stallguard(stepperZ, enable_stealth.z); - #endif - break; - #endif - #if Z_SENSORLESS - case Z_AXIS: - tmc_disable_stallguard(stepperZ, enable_stealth.z); - #if AXIS_HAS_STALLGUARD(Z2) - tmc_disable_stallguard(stepperZ2, enable_stealth.z2); - #endif - #if AXIS_HAS_STALLGUARD(Z3) - tmc_disable_stallguard(stepperZ3, enable_stealth.z3); - #endif - #if AXIS_HAS_STALLGUARD(Z4) - tmc_disable_stallguard(stepperZ4, enable_stealth.z4); - #endif - #if CORE_IS_XZ && X_SENSORLESS - tmc_disable_stallguard(stepperX, enable_stealth.x); - #elif CORE_IS_YZ && Y_SENSORLESS - tmc_disable_stallguard(stepperY, enable_stealth.y); - #endif - break; - #endif + return stealth_states; } - #if ENABLED(SPI_ENDSTOPS) + void end_sensorless_homing_per_axis(const AxisEnum axis, sensorless_t enable_stealth) { switch (axis) { - case X_AXIS: if (ENABLED(X_SPI_SENSORLESS)) endstops.tmc_spi_homing.x = false; break; - case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = false; break; - case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = false; break; default: break; + #if X_SENSORLESS + case X_AXIS: + tmc_disable_stallguard(stepperX, enable_stealth.x); + #if AXIS_HAS_STALLGUARD(X2) + tmc_disable_stallguard(stepperX2, enable_stealth.x2); + #endif + #if EITHER(CORE_IS_XY, MARKFORGED_XY) && Y_SENSORLESS + tmc_disable_stallguard(stepperY, enable_stealth.y); + #elif CORE_IS_XZ && Z_SENSORLESS + tmc_disable_stallguard(stepperZ, enable_stealth.z); + #endif + break; + #endif + #if Y_SENSORLESS + case Y_AXIS: + tmc_disable_stallguard(stepperY, enable_stealth.y); + #if AXIS_HAS_STALLGUARD(Y2) + tmc_disable_stallguard(stepperY2, enable_stealth.y2); + #endif + #if EITHER(CORE_IS_XY, MARKFORGED_XY) && X_SENSORLESS + tmc_disable_stallguard(stepperX, enable_stealth.x); + #elif CORE_IS_YZ && Z_SENSORLESS + tmc_disable_stallguard(stepperZ, enable_stealth.z); + #endif + break; + #endif + #if Z_SENSORLESS + case Z_AXIS: + tmc_disable_stallguard(stepperZ, enable_stealth.z); + #if AXIS_HAS_STALLGUARD(Z2) + tmc_disable_stallguard(stepperZ2, enable_stealth.z2); + #endif + #if AXIS_HAS_STALLGUARD(Z3) + tmc_disable_stallguard(stepperZ3, enable_stealth.z3); + #endif + #if AXIS_HAS_STALLGUARD(Z4) + tmc_disable_stallguard(stepperZ4, enable_stealth.z4); + #endif + #if CORE_IS_XZ && X_SENSORLESS + tmc_disable_stallguard(stepperX, enable_stealth.x); + #elif CORE_IS_YZ && Y_SENSORLESS + tmc_disable_stallguard(stepperY, enable_stealth.y); + #endif + break; + #endif } - #endif - } -#endif // SENSORLESS_HOMING - -/** - * Home an individual linear axis - */ -void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t fr_mm_s=0.0, const bool final_approach=true) { - DEBUG_SECTION(log_move, "do_homing_move", DEBUGGING(LEVELING)); - - const feedRate_t home_fr_mm_s = fr_mm_s ?: homing_feedrate(axis); - - if (DEBUGGING(LEVELING)) { - DEBUG_ECHOPAIR("...(", AS_CHAR(axis_codes[axis]), ", ", distance, ", "); - if (fr_mm_s) - DEBUG_ECHO(fr_mm_s); - else - DEBUG_ECHOPAIR("[", home_fr_mm_s, "]"); - DEBUG_ECHOLNPGM(")"); - } - - // Only do some things when moving towards an endstop - const int8_t axis_home_dir = TERN0(DUAL_X_CARRIAGE, axis == X_AXIS) - ? x_home_dir(active_extruder) : home_dir(axis); - const bool is_home_dir = (axis_home_dir > 0) == (distance > 0); - - #if ENABLED(SENSORLESS_HOMING) - sensorless_t stealth_states; - #endif - - if (is_home_dir) { - - if (TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS)) { - #if ALL(HAS_HEATED_BED, WAIT_FOR_BED_HEATER) - // Wait for bed to heat back up between probing points - thermalManager.wait_for_bed_heating(); + #if ENABLED(SPI_ENDSTOPS) + switch (axis) { + case X_AXIS: if (ENABLED(X_SPI_SENSORLESS)) endstops.tmc_spi_homing.x = false; break; + case Y_AXIS: if (ENABLED(Y_SPI_SENSORLESS)) endstops.tmc_spi_homing.y = false; break; + case Z_AXIS: if (ENABLED(Z_SPI_SENSORLESS)) endstops.tmc_spi_homing.z = false; break; + default: break; + } #endif - - TERN_(HAS_QUIET_PROBING, if (final_approach) probe.set_probing_paused(true)); } - // Disable stealthChop if used. Enable diag1 pin on driver. - TERN_(SENSORLESS_HOMING, stealth_states = start_sensorless_homing_per_axis(axis)); - } - - #if IS_SCARA - // Tell the planner the axis is at 0 - current_position[axis] = 0; - sync_plan_position(); - current_position[axis] = distance; - line_to_current_position(home_fr_mm_s); - #else - // Get the ABC or XYZ positions in mm - abce_pos_t target = planner.get_axis_positions_mm(); + #endif // SENSORLESS_HOMING - target[axis] = 0; // Set the single homing axis to 0 - planner.set_machine_position_mm(target); // Update the machine position + /** + * Home an individual linear axis + */ + void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t fr_mm_s=0.0, const bool final_approach=true) { + DEBUG_SECTION(log_move, "do_homing_move", DEBUGGING(LEVELING)); - #if HAS_DIST_MM_ARG - const xyze_float_t cart_dist_mm{0}; - #endif + const feedRate_t home_fr_mm_s = fr_mm_s ?: homing_feedrate(axis); - // Set delta/cartesian axes directly - target[axis] = distance; // The move will be towards the endstop - planner.buffer_segment(target - #if HAS_DIST_MM_ARG - , cart_dist_mm - #endif - , home_fr_mm_s, active_extruder - ); - #endif - - planner.synchronize(); + if (DEBUGGING(LEVELING)) { + DEBUG_ECHOPAIR("...(", AS_CHAR(axis_codes[axis]), ", ", distance, ", "); + if (fr_mm_s) + DEBUG_ECHO(fr_mm_s); + else + DEBUG_ECHOPAIR("[", home_fr_mm_s, "]"); + DEBUG_ECHOLNPGM(")"); + } - if (is_home_dir) { + // Only do some things when moving towards an endstop + const int8_t axis_home_dir = TERN0(DUAL_X_CARRIAGE, axis == X_AXIS) + ? x_home_dir(active_extruder) : home_dir(axis); + const bool is_home_dir = (axis_home_dir > 0) == (distance > 0); - #if HOMING_Z_WITH_PROBE && HAS_QUIET_PROBING - if (axis == Z_AXIS && final_approach) probe.set_probing_paused(false); + #if ENABLED(SENSORLESS_HOMING) + sensorless_t stealth_states; #endif - endstops.validate_homing_move(); + if (is_home_dir) { - // Re-enable stealthChop if used. Disable diag1 pin on driver. - TERN_(SENSORLESS_HOMING, end_sensorless_homing_per_axis(axis, stealth_states)); - } -} + if (TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS)) { + #if BOTH(HAS_HEATED_BED, WAIT_FOR_BED_HEATER) + // Wait for bed to heat back up between probing points + thermalManager.wait_for_bed_heating(); + #endif -/** - * Set an axis' current position to its home position (after homing). - * - * For Core and Cartesian robots this applies one-to-one when an - * individual axis has been homed. - * - * DELTA should wait until all homing is done before setting the XYZ - * current_position to home, because homing is a single operation. - * In the case where the axis positions are trusted and previously - * homed, DELTA could home to X or Y individually by moving either one - * to the center. However, homing Z always homes XY and Z. - * - * SCARA should wait until all XY homing is done before setting the XY - * current_position to home, because neither X nor Y is at home until - * both are at home. Z can however be homed individually. - * - * Callers must sync the planner position after calling this! - */ -void set_axis_is_at_home(const AxisEnum axis) { - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> set_axis_is_at_home(", AS_CHAR(axis_codes[axis]), ")"); + #if BOTH(HAS_HOTEND, WAIT_FOR_HOTEND) + // Wait for the hotend to heat back up between probing points + thermalManager.wait_for_hotend_heating(active_extruder); + #endif - set_axis_trusted(axis); - set_axis_homed(axis); + TERN_(HAS_QUIET_PROBING, if (final_approach) probe.set_probing_paused(true)); + } - #if ENABLED(DUAL_X_CARRIAGE) - if (axis == X_AXIS && (active_extruder == 1 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) { - current_position.x = x_home_pos(active_extruder); - return; + // Disable stealthChop if used. Enable diag1 pin on driver. + TERN_(SENSORLESS_HOMING, stealth_states = start_sensorless_homing_per_axis(axis)); } - #endif - #if ENABLED(MORGAN_SCARA) - scara_set_axis_is_at_home(axis); - #elif ENABLED(DELTA) - current_position[axis] = (axis == Z_AXIS) ? delta_height - TERN0(HAS_BED_PROBE, probe.offset.z) : base_home_pos(axis); - #else - current_position[axis] = base_home_pos(axis); - #endif + #if EITHER(MORGAN_SCARA, MP_SCARA) + // Tell the planner the axis is at 0 + current_position[axis] = 0; + sync_plan_position(); + current_position[axis] = distance; + line_to_current_position(home_fr_mm_s); + #else + // Get the ABC or XYZ positions in mm + abce_pos_t target = planner.get_axis_positions_mm(); - /** - * Z Probe Z Homing? Account for the probe's Z offset. - */ - #if HAS_BED_PROBE && Z_HOME_DIR < 0 - if (axis == Z_AXIS) { - #if HOMING_Z_WITH_PROBE + target[axis] = 0; // Set the single homing axis to 0 + planner.set_machine_position_mm(target); // Update the machine position - current_position.z -= probe.offset.z; + #if HAS_DIST_MM_ARG + const xyze_float_t cart_dist_mm{0}; + #endif - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> probe.offset.z = ", probe.offset.z); + // Set delta/cartesian axes directly + target[axis] = distance; // The move will be towards the endstop + planner.buffer_segment(target + #if HAS_DIST_MM_ARG + , cart_dist_mm + #endif + , home_fr_mm_s, active_extruder + ); + #endif - #else + planner.synchronize(); - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z HOMED TO ENDSTOP ***"); + if (is_home_dir) { + #if HOMING_Z_WITH_PROBE && HAS_QUIET_PROBING + if (axis == Z_AXIS && final_approach) probe.set_probing_paused(false); #endif - } - #endif - - TERN_(I2C_POSITION_ENCODERS, I2CPEM.homed(axis)); - - TERN_(BABYSTEP_DISPLAY_TOTAL, babystep.reset_total(axis)); - #if HAS_POSITION_SHIFT - position_shift[axis] = 0; - update_workspace_offset(axis); - #endif + endstops.validate_homing_move(); - if (DEBUGGING(LEVELING)) { - #if HAS_HOME_OFFSET - DEBUG_ECHOLNPAIR("> home_offset[", AS_CHAR(axis_codes[axis]), "] = ", home_offset[axis]); - #endif - DEBUG_POS("", current_position); - DEBUG_ECHOLNPAIR("<<< set_axis_is_at_home(", axis_codes[axis], ")"); + // Re-enable stealthChop if used. Disable diag1 pin on driver. + TERN_(SENSORLESS_HOMING, end_sensorless_homing_per_axis(axis, stealth_states)); + } } -} -/** - * Set an axis to be unhomed. - */ -void set_axis_never_homed(const AxisEnum axis) { - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> set_axis_never_homed(", axis_codes[axis], ")"); - - set_axis_untrusted(axis); - set_axis_unhomed(axis); - - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< set_axis_never_homed(", axis_codes[axis], ")"); - - TERN_(I2C_POSITION_ENCODERS, I2CPEM.unhomed(axis)); -} - -#ifdef TMC_HOME_PHASE /** - * Move the axis back to its home_phase if set and driver is capable (TMC) - * - * Improves homing repeatability by homing to stepper coil's nearest absolute - * phase position. Trinamic drivers use a stepper phase table with 1024 values - * spanning 4 full steps with 256 positions each (ergo, 1024 positions). + * Set an axis to be unhomed. (Unless we are on a machine - e.g. a cheap Chinese CNC machine - + * that has no endstops. Such machines should always be considered to be in a "known" and + * "trusted" position). */ - void backout_to_tmc_homing_phase(const AxisEnum axis) { - const xyz_long_t home_phase = TMC_HOME_PHASE; + void set_axis_never_homed(const AxisEnum axis) { + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> set_axis_never_homed(", axis_codes[axis], ")"); - // check if home phase is disabled for this axis. - if (home_phase[axis] < 0) return; + set_axis_untrusted(axis); + set_axis_unhomed(axis); - int16_t phasePerUStep, // TMC µsteps(phase) per Marlin µsteps - phaseCurrent, // The TMC µsteps(phase) count of the current position - effectorBackoutDir, // Direction in which the effector mm coordinates move away from endstop. - stepperBackoutDir; // Direction in which the TMC µstep count(phase) move away from endstop. + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< set_axis_never_homed(", axis_codes[axis], ")"); - #define PHASE_PER_MICROSTEP(N) (256 / _MAX(1, N##_MICROSTEPS)) + TERN_(I2C_POSITION_ENCODERS, I2CPEM.unhomed(axis)); + } - switch (axis) { - #ifdef X_MICROSTEPS - case X_AXIS: - phasePerUStep = PHASE_PER_MICROSTEP(X); - phaseCurrent = stepperX.get_microstep_counter(); - effectorBackoutDir = -X_HOME_DIR; - stepperBackoutDir = INVERT_X_DIR ? effectorBackoutDir : -effectorBackoutDir; - break; - #endif - #ifdef Y_MICROSTEPS - case Y_AXIS: - phasePerUStep = PHASE_PER_MICROSTEP(Y); - phaseCurrent = stepperY.get_microstep_counter(); - effectorBackoutDir = -Y_HOME_DIR; - stepperBackoutDir = INVERT_Y_DIR ? effectorBackoutDir : -effectorBackoutDir; - break; - #endif - #ifdef Z_MICROSTEPS - case Z_AXIS: - phasePerUStep = PHASE_PER_MICROSTEP(Z); - phaseCurrent = stepperZ.get_microstep_counter(); - effectorBackoutDir = -Z_HOME_DIR; - stepperBackoutDir = INVERT_Z_DIR ? effectorBackoutDir : -effectorBackoutDir; - break; - #endif - default: return; - } + #ifdef TMC_HOME_PHASE + /** + * Move the axis back to its home_phase if set and driver is capable (TMC) + * + * Improves homing repeatability by homing to stepper coil's nearest absolute + * phase position. Trinamic drivers use a stepper phase table with 1024 values + * spanning 4 full steps with 256 positions each (ergo, 1024 positions). + */ + void backout_to_tmc_homing_phase(const AxisEnum axis) { + const xyz_long_t home_phase = TMC_HOME_PHASE; - // Phase distance to nearest home phase position when moving in the backout direction from endstop(may be negative). - int16_t phaseDelta = (home_phase[axis] - phaseCurrent) * stepperBackoutDir; + // check if home phase is disabled for this axis. + if (home_phase[axis] < 0) return; - // Check if home distance within endstop assumed repeatability noise of .05mm and warn. - if (ABS(phaseDelta) * planner.steps_to_mm[axis] / phasePerUStep < 0.05f) - SERIAL_ECHOLNPAIR("Selected home phase ", home_phase[axis], - " too close to endstop trigger phase ", phaseCurrent, - ". Pick a different phase for ", axis_codes[axis]); + int16_t phasePerUStep, // TMC µsteps(phase) per Marlin µsteps + phaseCurrent, // The TMC µsteps(phase) count of the current position + effectorBackoutDir, // Direction in which the effector mm coordinates move away from endstop. + stepperBackoutDir; // Direction in which the TMC µstep count(phase) move away from endstop. - // Skip to next if target position is behind current. So it only moves away from endstop. - if (phaseDelta < 0) phaseDelta += 1024; + #define PHASE_PER_MICROSTEP(N) (256 / _MAX(1, N##_MICROSTEPS)) - // Convert TMC µsteps(phase) to whole Marlin µsteps to effector backout direction to mm - const float mmDelta = int16_t(phaseDelta / phasePerUStep) * effectorBackoutDir * planner.steps_to_mm[axis]; + switch (axis) { + #ifdef X_MICROSTEPS + case X_AXIS: + phasePerUStep = PHASE_PER_MICROSTEP(X); + phaseCurrent = stepperX.get_microstep_counter(); + effectorBackoutDir = -X_HOME_DIR; + stepperBackoutDir = INVERT_X_DIR ? effectorBackoutDir : -effectorBackoutDir; + break; + #endif + #ifdef Y_MICROSTEPS + case Y_AXIS: + phasePerUStep = PHASE_PER_MICROSTEP(Y); + phaseCurrent = stepperY.get_microstep_counter(); + effectorBackoutDir = -Y_HOME_DIR; + stepperBackoutDir = INVERT_Y_DIR ? effectorBackoutDir : -effectorBackoutDir; + break; + #endif + #ifdef Z_MICROSTEPS + case Z_AXIS: + phasePerUStep = PHASE_PER_MICROSTEP(Z); + phaseCurrent = stepperZ.get_microstep_counter(); + effectorBackoutDir = -Z_HOME_DIR; + stepperBackoutDir = INVERT_Z_DIR ? effectorBackoutDir : -effectorBackoutDir; + break; + #endif + default: return; + } - // Optional debug messages - if (DEBUGGING(LEVELING)) { - DEBUG_ECHOLNPAIR( - "Endstop ", axis_codes[axis], " hit at Phase:", phaseCurrent, - " Delta:", phaseDelta, " Distance:", mmDelta - ); - } + // Phase distance to nearest home phase position when moving in the backout direction from endstop(may be negative). + int16_t phaseDelta = (home_phase[axis] - phaseCurrent) * stepperBackoutDir; - if (mmDelta != 0) { - // Retrace by the amount computed in mmDelta. - do_homing_move(axis, mmDelta, get_homing_bump_feedrate(axis)); - } - } -#endif + // Check if home distance within endstop assumed repeatability noise of .05mm and warn. + if (ABS(phaseDelta) * planner.steps_to_mm[axis] / phasePerUStep < 0.05f) + SERIAL_ECHOLNPAIR("Selected home phase ", home_phase[axis], + " too close to endstop trigger phase ", phaseCurrent, + ". Pick a different phase for ", axis_codes[axis]); -/** - * Home an individual "raw axis" to its endstop. - * This applies to XYZ on Cartesian and Core robots, and - * to the individual ABC steppers on DELTA and SCARA. - * - * At the end of the procedure the axis is marked as - * homed and the current position of that axis is updated. - * Kinematic robots should wait till all axes are homed - * before updating the current position. - */ + // Skip to next if target position is behind current. So it only moves away from endstop. + if (phaseDelta < 0) phaseDelta += 1024; -void homeaxis(const AxisEnum axis) { + // Convert TMC µsteps(phase) to whole Marlin µsteps to effector backout direction to mm + const float mmDelta = int16_t(phaseDelta / phasePerUStep) * effectorBackoutDir * planner.steps_to_mm[axis]; - #if IS_SCARA - // Only Z homing (with probe) is permitted - if (axis != Z_AXIS) { BUZZ(100, 880); return; } - #else - #define _CAN_HOME(A) (axis == _AXIS(A) && ( \ - ENABLED(A##_SPI_SENSORLESS) \ - || (_AXIS(A) == Z_AXIS && ENABLED(HOMING_Z_WITH_PROBE)) \ - || (A##_MIN_PIN > -1 && A##_HOME_DIR < 0) \ - || (A##_MAX_PIN > -1 && A##_HOME_DIR > 0) \ - )) - if (!_CAN_HOME(X) && !_CAN_HOME(Y) && !_CAN_HOME(Z)) return; - #endif + // Optional debug messages + if (DEBUGGING(LEVELING)) { + DEBUG_ECHOLNPAIR( + "Endstop ", axis_codes[axis], " hit at Phase:", phaseCurrent, + " Delta:", phaseDelta, " Distance:", mmDelta + ); + } - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> homeaxis(", axis_codes[axis], ")"); - - const int axis_home_dir = TERN0(DUAL_X_CARRIAGE, axis == X_AXIS) - ? x_home_dir(active_extruder) : home_dir(axis); - - // - // Homing Z with a probe? Raise Z (maybe) and deploy the Z probe. - // - if (TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS && probe.deploy())) - return; - - // Set flags for X, Y, Z motor locking - #if HAS_EXTRA_ENDSTOPS - switch (axis) { - TERN_(X_DUAL_ENDSTOPS, case X_AXIS:) - TERN_(Y_DUAL_ENDSTOPS, case Y_AXIS:) - TERN_(Z_MULTI_ENDSTOPS, case Z_AXIS:) - stepper.set_separate_multi_axis(true); - default: break; + if (mmDelta != 0) { + // Retrace by the amount computed in mmDelta. + do_homing_move(axis, mmDelta, get_homing_bump_feedrate(axis)); + } } #endif - // - // Deploy BLTouch or tare the probe just before probing - // - #if HOMING_Z_WITH_PROBE - if (axis == Z_AXIS) { - if (TERN0(BLTOUCH, bltouch.deploy())) return; // BLTouch was deployed above, but get the alarm state. - if (TERN0(PROBE_TARE, probe.tare())) return; - } - #endif + /** + * Home an individual "raw axis" to its endstop. + * This applies to XYZ on Cartesian and Core robots, and + * to the individual ABC steppers on DELTA and SCARA. + * + * At the end of the procedure the axis is marked as + * homed and the current position of that axis is updated. + * Kinematic robots should wait till all axes are homed + * before updating the current position. + */ - // - // Back away to prevent an early X/Y sensorless trigger - // - #if DISABLED(DELTA) && defined(SENSORLESS_BACKOFF_MM) - const xy_float_t backoff = SENSORLESS_BACKOFF_MM; - if ((TERN0(X_SENSORLESS, axis == X_AXIS) || TERN0(Y_SENSORLESS, axis == Y_AXIS)) && backoff[axis]) { - const float backoff_length = -ABS(backoff[axis]) * axis_home_dir; - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Sensorless backoff: ", backoff_length, "mm"); - do_homing_move(axis, backoff_length, homing_feedrate(axis)); - } - #endif + void homeaxis(const AxisEnum axis) { - // Determine if a homing bump will be done and the bumps distance - // When homing Z with probe respect probe clearance - const bool use_probe_bump = TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS && home_bump_mm(Z_AXIS)); - const float bump = axis_home_dir * ( - use_probe_bump ? _MAX(TERN0(HOMING_Z_WITH_PROBE, Z_CLEARANCE_BETWEEN_PROBES), home_bump_mm(Z_AXIS)) : home_bump_mm(axis) - ); - - // - // Fast move towards endstop until triggered - // - const float move_length = 1.5f * max_length(TERN(DELTA, Z_AXIS, axis)) * axis_home_dir; - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Home Fast: ", move_length, "mm"); - do_homing_move(axis, move_length, 0.0, !use_probe_bump); - - #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH_SLOW_MODE) - if (axis == Z_AXIS) bltouch.stow(); // Intermediate STOW (in LOW SPEED MODE) - #endif + #if EITHER(MORGAN_SCARA, MP_SCARA) + // Only Z homing (with probe) is permitted + if (axis != Z_AXIS) { BUZZ(100, 880); return; } + #else + #define _CAN_HOME(A) (axis == _AXIS(A) && ( \ + ENABLED(A##_SPI_SENSORLESS) \ + || (_AXIS(A) == Z_AXIS && ENABLED(HOMING_Z_WITH_PROBE)) \ + || (A##_MIN_PIN > -1 && A##_HOME_DIR < 0) \ + || (A##_MAX_PIN > -1 && A##_HOME_DIR > 0) \ + )) + if (!_CAN_HOME(X) && !_CAN_HOME(Y) && !_CAN_HOME(Z)) return; + #endif - // If a second homing move is configured... - if (bump) { - // Move away from the endstop by the axis HOMING_BUMP_MM - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Move Away: ", -bump, "mm"); - do_homing_move(axis, -bump, TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS) ? MMM_TO_MMS(Z_PROBE_SPEED_FAST) : 0, false); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> homeaxis(", axis_codes[axis], ")"); - #if ENABLED(DETECT_BROKEN_ENDSTOP) - // Check for a broken endstop - EndstopEnum es; + const int axis_home_dir = TERN0(DUAL_X_CARRIAGE, axis == X_AXIS) + ? x_home_dir(active_extruder) : home_dir(axis); + + // + // Homing Z with a probe? Raise Z (maybe) and deploy the Z probe. + // + if (TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS && probe.deploy())) + return; + + // Set flags for X, Y, Z motor locking + #if HAS_EXTRA_ENDSTOPS switch (axis) { - default: - case X_AXIS: es = X_ENDSTOP; break; - case Y_AXIS: es = Y_ENDSTOP; break; - case Z_AXIS: es = Z_ENDSTOP; break; + TERN_(X_DUAL_ENDSTOPS, case X_AXIS:) + TERN_(Y_DUAL_ENDSTOPS, case Y_AXIS:) + TERN_(Z_MULTI_ENDSTOPS, case Z_AXIS:) + stepper.set_separate_multi_axis(true); + default: break; } - if (TEST(endstops.state(), es)) { - SERIAL_ECHO_MSG("Bad ", axis_codes[axis], " Endstop?"); - kill(GET_TEXT(MSG_KILL_HOMING_FAILED)); + #endif + + // + // Deploy BLTouch or tare the probe just before probing + // + #if HOMING_Z_WITH_PROBE + if (axis == Z_AXIS) { + if (TERN0(BLTOUCH, bltouch.deploy())) return; // BLTouch was deployed above, but get the alarm state. + if (TERN0(PROBE_TARE, probe.tare())) return; } #endif - #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH_SLOW_MODE) - if (axis == Z_AXIS && bltouch.deploy()) return; // Intermediate DEPLOY (in LOW SPEED MODE) + // + // Back away to prevent an early X/Y sensorless trigger + // + #if DISABLED(DELTA) && defined(SENSORLESS_BACKOFF_MM) + const xy_float_t backoff = SENSORLESS_BACKOFF_MM; + if ((TERN0(X_SENSORLESS, axis == X_AXIS) || TERN0(Y_SENSORLESS, axis == Y_AXIS)) && backoff[axis]) { + const float backoff_length = -ABS(backoff[axis]) * axis_home_dir; + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Sensorless backoff: ", backoff_length, "mm"); + do_homing_move(axis, backoff_length, homing_feedrate(axis)); + } #endif - // Slow move towards endstop until triggered - const float rebump = bump * 2; - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Re-bump: ", rebump, "mm"); - do_homing_move(axis, rebump, get_homing_bump_feedrate(axis), true); + // Determine if a homing bump will be done and the bumps distance + // When homing Z with probe respect probe clearance + const bool use_probe_bump = TERN0(HOMING_Z_WITH_PROBE, axis == Z_AXIS && home_bump_mm(Z_AXIS)); + const float bump = axis_home_dir * ( + use_probe_bump ? _MAX(TERN0(HOMING_Z_WITH_PROBE, Z_CLEARANCE_BETWEEN_PROBES), home_bump_mm(Z_AXIS)) : home_bump_mm(axis) + ); - #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH) - if (axis == Z_AXIS) bltouch.stow(); // The final STOW + // + // Fast move towards endstop until triggered + // + const float move_length = 1.5f * max_length(TERN(DELTA, Z_AXIS, axis)) * axis_home_dir; + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Home Fast: ", move_length, "mm"); + do_homing_move(axis, move_length, 0.0, !use_probe_bump); + + #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH_SLOW_MODE) + if (axis == Z_AXIS) bltouch.stow(); // Intermediate STOW (in LOW SPEED MODE) #endif - } - #if HAS_EXTRA_ENDSTOPS - const bool pos_dir = axis_home_dir > 0; - #if ENABLED(X_DUAL_ENDSTOPS) - if (axis == X_AXIS) { - const float adj = ABS(endstops.x2_endstop_adj); - if (adj) { - if (pos_dir ? (endstops.x2_endstop_adj > 0) : (endstops.x2_endstop_adj < 0)) stepper.set_x_lock(true); else stepper.set_x2_lock(true); - do_homing_move(axis, pos_dir ? -adj : adj); - stepper.set_x_lock(false); - stepper.set_x2_lock(false); + // If a second homing move is configured... + if (bump) { + // Move away from the endstop by the axis HOMING_BUMP_MM + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Move Away: ", -bump, "mm"); + do_homing_move(axis, -bump, TERN(HOMING_Z_WITH_PROBE, (axis == Z_AXIS ? z_probe_fast_mm_s : 0), 0), false); + + #if ENABLED(DETECT_BROKEN_ENDSTOP) + // Check for a broken endstop + EndstopEnum es; + switch (axis) { + default: + case X_AXIS: es = X_ENDSTOP; break; + case Y_AXIS: es = Y_ENDSTOP; break; + case Z_AXIS: es = Z_ENDSTOP; break; } - } - #endif - #if ENABLED(Y_DUAL_ENDSTOPS) - if (axis == Y_AXIS) { - const float adj = ABS(endstops.y2_endstop_adj); - if (adj) { - if (pos_dir ? (endstops.y2_endstop_adj > 0) : (endstops.y2_endstop_adj < 0)) stepper.set_y_lock(true); else stepper.set_y2_lock(true); - do_homing_move(axis, pos_dir ? -adj : adj); - stepper.set_y_lock(false); - stepper.set_y2_lock(false); + if (TEST(endstops.state(), es)) { + SERIAL_ECHO_MSG("Bad ", axis_codes[axis], " Endstop?"); + kill(GET_TEXT(MSG_KILL_HOMING_FAILED)); } - } - #endif + #endif - #if ENABLED(Z_MULTI_ENDSTOPS) - if (axis == Z_AXIS) { + #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH_SLOW_MODE) + if (axis == Z_AXIS && bltouch.deploy()) return; // Intermediate DEPLOY (in LOW SPEED MODE) + #endif + + // Slow move towards endstop until triggered + const float rebump = bump * 2; + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Re-bump: ", rebump, "mm"); + do_homing_move(axis, rebump, get_homing_bump_feedrate(axis), true); - #if NUM_Z_STEPPER_DRIVERS == 2 + #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH) + if (axis == Z_AXIS) bltouch.stow(); // The final STOW + #endif + } - const float adj = ABS(endstops.z2_endstop_adj); + #if HAS_EXTRA_ENDSTOPS + const bool pos_dir = axis_home_dir > 0; + #if ENABLED(X_DUAL_ENDSTOPS) + if (axis == X_AXIS) { + const float adj = ABS(endstops.x2_endstop_adj); if (adj) { - if (pos_dir ? (endstops.z2_endstop_adj > 0) : (endstops.z2_endstop_adj < 0)) stepper.set_z1_lock(true); else stepper.set_z2_lock(true); + if (pos_dir ? (endstops.x2_endstop_adj > 0) : (endstops.x2_endstop_adj < 0)) stepper.set_x_lock(true); else stepper.set_x2_lock(true); do_homing_move(axis, pos_dir ? -adj : adj); - stepper.set_z1_lock(false); - stepper.set_z2_lock(false); + stepper.set_x_lock(false); + stepper.set_x2_lock(false); } + } + #endif + #if ENABLED(Y_DUAL_ENDSTOPS) + if (axis == Y_AXIS) { + const float adj = ABS(endstops.y2_endstop_adj); + if (adj) { + if (pos_dir ? (endstops.y2_endstop_adj > 0) : (endstops.y2_endstop_adj < 0)) stepper.set_y_lock(true); else stepper.set_y2_lock(true); + do_homing_move(axis, pos_dir ? -adj : adj); + stepper.set_y_lock(false); + stepper.set_y2_lock(false); + } + } + #endif - #else - - // Handy arrays of stepper lock function pointers + #if ENABLED(Z_MULTI_ENDSTOPS) + if (axis == Z_AXIS) { - typedef void (*adjustFunc_t)(const bool); + #if NUM_Z_STEPPER_DRIVERS == 2 - adjustFunc_t lock[] = { - stepper.set_z1_lock, stepper.set_z2_lock, stepper.set_z3_lock - #if NUM_Z_STEPPER_DRIVERS >= 4 - , stepper.set_z4_lock - #endif - }; - float adj[] = { - 0, endstops.z2_endstop_adj, endstops.z3_endstop_adj - #if NUM_Z_STEPPER_DRIVERS >= 4 - , endstops.z4_endstop_adj - #endif - }; + const float adj = ABS(endstops.z2_endstop_adj); + if (adj) { + if (pos_dir ? (endstops.z2_endstop_adj > 0) : (endstops.z2_endstop_adj < 0)) stepper.set_z1_lock(true); else stepper.set_z2_lock(true); + do_homing_move(axis, pos_dir ? -adj : adj); + stepper.set_z1_lock(false); + stepper.set_z2_lock(false); + } - adjustFunc_t tempLock; - float tempAdj; + #else - // Manual bubble sort by adjust value - if (adj[1] < adj[0]) { - tempLock = lock[0], tempAdj = adj[0]; - lock[0] = lock[1], adj[0] = adj[1]; - lock[1] = tempLock, adj[1] = tempAdj; - } - if (adj[2] < adj[1]) { - tempLock = lock[1], tempAdj = adj[1]; - lock[1] = lock[2], adj[1] = adj[2]; - lock[2] = tempLock, adj[2] = tempAdj; - } - #if NUM_Z_STEPPER_DRIVERS >= 4 - if (adj[3] < adj[2]) { - tempLock = lock[2], tempAdj = adj[2]; - lock[2] = lock[3], adj[2] = adj[3]; - lock[3] = tempLock, adj[3] = tempAdj; + // Handy arrays of stepper lock function pointers + + typedef void (*adjustFunc_t)(const bool); + + adjustFunc_t lock[] = { + stepper.set_z1_lock, stepper.set_z2_lock, stepper.set_z3_lock + #if NUM_Z_STEPPER_DRIVERS >= 4 + , stepper.set_z4_lock + #endif + }; + float adj[] = { + 0, endstops.z2_endstop_adj, endstops.z3_endstop_adj + #if NUM_Z_STEPPER_DRIVERS >= 4 + , endstops.z4_endstop_adj + #endif + }; + + adjustFunc_t tempLock; + float tempAdj; + + // Manual bubble sort by adjust value + if (adj[1] < adj[0]) { + tempLock = lock[0], tempAdj = adj[0]; + lock[0] = lock[1], adj[0] = adj[1]; + lock[1] = tempLock, adj[1] = tempAdj; } if (adj[2] < adj[1]) { tempLock = lock[1], tempAdj = adj[1]; lock[1] = lock[2], adj[1] = adj[2]; lock[2] = tempLock, adj[2] = tempAdj; } - #endif - if (adj[1] < adj[0]) { - tempLock = lock[0], tempAdj = adj[0]; - lock[0] = lock[1], adj[0] = adj[1]; - lock[1] = tempLock, adj[1] = tempAdj; - } - - if (pos_dir) { - // normalize adj to smallest value and do the first move - (*lock[0])(true); - do_homing_move(axis, adj[1] - adj[0]); - // lock the second stepper for the final correction - (*lock[1])(true); - do_homing_move(axis, adj[2] - adj[1]); #if NUM_Z_STEPPER_DRIVERS >= 4 - // lock the third stepper for the final correction - (*lock[2])(true); - do_homing_move(axis, adj[3] - adj[2]); + if (adj[3] < adj[2]) { + tempLock = lock[2], tempAdj = adj[2]; + lock[2] = lock[3], adj[2] = adj[3]; + lock[3] = tempLock, adj[3] = tempAdj; + } + if (adj[2] < adj[1]) { + tempLock = lock[1], tempAdj = adj[1]; + lock[1] = lock[2], adj[1] = adj[2]; + lock[2] = tempLock, adj[2] = tempAdj; + } #endif - } - else { + if (adj[1] < adj[0]) { + tempLock = lock[0], tempAdj = adj[0]; + lock[0] = lock[1], adj[0] = adj[1]; + lock[1] = tempLock, adj[1] = tempAdj; + } + + if (pos_dir) { + // normalize adj to smallest value and do the first move + (*lock[0])(true); + do_homing_move(axis, adj[1] - adj[0]); + // lock the second stepper for the final correction + (*lock[1])(true); + do_homing_move(axis, adj[2] - adj[1]); + #if NUM_Z_STEPPER_DRIVERS >= 4 + // lock the third stepper for the final correction + (*lock[2])(true); + do_homing_move(axis, adj[3] - adj[2]); + #endif + } + else { + #if NUM_Z_STEPPER_DRIVERS >= 4 + (*lock[3])(true); + do_homing_move(axis, adj[2] - adj[3]); + #endif + (*lock[2])(true); + do_homing_move(axis, adj[1] - adj[2]); + (*lock[1])(true); + do_homing_move(axis, adj[0] - adj[1]); + } + + stepper.set_z1_lock(false); + stepper.set_z2_lock(false); + stepper.set_z3_lock(false); #if NUM_Z_STEPPER_DRIVERS >= 4 - (*lock[3])(true); - do_homing_move(axis, adj[2] - adj[3]); + stepper.set_z4_lock(false); #endif - (*lock[2])(true); - do_homing_move(axis, adj[1] - adj[2]); - (*lock[1])(true); - do_homing_move(axis, adj[0] - adj[1]); - } - stepper.set_z1_lock(false); - stepper.set_z2_lock(false); - stepper.set_z3_lock(false); - #if NUM_Z_STEPPER_DRIVERS >= 4 - stepper.set_z4_lock(false); #endif + } + #endif - #endif + // Reset flags for X, Y, Z motor locking + switch (axis) { + default: break; + TERN_(X_DUAL_ENDSTOPS, case X_AXIS:) + TERN_(Y_DUAL_ENDSTOPS, case Y_AXIS:) + TERN_(Z_MULTI_ENDSTOPS, case Z_AXIS:) + stepper.set_separate_multi_axis(false); } + + #endif // HAS_EXTRA_ENDSTOPS + + #ifdef TMC_HOME_PHASE + // move back to homing phase if configured and capable + backout_to_tmc_homing_phase(axis); #endif - // Reset flags for X, Y, Z motor locking - switch (axis) { - default: break; - TERN_(X_DUAL_ENDSTOPS, case X_AXIS:) - TERN_(Y_DUAL_ENDSTOPS, case Y_AXIS:) - TERN_(Z_MULTI_ENDSTOPS, case Z_AXIS:) - stepper.set_separate_multi_axis(false); - } - #endif + #if IS_SCARA - #ifdef TMC_HOME_PHASE - // move back to homing phase if configured and capable - backout_to_tmc_homing_phase(axis); - #endif + set_axis_is_at_home(axis); + sync_plan_position(); - #if IS_SCARA + #elif ENABLED(DELTA) - set_axis_is_at_home(axis); - sync_plan_position(); + // Delta has already moved all three towers up in G28 + // so here it re-homes each tower in turn. + // Delta homing treats the axes as normal linear axes. - #elif ENABLED(DELTA) + const float adjDistance = delta_endstop_adj[axis], + minDistance = (MIN_STEPS_PER_SEGMENT) * planner.steps_to_mm[axis]; - // Delta has already moved all three towers up in G28 - // so here it re-homes each tower in turn. - // Delta homing treats the axes as normal linear axes. + // Retrace by the amount specified in delta_endstop_adj if more than min steps. + if (adjDistance * (Z_HOME_DIR) < 0 && ABS(adjDistance) > minDistance) { // away from endstop, more than min distance + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("adjDistance:", adjDistance); + do_homing_move(axis, adjDistance, get_homing_bump_feedrate(axis)); + } - const float adjDistance = delta_endstop_adj[axis], - minDistance = (MIN_STEPS_PER_SEGMENT) * planner.steps_to_mm[axis]; + #else // CARTESIAN / CORE / MARKFORGED_XY - // Retrace by the amount specified in delta_endstop_adj if more than min steps. - if (adjDistance * (Z_HOME_DIR) < 0 && ABS(adjDistance) > minDistance) { // away from endstop, more than min distance - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("adjDistance:", adjDistance); - do_homing_move(axis, adjDistance, get_homing_bump_feedrate(axis)); - } + set_axis_is_at_home(axis); + sync_plan_position(); - #else // CARTESIAN / CORE / MARKFORGED_XY + destination[axis] = current_position[axis]; - set_axis_is_at_home(axis); - sync_plan_position(); + if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", current_position); - destination[axis] = current_position[axis]; + #endif - if (DEBUGGING(LEVELING)) DEBUG_POS("> AFTER set_axis_is_at_home", current_position); + // Put away the Z probe + #if HOMING_Z_WITH_PROBE + if (axis == Z_AXIS && probe.stow()) return; + #endif + #if DISABLED(DELTA) && defined(HOMING_BACKOFF_POST_MM) + const xyz_float_t endstop_backoff = HOMING_BACKOFF_POST_MM; + if (endstop_backoff[axis]) { + current_position[axis] -= ABS(endstop_backoff[axis]) * axis_home_dir; + line_to_current_position( + #if HOMING_Z_WITH_PROBE + (axis == Z_AXIS) ? z_probe_fast_mm_s : + #endif + homing_feedrate(axis) + ); + + #if ENABLED(SENSORLESS_HOMING) + planner.synchronize(); + if (false + #if EITHER(IS_CORE, MARKFORGED_XY) + || axis != NORMAL_AXIS + #endif + ) safe_delay(200); // Short delay to allow belts to spring back + #endif + } + #endif + + // Clear retracted status if homing the Z axis + #if ENABLED(FWRETRACT) + if (axis == Z_AXIS) fwretract.current_hop = 0.0; + #endif + + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< homeaxis(", axis_codes[axis], ")"); + + } // homeaxis() + +#endif // HAS_ENDSTOPS + +/** + * Set an axis' current position to its home position (after homing). + * + * For Core and Cartesian robots this applies one-to-one when an + * individual axis has been homed. + * + * DELTA should wait until all homing is done before setting the XYZ + * current_position to home, because homing is a single operation. + * In the case where the axis positions are trusted and previously + * homed, DELTA could home to X or Y individually by moving either one + * to the center. However, homing Z always homes XY and Z. + * + * SCARA should wait until all XY homing is done before setting the XY + * current_position to home, because neither X nor Y is at home until + * both are at home. Z can however be homed individually. + * + * Callers must sync the planner position after calling this! + */ +void set_axis_is_at_home(const AxisEnum axis) { + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR(">>> set_axis_is_at_home(", AS_CHAR(axis_codes[axis]), ")"); + + set_axis_trusted(axis); + set_axis_homed(axis); + + #if ENABLED(DUAL_X_CARRIAGE) + if (axis == X_AXIS && (active_extruder == 1 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) { + current_position.x = x_home_pos(active_extruder); + return; + } #endif - // Put away the Z probe - #if HOMING_Z_WITH_PROBE - if (axis == Z_AXIS && probe.stow()) return; + #if EITHER(MORGAN_SCARA, AXEL_TPARA) + scara_set_axis_is_at_home(axis); + #elif ENABLED(DELTA) + current_position[axis] = (axis == Z_AXIS) ? delta_height - TERN0(HAS_BED_PROBE, probe.offset.z) : base_home_pos(axis); + #else + current_position[axis] = base_home_pos(axis); #endif - #if DISABLED(DELTA) && defined(HOMING_BACKOFF_POST_MM) - const xyz_float_t endstop_backoff = HOMING_BACKOFF_POST_MM; - if (endstop_backoff[axis]) { - current_position[axis] -= ABS(endstop_backoff[axis]) * axis_home_dir; - line_to_current_position( - #if HOMING_Z_WITH_PROBE - (axis == Z_AXIS) ? z_probe_fast_mm_s : - #endif - homing_feedrate(axis) - ); + /** + * Z Probe Z Homing? Account for the probe's Z offset. + */ + #if HAS_BED_PROBE && Z_HOME_DIR < 0 + if (axis == Z_AXIS) { + #if HOMING_Z_WITH_PROBE + + current_position.z -= probe.offset.z; + + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("*** Z HOMED WITH PROBE (Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) ***\n> probe.offset.z = ", probe.offset.z); + + #else + + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("*** Z HOMED TO ENDSTOP ***"); - #if ENABLED(SENSORLESS_HOMING) - planner.synchronize(); - if (false - #if EITHER(IS_CORE, MARKFORGED_XY) - || axis != NORMAL_AXIS - #endif - ) safe_delay(200); // Short delay to allow belts to spring back #endif } #endif - // Clear retracted status if homing the Z axis - #if ENABLED(FWRETRACT) - if (axis == Z_AXIS) fwretract.current_hop = 0.0; - #endif + TERN_(I2C_POSITION_ENCODERS, I2CPEM.homed(axis)); + + TERN_(BABYSTEP_DISPLAY_TOTAL, babystep.reset_total(axis)); - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("<<< homeaxis(", axis_codes[axis], ")"); + #if HAS_POSITION_SHIFT + position_shift[axis] = 0; + update_workspace_offset(axis); + #endif -} // homeaxis() + if (DEBUGGING(LEVELING)) { + #if HAS_HOME_OFFSET + DEBUG_ECHOLNPAIR("> home_offset[", AS_CHAR(axis_codes[axis]), "] = ", home_offset[axis]); + #endif + DEBUG_POS("", current_position); + DEBUG_ECHOLNPAIR("<<< set_axis_is_at_home(", axis_codes[axis], ")"); + } +} #if HAS_WORKSPACE_OFFSET void update_workspace_offset(const AxisEnum axis) { @@ -1893,4 +1905,4 @@ void homeaxis(const AxisEnum axis) { home_offset[axis] = v; update_workspace_offset(axis); } -#endif // HAS_M206_COMMAND +#endif diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 887da1aa1886..0328d015a49d 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -59,13 +59,15 @@ extern xyz_pos_t cartes; #if HAS_ABL_NOT_UBL extern feedRate_t xy_probe_feedrate_mm_s; #define XY_PROBE_FEEDRATE_MM_S xy_probe_feedrate_mm_s -#elif defined(XY_PROBE_SPEED) - #define XY_PROBE_FEEDRATE_MM_S MMM_TO_MMS(XY_PROBE_SPEED) +#elif defined(XY_PROBE_FEEDRATE) + #define XY_PROBE_FEEDRATE_MM_S MMM_TO_MMS(XY_PROBE_FEEDRATE) #else #define XY_PROBE_FEEDRATE_MM_S PLANNER_XY_FEEDRATE() #endif -constexpr feedRate_t z_probe_fast_mm_s = MMM_TO_MMS(Z_PROBE_SPEED_FAST); +#if HAS_BED_PROBE + constexpr feedRate_t z_probe_fast_mm_s = MMM_TO_MMS(Z_PROBE_FEEDRATE_FAST); +#endif /** * Feed rates are often configured with mm/m @@ -278,33 +280,57 @@ void remember_feedrate_and_scaling(); void remember_feedrate_scaling_off(); void restore_feedrate_and_scaling(); -void do_z_clearance(const float &zclear, const bool z_trusted=true, const bool raise_on_untrusted=true, const bool lower_allowed=false); +void do_z_clearance(const float &zclear, const bool lower_allowed=false); /** * Homing and Trusted Axes */ constexpr uint8_t xyz_bits = _BV(X_AXIS) | _BV(Y_AXIS) | _BV(Z_AXIS); -extern uint8_t axis_homed, axis_trusted; -void homeaxis(const AxisEnum axis); void set_axis_is_at_home(const AxisEnum axis); -void set_axis_never_homed(const AxisEnum axis); -uint8_t axes_should_home(uint8_t axis_bits=0x07); -bool homing_needed_error(uint8_t axis_bits=0x07); - -FORCE_INLINE bool axis_was_homed(const AxisEnum axis) { return TEST(axis_homed, axis); } -FORCE_INLINE bool axis_is_trusted(const AxisEnum axis) { return TEST(axis_trusted, axis); } -FORCE_INLINE bool axis_should_home(const AxisEnum axis) { return (axes_should_home() & _BV(axis)) != 0; } -FORCE_INLINE bool no_axes_homed() { return !axis_homed; } -FORCE_INLINE bool all_axes_homed() { return xyz_bits == (axis_homed & xyz_bits); } -FORCE_INLINE bool homing_needed() { return !all_axes_homed(); } -FORCE_INLINE bool all_axes_trusted() { return xyz_bits == (axis_trusted & xyz_bits); } -FORCE_INLINE void set_axis_homed(const AxisEnum axis) { SBI(axis_homed, axis); } -FORCE_INLINE void set_axis_unhomed(const AxisEnum axis) { CBI(axis_homed, axis); } -FORCE_INLINE void set_axis_trusted(const AxisEnum axis) { SBI(axis_trusted, axis); } -FORCE_INLINE void set_axis_untrusted(const AxisEnum axis) { CBI(axis_trusted, axis); } -FORCE_INLINE void set_all_homed() { axis_homed = axis_trusted = xyz_bits; } -FORCE_INLINE void set_all_unhomed() { axis_homed = axis_trusted = 0; } + +#if HAS_ENDSTOPS + /** + * axis_homed + * Flags that each linear axis was homed. + * XYZ on cartesian, ABC on delta, ABZ on SCARA. + * + * axis_trusted + * Flags that the position is trusted in each linear axis. Set when homed. + * Cleared whenever a stepper powers off, potentially losing its position. + */ + extern uint8_t axis_homed, axis_trusted; + void homeaxis(const AxisEnum axis); + void set_axis_never_homed(const AxisEnum axis); + uint8_t axes_should_home(uint8_t axis_bits=0x07); + bool homing_needed_error(uint8_t axis_bits=0x07); + FORCE_INLINE void set_axis_unhomed(const AxisEnum axis) { CBI(axis_homed, axis); } + FORCE_INLINE void set_axis_untrusted(const AxisEnum axis) { CBI(axis_trusted, axis); } + FORCE_INLINE void set_all_unhomed() { axis_homed = axis_trusted = 0; } + FORCE_INLINE void set_axis_homed(const AxisEnum axis) { SBI(axis_homed, axis); } + FORCE_INLINE void set_axis_trusted(const AxisEnum axis) { SBI(axis_trusted, axis); } + FORCE_INLINE void set_all_homed() { axis_homed = axis_trusted = xyz_bits; } +#else + constexpr uint8_t axis_homed = xyz_bits, axis_trusted = xyz_bits; // Zero-endstop machines are always homed and trusted + FORCE_INLINE void homeaxis(const AxisEnum axis) {} + FORCE_INLINE void set_axis_never_homed(const AxisEnum) {} + FORCE_INLINE uint8_t axes_should_home(uint8_t=0x07) { return false; } + FORCE_INLINE bool homing_needed_error(uint8_t=0x07) { return false; } + FORCE_INLINE void set_axis_unhomed(const AxisEnum axis) {} + FORCE_INLINE void set_axis_untrusted(const AxisEnum axis) {} + FORCE_INLINE void set_all_unhomed() {} + FORCE_INLINE void set_axis_homed(const AxisEnum axis) {} + FORCE_INLINE void set_axis_trusted(const AxisEnum axis) {} + FORCE_INLINE void set_all_homed() {} +#endif + +FORCE_INLINE bool axis_was_homed(const AxisEnum axis) { return TEST(axis_homed, axis); } +FORCE_INLINE bool axis_is_trusted(const AxisEnum axis) { return TEST(axis_trusted, axis); } +FORCE_INLINE bool axis_should_home(const AxisEnum axis) { return (axes_should_home() & _BV(axis)) != 0; } +FORCE_INLINE bool no_axes_homed() { return !axis_homed; } +FORCE_INLINE bool all_axes_homed() { return xyz_bits == (axis_homed & xyz_bits); } +FORCE_INLINE bool homing_needed() { return !all_axes_homed(); } +FORCE_INLINE bool all_axes_trusted() { return xyz_bits == (axis_trusted & xyz_bits); } #if ENABLED(NO_MOTION_BEFORE_HOMING) #define MOTION_CONDITIONS (IsRunning() && !homing_needed_error()) @@ -360,7 +386,6 @@ FORCE_INLINE void set_all_unhomed() { axis_homed = axis_tr /** * position_is_reachable family of functions */ - #if IS_KINEMATIC // (DELTA or SCARA) #if HAS_SCARA_OFFSET @@ -370,8 +395,21 @@ FORCE_INLINE void set_all_unhomed() { axis_homed = axis_tr // Return true if the given point is within the printable area inline bool position_is_reachable(const float &rx, const float &ry, const float inset=0) { #if ENABLED(DELTA) + return HYPOT2(rx, ry) <= sq(DELTA_PRINTABLE_RADIUS - inset + fslop); + + #elif ENABLED(AXEL_TPARA) + + const float R2 = HYPOT2(rx - TPARA_OFFSET_X, ry - TPARA_OFFSET_Y); + return ( + R2 <= sq(L1 + L2) - inset + #if MIDDLE_DEAD_ZONE_R > 0 + && R2 >= sq(float(MIDDLE_DEAD_ZONE_R)) + #endif + ); + #elif IS_SCARA + const float R2 = HYPOT2(rx - SCARA_OFFSET_X, ry - SCARA_OFFSET_Y); return ( R2 <= sq(L1 + L2) - inset @@ -379,6 +417,7 @@ FORCE_INLINE void set_all_unhomed() { axis_homed = axis_tr && R2 >= sq(float(MIDDLE_DEAD_ZONE_R)) #endif ); + #endif } @@ -390,14 +429,14 @@ FORCE_INLINE void set_all_unhomed() { axis_homed = axis_tr // Return true if the given position is within the machine bounds. inline bool position_is_reachable(const float &rx, const float &ry) { - if (!WITHIN(ry, Y_MIN_POS - fslop, Y_MAX_POS + fslop)) return false; + if (!COORDINATE_OKAY(ry, Y_MIN_POS - fslop, Y_MAX_POS + fslop)) return false; #if ENABLED(DUAL_X_CARRIAGE) if (active_extruder) - return WITHIN(rx, X2_MIN_POS - fslop, X2_MAX_POS + fslop); + return COORDINATE_OKAY(rx, X2_MIN_POS - fslop, X2_MAX_POS + fslop); else - return WITHIN(rx, X1_MIN_POS - fslop, X1_MAX_POS + fslop); + return COORDINATE_OKAY(rx, X1_MIN_POS - fslop, X1_MAX_POS + fslop); #else - return WITHIN(rx, X_MIN_POS - fslop, X_MAX_POS + fslop); + return COORDINATE_OKAY(rx, X_MIN_POS - fslop, X_MAX_POS + fslop); #endif } inline bool position_is_reachable(const xy_pos_t &pos) { return position_is_reachable(pos.x, pos.y); } @@ -450,7 +489,7 @@ FORCE_INLINE void set_all_unhomed() { axis_homed = axis_tr FORCE_INLINE void set_duplication_enabled(const bool dupe) { extruder_duplication_enabled = dupe; } #endif - FORCE_INLINE int x_home_dir(const uint8_t) { return home_dir(X_AXIS); } + FORCE_INLINE int x_home_dir(const uint8_t) { return X_HOME_DIR; } #endif diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 541aed943ee7..dd87a0d24d8e 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -1690,13 +1690,15 @@ bool Planner::_buffer_steps(const xyze_long_t &target , feedRate_t fr_mm_s, const uint8_t extruder, const float &millimeters ) { - // If we are cleaning, do not accept queuing of movements - if (cleaning_buffer_counter) return false; - // Wait for the next available block uint8_t next_buffer_head; block_t * const block = get_next_free_block(next_buffer_head); + // If we are cleaning, do not accept queuing of movements + // This must be after get_next_free_block() because it calls idle() + // where cleaning_buffer_counter can be changed + if (cleaning_buffer_counter) return false; + // Fill the block with the specified movement if (!_populate_block(block, false, target #if HAS_POSITION_FLOAT @@ -2971,7 +2973,7 @@ inline void limit_and_warn(float &val, const uint8_t axis, PGM_P const setting_n if (before != val) { SERIAL_CHAR(axis_codes[lim_axis]); SERIAL_ECHOPGM(" Max "); - serialprintPGM(setting_name); + SERIAL_ECHOPGM_P(setting_name); SERIAL_ECHOLNPAIR(" limited to ", val); } } diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index cd906c5d134a..b7ff0ee93282 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -564,10 +564,10 @@ class Planner { #if ENABLED(SKEW_CORRECTION) FORCE_INLINE static void skew(float &cx, float &cy, const float &cz) { - if (WITHIN(cx, X_MIN_POS + 1, X_MAX_POS) && WITHIN(cy, Y_MIN_POS + 1, Y_MAX_POS)) { + if (COORDINATE_OKAY(cx, X_MIN_POS + 1, X_MAX_POS) && COORDINATE_OKAY(cy, Y_MIN_POS + 1, Y_MAX_POS)) { const float sx = cx - cy * skew_factor.xy - cz * (skew_factor.xz - (skew_factor.xy * skew_factor.yz)), sy = cy - cz * skew_factor.yz; - if (WITHIN(sx, X_MIN_POS, X_MAX_POS) && WITHIN(sy, Y_MIN_POS, Y_MAX_POS)) { + if (COORDINATE_OKAY(sx, X_MIN_POS, X_MAX_POS) && COORDINATE_OKAY(sy, Y_MIN_POS, Y_MAX_POS)) { cx = sx; cy = sy; } } @@ -575,10 +575,10 @@ class Planner { FORCE_INLINE static void skew(xyz_pos_t &raw) { skew(raw.x, raw.y, raw.z); } FORCE_INLINE static void unskew(float &cx, float &cy, const float &cz) { - if (WITHIN(cx, X_MIN_POS, X_MAX_POS) && WITHIN(cy, Y_MIN_POS, Y_MAX_POS)) { + if (COORDINATE_OKAY(cx, X_MIN_POS, X_MAX_POS) && COORDINATE_OKAY(cy, Y_MIN_POS, Y_MAX_POS)) { const float sx = cx + cy * skew_factor.xy + cz * skew_factor.xz, sy = cy + cz * skew_factor.yz; - if (WITHIN(sx, X_MIN_POS, X_MAX_POS) && WITHIN(sy, Y_MIN_POS, Y_MAX_POS)) { + if (COORDINATE_OKAY(sx, X_MIN_POS, X_MAX_POS) && COORDINATE_OKAY(sy, Y_MIN_POS, Y_MAX_POS)) { cx = sx; cy = sy; } } diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 45072c8f0189..2728b8d5a9c4 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -43,6 +43,7 @@ Stopwatch print_job_timer; // Global Print Job Timer instance #if PRINTCOUNTER_SYNC #include "../module/planner.h" + #warning "To prevent step loss, motion will pause for PRINTCOUNTER auto-save." #endif // Service intervals @@ -118,7 +119,7 @@ void PrintCounter::initStats() { inline bool _service_warn(const char * const msg) { _print_divider(); SERIAL_ECHO_START(); - serialprintPGM(msg); + SERIAL_ECHOPGM_P(msg); SERIAL_ECHOLNPGM("!"); _print_divider(); return true; @@ -177,7 +178,7 @@ void PrintCounter::saveStats() { #if HAS_SERVICE_INTERVALS inline void _service_when(char buffer[], const char * const msg, const uint32_t when) { SERIAL_ECHOPGM(STR_STATS); - serialprintPGM(msg); + SERIAL_ECHOPGM_P(msg); SERIAL_ECHOLNPAIR(" in ", duration_t(when).toString(buffer)); } #endif @@ -339,7 +340,7 @@ void PrintCounter::reset() { void PrintCounter::debug(const char func[]) { if (DEBUGGING(INFO)) { SERIAL_ECHOPGM("PrintCounter::"); - serialprintPGM(func); + SERIAL_ECHOPGM_P(func); SERIAL_ECHOLNPGM("()"); } } diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index 925538ef8316..28c89e7a00ee 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -238,20 +238,32 @@ xyz_pos_t Probe::offset; // Initialized by settings.load() #if HAS_QUIET_PROBING - void Probe::set_probing_paused(const bool p) { - TERN_(PROBING_HEATERS_OFF, thermalManager.pause(p)); - TERN_(PROBING_FANS_OFF, thermalManager.set_fans_paused(p)); + #ifndef DELAY_BEFORE_PROBING + #define DELAY_BEFORE_PROBING 25 + #endif + + void Probe::set_probing_paused(const bool dopause) { + TERN_(PROBING_HEATERS_OFF, thermalManager.pause(dopause)); + TERN_(PROBING_FANS_OFF, thermalManager.set_fans_paused(dopause)); #if ENABLED(PROBING_STEPPERS_OFF) - disable_e_steppers(); - #if NONE(DELTA, HOME_AFTER_DEACTIVATE) - DISABLE_AXIS_X(); DISABLE_AXIS_Y(); - #endif + IF_DISABLED(DELTA, static uint8_t old_trusted); + if (dopause) { + #if DISABLED(DELTA) + old_trusted = axis_trusted; + DISABLE_AXIS_X(); + DISABLE_AXIS_Y(); + #endif + disable_e_steppers(); + } + else { + #if DISABLED(DELTA) + if (TEST(old_trusted, X_AXIS)) ENABLE_AXIS_X(); + if (TEST(old_trusted, Y_AXIS)) ENABLE_AXIS_Y(); + #endif + axis_trusted = old_trusted; + } #endif - if (p) safe_delay(25 - #if DELAY_BEFORE_PROBING > 25 - - 25 + DELAY_BEFORE_PROBING - #endif - ); + if (dopause) safe_delay(_MAX(DELAY_BEFORE_PROBING, 25)); } #endif // HAS_QUIET_PROBING @@ -279,8 +291,7 @@ FORCE_INLINE void probe_specific_action(const bool deploy) { PGM_P const ds_str = deploy ? GET_TEXT(MSG_MANUAL_DEPLOY) : GET_TEXT(MSG_MANUAL_STOW); ui.return_to_status(); // To display the new status message ui.set_status_P(ds_str, 99); - serialprintPGM(ds_str); - SERIAL_EOL(); + SERIAL_ECHOLNPGM_P(ds_str); TERN_(HOST_PROMPT_SUPPORT, host_prompt_do(PROMPT_USER_CONTINUE, PSTR("Stow Probe"), CONTINUE_STR)); TERN_(EXTENSIBLE_UI, ExtUI::onUserConfirmRequired_P(PSTR("Stow Probe"))); @@ -327,30 +338,53 @@ FORCE_INLINE void probe_specific_action(const bool deploy) { #if EITHER(PREHEAT_BEFORE_PROBING, PREHEAT_BEFORE_LEVELING) + #if ENABLED(PREHEAT_BEFORE_PROBING) + #ifndef PROBING_NOZZLE_TEMP + #define PROBING_NOZZLE_TEMP 0 + #endif + #ifndef PROBING_BED_TEMP + #define PROBING_BED_TEMP 0 + #endif + #endif + /** - * Do preheating as required before leveling or probing + * Do preheating as required before leveling or probing. + * - If a preheat input is higher than the current target, raise the target temperature. + * - If a preheat input is higher than the current temperature, wait for stabilization. */ - void Probe::preheat_for_probing(const uint16_t hotend_temp, const uint16_t bed_temp) { - #if PROBING_NOZZLE_TEMP || LEVELING_NOZZLE_TEMP + void Probe::preheat_for_probing(const int16_t hotend_temp, const int16_t bed_temp) { + #if HAS_HOTEND && (PROBING_NOZZLE_TEMP || LEVELING_NOZZLE_TEMP) #define WAIT_FOR_NOZZLE_HEAT #endif - #if PROBING_BED_TEMP || LEVELING_BED_TEMP + #if HAS_HEATED_BED && (PROBING_BED_TEMP || LEVELING_BED_TEMP) #define WAIT_FOR_BED_HEAT #endif - const uint16_t hotendPreheat = TERN0(WAIT_FOR_NOZZLE_HEAT, thermalManager.degHotend(0) < hotend_temp) ? hotend_temp : 0, - bedPreheat = TERN0(WAIT_FOR_BED_HEAT, thermalManager.degBed() < bed_temp) ? bed_temp : 0; + DEBUG_ECHOPGM("Preheating "); - if (hotendPreheat) { - DEBUG_ECHOPAIR("hotend (", hotendPreheat, ") "); - if (bedPreheat) DEBUG_ECHOPGM("and "); - } - if (bedPreheat) DEBUG_ECHOPAIR("bed (", bedPreheat, ") "); + + #if ENABLED(WAIT_FOR_NOZZLE_HEAT) + const int16_t hotendPreheat = hotend_temp > thermalManager.degTargetHotend(0) ? hotend_temp : 0; + if (hotendPreheat) { + DEBUG_ECHOPAIR("hotend (", hotendPreheat, ")"); + thermalManager.setTargetHotend(hotendPreheat, 0); + } + #elif ENABLED(WAIT_FOR_BED_HEAT) + constexpr int16_t hotendPreheat = 0; + #endif + + #if ENABLED(WAIT_FOR_BED_HEAT) + const int16_t bedPreheat = bed_temp > thermalManager.degTargetBed() ? bed_temp : 0; + if (bedPreheat) { + if (hotendPreheat) DEBUG_ECHOPGM(" and "); + DEBUG_ECHOPAIR("bed (", bedPreheat, ")"); + thermalManager.setTargetBed(bedPreheat); + } + #endif + DEBUG_EOL(); - TERN_(WAIT_FOR_NOZZLE_HEAT, if (hotendPreheat) thermalManager.setTargetHotend(hotendPreheat, 0)); - TERN_(WAIT_FOR_BED_HEAT, if (bedPreheat) thermalManager.setTargetBed(bedPreheat)); - TERN_(WAIT_FOR_NOZZLE_HEAT, if (hotendPreheat) thermalManager.wait_for_hotend(0)); - TERN_(WAIT_FOR_BED_HEAT, if (bedPreheat) thermalManager.wait_for_bed_heating()); + TERN_(WAIT_FOR_NOZZLE_HEAT, if (hotend_temp > thermalManager.degHotend(0) + (TEMP_WINDOW)) thermalManager.wait_for_hotend(0)); + TERN_(WAIT_FOR_BED_HEAT, if (bed_temp > thermalManager.degBed() + (TEMP_BED_WINDOW)) thermalManager.wait_for_bed_heating()); } #endif @@ -378,14 +412,7 @@ bool Probe::set_deployed(const bool deploy) { constexpr bool z_raise_wanted = true; #endif - // For beds that fall when Z is powered off only raise for trusted Z - #if ENABLED(UNKNOWN_Z_NO_RAISE) - const bool z_is_trusted = axis_is_trusted(Z_AXIS); - #else - constexpr float z_is_trusted = true; - #endif - - if (z_is_trusted && z_raise_wanted) + if (z_raise_wanted) do_z_raise(_MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE)); #if EITHER(Z_PROBE_SLED, Z_PROBE_ALLEN_KEY) @@ -455,6 +482,10 @@ bool Probe::probe_down_to_z(const float z, const feedRate_t fr_mm_s) { thermalManager.wait_for_bed_heating(); #endif + #if BOTH(HAS_TEMP_HOTEND, WAIT_FOR_HOTEND) + thermalManager.wait_for_hotend_heating(active_extruder); + #endif + if (TERN0(BLTOUCH_SLOW_MODE, bltouch.deploy())) return true; // Deploy in LOW SPEED MODE on every probe action // Disable stealthChop if used. Enable diag1 pin on driver. @@ -566,7 +597,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) { early_fail = (scheck && current_position.z > -offset.z + clearance); // Probe triggered too high? #if ENABLED(DEBUG_LEVELING_FEATURE) if (DEBUGGING(LEVELING) && (probe_fail || early_fail)) { - DEBUG_PRINT_P(plbl); + DEBUG_ECHOPGM_P(plbl); DEBUG_ECHOPGM(" Probe fail! -"); if (probe_fail) DEBUG_ECHOPGM(" No trigger."); if (early_fail) DEBUG_ECHOPGM(" Triggered early."); @@ -599,7 +630,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) { // Raise to give the probe clearance do_blocking_move_to_z(current_position.z + Z_CLEARANCE_MULTI_PROBE, z_probe_fast_mm_s); - #elif Z_PROBE_SPEED_FAST != Z_PROBE_SPEED_SLOW + #elif Z_PROBE_FEEDRATE_FAST != Z_PROBE_FEEDRATE_SLOW // If the nozzle is well over the travel height then // move down quickly before doing the slow probe @@ -630,7 +661,7 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) { if (TERN0(PROBE_TARE, tare())) return true; // Probe downward slowly to find the bed - if (try_to_probe(PSTR("SLOW"), z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_SLOW), + if (try_to_probe(PSTR("SLOW"), z_probe_low_point, MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW), sanity_check, Z_CLEARANCE_MULTI_PROBE) ) return NAN; TERN_(MEASURE_BACKLASH_WHEN_PROBING, backlash.measure_with_probe()); diff --git a/Marlin/src/module/probe.h b/Marlin/src/module/probe.h index d28cdff53a8e..b54bf00f0087 100644 --- a/Marlin/src/module/probe.h +++ b/Marlin/src/module/probe.h @@ -44,6 +44,15 @@ #define PROBE_TRIGGERED() (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) #endif +#if ENABLED(PREHEAT_BEFORE_LEVELING) + #ifndef LEVELING_NOZZLE_TEMP + #define LEVELING_NOZZLE_TEMP 0 + #endif + #ifndef LEVELING_BED_TEMP + #define LEVELING_BED_TEMP 0 + #endif +#endif + class Probe { public: @@ -52,7 +61,7 @@ class Probe { static xyz_pos_t offset; #if EITHER(PREHEAT_BEFORE_PROBING, PREHEAT_BEFORE_LEVELING) - static void preheat_for_probing(const uint16_t hotend_temp, const uint16_t bed_temp); + static void preheat_for_probing(const int16_t hotend_temp, const int16_t bed_temp); #endif static bool set_deployed(const bool deploy); @@ -83,15 +92,15 @@ class Probe { */ static bool can_reach(const float &rx, const float &ry) { return position_is_reachable(rx - offset_xy.x, ry - offset_xy.y) - && WITHIN(rx, min_x() - fslop, max_x() + fslop) - && WITHIN(ry, min_y() - fslop, max_y() + fslop); + && COORDINATE_OKAY(rx, min_x() - fslop, max_x() + fslop) + && COORDINATE_OKAY(ry, min_y() - fslop, max_y() + fslop); } #endif static void move_z_after_probing() { #ifdef Z_AFTER_PROBING - do_z_clearance(Z_AFTER_PROBING, true, true, true); // Move down still permitted + do_z_clearance(Z_AFTER_PROBING, true); // Move down still permitted #endif } static float probe_at_point(const float &rx, const float &ry, const ProbePtRaise raise_after=PROBE_PT_NONE, const uint8_t verbose_level=0, const bool probe_relative=true, const bool sanity_check=true); @@ -111,7 +120,7 @@ class Probe { static void move_z_after_homing() { #ifdef Z_AFTER_HOMING - do_z_clearance(Z_AFTER_HOMING, true, true, true); + do_z_clearance(Z_AFTER_HOMING, true); #elif BOTH(Z_AFTER_PROBING, HAS_BED_PROBE) move_z_after_probing(); #endif @@ -197,8 +206,8 @@ class Probe { #if IS_KINEMATIC return HYPOT2(x, y) <= sq(probe_radius(default_probe_xy_offset)); #else - return WITHIN(x, _min_x(default_probe_xy_offset) - fslop, _max_x(default_probe_xy_offset) + fslop) - && WITHIN(y, _min_y(default_probe_xy_offset) - fslop, _max_y(default_probe_xy_offset) + fslop); + return COORDINATE_OKAY(x, _min_x(default_probe_xy_offset) - fslop, _max_x(default_probe_xy_offset) + fslop) + && COORDINATE_OKAY(y, _min_y(default_probe_xy_offset) - fslop, _max_y(default_probe_xy_offset) + fslop); #endif } diff --git a/Marlin/src/module/scara.cpp b/Marlin/src/module/scara.cpp index e4b2f0b75c51..1767e230c153 100644 --- a/Marlin/src/module/scara.cpp +++ b/Marlin/src/module/scara.cpp @@ -32,79 +32,74 @@ #include "motion.h" #include "planner.h" -float delta_segments_per_second = SCARA_SEGMENTS_PER_SECOND; - -void scara_set_axis_is_at_home(const AxisEnum axis) { - if (axis == Z_AXIS) - current_position.z = Z_HOME_POS; - else { - - /** - * SCARA homes XY at the same time - */ - xyz_pos_t homeposition; - LOOP_XYZ(i) homeposition[i] = base_home_pos((AxisEnum)i); - - #if ENABLED(MORGAN_SCARA) - // MORGAN_SCARA uses arm angles for AB home position - // SERIAL_ECHOLNPAIR("homeposition A:", homeposition.a, " B:", homeposition.b); - inverse_kinematics(homeposition); - forward_kinematics_SCARA(delta.a, delta.b); - current_position[axis] = cartes[axis]; - #else - // MP_SCARA uses a Cartesian XY home position - // SERIAL_ECHOPGM("homeposition"); - // SERIAL_ECHOLNPAIR_P(SP_X_LBL, homeposition.x, SP_Y_LBL, homeposition.y); - current_position[axis] = homeposition[axis]; - #endif +#if ENABLED(AXEL_TPARA) + #include "endstops.h" + #include "../MarlinCore.h" +#endif + +float segments_per_second = TERN(AXEL_TPARA, TPARA_SEGMENTS_PER_SECOND, SCARA_SEGMENTS_PER_SECOND); + +#if EITHER(MORGAN_SCARA, MP_SCARA) + + static constexpr xy_pos_t scara_offset = { SCARA_OFFSET_X, SCARA_OFFSET_Y }; + + /** + * Morgan SCARA Forward Kinematics. Results in 'cartes'. + * Maths and first version by QHARLEY. + * Integrated into Marlin and slightly restructured by Joachim Cerny. + */ + void forward_kinematics(const float &a, const float &b) { + const float a_sin = sin(RADIANS(a)) * L1, + a_cos = cos(RADIANS(a)) * L1, + b_sin = sin(RADIANS(b + TERN0(MP_SCARA, a))) * L2, + b_cos = cos(RADIANS(b + TERN0(MP_SCARA, a))) * L2; + + cartes.x = a_cos + b_cos + scara_offset.x; // theta + cartes.y = a_sin + b_sin + scara_offset.y; // phi - // SERIAL_ECHOPGM("Cartesian"); - // SERIAL_ECHOLNPAIR_P(SP_X_LBL, current_position.x, SP_Y_LBL, current_position.y); - update_software_endstops(axis); + /* + DEBUG_ECHOLNPAIR( + "SCARA FK Angle a=", a, + " b=", b, + " a_sin=", a_sin, + " a_cos=", a_cos, + " b_sin=", b_sin, + " b_cos=", b_cos + ); + DEBUG_ECHOLNPAIR(" cartes (X,Y) = "(cartes.x, ", ", cartes.y, ")"); + //*/ } -} -static constexpr xy_pos_t scara_offset = { SCARA_OFFSET_X, SCARA_OFFSET_Y }; +#endif -/** - * Morgan SCARA Forward Kinematics. Results in 'cartes'. - * Maths and first version by QHARLEY. - * Integrated into Marlin and slightly restructured by Joachim Cerny. - */ -void forward_kinematics_SCARA(const float &a, const float &b) { - - const float a_sin = sin(RADIANS(a)) * L1, - a_cos = cos(RADIANS(a)) * L1, - b_sin = sin(RADIANS(b)) * L2, - b_cos = cos(RADIANS(b)) * L2; - - cartes.set(a_cos + b_cos + scara_offset.x, // theta - a_sin + b_sin + scara_offset.y); // theta+phi - - /* - SERIAL_ECHOLNPAIR( - "SCARA FK Angle a=", a, - " b=", b, - " a_sin=", a_sin, - " a_cos=", a_cos, - " b_sin=", b_sin, - " b_cos=", b_cos - ); - SERIAL_ECHOLNPAIR(" cartes (X,Y) = "(cartes.x, ", ", cartes.y, ")"); - //*/ -} +#if ENABLED(MORGAN_SCARA) -void inverse_kinematics(const xyz_pos_t &raw) { - - #if ENABLED(MORGAN_SCARA) - /** - * Morgan SCARA Inverse Kinematics. Results in 'delta'. - * - * See https://reprap.org/forum/read.php?185,283327 - * - * Maths and first version by QHARLEY. - * Integrated into Marlin and slightly restructured by Joachim Cerny. - */ + void scara_set_axis_is_at_home(const AxisEnum axis) { + if (axis == Z_AXIS) + current_position.z = Z_HOME_POS; + else { + // MORGAN_SCARA uses a Cartesian XY home position + xyz_pos_t homeposition = { X_HOME_POS, Y_HOME_POS, Z_HOME_POS }; + //DEBUG_ECHOLNPAIR_P(PSTR("homeposition X"), homeposition.x, SP_Y_LBL, homeposition.y); + + delta = homeposition; + forward_kinematics(delta.a, delta.b); + current_position[axis] = cartes[axis]; + + //DEBUG_ECHOLNPAIR_P(PSTR("Cartesian X"), current_position.x, SP_Y_LBL, current_position.y); + update_software_endstops(axis); + } + } + + /** + * Morgan SCARA Inverse Kinematics. Results are stored in 'delta'. + * + * See https://reprap.org/forum/read.php?185,283327 + * + * Maths and first version by QHARLEY. + * Integrated into Marlin and slightly restructured by Joachim Cerny. + */ + void inverse_kinematics(const xyz_pos_t &raw) { float C2, S2, SK1, SK2, THETA, PSI; // Translate SCARA to standard XY with scaling factor @@ -116,6 +111,8 @@ void inverse_kinematics(const xyz_pos_t &raw) { else C2 = (H2 - (L1_2 + L2_2)) / (2.0f * L1 * L2); + LIMIT(C2, -1, 1); + S2 = SQRT(1.0f - sq(C2)); // Unrotated Arm1 plus rotated Arm2 gives the distance from Center to End @@ -130,16 +127,41 @@ void inverse_kinematics(const xyz_pos_t &raw) { // Angle of Arm2 PSI = ATAN2(S2, C2); - delta.set(DEGREES(THETA), DEGREES(THETA + PSI), raw.z); + delta.set(DEGREES(THETA), DEGREES(PSI + TERN0(MORGAN_SCARA, THETA)), raw.z); /* DEBUG_POS("SCARA IK", raw); DEBUG_POS("SCARA IK", delta); - SERIAL_ECHOLNPAIR(" SCARA (x,y) ", sx, ",", sy, " C2=", C2, " S2=", S2, " Theta=", THETA, " Phi=", PHI); + DEBUG_ECHOLNPAIR(" SCARA (x,y) ", sx, ",", sy, " C2=", C2, " S2=", S2, " Theta=", THETA, " Psi=", PSI); //*/ + } + +#elif ENABLED(MP_SCARA) + + void scara_set_axis_is_at_home(const AxisEnum axis) { + if (axis == Z_AXIS) + current_position.z = Z_HOME_POS; + else { + // MP_SCARA uses arm angles for AB home position + #ifndef SCARA_OFFSET_THETA1 + #define SCARA_OFFSET_THETA1 12 // degrees + #endif + #ifndef SCARA_OFFSET_THETA2 + #define SCARA_OFFSET_THETA2 131 // degrees + #endif + ab_float_t homeposition = { SCARA_OFFSET_THETA1, SCARA_OFFSET_THETA2 }; + //DEBUG_ECHOLNPAIR("homeposition A:", homeposition.a, " B:", homeposition.b); + + inverse_kinematics(homeposition); + forward_kinematics(delta.a, delta.b); + current_position[axis] = cartes[axis]; - #else // MP_SCARA + //DEBUG_ECHOLNPAIR_P(PSTR("Cartesian X"), current_position.x, SP_Y_LBL, current_position.y); + update_software_endstops(axis); + } + } + void inverse_kinematics(const xyz_pos_t &raw) { const float x = raw.x, y = raw.y, c = HYPOT(x, y), THETA3 = ATAN2(y, x), THETA1 = THETA3 + ACOS((sq(c) + sq(L1) - sq(L2)) / (2.0f * c * L1)), @@ -152,12 +174,135 @@ void inverse_kinematics(const xyz_pos_t &raw) { DEBUG_POS("SCARA IK", delta); SERIAL_ECHOLNPAIR(" SCARA (x,y) ", x, ",", y," Theta1=", THETA1, " Theta2=", THETA2); //*/ + } - #endif // MP_SCARA -} +#elif ENABLED(AXEL_TPARA) + + static constexpr xyz_pos_t robot_offset = { TPARA_OFFSET_X, TPARA_OFFSET_Y, TPARA_OFFSET_Z }; + + void scara_set_axis_is_at_home(const AxisEnum axis) { + if (axis == Z_AXIS) + current_position.z = Z_HOME_POS; + else { + xyz_pos_t homeposition = { X_HOME_POS, Y_HOME_POS, Z_HOME_POS }; + //DEBUG_ECHOLNPAIR_P(PSTR("homeposition X"), homeposition.x, SP_Y_LBL, homeposition.y, SP_Z_LBL, homeposition.z); + + inverse_kinematics(homeposition); + forward_kinematics(delta.a, delta.b, delta.c); + current_position[axis] = cartes[axis]; + + //DEBUG_ECHOLNPAIR_P(PSTR("Cartesian X"), current_position.x, SP_Y_LBL, current_position.y); + update_software_endstops(axis); + } + } + + // Convert ABC inputs in degrees to XYZ outputs in mm + void forward_kinematics(const float &a, const float &b, const float &c) { + const float w = c - b, + r = L1 * cos(RADIANS(b)) + L2 * sin(RADIANS(w - (90 - b))), + x = r * cos(RADIANS(a)), + y = r * sin(RADIANS(a)), + rho2 = L1_2 + L2_2 - 2.0f * L1 * L2 * cos(RADIANS(w)); + + cartes = robot_offset + xyz_pos_t({ x, y, SQRT(rho2 - x * x - y * y) }); + } + + // Home YZ together, then X (or all at once). Based on quick_home_xy & home_delta + void home_TPARA() { + // Init the current position of all carriages to 0,0,0 + current_position.reset(); + destination.reset(); + sync_plan_position(); + + // Disable stealthChop if used. Enable diag1 pin on driver. + #if ENABLED(SENSORLESS_HOMING) + TERN_(X_SENSORLESS, sensorless_t stealth_states_x = start_sensorless_homing_per_axis(X_AXIS)); + TERN_(Y_SENSORLESS, sensorless_t stealth_states_y = start_sensorless_homing_per_axis(Y_AXIS)); + TERN_(Z_SENSORLESS, sensorless_t stealth_states_z = start_sensorless_homing_per_axis(Z_AXIS)); + #endif + + // const int x_axis_home_dir = x_home_dir(active_extruder); + + // const xy_pos_t pos { max_length(X_AXIS) , max_length(Y_AXIS) }; + // const float mlz = max_length(X_AXIS), + + // Move all carriages together linearly until an endstop is hit. + //do_blocking_move_to_xy_z(pos, mlz, homing_feedrate(Z_AXIS)); + + current_position.x = 0 ; + current_position.y = 0 ; + current_position.z = max_length(Z_AXIS) ; + line_to_current_position(homing_feedrate(Z_AXIS)); + planner.synchronize(); + + // Re-enable stealthChop if used. Disable diag1 pin on driver. + #if ENABLED(SENSORLESS_HOMING) + TERN_(X_SENSORLESS, end_sensorless_homing_per_axis(X_AXIS, stealth_states_x)); + TERN_(Y_SENSORLESS, end_sensorless_homing_per_axis(Y_AXIS, stealth_states_y)); + TERN_(Z_SENSORLESS, end_sensorless_homing_per_axis(Z_AXIS, stealth_states_z)); + #endif + + endstops.validate_homing_move(); + + // At least one motor has reached its endstop. + // Now re-home each motor separately. + homeaxis(A_AXIS); + homeaxis(C_AXIS); + homeaxis(B_AXIS); + + // Set all carriages to their home positions + // Do this here all at once for Delta, because + // XYZ isn't ABC. Applying this per-tower would + // give the impression that they are the same. + LOOP_XYZ(i) set_axis_is_at_home((AxisEnum)i); + + sync_plan_position(); + } + + void inverse_kinematics(const xyz_pos_t &raw) { + const xyz_pos_t spos = raw - robot_offset; + + const float RXY = SQRT(HYPOT2(spos.x, spos.y)), + RHO2 = NORMSQ(spos.x, spos.y, spos.z), + //RHO = SQRT(RHO2), + LSS = L1_2 + L2_2, + LM = 2.0f * L1 * L2, + + CG = (LSS - RHO2) / LM, + SG = SQRT(1 - POW(CG, 2)), // Method 2 + K1 = L1 - L2 * CG, + K2 = L2 * SG, + + // Angle of Body Joint + THETA = ATAN2(spos.y, spos.x), + + // Angle of Elbow Joint + //GAMMA = ACOS(CG), + GAMMA = ATAN2(SG, CG), // Method 2 + + // Angle of Shoulder Joint, elevation angle measured from horizontal (r+) + //PHI = asin(spos.z/RHO) + asin(L2 * sin(GAMMA) / RHO), + PHI = ATAN2(spos.z, RXY) + ATAN2(K2, K1), // Method 2 + + // Elbow motor angle measured from horizontal, same frame as shoulder (r+) + PSI = PHI + GAMMA; + + delta.set(DEGREES(THETA), DEGREES(PHI), DEGREES(PSI)); + + //SERIAL_ECHOLNPAIR(" SCARA (x,y,z) ", spos.x , ",", spos.y, ",", spos.z, " Rho=", RHO, " Rho2=", RHO2, " Theta=", THETA, " Phi=", PHI, " Psi=", PSI, " Gamma=", GAMMA); + } + +#endif void scara_report_positions() { - SERIAL_ECHOLNPAIR("SCARA Theta:", planner.get_axis_position_degrees(A_AXIS), " Psi+Theta:", planner.get_axis_position_degrees(B_AXIS)); + SERIAL_ECHOLNPAIR("SCARA Theta:", planner.get_axis_position_degrees(A_AXIS) + #if ENABLED(AXEL_TPARA) + , " Phi:", planner.get_axis_position_degrees(B_AXIS) + , " Psi:", planner.get_axis_position_degrees(C_AXIS) + #else + , " Psi" TERN_(MORGAN_SCARA, "+Theta") ":", planner.get_axis_position_degrees(B_AXIS) + #endif + ); SERIAL_EOL(); } diff --git a/Marlin/src/module/scara.h b/Marlin/src/module/scara.h index e2acaf30822c..d24a4110fdcd 100644 --- a/Marlin/src/module/scara.h +++ b/Marlin/src/module/scara.h @@ -27,16 +27,27 @@ #include "../core/macros.h" -extern float delta_segments_per_second; +extern float segments_per_second; -// Float constants for SCARA calculations -float constexpr L1 = SCARA_LINKAGE_1, L2 = SCARA_LINKAGE_2, - L1_2 = sq(float(L1)), L1_2_2 = 2.0 * L1_2, - L2_2 = sq(float(L2)); +#if ENABLED(AXEL_TPARA) -void scara_set_axis_is_at_home(const AxisEnum axis); + float constexpr L1 = TPARA_LINKAGE_1, L2 = TPARA_LINKAGE_2, // Float constants for Robot arm calculations + L1_2 = sq(float(L1)), L1_2_2 = 2.0 * L1_2, + L2_2 = sq(float(L2)); -void inverse_kinematics(const xyz_pos_t &raw); -void forward_kinematics_SCARA(const float &a, const float &b); + void forward_kinematics(const float &a, const float &b, const float &c); + void home_TPARA(); + +#else + + float constexpr L1 = SCARA_LINKAGE_1, L2 = SCARA_LINKAGE_2, // Float constants for SCARA calculations + L1_2 = sq(float(L1)), L1_2_2 = 2.0 * L1_2, + L2_2 = sq(float(L2)); + void forward_kinematics(const float &a, const float &b); + +#endif + +void inverse_kinematics(const xyz_pos_t &raw); +void scara_set_axis_is_at_home(const AxisEnum axis); void scara_report_positions(); diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 7fb378191e2c..c82ed0eb8f3f 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -279,7 +279,7 @@ typedef struct SettingsDataStruct { abc_float_t delta_endstop_adj; // M666 X Y Z float delta_radius, // M665 R delta_diagonal_rod, // M665 L - delta_segments_per_second; // M665 S + segments_per_second; // M665 S abc_float_t delta_tower_angle_trim, // M665 X Y Z delta_diagonal_rod_trim; // M665 A B C #elif HAS_EXTRA_ENDSTOPS @@ -318,6 +318,11 @@ typedef struct SettingsDataStruct { // PID_t bedPID; // M304 PID / M303 E-1 U + // + // PIDTEMPCHAMBER + // + PID_t chamberPID; // M309 PID / M303 E-2 U + // // User-defined Thermistors // @@ -835,7 +840,7 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(delta_endstop_adj); // 3 floats EEPROM_WRITE(delta_radius); // 1 float EEPROM_WRITE(delta_diagonal_rod); // 1 float - EEPROM_WRITE(delta_segments_per_second); // 1 float + EEPROM_WRITE(segments_per_second); // 1 float EEPROM_WRITE(delta_tower_angle_trim); // 3 floats EEPROM_WRITE(delta_diagonal_rod_trim); // 3 floats @@ -926,6 +931,25 @@ void MarlinSettings::postprocess() { EEPROM_WRITE(bed_pid); } + // + // PIDTEMPCHAMBER + // + { + _FIELD_TEST(chamberPID); + + const PID_t chamber_pid = { + #if DISABLED(PIDTEMPCHAMBER) + NAN, NAN, NAN + #else + // Store the unscaled PID values + thermalManager.temp_chamber.pid.Kp, + unscalePID_i(thermalManager.temp_chamber.pid.Ki), + unscalePID_d(thermalManager.temp_chamber.pid.Kd) + #endif + }; + EEPROM_WRITE(chamber_pid); + } + // // User-defined Thermistors // @@ -1697,7 +1721,7 @@ void MarlinSettings::postprocess() { EEPROM_READ(delta_endstop_adj); // 3 floats EEPROM_READ(delta_radius); // 1 float EEPROM_READ(delta_diagonal_rod); // 1 float - EEPROM_READ(delta_segments_per_second); // 1 float + EEPROM_READ(segments_per_second); // 1 float EEPROM_READ(delta_tower_angle_trim); // 3 floats EEPROM_READ(delta_diagonal_rod_trim); // 3 floats @@ -1787,6 +1811,22 @@ void MarlinSettings::postprocess() { #endif } + // + // Heated Chamber PID + // + { + PID_t pid; + EEPROM_READ(pid); + #if ENABLED(PIDTEMPCHAMBER) + if (!validating && !isnan(pid.Kp)) { + // Scale PID values since EEPROM values are unscaled + thermalManager.temp_chamber.pid.Kp = pid.Kp; + thermalManager.temp_chamber.pid.Ki = scalePID_i(pid.Ki); + thermalManager.temp_chamber.pid.Kd = scalePID_d(pid.Kd); + } + #endif + } + // // User-defined Thermistors // @@ -2671,7 +2711,7 @@ void MarlinSettings::reset() { delta_endstop_adj = adj; delta_radius = DELTA_RADIUS; delta_diagonal_rod = DELTA_DIAGONAL_ROD; - delta_segments_per_second = DELTA_SEGMENTS_PER_SECOND; + segments_per_second = DELTA_SEGMENTS_PER_SECOND; delta_tower_angle_trim = dta; delta_diagonal_rod_trim = ddr; #endif @@ -2811,6 +2851,16 @@ void MarlinSettings::reset() { thermalManager.temp_bed.pid.Kd = scalePID_d(DEFAULT_bedKd); #endif + // + // Heated Chamber PID + // + + #if ENABLED(PIDTEMPCHAMBER) + thermalManager.temp_chamber.pid.Kp = DEFAULT_chamberKp; + thermalManager.temp_chamber.pid.Ki = scalePID_i(DEFAULT_chamberKi); + thermalManager.temp_chamber.pid.Kd = scalePID_d(DEFAULT_chamberKd); + #endif + // // User-Defined Thermistors // @@ -2940,7 +2990,7 @@ void MarlinSettings::reset() { if (!repl) { SERIAL_ECHO_START(); SERIAL_ECHOPGM("; "); - serialprintPGM(pstr); + SERIAL_ECHOPGM_P(pstr); if (eol) SERIAL_EOL(); } } @@ -2957,7 +3007,7 @@ void MarlinSettings::reset() { SERIAL_ECHOPGM(" M569 S1"); if (etc) { SERIAL_CHAR(' '); - serialprintPGM(etc); + SERIAL_ECHOPGM_P(etc); } if (newLine) SERIAL_EOL(); } @@ -2975,7 +3025,7 @@ void MarlinSettings::reset() { #endif inline void say_units(const bool colon) { - serialprintPGM( + SERIAL_ECHOPGM_P( #if ENABLED(INCH_MODE_SUPPORT) parser.linear_unit_factor != 1.0 ? PSTR(" (in)") : #endif @@ -3016,7 +3066,7 @@ void MarlinSettings::reset() { SERIAL_ECHOPGM(" M149 "); SERIAL_CHAR(parser.temp_units_code()); SERIAL_ECHOPGM(" ; Units in "); - serialprintPGM(parser.temp_units_name()); + SERIAL_ECHOPGM_P(parser.temp_units_name()); #else SERIAL_ECHOLNPGM(" M149 C ; Units in Celsius"); #endif @@ -3204,12 +3254,12 @@ void MarlinSettings::reset() { LOOP_L_N(py, GRID_MAX_POINTS_Y) { LOOP_L_N(px, GRID_MAX_POINTS_X) { CONFIG_ECHO_START(); - SERIAL_ECHOPAIR_P(PSTR(" G29 S3 I"), px, PSTR(" J"), py); + SERIAL_ECHOPAIR(" G29 S3 I", px, " J", py); SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, LINEAR_UNIT(mbl.z_values[px][py]), 5); } } CONFIG_ECHO_START(); - SERIAL_ECHOLNPAIR_F_P(PSTR(" G29 S4 Z"), LINEAR_UNIT(mbl.z_offset), 5); + SERIAL_ECHOLNPAIR_F(" G29 S4 Z", LINEAR_UNIT(mbl.z_offset), 5); } #elif ENABLED(AUTO_BED_LEVELING_UBL) @@ -3270,7 +3320,7 @@ void MarlinSettings::reset() { CONFIG_ECHO_HEADING("SCARA settings: S P T"); CONFIG_ECHO_START(); SERIAL_ECHOLNPAIR_P( - PSTR(" M665 S"), delta_segments_per_second + PSTR(" M665 S"), segments_per_second , SP_P_STR, scara_home_offset.a , SP_T_STR, scara_home_offset.b , SP_Z_STR, LINEAR_UNIT(scara_home_offset.z) @@ -3292,7 +3342,7 @@ void MarlinSettings::reset() { PSTR(" M665 L"), LINEAR_UNIT(delta_diagonal_rod) , PSTR(" R"), LINEAR_UNIT(delta_radius) , PSTR(" H"), LINEAR_UNIT(delta_height) - , PSTR(" S"), delta_segments_per_second + , PSTR(" S"), segments_per_second , SP_X_STR, LINEAR_UNIT(delta_tower_angle_trim.a) , SP_Y_STR, LINEAR_UNIT(delta_tower_angle_trim.b) , SP_Z_STR, LINEAR_UNIT(delta_tower_angle_trim.c) @@ -3386,7 +3436,16 @@ void MarlinSettings::reset() { ); #endif - #endif // PIDTEMP || PIDTEMPBED + #if ENABLED(PIDTEMPCHAMBER) + CONFIG_ECHO_START(); + SERIAL_ECHOLNPAIR( + " M309 P", thermalManager.temp_chamber.pid.Kp + , " I", unscalePID_i(thermalManager.temp_chamber.pid.Ki) + , " D", unscalePID_d(thermalManager.temp_chamber.pid.Kd) + ); + #endif + + #endif // PIDTEMP || PIDTEMPBED || PIDTEMPCHAMBER #if HAS_USER_THERMISTORS CONFIG_ECHO_HEADING("User thermistors:"); diff --git a/Marlin/src/module/stepper/indirection.h b/Marlin/src/module/stepper/indirection.h index 4346e9d6cccf..e72d793ca6bc 100644 --- a/Marlin/src/module/stepper/indirection.h +++ b/Marlin/src/module/stepper/indirection.h @@ -862,8 +862,8 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset #define ENABLE_AXIS_Z() if (SHOULD_ENABLE(z)) { ENABLE_STEPPER_Z(); ENABLE_STEPPER_Z2(); ENABLE_STEPPER_Z3(); ENABLE_STEPPER_Z4(); AFTER_CHANGE(z, true); } #define DISABLE_AXIS_Z() if (SHOULD_DISABLE(z)) { DISABLE_STEPPER_Z(); DISABLE_STEPPER_Z2(); DISABLE_STEPPER_Z3(); DISABLE_STEPPER_Z4(); AFTER_CHANGE(z, false); set_axis_untrusted(Z_AXIS); Z_RESET(); } -#ifdef Z_AFTER_DEACTIVATE - #define Z_RESET() do{ current_position.z = Z_AFTER_DEACTIVATE; sync_plan_position(); }while(0) +#ifdef Z_IDLE_HEIGHT + #define Z_RESET() do{ current_position.z = Z_IDLE_HEIGHT; sync_plan_position(); }while(0) #else #define Z_RESET() #endif diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index edd76df3b7f2..be98972b7712 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -371,10 +371,8 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, #ifdef CHAMBER_MAXTEMP int16_t Temperature::maxtemp_raw_CHAMBER = TEMP_SENSOR_CHAMBER_RAW_HI_TEMP; #endif - #if WATCH_CHAMBER - chamber_watch_t Temperature::watch_chamber{0}; - #endif - millis_t Temperature::next_chamber_check_ms; + TERN_(WATCH_CHAMBER, chamber_watch_t Temperature::watch_chamber{0}); + IF_DISABLED(PIDTEMPCHAMBER, millis_t Temperature::next_chamber_check_ms); #endif // HAS_HEATED_CHAMBER #endif // HAS_TEMP_CHAMBER @@ -382,11 +380,6 @@ const char str_t_thermal_runaway[] PROGMEM = STR_T_THERMAL_RUNAWAY, probe_info_t Temperature::temp_probe; // = { 0 } #endif -// Initialized by settings.load() -#if ENABLED(PIDTEMP) - //hotend_pid_t Temperature::pid[HOTENDS]; -#endif - #if ENABLED(PREVENT_COLD_EXTRUSION) bool Temperature::allow_cold_extrude = false; int16_t Temperature::extrude_min_temp = EXTRUDE_MINTEMP; @@ -485,41 +478,44 @@ volatile bool Temperature::raw_temps_ready = false; millis_t next_temp_ms = millis(), t1 = next_temp_ms, t2 = next_temp_ms; long t_high = 0, t_low = 0; - long bias, d; PID_t tune_pid = { 0, 0, 0 }; float maxT = 0, minT = 10000; const bool isbed = (heater_id == H_BED); + const bool ischamber = (heater_id == H_CHAMBER); - #if HAS_PID_FOR_BOTH - #define GHV(B,H) (isbed ? (B) : (H)) - #define SHV(B,H) do{ if (isbed) temp_bed.soft_pwm_amount = B; else temp_hotend[heater_id].soft_pwm_amount = H; }while(0) - #define ONHEATINGSTART() (isbed ? printerEventLEDs.onBedHeatingStart() : printerEventLEDs.onHotendHeatingStart()) - #define ONHEATING(S,C,T) (isbed ? printerEventLEDs.onBedHeating(S,C,T) : printerEventLEDs.onHotendHeating(S,C,T)) - #elif ENABLED(PIDTEMPBED) - #define GHV(B,H) B - #define SHV(B,H) (temp_bed.soft_pwm_amount = B) - #define ONHEATINGSTART() printerEventLEDs.onBedHeatingStart() - #define ONHEATING(S,C,T) printerEventLEDs.onBedHeating(S,C,T) + #if ENABLED(PIDTEMPCHAMBER) + #define C_TERN(T,A,B) ((T) ? (A) : (B)) #else - #define GHV(B,H) H - #define SHV(B,H) (temp_hotend[heater_id].soft_pwm_amount = H) - #define ONHEATINGSTART() printerEventLEDs.onHotendHeatingStart() - #define ONHEATING(S,C,T) printerEventLEDs.onHotendHeating(S,C,T) + #define C_TERN(T,A,B) (B) #endif - #define WATCH_PID BOTH(WATCH_BED, PIDTEMPBED) || BOTH(WATCH_HOTENDS, PIDTEMP) + #if ENABLED(PIDTEMPBED) + #define B_TERN(T,A,B) ((T) ? (A) : (B)) + #else + #define B_TERN(T,A,B) (B) + #endif + #define GHV(C,B,H) C_TERN(ischamber, C, B_TERN(isbed, B, H)) + #define SHV(V) C_TERN(ischamber, temp_chamber.soft_pwm_amount = V, B_TERN(isbed, temp_bed.soft_pwm_amount = V, temp_hotend[heater_id].soft_pwm_amount = V)) + #define ONHEATINGSTART() C_TERN(ischamber, printerEventLEDs.onChamberHeatingStart(), B_TERN(isbed, printerEventLEDs.onBedHeatingStart(), printerEventLEDs.onHotendHeatingStart())) + #define ONHEATING(S,C,T) C_TERN(ischamber, printerEventLEDs.onChamberHeating(S,C,T), B_TERN(isbed, printerEventLEDs.onBedHeating(S,C,T), printerEventLEDs.onHotendHeating(S,C,T))) + + #define WATCH_PID BOTH(WATCH_CHAMBER, PIDTEMPCHAMBER) || BOTH(WATCH_BED, PIDTEMPBED) || BOTH(WATCH_HOTENDS, PIDTEMP) #if WATCH_PID - #if ALL(THERMAL_PROTECTION_HOTENDS, PIDTEMP, THERMAL_PROTECTION_BED, PIDTEMPBED) - #define GTV(B,H) (isbed ? (B) : (H)) - #elif BOTH(THERMAL_PROTECTION_HOTENDS, PIDTEMP) - #define GTV(B,H) (H) + #if BOTH(THERMAL_PROTECTION_CHAMBER, PIDTEMPCHAMBER) + #define C_GTV(T,A,B) ((T) ? (A) : (B)) #else - #define GTV(B,H) (B) + #define C_GTV(T,A,B) (B) #endif - const uint16_t watch_temp_period = GTV(WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD); - const uint8_t watch_temp_increase = GTV(WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE); - const float watch_temp_target = target - float(watch_temp_increase + GTV(TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1); + #if BOTH(THERMAL_PROTECTION_BED, PIDTEMPBED) + #define B_GTV(T,A,B) ((T) ? (A) : (B)) + #else + #define B_GTV(T,A,B) (B) + #endif + #define GTV(C,B,H) C_GTV(ischamber, C, B_GTV(isbed, B, H)) + const uint16_t watch_temp_period = GTV(WATCH_CHAMBER_TEMP_PERIOD, WATCH_BED_TEMP_PERIOD, WATCH_TEMP_PERIOD); + const uint8_t watch_temp_increase = GTV(WATCH_CHAMBER_TEMP_INCREASE, WATCH_BED_TEMP_INCREASE, WATCH_TEMP_INCREASE); + const float watch_temp_target = target - float(watch_temp_increase + GTV(TEMP_CHAMBER_HYSTERESIS, TEMP_BED_HYSTERESIS, TEMP_HYSTERESIS) + 1); millis_t temp_change_ms = next_temp_ms + SEC_TO_MS(watch_temp_period); float next_watch_temp = 0.0; bool heated = false; @@ -527,7 +523,7 @@ volatile bool Temperature::raw_temps_ready = false; TERN_(HAS_AUTO_FAN, next_auto_fan_check_ms = next_temp_ms + 2500UL); - if (target > GHV(BED_MAX_TARGET, temp_range[heater_id].maxtemp - HOTEND_OVERSHOOT)) { + if (target > GHV(CHAMBER_MAX_TARGET, BED_MAX_TARGET, temp_range[heater_id].maxtemp - HOTEND_OVERSHOOT)) { SERIAL_ECHOLNPGM(STR_PID_TEMP_TOO_HIGH); TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TEMP_TOO_HIGH)); return; @@ -538,10 +534,11 @@ volatile bool Temperature::raw_temps_ready = false; disable_all_heaters(); TERN_(AUTO_POWER_CONTROL, powerManager.power_on()); - SHV(bias = d = (MAX_BED_POWER) >> 1, bias = d = (PID_MAX) >> 1); + long bias = GHV(MAX_CHAMBER_POWER, MAX_BED_POWER, PID_MAX) >> 1, d = bias; + SHV(bias); #if ENABLED(PRINTER_EVENT_LEDS) - const float start_temp = GHV(temp_bed.celsius, temp_hotend[heater_id].celsius); + const float start_temp = GHV(temp_chamber.celsius, temp_bed.celsius, temp_hotend[heater_id].celsius); LEDColor color = ONHEATINGSTART(); #endif @@ -557,7 +554,7 @@ volatile bool Temperature::raw_temps_ready = false; updateTemperaturesFromRawValues(); // Get the current temperature and constrain it - current_temp = GHV(temp_bed.celsius, temp_hotend[heater_id].celsius); + current_temp = GHV(temp_chamber.celsius, temp_bed.celsius, temp_hotend[heater_id].celsius); NOLESS(maxT, current_temp); NOMORE(minT, current_temp); @@ -572,67 +569,46 @@ volatile bool Temperature::raw_temps_ready = false; } #endif - if (heating && current_temp > target) { - if (ELAPSED(ms, t2 + 5000UL)) { - heating = false; - SHV((bias - d) >> 1, (bias - d) >> 1); - t1 = ms; - t_high = t1 - t2; - maxT = target; - } + if (heating && current_temp > target && ELAPSED(ms, t2 + 5000UL)) { + heating = false; + SHV((bias - d) >> 1); + t1 = ms; + t_high = t1 - t2; + maxT = target; } - if (!heating && current_temp < target) { - if (ELAPSED(ms, t1 + 5000UL)) { - heating = true; - t2 = ms; - t_low = t2 - t1; - if (cycles > 0) { - const long max_pow = GHV(MAX_BED_POWER, PID_MAX); - bias += (d * (t_high - t_low)) / (t_low + t_high); - LIMIT(bias, 20, max_pow - 20); - d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias; - - SERIAL_ECHOPAIR(STR_BIAS, bias, STR_D_COLON, d, STR_T_MIN, minT, STR_T_MAX, maxT); - if (cycles > 2) { - const float Ku = (4.0f * d) / (float(M_PI) * (maxT - minT) * 0.5f), - Tu = float(t_low + t_high) * 0.001f, - pf = isbed ? 0.2f : 0.6f, - df = isbed ? 1.0f / 3.0f : 1.0f / 8.0f; - - SERIAL_ECHOPAIR(STR_KU, Ku, STR_TU, Tu); - if (isbed) { // Do not remove this otherwise PID autotune won't work right for the bed! - tune_pid.Kp = Ku * 0.2f; - tune_pid.Ki = 2 * tune_pid.Kp / Tu; - tune_pid.Kd = tune_pid.Kp * Tu / 3; - SERIAL_ECHOLNPGM("\n" " No overshoot"); // Works far better for the bed. Classic and some have bad ringing. - SERIAL_ECHOLNPAIR(STR_KP, tune_pid.Kp, STR_KI, tune_pid.Ki, STR_KD, tune_pid.Kd); - } - else { - tune_pid.Kp = Ku * pf; - tune_pid.Kd = tune_pid.Kp * Tu * df; - tune_pid.Ki = 2 * tune_pid.Kp / Tu; - SERIAL_ECHOLNPGM("\n" STR_CLASSIC_PID); - SERIAL_ECHOLNPAIR(STR_KP, tune_pid.Kp, STR_KI, tune_pid.Ki, STR_KD, tune_pid.Kd); - } - - /** - tune_pid.Kp = 0.33 * Ku; - tune_pid.Ki = tune_pid.Kp / Tu; - tune_pid.Kd = tune_pid.Kp * Tu / 3; - SERIAL_ECHOLNPGM(" Some overshoot"); - SERIAL_ECHOLNPAIR(" Kp: ", tune_pid.Kp, " Ki: ", tune_pid.Ki, " Kd: ", tune_pid.Kd, " No overshoot"); - tune_pid.Kp = 0.2 * Ku; - tune_pid.Ki = 2 * tune_pid.Kp / Tu; - tune_pid.Kd = tune_pid.Kp * Tu / 3; - SERIAL_ECHOPAIR(" Kp: ", tune_pid.Kp, " Ki: ", tune_pid.Ki, " Kd: ", tune_pid.Kd); - */ - } + if (!heating && current_temp < target && ELAPSED(ms, t1 + 5000UL)) { + heating = true; + t2 = ms; + t_low = t2 - t1; + if (cycles > 0) { + const long max_pow = GHV(MAX_CHAMBER_POWER, MAX_BED_POWER, PID_MAX); + bias += (d * (t_high - t_low)) / (t_low + t_high); + LIMIT(bias, 20, max_pow - 20); + d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias; + + SERIAL_ECHOPAIR(STR_BIAS, bias, STR_D_COLON, d, STR_T_MIN, minT, STR_T_MAX, maxT); + if (cycles > 2) { + const float Ku = (4.0f * d) / (float(M_PI) * (maxT - minT) * 0.5f), + Tu = float(t_low + t_high) * 0.001f, + pf = ischamber ? 0.2f : (isbed ? 0.2f : 0.6f), + df = ischamber ? 1.0f / 3.0f : (isbed ? 1.0f / 3.0f : 1.0f / 8.0f); + + tune_pid.Kp = Ku * pf; + tune_pid.Ki = tune_pid.Kp * 2.0f / Tu; + tune_pid.Kd = tune_pid.Kp * Tu * df; + + SERIAL_ECHOLNPAIR(STR_KU, Ku, STR_TU, Tu); + if (ischamber || isbed) + SERIAL_ECHOLNPGM(" No overshoot"); + else + SERIAL_ECHOLNPGM(STR_CLASSIC_PID); + SERIAL_ECHOLNPAIR(STR_KP, tune_pid.Kp, STR_KI, tune_pid.Ki, STR_KD, tune_pid.Kd); } - SHV((bias + d) >> 1, (bias + d) >> 1); - cycles++; - minT = target; } + SHV((bias + d) >> 1); + cycles++; + minT = target; } } @@ -649,14 +625,14 @@ volatile bool Temperature::raw_temps_ready = false; // Report heater states every 2 seconds if (ELAPSED(ms, next_temp_ms)) { #if HAS_TEMP_SENSOR - print_heater_states(isbed ? active_extruder : heater_id); + print_heater_states(ischamber ? active_extruder : (isbed ? active_extruder : heater_id)); SERIAL_EOL(); #endif next_temp_ms = ms + 2000UL; // Make sure heating is actually working #if WATCH_PID - if (BOTH(WATCH_BED, WATCH_HOTENDS) || isbed == DISABLED(WATCH_HOTENDS)) { + if (BOTH(WATCH_BED, WATCH_HOTENDS) || isbed == DISABLED(WATCH_HOTENDS) || ischamber == DISABLED(WATCH_HOTENDS)) { if (!heated) { // If not yet reached target... if (current_temp > next_watch_temp) { // Over the watch temp? next_watch_temp = current_temp + watch_temp_increase; // - set the next temp to watch for @@ -686,43 +662,47 @@ volatile bool Temperature::raw_temps_ready = false; if (cycles > ncycles && cycles > 2) { SERIAL_ECHOLNPGM(STR_PID_AUTOTUNE_FINISHED); - #if HAS_PID_FOR_BOTH - const char * const estring = GHV(PSTR("bed"), NUL_STR); - say_default_(); serialprintPGM(estring); SERIAL_ECHOLNPAIR("Kp ", tune_pid.Kp); - say_default_(); serialprintPGM(estring); SERIAL_ECHOLNPAIR("Ki ", tune_pid.Ki); - say_default_(); serialprintPGM(estring); SERIAL_ECHOLNPAIR("Kd ", tune_pid.Kd); - #elif ENABLED(PIDTEMP) + #if EITHER(PIDTEMPBED, PIDTEMPCHAMBER) + PGM_P const estring = GHV(PSTR("chamber"), PSTR("bed"), NUL_STR); + say_default_(); SERIAL_ECHOPGM_P(estring); SERIAL_ECHOLNPAIR("Kp ", tune_pid.Kp); + say_default_(); SERIAL_ECHOPGM_P(estring); SERIAL_ECHOLNPAIR("Ki ", tune_pid.Ki); + say_default_(); SERIAL_ECHOPGM_P(estring); SERIAL_ECHOLNPAIR("Kd ", tune_pid.Kd); + #else say_default_(); SERIAL_ECHOLNPAIR("Kp ", tune_pid.Kp); say_default_(); SERIAL_ECHOLNPAIR("Ki ", tune_pid.Ki); say_default_(); SERIAL_ECHOLNPAIR("Kd ", tune_pid.Kd); - #else - say_default_(); SERIAL_ECHOLNPAIR("bedKp ", tune_pid.Kp); - say_default_(); SERIAL_ECHOLNPAIR("bedKi ", tune_pid.Ki); - say_default_(); SERIAL_ECHOLNPAIR("bedKd ", tune_pid.Kd); #endif - #define _SET_BED_PID() do { \ - temp_bed.pid.Kp = tune_pid.Kp; \ - temp_bed.pid.Ki = scalePID_i(tune_pid.Ki); \ - temp_bed.pid.Kd = scalePID_d(tune_pid.Kd); \ - }while(0) + auto _set_hotend_pid = [](const uint8_t e, const PID_t &in_pid) { + #if ENABLED(PIDTEMP) + PID_PARAM(Kp, e) = in_pid.Kp; + PID_PARAM(Ki, e) = scalePID_i(in_pid.Ki); + PID_PARAM(Kd, e) = scalePID_d(in_pid.Kd); + updatePID(); + #else + UNUSED(e); UNUSED(in_pid); + #endif + }; - #define _SET_EXTRUDER_PID() do { \ - PID_PARAM(Kp, heater_id) = tune_pid.Kp; \ - PID_PARAM(Ki, heater_id) = scalePID_i(tune_pid.Ki); \ - PID_PARAM(Kd, heater_id) = scalePID_d(tune_pid.Kd); \ - updatePID(); }while(0) + #if ENABLED(PIDTEMPBED) + auto _set_bed_pid = [](const PID_t &in_pid) { + temp_bed.pid.Kp = in_pid.Kp; + temp_bed.pid.Ki = scalePID_i(in_pid.Ki); + temp_bed.pid.Kd = scalePID_d(in_pid.Kd); + }; + #endif + + #if ENABLED(PIDTEMPCHAMBER) + auto _set_chamber_pid = [](const PID_t &in_pid) { + temp_chamber.pid.Kp = in_pid.Kp; + temp_chamber.pid.Ki = scalePID_i(in_pid.Ki); + temp_chamber.pid.Kd = scalePID_d(in_pid.Kd); + }; + #endif // Use the result? (As with "M303 U1") - if (set_result) { - #if HAS_PID_FOR_BOTH - if (isbed) _SET_BED_PID(); else _SET_EXTRUDER_PID(); - #elif ENABLED(PIDTEMP) - _SET_EXTRUDER_PID(); - #else - _SET_BED_PID(); - #endif - } + if (set_result) + GHV(_set_chamber_pid(tune_pid), _set_bed_pid(tune_pid), _set_hotend_pid(heater_id, tune_pid)); TERN_(PRINTER_EVENT_LEDS, printerEventLEDs.onPidTuningDone(color)); @@ -888,7 +868,7 @@ void Temperature::_temp_error(const heater_id_t heater_id, PGM_P const serial_ms if (IsRunning() && TERN1(BOGUS_TEMPERATURE_GRACE_PERIOD, killed == 2)) { SERIAL_ERROR_START(); - serialprintPGM(serial_msg); + SERIAL_ECHOPGM_P(serial_msg); SERIAL_ECHOPGM(STR_STOPPED_HEATER); if (heater_id >= 0) SERIAL_ECHO(heater_id); @@ -939,10 +919,11 @@ void Temperature::min_temp_error(const heater_id_t heater_id) { _temp_error(heater_id, PSTR(STR_T_MINTEMP), GET_TEXT(MSG_ERR_MINTEMP)); } +#if ANY(PID_DEBUG, PID_BED_DEBUG, PID_CHAMBER_DEBUG) + bool Temperature::pid_debug_flag; // = 0 +#endif + #if HAS_HOTEND - #if ENABLED(PID_DEBUG) - extern bool pid_debug_flag; - #endif float Temperature::get_pid_output_hotend(const uint8_t E_NAME) { const uint8_t ee = HOTEND_INDEX; @@ -1023,23 +1004,18 @@ void Temperature::min_temp_error(const heater_id_t heater_id) { #if ENABLED(PID_DEBUG) if (ee == active_extruder && pid_debug_flag) { - SERIAL_ECHO_START(); - SERIAL_ECHOPAIR(STR_PID_DEBUG, ee, STR_PID_DEBUG_INPUT, temp_hotend[ee].celsius, STR_PID_DEBUG_OUTPUT, pid_output); - #if DISABLED(PID_OPENLOOP) - { - SERIAL_ECHOPAIR( - STR_PID_DEBUG_PTERM, work_pid[ee].Kp, - STR_PID_DEBUG_ITERM, work_pid[ee].Ki, - STR_PID_DEBUG_DTERM, work_pid[ee].Kd + SERIAL_ECHO_MSG(STR_PID_DEBUG, ee, STR_PID_DEBUG_INPUT, temp_hotend[ee].celsius, STR_PID_DEBUG_OUTPUT, pid_output + #if DISABLED(PID_OPENLOOP) + , STR_PID_DEBUG_PTERM, work_pid[ee].Kp + , STR_PID_DEBUG_ITERM, work_pid[ee].Ki + , STR_PID_DEBUG_DTERM, work_pid[ee].Kd #if ENABLED(PID_EXTRUSION_SCALING) , STR_PID_DEBUG_CTERM, work_pid[ee].Kc #endif - ); - } - #endif - SERIAL_EOL(); + #endif + ); } - #endif // PID_DEBUG + #endif #else // No PID enabled @@ -1099,13 +1075,76 @@ void Temperature::min_temp_error(const heater_id_t heater_id) { #endif // PID_OPENLOOP #if ENABLED(PID_BED_DEBUG) + if (pid_debug_flag) { + SERIAL_ECHO_MSG( + " PID_BED_DEBUG : Input ", temp_bed.celsius, " Output ", pid_output + #if DISABLED(PID_OPENLOOP) + , STR_PID_DEBUG_PTERM, work_pid.Kp + , STR_PID_DEBUG_ITERM, work_pid.Ki + , STR_PID_DEBUG_DTERM, work_pid.Kd + #endif + ); + } + #endif + + return pid_output; + } + +#endif // PIDTEMPBED + +#if ENABLED(PIDTEMPCHAMBER) + + float Temperature::get_pid_output_chamber() { + + #if DISABLED(PID_OPENLOOP) + + static PID_t work_pid{0}; + static float temp_iState = 0, temp_dState = 0; + static bool pid_reset = true; + float pid_output = 0; + const float max_power_over_i_gain = float(MAX_CHAMBER_POWER) / temp_chamber.pid.Ki - float(MIN_CHAMBER_POWER), + pid_error = temp_chamber.target - temp_chamber.celsius; + + if (!temp_chamber.target || pid_error < -(PID_FUNCTIONAL_RANGE)) { + pid_output = 0; + pid_reset = true; + } + else if (pid_error > PID_FUNCTIONAL_RANGE) { + pid_output = MAX_CHAMBER_POWER; + pid_reset = true; + } + else { + if (pid_reset) { + temp_iState = 0.0; + work_pid.Kd = 0.0; + pid_reset = false; + } + + temp_iState = constrain(temp_iState + pid_error, 0, max_power_over_i_gain); + + work_pid.Kp = temp_chamber.pid.Kp * pid_error; + work_pid.Ki = temp_chamber.pid.Ki * temp_iState; + work_pid.Kd = work_pid.Kd + PID_K2 * (temp_chamber.pid.Kd * (temp_dState - temp_chamber.celsius) - work_pid.Kd); + + temp_dState = temp_chamber.celsius; + + pid_output = constrain(work_pid.Kp + work_pid.Ki + work_pid.Kd + float(MIN_CHAMBER_POWER), 0, MAX_CHAMBER_POWER); + } + + #else // PID_OPENLOOP + + const float pid_output = constrain(temp_chamber.target, 0, MAX_CHAMBER_POWER); + + #endif // PID_OPENLOOP + + #if ENABLED(PID_CHAMBER_DEBUG) { SERIAL_ECHO_MSG( - " PID_BED_DEBUG : Input ", temp_bed.celsius, " Output ", pid_output, + " PID_CHAMBER_DEBUG : Input ", temp_chamber.celsius, " Output ", pid_output #if DISABLED(PID_OPENLOOP) - STR_PID_DEBUG_PTERM, work_pid.Kp, - STR_PID_DEBUG_ITERM, work_pid.Ki, - STR_PID_DEBUG_DTERM, work_pid.Kd, + , STR_PID_DEBUG_PTERM, work_pid.Kp + , STR_PID_DEBUG_ITERM, work_pid.Ki + , STR_PID_DEBUG_DTERM, work_pid.Kd #endif ); } @@ -1114,7 +1153,7 @@ void Temperature::min_temp_error(const heater_id_t heater_id) { return pid_output; } -#endif // PIDTEMPBED +#endif // PIDTEMPCHAMBER /** * Manage heating activities for extruder hot-ends and a heated bed @@ -1363,42 +1402,47 @@ void Temperature::manage_heater() { } #endif + + + + #if ENABLED(PIDTEMPCHAMBER) + // PIDTEMPCHAMBER doens't support a CHAMBER_VENT yet. + temp_chamber.soft_pwm_amount = WITHIN(temp_chamber.celsius, CHAMBER_MINTEMP, CHAMBER_MAXTEMP) ? (int)get_pid_output_chamber() >> 1 : 0; + #else if (ELAPSED(ms, next_chamber_check_ms)) { next_chamber_check_ms = ms + CHAMBER_CHECK_INTERVAL; if (WITHIN(temp_chamber.celsius, CHAMBER_MINTEMP, CHAMBER_MAXTEMP)) { - if (flag_chamber_excess_heat) { - temp_chamber.soft_pwm_amount = 0; - #if ENABLED(CHAMBER_VENT) - if (!flag_chamber_off) MOVE_SERVO(CHAMBER_VENT_SERVO_NR, temp_chamber.celsius <= temp_chamber.target ? 0 : 90); - #endif + if (flag_chamber_excess_heat) { + temp_chamber.soft_pwm_amount = 0; + #if ENABLED(CHAMBER_VENT) + if (!flag_chamber_off) MOVE_SERVO(CHAMBER_VENT_SERVO_NR, temp_chamber.celsius <= temp_chamber.target ? 0 : 90); + #endif + } + else { + #if ENABLED(CHAMBER_LIMIT_SWITCHING) + if (temp_chamber.celsius >= temp_chamber.target + TEMP_CHAMBER_HYSTERESIS) + temp_chamber.soft_pwm_amount = 0; + else if (temp_chamber.celsius <= temp_chamber.target - (TEMP_CHAMBER_HYSTERESIS)) + temp_chamber.soft_pwm_amount = (MAX_CHAMBER_POWER) >> 1; + #else + temp_chamber.soft_pwm_amount = temp_chamber.celsius < temp_chamber.target ? (MAX_CHAMBER_POWER) >> 1 : 0; + #endif + #if ENABLED(CHAMBER_VENT) + if (!flag_chamber_off) MOVE_SERVO(CHAMBER_VENT_SERVO_NR, 0); + #endif + } } else { - #if ENABLED(CHAMBER_LIMIT_SWITCHING) - if (temp_chamber.celsius >= temp_chamber.target + TEMP_CHAMBER_HYSTERESIS) - temp_chamber.soft_pwm_amount = 0; - else if (temp_chamber.celsius <= temp_chamber.target - (TEMP_CHAMBER_HYSTERESIS)) - temp_chamber.soft_pwm_amount = (MAX_CHAMBER_POWER) >> 1; - #else - temp_chamber.soft_pwm_amount = temp_chamber.celsius < temp_chamber.target ? (MAX_CHAMBER_POWER) >> 1 : 0; - #endif - #if ENABLED(CHAMBER_VENT) - if (!flag_chamber_off) MOVE_SERVO(CHAMBER_VENT_SERVO_NR, 0); - #endif + temp_chamber.soft_pwm_amount = 0; + WRITE_HEATER_CHAMBER(LOW); } - } - else { - temp_chamber.soft_pwm_amount = 0; - WRITE_HEATER_CHAMBER(LOW); - } - #if ENABLED(THERMAL_PROTECTION_CHAMBER) - tr_state_machine[RUNAWAY_IND_CHAMBER].run(temp_chamber.celsius, temp_chamber.target, H_CHAMBER, THERMAL_PROTECTION_CHAMBER_PERIOD, THERMAL_PROTECTION_CHAMBER_HYSTERESIS); - #endif - } - - // TODO: Implement true PID pwm - //temp_bed.soft_pwm_amount = WITHIN(temp_chamber.celsius, CHAMBER_MINTEMP, CHAMBER_MAXTEMP) ? (int)get_pid_output_chamber() >> 1 : 0; + } + #if ENABLED(THERMAL_PROTECTION_CHAMBER) + tr_state_machine[RUNAWAY_IND_CHAMBER].run(temp_chamber.celsius, temp_chamber.target, H_CHAMBER, THERMAL_PROTECTION_CHAMBER_PERIOD, THERMAL_PROTECTION_CHAMBER_HYSTERESIS); + #endif + #endif #endif // HAS_HEATED_CHAMBER @@ -1488,7 +1532,7 @@ void Temperature::manage_heater() { SERIAL_ECHOPAIR_F_P(SP_B_STR, t.beta, 1); SERIAL_ECHOPAIR_F_P(SP_C_STR, t.sh_c_coeff, 9); SERIAL_ECHOPGM(" ; "); - serialprintPGM( + SERIAL_ECHOPGM_P( TERN_(TEMP_SENSOR_0_IS_CUSTOM, t_index == CTI_HOTEND_0 ? PSTR("HOTEND 0") :) TERN_(TEMP_SENSOR_1_IS_CUSTOM, t_index == CTI_HOTEND_1 ? PSTR("HOTEND 1") :) TERN_(TEMP_SENSOR_2_IS_CUSTOM, t_index == CTI_HOTEND_2 ? PSTR("HOTEND 2") :) @@ -1749,7 +1793,7 @@ void Temperature::updateTemperaturesFromRawValues() { #endif // Init fans according to whether they're native PWM or Software PWM -#ifdef ALFAWISE_UX0 +#ifdef BOARD_OPENDRAIN_MOSFETS #define _INIT_SOFT_FAN(P) OUT_WRITE_OD(P, FAN_INVERTING ? LOW : HIGH) #else #define _INIT_SOFT_FAN(P) OUT_WRITE(P, FAN_INVERTING ? LOW : HIGH) @@ -1842,7 +1886,7 @@ void Temperature::init() { #endif #if HAS_HEATER_0 - #ifdef ALFAWISE_UX0 + #ifdef BOARD_OPENDRAIN_MOSFETS OUT_WRITE_OD(HEATER_0_PIN, HEATER_0_INVERTING); #else OUT_WRITE(HEATER_0_PIN, HEATER_0_INVERTING); @@ -1872,7 +1916,7 @@ void Temperature::init() { #endif #if HAS_HEATED_BED - #ifdef ALFAWISE_UX0 + #ifdef BOARD_OPENDRAIN_MOSFETS OUT_WRITE_OD(HEATER_BED_PIN, HEATER_BED_INVERTING); #else OUT_WRITE(HEATER_BED_PIN, HEATER_BED_INVERTING); @@ -3403,6 +3447,17 @@ void Temperature::tick() { return false; } + #if ENABLED(WAIT_FOR_HOTEND) + void Temperature::wait_for_hotend_heating(const uint8_t target_extruder) { + if (isHeatingHotend(target_extruder)) { + SERIAL_ECHOLNPGM("Wait for hotend heating..."); + LCD_MESSAGEPGM(MSG_HEATING); + wait_for_hotend(target_extruder); + ui.reset_status(); + } + } + #endif + #endif // HAS_TEMP_HOTEND #if HAS_HEATED_BED diff --git a/Marlin/src/module/temperature.h b/Marlin/src/module/temperature.h index 75da232874a6..5f5a076911fa 100644 --- a/Marlin/src/module/temperature.h +++ b/Marlin/src/module/temperature.h @@ -210,7 +210,11 @@ struct PIDHeaterInfo : public HeaterInfo { typedef temp_info_t probe_info_t; #endif #if HAS_HEATED_CHAMBER - typedef heater_info_t chamber_info_t; + #if ENABLED(PIDTEMPCHAMBER) + typedef struct PIDHeaterInfo chamber_info_t; + #else + typedef heater_info_t chamber_info_t; + #endif #elif HAS_TEMP_CHAMBER typedef temp_info_t chamber_info_t; #endif @@ -415,7 +419,7 @@ class Temperature { #if HAS_HEATED_CHAMBER TERN_(WATCH_CHAMBER, static chamber_watch_t watch_chamber); - static millis_t next_chamber_check_ms; + TERN(PIDTEMPCHAMBER,,static millis_t next_chamber_check_ms); #ifdef CHAMBER_MINTEMP static int16_t mintemp_raw_CHAMBER; #endif @@ -626,6 +630,10 @@ class Temperature { , const bool click_to_cancel=false #endif ); + + #if ENABLED(WAIT_FOR_HOTEND) + static void wait_for_hotend_heating(const uint8_t target_extruder); + #endif #endif FORCE_INLINE static bool still_heating(const uint8_t e) { @@ -751,6 +759,11 @@ class Temperature { * Perform auto-tuning for hotend or bed in response to M303 */ #if HAS_PID_HEATING + + #if ANY(PID_DEBUG, PID_BED_DEBUG, PID_CHAMBER_DEBUG) + static bool pid_debug_flag; + #endif + static void PID_autotune(const float &target, const heater_id_t heater_id, const int8_t ncycles, const bool set_result=false); #if ENABLED(NO_FAN_SLOWING_IN_PID_TUNING) @@ -826,11 +839,9 @@ class Temperature { static void checkExtruderAutoFans(); - static float get_pid_output_hotend(const uint8_t e); - - TERN_(PIDTEMPBED, static float get_pid_output_bed()); - - TERN_(HAS_HEATED_CHAMBER, static float get_pid_output_chamber()); + TERN_(HAS_HOTEND, static float get_pid_output_hotend(const uint8_t e)); + TERN_(PIDTEMPBED, static float get_pid_output_bed()); + TERN_(PIDTEMPCHAMBER, static float get_pid_output_chamber()); static void _temp_error(const heater_id_t e, PGM_P const serial_msg, PGM_P const lcd_msg); static void min_temp_error(const heater_id_t e); diff --git a/Marlin/src/module/tool_change.h b/Marlin/src/module/tool_change.h index 4f88ca7432b4..5361451c8224 100644 --- a/Marlin/src/module/tool_change.h +++ b/Marlin/src/module/tool_change.h @@ -21,8 +21,7 @@ */ #pragma once -#include "../inc/MarlinConfigPre.h" -#include "../core/types.h" +#include "../inc/MarlinConfig.h" //#define DEBUG_TOOLCHANGE_MIGRATION_FEATURE @@ -80,11 +79,7 @@ #if ENABLED(PARKING_EXTRUDER) - #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT) - #define PE_MAGNET_ON_STATE !PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE - #else - #define PE_MAGNET_ON_STATE PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE - #endif + #define PE_MAGNET_ON_STATE TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT, !)PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE void pe_solenoid_set_pin_state(const uint8_t extruder_num, const uint8_t state); diff --git a/Marlin/src/pins/esp32/env_validate.h b/Marlin/src/pins/esp32/env_validate.h new file mode 100644 index 000000000000..ce14c33414ad --- /dev/null +++ b/Marlin/src/pins/esp32/env_validate.h @@ -0,0 +1,26 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if NOT_TARGET(ARDUINO_ARCH_ESP32) + #error "Oops! Select an ESP32 board in 'Tools > Board.'" +#endif diff --git a/Marlin/src/pins/esp32/pins_E4D.h b/Marlin/src/pins/esp32/pins_E4D.h index 4a5a2bf9b0a8..9e28af2190ab 100644 --- a/Marlin/src/pins/esp32/pins_E4D.h +++ b/Marlin/src/pins/esp32/pins_E4D.h @@ -27,9 +27,9 @@ * for more info check https://atbox.tech/ and join to Facebook page E4d@box. */ -#if NOT_TARGET(ARDUINO_ARCH_ESP32) - #error "Oops! Select an ESP32 board in 'Tools > Board.'" -#elif EXTRUDERS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#if EXTRUDERS > 1 || E_STEPPERS > 1 #error "E4d@box only supports one E Stepper. Comment out this line to continue." #elif HOTENDS > 1 #error "E4d@box only supports one hotend / E-stepper. Comment out this line to continue." diff --git a/Marlin/src/pins/esp32/pins_ESP32.h b/Marlin/src/pins/esp32/pins_ESP32.h index d54a92b9c4e5..6578770ba0e2 100644 --- a/Marlin/src/pins/esp32/pins_ESP32.h +++ b/Marlin/src/pins/esp32/pins_ESP32.h @@ -25,9 +25,7 @@ * Espressif ESP32 (Tensilica Xtensa LX6) pin assignments */ -#if NOT_TARGET(ARDUINO_ARCH_ESP32) - "Oops! Select an ESP32 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Espressif ESP32" diff --git a/Marlin/src/pins/esp32/pins_FYSETC_E4.h b/Marlin/src/pins/esp32/pins_FYSETC_E4.h index 50a8587b1ecf..7dd7f94ae567 100644 --- a/Marlin/src/pins/esp32/pins_FYSETC_E4.h +++ b/Marlin/src/pins/esp32/pins_FYSETC_E4.h @@ -27,9 +27,9 @@ * Supports 4 stepper drivers, heated bed, single hotend. */ -#ifndef ARDUINO_ARCH_ESP32 - #error "Oops! Select an ESP32 board in 'Tools > Board.'" -#elif EXTRUDERS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#if EXTRUDERS > 1 || E_STEPPERS > 1 #error "FYSETC E4 only supports one E Stepper. Comment out this line to continue." #elif HOTENDS > 1 #error "FYSETC E4 only supports one hotend / E-stepper. Comment out this line to continue." diff --git a/Marlin/src/pins/esp32/pins_MRR_ESPA.h b/Marlin/src/pins/esp32/pins_MRR_ESPA.h index fe67f7537204..38f43b53d329 100644 --- a/Marlin/src/pins/esp32/pins_MRR_ESPA.h +++ b/Marlin/src/pins/esp32/pins_MRR_ESPA.h @@ -27,9 +27,9 @@ * Supports 4 stepper drivers, heated bed, single hotend. */ -#if NOT_TARGET(ARDUINO_ARCH_ESP32) - #error "Oops! Select an ESP32 board in 'Tools > Board.'" -#elif EXTRUDERS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#if EXTRUDERS > 1 || E_STEPPERS > 1 #error "MRR ESPA only supports one E Stepper. Comment out this line to continue." #elif HOTENDS > 1 #error "MRR ESPA only supports one hotend / E-stepper. Comment out this line to continue." diff --git a/Marlin/src/pins/esp32/pins_MRR_ESPE.h b/Marlin/src/pins/esp32/pins_MRR_ESPE.h index 3f9a6a0af3a6..f156efd2e8a9 100644 --- a/Marlin/src/pins/esp32/pins_MRR_ESPE.h +++ b/Marlin/src/pins/esp32/pins_MRR_ESPE.h @@ -28,9 +28,9 @@ * single hotend, and LCD controller. */ -#if NOT_TARGET(ARDUINO_ARCH_ESP32) - #error "Oops! Select an ESP32 board in 'Tools > Board.'" -#elif EXTRUDERS > 2 || E_STEPPERS > 2 +#include "env_validate.h" + +#if EXTRUDERS > 2 || E_STEPPERS > 2 #error "MRR ESPE only supports two E Steppers. Comment out this line to continue." #elif HOTENDS > 1 #error "MRR ESPE only supports one hotend / E-stepper. Comment out this line to continue." diff --git a/Marlin/src/pins/lpc1768/env_validate.h b/Marlin/src/pins/lpc1768/env_validate.h new file mode 100644 index 000000000000..adb3ea938dc2 --- /dev/null +++ b/Marlin/src/pins/lpc1768/env_validate.h @@ -0,0 +1,30 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if ENABLED(REQUIRE_LPC1769) && NOT_TARGET(MCU_LPC1769) + #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." +#elif DISABLED(REQUIRE_LPC1769) && NOT_TARGET(MCU_LPC1768) + #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." +#endif + +#undef REQUIRE_LPC1769 diff --git a/Marlin/src/pins/lpc1768/pins_AZSMZ_MINI.h b/Marlin/src/pins/lpc1768/pins_AZSMZ_MINI.h index 70682ad1518b..0760eee0abe1 100644 --- a/Marlin/src/pins/lpc1768/pins_AZSMZ_MINI.h +++ b/Marlin/src/pins/lpc1768/pins_AZSMZ_MINI.h @@ -25,9 +25,7 @@ * AZSMZ MINI pin assignments */ -#if NOT_TARGET(MCU_LPC1768) - #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "AZSMZ MINI" diff --git a/Marlin/src/pins/lpc1768/pins_BIQU_B300_V1.0.h b/Marlin/src/pins/lpc1768/pins_BIQU_B300_V1.0.h index 5ac119f398b1..10a610ff95f7 100644 --- a/Marlin/src/pins/lpc1768/pins_BIQU_B300_V1.0.h +++ b/Marlin/src/pins/lpc1768/pins_BIQU_B300_V1.0.h @@ -29,9 +29,7 @@ * BOARD_BIQU_BQ111_A4 (Hotend, Fan, Bed) */ -#if NOT_TARGET(MCU_LPC1768) - #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." -#endif +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "BIQU Thunder B300 V1.0" diff --git a/Marlin/src/pins/lpc1768/pins_BIQU_BQ111_A4.h b/Marlin/src/pins/lpc1768/pins_BIQU_BQ111_A4.h index 3b2137b400fd..f94381e13a47 100644 --- a/Marlin/src/pins/lpc1768/pins_BIQU_BQ111_A4.h +++ b/Marlin/src/pins/lpc1768/pins_BIQU_BQ111_A4.h @@ -29,9 +29,7 @@ * BOARD_BIQU_BQ111_A4 (Hotend, Fan, Bed) */ -#if NOT_TARGET(MCU_LPC1768) - #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "BIQU BQ111-A4" diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_3.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_3.h index db9f85c7428f..89f0e1783253 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_3.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_3.h @@ -197,23 +197,23 @@ * EXP2 EXP1 */ -#define EXPA1_03_PIN P1_23 -#define EXPA1_04_PIN P1_22 -#define EXPA1_05_PIN P1_21 -#define EXPA1_06_PIN P1_20 -#define EXPA1_07_PIN P1_19 -#define EXPA1_08_PIN P1_18 -#define EXPA1_09_PIN P0_28 -#define EXPA1_10_PIN P1_30 - -#define EXPA2_03_PIN -1 -#define EXPA2_04_PIN P1_31 -#define EXPA2_05_PIN P0_18 -#define EXPA2_06_PIN P3_25 -#define EXPA2_07_PIN P0_16 -#define EXPA2_08_PIN P3_26 -#define EXPA2_09_PIN P0_15 -#define EXPA2_10_PIN P0_17 +#define EXP1_03_PIN P1_23 +#define EXP1_04_PIN P1_22 +#define EXP1_05_PIN P1_21 +#define EXP1_06_PIN P1_20 +#define EXP1_07_PIN P1_19 +#define EXP1_08_PIN P1_18 +#define EXP1_09_PIN P0_28 +#define EXP1_10_PIN P1_30 + +#define EXP2_03_PIN -1 +#define EXP2_04_PIN P1_31 +#define EXP2_05_PIN P0_18 +#define EXP2_06_PIN P3_25 +#define EXP2_07_PIN P0_16 +#define EXP2_08_PIN P3_26 +#define EXP2_09_PIN P0_15 +#define EXP2_10_PIN P0_17 #if HAS_WIRED_LCD #if ENABLED(ANET_FULL_GRAPHICS_LCD_ALT_WIRING) @@ -243,25 +243,25 @@ * LCD LCD */ - #define LCD_PINS_RS EXPA1_03_PIN + #define LCD_PINS_RS EXP1_03_PIN - #define BTN_EN1 EXPA1_06_PIN - #define BTN_EN2 EXPA1_04_PIN - #define BTN_ENC EXPA1_08_PIN + #define BTN_EN1 EXP1_06_PIN + #define BTN_EN2 EXP1_04_PIN + #define BTN_ENC EXP1_08_PIN - #define LCD_PINS_ENABLE EXPA1_05_PIN - #define LCD_PINS_D4 EXPA1_07_PIN + #define LCD_PINS_ENABLE EXP1_05_PIN + #define LCD_PINS_D4 EXP1_07_PIN #elif ENABLED(CR10_STOCKDISPLAY) - #define LCD_PINS_RS EXPA1_04_PIN + #define LCD_PINS_RS EXP1_04_PIN - #define BTN_EN1 EXPA1_08_PIN - #define BTN_EN2 EXPA1_06_PIN - #define BTN_ENC EXPA1_09_PIN // (58) open-drain + #define BTN_EN1 EXP1_08_PIN + #define BTN_EN2 EXP1_06_PIN + #define BTN_ENC EXP1_09_PIN // (58) open-drain - #define LCD_PINS_ENABLE EXPA1_03_PIN - #define LCD_PINS_D4 EXPA1_05_PIN + #define LCD_PINS_ENABLE EXP1_03_PIN + #define LCD_PINS_D4 EXP1_05_PIN #elif HAS_ADC_BUTTONS @@ -270,60 +270,60 @@ #elif IS_TFTGLCD_PANEL #if ENABLED(TFTGLCD_PANEL_SPI) - #define TFTGLCD_CS EXPA2_08_PIN + #define TFTGLCD_CS EXP2_08_PIN #endif - #define SD_DETECT_PIN EXPA2_04_PIN + #define SD_DETECT_PIN EXP2_04_PIN #else // !CR10_STOCKDISPLAY - #define LCD_PINS_RS EXPA1_07_PIN + #define LCD_PINS_RS EXP1_07_PIN - #define BTN_EN1 EXPA2_08_PIN // (31) J3-2 & AUX-4 - #define BTN_EN2 EXPA2_06_PIN // (33) J3-4 & AUX-4 - #define BTN_ENC EXPA1_09_PIN // (58) open-drain + #define BTN_EN1 EXP2_08_PIN // (31) J3-2 & AUX-4 + #define BTN_EN2 EXP2_06_PIN // (33) J3-4 & AUX-4 + #define BTN_ENC EXP1_09_PIN // (58) open-drain - #define LCD_PINS_ENABLE EXPA1_08_PIN - #define LCD_PINS_D4 EXPA1_06_PIN + #define LCD_PINS_ENABLE EXP1_08_PIN + #define LCD_PINS_D4 EXP1_06_PIN - #define LCD_SDSS EXPA2_07_PIN // (16) J3-7 & AUX-4 - #define SD_DETECT_PIN EXPA2_04_PIN // (49) (NOT 5V tolerant) + #define LCD_SDSS EXP2_07_PIN // (16) J3-7 & AUX-4 + #define SD_DETECT_PIN EXP2_04_PIN // (49) (NOT 5V tolerant) #if ENABLED(FYSETC_MINI_12864) - #define DOGLCD_CS EXPA1_08_PIN - #define DOGLCD_A0 EXPA1_07_PIN - #define DOGLCD_SCK EXPA2_09_PIN - #define DOGLCD_MOSI EXPA2_05_PIN + #define DOGLCD_CS EXP1_08_PIN + #define DOGLCD_A0 EXP1_07_PIN + #define DOGLCD_SCK EXP2_09_PIN + #define DOGLCD_MOSI EXP2_05_PIN #define LCD_BACKLIGHT_PIN -1 #define FORCE_SOFT_SPI // Use this if default of hardware SPI causes display problems // results in LCD soft SPI mode 3, SD soft SPI mode 0 - #define LCD_RESET_PIN EXPA1_06_PIN // Must be high or open for LCD to operate normally. + #define LCD_RESET_PIN EXP1_06_PIN // Must be high or open for LCD to operate normally. #if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0) #ifndef RGB_LED_R_PIN - #define RGB_LED_R_PIN EXPA1_05_PIN + #define RGB_LED_R_PIN EXP1_05_PIN #endif #ifndef RGB_LED_G_PIN - #define RGB_LED_G_PIN EXPA1_04_PIN + #define RGB_LED_G_PIN EXP1_04_PIN #endif #ifndef RGB_LED_B_PIN - #define RGB_LED_B_PIN EXPA1_03_PIN + #define RGB_LED_B_PIN EXP1_03_PIN #endif #elif ENABLED(FYSETC_MINI_12864_2_1) - #define NEOPIXEL_PIN EXPA1_05_PIN + #define NEOPIXEL_PIN EXP1_05_PIN #endif #else // !FYSETC_MINI_12864 #if ENABLED(MKS_MINI_12864) - #define DOGLCD_CS EXPA1_05_PIN - #define DOGLCD_A0 EXPA1_04_PIN - #define DOGLCD_SCK EXPA2_09_PIN - #define DOGLCD_MOSI EXPA2_05_PIN + #define DOGLCD_CS EXP1_05_PIN + #define DOGLCD_A0 EXP1_04_PIN + #define DOGLCD_SCK EXP2_09_PIN + #define DOGLCD_MOSI EXP2_05_PIN #elif ENABLED(ENDER2_STOCKDISPLAY) @@ -339,21 +339,21 @@ * EXP1 */ - #define BTN_EN1 EXPA1_08_PIN - #define BTN_EN2 EXPA1_06_PIN - #define BTN_ENC EXPA1_09_PIN - #define DOGLCD_CS EXPA1_04_PIN - #define DOGLCD_A0 EXPA1_05_PIN - #define DOGLCD_SCK EXPA1_10_PIN - #define DOGLCD_MOSI EXPA1_03_PIN + #define BTN_EN1 EXP1_08_PIN + #define BTN_EN2 EXP1_06_PIN + #define BTN_ENC EXP1_09_PIN + #define DOGLCD_CS EXP1_04_PIN + #define DOGLCD_A0 EXP1_05_PIN + #define DOGLCD_SCK EXP1_10_PIN + #define DOGLCD_MOSI EXP1_03_PIN #define FORCE_SOFT_SPI #define LCD_BACKLIGHT_PIN -1 #endif #if IS_ULTIPANEL - #define LCD_PINS_D5 EXPA1_05_PIN - #define LCD_PINS_D6 EXPA1_04_PIN - #define LCD_PINS_D7 EXPA1_03_PIN + #define LCD_PINS_D5 EXP1_05_PIN + #define LCD_PINS_D6 EXP1_04_PIN + #define LCD_PINS_D7 EXP1_03_PIN #if ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) #define BTN_ENC_EN LCD_PINS_D7 // Detect the presence of the encoder @@ -376,7 +376,7 @@ #endif #if SD_CONNECTION_IS(LCD) - #define SD_SS_PIN EXPA2_07_PIN + #define SD_SS_PIN EXP2_07_PIN #endif /** diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h index dfe86b12b724..c555ef7863ee 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h @@ -21,14 +21,12 @@ */ #pragma once +#include "env_validate.h" + #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "BTT SKR V1.4" #endif -#ifndef BOARD_CUSTOM_BUILD_FLAGS - #define BOARD_CUSTOM_BUILD_FLAGS -DLPC_PINCFG_UART3_P4_28 -#endif - // // SD Connection // @@ -243,29 +241,29 @@ * EXP2 EXP1 */ -#define EXPA1_03_PIN P1_23 -#define EXPA1_04_PIN P1_22 -#define EXPA1_05_PIN P1_21 -#define EXPA1_06_PIN P1_20 -#define EXPA1_07_PIN P1_19 -#define EXPA1_08_PIN P1_18 -#define EXPA1_09_PIN P0_28 -#define EXPA1_10_PIN P1_30 - -#define EXPA2_03_PIN -1 -#define EXPA2_04_PIN P1_31 -#define EXPA2_05_PIN P0_18 -#define EXPA2_06_PIN P3_25 -#define EXPA2_07_PIN P0_16 -#define EXPA2_08_PIN P3_26 -#define EXPA2_09_PIN P0_15 -#define EXPA2_10_PIN P0_17 +#define EXP1_03_PIN P1_23 +#define EXP1_04_PIN P1_22 +#define EXP1_05_PIN P1_21 +#define EXP1_06_PIN P1_20 +#define EXP1_07_PIN P1_19 +#define EXP1_08_PIN P1_18 +#define EXP1_09_PIN P0_28 +#define EXP1_10_PIN P1_30 + +#define EXP2_03_PIN -1 +#define EXP2_04_PIN P1_31 +#define EXP2_05_PIN P0_18 +#define EXP2_06_PIN P3_25 +#define EXP2_07_PIN P0_16 +#define EXP2_08_PIN P3_26 +#define EXP2_09_PIN P0_15 +#define EXP2_10_PIN P0_17 // // SD Connection // #if SD_CONNECTION_IS(LCD) - #define SD_SS_PIN EXPA2_07_PIN + #define SD_SS_PIN EXP2_07_PIN #endif /** @@ -282,12 +280,12 @@ #if ENABLED(DWIN_CREALITY_LCD) // RET6 DWIN ENCODER LCD - #define BTN_ENC P1_20 - #define BTN_EN1 P1_23 - #define BTN_EN2 P1_22 + #define BTN_ENC P1_20 + #define BTN_EN1 P1_23 + #define BTN_EN2 P1_22 #ifndef BEEPER_PIN - #define BEEPER_PIN P1_21 + #define BEEPER_PIN P1_21 #undef SPEAKER #endif @@ -315,15 +313,15 @@ * LCD LCD */ - #define LCD_PINS_RS EXPA1_07_PIN + #define LCD_PINS_RS EXP1_07_PIN - #define BTN_EN1 EXPA1_05_PIN - #define BTN_EN2 EXPA1_04_PIN - #define BTN_ENC EXPA1_10_PIN + #define BTN_EN1 EXP1_05_PIN + #define BTN_EN2 EXP1_04_PIN + #define BTN_ENC EXP1_10_PIN - #define LCD_PINS_ENABLE EXPA1_08_PIN - #define LCD_PINS_D4 EXPA1_06_PIN - #define BEEPER_PIN EXPA1_03_PIN + #define LCD_PINS_ENABLE EXP1_08_PIN + #define LCD_PINS_D4 EXP1_06_PIN + #define BEEPER_PIN EXP1_03_PIN #elif ENABLED(ANET_FULL_GRAPHICS_LCD) #error "CAUTION! ANET_FULL_GRAPHICS_LCD requires wiring modifications. See 'pins_BTT_SKR_V1_4.h' for details. Comment out this line to continue." @@ -349,26 +347,26 @@ * LCD LCD */ - #define LCD_PINS_RS EXPA1_03_PIN + #define LCD_PINS_RS EXP1_03_PIN - #define BTN_EN1 EXPA1_06_PIN - #define BTN_EN2 EXPA1_04_PIN - #define BTN_ENC EXPA1_08_PIN + #define BTN_EN1 EXP1_06_PIN + #define BTN_EN2 EXP1_04_PIN + #define BTN_ENC EXP1_08_PIN - #define LCD_PINS_ENABLE EXPA1_05_PIN - #define LCD_PINS_D4 EXPA1_07_PIN + #define LCD_PINS_ENABLE EXP1_05_PIN + #define LCD_PINS_D4 EXP1_07_PIN - #define BEEPER_PIN EXPA1_10_PIN + #define BEEPER_PIN EXP1_10_PIN #elif ENABLED(CR10_STOCKDISPLAY) - #define BTN_ENC EXPA1_09_PIN // (58) open-drain - #define LCD_PINS_RS EXPA1_04_PIN + #define BTN_ENC EXP1_09_PIN // (58) open-drain + #define LCD_PINS_RS EXP1_04_PIN - #define BTN_EN1 EXPA1_08_PIN - #define BTN_EN2 EXPA1_06_PIN + #define BTN_EN1 EXP1_08_PIN + #define BTN_EN2 EXP1_06_PIN - #define LCD_PINS_ENABLE EXPA1_03_PIN - #define LCD_PINS_D4 EXPA1_05_PIN + #define LCD_PINS_ENABLE EXP1_03_PIN + #define LCD_PINS_D4 EXP1_05_PIN #elif ENABLED(ENDER2_STOCKDISPLAY) @@ -383,36 +381,36 @@ * EXP1 */ - #define BTN_EN1 EXPA1_08_PIN - #define BTN_EN2 EXPA1_06_PIN - #define BTN_ENC EXPA1_09_PIN + #define BTN_EN1 EXP1_08_PIN + #define BTN_EN2 EXP1_06_PIN + #define BTN_ENC EXP1_09_PIN - #define DOGLCD_CS EXPA1_04_PIN - #define DOGLCD_A0 EXPA1_05_PIN - #define DOGLCD_SCK EXPA1_10_PIN - #define DOGLCD_MOSI EXPA1_03_PIN + #define DOGLCD_CS EXP1_04_PIN + #define DOGLCD_A0 EXP1_05_PIN + #define DOGLCD_SCK EXP1_10_PIN + #define DOGLCD_MOSI EXP1_03_PIN #define FORCE_SOFT_SPI #define LCD_BACKLIGHT_PIN -1 #elif HAS_SPI_TFT // Config for Classic UI (emulated DOGM) and Color UI - #define TFT_CS_PIN EXPA1_04_PIN - #define TFT_A0_PIN EXPA1_03_PIN - #define TFT_DC_PIN EXPA1_03_PIN - #define TFT_MISO_PIN EXPA2_10_PIN - #define TFT_BACKLIGHT_PIN EXPA1_08_PIN - #define TFT_RESET_PIN EXPA1_07_PIN + #define TFT_CS_PIN EXP1_04_PIN + #define TFT_A0_PIN EXP1_03_PIN + #define TFT_DC_PIN EXP1_03_PIN + #define TFT_MISO_PIN EXP2_10_PIN + #define TFT_BACKLIGHT_PIN EXP1_08_PIN + #define TFT_RESET_PIN EXP1_07_PIN #define LCD_USE_DMA_SPI - #define TOUCH_INT_PIN EXPA1_05_PIN - #define TOUCH_CS_PIN EXPA1_06_PIN + #define TOUCH_INT_PIN EXP1_05_PIN + #define TOUCH_CS_PIN EXP1_06_PIN #define TOUCH_BUTTONS_HW_SPI #define TOUCH_BUTTONS_HW_SPI_DEVICE 1 // SPI 1 - #define SD_SCK_PIN EXPA2_09_PIN - #define SD_MISO_PIN EXPA2_10_PIN - #define SD_MOSI_PIN EXPA2_05_PIN + #define SD_SCK_PIN EXP2_09_PIN + #define SD_MISO_PIN EXP2_10_PIN + #define SD_MOSI_PIN EXP2_05_PIN // Disable any LCD related PINs config #define LCD_PINS_ENABLE -1 @@ -423,72 +421,72 @@ #elif IS_TFTGLCD_PANEL #if ENABLED(TFTGLCD_PANEL_SPI) - #define TFTGLCD_CS EXPA2_08_PIN + #define TFTGLCD_CS EXP2_08_PIN #endif - #define SD_DETECT_PIN EXPA2_04_PIN + #define SD_DETECT_PIN EXP2_04_PIN #else - #define BTN_ENC EXPA1_09_PIN // (58) open-drain - #define LCD_PINS_RS EXPA1_07_PIN + #define BTN_ENC EXP1_09_PIN // (58) open-drain + #define LCD_PINS_RS EXP1_07_PIN - #define BTN_EN1 EXPA2_08_PIN // (31) J3-2 & AUX-4 - #define BTN_EN2 EXPA2_06_PIN // (33) J3-4 & AUX-4 + #define BTN_EN1 EXP2_08_PIN // (31) J3-2 & AUX-4 + #define BTN_EN2 EXP2_06_PIN // (33) J3-4 & AUX-4 - #define LCD_PINS_ENABLE EXPA1_08_PIN - #define LCD_PINS_D4 EXPA1_06_PIN + #define LCD_PINS_ENABLE EXP1_08_PIN + #define LCD_PINS_D4 EXP1_06_PIN - #define LCD_SDSS EXPA2_07_PIN // (16) J3-7 & AUX-4 + #define LCD_SDSS EXP2_07_PIN // (16) J3-7 & AUX-4 #if SD_CONNECTION_IS(LCD) - #define SD_DETECT_PIN EXPA2_04_PIN // (49) (NOT 5V tolerant) + #define SD_DETECT_PIN EXP2_04_PIN // (49) (NOT 5V tolerant) #endif #if ENABLED(FYSETC_MINI_12864) - #define DOGLCD_CS EXPA1_08_PIN - #define DOGLCD_A0 EXPA1_07_PIN - #define DOGLCD_SCK EXPA2_09_PIN - #define DOGLCD_MOSI EXPA2_05_PIN + #define DOGLCD_CS EXP1_08_PIN + #define DOGLCD_A0 EXP1_07_PIN + #define DOGLCD_SCK EXP2_09_PIN + #define DOGLCD_MOSI EXP2_05_PIN #define LCD_BACKLIGHT_PIN -1 #define FORCE_SOFT_SPI // Use this if default of hardware SPI causes display problems // results in LCD soft SPI mode 3, SD soft SPI mode 0 - #define LCD_RESET_PIN EXPA1_06_PIN // Must be high or open for LCD to operate normally. + #define LCD_RESET_PIN EXP1_06_PIN // Must be high or open for LCD to operate normally. #if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0) #ifndef RGB_LED_R_PIN - #define RGB_LED_R_PIN EXPA1_05_PIN + #define RGB_LED_R_PIN EXP1_05_PIN #endif #ifndef RGB_LED_G_PIN - #define RGB_LED_G_PIN EXPA1_04_PIN + #define RGB_LED_G_PIN EXP1_04_PIN #endif #ifndef RGB_LED_B_PIN - #define RGB_LED_B_PIN EXPA1_03_PIN + #define RGB_LED_B_PIN EXP1_03_PIN #endif #elif ENABLED(FYSETC_MINI_12864_2_1) - #define NEOPIXEL_PIN EXPA1_05_PIN + #define NEOPIXEL_PIN EXP1_05_PIN #endif #else // !FYSETC_MINI_12864 #if ENABLED(MKS_MINI_12864) - #define DOGLCD_CS EXPA1_05_PIN - #define DOGLCD_A0 EXPA1_04_PIN - #define DOGLCD_SCK EXPA2_09_PIN - #define DOGLCD_MOSI EXPA2_05_PIN + #define DOGLCD_CS EXP1_05_PIN + #define DOGLCD_A0 EXP1_04_PIN + #define DOGLCD_SCK EXP2_09_PIN + #define DOGLCD_MOSI EXP2_05_PIN #define FORCE_SOFT_SPI #endif #if IS_ULTIPANEL - #define LCD_PINS_D5 EXPA1_05_PIN - #define LCD_PINS_D6 EXPA1_04_PIN - #define LCD_PINS_D7 EXPA1_03_PIN + #define LCD_PINS_D5 EXP1_05_PIN + #define LCD_PINS_D6 EXP1_04_PIN + #define LCD_PINS_D7 EXP1_03_PIN #if ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) - #define BTN_ENC_EN EXPA1_03_PIN // Detect the presence of the encoder + #define BTN_ENC_EN EXP1_03_PIN // Detect the presence of the encoder #endif #endif diff --git a/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h b/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h index 80d61d9c474b..98e4f8ee2679 100644 --- a/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h +++ b/Marlin/src/pins/lpc1768/pins_BTT_SKR_common.h @@ -21,13 +21,7 @@ */ #pragma once -#if ENABLED(SKR_HAS_LPC1769) - #if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." - #endif -#elif NOT_TARGET(MCU_LPC1768) - #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." -#endif +#include "env_validate.h" // If you have the Big tree tech driver expansion module, enable HAS_BTT_EXP_MOT // https://github.com/bigtreetech/BTT-Expansion-module/tree/master/BTT%20EXP-MOT @@ -143,46 +137,46 @@ */ // M1 on Driver Expansion Module - #define E2_STEP_PIN EXPA2_05_PIN - #define E2_DIR_PIN EXPA2_06_PIN - #define E2_ENABLE_PIN EXPA2_04_PIN + #define E2_STEP_PIN EXP2_05_PIN + #define E2_DIR_PIN EXP2_06_PIN + #define E2_ENABLE_PIN EXP2_04_PIN #if !EXP_MOT_USE_EXP2_ONLY - #define E2_DIAG_PIN EXPA1_06_PIN - #define E2_CS_PIN EXPA1_05_PIN + #define E2_DIAG_PIN EXP1_06_PIN + #define E2_CS_PIN EXP1_05_PIN #if HAS_TMC_UART - #define E2_SERIAL_TX_PIN EXPA1_05_PIN - #define E2_SERIAL_RX_PIN EXPA1_05_PIN + #define E2_SERIAL_TX_PIN EXP1_05_PIN + #define E2_SERIAL_RX_PIN EXP1_05_PIN #endif #endif // M2 on Driver Expansion Module - #define E3_STEP_PIN EXPA2_08_PIN - #define E3_DIR_PIN EXPA2_07_PIN + #define E3_STEP_PIN EXP2_08_PIN + #define E3_DIR_PIN EXP2_07_PIN #if !EXP_MOT_USE_EXP2_ONLY - #define E3_ENABLE_PIN EXPA1_03_PIN - #define E3_DIAG_PIN EXPA1_08_PIN - #define E3_CS_PIN EXPA1_07_PIN + #define E3_ENABLE_PIN EXP1_03_PIN + #define E3_DIAG_PIN EXP1_08_PIN + #define E3_CS_PIN EXP1_07_PIN #if HAS_TMC_UART - #define E3_SERIAL_TX_PIN EXPA1_07_PIN - #define E3_SERIAL_RX_PIN EXPA1_07_PIN + #define E3_SERIAL_TX_PIN EXP1_07_PIN + #define E3_SERIAL_RX_PIN EXP1_07_PIN #endif #else - #define E3_ENABLE_PIN EXPA2_04_PIN + #define E3_ENABLE_PIN EXP2_04_PIN #endif // M3 on Driver Expansion Module - #define E4_STEP_PIN EXPA2_10_PIN - #define E4_DIR_PIN EXPA2_09_PIN + #define E4_STEP_PIN EXP2_10_PIN + #define E4_DIR_PIN EXP2_09_PIN #if !EXP_MOT_USE_EXP2_ONLY - #define E4_ENABLE_PIN EXPA1_04_PIN - #define E4_DIAG_PIN EXPA1_10_PIN - #define E4_CS_PIN EXPA1_09_PIN + #define E4_ENABLE_PIN EXP1_04_PIN + #define E4_DIAG_PIN EXP1_10_PIN + #define E4_CS_PIN EXP1_09_PIN #if HAS_TMC_UART - #define E4_SERIAL_TX_PIN EXPA1_09_PIN - #define E4_SERIAL_RX_PIN EXPA1_09_PIN + #define E4_SERIAL_TX_PIN EXP1_09_PIN + #define E4_SERIAL_RX_PIN EXP1_09_PIN #endif #else - #define E4_ENABLE_PIN EXPA2_04_PIN + #define E4_ENABLE_PIN EXP2_04_PIN #endif #endif // HAS_BTT_EXP_MOT diff --git a/Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h b/Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h index 1970c0c479fd..0df8b10292f8 100644 --- a/Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h +++ b/Marlin/src/pins/lpc1768/pins_GMARSH_X6_REV1.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(MCU_LPC1768) - #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "GMARSH X6 REV1" diff --git a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h index fbddc66e7ce6..71d7ad30370c 100644 --- a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h +++ b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h @@ -25,11 +25,7 @@ * MKS SBASE pin assignments */ -#if defined(MKS_HAS_LPC1769) && NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#elif !defined(MKS_HAS_LPC1769) && NOT_TARGET(MCU_LPC1768) - #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." -#endif +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "MKS SBASE" diff --git a/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h b/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h index b919ecad85a1..40fac4e7fa38 100644 --- a/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h +++ b/Marlin/src/pins/lpc1768/pins_MKS_SGEN_L.h @@ -25,9 +25,7 @@ * MKS SGEN-L pin assignments */ -#if NOT_TARGET(MCU_LPC1768) - #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "MKS SGen-L" #define BOARD_WEBSITE_URL "github.com/makerbase-mks/MKS-SGEN_L" diff --git a/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h b/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h index 65840308ca90..83fcf36e4e1f 100644 --- a/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h +++ b/Marlin/src/pins/lpc1768/pins_RAMPS_RE_ARM.h @@ -35,9 +35,7 @@ // Numbers in parentheses () are the corresponding mega2560 pin numbers -#if NOT_TARGET(MCU_LPC1768) - #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Re-ARM RAMPS 1.4" diff --git a/Marlin/src/pins/lpc1768/pins_SELENA_COMPACT.h b/Marlin/src/pins/lpc1768/pins_SELENA_COMPACT.h index 700e79de9cce..29fe3b528c08 100644 --- a/Marlin/src/pins/lpc1768/pins_SELENA_COMPACT.h +++ b/Marlin/src/pins/lpc1768/pins_SELENA_COMPACT.h @@ -25,9 +25,7 @@ * Selena Compact pin assignments */ -#if NOT_TARGET(MCU_LPC1768) - #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Selena Compact" #define BOARD_WEBSITE_URL "github.com/Ales2-k/Selena" diff --git a/Marlin/src/pins/lpc1769/env_validate.h b/Marlin/src/pins/lpc1769/env_validate.h new file mode 100644 index 000000000000..2e2b63d5203f --- /dev/null +++ b/Marlin/src/pins/lpc1769/env_validate.h @@ -0,0 +1,26 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if NOT_TARGET(MCU_LPC1769) + #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." +#endif diff --git a/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_GT.h b/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_GT.h index adf9085262a0..7ce78ad2832d 100644 --- a/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_GT.h +++ b/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_GT.h @@ -25,9 +25,7 @@ * Azteeg X5 GT pin assignments */ -#if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Azteeg X5 GT" #define BOARD_WEBSITE_URL "tinyurl.com/yx8tdqa3" diff --git a/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_MINI.h b/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_MINI.h index fdd64878fbc6..80a91d2cbc4b 100644 --- a/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_MINI.h +++ b/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_MINI.h @@ -24,10 +24,7 @@ /** * Azteeg X5 MINI pin assignments */ - -#if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#endif +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "Azteeg X5 MINI" diff --git a/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_MINI_WIFI.h b/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_MINI_WIFI.h index 99ff0fd25a14..086bacbac0f6 100644 --- a/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_MINI_WIFI.h +++ b/Marlin/src/pins/lpc1769/pins_AZTEEG_X5_MINI_WIFI.h @@ -22,12 +22,10 @@ #pragma once /** - * Azteeg X5 MINI pin assignments + * Azteeg X5 MINI WIFI pin assignments */ -#if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Azteeg X5 MINI WIFI" diff --git a/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h b/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h index 6e498ba6aa8b..2e1e02f99134 100644 --- a/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h +++ b/Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h @@ -21,6 +21,8 @@ */ #pragma once +#include "env_validate.h" + #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "BTT SKR E3 Turbo" #endif @@ -190,51 +192,51 @@ * EXP */ -#define EXPA1_03_PIN P0_18 -#define EXPA1_04_PIN P0_17 -#define EXPA1_05_PIN P0_15 -#define EXPA1_06_PIN P0_20 -#define EXPA1_07_PIN -1 -#define EXPA1_08_PIN P0_19 -#define EXPA1_09_PIN P0_16 -#define EXPA1_10_PIN P2_08 +#define EXP1_03_PIN P0_18 +#define EXP1_04_PIN P0_17 +#define EXP1_05_PIN P0_15 +#define EXP1_06_PIN P0_20 +#define EXP1_07_PIN -1 +#define EXP1_08_PIN P0_19 +#define EXP1_09_PIN P0_16 +#define EXP1_10_PIN P2_08 #if HAS_WIRED_LCD #if ENABLED(CR10_STOCKDISPLAY) - #define BEEPER_PIN EXPA1_10_PIN + #define BEEPER_PIN EXP1_10_PIN - #define BTN_EN1 EXPA1_08_PIN - #define BTN_EN2 EXPA1_06_PIN - #define BTN_ENC EXPA1_09_PIN + #define BTN_EN1 EXP1_08_PIN + #define BTN_EN2 EXP1_06_PIN + #define BTN_ENC EXP1_09_PIN - #define LCD_PINS_RS EXPA1_04_PIN - #define LCD_PINS_ENABLE EXPA1_03_PIN - #define LCD_PINS_D4 EXPA1_05_PIN + #define LCD_PINS_RS EXP1_04_PIN + #define LCD_PINS_ENABLE EXP1_03_PIN + #define LCD_PINS_D4 EXP1_05_PIN #elif ENABLED(ZONESTAR_LCD) // ANET A8 LCD Controller - Must convert to 3.3V - CONNECTING TO 5V WILL DAMAGE THE BOARD! #error "CAUTION! ZONESTAR_LCD requires wiring modifications. See 'pins_BTT_SKR_E3_TURBO.h' for details. Comment out this line to continue." - #define LCD_PINS_RS EXPA1_05_PIN - #define LCD_PINS_ENABLE EXPA1_09_PIN - #define LCD_PINS_D4 EXPA1_04_PIN - #define LCD_PINS_D5 EXPA1_06_PIN - #define LCD_PINS_D6 EXPA1_08_PIN - #define LCD_PINS_D7 EXPA1_10_PIN + #define LCD_PINS_RS EXP1_05_PIN + #define LCD_PINS_ENABLE EXP1_09_PIN + #define LCD_PINS_D4 EXP1_04_PIN + #define LCD_PINS_D5 EXP1_06_PIN + #define LCD_PINS_D6 EXP1_08_PIN + #define LCD_PINS_D7 EXP1_10_PIN #define ADC_KEYPAD_PIN P1_23 // Repurpose servo pin for ADC - CONNECTING TO 5V WILL DAMAGE THE BOARD! #elif EITHER(MKS_MINI_12864, ENDER2_STOCKDISPLAY) - #define BTN_EN1 EXPA1_08_PIN - #define BTN_EN2 EXPA1_06_PIN - #define BTN_ENC EXPA1_09_PIN + #define BTN_EN1 EXP1_08_PIN + #define BTN_EN2 EXP1_06_PIN + #define BTN_ENC EXP1_09_PIN - #define DOGLCD_CS EXPA1_04_PIN - #define DOGLCD_A0 EXPA1_05_PIN - #define DOGLCD_SCK EXPA1_10_PIN - #define DOGLCD_MOSI EXPA1_03_PIN + #define DOGLCD_CS EXP1_04_PIN + #define DOGLCD_A0 EXP1_05_PIN + #define DOGLCD_SCK EXP1_10_PIN + #define DOGLCD_MOSI EXP1_03_PIN #define FORCE_SOFT_SPI #define LCD_BACKLIGHT_PIN -1 diff --git a/Marlin/src/pins/lpc1769/pins_BTT_SKR_V1_4_TURBO.h b/Marlin/src/pins/lpc1769/pins_BTT_SKR_V1_4_TURBO.h index a751286e3a81..5af1dfec3f61 100644 --- a/Marlin/src/pins/lpc1769/pins_BTT_SKR_V1_4_TURBO.h +++ b/Marlin/src/pins/lpc1769/pins_BTT_SKR_V1_4_TURBO.h @@ -22,9 +22,9 @@ #pragma once #define BOARD_INFO_NAME "BTT SKR V1.4 TURBO" -#define SKR_HAS_LPC1769 // // Include SKR 1.4 pins // +#define REQUIRE_LPC1769 #include "../lpc1768/pins_BTT_SKR_V1_4.h" diff --git a/Marlin/src/pins/lpc1769/pins_COHESION3D_MINI.h b/Marlin/src/pins/lpc1769/pins_COHESION3D_MINI.h index d66ffbe4e5d3..237dfaec36fb 100644 --- a/Marlin/src/pins/lpc1769/pins_COHESION3D_MINI.h +++ b/Marlin/src/pins/lpc1769/pins_COHESION3D_MINI.h @@ -25,9 +25,7 @@ * Cohesion3D Mini pin assignments */ -#if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Cohesion3D Mini" diff --git a/Marlin/src/pins/lpc1769/pins_COHESION3D_REMIX.h b/Marlin/src/pins/lpc1769/pins_COHESION3D_REMIX.h index edf13cee298d..57b45214535b 100644 --- a/Marlin/src/pins/lpc1769/pins_COHESION3D_REMIX.h +++ b/Marlin/src/pins/lpc1769/pins_COHESION3D_REMIX.h @@ -25,9 +25,7 @@ * Cohesion3D ReMix pin assignments */ -#if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Cohesion3D ReMix" diff --git a/Marlin/src/pins/lpc1769/pins_FLY_CDY.h b/Marlin/src/pins/lpc1769/pins_FLY_CDY.h index 3982d76a012d..b90443403ccb 100644 --- a/Marlin/src/pins/lpc1769/pins_FLY_CDY.h +++ b/Marlin/src/pins/lpc1769/pins_FLY_CDY.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "FLY-CDY" #define BOARD_WEBSITE_URL "github.com/FLYmaker/FLY-CDY" diff --git a/Marlin/src/pins/lpc1769/pins_MKS_SGEN.h b/Marlin/src/pins/lpc1769/pins_MKS_SGEN.h index d67549997be5..ddfee63cd080 100644 --- a/Marlin/src/pins/lpc1769/pins_MKS_SGEN.h +++ b/Marlin/src/pins/lpc1769/pins_MKS_SGEN.h @@ -28,14 +28,10 @@ * https://github.com/makerbase-mks/MKS-SGen/blob/master/Hardware/MKS%20SGEN%20V1.0_001/MKS%20SGEN%20V1.0_001%20PIN.pdf */ -#if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#endif - #define BOARD_INFO_NAME "MKS SGen" #define BOARD_WEBSITE_URL "github.com/makerbase-mks/MKS-SGEN" -#define MKS_HAS_LPC1769 +#define REQUIRE_LPC1769 #include "../lpc1768/pins_MKS_SBASE.h" #if HAS_TMC_UART diff --git a/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h b/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h index abf5be3c8990..a6160794039b 100644 --- a/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h +++ b/Marlin/src/pins/lpc1769/pins_MKS_SGEN_L_V2.h @@ -25,9 +25,7 @@ * MKS SGen pin assignments */ -#if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "MKS SGEN_L V2" #define BOARD_WEBSITE_URL "github.com/makerbase-mks" diff --git a/Marlin/src/pins/lpc1769/pins_SMOOTHIEBOARD.h b/Marlin/src/pins/lpc1769/pins_SMOOTHIEBOARD.h index c5ce3f879582..f7bc9602d793 100644 --- a/Marlin/src/pins/lpc1769/pins_SMOOTHIEBOARD.h +++ b/Marlin/src/pins/lpc1769/pins_SMOOTHIEBOARD.h @@ -25,9 +25,7 @@ * Smoothieboard pin assignments */ -#if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Smoothieboard" #define BOARD_WEBSITE_URL "smoothieware.org/smoothieboard" diff --git a/Marlin/src/pins/lpc1769/pins_TH3D_EZBOARD.h b/Marlin/src/pins/lpc1769/pins_TH3D_EZBOARD.h index d4f3e5bc21b5..4d725bc7d16a 100644 --- a/Marlin/src/pins/lpc1769/pins_TH3D_EZBOARD.h +++ b/Marlin/src/pins/lpc1769/pins_TH3D_EZBOARD.h @@ -25,9 +25,7 @@ * TH3D EZBoard pin assignments */ -#if NOT_TARGET(MCU_LPC1769) - #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "TH3D EZBoard" #define BOARD_WEBSITE_URL "th3dstudio.com" diff --git a/Marlin/src/pins/mega/env_validate.h b/Marlin/src/pins/mega/env_validate.h new file mode 100644 index 000000000000..fe4a39a612ef --- /dev/null +++ b/Marlin/src/pins/mega/env_validate.h @@ -0,0 +1,30 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if ENABLED(ALLOW_MEGA1280) && NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) + #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560 or 1280' in 'Tools > Board.'" +#elif NOT_TARGET(__AVR_ATmega2560__) + #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" +#endif + +#undef ALLOW_MEGA1280 diff --git a/Marlin/src/pins/mega/pins_CHEAPTRONIC.h b/Marlin/src/pins/mega/pins_CHEAPTRONIC.h index 98427d9e592a..8bcb263bc1fd 100644 --- a/Marlin/src/pins/mega/pins_CHEAPTRONIC.h +++ b/Marlin/src/pins/mega/pins_CHEAPTRONIC.h @@ -25,9 +25,7 @@ * Cheaptronic v1.0 pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Cheaptronic v1.0" // diff --git a/Marlin/src/pins/mega/pins_CHEAPTRONICv2.h b/Marlin/src/pins/mega/pins_CHEAPTRONICv2.h index 3f18bc8bbea0..01438975b979 100644 --- a/Marlin/src/pins/mega/pins_CHEAPTRONICv2.h +++ b/Marlin/src/pins/mega/pins_CHEAPTRONICv2.h @@ -27,9 +27,7 @@ * www.reprapobchod.cz */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Cheaptronic v2.0" diff --git a/Marlin/src/pins/mega/pins_CNCONTROLS_11.h b/Marlin/src/pins/mega/pins_CNCONTROLS_11.h index f80e6144ce18..6f9e5e8e6c47 100644 --- a/Marlin/src/pins/mega/pins_CNCONTROLS_11.h +++ b/Marlin/src/pins/mega/pins_CNCONTROLS_11.h @@ -25,9 +25,8 @@ * CartesioV11 pin assignments */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#define ALLOW_MEGA1280 +#include "env_validate.h" #define BOARD_INFO_NAME "CN Controls V11" diff --git a/Marlin/src/pins/mega/pins_CNCONTROLS_12.h b/Marlin/src/pins/mega/pins_CNCONTROLS_12.h index 540f5c29f517..f1200e09018a 100644 --- a/Marlin/src/pins/mega/pins_CNCONTROLS_12.h +++ b/Marlin/src/pins/mega/pins_CNCONTROLS_12.h @@ -25,9 +25,8 @@ * CartesioV12 pin assignments */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#define ALLOW_MEGA1280 +#include "env_validate.h" #define BOARD_INFO_NAME "CN Controls V12" diff --git a/Marlin/src/pins/mega/pins_CNCONTROLS_15.h b/Marlin/src/pins/mega/pins_CNCONTROLS_15.h index 8bafbdf00058..6de3b7172eb0 100644 --- a/Marlin/src/pins/mega/pins_CNCONTROLS_15.h +++ b/Marlin/src/pins/mega/pins_CNCONTROLS_15.h @@ -25,9 +25,8 @@ * CNControls V15 for HMS434 pin assignments */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#define ALLOW_MEGA1280 +#include "env_validate.h" #define BOARD_INFO_NAME "CN Controls V15" diff --git a/Marlin/src/pins/mega/pins_EINSTART-S.h b/Marlin/src/pins/mega/pins_EINSTART-S.h index 40d65c353e8c..d42efe73617f 100644 --- a/Marlin/src/pins/mega/pins_EINSTART-S.h +++ b/Marlin/src/pins/mega/pins_EINSTART-S.h @@ -26,9 +26,8 @@ * PCB Silkscreen: 3DPrinterCon_v3.5 */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#define ALLOW_MEGA1280 +#include "env_validate.h" #define BOARD_INFO_NAME "Einstart-S" diff --git a/Marlin/src/pins/mega/pins_ELEFU_3.h b/Marlin/src/pins/mega/pins_ELEFU_3.h index af93c408a25a..f5e146cff99c 100644 --- a/Marlin/src/pins/mega/pins_ELEFU_3.h +++ b/Marlin/src/pins/mega/pins_ELEFU_3.h @@ -25,9 +25,7 @@ * Elefu RA Board Pin Assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Elefu Ra v3" diff --git a/Marlin/src/pins/mega/pins_GT2560_REV_A.h b/Marlin/src/pins/mega/pins_GT2560_REV_A.h index dcd829f7a7ae..2fb43a299f29 100644 --- a/Marlin/src/pins/mega/pins_GT2560_REV_A.h +++ b/Marlin/src/pins/mega/pins_GT2560_REV_A.h @@ -27,9 +27,8 @@ * Richard Smith */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#define ALLOW_MEGA1280 +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "GT2560 Rev.A" diff --git a/Marlin/src/pins/mega/pins_GT2560_V3.h b/Marlin/src/pins/mega/pins_GT2560_V3.h index 606debd1b06b..65642464d9f1 100644 --- a/Marlin/src/pins/mega/pins_GT2560_V3.h +++ b/Marlin/src/pins/mega/pins_GT2560_V3.h @@ -22,21 +22,20 @@ #pragma once /** - * GT2560 RevB + GT2560 V3.0 + GT2560 V3.1 + GT2560 V4.0 pin assignment + * Geeetech GT2560 RevB + GT2560 3.0/3.1 + GT2560 4.0/4.1 pin assignments */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#define ALLOW_MEGA1280 +#include "env_validate.h" #ifndef BOARD_INFO_NAME - #define BOARD_INFO_NAME "GT2560 V3.0" + #define BOARD_INFO_NAME "GT2560 RevB/3.x/4.x" #endif // // Servos // -#define SERVO0_PIN 11 //13 untested 3Dtouch +#define SERVO0_PIN 11 // 13 untested 3Dtouch // // Limit Switches @@ -142,7 +141,10 @@ #define SDSS 53 #define LED_PIN 13 // Use 6 (case light) for external LED. 13 is internal (yellow) LED. #define PS_ON_PIN 12 -#define SUICIDE_PIN 54 // This pin must be enabled at boot to keep power flowing + +#if NUM_RUNOUT_SENSORS < 3 + #define SUICIDE_PIN 54 // This pin must be enabled at boot to keep power flowing +#endif #ifndef CASE_LIGHT_PIN #define CASE_LIGHT_PIN 6 // 21 @@ -153,26 +155,48 @@ // #define BEEPER_PIN 18 -#ifndef LCD_PINS_RS - #define LCD_PINS_RS 20 -#endif -#ifndef LCD_PINS_ENABLE - #define LCD_PINS_ENABLE 17 -#endif -#ifndef LCD_PINS_D4 - #define LCD_PINS_D4 16 -#endif -#ifndef LCD_PINS_D5 - #define LCD_PINS_D5 21 -#endif -#ifndef LCD_PINS_D6 - #define LCD_PINS_D6 5 -#endif -#ifndef LCD_PINS_D7 - #define LCD_PINS_D7 36 +#if ENABLED(YHCB2004) + #ifndef YHCB2004_CLK + #define YHCB2004_CLK 5 + #endif + #ifndef YHCB2004_MOSI + #define YHCB2004_MOSI 21 + #endif + #ifndef YHCB2004_MISO + #define YHCB2004_MISO 36 + #endif +#elif HAS_WIRED_LCD + #ifndef LCD_PINS_RS + #define LCD_PINS_RS 20 + #endif + #ifndef LCD_PINS_ENABLE + #define LCD_PINS_ENABLE 17 + #endif + #ifndef LCD_PINS_D4 + #define LCD_PINS_D4 16 + #endif + #ifndef LCD_PINS_D5 + #define LCD_PINS_D5 21 + #endif + #ifndef LCD_PINS_D6 + #define LCD_PINS_D6 5 + #endif + #ifndef LCD_PINS_D7 + #define LCD_PINS_D7 36 + #endif #endif -#if IS_NEWPANEL +#if ENABLED(YHCB2004) + #ifndef BTN_EN1 + #define BTN_EN1 16 + #endif + #ifndef BTN_EN2 + #define BTN_EN2 17 + #endif + #ifndef BTN_ENC + #define BTN_ENC 19 + #endif +#elif IS_NEWPANEL #ifndef BTN_EN1 #define BTN_EN1 42 #endif diff --git a/Marlin/src/pins/mega/pins_GT2560_V3_A20.h b/Marlin/src/pins/mega/pins_GT2560_V3_A20.h index c445f5b24187..986dd1cb04bb 100644 --- a/Marlin/src/pins/mega/pins_GT2560_V3_A20.h +++ b/Marlin/src/pins/mega/pins_GT2560_V3_A20.h @@ -22,7 +22,7 @@ #pragma once /** - * Geeetech A20M pin assignment + * Geeetech A20M board pin assignments */ #define LCD_PINS_RS 5 @@ -30,7 +30,7 @@ #define LCD_PINS_D4 21 #define LCD_PINS_D7 6 -#define SPEAKER // The speaker can produce tones +#define SPEAKER // The speaker can produce tones #if IS_NEWPANEL #define BTN_EN1 16 diff --git a/Marlin/src/pins/mega/pins_GT2560_V3_MC2.h b/Marlin/src/pins/mega/pins_GT2560_V3_MC2.h index 26721df3641e..6b22b4139b6d 100644 --- a/Marlin/src/pins/mega/pins_GT2560_V3_MC2.h +++ b/Marlin/src/pins/mega/pins_GT2560_V3_MC2.h @@ -21,9 +21,9 @@ */ #pragma once -/***************************************************************** - * GT2560 V3.0 pin assignment (for Mecreator 2) - *****************************************************************/ +/** + * Geeetech GT2560 V 3.0 board pin assignments (for Mecreator 2) + */ #define BOARD_INFO_NAME "GT2560 V3.0 (MC2)" diff --git a/Marlin/src/pins/mega/pins_HJC2560C_REV2.h b/Marlin/src/pins/mega/pins_HJC2560C_REV2.h index d507d20ca7ab..27ec9988918d 100644 --- a/Marlin/src/pins/mega/pins_HJC2560C_REV2.h +++ b/Marlin/src/pins/mega/pins_HJC2560C_REV2.h @@ -22,12 +22,10 @@ #pragma once /** - * HJC2560-C Rev2.x pin assignments + * Geeetech HJC2560-C Rev 2.x board pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define DEFAULT_MACHINE_NAME "ADIMLab Gantry v2" #define BOARD_INFO_NAME "HJC2560-C" diff --git a/Marlin/src/pins/mega/pins_INTAMSYS40.h b/Marlin/src/pins/mega/pins_INTAMSYS40.h index be5f461dda38..2e2a9b85db14 100644 --- a/Marlin/src/pins/mega/pins_INTAMSYS40.h +++ b/Marlin/src/pins/mega/pins_INTAMSYS40.h @@ -27,9 +27,7 @@ * 2208 version exists and may or may not work */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Intamsys 4.0" diff --git a/Marlin/src/pins/mega/pins_LEAPFROG.h b/Marlin/src/pins/mega/pins_LEAPFROG.h index 9e6802b24bd7..4700fd6729bd 100644 --- a/Marlin/src/pins/mega/pins_LEAPFROG.h +++ b/Marlin/src/pins/mega/pins_LEAPFROG.h @@ -25,9 +25,8 @@ * Leapfrog Driver board pin assignments */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Mega 1280' or 'Mega 2560' in 'Tools > Board.'" -#endif +#define ALLOW_MEGA1280 +#include "env_validate.h" #define BOARD_INFO_NAME "Leapfrog" diff --git a/Marlin/src/pins/mega/pins_LEAPFROG_XEED2015.h b/Marlin/src/pins/mega/pins_LEAPFROG_XEED2015.h index 9c316aa75951..af5cfd6a2eef 100644 --- a/Marlin/src/pins/mega/pins_LEAPFROG_XEED2015.h +++ b/Marlin/src/pins/mega/pins_LEAPFROG_XEED2015.h @@ -29,9 +29,7 @@ * printer models. As such this file is currently specific to the Xeed. */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Leapfrog Xeed 2015" diff --git a/Marlin/src/pins/mega/pins_MEGACONTROLLER.h b/Marlin/src/pins/mega/pins_MEGACONTROLLER.h index 938ad82eff03..69c60b29ec54 100644 --- a/Marlin/src/pins/mega/pins_MEGACONTROLLER.h +++ b/Marlin/src/pins/mega/pins_MEGACONTROLLER.h @@ -25,12 +25,12 @@ * Mega controller pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#if HOTENDS > 2 || E_STEPPERS > 2 #error "Mega Controller supports up to 2 hotends / E-steppers. Comment out this line to continue." #endif +#include "env_validate.h" + #define BOARD_INFO_NAME "Mega Controller" // diff --git a/Marlin/src/pins/mega/pins_MEGATRONICS.h b/Marlin/src/pins/mega/pins_MEGATRONICS.h index f813366a14e0..0308175b2a3f 100644 --- a/Marlin/src/pins/mega/pins_MEGATRONICS.h +++ b/Marlin/src/pins/mega/pins_MEGATRONICS.h @@ -25,9 +25,7 @@ * MegaTronics pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Megatronics" // diff --git a/Marlin/src/pins/mega/pins_MEGATRONICS_2.h b/Marlin/src/pins/mega/pins_MEGATRONICS_2.h index ef4605edd437..e52703591063 100644 --- a/Marlin/src/pins/mega/pins_MEGATRONICS_2.h +++ b/Marlin/src/pins/mega/pins_MEGATRONICS_2.h @@ -25,9 +25,7 @@ * MegaTronics v2.0 pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Megatronics v2.0" // diff --git a/Marlin/src/pins/mega/pins_MEGATRONICS_3.h b/Marlin/src/pins/mega/pins_MEGATRONICS_3.h index 9f85d46a544b..5dea438d704a 100644 --- a/Marlin/src/pins/mega/pins_MEGATRONICS_3.h +++ b/Marlin/src/pins/mega/pins_MEGATRONICS_3.h @@ -25,9 +25,7 @@ * MegaTronics v3.0 / v3.1 / v3.2 pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #if MB(MEGATRONICS_32) #define BOARD_INFO_NAME "Megatronics v3.2" diff --git a/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVE.h b/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVE.h index b260a27867da..2531f10a7ae3 100644 --- a/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVE.h +++ b/Marlin/src/pins/mega/pins_MIGHTYBOARD_REVE.h @@ -37,9 +37,8 @@ * number (B5) agrees with the schematic but B5 is assigned to logical pin 11. */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Mega 1280' or 'Mega 2560' in 'Tools > Board.'" -#endif +#define ALLOW_MEGA1280 +#include "env_validate.h" #define BOARD_INFO_NAME "Mightyboard" #define DEFAULT_MACHINE_NAME "MB Replicator" diff --git a/Marlin/src/pins/mega/pins_OVERLORD.h b/Marlin/src/pins/mega/pins_OVERLORD.h index 18bb1f27bf43..161820b67a8e 100644 --- a/Marlin/src/pins/mega/pins_OVERLORD.h +++ b/Marlin/src/pins/mega/pins_OVERLORD.h @@ -25,12 +25,12 @@ * Dreammaker Overlord v1.1 pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#if HOTENDS > 2 || E_STEPPERS > 2 #error "Overlord Controller supports up to 2 hotends / E-steppers. Comment out this line to continue." #endif +#include "env_validate.h" + #define BOARD_INFO_NAME "OVERLORD" #define DEFAULT_MACHINE_NAME BOARD_INFO_NAME diff --git a/Marlin/src/pins/mega/pins_PICA.h b/Marlin/src/pins/mega/pins_PICA.h index ff4d3e834d05..81f631937708 100644 --- a/Marlin/src/pins/mega/pins_PICA.h +++ b/Marlin/src/pins/mega/pins_PICA.h @@ -29,6 +29,8 @@ * Applies to PICA, PICA_REVB */ +#include "env_validate.h" + #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "PICA" #endif @@ -42,10 +44,6 @@ AD12 = 66; AD13 = 67; AD14 = 68; AD15 = 69; */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Make sure you have 'Arduino Mega' selected from the 'Tools -> Boards' menu." -#endif - // // Servos // diff --git a/Marlin/src/pins/mega/pins_WANHAO_ONEPLUS.h b/Marlin/src/pins/mega/pins_WANHAO_ONEPLUS.h index 715e823393cf..503dd9ec8148 100644 --- a/Marlin/src/pins/mega/pins_WANHAO_ONEPLUS.h +++ b/Marlin/src/pins/mega/pins_WANHAO_ONEPLUS.h @@ -25,9 +25,7 @@ * Wanhao 0ne+ pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Wanhao i3 Mini 0ne+" #define DEFAULT_MACHINE_NAME "i3 Mini" diff --git a/Marlin/src/pins/pins.h b/Marlin/src/pins/pins.h index 737c8869d1fd..55240021fae0 100644 --- a/Marlin/src/pins/pins.h +++ b/Marlin/src/pins/pins.h @@ -70,32 +70,32 @@ // #if MB(RAMPS_OLD) - #include "ramps/pins_RAMPS_OLD.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_RAMPS_OLD.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(RAMPS_13_EFB, RAMPS_13_EEB, RAMPS_13_EFF, RAMPS_13_EEF, RAMPS_13_SF) - #include "ramps/pins_RAMPS_13.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_RAMPS_13.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(RAMPS_14_EFB, RAMPS_14_EEB, RAMPS_14_EFF, RAMPS_14_EEF, RAMPS_14_SF) - #include "ramps/pins_RAMPS.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_RAMPS.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(RAMPS_PLUS_EFB, RAMPS_PLUS_EEB, RAMPS_PLUS_EFF, RAMPS_PLUS_EEF, RAMPS_PLUS_SF) - #include "ramps/pins_RAMPS_PLUS.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_RAMPS_PLUS.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 // // RAMPS Derivatives - ATmega1280, ATmega2560 // #elif MB(3DRAG) - #include "ramps/pins_3DRAG.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_3DRAG.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(K8200) - #include "ramps/pins_K8200.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_K8200.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(K8400) - #include "ramps/pins_K8400.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_K8400.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(K8600) - #include "ramps/pins_K8600.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_K8600.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(K8800) - #include "ramps/pins_K8800.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_K8800.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(BAM_DICE) - #include "ramps/pins_RAMPS.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_RAMPS.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(BAM_DICE_DUE) - #include "ramps/pins_BAM_DICE_DUE.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_BAM_DICE_DUE.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(MKS_BASE) #include "ramps/pins_MKS_BASE_10.h" // ATmega2560 env:mega2560 #elif MB(MKS_BASE_14) @@ -107,27 +107,27 @@ #elif MB(MKS_BASE_HEROIC) #include "ramps/pins_MKS_BASE_HEROIC.h" // ATmega2560 env:mega2560 #elif MB(MKS_GEN_13) - #include "ramps/pins_MKS_GEN_13.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_MKS_GEN_13.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(MKS_GEN_L) - #include "ramps/pins_MKS_GEN_L.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_MKS_GEN_L.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(KFB_2) #include "ramps/pins_BIQU_KFB_2.h" // ATmega2560 env:mega2560 #elif MB(ZRIB_V20) - #include "ramps/pins_ZRIB_V20.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_ZRIB_V20.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(ZRIB_V52) - #include "ramps/pins_ZRIB_V52.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_ZRIB_V52.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(FELIX2) - #include "ramps/pins_FELIX2.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_FELIX2.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(RIGIDBOARD) - #include "ramps/pins_RIGIDBOARD.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_RIGIDBOARD.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(RIGIDBOARD_V2) - #include "ramps/pins_RIGIDBOARD_V2.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_RIGIDBOARD_V2.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(SAINSMART_2IN1) - #include "ramps/pins_SAINSMART_2IN1.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_SAINSMART_2IN1.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(ULTIMAKER) - #include "ramps/pins_ULTIMAKER.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_ULTIMAKER.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(ULTIMAKER_OLD) - #include "ramps/pins_ULTIMAKER_OLD.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "ramps/pins_ULTIMAKER_OLD.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(AZTEEG_X3) #include "ramps/pins_AZTEEG_X3.h" // ATmega2560 env:mega2560 #elif MB(AZTEEG_X3_PRO) @@ -207,19 +207,21 @@ #include "rambo/pins_EINSY_RETRO.h" // ATmega2560 env:rambo #elif MB(SCOOVO_X9H) #include "rambo/pins_SCOOVO_X9H.h" // ATmega2560 env:rambo +#elif MB(RAMBO_THINKERV2) + #include "rambo/pins_RAMBO_THINKERV2.h" // ATmega2560 env:rambo // // Other ATmega1280, ATmega2560 // #elif MB(CNCONTROLS_11) - #include "mega/pins_CNCONTROLS_11.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "mega/pins_CNCONTROLS_11.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(CNCONTROLS_12) - #include "mega/pins_CNCONTROLS_12.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "mega/pins_CNCONTROLS_12.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(CNCONTROLS_15) - #include "mega/pins_CNCONTROLS_15.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "mega/pins_CNCONTROLS_15.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(MIGHTYBOARD_REVE) - #include "mega/pins_MIGHTYBOARD_REVE.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560ext + #include "mega/pins_MIGHTYBOARD_REVE.h" // ATmega2560, ATmega1280 env:mega2560ext env:mega1280 #elif MB(CHEAPTRONIC) #include "mega/pins_CHEAPTRONIC.h" // ATmega2560 env:mega2560 #elif MB(CHEAPTRONIC_V2) @@ -233,13 +235,13 @@ #elif MB(ELEFU_3) #include "mega/pins_ELEFU_3.h" // ATmega2560 env:mega2560 #elif MB(LEAPFROG) - #include "mega/pins_LEAPFROG.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "mega/pins_LEAPFROG.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(MEGACONTROLLER) #include "mega/pins_MEGACONTROLLER.h" // ATmega2560 env:mega2560 #elif MB(GT2560_REV_A) - #include "mega/pins_GT2560_REV_A.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "mega/pins_GT2560_REV_A.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(GT2560_REV_A_PLUS) - #include "mega/pins_GT2560_REV_A_PLUS.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560 + #include "mega/pins_GT2560_REV_A_PLUS.h" // ATmega2560, ATmega1280 env:mega2560 env:mega1280 #elif MB(GT2560_V3) #include "mega/pins_GT2560_V3.h" // ATmega2560 env:mega2560 #elif MB(GT2560_V3_MC2) @@ -247,11 +249,13 @@ #elif MB(GT2560_V3_A20) #include "mega/pins_GT2560_V3_A20.h" // ATmega2560 env:mega2560 #elif MB(EINSTART_S) - #include "mega/pins_EINSTART-S.h" // ATmega1280, ATmega2560 env:mega1280 env:mega2560ext + #include "mega/pins_EINSTART-S.h" // ATmega2560, ATmega1280 env:mega2560ext env:mega1280 #elif MB(WANHAO_ONEPLUS) #include "mega/pins_WANHAO_ONEPLUS.h" // ATmega2560 env:mega2560 #elif MB(OVERLORD) #include "mega/pins_OVERLORD.h" // ATmega2560 env:mega2560 +#elif MB(HJC2560C_REV1) + #include "mega/pins_HJC2560C_REV2.h" // ATmega2560 env:mega2560 #elif MB(HJC2560C_REV2) #include "mega/pins_HJC2560C_REV2.h" // ATmega2560 env:mega2560 #elif MB(LEAPFROG_XEED2015) @@ -277,27 +281,27 @@ // #elif MB(SANGUINOLOLU_11) - #include "sanguino/pins_SANGUINOLOLU_11.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_SANGUINOLOLU_11.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(SANGUINOLOLU_12) - #include "sanguino/pins_SANGUINOLOLU_12.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_SANGUINOLOLU_12.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(MELZI) - #include "sanguino/pins_MELZI.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_MELZI.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(MELZI_V2) - #include "sanguino/pins_MELZI_V2.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_MELZI_V2.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(MELZI_MAKR3D) - #include "sanguino/pins_MELZI_MAKR3D.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_MELZI_MAKR3D.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(MELZI_CREALITY) - #include "sanguino/pins_MELZI_CREALITY.h" // ATmega1284P env:melzi env:melzi_optimized env:melzi_optiboot env:melzi_optiboot_optimized + #include "sanguino/pins_MELZI_CREALITY.h" // ATmega1284P env:melzi_optiboot_optimized env:melzi_optiboot env:melzi_optimized env:melzi #elif MB(MELZI_MALYAN) - #include "sanguino/pins_MELZI_MALYAN.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_MELZI_MALYAN.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(MELZI_TRONXY) - #include "sanguino/pins_MELZI_TRONXY.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_MELZI_TRONXY.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(STB_11) - #include "sanguino/pins_STB_11.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_STB_11.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(AZTEEG_X1) - #include "sanguino/pins_AZTEEG_X1.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_AZTEEG_X1.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(ZMIB_V2) - #include "sanguino/pins_ZMIB_V2.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_ZMIB_V2.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p // // Other ATmega644P, ATmega644, ATmega1284P @@ -306,19 +310,19 @@ #elif MB(GEN3_MONOLITHIC) #include "sanguino/pins_GEN3_MONOLITHIC.h" // ATmega644P env:sanguino644p #elif MB(GEN3_PLUS) - #include "sanguino/pins_GEN3_PLUS.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_GEN3_PLUS.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(GEN6) - #include "sanguino/pins_GEN6.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_GEN6.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(GEN6_DELUXE) - #include "sanguino/pins_GEN6_DELUXE.h" // ATmega644P, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_GEN6_DELUXE.h" // ATmega644P, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(GEN7_CUSTOM) - #include "sanguino/pins_GEN7_CUSTOM.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_GEN7_CUSTOM.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(GEN7_12) - #include "sanguino/pins_GEN7_12.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_GEN7_12.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(GEN7_13) - #include "sanguino/pins_GEN7_13.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_GEN7_13.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(GEN7_14) - #include "sanguino/pins_GEN7_14.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_GEN7_14.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p #elif MB(OMCA_A) #include "sanguino/pins_OMCA_A.h" // ATmega644 env:sanguino644p #elif MB(OMCA) @@ -326,7 +330,7 @@ #elif MB(ANET_10) #include "sanguino/pins_ANET_10.h" // ATmega1284P env:sanguino1284p env:sanguino1284p_optimized #elif MB(SETHI) - #include "sanguino/pins_SETHI.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino644p env:sanguino1284p env:sanguino1284p_optimized + #include "sanguino/pins_SETHI.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino1284p_optimized env:sanguino1284p env:sanguino644p // // Teensyduino - AT90USB1286, AT90USB1286P @@ -374,7 +378,7 @@ #elif MB(BTT_SKR_V1_3) #include "lpc1768/pins_BTT_SKR_V1_3.h" // LPC1768 env:LPC1768 #elif MB(BTT_SKR_V1_4) - #include "lpc1768/pins_BTT_SKR_V1_4.h" // LPC1768 env:LPC1768 + #include "lpc1768/pins_BTT_SKR_V1_4.h" // LPC1768 env:LPC1768_btt_skr_v1_4 // // LPC1769 ARM Cortex M3 @@ -479,9 +483,9 @@ #elif MB(MKS_ROBIN_MINI) #include "stm32f1/pins_MKS_ROBIN_MINI.h" // STM32F1 env:mks_robin_mini #elif MB(MKS_ROBIN_NANO) - #include "stm32f1/pins_MKS_ROBIN_NANO.h" // STM32F1 env:mks_robin_nano35 + #include "stm32f1/pins_MKS_ROBIN_NANO.h" // STM32F1 env:mks_robin_nano35 env:mks_robin_nano35_stm32 #elif MB(MKS_ROBIN_NANO_V2) - #include "stm32f1/pins_MKS_ROBIN_NANO_V2.h" // STM32F1 env:mks_robin_nano35 + #include "stm32f1/pins_MKS_ROBIN_NANO_V2.h" // STM32F1 env:mks_robin_nano35 env:mks_robin_nano35_stm32 #elif MB(MKS_ROBIN_LITE) #include "stm32f1/pins_MKS_ROBIN_LITE.h" // STM32F1 env:mks_robin_lite #elif MB(MKS_ROBIN_LITE3) @@ -511,7 +515,7 @@ #elif MB(BTT_SKR_E3_DIP) #include "stm32f1/pins_BTT_SKR_E3_DIP.h" // STM32F1 env:STM32F103RE_btt env:STM32F103RE_btt_USB env:STM32F103RC_btt env:STM32F103RC_btt_512K env:STM32F103RC_btt_USB env:STM32F103RC_btt_512K_USB #elif MB(BTT_SKR_CR6) - #include "stm32f1/pins_BTT_SKR_CR6.h" // STM32F1 env:STM32F103RC_btt_512K_USB + #include "stm32f1/pins_BTT_SKR_CR6.h" // STM32F1 env:STM32F103RE_btt env:STM32F103RE_btt_USB #elif MB(JGAURORA_A5S_A1) #include "stm32f1/pins_JGAURORA_A5S_A1.h" // STM32F1 env:jgaurora_a5s_a1 #elif MB(FYSETC_AIO_II) @@ -601,7 +605,7 @@ #elif MB(MKS_ROBIN_PRO_V2) #include "stm32f4/pins_MKS_ROBIN_PRO_V2.h" // STM32F4 env:mks_robin_pro2 #elif MB(MKS_ROBIN_NANO_V3) - #include "stm32f4/pins_MKS_ROBIN_NANO_V3.h" // STM32F4 env:mks_robin_nano_v3 env:mks_robin_nano_v3_usb_flash_drive + #include "stm32f4/pins_MKS_ROBIN_NANO_V3.h" // STM32F4 env:mks_robin_nano_v3 env:mks_robin_nano_v3_usb_flash_drive env:mks_robin_nano_v3_usb_flash_drive_msc #elif MB(ANET_ET4) #include "stm32f4/pins_ANET_ET4.h" // STM32F4 env:Anet_ET4_OpenBLT #elif MB(ANET_ET4P) diff --git a/Marlin/src/pins/pinsDebug.h b/Marlin/src/pins/pinsDebug.h index 5f153cfa2b0f..72e31b7b2525 100644 --- a/Marlin/src/pins/pinsDebug.h +++ b/Marlin/src/pins/pinsDebug.h @@ -41,7 +41,7 @@ #define REPORT_NAME_ANALOG(COUNTER, NAME) _ADD_PIN(#NAME, COUNTER) #include "pinsDebug_list.h" -#line 46 +#line 45 // manually add pins that have names that are macros which don't play well with these macros #if ANY(AVR_ATmega2560_FAMILY, AVR_ATmega1284_FAMILY, ARDUINO_ARCH_SAM, TARGET_LPC1768) @@ -227,7 +227,7 @@ const PinInfo pin_array[] PROGMEM = { #endif #include "pinsDebug_list.h" - #line 172 + #line 231 }; @@ -238,7 +238,7 @@ const PinInfo pin_array[] PROGMEM = { #endif static void print_input_or_output(const bool isout) { - serialprintPGM(isout ? PSTR("Output = ") : PSTR("Input = ")); + SERIAL_ECHOPGM_P(isout ? PSTR("Output = ") : PSTR("Input = ")); } // pretty report with PWM info @@ -266,8 +266,8 @@ inline void report_pin_state_extended(pin_t pin, const bool ignore, const bool e LOOP_L_N(x, COUNT(pin_array)) { // scan entire array and report all instances of this pin if (GET_ARRAY_PIN(x) == pin) { if (!found) { // report digital and analog pin number only on the first time through - if (start_string) serialprintPGM(start_string); - serialprintPGM(PSTR("PIN: ")); + if (start_string) SERIAL_ECHOPGM_P(start_string); + SERIAL_ECHOPGM("PIN: "); PRINT_PIN(pin); PRINT_PORT(pin); if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) { @@ -317,8 +317,8 @@ inline void report_pin_state_extended(pin_t pin, const bool ignore, const bool e } // end of for loop if (!found) { - if (start_string) serialprintPGM(start_string); - serialprintPGM(PSTR("PIN: ")); + if (start_string) SERIAL_ECHOPGM_P(start_string); + SERIAL_ECHOPGM("PIN: "); PRINT_PIN(pin); PRINT_PORT(pin); if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) { diff --git a/Marlin/src/pins/pinsDebug_list.h b/Marlin/src/pins/pinsDebug_list.h index 79a67c34f870..42095fa926b4 100644 --- a/Marlin/src/pins/pinsDebug_list.h +++ b/Marlin/src/pins/pinsDebug_list.h @@ -183,6 +183,81 @@ #if PIN_EXISTS(JOY_EN) REPORT_NAME_DIGITAL(__LINE__, JOY_EN_PIN) #endif +#if PIN_EXISTS(BUTTON1) + REPORT_NAME_DIGITAL(__LINE__, BUTTON1_PIN) +#endif +#if PIN_EXISTS(BUTTON2) + REPORT_NAME_DIGITAL(__LINE__, BUTTON2_PIN) +#endif +#if PIN_EXISTS(BUTTON3) + REPORT_NAME_DIGITAL(__LINE__, BUTTON3_PIN) +#endif +#if PIN_EXISTS(BUTTON4) + REPORT_NAME_DIGITAL(__LINE__, BUTTON4_PIN) +#endif +#if PIN_EXISTS(BUTTON5) + REPORT_NAME_DIGITAL(__LINE__, BUTTON5_PIN) +#endif +#if PIN_EXISTS(BUTTON6) + REPORT_NAME_DIGITAL(__LINE__, BUTTON6_PIN) +#endif +#if PIN_EXISTS(BUTTON7) + REPORT_NAME_DIGITAL(__LINE__, BUTTON7_PIN) +#endif +#if PIN_EXISTS(BUTTON8) + REPORT_NAME_DIGITAL(__LINE__, BUTTON8_PIN) +#endif +#if PIN_EXISTS(BUTTON9) + REPORT_NAME_DIGITAL(__LINE__, BUTTON9_PIN) +#endif +#if PIN_EXISTS(BUTTON10) + REPORT_NAME_DIGITAL(__LINE__, BUTTON10_PIN) +#endif +#if PIN_EXISTS(BUTTON11) + REPORT_NAME_DIGITAL(__LINE__, BUTTON11_PIN) +#endif +#if PIN_EXISTS(BUTTON12) + REPORT_NAME_DIGITAL(__LINE__, BUTTON12_PIN) +#endif +#if PIN_EXISTS(BUTTON13) + REPORT_NAME_DIGITAL(__LINE__, BUTTON13_PIN) +#endif +#if PIN_EXISTS(BUTTON14) + REPORT_NAME_DIGITAL(__LINE__, BUTTON14_PIN) +#endif +#if PIN_EXISTS(BUTTON15) + REPORT_NAME_DIGITAL(__LINE__, BUTTON15_PIN) +#endif +#if PIN_EXISTS(BUTTON16) + REPORT_NAME_DIGITAL(__LINE__, BUTTON16_PIN) +#endif +#if PIN_EXISTS(BUTTON17) + REPORT_NAME_DIGITAL(__LINE__, BUTTON17_PIN) +#endif +#if PIN_EXISTS(BUTTON18) + REPORT_NAME_DIGITAL(__LINE__, BUTTON18_PIN) +#endif +#if PIN_EXISTS(BUTTON19) + REPORT_NAME_DIGITAL(__LINE__, BUTTON19_PIN) +#endif +#if PIN_EXISTS(BUTTON20) + REPORT_NAME_DIGITAL(__LINE__, BUTTON20_PIN) +#endif +#if PIN_EXISTS(BUTTON21) + REPORT_NAME_DIGITAL(__LINE__, BUTTON21_PIN) +#endif +#if PIN_EXISTS(BUTTON22) + REPORT_NAME_DIGITAL(__LINE__, BUTTON22_PIN) +#endif +#if PIN_EXISTS(BUTTON23) + REPORT_NAME_DIGITAL(__LINE__, BUTTON23_PIN) +#endif +#if PIN_EXISTS(BUTTON24) + REPORT_NAME_DIGITAL(__LINE__, BUTTON24_PIN) +#endif +#if PIN_EXISTS(BUTTON25) + REPORT_NAME_DIGITAL(__LINE__, BUTTON25_PIN) +#endif #if PIN_EXISTS(CASE_LIGHT) REPORT_NAME_DIGITAL(__LINE__, CASE_LIGHT_PIN) #endif diff --git a/Marlin/src/pins/pins_postprocess.h b/Marlin/src/pins/pins_postprocess.h index de70248d4d02..d37dd4352ab0 100644 --- a/Marlin/src/pins/pins_postprocess.h +++ b/Marlin/src/pins/pins_postprocess.h @@ -876,5 +876,9 @@ #undef BOARD_ST7920_DELAY_3 #endif +#if !NEED_CASE_LIGHT_PIN + #undef CASE_LIGHT_PIN +#endif + #undef HAS_FREE_AUX2_PINS #undef DIAG_REMAPPED diff --git a/Marlin/src/pins/rambo/env_validate.h b/Marlin/src/pins/rambo/env_validate.h new file mode 100644 index 000000000000..84cf8392cdfc --- /dev/null +++ b/Marlin/src/pins/rambo/env_validate.h @@ -0,0 +1,26 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if NOT_TARGET(__AVR_ATmega2560__) + #error "Oops! Select 'Arduino Mega 2560 or Rambo' in 'Tools > Board.'" +#endif diff --git a/Marlin/src/pins/rambo/pins_EINSY_RAMBO.h b/Marlin/src/pins/rambo/pins_EINSY_RAMBO.h index 2ca2cc9c8d07..7b05d454af31 100644 --- a/Marlin/src/pins/rambo/pins_EINSY_RAMBO.h +++ b/Marlin/src/pins/rambo/pins_EINSY_RAMBO.h @@ -25,9 +25,7 @@ * Einsy-Rambo pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino Mega 2560 or Rambo' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Einsy Rambo" diff --git a/Marlin/src/pins/rambo/pins_EINSY_RETRO.h b/Marlin/src/pins/rambo/pins_EINSY_RETRO.h index a6a4b65e05bc..ee537495ea23 100644 --- a/Marlin/src/pins/rambo/pins_EINSY_RETRO.h +++ b/Marlin/src/pins/rambo/pins_EINSY_RETRO.h @@ -25,9 +25,7 @@ * Einsy-Retro pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino Mega 2560 or Rambo' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Einsy Retro" diff --git a/Marlin/src/pins/rambo/pins_MINIRAMBO.h b/Marlin/src/pins/rambo/pins_MINIRAMBO.h index 4dcf35827cba..ec44cc3b3661 100644 --- a/Marlin/src/pins/rambo/pins_MINIRAMBO.h +++ b/Marlin/src/pins/rambo/pins_MINIRAMBO.h @@ -25,9 +25,7 @@ * Mini-RAMBo pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'RAMBo' in 'Tools > Board' or the Mega2560 environment in PlatformIO." -#endif +#include "env_validate.h" #if MB(MINIRAMBO_10A) #define BOARD_INFO_NAME "Mini RAMBo 1.0a" diff --git a/Marlin/src/pins/rambo/pins_RAMBO.h b/Marlin/src/pins/rambo/pins_RAMBO.h index be2317b146bd..5d6f9c1fd09d 100644 --- a/Marlin/src/pins/rambo/pins_RAMBO.h +++ b/Marlin/src/pins/rambo/pins_RAMBO.h @@ -41,18 +41,22 @@ * Rambo pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" -#define BOARD_INFO_NAME "Rambo" +#ifndef BOARD_INFO_NAME + #define BOARD_INFO_NAME "Rambo" +#endif // // Servos // -#define SERVO0_PIN 22 // Motor header MX1 +#ifndef SERVO0_PIN + #define SERVO0_PIN 22 // Motor header MX1 +#endif #define SERVO1_PIN 23 // Motor header MX2 -#define SERVO2_PIN 24 // Motor header MX3 +#ifndef SERVO2_PIN + #define SERVO2_PIN 24 // Motor header MX3 +#endif #define SERVO3_PIN 5 // PWM header pin 5 // @@ -62,7 +66,9 @@ #define X_MAX_PIN 24 #define Y_MIN_PIN 11 #define Y_MAX_PIN 23 -#define Z_MIN_PIN 10 +#ifndef Z_MIN_PIN + #define Z_MIN_PIN 10 +#endif #define Z_MAX_PIN 30 // @@ -135,8 +141,12 @@ #ifndef FAN_PIN #define FAN_PIN 8 #endif -#define FAN1_PIN 6 -#define FAN2_PIN 2 +#ifndef FAN1_PIN + #define FAN1_PIN 6 +#endif +#ifndef FAN2_PIN + #define FAN2_PIN 2 +#endif // // Misc. Functions @@ -220,8 +230,12 @@ #define BEEPER_PIN 79 // AUX-4 // AUX-2 - #define BTN_EN1 76 - #define BTN_EN2 77 + #ifndef BTN_EN1 + #define BTN_EN1 76 + #endif + #ifndef BTN_EN2 + #define BTN_EN2 77 + #endif #define BTN_ENC 78 #define SD_DETECT_PIN 81 diff --git a/Marlin/src/pins/rambo/pins_RAMBO_THINKERV2.h b/Marlin/src/pins/rambo/pins_RAMBO_THINKERV2.h new file mode 100755 index 000000000000..278a5bf0b45a --- /dev/null +++ b/Marlin/src/pins/rambo/pins_RAMBO_THINKERV2.h @@ -0,0 +1,60 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +/** + * Rambo ThinkerV2 pin assignments + */ + +#define BOARD_INFO_NAME "Rambo ThinkerV2" + +#define SERVO0_PIN 4 // Motor header MX1 +#define SERVO2_PIN -1 // Motor header MX3 + +#ifndef FIL_RUNOUT_PIN + #define FIL_RUNOUT_PIN 10 +#endif + +// Support BLTouch and fixed probes +#if ENABLED(BLTOUCH) + #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) + #define Z_MIN_PIN 22 + #elif !defined(Z_MIN_PROBE_PIN) + #define Z_MIN_PROBE_PIN 22 + #endif +#elif ENABLED(FIX_MOUNTED_PROBE) + #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) + #define Z_MIN_PIN 4 + #elif !defined(Z_MIN_PROBE_PIN) + #define Z_MIN_PROBE_PIN 4 + #endif +#endif + +// Eryone has the fan pins reversed +#define FAN1_PIN 2 +#define FAN2_PIN 6 + +// Encoder +#define BTN_EN1 64 +#define BTN_EN2 63 + +#include "pins_RAMBO.h" diff --git a/Marlin/src/pins/rambo/pins_SCOOVO_X9H.h b/Marlin/src/pins/rambo/pins_SCOOVO_X9H.h index 5680b00df693..c2a691a3b73b 100644 --- a/Marlin/src/pins/rambo/pins_SCOOVO_X9H.h +++ b/Marlin/src/pins/rambo/pins_SCOOVO_X9H.h @@ -25,9 +25,7 @@ * Rambo pin assignments MODIFIED FOR Scoovo X9H ************************************************/ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_target.h" #define BOARD_INFO_NAME "Scoovo X9H" diff --git a/Marlin/src/pins/ramps/env_validate.h b/Marlin/src/pins/ramps/env_validate.h new file mode 100644 index 000000000000..6006a78f013c --- /dev/null +++ b/Marlin/src/pins/ramps/env_validate.h @@ -0,0 +1,35 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if ENABLED(ALLOW_SAM3X8E) + #if NOT_TARGET(__SAM3X8E__, __AVR_ATmega2560__) + #error "Oops! Select 'Arduino Due' or 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" + #endif +#elif ENABLED(REQUIRE_MEGA2560) && NOT_TARGET(__AVR_ATmega2560__) + #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" +#elif DISABLED(REQUIRE_MEGA2560) && NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) + #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560 or 1280' in 'Tools > Board.'" +#endif + +#undef ALLOW_SAM3X8E +#undef REQUIRE_MEGA2560 diff --git a/Marlin/src/pins/ramps/pins_AZTEEG_X3.h b/Marlin/src/pins/ramps/pins_AZTEEG_X3.h index 6ddd2a5165e6..07af61e69381 100644 --- a/Marlin/src/pins/ramps/pins_AZTEEG_X3.h +++ b/Marlin/src/pins/ramps/pins_AZTEEG_X3.h @@ -25,9 +25,10 @@ * AZTEEG_X3 Arduino Mega with RAMPS v1.4 pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define REQUIRE_MEGA2560 +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "Azteeg X3 supports up to 2 hotends / E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/ramps/pins_AZTEEG_X3_PRO.h b/Marlin/src/pins/ramps/pins_AZTEEG_X3_PRO.h index 9ba6a0c1ac45..c2896146e64f 100644 --- a/Marlin/src/pins/ramps/pins_AZTEEG_X3_PRO.h +++ b/Marlin/src/pins/ramps/pins_AZTEEG_X3_PRO.h @@ -25,9 +25,10 @@ * AZTEEG_X3_PRO (Arduino Mega) pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 5 || E_STEPPERS > 5 +#define REQUIRE_MEGA2560 +#include "env_validate.h" + +#if HOTENDS > 5 || E_STEPPERS > 5 #error "Azteeg X3 Pro supports up to 5 hotends / E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/ramps/pins_BQ_ZUM_MEGA_3D.h b/Marlin/src/pins/ramps/pins_BQ_ZUM_MEGA_3D.h index f120e9c44f54..99cf484de7f0 100644 --- a/Marlin/src/pins/ramps/pins_BQ_ZUM_MEGA_3D.h +++ b/Marlin/src/pins/ramps/pins_BQ_ZUM_MEGA_3D.h @@ -25,9 +25,8 @@ * bq ZUM Mega 3D board definition */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#define REQUIRE_MEGA2560 +#include "env_validate.h" #define BOARD_INFO_NAME "ZUM Mega 3D" diff --git a/Marlin/src/pins/ramps/pins_DUPLICATOR_I3_PLUS.h b/Marlin/src/pins/ramps/pins_DUPLICATOR_I3_PLUS.h index 93ec3d607026..1a4b83f02dce 100644 --- a/Marlin/src/pins/ramps/pins_DUPLICATOR_I3_PLUS.h +++ b/Marlin/src/pins/ramps/pins_DUPLICATOR_I3_PLUS.h @@ -25,9 +25,8 @@ * Wanhao Duplicator i3 Plus pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#define REQUIRE_MEGA2560 +#include "env_validate.h" #define BOARD_INFO_NAME "Duplicator i3 Plus" diff --git a/Marlin/src/pins/ramps/pins_FORMBOT_RAPTOR.h b/Marlin/src/pins/ramps/pins_FORMBOT_RAPTOR.h index 5b724787e941..383501caaaf8 100644 --- a/Marlin/src/pins/ramps/pins_FORMBOT_RAPTOR.h +++ b/Marlin/src/pins/ramps/pins_FORMBOT_RAPTOR.h @@ -25,9 +25,10 @@ * Formbot Raptor pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 3 || E_STEPPERS > 3 +#define REQUIRE_MEGA2560 +#include "env_validate.h" + +#if HOTENDS > 3 || E_STEPPERS > 3 #error "Formbot supports up to 3 hotends / E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/ramps/pins_FORMBOT_TREX2PLUS.h b/Marlin/src/pins/ramps/pins_FORMBOT_TREX2PLUS.h index 81b6ea16d7fe..ac0b7428f498 100644 --- a/Marlin/src/pins/ramps/pins_FORMBOT_TREX2PLUS.h +++ b/Marlin/src/pins/ramps/pins_FORMBOT_TREX2PLUS.h @@ -25,9 +25,10 @@ * Formbot pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define REQUIRE_MEGA2560 +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "Formbot supports up to 2 hotends / E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/ramps/pins_FORMBOT_TREX3.h b/Marlin/src/pins/ramps/pins_FORMBOT_TREX3.h index a97b0d2d1227..76a9fbe62804 100644 --- a/Marlin/src/pins/ramps/pins_FORMBOT_TREX3.h +++ b/Marlin/src/pins/ramps/pins_FORMBOT_TREX3.h @@ -25,9 +25,10 @@ * Formbot pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define REQUIRE_MEGA2560 +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "Formbot supports up to 2 hotends / E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/ramps/pins_K8800.h b/Marlin/src/pins/ramps/pins_K8800.h index 5388c9621da5..9bc74943b47a 100644 --- a/Marlin/src/pins/ramps/pins_K8800.h +++ b/Marlin/src/pins/ramps/pins_K8800.h @@ -25,9 +25,7 @@ * Velleman K8800 (Vertex) */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "K8800" #define DEFAULT_MACHINE_NAME "Vertex Delta" diff --git a/Marlin/src/pins/ramps/pins_LONGER3D_LKx_PRO.h b/Marlin/src/pins/ramps/pins_LONGER3D_LKx_PRO.h index 6fcb7b94e0c2..2fd599e61981 100644 --- a/Marlin/src/pins/ramps/pins_LONGER3D_LKx_PRO.h +++ b/Marlin/src/pins/ramps/pins_LONGER3D_LKx_PRO.h @@ -25,9 +25,10 @@ * Longer3D LK1/LK4/LK5 Pro board pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 1 || E_STEPPERS > 1 +#define REQUIRE_MEGA2560 +#include "env_validate.h" + +#if HOTENDS > 1 || E_STEPPERS > 1 #error "Longer3D LGT KIT V1.0 board only supports one hotend / E-stepper. Comment out this line to continue." #endif @@ -42,9 +43,6 @@ #warning "Serial 3 is originally reserved to Y limit switches. Hardware changes are required to use it." #endif -// Custom flags and defines for the build -//#define BOARD_CUSTOM_BUILD_FLAGS -D__FOO__ - #define BOARD_INFO_NAME "LGT KIT V1.0" // diff --git a/Marlin/src/pins/ramps/pins_RAMPS.h b/Marlin/src/pins/ramps/pins_RAMPS.h index 5bcd877dcdbc..f56a9ec38ed7 100644 --- a/Marlin/src/pins/ramps/pins_RAMPS.h +++ b/Marlin/src/pins/ramps/pins_RAMPS.h @@ -45,18 +45,7 @@ * 7 | 11 */ -#ifdef TARGET_LPC1768 - #error "Oops! Set MOTHERBOARD to an LPC1768-based board when building for LPC1768." -#elif defined(__STM32F1__) - #error "Oops! Set MOTHERBOARD to an STM32F1-based board when building for STM32F1." -#endif - -#if NOT_TARGET(IS_RAMPS_SMART, IS_RAMPS_DUO, IS_RAMPS4DUE, TARGET_LPC1768, __AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' (or other appropriate target) in 'Tools > Board.'" -#endif - -// Custom flags and defines for the build -//#define BOARD_CUSTOM_BUILD_FLAGS -D__FOO__ +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "RAMPS 1.4" @@ -124,14 +113,14 @@ #define X_DIR_PIN 55 #define X_ENABLE_PIN 38 #ifndef X_CS_PIN - #define X_CS_PIN 53 + #define X_CS_PIN EXP2_07_PIN #endif #define Y_STEP_PIN 60 #define Y_DIR_PIN 61 #define Y_ENABLE_PIN 56 #ifndef Y_CS_PIN - #define Y_CS_PIN 49 + #define Y_CS_PIN EXP2_04_PIN #endif #ifndef Z_STEP_PIN @@ -245,7 +234,7 @@ // // Misc. Functions // -#define SDSS 53 +#define SDSS EXP2_07_PIN #define LED_PIN 13 #ifndef FILWIDTH_PIN @@ -307,6 +296,9 @@ * * Hardware serial communication ports. * If undefined software serial is used according to the pins below + * + * Serial2 -- AUX-4 Pin 18 (D16 TX2) and AUX-4 Pin 17 (D17 RX2) + * Serial1 -- Pins D18 and D19 are used for Z-MIN and Z-MAX */ //#define X_HARDWARE_SERIAL Serial1 //#define X2_HARDWARE_SERIAL Serial1 @@ -426,10 +418,57 @@ #define E_MUX2_PIN 44 // E1_CS_PIN #endif +// +// Aux 3 GND D52 D50 5V +// NC D53 D51 D49 + +// +// Aux 4 D16 D17 D23 D25 D27 D29 D31 D33 D35 D37 D39 D41 D43 D45 D47 D32 GND 5V +// + +/** + * LCD adapter. Please note: These comes in two variants. The socket keys can be + * on either side, and may be backwards on some boards / displays. + * _____ _____ + * D37 |10 9 | D35 (MISO) D50 |10 9 | D52 (SCK) + * D17 | 8 7 | D16 D31 | 8 7 | D53 + * D23 6 5 D25 D33 6 5 D51 (MOSI) + * D27 | 4 3 | D29 D49 | 4 3 | D41 + * GND | 2 1 | 5V GND | 2 1 | NC + * ----- ----- + * EXP1 EXP2 + */ + +#ifndef EXP1_03_PIN + #define EXP1_03_PIN 29 + #define EXP1_04_PIN 27 + #define EXP1_05_PIN 25 + #define EXP1_06_PIN 23 + #define EXP1_07_PIN 16 + #define EXP1_08_PIN 17 + #define EXP1_09_PIN 35 + #define EXP1_10_PIN 37 + + #define EXP2_03_PIN 41 + #define EXP2_04_PIN 49 + #define EXP2_05_PIN 51 + #define EXP2_06_PIN 33 + #define EXP2_07_PIN 53 + #define EXP2_08_PIN 31 + #define EXP2_09_PIN 52 + #define EXP2_10_PIN 50 +#endif + ////////////////////////// // LCDs and Controllers // ////////////////////////// +// GLCD features +// Uncomment screen orientation +//#define LCD_SCREEN_ROT_90 +//#define LCD_SCREEN_ROT_180 +//#define LCD_SCREEN_ROT_270 + #if HAS_WIRED_LCD // @@ -437,9 +476,9 @@ // #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD) - #define LCD_PINS_RS 49 // CS chip select /SS chip slave select - #define LCD_PINS_ENABLE 51 // SID (MOSI) - #define LCD_PINS_D4 52 // SCK (CLK) clock + #define LCD_PINS_RS EXP2_04_PIN // CS chip select /SS chip slave select + #define LCD_PINS_ENABLE EXP2_05_PIN // SID (MOSI) + #define LCD_PINS_D4 EXP2_09_PIN // SCK (CLK) clock #elif BOTH(IS_NEWPANEL, PANEL_ONE) @@ -452,18 +491,18 @@ #elif ENABLED(TFTGLCD_PANEL_SPI) - #define TFTGLCD_CS 33 + #define TFTGLCD_CS EXP2_06_PIN #else #if ENABLED(CR10_STOCKDISPLAY) - #define LCD_PINS_RS 27 - #define LCD_PINS_ENABLE 29 - #define LCD_PINS_D4 25 + #define LCD_PINS_RS EXP1_04_PIN + #define LCD_PINS_ENABLE EXP1_03_PIN + #define LCD_PINS_D4 EXP1_05_PIN #if !IS_NEWPANEL - #define BEEPER_PIN 37 + #define BEEPER_PIN EXP1_10_PIN #endif #elif ENABLED(ZONESTAR_LCD) @@ -479,25 +518,25 @@ #else #if EITHER(MKS_12864OLED, MKS_12864OLED_SSD1306) - #define LCD_PINS_DC 25 // Set as output on init - #define LCD_PINS_RS 27 // Pull low for 1s to init + #define LCD_PINS_DC EXP1_05_PIN // Set as output on init + #define LCD_PINS_RS EXP1_04_PIN // Pull low for 1s to init // DOGM SPI LCD Support #define DOGLCD_A0 LCD_PINS_DC - #define DOGLCD_CS 16 - #define DOGLCD_MOSI 17 - #define DOGLCD_SCK 23 + #define DOGLCD_CS EXP1_07_PIN + #define DOGLCD_MOSI EXP1_08_PIN + #define DOGLCD_SCK EXP1_06_PIN #else - #define LCD_PINS_RS 16 - #define LCD_PINS_ENABLE 17 - #define LCD_PINS_D4 23 - #define LCD_PINS_D5 25 - #define LCD_PINS_D6 27 + #define LCD_PINS_RS EXP1_07_PIN + #define LCD_PINS_ENABLE EXP1_08_PIN + #define LCD_PINS_D4 EXP1_06_PIN + #define LCD_PINS_D5 EXP1_05_PIN + #define LCD_PINS_D6 EXP1_04_PIN #endif - #define LCD_PINS_D7 29 + #define LCD_PINS_D7 EXP1_03_PIN #if !IS_NEWPANEL - #define BEEPER_PIN 33 + #define BEEPER_PIN EXP2_06_PIN #endif #endif @@ -508,7 +547,7 @@ //#define SHIFT_CLK_PIN 38 //#define SHIFT_LD_PIN 42 //#define SHIFT_OUT_PIN 40 - //#define SHIFT_EN_PIN 17 + //#define SHIFT_EN_PIN EXP1_08_PIN #endif #endif @@ -524,22 +563,22 @@ #if IS_RRD_SC - #define BEEPER_PIN 37 + #define BEEPER_PIN EXP1_10_PIN #if ENABLED(CR10_STOCKDISPLAY) - #define BTN_EN1 17 - #define BTN_EN2 23 + #define BTN_EN1 EXP1_08_PIN + #define BTN_EN2 EXP1_06_PIN #else - #define BTN_EN1 31 - #define BTN_EN2 33 + #define BTN_EN1 EXP2_08_PIN + #define BTN_EN2 EXP2_06_PIN #endif - #define BTN_ENC 35 + #define BTN_ENC EXP1_09_PIN #ifndef SD_DETECT_PIN - #define SD_DETECT_PIN 49 + #define SD_DETECT_PIN EXP2_04_PIN #endif #ifndef KILL_PIN - #define KILL_PIN 41 + #define KILL_PIN EXP2_03_PIN #endif #if ENABLED(BQ_LCD_SMART_CONTROLLER) @@ -559,7 +598,7 @@ #define BTN_EN2 43 #define BTN_ENC 32 #define LCD_SDSS SDSS - #define KILL_PIN 41 + #define KILL_PIN EXP2_03_PIN #elif ENABLED(LCD_I2C_VIKI) @@ -568,7 +607,7 @@ #define BTN_ENC -1 #define LCD_SDSS SDSS - #define SD_DETECT_PIN 49 + #define SD_DETECT_PIN EXP2_04_PIN #elif ANY(VIKI2, miniVIKI) @@ -576,87 +615,81 @@ #define DOGLCD_A0 44 #define LCD_SCREEN_ROT_180 - #define BEEPER_PIN 33 + #define BEEPER_PIN EXP2_06_PIN #define STAT_LED_RED_PIN 32 - #define STAT_LED_BLUE_PIN 35 + #define STAT_LED_BLUE_PIN EXP1_09_PIN #define BTN_EN1 22 #define BTN_EN2 7 #define BTN_ENC 39 #define SD_DETECT_PIN -1 // Pin 49 for display SD interface, 72 for easy adapter board - #define KILL_PIN 31 + #define KILL_PIN EXP2_08_PIN #elif ENABLED(ELB_FULL_GRAPHIC_CONTROLLER) - #define DOGLCD_CS 29 - #define DOGLCD_A0 27 + #define DOGLCD_CS EXP1_03_PIN + #define DOGLCD_A0 EXP1_04_PIN - #define BEEPER_PIN 23 - #define LCD_BACKLIGHT_PIN 33 + #define BEEPER_PIN EXP1_06_PIN + #define LCD_BACKLIGHT_PIN EXP2_06_PIN - #define BTN_EN1 35 - #define BTN_EN2 37 - #define BTN_ENC 31 + #define BTN_EN1 EXP1_09_PIN + #define BTN_EN2 EXP1_10_PIN + #define BTN_ENC EXP2_08_PIN #define LCD_SDSS SDSS - #define SD_DETECT_PIN 49 - #define KILL_PIN 41 + #define SD_DETECT_PIN EXP2_04_PIN + #define KILL_PIN EXP2_03_PIN #elif EITHER(MKS_MINI_12864, FYSETC_MINI_12864) - #define BEEPER_PIN 37 - #define BTN_ENC 35 - #define SD_DETECT_PIN 49 + #define BEEPER_PIN EXP1_10_PIN + #define BTN_ENC EXP1_09_PIN + #define SD_DETECT_PIN EXP2_04_PIN #ifndef KILL_PIN - #define KILL_PIN 41 + #define KILL_PIN EXP2_03_PIN #endif #if ENABLED(MKS_MINI_12864) - #define DOGLCD_A0 27 - #define DOGLCD_CS 25 - - // GLCD features - // Uncomment screen orientation - //#define LCD_SCREEN_ROT_90 - //#define LCD_SCREEN_ROT_180 - //#define LCD_SCREEN_ROT_270 + #define DOGLCD_A0 EXP1_04_PIN + #define DOGLCD_CS EXP1_05_PIN // not connected to a pin #define LCD_BACKLIGHT_PIN -1 // 65 (MKS mini12864 can't adjust backlight by software!) - #define BTN_EN1 31 - #define BTN_EN2 33 + #define BTN_EN1 EXP2_08_PIN + #define BTN_EN2 EXP2_06_PIN #elif ENABLED(FYSETC_MINI_12864) // From https://wiki.fysetc.com/Mini12864_Panel/?fbclid=IwAR1FyjuNdVOOy9_xzky3qqo_WeM5h-4gpRnnWhQr_O1Ef3h0AFnFXmCehK8 - #define DOGLCD_A0 16 - #define DOGLCD_CS 17 + #define DOGLCD_A0 EXP1_07_PIN + #define DOGLCD_CS EXP1_08_PIN - #define BTN_EN1 33 - #define BTN_EN2 31 + #define BTN_EN1 EXP2_06_PIN + #define BTN_EN2 EXP2_08_PIN //#define FORCE_SOFT_SPI // Use this if default of hardware SPI causes display problems // results in LCD soft SPI mode 3, SD soft SPI mode 0 - #define LCD_RESET_PIN 23 // Must be high or open for LCD to operate normally. + #define LCD_RESET_PIN EXP1_06_PIN // Must be high or open for LCD to operate normally. #if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0) #ifndef RGB_LED_R_PIN - #define RGB_LED_R_PIN 25 + #define RGB_LED_R_PIN EXP1_05_PIN #endif #ifndef RGB_LED_G_PIN - #define RGB_LED_G_PIN 27 + #define RGB_LED_G_PIN EXP1_04_PIN #endif #ifndef RGB_LED_B_PIN - #define RGB_LED_B_PIN 29 + #define RGB_LED_B_PIN EXP1_03_PIN #endif #elif ENABLED(FYSETC_MINI_12864_2_1) - #define NEOPIXEL_PIN 25 + #define NEOPIXEL_PIN EXP1_05_PIN #endif #endif @@ -670,17 +703,11 @@ #define DOGLCD_A0 44 #define DOGLCD_CS 66 - // GLCD features - // Uncomment screen orientation - //#define LCD_SCREEN_ROT_90 - //#define LCD_SCREEN_ROT_180 - //#define LCD_SCREEN_ROT_270 - #define BTN_EN1 40 #define BTN_EN2 63 #define BTN_ENC 59 - #define SD_DETECT_PIN 49 + #define SD_DETECT_PIN EXP2_04_PIN #define KILL_PIN 64 #elif ENABLED(ZONESTAR_LCD) @@ -690,31 +717,33 @@ #elif ENABLED(AZSMZ_12864) // Pins only defined for RAMPS_SMART currently - #error "No pins defined for RAMPS with AZSMZ_12864." + #if DISABLED(IS_RAMPS_SMART) + #error "No pins defined for RAMPS with AZSMZ_12864." + #endif #elif IS_TFTGLCD_PANEL - #define SD_DETECT_PIN 49 + #define SD_DETECT_PIN EXP2_04_PIN #else // Beeper on AUX-4 - #define BEEPER_PIN 33 + #define BEEPER_PIN EXP2_06_PIN // Buttons are directly attached to AUX-2 #if ENABLED(PANEL_ONE) #define BTN_EN1 59 // AUX2 PIN 3 #define BTN_EN2 63 // AUX2 PIN 4 - #define BTN_ENC 49 // AUX3 PIN 7 + #define BTN_ENC EXP2_04_PIN #else - #define BTN_EN1 37 - #define BTN_EN2 35 - #define BTN_ENC 31 + #define BTN_EN1 EXP1_10_PIN + #define BTN_EN2 EXP1_09_PIN + #define BTN_ENC EXP2_08_PIN #endif #if ENABLED(G3D_PANEL) - #define SD_DETECT_PIN 49 - #define KILL_PIN 41 + #define SD_DETECT_PIN EXP2_04_PIN + #define KILL_PIN EXP2_03_PIN #endif #endif @@ -741,7 +770,8 @@ #error "CAUTION! LCD_FYSETC_TFT81050 requires wiring modifications. See 'pins_RAMPS.h' for details. Comment out this line to continue." - /** FYSETC TFT TFT81050 display pinout + /** + * FYSETC TFT-81050 display pinout * * Board Display * _____ _____ @@ -766,16 +796,16 @@ * EXP2-7 ----------- EXP1-4 * EXP2-8 ----------- EXP1-3 * EXP2-1 ----------- EXP1-2 - * EXP1-10 ----------- EXP1-1 + * EXP1-10 ---------- EXP1-1 * * NOTE: The MISO pin should not get a 5V signal. * To fix, insert a 1N4148 diode in the MISO line. */ - #define BEEPER_PIN 37 + #define BEEPER_PIN EXP1_10_PIN - #define SD_DETECT_PIN 49 + #define SD_DETECT_PIN EXP2_04_PIN - #define CLCD_MOD_RESET 31 - #define CLCD_SPI_CS 33 + #define CLCD_MOD_RESET EXP2_08_PIN + #define CLCD_SPI_CS EXP2_06_PIN #endif // TOUCH_UI_FTDI_EVE && LCD_FYSETC_TFT81050 diff --git a/Marlin/src/pins/ramps/pins_RAMPS_CREALITY.h b/Marlin/src/pins/ramps/pins_RAMPS_CREALITY.h index 1dc898e6ca9a..05de208ca1e9 100644 --- a/Marlin/src/pins/ramps/pins_RAMPS_CREALITY.h +++ b/Marlin/src/pins/ramps/pins_RAMPS_CREALITY.h @@ -35,7 +35,7 @@ #define MOSFET_D_PIN 7 #define FIL_RUNOUT_PIN 2 -#if NUM_RUNOUT_SENSORS > 1 +#if NUM_RUNOUT_SENSORS >= 2 #define FIL_RUNOUT2_PIN 15 // Creality CR-X can use dual runout sensors #endif diff --git a/Marlin/src/pins/ramps/pins_RAMPS_OLD.h b/Marlin/src/pins/ramps/pins_RAMPS_OLD.h index 6d2dad231491..a43ee3c6ca5a 100644 --- a/Marlin/src/pins/ramps/pins_RAMPS_OLD.h +++ b/Marlin/src/pins/ramps/pins_RAMPS_OLD.h @@ -25,9 +25,7 @@ * Arduino Mega with RAMPS v1.0, v1.1, v1.2 pin assignments */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "RAMPS <1.2" diff --git a/Marlin/src/pins/ramps/pins_RAMPS_PLUS.h b/Marlin/src/pins/ramps/pins_RAMPS_PLUS.h index 23b1dfa34690..43a769b34db7 100644 --- a/Marlin/src/pins/ramps/pins_RAMPS_PLUS.h +++ b/Marlin/src/pins/ramps/pins_RAMPS_PLUS.h @@ -37,9 +37,7 @@ * RAMPS_PLUS_SF (Spindle, Controller Fan) */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "RAMPS 1.4 Plus" diff --git a/Marlin/src/pins/ramps/pins_RAMPS_S_12.h b/Marlin/src/pins/ramps/pins_RAMPS_S_12.h index 1bcf310bc17c..62b6e3ff940b 100644 --- a/Marlin/src/pins/ramps/pins_RAMPS_S_12.h +++ b/Marlin/src/pins/ramps/pins_RAMPS_S_12.h @@ -34,12 +34,7 @@ * Other pins_MYBOARD.h files may override these defaults */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif - -// Custom flags and defines for the build -//#define BOARD_CUSTOM_BUILD_FLAGS -D__FOO__ +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "RAMPS S 1.2" diff --git a/Marlin/src/pins/ramps/pins_RUMBA.h b/Marlin/src/pins/ramps/pins_RUMBA.h index 4af49d9164d4..942afafd7a64 100644 --- a/Marlin/src/pins/ramps/pins_RUMBA.h +++ b/Marlin/src/pins/ramps/pins_RUMBA.h @@ -25,9 +25,10 @@ * RUMBA pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 3 || E_STEPPERS > 3 +#define REQUIRE_MEGA2560 +#include "env_validate.h" + +#if HOTENDS > 3 || E_STEPPERS > 3 #error "RUMBA supports up to 3 hotends / E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/ramps/pins_TENLOG_D3_HERO.h b/Marlin/src/pins/ramps/pins_TENLOG_D3_HERO.h index 84e7e311264e..53e419af00cc 100644 --- a/Marlin/src/pins/ramps/pins_TENLOG_D3_HERO.h +++ b/Marlin/src/pins/ramps/pins_TENLOG_D3_HERO.h @@ -25,9 +25,10 @@ * Tenlog pin assignments */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define REQUIRE_MEGA2560 +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "Tenlog supports up to 2 hotends / E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/ramps/pins_TRONXY_V3_1_0.h b/Marlin/src/pins/ramps/pins_TRONXY_V3_1_0.h index f342eff8aa6c..ffe6d56eb8b1 100644 --- a/Marlin/src/pins/ramps/pins_TRONXY_V3_1_0.h +++ b/Marlin/src/pins/ramps/pins_TRONXY_V3_1_0.h @@ -25,9 +25,10 @@ * Arduino Mega for Tronxy X5S-2E, etc. */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define REQUIRE_MEGA2560 +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "TRONXY-V3-1.0 supports only 2 hotends/E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/ramps/pins_TT_OSCAR.h b/Marlin/src/pins/ramps/pins_TT_OSCAR.h index ca402553e112..18d0f1770e11 100644 --- a/Marlin/src/pins/ramps/pins_TT_OSCAR.h +++ b/Marlin/src/pins/ramps/pins_TT_OSCAR.h @@ -20,9 +20,7 @@ * */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #if HOTENDS > 5 || E_STEPPERS > 5 #error "TTOSCAR supports up to 5 hotends / E-steppers. Comment out this line to continue." diff --git a/Marlin/src/pins/ramps/pins_ULTIMAIN_2.h b/Marlin/src/pins/ramps/pins_ULTIMAIN_2.h index 211caddba0ef..128f1974e0e6 100644 --- a/Marlin/src/pins/ramps/pins_ULTIMAIN_2.h +++ b/Marlin/src/pins/ramps/pins_ULTIMAIN_2.h @@ -33,9 +33,8 @@ * case light */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#define REQUIRE_MEGA2560 +#include "env_validate.h" #define BOARD_INFO_NAME "Ultimaker 2.x" #define DEFAULT_MACHINE_NAME "Ultimaker" diff --git a/Marlin/src/pins/ramps/pins_ULTIMAKER.h b/Marlin/src/pins/ramps/pins_ULTIMAKER.h index 22c7fd95b47e..0bc04d962aaf 100644 --- a/Marlin/src/pins/ramps/pins_ULTIMAKER.h +++ b/Marlin/src/pins/ramps/pins_ULTIMAKER.h @@ -33,9 +33,7 @@ * case light */ -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Ultimaker" #define DEFAULT_MACHINE_NAME BOARD_INFO_NAME diff --git a/Marlin/src/pins/ramps/pins_ULTIMAKER_OLD.h b/Marlin/src/pins/ramps/pins_ULTIMAKER_OLD.h index 37c28ece4ce4..091356a11f82 100644 --- a/Marlin/src/pins/ramps/pins_ULTIMAKER_OLD.h +++ b/Marlin/src/pins/ramps/pins_ULTIMAKER_OLD.h @@ -60,9 +60,7 @@ //#define BOARD_REV_1_0 //#define BOARD_REV_1_5 -#if NOT_TARGET(__AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif +#include "env_validate.h" #ifdef BOARD_REV_1_1_TO_1_3 #define BOARD_INFO_NAME "Ultimaker 1.1-1.3" diff --git a/Marlin/src/pins/ramps/pins_ZRIB_V52.h b/Marlin/src/pins/ramps/pins_ZRIB_V52.h index 983c840bbc13..f4db07ef8d4e 100644 --- a/Marlin/src/pins/ramps/pins_ZRIB_V52.h +++ b/Marlin/src/pins/ramps/pins_ZRIB_V52.h @@ -46,6 +46,7 @@ #define E2_STEP_PIN 4 #define E2_DIR_PIN 5 #define E2_ENABLE_PIN 22 +#define HEATER_1_PIN 7 #include "pins_MKS_BASE_common.h" diff --git a/Marlin/src/pins/ramps/pins_Z_BOLT_X_SERIES.h b/Marlin/src/pins/ramps/pins_Z_BOLT_X_SERIES.h index 096d970871f2..26ad5fd6580a 100644 --- a/Marlin/src/pins/ramps/pins_Z_BOLT_X_SERIES.h +++ b/Marlin/src/pins/ramps/pins_Z_BOLT_X_SERIES.h @@ -25,9 +25,10 @@ * Z-Bolt X Series board – based on Arduino Mega2560 */ -#if NOT_TARGET(__AVR_ATmega2560__) - #error "Oops! Select 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#elif HOTENDS > 4 || E_STEPPERS > 4 +#define REQUIRE_MEGA2560 +#include "env_validate.h" + +#if HOTENDS > 4 || E_STEPPERS > 4 #error "Z-Bolt X Series board supports up to 4 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/sam/env_validate.h b/Marlin/src/pins/sam/env_validate.h new file mode 100644 index 000000000000..09bcd1364921 --- /dev/null +++ b/Marlin/src/pins/sam/env_validate.h @@ -0,0 +1,33 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if BOTH(ALLOW_MEGA1280, ALLOW_MEGA2560) && NOT_TARGET(__SAM3X8E__, __AVR_ATmega1280__, __AVR_ATmega2560__) + #error "Oops! Select 'Arduino Due or Mega' in 'Tools > Board.'" +#elif ENABLED(ALLOW_MEGA2560) && NOT_TARGET(__SAM3X8E__, __AVR_ATmega2560__) + #error "Oops! Select 'Arduino Due or Mega' in 'Tools > Board.'" +#elif ENABLED(ALLOW_MEGA1280) && NOT_TARGET(__SAM3X8E__, __AVR_ATmega1280__) + #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" +#endif + +#undef ALLOW_MEGA1280 +#undef ALLOW_MEGA2560 diff --git a/Marlin/src/pins/sam/pins_ADSK.h b/Marlin/src/pins/sam/pins_ADSK.h index b0e171cf1716..9026ca7771da 100644 --- a/Marlin/src/pins/sam/pins_ADSK.h +++ b/Marlin/src/pins/sam/pins_ADSK.h @@ -27,9 +27,9 @@ #define BOARD_INFO_NAME "ADSK" -#if NOT_TARGET(__SAM3X8E__, __AVR_ATmega1280__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino Due or Mega' in 'Tools > Board.'" -#endif +#define ALLOW_MEGA1280 +#define ALLOW_MEGA2560 +#include "env_validate.h" /* CNC shield modifications: FROM THE BOTTOM CUT THE 5V PIN THAT GOES TO ARDUINO!!! diff --git a/Marlin/src/pins/sam/pins_ALLIGATOR_R2.h b/Marlin/src/pins/sam/pins_ALLIGATOR_R2.h index b01d1aafdfe0..c273edfc6b4d 100644 --- a/Marlin/src/pins/sam/pins_ALLIGATOR_R2.h +++ b/Marlin/src/pins/sam/pins_ALLIGATOR_R2.h @@ -26,9 +26,7 @@ * https://reprap.org/wiki/Alligator_Board */ -#if NOT_TARGET(__SAM3X8E__) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Alligator Board R2" diff --git a/Marlin/src/pins/sam/pins_CNCONTROLS_15D.h b/Marlin/src/pins/sam/pins_CNCONTROLS_15D.h index 5bf31450b707..a63c33788044 100644 --- a/Marlin/src/pins/sam/pins_CNCONTROLS_15D.h +++ b/Marlin/src/pins/sam/pins_CNCONTROLS_15D.h @@ -24,9 +24,7 @@ * CNControls V15 for HMS434 with DUE pin assignments */ -#if NOT_TARGET(__SAM3X8E__) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "CN Controls V15D" diff --git a/Marlin/src/pins/sam/pins_DUE3DOM.h b/Marlin/src/pins/sam/pins_DUE3DOM.h index 90d6bdc3403d..4ebece58e4c2 100644 --- a/Marlin/src/pins/sam/pins_DUE3DOM.h +++ b/Marlin/src/pins/sam/pins_DUE3DOM.h @@ -25,9 +25,7 @@ * DUE3DOM pin assignments */ -#if NOT_TARGET(__SAM3X8E__) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "DUE3DOM" diff --git a/Marlin/src/pins/sam/pins_DUE3DOM_MINI.h b/Marlin/src/pins/sam/pins_DUE3DOM_MINI.h index 5a205423ed5b..dd8f2636760c 100644 --- a/Marlin/src/pins/sam/pins_DUE3DOM_MINI.h +++ b/Marlin/src/pins/sam/pins_DUE3DOM_MINI.h @@ -25,9 +25,7 @@ * DUE3DOM MINI pin assignments */ -#if NOT_TARGET(__SAM3X8E__) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "DUE3DOM MINI" diff --git a/Marlin/src/pins/sam/pins_PRINTRBOARD_G2.h b/Marlin/src/pins/sam/pins_PRINTRBOARD_G2.h index 424d858a8512..874950f34b80 100644 --- a/Marlin/src/pins/sam/pins_PRINTRBOARD_G2.h +++ b/Marlin/src/pins/sam/pins_PRINTRBOARD_G2.h @@ -25,9 +25,7 @@ * PRINTRBOARD_G2 */ -#if NOT_TARGET(__SAM3X8E__) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "Printrboard G2" diff --git a/Marlin/src/pins/sam/pins_RADDS.h b/Marlin/src/pins/sam/pins_RADDS.h index 7b9c7f1b2818..7b0ec5ab68e8 100644 --- a/Marlin/src/pins/sam/pins_RADDS.h +++ b/Marlin/src/pins/sam/pins_RADDS.h @@ -25,9 +25,7 @@ * RADDS */ -#if NOT_TARGET(__SAM3X8E__) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "RADDS" diff --git a/Marlin/src/pins/sam/pins_RAMPS4DUE.h b/Marlin/src/pins/sam/pins_RAMPS4DUE.h index 54548333b5fd..6d9d06a17561 100644 --- a/Marlin/src/pins/sam/pins_RAMPS4DUE.h +++ b/Marlin/src/pins/sam/pins_RAMPS4DUE.h @@ -39,14 +39,9 @@ * A15 | NC */ -#if NOT_TARGET(__SAM3X8E__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino Due' or 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif - +#define ALLOW_SAM3X8E #define BOARD_INFO_NAME "RAMPS4DUE" -#define IS_RAMPS4DUE - // // Temperature Sensors // diff --git a/Marlin/src/pins/sam/pins_RAMPS_DUO.h b/Marlin/src/pins/sam/pins_RAMPS_DUO.h index d2ab5c96b22d..b1a6680c506c 100644 --- a/Marlin/src/pins/sam/pins_RAMPS_DUO.h +++ b/Marlin/src/pins/sam/pins_RAMPS_DUO.h @@ -43,14 +43,9 @@ * A15 | A11 */ -#if NOT_TARGET(__SAM3X8E__, __AVR_ATmega2560__) - #error "Oops! Select 'Arduino Due' or 'Arduino/Genuino Mega or Mega 2560' in 'Tools > Board.'" -#endif - #define BOARD_INFO_NAME "RAMPS Duo" -#define IS_RAMPS_DUO - +#define ALLOW_SAM3X8E #include "../ramps/pins_RAMPS.h" // diff --git a/Marlin/src/pins/sam/pins_RAMPS_FD_V1.h b/Marlin/src/pins/sam/pins_RAMPS_FD_V1.h index 80e8f0dc7e9d..e4c53530f7b0 100644 --- a/Marlin/src/pins/sam/pins_RAMPS_FD_V1.h +++ b/Marlin/src/pins/sam/pins_RAMPS_FD_V1.h @@ -28,9 +28,7 @@ * Use 4k7 thermistor tables */ -#if NOT_TARGET(__SAM3X8E__) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "RAMPS-FD v1" diff --git a/Marlin/src/pins/sam/pins_RAMPS_SMART.h b/Marlin/src/pins/sam/pins_RAMPS_SMART.h index 9b76ee290b96..3882dfb94420 100644 --- a/Marlin/src/pins/sam/pins_RAMPS_SMART.h +++ b/Marlin/src/pins/sam/pins_RAMPS_SMART.h @@ -60,18 +60,26 @@ * (Search the web for "Arduino DUE Board Pinout" to see the correct header.) */ -#if NOT_TARGET(__SAM3X8E__) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif - #define BOARD_INFO_NAME "RAMPS-SMART" -#define IS_RAMPS_SMART +#define ALLOW_SAM3X8E #include "../ramps/pins_RAMPS.h" // I2C EEPROM with 4K of space #define I2C_EEPROM #define MARLIN_EEPROM_SIZE 0x1000 +#define SDA_PIN 20 +#define SCL_PIN 21 + +// See EEPROM device datasheet for the following values. These are for 24xx256 +#define EEPROM_SERIAL_ADDR 0x50 // 7 bit i2c address (without R/W bit) +#define EEPROM_PAGE_SIZE 64 // page write buffer size +#define EEPROM_PAGE_WRITE_TIME 7 // page write time in milliseconds (docs say 5ms but that is too short) + +#define TWI_CLOCK_FREQ 400000 +#define EEPROM_ADDRSZ_BYTES TWI_MMR_IADRSZ_2_BYTE // TWI_MMR_IADRSZ_1_BYTE for 1 byte, or TWI_MMR_IADRSZ_2_BYTE for 2 byte +#define EEPROM_AVAILABLE EEPROM_I2C + #define RESET_PIN 42 // Resets the board if the jumper is attached // @@ -97,6 +105,7 @@ // // LCD / Controller // + // Support for AZSMZ 12864 LCD with SD Card 3D printer smart controller control panel #if ENABLED(AZSMZ_12864) #define BEEPER_PIN 66 // Smart RAMPS 1.42 pinout diagram on RepRap WIKI erroneously says this should be pin 65 diff --git a/Marlin/src/pins/sam/pins_RURAMPS4D_11.h b/Marlin/src/pins/sam/pins_RURAMPS4D_11.h index 6a283401f453..908bbc6b229e 100644 --- a/Marlin/src/pins/sam/pins_RURAMPS4D_11.h +++ b/Marlin/src/pins/sam/pins_RURAMPS4D_11.h @@ -32,9 +32,7 @@ * | */ -#if NOT_TARGET(__SAM3X8E__) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "RuRAMPS4Due v1.1" diff --git a/Marlin/src/pins/sam/pins_RURAMPS4D_13.h b/Marlin/src/pins/sam/pins_RURAMPS4D_13.h index 6ec10f64af7d..3e73c33acbc4 100644 --- a/Marlin/src/pins/sam/pins_RURAMPS4D_13.h +++ b/Marlin/src/pins/sam/pins_RURAMPS4D_13.h @@ -32,9 +32,7 @@ * | */ -#if NOT_TARGET(__SAM3X8E__) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "RuRAMPS4Due v1.3" diff --git a/Marlin/src/pins/sam/pins_ULTRATRONICS_PRO.h b/Marlin/src/pins/sam/pins_ULTRATRONICS_PRO.h index ea096187f713..e567b0f5e11d 100644 --- a/Marlin/src/pins/sam/pins_ULTRATRONICS_PRO.h +++ b/Marlin/src/pins/sam/pins_ULTRATRONICS_PRO.h @@ -26,9 +26,7 @@ * https://reprapworld.com/documentation/datasheet_ultratronics10_05.pdf */ -#if NOT_TARGET(ARDUINO_ARCH_SAM) - #error "Oops! Select 'Arduino Due' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Ultratronics v1.0" diff --git a/Marlin/src/pins/sanguino/env_validate.h b/Marlin/src/pins/sanguino/env_validate.h new file mode 100644 index 000000000000..d229b6f102e4 --- /dev/null +++ b/Marlin/src/pins/sanguino/env_validate.h @@ -0,0 +1,42 @@ + /** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if ENABLED(ALLOW_MEGA644) + #if NOT_TARGET(__AVR_ATmega644__, __AVR_ATmega644P__, __AVR_ATmega1284P__) + #error "Oops! Select 'Sanguino' in 'Tools > Boards' and 'ATmega644', 'ATmega644P', or 'ATmega1284P' in 'Tools > Processor.'" + #endif +#elif ENABLED(ALLOW_MEGA644P) + #if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega1284P__) + #error "Oops! Select 'Sanguino' in 'Tools > Boards' and 'ATmega644P' or 'ATmega1284P' in 'Tools > Processor.'" + #endif +#elif ENABLED(REQUIRE_MEGA644P) + #if NOT_TARGET(__AVR_ATmega644P__) + #error "Oops! Select 'Sanguino' in 'Tools > Board' and 'ATmega644P' in 'Tools > Processor.'" + #endif +#elif NOT_TARGET(__AVR_ATmega1284P__) + #error "Oops! Select 'Sanguino' in 'Tools > Board' and 'ATmega1284P' in 'Tools > Processor.' (For PlatformIO, use 'melzi' or 'melzi_optiboot.')" +#endif + +#undef ALLOW_MEGA644 +#undef ALLOW_MEGA644P +#undef REQUIRE_MEGA644P diff --git a/Marlin/src/pins/sanguino/pins_GEN3_MONOLITHIC.h b/Marlin/src/pins/sanguino/pins_GEN3_MONOLITHIC.h index 29905c108954..1343739a119e 100644 --- a/Marlin/src/pins/sanguino/pins_GEN3_MONOLITHIC.h +++ b/Marlin/src/pins/sanguino/pins_GEN3_MONOLITHIC.h @@ -48,9 +48,8 @@ * Once installed select the Sanguino board and then select the CPU. */ -#if NOT_TARGET(__AVR_ATmega644P__) - #error "Oops! Select 'Sanguino' in 'Tools > Board.'" -#endif +#define REQUIRE_MEGA644P +#include "env_validate.h" #define BOARD_INFO_NAME "Gen3 Monolithic" #define DEBUG_PIN 0 diff --git a/Marlin/src/pins/sanguino/pins_GEN3_PLUS.h b/Marlin/src/pins/sanguino/pins_GEN3_PLUS.h index 33fc233f7ab1..7cab1bd762c5 100644 --- a/Marlin/src/pins/sanguino/pins_GEN3_PLUS.h +++ b/Marlin/src/pins/sanguino/pins_GEN3_PLUS.h @@ -48,9 +48,8 @@ * Once installed select the SANGUINO board and then select the CPU. */ -#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega1284P__) - #error "Oops! Select 'Sanguino' in 'Tools > Boards' and 'ATmega644P' or 'ATmega1284P' in 'Tools > Processor.'" -#endif +#define ALLOW_MEGA644P +#include "env_validate.h" #define BOARD_INFO_NAME "Gen3+" diff --git a/Marlin/src/pins/sanguino/pins_GEN6.h b/Marlin/src/pins/sanguino/pins_GEN6.h index bfca8e90d9cc..51e8200b9570 100644 --- a/Marlin/src/pins/sanguino/pins_GEN6.h +++ b/Marlin/src/pins/sanguino/pins_GEN6.h @@ -50,9 +50,8 @@ * Once installed select the Sanguino board and then select the CPU. */ -#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega1284P__) - #error "Oops! Select 'Sanguino' in 'Tools > Boards' and 'ATmega644P' or 'ATmega1284P' in 'Tools > Processor.'" -#endif +#define ALLOW_MEGA644P +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "Gen6" diff --git a/Marlin/src/pins/sanguino/pins_GEN7_12.h b/Marlin/src/pins/sanguino/pins_GEN7_12.h index 9db7d7214a5b..0834da78c45c 100644 --- a/Marlin/src/pins/sanguino/pins_GEN7_12.h +++ b/Marlin/src/pins/sanguino/pins_GEN7_12.h @@ -50,9 +50,8 @@ * Once installed select the Sanguino board and then select the CPU. */ -#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega644__, __AVR_ATmega1284P__) - #error "Oops! Select 'Sanguino' in 'Tools > Boards' and 'ATmega644', 'ATmega644P', or 'ATmega1284P' in 'Tools > Processor.'" -#endif +#define ALLOW_MEGA644 +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "Gen7 v1.1 / 1.2" diff --git a/Marlin/src/pins/sanguino/pins_GEN7_14.h b/Marlin/src/pins/sanguino/pins_GEN7_14.h index 66dba533e988..97bfdd28a727 100644 --- a/Marlin/src/pins/sanguino/pins_GEN7_14.h +++ b/Marlin/src/pins/sanguino/pins_GEN7_14.h @@ -50,9 +50,8 @@ * Once installed select the Sanguino board and then select the CPU. */ -#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega644__, __AVR_ATmega1284P__) - #error "Oops! Select 'Sanguino' in 'Tools > Boards' and 'ATmega644', 'ATmega644P', or 'ATmega1284P' in 'Tools > Processor.'" -#endif +#define ALLOW_MEGA644 +#include "env_validate.h" #define BOARD_INFO_NAME "Gen7 v1.4" diff --git a/Marlin/src/pins/sanguino/pins_GEN7_CUSTOM.h b/Marlin/src/pins/sanguino/pins_GEN7_CUSTOM.h index 0c4871fb27d5..6d7678e6e3d2 100644 --- a/Marlin/src/pins/sanguino/pins_GEN7_CUSTOM.h +++ b/Marlin/src/pins/sanguino/pins_GEN7_CUSTOM.h @@ -53,9 +53,8 @@ * Once installed select the Sanguino board and then select the CPU. */ -#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega644__, __AVR_ATmega1284P__) - #error "Oops! Select 'Sanguino' in 'Tools > Boards' and 'ATmega644', 'ATmega644P', or 'ATmega1284P' in 'Tools > Processor.'" -#endif +#define ALLOW_MEGA644 +#include "env_validate.h" #define BOARD_INFO_NAME "Gen7 Custom" diff --git a/Marlin/src/pins/sanguino/pins_OMCA_A.h b/Marlin/src/pins/sanguino/pins_OMCA_A.h index 770732051900..a3ceb76a0de9 100644 --- a/Marlin/src/pins/sanguino/pins_OMCA_A.h +++ b/Marlin/src/pins/sanguino/pins_OMCA_A.h @@ -74,7 +74,7 @@ */ #if NOT_TARGET(__AVR_ATmega644__) - #error "Oops! Select 'Sanguino' in 'Tools > Board' and ATmega644 in 'Tools > Processor.'" + #error "Oops! Select 'Sanguino' in 'Tools > Board' and 'ATmega644' in 'Tools > Processor.'" #endif #define BOARD_INFO_NAME "Alpha OMCA" diff --git a/Marlin/src/pins/sanguino/pins_SANGUINOLOLU_11.h b/Marlin/src/pins/sanguino/pins_SANGUINOLOLU_11.h index af27159936f7..d79ad7a3dda8 100644 --- a/Marlin/src/pins/sanguino/pins_SANGUINOLOLU_11.h +++ b/Marlin/src/pins/sanguino/pins_SANGUINOLOLU_11.h @@ -50,9 +50,8 @@ * Once installed select the Sanguino board and then select the CPU. */ -#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega1284P__) - #error "Oops! Select 'Sanguino' in 'Tools > Boards' and 'ATmega644P' or 'ATmega1284P' in 'Tools > Processor.'" -#endif +#define ALLOW_MEGA644P +#include "env_validate.h" #ifndef BOARD_INFO_NAME #define BOARD_INFO_NAME "Sanguinololu <1.2" diff --git a/Marlin/src/pins/sanguino/pins_SETHI.h b/Marlin/src/pins/sanguino/pins_SETHI.h index dc2133e441dc..a2240b385b2b 100644 --- a/Marlin/src/pins/sanguino/pins_SETHI.h +++ b/Marlin/src/pins/sanguino/pins_SETHI.h @@ -49,9 +49,8 @@ * Once installed select the Sanguino board and then select the CPU. */ -#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega644__, __AVR_ATmega1284P__) - #error "Oops! Select 'Sanguino' in 'Tools > Boards' and 'ATmega644', 'ATmega644P', or 'ATmega1284P' in 'Tools > Processor.'" -#endif +#define ALLOW_MEGA644 +#include "env_validate.h" #define BOARD_INFO_NAME "Sethi 3D_1" diff --git a/Marlin/src/pins/sanguino/pins_ZMIB_V2.h b/Marlin/src/pins/sanguino/pins_ZMIB_V2.h index d064d801329d..0265ae0a64f5 100644 --- a/Marlin/src/pins/sanguino/pins_ZMIB_V2.h +++ b/Marlin/src/pins/sanguino/pins_ZMIB_V2.h @@ -21,9 +21,8 @@ */ #pragma once -#if NOT_TARGET(__AVR_ATmega644P__, __AVR_ATmega1284P__) - #error "Oops! Select 'Sanguino' in 'Tools > Boards' and 'ATmega644P' or 'ATmega1284P' in 'Tools > Processor.'" -#endif +#define ALLOW_MEGA644P +#include "env_validate.h" #define BOARD_INFO_NAME "Zonestar ZMIB_V2" #define BOARD_WEBSITE_URL "www.aliexpress.com/item/32957490744.html" diff --git a/Marlin/src/pins/stm32f1/env_validate.h b/Marlin/src/pins/stm32f1/env_validate.h new file mode 100644 index 000000000000..62ccf7edcc46 --- /dev/null +++ b/Marlin/src/pins/stm32f1/env_validate.h @@ -0,0 +1,26 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if NOT_TARGET(__STM32F1__) + #error "Oops! Select an STM32F1 board in 'Tools > Board.'" +#endif diff --git a/Marlin/src/pins/stm32f1/pins_BEAST.h b/Marlin/src/pins/stm32f1/pins_BEAST.h index bf2cf6463a26..05f77f10291d 100644 --- a/Marlin/src/pins/stm32f1/pins_BEAST.h +++ b/Marlin/src/pins/stm32f1/pins_BEAST.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" /** * 21017 Victor Perez Marlin for stm32f1 test diff --git a/Marlin/src/pins/stm32f1/pins_BTT_SKR_CR6.h b/Marlin/src/pins/stm32f1/pins_BTT_SKR_CR6.h index 73a18faf05b2..e76c77e70685 100644 --- a/Marlin/src/pins/stm32f1/pins_BTT_SKR_CR6.h +++ b/Marlin/src/pins/stm32f1/pins_BTT_SKR_CR6.h @@ -28,9 +28,7 @@ #define DEFAULT_MACHINE_NAME "Creality3D" #define BOARD_INFO_NAME "BTT SKR CR-6" -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" // // Release PB4 (Z_STEP_PIN) from JTAG NRST role diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D.h b/Marlin/src/pins/stm32f1/pins_CHITU3D.h index bb6f5719246e..dd6edf9024b6 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" /** * 2017 Victor Perez Marlin for stm32f1 test diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h index c90ae84acbb9..d25a1f34f9fa 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V5.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" /** * 2017 Victor Perez Marlin for stm32f1 test diff --git a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h index 96cf36629a5b..5afa6531170a 100644 --- a/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h +++ b/Marlin/src/pins/stm32f1/pins_CHITU3D_V6.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" /** * 2017 Victor Perez Marlin for stm32f1 test diff --git a/Marlin/src/pins/stm32f1/pins_CREALITY_V4.h b/Marlin/src/pins/stm32f1/pins_CREALITY_V4.h index 8b5b8562a2bb..733e24cfac92 100644 --- a/Marlin/src/pins/stm32f1/pins_CREALITY_V4.h +++ b/Marlin/src/pins/stm32f1/pins_CREALITY_V4.h @@ -24,9 +24,9 @@ * Creality 4.2.x (STM32F103RET6) board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#elif HOTENDS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#if HOTENDS > 1 || E_STEPPERS > 1 #error "Creality V4 only supports one hotend / E-stepper. Comment out this line to continue." #endif @@ -132,8 +132,12 @@ #define HEATER_0_PIN PA1 // HEATER1 #define HEATER_BED_PIN PA2 // HOT BED -#define FAN_PIN PA0 // FAN -#define FAN_SOFT_PWM +#ifndef FAN_PIN + #define FAN_PIN PA0 // FAN +#endif +#if PIN_EXISTS(FAN) + #define FAN_SOFT_PWM +#endif // // SD Card diff --git a/Marlin/src/pins/stm32f1/pins_CREALITY_V4210.h b/Marlin/src/pins/stm32f1/pins_CREALITY_V4210.h index 025e68d4da05..6585d40d45d5 100644 --- a/Marlin/src/pins/stm32f1/pins_CREALITY_V4210.h +++ b/Marlin/src/pins/stm32f1/pins_CREALITY_V4210.h @@ -24,9 +24,9 @@ * CREALITY 4.2.10 (STM32F103) board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#elif HOTENDS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#if HOTENDS > 1 || E_STEPPERS > 1 #error "CREALITY supports up to 1 hotends / E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/stm32f1/pins_CREALITY_V45x.h b/Marlin/src/pins/stm32f1/pins_CREALITY_V45x.h index f2be2895305f..c73c92080e80 100644 --- a/Marlin/src/pins/stm32f1/pins_CREALITY_V45x.h +++ b/Marlin/src/pins/stm32f1/pins_CREALITY_V45x.h @@ -24,9 +24,7 @@ * Creality v4.5.2 and v4.5.3 (STM32F103RET6) board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #define DEFAULT_MACHINE_NAME "Creality3D" diff --git a/Marlin/src/pins/stm32f1/pins_FLY_MINI.h b/Marlin/src/pins/stm32f1/pins_FLY_MINI.h index 2278d558702e..b94ec0c7f35e 100644 --- a/Marlin/src/pins/stm32f1/pins_FLY_MINI.h +++ b/Marlin/src/pins/stm32f1/pins_FLY_MINI.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "FLY_MINI" #define BOARD_WEBSITE_URL "github.com/FLYmaker" diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h index 3919723f3788..7ffe67c4f86b 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_AIO_II.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "FYSETC AIO II" #define BOARD_WEBSITE_URL "fysetc.com" diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h b/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h index c978092ab22c..552ad9ac5717 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #define DEFAULT_MACHINE_NAME "3D Printer" diff --git a/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH_V12.h b/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH_V12.h index 65b16755ca30..ba35265d10a0 100644 --- a/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH_V12.h +++ b/Marlin/src/pins/stm32f1/pins_FYSETC_CHEETAH_V12.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #include "pins_FYSETC_CHEETAH.h" diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h b/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h index 5b97e7f202de..4edd67a14df2 100644 --- a/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h +++ b/Marlin/src/pins/stm32f1/pins_GTM32_MINI.h @@ -22,13 +22,10 @@ #pragma once /** - * 24 May 2018 - @chepo for STM32F103VET6 - * Schematic: https://github.com/chepo92/Smartto/blob/master/circuit_diagram/Rostock301/Hardware_GTM32_PRO_VB.pdf + * Geeetech GTM32 Mini board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "GTM32 Pro VB" #define DEFAULT_MACHINE_NAME "STM32F103VET6" diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h b/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h index 173eb67f0d09..f346c3a9fdf1 100644 --- a/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h +++ b/Marlin/src/pins/stm32f1/pins_GTM32_MINI_A30.h @@ -22,13 +22,10 @@ #pragma once /** - * 24 May 2018 - @chepo for STM32F103VET6 - * Schematic: https://github.com/chepo92/Smartto/blob/master/circuit_diagram/Rostock301/Hardware_GTM32_PRO_VB.pdf + * Geeetech GTM32 Mini A30 board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "GTM32 Pro VB" #define DEFAULT_MACHINE_NAME "STM32F103VET6" diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h b/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h index 5b97e7f202de..18156fc0ff1f 100644 --- a/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h +++ b/Marlin/src/pins/stm32f1/pins_GTM32_PRO_VB.h @@ -22,15 +22,13 @@ #pragma once /** - * 24 May 2018 - @chepo for STM32F103VET6 - * Schematic: https://github.com/chepo92/Smartto/blob/master/circuit_diagram/Rostock301/Hardware_GTM32_PRO_VB.pdf + * Geeetech GTM32 Pro VB/VD board pin assignments + * http://www.geeetech.com/wiki/index.php/File:Hardware_GTM32_PRO_VB.pdf */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" -#define BOARD_INFO_NAME "GTM32 Pro VB" +#define BOARD_INFO_NAME "GTM32 Pro VB/VD" #define DEFAULT_MACHINE_NAME "STM32F103VET6" #define BOARD_NO_NATIVE_USB diff --git a/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h b/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h index b4a34a4b1e4b..865de809e20a 100644 --- a/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h +++ b/Marlin/src/pins/stm32f1/pins_GTM32_REV_B.h @@ -22,15 +22,12 @@ #pragma once /** - * 24 May 2018 - @chepo for STM32F103VET6 - * Schematic: https://github.com/chepo92/Smartto/blob/master/circuit_diagram/Rostock301/Hardware_GTM32_PRO_VB.pdf + * Geeetech GTM32 Rev. B board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" -#define BOARD_INFO_NAME "GTM32 Pro VB" +#define BOARD_INFO_NAME "GTM32 Rev B" #define DEFAULT_MACHINE_NAME "M201" #define BOARD_NO_NATIVE_USB diff --git a/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h b/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h index 4f02b0e23cde..9f08f18bf7f6 100644 --- a/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h +++ b/Marlin/src/pins/stm32f1/pins_JGAURORA_A5S_A1.h @@ -28,9 +28,9 @@ * Pin assignments for 32-bit JGAurora A5S & A1 */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#elif HOTENDS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#if HOTENDS > 1 || E_STEPPERS > 1 #error "JGAurora A5S A1 only supports one hotend / E-stepper. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h index 33f995dcaef0..fa708b248edf 100644 --- a/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h +++ b/Marlin/src/pins/stm32f1/pins_LONGER3D_LK.h @@ -29,7 +29,6 @@ #endif #define BOARD_INFO_NAME "Longer3D" -#define ALFAWISE_UX0 // Common to all Longer3D STM32F1 boards (used for Open drain mosfets) #define BOARD_NO_NATIVE_USB @@ -92,10 +91,20 @@ #define FAN_MAX_PWM 255 //#define BEEPER_PIN PD13 // pin 60 (Servo PWM output 5V/GND on Board V0G+) made for BL-Touch sensor - // Can drive a PC Buzzer, if connected between PWM and 5V pins + // Can drive a PC Buzzer, if connected between PWM and 5V pins #define LED_PIN PC2 // pin 17 +// Longer3D board mosfets are passing by default +// Avoid nozzle heat and fan start before serial init +#define BOARD_OPENDRAIN_MOSFETS + +#define BOARD_PREINIT() { \ + OUT_WRITE_OD(HEATER_0_PIN, 0); \ + OUT_WRITE_OD(HEATER_BED_PIN, 0); \ + OUT_WRITE_OD(FAN_PIN, 0); \ +} + // // PWM for a servo probe // Other servo devices are not supported on this board! diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h index 3118a521bbeb..14664bda3940 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h @@ -25,9 +25,9 @@ * MKS Robin nano (STM32F130VET6) board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#elif HOTENDS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#if HOTENDS > 1 || E_STEPPERS > 1 #error "MKS Robin E3P only supports one hotend / E-stepper. Comment out this line to continue." #elif HAS_FSMC_TFT #error "MKS Robin E3P doesn't support FSMC-based TFT displays." diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h index c4a7e9f40861..da7bdc79e50d 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3_common.h @@ -25,9 +25,7 @@ * MKS Robin E3 & E3D (STM32F103RCT6) common board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_NO_NATIVE_USB diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE.h index 13c2d41d577b..fad36e838480 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE.h @@ -21,9 +21,9 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#elif HOTENDS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#if HOTENDS > 1 || E_STEPPERS > 1 #error "MKS Robin Lite only supports one hotend / E-stepper. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h index f814052fa800..73fefddf8fbc 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_LITE3.h @@ -25,9 +25,9 @@ * MKS Robin Lite 3 (STM32F103RCT6) board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "MKS Robin Lite3 supports up to 2 hotends / E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h index b3cfe5b6baa7..be23394af7ab 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_MINI.h @@ -25,9 +25,9 @@ * MKS Robin mini (STM32F130VET6) board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#elif HOTENDS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#if HOTENDS > 1 || E_STEPPERS > 1 #error "MKS Robin mini only supports one hotend / E-stepper. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h index 39676bf9d789..10e1633124ad 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_PRO.h @@ -25,9 +25,9 @@ * MKS Robin pro (STM32F103ZET6) board pin assignments */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#elif HOTENDS > 3 || E_STEPPERS > 3 +#include "env_validate.h" + +#if HOTENDS > 3 || E_STEPPERS > 3 #error "MKS Robin pro supports up to 3 hotends / E-steppers. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/stm32f1/pins_STM32F1R.h b/Marlin/src/pins/stm32f1/pins_STM32F1R.h index d666755c6ffa..c08b707d7e99 100644 --- a/Marlin/src/pins/stm32f1/pins_STM32F1R.h +++ b/Marlin/src/pins/stm32f1/pins_STM32F1R.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" /** * 21017 Victor Perez Marlin for stm32f1 test diff --git a/Marlin/src/pins/stm32f1/pins_STM3R_MINI.h b/Marlin/src/pins/stm32f1/pins_STM3R_MINI.h index 4f8183caf4c1..d25ca1bd2ea7 100644 --- a/Marlin/src/pins/stm32f1/pins_STM3R_MINI.h +++ b/Marlin/src/pins/stm32f1/pins_STM3R_MINI.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#endif +#include "env_validate.h" /** * 21017 Victor Perez Marlin for stm32f1 test diff --git a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h index e09bbff324f3..dc603cda54f0 100644 --- a/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h +++ b/Marlin/src/pins/stm32f1/pins_TRIGORILLA_PRO.h @@ -28,9 +28,9 @@ * https://github.com/MarlinFirmware/Marlin/files/3401484/x5sa-main_board-2.pdf */ -#if NOT_TARGET(__STM32F1__) - #error "Oops! Select an STM32F1 board in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "Trigorilla Pro supports up to 2 hotends / E-steppers. Comment out this line to continue." #endif @@ -58,8 +58,12 @@ // #define X_STOP_PIN PG10 #define Y_STOP_PIN PA12 -#define Z_MAX_PIN PA14 -#define Z_MIN_PIN PA13 +#ifndef Z_MIN_PIN + #define Z_MIN_PIN PA14 +#endif +#ifndef Z_MAX_PIN + #define Z_MAX_PIN PA13 +#endif // // Steppers diff --git a/Marlin/src/pins/stm32f4/env_validate.h b/Marlin/src/pins/stm32f4/env_validate.h new file mode 100644 index 000000000000..c01401f06c9a --- /dev/null +++ b/Marlin/src/pins/stm32f4/env_validate.h @@ -0,0 +1,28 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if NOT_TARGET(STM32F4) && (DISABLED(ALLOW_STM32DUINO) || NOT_TARGET(STM32F4xx)) + #error "Oops! Select an STM32F4 board in 'Tools > Board.'" +#endif + +#undef ALLOW_STM32DUINO diff --git a/Marlin/src/pins/stm32f4/pins_ANET_ET4.h b/Marlin/src/pins/stm32f4/pins_ANET_ET4.h index 487080f46b67..1e1f5251c155 100644 --- a/Marlin/src/pins/stm32f4/pins_ANET_ET4.h +++ b/Marlin/src/pins/stm32f4/pins_ANET_ET4.h @@ -22,9 +22,11 @@ #pragma once -#if NOT_TARGET(STM32F4) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#include "env_validate.h" + +#if HOTENDS > 1 || E_STEPPERS > 1 #error "Anet ET4 only supports one hotend / E-stepper. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/stm32f4/pins_ARMED.h b/Marlin/src/pins/stm32f4/pins_ARMED.h index db57db14d549..a67af089f20a 100644 --- a/Marlin/src/pins/stm32f4/pins_ARMED.h +++ b/Marlin/src/pins/stm32f4/pins_ARMED.h @@ -24,9 +24,9 @@ #pragma once -#if NOT_TARGET(STM32F4) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "Arm'ed supports up to 2 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/stm32f4/pins_BLACK_STM32F407VE.h b/Marlin/src/pins/stm32f4/pins_BLACK_STM32F407VE.h index c2ad907e0470..d8a83bef3a89 100644 --- a/Marlin/src/pins/stm32f4/pins_BLACK_STM32F407VE.h +++ b/Marlin/src/pins/stm32f4/pins_BLACK_STM32F407VE.h @@ -27,9 +27,10 @@ * Shield - https://github.com/jmz52/Hardware */ -#if NOT_TARGET(STM32F4, STM32F4xx) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define ALLOW_STM32DUINO +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "Black STM32F4VET6 supports up to 2 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/stm32f4/pins_BTT_BTT002_V1_0.h b/Marlin/src/pins/stm32f4/pins_BTT_BTT002_V1_0.h index 939bc1eccd08..6029031a6348 100644 --- a/Marlin/src/pins/stm32f4/pins_BTT_BTT002_V1_0.h +++ b/Marlin/src/pins/stm32f4/pins_BTT_BTT002_V1_0.h @@ -21,9 +21,9 @@ */ #pragma once -#if NOT_TARGET(STM32F4) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 1 || E_STEPPERS > 1 +#include "env_validate.h" + +#if HOTENDS > 1 || E_STEPPERS > 1 #error "BIGTREE BTT002 V1.0 only supports one hotend / E-stepper. Comment out this line to continue." #endif @@ -172,73 +172,121 @@ #define FAN_PIN PB8 // Fan1 #define FAN1_PIN PB9 // Fan0 +/** + * -----------------------------------BTT002 V1.0---------------------------------------- + * ------ ------ | + * PA3 | 1 2 | GND 5V | 1 2 | GND | + * NRESET | 3 4 | PC4 (SD_DET) (LCD_D7) PE13 | 3 4 | PE12 (LCD_D6) | + * (MOSI) PA7 | 5 6 | PB0 (BTN_EN2) (LCD_D5) PE11 | 5 6 | PE10 (LCD_D4) | + * (SD_SS) PA4 | 7 8 | PC5 (BTN_EN1) (LCD_RS) PE8 | 7 8 | PE9 (LCD_EN) | + * (SCK) PA5 | 9 10 | PA6 (MISO) (BTN_ENC) PB1 | 9 10 | PE7 (BEEPER) | + * ------ ------ | + * EXP2 EXP1 | + * -------------------------------------------------------------------------------------- + */ + +#define EXP1_03_PIN PE13 +#define EXP1_04_PIN PE12 +#define EXP1_05_PIN PE11 +#define EXP1_06_PIN PE10 +#define EXP1_07_PIN PE8 +#define EXP1_08_PIN PE9 +#define EXP1_09_PIN PB1 +#define EXP1_10_PIN PE7 + +#define EXP2_03_PIN -1 +#define EXP2_04_PIN PC4 +#define EXP2_05_PIN PA7 +#define EXP2_06_PIN PB0 +#define EXP2_07_PIN PA4 +#define EXP2_08_PIN PC5 +#define EXP2_09_PIN PA5 +#define EXP2_10_PIN PA6 + // HAL SPI1 pins #define CUSTOM_SPI_PINS #if ENABLED(CUSTOM_SPI_PINS) - #define SD_SCK_PIN PA5 // SPI1 SCLK - #define SD_SS_PIN PA4 // SPI1 SSEL - #define SD_MISO_PIN PA6 // SPI1 MISO - #define SD_MOSI_PIN PA7 // SPI1 MOSI + #define SD_SCK_PIN EXP2_09_PIN // SPI1 SCLK + #define SD_SS_PIN EXP2_07_PIN // SPI1 SSEL + #define SD_MISO_PIN EXP2_10_PIN // SPI1 MISO + #define SD_MOSI_PIN EXP2_05_PIN // SPI1 MOSI #endif -// -// Misc. Functions -// -#define SDSS PA4 - -/** - * -------------------------------------BTT002 V1.0-------------------------------------------- - * ----- ----- | - * PA3 | · · | GND 5V | · · | GND | - * NRESET | · · | PC4(SD_DET) (LCD_D7) PE13 | · · | PE12 (LCD_D6) | - * (MOSI)PA7 | · · | PB0(BTN_EN2) (LCD_D5) PE11 | · · | PE10 (LCD_D4) | - * (SD_SS)PA4 | · · | PC5(BTN_EN1) (LCD_RS) PE8 | · · | PE9 (LCD_EN) | - * (SCK)PA5 | · · | PA6(MISO) (BTN_ENC) PB1 | · · | PE7 (BEEPER) | - * ----- ----- | - * EXP2 EXP1 | - * -------------------------------------------------------------------------------------------- - */ +#define SDSS EXP2_07_PIN // // LCDs and Controllers // #if HAS_WIRED_LCD - #define BEEPER_PIN PE7 - #define BTN_ENC PB1 + #define BEEPER_PIN EXP1_10_PIN + #define BTN_ENC EXP1_09_PIN + + #define SD_DETECT_PIN EXP2_04_PIN #if ENABLED(CR10_STOCKDISPLAY) - #define LCD_PINS_RS PE12 + #define LCD_PINS_RS EXP1_04_PIN + + #define BTN_EN1 EXP1_08_PIN + #define BTN_EN2 EXP1_06_PIN + + #define LCD_PINS_ENABLE EXP1_03_PIN + #define LCD_PINS_D4 EXP1_05_PIN - #define BTN_EN1 PE9 - #define BTN_EN2 PE10 + #elif ENABLED(MKS_MINI_12864) - #define LCD_PINS_ENABLE PE13 - #define LCD_PINS_D4 PE11 + #define DOGLCD_A0 EXP1_04_PIN + #define DOGLCD_CS EXP1_05_PIN + #define BTN_EN1 EXP2_08_PIN + #define BTN_EN2 EXP2_06_PIN #else - #define LCD_PINS_RS PE8 + #define LCD_PINS_RS EXP1_07_PIN + + #define BTN_EN1 EXP2_08_PIN + #define BTN_EN2 EXP2_06_PIN + + #define LCD_PINS_ENABLE EXP1_08_PIN + #define LCD_PINS_D4 EXP1_06_PIN - #define BTN_EN1 PC5 - #define BTN_EN2 PB0 - #define SD_DETECT_PIN PC4 + #if ENABLED(FYSETC_MINI_12864) + #define DOGLCD_CS EXP1_08_PIN + #define DOGLCD_A0 EXP1_07_PIN + #define DOGLCD_MOSI EXP2_05_PIN + #define DOGLCD_MISO EXP2_10_PIN + #define DOGLCD_SCK EXP2_09_PIN - #define LCD_SDSS PA4 + #define LCD_BACKLIGHT_PIN -1 - #define LCD_PINS_ENABLE PE9 - #define LCD_PINS_D4 PE10 + #define FORCE_SOFT_SPI + + #define LCD_RESET_PIN EXP1_06_PIN // Must be high or open for LCD to operate normally. + + #if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0) + #ifndef RGB_LED_R_PIN + #define RGB_LED_R_PIN EXP1_05_PIN + #endif + #ifndef RGB_LED_G_PIN + #define RGB_LED_G_PIN EXP1_04_PIN + #endif + #ifndef RGB_LED_B_PIN + #define RGB_LED_B_PIN EXP1_03_PIN + #endif + #elif ENABLED(FYSETC_MINI_12864_2_1) + #define NEOPIXEL_PIN EXP1_05_PIN + #endif + #endif // !FYSETC_MINI_12864 #if IS_ULTIPANEL - #define LCD_PINS_D5 PE11 - #define LCD_PINS_D6 PE12 - #define LCD_PINS_D7 PE13 + #define LCD_PINS_D5 EXP1_05_PIN + #define LCD_PINS_D6 EXP1_04_PIN + #define LCD_PINS_D7 EXP1_03_PIN #if ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) #define BTN_ENC_EN LCD_PINS_D7 // Detect the presence of the encoder #endif #endif - #endif // Alter timing for graphical display diff --git a/Marlin/src/pins/stm32f4/pins_BTT_GTR_V1_0.h b/Marlin/src/pins/stm32f4/pins_BTT_GTR_V1_0.h index cd9d60d2f016..6c59f27c5efe 100644 --- a/Marlin/src/pins/stm32f4/pins_BTT_GTR_V1_0.h +++ b/Marlin/src/pins/stm32f4/pins_BTT_GTR_V1_0.h @@ -21,9 +21,9 @@ */ #pragma once -#if NOT_TARGET(STM32F4) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 8 || E_STEPPERS > 8 +#include "env_validate.h" + +#if HOTENDS > 8 || E_STEPPERS > 8 #error "BIGTREE GTR V1.0 supports up to 8 hotends / E-steppers." #elif HOTENDS > MAX_E_STEPPERS || E_STEPPERS > MAX_E_STEPPERS #error "Marlin extruder/hotends limit! Increase MAX_E_STEPPERS to continue." diff --git a/Marlin/src/pins/stm32f4/pins_BTT_SKR_PRO_common.h b/Marlin/src/pins/stm32f4/pins_BTT_SKR_PRO_common.h index 549b578f4249..863429f2a2a7 100644 --- a/Marlin/src/pins/stm32f4/pins_BTT_SKR_PRO_common.h +++ b/Marlin/src/pins/stm32f4/pins_BTT_SKR_PRO_common.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(STM32F4) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#endif +#include "env_validate.h" // BigTreeTech driver expansion module https://bit.ly/3ptRRoj //#define BTT_MOTOR_EXPANSION @@ -243,7 +241,7 @@ #define HEATER_BED_PIN PD12 // Hotbed #define FAN_PIN PC8 // Fan0 #define FAN1_PIN PE5 // Fan1 -#define FAN2_PIN PE6 +#define FAN2_PIN PE6 // Fan2 #ifndef E0_AUTO_FAN_PIN #define E0_AUTO_FAN_PIN FAN1_PIN @@ -268,23 +266,23 @@ * EXP2 EXP1 */ -#define EXPA1_03_PIN PG7 -#define EXPA1_04_PIN PG6 -#define EXPA1_05_PIN PG3 -#define EXPA1_06_PIN PG2 -#define EXPA1_07_PIN PD10 -#define EXPA1_08_PIN PD11 -#define EXPA1_09_PIN PA8 -#define EXPA1_10_PIN PG4 - -#define EXPA2_03_PIN -1 -#define EXPA2_04_PIN PF12 -#define EXPA2_05_PIN PB15 -#define EXPA2_06_PIN PF11 -#define EXPA2_07_PIN PB12 -#define EXPA2_08_PIN PG10 -#define EXPA2_09_PIN PB13 -#define EXPA2_10_PIN PB14 +#define EXP1_03_PIN PG7 +#define EXP1_04_PIN PG6 +#define EXP1_05_PIN PG3 +#define EXP1_06_PIN PG2 +#define EXP1_07_PIN PD10 +#define EXP1_08_PIN PD11 +#define EXP1_09_PIN PA8 +#define EXP1_10_PIN PG4 + +#define EXP2_03_PIN -1 +#define EXP2_04_PIN PF12 +#define EXP2_05_PIN PB15 +#define EXP2_06_PIN PF11 +#define EXP2_07_PIN PB12 +#define EXP2_08_PIN PG10 +#define EXP2_09_PIN PB13 +#define EXP2_10_PIN PB14 // // Onboard SD card @@ -292,8 +290,8 @@ // #if SD_CONNECTION_IS(LCD) - #define SD_DETECT_PIN EXPA2_04_PIN - #define SDSS EXPA2_07_PIN + #define SD_DETECT_PIN EXP2_04_PIN + #define SDSS EXP2_07_PIN #elif SD_CONNECTION_IS(ONBOARD) @@ -325,36 +323,36 @@ */ // M1 on Driver Expansion Module - #define E3_STEP_PIN EXPA2_05_PIN - #define E3_DIR_PIN EXPA2_06_PIN - #define E3_ENABLE_PIN EXPA2_04_PIN - #define E3_DIAG_PIN EXPA1_06_PIN - #define E3_CS_PIN EXPA1_05_PIN + #define E3_STEP_PIN EXP2_05_PIN + #define E3_DIR_PIN EXP2_06_PIN + #define E3_ENABLE_PIN EXP2_04_PIN + #define E3_DIAG_PIN EXP1_06_PIN + #define E3_CS_PIN EXP1_05_PIN #if HAS_TMC_UART - #define E3_SERIAL_TX_PIN EXPA1_05_PIN - #define E3_SERIAL_RX_PIN EXPA1_05_PIN + #define E3_SERIAL_TX_PIN EXP1_05_PIN + #define E3_SERIAL_RX_PIN EXP1_05_PIN #endif // M2 on Driver Expansion Module - #define E4_STEP_PIN EXPA2_08_PIN - #define E4_DIR_PIN EXPA2_07_PIN - #define E4_ENABLE_PIN EXPA1_03_PIN - #define E4_DIAG_PIN EXPA1_08_PIN - #define E4_CS_PIN EXPA1_07_PIN + #define E4_STEP_PIN EXP2_08_PIN + #define E4_DIR_PIN EXP2_07_PIN + #define E4_ENABLE_PIN EXP1_03_PIN + #define E4_DIAG_PIN EXP1_08_PIN + #define E4_CS_PIN EXP1_07_PIN #if HAS_TMC_UART - #define E4_SERIAL_TX_PIN EXPA1_07_PIN - #define E4_SERIAL_RX_PIN EXPA1_07_PIN + #define E4_SERIAL_TX_PIN EXP1_07_PIN + #define E4_SERIAL_RX_PIN EXP1_07_PIN #endif // M3 on Driver Expansion Module - #define E5_STEP_PIN EXPA2_10_PIN - #define E5_DIR_PIN EXPA2_09_PIN - #define E5_ENABLE_PIN EXPA1_04_PIN - #define E5_DIAG_PIN EXPA1_10_PIN - #define E5_CS_PIN EXPA1_09_PIN + #define E5_STEP_PIN EXP2_10_PIN + #define E5_DIR_PIN EXP2_09_PIN + #define E5_ENABLE_PIN EXP1_04_PIN + #define E5_DIAG_PIN EXP1_10_PIN + #define E5_CS_PIN EXP1_09_PIN #if HAS_TMC_UART - #define E5_SERIAL_TX_PIN EXPA1_09_PIN - #define E5_SERIAL_RX_PIN EXPA1_09_PIN + #define E5_SERIAL_TX_PIN EXP1_09_PIN + #define E5_SERIAL_RX_PIN EXP1_09_PIN #endif #endif // BTT_MOTOR_EXPANSION @@ -365,23 +363,23 @@ #if IS_TFTGLCD_PANEL #if ENABLED(TFTGLCD_PANEL_SPI) - #define TFTGLCD_CS EXPA2_08_PIN + #define TFTGLCD_CS EXP2_08_PIN #endif #elif HAS_WIRED_LCD - #define BEEPER_PIN EXPA1_10_PIN - #define BTN_ENC EXPA1_09_PIN + #define BEEPER_PIN EXP1_10_PIN + #define BTN_ENC EXP1_09_PIN #if ENABLED(CR10_STOCKDISPLAY) - #define LCD_PINS_RS EXPA1_04_PIN + #define LCD_PINS_RS EXP1_04_PIN - #define BTN_EN1 EXPA1_08_PIN - #define BTN_EN2 EXPA1_06_PIN + #define BTN_EN1 EXP1_08_PIN + #define BTN_EN2 EXP1_06_PIN - #define LCD_PINS_ENABLE EXPA1_03_PIN - #define LCD_PINS_D4 EXPA1_05_PIN + #define LCD_PINS_ENABLE EXP1_03_PIN + #define LCD_PINS_D4 EXP1_05_PIN // CR10_STOCKDISPLAY default timing is too fast #undef BOARD_ST7920_DELAY_1 @@ -390,45 +388,45 @@ #elif ENABLED(MKS_MINI_12864) - #define DOGLCD_A0 EXPA1_04_PIN - #define DOGLCD_CS EXPA1_05_PIN - #define BTN_EN1 EXPA2_08_PIN - #define BTN_EN2 EXPA2_06_PIN + #define DOGLCD_A0 EXP1_04_PIN + #define DOGLCD_CS EXP1_05_PIN + #define BTN_EN1 EXP2_08_PIN + #define BTN_EN2 EXP2_06_PIN #else - #define LCD_PINS_RS EXPA1_07_PIN + #define LCD_PINS_RS EXP1_07_PIN - #define BTN_EN1 EXPA2_08_PIN - #define BTN_EN2 EXPA2_06_PIN + #define BTN_EN1 EXP2_08_PIN + #define BTN_EN2 EXP2_06_PIN - #define LCD_PINS_ENABLE EXPA1_08_PIN - #define LCD_PINS_D4 EXPA1_06_PIN + #define LCD_PINS_ENABLE EXP1_08_PIN + #define LCD_PINS_D4 EXP1_06_PIN #if ENABLED(FYSETC_MINI_12864) - #define DOGLCD_CS EXPA1_08_PIN - #define DOGLCD_A0 EXPA1_07_PIN + #define DOGLCD_CS EXP1_08_PIN + #define DOGLCD_A0 EXP1_07_PIN //#define LCD_BACKLIGHT_PIN -1 - #define LCD_RESET_PIN EXPA1_06_PIN // Must be high or open for LCD to operate normally. + #define LCD_RESET_PIN EXP1_06_PIN // Must be high or open for LCD to operate normally. #if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0) #ifndef RGB_LED_R_PIN - #define RGB_LED_R_PIN EXPA1_05_PIN + #define RGB_LED_R_PIN EXP1_05_PIN #endif #ifndef RGB_LED_G_PIN - #define RGB_LED_G_PIN EXPA1_04_PIN + #define RGB_LED_G_PIN EXP1_04_PIN #endif #ifndef RGB_LED_B_PIN - #define RGB_LED_B_PIN EXPA1_03_PIN + #define RGB_LED_B_PIN EXP1_03_PIN #endif #elif ENABLED(FYSETC_MINI_12864_2_1) - #define NEOPIXEL_PIN EXPA1_05_PIN + #define NEOPIXEL_PIN EXP1_05_PIN #endif #endif // !FYSETC_MINI_12864 #if IS_ULTIPANEL - #define LCD_PINS_D5 EXPA1_05_PIN - #define LCD_PINS_D6 EXPA1_04_PIN - #define LCD_PINS_D7 EXPA1_03_PIN + #define LCD_PINS_D5 EXP1_05_PIN + #define LCD_PINS_D6 EXP1_04_PIN + #define LCD_PINS_D7 EXP1_03_PIN #if ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) #define BTN_ENC_EN LCD_PINS_D7 // Detect the presence of the encoder diff --git a/Marlin/src/pins/stm32f4/pins_FLYF407ZG.h b/Marlin/src/pins/stm32f4/pins_FLYF407ZG.h index 7965d262c3dc..34124a9b02e9 100644 --- a/Marlin/src/pins/stm32f4/pins_FLYF407ZG.h +++ b/Marlin/src/pins/stm32f4/pins_FLYF407ZG.h @@ -21,9 +21,10 @@ */ #pragma once -#if NOT_TARGET(STM32F4, STM32F4xx) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 6 || E_STEPPERS > 6 +#define ALLOW_STM32DUINO +#include "env_validate.h" + +#if HOTENDS > 6 || E_STEPPERS > 6 #error "FLYF407ZG supports up to 6 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/stm32f4/pins_FYSETC_CHEETAH_V20.h b/Marlin/src/pins/stm32f4/pins_FYSETC_CHEETAH_V20.h index 18e689d1d93a..ef1c14aae0bf 100644 --- a/Marlin/src/pins/stm32f4/pins_FYSETC_CHEETAH_V20.h +++ b/Marlin/src/pins/stm32f4/pins_FYSETC_CHEETAH_V20.h @@ -21,9 +21,7 @@ */ #pragma once -#if NOT_TARGET(STM32F4) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #define DEFAULT_MACHINE_NAME "3D Printer" @@ -161,38 +159,38 @@ * EXP3 */ -#define EXPA1_03_PIN PB7 -#define EXPA1_04_PIN PB6 -#define EXPA1_05_PIN PB14 -#define EXPA1_06_PIN PB13 -#define EXPA1_07_PIN PB12 -#define EXPA1_08_PIN PB15 -#define EXPA1_09_PIN PC12 -#define EXPA1_10_PIN PC9 - -#define EXPA2_03_PIN -1 -#define EXPA2_04_PIN PC3 -#define EXPA2_05_PIN PA7 -#define EXPA2_06_PIN PC11 -#define EXPA2_07_PIN PA4 -#define EXPA2_08_PIN PC10 -#define EXPA2_09_PIN PA5 -#define EXPA2_10_PIN PA6 +#define EXP1_03_PIN PB7 +#define EXP1_04_PIN PB6 +#define EXP1_05_PIN PB14 +#define EXP1_06_PIN PB13 +#define EXP1_07_PIN PB12 +#define EXP1_08_PIN PB15 +#define EXP1_09_PIN PC12 +#define EXP1_10_PIN PC9 + +#define EXP2_03_PIN -1 +#define EXP2_04_PIN PC3 +#define EXP2_05_PIN PA7 +#define EXP2_06_PIN PC11 +#define EXP2_07_PIN PA4 +#define EXP2_08_PIN PC10 +#define EXP2_09_PIN PA5 +#define EXP2_10_PIN PA6 #if HAS_WIRED_LCD - #define BEEPER_PIN EXPA1_10_PIN - #define BTN_ENC EXPA1_09_PIN + #define BEEPER_PIN EXP1_10_PIN + #define BTN_ENC EXP1_09_PIN #if ENABLED(CR10_STOCKDISPLAY) - #define LCD_PINS_RS EXPA1_07_PIN + #define LCD_PINS_RS EXP1_07_PIN - #define BTN_EN1 EXPA2_08_PIN - #define BTN_EN2 EXPA2_06_PIN + #define BTN_EN1 EXP2_08_PIN + #define BTN_EN2 EXP2_06_PIN - #define LCD_PINS_ENABLE EXPA1_08_PIN - #define LCD_PINS_D4 EXPA1_06_PIN + #define LCD_PINS_ENABLE EXP1_08_PIN + #define LCD_PINS_D4 EXP1_06_PIN // CR10_STOCKDISPLAY default timing is too fast #undef BOARD_ST7920_DELAY_1 @@ -201,45 +199,45 @@ #elif ENABLED(MKS_MINI_12864) - #define DOGLCD_A0 EXPA1_04_PIN - #define DOGLCD_CS EXPA1_05_PIN - #define BTN_EN1 EXPA2_08_PIN - #define BTN_EN2 EXPA2_06_PIN + #define DOGLCD_A0 EXP1_04_PIN + #define DOGLCD_CS EXP1_05_PIN + #define BTN_EN1 EXP2_08_PIN + #define BTN_EN2 EXP2_06_PIN #else - #define LCD_PINS_RS EXPA1_07_PIN + #define LCD_PINS_RS EXP1_07_PIN - #define BTN_EN1 EXPA2_06_PIN - #define BTN_EN2 EXPA2_08_PIN + #define BTN_EN1 EXP2_06_PIN + #define BTN_EN2 EXP2_08_PIN - #define LCD_PINS_ENABLE EXPA1_08_PIN - #define LCD_PINS_D4 EXPA1_06_PIN + #define LCD_PINS_ENABLE EXP1_08_PIN + #define LCD_PINS_D4 EXP1_06_PIN #if ENABLED(FYSETC_MINI_12864) - #define DOGLCD_CS EXPA1_08_PIN - #define DOGLCD_A0 EXPA1_07_PIN + #define DOGLCD_CS EXP1_08_PIN + #define DOGLCD_A0 EXP1_07_PIN //#define LCD_BACKLIGHT_PIN -1 - #define LCD_RESET_PIN EXPA1_06_PIN // Must be high or open for LCD to operate normally. + #define LCD_RESET_PIN EXP1_06_PIN // Must be high or open for LCD to operate normally. #if EITHER(FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0) #ifndef RGB_LED_R_PIN - #define RGB_LED_R_PIN EXPA1_05_PIN + #define RGB_LED_R_PIN EXP1_05_PIN #endif #ifndef RGB_LED_G_PIN - #define RGB_LED_G_PIN EXPA1_04_PIN + #define RGB_LED_G_PIN EXP1_04_PIN #endif #ifndef RGB_LED_B_PIN - #define RGB_LED_B_PIN EXPA1_03_PIN + #define RGB_LED_B_PIN EXP1_03_PIN #endif #elif ENABLED(FYSETC_MINI_12864_2_1) - #define NEOPIXEL_PIN EXPA1_05_PIN + #define NEOPIXEL_PIN EXP1_05_PIN #endif #endif // !FYSETC_MINI_12864 #if IS_ULTIPANEL - #define LCD_PINS_D5 EXPA1_05_PIN - #define LCD_PINS_D6 EXPA1_04_PIN - #define LCD_PINS_D7 EXPA1_03_PIN + #define LCD_PINS_D5 EXP1_05_PIN + #define LCD_PINS_D6 EXP1_04_PIN + #define LCD_PINS_D7 EXP1_03_PIN #if ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) #define BTN_ENC_EN LCD_PINS_D7 // Detect the presence of the encoder @@ -265,7 +263,7 @@ #endif #if ENABLED(TOUCH_UI_FTDI_EVE) - #define BEEPER_PIN EXPA1_10_PIN - #define CLCD_MOD_RESET EXPA2_08_PIN - #define CLCD_SPI_CS EXPA2_06_PIN + #define BEEPER_PIN EXP1_10_PIN + #define CLCD_MOD_RESET EXP2_08_PIN + #define CLCD_SPI_CS EXP2_06_PIN #endif diff --git a/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h b/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h index a28077564634..d617087e9df8 100644 --- a/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h +++ b/Marlin/src/pins/stm32f4/pins_FYSETC_S6.h @@ -21,9 +21,9 @@ */ #pragma once -#if NOT_TARGET(STM32F4) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 3 || E_STEPPERS > 3 +#include "env_validate.h" + +#if HOTENDS > 3 || E_STEPPERS > 3 #error "RUMBA32 supports up to 3 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/stm32f4/pins_LERDGE_K.h b/Marlin/src/pins/stm32f4/pins_LERDGE_K.h index bf6df0356237..fad8d2059e08 100644 --- a/Marlin/src/pins/stm32f4/pins_LERDGE_K.h +++ b/Marlin/src/pins/stm32f4/pins_LERDGE_K.h @@ -18,9 +18,10 @@ */ #pragma once -#if NOT_TARGET(STM32F4, STM32F4xx) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define ALLOW_STM32DUINO +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "LERDGE K supports up to 2 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/stm32f4/pins_LERDGE_S.h b/Marlin/src/pins/stm32f4/pins_LERDGE_S.h index c6cfa98831e2..105d0d6f6070 100644 --- a/Marlin/src/pins/stm32f4/pins_LERDGE_S.h +++ b/Marlin/src/pins/stm32f4/pins_LERDGE_S.h @@ -18,9 +18,10 @@ */ #pragma once -#if NOT_TARGET(STM32F4, STM32F4xx) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define ALLOW_STM32DUINO +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "LERDGE S supports up to 2 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/stm32f4/pins_LERDGE_X.h b/Marlin/src/pins/stm32f4/pins_LERDGE_X.h index 606d932c5739..974392373f23 100644 --- a/Marlin/src/pins/stm32f4/pins_LERDGE_X.h +++ b/Marlin/src/pins/stm32f4/pins_LERDGE_X.h @@ -18,9 +18,10 @@ */ #pragma once -#if NOT_TARGET(STM32F4, STM32F4xx) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 1 || E_STEPPERS > 1 +#define ALLOW_STM32DUINO +#include "env_validate.h" + +#if HOTENDS > 1 || E_STEPPERS > 1 #error "LERDGE X only supports one hotend / E-stepper. Comment out this line to continue." #endif diff --git a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN2.h b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN2.h index c2f5f324ba28..589300f34175 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN2.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN2.h @@ -21,9 +21,9 @@ */ #pragma once -#if NOT_TARGET(STM32F4) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "MKS_ROBIN2 supports up to 2 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h index 49ee420aaee1..f9e85c49190d 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h @@ -21,9 +21,10 @@ */ #pragma once -#if NOT_TARGET(STM32F4, STM32F4xx) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define ALLOW_STM32DUINO +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "MKS Robin Nano V3 supports up to 2 hotends / E-steppers." #elif HAS_FSMC_TFT #error "MKS Robin Nano V3 doesn't support FSMC-based TFT displays." @@ -42,6 +43,8 @@ //#define FLASH_EEPROM_EMULATION // Use Flash-based EEPROM emulation #define I2C_EEPROM #define MARLIN_EEPROM_SIZE 0x1000 // 4KB +#define I2C_SCL_PIN PB6 +#define I2C_SDA_PIN PB7 // // Release PB4 (Z_DIR_PIN) from JTAG NRST role @@ -163,8 +166,8 @@ #define HEATER_1_PIN PB0 // HEATER2 #define HEATER_BED_PIN PA0 // HOT BED -#define FAN_PIN PB1 // FAN -#define FAN1_PIN PC14 // FAN1 +#define FAN_PIN PC14 // FAN +#define FAN1_PIN PB1 // FAN1 // // Thermocouples diff --git a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h index 5533e35f07cf..f2ddfc2b5224 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_PRO_V2.h @@ -21,9 +21,10 @@ */ #pragma once -#if NOT_TARGET(STM32F4, STM32F4xx) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define ALLOW_STM32DUINO +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "MKS Robin Nano V3 supports up to 1 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/stm32f4/pins_RUMBA32_common.h b/Marlin/src/pins/stm32f4/pins_RUMBA32_common.h index 2a0cfa897cf4..be6e4f8a3422 100644 --- a/Marlin/src/pins/stm32f4/pins_RUMBA32_common.h +++ b/Marlin/src/pins/stm32f4/pins_RUMBA32_common.h @@ -25,9 +25,9 @@ * Common pin assignments for all RUMBA32 boards */ -#if NOT_TARGET(STM32F4) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 3 || E_STEPPERS > 3 +#include "env_validate.h" + +#if HOTENDS > 3 || E_STEPPERS > 3 #error "RUMBA32 boards support up to 3 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/stm32f4/pins_STEVAL_3DP001V1.h b/Marlin/src/pins/stm32f4/pins_STEVAL_3DP001V1.h index 25679517c269..dc02fd02eac6 100644 --- a/Marlin/src/pins/stm32f4/pins_STEVAL_3DP001V1.h +++ b/Marlin/src/pins/stm32f4/pins_STEVAL_3DP001V1.h @@ -40,9 +40,7 @@ #pragma once -#if NOT_TARGET(STM32F4) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#endif +#include "env_validate.h" #ifndef MACHINE_NAME #define MACHINE_NAME "STEVAL-3DP001V1" diff --git a/Marlin/src/pins/stm32f4/pins_VAKE403D.h b/Marlin/src/pins/stm32f4/pins_VAKE403D.h index 1135af847fa0..9d122c264225 100644 --- a/Marlin/src/pins/stm32f4/pins_VAKE403D.h +++ b/Marlin/src/pins/stm32f4/pins_VAKE403D.h @@ -21,9 +21,10 @@ */ #pragma once -#if NOT_TARGET(STM32F4, STM32F4xx) - #error "Oops! Select an STM32F4 board in 'Tools > Board.'" -#elif HOTENDS > 2 || E_STEPPERS > 2 +#define ALLOW_STM32DUINO +#include "env_validate.h" + +#if HOTENDS > 2 || E_STEPPERS > 2 #error "STM32F4 supports up to 2 hotends / E-steppers." #endif diff --git a/Marlin/src/pins/teensy2/env_validate.h b/Marlin/src/pins/teensy2/env_validate.h new file mode 100644 index 000000000000..5f0ea4f3b672 --- /dev/null +++ b/Marlin/src/pins/teensy2/env_validate.h @@ -0,0 +1,28 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#if NOT_TARGET(__AVR_AT90USB1286__) && (DISABLED(ALLOW_AT90USB1286P) || NOT_TARGET(__AVR_AT90USB1286P__)) + #error "Oops! Select 'Teensy++ 2.0' or 'Printrboard' in 'Tools > Board.'" +#endif + +#undef ALLOW_AT90USB1286P diff --git a/Marlin/src/pins/teensy2/pins_5DPRINT.h b/Marlin/src/pins/teensy2/pins_5DPRINT.h index 908e12e0bae2..6e1f9c021746 100644 --- a/Marlin/src/pins/teensy2/pins_5DPRINT.h +++ b/Marlin/src/pins/teensy2/pins_5DPRINT.h @@ -68,9 +68,7 @@ * https://bitbucket.org/makible/5dprint-d8-controller-board */ -#if NOT_TARGET(__AVR_AT90USB1286__) - #error "Oops! Select 'Teensy++ 2.0' or 'Printrboard' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define DEFAULT_MACHINE_NAME "Makibox" #define BOARD_INFO_NAME "5DPrint D8" diff --git a/Marlin/src/pins/teensy2/pins_BRAINWAVE.h b/Marlin/src/pins/teensy2/pins_BRAINWAVE.h index 97d210a0f852..cdcc249c00d2 100644 --- a/Marlin/src/pins/teensy2/pins_BRAINWAVE.h +++ b/Marlin/src/pins/teensy2/pins_BRAINWAVE.h @@ -69,7 +69,7 @@ */ #if NOT_TARGET(__AVR_AT90USB646__) - #error "Oops! Select 'AT90USB646_TEENSYPP' in 'Tools > Board.'" + #error "Oops! Select 'Brainwave' in 'Tools > Board.'" #endif #define BOARD_INFO_NAME "Brainwave" diff --git a/Marlin/src/pins/teensy2/pins_BRAINWAVE_PRO.h b/Marlin/src/pins/teensy2/pins_BRAINWAVE_PRO.h index e41fcaab9442..319130ef968d 100644 --- a/Marlin/src/pins/teensy2/pins_BRAINWAVE_PRO.h +++ b/Marlin/src/pins/teensy2/pins_BRAINWAVE_PRO.h @@ -75,9 +75,7 @@ * 4. The programmer is no longer needed. Remove it. */ -#if NOT_TARGET(__AVR_AT90USB1286__) - #error "Oops! Select 'Teensy++ 2.0' or 'Printrboard' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Brainwave Pro" diff --git a/Marlin/src/pins/teensy2/pins_PRINTRBOARD.h b/Marlin/src/pins/teensy2/pins_PRINTRBOARD.h index 2401c976f157..7b3685d08e7a 100644 --- a/Marlin/src/pins/teensy2/pins_PRINTRBOARD.h +++ b/Marlin/src/pins/teensy2/pins_PRINTRBOARD.h @@ -62,9 +62,7 @@ * 4. The programmer is no longer needed. Remove it. */ -#if NOT_TARGET(__AVR_AT90USB1286__) - #error "Oops! Select 'Teensy++ 2.0' or 'Printrboard' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Printrboard" diff --git a/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h b/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h index d4f9fc76415d..0e6842125e11 100644 --- a/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h +++ b/Marlin/src/pins/teensy2/pins_PRINTRBOARD_REVF.h @@ -63,9 +63,7 @@ * 4. The programmer is no longer needed. Remove it. */ -#if NOT_TARGET(__AVR_AT90USB1286__) - #error "Oops! Select 'Teensy++ 2.0' or 'Printrboard' in 'Tools > Board.'" -#endif +#include "env_validate.h" #if !defined(__MARLIN_DEPS__) && !defined(USBCON) #error "USBCON should be defined by the platform for this board." diff --git a/Marlin/src/pins/teensy2/pins_SAV_MKI.h b/Marlin/src/pins/teensy2/pins_SAV_MKI.h index bcc456c16e8a..cdba535090e4 100644 --- a/Marlin/src/pins/teensy2/pins_SAV_MKI.h +++ b/Marlin/src/pins/teensy2/pins_SAV_MKI.h @@ -62,9 +62,7 @@ * 4. The programmer is no longer needed. Remove it. */ -#if NOT_TARGET(__AVR_AT90USB1286__) - #error "Oops! Select 'Teensy++ 2.0' or 'Printrboard' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "SAV MkI" #define DEFAULT_MACHINE_NAME BOARD_INFO_NAME diff --git a/Marlin/src/pins/teensy2/pins_TEENSY2.h b/Marlin/src/pins/teensy2/pins_TEENSY2.h index d43e39b09aac..efb409bf3259 100644 --- a/Marlin/src/pins/teensy2/pins_TEENSY2.h +++ b/Marlin/src/pins/teensy2/pins_TEENSY2.h @@ -107,9 +107,7 @@ * E DIR 35 a7 a3 31 Y DIR */ -#if NOT_TARGET(__AVR_AT90USB1286__) - #error "Oops! Select 'Teensy++ 2.0' or 'Printrboard' in 'Tools > Board.'" -#endif +#include "env_validate.h" #define BOARD_INFO_NAME "Teensy++2.0" diff --git a/Marlin/src/pins/teensy2/pins_TEENSYLU.h b/Marlin/src/pins/teensy2/pins_TEENSYLU.h index 54cee137ad24..f551d802cfb2 100644 --- a/Marlin/src/pins/teensy2/pins_TEENSYLU.h +++ b/Marlin/src/pins/teensy2/pins_TEENSYLU.h @@ -72,6 +72,9 @@ * The pin assignments in this file match the silkscreen. */ +#define ALLOW_AT90USB1286P +#include "env_validate.h" + #if NOT_TARGET(__AVR_AT90USB1286__, __AVR_AT90USB1286P__) #error "Oops! Select 'Teensy++ 2.0' or 'Printrboard' in 'Tools > Board.'" #endif diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index fd26bdd671af..c973ba594597 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -552,7 +552,7 @@ void announceOpen(const uint8_t doing, const char * const path) { PORT_REDIRECT(SERIAL_ALL); SERIAL_ECHO_START(); SERIAL_ECHOPGM("Now "); - serialprintPGM(doing == 1 ? PSTR("doing") : PSTR("fresh")); + SERIAL_ECHOPGM_P(doing == 1 ? PSTR("doing") : PSTR("fresh")); SERIAL_ECHOLNPAIR(" file: ", path); } } @@ -1251,7 +1251,7 @@ void CardReader::fileHasFinished() { removeFile(recovery.filename); #if ENABLED(DEBUG_POWER_LOSS_RECOVERY) SERIAL_ECHOPGM("Power-loss file delete"); - serialprintPGM(jobRecoverFileExists() ? PSTR(" failed.\n") : PSTR("d.\n")); + SERIAL_ECHOPGM_P(jobRecoverFileExists() ? PSTR(" failed.\n") : PSTR("d.\n")); #endif } } diff --git a/Marlin/src/sd/usb_flashdrive/lib-uhs3/UHS_host/UHS_host_INLINE.h b/Marlin/src/sd/usb_flashdrive/lib-uhs3/UHS_host/UHS_host_INLINE.h index 9c7b5001c090..4ab1a6b8f9d1 100644 --- a/Marlin/src/sd/usb_flashdrive/lib-uhs3/UHS_host/UHS_host_INLINE.h +++ b/Marlin/src/sd/usb_flashdrive/lib-uhs3/UHS_host/UHS_host_INLINE.h @@ -984,7 +984,7 @@ uint8_t UHS_USB_HOST_BASE::ctrlReq(uint8_t addr, uint64_t Request, uint16_t nbyt //bool direction = bmReqType & 0x80; //request direction, IN or OUT uint8_t rcode = 0; - // Serial.println(""); + //Serial.println(); UHS_EpInfo *pep = ctrlReqOpen(addr, Request, dataptr); if(!pep) { HOST_DEBUG("ctrlReq1: ERROR_NULL_EPINFO addr: %d\r\n", addr); diff --git a/buildroot/bin/build_all_examples b/buildroot/bin/build_all_examples new file mode 100755 index 000000000000..bce95dce8861 --- /dev/null +++ b/buildroot/bin/build_all_examples @@ -0,0 +1,101 @@ +#!/usr/bin/env bash +# +# build_all_examples base_branch [resume_point] +# + +GITREPO=https://github.com/MarlinFirmware/Configurations.git +STAT_FILE=./.pio/.buildall + +# Check dependencies +which curl 1>/dev/null 2>&1 || { echo "curl not found! Please install it."; exit ; } +which git 1>/dev/null 2>&1 || { echo "git not found! Please install it."; exit ; } + +SED=$(command -v gsed 2>/dev/null || command -v sed 2>/dev/null) +[[ -z "$SED" ]] && { echo "No sed found, please install sed" ; exit 1 ; } + +SELF=`basename "$0"` +HERE=`dirname "$0"` + +# Check if called in the right location +[[ -e "Marlin/src" ]] || { echo -e "This script must be called from a Marlin working copy with:\n ./buildroot/bin/$SELF $1" ; exit ; } + +if [[ $# -lt 1 || $# -gt 2 ]]; then + echo "Usage: $SELF base_branch [resume_point] + base_branch - Configuration branch to download and build + resume_point - Configuration path to start from" + exit +fi + +echo "This script downloads all Configurations and builds Marlin with each one." +echo "On failure the last-built configs will be left in your working copy." +echo "Restore your configs with 'git checkout -f' or 'git reset --hard HEAD'." + +unset BRANCH +unset FIRST_CONF +if [[ -f "$STAT_FILE" ]]; then + IFS='*' read BRANCH FIRST_CONF <"$STAT_FILE" +fi + +# If -c is given start from the last attempted build +if [[ $1 == '-c' ]]; then + if [[ -z $BRANCH || -z $FIRST_CONF ]]; then + echo "Nothing to continue" + exit + fi +elif [[ $1 == '-s' ]]; then + if [[ -n $BRANCH && -n $FIRST_CONF ]]; then + SKIP_CONF=1 + else + echo "Nothing to skip" + exit + fi +else + BRANCH=${1:-"import-2.0.x"} + FIRST_CONF=$2 +fi + +# Check if the current repository has unmerged changes +if [[ $SKIP_CONF ]]; then + echo "Skipping $FIRST_CONF" +elif [[ $FIRST_CONF ]]; then + echo "Resuming from $FIRST_CONF" +else + git diff --quiet || { echo "The working copy is modified. Commit or stash changes before proceeding."; exit ; } +fi + +# Create a temporary folder inside .pio +TMP=./.pio/build-$BRANCH +[[ -d "$TMP" ]] || mkdir -p $TMP + +# Download Configurations into the temporary folder +if [[ ! -e "$TMP/README.md" ]]; then + echo "Downloading Configurations from GitHub into $TMP" + git clone --depth=1 --single-branch --branch "$BRANCH" $GITREPO "$TMP" || { echo "Failed to clone the configuration repository"; exit ; } +else + echo "Using previously downloaded Configurations at $TMP" +fi + +echo -e "Start building now...\n=====================" +shopt -s nullglob +IFS=' +' +CONF_TREE=$( ls -d "$TMP"/config/examples/*/ "$TMP"/config/examples/*/*/ "$TMP"/config/examples/*/*/*/ "$TMP"/config/examples/*/*/*/*/ | grep -vE ".+\.(\w+)$" ) +DOSKIP=0 +for CONF in $CONF_TREE ; do + # Get a config's directory name + DIR=$( echo $CONF | sed "s|$TMP/config/examples/||" ) + # If looking for a config, skip others + [[ $FIRST_CONF ]] && [[ $FIRST_CONF != $DIR && "$FIRST_CONF/" != $DIR ]] && continue + # Once found, stop looking + unset FIRST_CONF + # If skipping, don't build the found one + [[ $SKIP_CONF ]] && { unset SKIP_CONF ; continue ; } + # ...if skipping, don't build this one + compgen -G "${CONF}Con*.h" > /dev/null || continue + echo "${BRANCH}*${DIR}" >"$STAT_FILE" + "$HERE/build_example" "internal" "$TMP" "$DIR" || { echo "Failed to build $DIR"; exit ; } +done + +# Delete the temp folder and build state +[[ -e "$TMP/config/examples" ]] && rm -rf "$TMP" +rm "$STAT_FILE" diff --git a/buildroot/bin/build_example b/buildroot/bin/build_example new file mode 100755 index 000000000000..8ebb58f972e1 --- /dev/null +++ b/buildroot/bin/build_example @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# +# build_example +# +# Usage: build_example internal config-home config-folder +# + +# Require 'internal' as the first argument +[[ "$1" == "internal" ]] || { echo "Don't call this script directly, use build_all_examples instead." ; exit 1 ; } + +echo "Testing $3:" + +SUB=$2/config/examples/$3 +[[ -d "$SUB" ]] || { echo "$SUB is not a good path" ; exit 1 ; } + +compgen -G "${SUB}Con*.h" > /dev/null || { echo "No configuration files found in $SUB" ; exit 1 ; } + +echo "Getting configuration files from $SUB" +cp "$2/config/default"/*.h Marlin/ +cp "$SUB"/Configuration.h Marlin/ 2>/dev/null +cp "$SUB"/Configuration_adv.h Marlin/ 2>/dev/null +cp "$SUB"/_Bootscreen.h Marlin/ 2>/dev/null +cp "$SUB"/_Statusscreen.h Marlin/ 2>/dev/null + +echo "Building the firmware now..." +HERE=`dirname "$0"` +$HERE/mftest -a -n1 || { echo "Failed"; exit 1; } + +echo "Success" diff --git a/buildroot/share/git/mftest b/buildroot/bin/mftest similarity index 85% rename from buildroot/share/git/mftest rename to buildroot/bin/mftest index 11d0ac38814a..d769ff8cb809 100755 --- a/buildroot/share/git/mftest +++ b/buildroot/bin/mftest @@ -6,7 +6,6 @@ # mftest [name] [index] [-y] Set config options and optionally build a test # -MFINFO=$(mfinfo) || exit 1 [[ -d Marlin/src ]] || { echo "Please 'cd' to the Marlin repo root." ; exit 1 ; } perror() { echo -e "$0: \033[0;31m$1 -- $2\033[0m" ; } @@ -22,7 +21,7 @@ Usage: mftest [-t|--env=] [-n|--num=] [-m|--make] [-y|--build=] OPTIONS -t --env The environment of the test to apply / run. (As named in platformio.ini.) - -n --num The index of the test to run. (In *-tests file order.) + -n --num The index of the test to run. (In file order.) -m --make Use the make / Docker method for the build. -y --build Skip 'Do you want to build this test?' and assume YES. -h --help Print this help. @@ -37,7 +36,7 @@ env shortcuts: tree due esp lin lpc|lpc8 lpc9 m128 m256|mega stm|f1 f4 f7 s6 tee TESTPATH=buildroot/tests -STATE_FILE=$( echo ./.pio/.mftestrc ) +STATE_FILE="./.pio/.mftestrc" SED=$(which gsed || which sed) shopt -s extglob nocasematch @@ -106,32 +105,33 @@ if ((REBUILD)); then # Build with the last-built env [[ -f "$STATE_FILE" ]] || { errout "No previous (-r) build state found." ; exit 1 ; } read TESTENV <"$STATE_FILE" - pio run -d . -e $TESTENV + pio run -s -d . -e $TESTENV exit fi case $TESTENV in - tree) pio run -d . -e include_tree ; exit 1 ;; - due) TESTENV='DUE' ;; - esp) TESTENV='esp32' ;; - lin*) TESTENV='linux_native' ;; -lpc?(8)) TESTENV='LPC1768' ;; - lpc9) TESTENV='LPC1769' ;; - m128) TESTENV='mega1280' ;; - m256) TESTENV='mega2560' ;; - mega) TESTENV='mega2560' ;; - stm) TESTENV='STM32F103RE' ;; - f1) TESTENV='STM32F103RE' ;; - f4) TESTENV='STM32F4' ;; - f7) TESTENV='STM32F7' ;; - s6) TESTENV='FYSETC_S6' ;; - teensy) TESTENV='teensy31' ;; - t31) TESTENV='teensy31' ;; - t32) TESTENV='teensy31' ;; - t35) TESTENV='teensy35' ;; - t36) TESTENV='teensy35' ;; - t40) TESTENV='teensy41' ;; - t41) TESTENV='teensy41' ;; + tree) pio run -d . -e include_tree ; exit 1 ;; + due) TESTENV='DUE' ;; + esp) TESTENV='esp32' ;; + lin*) TESTENV='linux_native' ;; +lp8|lpc8) TESTENV='LPC1768' ;; +lp9|lpc9) TESTENV='LPC1769' ;; + m128) TESTENV='mega1280' ;; + m256) TESTENV='mega2560' ;; + mega) TESTENV='mega2560' ;; + stm) TESTENV='STM32F103RE' ;; + f1) TESTENV='STM32F103RE' ;; + f4) TESTENV='STM32F4' ;; + f7) TESTENV='STM32F7' ;; + s6) TESTENV='FYSETC_S6' ;; + teensy) TESTENV='teensy31' ;; + t31) TESTENV='teensy31' ;; + t32) TESTENV='teensy31' ;; + t35) TESTENV='teensy35' ;; + t36) TESTENV='teensy35' ;; + t40) TESTENV='teensy41' ;; + t41) TESTENV='teensy41' ;; +[1-9][1-9]|[1-9]) TESTNUM=$TESTENV ; TESTENV=- ;; esac if ((AUTO_BUILD)); then @@ -192,7 +192,7 @@ if ((AUTO_BUILD)); then pio run -t upload -e $TARGET else echo "Building environment $TARGET for board $MB ($BNUM)..." ; echo - pio run -e $TARGET + pio run -s -e $TARGET fi exit fi @@ -204,11 +204,10 @@ fi if [[ $TESTENV == '-' ]]; then IND=0 NAMES=() - for FILE in $( ls -1 $TESTPATH/*-tests ) + for FILE in $( ls -1 $TESTPATH/* ) do let IND++ - TNAME=${FILE/-tests/} - TNAME=${TNAME/$TESTPATH\//} + TNAME=${FILE/$TESTPATH\//} NAMES+=($TNAME) (( IND < 10 )) && echo -n " " echo " $IND) $TNAME" @@ -217,15 +216,21 @@ if [[ $TESTENV == '-' ]]; then echo for (( ; ; )) do - read -p "Select a test to apply (1-$IND) : " NAMEIND - [[ -z "$NAMEIND" ]] && { errout "(canceled)" ; exit 1 ; } + if [[ $TESTNUM -gt 0 ]]; then + NAMEIND=$TESTNUM + else + read -p "Select a test to apply (1-$IND) : " NAMEIND + fi + [[ -z $NAMEIND ]] && { errout "(canceled)" ; exit 1 ; } + TESTENV=${NAMES[$NAMEIND-1]} + [[ $TESTNUM -gt 0 ]] && { echo "Preselected test $TESTNUM ... ($TESTENV)" ; TESTNUM='' ; } [[ $NAMEIND =~ $ISNUM ]] && ((NAMEIND >= 1 && NAMEIND <= IND)) && { TESTENV=${NAMES[$NAMEIND-1]} ; echo ; break ; } errout "Invalid selection." done fi # Get the contents of the test file -OUT=$( cat $TESTPATH/$TESTENV-tests 2>/dev/null ) || { errout "Can't find test '$TESTENV'." ; exit 1 ; } +OUT=$( cat $TESTPATH/$TESTENV 2>/dev/null ) || { errout "Can't find test '$TESTENV'." ; exit 1 ; } # Count up the number of tests TESTCOUNT=$( awk "/$ISEXEC/{a++}END{print a}" <<<"$OUT" ) @@ -291,7 +296,7 @@ echo "$OUT" | { echo -ne "\033[0m" # Make clear it's a TEST -opt_set CUSTOM_MACHINE_NAME "\"$TESTENV-tests ($CHOICE)\"" +opt_set CUSTOM_MACHINE_NAME "\"Test $TESTENV ($CHOICE)\"" # Build the test too? if [[ -z "$BUILD_YES" ]]; then @@ -301,6 +306,6 @@ fi [[ $BUILD_YES == 'Y' || $BUILD_YES == 'Yes' ]] && { ((USE_MAKE)) && make tests-single-local TEST_TARGET=$TESTENV ONLY_TEST=$CHOICE - ((USE_MAKE)) || pio run -d . -e $TESTENV + ((USE_MAKE)) || pio run -s -d . -e $TESTENV echo "$TESTENV" >"$STATE_FILE" } diff --git a/buildroot/bin/opt_enable b/buildroot/bin/opt_enable index 96686d6c6845..fdcb5dae2d54 100755 --- a/buildroot/bin/opt_enable +++ b/buildroot/bin/opt_enable @@ -7,7 +7,7 @@ SED=$(which gsed || which sed) for opt in "$@" ; do # Logic for returning nonzero based on answer here: https://stackoverflow.com/a/15966279/104648 - eval "${SED} -i '/\(\/\/\)*[[:blank:]]*\(#define \b${opt}\b\)/{s//\2/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration.h" || - eval "${SED} -i '/\(\/\/\)*[[:blank:]]*\(#define \b${opt}\b\)/{s//\2/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration_adv.h" || + eval "${SED} -i '/^[[:blank:]]*\(\/\/\)*[[:blank:]]*\(#define \b${opt}\b\)/{s//\2/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration.h" || + eval "${SED} -i '/^[[:blank:]]*\(\/\/\)*[[:blank:]]*\(#define \b${opt}\b\)/{s//\2/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration_adv.h" || (echo "ERROR: opt_enable Can't find ${opt}" >&2 && exit 9) done diff --git a/buildroot/bin/opt_set b/buildroot/bin/opt_set index a646e09ae789..2a7a676cdce7 100755 --- a/buildroot/bin/opt_set +++ b/buildroot/bin/opt_set @@ -5,8 +5,12 @@ set -e SED=$(which gsed || which sed) -# Logic for returning nonzero based on answer here: https://stackoverflow.com/a/15966279/104648 -eval "${SED} -i '/\(\/\/\)*\([[:blank:]]*\)\(#define\s\+\b${1}\b\).*$/{s//\2\3 ${2}/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration.h" || -eval "${SED} -i '/\(\/\/\)*\([[:blank:]]*\)\(#define\s\+\b${1}\b\).*$/{s//\2\3 ${2}/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration_adv.h" || -eval "echo '#define ${@}' >>Marlin/Configuration_adv.h" || -(echo "ERROR: opt_set Can't set or add ${1}" >&2 && exit 9) +ARGC=$# +while [[ $# > 1 ]]; do + # Logic for returning nonzero based on answer here: https://stackoverflow.com/a/15966279/104648 + eval "${SED} -i '/^[[:blank:]]*\(\/\/\)*\([[:blank:]]*\)\(#define\s\+\b${1}\b\).*$/{s//\2\3 ${2}/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration.h" || + eval "${SED} -i '/^[[:blank:]]*\(\/\/\)*\([[:blank:]]*\)\(#define\s\+\b${1}\b\).*$/{s//\2\3 ${2}/;h};\${x;/./{x;q0};x;q9}' Marlin/Configuration_adv.h" || + eval "echo '#define ${1} ${2}' >>Marlin/Configuration.h" || + (echo "ERROR: opt_set Can't set or add ${1}" >&2 && exit 9) + shift 2 +done diff --git a/buildroot/bin/pins_set b/buildroot/bin/pins_set index 87a8692aa25d..860c64940f38 100755 --- a/buildroot/bin/pins_set +++ b/buildroot/bin/pins_set @@ -7,5 +7,5 @@ PIN=$2 VAL=$3 SED=$(which gsed || which sed) -eval "${SED} -i '/\(\/\/\)*\(#define \+${PIN}\b\).*$/{s//\2 ${VAL}/;h};\${x;/./{x;q0};x;q9}' Marlin/src/pins/$DIR/pins_${NAM}.h" || +eval "${SED} -i '/^[[:blank:]]*\(\/\/\)*[[:blank:]]*\(#define \+${PIN}\b\).*$/{s//\2 ${VAL}/;h};\${x;/./{x;q0};x;q9}' Marlin/src/pins/$DIR/pins_${NAM}.h" || (echo "ERROR: pins_set Can't find ${PIN}" >&2 && exit 9) diff --git a/buildroot/tests/run_tests b/buildroot/bin/run_tests similarity index 79% rename from buildroot/tests/run_tests rename to buildroot/bin/run_tests index c4286f4695a1..26284fa69330 100755 --- a/buildroot/tests/run_tests +++ b/buildroot/bin/run_tests @@ -2,8 +2,9 @@ # # run_tests # -export PATH="$PATH:$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )" -export PATH="$PATH:./buildroot/bin" +HERE="$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )" +TESTS="$HERE/../tests" +export PATH="$HERE:$TESTS:$PATH" # exit on first failure set -e @@ -40,10 +41,9 @@ export -f exec_test printf "Running \033[0;32m$2\033[0m Tests\n" if [[ $2 = "ALL" ]]; then - dir_list=("$(dirname "${BASH_SOURCE[0]}")"/*) - declare -a tests=(${dir_list[@]/*run_tests/}) + tests=("$TESTS"/*) for f in "${tests[@]}"; do - testenv=$(basename $f | cut -d"-" -f1) + testenv=$(basename $f) printf "Running \033[0;32m$f\033[0m Tests\n" exec_test $1 "$testenv --target clean" "Setup Build Environment" if [[ $GIT_RESET_HARD == "true" ]]; then @@ -58,16 +58,16 @@ else # If the test name is 1 or 2 digits, treat it as an index if [[ "$test_name" =~ ^[0-9][0-9]?$ ]] ; then # Find the test name that corresponds to that index - test_name="$(cat buildroot/tests/$2-tests | grep -e '^exec_test' | sed -n "$3p" | sed "s/.*\$1 \$2 \"\([^\"]*\).*/\1/g")" + test_name="$(cat $TESTS/$2 | grep -e '^exec_test' | sed -n "$3p" | sed "s/.*\$1 \$2 \"\([^\"]*\).*/\1/g")" if [[ -z "$test_name" ]] ; then # Fail if none matches - printf "\033[0;31mCould not find test \033[0m#$3\033[0;31m in \033[0mbuildroot/tests/$2-tests\n" + printf "\033[0;31mCould not find test \033[0m#$3\033[0;31m in \033[0mbuildroot/tests/$2\n" exit 1 else printf "\033[0;32mMatching test \033[0m#$3\033[0;32m: '\033[0m$test_name\033[0;32m'\n" fi fi - $2-tests $1 $2 "$test_name" + $TESTS/$2 $1 $2 "$test_name" if [[ $GIT_RESET_HARD == "true" ]]; then git reset --hard HEAD else diff --git a/buildroot/share/PlatformIO/scripts/SAMD51_grandcentral_m4.py b/buildroot/share/PlatformIO/scripts/SAMD51_grandcentral_m4.py new file mode 100644 index 000000000000..9e37024d118f --- /dev/null +++ b/buildroot/share/PlatformIO/scripts/SAMD51_grandcentral_m4.py @@ -0,0 +1,19 @@ +# +# SAMD51_grandcentral_m4.py +# Customizations for env:SAMD51_grandcentral_m4 +# +from os.path import join, isfile +import shutil +from pprint import pprint + +Import("env") + +mf = env["MARLIN_FEATURES"] +rxBuf = mf["RX_BUFFER_SIZE"] if "RX_BUFFER_SIZE" in mf else "0" +txBuf = mf["TX_BUFFER_SIZE"] if "TX_BUFFER_SIZE" in mf else "0" + +serialBuf = str(max(int(rxBuf), int(txBuf), 350)) + +build_flags = env.get('BUILD_FLAGS') +build_flags.append("-DSERIAL_BUFFER_SIZE=" + serialBuf) +env.Replace(BUILD_FLAGS=build_flags) diff --git a/buildroot/share/PlatformIO/scripts/STM32F103RC_MEEB_3DP.py b/buildroot/share/PlatformIO/scripts/STM32F103RC_MEEB_3DP.py index 547d80ace51c..6d7f21942e9e 100644 --- a/buildroot/share/PlatformIO/scripts/STM32F103RC_MEEB_3DP.py +++ b/buildroot/share/PlatformIO/scripts/STM32F103RC_MEEB_3DP.py @@ -1,3 +1,6 @@ +# +# STM32F103RC_MEEB_3DP.py +# try: import configparser except ImportError: diff --git a/buildroot/share/PlatformIO/scripts/STM32F103RC_SKR_MINI.py b/buildroot/share/PlatformIO/scripts/STM32F103RC_SKR_MINI.py index 497a035fdf4b..7e9dc676b6fb 100644 --- a/buildroot/share/PlatformIO/scripts/STM32F103RC_SKR_MINI.py +++ b/buildroot/share/PlatformIO/scripts/STM32F103RC_SKR_MINI.py @@ -1,3 +1,6 @@ +# +# STM32F103RC_SKR_MINI.py +# import os Import("env") diff --git a/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py b/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py index b69f62578bd4..1a7cc34edb8f 100644 --- a/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py +++ b/buildroot/share/PlatformIO/scripts/STM32F103RC_fysetc.py @@ -1,3 +1,6 @@ +# +# STM32F103RC_fysetc.py +# import os from os.path import join from os.path import expandvars diff --git a/buildroot/share/PlatformIO/scripts/creality.py b/buildroot/share/PlatformIO/scripts/STM32F103RET6_creality.py similarity index 94% rename from buildroot/share/PlatformIO/scripts/creality.py rename to buildroot/share/PlatformIO/scripts/STM32F103RET6_creality.py index b9d7d7039bb4..e3ef98b03ff0 100644 --- a/buildroot/share/PlatformIO/scripts/creality.py +++ b/buildroot/share/PlatformIO/scripts/STM32F103RET6_creality.py @@ -1,3 +1,6 @@ +# +# STM32F103RET6_creality.py +# import os Import("env") diff --git a/buildroot/share/PlatformIO/scripts/STM32F103RE_SKR_E3_DIP.py b/buildroot/share/PlatformIO/scripts/STM32F103RE_SKR_E3_DIP.py index ecdd57f594e8..06e586f7f807 100644 --- a/buildroot/share/PlatformIO/scripts/STM32F103RE_SKR_E3_DIP.py +++ b/buildroot/share/PlatformIO/scripts/STM32F103RE_SKR_E3_DIP.py @@ -1,3 +1,6 @@ +# +# STM32F103RE_SKR_E3_DIP.py +# import os Import("env") diff --git a/buildroot/share/PlatformIO/scripts/STM32F103VE_longer.py b/buildroot/share/PlatformIO/scripts/STM32F103VE_longer.py index ece47ed09601..321dd01b8d9c 100644 --- a/buildroot/share/PlatformIO/scripts/STM32F103VE_longer.py +++ b/buildroot/share/PlatformIO/scripts/STM32F103VE_longer.py @@ -1,3 +1,7 @@ +# +# STM32F103VE_longer.py +# Customizations for env:STM32F103VE_longer +# import os Import("env") @@ -14,7 +18,6 @@ elif flag == "-T": env["LINKFLAGS"][i + 1] = custom_ld_script - # Rename ${PROGNAME}.bin and save it as 'project.bin' (No encryption on the Longer3D) def encrypt(source, target, env): firmware = open(target[0].path, "rb") diff --git a/buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py b/buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py index 4849f59ceb03..0ba5d71f263f 100644 --- a/buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py +++ b/buildroot/share/PlatformIO/scripts/STM32F1_create_variant.py @@ -1,3 +1,6 @@ +# +# STM32F1_create_variant.py +# import os,shutil from SCons.Script import DefaultEnvironment from platformio import util diff --git a/buildroot/share/PlatformIO/scripts/STEVAL__F401XX.py b/buildroot/share/PlatformIO/scripts/STM32F401VE_STEVAL.py similarity index 81% rename from buildroot/share/PlatformIO/scripts/STEVAL__F401XX.py rename to buildroot/share/PlatformIO/scripts/STM32F401VE_STEVAL.py index 580529c9c1a8..ffd5bcd42d25 100644 --- a/buildroot/share/PlatformIO/scripts/STEVAL__F401XX.py +++ b/buildroot/share/PlatformIO/scripts/STM32F401VE_STEVAL.py @@ -1,3 +1,7 @@ +# +# STM32F401VE_STEVAL.py +# Customizations for env:STM32F401VE_STEVAL +# import os Import("env") diff --git a/buildroot/share/PlatformIO/scripts/add_nanolib.py b/buildroot/share/PlatformIO/scripts/add_nanolib.py index 102b4b9bb0e1..3b74b0d2714d 100644 --- a/buildroot/share/PlatformIO/scripts/add_nanolib.py +++ b/buildroot/share/PlatformIO/scripts/add_nanolib.py @@ -1,2 +1,5 @@ +# +# add_nanolib.py +# Import("env") env.Append(LINKFLAGS=["--specs=nano.specs"]) diff --git a/buildroot/share/PlatformIO/scripts/chitu_crypt.py b/buildroot/share/PlatformIO/scripts/chitu_crypt.py index aa675878e70e..3d4854b51f56 100644 --- a/buildroot/share/PlatformIO/scripts/chitu_crypt.py +++ b/buildroot/share/PlatformIO/scripts/chitu_crypt.py @@ -1,8 +1,9 @@ +# +# chitu_crypt.py +# Customizations for Chitu boards +# Import("env") -import os -import random -import struct -import uuid +import os,random,struct,uuid # Relocate firmware from 0x08000000 to 0x08008800 env['CPPDEFINES'].remove(("VECT_TAB_ADDR", "0x8000000")) diff --git a/buildroot/share/PlatformIO/scripts/common-cxxflags.py b/buildroot/share/PlatformIO/scripts/common-cxxflags.py index a0a3b45043f2..5c2bde7700fb 100644 --- a/buildroot/share/PlatformIO/scripts/common-cxxflags.py +++ b/buildroot/share/PlatformIO/scripts/common-cxxflags.py @@ -11,6 +11,13 @@ #"-Wno-sign-compare" ]) +# +# Add CPU frequency as a compile time constant instead of a runtime variable +# +def add_cpu_freq(): + if 'BOARD_F_CPU' in env: + env['BUILD_FLAGS'].append('-DBOARD_F_CPU=' + env['BOARD_F_CPU']) + # Useful for JTAG debugging # # It will separe release and debug build folders. @@ -20,3 +27,9 @@ # if env.GetBuildType() == "debug": env['BUILD_DIR'] = '$PROJECT_BUILD_DIR/$PIOENV/debug' + +# On some platform, F_CPU is a runtime variable. Since it's used to convert from ns +# to CPU cycles, this adds overhead preventing small delay (in the order of less than +# 30 cycles) to be generated correctly. By using a compile time constant instead +# the compiler will perform the computation and this overhead will be avoided +add_cpu_freq() diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies-post.py b/buildroot/share/PlatformIO/scripts/common-dependencies-post.py deleted file mode 100644 index 2b1b948119f0..000000000000 --- a/buildroot/share/PlatformIO/scripts/common-dependencies-post.py +++ /dev/null @@ -1,16 +0,0 @@ -# -# common-dependencies-post.py -# Convenience script to add build flags for Marlin Enabled Features -# - -Import("env") -Import("projenv") - -def apply_board_build_flags(): - if not 'BOARD_CUSTOM_BUILD_FLAGS' in env['MARLIN_FEATURES']: - return - projenv.Append(CCFLAGS=env['MARLIN_FEATURES']['BOARD_CUSTOM_BUILD_FLAGS'].split()) - -# We need to add the board build flags in a post script -# so the platform build script doesn't overwrite the custom CCFLAGS -apply_board_build_flags() diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.py b/buildroot/share/PlatformIO/scripts/common-dependencies.py index 4500f529a66b..3844d8298a45 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.py +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.py @@ -2,9 +2,7 @@ # common-dependencies.py # Convenience script to check dependencies and add libs and sources for Marlin Enabled Features # -import subprocess -import os -import re +import subprocess,os,re try: import configparser except ImportError: @@ -312,16 +310,6 @@ def MarlinFeatureIsEnabled(env, feature): return some_on -# -# Check for Configfiles in two common incorrect places -# -def check_configfile_locations(): - for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]: - for f in [ "Configuration.h", "Configuration_adv.h" ]: - if os.path.isfile(os.path.join(p, f)): - err = 'ERROR: Config files found in directory ' + str(p) + '. Please move them into the Marlin subdirectory.' - raise SystemExit(err) - # # Add a method for other PIO scripts to query enabled features # @@ -330,6 +318,5 @@ def check_configfile_locations(): # # Add dependencies for enabled Marlin features # -check_configfile_locations() apply_features_config() force_ignore_unused_libs() diff --git a/buildroot/share/PlatformIO/scripts/copy_marlin_variant_to_framework.py b/buildroot/share/PlatformIO/scripts/copy_marlin_variant_to_framework.py index f7d3f0d03ab7..7ea7ac57f3b0 100644 --- a/buildroot/share/PlatformIO/scripts/copy_marlin_variant_to_framework.py +++ b/buildroot/share/PlatformIO/scripts/copy_marlin_variant_to_framework.py @@ -1,3 +1,6 @@ +# +# copy_marlin_variant_to_framework.py +# import os,shutil from SCons.Script import DefaultEnvironment from platformio import util diff --git a/buildroot/share/PlatformIO/scripts/download_mks_assets.py b/buildroot/share/PlatformIO/scripts/download_mks_assets.py index ae2ce467e84a..33acab9e12c0 100644 --- a/buildroot/share/PlatformIO/scripts/download_mks_assets.py +++ b/buildroot/share/PlatformIO/scripts/download_mks_assets.py @@ -1,9 +1,8 @@ +# +# download_mks_assets.py +# Import("env") -import os -import requests -import zipfile -import tempfile -import shutil +import os,requests,zipfile,tempfile,shutil url = "https://github.com/makerbase-mks/Mks-Robin-Nano-Marlin2.0-Firmware/archive/master.zip" zip_path = os.path.join(env.Dictionary("PROJECT_LIBDEPS_DIR"), "mks-assets.zip") diff --git a/buildroot/share/PlatformIO/scripts/exc.S b/buildroot/share/PlatformIO/scripts/exc.S new file mode 100644 index 000000000000..1db462bb2379 --- /dev/null +++ b/buildroot/share/PlatformIO/scripts/exc.S @@ -0,0 +1,104 @@ +/* ***************************************************************************** + * The MIT License + * + * Copyright (c) 2010 Perry Hung. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * ****************************************************************************/ + +# On an exception, push a fake stack thread mode stack frame and redirect +# thread execution to a thread mode error handler + +# From RM008: +# The SP is decremented by eight words by the completion of the stack push. +# Figure 5-1 shows the contents of the stack after an exception pre-empts the +# current program flow. +# +# Old SP--> +# xPSR +# PC +# LR +# r12 +# r3 +# r2 +# r1 +# SP--> r0 + +.text +.globl __exc_nmi +.weak __exc_nmi +.globl __exc_hardfault +.weak __exc_hardfault +.globl __exc_memmanage +.weak __exc_memmanage +.globl __exc_busfault +.weak __exc_busfault +.globl __exc_usagefault +.weak __exc_usagefault + +.code 16 +.thumb_func +__exc_nmi: + mov r0, #1 + b __default_exc + +.thumb_func +__exc_hardfault: + mov r0, #2 + b __default_exc + +.thumb_func +__exc_memmanage: + mov r0, #3 + b __default_exc + +.thumb_func +__exc_busfault: + mov r0, #4 + b __default_exc + +.thumb_func +__exc_usagefault: + mov r0, #5 + b __default_exc + +.thumb_func +__default_exc: + ldr r2, NVIC_CCR @ Enable returning to thread mode even if there are + mov r1 ,#1 @ pending exceptions. See flag NONEBASETHRDENA. + str r1, [r2] + cpsid i @ Disable global interrupts + ldr r2, SYSTICK_CSR @ Disable systick handler + mov r1, #0 + str r1, [r2] + ldr r1, CPSR_MASK @ Set default CPSR + push {r1} + ldr r1, TARGET_PC @ Set target pc + push {r1} + sub sp, sp, #24 @ Don't care + ldr r1, EXC_RETURN @ Return to thread mode + mov lr, r1 + bx lr @ Exception exit + +.align 4 +CPSR_MASK: .word 0x61000000 +EXC_RETURN: .word 0xFFFFFFF9 +TARGET_PC: .word __error +NVIC_CCR: .word 0xE000ED14 @ NVIC configuration control register +SYSTICK_CSR: .word 0xE000E010 @ Systick control register diff --git a/buildroot/share/PlatformIO/scripts/fix_framework_weakness.py b/buildroot/share/PlatformIO/scripts/fix_framework_weakness.py new file mode 100644 index 000000000000..29705de442c7 --- /dev/null +++ b/buildroot/share/PlatformIO/scripts/fix_framework_weakness.py @@ -0,0 +1,44 @@ +# +# fix_framework_weakness.py +# +from os.path import join, isfile +import shutil +from pprint import pprint + +Import("env") + +if env.MarlinFeatureIsEnabled("POSTMORTEM_DEBUGGING"): + FRAMEWORK_DIR = env.PioPlatform().get_package_dir("framework-arduinoststm32-maple") + patchflag_path = join(FRAMEWORK_DIR, ".exc-patching-done") + + # patch file only if we didn't do it before + if not isfile(patchflag_path): + print("Patching libmaple exception handlers") + original_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S") + backup_file = join(FRAMEWORK_DIR, "STM32F1", "cores", "maple", "libmaple", "exc.S.bak") + src_file = join("buildroot", "share", "PlatformIO", "scripts", "exc.S") + + assert isfile(original_file) and isfile(src_file) + shutil.copyfile(original_file, backup_file) + shutil.copyfile(src_file, original_file); + + def _touch(path): + with open(path, "w") as fp: + fp.write("") + + env.Execute(lambda *args, **kwargs: _touch(patchflag_path)) + print("Done patching exception handler") + + print("Libmaple modified and ready for post mortem debugging") + +mf = env["MARLIN_FEATURES"] +rxBuf = mf["RX_BUFFER_SIZE"] if "RX_BUFFER_SIZE" in mf else "0" +txBuf = mf["TX_BUFFER_SIZE"] if "TX_BUFFER_SIZE" in mf else "0" +if int(rxBuf) < 64: + rxBuf = "64" +if int(txBuf) < 64: + txBuf = "64" + +build_flags = env.get('BUILD_FLAGS') +build_flags.append("-DUSART_RX_BUF_SIZE=" + rxBuf + " -DUSART_TX_BUF_SIZE=" + txBuf) +env.Replace(BUILD_FLAGS=build_flags) diff --git a/buildroot/share/PlatformIO/scripts/fly_mini.py b/buildroot/share/PlatformIO/scripts/fly_mini.py index 34d132958d6a..9c5df359ad76 100644 --- a/buildroot/share/PlatformIO/scripts/fly_mini.py +++ b/buildroot/share/PlatformIO/scripts/fly_mini.py @@ -1,3 +1,7 @@ +# +# fly_mini.py +# Customizations for env:FLY_MINI +# import os Import("env") diff --git a/buildroot/share/PlatformIO/scripts/fysetc_cheetah_v20.py b/buildroot/share/PlatformIO/scripts/fysetc_cheetah_v20.py index 10471d375346..f36d51f97205 100644 --- a/buildroot/share/PlatformIO/scripts/fysetc_cheetah_v20.py +++ b/buildroot/share/PlatformIO/scripts/fysetc_cheetah_v20.py @@ -1,3 +1,7 @@ +# +# STM32F401VE_STEVAL.py +# Customizations for env:STM32F401VE_STEVAL +# import os Import("env") diff --git a/buildroot/share/PlatformIO/scripts/generic_create_variant.py b/buildroot/share/PlatformIO/scripts/generic_create_variant.py index 0b82c69f5a3f..aa79d39b5122 100644 --- a/buildroot/share/PlatformIO/scripts/generic_create_variant.py +++ b/buildroot/share/PlatformIO/scripts/generic_create_variant.py @@ -1,3 +1,6 @@ +# +# Generate a generic variant +# import os,shutil from SCons.Script import DefaultEnvironment from platformio import util diff --git a/buildroot/share/PlatformIO/scripts/lerdge.py b/buildroot/share/PlatformIO/scripts/lerdge.py index fd934a127866..ff4f5e446ba7 100644 --- a/buildroot/share/PlatformIO/scripts/lerdge.py +++ b/buildroot/share/PlatformIO/scripts/lerdge.py @@ -1,3 +1,7 @@ +# +# lerdge.py +# Customizations for Lerdge build environments +# import os,sys Import("env") diff --git a/buildroot/share/PlatformIO/scripts/anet_et4_openblt.py b/buildroot/share/PlatformIO/scripts/openblt.py similarity index 100% rename from buildroot/share/PlatformIO/scripts/anet_et4_openblt.py rename to buildroot/share/PlatformIO/scripts/openblt.py diff --git a/buildroot/share/PlatformIO/scripts/preflight-checks.py b/buildroot/share/PlatformIO/scripts/preflight-checks.py new file mode 100644 index 000000000000..969a82aad29e --- /dev/null +++ b/buildroot/share/PlatformIO/scripts/preflight-checks.py @@ -0,0 +1,63 @@ +# +# preflight-checks.py +# Check for common issues prior to compiling +# +import os,re +Import("env") + +def get_envs_for_board(board): + if board.startswith("BOARD_"): + board = board[6:] + with open(os.path.join("Marlin", "src", "pins", "pins.h"),"r") as f: + board_found = "" + r=re.compile(r"if\s+MB\((.+)\)") + for line in f.readlines(): + mbs = r.findall(line) + if mbs: + board_found = board if board in re.split(r",\s*", mbs[0]) else "" + if board_found and "#include " in line and "env:" in line: + return re.findall(r"env:\w+", line) + return [] + +def check_envs(build_env, base_envs, config): + if build_env in base_envs: + return True + ext = config.get(build_env, 'extends', default=None) + if ext: + if isinstance(ext, str): + return check_envs(ext, base_envs, config) + elif isinstance(ext, list): + for ext_env in ext: + if check_envs(ext_env, base_envs, config): + return True + return False + +# Sanity checks: +if 'PIOENV' not in env: + raise SystemExit("Error: PIOENV is not defined. This script is intended to be used with PlatformIO") + +if 'MARLIN_FEATURES' not in env: + raise SystemExit("Error: this script should be used after common Marlin scripts") + +if 'MOTHERBOARD' not in env['MARLIN_FEATURES']: + raise SystemExit("Error: MOTHERBOARD is not defined in Configuration.h") + +build_env = env['PIOENV'] +motherboard = env['MARLIN_FEATURES']['MOTHERBOARD'] +base_envs = get_envs_for_board(motherboard) +config = env.GetProjectConfig() +result = check_envs("env:"+build_env, base_envs, config) + +if not result: + err = "Error: Build environment '%s' is incompatible with %s. Use one of these: %s" % \ + (build_env, motherboard, ",".join([e[4:] for e in base_envs if e.startswith("env:")])) + raise SystemExit(err) + +# +# Check for Config files in two common incorrect places +# +for p in [ env['PROJECT_DIR'], os.path.join(env['PROJECT_DIR'], "config") ]: + for f in [ "Configuration.h", "Configuration_adv.h" ]: + if os.path.isfile(os.path.join(p, f)): + err = "ERROR: Config files found in directory %s. Please move them into the Marlin subfolder." % p + raise SystemExit(err) diff --git a/buildroot/share/PlatformIO/scripts/random-bin.py b/buildroot/share/PlatformIO/scripts/random-bin.py index 4d7ca5dc09b7..c03b8634487a 100644 --- a/buildroot/share/PlatformIO/scripts/random-bin.py +++ b/buildroot/share/PlatformIO/scripts/random-bin.py @@ -1,3 +1,7 @@ +# +# random-bin.py +# Set a unique firmware name based on current date and time +# Import("env") from datetime import datetime diff --git a/buildroot/share/PlatformIO/scripts/stm32_bootloader.py b/buildroot/share/PlatformIO/scripts/stm32_bootloader.py index 7f49ea0e66f4..bbec61750c4c 100644 --- a/buildroot/share/PlatformIO/scripts/stm32_bootloader.py +++ b/buildroot/share/PlatformIO/scripts/stm32_bootloader.py @@ -1,3 +1,6 @@ +# +# stm32_bootloader.py +# import os,sys,shutil Import("env") diff --git a/buildroot/share/PlatformIO/variants/MARLIN_F4x7Vx/variant.h b/buildroot/share/PlatformIO/variants/MARLIN_F4x7Vx/variant.h index b53ad32d0f29..94fa79c065d8 100644 --- a/buildroot/share/PlatformIO/variants/MARLIN_F4x7Vx/variant.h +++ b/buildroot/share/PlatformIO/variants/MARLIN_F4x7Vx/variant.h @@ -143,8 +143,12 @@ extern "C" { #define PIN_SPI_SCK PA5 // I2C definitions -#define PIN_WIRE_SDA PB9 -#define PIN_WIRE_SCL PB8 +#ifndef PIN_WIRE_SDA + #define PIN_WIRE_SDA PB9 +#endif +#ifndef PIN_WIRE_SCL + #define PIN_WIRE_SCL PB8 +#endif // Timer Definitions // Use TIM6/TIM7 when possible as servo and tone don't need GPIO output pin diff --git a/buildroot/share/scripts/config-labels.py b/buildroot/share/scripts/config-labels.py index 267aa2d27353..700604e45284 100755 --- a/buildroot/share/scripts/config-labels.py +++ b/buildroot/share/scripts/config-labels.py @@ -22,8 +22,7 @@ # 2020-06-05 SRL style tweaks #----------------------------------- # -import sys -import os +import sys,os from pathlib import Path from distutils.dir_util import copy_tree # for copy_tree, because shutil.copytree can't handle existing files, dirs diff --git a/buildroot/share/scripts/createTemperatureLookupMarlin.py b/buildroot/share/scripts/createTemperatureLookupMarlin.py index b2d8964f556c..b3343de1a0f3 100755 --- a/buildroot/share/scripts/createTemperatureLookupMarlin.py +++ b/buildroot/share/scripts/createTemperatureLookupMarlin.py @@ -22,8 +22,7 @@ from __future__ import division from math import * -import sys -import getopt +import sys,getopt "Constants" ZERO = 273.15 # zero point of Kelvin scale diff --git a/buildroot/share/vscode/auto_build.py b/buildroot/share/vscode/auto_build.py index 61cacca4d777..ac8432729f0a 100644 --- a/buildroot/share/vscode/auto_build.py +++ b/buildroot/share/vscode/auto_build.py @@ -72,8 +72,7 @@ from __future__ import print_function from __future__ import division -import sys -import os +import sys,os pwd = os.getcwd() # make sure we're executing from the correct directory level pwd = pwd.replace('\\', '/') diff --git a/buildroot/share/vscode/create_custom_upload_command_CDC.py b/buildroot/share/vscode/create_custom_upload_command_CDC.py index 65edbd15b81d..4662dd26cb49 100644 --- a/buildroot/share/vscode/create_custom_upload_command_CDC.py +++ b/buildroot/share/vscode/create_custom_upload_command_CDC.py @@ -13,11 +13,9 @@ from __future__ import print_function from __future__ import division -import subprocess -import os -import sys +import subprocess,os,sys,platform from SCons.Script import DefaultEnvironment -import platform + current_OS = platform.system() env = DefaultEnvironment() diff --git a/buildroot/share/vscode/create_custom_upload_command_DFU.py b/buildroot/share/vscode/create_custom_upload_command_DFU.py index 9082699bf459..562e284e63c2 100644 --- a/buildroot/share/vscode/create_custom_upload_command_DFU.py +++ b/buildroot/share/vscode/create_custom_upload_command_DFU.py @@ -9,8 +9,7 @@ # Will continue on if a COM port isn't found so that the compilation can be done. # -import os -import sys +import os,sys from SCons.Script import DefaultEnvironment import platform current_OS = platform.system() diff --git a/buildroot/tests/ARMED-tests b/buildroot/tests/ARMED similarity index 82% rename from buildroot/tests/ARMED-tests rename to buildroot/tests/ARMED index 6aa1308ca41c..8764d47e84b1 100755 --- a/buildroot/tests/ARMED-tests +++ b/buildroot/tests/ARMED @@ -11,8 +11,7 @@ set -e # restore_configs use_example_configs ArmEd -opt_set X_DRIVER_TYPE TMC2130 -opt_set Y_DRIVER_TYPE TMC2208 +opt_set X_DRIVER_TYPE TMC2130 Y_DRIVER_TYPE TMC2208 exec_test $1 $2 "ArmEd Example Configuration with mixed TMC Drivers" "$3" # clean up diff --git a/buildroot/tests/BIGTREE_BTT002-tests b/buildroot/tests/BIGTREE_BTT002 similarity index 68% rename from buildroot/tests/BIGTREE_BTT002-tests rename to buildroot/tests/BIGTREE_BTT002 index 90e033e96958..ba13e3eafd69 100755 --- a/buildroot/tests/BIGTREE_BTT002-tests +++ b/buildroot/tests/BIGTREE_BTT002 @@ -10,10 +10,10 @@ set -e # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_BTT_BTT002_V1_0 -opt_set SERIAL_PORT 1 -opt_set X_DRIVER_TYPE TMC2209 -opt_set Y_DRIVER_TYPE TMC2130 +opt_set MOTHERBOARD BOARD_BTT_BTT002_V1_0 \ + SERIAL_PORT 1 \ + X_DRIVER_TYPE TMC2209 \ + Y_DRIVER_TYPE TMC2130 exec_test $1 $2 "BigTreeTech BTT002 Default Configuration plus TMC steppers" "$3" # clean up diff --git a/buildroot/tests/BIGTREE_GTR_V1_0 b/buildroot/tests/BIGTREE_GTR_V1_0 new file mode 100755 index 000000000000..95a1e0acac9e --- /dev/null +++ b/buildroot/tests/BIGTREE_GTR_V1_0 @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# +# Build tests for BigTreeTech GTR 1.0 +# + +# exit on first failure +set -e + +restore_configs +opt_set MOTHERBOARD BOARD_BTT_GTR_V1_0 SERIAL_PORT -1 \ + EXTRUDERS 8 TEMP_SENSOR_1 1 TEMP_SENSOR_2 1 TEMP_SENSOR_3 1 TEMP_SENSOR_4 1 TEMP_SENSOR_5 1 TEMP_SENSOR_6 1 TEMP_SENSOR_7 1 +# Not necessary to enable auto-fan for all extruders to hit problematic code paths +opt_set E0_AUTO_FAN_PIN PC10 E1_AUTO_FAN_PIN PC11 E2_AUTO_FAN_PIN PC12 NEOPIXEL_PIN PF13 \ + X_DRIVER_TYPE TMC2208 Y_DRIVER_TYPE TMC2130 \ + FIL_RUNOUT_PIN 3 FIL_RUNOUT2_PIN 4 FIL_RUNOUT3_PIN 5 FIL_RUNOUT4_PIN 6 FIL_RUNOUT5_PIN 7 FIL_RUNOUT6_PIN 8 FIL_RUNOUT7_PIN 9 FIL_RUNOUT8_PIN 10 \ + FIL_RUNOUT4_STATE HIGH FIL_RUNOUT8_STATE HIGH +opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER BLTOUCH NEOPIXEL_LED Z_SAFE_HOMING NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE \ + FILAMENT_RUNOUT_SENSOR FIL_RUNOUT4_PULLUP FIL_RUNOUT8_PULLUP +exec_test $1 $2 "BigTreeTech GTR | 8 Extruders | Auto-Fan | Mixed TMC Drivers | Runout Sensors w/ distinct states" "$3" + +restore_configs +opt_set MOTHERBOARD BOARD_BTT_GTR_V1_0 SERIAL_PORT -1 \ + EXTRUDERS 6 TEMP_SENSOR_1 1 TEMP_SENSOR_2 1 TEMP_SENSOR_3 1 TEMP_SENSOR_4 1 TEMP_SENSOR_5 1 \ + NUM_Z_STEPPER_DRIVERS 3 \ + DEFAULT_Kp_LIST '{ 22.2, 20.0, 21.0, 19.0, 18.0, 17.0 }' DEFAULT_Ki_LIST '{ 1.08 }' DEFAULT_Kd_LIST '{ 114.0, 112.0, 110.0, 108.0 }' +opt_enable TOOLCHANGE_FILAMENT_SWAP TOOLCHANGE_MIGRATION_FEATURE TOOLCHANGE_FS_INIT_BEFORE_SWAP TOOLCHANGE_FS_PRIME_FIRST_USED PID_PARAMS_PER_HOTEND +exec_test $1 $2 "BigTreeTech GTR | 6 Extruders | Triple Z" "$3" + +# clean up +restore_configs diff --git a/buildroot/tests/BIGTREE_GTR_V1_0-tests b/buildroot/tests/BIGTREE_GTR_V1_0-tests deleted file mode 100755 index adc850db03b3..000000000000 --- a/buildroot/tests/BIGTREE_GTR_V1_0-tests +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env bash -# -# Build tests for BigTreeTech GTR 1.0 -# - -# exit on first failure -set -e - -restore_configs -opt_set MOTHERBOARD BOARD_BTT_GTR_V1_0 -opt_set SERIAL_PORT -1 -opt_set EXTRUDERS 8 -opt_set TEMP_SENSOR_1 1 -opt_set TEMP_SENSOR_2 1 -opt_set TEMP_SENSOR_3 1 -opt_set TEMP_SENSOR_4 1 -opt_set TEMP_SENSOR_5 1 -opt_set TEMP_SENSOR_6 1 -opt_set TEMP_SENSOR_7 1 -# Not necessary to enable auto-fan for all extruders to hit problematic code paths -opt_set E0_AUTO_FAN_PIN PC10 -opt_set E1_AUTO_FAN_PIN PC11 -opt_set E2_AUTO_FAN_PIN PC12 -opt_set X_DRIVER_TYPE TMC2208 -opt_set Y_DRIVER_TYPE TMC2130 -opt_set NEOPIXEL_PIN PF13 -opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER BLTOUCH NEOPIXEL_LED Z_SAFE_HOMING -opt_enable FILAMENT_RUNOUT_SENSOR NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE -opt_set FIL_RUNOUT_PIN 3 -opt_set FIL_RUNOUT2_PIN 4 -opt_set FIL_RUNOUT3_PIN 5 -opt_set FIL_RUNOUT4_PIN 6 -opt_set FIL_RUNOUT5_PIN 7 -opt_set FIL_RUNOUT6_PIN 8 -opt_set FIL_RUNOUT7_PIN 9 -opt_set FIL_RUNOUT8_PIN 10 -opt_set FIL_RUNOUT4_STATE HIGH -opt_enable FIL_RUNOUT4_PULLUP -opt_set FIL_RUNOUT8_STATE HIGH -opt_enable FIL_RUNOUT8_PULLUP -exec_test $1 $2 "BigTreeTech GTR 8 Extruders with Auto-Fan, Mixed TMC Drivers, and Runout Sensors with distinct states" "$3" - -restore_configs -opt_set MOTHERBOARD BOARD_BTT_GTR_V1_0 -opt_set SERIAL_PORT -1 -opt_set EXTRUDERS 6 -opt_set TEMP_SENSOR_1 1 -opt_set TEMP_SENSOR_2 1 -opt_set TEMP_SENSOR_3 1 -opt_set TEMP_SENSOR_4 1 -opt_set TEMP_SENSOR_5 1 -opt_set NUM_Z_STEPPER_DRIVERS 3 -opt_set DEFAULT_Kp_LIST "{ 22.2, 20.0, 21.0, 19.0, 18.0, 17.0 }" -opt_set DEFAULT_Ki_LIST "{ 1.08 }" -opt_set DEFAULT_Kd_LIST "{ 114.0, 112.0, 110.0, 108.0 }" -opt_enable TOOLCHANGE_FILAMENT_SWAP TOOLCHANGE_MIGRATION_FEATURE TOOLCHANGE_FS_INIT_BEFORE_SWAP TOOLCHANGE_FS_PRIME_FIRST_USED PID_PARAMS_PER_HOTEND -exec_test $1 $2 "BigTreeTech GTR 6 Extruders Triple Z" "$3" - -# clean up -restore_configs diff --git a/buildroot/tests/BIGTREE_GTR_V1_0_usb_flash_drive b/buildroot/tests/BIGTREE_GTR_V1_0_usb_flash_drive new file mode 100755 index 000000000000..197ece5dfd66 --- /dev/null +++ b/buildroot/tests/BIGTREE_GTR_V1_0_usb_flash_drive @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# +# Build tests for BigTreeTech GTR 1.0 +# + +# exit on first failure +set -e + +restore_configs +opt_set MOTHERBOARD BOARD_BTT_GTR_V1_0 SERIAL_PORT 3 \ + EXTRUDERS 8 TEMP_SENSOR_1 1 TEMP_SENSOR_2 1 TEMP_SENSOR_3 1 TEMP_SENSOR_4 1 TEMP_SENSOR_5 1 TEMP_SENSOR_6 1 TEMP_SENSOR_7 1 +opt_enable SDSUPPORT USB_FLASH_DRIVE_SUPPORT USE_OTG_USB_HOST \ + REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER BLTOUCH NEOPIXEL_LED Z_SAFE_HOMING \ + FILAMENT_RUNOUT_SENSOR NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE +# Not necessary to enable auto-fan for all extruders to hit problematic code paths +opt_set E0_AUTO_FAN_PIN PC10 E1_AUTO_FAN_PIN PC11 E2_AUTO_FAN_PIN PC12 NEOPIXEL_PIN PF13 \ + X_DRIVER_TYPE TMC2208 Y_DRIVER_TYPE TMC2130 \ + FIL_RUNOUT_PIN 3 FIL_RUNOUT2_PIN 4 FIL_RUNOUT3_PIN 5 FIL_RUNOUT4_PIN 6 FIL_RUNOUT5_PIN 7 FIL_RUNOUT6_PIN 8 FIL_RUNOUT7_PIN 9 FIL_RUNOUT8_PIN 10 \ + FIL_RUNOUT4_STATE HIGH FIL_RUNOUT8_STATE HIGH +opt_enable FIL_RUNOUT4_PULLUP FIL_RUNOUT8_PULLUP +exec_test $1 $2 "GTT GTR | OTG USB Flash Drive | 8 Extruders | Auto-Fan | Mixed TMC Drivers | Runout Sensors (distinct)" "$3" + +# clean up +restore_configs diff --git a/buildroot/tests/BIGTREE_SKR_PRO-tests b/buildroot/tests/BIGTREE_SKR_PRO similarity index 52% rename from buildroot/tests/BIGTREE_SKR_PRO-tests rename to buildroot/tests/BIGTREE_SKR_PRO index 8dc433deb27b..74020c1b271b 100755 --- a/buildroot/tests/BIGTREE_SKR_PRO-tests +++ b/buildroot/tests/BIGTREE_SKR_PRO @@ -10,31 +10,22 @@ set -e # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_BTT_SKR_PRO_V1_1 -opt_set SERIAL_PORT 1 +opt_set MOTHERBOARD BOARD_BTT_SKR_PRO_V1_1 SERIAL_PORT 1 exec_test $1 $2 "BigTreeTech SKR Pro Default Configuration" "$3" restore_configs -opt_set MOTHERBOARD BOARD_BTT_SKR_PRO_V1_1 -opt_set SERIAL_PORT -1 -opt_set EXTRUDERS 3 -opt_set TEMP_SENSOR_1 1 -opt_set TEMP_SENSOR_2 1 -opt_set E0_AUTO_FAN_PIN PC10 -opt_set E1_AUTO_FAN_PIN PC11 -opt_set E2_AUTO_FAN_PIN PC12 -opt_set X_DRIVER_TYPE TMC2209 -opt_set Y_DRIVER_TYPE TMC2130 +opt_set MOTHERBOARD BOARD_BTT_SKR_PRO_V1_1 SERIAL_PORT -1 \ + EXTRUDERS 3 TEMP_SENSOR_1 1 TEMP_SENSOR_2 1 \ + E0_AUTO_FAN_PIN PC10 E1_AUTO_FAN_PIN PC11 E2_AUTO_FAN_PIN PC12 \ + X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2130 opt_enable BLTOUCH EEPROM_SETTINGS AUTO_BED_LEVELING_3POINT Z_SAFE_HOMING PINS_DEBUGGING exec_test $1 $2 "BigTreeTech SKR Pro 3 Extruders, Auto-Fan, BLTOUCH, mixed TMC drivers" "$3" restore_configs -opt_set MOTHERBOARD BOARD_BTT_SKR_PRO_V1_1 -opt_set SERIAL_PORT -1 +opt_set MOTHERBOARD BOARD_BTT_SKR_PRO_V1_1 SERIAL_PORT -1 \ + CUTTER_POWER_UNIT PERCENT \ + SPINDLE_LASER_PWM_PIN HEATER_1_PIN SPINDLE_LASER_ENA_PIN HEATER_2_PIN opt_enable LASER_FEATURE REPRAP_DISCOUNT_SMART_CONTROLLER -opt_set CUTTER_POWER_UNIT PERCENT -opt_add SPINDLE_LASER_PWM_PIN HEATER_1_PIN -opt_add SPINDLE_LASER_ENA_PIN HEATER_2_PIN exec_test $1 $2 "Laser, LCD, PERCENT power unit" "$3" # clean up diff --git a/buildroot/tests/DUE-tests b/buildroot/tests/DUE similarity index 79% rename from buildroot/tests/DUE-tests rename to buildroot/tests/DUE index d4c49a3185bc..d1601edf5ab7 100755 --- a/buildroot/tests/DUE-tests +++ b/buildroot/tests/DUE @@ -7,18 +7,18 @@ set -e restore_configs -opt_set LCD_LANGUAGE bg -opt_set MOTHERBOARD BOARD_RAMPS4DUE_EFB -opt_set TEMP_SENSOR_0 -2 -opt_set TEMP_SENSOR_BED 2 -opt_set GRID_MAX_POINTS_X 16 -opt_set FANMUX0_PIN 53 +opt_set MOTHERBOARD BOARD_RAMPS4DUE_EFB \ + LCD_LANGUAGE bg \ + TEMP_SENSOR_0 -2 TEMP_SENSOR_BED 2 \ + GRID_MAX_POINTS_X 16 \ + E0_AUTO_FAN_PIN 8 FANMUX0_PIN 53 EXTRUDER_AUTO_FAN_SPEED 100 \ + TEMP_SENSOR_CHAMBER 3 TEMP_CHAMBER_PIN 6 HEATER_CHAMBER_PIN 45 opt_enable S_CURVE_ACCELERATION EEPROM_SETTINGS GCODE_MACROS \ FIX_MOUNTED_PROBE Z_SAFE_HOMING CODEPENDENT_XY_HOMING \ ASSISTED_TRAMMING ASSISTED_TRAMMING_WIZARD REPORT_TRAMMING_MM ASSISTED_TRAMMING_WAIT_POSITION \ EEPROM_SETTINGS SDSUPPORT BINARY_FILE_TRANSFER \ BLINKM PCA9533 PCA9632 RGB_LED RGB_LED_R_PIN RGB_LED_G_PIN RGB_LED_B_PIN LED_CONTROL_MENU \ - NEOPIXEL_LED CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CASE_LIGHT_MENU \ + NEOPIXEL_LED CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CASE_LIGHT_USE_RGB_LED CASE_LIGHT_MENU \ NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE FILAMENT_RUNOUT_DISTANCE_MM FILAMENT_RUNOUT_SENSOR \ AUTO_BED_LEVELING_BILINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \ SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE CALIBRATION_GCODE \ @@ -28,23 +28,17 @@ opt_enable S_CURVE_ACCELERATION EEPROM_SETTINGS GCODE_MACROS \ PIDTEMPBED SLOW_PWM_HEATERS THERMAL_PROTECTION_CHAMBER \ PINS_DEBUGGING MAX7219_DEBUG M114_DETAIL \ EXTENSIBLE_UI -opt_add EXTUI_EXAMPLE -opt_set E0_AUTO_FAN_PIN 8 -opt_set EXTRUDER_AUTO_FAN_SPEED 100 -opt_set TEMP_SENSOR_CHAMBER 3 -opt_add TEMP_CHAMBER_PIN 6 -opt_set HEATER_CHAMBER_PIN 45 +opt_add EXTUI_EXAMPLE exec_test $1 $2 "RAMPS4DUE_EFB with ABL (Bilinear), ExtUI, S-Curve, many options." "$3" # # RADDS with BLTouch, ABL(B), 3 x Z auto-align # restore_configs -opt_set MOTHERBOARD BOARD_RADDS +opt_set MOTHERBOARD BOARD_RADDS NUM_Z_STEPPER_DRIVERS 3 opt_enable USE_XMAX_PLUG USE_YMAX_PLUG ENDSTOPPULLUPS BLTOUCH AUTO_BED_LEVELING_BILINEAR \ Z_STEPPER_AUTO_ALIGN Z_STEPPER_ALIGN_KNOWN_STEPPER_POSITIONS Z_SAFE_HOMING #TOUCH_UI_FTDI_EVE LCD_ALEPHOBJECTS_CLCD_UI OTHER_PIN_LAYOUT -opt_set NUM_Z_STEPPER_DRIVERS 3 pins_set ramps/RAMPS X_MAX_PIN -1 pins_set ramps/RAMPS Y_MAX_PIN -1 exec_test $1 $2 "RADDS with ABL (Bilinear), Triple Z Axis, Z_STEPPER_AUTO_ALIGN" "$3" @@ -53,9 +47,6 @@ exec_test $1 $2 "RADDS with ABL (Bilinear), Triple Z Axis, Z_STEPPER_AUTO_ALIGN" # Test SWITCHING_EXTRUDER # restore_configs -opt_set LCD_LANGUAGE fi -opt_set MOTHERBOARD BOARD_RAMPS4DUE_EEF -opt_set EXTRUDERS 2 -opt_set NUM_SERVOS 1 +opt_set MOTHERBOARD BOARD_RAMPS4DUE_EEF LCD_LANGUAGE fi EXTRUDERS 2 NUM_SERVOS 1 opt_enable SWITCHING_EXTRUDER ULTIMAKERCONTROLLER BEEP_ON_FEEDRATE_CHANGE POWER_LOSS_RECOVERY exec_test $1 $2 "RAMPS4DUE_EEF with SWITCHING_EXTRUDER, POWER_LOSS_RECOVERY" "$3" diff --git a/buildroot/tests/DUE_archim-tests b/buildroot/tests/DUE_archim similarity index 100% rename from buildroot/tests/DUE_archim-tests rename to buildroot/tests/DUE_archim diff --git a/buildroot/tests/FLYF407ZG-tests b/buildroot/tests/FLYF407ZG similarity index 64% rename from buildroot/tests/FLYF407ZG-tests rename to buildroot/tests/FLYF407ZG index 2c915eb48b39..22dd3488c8e1 100755 --- a/buildroot/tests/FLYF407ZG-tests +++ b/buildroot/tests/FLYF407ZG @@ -8,10 +8,7 @@ set -e # Build examples restore_configs -opt_set MOTHERBOARD BOARD_FLYF407ZG -opt_set SERIAL_PORT -1 -opt_set X_DRIVER_TYPE TMC2208 -opt_set Y_DRIVER_TYPE TMC2130 +opt_set MOTHERBOARD BOARD_FLYF407ZG SERIAL_PORT -1 X_DRIVER_TYPE TMC2208 Y_DRIVER_TYPE TMC2130 exec_test $1 $2 "FLYF407ZG Default Config with mixed TMC Drivers" "$3" # cleanup diff --git a/buildroot/tests/FYSETC_F6-tests b/buildroot/tests/FYSETC_F6 similarity index 66% rename from buildroot/tests/FYSETC_F6-tests rename to buildroot/tests/FYSETC_F6 index e1eb6684a539..3fe59d59a129 100755 --- a/buildroot/tests/FYSETC_F6-tests +++ b/buildroot/tests/FYSETC_F6 @@ -18,34 +18,24 @@ exec_test $1 $2 "FYSETC F6 1.3 with DGUS" "$3" # Delta Config (generic) + UBL + ALLEN_KEY + EEPROM_SETTINGS + OLED_PANEL_TINYBOY2 # use_example_configs delta/generic -opt_set MOTHERBOARD BOARD_FYSETC_F6_13 +opt_set MOTHERBOARD BOARD_FYSETC_F6_13 \ + LCD_LANGUAGE ko_KR \ + X_DRIVER_TYPE L6470 Y_DRIVER_TYPE L6470 Z_DRIVER_TYPE L6470 \ + L6470_CHAIN_SCK_PIN 53 L6470_CHAIN_MISO_PIN 49 L6470_CHAIN_MOSI_PIN 40 L6470_CHAIN_SS_PIN 42 \ + 'ENABLE_RESET_L64XX_CHIPS(V)' NOOP opt_enable RESTORE_LEVELING_AFTER_G28 EEPROM_SETTINGS EEPROM_CHITCHAT \ Z_PROBE_ALLEN_KEY AUTO_BED_LEVELING_UBL \ OLED_PANEL_TINYBOY2 MESH_EDIT_GFX_OVERLAY DELTA_CALIBRATION_MENU -opt_set LCD_LANGUAGE ko_KR -opt_set X_DRIVER_TYPE L6470 -opt_set Y_DRIVER_TYPE L6470 -opt_set Z_DRIVER_TYPE L6470 -opt_add L6470_CHAIN_SCK_PIN 53 -opt_add L6470_CHAIN_MISO_PIN 49 -opt_add L6470_CHAIN_MOSI_PIN 40 -opt_add L6470_CHAIN_SS_PIN 42 -opt_add "ENABLE_RESET_L64XX_CHIPS(V) NOOP" exec_test $1 $2 "DELTA, RAMPS, L6470, UBL, Allen Key, EEPROM, OLED_PANEL_TINYBOY2..." "$3" # # Test mixed TMC config # restore_configs -opt_set MOTHERBOARD BOARD_FYSETC_F6_13 -opt_set LCD_LANGUAGE vi -opt_set LCD_LANGUAGE_2 fr -opt_set X_DRIVER_TYPE TMC2160 -opt_set Y_DRIVER_TYPE TMC5160 -opt_set Z_DRIVER_TYPE TMC2208_STANDALONE -opt_set E0_DRIVER_TYPE TMC2130 -opt_set X_MIN_ENDSTOP_INVERTING true -opt_set Y_MIN_ENDSTOP_INVERTING true +opt_set MOTHERBOARD BOARD_FYSETC_F6_13 \ + LCD_LANGUAGE vi LCD_LANGUAGE_2 fr \ + X_DRIVER_TYPE TMC2160 Y_DRIVER_TYPE TMC5160 Z_DRIVER_TYPE TMC2208_STANDALONE E0_DRIVER_TYPE TMC2130 \ + X_MIN_ENDSTOP_INVERTING true Y_MIN_ENDSTOP_INVERTING true opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER \ MARLIN_BRICKOUT MARLIN_INVADERS MARLIN_SNAKE \ MONITOR_DRIVER_STATUS STEALTHCHOP_XY STEALTHCHOP_Z STEALTHCHOP_E HYBRID_THRESHOLD \ @@ -63,17 +53,14 @@ exec_test $1 $2 "RAMPS 1.3 | DELTA | FLSUN AC Config" "$3" # SCARA with Mixed TMC # use_example_configs SCARA/Morgan -opt_set MOTHERBOARD BOARD_FYSETC_F6_13 -opt_set LCD_LANGUAGE es +opt_set MOTHERBOARD BOARD_FYSETC_F6_13 \ + LCD_LANGUAGE es \ + X_MAX_ENDSTOP_INVERTING false \ + X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2130 Z_DRIVER_TYPE TMC2130_STANDALONE E0_DRIVER_TYPE TMC2660 \ + X_HARDWARE_SERIAL Serial2 opt_enable USE_ZMIN_PLUG FIX_MOUNTED_PROBE AUTO_BED_LEVELING_BILINEAR PAUSE_BEFORE_DEPLOY_STOW \ FYSETC_242_OLED_12864 EEPROM_SETTINGS EEPROM_CHITCHAT M114_DETAIL Z_SAFE_HOMING \ STEALTHCHOP_XY STEALTHCHOP_Z STEALTHCHOP_E HYBRID_THRESHOLD SENSORLESS_HOMING SQUARE_WAVE_STEPPING -opt_set X_MAX_ENDSTOP_INVERTING false -opt_set X_DRIVER_TYPE TMC2209 -opt_set Y_DRIVER_TYPE TMC2130 -opt_set Z_DRIVER_TYPE TMC2130_STANDALONE -opt_set E0_DRIVER_TYPE TMC2660 -opt_add X_HARDWARE_SERIAL Serial2 exec_test $1 $2 "FYSETC_F6 | SCARA | Mixed TMC | EEPROM" "$3" # clean up diff --git a/buildroot/tests/FYSETC_S6-tests b/buildroot/tests/FYSETC_S6 similarity index 79% rename from buildroot/tests/FYSETC_S6-tests rename to buildroot/tests/FYSETC_S6 index c7f7a16bbdbf..ce5442c37618 100755 --- a/buildroot/tests/FYSETC_S6-tests +++ b/buildroot/tests/FYSETC_S6 @@ -10,8 +10,7 @@ set -e restore_configs use_example_configs FYSETC/S6 opt_enable MEATPACK -opt_set Y_DRIVER_TYPE TMC2209 -opt_set Z_DRIVER_TYPE TMC2130 +opt_set Y_DRIVER_TYPE TMC2209 Z_DRIVER_TYPE TMC2130 exec_test $1 $2 "FYSETC S6 Example" "$3" # cleanup diff --git a/buildroot/tests/LERDGEX-tests b/buildroot/tests/LERDGEX similarity index 80% rename from buildroot/tests/LERDGEX-tests rename to buildroot/tests/LERDGEX index 7fcdb2684f98..cf7dfebfeabb 100755 --- a/buildroot/tests/LERDGEX-tests +++ b/buildroot/tests/LERDGEX @@ -10,8 +10,7 @@ set -e # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_LERDGE_X -opt_set SERIAL_PORT 1 +opt_set MOTHERBOARD BOARD_LERDGE_X SERIAL_PORT 1 exec_test $1 $2 "LERDGE X with Default Configuration" "$3" # clean up diff --git a/buildroot/tests/LPC1768-tests b/buildroot/tests/LPC1768 similarity index 80% rename from buildroot/tests/LPC1768-tests rename to buildroot/tests/LPC1768 index 27d2fbf3ff6f..a6829e85ea2a 100755 --- a/buildroot/tests/LPC1768-tests +++ b/buildroot/tests/LPC1768 @@ -14,9 +14,8 @@ set -e #exec_test $1 $2 "Default Configuration" "$3" restore_configs -opt_set MOTHERBOARD BOARD_RAMPS_14_RE_ARM_EFB +opt_set MOTHERBOARD BOARD_RAMPS_14_RE_ARM_EFB NEOPIXEL_PIN P1_16 opt_enable VIKI2 SDSUPPORT SDCARD_READONLY SERIAL_PORT_2 NEOPIXEL_LED -opt_set NEOPIXEL_PIN P1_16 exec_test $1 $2 "ReARM EFB VIKI2, SDSUPPORT, 2 Serial ports (USB CDC + UART0), NeoPixel" "$3" #restore_configs @@ -24,19 +23,18 @@ exec_test $1 $2 "ReARM EFB VIKI2, SDSUPPORT, 2 Serial ports (USB CDC + UART0), N #exec_test $1 $2 "MKS SBASE Example Config" "$3" restore_configs -opt_set MOTHERBOARD BOARD_MKS_SBASE -opt_set EXTRUDERS 2 -opt_set TEMP_SENSOR_1 1 -opt_set NUM_SERVOS 2 -opt_set SERVO_DELAY "{ 300, 300 }" +opt_set MOTHERBOARD BOARD_MKS_SBASE \ + EXTRUDERS 2 TEMP_SENSOR_1 1 \ + NUM_SERVOS 2 SERVO_DELAY '{ 300, 300 }' opt_enable SWITCHING_NOZZLE SWITCHING_NOZZLE_E1_SERVO_NR ULTIMAKERCONTROLLER exec_test $1 $2 "MKS SBASE with SWITCHING_NOZZLE" "$3" restore_configs -opt_set MOTHERBOARD BOARD_RAMPS_14_RE_ARM_EEB -opt_set EXTRUDERS 2 -opt_set TEMP_SENSOR_1 -1 -opt_set TEMP_SENSOR_BED 5 +opt_set MOTHERBOARD BOARD_RAMPS_14_RE_ARM_EEB \ + EXTRUDERS 2 TEMP_SENSOR_1 -1 TEMP_SENSOR_BED 5 \ + GRID_MAX_POINTS_X 16 \ + NOZZLE_TO_PROBE_OFFSET '{ 0, 0, 0 }' \ + NOZZLE_CLEAN_MIN_TEMP 170 opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER ADAPTIVE_FAN_SLOWING NO_FAN_SLOWING_IN_PID_TUNING \ FILAMENT_WIDTH_SENSOR FILAMENT_LCD_DISPLAY PID_EXTRUSION_SCALING SOUND_MENU_ITEM \ NOZZLE_AS_PROBE AUTO_BED_LEVELING_BILINEAR PREHEAT_BEFORE_LEVELING G29_RETRY_AND_RECOVER Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \ @@ -46,9 +44,6 @@ opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER ADAPTIVE_FAN_SLOWING NO HOST_KEEPALIVE_FEATURE HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT \ LCD_INFO_MENU ARC_SUPPORT BEZIER_CURVE_SUPPORT EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES \ SDSUPPORT SDCARD_SORT_ALPHA AUTO_REPORT_SD_STATUS EMERGENCY_PARSER -opt_set GRID_MAX_POINTS_X 16 -opt_set NOZZLE_TO_PROBE_OFFSET "{ 0, 0, 0 }" -opt_set NOZZLE_CLEAN_MIN_TEMP 170 exec_test $1 $2 "Re-ARM with NOZZLE_AS_PROBE and many features." "$3" # clean up diff --git a/buildroot/tests/LPC1769-tests b/buildroot/tests/LPC1769 similarity index 86% rename from buildroot/tests/LPC1769-tests rename to buildroot/tests/LPC1769 index 0a61d4280002..5ca711454344 100755 --- a/buildroot/tests/LPC1769-tests +++ b/buildroot/tests/LPC1769 @@ -13,17 +13,15 @@ use_example_configs Azteeg/X5GT exec_test $1 $2 "Azteeg X5GT Example Configuration" "$3" restore_configs -opt_set MOTHERBOARD BOARD_SMOOTHIEBOARD -opt_set EXTRUDERS 2 -opt_set TEMP_SENSOR_1 -1 -opt_set TEMP_SENSOR_BED 5 +opt_set MOTHERBOARD BOARD_SMOOTHIEBOARD \ + EXTRUDERS 2 TEMP_SENSOR_1 -1 TEMP_SENSOR_BED 5 \ + GRID_MAX_POINTS_X 16 opt_enable TFTGLCD_PANEL_SPI SDSUPPORT ADAPTIVE_FAN_SLOWING NO_FAN_SLOWING_IN_PID_TUNING \ FIX_MOUNTED_PROBE AUTO_BED_LEVELING_BILINEAR G29_RETRY_AND_RECOVER Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \ BABYSTEPPING BABYSTEP_XY BABYSTEP_ZPROBE_OFFSET LEVEL_CORNERS_USE_PROBE LEVEL_CORNERS_VERIFY_RAISED \ PRINTCOUNTER NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE SLOW_PWM_HEATERS PIDTEMPBED EEPROM_SETTINGS INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT \ Z_SAFE_HOMING ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE \ LCD_INFO_MENU ARC_SUPPORT BEZIER_CURVE_SUPPORT EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES SDCARD_SORT_ALPHA EMERGENCY_PARSER -opt_set GRID_MAX_POINTS_X 16 exec_test $1 $2 "Smoothieboard with TFTGLCD_PANEL_SPI and many features" "$3" #restore_configs @@ -36,17 +34,13 @@ exec_test $1 $2 "Smoothieboard with TFTGLCD_PANEL_SPI and many features" "$3" # SD_ABORT_ON_ENDSTOP_HIT ADVANCED_OK GCODE_MACROS \ # VOLUMETRIC_DEFAULT_ON NO_WORKSPACE_OFFSETS \ # EXTRA_FAN_SPEED FWRETRACT MENU_ADDAUTOSTART SDCARD_SORT_ALPHA -#opt_set FAN_MIN_PWM 50 -#opt_set FAN_KICKSTART_TIME 100 -#opt_set XY_FREQUENCY_LIMIT 15 +#opt_set FAN_MIN_PWM 50 FAN_KICKSTART_TIME 100 XY_FREQUENCY_LIMIT 15 #exec_test $1 $2 "Azteeg X5 MINI WIFI Many less common options" "$3" restore_configs use_example_configs delta/generic -opt_set MOTHERBOARD BOARD_COHESION3D_REMIX -opt_set X_DRIVER_TYPE TMC2130 -opt_set Y_DRIVER_TYPE TMC2130 -opt_set Z_DRIVER_TYPE TMC2130 +opt_set MOTHERBOARD BOARD_COHESION3D_REMIX \ + X_DRIVER_TYPE TMC2130 Y_DRIVER_TYPE TMC2130 Z_DRIVER_TYPE TMC2130 opt_enable AUTO_BED_LEVELING_BILINEAR EEPROM_SETTINGS EEPROM_CHITCHAT MECHANICAL_GANTRY_CALIBRATION \ TMC_USE_SW_SPI MONITOR_DRIVER_STATUS STEALTHCHOP_XY STEALTHCHOP_Z HYBRID_THRESHOLD \ SENSORLESS_PROBING Z_SAFE_HOMING X_STALL_SENSITIVITY Y_STALL_SENSITIVITY Z_STALL_SENSITIVITY TMC_DEBUG \ diff --git a/buildroot/tests/NUCLEO_F767ZI-tests b/buildroot/tests/NUCLEO_F767ZI similarity index 69% rename from buildroot/tests/NUCLEO_F767ZI-tests rename to buildroot/tests/NUCLEO_F767ZI index bd5ca8697095..9e2324660695 100755 --- a/buildroot/tests/NUCLEO_F767ZI-tests +++ b/buildroot/tests/NUCLEO_F767ZI @@ -10,11 +10,8 @@ set -e # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_NUCLEO_F767ZI -opt_set SERIAL_PORT -1 +opt_set MOTHERBOARD BOARD_NUCLEO_F767ZI SERIAL_PORT -1 X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2208 opt_enable BLTOUCH Z_SAFE_HOMING SPEAKER SOFTWARE_DRIVER_ENABLE -opt_set X_DRIVER_TYPE TMC2209 -opt_set Y_DRIVER_TYPE TMC2208 exec_test $1 $2 "Mixed timer usage" "$3" # clean up diff --git a/buildroot/tests/REMRAM_V1-tests b/buildroot/tests/REMRAM_V1 similarity index 100% rename from buildroot/tests/REMRAM_V1-tests rename to buildroot/tests/REMRAM_V1 diff --git a/buildroot/tests/SAMD51_grandcentral_m4-tests b/buildroot/tests/SAMD51_grandcentral_m4 similarity index 72% rename from buildroot/tests/SAMD51_grandcentral_m4-tests rename to buildroot/tests/SAMD51_grandcentral_m4 index a98929520ec1..92a62c9d37a4 100755 --- a/buildroot/tests/SAMD51_grandcentral_m4-tests +++ b/buildroot/tests/SAMD51_grandcentral_m4 @@ -10,20 +10,14 @@ set -e # Build with the default configurations # restore_configs -opt_set SERIAL_PORT -1 -opt_set MOTHERBOARD BOARD_AGCM4_RAMPS_144 -opt_set TEMP_SENSOR_0 11 -opt_set TEMP_SENSOR_BED 11 -opt_set X_DRIVER_TYPE TMC2209 -opt_set Y_DRIVER_TYPE TMC2209 -opt_set Z_DRIVER_TYPE TMC2209 -opt_set Z2_DRIVER_TYPE TMC2209 -opt_set E0_DRIVER_TYPE TMC2209 -opt_set RESTORE_LEVELING_AFTER_G28 false -opt_set LCD_LANGUAGE it -opt_set NUM_Z_STEPPER_DRIVERS 2 -opt_set HOMING_BUMP_MM "{ 0, 0, 0 }" -opt_set SDCARD_CONNECTION LCD +opt_set MOTHERBOARD BOARD_AGCM4_RAMPS_144 SERIAL_PORT -1 \ + TEMP_SENSOR_0 11 TEMP_SENSOR_BED 11 \ + X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2209 Z_DRIVER_TYPE TMC2209 Z2_DRIVER_TYPE TMC2209 E0_DRIVER_TYPE TMC2209 \ + RESTORE_LEVELING_AFTER_G28 false \ + LCD_LANGUAGE it \ + SDCARD_CONNECTION LCD \ + NUM_Z_STEPPER_DRIVERS 2 \ + HOMING_BUMP_MM '{ 0, 0, 0 }' opt_enable ENDSTOP_INTERRUPTS_FEATURE S_CURVE_ACCELERATION BLTOUCH Z_MIN_PROBE_REPEATABILITY_TEST \ FILAMENT_RUNOUT_SENSOR G26_MESH_VALIDATION MESH_EDIT_GFX_OVERLAY Z_SAFE_HOMING \ EEPROM_SETTINGS NOZZLE_PARK_FEATURE SDSUPPORT SD_CHECK_AND_RETRY \ diff --git a/buildroot/tests/STM32F070CB_malyan-tests b/buildroot/tests/STM32F070CB_malyan similarity index 75% rename from buildroot/tests/STM32F070CB_malyan-tests rename to buildroot/tests/STM32F070CB_malyan index eeec7e9b1f12..060d707b04e5 100755 --- a/buildroot/tests/STM32F070CB_malyan-tests +++ b/buildroot/tests/STM32F070CB_malyan @@ -7,8 +7,7 @@ set -e restore_configs -opt_set MOTHERBOARD BOARD_MALYAN_M200_V2 -opt_set SERIAL_PORT -1 +opt_set MOTHERBOARD BOARD_MALYAN_M200_V2 SERIAL_PORT -1 exec_test $1 $2 "Malyan M200 v2 Default Config" "$3" # cleanup diff --git a/buildroot/tests/STM32F070RB_malyan-tests b/buildroot/tests/STM32F070RB_malyan similarity index 100% rename from buildroot/tests/STM32F070RB_malyan-tests rename to buildroot/tests/STM32F070RB_malyan diff --git a/buildroot/tests/STM32F103CB_malyan-tests b/buildroot/tests/STM32F103CB_malyan similarity index 100% rename from buildroot/tests/STM32F103CB_malyan-tests rename to buildroot/tests/STM32F103CB_malyan diff --git a/buildroot/tests/STM32F103RC_btt-tests b/buildroot/tests/STM32F103RC_btt similarity index 54% rename from buildroot/tests/STM32F103RC_btt-tests rename to buildroot/tests/STM32F103RC_btt index 0084f59a0ce8..e76060aee82f 100755 --- a/buildroot/tests/STM32F103RC_btt-tests +++ b/buildroot/tests/STM32F103RC_btt @@ -10,14 +10,9 @@ set -e # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_E3_V1_0 -opt_set SERIAL_PORT 1 -opt_set SERIAL_PORT_2 -1 -opt_set X_DRIVER_TYPE TMC2209 -opt_set Y_DRIVER_TYPE TMC2209 -opt_set Z_DRIVER_TYPE TMC2209 -opt_set E0_DRIVER_TYPE TMC2209 -opt_enable PINS_DEBUGGING +opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_E3_V1_0 SERIAL_PORT 1 SERIAL_PORT_2 -1 \ + X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2209 Z_DRIVER_TYPE TMC2209 E0_DRIVER_TYPE TMC2209 +opt_enable PINS_DEBUGGING Z_IDLE_HEIGHT exec_test $1 $2 "BigTreeTech SKR Mini E3 1.0 - Basic Config with TMC2209 HW Serial" "$3" diff --git a/buildroot/tests/STM32F103RC_btt_USB-tests b/buildroot/tests/STM32F103RC_btt_USB similarity index 75% rename from buildroot/tests/STM32F103RC_btt_USB-tests rename to buildroot/tests/STM32F103RC_btt_USB index d752c87d1820..8381de0ea6e4 100755 --- a/buildroot/tests/STM32F103RC_btt_USB-tests +++ b/buildroot/tests/STM32F103RC_btt_USB @@ -10,9 +10,7 @@ set -e # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_V1_1 -opt_set SERIAL_PORT 1 -opt_set SERIAL_PORT_2 -1 +opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_V1_1 SERIAL_PORT 1 SERIAL_PORT_2 -1 exec_test $1 $2 "BigTreeTech SKR Mini v1.1 - Basic Configuration" "$3" # clean up diff --git a/buildroot/tests/STM32F103RC_fysetc-tests b/buildroot/tests/STM32F103RC_fysetc similarity index 100% rename from buildroot/tests/STM32F103RC_fysetc-tests rename to buildroot/tests/STM32F103RC_fysetc diff --git a/buildroot/tests/STM32F103RC_meeb-tests b/buildroot/tests/STM32F103RC_meeb similarity index 56% rename from buildroot/tests/STM32F103RC_meeb-tests rename to buildroot/tests/STM32F103RC_meeb index 4fcb6e8118d3..3a191b4e7e2d 100755 --- a/buildroot/tests/STM32F103RC_meeb-tests +++ b/buildroot/tests/STM32F103RC_meeb @@ -10,13 +10,8 @@ set -e # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_CCROBOT_MEEB_3DP -opt_set SERIAL_PORT 1 -opt_set SERIAL_PORT_2 -1 -opt_set X_DRIVER_TYPE TMC2208 -opt_set Y_DRIVER_TYPE TMC2208 -opt_set Z_DRIVER_TYPE TMC2208 -opt_set E0_DRIVER_TYPE TMC2208 +opt_set MOTHERBOARD BOARD_CCROBOT_MEEB_3DP SERIAL_PORT 1 SERIAL_PORT_2 -1 \ + X_DRIVER_TYPE TMC2208 Y_DRIVER_TYPE TMC2208 Z_DRIVER_TYPE TMC2208 E0_DRIVER_TYPE TMC2208 exec_test $1 $2 "MEEB_3DP - Basic Config with TMC2208 SW Serial" "$3" # clean up diff --git a/buildroot/tests/STM32F103RE-tests b/buildroot/tests/STM32F103RE similarity index 87% rename from buildroot/tests/STM32F103RE-tests rename to buildroot/tests/STM32F103RE index 909c362d066d..426f87d21bb1 100755 --- a/buildroot/tests/STM32F103RE-tests +++ b/buildroot/tests/STM32F103RE @@ -10,9 +10,7 @@ set -e # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_STM32F103RE -opt_set EXTRUDERS 2 -opt_set SERIAL_PORT -1 +opt_set MOTHERBOARD BOARD_STM32F103RE SERIAL_PORT -1 EXTRUDERS 2 opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT \ PAREN_COMMENTS GCODE_MOTION_MODES SINGLENOZZLE TOOLCHANGE_FILAMENT_SWAP TOOLCHANGE_PARK \ BAUD_RATE_GCODE GCODE_MACROS NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE diff --git a/buildroot/tests/STM32F103RET6_creality-tests b/buildroot/tests/STM32F103RET6_creality similarity index 82% rename from buildroot/tests/STM32F103RET6_creality-tests rename to buildroot/tests/STM32F103RET6_creality index 199bd6a9c2d8..ef020a33f1c6 100755 --- a/buildroot/tests/STM32F103RET6_creality-tests +++ b/buildroot/tests/STM32F103RET6_creality @@ -19,11 +19,10 @@ opt_add SDCARD_EEPROM_EMULATION exec_test $1 $2 "Ender 3 v2, SD EEPROM, w/o CLASSIC_JERK" "$3" restore_configs -opt_set SERIAL_PORT 1 -opt_set MOTHERBOARD BOARD_CREALITY_V452 +opt_set MOTHERBOARD BOARD_CREALITY_V452 SERIAL_PORT 1 opt_disable NOZZLE_TO_PROBE_OFFSET -opt_enable NOZZLE_AS_PROBE Z_SAFE_HOMING Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN -opt_enable PROBE_ACTIVATION_SWITCH PROBE_TARE PROBE_TARE_ONLY_WHILE_INACTIVE +opt_enable NOZZLE_AS_PROBE Z_SAFE_HOMING Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN \ + PROBE_ACTIVATION_SWITCH PROBE_TARE PROBE_TARE_ONLY_WHILE_INACTIVE exec_test $1 $2 "Creality V4.5.2 PROBE_ACTIVATION_SWITCH, Probe Tare" "$3" # clean up diff --git a/buildroot/tests/STM32F103RE_btt b/buildroot/tests/STM32F103RE_btt new file mode 100755 index 000000000000..97d7ffec4bdd --- /dev/null +++ b/buildroot/tests/STM32F103RE_btt @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# +# Build tests for STM32F103RE BigTreeTech (SKR E3 DIP v1.0) +# + +# exit on first failure +set -e + +# +# Build with the default configurations +# +restore_configs +opt_set MOTHERBOARD BOARD_BTT_SKR_E3_DIP \ + SERIAL_PORT 1 SERIAL_PORT_2 -1 \ + X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2130 +exec_test $1 $2 "BTT SKR E3 DIP 1.0 | Mixed TMC Drivers" "$3" + +# clean up +restore_configs diff --git a/buildroot/tests/STM32F103RE_btt-tests b/buildroot/tests/STM32F103RE_btt-tests deleted file mode 100755 index ab8681c7f527..000000000000 --- a/buildroot/tests/STM32F103RE_btt-tests +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# -# Build tests for STM32F103RE BigTreeTech (SKR E3 DIP v1.0) -# - -# exit on first failure -set -e - -# -# Build with the default configurations -# -restore_configs -opt_set MOTHERBOARD BOARD_BTT_SKR_E3_DIP -opt_set SERIAL_PORT 1 -opt_set SERIAL_PORT_2 -1 -opt_set X_DRIVER_TYPE TMC2209 -opt_set Y_DRIVER_TYPE TMC2130 -exec_test $1 $2 "BigTreeTech SKR E3 DIP v1.0 - Basic Config with mixed TMC Drivers" "$3" - -# clean up -restore_configs diff --git a/buildroot/tests/STM32F103RE_btt_USB-tests b/buildroot/tests/STM32F103RE_btt_USB similarity index 76% rename from buildroot/tests/STM32F103RE_btt_USB-tests rename to buildroot/tests/STM32F103RE_btt_USB index 43162b68a4b3..c63a90e43681 100755 --- a/buildroot/tests/STM32F103RE_btt_USB-tests +++ b/buildroot/tests/STM32F103RE_btt_USB @@ -10,16 +10,11 @@ set -e # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_BTT_SKR_E3_DIP -opt_set SERIAL_PORT 1 -opt_set SERIAL_PORT_2 -1 +opt_set MOTHERBOARD BOARD_BTT_SKR_E3_DIP SERIAL_PORT 1 SERIAL_PORT_2 -1 exec_test $1 $2 "BigTreeTech SKR E3 DIP v1.0 - Basic Configuration" "$3" restore_configs -opt_set MOTHERBOARD BOARD_BTT_SKR_CR6 -opt_set SERIAL_PORT -1 -opt_set SERIAL_PORT_2 2 -opt_set TEMP_SENSOR_BED 1 +opt_set MOTHERBOARD BOARD_BTT_SKR_CR6 SERIAL_PORT -1 SERIAL_PORT_2 2 TEMP_SENSOR_BED 1 opt_enable CR10_STOCKDISPLAY \ NOZZLE_AS_PROBE Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN Z_SAFE_HOMING \ PROBE_ACTIVATION_SWITCH PROBE_TARE PROBE_TARE_ONLY_WHILE_INACTIVE \ diff --git a/buildroot/tests/STM32F103VE_longer-tests b/buildroot/tests/STM32F103VE_longer similarity index 100% rename from buildroot/tests/STM32F103VE_longer-tests rename to buildroot/tests/STM32F103VE_longer diff --git a/buildroot/tests/STM32F401VE_STEVAL-tests b/buildroot/tests/STM32F401VE_STEVAL similarity index 76% rename from buildroot/tests/STM32F401VE_STEVAL-tests rename to buildroot/tests/STM32F401VE_STEVAL index d7c90e7907f9..1704f3d2f004 100755 --- a/buildroot/tests/STM32F401VE_STEVAL-tests +++ b/buildroot/tests/STM32F401VE_STEVAL @@ -8,8 +8,7 @@ set -e # Build examples restore_configs -opt_set MOTHERBOARD BOARD_STEVAL_3DP001V1 -opt_set SERIAL_PORT -1 +opt_set MOTHERBOARD BOARD_STEVAL_3DP001V1 SERIAL_PORT -1 exec_test $1 $2 "STM32F401VE_STEVAL Default Config" "$3" # cleanup diff --git a/buildroot/tests/STM32F407VE_black-tests b/buildroot/tests/STM32F407VE_black similarity index 100% rename from buildroot/tests/STM32F407VE_black-tests rename to buildroot/tests/STM32F407VE_black diff --git a/buildroot/tests/at90usb1286_cdc-tests b/buildroot/tests/at90usb1286_cdc similarity index 100% rename from buildroot/tests/at90usb1286_cdc-tests rename to buildroot/tests/at90usb1286_cdc diff --git a/buildroot/tests/at90usb1286_dfu-tests b/buildroot/tests/at90usb1286_dfu similarity index 100% rename from buildroot/tests/at90usb1286_dfu-tests rename to buildroot/tests/at90usb1286_dfu diff --git a/buildroot/tests/esp32 b/buildroot/tests/esp32 new file mode 100755 index 000000000000..a0f79107cf2f --- /dev/null +++ b/buildroot/tests/esp32 @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# +# Build tests for ESP32 +# + +# exit on first failure +set -e + +# +# Build with the default configurations +# +restore_configs +opt_set MOTHERBOARD BOARD_ESPRESSIF_ESP32 TX_BUFFER_SIZE 64 \ + WIFI_SSID '"ssid"' WIFI_PWD '"password"' +opt_enable WIFISUPPORT WEBSUPPORT GCODE_MACROS BAUD_RATE_GCODE M115_GEOMETRY_REPORT REPETIER_GCODE_M360 +exec_test $1 $2 "ESP32 with WIFISUPPORT and WEBSUPPORT" "$3" + +# +# Build with TMC drivers using hardware serial +# +restore_configs +opt_set MOTHERBOARD BOARD_ESPRESSIF_ESP32 \ + X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2208 Z_DRIVER_TYPE TMC2209 E0_DRIVER_TYPE TMC2209 \ + X_HARDWARE_SERIAL Serial1 Y_HARDWARE_SERIAL Serial1 Z_HARDWARE_SERIAL Serial1 E0_HARDWARE_SERIAL Serial1 \ + X_SLAVE_ADDRESS 0 Y_SLAVE_ADDRESS 1 Z_SLAVE_ADDRESS 2 E0_SLAVE_ADDRESS 3 +opt_enable HOTEND_IDLE_TIMEOUT SOFTWARE_DRIVER_ENABLE +exec_test $1 $2 "ESP32, TMC HW Serial, Hotend Idle" "$3" + +# cleanup +restore_configs diff --git a/buildroot/tests/esp32-tests b/buildroot/tests/esp32-tests deleted file mode 100755 index 310eea298e11..000000000000 --- a/buildroot/tests/esp32-tests +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# -# Build tests for ESP32 -# - -# exit on first failure -set -e - -# -# Build with the default configurations -# -restore_configs -opt_set MOTHERBOARD BOARD_ESPRESSIF_ESP32 -opt_enable WIFISUPPORT WEBSUPPORT GCODE_MACROS BAUD_RATE_GCODE M115_GEOMETRY_REPORT REPETIER_GCODE_M360 -opt_add WIFI_SSID "\"ssid\"" -opt_add WIFI_PWD "\"password\"" -opt_set TX_BUFFER_SIZE 64 -exec_test $1 $2 "ESP32 with WIFISUPPORT and WEBSUPPORT" "$3" - -# -# Build with TMC drivers using hardware serial -# -restore_configs -opt_set MOTHERBOARD BOARD_ESPRESSIF_ESP32 -opt_set X_DRIVER_TYPE TMC2209 -opt_set Y_DRIVER_TYPE TMC2208 -opt_set Z_DRIVER_TYPE TMC2209 -opt_set E0_DRIVER_TYPE TMC2209 -opt_set X_HARDWARE_SERIAL Serial1 -opt_set Y_HARDWARE_SERIAL Serial1 -opt_set Z_HARDWARE_SERIAL Serial1 -opt_set E0_HARDWARE_SERIAL Serial1 -opt_set X_SLAVE_ADDRESS 0 -opt_set Y_SLAVE_ADDRESS 1 -opt_set Z_SLAVE_ADDRESS 2 -opt_set E0_SLAVE_ADDRESS 3 -opt_enable HOTEND_IDLE_TIMEOUT SOFTWARE_DRIVER_ENABLE -exec_test $1 $2 "ESP32, TMC HW Serial, Hotend Idle" "$3" - -# cleanup -restore_configs diff --git a/buildroot/tests/jgaurora_a5s_a1-tests b/buildroot/tests/jgaurora_a5s_a1 similarity index 100% rename from buildroot/tests/jgaurora_a5s_a1-tests rename to buildroot/tests/jgaurora_a5s_a1 diff --git a/buildroot/tests/linux_native-tests b/buildroot/tests/linux_native similarity index 80% rename from buildroot/tests/linux_native-tests rename to buildroot/tests/linux_native index 711691fb9d83..0153687eacb7 100755 --- a/buildroot/tests/linux_native-tests +++ b/buildroot/tests/linux_native @@ -10,8 +10,7 @@ set -e # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_LINUX_RAMPS -opt_set TEMP_SENSOR_BED 1 +opt_set MOTHERBOARD BOARD_LINUX_RAMPS TEMP_SENSOR_BED 1 opt_enable PIDTEMPBED EEPROM_SETTINGS BAUD_RATE_GCODE exec_test $1 $2 "Linux with EEPROM" "$3" diff --git a/buildroot/tests/malyan_M300-tests b/buildroot/tests/malyan_M300 similarity index 100% rename from buildroot/tests/malyan_M300-tests rename to buildroot/tests/malyan_M300 diff --git a/buildroot/tests/mega1280-tests b/buildroot/tests/mega1280 similarity index 80% rename from buildroot/tests/mega1280-tests rename to buildroot/tests/mega1280 index ac1b5f692d89..8b16b1dbc822 100755 --- a/buildroot/tests/mega1280-tests +++ b/buildroot/tests/mega1280 @@ -16,30 +16,26 @@ set -e # Test MESH_BED_LEVELING feature, with LCD # restore_configs -opt_set LCD_LANGUAGE an +opt_set LCD_LANGUAGE an \ + POWER_MONITOR_CURRENT_PIN 14 POWER_MONITOR_VOLTAGE_PIN 15 \ + CLOSED_LOOP_ENABLE_PIN 44 CLOSED_LOOP_MOVE_COMPLETE_PIN 45 opt_enable SPINDLE_FEATURE ULTIMAKERCONTROLLER LCD_BED_LEVELING \ EEPROM_SETTINGS EEPROM_BOOT_SILENT EEPROM_AUTO_INIT \ SENSORLESS_BACKOFF_MM HOMING_BACKOFF_POST_MM HOME_Y_BEFORE_X CODEPENDENT_XY_HOMING \ MESH_BED_LEVELING ENABLE_LEVELING_FADE_HEIGHT MESH_G28_REST_ORIGIN \ G26_MESH_VALIDATION MESH_EDIT_MENU GCODE_QUOTED_STRINGS \ EXTERNAL_CLOSED_LOOP_CONTROLLER POWER_MONITOR_CURRENT POWER_MONITOR_VOLTAGE -opt_set POWER_MONITOR_CURRENT_PIN 14 -opt_set POWER_MONITOR_VOLTAGE_PIN 15 -opt_set CLOSED_LOOP_ENABLE_PIN 44 -opt_set CLOSED_LOOP_MOVE_COMPLETE_PIN 45 exec_test $1 $2 "Spindle, MESH_BED_LEVELING, closed loop, Power Monitor, and LCD" "$3" # # Test DUAL_X_CARRIAGE # restore_configs -opt_set MOTHERBOARD BOARD_TT_OSCAR -opt_set LCD_LANGUAGE pt -opt_set EXTRUDERS 2 -opt_set TEMP_SENSOR_1 1 +opt_set MOTHERBOARD BOARD_ZRIB_V52 \ + LCD_LANGUAGE pt REPRAPWORLD_KEYPAD_MOVE_STEP 10.0 \ + EXTRUDERS 2 TEMP_SENSOR_1 1 opt_enable USE_XMAX_PLUG DUAL_X_CARRIAGE REPRAPWORLD_KEYPAD -opt_set REPRAPWORLD_KEYPAD_MOVE_STEP 10.0 -exec_test $1 $2 "TT Oscar | DUAL_X_CARRIAGE" "$3" +exec_test $1 $2 "ZRIB_V52 | DUAL_X_CARRIAGE" "$3" # # Delta Config (generic) + Probeless diff --git a/buildroot/tests/mega2560-tests b/buildroot/tests/mega2560 similarity index 74% rename from buildroot/tests/mega2560-tests rename to buildroot/tests/mega2560 index aef2b8756ac1..d961ab4effe3 100755 --- a/buildroot/tests/mega2560-tests +++ b/buildroot/tests/mega2560 @@ -16,17 +16,10 @@ set -e # Test a probeless build of AUTO_BED_LEVELING_UBL, with lots of extruders # use_example_configs AnimationExample -opt_set SHOW_CUSTOM_BOOTSCREEN -opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO -opt_set LCD_LANGUAGE fr -opt_set EXTRUDERS 5 -opt_set TEMP_SENSOR_1 1 -opt_set TEMP_SENSOR_2 5 -opt_set TEMP_SENSOR_3 20 -opt_set TEMP_SENSOR_4 1000 -opt_set TEMP_SENSOR_BED 1 +opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO LCD_LANGUAGE fr \ + EXTRUDERS 5 TEMP_SENSOR_1 1 TEMP_SENSOR_2 5 TEMP_SENSOR_3 20 TEMP_SENSOR_4 1000 TEMP_SENSOR_BED 1 opt_enable AUTO_BED_LEVELING_UBL RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT SKEW_CORRECTION \ - REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI STATUS_MESSAGE_SCROLLING BOOT_MARLIN_LOGO_SMALL \ + REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI STATUS_MESSAGE_SCROLLING SHOW_CUSTOM_BOOTSCREEN BOOT_MARLIN_LOGO_SMALL \ SDSUPPORT SDCARD_SORT_ALPHA USB_FLASH_DRIVE_SUPPORT AUTO_REPORT_SD_STATUS SCROLL_LONG_FILENAMES CANCEL_OBJECTS SOUND_MENU_ITEM \ EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_USER_MENUS \ MULTI_NOZZLE_DUPLICATION CLASSIC_JERK LIN_ADVANCE EXTRA_LIN_ADVANCE_K QUICK_HOME \ @@ -38,26 +31,18 @@ exec_test $1 $2 "Azteeg X3 Pro | EXTRUDERS 5 | RRDFGSC | UBL | LIN_ADVANCE ..." # Add a Sled Z Probe, use UBL Cartesian moves, use Japanese language # use_example_configs AnimationExample -opt_set SHOW_CUSTOM_BOOTSCREEN -opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO -opt_set LCD_LANGUAGE fr -opt_set EXTRUDERS 5 -opt_set TEMP_SENSOR_1 1 -opt_set TEMP_SENSOR_2 5 -opt_set TEMP_SENSOR_3 20 -opt_set TEMP_SENSOR_4 1000 -opt_set TEMP_SENSOR_BED 1 -opt_enable AUTO_BED_LEVELING_UBL RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT SKEW_CORRECTION \ - REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI STATUS_MESSAGE_SCROLLING BOOT_MARLIN_LOGO_SMALL \ - SDSUPPORT SDCARD_SORT_ALPHA USB_FLASH_DRIVE_SUPPORT SCROLL_LONG_FILENAMES CANCEL_OBJECTS NO_SD_AUTOSTART \ +opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO LCD_LANGUAGE jp_kana \ + EXTRUDERS 5 TEMP_SENSOR_1 1 TEMP_SENSOR_2 5 TEMP_SENSOR_3 20 TEMP_SENSOR_4 1000 TEMP_SENSOR_BED 1 +opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI SHOW_CUSTOM_BOOTSCREEN BOOT_MARLIN_LOGO_SMALL \ + LCD_SET_PROGRESS_MANUALLY PRINT_PROGRESS_SHOW_DECIMALS SHOW_REMAINING_TIME STATUS_MESSAGE_SCROLLING SCROLL_LONG_FILENAMES \ + SDSUPPORT SDCARD_SORT_ALPHA NO_SD_AUTOSTART USB_FLASH_DRIVE_SUPPORT CANCEL_OBJECTS \ + Z_PROBE_SLED AUTO_BED_LEVELING_UBL RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATURE G26_MESH_VALIDATION ENABLE_LEVELING_FADE_HEIGHT \ EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_USER_MENUS \ MULTI_NOZZLE_DUPLICATION CLASSIC_JERK LIN_ADVANCE QUICK_HOME \ - LCD_SET_PROGRESS_MANUALLY PRINT_PROGRESS_SHOW_DECIMALS SHOW_REMAINING_TIME \ - BABYSTEPPING BABYSTEP_XY NANODLP_Z_SYNC I2C_POSITION_ENCODERS M114_DETAIL \ - Z_PROBE_SLED SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE -opt_set LCD_LANGUAGE jp_kana + NANODLP_Z_SYNC I2C_POSITION_ENCODERS M114_DETAIL \ + SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE \ + BABYSTEPPING BABYSTEP_XY BABYSTEP_ZPROBE_OFFSET DOUBLECLICK_FOR_Z_BABYSTEPPING BABYSTEP_HOTEND_Z_OFFSET BABYSTEP_DISPLAY_TOTAL opt_disable SEGMENT_LEVELED_MOVES -opt_enable BABYSTEPPING BABYSTEP_XY BABYSTEP_ZPROBE_OFFSET DOUBLECLICK_FOR_Z_BABYSTEPPING BABYSTEP_HOTEND_Z_OFFSET BABYSTEP_DISPLAY_TOTAL M114_DETAIL exec_test $1 $2 "Azteeg X3 Pro | EXTRUDERS 5 | RRDFGSC | UBL | LIN_ADVANCE | Sled Probe | Skew | JP-Kana | Babystep offsets ..." "$3" @@ -65,25 +50,16 @@ exec_test $1 $2 "Azteeg X3 Pro | EXTRUDERS 5 | RRDFGSC | UBL | LIN_ADVANCE | Sle # 5 runout sensors with distinct states # restore_configs -opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO -opt_set EXTRUDERS 5 -opt_set NUM_SERVOS 1 -opt_set TEMP_SENSOR_1 1 -opt_set TEMP_SENSOR_2 1 -opt_set TEMP_SENSOR_3 1 -opt_set TEMP_SENSOR_4 1 +opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO NUM_SERVOS 1 \ + EXTRUDERS 5 TEMP_SENSOR_1 1 TEMP_SENSOR_2 1 TEMP_SENSOR_3 1 TEMP_SENSOR_4 1 \ + NUM_RUNOUT_SENSORS 5 FIL_RUNOUT2_PIN 44 FIL_RUNOUT3_PIN 45 FIL_RUNOUT4_PIN 46 FIL_RUNOUT5_PIN 47 \ + FIL_RUNOUT3_STATE HIGH opt_enable VIKI2 BOOT_MARLIN_LOGO_ANIMATED SDSUPPORT AUTO_REPORT_SD_STATUS \ Z_PROBE_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE \ EEPROM_SETTINGS EEPROM_CHITCHAT M114_DETAIL \ NO_VOLUMETRICS EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES AUTOTEMP G38_PROBE_TARGET JOYSTICK \ DIRECT_STEPPING DETECT_BROKEN_ENDSTOP \ FILAMENT_RUNOUT_SENSOR NOZZLE_PARK_FEATURE ADVANCED_PAUSE_FEATURE Z_SAFE_HOMING FIL_RUNOUT3_PULLUP -opt_set NUM_RUNOUT_SENSORS 5 -opt_set FIL_RUNOUT2_PIN 44 -opt_set FIL_RUNOUT3_PIN 45 -opt_set FIL_RUNOUT3_STATE HIGH -opt_set FIL_RUNOUT4_PIN 46 -opt_set FIL_RUNOUT5_PIN 47 exec_test $1 $2 "Multiple runout sensors (x5) | Distinct runout states" "$3" @@ -91,21 +67,19 @@ exec_test $1 $2 "Multiple runout sensors (x5) | Distinct runout states" "$3" # Mixing Extruder with 5 steppers, Greek # restore_configs -opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO -opt_set LCD_LANGUAGE el_gr +opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO MIXING_STEPPERS 5 LCD_LANGUAGE ru \ + NUM_RUNOUT_SENSORS E_STEPPERS FIL_RUNOUT2_PIN 16 FIL_RUNOUT3_PIN 17 FIL_RUNOUT4_PIN 4 FIL_RUNOUT5_PIN 5 opt_enable MIXING_EXTRUDER GRADIENT_MIX GRADIENT_VTOOL CR10_STOCKDISPLAY \ - USE_CONTROLLER_FAN CONTROLLER_FAN_EDITABLE CONTROLLER_FAN_IGNORE_Z -opt_set MIXING_STEPPERS 5 -opt_set LCD_LANGUAGE ru + USE_CONTROLLER_FAN CONTROLLER_FAN_EDITABLE CONTROLLER_FAN_IGNORE_Z \ + FILAMENT_RUNOUT_SENSOR ADVANCED_PAUSE_FEATURE NOZZLE_PARK_FEATURE exec_test $1 $2 "Azteeg X3 | Mixing Extruder (x5) | Gradient Mix | Greek" "$3" # # Test SPEAKER with BOARD_BQ_ZUM_MEGA_3D and BQ_LCD_SMART_CONTROLLER # #restore_configs -#opt_set MOTHERBOARD BOARD_BQ_ZUM_MEGA_3D -#opt_set LCD_FEEDBACK_FREQUENCY_DURATION_MS 10 -#opt_set LCD_FEEDBACK_FREQUENCY_HZ 100 +#opt_set MOTHERBOARD BOARD_BQ_ZUM_MEGA_3D \ +# LCD_FEEDBACK_FREQUENCY_DURATION_MS 10 LCD_FEEDBACK_FREQUENCY_HZ 100 #opt_enable BQ_LCD_SMART_CONTROLLER SPEAKER # @@ -147,10 +121,7 @@ exec_test $1 $2 "Azteeg X3 | Mixing Extruder (x5) | Gradient Mix | Greek" "$3" # #restore_configs #opt_enable G3D_PANEL SDSUPPORT SDCARD_SORT_ALPHA STATUS_MESSAGE_SCROLLING SCROLL_LONG_FILENAMES -#opt_set SDSORT_GCODE true -#opt_set SDSORT_USES_RAM true -#opt_set SDSORT_USES_STACK true -#opt_set SDSORT_CACHE_NAMES true +#opt_set SDSORT_GCODE true SDSORT_USES_RAM true SDSORT_USES_STACK true SDSORT_CACHE_NAMES true #exec_test $1 $2 "Stuff" "$3" # # REPRAPWORLD_KEYPAD diff --git a/buildroot/tests/mks_robin-tests b/buildroot/tests/mks_robin similarity index 100% rename from buildroot/tests/mks_robin-tests rename to buildroot/tests/mks_robin diff --git a/buildroot/tests/mks_robin_lite-tests b/buildroot/tests/mks_robin_lite similarity index 65% rename from buildroot/tests/mks_robin_lite-tests rename to buildroot/tests/mks_robin_lite index c4be4f206d2a..49ef0048716b 100755 --- a/buildroot/tests/mks_robin_lite-tests +++ b/buildroot/tests/mks_robin_lite @@ -7,10 +7,8 @@ set -e restore_configs -opt_set MOTHERBOARD BOARD_MKS_ROBIN_LITE -opt_set SERIAL_PORT 1 -opt_enable EEPROM_SETTINGS -opt_enable SDSUPPORT +opt_set MOTHERBOARD BOARD_MKS_ROBIN_LITE SERIAL_PORT 1 +opt_enable EEPROM_SETTINGS SDSUPPORT exec_test $1 $2 "Default Configuration with Fallback SD EEPROM" "$3" # cleanup diff --git a/buildroot/tests/mks_robin_mini-tests b/buildroot/tests/mks_robin_mini similarity index 71% rename from buildroot/tests/mks_robin_mini-tests rename to buildroot/tests/mks_robin_mini index 6675634f3068..29baee8818d6 100755 --- a/buildroot/tests/mks_robin_mini-tests +++ b/buildroot/tests/mks_robin_mini @@ -8,9 +8,7 @@ set -e use_example_configs Mks/Robin -opt_set MOTHERBOARD BOARD_MKS_ROBIN_MINI -opt_set EXTRUDERS 1 -opt_set TEMP_SENSOR_1 0 +opt_set MOTHERBOARD BOARD_MKS_ROBIN_MINI EXTRUDERS 1 TEMP_SENSOR_1 0 exec_test $1 $2 "MKS Robin mini" "$3" # cleanup diff --git a/buildroot/tests/mks_robin_nano35-tests b/buildroot/tests/mks_robin_nano35 similarity index 94% rename from buildroot/tests/mks_robin_nano35-tests rename to buildroot/tests/mks_robin_nano35 index 6e2f9f1b0c32..7ab592aaa3eb 100755 --- a/buildroot/tests/mks_robin_nano35-tests +++ b/buildroot/tests/mks_robin_nano35 @@ -49,11 +49,9 @@ exec_test $1 $2 "MKS Robin v2 nano New Color UI 480x320 SPI" "$3" # (Robin v2 nano has no FSMC interface) # use_example_configs Mks/Robin -opt_set MOTHERBOARD BOARD_MKS_ROBIN_NANO_V2 +opt_set MOTHERBOARD BOARD_MKS_ROBIN_NANO_V2 X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2209 opt_disable TFT_INTERFACE_FSMC TFT_COLOR_UI TOUCH_SCREEN TFT_RES_320x240 opt_enable TFT_INTERFACE_SPI TFT_LVGL_UI TFT_RES_480x320 -opt_set X_DRIVER_TYPE TMC2209 -opt_set Y_DRIVER_TYPE TMC2209 exec_test $1 $2 "MKS Robin v2 nano LVGL SPI + TMC" "$3" # diff --git a/buildroot/tests/mks_robin_nano35_stm32-tests b/buildroot/tests/mks_robin_nano35_stm32 similarity index 94% rename from buildroot/tests/mks_robin_nano35_stm32-tests rename to buildroot/tests/mks_robin_nano35_stm32 index 696fb9406952..08917446927e 100755 --- a/buildroot/tests/mks_robin_nano35_stm32-tests +++ b/buildroot/tests/mks_robin_nano35_stm32 @@ -58,11 +58,9 @@ exec_test $1 $2 "MKS Robin v2 nano New Color UI 480x320 SPI" "$3" # (Robin v2 nano has no FSMC interface) # # use_example_configs Mks/Robin -# opt_set MOTHERBOARD BOARD_MKS_ROBIN_NANO_V2 +# opt_set MOTHERBOARD BOARD_MKS_ROBIN_NANO_V2 X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2209 # opt_disable TFT_INTERFACE_FSMC TFT_COLOR_UI TOUCH_SCREEN TFT_RES_320x240 # opt_enable TFT_INTERFACE_SPI TFT_LVGL_UI TFT_RES_480x320 -# opt_set X_DRIVER_TYPE TMC2209 -# opt_set Y_DRIVER_TYPE TMC2209 # exec_test $1 $2 "MKS Robin v2 nano LVGL SPI + TMC" "$3" # cleanup diff --git a/buildroot/tests/mks_robin_pro-tests b/buildroot/tests/mks_robin_pro similarity index 55% rename from buildroot/tests/mks_robin_pro-tests rename to buildroot/tests/mks_robin_pro index 3503d0ce1f7d..4b38ab97b6bf 100755 --- a/buildroot/tests/mks_robin_pro-tests +++ b/buildroot/tests/mks_robin_pro @@ -8,13 +8,11 @@ set -e use_example_configs Mks/Robin_Pro opt_enable EMERGENCY_PARSER -opt_set SERIAL_PORT 3 -opt_disable SERIAL_PORT_2 -opt_set SDCARD_CONNECTION LCD -opt_set X_DRIVER_TYPE TMC2209 -opt_set Y_DRIVER_TYPE TMC2130 -opt_set TEMP_SENSOR_BED 1 -opt_disable THERMAL_PROTECTION_HOTENDS +opt_set SERIAL_PORT 3 \ + SDCARD_CONNECTION LCD \ + X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2130 \ + TEMP_SENSOR_BED 1 +opt_disable SERIAL_PORT_2 THERMAL_PROTECTION_HOTENDS exec_test $1 $2 "MKS Robin Pro, TMC Drivers, no thermal protection" "$3" # cleanup diff --git a/buildroot/tests/mks_robin_stm32-tests b/buildroot/tests/mks_robin_stm32 similarity index 100% rename from buildroot/tests/mks_robin_stm32-tests rename to buildroot/tests/mks_robin_stm32 diff --git a/buildroot/tests/rambo-tests b/buildroot/tests/rambo similarity index 74% rename from buildroot/tests/rambo-tests rename to buildroot/tests/rambo index d471f4201c80..5da4eed9b419 100755 --- a/buildroot/tests/rambo-tests +++ b/buildroot/tests/rambo @@ -10,21 +10,15 @@ set -e # Lots of options - Formerly the first Mega2560 test # restore_configs -opt_set MOTHERBOARD BOARD_RAMBO -opt_set EXTRUDERS 2 -opt_set TEMP_SENSOR_0 -2 -opt_set TEMP_SENSOR_1 1 -opt_set TEMP_SENSOR_BED 2 -opt_set TEMP_SENSOR_PROBE 1 -opt_add TEMP_PROBE_PIN 12 -opt_set TEMP_SENSOR_CHAMBER 3 -opt_add TEMP_CHAMBER_PIN 3 -opt_add HEATER_CHAMBER_PIN 45 -opt_set GRID_MAX_POINTS_X 16 -opt_set FANMUX0_PIN 53 -opt_disable USE_WATCHDOG -opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_PROGRESS_BAR_TEST \ - FIX_MOUNTED_PROBE Z_SAFE_HOMING CODEPENDENT_XY_HOMING PIDTEMPBED PROBE_TEMP_COMPENSATION \ +opt_set MOTHERBOARD BOARD_RAMBO \ + EXTRUDERS 2 TEMP_SENSOR_0 -2 TEMP_SENSOR_1 1 TEMP_SENSOR_BED 2 \ + TEMP_SENSOR_PROBE 1 TEMP_PROBE_PIN 12 \ + TEMP_SENSOR_CHAMBER 3 TEMP_CHAMBER_PIN 3 HEATER_CHAMBER_PIN 45 \ + Z_HOME_DIR 1 GRID_MAX_POINTS_X 16 \ + FANMUX0_PIN 53 +opt_disable USE_ZMIN_PLUG Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN USE_WATCHDOG +opt_enable USE_ZMAX_PLUG REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_PROGRESS_BAR_TEST \ + FIX_MOUNTED_PROBE CODEPENDENT_XY_HOMING PIDTEMPBED PROBE_TEMP_COMPENSATION \ PREHEAT_BEFORE_PROBING PROBING_HEATERS_OFF PROBING_FANS_OFF PROBING_STEPPERS_OFF WAIT_FOR_BED_HEATER \ EEPROM_SETTINGS SDSUPPORT SD_REPRINT_LAST_SELECTED_FILE BINARY_FILE_TRANSFER \ BLINKM PCA9533 PCA9632 RGB_LED RGB_LED_R_PIN RGB_LED_G_PIN RGB_LED_B_PIN LED_CONTROL_MENU \ @@ -38,7 +32,7 @@ opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_PROGRESS_BAR_TE SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE \ BACKLASH_COMPENSATION BACKLASH_GCODE BAUD_RATE_GCODE BEZIER_CURVE_SUPPORT \ FWRETRACT ARC_P_CIRCLES CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS \ - PSU_CONTROL AUTO_POWER_CONTROL POWER_LOSS_RECOVERY POWER_LOSS_PIN POWER_LOSS_STATE \ + PSU_CONTROL AUTO_POWER_CONTROL POWER_LOSS_RECOVERY POWER_LOSS_PIN POWER_LOSS_STATE POWER_LOSS_RECOVER_ZHOME \ SLOW_PWM_HEATERS THERMAL_PROTECTION_CHAMBER LIN_ADVANCE EXTRA_LIN_ADVANCE_K \ HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT PINS_DEBUGGING MAX7219_DEBUG M114_DETAIL opt_add DEBUG_POWER_LOSS_RECOVERY @@ -48,12 +42,10 @@ exec_test $1 $2 "RAMBO | EXTRUDERS 2 | CHAR LCD + SD | FIX Probe | ABL-Linear | # Full size Rambo Dual Endstop CNC # restore_configs -opt_set MOTHERBOARD BOARD_RAMBO -opt_set EXTRUDERS 0 -opt_set TEMP_SENSOR_0 999 -opt_set DUMMY_THERMISTOR_999_VALUE 170 -opt_set DIGIPOT_MOTOR_CURRENT '{ 120, 120, 120, 120, 120 }' -opt_set LEVEL_CORNERS_LEVELING_ORDER '{ LF, RF }' +opt_set MOTHERBOARD BOARD_RAMBO \ + EXTRUDERS 0 TEMP_SENSOR_0 999 DUMMY_THERMISTOR_999_VALUE 170 \ + DIGIPOT_MOTOR_CURRENT '{ 120, 120, 120, 120, 120 }' \ + LEVEL_CORNERS_LEVELING_ORDER '{ LF, RF }' opt_enable USE_XMAX_PLUG USE_YMAX_PLUG USE_ZMAX_PLUG \ REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER REVERSE_ENCODER_DIRECTION SDSUPPORT EEPROM_SETTINGS \ S_CURVE_ACCELERATION X_DUAL_STEPPER_DRIVERS X_DUAL_ENDSTOPS Y_DUAL_STEPPER_DRIVERS Y_DUAL_ENDSTOPS \ @@ -66,9 +58,7 @@ exec_test $1 $2 "Rambo CNC Configuration" "$3" # Rambo heated bed only # restore_configs -opt_set MOTHERBOARD BOARD_RAMBO -opt_set EXTRUDERS 0 -opt_set TEMP_SENSOR_BED 1 +opt_set MOTHERBOARD BOARD_RAMBO EXTRUDERS 0 TEMP_SENSOR_BED 1 opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER exec_test $1 $2 "Rambo heated bed only" "$3" @@ -76,18 +66,18 @@ exec_test $1 $2 "Rambo heated bed only" "$3" # Build with the default configurations # restore_configs -opt_set MOTHERBOARD BOARD_EINSY_RAMBO -opt_set X_DRIVER_TYPE TMC2130 -opt_set Y_DRIVER_TYPE TMC2130 -opt_set Z_DRIVER_TYPE TMC2130 -opt_set E0_DRIVER_TYPE TMC2130 +opt_set MOTHERBOARD BOARD_EINSY_RAMBO \ + X_DRIVER_TYPE TMC2130 Y_DRIVER_TYPE TMC2130 Z_DRIVER_TYPE TMC2130 E0_DRIVER_TYPE TMC2130 exec_test $1 $2 "Einsy RAMBo with TMC2130" "$3" # # Test MINIRAMBO with PWM_MOTOR_CURRENT and many features # restore_configs -opt_set MOTHERBOARD BOARD_MINIRAMBO +opt_set MOTHERBOARD BOARD_MINIRAMBO \ + CONTROLLERFAN_SPEED_IDLE 128 \ + PWM_MOTOR_CURRENT '{ 1300, 1300, 1250 }' \ + I2C_SLAVE_ADDRESS 63 opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER \ SDSUPPORT PCA9632 SOUND_MENU_ITEM GCODE_REPEAT_MARKERS \ AUTO_BED_LEVELING_BILINEAR PROBE_MANUALLY LCD_BED_LEVELING G26_MESH_VALIDATION MESH_EDIT_MENU \ @@ -96,23 +86,23 @@ opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CO NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE \ ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE ADVANCED_PAUSE_CONTINUOUS_PURGE FILAMENT_LOAD_UNLOAD_GCODES \ PRINTCOUNTER SERVICE_NAME_1 SERVICE_INTERVAL_1 M114_DETAIL -opt_set CONTROLLERFAN_SPEED_IDLE 128 opt_add M100_FREE_MEMORY_DUMPER opt_add M100_FREE_MEMORY_CORRUPTOR -opt_set PWM_MOTOR_CURRENT "{ 1300, 1300, 1250 }" -opt_set I2C_SLAVE_ADDRESS 63 exec_test $1 $2 "MINIRAMBO | RRDGFSC | M100 | PWM_MOTOR_CURRENT | PRINTCOUNTER | Advanced Pause ..." "$3" # # Test many less common options # restore_configs -opt_set MOTHERBOARD BOARD_RAMBO -opt_set TEMP_SENSOR_0 -2 -opt_set DIGIPOT_I2C_NUM_CHANNELS 5 -opt_set LCD_LANGUAGE it -opt_set MIXING_STEPPERS 2 -opt_set SERVO_DELAY "{ 300, 300, 300 }" +opt_set MOTHERBOARD BOARD_RAMBO \ + TEMP_SENSOR_0 -2 \ + DIGIPOT_I2C_NUM_CHANNELS 5 \ + LCD_LANGUAGE it \ + MIXING_STEPPERS 2 \ + SERVO_DELAY '{ 300, 300, 300 }' \ + CONTROLLER_FAN_PIN X_MAX_PIN FILWIDTH_PIN 5 \ + FAN_MIN_PWM 50 FAN_KICKSTART_TIME 100 \ + XY_FREQUENCY_LIMIT 15 opt_enable COREYX USE_XMAX_PLUG MIXING_EXTRUDER GRADIENT_MIX \ BABYSTEPPING BABYSTEP_DISPLAY_TOTAL FILAMENT_LCD_DISPLAY \ REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER MENU_ADDAUTOSTART SDSUPPORT SDCARD_SORT_ALPHA \ @@ -122,11 +112,6 @@ opt_enable COREYX USE_XMAX_PLUG MIXING_EXTRUDER GRADIENT_MIX \ SD_ABORT_ON_ENDSTOP_HIT HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT ADVANCED_OK M114_DETAIL \ VOLUMETRIC_DEFAULT_ON NO_WORKSPACE_OFFSETS EXTRA_FAN_SPEED FWRETRACT \ USE_CONTROLLER_FAN CONTROLLER_FAN_EDITABLE CONTROLLER_FAN_USE_Z_ONLY -opt_set CONTROLLER_FAN_PIN X_MAX_PIN -opt_set FAN_MIN_PWM 50 -opt_set FAN_KICKSTART_TIME 100 -opt_set XY_FREQUENCY_LIMIT 15 -opt_add FILWIDTH_PIN 5 exec_test $1 $2 "Rambo | CoreXY, Gradient Mix | Endstop Int. | Home Y > X | FW Retract ..." "$3" # clean up diff --git a/buildroot/tests/rumba32-tests b/buildroot/tests/rumba32 similarity index 63% rename from buildroot/tests/rumba32-tests rename to buildroot/tests/rumba32 index 20a640efed46..f26af33610c6 100755 --- a/buildroot/tests/rumba32-tests +++ b/buildroot/tests/rumba32 @@ -8,31 +8,23 @@ set -e # Build examples restore_configs -opt_set MOTHERBOARD BOARD_RUMBA32_V1_0 -opt_set SERIAL_PORT -1 +opt_set MOTHERBOARD BOARD_RUMBA32_V1_0 SERIAL_PORT -1 \ + TEMP_SENSOR_BED 1 X_DRIVER_TYPE TMC2130 opt_disable PIDTEMP opt_enable PIDTEMPBED -opt_set TEMP_SENSOR_BED 1 opt_disable THERMAL_PROTECTION_BED -opt_set X_DRIVER_TYPE TMC2130 exec_test $1 $2 "RUMBA32 V1.0 with TMC2130, PID Bed, and bed thermal protection disabled" "$3" # Build examples restore_configs -opt_set MOTHERBOARD BOARD_RUMBA32_V1_1 -opt_set SERIAL_PORT -1 +opt_set MOTHERBOARD BOARD_RUMBA32_V1_1 SERIAL_PORT -1 \ + TEMP_SENSOR_BED 1 X_DRIVER_TYPE TMC2130 Y_DRIVER_TYPE TMC2208 opt_enable PIDTEMPBED EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER -opt_set TEMP_SENSOR_BED 1 -opt_set X_DRIVER_TYPE TMC2130 -opt_set Y_DRIVER_TYPE TMC2208 exec_test $1 $2 "RUMBA32 V1.1 with TMC2130, TMC2208, PID Bed, EEPROM settings, and graphic LCD controller" "$3" # Build examples restore_configs -opt_set MOTHERBOARD BOARD_RUMBA32_MKS -opt_set SERIAL_PORT -1 -opt_set X_DRIVER_TYPE TMC2130 -opt_set Y_DRIVER_TYPE TMC2208 +opt_set MOTHERBOARD BOARD_RUMBA32_MKS SERIAL_PORT -1 X_DRIVER_TYPE TMC2130 Y_DRIVER_TYPE TMC2208 exec_test $1 $2 "RUMBA32 MKS Default Config with Mixed TMC Drivers" "$3" # cleanup diff --git a/buildroot/tests/sanguino1284p-tests b/buildroot/tests/sanguino1284p similarity index 83% rename from buildroot/tests/sanguino1284p-tests rename to buildroot/tests/sanguino1284p index 55cdf418da98..7c2aa61f69be 100755 --- a/buildroot/tests/sanguino1284p-tests +++ b/buildroot/tests/sanguino1284p @@ -10,10 +10,10 @@ set -e # Start with default configurations... # restore_configs -opt_set MOTHERBOARD BOARD_SANGUINOLOLU_12 -opt_set LCD_LANGUAGE de +opt_set MOTHERBOARD BOARD_SANGUINOLOLU_12 \ + LCD_LANGUAGE de \ + CONTROLLER_FAN_PIN 27 opt_enable MINIPANEL USE_CONTROLLER_FAN CONTROLLER_FAN_EDITABLE -opt_set CONTROLLER_FAN_PIN 27 exec_test $1 $2 "Default Configuration | MINIPANAL | CONTROLLER_FAN" "$3" # diff --git a/buildroot/tests/sanguino644p-tests b/buildroot/tests/sanguino644p similarity index 100% rename from buildroot/tests/sanguino644p-tests rename to buildroot/tests/sanguino644p diff --git a/buildroot/tests/teensy31-tests b/buildroot/tests/teensy31 similarity index 78% rename from buildroot/tests/teensy31-tests rename to buildroot/tests/teensy31 index 448a8860c7a0..10dde2be99ad 100755 --- a/buildroot/tests/teensy31-tests +++ b/buildroot/tests/teensy31 @@ -11,12 +11,21 @@ opt_set MOTHERBOARD BOARD_TEENSY31_32 exec_test $1 $2 "Teensy3.1 with default config" "$3" # -# Test many features together +# Zero endstops, as with a CNC # restore_configs opt_set MOTHERBOARD BOARD_TEENSY31_32 -opt_set TEMP_SENSOR_0 1 -opt_set TEMP_SENSOR_BED 1 +opt_disable USE_XMIN_PLUG USE_YMIN_PLUG USE_ZMIN_PLUG +exec_test $1 $2 "Teensy3.1 with Zero Endstops" "$3" + +# +# Test many features together +# +restore_configs +opt_set MOTHERBOARD BOARD_TEENSY31_32 \ + TEMP_SENSOR_0 1 TEMP_SENSOR_BED 1 \ + I2C_SLAVE_ADDRESS 63 \ + GRID_MAX_POINTS_X 16 opt_enable EEPROM_SETTINGS FILAMENT_WIDTH_SENSOR CALIBRATION_GCODE BAUD_RATE_GCODE \ FIX_MOUNTED_PROBE Z_SAFE_HOMING AUTO_BED_LEVELING_BILINEAR DEBUG_LEVELING_FEATURE Z_MIN_PROBE_REPEATABILITY_TEST \ BABYSTEPPING BABYSTEP_XY BABYSTEP_ZPROBE_OFFSET PRINTCOUNTER SLOW_PWM_HEATERS PIDTEMPBED \ @@ -25,6 +34,4 @@ opt_enable EEPROM_SETTINGS FILAMENT_WIDTH_SENSOR CALIBRATION_GCODE BAUD_RATE_GCO ARC_SUPPORT BEZIER_CURVE_SUPPORT EXPERIMENTAL_I2CBUS EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES \ PHOTO_GCODE PHOTO_POSITION PHOTO_SWITCH_POSITION PHOTO_SWITCH_MS PHOTO_DELAY_MS PHOTO_RETRACT_MM \ HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT -opt_set I2C_SLAVE_ADDRESS 63 -opt_set GRID_MAX_POINTS_X 16 exec_test $1 $2 "Teensy3.1 with many features" "$3" diff --git a/buildroot/tests/teensy35-tests b/buildroot/tests/teensy35 similarity index 75% rename from buildroot/tests/teensy35-tests rename to buildroot/tests/teensy35 index 79998a26d33e..c9731665c533 100755 --- a/buildroot/tests/teensy35-tests +++ b/buildroot/tests/teensy35 @@ -14,11 +14,10 @@ exec_test $1 $2 "Teensy3.5 with default config" "$3" # Test as many features together as possible # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY35_36 -opt_set EXTRUDERS 2 -opt_set TEMP_SENSOR_0 1 -opt_set TEMP_SENSOR_1 5 -opt_set TEMP_SENSOR_BED 1 +opt_set MOTHERBOARD BOARD_TEENSY35_36 \ + EXTRUDERS 2 TEMP_SENSOR_0 1 TEMP_SENSOR_1 5 TEMP_SENSOR_BED 1 \ + I2C_SLAVE_ADDRESS 63 \ + GRID_MAX_POINTS_X 16 opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LCD_INFO_MENU SDSUPPORT SDCARD_SORT_ALPHA \ FILAMENT_WIDTH_SENSOR FILAMENT_LCD_DISPLAY CALIBRATION_GCODE BAUD_RATE_GCODE SOUND_MENU_ITEM \ FIX_MOUNTED_PROBE Z_SAFE_HOMING AUTO_BED_LEVELING_BILINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \ @@ -27,8 +26,6 @@ opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LCD_INFO_MENU SDSUPPORT ADVANCED_PAUSE_FEATURE ARC_SUPPORT BEZIER_CURVE_SUPPORT EXPERIMENTAL_I2CBUS EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES PARK_HEAD_ON_PAUSE \ PHOTO_GCODE PHOTO_POSITION PHOTO_SWITCH_POSITION PHOTO_SWITCH_MS PHOTO_DELAY_MS PHOTO_RETRACT_MM \ HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT -opt_set I2C_SLAVE_ADDRESS 63 -opt_set GRID_MAX_POINTS_X 16 exec_test $1 $2 "Teensy3.5 with many features" "$3" # @@ -43,10 +40,9 @@ exec_test $1 $2 "Sled Z Probe with Linear leveling" "$3" # Test a Servo Probe # # restore_configs -# opt_set MOTHERBOARD BOARD_TEENSY35_36 +# opt_set MOTHERBOARD BOARD_TEENSY35_36 NUM_SERVOS 1 # opt_enable Z_PROBE_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE \ # AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE EEPROM_SETTINGS -# opt_set NUM_SERVOS 1 # exec_test $1 $2 "Servo Probe" # # ...with AUTO_BED_LEVELING_3POINT, DEBUG_LEVELING_FEATURE, EEPROM_SETTINGS, EEPROM_CHITCHAT, EXTENDED_CAPABILITIES_REPORT, and AUTO_REPORT_TEMPERATURES @@ -59,28 +55,23 @@ exec_test $1 $2 "Sled Z Probe with Linear leveling" "$3" # Test MAGNETIC_PARKING_EXTRUDER with LCD # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY35_36 -opt_set EXTRUDERS 2 -opt_set TEMP_SENSOR_1 1 -opt_enable MAGNETIC_PARKING_EXTRUDER ULTIMAKERCONTROLLER -exec_test $1 $2 "MAGNETIC_PARKING_EXTRUDER with LCD" "$3" +opt_set MOTHERBOARD BOARD_TEENSY35_36 EXTRUDERS 2 TEMP_SENSOR_1 1 SOL0_PIN 29 EXTRUDERS 2 +opt_enable PARKING_EXTRUDER ULTIMAKERCONTROLLER +exec_test $1 $2 "PARKING_EXTRUDER with LCD" "$3" # # Mixing Extruder # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY35_36 +opt_set MOTHERBOARD BOARD_TEENSY35_36 MIXING_STEPPERS 2 opt_enable MIXING_EXTRUDER DIRECT_MIXING_IN_G1 GRADIENT_MIX GRADIENT_VTOOL REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER -opt_set MIXING_STEPPERS 2 exec_test $1 $2 "Mixing Extruder" "$3" # # Test SWITCHING_EXTRUDER # # restore_configs -# opt_set MOTHERBOARD BOARD_TEENSY35_36 -# opt_set EXTRUDERS 2 -# opt_set NUM_SERVOS 1 +# opt_set MOTHERBOARD BOARD_TEENSY35_36 EXTRUDERS 2 NUM_SERVOS 1 # opt_enable SWITCHING_EXTRUDER ULTIMAKERCONTROLLER # exec_test $1 $2 "SWITCHING_EXTRUDER" @@ -88,15 +79,11 @@ exec_test $1 $2 "Mixing Extruder" "$3" # Enable COREXY # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY35_36 -opt_enable COREXY -opt_set X_DRIVER_TYPE TMC5160 -opt_set Y_DRIVER_TYPE TMC5160 -opt_set X_MIN_ENDSTOP_INVERTING true -opt_set Y_MIN_ENDSTOP_INVERTING true -opt_add X_CS_PIN 46 -opt_add Y_CS_PIN 47 -opt_enable USE_ZMIN_PLUG MONITOR_DRIVER_STATUS SENSORLESS_HOMING +opt_set MOTHERBOARD BOARD_TEENSY35_36 \ + X_DRIVER_TYPE TMC5160 Y_DRIVER_TYPE TMC5160 \ + X_MIN_ENDSTOP_INVERTING true Y_MIN_ENDSTOP_INVERTING true \ + X_CS_PIN 46 Y_CS_PIN 47 +opt_enable COREXY USE_ZMIN_PLUG MONITOR_DRIVER_STATUS SENSORLESS_HOMING exec_test $1 $2 "Teensy 3.5/3.6 COREXY" "$3" # @@ -111,11 +98,9 @@ exec_test $1 $2 "Teensy 3.5/3.6 COREXZ" "$3" # Enable Dual Z with Dual Z endstops # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY35_36 -opt_set NUM_Z_STEPPER_DRIVERS 2 +opt_set MOTHERBOARD BOARD_TEENSY35_36 NUM_Z_STEPPER_DRIVERS 2 Z2_MAX_PIN 2 opt_enable Z_MULTI_ENDSTOPS USE_XMAX_PLUG pins_set ramps/RAMPS X_MAX_PIN -1 -opt_add Z2_MAX_PIN 2 exec_test $1 $2 "Dual Z with Dual Z endstops" "$3" # Clean up diff --git a/buildroot/tests/teensy41-tests b/buildroot/tests/teensy41 similarity index 79% rename from buildroot/tests/teensy41-tests rename to buildroot/tests/teensy41 index 6829045496c0..6074b5dc5ff6 100755 --- a/buildroot/tests/teensy41-tests +++ b/buildroot/tests/teensy41 @@ -14,11 +14,10 @@ exec_test $1 $2 "Teensy4.1 with default config" "$3" # Test as many features together as possible # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY41 -opt_set EXTRUDERS 2 -opt_set TEMP_SENSOR_0 1 -opt_set TEMP_SENSOR_1 5 -opt_set TEMP_SENSOR_BED 1 +opt_set MOTHERBOARD BOARD_TEENSY41 \ + EXTRUDERS 2 TEMP_SENSOR_0 1 TEMP_SENSOR_1 5 TEMP_SENSOR_BED 1 \ + I2C_SLAVE_ADDRESS 63 \ + GRID_MAX_POINTS_X 16 opt_enable EXTENSIBLE_UI LCD_INFO_MENU SDSUPPORT SDCARD_SORT_ALPHA \ FILAMENT_LCD_DISPLAY CALIBRATION_GCODE BAUD_RATE_GCODE \ FIX_MOUNTED_PROBE Z_SAFE_HOMING AUTO_BED_LEVELING_BILINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \ @@ -28,8 +27,6 @@ opt_enable EXTENSIBLE_UI LCD_INFO_MENU SDSUPPORT SDCARD_SORT_ALPHA \ PHOTO_GCODE PHOTO_POSITION PHOTO_SWITCH_POSITION PHOTO_SWITCH_MS PHOTO_DELAY_MS PHOTO_RETRACT_MM \ HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT opt_add EXTUI_EXAMPLE -opt_set I2C_SLAVE_ADDRESS 63 -opt_set GRID_MAX_POINTS_X 16 exec_test $1 $2 "Teensy4.1 with many features" "$3" # @@ -60,10 +57,8 @@ exec_test $1 $2 "Sled Z Probe with Linear leveling" "$3" # Test MAGNETIC_PARKING_EXTRUDER with no LCD # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY41 -opt_set EXTRUDERS 2 -opt_set TEMP_SENSOR_1 1 -opt_set SERIAL_PORT_2 -2 +opt_set MOTHERBOARD BOARD_TEENSY41 SERIAL_PORT_2 -2 \ + EXTRUDERS 2 TEMP_SENSOR_1 1 opt_enable EEPROM_SETTINGS MAGNETIC_PARKING_EXTRUDER exec_test $1 $2 "Ethernet, EEPROM, Magnetic Parking Extruder, No LCD" "$3" @@ -71,18 +66,15 @@ exec_test $1 $2 "Ethernet, EEPROM, Magnetic Parking Extruder, No LCD" "$3" # Mixing Extruder # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY41 +opt_set MOTHERBOARD BOARD_TEENSY41 MIXING_STEPPERS 2 opt_enable MIXING_EXTRUDER DIRECT_MIXING_IN_G1 GRADIENT_MIX GRADIENT_VTOOL -opt_set MIXING_STEPPERS 2 exec_test $1 $2 "Mixing Extruder" "$3" # # Test SWITCHING_EXTRUDER # # restore_configs -# opt_set MOTHERBOARD BOARD_TEENSY41 -# opt_set EXTRUDERS 2 -# opt_set NUM_SERVOS 1 +# opt_set MOTHERBOARD BOARD_TEENSY41 EXTRUDERS 2 NUM_SERVOS 1 # opt_enable SWITCHING_EXTRUDER ULTIMAKERCONTROLLER # exec_test $1 $2 "SWITCHING_EXTRUDER" "$3" @@ -90,15 +82,11 @@ exec_test $1 $2 "Mixing Extruder" "$3" # Enable COREXY # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY41 -opt_enable COREXY -opt_set X_DRIVER_TYPE TMC5160 -opt_set Y_DRIVER_TYPE TMC5160 -opt_set X_MIN_ENDSTOP_INVERTING true -opt_set Y_MIN_ENDSTOP_INVERTING true -opt_add X_CS_PIN 46 -opt_add Y_CS_PIN 47 -opt_enable USE_ZMIN_PLUG MONITOR_DRIVER_STATUS SENSORLESS_HOMING +opt_set MOTHERBOARD BOARD_TEENSY41 \ + X_DRIVER_TYPE TMC5160 Y_DRIVER_TYPE TMC5160 \ + X_MIN_ENDSTOP_INVERTING true Y_MIN_ENDSTOP_INVERTING true \ + X_CS_PIN 46 Y_CS_PIN 47 +opt_enable COREXY USE_ZMIN_PLUG MONITOR_DRIVER_STATUS SENSORLESS_HOMING exec_test $1 $2 "Teensy 4.0/4.1 COREXY" "$3" # @@ -113,11 +101,9 @@ exec_test $1 $2 "Teensy 4.0/4.1 COREXZ" "$3" # Enable Dual Z with Dual Z endstops # restore_configs -opt_set MOTHERBOARD BOARD_TEENSY41 +opt_set MOTHERBOARD BOARD_TEENSY41 NUM_Z_STEPPER_DRIVERS 2 Z2_MAX_PIN 2 opt_enable Z_MULTI_ENDSTOPS USE_XMAX_PLUG -opt_set NUM_Z_STEPPER_DRIVERS 2 pins_set ramps/RAMPS X_MAX_PIN -1 -opt_add Z2_MAX_PIN 2 exec_test $1 $2 "Dual Z with Dual Z endstops" "$3" # Clean up diff --git a/docs/Queue.md b/docs/Queue.md new file mode 100644 index 000000000000..bce68b0551a7 --- /dev/null +++ b/docs/Queue.md @@ -0,0 +1,59 @@ +# Marlin's command queue concept + +Marlin Firmware processes G-code commands as they arrive from multiple sources, including the SD card and one or more serial ports such as USB-connected hosts, WiFi, Bluetooth, and so on. + +Marlin is also continuously processing the commands at the front of the queue, converting them into signals for many physical actuators such as motors, heaters, lasers, and RGB LEDs. + +The firmware needs to maintain continuity and timing so the command senders remain unblocked, while still performing physical movements and other actions in real-time, respecting the physical limits of stepper motors and other peripherals. + +To keep things flowing Marlin feeds a single queue of G-code commands from all inputs, inserting them in the order received. Movement commands immediately go into the Planner Buffer, if there is room. The buffering of a move is considered the completion of the command, so if a non-movement command has to occur after a move is done, and not just after a move is buffered, then there has to be an `M400` to wait for the Planner Buffer to finish. + +Whenever the command queue gets full the sender needs to wait for space to open up, and the host may need to re-send the last command again. Marlin does some handshaking to keep the host informed during a print job, described below. + +An opposite problem called "planner starvation" occurs when Marlin receives many short and fast moves in a row so the Planner Buffer gets completed very quickly. In this case the host can't send commands fast enough to prevent the Planner Buffer from emptying out. Planner starvation causes obvious stuttering and is commonly seen on overloaded deltabots during small curves. Marlin has strategies to mitigate this issue, but sometimes a model has to be re-sliced (or the G-code has to be post-processed with Arc Welder) just to stay within the machine's inherent limits. + +Here's a basic flowchart of Marlin command processing: +``` ++------+ Marlin's GCodeQueue +| | +--------------------------------------+ +-----------+ +| Host | | SerialState RingBuffer | | | +| | Marlin | NUM_SERIAL BUF_SIZE | | Marlin | ++--+---+ R/TX_BUFFER_SIZE | +---+ +------------------+ | | | + | +------------+ | | | | | | | GCode | + | | | | | | | MAX_CMD_SIZE +-+-----> processor | + | | Platform | | | | On EOL | +--------------+ | r_pos | | + +-------------> serial's +-----------> +--------> | G-code | | | +-----------+ + | buffer | | | | w_pos | | command | | | + | | | | | | | line | | | + +------------+ | +---+ | +--------------+ | | + | Line buffer | x BUF_SIZE | | + | | | | + | | | | + | | | | + | | | | + | +------------------+ | + | | + | | + | | + +--------------------------------------+ +``` + +Marlin is a single-threaded application with a main `loop()` that manages the command queue and an `idle()` routine that manages the hardware. The command queue is handled in two stages: +1. The `idle()` routine reads all inputs and attempts to enqueue any completed command lines. +2. The main `loop()` gets the command at the front the G-code queue (if any) and runs it. Each G-code command blocks the main loop, preventing the queue from advancing until it returns. To keep essential tasks and the UI running, any commands that run a long process need to call `idle()` frequently. + +## Synchronization + +To maintain synchronization Marlin replies "`ok`" to the host as soon as the command has been enqueued. This lets the host know that it can send another command, and well-behaved hosts will wait for this message. With `ADVANCED_OK` enabled the `ok` message includes extra information (such as the number of slots left in the queue). + +If no data is available on the serial buffer, Marlin can be configured to periodically send a "`wait`" message to the host. This was the only method of "host keepalive" provided in Marlin 1.0, but today the better options are `HOST_KEEPALIVE` and `ADVANCED_OK`. + +## Limitation of the design + +Some limitations to the design are evident: +1. Whenever the G-code processor is busy processing a command, the G-code queue cannot advance. +2. A long command like `G29` causes commands to pile up and to fill the queue, making the host wait. +3. Each serial input requires a buffer large enough for a complete G-code line. This is set by `MAX_CMD_SIZE` with a default value of 96. +4. Since serial buffer sizes are likely used as ring buffers themselves, as an optimization their sizes must be a power of 2 (64 or 128 bytes recommended). +5. If a host sends too much G-code at once it can saturate the `GCodeQueue`. This doesn't do anything to improve the processing rate of Marlin since only one command can be dispatched per loop iteration. +6. With the previous point in mind, it's clear that the longstanding wisdom that you don't need a large `BUF_SIZE` is not just apocryphal. The default value of 4 is typically just fine for a single serial port. (And, if you decide to send a `G25` to pause the machine, the wait will be much shorter!) diff --git a/docs/Serial.md b/docs/Serial.md index 948e07b44838..b4079d765f73 100644 --- a/docs/Serial.md +++ b/docs/Serial.md @@ -1,11 +1,10 @@ # Serial port architecture in Marlin -Marlin is targeting a pletora of different CPU architecture and platforms. Each of these platforms has its own serial interface. +Marlin is targeting a plethora of different CPU architecture and platforms. Each of these platforms has its own serial interface. While many provide a Arduino-like Serial class, it's not all of them, and the differences in the existing API create a very complex brain teaser for writing code that works more or less on each platform. Moreover, many platform have intrinsic needs about serial port (like forwarding the output on multiple serial port, providing a *serial-like* telnet server, mixing USB-based serial port with SD card emulation) that are difficult to handle cleanly in the other platform serial logic. - Starting with version `2.0.9`, Marlin provides a common interface for its serial needs. ## Common interface @@ -16,7 +15,7 @@ Any implementation will need to follow this interface for being used transparent The implementation was written to prioritize performance over abstraction, so the base interface is not using virtual inheritance to avoid the cost of virtual dispatching while calling methods. Instead, the Curiously Recurring Template Pattern (**CRTP**) is used so that, upon compilation, the interface abstraction does not incur a performance cost. -Because some platform do not follow the same interface, the missing method in the actual low-level implementation are detected via SFINAE and a wrapper is generated when such method are missing. See `CALL_IF_EXISTS` macro in `Marlin/src/core/macros.h` for the documentation of this technic. +Because some platform do not follow the same interface, the missing method in the actual low-level implementation are detected via SFINAE and a wrapper is generated when such method are missing. See the `CALL_IF_EXISTS` macro in `Marlin/src/core/macros.h` for documentation of this technique. ## Composing the desired feature The different specificities for each architecture are provided by composing the serial type based on desired functionality. @@ -31,14 +30,25 @@ In the `Marlin/src/core/serial_hook.h` file, the different serial feature are de Since all the types above are using CRTP, it's possible to combine them to get the appropriate functionality. This is easily done via type definition of the feature. -For example, to present a serial interface that's outputting to 2 serial port, the first one being hooked at runtime and the second one connected to a runtime switchable telnet client, you'll declare the type to use as: -``` +For example, to create a single serial interface with 2 serial outputs (one enabled at runtime and the other switchable): +```cpp typedef MultiSerial< RuntimeSerial, ConditionalSerial > Serial0Type; ``` +To send the same output to 4 serial ports you could nest `MultiSerial` like this: +```cpp +typedef MultiSerial< MultiSerial< BaseSerial, BaseSerial >, MultiSerial< BaseSerial, BaseSerial, 2, 1>, 0, 2> Serial0Type; +``` +The magical numbers here are the step and offset for computing the serial port. Simplifying the above monster a bit: +```cpp +MS< A = MS, B=MS, offset=0, step=2> +``` +This means that the underlying multiserial A (with output to `a,b`) is available from offset = 0 to offset + step = 1 (default value). +The multiserial B (with output to `c,d`) is available from offset = 2 (the next step from the root multiserial) to offset + step = 3. +In practice, the root multiserial will redirect any index/mask `offset` to `offset + step - 1` to its first leaf, and any index/mask `offset + step` to `offset + 2*step - 1` to its second leaf. + ## Emergency parser -By default, the serial base interface provide an emergency parser that's only enable for serial classes that support it. -Because of this condition, all underlying type takes a first `bool emergencyParserEnabled` argument to their constructor. You must take into account this parameter when defining the actual type used. +By default, the serial base interface provide an emergency parser that's only enable for serial classes that support it. Because of this condition, all underlying types take a first `bool emergencyParserEnabled` argument to their constructor. You must take into account this parameter when defining the actual type used. ## SERIAL macros The following macros are defined (in `serial.h`) to output data to the serial ports: diff --git a/platformio.ini b/platformio.ini index a07ad01f97d4..0e50902489f7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -53,6 +53,7 @@ default_src_filter = + - - + - - - - + - - - - - - - @@ -64,6 +65,7 @@ default_src_filter = + - - + - - - - - - - - - + - - - - @@ -109,6 +111,7 @@ default_src_filter = + - - + - - - - + - - - - - - - @@ -211,17 +214,20 @@ default_src_filter = + - - + extra_scripts = pre:buildroot/share/PlatformIO/scripts/common-dependencies.py pre:buildroot/share/PlatformIO/scripts/common-cxxflags.py - post:buildroot/share/PlatformIO/scripts/common-dependencies-post.py -build_flags = -fmax-errors=5 -g -D__MARLIN_FIRMWARE__ -fmerge-constants + pre:buildroot/share/PlatformIO/scripts/preflight-checks.py +build_flags = -fmax-errors=5 -g3 -D__MARLIN_FIRMWARE__ -fmerge-constants lib_deps = # # Feature Dependencies # [features] +YHCB2004 = red-scorp/LiquidCrystal_AIP31068@^1.0.4, red-scorp/SoftSPIB@^1.1.1 HAS_TFT_LVGL_UI = lvgl=https://github.com/makerbase-mks/LVGL-6.1.1-MKS/archive/master.zip src_filter=+ extra_scripts=download_mks_assets.py +POSTMORTEM_DEBUGGING = src_filter=+ + + build_flags=-funwind-tables MKS_WIFI_MODULE = QRCode=https://github.com/makerbase-mks/QRCode/archive/master.zip HAS_TRINAMIC_CONFIG = TMCStepper@~0.7.1 src_filter=+ + + + + @@ -282,6 +288,10 @@ HAS_MENU_UBL = src_filter=+ ANYCUBIC_LCD_CHIRON = src_filter=+ + ANYCUBIC_LCD_I3MEGA = src_filter=+ + HAS_DGUS_LCD = src_filter=+ + +DGUS_LCD_UI_FYSETC = src_filter=+ +DGUS_LCD_UI_HIPRECY = src_filter=+ +DGUS_LCD_UI_MKS = src_filter=+ +DGUS_LCD_UI_ORIGIN = src_filter=+ TOUCH_UI_FTDI_EVE = src_filter=+ EXTUI_EXAMPLE = src_filter=+ MALYAN_LCD = src_filter=+ @@ -332,6 +342,7 @@ POWER_LOSS_RECOVERY = src_filter=+ + + HAS_FILAMENT_SENSOR = src_filter=+ + (EXT|MANUAL)_SOLENOID.* = src_filter=+ + +MK2_MULTIPLEXER = src_filter=+ HAS_CUTTER = src_filter=+ + EXPERIMENTAL_I2CBUS = src_filter=+ + MECHANICAL_GANTRY_CAL.+ = src_filter=+ @@ -636,14 +647,6 @@ platform = atmelsam extends = env:DUE board = dueUSB -[env:DUE_debug] -# Used when WATCHDOG_RESET_MANUAL is enabled -platform = atmelsam -extends = env:DUE -build_flags = ${common.build_flags} - -funwind-tables - -mpoke-function-name - # # Archim SAM # @@ -661,12 +664,6 @@ extra_scripts = ${common.extra_scripts} platform = ${common_DUE_archim.platform} extends = common_DUE_archim -# Used when WATCHDOG_RESET_MANUAL is enabled -[env:DUE_archim_debug] -platform = ${common_DUE_archim.platform} -extends = common_DUE_archim -build_flags = ${common_DUE_archim.build_flags} -funwind-tables -mpoke-function-name - ################################# # # # SAMD51 Architecture # @@ -685,6 +682,8 @@ src_filter = ${common.default_src_filter} + lib_deps = ${common.lib_deps} SoftwareSerialM Adafruit SPIFlash +extra_scripts = ${common.extra_scripts} + pre:buildroot/share/PlatformIO/scripts/SAMD51_grandcentral_m4.py custom_marlin.SDSUPPORT = SdFat - Adafruit Fork debug_tool = jlink @@ -728,6 +727,12 @@ platform = ${common_LPC.platform} extends = common_LPC board = nxp_lpc1769 +# BTT SKR 1.4 needs a UART3 tweak +[env:LPC1768_btt_skr_v1_4] +platform = ${LPC1768.platform} +extends = env:LPC1768 +build_flags = ${env:LPC1768.build_flags} -DLPC_PINCFG_UART3_P4_28 + ################################# # # # STM32 Architecture # @@ -738,7 +743,7 @@ board = nxp_lpc1769 # HAL/STM32 Base Environment values # [common_stm32] -platform = ststm32@~10.0 +platform = ststm32@~12.0 build_flags = ${common.build_flags} -std=gnu++14 -DUSBCON -DUSBD_USE_CDC @@ -751,7 +756,7 @@ src_filter = ${common.default_src_filter} + +