diff --git a/Marlin/Conditionals_LCD.h b/Marlin/Conditionals_LCD.h
index 4a4213215a..2cd7504326 100644
--- a/Marlin/Conditionals_LCD.h
+++ b/Marlin/Conditionals_LCD.h
@@ -28,474 +28,491 @@
#ifndef CONDITIONALS_LCD_H // Get the LCD defines which are needed first
#define CONDITIONALS_LCD_H
- #define LCD_HAS_DIRECTIONAL_BUTTONS (BUTTON_EXISTS(UP) || BUTTON_EXISTS(DWN) || BUTTON_EXISTS(LFT) || BUTTON_EXISTS(RT))
+#define LCD_HAS_DIRECTIONAL_BUTTONS (BUTTON_EXISTS(UP) || BUTTON_EXISTS(DWN) || BUTTON_EXISTS(LFT) || BUTTON_EXISTS(RT))
- #if ENABLED(CARTESIO_UI)
+#if ENABLED(CARTESIO_UI)
- #define DOGLCD
- #define ULTIPANEL
- #define DEFAULT_LCD_CONTRAST 90
- #define LCD_CONTRAST_MIN 60
- #define LCD_CONTRAST_MAX 140
+ #define DOGLCD
+ #define ULTIPANEL
+ #define DEFAULT_LCD_CONTRAST 90
+ #define LCD_CONTRAST_MIN 60
+ #define LCD_CONTRAST_MAX 140
- #elif ENABLED(MAKRPANEL)
+#elif ENABLED(MAKRPANEL)
+ #define U8GLIB_ST7565_64128N
+
+#elif ENABLED(ZONESTAR_LCD)
+
+ #define REPRAPWORLD_KEYPAD
+ #define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0
+ #define ADC_KEYPAD
+ #define ADC_KEY_NUM 8
+ #define ULTIPANEL
+
+ // this helps to implement ADC_KEYPAD menus
+ #define ENCODER_PULSES_PER_STEP 1
+ #define ENCODER_STEPS_PER_MENU_ITEM 1
+ #define ENCODER_FEEDRATE_DEADZONE 2
+ #define REVERSE_MENU_DIRECTION
+
+#elif ENABLED(ANET_FULL_GRAPHICS_LCD)
+
+ #define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
+
+#elif ENABLED(BQ_LCD_SMART_CONTROLLER)
+
+ #define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
+
+#elif ENABLED(miniVIKI) || ENABLED(VIKI2) || ENABLED(ELB_FULL_GRAPHIC_CONTROLLER)
+
+ #define ULTRA_LCD //general LCD support, also 16x2
+ #define DOGLCD // Support for SPI LCD 128x64 (Controller ST7565R graphic Display Family)
+ #define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
+
+ #if ENABLED(miniVIKI)
+ #define LCD_CONTRAST_MIN 75
+ #define LCD_CONTRAST_MAX 115
+ #define DEFAULT_LCD_CONTRAST 95
#define U8GLIB_ST7565_64128N
-
- #elif ENABLED(ZONESTAR_LCD)
-
- #define REPRAPWORLD_KEYPAD
- #define REPRAPWORLD_KEYPAD_MOVE_STEP 10.0
- #define ADC_KEYPAD
- #define ADC_KEY_NUM 8
- #define ULTIPANEL
-
- // this helps to implement ADC_KEYPAD menus
- #define ENCODER_PULSES_PER_STEP 1
- #define ENCODER_STEPS_PER_MENU_ITEM 1
- #define ENCODER_FEEDRATE_DEADZONE 2
- #define REVERSE_MENU_DIRECTION
-
- #elif ENABLED(ANET_FULL_GRAPHICS_LCD)
-
- #define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
-
- #elif ENABLED(BQ_LCD_SMART_CONTROLLER)
-
- #define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
-
- #elif ENABLED(miniVIKI) || ENABLED(VIKI2) || ENABLED(ELB_FULL_GRAPHIC_CONTROLLER)
-
- #define ULTRA_LCD //general LCD support, also 16x2
- #define DOGLCD // Support for SPI LCD 128x64 (Controller ST7565R graphic Display Family)
- #define ULTIMAKERCONTROLLER //as available from the Ultimaker online store.
-
- #if ENABLED(miniVIKI)
- #define LCD_CONTRAST_MIN 75
- #define LCD_CONTRAST_MAX 115
- #define DEFAULT_LCD_CONTRAST 95
- #define U8GLIB_ST7565_64128N
- #elif ENABLED(VIKI2)
- #define LCD_CONTRAST_MIN 0
- #define LCD_CONTRAST_MAX 255
- #define DEFAULT_LCD_CONTRAST 140
- #define U8GLIB_ST7565_64128N
- #elif ENABLED(ELB_FULL_GRAPHIC_CONTROLLER)
- #define LCD_CONTRAST_MIN 90
- #define LCD_CONTRAST_MAX 130
- #define DEFAULT_LCD_CONTRAST 110
- #define U8GLIB_LM6059_AF
- #define SD_DETECT_INVERTED
- #endif
-
- #elif ENABLED(OLED_PANEL_TINYBOY2)
-
- #define U8GLIB_SSD1306
- #define ULTIPANEL
- #define REVERSE_ENCODER_DIRECTION
- #define REVERSE_MENU_DIRECTION
-
- #elif ENABLED(RA_CONTROL_PANEL)
-
- #define LCD_I2C_TYPE_PCA8574
- #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander
- #define ULTIPANEL
-
- #elif ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
-
- #define DOGLCD
- #define U8GLIB_ST7920
- #define ULTIPANEL
-
- #elif ENABLED(CR10_STOCKDISPLAY)
-
- #define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
- #ifndef ST7920_DELAY_1
- #define ST7920_DELAY_1 DELAY_2_NOP
- #endif
- #ifndef ST7920_DELAY_2
- #define ST7920_DELAY_2 DELAY_2_NOP
- #endif
- #ifndef ST7920_DELAY_3
- #define ST7920_DELAY_3 DELAY_2_NOP
- #endif
-
- #elif ENABLED(MKS_12864OLED)
-
- #define REPRAP_DISCOUNT_SMART_CONTROLLER
- #define U8GLIB_SH1106
-
- #elif ENABLED(MKS_12864OLED_SSD1306)
-
- #define REPRAP_DISCOUNT_SMART_CONTROLLER
- #define U8GLIB_SSD1306
-
- #elif ENABLED(MKS_MINI_12864)
-
- #define MINIPANEL
-
+ #elif ENABLED(VIKI2)
+ #define LCD_CONTRAST_MIN 0
+ #define LCD_CONTRAST_MAX 255
+ #define DEFAULT_LCD_CONTRAST 140
+ #define U8GLIB_ST7565_64128N
+ #elif ENABLED(ELB_FULL_GRAPHIC_CONTROLLER)
+ #define LCD_CONTRAST_MIN 90
+ #define LCD_CONTRAST_MAX 130
+ #define DEFAULT_LCD_CONTRAST 110
+ #define U8GLIB_LM6059_AF
+ #define SD_DETECT_INVERTED
#endif
- #if ENABLED(MAKRPANEL) || ENABLED(MINIPANEL)
- #define DOGLCD
- #define ULTIPANEL
- #define DEFAULT_LCD_CONTRAST 17
+#elif ENABLED(OLED_PANEL_TINYBOY2)
+
+ #define U8GLIB_SSD1306
+ #define ULTIPANEL
+ #define REVERSE_ENCODER_DIRECTION
+ #define REVERSE_MENU_DIRECTION
+
+#elif ENABLED(RA_CONTROL_PANEL)
+
+ #define LCD_I2C_TYPE_PCA8574
+ #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander
+ #define ULTIPANEL
+
+#elif ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
+
+ #define DOGLCD
+ #define U8GLIB_ST7920
+ #define ULTIPANEL
+
+#elif ENABLED(CR10_STOCKDISPLAY)
+
+ #define REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
+ #ifndef ST7920_DELAY_1
+ #define ST7920_DELAY_1 DELAY_NS(125)
+ #endif
+ #ifndef ST7920_DELAY_2
+ #define ST7920_DELAY_2 DELAY_NS(125)
+ #endif
+ #ifndef ST7920_DELAY_3
+ #define ST7920_DELAY_3 DELAY_NS(125)
#endif
- #if ENABLED(ULTI_CONTROLLER)
- #define U8GLIB_SSD1309
- #define REVERSE_ENCODER_DIRECTION
- #define LCD_RESET_PIN LCD_PINS_D6 // This controller need a reset pin
- #define LCD_CONTRAST_MIN 0
- #define LCD_CONTRAST_MAX 254
- #define DEFAULT_LCD_CONTRAST 127
- #define ENCODER_PULSES_PER_STEP 2
- #define ENCODER_STEPS_PER_MENU_ITEM 2
+#elif ENABLED(MKS_12864OLED)
+
+ #define REPRAP_DISCOUNT_SMART_CONTROLLER
+ #define U8GLIB_SH1106
+
+#elif ENABLED(MKS_12864OLED_SSD1306)
+
+ #define REPRAP_DISCOUNT_SMART_CONTROLLER
+ #define U8GLIB_SSD1306
+
+#elif ENABLED(MKS_MINI_12864)
+
+ #define MINIPANEL
+
+#endif
+
+#if ENABLED(MAKRPANEL) || ENABLED(MINIPANEL)
+ #define DOGLCD
+ #define ULTIPANEL
+ #define DEFAULT_LCD_CONTRAST 17
+#endif
+
+#if ENABLED(ULTI_CONTROLLER)
+ #define U8GLIB_SSD1309
+ #define REVERSE_ENCODER_DIRECTION
+ #define LCD_RESET_PIN LCD_PINS_D6 // This controller need a reset pin
+ #define LCD_CONTRAST_MIN 0
+ #define LCD_CONTRAST_MAX 254
+ #define DEFAULT_LCD_CONTRAST 127
+ #define ENCODER_PULSES_PER_STEP 2
+ #define ENCODER_STEPS_PER_MENU_ITEM 2
+#endif
+
+// Generic support for SSD1306 / SSD1309 / SH1106 OLED based LCDs.
+#if ENABLED(U8GLIB_SSD1306) || ENABLED(U8GLIB_SSD1309) || ENABLED(U8GLIB_SH1106)
+ #define ULTRA_LCD //general LCD support, also 16x2
+ #define DOGLCD // Support for I2C LCD 128x64 (Controller SSD1306 / SSD1309 / SH1106 graphic Display Family)
+#endif
+
+#if ENABLED(PANEL_ONE) || ENABLED(U8GLIB_SH1106)
+
+ #define ULTIMAKERCONTROLLER
+
+#elif ENABLED(MAKEBOARD_MINI_2_LINE_DISPLAY_1602)
+
+ #define REPRAP_DISCOUNT_SMART_CONTROLLER
+ #define LCD_WIDTH 16
+ #define LCD_HEIGHT 2
+
+#endif
+
+#if ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) || ENABLED(LCD_FOR_MELZI) || ENABLED(SILVER_GATE_GLCD_CONTROLLER)
+ #define DOGLCD
+ #define U8GLIB_ST7920
+ #define REPRAP_DISCOUNT_SMART_CONTROLLER
+#endif
+
+#if ENABLED(ULTIMAKERCONTROLLER) \
+ || ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) \
+ || ENABLED(G3D_PANEL) \
+ || ENABLED(RIGIDBOT_PANEL) \
+ || ENABLED(ULTI_CONTROLLER)
+ #define ULTIPANEL
+#endif
+
+#if ENABLED(REPRAPWORLD_KEYPAD)
+ #define NEWPANEL
+ #if ENABLED(ULTIPANEL) && !defined(REPRAPWORLD_KEYPAD_MOVE_STEP)
+ #define REPRAPWORLD_KEYPAD_MOVE_STEP 1.0
+ #endif
+#endif
+
+/**
+ * I2C PANELS
+ */
+
+#if ENABLED(LCD_SAINSMART_I2C_1602) || ENABLED(LCD_SAINSMART_I2C_2004)
+
+ #define LCD_I2C_TYPE_PCF8575
+ #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander
+ #define ULTRA_LCD
+
+ #if ENABLED(LCD_SAINSMART_I2C_2004)
+ #define LCD_WIDTH 20
+ #define LCD_HEIGHT 4
#endif
- // Generic support for SSD1306 / SSD1309 / SH1106 OLED based LCDs.
- #if ENABLED(U8GLIB_SSD1306) || ENABLED(U8GLIB_SSD1309) || ENABLED(U8GLIB_SH1106)
- #define ULTRA_LCD //general LCD support, also 16x2
- #define DOGLCD // Support for I2C LCD 128x64 (Controller SSD1306 / SSD1309 / SH1106 graphic Display Family)
+#elif ENABLED(LCD_I2C_PANELOLU2)
+
+ // PANELOLU2 LCD with status LEDs, separate encoder and click inputs
+
+ #define LCD_I2C_TYPE_MCP23017
+ #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander
+ #define LCD_USE_I2C_BUZZER // Enable buzzer on LCD (optional)
+ #define ULTIPANEL
+
+#elif ENABLED(LCD_I2C_VIKI)
+
+ /**
+ * Panucatt VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs
+ *
+ * This uses the LiquidTWI2 library v1.2.3 or later ( https://github.com/lincomatic/LiquidTWI2 )
+ * Make sure the LiquidTWI2 directory is placed in the Arduino or Sketchbook libraries subdirectory.
+ * Note: The pause/stop/resume LCD button pin should be connected to the Arduino
+ * BTN_ENC pin (or set BTN_ENC to -1 if not used)
+ */
+ #define LCD_I2C_TYPE_MCP23017
+ #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander
+ #define LCD_USE_I2C_BUZZER // Enable buzzer on LCD (requires LiquidTWI2 v1.2.3 or later)
+ #define ULTIPANEL
+
+ #define ENCODER_FEEDRATE_DEADZONE 4
+
+ #define STD_ENCODER_PULSES_PER_STEP 1
+ #define STD_ENCODER_STEPS_PER_MENU_ITEM 2
+
+#elif ENABLED(G3D_PANEL)
+
+ #define STD_ENCODER_PULSES_PER_STEP 2
+ #define STD_ENCODER_STEPS_PER_MENU_ITEM 1
+
+#elif ENABLED(miniVIKI) || ENABLED(VIKI2) \
+ || ENABLED(ELB_FULL_GRAPHIC_CONTROLLER) \
+ || ENABLED(OLED_PANEL_TINYBOY2) \
+ || ENABLED(BQ_LCD_SMART_CONTROLLER) \
+ || ENABLED(LCD_I2C_PANELOLU2) \
+ || ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER)
+ #define STD_ENCODER_PULSES_PER_STEP 4
+ #define STD_ENCODER_STEPS_PER_MENU_ITEM 1
+#endif
+
+#ifndef STD_ENCODER_PULSES_PER_STEP
+ #define STD_ENCODER_PULSES_PER_STEP 5
+#endif
+#ifndef STD_ENCODER_STEPS_PER_MENU_ITEM
+ #define STD_ENCODER_STEPS_PER_MENU_ITEM 1
+#endif
+#ifndef ENCODER_PULSES_PER_STEP
+ #define ENCODER_PULSES_PER_STEP STD_ENCODER_PULSES_PER_STEP
+#endif
+#ifndef ENCODER_STEPS_PER_MENU_ITEM
+ #define ENCODER_STEPS_PER_MENU_ITEM STD_ENCODER_STEPS_PER_MENU_ITEM
+#endif
+#ifndef ENCODER_FEEDRATE_DEADZONE
+ #define ENCODER_FEEDRATE_DEADZONE 6
+#endif
+
+// Shift register panels
+// ---------------------
+// 2 wire Non-latching LCD SR from:
+// https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection
+
+#if ENABLED(SAV_3DLCD)
+ #define SR_LCD_2W_NL // Non latching 2 wire shift register
+ #define ULTIPANEL
+#endif
+
+#if ENABLED(DOGLCD) // Change number of lines to match the DOG graphic display
+ #ifndef LCD_WIDTH
+ #ifdef LCD_WIDTH_OVERRIDE
+ #define LCD_WIDTH LCD_WIDTH_OVERRIDE
+ #else
+ #define LCD_WIDTH 22
+ #endif
#endif
+ #ifndef LCD_HEIGHT
+ #define LCD_HEIGHT 5
+ #endif
+#endif
- #if ENABLED(PANEL_ONE) || ENABLED(U8GLIB_SH1106)
+#if ENABLED(NO_LCD_MENUS)
+ #undef ULTIPANEL
+#endif
- #define ULTIMAKERCONTROLLER
-
- #elif ENABLED(MAKEBOARD_MINI_2_LINE_DISPLAY_1602)
-
- #define REPRAP_DISCOUNT_SMART_CONTROLLER
+#if ENABLED(ULTIPANEL)
+ #define NEWPANEL // Disable this if you actually have no click-encoder panel
+ #define ULTRA_LCD
+ #ifndef LCD_WIDTH
+ #define LCD_WIDTH 20
+ #endif
+ #ifndef LCD_HEIGHT
+ #define LCD_HEIGHT 4
+ #endif
+#elif ENABLED(ULTRA_LCD) // no panel but just LCD
+ #ifndef LCD_WIDTH
#define LCD_WIDTH 16
+ #endif
+ #ifndef LCD_HEIGHT
#define LCD_HEIGHT 2
-
#endif
+#endif
- #if ENABLED(REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER) || ENABLED(LCD_FOR_MELZI) || ENABLED(SILVER_GATE_GLCD_CONTROLLER)
- #define DOGLCD
- #define U8GLIB_ST7920
- #define REPRAP_DISCOUNT_SMART_CONTROLLER
- #endif
+#if ENABLED(DOGLCD)
+ /* Custom characters defined in font dogm_font_data_Marlin_symbols.h / Marlin_symbols.fon */
+ // \x00 intentionally skipped to avoid problems in strings
+ #define LCD_STR_REFRESH "\x01"
+ #define LCD_STR_FOLDER "\x02"
+ #define LCD_STR_ARROW_RIGHT "\x03"
+ #define LCD_STR_UPLEVEL "\x04"
+ #define LCD_STR_CLOCK "\x05"
+ #define LCD_STR_FEEDRATE "\x06"
+ #define LCD_STR_BEDTEMP "\x07"
+ #define LCD_STR_THERMOMETER "\x08"
+ #define LCD_STR_DEGREE "\x09"
- #if ENABLED(ULTIMAKERCONTROLLER) \
- || ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER) \
- || ENABLED(G3D_PANEL) \
- || ENABLED(RIGIDBOT_PANEL) \
- || ENABLED(ULTI_CONTROLLER)
- #define ULTIPANEL
- #endif
+ #define LCD_STR_SPECIAL_MAX '\x09'
+ // Maximum here is 0x1F because 0x20 is ' ' (space) and the normal charsets begin.
+ // Better stay below 0x10 because DISPLAY_CHARSET_HD44780_WESTERN begins here.
- #if ENABLED(REPRAPWORLD_KEYPAD)
- #define NEWPANEL
- #if ENABLED(ULTIPANEL) && !defined(REPRAPWORLD_KEYPAD_MOVE_STEP)
- #define REPRAPWORLD_KEYPAD_MOVE_STEP 1.0
+ // Symbol characters
+ #define LCD_STR_FILAM_DIA "\xf8"
+ #define LCD_STR_FILAM_MUL "\xa4"
+#else
+ // Custom characters defined in the first 8 characters of the LCD
+ #define LCD_BEDTEMP_CHAR 0x00 // Print only as a char. This will have 'unexpected' results when used in a string!
+ #define LCD_DEGREE_CHAR 0x01
+ #define LCD_STR_THERMOMETER "\x02" // Still used with string concatenation
+ #define LCD_UPLEVEL_CHAR 0x03
+ #define LCD_STR_REFRESH "\x04"
+ #define LCD_STR_FOLDER "\x05"
+ #define LCD_FEEDRATE_CHAR 0x06
+ #define LCD_CLOCK_CHAR 0x07
+ #define LCD_STR_ARROW_RIGHT ">" /* from the default character set */
+#endif
+
+/**
+ * Default LCD contrast for dogm-like LCD displays
+ */
+#if ENABLED(DOGLCD)
+
+ #define HAS_LCD_CONTRAST ( \
+ ENABLED(MAKRPANEL) \
+ || ENABLED(CARTESIO_UI) \
+ || ENABLED(VIKI2) \
+ || ENABLED(miniVIKI) \
+ || ENABLED(ELB_FULL_GRAPHIC_CONTROLLER) \
+ )
+
+ #if HAS_LCD_CONTRAST
+ #ifndef LCD_CONTRAST_MIN
+ #define LCD_CONTRAST_MIN 0
+ #endif
+ #ifndef LCD_CONTRAST_MAX
+ #define LCD_CONTRAST_MAX 63
+ #endif
+ #ifndef DEFAULT_LCD_CONTRAST
+ #define DEFAULT_LCD_CONTRAST 32
#endif
#endif
+#endif
- /**
- * I2C PANELS
- */
+// Boot screens
+#if DISABLED(ULTRA_LCD)
+ #undef SHOW_BOOTSCREEN
+#elif !defined(BOOTSCREEN_TIMEOUT)
+ #define BOOTSCREEN_TIMEOUT 2500
+#endif
- #if ENABLED(LCD_SAINSMART_I2C_1602) || ENABLED(LCD_SAINSMART_I2C_2004)
+#define HAS_DEBUG_MENU (ENABLED(ULTIPANEL) && ENABLED(LCD_PROGRESS_BAR_TEST))
- #define LCD_I2C_TYPE_PCF8575
- #define LCD_I2C_ADDRESS 0x27 // I2C Address of the port expander
- #define ULTRA_LCD
-
- #if ENABLED(LCD_SAINSMART_I2C_2004)
- #define LCD_WIDTH 20
- #define LCD_HEIGHT 4
- #endif
-
- #elif ENABLED(LCD_I2C_PANELOLU2)
-
- // PANELOLU2 LCD with status LEDs, separate encoder and click inputs
-
- #define LCD_I2C_TYPE_MCP23017
- #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander
- #define LCD_USE_I2C_BUZZER // Enable buzzer on LCD (optional)
- #define ULTIPANEL
-
- #elif ENABLED(LCD_I2C_VIKI)
-
- /**
- * Panucatt VIKI LCD with status LEDs, integrated click & L/R/U/P buttons, separate encoder inputs
- *
- * This uses the LiquidTWI2 library v1.2.3 or later ( https://github.com/lincomatic/LiquidTWI2 )
- * Make sure the LiquidTWI2 directory is placed in the Arduino or Sketchbook libraries subdirectory.
- * Note: The pause/stop/resume LCD button pin should be connected to the Arduino
- * BTN_ENC pin (or set BTN_ENC to -1 if not used)
- */
- #define LCD_I2C_TYPE_MCP23017
- #define LCD_I2C_ADDRESS 0x20 // I2C Address of the port expander
- #define LCD_USE_I2C_BUZZER // Enable buzzer on LCD (requires LiquidTWI2 v1.2.3 or later)
- #define ULTIPANEL
-
- #define ENCODER_FEEDRATE_DEADZONE 4
-
- #define STD_ENCODER_PULSES_PER_STEP 1
- #define STD_ENCODER_STEPS_PER_MENU_ITEM 2
-
- #elif ENABLED(G3D_PANEL)
-
- #define STD_ENCODER_PULSES_PER_STEP 2
- #define STD_ENCODER_STEPS_PER_MENU_ITEM 1
-
- #elif ENABLED(miniVIKI) || ENABLED(VIKI2) \
- || ENABLED(ELB_FULL_GRAPHIC_CONTROLLER) \
- || ENABLED(OLED_PANEL_TINYBOY2) \
- || ENABLED(BQ_LCD_SMART_CONTROLLER) \
- || ENABLED(LCD_I2C_PANELOLU2) \
- || ENABLED(REPRAP_DISCOUNT_SMART_CONTROLLER)
- #define STD_ENCODER_PULSES_PER_STEP 4
- #define STD_ENCODER_STEPS_PER_MENU_ITEM 1
- #endif
-
- #ifndef STD_ENCODER_PULSES_PER_STEP
- #define STD_ENCODER_PULSES_PER_STEP 5
- #endif
- #ifndef STD_ENCODER_STEPS_PER_MENU_ITEM
- #define STD_ENCODER_STEPS_PER_MENU_ITEM 1
- #endif
- #ifndef ENCODER_PULSES_PER_STEP
- #define ENCODER_PULSES_PER_STEP STD_ENCODER_PULSES_PER_STEP
- #endif
- #ifndef ENCODER_STEPS_PER_MENU_ITEM
- #define ENCODER_STEPS_PER_MENU_ITEM STD_ENCODER_STEPS_PER_MENU_ITEM
- #endif
- #ifndef ENCODER_FEEDRATE_DEADZONE
- #define ENCODER_FEEDRATE_DEADZONE 6
- #endif
-
- // Shift register panels
- // ---------------------
- // 2 wire Non-latching LCD SR from:
- // https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection
-
- #if ENABLED(SAV_3DLCD)
- #define SR_LCD_2W_NL // Non latching 2 wire shift register
- #define ULTIPANEL
- #endif
-
- #if ENABLED(DOGLCD) // Change number of lines to match the DOG graphic display
- #ifndef LCD_WIDTH
- #ifdef LCD_WIDTH_OVERRIDE
- #define LCD_WIDTH LCD_WIDTH_OVERRIDE
- #else
- #define LCD_WIDTH 22
- #endif
- #endif
- #ifndef LCD_HEIGHT
- #define LCD_HEIGHT 5
- #endif
- #endif
-
- #if ENABLED(ULTIPANEL)
- #define NEWPANEL // Disable this if you actually have no click-encoder panel
- #define ULTRA_LCD
- #ifndef LCD_WIDTH
- #define LCD_WIDTH 20
- #endif
- #ifndef LCD_HEIGHT
- #define LCD_HEIGHT 4
- #endif
- #elif ENABLED(ULTRA_LCD) // no panel but just LCD
- #ifndef LCD_WIDTH
- #define LCD_WIDTH 16
- #endif
- #ifndef LCD_HEIGHT
- #define LCD_HEIGHT 2
- #endif
- #endif
-
- #if ENABLED(DOGLCD)
- /* Custom characters defined in font dogm_font_data_Marlin_symbols.h / Marlin_symbols.fon */
- // \x00 intentionally skipped to avoid problems in strings
- #define LCD_STR_REFRESH "\x01"
- #define LCD_STR_FOLDER "\x02"
- #define LCD_STR_ARROW_RIGHT "\x03"
- #define LCD_STR_UPLEVEL "\x04"
- #define LCD_STR_CLOCK "\x05"
- #define LCD_STR_FEEDRATE "\x06"
- #define LCD_STR_BEDTEMP "\x07"
- #define LCD_STR_THERMOMETER "\x08"
- #define LCD_STR_DEGREE "\x09"
-
- #define LCD_STR_SPECIAL_MAX '\x09'
- // Maximum here is 0x1F because 0x20 is ' ' (space) and the normal charsets begin.
- // Better stay below 0x10 because DISPLAY_CHARSET_HD44780_WESTERN begins here.
-
- // Symbol characters
- #define LCD_STR_FILAM_DIA "\xf8"
- #define LCD_STR_FILAM_MUL "\xa4"
+/**
+ * Extruders have some combination of stepper motors and hotends
+ * so we separate these concepts into the defines:
+ *
+ * EXTRUDERS - Number of Selectable Tools
+ * HOTENDS - Number of hotends, whether connected or separate
+ * E_STEPPERS - Number of actual E stepper motors
+ * E_MANUAL - Number of E steppers for LCD move options
+ *
+ */
+#if ENABLED(SWITCHING_EXTRUDER) // One stepper for every two EXTRUDERS
+ #if EXTRUDERS > 4
+ #define E_STEPPERS 3
+ #elif EXTRUDERS > 2
+ #define E_STEPPERS 2
#else
- // Custom characters defined in the first 8 characters of the LCD
- #define LCD_BEDTEMP_CHAR 0x00 // Print only as a char. This will have 'unexpected' results when used in a string!
- #define LCD_DEGREE_CHAR 0x01
- #define LCD_STR_THERMOMETER "\x02" // Still used with string concatenation
- #define LCD_UPLEVEL_CHAR 0x03
- #define LCD_STR_REFRESH "\x04"
- #define LCD_STR_FOLDER "\x05"
- #define LCD_FEEDRATE_CHAR 0x06
- #define LCD_CLOCK_CHAR 0x07
- #define LCD_STR_ARROW_RIGHT ">" /* from the default character set */
+ #define E_STEPPERS 1
#endif
-
- /**
- * Default LCD contrast for dogm-like LCD displays
- */
- #if ENABLED(DOGLCD)
-
- #define HAS_LCD_CONTRAST ( \
- ENABLED(MAKRPANEL) \
- || ENABLED(CARTESIO_UI) \
- || ENABLED(VIKI2) \
- || ENABLED(miniVIKI) \
- || ENABLED(ELB_FULL_GRAPHIC_CONTROLLER) \
- )
-
- #if HAS_LCD_CONTRAST
- #ifndef LCD_CONTRAST_MIN
- #define LCD_CONTRAST_MIN 0
- #endif
- #ifndef LCD_CONTRAST_MAX
- #define LCD_CONTRAST_MAX 63
- #endif
- #ifndef DEFAULT_LCD_CONTRAST
- #define DEFAULT_LCD_CONTRAST 32
- #endif
- #endif
+ #if DISABLED(SWITCHING_NOZZLE)
+ #define HOTENDS E_STEPPERS
#endif
+ #define E_MANUAL EXTRUDERS
+#elif ENABLED(MIXING_EXTRUDER)
+ #define E_STEPPERS MIXING_STEPPERS
+ #define E_MANUAL 1
+#else
+ #define E_STEPPERS EXTRUDERS
+ #define E_MANUAL EXTRUDERS
+#endif
- // Boot screens
- #if DISABLED(ULTRA_LCD)
- #undef SHOW_BOOTSCREEN
- #elif !defined(BOOTSCREEN_TIMEOUT)
- #define BOOTSCREEN_TIMEOUT 2500
+// No inactive extruders with MK2_MULTIPLEXER or SWITCHING_NOZZLE
+#if ENABLED(MK2_MULTIPLEXER) || ENABLED(SWITCHING_NOZZLE)
+ #undef DISABLE_INACTIVE_EXTRUDER
+#endif
+
+// MK2 Multiplexer forces SINGLENOZZLE
+#if ENABLED(MK2_MULTIPLEXER)
+ #define SINGLENOZZLE
+#endif
+
+#if ENABLED(SINGLENOZZLE) || ENABLED(MIXING_EXTRUDER) // One hotend, one thermistor, no XY offset
+ #undef HOTENDS
+ #define HOTENDS 1
+ #undef TEMP_SENSOR_1_AS_REDUNDANT
+ #undef HOTEND_OFFSET_X
+ #undef HOTEND_OFFSET_Y
+#endif
+
+#ifndef HOTENDS
+ #define HOTENDS EXTRUDERS
+#endif
+
+#define DO_SWITCH_EXTRUDER (ENABLED(SWITCHING_EXTRUDER) && (DISABLED(SWITCHING_NOZZLE) || SWITCHING_EXTRUDER_SERVO_NR != SWITCHING_NOZZLE_SERVO_NR))
+
+/**
+ * DISTINCT_E_FACTORS affects how some E factors are accessed
+ */
+#if ENABLED(DISTINCT_E_FACTORS) && E_STEPPERS > 1
+ #define XYZE_N (XYZ + E_STEPPERS)
+ #define E_AXIS_N (E_AXIS + extruder)
+#else
+ #undef DISTINCT_E_FACTORS
+ #define XYZE_N XYZE
+ #define E_AXIS_N E_AXIS
+#endif
+
+/**
+ * The BLTouch Probe emulates a servo probe
+ * and uses "special" angles for its state.
+ */
+#if ENABLED(BLTOUCH)
+ #ifndef Z_PROBE_SERVO_NR
+ #define Z_PROBE_SERVO_NR 0
#endif
-
- #define HAS_DEBUG_MENU ENABLED(LCD_PROGRESS_BAR_TEST)
-
- // MK2 Multiplexer forces SINGLENOZZLE and kills DISABLE_INACTIVE_EXTRUDER
- #if ENABLED(MK2_MULTIPLEXER)
- #define SINGLENOZZLE
- #undef DISABLE_INACTIVE_EXTRUDER
+ #ifndef NUM_SERVOS
+ #define NUM_SERVOS (Z_PROBE_SERVO_NR + 1)
#endif
-
- /**
- * Extruders have some combination of stepper motors and hotends
- * so we separate these concepts into the defines:
- *
- * EXTRUDERS - Number of Selectable Tools
- * HOTENDS - Number of hotends, whether connected or separate
- * E_STEPPERS - Number of actual E stepper motors
- * E_MANUAL - Number of E steppers for LCD move options
- *
- */
- #if ENABLED(SINGLENOZZLE) || ENABLED(MIXING_EXTRUDER) // One hotend, one thermistor, no XY offset
- #define HOTENDS 1
- #undef TEMP_SENSOR_1_AS_REDUNDANT
- #undef HOTEND_OFFSET_X
- #undef HOTEND_OFFSET_Y
- #else // Two hotends
- #define HOTENDS EXTRUDERS
- #if ENABLED(SWITCHING_NOZZLE) && !defined(HOTEND_OFFSET_Z)
- #define HOTEND_OFFSET_Z { 0 }
- #endif
+ #undef DEACTIVATE_SERVOS_AFTER_MOVE
+ #if NUM_SERVOS == 1
+ #undef SERVO_DELAY
+ #define SERVO_DELAY { 50 }
#endif
+ #ifndef BLTOUCH_DELAY
+ #define BLTOUCH_DELAY 375
+ #endif
+ #undef Z_SERVO_ANGLES
+ #define Z_SERVO_ANGLES { BLTOUCH_DEPLOY, BLTOUCH_STOW }
- #if ENABLED(SWITCHING_EXTRUDER) // One stepper for every two EXTRUDERS
- #if EXTRUDERS > 4
- #define E_STEPPERS 3
- #define E_MANUAL 3
- #elif EXTRUDERS > 2
- #define E_STEPPERS 2
- #define E_MANUAL 2
- #else
- #define E_STEPPERS 1
- #endif
- #define E_MANUAL EXTRUDERS
- #elif ENABLED(MIXING_EXTRUDER)
- #define E_STEPPERS MIXING_STEPPERS
- #define E_MANUAL 1
+ #define BLTOUCH_DEPLOY 10
+ #define BLTOUCH_STOW 90
+ #define BLTOUCH_SELFTEST 120
+ #define BLTOUCH_RESET 160
+ #define _TEST_BLTOUCH(P) (READ(P##_PIN) != P##_ENDSTOP_INVERTING)
+
+ // Always disable probe pin inverting for BLTouch
+ #undef Z_MIN_PROBE_ENDSTOP_INVERTING
+ #define Z_MIN_PROBE_ENDSTOP_INVERTING false
+
+ #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
+ #undef Z_MIN_ENDSTOP_INVERTING
+ #define Z_MIN_ENDSTOP_INVERTING Z_MIN_PROBE_ENDSTOP_INVERTING
+ #define TEST_BLTOUCH() _TEST_BLTOUCH(Z_MIN)
#else
- #define E_STEPPERS EXTRUDERS
- #define E_MANUAL EXTRUDERS
+ #define TEST_BLTOUCH() _TEST_BLTOUCH(Z_MIN_PROBE)
#endif
+#endif
- /**
- * DISTINCT_E_FACTORS affects how some E factors are accessed
- */
- #if ENABLED(DISTINCT_E_FACTORS) && E_STEPPERS > 1
- #define XYZE_N (XYZ + E_STEPPERS)
- #define E_AXIS_N (E_AXIS + extruder)
- #else
- #undef DISTINCT_E_FACTORS
- #define XYZE_N XYZE
- #define E_AXIS_N E_AXIS
- #endif
+/**
+ * Set a flag for a servo probe
+ */
+#define HAS_Z_SERVO_PROBE (defined(Z_PROBE_SERVO_NR) && Z_PROBE_SERVO_NR >= 0)
- /**
- * The BLTouch Probe emulates a servo probe
- * and uses "special" angles for its state.
- */
- #if ENABLED(BLTOUCH)
- #ifndef Z_PROBE_SERVO_NR
- #define Z_PROBE_SERVO_NR 0
- #endif
- #ifndef NUM_SERVOS
- #define NUM_SERVOS (Z_PROBE_SERVO_NR + 1)
- #endif
- #undef DEACTIVATE_SERVOS_AFTER_MOVE
- #if NUM_SERVOS == 1
- #undef SERVO_DELAY
- #define SERVO_DELAY { 50 }
- #endif
- #ifndef BLTOUCH_DELAY
- #define BLTOUCH_DELAY 375
- #endif
- #undef Z_SERVO_ANGLES
- #define Z_SERVO_ANGLES { BLTOUCH_DEPLOY, BLTOUCH_STOW }
+/**
+ * Set flags for enabled probes
+ */
+#define HAS_BED_PROBE (ENABLED(FIX_MOUNTED_PROBE) || ENABLED(Z_PROBE_ALLEN_KEY) || HAS_Z_SERVO_PROBE || ENABLED(Z_PROBE_SLED) || ENABLED(SOLENOID_PROBE))
+#define PROBE_SELECTED (HAS_BED_PROBE || ENABLED(PROBE_MANUALLY))
- #define BLTOUCH_DEPLOY 10
- #define BLTOUCH_STOW 90
- #define BLTOUCH_SELFTEST 120
- #define BLTOUCH_RESET 160
- #define _TEST_BLTOUCH(P) (READ(P##_PIN) != P##_ENDSTOP_INVERTING)
+#if !HAS_BED_PROBE
+ // Clear probe pin settings when no probe is selected
+ #undef Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
+ #undef Z_MIN_PROBE_ENDSTOP
+#elif ENABLED(Z_PROBE_ALLEN_KEY)
+ // Extra test for Allen Key Probe
+ #define PROBE_IS_TRIGGERED_WHEN_STOWED_TEST
+#endif
- // Always disable probe pin inverting for BLTouch
- #undef Z_MIN_PROBE_ENDSTOP_INVERTING
- #define Z_MIN_PROBE_ENDSTOP_INVERTING false
+#define HOMING_Z_WITH_PROBE (HAS_BED_PROBE && Z_HOME_DIR < 0 && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN))
- #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
- #undef Z_MIN_ENDSTOP_INVERTING
- #define Z_MIN_ENDSTOP_INVERTING Z_MIN_PROBE_ENDSTOP_INVERTING
- #define TEST_BLTOUCH() _TEST_BLTOUCH(Z_MIN)
- #else
- #define TEST_BLTOUCH() _TEST_BLTOUCH(Z_MIN_PROBE)
- #endif
- #endif
+#define HAS_SOFTWARE_ENDSTOPS (ENABLED(MIN_SOFTWARE_ENDSTOPS) || ENABLED(MAX_SOFTWARE_ENDSTOPS))
+#define HAS_RESUME_CONTINUE (ENABLED(NEWPANEL) || ENABLED(EMERGENCY_PARSER))
+#define HAS_COLOR_LEDS (ENABLED(BLINKM) || ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(PCA9632) || ENABLED(NEOPIXEL_LED))
- /**
- * Set a flag for a servo probe
- */
- #define HAS_Z_SERVO_PROBE (defined(Z_PROBE_SERVO_NR) && Z_PROBE_SERVO_NR >= 0)
-
- /**
- * Set a flag for any enabled probe
- */
- #define PROBE_SELECTED (ENABLED(PROBE_MANUALLY) || ENABLED(FIX_MOUNTED_PROBE) || ENABLED(Z_PROBE_ALLEN_KEY) || HAS_Z_SERVO_PROBE || ENABLED(Z_PROBE_SLED) || ENABLED(SOLENOID_PROBE))
-
- /**
- * Clear probe pin settings when no probe is selected
- */
- #if !PROBE_SELECTED || ENABLED(PROBE_MANUALLY)
- #undef Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
- #undef Z_MIN_PROBE_ENDSTOP
- #endif
-
- #define HAS_SOFTWARE_ENDSTOPS (ENABLED(MIN_SOFTWARE_ENDSTOPS) || ENABLED(MAX_SOFTWARE_ENDSTOPS))
- #define HAS_RESUME_CONTINUE (ENABLED(NEWPANEL) || ENABLED(EMERGENCY_PARSER))
- #define HAS_COLOR_LEDS (ENABLED(BLINKM) || ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(PCA9632) || ENABLED(NEOPIXEL_LED))
+#define USE_MARLINSERIAL !(defined(__AVR__) && defined(USBCON))
#endif // CONDITIONALS_LCD_H
diff --git a/Marlin/Conditionals_post.h b/Marlin/Conditionals_post.h
index fa87a0d00d..924ac46ba6 100644
--- a/Marlin/Conditionals_post.h
+++ b/Marlin/Conditionals_post.h
@@ -28,1261 +28,1288 @@
#ifndef CONDITIONALS_POST_H
#define CONDITIONALS_POST_H
- #define IS_SCARA (ENABLED(MORGAN_SCARA) || ENABLED(MAKERARM_SCARA))
- #define IS_KINEMATIC (ENABLED(DELTA) || IS_SCARA)
- #define IS_CARTESIAN !IS_KINEMATIC
+#define IS_SCARA (ENABLED(MORGAN_SCARA) || ENABLED(MAKERARM_SCARA))
+#define IS_KINEMATIC (ENABLED(DELTA) || IS_SCARA)
+#define IS_CARTESIAN !IS_KINEMATIC
- /**
- * Axis lengths and center
- */
- #define X_MAX_LENGTH (X_MAX_POS - (X_MIN_POS))
- #define Y_MAX_LENGTH (Y_MAX_POS - (Y_MIN_POS))
- #define Z_MAX_LENGTH (Z_MAX_POS - (Z_MIN_POS))
+/**
+ * Axis lengths and center
+ */
+#define X_MAX_LENGTH (X_MAX_POS - (X_MIN_POS))
+#define Y_MAX_LENGTH (Y_MAX_POS - (Y_MIN_POS))
+#define Z_MAX_LENGTH (Z_MAX_POS - (Z_MIN_POS))
- // Defined only if the sanity-check is bypassed
- #ifndef X_BED_SIZE
- #define X_BED_SIZE X_MAX_LENGTH
+// Defined only if the sanity-check is bypassed
+#ifndef X_BED_SIZE
+ #define X_BED_SIZE X_MAX_LENGTH
+#endif
+#ifndef Y_BED_SIZE
+ #define Y_BED_SIZE Y_MAX_LENGTH
+#endif
+
+// Require 0,0 bed center for Delta and SCARA
+#if IS_KINEMATIC
+ #define BED_CENTER_AT_0_0
+#endif
+
+// Define center values for future use
+#if ENABLED(BED_CENTER_AT_0_0)
+ #define X_CENTER 0
+ #define Y_CENTER 0
+#else
+ #define X_CENTER ((X_BED_SIZE) / 2)
+ #define Y_CENTER ((Y_BED_SIZE) / 2)
+#endif
+#define Z_CENTER ((Z_MIN_POS + Z_MAX_POS) / 2)
+
+// Get the linear boundaries of the bed
+#define X_MIN_BED (X_CENTER - (X_BED_SIZE) / 2)
+#define X_MAX_BED (X_CENTER + (X_BED_SIZE) / 2)
+#define Y_MIN_BED (Y_CENTER - (Y_BED_SIZE) / 2)
+#define Y_MAX_BED (Y_CENTER + (Y_BED_SIZE) / 2)
+
+/**
+ * CoreXY, CoreXZ, and CoreYZ - and their reverse
+ */
+#define CORE_IS_XY (ENABLED(COREXY) || ENABLED(COREYX))
+#define CORE_IS_XZ (ENABLED(COREXZ) || ENABLED(COREZX))
+#define CORE_IS_YZ (ENABLED(COREYZ) || ENABLED(COREZY))
+#define IS_CORE (CORE_IS_XY || CORE_IS_XZ || CORE_IS_YZ)
+#if IS_CORE
+ #if CORE_IS_XY
+ #define CORE_AXIS_1 A_AXIS
+ #define CORE_AXIS_2 B_AXIS
+ #define NORMAL_AXIS Z_AXIS
+ #elif CORE_IS_XZ
+ #define CORE_AXIS_1 A_AXIS
+ #define NORMAL_AXIS Y_AXIS
+ #define CORE_AXIS_2 C_AXIS
+ #elif CORE_IS_YZ
+ #define NORMAL_AXIS X_AXIS
+ #define CORE_AXIS_1 B_AXIS
+ #define CORE_AXIS_2 C_AXIS
#endif
- #ifndef Y_BED_SIZE
- #define Y_BED_SIZE Y_MAX_LENGTH
- #endif
-
- // Require 0,0 bed center for Delta and SCARA
- #if IS_KINEMATIC
- #define BED_CENTER_AT_0_0
- #endif
-
- // Define center values for future use
- #if ENABLED(BED_CENTER_AT_0_0)
- #define X_CENTER 0
- #define Y_CENTER 0
+ #if ENABLED(COREYX) || ENABLED(COREZX) || ENABLED(COREZY)
+ #define CORESIGN(n) (-(n))
#else
- #define X_CENTER ((X_BED_SIZE) / 2)
- #define Y_CENTER ((Y_BED_SIZE) / 2)
+ #define CORESIGN(n) (n)
#endif
- #define Z_CENTER ((Z_MIN_POS + Z_MAX_POS) / 2)
+#endif
- // Get the linear boundaries of the bed
- #define X_MIN_BED (X_CENTER - (X_BED_SIZE) / 2)
- #define X_MAX_BED (X_CENTER + (X_BED_SIZE) / 2)
- #define Y_MIN_BED (Y_CENTER - (Y_BED_SIZE) / 2)
- #define Y_MAX_BED (Y_CENTER + (Y_BED_SIZE) / 2)
+/**
+ * No adjustable bed on non-cartesians
+ */
+#if IS_KINEMATIC
+ #undef LEVEL_BED_CORNERS
+#endif
- /**
- * CoreXY, CoreXZ, and CoreYZ - and their reverse
- */
- #define CORE_IS_XY (ENABLED(COREXY) || ENABLED(COREYX))
- #define CORE_IS_XZ (ENABLED(COREXZ) || ENABLED(COREZX))
- #define CORE_IS_YZ (ENABLED(COREYZ) || ENABLED(COREZY))
- #define IS_CORE (CORE_IS_XY || CORE_IS_XZ || CORE_IS_YZ)
- #if IS_CORE
- #if CORE_IS_XY
- #define CORE_AXIS_1 A_AXIS
- #define CORE_AXIS_2 B_AXIS
- #define NORMAL_AXIS Z_AXIS
- #elif CORE_IS_XZ
- #define CORE_AXIS_1 A_AXIS
- #define NORMAL_AXIS Y_AXIS
- #define CORE_AXIS_2 C_AXIS
- #elif CORE_IS_YZ
- #define NORMAL_AXIS X_AXIS
- #define CORE_AXIS_1 B_AXIS
- #define CORE_AXIS_2 C_AXIS
- #endif
- #if ENABLED(COREYX) || ENABLED(COREZX) || ENABLED(COREZY)
- #define CORESIGN(n) (-(n))
- #else
- #define CORESIGN(n) (n)
- #endif
- #endif
+/**
+ * SCARA cannot use SLOWDOWN and requires QUICKHOME
+ */
+#if IS_SCARA
+ #undef SLOWDOWN
+ #define QUICK_HOME
+#endif
- /**
- * No adjustable bed on non-cartesians
- */
- #if IS_KINEMATIC
- #undef LEVEL_BED_CORNERS
- #endif
-
- /**
- * SCARA cannot use SLOWDOWN and requires QUICKHOME
- */
- #if IS_SCARA
- #undef SLOWDOWN
- #define QUICK_HOME
- #endif
-
- /**
- * Set the home position based on settings or manual overrides
- */
- #ifdef MANUAL_X_HOME_POS
- #define X_HOME_POS MANUAL_X_HOME_POS
- #elif ENABLED(BED_CENTER_AT_0_0)
- #if ENABLED(DELTA)
- #define X_HOME_POS 0
- #else
- #define X_HOME_POS ((X_BED_SIZE) * (X_HOME_DIR) * 0.5)
- #endif
- #else
- #if ENABLED(DELTA)
- #define X_HOME_POS (X_MIN_POS + (X_BED_SIZE) * 0.5)
- #else
- #define X_HOME_POS (X_HOME_DIR < 0 ? X_MIN_POS : X_MAX_POS)
- #endif
- #endif
-
- #ifdef MANUAL_Y_HOME_POS
- #define Y_HOME_POS MANUAL_Y_HOME_POS
- #elif ENABLED(BED_CENTER_AT_0_0)
- #if ENABLED(DELTA)
- #define Y_HOME_POS 0
- #else
- #define Y_HOME_POS ((Y_BED_SIZE) * (Y_HOME_DIR) * 0.5)
- #endif
- #else
- #if ENABLED(DELTA)
- #define Y_HOME_POS (Y_MIN_POS + (Y_BED_SIZE) * 0.5)
- #else
- #define Y_HOME_POS (Y_HOME_DIR < 0 ? Y_MIN_POS : Y_MAX_POS)
- #endif
- #endif
-
- #ifdef MANUAL_Z_HOME_POS
- #define Z_HOME_POS MANUAL_Z_HOME_POS
- #else
- #define Z_HOME_POS (Z_HOME_DIR < 0 ? Z_MIN_POS : Z_MAX_POS)
- #endif
-
- /**
- * If DELTA_HEIGHT isn't defined use the old setting
- */
- #if ENABLED(DELTA) && !defined(DELTA_HEIGHT)
- #define DELTA_HEIGHT Z_HOME_POS
- #endif
-
- /**
- * Auto Bed Leveling and Z Probe Repeatability Test
- */
- #define HOMING_Z_WITH_PROBE (HAS_BED_PROBE && Z_HOME_DIR < 0 && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN))
-
- /**
- * Z Sled Probe requires Z_SAFE_HOMING
- */
- #if ENABLED(Z_PROBE_SLED)
- #define Z_SAFE_HOMING
- #endif
-
- /**
- * DELTA should ignore Z_SAFE_HOMING and SLOWDOWN
- */
+/**
+ * Set the home position based on settings or manual overrides
+ */
+#ifdef MANUAL_X_HOME_POS
+ #define X_HOME_POS MANUAL_X_HOME_POS
+#elif ENABLED(BED_CENTER_AT_0_0)
#if ENABLED(DELTA)
- #undef Z_SAFE_HOMING
- #undef SLOWDOWN
- #endif
-
- /**
- * Safe Homing Options
- */
- #if ENABLED(Z_SAFE_HOMING)
- #ifndef Z_SAFE_HOMING_X_POINT
- #define Z_SAFE_HOMING_X_POINT X_CENTER
- #endif
- #ifndef Z_SAFE_HOMING_Y_POINT
- #define Z_SAFE_HOMING_Y_POINT Y_CENTER
- #endif
- #define X_TILT_FULCRUM Z_SAFE_HOMING_X_POINT
- #define Y_TILT_FULCRUM Z_SAFE_HOMING_Y_POINT
+ #define X_HOME_POS 0
#else
- #define X_TILT_FULCRUM X_HOME_POS
- #define Y_TILT_FULCRUM Y_HOME_POS
+ #define X_HOME_POS ((X_BED_SIZE) * (X_HOME_DIR) * 0.5)
#endif
-
- /**
- * Host keep alive
- */
- #ifndef DEFAULT_KEEPALIVE_INTERVAL
- #define DEFAULT_KEEPALIVE_INTERVAL 2
- #endif
-
- /**
- * Provide a MAX_AUTORETRACT for older configs
- */
- #if ENABLED(FWRETRACT) && !defined(MAX_AUTORETRACT)
- #define MAX_AUTORETRACT 99
- #endif
-
- /**
- * MAX_STEP_FREQUENCY differs for TOSHIBA
- */
- #if ENABLED(CONFIG_STEPPERS_TOSHIBA)
- #define MAX_STEP_FREQUENCY 10000 // Max step frequency for Toshiba Stepper Controllers
+#else
+ #if ENABLED(DELTA)
+ #define X_HOME_POS (X_MIN_POS + (X_BED_SIZE) * 0.5)
#else
- #define MAX_STEP_FREQUENCY 40000 // Max step frequency for Ultimaker (5000 pps / half step)
+ #define X_HOME_POS (X_HOME_DIR < 0 ? X_MIN_POS : X_MAX_POS)
#endif
+#endif
- // MS1 MS2 Stepper Driver Microstepping mode table
- #define MICROSTEP1 LOW,LOW
- #if ENABLED(HEROIC_STEPPER_DRIVERS)
- #define MICROSTEP128 LOW,HIGH
+#ifdef MANUAL_Y_HOME_POS
+ #define Y_HOME_POS MANUAL_Y_HOME_POS
+#elif ENABLED(BED_CENTER_AT_0_0)
+ #if ENABLED(DELTA)
+ #define Y_HOME_POS 0
#else
- #define MICROSTEP2 HIGH,LOW
- #define MICROSTEP4 LOW,HIGH
+ #define Y_HOME_POS ((Y_BED_SIZE) * (Y_HOME_DIR) * 0.5)
#endif
- #define MICROSTEP8 HIGH,HIGH
- #define MICROSTEP16 HIGH,HIGH
+#else
+ #if ENABLED(DELTA)
+ #define Y_HOME_POS (Y_MIN_POS + (Y_BED_SIZE) * 0.5)
+ #else
+ #define Y_HOME_POS (Y_HOME_DIR < 0 ? Y_MIN_POS : Y_MAX_POS)
+ #endif
+#endif
- /**
- * Override here because this is set in Configuration_adv.h
- */
- #if ENABLED(ULTIPANEL) && DISABLED(ELB_FULL_GRAPHIC_CONTROLLER)
- #undef SD_DETECT_INVERTED
- #endif
+#ifdef MANUAL_Z_HOME_POS
+ #define Z_HOME_POS MANUAL_Z_HOME_POS
+#else
+ #define Z_HOME_POS (Z_HOME_DIR < 0 ? Z_MIN_POS : Z_MAX_POS)
+#endif
- /**
- * Set defaults for missing (newer) options
- */
- #ifndef DISABLE_INACTIVE_X
- #define DISABLE_INACTIVE_X DISABLE_X
- #endif
- #ifndef DISABLE_INACTIVE_Y
- #define DISABLE_INACTIVE_Y DISABLE_Y
- #endif
- #ifndef DISABLE_INACTIVE_Z
- #define DISABLE_INACTIVE_Z DISABLE_Z
- #endif
- #ifndef DISABLE_INACTIVE_E
- #define DISABLE_INACTIVE_E DISABLE_E
- #endif
+/**
+ * If DELTA_HEIGHT isn't defined use the old setting
+ */
+#if ENABLED(DELTA) && !defined(DELTA_HEIGHT)
+ #define DELTA_HEIGHT Z_HOME_POS
+#endif
- // Power Signal Control Definitions
- // By default use ATX definition
- #ifndef POWER_SUPPLY
- #define POWER_SUPPLY 1
+/**
+ * Z Sled Probe requires Z_SAFE_HOMING
+ */
+#if ENABLED(Z_PROBE_SLED)
+ #define Z_SAFE_HOMING
+#endif
+
+/**
+ * DELTA should ignore Z_SAFE_HOMING and SLOWDOWN
+ */
+#if ENABLED(DELTA)
+ #undef Z_SAFE_HOMING
+ #undef SLOWDOWN
+#endif
+
+/**
+ * Safe Homing Options
+ */
+#if ENABLED(Z_SAFE_HOMING)
+ #ifndef Z_SAFE_HOMING_X_POINT
+ #define Z_SAFE_HOMING_X_POINT X_CENTER
#endif
- #if (POWER_SUPPLY == 1) // 1 = ATX
- #define PS_ON_AWAKE LOW
- #define PS_ON_ASLEEP HIGH
- #elif (POWER_SUPPLY == 2) // 2 = X-Box 360 203W
- #define PS_ON_AWAKE HIGH
- #define PS_ON_ASLEEP LOW
+ #ifndef Z_SAFE_HOMING_Y_POINT
+ #define Z_SAFE_HOMING_Y_POINT Y_CENTER
#endif
- #define HAS_POWER_SWITCH (POWER_SUPPLY > 0 && PIN_EXISTS(PS_ON))
+ #define X_TILT_FULCRUM Z_SAFE_HOMING_X_POINT
+ #define Y_TILT_FULCRUM Z_SAFE_HOMING_Y_POINT
+#else
+ #define X_TILT_FULCRUM X_HOME_POS
+ #define Y_TILT_FULCRUM Y_HOME_POS
+#endif
- /**
- * Temp Sensor defines
- */
- #if TEMP_SENSOR_0 == -3
- #define HEATER_0_USES_MAX6675
- #define MAX6675_IS_MAX31855
- #define MAX6675_TMIN -270
- #define MAX6675_TMAX 1800
- #elif TEMP_SENSOR_0 == -2
- #define HEATER_0_USES_MAX6675
- #define MAX6675_TMIN 0
- #define MAX6675_TMAX 1024
- #elif TEMP_SENSOR_0 == -1
- #define HEATER_0_USES_AD595
- #elif TEMP_SENSOR_0 == 0
- #undef HEATER_0_MINTEMP
- #undef HEATER_0_MAXTEMP
- #elif TEMP_SENSOR_0 > 0
- #define THERMISTORHEATER_0 TEMP_SENSOR_0
- #define HEATER_0_USES_THERMISTOR
+/**
+ * Host keep alive
+ */
+#ifndef DEFAULT_KEEPALIVE_INTERVAL
+ #define DEFAULT_KEEPALIVE_INTERVAL 2
+#endif
+
+/**
+ * Provide a MAX_AUTORETRACT for older configs
+ */
+#if ENABLED(FWRETRACT) && !defined(MAX_AUTORETRACT)
+ #define MAX_AUTORETRACT 99
+#endif
+
+// MS1 MS2 Stepper Driver Microstepping mode table
+#define MICROSTEP1 LOW,LOW
+#if ENABLED(HEROIC_STEPPER_DRIVERS)
+ #define MICROSTEP128 LOW,HIGH
+#else
+ #define MICROSTEP2 HIGH,LOW
+ #define MICROSTEP4 LOW,HIGH
+#endif
+#define MICROSTEP8 HIGH,HIGH
+#define MICROSTEP16 HIGH,HIGH
+
+/**
+ * Override here because this is set in Configuration_adv.h
+ */
+#if ENABLED(ULTIPANEL) && DISABLED(ELB_FULL_GRAPHIC_CONTROLLER)
+ #undef SD_DETECT_INVERTED
+#endif
+
+/**
+ * Set defaults for missing (newer) options
+ */
+#ifndef DISABLE_INACTIVE_X
+ #define DISABLE_INACTIVE_X DISABLE_X
+#endif
+#ifndef DISABLE_INACTIVE_Y
+ #define DISABLE_INACTIVE_Y DISABLE_Y
+#endif
+#ifndef DISABLE_INACTIVE_Z
+ #define DISABLE_INACTIVE_Z DISABLE_Z
+#endif
+#ifndef DISABLE_INACTIVE_E
+ #define DISABLE_INACTIVE_E DISABLE_E
+#endif
+
+// Power Signal Control Definitions
+// By default use ATX definition
+#ifndef POWER_SUPPLY
+ #define POWER_SUPPLY 1
+#endif
+#if (POWER_SUPPLY == 1) // 1 = ATX
+ #define PS_ON_AWAKE LOW
+ #define PS_ON_ASLEEP HIGH
+#elif (POWER_SUPPLY == 2) // 2 = X-Box 360 203W
+ #define PS_ON_AWAKE HIGH
+ #define PS_ON_ASLEEP LOW
+#endif
+#define HAS_POWER_SWITCH (POWER_SUPPLY > 0 && PIN_EXISTS(PS_ON))
+
+/**
+ * Temp Sensor defines
+ */
+#if TEMP_SENSOR_0 == -4
+ #define HEATER_0_USES_AD8495
+#elif TEMP_SENSOR_0 == -3
+ #define HEATER_0_USES_MAX6675
+ #define MAX6675_IS_MAX31855
+ #define MAX6675_TMIN -270
+ #define MAX6675_TMAX 1800
+#elif TEMP_SENSOR_0 == -2
+ #define HEATER_0_USES_MAX6675
+ #define MAX6675_TMIN 0
+ #define MAX6675_TMAX 1024
+#elif TEMP_SENSOR_0 == -1
+ #define HEATER_0_USES_AD595
+#elif TEMP_SENSOR_0 == 0
+ #undef HEATER_0_MINTEMP
+ #undef HEATER_0_MAXTEMP
+#elif TEMP_SENSOR_0 > 0
+ #define THERMISTORHEATER_0 TEMP_SENSOR_0
+ #define HEATER_0_USES_THERMISTOR
+#endif
+
+#if TEMP_SENSOR_1 == -4
+ #define HEATER_1_USES_AD8495
+#elif TEMP_SENSOR_1 == -3
+ #error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_1."
+#elif TEMP_SENSOR_1 == -2
+ #error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_1."
+#elif TEMP_SENSOR_1 == -1
+ #define HEATER_1_USES_AD595
+#elif TEMP_SENSOR_1 == 0
+ #undef HEATER_1_MINTEMP
+ #undef HEATER_1_MAXTEMP
+#elif TEMP_SENSOR_1 > 0
+ #define THERMISTORHEATER_1 TEMP_SENSOR_1
+ #define HEATER_1_USES_THERMISTOR
+#endif
+
+#if TEMP_SENSOR_2 == -4
+ #define HEATER_2_USES_AD8495
+#elif TEMP_SENSOR_2 == -3
+ #error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_2."
+#elif TEMP_SENSOR_2 == -2
+ #error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_2."
+#elif TEMP_SENSOR_2 == -1
+ #define HEATER_2_USES_AD595
+#elif TEMP_SENSOR_2 == 0
+ #undef HEATER_2_MINTEMP
+ #undef HEATER_2_MAXTEMP
+#elif TEMP_SENSOR_2 > 0
+ #define THERMISTORHEATER_2 TEMP_SENSOR_2
+ #define HEATER_2_USES_THERMISTOR
+#endif
+
+#if TEMP_SENSOR_3 == -4
+ #define HEATER_3_USES_AD8495
+#elif TEMP_SENSOR_3 == -3
+ #error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_3."
+#elif TEMP_SENSOR_3 == -2
+ #error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_3."
+#elif TEMP_SENSOR_3 == -1
+ #define HEATER_3_USES_AD595
+#elif TEMP_SENSOR_3 == 0
+ #undef HEATER_3_MINTEMP
+ #undef HEATER_3_MAXTEMP
+#elif TEMP_SENSOR_3 > 0
+ #define THERMISTORHEATER_3 TEMP_SENSOR_3
+ #define HEATER_3_USES_THERMISTOR
+#endif
+
+#if TEMP_SENSOR_4 == -4
+ #define HEATER_4_USES_AD8495
+#elif TEMP_SENSOR_4 == -3
+ #error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_4."
+#elif TEMP_SENSOR_4 == -2
+ #error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_4."
+#elif TEMP_SENSOR_4 == -1
+ #define HEATER_4_USES_AD595
+#elif TEMP_SENSOR_4 == 0
+ #undef HEATER_4_MINTEMP
+ #undef HEATER_4_MAXTEMP
+#elif TEMP_SENSOR_4 > 0
+ #define THERMISTORHEATER_4 TEMP_SENSOR_4
+ #define HEATER_4_USES_THERMISTOR
+#endif
+
+#if TEMP_SENSOR_BED == -4
+ #define HEATER_BED_USES_AD8495
+#elif TEMP_SENSOR_BED == -3
+ #error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_BED."
+#elif TEMP_SENSOR_BED == -2
+ #error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_BED."
+#elif TEMP_SENSOR_BED == -1
+ #define HEATER_BED_USES_AD595
+#elif TEMP_SENSOR_BED == 0
+ #undef BED_MINTEMP
+ #undef BED_MAXTEMP
+#elif TEMP_SENSOR_BED > 0
+ #define THERMISTORBED TEMP_SENSOR_BED
+ #define HEATER_BED_USES_THERMISTOR
+#endif
+
+#if TEMP_SENSOR_CHAMBER == -4
+ #define HEATER_CHAMBER_USES_AD8495
+#elif TEMP_SENSOR_CHAMBER == -3
+ #error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_CHAMBER."
+#elif TEMP_SENSOR_CHAMBER == -2
+ #error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_CHAMBER."
+#elif TEMP_SENSOR_CHAMBER == -1
+ #define HEATER_CHAMBER_USES_AD595
+#elif TEMP_SENSOR_CHAMBER > 0
+ #define THERMISTORCHAMBER TEMP_SENSOR_CHAMBER
+ #define HEATER_CHAMBER_USES_THERMISTOR
+#endif
+
+#define HOTEND_USES_THERMISTOR (ENABLED(HEATER_0_USES_THERMISTOR) || ENABLED(HEATER_1_USES_THERMISTOR) || ENABLED(HEATER_2_USES_THERMISTOR) || ENABLED(HEATER_3_USES_THERMISTOR) || ENABLED(HEATER_4_USES_THERMISTOR))
+
+/**
+ * Default hotend offsets, if not defined
+ */
+#define HAS_HOTEND_OFFSET_Z (HOTENDS > 1 && (ENABLED(DUAL_X_CARRIAGE) || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER)))
+#if HOTENDS > 1
+ #ifndef HOTEND_OFFSET_X
+ #define HOTEND_OFFSET_X { 0 } // X offsets for each extruder
#endif
-
- #if TEMP_SENSOR_1 <= -2
- #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_1"
- #elif TEMP_SENSOR_1 == -1
- #define HEATER_1_USES_AD595
- #elif TEMP_SENSOR_1 == 0
- #undef HEATER_1_MINTEMP
- #undef HEATER_1_MAXTEMP
- #elif TEMP_SENSOR_1 > 0
- #define THERMISTORHEATER_1 TEMP_SENSOR_1
- #define HEATER_1_USES_THERMISTOR
+ #ifndef HOTEND_OFFSET_Y
+ #define HOTEND_OFFSET_Y { 0 } // Y offsets for each extruder
#endif
-
- #if TEMP_SENSOR_2 <= -2
- #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_2"
- #elif TEMP_SENSOR_2 == -1
- #define HEATER_2_USES_AD595
- #elif TEMP_SENSOR_2 == 0
- #undef HEATER_2_MINTEMP
- #undef HEATER_2_MAXTEMP
- #elif TEMP_SENSOR_2 > 0
- #define THERMISTORHEATER_2 TEMP_SENSOR_2
- #define HEATER_2_USES_THERMISTOR
+ #if HAS_HOTEND_OFFSET_Z && !defined(HOTEND_OFFSET_Z)
+ #define HOTEND_OFFSET_Z { 0 }
#endif
+#endif
- #if TEMP_SENSOR_3 <= -2
- #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_3"
- #elif TEMP_SENSOR_3 == -1
- #define HEATER_3_USES_AD595
- #elif TEMP_SENSOR_3 == 0
- #undef HEATER_3_MINTEMP
- #undef HEATER_3_MAXTEMP
- #elif TEMP_SENSOR_3 > 0
- #define THERMISTORHEATER_3 TEMP_SENSOR_3
- #define HEATER_3_USES_THERMISTOR
- #endif
+/**
+ * ARRAY_BY_EXTRUDERS based on EXTRUDERS
+ */
+#define ARRAY_BY_EXTRUDERS(...) ARRAY_N(EXTRUDERS, __VA_ARGS__)
+#define ARRAY_BY_EXTRUDERS1(v1) ARRAY_BY_EXTRUDERS(v1, v1, v1, v1, v1, v1)
- #if TEMP_SENSOR_4 <= -2
- #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_4"
- #elif TEMP_SENSOR_4 == -1
- #define HEATER_4_USES_AD595
- #elif TEMP_SENSOR_4 == 0
- #undef HEATER_4_MINTEMP
- #undef HEATER_4_MAXTEMP
- #elif TEMP_SENSOR_4 > 0
- #define THERMISTORHEATER_4 TEMP_SENSOR_4
- #define HEATER_4_USES_THERMISTOR
- #endif
+/**
+ * ARRAY_BY_HOTENDS based on HOTENDS
+ */
+#define ARRAY_BY_HOTENDS(...) ARRAY_N(HOTENDS, __VA_ARGS__)
+#define ARRAY_BY_HOTENDS1(v1) ARRAY_BY_HOTENDS(v1, v1, v1, v1, v1, v1)
- #if TEMP_SENSOR_BED <= -2
- #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_BED"
- #elif TEMP_SENSOR_BED == -1
- #define BED_USES_AD595
- #elif TEMP_SENSOR_BED == 0
- #undef BED_MINTEMP
- #undef BED_MAXTEMP
- #elif TEMP_SENSOR_BED > 0
- #define THERMISTORBED TEMP_SENSOR_BED
- #define BED_USES_THERMISTOR
- #endif
-
- #if TEMP_SENSOR_CHAMBER <= -2
- #error "MAX6675 / MAX31855 Thermocouples not supported for TEMP_SENSOR_CHAMBER"
- #elif TEMP_SENSOR_CHAMBER == -1
- #define CHAMBER_USES_AD595
- #elif TEMP_SENSOR_CHAMBER > 0
- #define THERMISTORCHAMBER TEMP_SENSOR_CHAMBER
- #define CHAMBER_USES_THERMISTOR
- #endif
-
- /**
- * Default hotend offsets, if not defined
- */
- #if HOTENDS > 1
- #ifndef HOTEND_OFFSET_X
- #define HOTEND_OFFSET_X { 0 } // X offsets for each extruder
- #endif
- #ifndef HOTEND_OFFSET_Y
- #define HOTEND_OFFSET_Y { 0 } // Y offsets for each extruder
- #endif
- #if !defined(HOTEND_OFFSET_Z) && (ENABLED(DUAL_X_CARRIAGE) || ENABLED(SWITCHING_NOZZLE))
- #define HOTEND_OFFSET_Z { 0 }
- #endif
- #endif
-
- /**
- * ARRAY_BY_EXTRUDERS based on EXTRUDERS
- */
- #define ARRAY_BY_EXTRUDERS(...) ARRAY_N(EXTRUDERS, __VA_ARGS__)
- #define ARRAY_BY_EXTRUDERS1(v1) ARRAY_BY_EXTRUDERS(v1, v1, v1, v1, v1, v1)
-
- /**
- * ARRAY_BY_HOTENDS based on HOTENDS
- */
- #define ARRAY_BY_HOTENDS(...) ARRAY_N(HOTENDS, __VA_ARGS__)
- #define ARRAY_BY_HOTENDS1(v1) ARRAY_BY_HOTENDS(v1, v1, v1, v1, v1, v1)
-
- /**
- * X_DUAL_ENDSTOPS endstop reassignment
- */
- #if ENABLED(X_DUAL_ENDSTOPS)
- #if X_HOME_DIR > 0
- #if X2_USE_ENDSTOP == _XMIN_
- #define X2_MAX_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
- #define X2_MAX_PIN X_MIN_PIN
- #elif X2_USE_ENDSTOP == _XMAX_
- #define X2_MAX_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
- #define X2_MAX_PIN X_MAX_PIN
- #elif X2_USE_ENDSTOP == _YMIN_
- #define X2_MAX_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
- #define X2_MAX_PIN Y_MIN_PIN
- #elif X2_USE_ENDSTOP == _YMAX_
- #define X2_MAX_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
- #define X2_MAX_PIN Y_MAX_PIN
- #elif X2_USE_ENDSTOP == _ZMIN_
- #define X2_MAX_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
- #define X2_MAX_PIN Z_MIN_PIN
- #elif X2_USE_ENDSTOP == _ZMAX_
- #define X2_MAX_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
- #define X2_MAX_PIN Z_MAX_PIN
- #else
- #define X2_MAX_ENDSTOP_INVERTING false
- #endif
- #define X2_MIN_ENDSTOP_INVERTING false
+/**
+ * X_DUAL_ENDSTOPS endstop reassignment
+ */
+#if ENABLED(X_DUAL_ENDSTOPS)
+ #if X_HOME_DIR > 0
+ #if X2_USE_ENDSTOP == _XMIN_
+ #define X2_MAX_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
+ #define X2_MAX_PIN X_MIN_PIN
+ #elif X2_USE_ENDSTOP == _XMAX_
+ #define X2_MAX_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
+ #define X2_MAX_PIN X_MAX_PIN
+ #elif X2_USE_ENDSTOP == _YMIN_
+ #define X2_MAX_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
+ #define X2_MAX_PIN Y_MIN_PIN
+ #elif X2_USE_ENDSTOP == _YMAX_
+ #define X2_MAX_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
+ #define X2_MAX_PIN Y_MAX_PIN
+ #elif X2_USE_ENDSTOP == _ZMIN_
+ #define X2_MAX_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
+ #define X2_MAX_PIN Z_MIN_PIN
+ #elif X2_USE_ENDSTOP == _ZMAX_
+ #define X2_MAX_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
+ #define X2_MAX_PIN Z_MAX_PIN
#else
- #if X2_USE_ENDSTOP == _XMIN_
- #define X2_MIN_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
- #define X2_MIN_PIN X_MIN_PIN
- #elif X2_USE_ENDSTOP == _XMAX_
- #define X2_MIN_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
- #define X2_MIN_PIN X_MAX_PIN
- #elif X2_USE_ENDSTOP == _YMIN_
- #define X2_MIN_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
- #define X2_MIN_PIN Y_MIN_PIN
- #elif X2_USE_ENDSTOP == _YMAX_
- #define X2_MIN_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
- #define X2_MIN_PIN Y_MAX_PIN
- #elif X2_USE_ENDSTOP == _ZMIN_
- #define X2_MIN_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
- #define X2_MIN_PIN Z_MIN_PIN
- #elif X2_USE_ENDSTOP == _ZMAX_
- #define X2_MIN_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
- #define X2_MIN_PIN Z_MAX_PIN
- #else
- #define X2_MIN_ENDSTOP_INVERTING false
- #endif
#define X2_MAX_ENDSTOP_INVERTING false
#endif
- #endif
-
- // Is an endstop plug used for the X2 endstop?
- #define IS_X2_ENDSTOP(A,M) (ENABLED(X_DUAL_ENDSTOPS) && X2_USE_ENDSTOP == _##A##M##_)
-
- /**
- * Y_DUAL_ENDSTOPS endstop reassignment
- */
- #if ENABLED(Y_DUAL_ENDSTOPS)
- #if Y_HOME_DIR > 0
- #if Y2_USE_ENDSTOP == _XMIN_
- #define Y2_MAX_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
- #define Y2_MAX_PIN X_MIN_PIN
- #elif Y2_USE_ENDSTOP == _XMAX_
- #define Y2_MAX_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
- #define Y2_MAX_PIN X_MAX_PIN
- #elif Y2_USE_ENDSTOP == _YMIN_
- #define Y2_MAX_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
- #define Y2_MAX_PIN Y_MIN_PIN
- #elif Y2_USE_ENDSTOP == _YMAX_
- #define Y2_MAX_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
- #define Y2_MAX_PIN Y_MAX_PIN
- #elif Y2_USE_ENDSTOP == _ZMIN_
- #define Y2_MAX_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
- #define Y2_MAX_PIN Z_MIN_PIN
- #elif Y2_USE_ENDSTOP == _ZMAX_
- #define Y2_MAX_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
- #define Y2_MAX_PIN Z_MAX_PIN
- #else
- #define Y2_MAX_ENDSTOP_INVERTING false
- #endif
- #define Y2_MIN_ENDSTOP_INVERTING false
+ #define X2_MIN_ENDSTOP_INVERTING false
+ #else
+ #if X2_USE_ENDSTOP == _XMIN_
+ #define X2_MIN_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
+ #define X2_MIN_PIN X_MIN_PIN
+ #elif X2_USE_ENDSTOP == _XMAX_
+ #define X2_MIN_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
+ #define X2_MIN_PIN X_MAX_PIN
+ #elif X2_USE_ENDSTOP == _YMIN_
+ #define X2_MIN_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
+ #define X2_MIN_PIN Y_MIN_PIN
+ #elif X2_USE_ENDSTOP == _YMAX_
+ #define X2_MIN_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
+ #define X2_MIN_PIN Y_MAX_PIN
+ #elif X2_USE_ENDSTOP == _ZMIN_
+ #define X2_MIN_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
+ #define X2_MIN_PIN Z_MIN_PIN
+ #elif X2_USE_ENDSTOP == _ZMAX_
+ #define X2_MIN_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
+ #define X2_MIN_PIN Z_MAX_PIN
+ #else
+ #define X2_MIN_ENDSTOP_INVERTING false
+ #endif
+ #define X2_MAX_ENDSTOP_INVERTING false
+ #endif
+#endif
+
+// Is an endstop plug used for the X2 endstop?
+#define IS_X2_ENDSTOP(A,M) (ENABLED(X_DUAL_ENDSTOPS) && X2_USE_ENDSTOP == _##A##M##_)
+
+/**
+ * Y_DUAL_ENDSTOPS endstop reassignment
+ */
+#if ENABLED(Y_DUAL_ENDSTOPS)
+ #if Y_HOME_DIR > 0
+ #if Y2_USE_ENDSTOP == _XMIN_
+ #define Y2_MAX_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
+ #define Y2_MAX_PIN X_MIN_PIN
+ #elif Y2_USE_ENDSTOP == _XMAX_
+ #define Y2_MAX_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
+ #define Y2_MAX_PIN X_MAX_PIN
+ #elif Y2_USE_ENDSTOP == _YMIN_
+ #define Y2_MAX_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
+ #define Y2_MAX_PIN Y_MIN_PIN
+ #elif Y2_USE_ENDSTOP == _YMAX_
+ #define Y2_MAX_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
+ #define Y2_MAX_PIN Y_MAX_PIN
+ #elif Y2_USE_ENDSTOP == _ZMIN_
+ #define Y2_MAX_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
+ #define Y2_MAX_PIN Z_MIN_PIN
+ #elif Y2_USE_ENDSTOP == _ZMAX_
+ #define Y2_MAX_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
+ #define Y2_MAX_PIN Z_MAX_PIN
#else
- #if Y2_USE_ENDSTOP == _XMIN_
- #define Y2_MIN_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
- #define Y2_MIN_PIN X_MIN_PIN
- #elif Y2_USE_ENDSTOP == _XMAX_
- #define Y2_MIN_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
- #define Y2_MIN_PIN X_MAX_PIN
- #elif Y2_USE_ENDSTOP == _YMIN_
- #define Y2_MIN_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
- #define Y2_MIN_PIN Y_MIN_PIN
- #elif Y2_USE_ENDSTOP == _YMAX_
- #define Y2_MIN_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
- #define Y2_MIN_PIN Y_MAX_PIN
- #elif Y2_USE_ENDSTOP == _ZMIN_
- #define Y2_MIN_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
- #define Y2_MIN_PIN Z_MIN_PIN
- #elif Y2_USE_ENDSTOP == _ZMAX_
- #define Y2_MIN_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
- #define Y2_MIN_PIN Z_MAX_PIN
- #else
- #define Y2_MIN_ENDSTOP_INVERTING false
- #endif
#define Y2_MAX_ENDSTOP_INVERTING false
#endif
- #endif
-
- // Is an endstop plug used for the Y2 endstop or the bed probe?
- #define IS_Y2_ENDSTOP(A,M) (ENABLED(Y_DUAL_ENDSTOPS) && Y2_USE_ENDSTOP == _##A##M##_)
-
- /**
- * Z_DUAL_ENDSTOPS endstop reassignment
- */
- #if ENABLED(Z_DUAL_ENDSTOPS)
- #if Z_HOME_DIR > 0
- #if Z2_USE_ENDSTOP == _XMIN_
- #define Z2_MAX_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
- #define Z2_MAX_PIN X_MIN_PIN
- #elif Z2_USE_ENDSTOP == _XMAX_
- #define Z2_MAX_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
- #define Z2_MAX_PIN X_MAX_PIN
- #elif Z2_USE_ENDSTOP == _YMIN_
- #define Z2_MAX_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
- #define Z2_MAX_PIN Y_MIN_PIN
- #elif Z2_USE_ENDSTOP == _YMAX_
- #define Z2_MAX_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
- #define Z2_MAX_PIN Y_MAX_PIN
- #elif Z2_USE_ENDSTOP == _ZMIN_
- #define Z2_MAX_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
- #define Z2_MAX_PIN Z_MIN_PIN
- #elif Z2_USE_ENDSTOP == _ZMAX_
- #define Z2_MAX_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
- #define Z2_MAX_PIN Z_MAX_PIN
- #else
- #define Z2_MAX_ENDSTOP_INVERTING false
- #endif
- #define Z2_MIN_ENDSTOP_INVERTING false
+ #define Y2_MIN_ENDSTOP_INVERTING false
+ #else
+ #if Y2_USE_ENDSTOP == _XMIN_
+ #define Y2_MIN_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
+ #define Y2_MIN_PIN X_MIN_PIN
+ #elif Y2_USE_ENDSTOP == _XMAX_
+ #define Y2_MIN_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
+ #define Y2_MIN_PIN X_MAX_PIN
+ #elif Y2_USE_ENDSTOP == _YMIN_
+ #define Y2_MIN_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
+ #define Y2_MIN_PIN Y_MIN_PIN
+ #elif Y2_USE_ENDSTOP == _YMAX_
+ #define Y2_MIN_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
+ #define Y2_MIN_PIN Y_MAX_PIN
+ #elif Y2_USE_ENDSTOP == _ZMIN_
+ #define Y2_MIN_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
+ #define Y2_MIN_PIN Z_MIN_PIN
+ #elif Y2_USE_ENDSTOP == _ZMAX_
+ #define Y2_MIN_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
+ #define Y2_MIN_PIN Z_MAX_PIN
+ #else
+ #define Y2_MIN_ENDSTOP_INVERTING false
+ #endif
+ #define Y2_MAX_ENDSTOP_INVERTING false
+ #endif
+#endif
+
+// Is an endstop plug used for the Y2 endstop or the bed probe?
+#define IS_Y2_ENDSTOP(A,M) (ENABLED(Y_DUAL_ENDSTOPS) && Y2_USE_ENDSTOP == _##A##M##_)
+
+/**
+ * Z_DUAL_ENDSTOPS endstop reassignment
+ */
+#if ENABLED(Z_DUAL_ENDSTOPS)
+ #if Z_HOME_DIR > 0
+ #if Z2_USE_ENDSTOP == _XMIN_
+ #define Z2_MAX_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
+ #define Z2_MAX_PIN X_MIN_PIN
+ #elif Z2_USE_ENDSTOP == _XMAX_
+ #define Z2_MAX_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
+ #define Z2_MAX_PIN X_MAX_PIN
+ #elif Z2_USE_ENDSTOP == _YMIN_
+ #define Z2_MAX_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
+ #define Z2_MAX_PIN Y_MIN_PIN
+ #elif Z2_USE_ENDSTOP == _YMAX_
+ #define Z2_MAX_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
+ #define Z2_MAX_PIN Y_MAX_PIN
+ #elif Z2_USE_ENDSTOP == _ZMIN_
+ #define Z2_MAX_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
+ #define Z2_MAX_PIN Z_MIN_PIN
+ #elif Z2_USE_ENDSTOP == _ZMAX_
+ #define Z2_MAX_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
+ #define Z2_MAX_PIN Z_MAX_PIN
#else
- #if Z2_USE_ENDSTOP == _XMIN_
- #define Z2_MIN_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
- #define Z2_MIN_PIN X_MIN_PIN
- #elif Z2_USE_ENDSTOP == _XMAX_
- #define Z2_MIN_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
- #define Z2_MIN_PIN X_MAX_PIN
- #elif Z2_USE_ENDSTOP == _YMIN_
- #define Z2_MIN_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
- #define Z2_MIN_PIN Y_MIN_PIN
- #elif Z2_USE_ENDSTOP == _YMAX_
- #define Z2_MIN_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
- #define Z2_MIN_PIN Y_MAX_PIN
- #elif Z2_USE_ENDSTOP == _ZMIN_
- #define Z2_MIN_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
- #define Z2_MIN_PIN Z_MIN_PIN
- #elif Z2_USE_ENDSTOP == _ZMAX_
- #define Z2_MIN_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
- #define Z2_MIN_PIN Z_MAX_PIN
- #else
- #define Z2_MIN_ENDSTOP_INVERTING false
- #endif
#define Z2_MAX_ENDSTOP_INVERTING false
#endif
+ #define Z2_MIN_ENDSTOP_INVERTING false
+ #else
+ #if Z2_USE_ENDSTOP == _XMIN_
+ #define Z2_MIN_ENDSTOP_INVERTING X_MIN_ENDSTOP_INVERTING
+ #define Z2_MIN_PIN X_MIN_PIN
+ #elif Z2_USE_ENDSTOP == _XMAX_
+ #define Z2_MIN_ENDSTOP_INVERTING X_MAX_ENDSTOP_INVERTING
+ #define Z2_MIN_PIN X_MAX_PIN
+ #elif Z2_USE_ENDSTOP == _YMIN_
+ #define Z2_MIN_ENDSTOP_INVERTING Y_MIN_ENDSTOP_INVERTING
+ #define Z2_MIN_PIN Y_MIN_PIN
+ #elif Z2_USE_ENDSTOP == _YMAX_
+ #define Z2_MIN_ENDSTOP_INVERTING Y_MAX_ENDSTOP_INVERTING
+ #define Z2_MIN_PIN Y_MAX_PIN
+ #elif Z2_USE_ENDSTOP == _ZMIN_
+ #define Z2_MIN_ENDSTOP_INVERTING Z_MIN_ENDSTOP_INVERTING
+ #define Z2_MIN_PIN Z_MIN_PIN
+ #elif Z2_USE_ENDSTOP == _ZMAX_
+ #define Z2_MIN_ENDSTOP_INVERTING Z_MAX_ENDSTOP_INVERTING
+ #define Z2_MIN_PIN Z_MAX_PIN
+ #else
+ #define Z2_MIN_ENDSTOP_INVERTING false
+ #endif
+ #define Z2_MAX_ENDSTOP_INVERTING false
#endif
+#endif
- // Is an endstop plug used for the Z2 endstop or the bed probe?
- #define IS_Z2_OR_PROBE(A,M) ( \
- (ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP == _##A##M##_) \
- || (ENABLED(Z_MIN_PROBE_ENDSTOP) && Z_MIN_PROBE_PIN == A##_##M##_PIN ) )
+// Is an endstop plug used for the Z2 endstop or the bed probe?
+#define IS_Z2_OR_PROBE(A,M) ( \
+ (ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP == _##A##M##_) \
+ || (ENABLED(Z_MIN_PROBE_ENDSTOP) && Z_MIN_PROBE_PIN == A##_##M##_PIN ) )
- /**
- * Set ENDSTOPPULLUPS for active endstop switches
- */
- #if ENABLED(ENDSTOPPULLUPS)
- #if ENABLED(USE_XMAX_PLUG)
- #define ENDSTOPPULLUP_XMAX
- #endif
- #if ENABLED(USE_YMAX_PLUG)
- #define ENDSTOPPULLUP_YMAX
- #endif
- #if ENABLED(USE_ZMAX_PLUG)
- #define ENDSTOPPULLUP_ZMAX
- #endif
- #if ENABLED(USE_XMIN_PLUG)
- #define ENDSTOPPULLUP_XMIN
- #endif
- #if ENABLED(USE_YMIN_PLUG)
- #define ENDSTOPPULLUP_YMIN
- #endif
- #if ENABLED(USE_ZMIN_PLUG)
- #define ENDSTOPPULLUP_ZMIN
- #endif
+/**
+ * Set ENDSTOPPULLUPS for active endstop switches
+ */
+#if ENABLED(ENDSTOPPULLUPS)
+ #if ENABLED(USE_XMAX_PLUG)
+ #define ENDSTOPPULLUP_XMAX
#endif
+ #if ENABLED(USE_YMAX_PLUG)
+ #define ENDSTOPPULLUP_YMAX
+ #endif
+ #if ENABLED(USE_ZMAX_PLUG)
+ #define ENDSTOPPULLUP_ZMAX
+ #endif
+ #if ENABLED(USE_XMIN_PLUG)
+ #define ENDSTOPPULLUP_XMIN
+ #endif
+ #if ENABLED(USE_YMIN_PLUG)
+ #define ENDSTOPPULLUP_YMIN
+ #endif
+ #if ENABLED(USE_ZMIN_PLUG)
+ #define ENDSTOPPULLUP_ZMIN
+ #endif
+#endif
- /**
- * Shorthand for pin tests, used wherever needed
- */
+/**
+ * Shorthand for pin tests, used wherever needed
+ */
- // Steppers
- #define HAS_X_ENABLE (PIN_EXISTS(X_ENABLE))
- #define HAS_X_DIR (PIN_EXISTS(X_DIR))
- #define HAS_X_STEP (PIN_EXISTS(X_STEP))
- #define HAS_X_MICROSTEPS (PIN_EXISTS(X_MS1))
+// Steppers
+#define HAS_X_ENABLE (PIN_EXISTS(X_ENABLE))
+#define HAS_X_DIR (PIN_EXISTS(X_DIR))
+#define HAS_X_STEP (PIN_EXISTS(X_STEP))
+#define HAS_X_MICROSTEPS (PIN_EXISTS(X_MS1))
- #define HAS_X2_ENABLE (PIN_EXISTS(X2_ENABLE))
- #define HAS_X2_DIR (PIN_EXISTS(X2_DIR))
- #define HAS_X2_STEP (PIN_EXISTS(X2_STEP))
- #define HAS_Y_MICROSTEPS (PIN_EXISTS(Y_MS1))
+#define HAS_X2_ENABLE (PIN_EXISTS(X2_ENABLE))
+#define HAS_X2_DIR (PIN_EXISTS(X2_DIR))
+#define HAS_X2_STEP (PIN_EXISTS(X2_STEP))
+#define HAS_X2_MICROSTEPS (PIN_EXISTS(X2_MS1))
- #define HAS_Y_ENABLE (PIN_EXISTS(Y_ENABLE))
- #define HAS_Y_DIR (PIN_EXISTS(Y_DIR))
- #define HAS_Y_STEP (PIN_EXISTS(Y_STEP))
- #define HAS_Z_MICROSTEPS (PIN_EXISTS(Z_MS1))
+#define HAS_Y_ENABLE (PIN_EXISTS(Y_ENABLE))
+#define HAS_Y_DIR (PIN_EXISTS(Y_DIR))
+#define HAS_Y_STEP (PIN_EXISTS(Y_STEP))
+#define HAS_Y_MICROSTEPS (PIN_EXISTS(Y_MS1))
- #define HAS_Y2_ENABLE (PIN_EXISTS(Y2_ENABLE))
- #define HAS_Y2_DIR (PIN_EXISTS(Y2_DIR))
- #define HAS_Y2_STEP (PIN_EXISTS(Y2_STEP))
+#define HAS_Y2_ENABLE (PIN_EXISTS(Y2_ENABLE))
+#define HAS_Y2_DIR (PIN_EXISTS(Y2_DIR))
+#define HAS_Y2_STEP (PIN_EXISTS(Y2_STEP))
+#define HAS_Y2_MICROSTEPS (PIN_EXISTS(Y2_MS1))
- #define HAS_Z_ENABLE (PIN_EXISTS(Z_ENABLE))
- #define HAS_Z_DIR (PIN_EXISTS(Z_DIR))
- #define HAS_Z_STEP (PIN_EXISTS(Z_STEP))
+#define HAS_Z_ENABLE (PIN_EXISTS(Z_ENABLE))
+#define HAS_Z_DIR (PIN_EXISTS(Z_DIR))
+#define HAS_Z_STEP (PIN_EXISTS(Z_STEP))
+#define HAS_Z_MICROSTEPS (PIN_EXISTS(Z_MS1))
- #define HAS_Z2_ENABLE (PIN_EXISTS(Z2_ENABLE))
- #define HAS_Z2_DIR (PIN_EXISTS(Z2_DIR))
- #define HAS_Z2_STEP (PIN_EXISTS(Z2_STEP))
+#define HAS_Z2_ENABLE (PIN_EXISTS(Z2_ENABLE))
+#define HAS_Z2_DIR (PIN_EXISTS(Z2_DIR))
+#define HAS_Z2_STEP (PIN_EXISTS(Z2_STEP))
+#define HAS_Z2_MICROSTEPS (PIN_EXISTS(Z2_MS1))
- // Extruder steppers and solenoids
- #define HAS_E0_ENABLE (PIN_EXISTS(E0_ENABLE))
- #define HAS_E0_DIR (PIN_EXISTS(E0_DIR))
- #define HAS_E0_STEP (PIN_EXISTS(E0_STEP))
- #define HAS_E0_MICROSTEPS (PIN_EXISTS(E0_MS1))
- #define HAS_SOLENOID_0 (PIN_EXISTS(SOL0))
+// Extruder steppers and solenoids
+#define HAS_E0_ENABLE (PIN_EXISTS(E0_ENABLE))
+#define HAS_E0_DIR (PIN_EXISTS(E0_DIR))
+#define HAS_E0_STEP (PIN_EXISTS(E0_STEP))
+#define HAS_E0_MICROSTEPS (PIN_EXISTS(E0_MS1))
+#define HAS_SOLENOID_0 (PIN_EXISTS(SOL0))
- #define HAS_E1_ENABLE (PIN_EXISTS(E1_ENABLE))
- #define HAS_E1_DIR (PIN_EXISTS(E1_DIR))
- #define HAS_E1_STEP (PIN_EXISTS(E1_STEP))
- #define HAS_E1_MICROSTEPS (PIN_EXISTS(E1_MS1))
- #define HAS_SOLENOID_1 (PIN_EXISTS(SOL1))
+#define HAS_E1_ENABLE (PIN_EXISTS(E1_ENABLE))
+#define HAS_E1_DIR (PIN_EXISTS(E1_DIR))
+#define HAS_E1_STEP (PIN_EXISTS(E1_STEP))
+#define HAS_E1_MICROSTEPS (PIN_EXISTS(E1_MS1))
+#define HAS_SOLENOID_1 (PIN_EXISTS(SOL1))
- #define HAS_E2_ENABLE (PIN_EXISTS(E2_ENABLE))
- #define HAS_E2_DIR (PIN_EXISTS(E2_DIR))
- #define HAS_E2_STEP (PIN_EXISTS(E2_STEP))
- #define HAS_E2_MICROSTEPS (PIN_EXISTS(E2_MS1))
- #define HAS_SOLENOID_2 (PIN_EXISTS(SOL2))
+#define HAS_E2_ENABLE (PIN_EXISTS(E2_ENABLE))
+#define HAS_E2_DIR (PIN_EXISTS(E2_DIR))
+#define HAS_E2_STEP (PIN_EXISTS(E2_STEP))
+#define HAS_E2_MICROSTEPS (PIN_EXISTS(E2_MS1))
+#define HAS_SOLENOID_2 (PIN_EXISTS(SOL2))
- #define HAS_E3_ENABLE (PIN_EXISTS(E3_ENABLE))
- #define HAS_E3_DIR (PIN_EXISTS(E3_DIR))
- #define HAS_E3_STEP (PIN_EXISTS(E3_STEP))
- #define HAS_E3_MICROSTEPS (PIN_EXISTS(E3_MS1))
- #define HAS_SOLENOID_3 (PIN_EXISTS(SOL3))
+#define HAS_E3_ENABLE (PIN_EXISTS(E3_ENABLE))
+#define HAS_E3_DIR (PIN_EXISTS(E3_DIR))
+#define HAS_E3_STEP (PIN_EXISTS(E3_STEP))
+#define HAS_E3_MICROSTEPS (PIN_EXISTS(E3_MS1))
+#define HAS_SOLENOID_3 (PIN_EXISTS(SOL3))
- #define HAS_E4_ENABLE (PIN_EXISTS(E4_ENABLE))
- #define HAS_E4_DIR (PIN_EXISTS(E4_DIR))
- #define HAS_E4_STEP (PIN_EXISTS(E4_STEP))
- #define HAS_E4_MICROSTEPS (PIN_EXISTS(E4_MS1))
- #define HAS_SOLENOID_4 (PIN_EXISTS(SOL4))
+#define HAS_E4_ENABLE (PIN_EXISTS(E4_ENABLE))
+#define HAS_E4_DIR (PIN_EXISTS(E4_DIR))
+#define HAS_E4_STEP (PIN_EXISTS(E4_STEP))
+#define HAS_E4_MICROSTEPS (PIN_EXISTS(E4_MS1))
+#define HAS_SOLENOID_4 (PIN_EXISTS(SOL4))
- // Trinamic Stepper Drivers
- #define HAS_TRINAMIC (ENABLED(HAVE_TMC2130) || ENABLED(HAVE_TMC2208) || ENABLED(IS_TRAMS))
- #define X_IS_TRINAMIC (ENABLED( X_IS_TMC2130) || ENABLED( X_IS_TMC2208) || ENABLED(IS_TRAMS))
- #define X2_IS_TRINAMIC (ENABLED(X2_IS_TMC2130) || ENABLED(X2_IS_TMC2208))
- #define Y_IS_TRINAMIC (ENABLED( Y_IS_TMC2130) || ENABLED( Y_IS_TMC2208) || ENABLED(IS_TRAMS))
- #define Y2_IS_TRINAMIC (ENABLED(Y2_IS_TMC2130) || ENABLED(Y2_IS_TMC2208))
- #define Z_IS_TRINAMIC (ENABLED( Z_IS_TMC2130) || ENABLED( Z_IS_TMC2208) || ENABLED(IS_TRAMS))
- #define Z2_IS_TRINAMIC (ENABLED(Z2_IS_TMC2130) || ENABLED(Z2_IS_TMC2208))
- #define E0_IS_TRINAMIC (ENABLED(E0_IS_TMC2130) || ENABLED(E0_IS_TMC2208) || ENABLED(IS_TRAMS))
- #define E1_IS_TRINAMIC (ENABLED(E1_IS_TMC2130) || ENABLED(E1_IS_TMC2208))
- #define E2_IS_TRINAMIC (ENABLED(E2_IS_TMC2130) || ENABLED(E2_IS_TMC2208))
- #define E3_IS_TRINAMIC (ENABLED(E3_IS_TMC2130) || ENABLED(E3_IS_TMC2208))
- #define E4_IS_TRINAMIC (ENABLED(E4_IS_TMC2130) || ENABLED(E4_IS_TMC2208))
+// Trinamic Stepper Drivers
+#define HAS_TRINAMIC (ENABLED(HAVE_TMC2130) || ENABLED(HAVE_TMC2208) || ENABLED(IS_TRAMS))
+#define X_IS_TRINAMIC (ENABLED( X_IS_TMC2130) || ENABLED( X_IS_TMC2208) || ENABLED(IS_TRAMS))
+#define X2_IS_TRINAMIC (ENABLED(X2_IS_TMC2130) || ENABLED(X2_IS_TMC2208))
+#define Y_IS_TRINAMIC (ENABLED( Y_IS_TMC2130) || ENABLED( Y_IS_TMC2208) || ENABLED(IS_TRAMS))
+#define Y2_IS_TRINAMIC (ENABLED(Y2_IS_TMC2130) || ENABLED(Y2_IS_TMC2208))
+#define Z_IS_TRINAMIC (ENABLED( Z_IS_TMC2130) || ENABLED( Z_IS_TMC2208) || ENABLED(IS_TRAMS))
+#define Z2_IS_TRINAMIC (ENABLED(Z2_IS_TMC2130) || ENABLED(Z2_IS_TMC2208))
+#define E0_IS_TRINAMIC (ENABLED(E0_IS_TMC2130) || ENABLED(E0_IS_TMC2208) || ENABLED(IS_TRAMS))
+#define E1_IS_TRINAMIC (ENABLED(E1_IS_TMC2130) || ENABLED(E1_IS_TMC2208))
+#define E2_IS_TRINAMIC (ENABLED(E2_IS_TMC2130) || ENABLED(E2_IS_TMC2208))
+#define E3_IS_TRINAMIC (ENABLED(E3_IS_TMC2130) || ENABLED(E3_IS_TMC2208))
+#define E4_IS_TRINAMIC (ENABLED(E4_IS_TMC2130) || ENABLED(E4_IS_TMC2208))
+#if ENABLED(SENSORLESS_HOMING)
// Disable Z axis sensorless homing if a probe is used to home the Z axis
- #if ENABLED(SENSORLESS_HOMING)
- #define X_SENSORLESS (ENABLED(X_IS_TMC2130) && defined(X_HOMING_SENSITIVITY))
- #define Y_SENSORLESS (ENABLED(Y_IS_TMC2130) && defined(Y_HOMING_SENSITIVITY))
- #define Z_SENSORLESS (ENABLED(Z_IS_TMC2130) && defined(Z_HOMING_SENSITIVITY))
- #if HOMING_Z_WITH_PROBE
- #undef Z_HOMING_SENSITIVITY
+ #if HOMING_Z_WITH_PROBE
+ #undef Z_HOMING_SENSITIVITY
+ #endif
+ #define X_SENSORLESS (ENABLED(X_IS_TMC2130) && defined(X_HOMING_SENSITIVITY))
+ #define Y_SENSORLESS (ENABLED(Y_IS_TMC2130) && defined(Y_HOMING_SENSITIVITY))
+ #define Z_SENSORLESS (ENABLED(Z_IS_TMC2130) && defined(Z_HOMING_SENSITIVITY))
+#endif
+
+// Endstops and bed probe
+#define HAS_STOP_TEST(A,M) (PIN_EXISTS(A##_##M) && !IS_X2_ENDSTOP(A,M) && !IS_Y2_ENDSTOP(A,M) && !IS_Z2_OR_PROBE(A,M))
+#define HAS_X_MIN HAS_STOP_TEST(X,MIN)
+#define HAS_X_MAX HAS_STOP_TEST(X,MAX)
+#define HAS_Y_MIN HAS_STOP_TEST(Y,MIN)
+#define HAS_Y_MAX HAS_STOP_TEST(Y,MAX)
+#define HAS_Z_MIN HAS_STOP_TEST(Z,MIN)
+#define HAS_Z_MAX HAS_STOP_TEST(Z,MAX)
+#define HAS_X2_MIN (PIN_EXISTS(X2_MIN))
+#define HAS_X2_MAX (PIN_EXISTS(X2_MAX))
+#define HAS_Y2_MIN (PIN_EXISTS(Y2_MIN))
+#define HAS_Y2_MAX (PIN_EXISTS(Y2_MAX))
+#define HAS_Z2_MIN (PIN_EXISTS(Z2_MIN))
+#define HAS_Z2_MAX (PIN_EXISTS(Z2_MAX))
+#define HAS_Z_MIN_PROBE_PIN (PIN_EXISTS(Z_MIN_PROBE))
+
+// ADC Temp Sensors (Thermistor or Thermocouple with amplifier ADC interface)
+#define HAS_ADC_TEST(P) (PIN_EXISTS(TEMP_##P) && TEMP_SENSOR_##P != 0 && DISABLED(HEATER_##P##_USES_MAX6675))
+#define HAS_TEMP_ADC_0 HAS_ADC_TEST(0)
+#define HAS_TEMP_ADC_1 HAS_ADC_TEST(1)
+#define HAS_TEMP_ADC_2 HAS_ADC_TEST(2)
+#define HAS_TEMP_ADC_3 HAS_ADC_TEST(3)
+#define HAS_TEMP_ADC_4 HAS_ADC_TEST(4)
+#define HAS_TEMP_ADC_BED HAS_ADC_TEST(BED)
+#define HAS_TEMP_ADC_CHAMBER HAS_ADC_TEST(CHAMBER)
+
+#define HAS_TEMP_HOTEND (HAS_TEMP_ADC_0 || ENABLED(HEATER_0_USES_MAX6675))
+#define HAS_TEMP_BED HAS_TEMP_ADC_BED
+#define HAS_TEMP_CHAMBER HAS_TEMP_ADC_CHAMBER
+
+// Heaters
+#define HAS_HEATER_0 (PIN_EXISTS(HEATER_0))
+#define HAS_HEATER_1 (PIN_EXISTS(HEATER_1))
+#define HAS_HEATER_2 (PIN_EXISTS(HEATER_2))
+#define HAS_HEATER_3 (PIN_EXISTS(HEATER_3))
+#define HAS_HEATER_4 (PIN_EXISTS(HEATER_4))
+#define HAS_HEATER_BED (PIN_EXISTS(HEATER_BED))
+
+// Shorthand for common combinations
+#define HAS_HEATED_BED (HAS_TEMP_BED && HAS_HEATER_BED)
+#define HAS_TEMP_SENSOR (HAS_TEMP_HOTEND || HAS_HEATED_BED || HAS_TEMP_CHAMBER)
+
+// PID heating
+#if !HAS_HEATED_BED
+ #undef PIDTEMPBED
+#endif
+#define HAS_PID_HEATING (ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED))
+#define HAS_PID_FOR_BOTH (ENABLED(PIDTEMP) && ENABLED(PIDTEMPBED))
+
+// Thermal protection
+#define HAS_THERMALLY_PROTECTED_BED (HAS_HEATED_BED && ENABLED(THERMAL_PROTECTION_BED))
+#define WATCH_HOTENDS (ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0)
+#define WATCH_THE_BED (HAS_THERMALLY_PROTECTED_BED && WATCH_BED_TEMP_PERIOD > 0)
+
+// Auto fans
+#define HAS_AUTO_FAN_0 (PIN_EXISTS(E0_AUTO_FAN))
+#define HAS_AUTO_FAN_1 (HOTENDS > 1 && PIN_EXISTS(E1_AUTO_FAN))
+#define HAS_AUTO_FAN_2 (HOTENDS > 2 && PIN_EXISTS(E2_AUTO_FAN))
+#define HAS_AUTO_FAN_3 (HOTENDS > 3 && PIN_EXISTS(E3_AUTO_FAN))
+#define HAS_AUTO_FAN_4 (HOTENDS > 4 && PIN_EXISTS(E4_AUTO_FAN))
+#define HAS_AUTO_CHAMBER_FAN (PIN_EXISTS(CHAMBER_AUTO_FAN))
+#define HAS_AUTO_FAN (HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3 || HAS_AUTO_CHAMBER_FAN)
+#define AUTO_1_IS_0 (E1_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
+#define AUTO_2_IS_0 (E2_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
+#define AUTO_2_IS_1 (E2_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
+#define AUTO_3_IS_0 (E3_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
+#define AUTO_3_IS_1 (E3_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
+#define AUTO_3_IS_2 (E3_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
+#define AUTO_4_IS_0 (E4_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
+#define AUTO_4_IS_1 (E4_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
+#define AUTO_4_IS_2 (E4_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
+#define AUTO_4_IS_3 (E4_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
+#define AUTO_CHAMBER_IS_0 (CHAMBER_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
+#define AUTO_CHAMBER_IS_1 (CHAMBER_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
+#define AUTO_CHAMBER_IS_2 (CHAMBER_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
+#define AUTO_CHAMBER_IS_3 (CHAMBER_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
+#define AUTO_CHAMBER_IS_4 (CHAMBER_AUTO_FAN_PIN == E4_AUTO_FAN_PIN)
+
+// Other fans
+#define HAS_FAN0 (PIN_EXISTS(FAN))
+#define HAS_FAN1 (PIN_EXISTS(FAN1) && CONTROLLER_FAN_PIN != FAN1_PIN && E0_AUTO_FAN_PIN != FAN1_PIN && E1_AUTO_FAN_PIN != FAN1_PIN && E2_AUTO_FAN_PIN != FAN1_PIN && E3_AUTO_FAN_PIN != FAN1_PIN)
+#define HAS_FAN2 (PIN_EXISTS(FAN2) && CONTROLLER_FAN_PIN != FAN2_PIN && E0_AUTO_FAN_PIN != FAN2_PIN && E1_AUTO_FAN_PIN != FAN2_PIN && E2_AUTO_FAN_PIN != FAN2_PIN && E3_AUTO_FAN_PIN != FAN2_PIN)
+#define HAS_CONTROLLER_FAN (PIN_EXISTS(CONTROLLER_FAN))
+
+// Servos
+#define HAS_SERVO_0 (PIN_EXISTS(SERVO0))
+#define HAS_SERVO_1 (PIN_EXISTS(SERVO1))
+#define HAS_SERVO_2 (PIN_EXISTS(SERVO2))
+#define HAS_SERVO_3 (PIN_EXISTS(SERVO3))
+#define HAS_SERVOS (defined(NUM_SERVOS) && NUM_SERVOS > 0 && (HAS_SERVO_0 || HAS_SERVO_1 || HAS_SERVO_2 || HAS_SERVO_3))
+
+#if HAS_SERVOS && !defined(Z_PROBE_SERVO_NR)
+ #define Z_PROBE_SERVO_NR -1
+#endif
+
+// Sensors
+#define HAS_FILAMENT_WIDTH_SENSOR (PIN_EXISTS(FILWIDTH))
+
+// User Interface
+#define HAS_HOME (PIN_EXISTS(HOME))
+#define HAS_KILL (PIN_EXISTS(KILL))
+#define HAS_SUICIDE (PIN_EXISTS(SUICIDE))
+#define HAS_PHOTOGRAPH (PIN_EXISTS(PHOTOGRAPH))
+#define HAS_BUZZER (PIN_EXISTS(BEEPER) || ENABLED(LCD_USE_I2C_BUZZER))
+#define HAS_CASE_LIGHT (PIN_EXISTS(CASE_LIGHT) && ENABLED(CASE_LIGHT_ENABLE))
+
+// Digital control
+#define HAS_MICROSTEPS (HAS_X_MICROSTEPS || HAS_Y_MICROSTEPS || HAS_Z_MICROSTEPS || HAS_E0_MICROSTEPS || HAS_E1_MICROSTEPS || HAS_E2_MICROSTEPS || HAS_E3_MICROSTEPS || HAS_E4_MICROSTEPS)
+#define HAS_STEPPER_RESET (PIN_EXISTS(STEPPER_RESET))
+#define HAS_DIGIPOTSS (PIN_EXISTS(DIGIPOTSS))
+#define HAS_MOTOR_CURRENT_PWM (PIN_EXISTS(MOTOR_CURRENT_PWM_XY) || PIN_EXISTS(MOTOR_CURRENT_PWM_Z) || PIN_EXISTS(MOTOR_CURRENT_PWM_E))
+
+#if !HAS_TEMP_SENSOR
+ #undef AUTO_REPORT_TEMPERATURES
+#endif
+
+#define HAS_AUTO_REPORTING (ENABLED(AUTO_REPORT_TEMPERATURES) || ENABLED(AUTO_REPORT_SD_STATUS))
+
+/**
+ * This setting is also used by M109 when trying to calculate
+ * a ballpark safe margin to prevent wait-forever situation.
+ */
+#ifndef EXTRUDE_MINTEMP
+ #define EXTRUDE_MINTEMP 170
+#endif
+
+/**
+ * Helper Macros for heaters and extruder fan
+ */
+#define WRITE_HEATER_0P(v) WRITE(HEATER_0_PIN, v)
+#if HOTENDS > 1 || ENABLED(HEATERS_PARALLEL)
+ #define WRITE_HEATER_1(v) WRITE(HEATER_1_PIN, v)
+ #if HOTENDS > 2
+ #define WRITE_HEATER_2(v) WRITE(HEATER_2_PIN, v)
+ #if HOTENDS > 3
+ #define WRITE_HEATER_3(v) WRITE(HEATER_3_PIN, v)
+ #if HOTENDS > 4
+ #define WRITE_HEATER_4(v) WRITE(HEATER_4_PIN, v)
+ #endif // HOTENDS > 4
+ #endif // HOTENDS > 3
+ #endif // HOTENDS > 2
+#endif // HOTENDS > 1
+#if ENABLED(HEATERS_PARALLEL)
+ #define WRITE_HEATER_0(v) { WRITE_HEATER_0P(v); WRITE_HEATER_1(v); }
+#else
+ #define WRITE_HEATER_0(v) WRITE_HEATER_0P(v)
+#endif
+
+/**
+ * Heated bed requires settings
+ */
+#if HAS_HEATED_BED
+ #ifndef MAX_BED_POWER
+ #define MAX_BED_POWER 255
+ #endif
+ #ifndef HEATER_BED_INVERTING
+ #define HEATER_BED_INVERTING false
+ #endif
+ #define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, (v) ^ HEATER_BED_INVERTING)
+#endif
+
+/**
+ * Up to 3 PWM fans
+ */
+#if HAS_FAN2
+ #define FAN_COUNT 3
+#elif HAS_FAN1
+ #define FAN_COUNT 2
+#elif HAS_FAN0
+ #define FAN_COUNT 1
+#else
+ #define FAN_COUNT 0
+#endif
+
+#if HAS_FAN0
+ #define WRITE_FAN(v) WRITE(FAN_PIN, v)
+ #define WRITE_FAN0(v) WRITE_FAN(v)
+#endif
+#if HAS_FAN1
+ #define WRITE_FAN1(v) WRITE(FAN1_PIN, v)
+#endif
+#if HAS_FAN2
+ #define WRITE_FAN2(v) WRITE(FAN2_PIN, v)
+#endif
+#define WRITE_FAN_N(n, v) WRITE_FAN##n(v)
+
+/**
+ * Part Cooling fan multipliexer
+ */
+#define HAS_FANMUX PIN_EXISTS(FANMUX0)
+
+/**
+ * MIN/MAX fan PWM scaling
+ */
+#ifndef FAN_MIN_PWM
+ #define FAN_MIN_PWM 0
+#endif
+#ifndef FAN_MAX_PWM
+ #define FAN_MAX_PWM 255
+#endif
+#if FAN_MIN_PWM < 0 || FAN_MIN_PWM > 255
+ #error "FAN_MIN_PWM must be a value from 0 to 255."
+#elif FAN_MAX_PWM < 0 || FAN_MAX_PWM > 255
+ #error "FAN_MAX_PWM must be a value from 0 to 255."
+#elif FAN_MIN_PWM > FAN_MAX_PWM
+ #error "FAN_MIN_PWM must be less than or equal to FAN_MAX_PWM."
+#endif
+
+/**
+ * Bed Probe dependencies
+ */
+#if HAS_BED_PROBE
+ #if ENABLED(ENDSTOPPULLUPS) && HAS_Z_MIN_PROBE_PIN
+ #define ENDSTOPPULLUP_ZMIN_PROBE
+ #endif
+ #ifndef Z_PROBE_OFFSET_RANGE_MIN
+ #define Z_PROBE_OFFSET_RANGE_MIN -20
+ #endif
+ #ifndef Z_PROBE_OFFSET_RANGE_MAX
+ #define Z_PROBE_OFFSET_RANGE_MAX 20
+ #endif
+ #ifndef XY_PROBE_SPEED
+ #ifdef HOMING_FEEDRATE_XY
+ #define XY_PROBE_SPEED HOMING_FEEDRATE_XY
+ #else
+ #define XY_PROBE_SPEED 4000
#endif
#endif
+#else
+ #undef X_PROBE_OFFSET_FROM_EXTRUDER
+ #undef Y_PROBE_OFFSET_FROM_EXTRUDER
+ #undef Z_PROBE_OFFSET_FROM_EXTRUDER
+ #define X_PROBE_OFFSET_FROM_EXTRUDER 0
+ #define Y_PROBE_OFFSET_FROM_EXTRUDER 0
+ #define Z_PROBE_OFFSET_FROM_EXTRUDER 0
+#endif
- // Endstops and bed probe
- #define HAS_X_MIN (PIN_EXISTS(X_MIN) && !IS_X2_ENDSTOP(X,MIN) && !IS_Y2_ENDSTOP(X,MIN) && !IS_Z2_OR_PROBE(X,MIN))
- #define HAS_X_MAX (PIN_EXISTS(X_MAX) && !IS_X2_ENDSTOP(X,MAX) && !IS_Y2_ENDSTOP(X,MAX) && !IS_Z2_OR_PROBE(X,MAX))
- #define HAS_Y_MIN (PIN_EXISTS(Y_MIN) && !IS_X2_ENDSTOP(Y,MIN) && !IS_Y2_ENDSTOP(Y,MIN) && !IS_Z2_OR_PROBE(Y,MIN))
- #define HAS_Y_MAX (PIN_EXISTS(Y_MAX) && !IS_X2_ENDSTOP(Y,MAX) && !IS_Y2_ENDSTOP(Y,MAX) && !IS_Z2_OR_PROBE(Y,MAX))
- #define HAS_Z_MIN (PIN_EXISTS(Z_MIN) && !IS_X2_ENDSTOP(Z,MIN) && !IS_Y2_ENDSTOP(Z,MIN) && !IS_Z2_OR_PROBE(Z,MIN))
- #define HAS_Z_MAX (PIN_EXISTS(Z_MAX) && !IS_X2_ENDSTOP(Z,MAX) && !IS_Y2_ENDSTOP(Z,MAX) && !IS_Z2_OR_PROBE(Z,MAX))
- #define HAS_X2_MIN (PIN_EXISTS(X2_MIN))
- #define HAS_X2_MAX (PIN_EXISTS(X2_MAX))
- #define HAS_Y2_MIN (PIN_EXISTS(Y2_MIN))
- #define HAS_Y2_MAX (PIN_EXISTS(Y2_MAX))
- #define HAS_Z2_MIN (PIN_EXISTS(Z2_MIN))
- #define HAS_Z2_MAX (PIN_EXISTS(Z2_MAX))
- #define HAS_Z_MIN_PROBE_PIN (PIN_EXISTS(Z_MIN_PROBE))
+/**
+ * XYZ Bed Skew Correction
+ */
+#if ENABLED(SKEW_CORRECTION)
+ #define SKEW_FACTOR_MIN -1
+ #define SKEW_FACTOR_MAX 1
- // Thermistors
- #define HAS_TEMP_0 (PIN_EXISTS(TEMP_0) && TEMP_SENSOR_0 != 0 && TEMP_SENSOR_0 > -2)
- #define HAS_TEMP_1 (PIN_EXISTS(TEMP_1) && TEMP_SENSOR_1 != 0 && TEMP_SENSOR_1 > -2)
- #define HAS_TEMP_2 (PIN_EXISTS(TEMP_2) && TEMP_SENSOR_2 != 0 && TEMP_SENSOR_2 > -2)
- #define HAS_TEMP_3 (PIN_EXISTS(TEMP_3) && TEMP_SENSOR_3 != 0 && TEMP_SENSOR_3 > -2)
- #define HAS_TEMP_4 (PIN_EXISTS(TEMP_4) && TEMP_SENSOR_4 != 0 && TEMP_SENSOR_4 > -2)
- #define HAS_TEMP_HOTEND (HAS_TEMP_0 || ENABLED(HEATER_0_USES_MAX6675))
- #define HAS_TEMP_BED (PIN_EXISTS(TEMP_BED) && TEMP_SENSOR_BED != 0 && TEMP_SENSOR_BED > -2)
- #define HAS_TEMP_CHAMBER (PIN_EXISTS(TEMP_CHAMBER) && TEMP_SENSOR_CHAMBER != 0 && TEMP_SENSOR_CHAMBER > -2)
+ #define _GET_SIDE(a,b,c) (SQRT(2*sq(a)+2*sq(b)-4*sq(c))*0.5)
+ #define _SKEW_SIDE(a,b,c) tan(M_PI*0.5-acos((sq(a)-sq(b)-sq(c))/(2*c*b)))
+ #define _SKEW_FACTOR(a,b,c) _SKEW_SIDE(float(a),_GET_SIDE(float(a),float(b),float(c)),float(c))
- // Heaters
- #define HAS_HEATER_0 (PIN_EXISTS(HEATER_0))
- #define HAS_HEATER_1 (PIN_EXISTS(HEATER_1))
- #define HAS_HEATER_2 (PIN_EXISTS(HEATER_2))
- #define HAS_HEATER_3 (PIN_EXISTS(HEATER_3))
- #define HAS_HEATER_4 (PIN_EXISTS(HEATER_4))
- #define HAS_HEATER_BED (PIN_EXISTS(HEATER_BED))
-
- // Shorthand for common combinations
- #define HAS_HEATED_BED (HAS_TEMP_BED && HAS_HEATER_BED)
- #define HAS_TEMP_SENSOR (HAS_TEMP_HOTEND || HAS_HEATED_BED || HAS_TEMP_CHAMBER)
-
- // PID heating
- #if !HAS_HEATED_BED
- #undef PIDTEMPBED
- #endif
- #define HAS_PID_HEATING (ENABLED(PIDTEMP) || ENABLED(PIDTEMPBED))
- #define HAS_PID_FOR_BOTH (ENABLED(PIDTEMP) && ENABLED(PIDTEMPBED))
-
- // Thermal protection
- #define HAS_THERMALLY_PROTECTED_BED (HAS_HEATED_BED && ENABLED(THERMAL_PROTECTION_BED))
- #define WATCH_HOTENDS (ENABLED(THERMAL_PROTECTION_HOTENDS) && WATCH_TEMP_PERIOD > 0)
- #define WATCH_THE_BED (HAS_THERMALLY_PROTECTED_BED && WATCH_BED_TEMP_PERIOD > 0)
-
- // Auto fans
- #define HAS_AUTO_FAN_0 (PIN_EXISTS(E0_AUTO_FAN))
- #define HAS_AUTO_FAN_1 (HOTENDS > 1 && PIN_EXISTS(E1_AUTO_FAN))
- #define HAS_AUTO_FAN_2 (HOTENDS > 2 && PIN_EXISTS(E2_AUTO_FAN))
- #define HAS_AUTO_FAN_3 (HOTENDS > 3 && PIN_EXISTS(E3_AUTO_FAN))
- #define HAS_AUTO_FAN_4 (HOTENDS > 4 && PIN_EXISTS(E4_AUTO_FAN))
- #define HAS_AUTO_CHAMBER_FAN (PIN_EXISTS(CHAMBER_AUTO_FAN))
- #define HAS_AUTO_FAN (HAS_AUTO_FAN_0 || HAS_AUTO_FAN_1 || HAS_AUTO_FAN_2 || HAS_AUTO_FAN_3 || HAS_AUTO_CHAMBER_FAN)
- #define AUTO_1_IS_0 (E1_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
- #define AUTO_2_IS_0 (E2_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
- #define AUTO_2_IS_1 (E2_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
- #define AUTO_3_IS_0 (E3_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
- #define AUTO_3_IS_1 (E3_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
- #define AUTO_3_IS_2 (E3_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
- #define AUTO_4_IS_0 (E4_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
- #define AUTO_4_IS_1 (E4_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
- #define AUTO_4_IS_2 (E4_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
- #define AUTO_4_IS_3 (E4_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
- #define AUTO_CHAMBER_IS_0 (CHAMBER_AUTO_FAN_PIN == E0_AUTO_FAN_PIN)
- #define AUTO_CHAMBER_IS_1 (CHAMBER_AUTO_FAN_PIN == E1_AUTO_FAN_PIN)
- #define AUTO_CHAMBER_IS_2 (CHAMBER_AUTO_FAN_PIN == E2_AUTO_FAN_PIN)
- #define AUTO_CHAMBER_IS_3 (CHAMBER_AUTO_FAN_PIN == E3_AUTO_FAN_PIN)
- #define AUTO_CHAMBER_IS_4 (CHAMBER_AUTO_FAN_PIN == E4_AUTO_FAN_PIN)
-
- // Other fans
- #define HAS_FAN0 (PIN_EXISTS(FAN))
- #define HAS_FAN1 (PIN_EXISTS(FAN1) && CONTROLLER_FAN_PIN != FAN1_PIN && E0_AUTO_FAN_PIN != FAN1_PIN && E1_AUTO_FAN_PIN != FAN1_PIN && E2_AUTO_FAN_PIN != FAN1_PIN && E3_AUTO_FAN_PIN != FAN1_PIN)
- #define HAS_FAN2 (PIN_EXISTS(FAN2) && CONTROLLER_FAN_PIN != FAN2_PIN && E0_AUTO_FAN_PIN != FAN2_PIN && E1_AUTO_FAN_PIN != FAN2_PIN && E2_AUTO_FAN_PIN != FAN2_PIN && E3_AUTO_FAN_PIN != FAN2_PIN)
- #define HAS_CONTROLLER_FAN (PIN_EXISTS(CONTROLLER_FAN))
-
- // Servos
- #define HAS_SERVOS (defined(NUM_SERVOS) && NUM_SERVOS > 0)
- #define HAS_SERVO_0 (PIN_EXISTS(SERVO0))
- #define HAS_SERVO_1 (PIN_EXISTS(SERVO1))
- #define HAS_SERVO_2 (PIN_EXISTS(SERVO2))
- #define HAS_SERVO_3 (PIN_EXISTS(SERVO3))
-
- // Sensors
- #define HAS_FILAMENT_WIDTH_SENSOR (PIN_EXISTS(FILWIDTH))
-
- // User Interface
- #define HAS_HOME (PIN_EXISTS(HOME))
- #define HAS_KILL (PIN_EXISTS(KILL))
- #define HAS_SUICIDE (PIN_EXISTS(SUICIDE))
- #define HAS_PHOTOGRAPH (PIN_EXISTS(PHOTOGRAPH))
- #define HAS_BUZZER (PIN_EXISTS(BEEPER) || ENABLED(LCD_USE_I2C_BUZZER))
- #define HAS_CASE_LIGHT (PIN_EXISTS(CASE_LIGHT) && ENABLED(CASE_LIGHT_ENABLE))
-
- // Digital control
- #define HAS_MICROSTEPS (HAS_X_MICROSTEPS || HAS_Y_MICROSTEPS || HAS_Z_MICROSTEPS || HAS_E0_MICROSTEPS || HAS_E1_MICROSTEPS || HAS_E2_MICROSTEPS || HAS_E3_MICROSTEPS || HAS_E4_MICROSTEPS)
- #define HAS_STEPPER_RESET (PIN_EXISTS(STEPPER_RESET))
- #define HAS_DIGIPOTSS (PIN_EXISTS(DIGIPOTSS))
- #define HAS_MOTOR_CURRENT_PWM (PIN_EXISTS(MOTOR_CURRENT_PWM_XY) || PIN_EXISTS(MOTOR_CURRENT_PWM_Z) || PIN_EXISTS(MOTOR_CURRENT_PWM_E))
-
- #if !HAS_TEMP_SENSOR
- #undef AUTO_REPORT_TEMPERATURES
- #endif
-
- #define HAS_AUTO_REPORTING (ENABLED(AUTO_REPORT_TEMPERATURES) || ENABLED(AUTO_REPORT_SD_STATUS))
-
- /**
- * This setting is also used by M109 when trying to calculate
- * a ballpark safe margin to prevent wait-forever situation.
- */
- #ifndef EXTRUDE_MINTEMP
- #define EXTRUDE_MINTEMP 170
- #endif
-
- /**
- * Helper Macros for heaters and extruder fan
- */
- #define WRITE_HEATER_0P(v) WRITE(HEATER_0_PIN, v)
- #if HOTENDS > 1 || ENABLED(HEATERS_PARALLEL)
- #define WRITE_HEATER_1(v) WRITE(HEATER_1_PIN, v)
- #if HOTENDS > 2
- #define WRITE_HEATER_2(v) WRITE(HEATER_2_PIN, v)
- #if HOTENDS > 3
- #define WRITE_HEATER_3(v) WRITE(HEATER_3_PIN, v)
- #if HOTENDS > 4
- #define WRITE_HEATER_4(v) WRITE(HEATER_4_PIN, v)
- #endif // HOTENDS > 4
- #endif // HOTENDS > 3
- #endif // HOTENDS > 2
- #endif // HOTENDS > 1
- #if ENABLED(HEATERS_PARALLEL)
- #define WRITE_HEATER_0(v) { WRITE_HEATER_0P(v); WRITE_HEATER_1(v); }
- #else
- #define WRITE_HEATER_0(v) WRITE_HEATER_0P(v)
- #endif
-
- /**
- * Heated bed requires settings
- */
- #if HAS_HEATED_BED
- #ifndef MAX_BED_POWER
- #define MAX_BED_POWER 255
- #endif
- #ifndef HEATER_BED_INVERTING
- #define HEATER_BED_INVERTING false
- #endif
- #define WRITE_HEATER_BED(v) WRITE(HEATER_BED_PIN, (v) ^ HEATER_BED_INVERTING)
- #endif
-
- /**
- * Up to 3 PWM fans
- */
- #if HAS_FAN2
- #define FAN_COUNT 3
- #elif HAS_FAN1
- #define FAN_COUNT 2
- #elif HAS_FAN0
- #define FAN_COUNT 1
- #else
- #define FAN_COUNT 0
- #endif
-
- #if HAS_FAN0
- #define WRITE_FAN(v) WRITE(FAN_PIN, v)
- #define WRITE_FAN0(v) WRITE_FAN(v)
- #endif
- #if HAS_FAN1
- #define WRITE_FAN1(v) WRITE(FAN1_PIN, v)
- #endif
- #if HAS_FAN2
- #define WRITE_FAN2(v) WRITE(FAN2_PIN, v)
- #endif
- #define WRITE_FAN_N(n, v) WRITE_FAN##n(v)
-
- /**
- * Part Cooling fan multipliexer
- */
- #define HAS_FANMUX PIN_EXISTS(FANMUX0)
-
- /**
- * Servos and probes
- */
-
- #if HAS_SERVOS
- #ifndef Z_PROBE_SERVO_NR
- #define Z_PROBE_SERVO_NR -1
- #endif
- #endif
-
- #define HAS_BED_PROBE (PROBE_SELECTED && DISABLED(PROBE_MANUALLY))
-
- #if ENABLED(Z_PROBE_ALLEN_KEY)
- #define PROBE_IS_TRIGGERED_WHEN_STOWED_TEST
- #endif
-
- /**
- * Bed Probe dependencies
- */
- #if HAS_BED_PROBE
- #if ENABLED(ENDSTOPPULLUPS) && HAS_Z_MIN_PROBE_PIN
- #define ENDSTOPPULLUP_ZMIN_PROBE
- #endif
- #ifndef Z_PROBE_OFFSET_RANGE_MIN
- #define Z_PROBE_OFFSET_RANGE_MIN -20
- #endif
- #ifndef Z_PROBE_OFFSET_RANGE_MAX
- #define Z_PROBE_OFFSET_RANGE_MAX 20
- #endif
- #ifndef XY_PROBE_SPEED
- #ifdef HOMING_FEEDRATE_XY
- #define XY_PROBE_SPEED HOMING_FEEDRATE_XY
+ #ifndef XY_SKEW_FACTOR
+ constexpr float XY_SKEW_FACTOR = (
+ #if defined(XY_DIAG_AC) && defined(XY_DIAG_BD) && defined(XY_SIDE_AD)
+ _SKEW_FACTOR(XY_DIAG_AC, XY_DIAG_BD, XY_SIDE_AD)
#else
- #define XY_PROBE_SPEED 4000
+ 0.0
#endif
- #endif
- #else
- #undef X_PROBE_OFFSET_FROM_EXTRUDER
- #undef Y_PROBE_OFFSET_FROM_EXTRUDER
- #undef Z_PROBE_OFFSET_FROM_EXTRUDER
- #define X_PROBE_OFFSET_FROM_EXTRUDER 0
- #define Y_PROBE_OFFSET_FROM_EXTRUDER 0
- #define Z_PROBE_OFFSET_FROM_EXTRUDER 0
+ );
#endif
-
- /**
- * XYZ Bed Skew Correction
- */
- #if ENABLED(SKEW_CORRECTION)
- #define SKEW_FACTOR_MIN -1
- #define SKEW_FACTOR_MAX 1
-
- #define _GET_SIDE(a,b,c) (SQRT(2*sq(a)+2*sq(b)-4*sq(c))*0.5)
- #define _SKEW_SIDE(a,b,c) tan(M_PI*0.5-acos((sq(a)-sq(b)-sq(c))/(2*c*b)))
- #define _SKEW_FACTOR(a,b,c) _SKEW_SIDE(float(a),_GET_SIDE(float(a),float(b),float(c)),float(c))
-
- #ifndef XY_SKEW_FACTOR
- constexpr float XY_SKEW_FACTOR = (
- #if defined(XY_DIAG_AC) && defined(XY_DIAG_BD) && defined(XY_SIDE_AD)
- _SKEW_FACTOR(XY_DIAG_AC, XY_DIAG_BD, XY_SIDE_AD)
- #else
- 0.0
- #endif
- );
+ #ifndef XZ_SKEW_FACTOR
+ #if defined(XY_SIDE_AD) && !defined(XZ_SIDE_AD)
+ #define XZ_SIDE_AD XY_SIDE_AD
#endif
- #ifndef XZ_SKEW_FACTOR
- #if defined(XY_SIDE_AD) && !defined(XZ_SIDE_AD)
- #define XZ_SIDE_AD XY_SIDE_AD
+ constexpr float XZ_SKEW_FACTOR = (
+ #if defined(XZ_DIAG_AC) && defined(XZ_DIAG_BD) && defined(XZ_SIDE_AD)
+ _SKEW_FACTOR(XZ_DIAG_AC, XZ_DIAG_BD, XZ_SIDE_AD)
+ #else
+ 0.0
#endif
- constexpr float XZ_SKEW_FACTOR = (
- #if defined(XZ_DIAG_AC) && defined(XZ_DIAG_BD) && defined(XZ_SIDE_AD)
- _SKEW_FACTOR(XZ_DIAG_AC, XZ_DIAG_BD, XZ_SIDE_AD)
- #else
- 0.0
- #endif
- );
+ );
+ #endif
+ #ifndef YZ_SKEW_FACTOR
+ constexpr float YZ_SKEW_FACTOR = (
+ #if defined(YZ_DIAG_AC) && defined(YZ_DIAG_BD) && defined(YZ_SIDE_AD)
+ _SKEW_FACTOR(YZ_DIAG_AC, YZ_DIAG_BD, YZ_SIDE_AD)
+ #else
+ 0.0
+ #endif
+ );
+ #endif
+#endif // SKEW_CORRECTION
+
+/**
+ * Set granular options based on the specific type of leveling
+ */
+#define UBL_SEGMENTED (ENABLED(AUTO_BED_LEVELING_UBL) && (ENABLED(DELTA)))
+#define ABL_PLANAR (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
+#define ABL_GRID (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
+#define OLDSCHOOL_ABL (ABL_PLANAR || ABL_GRID)
+#define HAS_ABL (OLDSCHOOL_ABL || ENABLED(AUTO_BED_LEVELING_UBL))
+#define HAS_LEVELING (HAS_ABL || ENABLED(MESH_BED_LEVELING))
+#define HAS_AUTOLEVEL (HAS_ABL && DISABLED(PROBE_MANUALLY))
+#define HAS_MESH (ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING))
+#define PLANNER_LEVELING (OLDSCHOOL_ABL || ENABLED(MESH_BED_LEVELING) || UBL_SEGMENTED || ENABLED(SKEW_CORRECTION))
+#define HAS_PROBING_PROCEDURE (HAS_ABL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
+#define HAS_UBL_AND_CURVES (ENABLED(AUTO_BED_LEVELING_UBL) && !PLANNER_LEVELING && (ENABLED(ARC_SUPPORT) || ENABLED(BEZIER_CURVE_SUPPORT)))
+#define HAS_FEEDRATE_SCALING (ENABLED(SCARA_FEEDRATE_SCALING) || ENABLED(DELTA_FEEDRATE_SCALING))
+
+#if ENABLED(AUTO_BED_LEVELING_UBL)
+ #undef LCD_BED_LEVELING
+#endif
+
+/**
+ * Heater & Fan Pausing
+ */
+#if FAN_COUNT == 0
+ #undef PROBING_FANS_OFF
+#endif
+#define QUIET_PROBING (HAS_BED_PROBE && (ENABLED(PROBING_HEATERS_OFF) || ENABLED(PROBING_FANS_OFF) || DELAY_BEFORE_PROBING > 0))
+#define HEATER_IDLE_HANDLER (ENABLED(ADVANCED_PAUSE_FEATURE) || ENABLED(PROBING_HEATERS_OFF))
+
+#if ENABLED(ADVANCED_PAUSE_FEATURE) && !defined(FILAMENT_CHANGE_SLOW_LOAD_LENGTH)
+ #define FILAMENT_CHANGE_SLOW_LOAD_LENGTH 0
+#endif
+
+/**
+ * Only constrain Z on DELTA / SCARA machines
+ */
+#if IS_KINEMATIC
+ #undef MIN_SOFTWARE_ENDSTOP_X
+ #undef MIN_SOFTWARE_ENDSTOP_Y
+ #undef MAX_SOFTWARE_ENDSTOP_X
+ #undef MAX_SOFTWARE_ENDSTOP_Y
+#endif
+
+/**
+ * Bed Probing rectangular bounds
+ * These can be further constrained in code for Delta and SCARA
+ */
+
+#ifndef MIN_PROBE_EDGE
+ #define MIN_PROBE_EDGE 0
+#endif
+
+#if ENABLED(DELTA)
+ /**
+ * Delta radius/rod trimmers/angle trimmers
+ */
+ #define _PROBE_RADIUS (DELTA_PRINTABLE_RADIUS - (MIN_PROBE_EDGE))
+ #ifndef DELTA_CALIBRATION_RADIUS
+ #ifdef X_PROBE_OFFSET_FROM_EXTRUDER
+ #define DELTA_CALIBRATION_RADIUS (DELTA_PRINTABLE_RADIUS - MAX3(abs(X_PROBE_OFFSET_FROM_EXTRUDER), abs(Y_PROBE_OFFSET_FROM_EXTRUDER), abs(MIN_PROBE_EDGE)))
+ #else
+ #define DELTA_CALIBRATION_RADIUS _PROBE_RADIUS
#endif
- #ifndef YZ_SKEW_FACTOR
- constexpr float YZ_SKEW_FACTOR = (
- #if defined(YZ_DIAG_AC) && defined(YZ_DIAG_BD) && defined(YZ_SIDE_AD)
- _SKEW_FACTOR(YZ_DIAG_AC, YZ_DIAG_BD, YZ_SIDE_AD)
- #else
- 0.0
- #endif
- );
- #endif
- #endif // SKEW_CORRECTION
-
- /**
- * Set granular options based on the specific type of leveling
- */
- #define UBL_SEGMENTED (ENABLED(AUTO_BED_LEVELING_UBL) && (ENABLED(DELTA)))
- #define ABL_PLANAR (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_3POINT))
- #define ABL_GRID (ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR))
- #define OLDSCHOOL_ABL (ABL_PLANAR || ABL_GRID)
- #define HAS_ABL (OLDSCHOOL_ABL || ENABLED(AUTO_BED_LEVELING_UBL))
- #define HAS_LEVELING (HAS_ABL || ENABLED(MESH_BED_LEVELING))
- #define HAS_AUTOLEVEL (HAS_ABL && DISABLED(PROBE_MANUALLY))
- #define HAS_MESH (ENABLED(AUTO_BED_LEVELING_BILINEAR) || ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(MESH_BED_LEVELING))
- #define PLANNER_LEVELING (OLDSCHOOL_ABL || ENABLED(MESH_BED_LEVELING) || UBL_SEGMENTED || ENABLED(SKEW_CORRECTION))
- #define HAS_PROBING_PROCEDURE (HAS_ABL || ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST))
-
- #if ENABLED(AUTO_BED_LEVELING_UBL)
- #undef LCD_BED_LEVELING
+ #endif
+ #ifndef DELTA_ENDSTOP_ADJ
+ #define DELTA_ENDSTOP_ADJ { 0, 0, 0 }
+ #endif
+ #ifndef DELTA_TOWER_ANGLE_TRIM
+ #define DELTA_TOWER_ANGLE_TRIM {0, 0, 0}
+ #endif
+ #ifndef DELTA_RADIUS_TRIM_TOWER
+ #define DELTA_RADIUS_TRIM_TOWER {0, 0, 0}
+ #endif
+ #ifndef DELTA_DIAGONAL_ROD_TRIM_TOWER
+ #define DELTA_DIAGONAL_ROD_TRIM_TOWER {0, 0, 0}
#endif
- /**
- * Heater & Fan Pausing
- */
- #if FAN_COUNT == 0
- #undef PROBING_FANS_OFF
- #endif
- #define QUIET_PROBING (HAS_BED_PROBE && (ENABLED(PROBING_HEATERS_OFF) || ENABLED(PROBING_FANS_OFF) || DELAY_BEFORE_PROBING > 0))
- #define HEATER_IDLE_HANDLER (ENABLED(ADVANCED_PAUSE_FEATURE) || ENABLED(PROBING_HEATERS_OFF))
+ // Probing points may be verified at compile time within the radius
+ // using static_assert(HYPOT2(X2-X1,Y2-Y1)<=sq(DELTA_PRINTABLE_RADIUS),"bad probe point!")
+ // so that may be added to SanityCheck.h in the future.
+ #define _MIN_PROBE_X (X_CENTER - (_PROBE_RADIUS))
+ #define _MIN_PROBE_Y (Y_CENTER - (_PROBE_RADIUS))
+ #define _MAX_PROBE_X (X_CENTER + _PROBE_RADIUS)
+ #define _MAX_PROBE_Y (Y_CENTER + _PROBE_RADIUS)
- #if ENABLED(ADVANCED_PAUSE_FEATURE) && !defined(FILAMENT_CHANGE_SLOW_LOAD_LENGTH)
- #define FILAMENT_CHANGE_SLOW_LOAD_LENGTH 0
- #endif
+#elif IS_SCARA
- /**
- * Only constrain Z on DELTA / SCARA machines
- */
+ #define SCARA_PRINTABLE_RADIUS (SCARA_LINKAGE_1 + SCARA_LINKAGE_2)
+ #define _PROBE_RADIUS (SCARA_PRINTABLE_RADIUS - (MIN_PROBE_EDGE))
+ #define _MIN_PROBE_X (X_CENTER - (SCARA_PRINTABLE_RADIUS) + MIN_PROBE_EDGE)
+ #define _MIN_PROBE_Y (Y_CENTER - (SCARA_PRINTABLE_RADIUS) + MIN_PROBE_EDGE)
+ #define _MAX_PROBE_X (X_CENTER + SCARA_PRINTABLE_RADIUS - (MIN_PROBE_EDGE))
+ #define _MAX_PROBE_Y (Y_CENTER + SCARA_PRINTABLE_RADIUS - (MIN_PROBE_EDGE))
+
+#else
+
+ // Boundaries for Cartesian probing based on bed limits
+ #define _MIN_PROBE_X (max(X_MIN_BED + MIN_PROBE_EDGE, X_MIN_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
+ #define _MIN_PROBE_Y (max(Y_MIN_BED + MIN_PROBE_EDGE, Y_MIN_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
+ #define _MAX_PROBE_X (min(X_MAX_BED - (MIN_PROBE_EDGE), X_MAX_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
+ #define _MAX_PROBE_Y (min(Y_MAX_BED - (MIN_PROBE_EDGE), Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
+
+#endif
+
+#if ENABLED(SEGMENT_LEVELED_MOVES) && !defined(LEVELED_SEGMENT_LENGTH)
+ #define LEVELED_SEGMENT_LENGTH 5
+#endif
+
+// These may be overridden in Configuration.h if a smaller area is desired
+#ifndef MIN_PROBE_X
+ #define MIN_PROBE_X _MIN_PROBE_X
+#endif
+#ifndef MIN_PROBE_Y
+ #define MIN_PROBE_Y _MIN_PROBE_Y
+#endif
+#ifndef MAX_PROBE_X
+ #define MAX_PROBE_X _MAX_PROBE_X
+#endif
+#ifndef MAX_PROBE_Y
+ #define MAX_PROBE_Y _MAX_PROBE_Y
+#endif
+
+/**
+ * Default mesh area is an area with an inset margin on the print area.
+ */
+#if ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_UBL)
#if IS_KINEMATIC
- #undef MIN_SOFTWARE_ENDSTOP_X
- #undef MIN_SOFTWARE_ENDSTOP_Y
- #undef MAX_SOFTWARE_ENDSTOP_X
- #undef MAX_SOFTWARE_ENDSTOP_Y
- #endif
-
- /**
- * Bed Probing rectangular bounds
- * These can be further constrained in code for Delta and SCARA
- */
-
- #ifndef MIN_PROBE_EDGE
- #define MIN_PROBE_EDGE 0
- #endif
-
- #if ENABLED(DELTA)
- /**
- * Delta radius/rod trimmers/angle trimmers
- */
- #define _PROBE_RADIUS (DELTA_PRINTABLE_RADIUS - (MIN_PROBE_EDGE))
- #ifndef DELTA_CALIBRATION_RADIUS
- #ifdef X_PROBE_OFFSET_FROM_EXTRUDER
- #define DELTA_CALIBRATION_RADIUS (DELTA_PRINTABLE_RADIUS - MAX3(abs(X_PROBE_OFFSET_FROM_EXTRUDER), abs(Y_PROBE_OFFSET_FROM_EXTRUDER), abs(MIN_PROBE_EDGE)))
- #else
- #define DELTA_CALIBRATION_RADIUS _PROBE_RADIUS
- #endif
- #endif
- #ifndef DELTA_ENDSTOP_ADJ
- #define DELTA_ENDSTOP_ADJ { 0, 0, 0 }
- #endif
- #ifndef DELTA_TOWER_ANGLE_TRIM
- #define DELTA_TOWER_ANGLE_TRIM {0, 0, 0}
- #endif
- #ifndef DELTA_RADIUS_TRIM_TOWER
- #define DELTA_RADIUS_TRIM_TOWER {0, 0, 0}
- #endif
- #ifndef DELTA_DIAGONAL_ROD_TRIM_TOWER
- #define DELTA_DIAGONAL_ROD_TRIM_TOWER {0, 0, 0}
- #endif
-
// Probing points may be verified at compile time within the radius
// using static_assert(HYPOT2(X2-X1,Y2-Y1)<=sq(DELTA_PRINTABLE_RADIUS),"bad probe point!")
// so that may be added to SanityCheck.h in the future.
- #define _MIN_PROBE_X (X_CENTER - (_PROBE_RADIUS))
- #define _MIN_PROBE_Y (Y_CENTER - (_PROBE_RADIUS))
- #define _MAX_PROBE_X (X_CENTER + _PROBE_RADIUS)
- #define _MAX_PROBE_Y (Y_CENTER + _PROBE_RADIUS)
-
- #elif IS_SCARA
-
- #define SCARA_PRINTABLE_RADIUS (SCARA_LINKAGE_1 + SCARA_LINKAGE_2)
- #define _PROBE_RADIUS (SCARA_PRINTABLE_RADIUS - (MIN_PROBE_EDGE))
- #define _MIN_PROBE_X (X_CENTER - (SCARA_PRINTABLE_RADIUS) + MIN_PROBE_EDGE)
- #define _MIN_PROBE_Y (Y_CENTER - (SCARA_PRINTABLE_RADIUS) + MIN_PROBE_EDGE)
- #define _MAX_PROBE_X (X_CENTER + SCARA_PRINTABLE_RADIUS - (MIN_PROBE_EDGE))
- #define _MAX_PROBE_Y (Y_CENTER + SCARA_PRINTABLE_RADIUS - (MIN_PROBE_EDGE))
-
+ #define _MESH_MIN_X (X_MIN_BED + MESH_INSET)
+ #define _MESH_MIN_Y (Y_MIN_BED + MESH_INSET)
+ #define _MESH_MAX_X (X_MAX_BED - (MESH_INSET))
+ #define _MESH_MAX_Y (Y_MAX_BED - (MESH_INSET))
#else
-
- // Boundaries for Cartesian probing based on bed limits
- #define _MIN_PROBE_X (max(X_MIN_BED + MIN_PROBE_EDGE, X_MIN_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
- #define _MIN_PROBE_Y (max(Y_MIN_BED + MIN_PROBE_EDGE, Y_MIN_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
- #define _MAX_PROBE_X (min(X_MAX_BED - (MIN_PROBE_EDGE), X_MAX_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
- #define _MAX_PROBE_Y (min(Y_MAX_BED - (MIN_PROBE_EDGE), Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
-
- #endif
-
- #if ENABLED(SEGMENT_LEVELED_MOVES) && !defined(LEVELED_SEGMENT_LENGTH)
- #define LEVELED_SEGMENT_LENGTH 5
+ // Boundaries for Cartesian probing based on set limits
+ #if ENABLED(AUTO_BED_LEVELING_UBL)
+ #define _MESH_MIN_X (max(X_MIN_BED + MESH_INSET, X_MIN_POS)) // UBL is careful not to probe off the bed. It does not
+ #define _MESH_MIN_Y (max(Y_MIN_BED + MESH_INSET, Y_MIN_POS)) // need *_PROBE_OFFSET_FROM_EXTRUDER in the mesh dimensions
+ #define _MESH_MAX_X (min(X_MAX_BED - (MESH_INSET), X_MAX_POS))
+ #define _MESH_MAX_Y (min(Y_MAX_BED - (MESH_INSET), Y_MAX_POS))
+ #else
+ #define _MESH_MIN_X (max(X_MIN_BED + MESH_INSET, X_MIN_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
+ #define _MESH_MIN_Y (max(Y_MIN_BED + MESH_INSET, Y_MIN_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
+ #define _MESH_MAX_X (min(X_MAX_BED - (MESH_INSET), X_MAX_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
+ #define _MESH_MAX_Y (min(Y_MAX_BED - (MESH_INSET), Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
+ #endif
#endif
// These may be overridden in Configuration.h if a smaller area is desired
- #ifndef MIN_PROBE_X
- #define MIN_PROBE_X _MIN_PROBE_X
+ #ifndef MESH_MIN_X
+ #define MESH_MIN_X _MESH_MIN_X
#endif
- #ifndef MIN_PROBE_Y
- #define MIN_PROBE_Y _MIN_PROBE_Y
+ #ifndef MESH_MIN_Y
+ #define MESH_MIN_Y _MESH_MIN_Y
#endif
- #ifndef MAX_PROBE_X
- #define MAX_PROBE_X _MAX_PROBE_X
+ #ifndef MESH_MAX_X
+ #define MESH_MAX_X _MESH_MAX_X
#endif
- #ifndef MAX_PROBE_Y
- #define MAX_PROBE_Y _MAX_PROBE_Y
+ #ifndef MESH_MAX_Y
+ #define MESH_MAX_Y _MESH_MAX_Y
#endif
- /**
- * Default mesh area is an area with an inset margin on the print area.
- */
- #if ENABLED(MESH_BED_LEVELING) || ENABLED(AUTO_BED_LEVELING_UBL)
- #if IS_KINEMATIC
- // Probing points may be verified at compile time within the radius
- // using static_assert(HYPOT2(X2-X1,Y2-Y1)<=sq(DELTA_PRINTABLE_RADIUS),"bad probe point!")
- // so that may be added to SanityCheck.h in the future.
- #define _MESH_MIN_X (X_MIN_BED + MESH_INSET)
- #define _MESH_MIN_Y (Y_MIN_BED + MESH_INSET)
- #define _MESH_MAX_X (X_MAX_BED - (MESH_INSET))
- #define _MESH_MAX_Y (Y_MAX_BED - (MESH_INSET))
- #else
- // Boundaries for Cartesian probing based on set limits
- #if ENABLED(AUTO_BED_LEVELING_UBL)
- #define _MESH_MIN_X (max(X_MIN_BED + MESH_INSET, X_MIN_POS)) // UBL is careful not to probe off the bed. It does not
- #define _MESH_MIN_Y (max(Y_MIN_BED + MESH_INSET, Y_MIN_POS)) // need *_PROBE_OFFSET_FROM_EXTRUDER in the mesh dimensions
- #define _MESH_MAX_X (min(X_MAX_BED - (MESH_INSET), X_MAX_POS))
- #define _MESH_MAX_Y (min(Y_MAX_BED - (MESH_INSET), Y_MAX_POS))
- #else
- #define _MESH_MIN_X (max(X_MIN_BED + MESH_INSET, X_MIN_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
- #define _MESH_MIN_Y (max(Y_MIN_BED + MESH_INSET, Y_MIN_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
- #define _MESH_MAX_X (min(X_MAX_BED - (MESH_INSET), X_MAX_POS + X_PROBE_OFFSET_FROM_EXTRUDER))
- #define _MESH_MAX_Y (min(Y_MAX_BED - (MESH_INSET), Y_MAX_POS + Y_PROBE_OFFSET_FROM_EXTRUDER))
- #endif
- #endif
+#endif // MESH_BED_LEVELING || AUTO_BED_LEVELING_UBL
- // These may be overridden in Configuration.h if a smaller area is desired
- #ifndef MESH_MIN_X
- #define MESH_MIN_X _MESH_MIN_X
+#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_3POINT)
+ #if IS_KINEMATIC
+ #define SIN0 0.0
+ #define SIN120 0.866025
+ #define SIN240 -0.866025
+ #define COS0 1.0
+ #define COS120 -0.5
+ #define COS240 -0.5
+ #ifndef PROBE_PT_1_X
+ #define PROBE_PT_1_X (X_CENTER + (_PROBE_RADIUS) * COS0)
#endif
- #ifndef MESH_MIN_Y
- #define MESH_MIN_Y _MESH_MIN_Y
+ #ifndef PROBE_PT_1_Y
+ #define PROBE_PT_1_Y (Y_CENTER + (_PROBE_RADIUS) * SIN0)
#endif
- #ifndef MESH_MAX_X
- #define MESH_MAX_X _MESH_MAX_X
+ #ifndef PROBE_PT_2_X
+ #define PROBE_PT_2_X (X_CENTER + (_PROBE_RADIUS) * COS120)
#endif
- #ifndef MESH_MAX_Y
- #define MESH_MAX_Y _MESH_MAX_Y
+ #ifndef PROBE_PT_2_Y
+ #define PROBE_PT_2_Y (Y_CENTER + (_PROBE_RADIUS) * SIN120)
#endif
-
- #endif // MESH_BED_LEVELING || AUTO_BED_LEVELING_UBL
-
- #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(AUTO_BED_LEVELING_3POINT)
- #if IS_KINEMATIC
- #define SIN0 0.0
- #define SIN120 0.866025
- #define SIN240 -0.866025
- #define COS0 1.0
- #define COS120 -0.5
- #define COS240 -0.5
- #ifndef PROBE_PT_1_X
- #define PROBE_PT_1_X (X_CENTER + (_PROBE_RADIUS) * COS0)
- #endif
- #ifndef PROBE_PT_1_Y
- #define PROBE_PT_1_Y (Y_CENTER + (_PROBE_RADIUS) * SIN0)
- #endif
- #ifndef PROBE_PT_2_X
- #define PROBE_PT_2_X (X_CENTER + (_PROBE_RADIUS) * COS120)
- #endif
- #ifndef PROBE_PT_2_Y
- #define PROBE_PT_2_Y (Y_CENTER + (_PROBE_RADIUS) * SIN120)
- #endif
- #ifndef PROBE_PT_3_X
- #define PROBE_PT_3_X (X_CENTER + (_PROBE_RADIUS) * COS240)
- #endif
- #ifndef PROBE_PT_3_Y
- #define PROBE_PT_3_Y (Y_CENTER + (_PROBE_RADIUS) * SIN240)
- #endif
- #else
- #ifndef PROBE_PT_1_X
- #define PROBE_PT_1_X MIN_PROBE_X
- #endif
- #ifndef PROBE_PT_1_Y
- #define PROBE_PT_1_Y MIN_PROBE_Y
- #endif
- #ifndef PROBE_PT_2_X
- #define PROBE_PT_2_X MAX_PROBE_X
- #endif
- #ifndef PROBE_PT_2_Y
- #define PROBE_PT_2_Y MIN_PROBE_Y
- #endif
- #ifndef PROBE_PT_3_X
- #define PROBE_PT_3_X X_CENTER
- #endif
- #ifndef PROBE_PT_3_Y
- #define PROBE_PT_3_Y MAX_PROBE_Y
- #endif
+ #ifndef PROBE_PT_3_X
+ #define PROBE_PT_3_X (X_CENTER + (_PROBE_RADIUS) * COS240)
#endif
- #endif
-
- #if ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR)
- #ifndef LEFT_PROBE_BED_POSITION
- #define LEFT_PROBE_BED_POSITION MIN_PROBE_X
- #endif
- #ifndef RIGHT_PROBE_BED_POSITION
- #define RIGHT_PROBE_BED_POSITION MAX_PROBE_X
- #endif
- #ifndef FRONT_PROBE_BED_POSITION
- #define FRONT_PROBE_BED_POSITION MIN_PROBE_Y
- #endif
- #ifndef BACK_PROBE_BED_POSITION
- #define BACK_PROBE_BED_POSITION MAX_PROBE_Y
- #endif
- #endif
-
- /**
- * Buzzer/Speaker
- */
- #if ENABLED(LCD_USE_I2C_BUZZER)
- #ifndef LCD_FEEDBACK_FREQUENCY_HZ
- #define LCD_FEEDBACK_FREQUENCY_HZ 1000
- #endif
- #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
- #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100
+ #ifndef PROBE_PT_3_Y
+ #define PROBE_PT_3_Y (Y_CENTER + (_PROBE_RADIUS) * SIN240)
#endif
#else
- #ifndef LCD_FEEDBACK_FREQUENCY_HZ
- #define LCD_FEEDBACK_FREQUENCY_HZ 5000
+ #ifndef PROBE_PT_1_X
+ #define PROBE_PT_1_X MIN_PROBE_X
#endif
- #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
- #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
+ #ifndef PROBE_PT_1_Y
+ #define PROBE_PT_1_Y MIN_PROBE_Y
+ #endif
+ #ifndef PROBE_PT_2_X
+ #define PROBE_PT_2_X MAX_PROBE_X
+ #endif
+ #ifndef PROBE_PT_2_Y
+ #define PROBE_PT_2_Y MIN_PROBE_Y
+ #endif
+ #ifndef PROBE_PT_3_X
+ #define PROBE_PT_3_X X_CENTER
+ #endif
+ #ifndef PROBE_PT_3_Y
+ #define PROBE_PT_3_Y MAX_PROBE_Y
#endif
#endif
+#endif
- /**
- * VIKI2, miniVIKI, AZSMZ_12864, and MKS_12864OLED_SSD1306 require DOGLCD_SCK and DOGLCD_MOSI to be defined.
- */
- #if ENABLED(VIKI2) || ENABLED(miniVIKI) || ENABLED(AZSMZ_12864) || ENABLED(MKS_12864OLED_SSD1306)
- #ifndef DOGLCD_SCK
- #define DOGLCD_SCK SCK_PIN
- #endif
- #ifndef DOGLCD_MOSI
- #define DOGLCD_MOSI MOSI_PIN
- #endif
+#if ENABLED(AUTO_BED_LEVELING_LINEAR) || ENABLED(AUTO_BED_LEVELING_BILINEAR)
+ #ifndef LEFT_PROBE_BED_POSITION
+ #define LEFT_PROBE_BED_POSITION MIN_PROBE_X
#endif
+ #ifndef RIGHT_PROBE_BED_POSITION
+ #define RIGHT_PROBE_BED_POSITION MAX_PROBE_X
+ #endif
+ #ifndef FRONT_PROBE_BED_POSITION
+ #define FRONT_PROBE_BED_POSITION MIN_PROBE_Y
+ #endif
+ #ifndef BACK_PROBE_BED_POSITION
+ #define BACK_PROBE_BED_POSITION MAX_PROBE_Y
+ #endif
+#endif
- /**
- * Z_HOMING_HEIGHT / Z_CLEARANCE_BETWEEN_PROBES
- */
- #ifndef Z_HOMING_HEIGHT
- #ifndef Z_CLEARANCE_BETWEEN_PROBES
- #define Z_HOMING_HEIGHT 0
- #else
- #define Z_HOMING_HEIGHT Z_CLEARANCE_BETWEEN_PROBES
- #endif
+/**
+ * Buzzer/Speaker
+ */
+#if ENABLED(LCD_USE_I2C_BUZZER)
+ #ifndef LCD_FEEDBACK_FREQUENCY_HZ
+ #define LCD_FEEDBACK_FREQUENCY_HZ 1000
#endif
+ #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
+ #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 100
+ #endif
+#else
+ #ifndef LCD_FEEDBACK_FREQUENCY_HZ
+ #define LCD_FEEDBACK_FREQUENCY_HZ 5000
+ #endif
+ #ifndef LCD_FEEDBACK_FREQUENCY_DURATION_MS
+ #define LCD_FEEDBACK_FREQUENCY_DURATION_MS 2
+ #endif
+#endif
+
+/**
+ * VIKI2, miniVIKI, AZSMZ_12864, and MKS_12864OLED_SSD1306 require DOGLCD_SCK and DOGLCD_MOSI to be defined.
+ */
+#if ENABLED(VIKI2) || ENABLED(miniVIKI) || ENABLED(AZSMZ_12864) || ENABLED(MKS_12864OLED_SSD1306)
+ #ifndef DOGLCD_SCK
+ #define DOGLCD_SCK SCK_PIN
+ #endif
+ #ifndef DOGLCD_MOSI
+ #define DOGLCD_MOSI MOSI_PIN
+ #endif
+#endif
+
+/**
+ * Z_HOMING_HEIGHT / Z_CLEARANCE_BETWEEN_PROBES
+ */
+#ifndef Z_HOMING_HEIGHT
#ifndef Z_CLEARANCE_BETWEEN_PROBES
- #define Z_CLEARANCE_BETWEEN_PROBES Z_HOMING_HEIGHT
- #endif
- #if Z_CLEARANCE_BETWEEN_PROBES > Z_HOMING_HEIGHT
- #define MANUAL_PROBE_HEIGHT Z_CLEARANCE_BETWEEN_PROBES
+ #define Z_HOMING_HEIGHT 0
#else
- #define MANUAL_PROBE_HEIGHT Z_HOMING_HEIGHT
+ #define Z_HOMING_HEIGHT Z_CLEARANCE_BETWEEN_PROBES
#endif
+#endif
+#ifndef Z_CLEARANCE_BETWEEN_PROBES
+ #define Z_CLEARANCE_BETWEEN_PROBES Z_HOMING_HEIGHT
+#endif
+#if Z_CLEARANCE_BETWEEN_PROBES > Z_HOMING_HEIGHT
+ #define MANUAL_PROBE_HEIGHT Z_CLEARANCE_BETWEEN_PROBES
+#else
+ #define MANUAL_PROBE_HEIGHT Z_HOMING_HEIGHT
+#endif
- // Stepper pulse duration, in cycles
- #define STEP_PULSE_CYCLES ((MINIMUM_STEPPER_PULSE) * CYCLES_PER_MICROSECOND)
+// Updated G92 behavior shifts the workspace
+#define HAS_POSITION_SHIFT DISABLED(NO_WORKSPACE_OFFSETS)
+// The home offset also shifts the coordinate space
+#define HAS_HOME_OFFSET (DISABLED(NO_WORKSPACE_OFFSETS) && DISABLED(DELTA))
+// Either offset yields extra calculations on all moves
+#define HAS_WORKSPACE_OFFSET (HAS_POSITION_SHIFT || HAS_HOME_OFFSET)
+// M206 doesn't apply to DELTA
+#define HAS_M206_COMMAND (HAS_HOME_OFFSET && DISABLED(DELTA))
- // Updated G92 behavior shifts the workspace
- #define HAS_POSITION_SHIFT DISABLED(NO_WORKSPACE_OFFSETS)
- // The home offset also shifts the coordinate space
- #define HAS_HOME_OFFSET (DISABLED(NO_WORKSPACE_OFFSETS) && DISABLED(DELTA))
- // Either offset yields extra calculations on all moves
- #define HAS_WORKSPACE_OFFSET (HAS_POSITION_SHIFT || HAS_HOME_OFFSET)
- // M206 doesn't apply to DELTA
- #define HAS_M206_COMMAND (HAS_HOME_OFFSET && DISABLED(DELTA))
+// LCD timeout to status screen default is 15s
+#ifndef LCD_TIMEOUT_TO_STATUS
+ #define LCD_TIMEOUT_TO_STATUS 15000
+#endif
- // LCD timeout to status screen default is 15s
- #ifndef LCD_TIMEOUT_TO_STATUS
- #define LCD_TIMEOUT_TO_STATUS 15000
+// Shorthand
+#define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
+
+// Add commands that need sub-codes to this list
+#define USE_GCODE_SUBCODES ENABLED(G38_PROBE_TARGET) || ENABLED(CNC_COORDINATE_SYSTEMS) || ENABLED(POWER_LOSS_RECOVERY)
+
+// Parking Extruder
+#if ENABLED(PARKING_EXTRUDER)
+ #ifndef PARKING_EXTRUDER_GRAB_DISTANCE
+ #define PARKING_EXTRUDER_GRAB_DISTANCE 0
#endif
+ #ifndef PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE
+ #define PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE HIGH
+ #endif
+#endif
- // Shorthand
- #define GRID_MAX_POINTS ((GRID_MAX_POINTS_X) * (GRID_MAX_POINTS_Y))
+// Number of VFAT entries used. Each entry has 13 UTF-16 characters
+#if ENABLED(SCROLL_LONG_FILENAMES)
+ #define MAX_VFAT_ENTRIES (5)
+#else
+ #define MAX_VFAT_ENTRIES (2)
+#endif
- // Add commands that need sub-codes to this list
- #define USE_GCODE_SUBCODES ENABLED(G38_PROBE_TARGET) || ENABLED(CNC_COORDINATE_SYSTEMS) || ENABLED(POWER_LOSS_RECOVERY)
-
- // Parking Extruder
- #if ENABLED(PARKING_EXTRUDER)
- #ifndef PARKING_EXTRUDER_GRAB_DISTANCE
- #define PARKING_EXTRUDER_GRAB_DISTANCE 0
- #endif
- #ifndef PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE
- #define PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE HIGH
+// Set defaults for unspecified LED user colors
+#if ENABLED(LED_CONTROL_MENU)
+ #ifndef LED_USER_PRESET_RED
+ #define LED_USER_PRESET_RED 255
+ #endif
+ #ifndef LED_USER_PRESET_GREEN
+ #define LED_USER_PRESET_GREEN 255
+ #endif
+ #ifndef LED_USER_PRESET_BLUE
+ #define LED_USER_PRESET_BLUE 255
+ #endif
+ #ifndef LED_USER_PRESET_WHITE
+ #define LED_USER_PRESET_WHITE 0
+ #endif
+ #ifndef LED_USER_PRESET_BRIGHTNESS
+ #ifdef NEOPIXEL_BRIGHTNESS
+ #define LED_USER_PRESET_BRIGHTNESS NEOPIXEL_BRIGHTNESS
+ #else
+ #define LED_USER_PRESET_BRIGHTNESS 255
#endif
#endif
+#endif
- // Number of VFAT entries used. Each entry has 13 UTF-16 characters
- #if ENABLED(SCROLL_LONG_FILENAMES)
- #define MAX_VFAT_ENTRIES (5)
- #else
- #define MAX_VFAT_ENTRIES (2)
- #endif
+// Nozzle park
+#if ENABLED(NOZZLE_PARK_FEATURE) && ENABLED(DELTA)
+ #undef NOZZLE_PARK_Z_FEEDRATE
+ #define NOZZLE_PARK_Z_FEEDRATE NOZZLE_PARK_XY_FEEDRATE
+#endif
- // Set defaults for unspecified LED user colors
- #if ENABLED(LED_CONTROL_MENU)
- #ifndef LED_USER_PRESET_RED
- #define LED_USER_PRESET_RED 255
- #endif
- #ifndef LED_USER_PRESET_GREEN
- #define LED_USER_PRESET_GREEN 255
- #endif
- #ifndef LED_USER_PRESET_BLUE
- #define LED_USER_PRESET_BLUE 255
- #endif
- #ifndef LED_USER_PRESET_WHITE
- #define LED_USER_PRESET_WHITE 0
- #endif
- #ifndef LED_USER_PRESET_BRIGHTNESS
- #ifdef NEOPIXEL_BRIGHTNESS
- #define LED_USER_PRESET_BRIGHTNESS NEOPIXEL_BRIGHTNESS
- #else
- #define LED_USER_PRESET_BRIGHTNESS 255
- #endif
- #endif
- #endif
-
- // Nozzle park
- #if ENABLED(NOZZLE_PARK_FEATURE) && ENABLED(DELTA)
- #undef NOZZLE_PARK_Z_FEEDRATE
- #define NOZZLE_PARK_Z_FEEDRATE NOZZLE_PARK_XY_FEEDRATE
- #endif
-
- #if ENABLED(SDCARD_SORT_ALPHA)
- #define HAS_FOLDER_SORTING (FOLDER_SORTING || ENABLED(SDSORT_GCODE))
- #endif
+#if ENABLED(SDCARD_SORT_ALPHA)
+ #define HAS_FOLDER_SORTING (FOLDER_SORTING || ENABLED(SDSORT_GCODE))
+#endif
#endif // CONDITIONALS_POST_H
diff --git a/Marlin/G26_Mesh_Validation_Tool.cpp b/Marlin/G26_Mesh_Validation_Tool.cpp
index 4497eedd40..8a3f951c8c 100644
--- a/Marlin/G26_Mesh_Validation_Tool.cpp
+++ b/Marlin/G26_Mesh_Validation_Tool.cpp
@@ -134,9 +134,6 @@
// External references
extern Planner planner;
- #if ENABLED(ULTRA_LCD)
- extern char lcd_status_message[];
- #endif
// Private functions
@@ -158,7 +155,7 @@
static int8_t g26_prime_flag;
- #if ENABLED(NEWPANEL)
+ #if ENABLED(ULTIPANEL)
/**
* If the LCD is clicked, cancel, wait for release, return true
@@ -183,9 +180,9 @@
void G26_line_to_destination(const float &feed_rate) {
const float save_feedrate = feedrate_mm_s;
- feedrate_mm_s = feed_rate; // use specified feed rate
+ feedrate_mm_s = feed_rate;
prepare_move_to_destination(); // will ultimately call ubl.line_to_destination_cartesian or ubl.prepare_linear_move_to for UBL_SEGMENTED
- feedrate_mm_s = save_feedrate; // restore global feed rate
+ feedrate_mm_s = save_feedrate;
}
void move_to(const float &rx, const float &ry, const float &z, const float &e_delta) {
@@ -204,8 +201,6 @@
destination[E_AXIS] = current_position[E_AXIS];
G26_line_to_destination(feed_value);
-
- stepper.synchronize();
set_destination_from_current();
}
@@ -220,8 +215,6 @@
destination[E_AXIS] += e_delta;
G26_line_to_destination(feed_value);
-
- stepper.synchronize();
set_destination_from_current();
}
@@ -246,7 +239,7 @@
*/
inline bool prime_nozzle() {
- #if ENABLED(NEWPANEL)
+ #if ENABLED(ULTIPANEL)
float Total_Prime = 0.0;
if (g26_prime_flag == -1) { // The user wants to control how much filament gets purged
@@ -267,20 +260,17 @@
if (Total_Prime >= EXTRUDE_MAXLENGTH) return G26_ERR;
#endif
G26_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0);
-
- stepper.synchronize(); // Without this synchronize, the purge is more consistent,
+ set_destination_from_current();
+ planner.synchronize(); // Without this synchronize, the purge is more consistent,
// but because the planner has a buffer, we won't be able
// to stop as quickly. So we put up with the less smooth
// action to give the user a more responsive 'Stop'.
- set_destination_from_current();
- idle();
+
SERIAL_FLUSH(); // Prevent host M105 buffer overrun.
}
wait_for_release();
- strcpy_P(lcd_status_message, PSTR("Done Priming")); // Hack to get the message up. May be obsolete.
-
lcd_setstatusPGM(PSTR("Done Priming"), 99);
lcd_quick_feedback(true);
lcd_external_control = false;
@@ -295,7 +285,6 @@
set_destination_from_current();
destination[E_AXIS] += g26_prime_length;
G26_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0);
- stepper.synchronize();
set_destination_from_current();
retract_filament(destination);
}
@@ -369,7 +358,7 @@
// If the end point of the line is closer to the nozzle, flip the direction,
// moving from the end to the start. On very small lines the optimization isn't worth it.
- if (dist_end < dist_start && (INTERSECTION_CIRCLE_RADIUS) < FABS(line_length))
+ if (dist_end < dist_start && (INTERSECTION_CIRCLE_RADIUS) < ABS(line_length))
return print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
// Decide whether to retract & bump
@@ -395,7 +384,7 @@
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
- #if ENABLED(NEWPANEL)
+ #if ENABLED(ULTIPANEL)
if (user_canceled()) return true; // Check if the user wants to stop the Mesh Validation
#endif
@@ -486,12 +475,14 @@
if (g26_bed_temp > 25) {
lcd_setstatusPGM(PSTR("G26 Heating Bed."), 99);
lcd_quick_feedback(true);
- lcd_external_control = true;
+ #if ENABLED(ULTIPANEL)
+ lcd_external_control = true;
+ #endif
#endif
thermalManager.setTargetBed(g26_bed_temp);
- while (abs(thermalManager.degBed() - g26_bed_temp) > 3) {
+ while (ABS(thermalManager.degBed() - g26_bed_temp) > 3) {
- #if ENABLED(NEWPANEL)
+ #if ENABLED(ULTIPANEL)
if (is_lcd_clicked()) return exit_from_g26();
#endif
@@ -512,9 +503,9 @@
// Start heating the nozzle and wait for it to reach temperature.
thermalManager.setTargetHotend(g26_hotend_temp, 0);
- while (abs(thermalManager.degHotend(0) - g26_hotend_temp) > 3) {
+ while (ABS(thermalManager.degHotend(0) - g26_hotend_temp) > 3) {
- #if ENABLED(NEWPANEL)
+ #if ENABLED(ULTIPANEL)
if (is_lcd_clicked()) return exit_from_g26();
#endif
@@ -627,7 +618,7 @@
if (parser.seen('P')) {
if (!parser.has_value()) {
- #if ENABLED(NEWPANEL)
+ #if ENABLED(ULTIPANEL)
g26_prime_flag = -1;
#else
SERIAL_PROTOCOLLNPGM("?Prime length must be specified when not using an LCD.");
@@ -672,7 +663,7 @@
}
int16_t g26_repeats;
- #if ENABLED(NEWPANEL)
+ #if ENABLED(ULTIPANEL)
g26_repeats = parser.intval('R', GRID_MAX_POINTS + 1);
#else
if (!parser.seen('R')) {
@@ -701,7 +692,6 @@
if (current_position[Z_AXIS] < Z_CLEARANCE_BETWEEN_PROBES) {
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
- stepper.synchronize();
set_current_from_destination();
}
@@ -732,27 +722,31 @@
move_to(destination, 0.0);
move_to(destination, g26_ooze_amount);
- #if ENABLED(ULTRA_LCD)
+ #if ENABLED(ULTIPANEL)
lcd_external_control = true;
#endif
-// debug_current_and_destination(PSTR("Starting G26 Mesh Validation Pattern."));
+ //debug_current_and_destination(PSTR("Starting G26 Mesh Validation Pattern."));
- /**
- * Pre-generate radius offset values at 30 degree intervals to reduce CPU load.
- */
- #define A_INT 30
- #define _ANGS (360 / A_INT)
- #define A_CNT (_ANGS / 2)
- #define _IND(A) ((A + _ANGS * 8) % _ANGS)
- #define _COS(A) (trig_table[_IND(A) % A_CNT] * (_IND(A) >= A_CNT ? -1 : 1))
- #define _SIN(A) (-_COS((A + A_CNT / 2) % _ANGS))
- #if A_CNT & 1
- #error "A_CNT must be a positive value. Please change A_INT."
- #endif
- float trig_table[A_CNT];
- for (uint8_t i = 0; i < A_CNT; i++)
- trig_table[i] = INTERSECTION_CIRCLE_RADIUS * cos(RADIANS(i * A_INT));
+ #if DISABLED(ARC_SUPPORT)
+
+ /**
+ * Pre-generate radius offset values at 30 degree intervals to reduce CPU load.
+ */
+ #define A_INT 30
+ #define _ANGS (360 / A_INT)
+ #define A_CNT (_ANGS / 2)
+ #define _IND(A) ((A + _ANGS * 8) % _ANGS)
+ #define _COS(A) (trig_table[_IND(A) % A_CNT] * (_IND(A) >= A_CNT ? -1 : 1))
+ #define _SIN(A) (-_COS((A + A_CNT / 2) % _ANGS))
+ #if A_CNT & 1
+ #error "A_CNT must be a positive value. Please change A_INT."
+ #endif
+ float trig_table[A_CNT];
+ for (uint8_t i = 0; i < A_CNT; i++)
+ trig_table[i] = INTERSECTION_CIRCLE_RADIUS * cos(RADIANS(i * A_INT));
+
+ #endif // !ARC_SUPPORT
mesh_index_pair location;
do {
@@ -771,52 +765,127 @@
// which is always drawn counter-clockwise.
const uint8_t xi = location.x_index, yi = location.y_index;
const bool f = yi == 0, r = xi >= GRID_MAX_POINTS_X - 1, b = yi >= GRID_MAX_POINTS_Y - 1;
- int8_t start_ind = -2, end_ind = 9; // Assume a full circle (from 5:00 to 5:00)
- if (xi == 0) { // Left edge? Just right half.
- start_ind = f ? 0 : -3; // 03:00 to 12:00 for front-left
- end_ind = b ? 0 : 2; // 06:00 to 03:00 for back-left
- }
- else if (r) { // Right edge? Just left half.
- start_ind = b ? 6 : 3; // 12:00 to 09:00 for front-right
- end_ind = f ? 5 : 8; // 09:00 to 06:00 for back-right
- }
- else if (f) { // Front edge? Just back half.
- start_ind = 0; // 03:00
- end_ind = 5; // 09:00
- }
- else if (b) { // Back edge? Just front half.
- start_ind = 6; // 09:00
- end_ind = 11; // 03:00
- }
- for (int8_t ind = start_ind; ind <= end_ind; ind++) {
+ #if ENABLED(ARC_SUPPORT)
- #if ENABLED(NEWPANEL)
- if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation
+ #define ARC_LENGTH(quarters) (INTERSECTION_CIRCLE_RADIUS * M_PI * (quarters) / 2)
+ float sx = circle_x + INTERSECTION_CIRCLE_RADIUS, // default to full circle
+ ex = circle_x + INTERSECTION_CIRCLE_RADIUS,
+ sy = circle_y, ey = circle_y,
+ arc_length = ARC_LENGTH(4);
+
+ // Figure out where to start and end the arc - we always print counterclockwise
+ if (xi == 0) { // left edge
+ sx = f ? circle_x + INTERSECTION_CIRCLE_RADIUS : circle_x;
+ ex = b ? circle_x + INTERSECTION_CIRCLE_RADIUS : circle_x;
+ sy = f ? circle_y : circle_y - INTERSECTION_CIRCLE_RADIUS;
+ ey = b ? circle_y : circle_y + INTERSECTION_CIRCLE_RADIUS;
+ arc_length = (f || b) ? ARC_LENGTH(1) : ARC_LENGTH(2);
+ }
+ else if (r) { // right edge
+ sx = b ? circle_x - INTERSECTION_CIRCLE_RADIUS : circle_x;
+ ex = f ? circle_x - INTERSECTION_CIRCLE_RADIUS : circle_x;
+ sy = b ? circle_y : circle_y + INTERSECTION_CIRCLE_RADIUS;
+ ey = f ? circle_y : circle_y - INTERSECTION_CIRCLE_RADIUS;
+ arc_length = (f || b) ? ARC_LENGTH(1) : ARC_LENGTH(2);
+ }
+ else if (f) {
+ sx = circle_x + INTERSECTION_CIRCLE_RADIUS;
+ ex = circle_x - INTERSECTION_CIRCLE_RADIUS;
+ sy = ey = circle_y;
+ arc_length = ARC_LENGTH(2);
+ }
+ else if (b) {
+ sx = circle_x - INTERSECTION_CIRCLE_RADIUS;
+ ex = circle_x + INTERSECTION_CIRCLE_RADIUS;
+ sy = ey = circle_y;
+ arc_length = ARC_LENGTH(2);
+ }
+ const float arc_offset[2] = {
+ circle_x - sx,
+ circle_y - sy
+ };
+
+ const float dx_s = current_position[X_AXIS] - sx, // find our distance from the start of the actual circle
+ dy_s = current_position[Y_AXIS] - sy,
+ dist_start = HYPOT2(dx_s, dy_s);
+ const float endpoint[XYZE] = {
+ ex, ey,
+ g26_layer_height,
+ current_position[E_AXIS] + (arc_length * g26_e_axis_feedrate * g26_extrusion_multiplier)
+ };
+
+ if (dist_start > 2.0) {
+ retract_filament(destination);
+ //todo: parameterize the bump height with a define
+ move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + 0.500, 0.0); // Z bump to minimize scraping
+ move_to(sx, sy, g26_layer_height + 0.500, 0.0); // Get to the starting point with no extrusion while bumped
+ }
+
+ move_to(sx, sy, g26_layer_height, 0.0); // Get to the starting point with no extrusion / un-Z bump
+
+ recover_filament(destination);
+ const float save_feedrate = feedrate_mm_s;
+ feedrate_mm_s = PLANNER_XY_FEEDRATE() / 10.0;
+ plan_arc(endpoint, arc_offset, false); // Draw a counter-clockwise arc
+ feedrate_mm_s = save_feedrate;
+ set_destination_from_current();
+ #if ENABLED(ULTIPANEL)
+ if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation
#endif
- float rx = circle_x + _COS(ind), // For speed, these are now a lookup table entry
- ry = circle_y + _SIN(ind),
- xe = circle_x + _COS(ind + 1),
- ye = circle_y + _SIN(ind + 1);
+ #else // !ARC_SUPPORT
- #if IS_KINEMATIC
- // Check to make sure this segment is entirely on the bed, skip if not.
- if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue;
- #else // not, we need to skip
- rx = constrain(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops
- ry = constrain(ry, Y_MIN_POS + 1, Y_MAX_POS - 1);
- xe = constrain(xe, X_MIN_POS + 1, X_MAX_POS - 1);
- ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1);
- #endif
+ int8_t start_ind = -2, end_ind = 9; // Assume a full circle (from 5:00 to 5:00)
+ if (xi == 0) { // Left edge? Just right half.
+ start_ind = f ? 0 : -3; // 03:00 to 12:00 for front-left
+ end_ind = b ? 0 : 2; // 06:00 to 03:00 for back-left
+ }
+ else if (r) { // Right edge? Just left half.
+ start_ind = b ? 6 : 3; // 12:00 to 09:00 for front-right
+ end_ind = f ? 5 : 8; // 09:00 to 06:00 for back-right
+ }
+ else if (f) { // Front edge? Just back half.
+ start_ind = 0; // 03:00
+ end_ind = 5; // 09:00
+ }
+ else if (b) { // Back edge? Just front half.
+ start_ind = 6; // 09:00
+ end_ind = 11; // 03:00
+ }
- print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height);
- SERIAL_FLUSH(); // Prevent host M105 buffer overrun.
- }
- if (look_for_lines_to_connect())
- goto LEAVE;
+ for (int8_t ind = start_ind; ind <= end_ind; ind++) {
+
+ #if ENABLED(ULTIPANEL)
+ if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation
+ #endif
+
+ float rx = circle_x + _COS(ind), // For speed, these are now a lookup table entry
+ ry = circle_y + _SIN(ind),
+ xe = circle_x + _COS(ind + 1),
+ ye = circle_y + _SIN(ind + 1);
+
+ #if IS_KINEMATIC
+ // Check to make sure this segment is entirely on the bed, skip if not.
+ if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue;
+ #else // not, we need to skip
+ rx = constrain(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops
+ ry = constrain(ry, Y_MIN_POS + 1, Y_MAX_POS - 1);
+ xe = constrain(xe, X_MIN_POS + 1, X_MAX_POS - 1);
+ ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1);
+ #endif
+
+ print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height);
+ SERIAL_FLUSH(); // Prevent host M105 buffer overrun.
+ }
+
+ #endif // !ARC_SUPPORT
+
+ if (look_for_lines_to_connect()) goto LEAVE;
}
+
SERIAL_FLUSH(); // Prevent host M105 buffer overrun.
+
} while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0);
LEAVE:
@@ -836,7 +905,7 @@
move_to(destination, 0); // Move back to the starting position
//debug_current_and_destination(PSTR("done doing X/Y move."));
- #if ENABLED(ULTRA_LCD)
+ #if ENABLED(ULTIPANEL)
lcd_external_control = false; // Give back control of the LCD Panel!
#endif
diff --git a/Marlin/HAL.h b/Marlin/HAL.h
new file mode 100644
index 0000000000..bb985881c9
--- /dev/null
+++ b/Marlin/HAL.h
@@ -0,0 +1,338 @@
+/* **************************************************************************
+
+ Marlin 3D Printer Firmware
+ Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
+
+ Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
+
+ 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 .
+****************************************************************************/
+
+/**
+ * Description: HAL for __AVR__
+ */
+
+#ifndef _HAL_AVR_H_
+#define _HAL_AVR_H_
+
+// --------------------------------------------------------------------------
+// Includes
+// --------------------------------------------------------------------------
+
+#include "fastio.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+// --------------------------------------------------------------------------
+// Defines
+// --------------------------------------------------------------------------
+
+//#define analogInputToDigitalPin(IO) IO
+
+// Bracket code that shouldn't be interrupted
+#ifndef CRITICAL_SECTION_START
+ #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli()
+ #define CRITICAL_SECTION_END SREG = _sreg
+#endif
+
+#define ISRS_ENABLED() TEST(SREG, SREG_I)
+#define ENABLE_ISRS() sei()
+#define DISABLE_ISRS() cli()
+
+// --------------------------------------------------------------------------
+// Types
+// --------------------------------------------------------------------------
+
+typedef uint16_t hal_timer_t;
+#define HAL_TIMER_TYPE_MAX 0xFFFF
+
+typedef int8_t pin_t;
+
+#define HAL_SERVO_LIB Servo
+
+// --------------------------------------------------------------------------
+// Public Variables
+// --------------------------------------------------------------------------
+
+//extern uint8_t MCUSR;
+
+// --------------------------------------------------------------------------
+// Public functions
+// --------------------------------------------------------------------------
+
+//void cli(void);
+
+//void _delay_ms(const int delay);
+
+inline void HAL_clear_reset_source(void) { MCUSR = 0; }
+inline uint8_t HAL_get_reset_source(void) { return MCUSR; }
+
+// eeprom
+//void eeprom_write_byte(unsigned char *pos, unsigned char value);
+//unsigned char eeprom_read_byte(unsigned char *pos);
+
+// timers
+#define HAL_TIMER_RATE ((F_CPU) / 8) // i.e., 2MHz or 2.5MHz
+
+#define STEP_TIMER_NUM 1
+#define TEMP_TIMER_NUM 0
+#define PULSE_TIMER_NUM STEP_TIMER_NUM
+
+#define TEMP_TIMER_FREQUENCY ((F_CPU) / 64.0 / 256.0)
+
+#define STEPPER_TIMER_RATE HAL_TIMER_RATE
+#define STEPPER_TIMER_PRESCALE 8
+#define STEPPER_TIMER_TICKS_PER_US ((STEPPER_TIMER_RATE) / 1000000) // Cannot be of type double
+
+#define PULSE_TIMER_RATE STEPPER_TIMER_RATE // frequency of pulse timer
+#define PULSE_TIMER_PRESCALE STEPPER_TIMER_PRESCALE
+#define PULSE_TIMER_TICKS_PER_US STEPPER_TIMER_TICKS_PER_US
+
+#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
+#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
+#define STEPPER_ISR_ENABLED() TEST(TIMSK1, OCIE1A)
+
+#define ENABLE_TEMPERATURE_INTERRUPT() SBI(TIMSK0, OCIE0B)
+#define DISABLE_TEMPERATURE_INTERRUPT() CBI(TIMSK0, OCIE0B)
+#define TEMPERATURE_ISR_ENABLED() TEST(TIMSK0, OCIE0B)
+
+FORCE_INLINE void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency) {
+ UNUSED(frequency);
+ switch (timer_num) {
+ case STEP_TIMER_NUM:
+ // waveform generation = 0100 = CTC
+ SET_WGM(1, CTC_OCRnA);
+
+ // output mode = 00 (disconnected)
+ SET_COMA(1, NORMAL);
+
+ // Set the timer pre-scaler
+ // Generally we use a divider of 8, resulting in a 2MHz timer
+ // frequency on a 16MHz MCU. If you are going to change this, be
+ // sure to regenerate speed_lookuptable.h with
+ // create_speed_lookuptable.py
+ SET_CS(1, PRESCALER_8); // CS 2 = 1/8 prescaler
+
+ // Init Stepper ISR to 122 Hz for quick starting
+ // (F_CPU) / (STEPPER_TIMER_PRESCALE) / frequency
+ OCR1A = 0x4000;
+ TCNT1 = 0;
+ break;
+
+ case TEMP_TIMER_NUM:
+ // Use timer0 for temperature measurement
+ // Interleave temperature interrupt with millies interrupt
+ OCR0B = 128;
+ break;
+ }
+}
+
+#define TIMER_OCR_1 OCR1A
+#define TIMER_COUNTER_1 TCNT1
+
+#define TIMER_OCR_0 OCR0A
+#define TIMER_COUNTER_0 TCNT0
+
+#define _CAT(a, ...) a ## __VA_ARGS__
+#define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
+#define HAL_timer_restrain(timer, interval_ticks) NOLESS(_CAT(TIMER_OCR_, timer), _CAT(TIMER_COUNTER_, timer) + interval_ticks)
+
+#define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
+#define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)
+
+/**
+ * On AVR there is no hardware prioritization and preemption of
+ * interrupts, so this emulates it. The UART has first priority
+ * (otherwise, characters will be lost due to UART overflow).
+ * Then: Stepper, Endstops, Temperature, and -finally- all others.
+ */
+#define HAL_timer_isr_prologue(TIMER_NUM)
+#define HAL_timer_isr_epilogue(TIMER_NUM)
+
+/* 18 cycles maximum latency */
+#define HAL_STEP_TIMER_ISR \
+extern "C" void TIMER1_COMPA_vect (void) __attribute__ ((signal, naked, used, externally_visible)); \
+extern "C" void TIMER1_COMPA_vect_bottom (void) asm ("TIMER1_COMPA_vect_bottom") __attribute__ ((used, externally_visible, noinline)); \
+void TIMER1_COMPA_vect (void) { \
+ __asm__ __volatile__ ( \
+ A("push r16") /* 2 Save R16 */ \
+ A("in r16, __SREG__") /* 1 Get SREG */ \
+ A("push r16") /* 2 Save SREG into stack */ \
+ A("lds r16, %[timsk0]") /* 2 Load into R0 the Temperature timer Interrupt mask register */ \
+ A("push r16") /* 2 Save TIMSK0 into the stack */ \
+ A("andi r16,~%[msk0]") /* 1 Disable the temperature ISR */ \
+ A("sts %[timsk0], r16") /* 2 And set the new value */ \
+ A("lds r16, %[timsk1]") /* 2 Load into R0 the stepper timer Interrupt mask register [TIMSK1] */ \
+ A("andi r16,~%[msk1]") /* 1 Disable the stepper ISR */ \
+ A("sts %[timsk1], r16") /* 2 And set the new value */ \
+ A("push r16") /* 2 Save TIMSK1 into stack */ \
+ A("in r16, 0x3B") /* 1 Get RAMPZ register */ \
+ A("push r16") /* 2 Save RAMPZ into stack */ \
+ A("in r16, 0x3C") /* 1 Get EIND register */ \
+ A("push r0") /* C runtime can modify all the following registers without restoring them */ \
+ A("push r1") \
+ A("push r18") \
+ A("push r19") \
+ A("push r20") \
+ A("push r21") \
+ A("push r22") \
+ A("push r23") \
+ A("push r24") \
+ A("push r25") \
+ A("push r26") \
+ A("push r27") \
+ A("push r30") \
+ A("push r31") \
+ A("clr r1") /* C runtime expects this register to be 0 */ \
+ A("call TIMER1_COMPA_vect_bottom") /* Call the bottom handler - No inlining allowed, otherwise registers used are not saved */ \
+ A("pop r31") \
+ A("pop r30") \
+ A("pop r27") \
+ A("pop r26") \
+ A("pop r25") \
+ A("pop r24") \
+ A("pop r23") \
+ A("pop r22") \
+ A("pop r21") \
+ A("pop r20") \
+ A("pop r19") \
+ A("pop r18") \
+ A("pop r1") \
+ A("pop r0") \
+ A("out 0x3C, r16") /* 1 Restore EIND register */ \
+ A("pop r16") /* 2 Get the original RAMPZ register value */ \
+ A("out 0x3B, r16") /* 1 Restore RAMPZ register to its original value */ \
+ A("pop r16") /* 2 Get the original TIMSK1 value but with stepper ISR disabled */ \
+ A("ori r16,%[msk1]") /* 1 Reenable the stepper ISR */ \
+ A("cli") /* 1 Disable global interrupts - Reenabling Stepper ISR can reenter amd temperature can reenter, and we want that, if it happens, after this ISR has ended */ \
+ A("sts %[timsk1], r16") /* 2 And restore the old value - This reenables the stepper ISR */ \
+ A("pop r16") /* 2 Get the temperature timer Interrupt mask register [TIMSK0] */ \
+ A("sts %[timsk0], r16") /* 2 And restore the old value - This reenables the temperature ISR */ \
+ A("pop r16") /* 2 Get the old SREG value */ \
+ A("out __SREG__, r16") /* 1 And restore the SREG value */ \
+ A("pop r16") /* 2 Restore R16 value */ \
+ A("reti") /* 4 Return from interrupt */ \
+ : \
+ : [timsk0] "i" ((uint16_t)&TIMSK0), \
+ [timsk1] "i" ((uint16_t)&TIMSK1), \
+ [msk0] "M" ((uint8_t)(1< 7) ADCSRB = _BV(MUX5); else ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
+#else
+ #define HAL_START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
+#endif
+
+#define HAL_READ_ADC ADC
+
+#define GET_PIN_MAP_PIN(index) index
+#define GET_PIN_MAP_INDEX(pin) pin
+#define PARSED_PIN_INDEX(code, dval) parser.intval(code, dval)
+
+#define HAL_SENSITIVE_PINS 0, 1
+
+#endif // _HAL_AVR_H_
diff --git a/Marlin/I2CPositionEncoder.cpp b/Marlin/I2CPositionEncoder.cpp
index 95e0f1b725..285ba0d66f 100644
--- a/Marlin/I2CPositionEncoder.cpp
+++ b/Marlin/I2CPositionEncoder.cpp
@@ -99,7 +99,7 @@
//the encoder likely lost its place when the error occured, so we'll reset and use the printer's
//idea of where it the axis is to re-initialise
- float position = stepper.get_axis_position_mm(encoderAxis);
+ float position = planner.get_axis_position_mm(encoderAxis);
int32_t positionInTicks = position * get_ticks_unit();
//shift position from previous to current position
@@ -134,7 +134,7 @@
#ifdef I2CPE_EC_THRESH_PROPORTIONAL
const millis_t deltaTime = positionTime - lastPositionTime;
- const uint32_t distance = abs(position - lastPosition),
+ const uint32_t distance = ABS(position - lastPosition),
speed = distance / deltaTime;
const float threshold = constrain((speed / 50), 1, 50) * ecThreshold;
#else
@@ -150,7 +150,7 @@
LOOP_L_N(i, I2CPE_ERR_ARRAY_SIZE) {
sum += err[i];
- if (i) diffSum += abs(err[i-1] - err[i]);
+ if (i) diffSum += ABS(err[i-1] - err[i]);
}
const int32_t error = int32_t(sum / (I2CPE_ERR_ARRAY_SIZE + 1)); //calculate average for error
@@ -163,7 +163,7 @@
//SERIAL_ECHOLN(error);
#ifdef I2CPE_ERR_THRESH_ABORT
- if (labs(error) > I2CPE_ERR_THRESH_ABORT * planner.axis_steps_per_mm[encoderAxis]) {
+ if (ABS(error) > I2CPE_ERR_THRESH_ABORT * planner.axis_steps_per_mm[encoderAxis]) {
//kill("Significant Error");
SERIAL_ECHOPGM("Axis error greater than set threshold, aborting!");
SERIAL_ECHOLN(error);
@@ -175,13 +175,13 @@
if (errIdx == 0) {
// In order to correct for "error" but avoid correcting for noise and non-skips
// it must be > threshold and have a difference average of < 10 and be < 2000 steps
- if (labs(error) > threshold * planner.axis_steps_per_mm[encoderAxis] &&
- diffSum < 10 * (I2CPE_ERR_ARRAY_SIZE - 1) && labs(error) < 2000) { // Check for persistent error (skip)
+ if (ABS(error) > threshold * planner.axis_steps_per_mm[encoderAxis] &&
+ diffSum < 10 * (I2CPE_ERR_ARRAY_SIZE - 1) && ABS(error) < 2000) { // Check for persistent error (skip)
errPrst[errPrstIdx++] = error; // Error must persist for I2CPE_ERR_PRST_ARRAY_SIZE error cycles. This also serves to improve the average accuracy
if (errPrstIdx >= I2CPE_ERR_PRST_ARRAY_SIZE) {
float sumP = 0;
LOOP_L_N(i, I2CPE_ERR_PRST_ARRAY_SIZE) sumP += errPrst[i];
- const int32_t errorP = int32_t(sumP * (1.0 / (I2CPE_ERR_PRST_ARRAY_SIZE)));
+ const int32_t errorP = int32_t(sumP * (1.0f / (I2CPE_ERR_PRST_ARRAY_SIZE)));
SERIAL_ECHO(axis_codes[encoderAxis]);
SERIAL_ECHOPAIR(" - err detected: ", errorP * planner.steps_to_mm[encoderAxis]);
SERIAL_ECHOLNPGM("mm; correcting!");
@@ -193,14 +193,14 @@
errPrstIdx = 0;
}
#else
- if (labs(error) > threshold * planner.axis_steps_per_mm[encoderAxis]) {
+ if (ABS(error) > threshold * planner.axis_steps_per_mm[encoderAxis]) {
//SERIAL_ECHOLN(error);
//SERIAL_ECHOLN(position);
thermalManager.babystepsTodo[encoderAxis] = -LROUND(error / 2);
}
#endif
- if (labs(error) > I2CPE_ERR_CNT_THRESH * planner.axis_steps_per_mm[encoderAxis]) {
+ if (ABS(error) > I2CPE_ERR_CNT_THRESH * planner.axis_steps_per_mm[encoderAxis]) {
const millis_t ms = millis();
if (ELAPSED(ms, nextErrorCountTime)) {
SERIAL_ECHOPAIR("Large error on ", axis_codes[encoderAxis]);
@@ -254,11 +254,11 @@
float I2CPositionEncoder::get_axis_error_mm(const bool report) {
float target, actual, error;
- target = stepper.get_axis_position_mm(encoderAxis);
+ target = planner.get_axis_position_mm(encoderAxis);
actual = mm_from_count(position);
error = actual - target;
- if (labs(error) > 10000) error = 0; // ?
+ if (ABS(error) > 10000) error = 0; // ?
if (report) {
SERIAL_ECHO(axis_codes[encoderAxis]);
@@ -293,7 +293,7 @@
error = (encoderCountInStepperTicksScaled - target);
//suppress discontinuities (might be caused by bad I2C readings...?)
- bool suppressOutput = (labs(error - errorPrev) > 100);
+ const bool suppressOutput = (ABS(error - errorPrev) > 100);
if (report) {
SERIAL_ECHO(axis_codes[encoderAxis]);
@@ -349,18 +349,18 @@
ec = false;
LOOP_NA(i) {
- startCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
- endCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
+ startCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
+ endCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
}
startCoord[encoderAxis] = startPosition;
endCoord[encoderAxis] = endPosition;
- stepper.synchronize();
+ planner.synchronize();
- planner.buffer_line(startCoord[X_AXIS],startCoord[Y_AXIS],startCoord[Z_AXIS],
- stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
- stepper.synchronize();
+ planner.buffer_line(startCoord[X_AXIS], startCoord[Y_AXIS], startCoord[Z_AXIS],
+ planner.get_axis_position_mm(E_AXIS), feedrate, 0);
+ planner.synchronize();
// if the module isn't currently trusted, wait until it is (or until it should be if things are working)
if (!trusted) {
@@ -371,8 +371,8 @@
if (trusted) { // if trusted, commence test
planner.buffer_line(endCoord[X_AXIS], endCoord[Y_AXIS], endCoord[Z_AXIS],
- stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
- stepper.synchronize();
+ planner.get_axis_position_mm(E_AXIS), feedrate, 0);
+ planner.synchronize();
}
return trusted;
@@ -408,34 +408,34 @@
travelDistance = endDistance - startDistance;
LOOP_NA(i) {
- startCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
- endCoord[i] = stepper.get_axis_position_mm((AxisEnum)i);
+ startCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
+ endCoord[i] = planner.get_axis_position_mm((AxisEnum)i);
}
startCoord[encoderAxis] = startDistance;
endCoord[encoderAxis] = endDistance;
- LOOP_L_N(i, iter) {
- stepper.synchronize();
+ planner.synchronize();
- planner.buffer_line(startCoord[X_AXIS],startCoord[Y_AXIS],startCoord[Z_AXIS],
- stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
- stepper.synchronize();
+ LOOP_L_N(i, iter) {
+ planner.buffer_line(startCoord[X_AXIS], startCoord[Y_AXIS], startCoord[Z_AXIS],
+ planner.get_axis_position_mm(E_AXIS), feedrate, 0);
+ planner.synchronize();
delay(250);
startCount = get_position();
//do_blocking_move_to(endCoord[X_AXIS],endCoord[Y_AXIS],endCoord[Z_AXIS]);
- planner.buffer_line(endCoord[X_AXIS],endCoord[Y_AXIS],endCoord[Z_AXIS],
- stepper.get_axis_position_mm(E_AXIS), feedrate, 0);
- stepper.synchronize();
+ planner.buffer_line(endCoord[X_AXIS], endCoord[Y_AXIS], endCoord[Z_AXIS],
+ planner.get_axis_position_mm(E_AXIS), feedrate, 0);
+ planner.synchronize();
//Read encoder distance
delay(250);
stopCount = get_position();
- travelledDistance = mm_from_count(abs(stopCount - startCount));
+ travelledDistance = mm_from_count(ABS(stopCount - startCount));
SERIAL_ECHOPAIR("Attempted to travel: ", travelDistance);
SERIAL_ECHOLNPGM("mm.");
diff --git a/Marlin/I2CPositionEncoder.h b/Marlin/I2CPositionEncoder.h
index 7e5513423f..a0e8a6199a 100644
--- a/Marlin/I2CPositionEncoder.h
+++ b/Marlin/I2CPositionEncoder.h
@@ -134,16 +134,12 @@
nextErrorCountTime = 0,
lastErrorTime;
- //double positionMm; //calculate
-
#if ENABLED(I2CPE_ERR_ROLLING_AVERAGE)
uint8_t errIdx = 0, errPrstIdx = 0;
int err[I2CPE_ERR_ARRAY_SIZE] = { 0 },
errPrst[I2CPE_ERR_PRST_ARRAY_SIZE] = { 0 };
#endif
- //float positionMm; //calculate
-
public:
void init(const uint8_t address, const AxisEnum axis);
void reset();
diff --git a/Marlin/Marlin.h b/Marlin/Marlin.h
index aadbbdaf24..ef4c0f2b06 100644
--- a/Marlin/Marlin.h
+++ b/Marlin/Marlin.h
@@ -60,10 +60,10 @@ extern const char axis_codes[XYZE];
#if HAS_X2_ENABLE
#define enable_X() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0)
- #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
+ #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); CBI(axis_known_position, X_AXIS); }while(0)
#elif HAS_X_ENABLE
#define enable_X() X_ENABLE_WRITE( X_ENABLE_ON)
- #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0)
+ #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); CBI(axis_known_position, X_AXIS); }while(0)
#else
#define enable_X() NOOP
#define disable_X() NOOP
@@ -71,10 +71,10 @@ extern const char axis_codes[XYZE];
#if HAS_Y2_ENABLE
#define enable_Y() do{ Y_ENABLE_WRITE( Y_ENABLE_ON); Y2_ENABLE_WRITE(Y_ENABLE_ON); }while(0)
- #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
+ #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); Y2_ENABLE_WRITE(!Y_ENABLE_ON); CBI(axis_known_position, Y_AXIS); }while(0)
#elif HAS_Y_ENABLE
#define enable_Y() Y_ENABLE_WRITE( Y_ENABLE_ON)
- #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); axis_known_position[Y_AXIS] = false; }while(0)
+ #define disable_Y() do{ Y_ENABLE_WRITE(!Y_ENABLE_ON); CBI(axis_known_position, Y_AXIS); }while(0)
#else
#define enable_Y() NOOP
#define disable_Y() NOOP
@@ -82,10 +82,10 @@ extern const char axis_codes[XYZE];
#if HAS_Z2_ENABLE
#define enable_Z() do{ Z_ENABLE_WRITE( Z_ENABLE_ON); Z2_ENABLE_WRITE(Z_ENABLE_ON); }while(0)
- #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
+ #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); Z2_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
#elif HAS_Z_ENABLE
#define enable_Z() Z_ENABLE_WRITE( Z_ENABLE_ON)
- #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); axis_known_position[Z_AXIS] = false; }while(0)
+ #define disable_Z() do{ Z_ENABLE_WRITE(!Z_ENABLE_ON); CBI(axis_known_position, Z_AXIS); }while(0)
#else
#define enable_Z() NOOP
#define disable_Z() NOOP
@@ -220,11 +220,16 @@ inline void reset_stepper_timeout() { previous_move_ms = millis(); }
extern float feedrate_mm_s;
extern int16_t feedrate_percentage;
-#define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01)
+#define MMS_SCALED(MM_S) ((MM_S)*feedrate_percentage*0.01f)
+
+extern bool axis_relative_modes[XYZE];
+
+extern uint8_t axis_homed, axis_known_position;
+
+constexpr uint8_t xyz_bits = _BV(X_AXIS) | _BV(Y_AXIS) | _BV(Z_AXIS);
+FORCE_INLINE bool all_axes_homed() { return (axis_homed & xyz_bits) == xyz_bits; }
+FORCE_INLINE bool all_axes_known() { return (axis_known_position & xyz_bits) == xyz_bits; }
-extern bool axis_relative_modes[];
-extern bool axis_known_position[XYZ];
-extern bool axis_homed[XYZ];
extern volatile bool wait_for_heatup;
#if HAS_RESUME_CONTINUE
@@ -316,22 +321,15 @@ void report_current_position();
void recalc_delta_settings();
float delta_safe_distance_from_top();
- #if ENABLED(DELTA_FAST_SQRT)
- float Q_rsqrt(const float number);
- #define _SQRT(n) (1.0f / Q_rsqrt(n))
- #else
- #define _SQRT(n) SQRT(n)
- #endif
-
// Macro to obtain the Z position of an individual tower
- #define DELTA_Z(V,T) V[Z_AXIS] + _SQRT( \
+ #define DELTA_Z(V,T) V[Z_AXIS] + SQRT( \
delta_diagonal_rod_2_tower[T] - HYPOT2( \
delta_tower[T][X_AXIS] - V[X_AXIS], \
delta_tower[T][Y_AXIS] - V[Y_AXIS] \
) \
)
- #define DELTA_IK(V) do { \
+ #define DELTA_IK(V) do { \
delta[A_AXIS] = DELTA_Z(V, A_AXIS); \
delta[B_AXIS] = DELTA_Z(V, B_AXIS); \
delta[C_AXIS] = DELTA_Z(V, C_AXIS); \
@@ -370,11 +368,6 @@ void report_current_position();
void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, const element_2d_fn fn);
#endif
-#if ENABLED(AUTO_BED_LEVELING_UBL)
- typedef struct { double A, B, D; } linear_fit;
- linear_fit* lsf_linear_fit(double x[], double y[], double z[], const int);
-#endif
-
#if HAS_LEVELING
bool leveling_is_valid();
void set_bed_leveling_enabled(const bool enable=true);
@@ -388,7 +381,7 @@ void report_current_position();
#if HAS_BED_PROBE
extern float zprobe_zoffset;
bool set_probe_deployed(const bool deploy);
- #if Z_AFTER_PROBING
+ #ifdef Z_AFTER_PROBING
void move_z_after_probing();
#endif
enum ProbePtRaise : unsigned char {
@@ -448,10 +441,6 @@ void report_current_position();
filament_change_load_length[EXTRUDERS];
#endif
-#if ENABLED(PID_EXTRUSION_SCALING)
- extern int lpq_len;
-#endif
-
#if HAS_POWER_SWITCH
extern bool powersupply_on;
#define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE); powersupply_on = true; }while(0)
@@ -472,10 +461,14 @@ void prepare_move_to_destination();
/**
* Blocking movement and shorthand functions
*/
-void do_blocking_move_to(const float rx, const float ry, const float rz, const float &fr_mm_s=0.0);
-void do_blocking_move_to_x(const float &rx, const float &fr_mm_s=0.0);
-void do_blocking_move_to_z(const float &rz, const float &fr_mm_s=0.0);
-void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm_s=0.0);
+void do_blocking_move_to(const float rx, const float ry, const float rz, const float &fr_mm_s=0);
+void do_blocking_move_to_x(const float &rx, const float &fr_mm_s=0);
+void do_blocking_move_to_z(const float &rz, const float &fr_mm_s=0);
+void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm_s=0);
+
+#if ENABLED(ARC_SUPPORT)
+ void plan_arc(const float(&cart)[XYZE], const float(&offset)[2], const bool clockwise);
+#endif
#define HAS_AXIS_UNHOMED_ERR ( \
ENABLED(Z_PROBE_ALLEN_KEY) \
@@ -522,7 +515,7 @@ void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm
// Note: This won't work on SCARA since the probe offset rotates with the arm.
inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER))
- && position_is_reachable(rx, ry, FABS(MIN_PROBE_EDGE));
+ && position_is_reachable(rx, ry, ABS(MIN_PROBE_EDGE));
}
#endif
@@ -531,8 +524,8 @@ void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm
// Return true if the given position is within the machine bounds.
inline bool position_is_reachable(const float &rx, const float &ry) {
// Add 0.001 margin to deal with float imprecision
- return WITHIN(rx, X_MIN_POS - 0.001, X_MAX_POS + 0.001)
- && WITHIN(ry, Y_MIN_POS - 0.001, Y_MAX_POS + 0.001);
+ return WITHIN(rx, X_MIN_POS - 0.001f, X_MAX_POS + 0.001f)
+ && WITHIN(ry, Y_MIN_POS - 0.001f, Y_MAX_POS + 0.001f);
}
#if HAS_BED_PROBE
@@ -545,8 +538,8 @@ void do_blocking_move_to_xy(const float &rx, const float &ry, const float &fr_mm
*/
inline bool position_is_reachable_by_probe(const float &rx, const float &ry) {
return position_is_reachable(rx - (X_PROBE_OFFSET_FROM_EXTRUDER), ry - (Y_PROBE_OFFSET_FROM_EXTRUDER))
- && WITHIN(rx, MIN_PROBE_X - 0.001, MAX_PROBE_X + 0.001)
- && WITHIN(ry, MIN_PROBE_Y - 0.001, MAX_PROBE_Y + 0.001);
+ && WITHIN(rx, MIN_PROBE_X - 0.001f, MAX_PROBE_X + 0.001f)
+ && WITHIN(ry, MIN_PROBE_Y - 0.001f, MAX_PROBE_Y + 0.001f);
}
#endif
diff --git a/Marlin/Marlin.ino b/Marlin/Marlin.ino
index 842b2a14b9..1491c4efd5 100644
--- a/Marlin/Marlin.ino
+++ b/Marlin/Marlin.ino
@@ -12,8 +12,8 @@
Greetings! Thank you for choosing Marlin 2 as your 3D printer firmware.
To configure Marlin you must edit Configuration.h and Configuration_adv.h
-located in the root 'Marlin' folder. Check the config/examples folder to see if
-there's a more suitable starting-point for your specific hardware.
+located in the root 'Marlin' folder. Check the example_configurations folder to
+see if there's a more suitable starting-point for your specific hardware.
Before diving in, we recommend the following essential links:
diff --git a/Marlin/MarlinConfig.h b/Marlin/MarlinConfig.h
index 5f77dba0e4..f0aa130443 100644
--- a/Marlin/MarlinConfig.h
+++ b/Marlin/MarlinConfig.h
@@ -23,21 +23,25 @@
#ifndef MARLIN_CONFIG_H
#define MARLIN_CONFIG_H
-#include "fastio.h"
-#include "macros.h"
#include "boards.h"
+#include "macros.h"
#include "Version.h"
#include "Configuration.h"
#include "Conditionals_LCD.h"
#include "Configuration_adv.h"
-#include "pins.h"
-#if defined(__AVR__) && !defined(USBCON)
+
+#if USE_MARLINSERIAL
#define HardwareSerial_h // trick to disable the standard HWserial
#endif
-#include "Arduino.h"
+
+#include "types.h"
+#include "HAL.h"
+#include "pins.h"
#include "Conditionals_post.h"
#include "SanityCheck.h"
-
-#include
+#include "enum.h"
+#include "language.h"
+#include "utility.h"
+#include "serial.h"
#endif // MARLIN_CONFIG_H
diff --git a/Marlin/MarlinSerial.cpp b/Marlin/MarlinSerial.cpp
index cd4dd03ade..86d4c440ef 100644
--- a/Marlin/MarlinSerial.cpp
+++ b/Marlin/MarlinSerial.cpp
@@ -28,13 +28,14 @@
* Modified 28 September 2010 by Mark Sproul
* Modified 14 February 2016 by Andreas Hardtung (added tx buffer)
* Modified 01 October 2017 by Eduardo José Tagle (added XON/XOFF)
+ * Modified 10 June 2018 by Eduardo José Tagle (See #10991)
*/
// Disable HardwareSerial.cpp to support chips without a UART (Attiny, etc.)
#include "MarlinConfig.h"
-#if !(defined(__AVR__) && defined(USBCON)) && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H))
+#if USE_MARLINSERIAL && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H))
#include "MarlinSerial.h"
#include "Marlin.h"
@@ -55,140 +56,312 @@
ring_buffer_r rx_buffer = { { 0 }, 0, 0 };
#if TX_BUFFER_SIZE > 0
ring_buffer_t tx_buffer = { { 0 }, 0, 0 };
- static bool _written;
#endif
+ static bool _written;
#endif
#if ENABLED(SERIAL_XON_XOFF)
- constexpr uint8_t XON_XOFF_CHAR_SENT = 0x80; // XON / XOFF Character was sent
- constexpr uint8_t XON_XOFF_CHAR_MASK = 0x1F; // XON / XOFF character to send
+ constexpr uint8_t XON_XOFF_CHAR_SENT = 0x80, // XON / XOFF Character was sent
+ XON_XOFF_CHAR_MASK = 0x1F; // XON / XOFF character to send
// XON / XOFF character definitions
- constexpr uint8_t XON_CHAR = 17;
- constexpr uint8_t XOFF_CHAR = 19;
+ constexpr uint8_t XON_CHAR = 17, XOFF_CHAR = 19;
uint8_t xon_xoff_state = XON_XOFF_CHAR_SENT | XON_CHAR;
#endif
- void clear_command_queue();
-
#if ENABLED(SERIAL_STATS_DROPPED_RX)
uint8_t rx_dropped_bytes = 0;
#endif
+ #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
+ uint8_t rx_buffer_overruns = 0;
+ #endif
+
+ #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
+ uint8_t rx_framing_errors = 0;
+ #endif
+
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
ring_buffer_pos_t rx_max_enqueued = 0;
#endif
+ // A SW memory barrier, to ensure GCC does not overoptimize loops
+ #define sw_barrier() asm volatile("": : :"memory");
+
#if ENABLED(EMERGENCY_PARSER)
#include "emergency_parser.h"
#endif
+ // "Atomically" read the RX head index value without disabling interrupts:
+ // This MUST be called with RX interrupts enabled, and CAN'T be called
+ // from the RX ISR itself!
+ FORCE_INLINE ring_buffer_pos_t atomic_read_rx_head() {
+ #if RX_BUFFER_SIZE > 256
+ // Keep reading until 2 consecutive reads return the same value,
+ // meaning there was no update in-between caused by an interrupt.
+ // This works because serial RX interrupts happen at a slower rate
+ // than successive reads of a variable, so 2 consecutive reads with
+ // the same value means no interrupt updated it.
+ ring_buffer_pos_t vold, vnew = rx_buffer.head;
+ sw_barrier();
+ do {
+ vold = vnew;
+ vnew = rx_buffer.head;
+ sw_barrier();
+ } while (vold != vnew);
+ return vnew;
+ #else
+ // With an 8bit index, reads are always atomic. No need for special handling
+ return rx_buffer.head;
+ #endif
+ }
+
+ #if RX_BUFFER_SIZE > 256
+ static volatile bool rx_tail_value_not_stable = false;
+ static volatile uint16_t rx_tail_value_backup = 0;
+ #endif
+
+ // Set RX tail index, taking into account the RX ISR could interrupt
+ // the write to this variable in the middle - So a backup strategy
+ // is used to ensure reads of the correct values.
+ // -Must NOT be called from the RX ISR -
+ FORCE_INLINE void atomic_set_rx_tail(ring_buffer_pos_t value) {
+ #if RX_BUFFER_SIZE > 256
+ // Store the new value in the backup
+ rx_tail_value_backup = value;
+ sw_barrier();
+ // Flag we are about to change the true value
+ rx_tail_value_not_stable = true;
+ sw_barrier();
+ // Store the new value
+ rx_buffer.tail = value;
+ sw_barrier();
+ // Signal the new value is completely stored into the value
+ rx_tail_value_not_stable = false;
+ sw_barrier();
+ #else
+ rx_buffer.tail = value;
+ #endif
+ }
+
+ // Get the RX tail index, taking into account the read could be
+ // interrupting in the middle of the update of that index value
+ // -Called from the RX ISR -
+ FORCE_INLINE ring_buffer_pos_t atomic_read_rx_tail() {
+ #if RX_BUFFER_SIZE > 256
+ // If the true index is being modified, return the backup value
+ if (rx_tail_value_not_stable) return rx_tail_value_backup;
+ #endif
+ // The true index is stable, return it
+ return rx_buffer.tail;
+ }
+
+ // (called with RX interrupts disabled)
FORCE_INLINE void store_rxd_char() {
- const ring_buffer_pos_t h = rx_buffer.head,
- i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
+ // Get the tail - Nothing can alter its value while this ISR is executing, but there's
+ // a chance that this ISR interrupted the main process while it was updating the index.
+ // The backup mechanism ensures the correct value is always returned.
+ const ring_buffer_pos_t t = atomic_read_rx_tail();
+
+ // Get the head pointer - This ISR is the only one that modifies its value, so it's safe to read here
+ ring_buffer_pos_t h = rx_buffer.head;
+
+ // Get the next element
+ ring_buffer_pos_t i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
+
+ // This must read the M_UCSRxA register before reading the received byte to detect error causes
+ #if ENABLED(SERIAL_STATS_DROPPED_RX)
+ if (TEST(M_UCSRxA, M_DORx) && !++rx_dropped_bytes) --rx_dropped_bytes;
+ #endif
+
+ #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
+ if (TEST(M_UCSRxA, M_DORx) && !++rx_buffer_overruns) --rx_buffer_overruns;
+ #endif
+
+ #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
+ if (TEST(M_UCSRxA, M_FEx) && !++rx_framing_errors) --rx_framing_errors;
+ #endif
+
+ // Read the character from the USART
+ uint8_t c = M_UDRx;
+
+ #if ENABLED(EMERGENCY_PARSER)
+ emergency_parser.update(c);
+ #endif
// If the character is to be stored at the index just before the tail
- // (such that the head would advance to the current tail), the buffer is
- // critical, so don't write the character or advance the head.
- const char c = M_UDRx;
- if (i != rx_buffer.tail) {
+ // (such that the head would advance to the current tail), the RX FIFO is
+ // full, so don't write the character or advance the head.
+ if (i != t) {
rx_buffer.buffer[h] = c;
- rx_buffer.head = i;
- }
- else {
- #if ENABLED(SERIAL_STATS_DROPPED_RX)
- if (!++rx_dropped_bytes) ++rx_dropped_bytes;
- #endif
+ h = i;
}
+ #if ENABLED(SERIAL_STATS_DROPPED_RX)
+ else if (!++rx_dropped_bytes) --rx_dropped_bytes;
+ #endif
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
- // calculate count of bytes stored into the RX buffer
- ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(rx_buffer.head - rx_buffer.tail) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
+ // Calculate count of bytes stored into the RX buffer
+ const ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(h - t) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
+
// Keep track of the maximum count of enqueued bytes
NOLESS(rx_max_enqueued, rx_count);
#endif
#if ENABLED(SERIAL_XON_XOFF)
-
- // for high speed transfers, we can use XON/XOFF protocol to do
- // software handshake and avoid overruns.
+ // If the last char that was sent was an XON
if ((xon_xoff_state & XON_XOFF_CHAR_MASK) == XON_CHAR) {
- // calculate count of bytes stored into the RX buffer
- ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(rx_buffer.head - rx_buffer.tail) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
+ // Bytes stored into the RX buffer
+ const ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(h - t) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
- // if we are above 12.5% of RX buffer capacity, send XOFF before
- // we run out of RX buffer space .. We need 325 bytes @ 250kbits/s to
- // let the host react and stop sending bytes. This translates to 13mS
- // propagation time.
+ // If over 12.5% of RX buffer capacity, send XOFF before running out of
+ // RX buffer space .. 325 bytes @ 250kbits/s needed to let the host react
+ // and stop sending bytes. This translates to 13mS propagation time.
if (rx_count >= (RX_BUFFER_SIZE) / 8) {
- // If TX interrupts are disabled and data register is empty,
- // just write the byte to the data register and be done. This
- // shortcut helps significantly improve the effective datarate
- // at high (>500kbit/s) bitrates, where interrupt overhead
- // becomes a slowdown.
- if (!TEST(M_UCSRxB, M_UDRIEx) && TEST(M_UCSRxA, M_UDREx)) {
- // Send an XOFF character
- M_UDRx = XOFF_CHAR;
- // clear the TXC bit -- "can be cleared by writing a one to its bit
- // location". This makes sure flush() won't return until the bytes
- // actually got written
- SBI(M_UCSRxA, M_TXCx);
- // And remember it was sent
- xon_xoff_state = XOFF_CHAR | XON_XOFF_CHAR_SENT;
+
+ // At this point, definitely no TX interrupt was executing, since the TX ISR can't be preempted.
+ // Don't enable the TX interrupt here as a means to trigger the XOFF char, because if it happens
+ // to be in the middle of trying to disable the RX interrupt in the main program, eventually the
+ // enabling of the TX interrupt could be undone. The ONLY reliable thing this can do to ensure
+ // the sending of the XOFF char is to send it HERE AND NOW.
+
+ // About to send the XOFF char
+ xon_xoff_state = XOFF_CHAR | XON_XOFF_CHAR_SENT;
+
+ // Wait until the TX register becomes empty and send it - Here there could be a problem
+ // - While waiting for the TX register to empty, the RX register could receive a new
+ // character. This must also handle that situation!
+ while (!TEST(M_UCSRxA, M_UDREx)) {
+
+ if (TEST(M_UCSRxA,M_RXCx)) {
+ // A char arrived while waiting for the TX buffer to be empty - Receive and process it!
+
+ i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
+
+ // Read the character from the USART
+ c = M_UDRx;
+
+ #if ENABLED(EMERGENCY_PARSER)
+ emergency_parser.update(c);
+ #endif
+
+ // If the character is to be stored at the index just before the tail
+ // (such that the head would advance to the current tail), the FIFO is
+ // full, so don't write the character or advance the head.
+ if (i != t) {
+ rx_buffer.buffer[h] = c;
+ h = i;
+ }
+ #if ENABLED(SERIAL_STATS_DROPPED_RX)
+ else if (!++rx_dropped_bytes) --rx_dropped_bytes;
+ #endif
+ }
+ sw_barrier();
}
- else {
- // TX interrupts disabled, but buffer still not empty ... or
- // TX interrupts enabled. Reenable TX ints and schedule XOFF
- // character to be sent
- #if TX_BUFFER_SIZE > 0
- SBI(M_UCSRxB, M_UDRIEx);
- xon_xoff_state = XOFF_CHAR;
- #else
- // We are not using TX interrupts, we will have to send this manually
- while (!TEST(M_UCSRxA, M_UDREx)) {/* nada */}
- M_UDRx = XOFF_CHAR;
- // And remember we already sent it
- xon_xoff_state = XOFF_CHAR | XON_XOFF_CHAR_SENT;
- #endif
+
+ M_UDRx = XOFF_CHAR;
+
+ // Clear the TXC bit -- "can be cleared by writing a one to its bit
+ // location". This makes sure flush() won't return until the bytes
+ // actually got written
+ SBI(M_UCSRxA, M_TXCx);
+
+ // At this point there could be a race condition between the write() function
+ // and this sending of the XOFF char. This interrupt could happen between the
+ // wait to be empty TX buffer loop and the actual write of the character. Since
+ // the TX buffer is full because it's sending the XOFF char, the only way to be
+ // sure the write() function will succeed is to wait for the XOFF char to be
+ // completely sent. Since an extra character could be received during the wait
+ // it must also be handled!
+ while (!TEST(M_UCSRxA, M_UDREx)) {
+
+ if (TEST(M_UCSRxA,M_RXCx)) {
+ // A char arrived while waiting for the TX buffer to be empty - Receive and process it!
+
+ i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
+
+ // Read the character from the USART
+ c = M_UDRx;
+
+ #if ENABLED(EMERGENCY_PARSER)
+ emergency_parser.update(c);
+ #endif
+
+ // If the character is to be stored at the index just before the tail
+ // (such that the head would advance to the current tail), the FIFO is
+ // full, so don't write the character or advance the head.
+ if (i != t) {
+ rx_buffer.buffer[h] = c;
+ h = i;
+ }
+ #if ENABLED(SERIAL_STATS_DROPPED_RX)
+ else if (!++rx_dropped_bytes) --rx_dropped_bytes;
+ #endif
+ }
+ sw_barrier();
}
+
+ // At this point everything is ready. The write() function won't
+ // have any issues writing to the UART TX register if it needs to!
}
}
#endif // SERIAL_XON_XOFF
- #if ENABLED(EMERGENCY_PARSER)
- emergency_parser.update(c);
- #endif
+ // Store the new head value - The main loop will retry until the value is stable
+ rx_buffer.head = h;
}
#if TX_BUFFER_SIZE > 0
+ // (called with TX irqs disabled)
FORCE_INLINE void _tx_udr_empty_irq(void) {
- // If interrupts are enabled, there must be more data in the output
- // buffer.
+
+ // Read positions
+ uint8_t t = tx_buffer.tail;
+ const uint8_t h = tx_buffer.head;
#if ENABLED(SERIAL_XON_XOFF)
- // Do a priority insertion of an XON/XOFF char, if needed.
- const uint8_t state = xon_xoff_state;
- if (!(state & XON_XOFF_CHAR_SENT)) {
- M_UDRx = state & XON_XOFF_CHAR_MASK;
- xon_xoff_state = state | XON_XOFF_CHAR_SENT;
+ // If an XON char is pending to be sent, do it now
+ if (xon_xoff_state == XON_CHAR) {
+
+ // Send the character
+ M_UDRx = XON_CHAR;
+
+ // clear the TXC bit -- "can be cleared by writing a one to its bit
+ // location". This makes sure flush() won't return until the bytes
+ // actually got written
+ SBI(M_UCSRxA, M_TXCx);
+
+ // Remember we sent it.
+ xon_xoff_state = XON_CHAR | XON_XOFF_CHAR_SENT;
+
+ // If nothing else to transmit, just disable TX interrupts.
+ if (h == t) CBI(M_UCSRxB, M_UDRIEx); // (Non-atomic, could be reenabled by the main program, but eventually this will succeed)
+
+ return;
}
- else
#endif
- { // Send the next byte
- const uint8_t t = tx_buffer.tail, c = tx_buffer.buffer[t];
- tx_buffer.tail = (t + 1) & (TX_BUFFER_SIZE - 1);
- M_UDRx = c;
+
+ // If nothing to transmit, just disable TX interrupts. This could
+ // happen as the result of the non atomicity of the disabling of RX
+ // interrupts that could end reenabling TX interrupts as a side effect.
+ if (h == t) {
+ CBI(M_UCSRxB, M_UDRIEx); // (Non-atomic, could be reenabled by the main program, but eventually this will succeed)
+ return;
}
- // clear the TXC bit -- "can be cleared by writing a one to its bit
- // location". This makes sure flush() won't return until the bytes
- // actually got written
+ // There is something to TX, Send the next byte
+ const uint8_t c = tx_buffer.buffer[t];
+ t = (t + 1) & (TX_BUFFER_SIZE - 1);
+ M_UDRx = c;
+ tx_buffer.tail = t;
+
+ // Clear the TXC bit (by writing a one to its bit location).
+ // Ensures flush() won't return until the bytes are actually written/
SBI(M_UCSRxA, M_TXCx);
- // Disable interrupts if the buffer is empty
- if (tx_buffer.head == tx_buffer.tail)
- CBI(M_UCSRxB, M_UDRIEx);
+ // Disable interrupts if there is nothing to transmit following this byte
+ if (h == t) CBI(M_UCSRxB, M_UDRIEx); // (Non-atomic, could be reenabled by the main program, but eventually this will succeed)
}
#ifdef M_USARTx_UDRE_vect
@@ -232,8 +405,8 @@
SBI(M_UCSRxB, M_RXCIEx);
#if TX_BUFFER_SIZE > 0
CBI(M_UCSRxB, M_UDRIEx);
- _written = false;
#endif
+ _written = false;
}
void MarlinSerial::end() {
@@ -243,177 +416,179 @@
CBI(M_UCSRxB, M_UDRIEx);
}
- void MarlinSerial::checkRx(void) {
- if (TEST(M_UCSRxA, M_RXCx)) {
- CRITICAL_SECTION_START;
- store_rxd_char();
- CRITICAL_SECTION_END;
- }
- }
-
int MarlinSerial::peek(void) {
- CRITICAL_SECTION_START;
- const int v = rx_buffer.head == rx_buffer.tail ? -1 : rx_buffer.buffer[rx_buffer.tail];
- CRITICAL_SECTION_END;
- return v;
+ const ring_buffer_pos_t h = atomic_read_rx_head(), t = rx_buffer.tail;
+ return h == t ? -1 : rx_buffer.buffer[t];
}
int MarlinSerial::read(void) {
- int v;
- CRITICAL_SECTION_START;
- const ring_buffer_pos_t t = rx_buffer.tail;
- if (rx_buffer.head == t)
- v = -1;
- else {
- v = rx_buffer.buffer[t];
- rx_buffer.tail = (ring_buffer_pos_t)(t + 1) & (RX_BUFFER_SIZE - 1);
+ const ring_buffer_pos_t h = atomic_read_rx_head();
- #if ENABLED(SERIAL_XON_XOFF)
- if ((xon_xoff_state & XON_XOFF_CHAR_MASK) == XOFF_CHAR) {
- // Get count of bytes in the RX buffer
- ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(rx_buffer.head - rx_buffer.tail) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
- // When below 10% of RX buffer capacity, send XON before
- // running out of RX buffer bytes
- if (rx_count < (RX_BUFFER_SIZE) / 10) {
- xon_xoff_state = XON_CHAR | XON_XOFF_CHAR_SENT;
- CRITICAL_SECTION_END; // End critical section before returning!
- writeNoHandshake(XON_CHAR);
- return v;
- }
- }
- #endif
+ // Read the tail. Main thread owns it, so it is safe to directly read it
+ ring_buffer_pos_t t = rx_buffer.tail;
+
+ // If nothing to read, return now
+ if (h == t) return -1;
+
+ // Get the next char
+ const int v = rx_buffer.buffer[t];
+ t = (ring_buffer_pos_t)(t + 1) & (RX_BUFFER_SIZE - 1);
+
+ // Advance tail - Making sure the RX ISR will always get an stable value, even
+ // if it interrupts the writing of the value of that variable in the middle.
+ atomic_set_rx_tail(t);
+
+ #if ENABLED(SERIAL_XON_XOFF)
+ // If the XOFF char was sent, or about to be sent...
+ if ((xon_xoff_state & XON_XOFF_CHAR_MASK) == XOFF_CHAR) {
+ // Get count of bytes in the RX buffer
+ const ring_buffer_pos_t rx_count = (ring_buffer_pos_t)(h - t) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
+ if (rx_count < (RX_BUFFER_SIZE) / 10) {
+ #if TX_BUFFER_SIZE > 0
+ // Signal we want an XON character to be sent.
+ xon_xoff_state = XON_CHAR;
+ // Enable TX ISR. Non atomic, but it will eventually enable them
+ SBI(M_UCSRxB, M_UDRIEx);
+ #else
+ // If not using TX interrupts, we must send the XON char now
+ xon_xoff_state = XON_CHAR | XON_XOFF_CHAR_SENT;
+ while (!TEST(M_UCSRxA, M_UDREx)) sw_barrier();
+ M_UDRx = XON_CHAR;
+ #endif
+ }
}
- CRITICAL_SECTION_END;
+ #endif
+
return v;
}
ring_buffer_pos_t MarlinSerial::available(void) {
- CRITICAL_SECTION_START;
- const ring_buffer_pos_t h = rx_buffer.head, t = rx_buffer.tail;
- CRITICAL_SECTION_END;
+ const ring_buffer_pos_t h = atomic_read_rx_head(), t = rx_buffer.tail;
return (ring_buffer_pos_t)(RX_BUFFER_SIZE + h - t) & (RX_BUFFER_SIZE - 1);
}
void MarlinSerial::flush(void) {
- // Don't change this order of operations. If the RX interrupt occurs between
- // reading rx_buffer_head and updating rx_buffer_tail, the previous rx_buffer_head
- // may be written to rx_buffer_tail, making the buffer appear full rather than empty.
- CRITICAL_SECTION_START;
- rx_buffer.head = rx_buffer.tail = 0;
- clear_command_queue();
- CRITICAL_SECTION_END;
+
+ // Set the tail to the head:
+ // - Read the RX head index in a safe way. (See atomic_read_rx_head.)
+ // - Set the tail, making sure the RX ISR will always get a stable value, even
+ // if it interrupts the writing of the value of that variable in the middle.
+ atomic_set_rx_tail(atomic_read_rx_head());
#if ENABLED(SERIAL_XON_XOFF)
+ // If the XOFF char was sent, or about to be sent...
if ((xon_xoff_state & XON_XOFF_CHAR_MASK) == XOFF_CHAR) {
- xon_xoff_state = XON_CHAR | XON_XOFF_CHAR_SENT;
- writeNoHandshake(XON_CHAR);
+ #if TX_BUFFER_SIZE > 0
+ // Signal we want an XON character to be sent.
+ xon_xoff_state = XON_CHAR;
+ // Enable TX ISR. Non atomic, but it will eventually enable it.
+ SBI(M_UCSRxB, M_UDRIEx);
+ #else
+ // If not using TX interrupts, we must send the XON char now
+ xon_xoff_state = XON_CHAR | XON_XOFF_CHAR_SENT;
+ while (!TEST(M_UCSRxA, M_UDREx)) sw_barrier();
+ M_UDRx = XON_CHAR;
+ #endif
}
#endif
}
#if TX_BUFFER_SIZE > 0
- uint8_t MarlinSerial::availableForWrite(void) {
- CRITICAL_SECTION_START;
- const uint8_t h = tx_buffer.head, t = tx_buffer.tail;
- CRITICAL_SECTION_END;
- return (uint8_t)(TX_BUFFER_SIZE + h - t) & (TX_BUFFER_SIZE - 1);
- }
-
void MarlinSerial::write(const uint8_t c) {
- #if ENABLED(SERIAL_XON_XOFF)
- const uint8_t state = xon_xoff_state;
- if (!(state & XON_XOFF_CHAR_SENT)) {
- // Send 2 chars: XON/XOFF, then a user-specified char
- writeNoHandshake(state & XON_XOFF_CHAR_MASK);
- xon_xoff_state = state | XON_XOFF_CHAR_SENT;
- }
- #endif
- writeNoHandshake(c);
- }
-
- void MarlinSerial::writeNoHandshake(const uint8_t c) {
_written = true;
- CRITICAL_SECTION_START;
- bool emty = (tx_buffer.head == tx_buffer.tail);
- CRITICAL_SECTION_END;
- // If the buffer and the data register is empty, just write the byte
- // to the data register and be done. This shortcut helps
- // significantly improve the effective datarate at high (>
- // 500kbit/s) bitrates, where interrupt overhead becomes a slowdown.
- if (emty && TEST(M_UCSRxA, M_UDREx)) {
- CRITICAL_SECTION_START;
- M_UDRx = c;
- SBI(M_UCSRxA, M_TXCx);
- CRITICAL_SECTION_END;
+ // If the TX interrupts are disabled and the data register
+ // is empty, just write the byte to the data register and
+ // be done. This shortcut helps significantly improve the
+ // effective datarate at high (>500kbit/s) bitrates, where
+ // interrupt overhead becomes a slowdown.
+ // Yes, there is a race condition between the sending of the
+ // XOFF char at the RX ISR, but it is properly handled there
+ if (!TEST(M_UCSRxB, M_UDRIEx) && TEST(M_UCSRxA, M_UDREx)) {
+ M_UDRx = c;
+
+ // clear the TXC bit -- "can be cleared by writing a one to its bit
+ // location". This makes sure flush() won't return until the bytes
+ // actually got written
+ SBI(M_UCSRxA, M_TXCx);
return;
}
+
const uint8_t i = (tx_buffer.head + 1) & (TX_BUFFER_SIZE - 1);
- // If the output buffer is full, there's nothing for it other than to
- // wait for the interrupt handler to empty it a bit
- while (i == tx_buffer.tail) {
- if (!TEST(SREG, SREG_I)) {
- // Interrupts are disabled, so we'll have to poll the data
- // register empty flag ourselves. If it is set, pretend an
- // interrupt has happened and call the handler to free up
- // space for us.
- if (TEST(M_UCSRxA, M_UDREx))
- _tx_udr_empty_irq();
- }
- else {
- // nop, the interrupt handler will free up space for us
+ // If global interrupts are disabled (as the result of being called from an ISR)...
+ if (!ISRS_ENABLED()) {
+
+ // Make room by polling if it is possible to transmit, and do so!
+ while (i == tx_buffer.tail) {
+
+ // If we can transmit another byte, do it.
+ if (TEST(M_UCSRxA, M_UDREx)) _tx_udr_empty_irq();
+
+ // Make sure compiler rereads tx_buffer.tail
+ sw_barrier();
}
}
+ else {
+ // Interrupts are enabled, just wait until there is space
+ while (i == tx_buffer.tail) { sw_barrier(); }
+ }
+ // Store new char. head is always safe to move
tx_buffer.buffer[tx_buffer.head] = c;
- { CRITICAL_SECTION_START;
- tx_buffer.head = i;
- SBI(M_UCSRxB, M_UDRIEx);
- CRITICAL_SECTION_END;
- }
- return;
+ tx_buffer.head = i;
+
+ // Enable TX ISR - Non atomic, but it will eventually enable TX ISR
+ SBI(M_UCSRxB, M_UDRIEx);
}
void MarlinSerial::flushTX(void) {
- // TX
- // If we have never written a byte, no need to flush. This special
- // case is needed since there is no way to force the TXC (transmit
- // complete) bit to 1 during initialization
- if (!_written)
- return;
+ // No bytes written, no need to flush. This special case is needed since there's
+ // no way to force the TXC (transmit complete) bit to 1 during initialization.
+ if (!_written) return;
- while (TEST(M_UCSRxB, M_UDRIEx) || !TEST(M_UCSRxA, M_TXCx)) {
- if (!TEST(SREG, SREG_I) && TEST(M_UCSRxB, M_UDRIEx))
- // Interrupts are globally disabled, but the DR empty
- // interrupt should be enabled, so poll the DR empty flag to
- // prevent deadlock
+ // If global interrupts are disabled (as the result of being called from an ISR)...
+ if (!ISRS_ENABLED()) {
+
+ // Wait until everything was transmitted - We must do polling, as interrupts are disabled
+ while (tx_buffer.head != tx_buffer.tail || !TEST(M_UCSRxA, M_TXCx)) {
+
+ // If there is more space, send an extra character
if (TEST(M_UCSRxA, M_UDREx))
_tx_udr_empty_irq();
+
+ sw_barrier();
+ }
+
}
- // If we get here, nothing is queued anymore (DRIE is disabled) and
- // the hardware finished tranmission (TXC is set).
+ else {
+ // Wait until everything was transmitted
+ while (tx_buffer.head != tx_buffer.tail || !TEST(M_UCSRxA, M_TXCx)) sw_barrier();
+ }
+
+ // At this point nothing is queued anymore (DRIE is disabled) and
+ // the hardware finished transmission (TXC is set).
}
#else // TX_BUFFER_SIZE == 0
void MarlinSerial::write(const uint8_t c) {
- #if ENABLED(SERIAL_XON_XOFF)
- // Do a priority insertion of an XON/XOFF char, if needed.
- const uint8_t state = xon_xoff_state;
- if (!(state & XON_XOFF_CHAR_SENT)) {
- writeNoHandshake(state & XON_XOFF_CHAR_MASK);
- xon_xoff_state = state | XON_XOFF_CHAR_SENT;
- }
- #endif
- writeNoHandshake(c);
- }
-
- void MarlinSerial::writeNoHandshake(uint8_t c) {
- while (!TEST(M_UCSRxA, M_UDREx)) {/* nada */}
+ _written = true;
+ while (!TEST(M_UCSRxA, M_UDREx)) sw_barrier();
M_UDRx = c;
}
+ void MarlinSerial::flushTX(void) {
+ // No bytes written, no need to flush. This special case is needed since there's
+ // no way to force the TXC (transmit complete) bit to 1 during initialization.
+ if (!_written) return;
+
+ // Wait until everything was transmitted
+ while (!TEST(M_UCSRxA, M_TXCx)) sw_barrier();
+
+ // At this point nothing is queued anymore (DRIE is disabled) and
+ // the hardware finished transmission (TXC is set).
+ }
#endif // TX_BUFFER_SIZE == 0
/**
@@ -437,13 +612,9 @@
}
void MarlinSerial::print(long n, int base) {
- if (base == 0)
- write(n);
+ if (base == 0) write(n);
else if (base == 10) {
- if (n < 0) {
- print('-');
- n = -n;
- }
+ if (n < 0) { print('-'); n = -n; }
printNumber(n, 10);
}
else
@@ -561,9 +732,9 @@
// Preinstantiate
MarlinSerial customizedSerial;
-#endif // !(__AVR__ && USBCON) && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H)
+#endif // USE_MARLINSERIAL && (UBRRH || UBRR0H || UBRR1H || UBRR2H || UBRR3H)
// For AT90USB targets use the UART for BT interfacing
-#if defined(__AVR__) && defined(USBCON) && ENABLED(BLUETOOTH)
+#if !USE_MARLINSERIAL && ENABLED(BLUETOOTH)
HardwareSerial bluetoothSerial;
#endif
diff --git a/Marlin/MarlinSerial.h b/Marlin/MarlinSerial.h
index 9060f668ad..d8bd5346c6 100644
--- a/Marlin/MarlinSerial.h
+++ b/Marlin/MarlinSerial.h
@@ -26,10 +26,11 @@
*
* Modified 28 September 2010 by Mark Sproul
* Modified 14 February 2016 by Andreas Hardtung (added tx buffer)
+ * Modified 01 October 2017 by Eduardo José Tagle (added XON/XOFF)
*/
-#ifndef MARLINSERIAL_H
-#define MARLINSERIAL_H
+#ifndef _MARLINSERIAL_H_
+#define _MARLINSERIAL_H_
#include "MarlinConfig.h"
@@ -59,6 +60,9 @@
#define M_TXCx SERIAL_REGNAME(TXC,SERIAL_PORT,)
#define M_RXCIEx SERIAL_REGNAME(RXCIE,SERIAL_PORT,)
#define M_UDREx SERIAL_REGNAME(UDRE,SERIAL_PORT,)
+#define M_FEx SERIAL_REGNAME(FE,SERIAL_PORT,)
+#define M_DORx SERIAL_REGNAME(DOR,SERIAL_PORT,)
+#define M_UPEx SERIAL_REGNAME(UPE,SERIAL_PORT,)
#define M_UDRIEx SERIAL_REGNAME(UDRIE,SERIAL_PORT,)
#define M_UDRx SERIAL_REGNAME(UDR,SERIAL_PORT,)
#define M_UBRRxH SERIAL_REGNAME(UBRR,SERIAL_PORT,H)
@@ -85,7 +89,7 @@
#define TX_BUFFER_SIZE 32
#endif
-#if !(defined(__AVR__) && defined(USBCON))
+#if USE_MARLINSERIAL
#if RX_BUFFER_SIZE > 256
typedef uint16_t ring_buffer_pos_t;
@@ -97,11 +101,19 @@
extern uint8_t rx_dropped_bytes;
#endif
+ #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
+ extern uint8_t rx_buffer_overruns;
+ #endif
+
+ #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
+ extern uint8_t rx_framing_errors;
+ #endif
+
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
extern ring_buffer_pos_t rx_max_enqueued;
#endif
- class MarlinSerial { //: public Stream
+ class MarlinSerial {
public:
MarlinSerial() {};
@@ -111,27 +123,25 @@
static int read(void);
static void flush(void);
static ring_buffer_pos_t available(void);
- static void checkRx(void);
static void write(const uint8_t c);
- #if TX_BUFFER_SIZE > 0
- static uint8_t availableForWrite(void);
- static void flushTX(void);
- #endif
- static void writeNoHandshake(const uint8_t c);
+ static void flushTX(void);
#if ENABLED(SERIAL_STATS_DROPPED_RX)
FORCE_INLINE static uint32_t dropped() { return rx_dropped_bytes; }
#endif
+ #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
+ FORCE_INLINE static uint32_t buffer_overruns() { return rx_buffer_overruns; }
+ #endif
+
+ #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
+ FORCE_INLINE static uint32_t framing_errors() { return rx_framing_errors; }
+ #endif
+
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return rx_max_enqueued; }
#endif
- private:
- static void printNumber(unsigned long, const uint8_t);
- static void printFloat(double, uint8_t);
-
- public:
FORCE_INLINE static void write(const char* str) { while (*str) write(*str++); }
FORCE_INLINE static void write(const uint8_t* buffer, size_t size) { while (size--) write(*buffer++); }
FORCE_INLINE static void print(const String& s) { for (int i = 0; i < (int)s.length(); i++) write(s[i]); }
@@ -155,15 +165,20 @@
static void println(unsigned long, int = DEC);
static void println(double, int = 2);
static void println(void);
+ operator bool() { return true; }
+
+ private:
+ static void printNumber(unsigned long, const uint8_t);
+ static void printFloat(double, uint8_t);
};
extern MarlinSerial customizedSerial;
-#endif // !(__AVR__ && USBCON)
+#endif // USE_MARLINSERIAL
// Use the UART for Bluetooth in AT90USB configurations
-#if defined(__AVR__) && defined(USBCON) && ENABLED(BLUETOOTH)
+#if !USE_MARLINSERIAL && ENABLED(BLUETOOTH)
extern HardwareSerial bluetoothSerial;
#endif
-#endif // MARLINSERIAL_H
+#endif // _MARLINSERIAL_H_
diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index 2058372a01..3897f79577 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -196,7 +196,7 @@
* M407 - Display measured filament diameter in millimeters. (Requires FILAMENT_WIDTH_SENSOR)
* M410 - Quickstop. Abort all planned moves.
* M420 - Enable/Disable Leveling (with current values) S1=enable S0=disable (Requires MESH_BED_LEVELING or ABL)
- * M421 - Set a single Z coordinate in the Mesh Leveling grid. X Y Z (Requires MESH_BED_LEVELING or AUTO_BED_LEVELING_UBL)
+ * M421 - Set a single Z coordinate in the Mesh Leveling grid. X Y Z (Requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, or AUTO_BED_LEVELING_UBL)
* M428 - Set the home_offset based on the current_position. Nearest edge applies. (Disabled by NO_WORKSPACE_OFFSETS or DELTA)
* M500 - Store parameters in EEPROM. (Requires EEPROM_SETTINGS)
* M501 - Restore parameters from EEPROM. (Requires EEPROM_SETTINGS)
@@ -271,7 +271,7 @@
#include "power.h"
#endif
-#if HAS_ABL
+#if ABL_PLANAR
#include "vector_3.h"
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
#include "least_squares_fit.h"
@@ -336,10 +336,6 @@
#include "I2CPositionEncoder.h"
#endif
-#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
- #include "endstop_interrupts.h"
-#endif
-
#if ENABLED(M100_FREE_MEMORY_WATCHER)
void gcode_M100();
void M100_dump_routine(const char * const title, const char *start, const char *end);
@@ -382,7 +378,7 @@ uint8_t marlin_debug_flags = DEBUG_NONE;
* Used by 'buffer_line_to_current_position' to do a move after changing it.
* Used by 'SYNC_PLAN_POSITION_KINEMATIC' to update 'planner.position'.
*/
-float current_position[XYZE] = { 0.0 };
+float current_position[XYZE] = { 0 };
/**
* Cartesian Destination
@@ -390,7 +386,7 @@ float current_position[XYZE] = { 0.0 };
* and expected by functions like 'prepare_move_to_destination'.
* Set with 'gcode_get_destination' or 'set_destination_from_current'.
*/
-float destination[XYZE] = { 0.0 };
+float destination[XYZE] = { 0 };
/**
* axis_homed
@@ -401,7 +397,7 @@ float destination[XYZE] = { 0.0 };
* Flags that the position is known in each linear axis. Set when homed.
* Cleared whenever a stepper powers off, potentially losing its position.
*/
-bool axis_homed[XYZ] = { false }, axis_known_position[XYZ] = { false };
+uint8_t axis_homed, axis_known_position; // = 0
/**
* GCode line number handling. Hosts may opt to include line numbers when
@@ -450,12 +446,12 @@ static const float homing_feedrate_mm_s[] PROGMEM = {
};
FORCE_INLINE float homing_feedrate(const AxisEnum a) { return pgm_read_float(&homing_feedrate_mm_s[a]); }
-float feedrate_mm_s = MMM_TO_MMS(1500.0);
+float feedrate_mm_s = MMM_TO_MMS(1500.0f);
static float saved_feedrate_mm_s;
int16_t feedrate_percentage = 100, saved_feedrate_percentage;
// Initialized by settings.load()
-bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
+bool axis_relative_modes[XYZE] = AXIS_RELATIVE_MODES;
#if HAS_WORKSPACE_OFFSET
#if HAS_POSITION_SHIFT
@@ -537,10 +533,6 @@ static millis_t stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL
#define BUZZ(d,f) NOOP
#endif
-#if ENABLED(SWITCHING_NOZZLE)
- #define DO_SWITCH_EXTRUDER (SWITCHING_EXTRUDER_SERVO_NR != SWITCHING_NOZZLE_SERVO_NR)
-#endif
-
uint8_t target_extruder;
#if HAS_BED_PROBE
@@ -696,10 +688,6 @@ static bool send_ok[BUFSIZE];
bool chdkActive = false;
#endif
-#if ENABLED(PID_EXTRUSION_SCALING)
- int lpq_len = 20;
-#endif
-
#if ENABLED(HOST_KEEPALIVE_FEATURE)
MarlinBusyState busy_state = NOT_BUSY;
static millis_t next_busy_signal_ms = 0;
@@ -751,7 +739,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis);
#endif
#if ENABLED(BEZIER_CURVE_SUPPORT)
- void plan_cubic_move(const float (&offset)[4]);
+ void plan_cubic_move(const float (&cart)[XYZE], const float (&offset)[4]);
#endif
void tool_change(const uint8_t tmp_extruder, const float fr_mm_s=0.0, bool no_move=false);
@@ -773,12 +761,6 @@ void report_current_position_detail();
print_xyz(prefix, suffix, xyz[X_AXIS], xyz[Y_AXIS], xyz[Z_AXIS]);
}
- #if HAS_ABL
- void print_xyz(const char* prefix, const char* suffix, const vector_3 &xyz) {
- print_xyz(prefix, suffix, xyz.x, xyz.y, xyz.z);
- }
- #endif
-
#define DEBUG_POS(SUFFIX,VAR) do { \
print_xyz(PSTR(" " STRINGIFY(VAR) "="), PSTR(" : " SUFFIX "\n"), VAR); }while(0)
#endif
@@ -1200,7 +1182,6 @@ inline void get_serial_commands() {
leds.set_off();
#endif
#endif // PRINTER_EVENT_LEDS
- card.checkautostart(true);
}
}
else if (n == -1) {
@@ -1239,7 +1220,7 @@ inline void get_serial_commands() {
if (job_recovery_commands_count) {
if (_enqueuecommand(job_recovery_commands[job_recovery_commands_index])) {
++job_recovery_commands_index;
- if (!--job_recovery_commands_count) job_recovery_phase = JOB_RECOVERY_IDLE;
+ if (!--job_recovery_commands_count) job_recovery_phase = JOB_RECOVERY_DONE;
}
return true;
}
@@ -1349,7 +1330,7 @@ bool get_target_extruder_from_command(const uint16_t code) {
if (axis == X_AXIS) {
// In Dual X mode hotend_offset[X] is T1's home position
- float dual_max_x = max(hotend_offset[X_AXIS][1], X2_MAX_POS);
+ float dual_max_x = MAX(hotend_offset[X_AXIS][1], X2_MAX_POS);
if (active_extruder != 0) {
// T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger)
@@ -1360,7 +1341,7 @@ bool get_target_extruder_from_command(const uint16_t code) {
// In Duplication Mode, T0 can move as far left as X_MIN_POS
// but not so far to the right that T1 would move past the end
soft_endstop_min[X_AXIS] = base_min_pos(X_AXIS);
- soft_endstop_max[X_AXIS] = min(base_max_pos(X_AXIS), dual_max_x - duplicate_extruder_x_offset);
+ soft_endstop_max[X_AXIS] = MIN(base_max_pos(X_AXIS), dual_max_x - duplicate_extruder_x_offset);
}
else {
// In other modes, T0 can move from X_MIN_POS to X_MAX_POS
@@ -1391,12 +1372,12 @@ bool get_target_extruder_from_command(const uint16_t code) {
#endif
#if ENABLED(DELTA)
- switch(axis) {
+ switch (axis) {
#if HAS_SOFTWARE_ENDSTOPS
case X_AXIS:
case Y_AXIS:
// Get a minimum radius for clamping
- soft_endstop_radius = MIN3(FABS(max(soft_endstop_min[X_AXIS], soft_endstop_min[Y_AXIS])), soft_endstop_max[X_AXIS], soft_endstop_max[Y_AXIS]);
+ soft_endstop_radius = MIN3(ABS(MAX(soft_endstop_min[X_AXIS], soft_endstop_min[Y_AXIS])), soft_endstop_max[X_AXIS], soft_endstop_max[Y_AXIS]);
soft_endstop_radius_2 = sq(soft_endstop_radius);
break;
#endif
@@ -1447,7 +1428,8 @@ static void set_axis_is_at_home(const AxisEnum axis) {
}
#endif
- axis_known_position[axis] = axis_homed[axis] = true;
+ SBI(axis_known_position, axis);
+ SBI(axis_homed, axis);
#if HAS_POSITION_SHIFT
position_shift[axis] = 0;
@@ -1549,9 +1531,12 @@ static void set_axis_is_at_home(const AxisEnum axis) {
}
/**
- * Some planner shorthand inline functions
+ * Homing bump feedrate (mm/s)
*/
inline float 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) {
@@ -1562,6 +1547,10 @@ inline float get_homing_bump_feedrate(const AxisEnum axis) {
return homing_feedrate(axis) / hbd;
}
+/**
+ * Some planner shorthand inline functions
+ */
+
/**
* Move the planner to the current position from wherever it last moved
* (or from wherever it has been told it is located).
@@ -1582,7 +1571,7 @@ inline void buffer_line_to_destination(const float &fr_mm_s) {
/**
* Calculate delta, start a line, and set current_position to destination
*/
- void prepare_uninterpolated_move_to_destination(const float fr_mm_s=0.0) {
+ void prepare_uninterpolated_move_to_destination(const float fr_mm_s=0) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("prepare_uninterpolated_move_to_destination", destination);
#endif
@@ -1717,7 +1706,7 @@ void do_blocking_move_to(const float rx, const float ry, const float rz, const f
#endif
- stepper.synchronize();
+ planner.synchronize();
feedrate_mm_s = old_feedrate_mm_s;
@@ -1765,13 +1754,13 @@ void clean_up_after_endstop_or_probe_move() {
bool axis_unhomed_error(const bool x/*=true*/, const bool y/*=true*/, const bool z/*=true*/) {
#if ENABLED(HOME_AFTER_DEACTIVATE)
- const bool xx = x && !axis_known_position[X_AXIS],
- yy = y && !axis_known_position[Y_AXIS],
- zz = z && !axis_known_position[Z_AXIS];
+ const bool xx = x && !TEST(axis_known_position, X_AXIS),
+ yy = y && !TEST(axis_known_position, Y_AXIS),
+ zz = z && !TEST(axis_known_position, Z_AXIS);
#else
- const bool xx = x && !axis_homed[X_AXIS],
- yy = y && !axis_homed[Y_AXIS],
- zz = z && !axis_homed[Z_AXIS];
+ const bool xx = x && !TEST(axis_homed, X_AXIS),
+ yy = y && !TEST(axis_homed, Y_AXIS),
+ zz = z && !TEST(axis_homed, Z_AXIS);
#endif
if (xx || yy || zz) {
SERIAL_ECHO_START();
@@ -2122,13 +2111,13 @@ void clean_up_after_endstop_or_probe_move() {
// For beds that fall when Z is powered off only raise for trusted Z
#if ENABLED(UNKNOWN_Z_NO_RAISE)
- const bool unknown_condition = axis_known_position[Z_AXIS];
+ const bool unknown_condition = TEST(axis_known_position, Z_AXIS);
#else
constexpr float unknown_condition = true;
#endif
if (deploy_stow_condition && unknown_condition)
- do_probe_raise(max(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE));
+ do_probe_raise(MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE));
#if ENABLED(Z_PROBE_SLED) || ENABLED(Z_PROBE_ALLEN_KEY)
#if ENABLED(Z_PROBE_SLED)
@@ -2208,7 +2197,7 @@ void clean_up_after_endstop_or_probe_move() {
* @param fr_mm_s Feedrate in mm/s
* @return true to indicate an error
*/
- static bool do_probe_move(const float z, const float fr_mm_m) {
+ static bool do_probe_move(const float z, const float fr_mm_s) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> do_probe_move", current_position);
#endif
@@ -2221,8 +2210,8 @@ void clean_up_after_endstop_or_probe_move() {
while (thermalManager.isHeatingBed()) safe_delay(200);
lcd_reset_status();
}
- #endif
-
+ #endif
+
// Deploy BLTouch at the start of any probe
#if ENABLED(BLTOUCH)
if (set_bltouch_deployed(true)) return true;
@@ -2233,10 +2222,10 @@ void clean_up_after_endstop_or_probe_move() {
#endif
// Move down until probe triggered
- do_blocking_move_to_z(z, MMM_TO_MMS(fr_mm_m));
+ do_blocking_move_to_z(z, fr_mm_s);
// Check to see if the probe was triggered
- const bool probe_triggered = TEST(Endstops::endstop_hit_bits,
+ const bool probe_triggered = TEST(endstops.trigger_state(),
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
Z_MIN
#else
@@ -2253,7 +2242,6 @@ void clean_up_after_endstop_or_probe_move() {
if (probe_triggered && set_bltouch_deployed(false)) return true;
#endif
- // Clear endstop flags
endstops.hit_on_purpose();
// Get Z where the steppers were interrupted
@@ -2283,13 +2271,21 @@ void clean_up_after_endstop_or_probe_move() {
// Stop the probe before it goes too low to prevent damage.
// If Z isn't known then probe to -10mm.
- const float z_probe_low_point = axis_known_position[Z_AXIS] ? -zprobe_zoffset + Z_PROBE_LOW_POINT : -10.0;
+ const float z_probe_low_point = TEST(axis_known_position, Z_AXIS) ? -zprobe_zoffset + Z_PROBE_LOW_POINT : -10.0;
// Double-probing does a fast probe followed by a slow probe
#if MULTIPLE_PROBING == 2
// Do a first probe at the fast speed
- if (do_probe_move(z_probe_low_point, Z_PROBE_SPEED_FAST)) return NAN;
+ if (do_probe_move(z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_FAST))) {
+ #if ENABLED(DEBUG_LEVELING_FEATURE)
+ if (DEBUGGING(LEVELING)) {
+ SERIAL_ECHOLNPGM("FAST Probe fail!");
+ DEBUG_POS("<<< run_z_probe", current_position);
+ }
+ #endif
+ return NAN;
+ }
float first_probe_z = current_position[Z_AXIS];
@@ -2309,7 +2305,7 @@ void clean_up_after_endstop_or_probe_move() {
if (current_position[Z_AXIS] > z) {
// If we don't make it to the z position (i.e. the probe triggered), move up to make clearance for the probe
- if (!do_probe_move(z, Z_PROBE_SPEED_FAST))
+ if (!do_probe_move(z, MMM_TO_MMS(Z_PROBE_SPEED_FAST)))
do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_BETWEEN_PROBES, MMM_TO_MMS(Z_PROBE_SPEED_FAST));
}
#endif
@@ -2320,7 +2316,15 @@ void clean_up_after_endstop_or_probe_move() {
#endif
// move down slowly to find bed
- if (do_probe_move(z_probe_low_point, Z_PROBE_SPEED_SLOW)) return NAN;
+ if (do_probe_move(z_probe_low_point, MMM_TO_MMS(Z_PROBE_SPEED_SLOW))) {
+ #if ENABLED(DEBUG_LEVELING_FEATURE)
+ if (DEBUGGING(LEVELING)) {
+ SERIAL_ECHOLNPGM("SLOW Probe fail!");
+ DEBUG_POS("<<< run_z_probe", current_position);
+ }
+ #endif
+ return NAN;
+ }
#if MULTIPLE_PROBING > 2
probes_total += current_position[Z_AXIS];
@@ -2331,7 +2335,7 @@ void clean_up_after_endstop_or_probe_move() {
#if MULTIPLE_PROBING > 2
// Return the average value of all probes
- return probes_total * (1.0 / (MULTIPLE_PROBING));
+ const float measured_z = probes_total * (1.0f / (MULTIPLE_PROBING));
#elif MULTIPLE_PROBING == 2
@@ -2345,18 +2349,20 @@ void clean_up_after_endstop_or_probe_move() {
#endif
// Return a weighted average of the fast and slow probes
- return (z2 * 3.0 + first_probe_z * 2.0) * 0.2;
+ const float measured_z = (z2 * 3.0 + first_probe_z * 2.0) * 0.2;
#else
// Return the single probe result
- return current_position[Z_AXIS];
+ const float measured_z = current_position[Z_AXIS];
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< run_z_probe", current_position);
#endif
+
+ return measured_z;
}
/**
@@ -2393,7 +2399,7 @@ void clean_up_after_endstop_or_probe_move() {
const float nz =
#if ENABLED(DELTA)
// Move below clip height or xy move will be aborted by do_blocking_move_to
- min(current_position[Z_AXIS], delta_clip_start_height)
+ MIN(current_position[Z_AXIS], delta_clip_start_height)
#else
current_position[Z_AXIS]
#endif
@@ -2426,10 +2432,6 @@ void clean_up_after_endstop_or_probe_move() {
SERIAL_EOL();
}
- #if ENABLED(DEBUG_LEVELING_FEATURE)
- if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< probe_pt");
- #endif
-
feedrate_mm_s = old_feedrate_mm_s;
if (isnan(measured_z)) {
@@ -2438,6 +2440,10 @@ void clean_up_after_endstop_or_probe_move() {
SERIAL_ERRORLNPGM(MSG_ERR_PROBING_FAILED);
}
+ #if ENABLED(DEBUG_LEVELING_FEATURE)
+ if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< probe_pt");
+ #endif
+
return measured_z;
}
@@ -2452,7 +2458,7 @@ void clean_up_after_endstop_or_probe_move() {
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
!!bilinear_grid_spacing[X_AXIS]
#elif ENABLED(AUTO_BED_LEVELING_UBL)
- true
+ ubl.mesh_is_valid()
#else // 3POINT, LINEAR
true
#endif
@@ -2925,18 +2931,23 @@ void clean_up_after_endstop_or_probe_move() {
/**
* Home an individual linear axis
*/
-static void do_homing_move(const AxisEnum axis, const float distance, const float fr_mm_s=0.0) {
+static void do_homing_move(const AxisEnum axis, const float distance, const float fr_mm_s=0) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR(">>> do_homing_move(", axis_codes[axis]);
SERIAL_ECHOPAIR(", ", distance);
- SERIAL_ECHOPAIR(", ", fr_mm_s);
- SERIAL_CHAR(')');
- SERIAL_EOL();
+ SERIAL_ECHOPGM(", ");
+ if (fr_mm_s)
+ SERIAL_ECHO(fr_mm_s);
+ else {
+ SERIAL_ECHOPAIR("[", homing_feedrate(axis));
+ SERIAL_CHAR(']');
+ }
+ SERIAL_ECHOLNPGM(")");
}
#endif
-
+
#if HOMING_Z_WITH_PROBE && HAS_HEATED_BED && ENABLED(WAIT_FOR_BED_HEATER)
// Wait for bed to heat back up between probing points
if (axis == Z_AXIS && distance < 0 && thermalManager.isHeatingBed()) {
@@ -2977,6 +2988,7 @@ static void do_homing_move(const AxisEnum axis, const float distance, const floa
// Tell the planner the axis is at 0
current_position[axis] = 0;
+ // Do the move, which is required to hit an endstop
#if IS_SCARA
SYNC_PLAN_POSITION_KINEMATIC();
current_position[axis] = distance;
@@ -2984,11 +2996,11 @@ static void do_homing_move(const AxisEnum axis, const float distance, const floa
planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], current_position[E_AXIS], fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder);
#else
sync_plan_position();
- current_position[axis] = distance;
+ current_position[axis] = distance; // Set delta/cartesian axes directly
planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], fr_mm_s ? fr_mm_s : homing_feedrate(axis), active_extruder);
#endif
- stepper.synchronize();
+ planner.synchronize();
if (is_home_dir) {
@@ -3003,7 +3015,7 @@ static void do_homing_move(const AxisEnum axis, const float distance, const floa
#endif
}
- endstops.hit_on_purpose();
+ endstops.validate_homing_move();
// Re-enable stealthChop if used. Disable diag1 pin on driver.
#if ENABLED(SENSORLESS_HOMING)
@@ -3031,8 +3043,6 @@ static void do_homing_move(const AxisEnum axis, const float distance, const floa
* before updating the current position.
*/
-#define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
-
static void homeaxis(const AxisEnum axis) {
#if IS_SCARA
@@ -3040,7 +3050,7 @@ static void homeaxis(const AxisEnum axis) {
if (axis != Z_AXIS) { BUZZ(100, 880); return; }
#else
#define CAN_HOME(A) \
- (axis == A##_AXIS && ((A##_MIN_PIN > -1 && A##_HOME_DIR < 0) || (A##_MAX_PIN > -1 && A##_HOME_DIR > 0)))
+ (axis == _AXIS(A) && ((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
@@ -3052,11 +3062,12 @@ static void homeaxis(const AxisEnum axis) {
}
#endif
- const int axis_home_dir =
+ const int axis_home_dir = (
#if ENABLED(DUAL_X_CARRIAGE)
- (axis == X_AXIS) ? x_home_dir(active_extruder) :
+ axis == X_AXIS ? x_home_dir(active_extruder) :
#endif
- home_dir(axis);
+ home_dir(axis)
+ );
// Homing Z towards the bed? Deploy the Z probe or endstop.
#if HOMING_Z_WITH_PROBE
@@ -3064,26 +3075,32 @@ static void homeaxis(const AxisEnum axis) {
#endif
// Set flags for X, Y, Z motor locking
- #if ENABLED(X_DUAL_ENDSTOPS)
- if (axis == X_AXIS) stepper.set_homing_flag_x(true);
- #endif
- #if ENABLED(Y_DUAL_ENDSTOPS)
- if (axis == Y_AXIS) stepper.set_homing_flag_y(true);
- #endif
- #if ENABLED(Z_DUAL_ENDSTOPS)
- if (axis == Z_AXIS) stepper.set_homing_flag_z(true);
+ #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
+ switch (axis) {
+ #if ENABLED(X_DUAL_ENDSTOPS)
+ case X_AXIS:
+ #endif
+ #if ENABLED(Y_DUAL_ENDSTOPS)
+ case Y_AXIS:
+ #endif
+ #if ENABLED(Z_DUAL_ENDSTOPS)
+ case Z_AXIS:
+ #endif
+ stepper.set_homing_dual_axis(true);
+ default: break;
+ }
#endif
// Fast move towards endstop until triggered
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Home 1 Fast:");
#endif
- do_homing_move(axis, 1.5 * max_length(axis) * axis_home_dir);
+ do_homing_move(axis, 1.5f * max_length(axis) * axis_home_dir);
// When homing Z with probe respect probe clearance
const float bump = axis_home_dir * (
#if HOMING_Z_WITH_PROBE
- (axis == Z_AXIS) ? max(Z_CLEARANCE_BETWEEN_PROBES, home_bump_mm(Z_AXIS)) :
+ (axis == Z_AXIS && (Z_HOME_BUMP_MM)) ? MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_HOME_BUMP_MM) :
#endif
home_bump_mm(axis)
);
@@ -3094,7 +3111,11 @@ static void homeaxis(const AxisEnum axis) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Move Away:");
#endif
- do_homing_move(axis, -bump);
+ do_homing_move(axis, -bump
+ #if HOMING_Z_WITH_PROBE
+ , axis == Z_AXIS ? MMM_TO_MMS(Z_PROBE_SPEED_FAST) : 0.00
+ #endif
+ );
// Slow move towards endstop until triggered
#if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -3110,34 +3131,32 @@ static void homeaxis(const AxisEnum axis) {
const bool pos_dir = axis_home_dir > 0;
#if ENABLED(X_DUAL_ENDSTOPS)
if (axis == X_AXIS) {
- const bool lock_x1 = pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0);
- const float adj = FABS(endstops.x_endstop_adj);
- if (lock_x1) stepper.set_x_lock(true); else stepper.set_x2_lock(true);
+ const float adj = ABS(endstops.x_endstop_adj);
+ if (pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0)) stepper.set_x_lock(true); else stepper.set_x2_lock(true);
do_homing_move(axis, pos_dir ? -adj : adj);
- if (lock_x1) stepper.set_x_lock(false); else stepper.set_x2_lock(false);
- stepper.set_homing_flag_x(false);
+ stepper.set_x_lock(false);
+ stepper.set_x2_lock(false);
}
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
if (axis == Y_AXIS) {
- const bool lock_y1 = pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0);
- const float adj = FABS(endstops.y_endstop_adj);
- if (lock_y1) stepper.set_y_lock(true); else stepper.set_y2_lock(true);
+ const float adj = ABS(endstops.y_endstop_adj);
+ if (pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0)) stepper.set_y_lock(true); else stepper.set_y2_lock(true);
do_homing_move(axis, pos_dir ? -adj : adj);
- if (lock_y1) stepper.set_y_lock(false); else stepper.set_y2_lock(false);
- stepper.set_homing_flag_y(false);
+ stepper.set_y_lock(false);
+ stepper.set_y2_lock(false);
}
#endif
#if ENABLED(Z_DUAL_ENDSTOPS)
if (axis == Z_AXIS) {
- const bool lock_z1 = pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0);
- const float adj = FABS(endstops.z_endstop_adj);
- if (lock_z1) stepper.set_z_lock(true); else stepper.set_z2_lock(true);
+ const float adj = ABS(endstops.z_endstop_adj);
+ if (pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0)) stepper.set_z_lock(true); else stepper.set_z2_lock(true);
do_homing_move(axis, pos_dir ? -adj : adj);
- if (lock_z1) stepper.set_z_lock(false); else stepper.set_z2_lock(false);
- stepper.set_homing_flag_z(false);
+ stepper.set_z_lock(false);
+ stepper.set_z2_lock(false);
}
#endif
+ stepper.set_homing_dual_axis(false);
#endif
#if IS_SCARA
@@ -3181,8 +3200,7 @@ static void homeaxis(const AxisEnum axis) {
// Clear retracted status if homing the Z axis
#if ENABLED(FWRETRACT)
- if (axis == Z_AXIS)
- fwretract.hop_amount = 0.0;
+ if (axis == Z_AXIS) fwretract.hop_amount = 0.0;
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -3258,7 +3276,7 @@ void gcode_get_destination() {
destination[i] = current_position[i];
}
- if (parser.linearval('F') > 0.0)
+ if (parser.linearval('F') > 0)
feedrate_mm_s = MMM_TO_MMS(parser.value_feedrate());
#if ENABLED(PRINTCOUNTER)
@@ -3333,7 +3351,7 @@ inline void gcode_G0_G1(
if (fwretract.autoretract_enabled && parser.seen('E') && !(parser.seen('X') || parser.seen('Y') || parser.seen('Z'))) {
const float echange = destination[E_AXIS] - current_position[E_AXIS];
// Is this a retract or prime move?
- if (WITHIN(FABS(echange), MIN_AUTORETRACT, MAX_AUTORETRACT) && fwretract.retracted[active_extruder] == (echange > 0.0)) {
+ if (WITHIN(ABS(echange), MIN_AUTORETRACT, MAX_AUTORETRACT) && fwretract.retracted[active_extruder] == (echange > 0.0)) {
current_position[E_AXIS] = destination[E_AXIS]; // Hide a G1-based retract/prime from calculations
sync_plan_position_e(); // AND from the planner
return fwretract.retract(echange < 0.0); // Firmware-based retract/prime (double-retract ignored)
@@ -3355,7 +3373,7 @@ inline void gcode_G0_G1(
#define _MOVE_SYNC parser.seenval('Z') // Only for Z move
#endif
if (_MOVE_SYNC) {
- stepper.synchronize();
+ planner.synchronize();
SERIAL_ECHOLNPGM(MSG_Z_MOVE_COMP);
}
#endif
@@ -3408,19 +3426,19 @@ inline void gcode_G0_G1(
relative_mode = relative_mode_backup;
#endif
- float arc_offset[2] = { 0.0, 0.0 };
+ float arc_offset[2] = { 0, 0 };
if (parser.seenval('R')) {
const float r = parser.value_linear_units(),
p1 = current_position[X_AXIS], q1 = current_position[Y_AXIS],
p2 = destination[X_AXIS], q2 = destination[Y_AXIS];
if (r && (p2 != p1 || q2 != q1)) {
- const float e = clockwise ^ (r < 0) ? -1 : 1, // clockwise -1/1, counterclockwise 1/-1
- dx = p2 - p1, dy = q2 - q1, // X and Y differences
- d = HYPOT(dx, dy), // Linear distance between the points
- h = SQRT(sq(r) - sq(d * 0.5)), // Distance to the arc pivot-point
- mx = (p1 + p2) * 0.5, my = (q1 + q2) * 0.5, // Point between the two points
- sx = -dy / d, sy = dx / d, // Slope of the perpendicular bisector
- cx = mx + e * h * sx, cy = my + e * h * sy; // Pivot-point of the arc
+ const float e = clockwise ^ (r < 0) ? -1 : 1, // clockwise -1/1, counterclockwise 1/-1
+ dx = p2 - p1, dy = q2 - q1, // X and Y differences
+ d = HYPOT(dx, dy), // Linear distance between the points
+ h = SQRT(sq(r) - sq(d * 0.5f)), // Distance to the arc pivot-point
+ mx = (p1 + p2) * 0.5f, my = (q1 + q2) * 0.5f, // Point between the two points
+ sx = -dy / d, sy = dx / d, // Slope of the perpendicular bisector
+ cx = mx + e * h * sx, cy = my + e * h * sy; // Pivot-point of the arc
arc_offset[0] = cx - p1;
arc_offset[1] = cy - q1;
}
@@ -3470,7 +3488,7 @@ inline void gcode_G4() {
if (parser.seenval('P')) dwell_ms = parser.value_millis(); // milliseconds to wait
if (parser.seenval('S')) dwell_ms = parser.value_millis_from_seconds(); // seconds to wait
- stepper.synchronize();
+ planner.synchronize();
#if ENABLED(NANODLP_Z_SYNC)
SERIAL_ECHOLNPGM(MSG_Z_MOVE_COMP);
#endif
@@ -3516,7 +3534,7 @@ inline void gcode_G4() {
parser.linearval('Q')
};
- plan_cubic_move(offset);
+ plan_cubic_move(destination, offset);
}
}
@@ -3699,7 +3717,7 @@ inline void gcode_G4() {
const float mlx = max_length(X_AXIS),
mly = max_length(Y_AXIS),
mlratio = mlx > mly ? mly / mlx : mlx / mly,
- fr_mm_s = min(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)) * SQRT(sq(mlratio) + 1.0);
+ fr_mm_s = MIN(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)) * SQRT(sq(mlratio) + 1.0);
#if ENABLED(SENSORLESS_HOMING)
sensorless_homing_per_axis(X_AXIS);
@@ -3707,7 +3725,9 @@ inline void gcode_G4() {
#endif
do_blocking_move_to_xy(1.5 * mlx * x_axis_home_dir, 1.5 * mly * home_dir(Y_AXIS), fr_mm_s);
- endstops.hit_on_purpose(); // clear endstop hit flags
+
+ endstops.validate_homing_move();
+
current_position[X_AXIS] = current_position[Y_AXIS] = 0.0;
#if ENABLED(SENSORLESS_HOMING)
@@ -3763,9 +3783,17 @@ inline void gcode_G4() {
SERIAL_ECHOPGM(" (Aligned With");
#endif
#if Y_PROBE_OFFSET_FROM_EXTRUDER > 0
- SERIAL_ECHOPGM("-Back");
+ #if IS_SCARA
+ SERIAL_ECHOPGM("-Distal");
+ #else
+ SERIAL_ECHOPGM("-Back");
+ #endif
#elif Y_PROBE_OFFSET_FROM_EXTRUDER < 0
- SERIAL_ECHOPGM("-Front");
+ #if IS_SCARA
+ SERIAL_ECHOPGM("-Proximal");
+ #else
+ SERIAL_ECHOPGM("-Front");
+ #endif
#elif X_PROBE_OFFSET_FROM_EXTRUDER != 0
SERIAL_ECHOPGM("-Center");
#endif
@@ -3797,9 +3825,9 @@ inline void gcode_G4() {
#endif
#if ABL_PLANAR
const float diff[XYZ] = {
- stepper.get_axis_position_mm(X_AXIS) - current_position[X_AXIS],
- stepper.get_axis_position_mm(Y_AXIS) - current_position[Y_AXIS],
- stepper.get_axis_position_mm(Z_AXIS) - current_position[Z_AXIS]
+ planner.get_axis_position_mm(X_AXIS) - current_position[X_AXIS],
+ planner.get_axis_position_mm(Y_AXIS) - current_position[Y_AXIS],
+ planner.get_axis_position_mm(Z_AXIS) - current_position[Z_AXIS]
};
SERIAL_ECHOPGM("ABL Adjustment X");
if (diff[X_AXIS] > 0) SERIAL_CHAR('+');
@@ -3841,7 +3869,11 @@ inline void gcode_G4() {
SERIAL_ECHOPGM("Mesh Bed Leveling");
if (planner.leveling_active) {
SERIAL_ECHOLNPGM(" (enabled)");
- SERIAL_ECHOPAIR("MBL Adjustment Z", ftostr43sign(mbl.get_z(current_position[X_AXIS], current_position[Y_AXIS], 1.0), '+'));
+ SERIAL_ECHOPAIR("MBL Adjustment Z", ftostr43sign(mbl.get_z(current_position[X_AXIS], current_position[Y_AXIS]
+ #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
+ , 1.0
+ #endif
+ ), '+'));
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
if (planner.z_fade_height) {
SERIAL_ECHOPAIR(" (", ftostr43sign(
@@ -3875,7 +3907,7 @@ inline void gcode_G4() {
* A delta can only safely home all axes at the same time
* This is like quick_home_xy() but for 3 towers.
*/
- inline bool home_delta() {
+ inline void home_delta() {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS(">>> home_delta", current_position);
#endif
@@ -3892,29 +3924,20 @@ inline void gcode_G4() {
current_position[X_AXIS] = current_position[Y_AXIS] = current_position[Z_AXIS] = (delta_height + 10);
feedrate_mm_s = homing_feedrate(X_AXIS);
buffer_line_to_current_position();
- stepper.synchronize();
+ planner.synchronize();
// Re-enable stealthChop if used. Disable diag1 pin on driver.
#if ENABLED(SENSORLESS_HOMING)
delta_sensorless_homing(false);
#endif
- // If an endstop was not hit, then damage can occur if homing is continued.
- // This can occur if the delta height not set correctly.
- if (!(Endstops::endstop_hit_bits & (_BV(X_MAX) | _BV(Y_MAX) | _BV(Z_MAX)))) {
- LCD_MESSAGEPGM(MSG_ERR_HOMING_FAILED);
- SERIAL_ERROR_START();
- SERIAL_ERRORLNPGM(MSG_ERR_HOMING_FAILED);
- return false;
- }
-
- endstops.hit_on_purpose(); // clear endstop hit flags
+ endstops.validate_homing_move();
// At least one carriage has reached the top.
// Now re-home each carriage separately.
- HOMEAXIS(A);
- HOMEAXIS(B);
- HOMEAXIS(C);
+ homeaxis(A_AXIS);
+ homeaxis(B_AXIS);
+ homeaxis(C_AXIS);
// Set all carriages to their home positions
// Do this here all at once for Delta, because
@@ -3927,13 +3950,11 @@ inline void gcode_G4() {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) DEBUG_POS("<<< home_delta", current_position);
#endif
-
- return true;
}
#endif // DELTA
-#if Z_AFTER_PROBING
+#ifdef Z_AFTER_PROBING
void move_z_after_probing() {
if (current_position[Z_AXIS] != Z_AFTER_PROBING) {
do_blocking_move_to_z(Z_AFTER_PROBING);
@@ -3947,7 +3968,7 @@ inline void gcode_G4() {
inline void home_z_safely() {
// Disallow Z homing if X or Y are unknown
- if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
+ if (!TEST(axis_known_position, X_AXIS) || !TEST(axis_known_position, Y_AXIS)) {
LCD_MESSAGEPGM(MSG_ERR_Z_HOMING);
SERIAL_ECHO_START();
SERIAL_ECHOLNPGM(MSG_ERR_Z_HOMING);
@@ -3988,7 +4009,7 @@ inline void gcode_G4() {
#endif
do_blocking_move_to_xy(destination[X_AXIS], destination[Y_AXIS]);
- HOMEAXIS(Z);
+ homeaxis(Z_AXIS);
}
else {
LCD_MESSAGEPGM(MSG_ZPROBE_OUT);
@@ -4017,6 +4038,8 @@ inline void gcode_G4() {
* None Home to all axes with no parameters.
* With QUICK_HOME enabled XY will home together, then Z.
*
+ * O Home only if position is unknown
+ *
* Rn Raise by n mm/inches before homing
*
* Cartesian parameters
@@ -4030,13 +4053,36 @@ inline void gcode_G28(const bool always_home_all) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
- SERIAL_ECHOLNPGM(">>> gcode_G28");
+ SERIAL_ECHOLNPGM(">>> G28");
log_machine_info();
}
#endif
+ #if ENABLED(MARLIN_DEV_MODE)
+ if (parser.seen('S')) {
+ LOOP_XYZ(a) set_axis_is_at_home((AxisEnum)a);
+ SYNC_PLAN_POSITION_KINEMATIC();
+ SERIAL_ECHOLNPGM("Simulated Homing");
+ report_current_position();
+ #if ENABLED(DEBUG_LEVELING_FEATURE)
+ if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< G28");
+ #endif
+ return;
+ }
+ #endif
+
+ if (all_axes_known() && parser.boolval('O')) { // home only if needed
+ #if ENABLED(DEBUG_LEVELING_FEATURE)
+ if (DEBUGGING(LEVELING)) {
+ SERIAL_ECHOLNPGM("> homing not needed, skip");
+ SERIAL_ECHOLNPGM("<<< G28");
+ }
+ #endif
+ return;
+ }
+
// Wait for planner moves to finish!
- stepper.synchronize();
+ planner.synchronize();
// Cancel the active G29 session
#if ENABLED(PROBE_MANUALLY)
@@ -4055,6 +4101,11 @@ inline void gcode_G28(const bool always_home_all) {
workspace_plane = PLANE_XY;
#endif
+ #if ENABLED(BLTOUCH)
+ bltouch_command(BLTOUCH_RESET);
+ set_bltouch_deployed(false);
+ #endif
+
// Always home with tool 0 active
#if HOTENDS > 1
#if DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE)
@@ -4089,13 +4140,13 @@ inline void gcode_G28(const bool always_home_all) {
#if Z_HOME_DIR > 0 // If homing away from BED do Z first
- if (home_all || homeZ) HOMEAXIS(Z);
+ if (home_all || homeZ) homeaxis(Z_AXIS);
#endif
const float z_homing_height = (
#if ENABLED(UNKNOWN_Z_NO_RAISE)
- !axis_known_position[Z_AXIS] ? 0 :
+ !TEST(axis_known_position, Z_AXIS) ? 0 :
#endif
(parser.seenval('R') ? parser.value_linear_units() : Z_HOMING_HEIGHT)
);
@@ -4127,7 +4178,7 @@ inline void gcode_G28(const bool always_home_all) {
#if ENABLED(CODEPENDENT_XY_HOMING)
|| homeX
#endif
- ) HOMEAXIS(Y);
+ ) homeaxis(Y_AXIS);
#endif
@@ -4142,14 +4193,14 @@ inline void gcode_G28(const bool always_home_all) {
// Always home the 2nd (right) extruder first
active_extruder = 1;
- HOMEAXIS(X);
+ homeaxis(X_AXIS);
// Remember this extruder's position for later tool change
inactive_extruder_x_pos = current_position[X_AXIS];
// Home the 1st (left) extruder
active_extruder = 0;
- HOMEAXIS(X);
+ homeaxis(X_AXIS);
// Consider the active extruder to be parked
COPY(raised_parked_position, current_position);
@@ -4158,14 +4209,14 @@ inline void gcode_G28(const bool always_home_all) {
#else
- HOMEAXIS(X);
+ homeaxis(X_AXIS);
#endif
}
// Home Y (after X)
#if DISABLED(HOME_Y_BEFORE_X)
- if (home_all || homeY) HOMEAXIS(Y);
+ if (home_all || homeY) homeaxis(Y_AXIS);
#endif
// Home Z last if homing towards the bed
@@ -4174,10 +4225,10 @@ inline void gcode_G28(const bool always_home_all) {
#if ENABLED(Z_SAFE_HOMING)
home_z_safely();
#else
- HOMEAXIS(Z);
+ homeaxis(Z_AXIS);
#endif
- #if HOMING_Z_WITH_PROBE && Z_AFTER_PROBING
+ #if HOMING_Z_WITH_PROBE && defined(Z_AFTER_PROBING)
move_z_after_probing();
#endif
@@ -4226,7 +4277,7 @@ inline void gcode_G28(const bool always_home_all) {
#endif
#if ENABLED(DEBUG_LEVELING_FEATURE)
- if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< gcode_G28");
+ if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("<<< G28");
#endif
} // G28
@@ -4350,7 +4401,7 @@ void home_all_axes() { gcode_G28(true); }
// One last "return to the bed" (as originally coded) at completion
current_position[Z_AXIS] = MANUAL_PROBE_HEIGHT;
buffer_line_to_current_position();
- stepper.synchronize();
+ planner.synchronize();
// After recording the last point, activate home and activate
mbl_probe_index = -1;
@@ -4365,7 +4416,7 @@ void home_all_axes() { gcode_G28(true); }
current_position[Z_AXIS] = 0;
set_destination_from_current();
buffer_line_to_destination(homing_feedrate(Z_AXIS));
- stepper.synchronize();
+ planner.synchronize();
#endif
#if ENABLED(LCD_BED_LEVELING)
@@ -4420,10 +4471,10 @@ void home_all_axes() { gcode_G28(true); }
reset_bed_level();
break;
- } // switch(state)
+ } // switch (state)
if (state == MeshNext) {
- SERIAL_PROTOCOLPAIR("MBL G29 point ", min(mbl_probe_index, GRID_MAX_POINTS));
+ SERIAL_PROTOCOLPAIR("MBL G29 point ", MIN(mbl_probe_index, GRID_MAX_POINTS));
SERIAL_PROTOCOLLNPAIR(" of ", int(GRID_MAX_POINTS));
}
@@ -4452,6 +4503,8 @@ void home_all_axes() { gcode_G28(true); }
*
* Enhanced G29 Auto Bed Leveling Probe Routine
*
+ * O Auto-level only if needed
+ *
* D Dry-Run mode. Just evaluate the bed Topology - Don't apply
* or alter the bed level data. Useful to check the topology
* after a first run of G29.
@@ -4558,6 +4611,16 @@ void home_all_axes() { gcode_G28(true); }
// Don't allow auto-leveling without homing first
if (axis_unhomed_error()) return;
+ if (!no_action && planner.leveling_active && parser.boolval('O')) { // Auto-level only if needed
+ #if ENABLED(DEBUG_LEVELING_FEATURE)
+ if (DEBUGGING(LEVELING)) {
+ SERIAL_ECHOLNPGM("> Auto-level not needed, skip");
+ SERIAL_ECHOLNPGM("<<< G29");
+ }
+ #endif
+ return;
+ }
+
// Define local vars 'static' for manual probing, 'auto' otherwise
#if ENABLED(PROBE_MANUALLY)
#define ABL_VAR static
@@ -4640,6 +4703,10 @@ void home_all_axes() { gcode_G28(true); }
*/
if (!g29_in_progress) {
+ #if ENABLED(DUAL_X_CARRIAGE)
+ if (active_extruder != 0) tool_change(0);
+ #endif
+
#if ENABLED(PROBE_MANUALLY) || ENABLED(AUTO_BED_LEVELING_LINEAR)
abl_probe_index = -1;
#endif
@@ -4670,8 +4737,8 @@ void home_all_axes() { gcode_G28(true); }
if (!isnan(rx) && !isnan(ry)) {
// Get nearest i / j from rx / ry
- i = (rx - bilinear_start[X_AXIS] + 0.5 * xGridSpacing) / xGridSpacing;
- j = (ry - bilinear_start[Y_AXIS] + 0.5 * yGridSpacing) / yGridSpacing;
+ i = (rx - bilinear_start[X_AXIS] + 0.5f * xGridSpacing) / xGridSpacing;
+ j = (ry - bilinear_start[Y_AXIS] + 0.5f * yGridSpacing) / yGridSpacing;
i = constrain(i, 0, GRID_MAX_POINTS_X - 1);
j = constrain(j, 0, GRID_MAX_POINTS_Y - 1);
}
@@ -4748,8 +4815,17 @@ void home_all_axes() { gcode_G28(true); }
front_probe_bed_position = parser.seenval('F') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : FRONT_PROBE_BED_POSITION;
back_probe_bed_position = parser.seenval('B') ? (int)RAW_Y_POSITION(parser.value_linear_units()) : BACK_PROBE_BED_POSITION;
- if ( !position_is_reachable_by_probe(left_probe_bed_position, front_probe_bed_position)
- || !position_is_reachable_by_probe(right_probe_bed_position, back_probe_bed_position)) {
+ if (
+ #if IS_SCARA || ENABLED(DELTA)
+ !position_is_reachable_by_probe(left_probe_bed_position, 0)
+ || !position_is_reachable_by_probe(right_probe_bed_position, 0)
+ || !position_is_reachable_by_probe(0, front_probe_bed_position)
+ || !position_is_reachable_by_probe(0, back_probe_bed_position)
+ #else
+ !position_is_reachable_by_probe(left_probe_bed_position, front_probe_bed_position)
+ || !position_is_reachable_by_probe(right_probe_bed_position, back_probe_bed_position)
+ #endif
+ ) {
SERIAL_PROTOCOLLNPGM("? (L,R,F,B) out of bounds.");
return;
}
@@ -4766,7 +4842,7 @@ void home_all_axes() { gcode_G28(true); }
SERIAL_EOL();
}
- stepper.synchronize();
+ planner.synchronize();
// Disable auto bed leveling during G29.
// Be formal so G29 can be done successively without G28.
@@ -4846,7 +4922,7 @@ void home_all_axes() { gcode_G28(true); }
if (verbose_level || seenQ) {
SERIAL_PROTOCOLPGM("Manual G29 ");
if (g29_in_progress) {
- SERIAL_PROTOCOLPAIR("point ", min(abl_probe_index + 1, abl_points));
+ SERIAL_PROTOCOLPAIR("point ", MIN(abl_probe_index + 1, abl_points));
SERIAL_PROTOCOLLNPAIR(" of ", abl_points);
}
else
@@ -5324,8 +5400,8 @@ void home_all_axes() { gcode_G28(true); }
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR("Z Probe End Script: ", Z_PROBE_END_SCRIPT);
#endif
+ planner.synchronize();
enqueue_and_echo_commands_P(PSTR(Z_PROBE_END_SCRIPT));
- stepper.synchronize();
#endif
// Auto Bed Leveling is complete! Enable if possible.
@@ -5344,7 +5420,7 @@ void home_all_axes() { gcode_G28(true); }
if (planner.leveling_active)
SYNC_PLAN_POSITION_KINEMATIC();
- #if HAS_BED_PROBE && Z_AFTER_PROBING
+ #if HAS_BED_PROBE && defined(Z_AFTER_PROBING)
move_z_after_probing();
#endif
@@ -5362,7 +5438,7 @@ void home_all_axes() { gcode_G28(true); }
*
* X Probe X position (default current X)
* Y Probe Y position (default current Y)
- * E Engage the probe for each probe
+ * E Engage the probe for each probe (default 1)
*/
inline void gcode_G30() {
const float xpos = parser.linearval('X', current_position[X_AXIS] + X_PROBE_OFFSET_FROM_EXTRUDER),
@@ -5377,18 +5453,18 @@ void home_all_axes() { gcode_G28(true); }
setup_for_endstop_or_probe_move();
- const ProbePtRaise raise_after = parser.boolval('E') ? PROBE_PT_STOW : PROBE_PT_NONE;
+ const ProbePtRaise raise_after = parser.boolval('E', true) ? PROBE_PT_STOW : PROBE_PT_NONE;
const float measured_z = probe_pt(xpos, ypos, raise_after, parser.intval('V', 1));
if (!isnan(measured_z)) {
- SERIAL_PROTOCOLPAIR("Bed X: ", FIXFLOAT(xpos));
- SERIAL_PROTOCOLPAIR(" Y: ", FIXFLOAT(ypos));
- SERIAL_PROTOCOLLNPAIR(" Z: ", FIXFLOAT(measured_z));
+ SERIAL_PROTOCOLPAIR_F("Bed X: ", xpos);
+ SERIAL_PROTOCOLPAIR_F(" Y: ", ypos);
+ SERIAL_PROTOCOLLNPAIR_F(" Z: ", measured_z);
}
clean_up_after_endstop_or_probe_move();
- #if Z_AFTER_PROBING
+ #ifdef Z_AFTER_PROBING
if (raise_after == PROBE_PT_STOW) move_z_after_probing();
#endif
@@ -5442,12 +5518,10 @@ void home_all_axes() { gcode_G28(true); }
float lcd_probe_pt(const float &rx, const float &ry);
- bool ac_home() {
+ void ac_home() {
endstops.enable(true);
- if (!home_delta())
- return false;
+ home_delta();
endstops.not_homing();
- return true;
}
void ac_setup(const bool reset_bed) {
@@ -5455,7 +5529,7 @@ void home_all_axes() { gcode_G28(true); }
tool_change(0, 0, true);
#endif
- stepper.synchronize();
+ planner.synchronize();
setup_for_endstop_or_probe_move();
#if HAS_LEVELING
@@ -5557,7 +5631,7 @@ void home_all_axes() { gcode_G28(true); }
S2 += sq(z_pt[rad]);
N++;
}
- return round(SQRT(S2 / N) * 1000.0) / 1000.0 + 0.00001;
+ return LROUND(SQRT(S2 / N) * 1000.0) / 1000.0 + 0.00001;
}
}
return 0.00001;
@@ -5617,7 +5691,7 @@ void home_all_axes() { gcode_G28(true); }
}
if (_7p_calibration) { // probe extra center points
- const float start = _7p_9_center ? _CA + _7P_STEP / 3.0 : _7p_6_center ? _CA : __C,
+ const float start = _7p_9_center ? float(_CA) + _7P_STEP / 3.0 : _7p_6_center ? float(_CA) : float(__C),
steps = _7p_9_center ? _4P_STEP / 3.0 : _7p_6_center ? _7P_STEP : _4P_STEP;
I_LOOP_CAL_PT(rad, start, steps) {
const float a = RADIANS(210 + (360 / NPP) * (rad - 1)),
@@ -5649,8 +5723,8 @@ void home_all_axes() { gcode_G28(true); }
const float z_temp = calibration_probe(cos(a) * r, sin(a) * r, stow_after_each, set_up);
if (isnan(z_temp)) return false;
// split probe point to neighbouring calibration points
- z_pt[uint8_t(round(rad - interpol + NPP - 1)) % NPP + 1] += z_temp * sq(cos(RADIANS(interpol * 90)));
- z_pt[uint8_t(round(rad - interpol)) % NPP + 1] += z_temp * sq(sin(RADIANS(interpol * 90)));
+ z_pt[uint8_t(LROUND(rad - interpol + NPP - 1)) % NPP + 1] += z_temp * sq(cos(RADIANS(interpol * 90)));
+ z_pt[uint8_t(LROUND(rad - interpol)) % NPP + 1] += z_temp * sq(sin(RADIANS(interpol * 90)));
}
zig_zag = !zig_zag;
}
@@ -5666,7 +5740,7 @@ void home_all_axes() { gcode_G28(true); }
/**
* kinematics routines and auto tune matrix scaling parameters:
- * see https://github.com/LVD-AC/Marlin-AC/tree/1.1.x-AC/documentation for
+ * see https://github.com/LVD-AC/Marlin-AC/tree/1.1.x-AC/documentation for
* - formulae for approximative forward kinematics in the end-stop displacement matrix
* - definition of the matrix scaling parameters
*/
@@ -5680,7 +5754,7 @@ void home_all_axes() { gcode_G28(true); }
pos[Y_AXIS] = sin(a) * r;
pos[Z_AXIS] = z_pt[rad];
inverse_kinematics(pos);
- LOOP_XYZ(axis) mm_at_pt_axis[rad][axis] = delta[axis];
+ LOOP_XYZ(axis) mm_at_pt_axis[rad][axis] = delta[axis];
}
}
@@ -5731,7 +5805,7 @@ void home_all_axes() { gcode_G28(true); }
float h_fac = 0.0;
h_fac = r_quot / (2.0 / 3.0);
- h_fac = 1.0 / h_fac; // (2/3)/CR
+ h_fac = 1.0f / h_fac; // (2/3)/CR
return h_fac;
}
@@ -5744,7 +5818,7 @@ void home_all_axes() { gcode_G28(true); }
delta_t[ABC] = {0.0};
delta_r = diff;
- calc_kinematics_diff_probe_points(z_pt, delta_e, delta_r, delta_t);
+ calc_kinematics_diff_probe_points(z_pt, delta_e, delta_r, delta_t);
r_fac = -(z_pt[__A] + z_pt[__B] + z_pt[__C] + z_pt[_BC] + z_pt[_CA] + z_pt[_AB]) / 6.0;
r_fac = diff / r_fac / 3.0; // 1/(3*delta_Z)
return r_fac;
@@ -5761,7 +5835,7 @@ void home_all_axes() { gcode_G28(true); }
LOOP_XYZ(axis) {
LOOP_XYZ(axis_2) delta_t[axis_2] = 0.0;
delta_t[axis] = diff;
- calc_kinematics_diff_probe_points(z_pt, delta_e, delta_r, delta_t);
+ calc_kinematics_diff_probe_points(z_pt, delta_e, delta_r, delta_t);
a_fac += z_pt[uint8_t((axis * _4P_STEP) - _7P_STEP + NPP) % NPP + 1] / 6.0;
a_fac -= z_pt[uint8_t((axis * _4P_STEP) + 1 + _7P_STEP)] / 6.0;
}
@@ -5889,22 +5963,18 @@ void home_all_axes() { gcode_G28(true); }
}
// Report settings
-
const char *checkingac = PSTR("Checking... AC");
serialprintPGM(checkingac);
if (verbose_level == 0) SERIAL_PROTOCOLPGM(" (DRY-RUN)");
if (set_up) SERIAL_PROTOCOLPGM(" (SET-UP)");
SERIAL_EOL();
- char mess[11];
- strcpy_P(mess, checkingac);
- lcd_setstatus(mess);
+ lcd_setstatusPGM(checkingac);
print_calibration_settings(_endstop_results, _angle_results);
ac_setup(!_0p_calibration && !_1p_calibration);
- if (!_0p_calibration)
- if (!ac_home()) return;
+ if (!_0p_calibration) ac_home();
do { // start iterations
@@ -5943,7 +6013,7 @@ void home_all_axes() { gcode_G28(true); }
/**
* convergence matrices:
- * see https://github.com/LVD-AC/Marlin-AC/tree/1.1.x-AC/documentation for
+ * see https://github.com/LVD-AC/Marlin-AC/tree/1.1.x-AC/documentation for
* - definition of the matrix scaling parameters
* - matrices for 4 and 7 point calibration
*/
@@ -6009,7 +6079,7 @@ void home_all_axes() { gcode_G28(true); }
delta_radius += r_delta;
LOOP_XYZ(axis) delta_tower_angle_trim[axis] += t_delta[axis];
}
- else if (zero_std_dev >= test_precision) {
+ else if (zero_std_dev >= test_precision) {
// roll back
COPY(delta_endstop_adj, e_old);
delta_radius = r_old;
@@ -6035,7 +6105,7 @@ void home_all_axes() { gcode_G28(true); }
NOMORE(zero_std_dev_min, zero_std_dev);
// print report
-
+
if (verbose_level == 3)
print_calibration_results(z_at_pt, _tower_results, _opposite_results);
@@ -6056,9 +6126,9 @@ void home_all_axes() { gcode_G28(true); }
char mess[21];
strcpy_P(mess, PSTR("Calibration sd:"));
if (zero_std_dev_min < 1)
- sprintf_P(&mess[15], PSTR("0.%03i"), (int)round(zero_std_dev_min * 1000.0));
+ sprintf_P(&mess[15], PSTR("0.%03i"), (int)LROUND(zero_std_dev_min * 1000.0));
else
- sprintf_P(&mess[15], PSTR("%03i.x"), (int)round(zero_std_dev_min));
+ sprintf_P(&mess[15], PSTR("%03i.x"), (int)LROUND(zero_std_dev_min));
lcd_setstatus(mess);
print_calibration_settings(_endstop_results, _angle_results);
serialprintPGM(save_message);
@@ -6092,12 +6162,12 @@ void home_all_axes() { gcode_G28(true); }
strcpy_P(mess, enddryrun);
strcpy_P(&mess[11], PSTR(" sd:"));
if (zero_std_dev < 1)
- sprintf_P(&mess[15], PSTR("0.%03i"), (int)round(zero_std_dev * 1000.0));
+ sprintf_P(&mess[15], PSTR("0.%03i"), (int)LROUND(zero_std_dev * 1000.0));
else
- sprintf_P(&mess[15], PSTR("%03i.x"), (int)round(zero_std_dev));
+ sprintf_P(&mess[15], PSTR("%03i.x"), (int)LROUND(zero_std_dev));
lcd_setstatus(mess);
}
- if (!ac_home()) return;
+ ac_home();
}
while (((zero_std_dev < test_precision && iterations < 31) || iterations <= force_iterations) && zero_std_dev > calibration_precision);
@@ -6117,18 +6187,17 @@ void home_all_axes() { gcode_G28(true); }
float retract_mm[XYZ];
LOOP_XYZ(i) {
float dist = destination[i] - current_position[i];
- retract_mm[i] = FABS(dist) < G38_MINIMUM_MOVE ? 0 : home_bump_mm((AxisEnum)i) * (dist > 0 ? -1 : 1);
+ retract_mm[i] = ABS(dist) < G38_MINIMUM_MOVE ? 0 : home_bump_mm((AxisEnum)i) * (dist > 0 ? -1 : 1);
}
#endif
- stepper.synchronize(); // wait until the machine is idle
-
// Move until destination reached or target hit
+ planner.synchronize();
endstops.enable(true);
G38_move = true;
G38_endstop_hit = false;
prepare_move_to_destination();
- stepper.synchronize();
+ planner.synchronize();
G38_move = false;
endstops.hit_on_purpose();
@@ -6145,17 +6214,17 @@ void home_all_axes() { gcode_G28(true); }
LOOP_XYZ(i) destination[i] += retract_mm[i];
endstops.enable(false);
prepare_move_to_destination();
- stepper.synchronize();
feedrate_mm_s /= 4;
// Bump the target more slowly
LOOP_XYZ(i) destination[i] -= retract_mm[i] * 2;
+ planner.synchronize();
endstops.enable(true);
G38_move = true;
prepare_move_to_destination();
- stepper.synchronize();
+ planner.synchronize();
G38_move = false;
set_current_from_steppers_for_axis(ALL_AXES);
@@ -6182,7 +6251,7 @@ void home_all_axes() { gcode_G28(true); }
// If any axis has enough movement, do the move
LOOP_XYZ(i)
- if (FABS(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) {
+ if (ABS(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) {
if (!parser.seenval('F')) feedrate_mm_s = homing_feedrate((AxisEnum)i);
// If G38.2 fails throw an error
if (!G38_run_probe() && is_38_2) {
@@ -6245,8 +6314,6 @@ void home_all_axes() { gcode_G28(true); }
*/
inline void gcode_G92() {
- stepper.synchronize();
-
#if ENABLED(CNC_COORDINATE_SYSTEMS)
switch (parser.subcode) {
case 1:
@@ -6306,10 +6373,9 @@ inline void gcode_G92() {
COPY(coordinate_system[active_coordinate_system], position_shift);
#endif
- if (didXYZ)
- SYNC_PLAN_POSITION_KINEMATIC();
- else if (didE)
- sync_plan_position_e();
+ // Update planner/steppers only if the native coordinates changed
+ if (didXYZ) SYNC_PLAN_POSITION_KINEMATIC();
+ else if (didE) sync_plan_position_e();
report_current_position();
}
@@ -6336,6 +6402,8 @@ inline void gcode_G92() {
const bool has_message = !hasP && !hasS && args && *args;
+ planner.synchronize();
+
#if ENABLED(ULTIPANEL)
if (has_message)
@@ -6359,8 +6427,6 @@ inline void gcode_G92() {
KEEPALIVE_STATE(PAUSED_FOR_USER);
wait_for_user = true;
- stepper.synchronize();
-
if (ms > 0) {
ms += millis(); // wait until this time for a click
while (PENDING(millis(), ms) && wait_for_user) idle();
@@ -6437,7 +6503,7 @@ inline void gcode_G92() {
inline void gcode_M3_M4(bool is_M3) {
- stepper.synchronize(); // wait until previous movement commands (G0/G0/G2/G3) have completed before playing with the spindle
+ planner.synchronize(); // wait until previous movement commands (G0/G0/G2/G3) have completed before playing with the spindle
#if SPINDLE_DIR_CHANGE
const bool rotation_dir = (is_M3 && !SPINDLE_INVERT_DIR || !is_M3 && SPINDLE_INVERT_DIR) ? HIGH : LOW;
if (SPINDLE_STOP_ON_DIR_CHANGE \
@@ -6465,12 +6531,12 @@ inline void gcode_G92() {
delay_for_power_down();
}
else {
- int16_t ocr_val = (spindle_laser_power - (SPEED_POWER_INTERCEPT)) * (1.0 / (SPEED_POWER_SLOPE)); // convert RPM to PWM duty cycle
+ int16_t ocr_val = (spindle_laser_power - (SPEED_POWER_INTERCEPT)) * (1.0f / (SPEED_POWER_SLOPE)); // convert RPM to PWM duty cycle
NOMORE(ocr_val, 255); // limit to max the Atmel PWM will support
if (spindle_laser_power <= SPEED_POWER_MIN)
- ocr_val = (SPEED_POWER_MIN - (SPEED_POWER_INTERCEPT)) * (1.0 / (SPEED_POWER_SLOPE)); // minimum setting
+ ocr_val = (SPEED_POWER_MIN - (SPEED_POWER_INTERCEPT)) * (1.0f / (SPEED_POWER_SLOPE)); // minimum setting
if (spindle_laser_power >= SPEED_POWER_MAX)
- ocr_val = (SPEED_POWER_MAX - (SPEED_POWER_INTERCEPT)) * (1.0 / (SPEED_POWER_SLOPE)); // limit to max RPM
+ ocr_val = (SPEED_POWER_MAX - (SPEED_POWER_INTERCEPT)) * (1.0f / (SPEED_POWER_SLOPE)); // limit to max RPM
if (SPINDLE_LASER_PWM_INVERT) ocr_val = 255 - ocr_val;
WRITE(SPINDLE_LASER_ENABLE_PIN, SPINDLE_LASER_ENABLE_INVERT); // turn spindle on (active low)
analogWrite(SPINDLE_LASER_PWM_PIN, ocr_val & 0xFF); // only write low byte
@@ -6487,7 +6553,7 @@ inline void gcode_G92() {
* M5 turn off spindle
*/
inline void gcode_M5() {
- stepper.synchronize();
+ planner.synchronize();
WRITE(SPINDLE_LASER_ENABLE_PIN, !SPINDLE_LASER_ENABLE_INVERT);
#if ENABLED(SPINDLE_LASER_PWM)
analogWrite(SPINDLE_LASER_PWM_PIN, SPINDLE_LASER_PWM_INVERT ? 255 : 0);
@@ -6511,8 +6577,8 @@ inline void gcode_M17() {
set_destination_from_current();
destination[E_AXIS] += length / planner.e_factor[active_extruder];
planner.buffer_line_kinematic(destination, fr, active_extruder);
- stepper.synchronize();
set_current_from_destination();
+ planner.synchronize();
}
static float resume_position[XYZE];
@@ -6800,12 +6866,12 @@ inline void gcode_M17() {
#endif
print_job_timer.pause();
- // Wait for synchronize steppers
- stepper.synchronize();
-
// Save current position
COPY(resume_position, current_position);
+ // Wait for synchronize steppers
+ planner.synchronize();
+
// Initial retract before move to filament change position
if (retract && thermalManager.hotEnoughToExtrude(active_extruder))
do_pause_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);
@@ -7024,6 +7090,9 @@ inline void gcode_M17() {
* M23: Open a file
*/
inline void gcode_M23() {
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ card.removeJobRecoveryFile();
+ #endif
// Simplify3D includes the size, so zero out all spaces (#7227)
for (char *fn = parser.string_arg; *fn; ++fn) if (*fn == ' ') *fn = '\0';
card.openFile(parser.string_arg, true);
@@ -7033,16 +7102,22 @@ inline void gcode_M17() {
* M24: Start or Resume SD Print
*/
inline void gcode_M24() {
- #if ENABLED(POWER_LOSS_RECOVERY)
- card.removeJobRecoveryFile();
- #endif
-
#if ENABLED(PARK_HEAD_ON_PAUSE)
resume_print();
#endif
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ if (parser.seenval('S')) card.setIndex(parser.value_long());
+ #endif
+
card.startFileprint();
- print_job_timer.start();
+
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ if (parser.seenval('T'))
+ print_job_timer.resume(parser.value_long());
+ else
+ #endif
+ print_job_timer.start();
}
/**
@@ -7136,7 +7211,7 @@ inline void gcode_M31() {
*
*/
inline void gcode_M32() {
- if (card.sdprinting) stepper.synchronize();
+ if (card.sdprinting) planner.synchronize();
if (card.cardOK) {
const bool call_procedure = parser.boolval('P');
@@ -7205,6 +7280,11 @@ static bool pin_is_protected(const pin_t pin) {
return false;
}
+inline void protected_pin_err() {
+ SERIAL_ERROR_START();
+ SERIAL_ERRORLNPGM(MSG_ERR_PROTECTED_PIN);
+}
+
/**
* M42: Change pin status via GCode
*
@@ -7218,11 +7298,7 @@ inline void gcode_M42() {
const pin_t pin_number = parser.byteval('P', LED_PIN);
if (pin_number < 0) return;
- if (pin_is_protected(pin_number)) {
- SERIAL_ERROR_START();
- SERIAL_ERRORLNPGM(MSG_ERR_PROTECTED_PIN);
- return;
- }
+ if (pin_is_protected(pin_number)) return protected_pin_err();
pinMode(pin_number, OUTPUT);
digitalWrite(pin_number, pin_status);
@@ -7248,21 +7324,21 @@ inline void gcode_M42() {
#include "pinsDebug.h"
inline void toggle_pins() {
- const bool I_flag = parser.boolval('I');
+ const bool ignore_protection = parser.boolval('I');
const int repeat = parser.intval('R', 1),
start = parser.intval('S'),
end = parser.intval('L', NUM_DIGITAL_PINS - 1),
wait = parser.intval('W', 500);
for (uint8_t pin = start; pin <= end; pin++) {
- //report_pin_state_extended(pin, I_flag, false);
+ //report_pin_state_extended(pin, ignore_protection, false);
- if (!I_flag && pin_is_protected(pin)) {
- report_pin_state_extended(pin, I_flag, true, "Untouched ");
+ if (!ignore_protection && pin_is_protected(pin)) {
+ report_pin_state_extended(pin, ignore_protection, true, "Untouched ");
SERIAL_EOL();
}
else {
- report_pin_state_extended(pin, I_flag, true, "Pulsing ");
+ report_pin_state_extended(pin, ignore_protection, true, "Pulsing ");
#if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
if (pin == TEENSY_E2) {
SET_OUTPUT(TEENSY_E2);
@@ -7481,7 +7557,7 @@ inline void gcode_M42() {
SERIAL_PROTOCOLLNPGM("Watching pins");
byte pin_state[last_pin - first_pin + 1];
for (pin_t pin = first_pin; pin <= last_pin; pin++) {
- if (pin_is_protected(pin) && !ignore_protection) continue;
+ if (!ignore_protection && pin_is_protected(pin)) continue;
pinMode(pin, INPUT_PULLUP);
delay(1);
/*
@@ -7499,7 +7575,7 @@ inline void gcode_M42() {
for (;;) {
for (pin_t pin = first_pin; pin <= last_pin; pin++) {
- if (pin_is_protected(pin) && !ignore_protection) continue;
+ if (!ignore_protection && pin_is_protected(pin)) continue;
const byte val =
/*
IS_ANALOG(pin)
@@ -7609,7 +7685,7 @@ inline void gcode_M42() {
setup_for_endstop_or_probe_move();
- double mean = 0.0, sigma = 0.0, min = 99999.9, max = -99999.9, sample_set[n_samples];
+ float mean = 0.0, sigma = 0.0, min = 99999.9, max = -99999.9, sample_set[n_samples];
// Move to the first point, deploy, and probe
const float t = probe_pt(X_probe_location, Y_probe_location, raise_after, verbose_level);
@@ -7627,7 +7703,7 @@ inline void gcode_M42() {
0.1250000000 * (DELTA_PRINTABLE_RADIUS),
0.3333333333 * (DELTA_PRINTABLE_RADIUS)
#else
- 5.0, 0.125 * min(X_BED_SIZE, Y_BED_SIZE)
+ 5.0, 0.125 * MIN(X_BED_SIZE, Y_BED_SIZE)
#endif
);
@@ -7640,7 +7716,7 @@ inline void gcode_M42() {
}
for (uint8_t l = 0; l < n_legs - 1; l++) {
- double delta_angle;
+ float delta_angle;
if (schizoid_flag)
// The points of a 5 point star are 72 degrees apart. We need to
@@ -7697,7 +7773,7 @@ inline void gcode_M42() {
/**
* Get the current mean for the data points we have so far
*/
- double sum = 0.0;
+ float sum = 0.0;
for (uint8_t j = 0; j <= n; j++) sum += sample_set[j];
mean = sum / (n + 1);
@@ -7769,7 +7845,7 @@ inline void gcode_M42() {
set_bed_leveling_enabled(was_enabled);
#endif
- #if Z_AFTER_PROBING
+ #ifdef Z_AFTER_PROBING
move_z_after_probing();
#endif
@@ -7863,18 +7939,9 @@ inline void gcode_M104() {
*/
if (parser.value_celsius() <= (EXTRUDE_MINTEMP) / 2) {
print_job_timer.stop();
- LCD_MESSAGEPGM(WELCOME_MSG);
+ lcd_reset_status();
}
#endif
-
- #if ENABLED(ULTRA_LCD)
- if (parser.value_celsius() > thermalManager.degHotend(target_extruder))
- #if HOTENDS > 1
- lcd_status_printf_P(0, PSTR("E%i " MSG_HEATING), target_extruder + 1);
- #else
- LCD_MESSAGEPGM("E " MSG_HEATING);
- #endif
- #endif
}
#if ENABLED(AUTOTEMP)
@@ -7941,14 +8008,14 @@ inline void gcode_M105() {
fanSpeeds[p] = new_fanSpeeds[p];
break;
default:
- new_fanSpeeds[p] = min(t, 255);
+ new_fanSpeeds[p] = MIN(t, 255);
break;
}
return;
}
#endif // EXTRA_FAN_SPEED
const uint16_t s = parser.ushortval('S', 255);
- fanSpeeds[p] = min(s, 255);
+ fanSpeeds[p] = MIN(s, 255U);
}
}
@@ -8025,7 +8092,7 @@ inline void gcode_M109() {
*/
if (parser.value_celsius() <= (EXTRUDE_MINTEMP) / 2) {
print_job_timer.stop();
- LCD_MESSAGEPGM(WELCOME_MSG);
+ lcd_reset_status();
}
else
print_job_timer.start();
@@ -8056,7 +8123,7 @@ inline void gcode_M109() {
#define TEMP_CONDITIONS (wants_to_cool ? thermalManager.isCoolingHotend(target_extruder) : thermalManager.isHeatingHotend(target_extruder))
#endif
- float target_temp = -1.0, old_temp = 9999.0;
+ float target_temp = -1, old_temp = 9999;
bool wants_to_cool = false;
wait_for_heatup = true;
millis_t now, next_temp_ms = 0, next_cool_check_ms = 0;
@@ -8117,7 +8184,7 @@ inline void gcode_M109() {
#if TEMP_RESIDENCY_TIME > 0
- const float temp_diff = FABS(target_temp - temp);
+ const float temp_diff = ABS(target_temp - temp);
if (!residency_start_ms) {
// Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
@@ -8135,7 +8202,7 @@ inline void gcode_M109() {
// break after MIN_COOLING_SLOPE_TIME seconds
// if the temperature did not drop at least MIN_COOLING_SLOPE_DEG
if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
- if (old_temp - temp < MIN_COOLING_SLOPE_DEG) break;
+ if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG)) break;
next_cool_check_ms = now + 1000UL * MIN_COOLING_SLOPE_TIME;
old_temp = temp;
}
@@ -8263,7 +8330,7 @@ inline void gcode_M109() {
#if TEMP_BED_RESIDENCY_TIME > 0
- const float temp_diff = FABS(target_temp - temp);
+ const float temp_diff = ABS(target_temp - temp);
if (!residency_start_ms) {
// Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
@@ -8281,7 +8348,7 @@ inline void gcode_M109() {
// Break after MIN_COOLING_SLOPE_TIME_BED seconds
// if the temperature did not drop at least MIN_COOLING_SLOPE_DEG_BED
if (!next_cool_check_ms || ELAPSED(now, next_cool_check_ms)) {
- if (old_temp - temp < MIN_COOLING_SLOPE_DEG_BED) break;
+ if (old_temp - temp < float(MIN_COOLING_SLOPE_DEG_BED)) break;
next_cool_check_ms = now + 1000UL * MIN_COOLING_SLOPE_TIME_BED;
old_temp = temp;
}
@@ -8340,6 +8407,23 @@ inline void gcode_M111() {
}
else {
SERIAL_ECHOPGM(MSG_DEBUG_OFF);
+ #if !defined(__AVR__) || !defined(USBCON)
+ #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
+ SERIAL_ECHOPAIR("\nBuffer Overruns: ", customizedSerial.buffer_overruns());
+ #endif
+
+ #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
+ SERIAL_ECHOPAIR("\nFraming Errors: ", customizedSerial.framing_errors());
+ #endif
+
+ #if ENABLED(SERIAL_STATS_DROPPED_RX)
+ SERIAL_ECHOPAIR("\nDropped bytes: ", customizedSerial.dropped());
+ #endif
+
+ #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
+ SERIAL_ECHOPAIR("\nMax RX Queue Size: ", customizedSerial.rxMaxEnqueued());
+ #endif
+ #endif // !__AVR__ || !USBCON
}
SERIAL_EOL();
}
@@ -8469,7 +8553,7 @@ inline void gcode_M111() {
#endif
#if ENABLED(ULTIPANEL)
- LCD_MESSAGEPGM(WELCOME_MSG);
+ lcd_reset_status();
#endif
}
@@ -8482,7 +8566,7 @@ inline void gcode_M111() {
*/
inline void gcode_M81() {
thermalManager.disable_all_heaters();
- stepper.finish_and_disable();
+ planner.finish_and_disable();
#if FAN_COUNT > 0
for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
@@ -8495,7 +8579,6 @@ inline void gcode_M81() {
safe_delay(1000); // Wait 1 second before switching off
#if HAS_SUICIDE
- stepper.synchronize();
suicide();
#elif HAS_POWER_SWITCH
PSU_OFF();
@@ -8526,10 +8609,10 @@ inline void gcode_M18_M84() {
else {
bool all_axis = !(parser.seen('X') || parser.seen('Y') || parser.seen('Z') || parser.seen('E'));
if (all_axis) {
- stepper.finish_and_disable();
+ planner.finish_and_disable();
}
else {
- stepper.synchronize();
+ planner.synchronize();
if (parser.seen('X')) disable_X();
if (parser.seen('Y')) disable_Y();
if (parser.seen('Z')) disable_Z();
@@ -8576,9 +8659,11 @@ inline void gcode_M92() {
if (parser.seen(axis_codes[i])) {
if (i == E_AXIS) {
const float value = parser.value_per_axis_unit((AxisEnum)(E_AXIS + TARGET_EXTRUDER));
- if (value < 20.0) {
+ if (value < 20) {
float factor = planner.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] / value; // increase e constants if M92 E14 is given for netfab.
- planner.max_jerk[E_AXIS] *= factor;
+ #if DISABLED(JUNCTION_DEVIATION)
+ planner.max_jerk[E_AXIS] *= factor;
+ #endif
planner.max_feedrate_mm_s[E_AXIS + TARGET_EXTRUDER] *= factor;
planner.max_acceleration_steps_per_s2[E_AXIS + TARGET_EXTRUDER] *= factor;
}
@@ -8608,8 +8693,8 @@ void report_current_position() {
stepper.report_positions();
#if IS_SCARA
- SERIAL_PROTOCOLPAIR("SCARA Theta:", stepper.get_axis_position_degrees(A_AXIS));
- SERIAL_PROTOCOLLNPAIR(" Psi+Theta:", stepper.get_axis_position_degrees(B_AXIS));
+ SERIAL_PROTOCOLPAIR("SCARA Theta:", planner.get_axis_position_degrees(A_AXIS));
+ SERIAL_PROTOCOLLNPAIR(" Psi+Theta:", planner.get_axis_position_degrees(B_AXIS));
SERIAL_EOL();
#endif
}
@@ -8631,8 +8716,6 @@ void report_current_position() {
void report_current_position_detail() {
- stepper.synchronize();
-
SERIAL_PROTOCOLPGM("\nLogical:");
const float logical[XYZ] = {
LOGICAL_X_POSITION(current_position[X_AXIS]),
@@ -8667,6 +8750,8 @@ void report_current_position() {
report_xyz(delta);
#endif
+ planner.synchronize();
+
SERIAL_PROTOCOLPGM("Stepper:");
LOOP_XYZE(i) {
SERIAL_CHAR(' ');
@@ -8678,8 +8763,8 @@ void report_current_position() {
#if IS_SCARA
const float deg[XYZ] = {
- stepper.get_axis_position_degrees(A_AXIS),
- stepper.get_axis_position_degrees(B_AXIS)
+ planner.get_axis_position_degrees(A_AXIS),
+ planner.get_axis_position_degrees(B_AXIS)
};
SERIAL_PROTOCOLPGM("Degrees:");
report_xyze(deg, 2);
@@ -8687,7 +8772,7 @@ void report_current_position() {
SERIAL_PROTOCOLPGM("FromStp:");
get_cartesian_from_steppers(); // writes cartes[XYZ] (with forward kinematics)
- const float from_steppers[XYZE] = { cartes[X_AXIS], cartes[Y_AXIS], cartes[Z_AXIS], stepper.get_axis_position_mm(E_AXIS) };
+ const float from_steppers[XYZE] = { cartes[X_AXIS], cartes[Y_AXIS], cartes[Z_AXIS], planner.get_axis_position_mm(E_AXIS) };
report_xyze(from_steppers);
const float diff[XYZE] = {
@@ -8713,7 +8798,7 @@ inline void gcode_M114() {
}
#endif
- stepper.synchronize();
+ planner.synchronize();
report_current_position();
}
@@ -8853,7 +8938,7 @@ inline void gcode_M117() {
/**
* M118: Display a message in the host console.
*
- * A1 Append '// ' for an action command, as in OctoPrint
+ * A1 Prepend '// ' for an action command, as in OctoPrint
* E1 Have the host 'echo:' the text
*/
inline void gcode_M118() {
@@ -8906,7 +8991,7 @@ inline void gcode_M121() { endstops.enable_globally(false); }
inline void gcode_M125() {
// Initial retract before move to filament change position
- const float retract = -FABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : 0
+ const float retract = -ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : 0
#ifdef PAUSE_PARK_RETRACT_LENGTH
+ (PAUSE_PARK_RETRACT_LENGTH)
#endif
@@ -8992,7 +9077,7 @@ inline void gcode_M121() { endstops.enable_globally(false); }
// setting any extruder filament size disables volumetric on the assumption that
// slicers either generate in extruder values as cubic mm or as as filament feeds
// for all extruders
- if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0.0)) )
+ if ( (parser.volumetric_enabled = (parser.value_linear_units() != 0)) )
planner.set_filament_size(target_extruder, parser.value_linear_units());
}
planner.calculate_volumetric_multipliers();
@@ -9079,28 +9164,43 @@ inline void gcode_M204() {
/**
* M205: Set Advanced Settings
*
+ * B = Min Segment Time (µs)
* S = Min Feed Rate (units/s)
* T = Min Travel Feed Rate (units/s)
- * B = Min Segment Time (µs)
* X = Max X Jerk (units/sec^2)
* Y = Max Y Jerk (units/sec^2)
* Z = Max Z Jerk (units/sec^2)
* E = Max E Jerk (units/sec^2)
+ * J = Junction Deviation (mm) (Requires JUNCTION_DEVIATION)
*/
inline void gcode_M205() {
+ if (parser.seen('B')) planner.min_segment_time_us = parser.value_ulong();
if (parser.seen('S')) planner.min_feedrate_mm_s = parser.value_linear_units();
if (parser.seen('T')) planner.min_travel_feedrate_mm_s = parser.value_linear_units();
- if (parser.seen('B')) planner.min_segment_time_us = parser.value_ulong();
- if (parser.seen('X')) planner.max_jerk[X_AXIS] = parser.value_linear_units();
- if (parser.seen('Y')) planner.max_jerk[Y_AXIS] = parser.value_linear_units();
- if (parser.seen('Z')) {
- planner.max_jerk[Z_AXIS] = parser.value_linear_units();
- #if HAS_MESH
- if (planner.max_jerk[Z_AXIS] <= 0.1)
- SERIAL_ECHOLNPGM("WARNING! Low Z Jerk may lead to unwanted pauses.");
- #endif
- }
- if (parser.seen('E')) planner.max_jerk[E_AXIS] = parser.value_linear_units();
+ #if ENABLED(JUNCTION_DEVIATION)
+ if (parser.seen('J')) {
+ const float junc_dev = parser.value_linear_units();
+ if (WITHIN(junc_dev, 0.01f, 0.3f)) {
+ planner.junction_deviation_mm = junc_dev;
+ planner.recalculate_max_e_jerk();
+ }
+ else {
+ SERIAL_ERROR_START();
+ SERIAL_ERRORLNPGM("?J out of range (0.01 to 0.3)");
+ }
+ }
+ #else
+ if (parser.seen('X')) planner.max_jerk[X_AXIS] = parser.value_linear_units();
+ if (parser.seen('Y')) planner.max_jerk[Y_AXIS] = parser.value_linear_units();
+ if (parser.seen('Z')) {
+ planner.max_jerk[Z_AXIS] = parser.value_linear_units();
+ #if HAS_MESH
+ if (planner.max_jerk[Z_AXIS] <= 0.1f)
+ SERIAL_ECHOLNPGM("WARNING! Low Z Jerk may lead to unwanted pauses.");
+ #endif
+ }
+ if (parser.seen('E')) planner.max_jerk[E_AXIS] = parser.value_linear_units();
+ #endif
}
#if HAS_M206_COMMAND
@@ -9341,7 +9441,7 @@ inline void gcode_M211() {
* T
* X
* Y
- * Z - Available with DUAL_X_CARRIAGE and SWITCHING_NOZZLE
+ * Z - Available with DUAL_X_CARRIAGE, SWITCHING_NOZZLE, and PARKING_EXTRUDER
*/
inline void gcode_M218() {
if (get_target_extruder_from_command(218) || target_extruder == 0) return;
@@ -9356,7 +9456,7 @@ inline void gcode_M211() {
report = false;
}
- #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER)
+ #if HAS_HOTEND_OFFSET_Z
if (parser.seenval('Z')) {
hotend_offset[Z_AXIS][target_extruder] = parser.value_linear_units();
report = false;
@@ -9371,7 +9471,7 @@ inline void gcode_M211() {
SERIAL_ECHO(hotend_offset[X_AXIS][e]);
SERIAL_CHAR(',');
SERIAL_ECHO(hotend_offset[Y_AXIS][e]);
- #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER)
+ #if HAS_HOTEND_OFFSET_Z
SERIAL_CHAR(',');
SERIAL_ECHO(hotend_offset[Z_AXIS][e]);
#endif
@@ -9418,30 +9518,21 @@ inline void gcode_M221() {
*/
inline void gcode_M226() {
if (parser.seen('P')) {
- const int pin = parser.value_int(),
- pin_state = parser.intval('S', -1); // required pin state - default is inverted
-
- if (WITHIN(pin_state, -1, 1) && pin > -1 && !pin_is_protected(pin)) {
-
- int target = LOW;
-
- stepper.synchronize();
-
- pinMode(pin, INPUT);
- switch (pin_state) {
- case 1:
- target = HIGH;
- break;
- case 0:
- target = LOW;
- break;
- case -1:
- target = !digitalRead(pin);
- break;
+ const int pin = parser.value_int(), pin_state = parser.intval('S', -1);
+ if (WITHIN(pin_state, -1, 1) && pin > -1) {
+ if (pin_is_protected(pin))
+ protected_pin_err();
+ else {
+ int target = LOW;
+ planner.synchronize();
+ pinMode(pin, INPUT);
+ switch (pin_state) {
+ case 1: target = HIGH; break;
+ case 0: target = LOW; break;
+ case -1: target = !digitalRead(pin); break;
+ }
+ while (digitalRead(pin) != target) idle();
}
-
- while (digitalRead(pin) != target) idle();
-
} // pin_state -1 0 1 && pin > -1
} // parser.seen('P')
}
@@ -9590,7 +9681,7 @@ inline void gcode_M226() {
* With PID_EXTRUSION_SCALING:
*
* C[float] Kc term
- * L[float] LPQ length
+ * L[int] LPQ length
*/
inline void gcode_M301() {
@@ -9604,8 +9695,9 @@ inline void gcode_M226() {
if (parser.seen('D')) PID_PARAM(Kd, e) = scalePID_d(parser.value_float());
#if ENABLED(PID_EXTRUSION_SCALING)
if (parser.seen('C')) PID_PARAM(Kc, e) = parser.value_float();
- if (parser.seen('L')) lpq_len = parser.value_float();
- NOMORE(lpq_len, LPQ_MAX_LEN);
+ if (parser.seen('L')) thermalManager.lpq_len = parser.value_float();
+ NOMORE(thermalManager.lpq_len, LPQ_MAX_LEN);
+ NOLESS(thermalManager.lpq_len, 0);
#endif
thermalManager.updatePID();
@@ -9888,7 +9980,7 @@ inline void gcode_M303() {
/**
* M400: Finish all moves
*/
-inline void gcode_M400() { stepper.synchronize(); }
+inline void gcode_M400() { planner.synchronize(); }
#if HAS_BED_PROBE
@@ -9905,7 +9997,7 @@ inline void gcode_M400() { stepper.synchronize(); }
*/
inline void gcode_M402() {
STOW_PROBE();
- #if Z_AFTER_PROBING
+ #ifdef Z_AFTER_PROBING
move_z_after_probing();
#endif
report_current_position();
@@ -9971,8 +10063,8 @@ inline void gcode_M400() { stepper.synchronize(); }
#endif // FILAMENT_WIDTH_SENSOR
void quickstop_stepper() {
- stepper.quick_stop();
- stepper.synchronize();
+ planner.quick_stop();
+ planner.synchronize();
set_current_from_steppers_for_axis(ALL_AXES);
SYNC_PLAN_POSITION_KINEMATIC();
}
@@ -10043,8 +10135,9 @@ void quickstop_stepper() {
// L or V display the map info
if (parser.seen('L') || parser.seen('V')) {
ubl.display_map(parser.byteval('T'));
- SERIAL_ECHOLNPAIR("ubl.mesh_is_valid = ", ubl.mesh_is_valid());
- SERIAL_ECHOLNPAIR("ubl.storage_slot = ", ubl.storage_slot);
+ SERIAL_ECHOPGM("Mesh is ");
+ if (!ubl.mesh_is_valid()) SERIAL_ECHOPGM("in");
+ SERIAL_ECHOLNPAIR("valid\nStorage slot: ", ubl.storage_slot);
}
#endif // AUTO_BED_LEVELING_UBL
@@ -10063,7 +10156,7 @@ void quickstop_stepper() {
#if ENABLED(AUTO_BED_LEVELING_UBL)
set_bed_leveling_enabled(false);
- ubl.adjust_mesh_to_mean(cval);
+ ubl.adjust_mesh_to_mean(true, cval);
#else
@@ -10349,7 +10442,7 @@ inline void gcode_M502() {
* M540: Set whether SD card print should abort on endstop hit (M540 S<0|1>)
*/
inline void gcode_M540() {
- if (parser.seen('S')) stepper.abort_on_endstop_hit = parser.value_bool();
+ if (parser.seen('S')) planner.abort_on_endstop_hit = parser.value_bool();
}
#endif // ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED
@@ -10495,7 +10588,7 @@ inline void gcode_M502() {
#endif
// Initial retract before move to filament change position
- const float retract = -FABS(parser.seen('E') ? parser.value_axis_units(E_AXIS) : 0
+ const float retract = -ABS(parser.seen('E') ? parser.value_axis_units(E_AXIS) : 0
#ifdef PAUSE_PARK_RETRACT_LENGTH
+ (PAUSE_PARK_RETRACT_LENGTH)
#endif
@@ -10514,14 +10607,14 @@ inline void gcode_M502() {
#endif
// Unload filament
- const float unload_length = -FABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) :
+ const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) :
filament_change_unload_length[active_extruder]);
// Slow load filament
constexpr float slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH;
// Fast load filament
- const float fast_load_length = FABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) :
+ const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) :
filament_change_load_length[active_extruder]);
const int beep_count = parser.intval('B',
@@ -10563,7 +10656,7 @@ inline void gcode_M502() {
// Unload length
if (parser.seen('U')) {
- filament_change_unload_length[target_extruder] = FABS(parser.value_axis_units(E_AXIS));
+ filament_change_unload_length[target_extruder] = ABS(parser.value_axis_units(E_AXIS));
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
NOMORE(filament_change_unload_length[target_extruder], EXTRUDE_MAXLENGTH);
#endif
@@ -10571,7 +10664,7 @@ inline void gcode_M502() {
// Load length
if (parser.seen('L')) {
- filament_change_load_length[target_extruder] = FABS(parser.value_axis_units(E_AXIS));
+ filament_change_load_length[target_extruder] = ABS(parser.value_axis_units(E_AXIS));
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
NOMORE(filament_change_load_length[target_extruder], EXTRUDE_MAXLENGTH);
#endif
@@ -10583,7 +10676,7 @@ inline void gcode_M502() {
#if ENABLED(MK2_MULTIPLEXER)
inline void select_multiplexed_stepper(const uint8_t e) {
- stepper.synchronize();
+ planner.synchronize();
disable_e_steppers();
WRITE(E_MUX0_PIN, TEST(e, 0) ? HIGH : LOW);
WRITE(E_MUX1_PIN, TEST(e, 1) ? HIGH : LOW);
@@ -10608,14 +10701,14 @@ inline void gcode_M502() {
* Note: the X axis should be homed after changing dual x-carriage mode.
*/
inline void gcode_M605() {
- stepper.synchronize();
+ planner.synchronize();
if (parser.seen('S')) dual_x_carriage_mode = (DualXMode)parser.value_byte();
switch (dual_x_carriage_mode) {
case DXC_FULL_CONTROL_MODE:
case DXC_AUTO_PARK_MODE:
break;
case DXC_DUPLICATION_MODE:
- if (parser.seen('X')) duplicate_extruder_x_offset = max(parser.value_linear_units(), X2_MIN_POS - x_home_pos(0));
+ if (parser.seen('X')) duplicate_extruder_x_offset = MAX(parser.value_linear_units(), X2_MIN_POS - x_home_pos(0));
if (parser.seen('R')) duplicate_extruder_temp_offset = parser.value_celsius_diff();
SERIAL_ECHO_START();
SERIAL_ECHOPGM(MSG_HOTEND_OFFSET);
@@ -10640,7 +10733,7 @@ inline void gcode_M502() {
#elif ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
inline void gcode_M605() {
- stepper.synchronize();
+ planner.synchronize();
extruder_duplication_enabled = parser.intval('S') == (int)DXC_DUPLICATION_MODE;
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(MSG_DUPLICATION_MODE, extruder_duplication_enabled ? MSG_ON : MSG_OFF);
@@ -10653,9 +10746,9 @@ inline void gcode_M502() {
/**
* M701: Load filament
*
- * T[extruder] - Optional extruder number. Current extruder if omitted.
- * Z[distance] - Move the Z axis by this distance
- * L[distance] - Extrude distance for insertion (positive value) (manual reload)
+ * T - Optional extruder number. Current extruder if omitted.
+ * Z - Move the Z axis by this distance
+ * L - Extrude distance for insertion (positive value) (manual reload)
*
* Default values are used for omitted arguments.
*/
@@ -10686,16 +10779,16 @@ inline void gcode_M502() {
// Lift Z axis
if (park_point.z > 0)
- do_blocking_move_to_z(min(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
+ do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
constexpr float slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH;
- const float fast_load_length = FABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : filament_change_load_length[active_extruder]);
+ const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : filament_change_load_length[active_extruder]);
load_filament(slow_load_length, fast_load_length, ADVANCED_PAUSE_PURGE_LENGTH, FILAMENT_CHANGE_ALERT_BEEPS,
true, thermalManager.wait_for_heating(target_extruder), ADVANCED_PAUSE_MODE_LOAD_FILAMENT);
// Restore Z axis
if (park_point.z > 0)
- do_blocking_move_to_z(max(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
+ do_blocking_move_to_z(MAX(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
#if EXTRUDERS > 1
// Restore toolhead if it was changed
@@ -10712,10 +10805,10 @@ inline void gcode_M502() {
/**
* M702: Unload filament
*
- * T[extruder] - Optional extruder number. If omitted, current extruder
+ * T - Optional extruder number. If omitted, current extruder
* (or ALL extruders with FILAMENT_UNLOAD_ALL_EXTRUDERS).
- * Z[distance] - Move the Z axis by this distance
- * U[distance] - Retract distance for removal (manual reload)
+ * Z - Move the Z axis by this distance
+ * U - Retract distance for removal (manual reload)
*
* Default values are used for omitted arguments.
*/
@@ -10746,7 +10839,7 @@ inline void gcode_M502() {
// Lift Z axis
if (park_point.z > 0)
- do_blocking_move_to_z(min(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
+ do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
// Unload filament
#if EXTRUDERS > 1 && ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
@@ -10760,7 +10853,7 @@ inline void gcode_M502() {
#endif
{
// Unload length
- const float unload_length = -FABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) :
+ const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) :
filament_change_unload_length[target_extruder]);
unload_filament(unload_length, true, ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT);
@@ -10768,7 +10861,7 @@ inline void gcode_M502() {
// Restore Z axis
if (park_point.z > 0)
- do_blocking_move_to_z(max(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
+ do_blocking_move_to_z(MAX(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
#if EXTRUDERS > 1
// Restore toolhead if it was changed
@@ -10784,6 +10877,38 @@ inline void gcode_M502() {
#endif // FILAMENT_LOAD_UNLOAD_GCODES
+#if ENABLED(MAX7219_GCODE)
+ /**
+ * M7219: Control the Max7219 LED matrix
+ *
+ * I - Initialize (clear) the matrix
+ * C - Set a column to the 8-bit value V
+ * R - Set a row to the 8-bit value V
+ * X - X position of an LED to set or toggle
+ * Y - Y position of an LED to set or toggle
+ * V - The 8-bit value or on/off state to set
+ */
+ inline void gcode_M7219() {
+ if (parser.seen('I'))
+ Max7219_Clear();
+ else if (parser.seenval('R')) {
+ const uint8_t r = parser.value_int();
+ Max7219_Set_Row(r, parser.byteval('V'));
+ }
+ else if (parser.seenval('C')) {
+ const uint8_t c = parser.value_int();
+ Max7219_Set_Column(c, parser.byteval('V'));
+ }
+ else if (parser.seenval('X') || parser.seenval('Y')) {
+ const uint8_t x = parser.byteval('X'), y = parser.byteval('Y');
+ if (parser.seenval('V'))
+ Max7219_LED_Set(x, y, parser.boolval('V'));
+ else
+ Max7219_LED_Toggle(x, y);
+ }
+ }
+#endif // MAX7219_GCODE
+
#if ENABLED(LIN_ADVANCE)
/**
* M900: Get or Set Linear Advance K-factor
@@ -10794,7 +10919,7 @@ inline void gcode_M502() {
if (parser.seenval('K')) {
const float newK = parser.floatval('K');
if (WITHIN(newK, 0, 10)) {
- stepper.synchronize();
+ planner.synchronize();
planner.extruder_advance_K = newK;
}
else
@@ -10823,7 +10948,7 @@ inline void gcode_M502() {
*/
inline void gcode_M906() {
#define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q, TMC_##Q)
- #define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, TMC_##Q, value)
+ #define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, value)
bool report = true;
const uint8_t index = parser.byteval('I');
@@ -10922,48 +11047,119 @@ inline void gcode_M502() {
}
}
+ #define M91x_USE(A) (ENABLED(A##_IS_TMC2130) || (ENABLED(A##_IS_TMC2208) && PIN_EXISTS(A##_SERIAL_RX)))
+ #define M91x_USE_E(N) (E_STEPPERS > N && M91x_USE(E##N))
+ #define M91x_USE_X (ENABLED(IS_TRAMS) || M91x_USE(X))
+ #define M91x_USE_Y (ENABLED(IS_TRAMS) || M91x_USE(Y))
+ #define M91x_USE_Z (ENABLED(IS_TRAMS) || M91x_USE(Z))
+ #define M91x_USE_E0 (ENABLED(IS_TRAMS) || M91x_USE_E(0))
+
/**
* M911: Report TMC stepper driver overtemperature pre-warn flag
- * The flag is held by the library and persist until manually cleared by M912
+ * This flag is held by the library, persisting until cleared by M912
*/
inline void gcode_M911() {
- #if ENABLED(X_IS_TMC2130) || (ENABLED(X_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX)) || ENABLED(IS_TRAMS)
+ #if M91x_USE_X
tmc_report_otpw(stepperX, TMC_X);
#endif
- #if ENABLED(Y_IS_TMC2130) || (ENABLED(Y_IS_TMC2208) && PIN_EXISTS(Y_SERIAL_RX)) || ENABLED(IS_TRAMS)
+ #if M91x_USE(X2)
+ tmc_report_otpw(stepperX2, TMC_X2);
+ #endif
+ #if M91x_USE_Y
tmc_report_otpw(stepperY, TMC_Y);
#endif
- #if ENABLED(Z_IS_TMC2130) || (ENABLED(Z_IS_TMC2208) && PIN_EXISTS(Z_SERIAL_RX)) || ENABLED(IS_TRAMS)
+ #if M91x_USE(Y2)
+ tmc_report_otpw(stepperY2, TMC_Y2);
+ #endif
+ #if M91x_USE_Z
tmc_report_otpw(stepperZ, TMC_Z);
#endif
- #if ENABLED(E0_IS_TMC2130) || (ENABLED(E0_IS_TMC2208) && PIN_EXISTS(E0_SERIAL_RX)) || ENABLED(IS_TRAMS)
+ #if M91x_USE(Z2)
+ tmc_report_otpw(stepperZ2, TMC_Z2);
+ #endif
+ #if M91x_USE_E0
tmc_report_otpw(stepperE0, TMC_E0);
#endif
+ #if M91x_USE_E(1)
+ tmc_report_otpw(stepperE1, TMC_E1);
+ #endif
+ #if M91x_USE_E(2)
+ tmc_report_otpw(stepperE2, TMC_E2);
+ #endif
+ #if M91x_USE_E(3)
+ tmc_report_otpw(stepperE3, TMC_E3);
+ #endif
+ #if M91x_USE_E(4)
+ tmc_report_otpw(stepperE4, TMC_E4);
+ #endif
}
/**
* M912: Clear TMC stepper driver overtemperature pre-warn flag held by the library
+ * Specify one or more axes with X, Y, Z, X1, Y1, Z1, X2, Y2, Z2, and E[index].
+ * If no axes are given, clear all.
+ *
+ * Examples:
+ * M912 X ; clear X and X2
+ * M912 X1 ; clear X1 only
+ * M912 X2 ; clear X2 only
+ * M912 X E ; clear X, X2, and all E
+ * M912 E1 ; clear E1 only
*/
inline void gcode_M912() {
- const bool clearX = parser.seen(axis_codes[X_AXIS]), clearY = parser.seen(axis_codes[Y_AXIS]), clearZ = parser.seen(axis_codes[Z_AXIS]), clearE = parser.seen(axis_codes[E_AXIS]),
- clearAll = (!clearX && !clearY && !clearZ && !clearE) || (clearX && clearY && clearZ && clearE);
- #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS) || (ENABLED(X_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX))
- if (clearX || clearAll) tmc_clear_otpw(stepperX, TMC_X);
- #endif
- #if ENABLED(X2_IS_TMC2130) || (ENABLED(X2_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX))
- if (clearX || clearAll) tmc_clear_otpw(stepperX, TMC_X);
+ const bool hasX = parser.seen(axis_codes[X_AXIS]),
+ hasY = parser.seen(axis_codes[Y_AXIS]),
+ hasZ = parser.seen(axis_codes[Z_AXIS]),
+ hasE = parser.seen(axis_codes[E_AXIS]),
+ hasNone = !hasX && !hasY && !hasZ && !hasE;
+
+ #if M91x_USE_X || M91x_USE(X2)
+ const uint8_t xval = parser.byteval(axis_codes[X_AXIS], 10);
+ #if M91x_USE_X
+ if (hasNone || xval == 1 || (hasX && xval == 10)) tmc_clear_otpw(stepperX, TMC_X);
+ #endif
+ #if M91x_USE(X2)
+ if (hasNone || xval == 2 || (hasX && xval == 10)) tmc_clear_otpw(stepperX2, TMC_X2);
+ #endif
#endif
- #if ENABLED(Y_IS_TMC2130) || (ENABLED(Y_IS_TMC2208) && PIN_EXISTS(Y_SERIAL_RX))
- if (clearY || clearAll) tmc_clear_otpw(stepperY, TMC_Y);
+ #if M91x_USE_Y || M91x_USE(Y2)
+ const uint8_t yval = parser.byteval(axis_codes[Y_AXIS], 10);
+ #if M91x_USE_Y
+ if (hasNone || yval == 1 || (hasY && yval == 10)) tmc_clear_otpw(stepperY, TMC_Y);
+ #endif
+ #if M91x_USE(Y2)
+ if (hasNone || yval == 2 || (hasY && yval == 10)) tmc_clear_otpw(stepperY2, TMC_Y2);
+ #endif
#endif
- #if ENABLED(Z_IS_TMC2130) || (ENABLED(Z_IS_TMC2208) && PIN_EXISTS(Z_SERIAL_RX))
- if (clearZ || clearAll) tmc_clear_otpw(stepperZ, TMC_Z);
+ #if M91x_USE_Z || M91x_USE(Z2)
+ const uint8_t zval = parser.byteval(axis_codes[Z_AXIS], 10);
+ #if M91x_USE_Z
+ if (hasNone || zval == 1 || (hasZ && zval == 10)) tmc_clear_otpw(stepperZ, TMC_Z);
+ #endif
+ #if M91x_USE(Z2)
+ if (hasNone || zval == 2 || (hasZ && zval == 10)) tmc_clear_otpw(stepperZ2, TMC_Z2);
+ #endif
#endif
- #if ENABLED(E0_IS_TMC2130) || (ENABLED(E0_IS_TMC2208) && PIN_EXISTS(E0_SERIAL_RX))
- if (clearE || clearAll) tmc_clear_otpw(stepperE0, TMC_E0);
+ #if M91x_USE_E0 || M91x_USE_E(1) || M91x_USE_E(2) || M91x_USE_E(3) || M91x_USE_E(4)
+ const uint8_t eval = parser.byteval(axis_codes[E_AXIS], 10);
+ #if M91x_USE_E0
+ if (hasNone || eval == 0 || (hasE && eval == 10)) tmc_clear_otpw(stepperE0, TMC_E0);
+ #endif
+ #if M91x_USE_E(1)
+ if (hasNone || eval == 1 || (hasE && eval == 10)) tmc_clear_otpw(stepperE1, TMC_E1);
+ #endif
+ #if M91x_USE_E(2)
+ if (hasNone || eval == 2 || (hasE && eval == 10)) tmc_clear_otpw(stepperE2, TMC_E2);
+ #endif
+ #if M91x_USE_E(3)
+ if (hasNone || eval == 3 || (hasE && eval == 10)) tmc_clear_otpw(stepperE3, TMC_E3);
+ #endif
+ #if M91x_USE_E(4)
+ if (hasNone || eval == 4 || (hasE && eval == 10)) tmc_clear_otpw(stepperE4, TMC_E4);
+ #endif
#endif
}
@@ -10972,10 +11168,10 @@ inline void gcode_M502() {
*/
#if ENABLED(HYBRID_THRESHOLD)
inline void gcode_M913() {
- #define TMC_SAY_PWMTHRS(P,Q) tmc_get_pwmthrs(stepper##Q, TMC_##Q, planner.axis_steps_per_mm[P##_AXIS])
- #define TMC_SET_PWMTHRS(P,Q) tmc_set_pwmthrs(stepper##Q, TMC_##Q, value, planner.axis_steps_per_mm[P##_AXIS])
+ #define TMC_SAY_PWMTHRS(A,Q) tmc_get_pwmthrs(stepper##Q, TMC_##Q, planner.axis_steps_per_mm[_AXIS(A)])
+ #define TMC_SET_PWMTHRS(A,Q) tmc_set_pwmthrs(stepper##Q, value, planner.axis_steps_per_mm[_AXIS(A)])
#define TMC_SAY_PWMTHRS_E(E) do{ const uint8_t extruder = E; tmc_get_pwmthrs(stepperE##E, TMC_E##E, planner.axis_steps_per_mm[E_AXIS_N]); }while(0)
- #define TMC_SET_PWMTHRS_E(E) do{ const uint8_t extruder = E; tmc_set_pwmthrs(stepperE##E, TMC_E##E, value, planner.axis_steps_per_mm[E_AXIS_N]); }while(0)
+ #define TMC_SET_PWMTHRS_E(E) do{ const uint8_t extruder = E; tmc_set_pwmthrs(stepperE##E, value, planner.axis_steps_per_mm[E_AXIS_N]); }while(0)
bool report = true;
const uint8_t index = parser.byteval('I');
@@ -11081,66 +11277,78 @@ inline void gcode_M502() {
#if ENABLED(SENSORLESS_HOMING)
inline void gcode_M914() {
#define TMC_SAY_SGT(Q) tmc_get_sgt(stepper##Q, TMC_##Q)
- #define TMC_SET_SGT(Q) tmc_set_sgt(stepper##Q, TMC_##Q, value)
+ #define TMC_SET_SGT(Q) tmc_set_sgt(stepper##Q, value)
bool report = true;
const uint8_t index = parser.byteval('I');
LOOP_XYZ(i) if (parser.seen(axis_codes[i])) {
- const int8_t value = (int8_t)constrain(parser.value_int(), -63, 64);
+ const int8_t value = (int8_t)constrain(parser.value_int(), -64, 63);
report = false;
switch (i) {
- case X_AXIS:
- #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
- if (index == 0) TMC_SET_SGT(X);
- #endif
- #if ENABLED(X2_IS_TMC2130)
- if (index == 1) TMC_SET_SGT(X2);
- #endif
- break;
- case Y_AXIS:
- #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
- if (index == 0) TMC_SET_SGT(Y);
- #endif
- #if ENABLED(Y2_IS_TMC2130)
- if (index == 1) TMC_SET_SGT(Y2);
- #endif
- break;
- case Z_AXIS:
- #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
- if (index == 0) TMC_SET_SGT(Z);
- #endif
- #if ENABLED(Z2_IS_TMC2130)
- if (index == 1) TMC_SET_SGT(Z2);
- #endif
- break;
+ #if X_SENSORLESS
+ case X_AXIS:
+ #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
+ if (index == 0) TMC_SET_SGT(X);
+ #endif
+ #if ENABLED(X2_IS_TMC2130)
+ if (index == 1) TMC_SET_SGT(X2);
+ #endif
+ break;
+ #endif
+ #if Y_SENSORLESS
+ case Y_AXIS:
+ #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
+ if (index == 0) TMC_SET_SGT(Y);
+ #endif
+ #if ENABLED(Y2_IS_TMC2130)
+ if (index == 1) TMC_SET_SGT(Y2);
+ #endif
+ break;
+ #endif
+ #if Z_SENSORLESS
+ case Z_AXIS:
+ #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
+ if (index == 0) TMC_SET_SGT(Z);
+ #endif
+ #if ENABLED(Z2_IS_TMC2130)
+ if (index == 1) TMC_SET_SGT(Z2);
+ #endif
+ break;
+ #endif
}
}
if (report) LOOP_XYZ(i) switch (i) {
- case X_AXIS:
- #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
- TMC_SAY_SGT(X);
- #endif
- #if ENABLED(X2_IS_TMC2130)
- TMC_SAY_SGT(X2);
- #endif
- break;
- case Y_AXIS:
- #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
- TMC_SAY_SGT(Y);
- #endif
- #if ENABLED(Y2_IS_TMC2130)
- TMC_SAY_SGT(Y2);
- #endif
- break;
- case Z_AXIS:
- #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
- TMC_SAY_SGT(Z);
- #endif
- #if ENABLED(Z2_IS_TMC2130)
- TMC_SAY_SGT(Z2);
- #endif
- break;
+ #if X_SENSORLESS
+ case X_AXIS:
+ #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
+ TMC_SAY_SGT(X);
+ #endif
+ #if ENABLED(X2_IS_TMC2130)
+ TMC_SAY_SGT(X2);
+ #endif
+ break;
+ #endif
+ #if Y_SENSORLESS
+ case Y_AXIS:
+ #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
+ TMC_SAY_SGT(Y);
+ #endif
+ #if ENABLED(Y2_IS_TMC2130)
+ TMC_SAY_SGT(Y2);
+ #endif
+ break;
+ #endif
+ #if Z_SENSORLESS
+ case Z_AXIS:
+ #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
+ TMC_SAY_SGT(Z);
+ #endif
+ #if ENABLED(Z2_IS_TMC2130)
+ TMC_SAY_SGT(Z2);
+ #endif
+ break;
+ #endif
}
}
#endif // SENSORLESS_HOMING
@@ -11153,7 +11361,7 @@ inline void gcode_M502() {
const uint16_t _rms = parser.seenval('S') ? parser.value_int() : CALIBRATION_CURRENT,
_z = parser.seenval('Z') ? parser.value_linear_units() : CALIBRATION_EXTRA_HEIGHT;
- if (!axis_known_position[Z_AXIS]) {
+ if (!TEST(axis_known_position, Z_AXIS)) {
SERIAL_ECHOLNPGM("\nPlease home Z axis first");
return;
}
@@ -11444,7 +11652,7 @@ inline void gcode_M999() {
flush_and_request_resend();
}
-#if ENABLED(SWITCHING_EXTRUDER)
+#if DO_SWITCH_EXTRUDER
#if EXTRUDERS > 3
#define REQ_ANGLES 4
#define _SERVO_NR (e < 2 ? SWITCHING_EXTRUDER_SERVO_NR : SWITCHING_EXTRUDER_E23_SERVO_NR)
@@ -11455,7 +11663,7 @@ inline void gcode_M999() {
inline void move_extruder_servo(const uint8_t e) {
constexpr int16_t angles[] = SWITCHING_EXTRUDER_SERVO_ANGLES;
static_assert(COUNT(angles) == REQ_ANGLES, "SWITCHING_EXTRUDER_SERVO_ANGLES needs " STRINGIFY(REQ_ANGLES) " angles.");
- stepper.synchronize();
+ planner.synchronize();
#if EXTRUDERS & 1
if (e < EXTRUDERS - 1)
#endif
@@ -11464,12 +11672,12 @@ inline void gcode_M999() {
safe_delay(500);
}
}
-#endif // SWITCHING_EXTRUDER
+#endif // DO_SWITCH_EXTRUDER
#if ENABLED(SWITCHING_NOZZLE)
inline void move_nozzle_servo(const uint8_t e) {
const int16_t angles[2] = SWITCHING_NOZZLE_SERVO_ANGLES;
- stepper.synchronize();
+ planner.synchronize();
MOVE_SERVO(SWITCHING_NOZZLE_SERVO_NR, angles[e]);
safe_delay(500);
}
@@ -11588,7 +11796,7 @@ inline void invalid_extruder_error(const uint8_t e) {
planner.max_feedrate_mm_s[i == 1 ? X_AXIS : Z_AXIS],
active_extruder
);
- stepper.synchronize();
+ planner.synchronize();
}
// Apply Y & Z extruder offset (X offset is used as home pos with Dual X)
@@ -11686,7 +11894,7 @@ inline void invalid_extruder_error(const uint8_t e) {
if (DEBUGGING(LEVELING)) DEBUG_POS("Moving to Raised Z-Position", current_position);
#endif
planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
- stepper.synchronize();
+ planner.synchronize();
// STEP 2
current_position[X_AXIS] = parkingposx[active_extruder] + hotend_offset[X_AXIS][active_extruder];
@@ -11695,7 +11903,7 @@ inline void invalid_extruder_error(const uint8_t e) {
if (DEBUGGING(LEVELING)) DEBUG_POS("Moving ParkPos", current_position);
#endif
planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
- stepper.synchronize();
+ planner.synchronize();
// STEP 3
#if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -11713,7 +11921,7 @@ inline void invalid_extruder_error(const uint8_t e) {
if (DEBUGGING(LEVELING)) DEBUG_POS("Moving away from parked extruder", current_position);
#endif
planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
- stepper.synchronize();
+ planner.synchronize();
// STEP 5
#if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -11734,7 +11942,7 @@ inline void invalid_extruder_error(const uint8_t e) {
if (DEBUGGING(LEVELING)) DEBUG_POS("Move UnparkPos", current_position);
#endif
planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS]/2, active_extruder);
- stepper.synchronize();
+ planner.synchronize();
// Step 7
current_position[X_AXIS] = midpos - hotend_offset[X_AXIS][tmp_extruder];
@@ -11743,7 +11951,7 @@ inline void invalid_extruder_error(const uint8_t e) {
if (DEBUGGING(LEVELING)) DEBUG_POS("Move midway to new extruder", current_position);
#endif
planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[X_AXIS], active_extruder);
- stepper.synchronize();
+ planner.synchronize();
#if ENABLED(DEBUG_LEVELING_FEATURE)
SERIAL_ECHOLNPGM("Autopark done.");
#endif
@@ -11871,6 +12079,9 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#endif
// Move back to the original (or tweaked) position
do_blocking_move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS]);
+ #if ENABLED(DUAL_X_CARRIAGE)
+ active_extruder_parked = false;
+ #endif
}
#if ENABLED(SWITCHING_NOZZLE)
else {
@@ -11880,7 +12091,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#endif
} // (tmp_extruder != active_extruder)
- stepper.synchronize();
+ planner.synchronize();
#if ENABLED(EXT_SOLENOID) && !ENABLED(PARKING_EXTRUDER)
disable_all_solenoids();
@@ -11907,7 +12118,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#endif // HOTENDS <= 1
#if DO_SWITCH_EXTRUDER
- stepper.synchronize();
+ planner.synchronize();
move_extruder_servo(active_extruder);
#endif
@@ -12052,6 +12263,8 @@ void process_parsed_command() {
#if ENABLED(DEBUG_GCODE_PARSER)
case 800: parser.debug(); break; // G800: GCode Parser Test for G
#endif
+
+ default: parser.unknown_command_error();
}
break;
@@ -12351,6 +12564,10 @@ void process_parsed_command() {
case 702: gcode_M702(); break; // M702: Unload Filament
#endif
+ #if ENABLED(MAX7219_GCODE)
+ case 7219: gcode_M7219(); break; // M7219: Set LEDs, columns, and rows
+ #endif
+
#if ENABLED(DEBUG_GCODE_PARSER)
case 800: parser.debug(); break; // M800: GCode Parser Test for M
#endif
@@ -12409,6 +12626,8 @@ void process_parsed_command() {
#endif
case 999: gcode_M999(); break; // M999: Restart after being Stopped
+
+ default: parser.unknown_command_error();
}
break;
@@ -12433,8 +12652,6 @@ void process_next_command() {
#endif
}
- reset_stepper_timeout(); // Keep steppers powered
-
// Parse the next command in the queue
parser.parse(current_command);
process_parsed_command();
@@ -12555,7 +12772,7 @@ void ok_to_send() {
#endif
gridx = gx;
- nextx = min(gridx + 1, ABL_BG_POINTS_X - 1);
+ nextx = MIN(gridx + 1, ABL_BG_POINTS_X - 1);
}
if (last_y != ry || last_gridx != gridx) {
@@ -12572,7 +12789,7 @@ void ok_to_send() {
#endif
gridy = gy;
- nexty = min(gridy + 1, ABL_BG_POINTS_Y - 1);
+ nexty = MIN(gridy + 1, ABL_BG_POINTS_Y - 1);
}
if (last_gridx != gridx || last_gridy != gridy) {
@@ -12596,7 +12813,7 @@ void ok_to_send() {
/*
static float last_offset = 0;
- if (FABS(last_offset - offset) > 0.2) {
+ if (ABS(last_offset - offset) > 0.2) {
SERIAL_ECHOPGM("Sudden Shift at ");
SERIAL_ECHOPAIR("x=", rx);
SERIAL_ECHOPAIR(" / ", bilinear_grid_spacing[X_AXIS]);
@@ -12641,30 +12858,9 @@ void ok_to_send() {
delta_diagonal_rod_2_tower[B_AXIS] = sq(delta_diagonal_rod + drt[B_AXIS]);
delta_diagonal_rod_2_tower[C_AXIS] = sq(delta_diagonal_rod + drt[C_AXIS]);
update_software_endstops(Z_AXIS);
- axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
+ axis_homed = 0;
}
- #if ENABLED(DELTA_FAST_SQRT)
- /**
- * Fast inverse sqrt from Quake III Arena
- * See: https://en.wikipedia.org/wiki/Fast_inverse_square_root
- */
- float Q_rsqrt(const float number) {
- long i;
- float x2, y;
- const float threehalfs = 1.5f;
- x2 = number * 0.5f;
- y = number;
- i = * ( long * ) &y; // evil floating point bit level hacking
- i = 0x5F3759DF - ( i >> 1 ); // what the f***?
- y = * ( float * ) &i;
- y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
- // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
- return y;
- }
-
- #endif
-
/**
* Delta Inverse Kinematics
*
@@ -12679,9 +12875,6 @@ void ok_to_send() {
*
* - Disable the home_offset (M206) and/or position_shift (G92)
* features to remove up to 12 float additions.
- *
- * - Use a fast-inverse-sqrt function and add the reciprocal.
- * (see above)
*/
#define DELTA_DEBUG(VAR) do { \
@@ -12719,7 +12912,7 @@ void ok_to_send() {
const float centered_extent = delta[A_AXIS];
cartesian[Y_AXIS] = DELTA_PRINTABLE_RADIUS;
inverse_kinematics(cartesian);
- return FABS(centered_extent - delta[A_AXIS]);
+ return ABS(centered_extent - delta[A_AXIS]);
}
/**
@@ -12747,7 +12940,7 @@ void ok_to_send() {
*
* The result is stored in the cartes[] array.
*/
- void forward_kinematics_DELTA(float z1, float z2, float z3) {
+ void forward_kinematics_DELTA(const float &z1, const float &z2, const float &z3) {
// Create a vector in old coordinates along x axis of new coordinate
const float p12[] = {
delta_tower[B_AXIS][X_AXIS] - delta_tower[A_AXIS][X_AXIS],
@@ -12755,11 +12948,11 @@ void ok_to_send() {
z2 - z1
},
- // Get the Magnitude of vector.
- d = SQRT(sq(p12[0]) + sq(p12[1]) + sq(p12[2])),
+ // Get the reciprocal of Magnitude of vector.
+ d2 = sq(p12[0]) + sq(p12[1]) + sq(p12[2]), inv_d = RSQRT(d2),
- // Create unit vector by dividing by magnitude.
- ex[3] = { p12[0] / d, p12[1] / d, p12[2] / d },
+ // Create unit vector by multiplying by the inverse of the magnitude.
+ ex[3] = { p12[0] * inv_d, p12[1] * inv_d, p12[2] * inv_d },
// Get the vector from the origin of the new system to the third point.
p13[3] = {
@@ -12778,11 +12971,11 @@ void ok_to_send() {
// variable that will be the unit vector after we scale it.
float ey[3] = { p13[0] - iex[0], p13[1] - iex[1], p13[2] - iex[2] };
- // The magnitude of Y component
- const float j = SQRT(sq(ey[0]) + sq(ey[1]) + sq(ey[2]));
+ // The magnitude and the inverse of the magnitude of Y component
+ const float j2 = sq(ey[0]) + sq(ey[1]) + sq(ey[2]), inv_j = RSQRT(j2);
// Convert to a unit vector
- ey[0] /= j; ey[1] /= j; ey[2] /= j;
+ ey[0] *= inv_j; ey[1] *= inv_j; ey[2] *= inv_j;
// The cross product of the unit x and y is the unit z
// float[] ez = vectorCrossProd(ex, ey);
@@ -12793,8 +12986,8 @@ void ok_to_send() {
},
// We now have the d, i and j values defined in Wikipedia.
// Plug them into the equations defined in Wikipedia for Xnew, Ynew and Znew
- Xnew = (delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[B_AXIS] + sq(d)) / (d * 2),
- Ynew = ((delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[C_AXIS] + HYPOT2(i, j)) / 2 - i * Xnew) / j,
+ Xnew = (delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[B_AXIS] + d2) * inv_d * 0.5,
+ Ynew = ((delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[C_AXIS] + sq(i) + j2) * 0.5 - i * Xnew) * inv_j,
Znew = SQRT(delta_diagonal_rod_2_tower[A_AXIS] - HYPOT2(Xnew, Ynew));
// Start from the origin of the old coordinates and add vectors in the
@@ -12802,10 +12995,10 @@ void ok_to_send() {
// in the old system.
cartes[X_AXIS] = delta_tower[A_AXIS][X_AXIS] + ex[0] * Xnew + ey[0] * Ynew - ez[0] * Znew;
cartes[Y_AXIS] = delta_tower[A_AXIS][Y_AXIS] + ex[1] * Xnew + ey[1] * Ynew - ez[1] * Znew;
- cartes[Z_AXIS] = z1 + ex[2] * Xnew + ey[2] * Ynew - ez[2] * Znew;
+ cartes[Z_AXIS] = z1 + ex[2] * Xnew + ey[2] * Ynew - ez[2] * Znew;
}
- void forward_kinematics_DELTA(float point[ABC]) {
+ void forward_kinematics_DELTA(const float (&point)[ABC]) {
forward_kinematics_DELTA(point[A_AXIS], point[B_AXIS], point[C_AXIS]);
}
@@ -12823,21 +13016,21 @@ void ok_to_send() {
void get_cartesian_from_steppers() {
#if ENABLED(DELTA)
forward_kinematics_DELTA(
- stepper.get_axis_position_mm(A_AXIS),
- stepper.get_axis_position_mm(B_AXIS),
- stepper.get_axis_position_mm(C_AXIS)
+ planner.get_axis_position_mm(A_AXIS),
+ planner.get_axis_position_mm(B_AXIS),
+ planner.get_axis_position_mm(C_AXIS)
);
#else
#if IS_SCARA
forward_kinematics_SCARA(
- stepper.get_axis_position_degrees(A_AXIS),
- stepper.get_axis_position_degrees(B_AXIS)
+ planner.get_axis_position_degrees(A_AXIS),
+ planner.get_axis_position_degrees(B_AXIS)
);
#else
- cartes[X_AXIS] = stepper.get_axis_position_mm(X_AXIS);
- cartes[Y_AXIS] = stepper.get_axis_position_mm(Y_AXIS);
+ cartes[X_AXIS] = planner.get_axis_position_mm(X_AXIS);
+ cartes[Y_AXIS] = planner.get_axis_position_mm(Y_AXIS);
#endif
- cartes[Z_AXIS] = stepper.get_axis_position_mm(Z_AXIS);
+ cartes[Z_AXIS] = planner.get_axis_position_mm(Z_AXIS);
#endif
}
@@ -12892,7 +13085,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
// If the move is very short, check the E move distance
// No E move either? Game over.
float cartesian_mm = SQRT(sq(xdiff) + sq(ydiff) + sq(zdiff));
- if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = FABS(ediff);
+ if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = ABS(ediff);
if (UNEAR_ZERO(cartesian_mm)) return;
// The length divided by the segment size
@@ -12901,7 +13094,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
NOLESS(segments, 1);
// The approximate length of each segment
- const float inv_segments = 1.0 / float(segments),
+ const float inv_segments = 1.0f / float(segments),
cartesian_segment_mm = cartesian_mm * inv_segments,
segment_distance[XYZE] = {
xdiff * inv_segments,
@@ -12927,7 +13120,8 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
idle();
}
LOOP_XYZE(i) raw[i] += segment_distance[i];
- planner.buffer_line_kinematic(raw, fr_mm_s, active_extruder, cartesian_segment_mm);
+ if (!planner.buffer_line_kinematic(raw, fr_mm_s, active_extruder, cartesian_segment_mm))
+ break;
}
// Since segment_distance is only approximate,
@@ -12959,10 +13153,10 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
return;
}
- #define MBL_SEGMENT_END(A) (current_position[A ##_AXIS] + (destination[A ##_AXIS] - current_position[A ##_AXIS]) * normalized_dist)
+ #define MBL_SEGMENT_END(A) (current_position[_AXIS(A)] + (destination[_AXIS(A)] - current_position[_AXIS(A)]) * normalized_dist)
float normalized_dist, end[XYZE];
- const int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
+ const int8_t gcx = MAX(cx1, cx2), gcy = MAX(cy1, cy2);
// Crosses on the X and not already split on this X?
// The x_splits flags are insurance against rounding errors.
@@ -13003,7 +13197,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
- #define CELL_INDEX(A,V) ((V - bilinear_start[A##_AXIS]) * ABL_BG_FACTOR(A##_AXIS))
+ #define CELL_INDEX(A,V) ((V - bilinear_start[_AXIS(A)]) * ABL_BG_FACTOR(_AXIS(A)))
/**
* Prepare a bilinear-leveled linear move on Cartesian,
@@ -13027,10 +13221,10 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
return;
}
- #define LINE_SEGMENT_END(A) (current_position[A ##_AXIS] + (destination[A ##_AXIS] - current_position[A ##_AXIS]) * normalized_dist)
+ #define LINE_SEGMENT_END(A) (current_position[_AXIS(A)] + (destination[_AXIS(A)] - current_position[_AXIS(A)]) * normalized_dist)
float normalized_dist, end[XYZE];
- const int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
+ const int8_t gcx = MAX(cx1, cx2), gcy = MAX(cy1, cy2);
// Crosses on the X and not already split on this X?
// The x_splits flags are insurance against rounding errors.
@@ -13086,7 +13280,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
* but may produce jagged lines. Try 0.5mm, 1.0mm, and 2.0mm
* and compare the difference.
*/
- #define SCARA_MIN_SEGMENT_LENGTH 0.5
+ #define SCARA_MIN_SEGMENT_LENGTH 0.5f
#endif
/**
@@ -13123,7 +13317,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
// If the move is very short, check the E move distance
// No E move either? Game over.
float cartesian_mm = SQRT(sq(xdiff) + sq(ydiff) + sq(zdiff));
- if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = FABS(ediff);
+ if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = ABS(ediff);
if (UNEAR_ZERO(cartesian_mm)) return true;
// Minimum number of seconds to move the given distance
@@ -13135,14 +13329,14 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
// For SCARA enforce a minimum segment size
#if IS_SCARA
- NOMORE(segments, cartesian_mm * (1.0 / SCARA_MIN_SEGMENT_LENGTH));
+ NOMORE(segments, cartesian_mm * (1.0f / float(SCARA_MIN_SEGMENT_LENGTH)));
#endif
// At least one segment is required
NOLESS(segments, 1);
// The approximate length of each segment
- const float inv_segments = 1.0 / float(segments),
+ const float inv_segments = 1.0f / float(segments),
segment_distance[XYZE] = {
xdiff * inv_segments,
ydiff * inv_segments,
@@ -13150,7 +13344,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
ediff * inv_segments
};
- #if DISABLED(SCARA_FEEDRATE_SCALING)
+ #if !HAS_FEEDRATE_SCALING
const float cartesian_segment_mm = cartesian_mm * inv_segments;
#endif
@@ -13158,22 +13352,25 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
SERIAL_ECHOPAIR("mm=", cartesian_mm);
SERIAL_ECHOPAIR(" seconds=", seconds);
SERIAL_ECHOPAIR(" segments=", segments);
- #if DISABLED(SCARA_FEEDRATE_SCALING)
- SERIAL_ECHOLNPAIR(" segment_mm=", cartesian_segment_mm);
- #else
- SERIAL_EOL();
+ #if !HAS_FEEDRATE_SCALING
+ SERIAL_ECHOPAIR(" segment_mm=", cartesian_segment_mm);
#endif
+ SERIAL_EOL();
//*/
- #if ENABLED(SCARA_FEEDRATE_SCALING)
+ #if HAS_FEEDRATE_SCALING
// SCARA needs to scale the feed rate from mm/s to degrees/s
// i.e., Complete the angular vector in the given time.
const float segment_length = cartesian_mm * inv_segments,
- inv_segment_length = 1.0 / segment_length, // 1/mm/segs
+ inv_segment_length = 1.0f / segment_length, // 1/mm/segs
inverse_secs = inv_segment_length * _feedrate_mm_s;
float oldA = planner.position_float[A_AXIS],
- oldB = planner.position_float[B_AXIS];
+ oldB = planner.position_float[B_AXIS]
+ #if ENABLED(DELTA_FEEDRATE_SCALING)
+ , oldC = planner.position_float[C_AXIS]
+ #endif
+ ;
/*
SERIAL_ECHOPGM("Scaled kinematic move: ");
@@ -13182,7 +13379,11 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
SERIAL_ECHOPAIR(") _feedrate_mm_s=", _feedrate_mm_s);
SERIAL_ECHOPAIR(" inverse_secs=", inverse_secs);
SERIAL_ECHOPAIR(" oldA=", oldA);
- SERIAL_ECHOLNPAIR(" oldB=", oldB);
+ SERIAL_ECHOPAIR(" oldB=", oldB);
+ #if ENABLED(DELTA_FEEDRATE_SCALING)
+ SERIAL_ECHOPAIR(" oldC=", oldC);
+ #endif
+ SERIAL_EOL();
safe_delay(5);
//*/
#endif
@@ -13213,7 +13414,8 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
#if ENABLED(SCARA_FEEDRATE_SCALING)
// For SCARA scale the feed rate from mm/s to degrees/s
// i.e., Complete the angular vector in the given time.
- planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], raw[Z_AXIS], raw[E_AXIS], HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs, active_extruder);
+ if (!planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], raw[Z_AXIS], raw[E_AXIS], HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs, active_extruder))
+ break;
/*
SERIAL_ECHO(segments);
SERIAL_ECHOPAIR(": X=", raw[X_AXIS]); SERIAL_ECHOPAIR(" Y=", raw[Y_AXIS]);
@@ -13222,22 +13424,51 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
safe_delay(5);
//*/
oldA = delta[A_AXIS]; oldB = delta[B_AXIS];
+ #elif ENABLED(DELTA_FEEDRATE_SCALING)
+ // For DELTA scale the feed rate from Effector mm/s to Carriage mm/s
+ // i.e., Complete the linear vector in the given time.
+ if (!planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], SQRT(sq(delta[A_AXIS] - oldA) + sq(delta[B_AXIS] - oldB) + sq(delta[C_AXIS] - oldC)) * inverse_secs, active_extruder))
+ break;
+ /*
+ SERIAL_ECHO(segments);
+ SERIAL_ECHOPAIR(": X=", raw[X_AXIS]); SERIAL_ECHOPAIR(" Y=", raw[Y_AXIS]);
+ SERIAL_ECHOPAIR(" A=", delta[A_AXIS]); SERIAL_ECHOPAIR(" B=", delta[B_AXIS]); SERIAL_ECHOPAIR(" C=", delta[C_AXIS]);
+ SERIAL_ECHOLNPAIR(" F", SQRT(sq(delta[A_AXIS] - oldA) + sq(delta[B_AXIS] - oldB) + sq(delta[C_AXIS] - oldC)) * inverse_secs * 60);
+ safe_delay(5);
+ //*/
+ oldA = delta[A_AXIS]; oldB = delta[B_AXIS]; oldC = delta[C_AXIS];
#else
- planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], _feedrate_mm_s, active_extruder, cartesian_segment_mm);
+ if (!planner.buffer_line(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], _feedrate_mm_s, active_extruder, cartesian_segment_mm))
+ break;
#endif
}
// Ensure last segment arrives at target location.
- #if ENABLED(SCARA_FEEDRATE_SCALING)
+ #if HAS_FEEDRATE_SCALING
inverse_kinematics(rtarget);
ADJUST_DELTA(rtarget);
+ #endif
+
+ #if ENABLED(SCARA_FEEDRATE_SCALING)
const float diff2 = HYPOT2(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB);
if (diff2) {
planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], rtarget[Z_AXIS], rtarget[E_AXIS], SQRT(diff2) * inverse_secs, active_extruder);
/*
SERIAL_ECHOPAIR("final: A=", delta[A_AXIS]); SERIAL_ECHOPAIR(" B=", delta[B_AXIS]);
SERIAL_ECHOPAIR(" adiff=", delta[A_AXIS] - oldA); SERIAL_ECHOPAIR(" bdiff=", delta[B_AXIS] - oldB);
- SERIAL_ECHOLNPAIR(" F", (SQRT(diff2) * inverse_secs) * 60);
+ SERIAL_ECHOLNPAIR(" F", SQRT(diff2) * inverse_secs * 60);
+ SERIAL_EOL();
+ safe_delay(5);
+ //*/
+ }
+ #elif ENABLED(DELTA_FEEDRATE_SCALING)
+ const float diff2 = sq(delta[A_AXIS] - oldA) + sq(delta[B_AXIS] - oldB) + sq(delta[C_AXIS] - oldC);
+ if (diff2) {
+ planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], rtarget[E_AXIS], SQRT(diff2) * inverse_secs, active_extruder);
+ /*
+ SERIAL_ECHOPAIR("final: A=", delta[A_AXIS]); SERIAL_ECHOPAIR(" B=", delta[B_AXIS]); SERIAL_ECHOPAIR(" C=", delta[C_AXIS]);
+ SERIAL_ECHOPAIR(" adiff=", delta[A_AXIS] - oldA); SERIAL_ECHOPAIR(" bdiff=", delta[B_AXIS] - oldB); SERIAL_ECHOPAIR(" cdiff=", delta[C_AXIS] - oldC);
+ SERIAL_ECHOLNPAIR(" F", SQRT(diff2) * inverse_secs * 60);
SERIAL_EOL();
safe_delay(5);
//*/
@@ -13317,14 +13548,14 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
}
// unpark extruder: 1) raise, 2) move into starting XY position, 3) lower
for (uint8_t i = 0; i < 3; i++)
- planner.buffer_line(
+ if (!planner.buffer_line(
i == 0 ? raised_parked_position[X_AXIS] : current_position[X_AXIS],
i == 0 ? raised_parked_position[Y_AXIS] : current_position[Y_AXIS],
i == 2 ? current_position[Z_AXIS] : raised_parked_position[Z_AXIS],
current_position[E_AXIS],
i == 1 ? PLANNER_XY_FEEDRATE() : planner.max_feedrate_mm_s[Z_AXIS],
- active_extruder
- );
+ active_extruder)
+ ) break;
delayed_move_time = 0;
active_extruder_parked = false;
#if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -13341,19 +13572,14 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
}
#endif
// move duplicate extruder into correct duplication position.
- planner.set_position_mm(
- inactive_extruder_x_pos,
- current_position[Y_AXIS],
- current_position[Z_AXIS],
- current_position[E_AXIS]
- );
- planner.buffer_line(
+ planner.set_position_mm(inactive_extruder_x_pos, current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
+ if (!planner.buffer_line(
current_position[X_AXIS] + duplicate_extruder_x_offset,
current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS],
- planner.max_feedrate_mm_s[X_AXIS], 1
- );
+ planner.max_feedrate_mm_s[X_AXIS], 1)
+ ) break;
+ planner.synchronize();
SYNC_PLAN_POSITION_KINEMATIC();
- stepper.synchronize();
extruder_duplication_enabled = true;
active_extruder_parked = false;
#if ENABLED(DEBUG_LEVELING_FEATURE)
@@ -13396,7 +13622,7 @@ void prepare_move_to_destination() {
}
#endif // PREVENT_COLD_EXTRUSION
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
- if (FABS(destination[E_AXIS] - current_position[E_AXIS]) * planner.e_factor[active_extruder] > (EXTRUDE_MAXLENGTH)) {
+ if (ABS(destination[E_AXIS] - current_position[E_AXIS]) * planner.e_factor[active_extruder] > (EXTRUDE_MAXLENGTH)) {
current_position[E_AXIS] = destination[E_AXIS]; // Behave as if the move really took place, but ignore E part
SERIAL_ECHO_START();
SERIAL_ECHOLNPGM(MSG_ERR_LONG_EXTRUDE_STOP);
@@ -13478,8 +13704,8 @@ void prepare_move_to_destination() {
angular_travel = RADIANS(360);
const float flat_mm = radius * angular_travel,
- mm_of_travel = linear_travel ? HYPOT(flat_mm, linear_travel) : FABS(flat_mm);
- if (mm_of_travel < 0.001) return;
+ mm_of_travel = linear_travel ? HYPOT(flat_mm, linear_travel) : ABS(flat_mm);
+ if (mm_of_travel < 0.001f) return;
uint16_t segments = FLOOR(mm_of_travel / (MM_PER_ARC_SEGMENT));
NOLESS(segments, 1);
@@ -13516,7 +13742,7 @@ void prepare_move_to_destination() {
linear_per_segment = linear_travel / segments,
extruder_per_segment = extruder_travel / segments,
sin_T = theta_per_segment,
- cos_T = 1 - 0.5 * sq(theta_per_segment); // Small angle approximation
+ cos_T = 1 - 0.5f * sq(theta_per_segment); // Small angle approximation
// Initialize the linear axis
raw[l_axis] = current_position[l_axis];
@@ -13528,12 +13754,16 @@ void prepare_move_to_destination() {
millis_t next_idle_ms = millis() + 200UL;
- #if ENABLED(SCARA_FEEDRATE_SCALING)
+ #if HAS_FEEDRATE_SCALING
// SCARA needs to scale the feed rate from mm/s to degrees/s
- const float inv_segment_length = 1.0 / (MM_PER_ARC_SEGMENT),
+ const float inv_segment_length = 1.0f / (MM_PER_ARC_SEGMENT),
inverse_secs = inv_segment_length * fr_mm_s;
float oldA = planner.position_float[A_AXIS],
- oldB = planner.position_float[B_AXIS];
+ oldB = planner.position_float[B_AXIS]
+ #if ENABLED(DELTA_FEEDRATE_SCALING)
+ , oldC = planner.position_float[C_AXIS]
+ #endif
+ ;
#endif
#if N_ARC_CORRECTION > 1
@@ -13579,46 +13809,66 @@ void prepare_move_to_destination() {
clamp_to_software_endstops(raw);
+ #if HAS_FEEDRATE_SCALING
+ inverse_kinematics(raw);
+ ADJUST_DELTA(raw);
+ #endif
+
#if ENABLED(SCARA_FEEDRATE_SCALING)
// For SCARA scale the feed rate from mm/s to degrees/s
// i.e., Complete the angular vector in the given time.
- inverse_kinematics(raw);
- ADJUST_DELTA(raw);
- planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], raw[Z_AXIS], raw[E_AXIS], HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs, active_extruder);
+ if (!planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], raw[Z_AXIS], raw[E_AXIS], HYPOT(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB) * inverse_secs, active_extruder))
+ break;
oldA = delta[A_AXIS]; oldB = delta[B_AXIS];
+ #elif ENABLED(DELTA_FEEDRATE_SCALING)
+ // For DELTA scale the feed rate from Effector mm/s to Carriage mm/s
+ // i.e., Complete the linear vector in the given time.
+ if (!planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], raw[E_AXIS], SQRT(sq(delta[A_AXIS] - oldA) + sq(delta[B_AXIS] - oldB) + sq(delta[C_AXIS] - oldC)) * inverse_secs, active_extruder))
+ break;
+ oldA = delta[A_AXIS]; oldB = delta[B_AXIS]; oldC = delta[C_AXIS];
+ #elif HAS_UBL_AND_CURVES
+ float pos[XYZ] = { raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS] };
+ planner.apply_leveling(pos);
+ if (!planner.buffer_segment(pos[X_AXIS], pos[Y_AXIS], pos[Z_AXIS], raw[E_AXIS], fr_mm_s, active_extruder))
+ break;
#else
- planner.buffer_line_kinematic(raw, fr_mm_s, active_extruder);
+ if (!planner.buffer_line_kinematic(raw, fr_mm_s, active_extruder))
+ break;
#endif
}
// Ensure last segment arrives at target location.
- #if ENABLED(SCARA_FEEDRATE_SCALING)
+ #if HAS_FEEDRATE_SCALING
inverse_kinematics(cart);
ADJUST_DELTA(cart);
+ #endif
+
+ #if ENABLED(SCARA_FEEDRATE_SCALING)
const float diff2 = HYPOT2(delta[A_AXIS] - oldA, delta[B_AXIS] - oldB);
if (diff2)
planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], cart[Z_AXIS], cart[E_AXIS], SQRT(diff2) * inverse_secs, active_extruder);
+ #elif ENABLED(DELTA_FEEDRATE_SCALING)
+ const float diff2 = sq(delta[A_AXIS] - oldA) + sq(delta[B_AXIS] - oldB) + sq(delta[C_AXIS] - oldC);
+ if (diff2)
+ planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], cart[E_AXIS], SQRT(diff2) * inverse_secs, active_extruder);
+ #elif HAS_UBL_AND_CURVES
+ float pos[XYZ] = { cart[X_AXIS], cart[Y_AXIS], cart[Z_AXIS] };
+ planner.apply_leveling(pos);
+ planner.buffer_segment(pos[X_AXIS], pos[Y_AXIS], pos[Z_AXIS], cart[E_AXIS], fr_mm_s, active_extruder);
#else
planner.buffer_line_kinematic(cart, fr_mm_s, active_extruder);
#endif
- // As far as the parser is concerned, the position is now == target. In reality the
- // motion control system might still be processing the action and the real tool position
- // in any intermediate location.
- set_current_from_destination();
+ COPY(current_position, cart);
} // plan_arc
#endif // ARC_SUPPORT
#if ENABLED(BEZIER_CURVE_SUPPORT)
- void plan_cubic_move(const float (&offset)[4]) {
- cubic_b_spline(current_position, destination, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
-
- // As far as the parser is concerned, the position is now == destination. In reality the
- // motion control system might still be processing the action and the real tool position
- // in any intermediate location.
- set_current_from_destination();
+ void plan_cubic_move(const float (&cart)[XYZE], const float (&offset)[4]) {
+ cubic_b_spline(current_position, cart, offset, MMS_SCALED(feedrate_mm_s), active_extruder);
+ COPY(current_position, cart);
}
#endif // BEZIER_CURVE_SUPPORT
@@ -13631,7 +13881,10 @@ void prepare_move_to_destination() {
const millis_t ms = millis();
if (ELAPSED(ms, nextMotorCheck)) {
nextMotorCheck = ms + 2500UL; // Not a time critical function, so only check every 2.5s
- if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON || thermalManager.soft_pwm_amount_bed > 0
+ if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON
+ #if HAS_HEATED_BED
+ || thermalManager.soft_pwm_amount_bed > 0
+ #endif
|| E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
#if E_STEPPERS > 1
|| E1_ENABLE_READ == E_ENABLE_ON
@@ -13932,8 +14185,16 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
&& !planner.has_blocks_queued()
) {
#if ENABLED(SWITCHING_EXTRUDER)
- const bool oldstatus = E0_ENABLE_READ;
- enable_E0();
+ bool oldstatus;
+ switch (active_extruder) {
+ default: oldstatus = E0_ENABLE_READ; enable_E0(); break;
+ #if E_STEPPERS > 1
+ case 2: case 3: oldstatus = E1_ENABLE_READ; enable_E1(); break;
+ #if E_STEPPERS > 2
+ case 4: oldstatus = E2_ENABLE_READ; enable_E2(); break;
+ #endif // E_STEPPERS > 2
+ #endif // E_STEPPERS > 1
+ }
#else // !SWITCHING_EXTRUDER
bool oldstatus;
switch (active_extruder) {
@@ -13958,10 +14219,19 @@ void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
planner.buffer_line_kinematic(current_position, MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED), active_extruder);
current_position[E_AXIS] = olde;
planner.set_e_position_mm(olde);
- stepper.synchronize();
+ planner.synchronize();
+
#if ENABLED(SWITCHING_EXTRUDER)
- E0_ENABLE_WRITE(oldstatus);
- #else
+ switch (active_extruder) {
+ default: oldstatus = E0_ENABLE_WRITE(oldstatus); break;
+ #if E_STEPPERS > 1
+ case 2: case 3: oldstatus = E1_ENABLE_WRITE(oldstatus); break;
+ #if E_STEPPERS > 2
+ case 4: oldstatus = E2_ENABLE_WRITE(oldstatus); break;
+ #endif // E_STEPPERS > 2
+ #endif // E_STEPPERS > 1
+ }
+ #else // !SWITCHING_EXTRUDER
switch (active_extruder) {
case 0: E0_ENABLE_WRITE(oldstatus); break;
#if E_STEPPERS > 1
@@ -14014,7 +14284,7 @@ void idle(
) {
#if ENABLED(MAX7219_DEBUG)
Max7219_idle_tasks();
- #endif // MAX7219_DEBUG
+ #endif
lcd_update();
@@ -14218,7 +14488,9 @@ void setup() {
print_job_timer.init(); // Initial setup of print job timer
- stepper.init(); // Initialize stepper, this enables interrupts!
+ endstops.init(); // Init endstops and pullups
+
+ stepper.init(); // Init stepper. This enables interrupts!
servo_init(); // Initialize all servos, stow servo probe
@@ -14303,7 +14575,7 @@ void setup() {
#endif
lcd_init();
- LCD_MESSAGEPGM(WELCOME_MSG);
+ lcd_reset_status();
#if ENABLED(SHOW_BOOTSCREEN)
lcd_bootscreen();
@@ -14343,10 +14615,6 @@ void setup() {
i2c.onRequest(i2c_on_request);
#endif
- #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
- setup_endstop_interrupts();
- #endif
-
#if DO_SWITCH_EXTRUDER
move_extruder_servo(0); // Initialize extruder servo
#endif
@@ -14366,7 +14634,7 @@ void setup() {
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
- do_print_job_recovery();
+ check_print_job_recovery();
#endif
#if ENABLED(USE_WATCHDOG)
@@ -14389,7 +14657,7 @@ void loop() {
#if ENABLED(SDSUPPORT)
- card.checkautostart(false);
+ card.checkautostart();
#if ENABLED(ULTIPANEL)
if (abort_sd_printing) {
@@ -14407,6 +14675,9 @@ void loop() {
for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
#endif
wait_for_heatup = false;
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ card.removeJobRecoveryFile();
+ #endif
}
#endif
@@ -14425,15 +14696,14 @@ void loop() {
card.closefile();
SERIAL_PROTOCOLLNPGM(MSG_FILE_SAVED);
- #if !(defined(__AVR__) && defined(USBCON))
+ #if USE_MARLINSERIAL
#if ENABLED(SERIAL_STATS_DROPPED_RX)
SERIAL_ECHOLNPAIR("Dropped bytes: ", customizedSerial.dropped());
#endif
-
#if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
SERIAL_ECHOLNPAIR("Max RX Queue Size: ", customizedSerial.rxMaxEnqueued());
#endif
- #endif // !(__AVR__ && USBCON)
+ #endif
ok_to_send();
}
diff --git a/Marlin/Max7219_Debug_LEDs.cpp b/Marlin/Max7219_Debug_LEDs.cpp
index 102ec21cb7..eba1ffcd27 100644
--- a/Marlin/Max7219_Debug_LEDs.cpp
+++ b/Marlin/Max7219_Debug_LEDs.cpp
@@ -22,11 +22,9 @@
/**
* This module is off by default, but can be enabled to facilitate the display of
- * extra debug information during code development. It assumes the existence of a
- * Max7219 LED Matrix. A suitable device can be obtained on eBay similar to this:
- * http://www.ebay.com/itm/191781645249 for under $2.00 including shipping.
+ * extra debug information during code development.
*
- * Just connect up +5v and GND to give it power, then connect up the pins assigned
+ * Just connect up 5V and GND to give it power, then connect up the pins assigned
* in Configuration_adv.h. For example, on the Re-ARM you could use:
*
* #define MAX7219_CLK_PIN 77
@@ -35,187 +33,249 @@
*
* Max7219_init() is called automatically at startup, and then there are a number of
* support functions available to control the LEDs in the 8x8 grid.
- *
- * void Max7219_init();
- * void Max7219_PutByte(uint8_t data);
- * void Max7219(uint8_t reg, uint8_t data);
- * void Max7219_LED_On(uint8_t col, uint8_t row);
- * void Max7219_LED_Off(uint8_t col, uint8_t row);
- * void Max7219_LED_Toggle(uint8_t col, uint8_t row);
- * void Max7219_Clear_Row(uint8_t row);
- * void Max7219_Clear_Column(uint8_t col);
- * void Max7219_Set_Row(uint8_t row, uint8_t val);
- * void Max7219_Set_2_Rows(uint8_t row, uint16_t val);
- * void Max7219_Set_4_Rows(uint8_t row, uint32_t val);
- * void Max7219_Set_Column(uint8_t col, uint8_t val);
- * void Max7219_idle_tasks();
*/
#include "MarlinConfig.h"
#if ENABLED(MAX7219_DEBUG)
+#define MAX7219_ERRORS // Disable to save 406 bytes of Program Memory
+
#include "Max7219_Debug_LEDs.h"
#include "planner.h"
#include "stepper.h"
#include "Marlin.h"
+#include "delay.h"
static uint8_t LEDs[8] = { 0 };
-#ifdef CPU_32_BIT
- void MS_DELAY() { DELAY_1US; } // 32-bit processors need a delay to stabilize the signal
+#ifndef MAX7219_ROTATE
+ #define MAX7219_ROTATE 0
+#endif
+#define _ROT ((MAX7219_ROTATE + 360) % 360)
+#if _ROT == 0
+ #define _ROW_ y
+ #define _COL_ x
+ #define XOR_7219(x, y) LEDs[y] ^= _BV(7 - x)
+ #define BIT_7219(x, y) TEST(LEDs[y], 7 - x)
+ #define SEND_7219(R,V) Max7219(max7219_reg_digit0 + R, V)
+#elif _ROT == 90
+ #define _ROW_ x
+ #define _COL_ y
+ #define XOR_7219(x, y) LEDs[x] ^= _BV(y)
+ #define BIT_7219(x, y) TEST(LEDs[x], y)
+ #define SEND_7219(R,V) Max7219(max7219_reg_digit0 + R, V)
+#elif _ROT == 180
+ #define _ROW_ y
+ #define _COL_ x
+ #define XOR_7219(x, y) LEDs[y] ^= _BV(x)
+ #define BIT_7219(x, y) TEST(LEDs[y], x)
+ #define SEND_7219(R,V) Max7219(max7219_reg_digit7 - R, V)
+#elif _ROT == 270
+ #define _ROW_ x
+ #define _COL_ y
+ #define XOR_7219(x, y) LEDs[x] ^= _BV(7 - y)
+ #define BIT_7219(x, y) TEST(LEDs[x], 7 - y)
+ #define SEND_7219(R,V) Max7219(max7219_reg_digit7 - R, V)
#else
- #define MS_DELAY() DELAY_3_NOP
+ #error "MAX7219_ROTATE must be a multiple of +/- 90°."
#endif
+// Delay for 0.1875µs (16MHz AVR) or 0.15µs (20MHz AVR)
+#define SIG_DELAY() DELAY_NS(188)
+
void Max7219_PutByte(uint8_t data) {
- CRITICAL_SECTION_START
+ CRITICAL_SECTION_START;
for (uint8_t i = 8; i--;) {
- MS_DELAY();
+ SIG_DELAY();
WRITE(MAX7219_CLK_PIN, LOW); // tick
- MS_DELAY();
+ SIG_DELAY();
WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit
- MS_DELAY();
+ SIG_DELAY();
WRITE(MAX7219_CLK_PIN, HIGH); // tock
- MS_DELAY();
+ SIG_DELAY();
data <<= 1;
}
- CRITICAL_SECTION_END
+ CRITICAL_SECTION_END;
}
void Max7219(const uint8_t reg, const uint8_t data) {
- MS_DELAY();
- CRITICAL_SECTION_START
+ SIG_DELAY();
+ CRITICAL_SECTION_START;
WRITE(MAX7219_LOAD_PIN, LOW); // begin
- MS_DELAY();
+ SIG_DELAY();
Max7219_PutByte(reg); // specify register
- MS_DELAY();
+ SIG_DELAY();
Max7219_PutByte(data); // put data
- MS_DELAY();
+ SIG_DELAY();
WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data
- MS_DELAY();
+ SIG_DELAY();
WRITE(MAX7219_LOAD_PIN, HIGH);
- CRITICAL_SECTION_END
- MS_DELAY();
+ CRITICAL_SECTION_END;
+ SIG_DELAY();
}
-void Max7219_LED_Set(const uint8_t col, const uint8_t row, const bool on) {
- if (row > 7 || col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_LED_Set(", (int)row);
- SERIAL_ECHOPAIR(",", (int)col);
- SERIAL_ECHOLNPGM(")");
- return;
+#if ENABLED(MAX7219_NUMERIC)
+
+ // Draw an integer with optional leading zeros and optional decimal point
+ void Max7219_Print(const uint8_t start, int16_t value, uint8_t size, const bool leadzero=false, bool dec=false) {
+ constexpr uint8_t led_numeral[10] = { 0x7E, 0x60, 0x6D, 0x79, 0x63, 0x5B, 0x5F, 0x70, 0x7F, 0x7A },
+ led_decimal = 0x80, led_minus = 0x01;
+
+ bool blank = false, neg = value < 0;
+ if (neg) value *= -1;
+ while (size--) {
+ const bool minus = neg && blank;
+ if (minus) neg = false;
+ Max7219(
+ max7219_reg_digit0 + start + size,
+ minus ? led_minus : blank ? 0x00 : led_numeral[value % 10] | (dec ? led_decimal : 0x00)
+ );
+ value /= 10;
+ if (!value && !leadzero) blank = true;
+ dec = false;
+ }
}
- if (TEST(LEDs[row], col) == on) return; // if LED is already on/off, leave alone
- if (on) SBI(LEDs[row], col); else CBI(LEDs[row], col);
- Max7219(8 - row, LEDs[row]);
+
+ // Draw a float with a decimal point and optional digits
+ void Max7219_Print(const uint8_t start, const float value, const uint8_t pre_size, const uint8_t post_size, const bool leadzero=false) {
+ if (pre_size) Max7219_Print(start, value, pre_size, leadzero, !!post_size);
+ if (post_size) {
+ const int16_t after = ABS(value) * (10 ^ post_size);
+ Max7219_Print(start + pre_size, after, post_size, true);
+ }
+ }
+
+#endif // MAX7219_NUMERIC
+
+inline void Max7219_Error(const char * const func, const int32_t v1, const int32_t v2=-1) {
+ #if ENABLED(MAX7219_ERRORS)
+ SERIAL_ECHOPGM("??? ");
+ serialprintPGM(func);
+ SERIAL_CHAR('(');
+ SERIAL_ECHO(v1);
+ if (v2 > 0) SERIAL_ECHOPAIR(", ", v2);
+ SERIAL_CHAR(')');
+ SERIAL_EOL();
+ #else
+ UNUSED(func); UNUSED(v1); UNUSED(v2);
+ #endif
}
-void Max7219_LED_On(const uint8_t col, const uint8_t row) {
- if (row > 7 || col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_LED_On(", (int)col);
- SERIAL_ECHOPAIR(",", (int)row);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- Max7219_LED_Set(col, row, true);
+inline uint8_t flipped(const uint8_t bits) {
+ uint8_t outbits = 0;
+ for (uint8_t b = 0; b < 8; b++)
+ if (bits & _BV(b)) outbits |= _BV(7 - b);
+ return outbits;
}
-void Max7219_LED_Off(const uint8_t col, const uint8_t row) {
- if (row > 7 || col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_LED_Off(", (int)row);
- SERIAL_ECHOPAIR(",", (int)col);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- Max7219_LED_Set(col, row, false);
+// Modify a single LED bit and send the changed line
+void Max7219_LED_Set(const uint8_t x, const uint8_t y, const bool on) {
+ if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_Set"), x, y);
+ if (BIT_7219(x, y) == on) return;
+ XOR_7219(x, y);
+ SEND_7219(_ROW_, LEDs[_ROW_]);
}
-void Max7219_LED_Toggle(const uint8_t col, const uint8_t row) {
- if (row > 7 || col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_LED_Toggle(", (int)row);
- SERIAL_ECHOPAIR(",", (int)col);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- if (TEST(LEDs[row], col))
- Max7219_LED_Off(col, row);
- else
- Max7219_LED_On(col, row);
+void Max7219_LED_On(const uint8_t x, const uint8_t y) {
+ if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_On"), x, y);
+ Max7219_LED_Set(x, y, true);
}
-void Max7219_Clear_Column(const uint8_t col) {
- if (col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_Clear_Column(", (int)col);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- LEDs[col] = 0;
- Max7219(8 - col, LEDs[col]);
+void Max7219_LED_Off(const uint8_t x, const uint8_t y) {
+ if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_Off"), x, y);
+ Max7219_LED_Set(x, y, false);
}
-void Max7219_Clear_Row(const uint8_t row) {
- if (row > 7) {
- SERIAL_ECHOPAIR("??? Max7219_Clear_Row(", (int)row);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- for (uint8_t c = 0; c <= 7; c++)
- Max7219_LED_Off(c, row);
+void Max7219_LED_Toggle(const uint8_t x, const uint8_t y) {
+ if (x > 7 || y > 7) return Max7219_Error(PSTR("Max7219_LED_Toggle"), x, y);
+ Max7219_LED_Set(x, y, !BIT_7219(x, y));
}
-void Max7219_Set_Row(const uint8_t row, const uint8_t val) {
- if (row > 7) {
- SERIAL_ECHOPAIR("??? Max7219_Set_Row(", (int)row);
- SERIAL_ECHOPAIR(",", (int)val);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- for (uint8_t b = 0; b <= 7; b++)
- if (TEST(val, b))
- Max7219_LED_On(7 - b, row);
- else
- Max7219_LED_Off(7 - b, row);
+inline void _Max7219_Set_Reg(const uint8_t reg, const uint8_t val) {
+ LEDs[reg] = val;
+ SEND_7219(reg, val);
}
-void Max7219_Set_2_Rows(const uint8_t row, const uint16_t val) {
- if (row > 6) {
- SERIAL_ECHOPAIR("??? Max7219_Set_2_Rows(", (int)row);
- SERIAL_ECHOPAIR(",", (int)val);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- Max7219_Set_Row(row + 1, (val >> 8) & 0xFF);
- Max7219_Set_Row(row + 0, (val ) & 0xFF);
+void Max7219_Set_Row(const uint8_t _ROW_, const uint8_t val) {
+ if (_ROW_ > 7) return Max7219_Error(PSTR("Max7219_Set_Row"), _ROW_);
+ #if _ROT == 90
+ for (uint8_t _COL_ = 0; _COL_ <= 7; _COL_++) Max7219_LED_Set(7 - _COL_, _ROW_, TEST(val, _COL_));
+ #elif _ROT == 180
+ _Max7219_Set_Reg(_ROW_, flipped(val));
+ #elif _ROT == 270
+ for (uint8_t _COL_ = 0; _COL_ <= 7; _COL_++) Max7219_LED_Set(_COL_, _ROW_, TEST(val, _COL_));
+ #else
+ _Max7219_Set_Reg(_ROW_, val);
+ #endif
}
-void Max7219_Set_4_Rows(const uint8_t row, const uint32_t val) {
- if (row > 4) {
- SERIAL_ECHOPAIR("??? Max7219_Set_4_Rows(", (int)row);
- SERIAL_ECHOPAIR(",", (long)val);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- Max7219_Set_Row(row + 3, (val >> 24) & 0xFF);
- Max7219_Set_Row(row + 2, (val >> 16) & 0xFF);
- Max7219_Set_Row(row + 1, (val >> 8) & 0xFF);
- Max7219_Set_Row(row + 0, (val ) & 0xFF);
+void Max7219_Clear_Row(const uint8_t _ROW_) {
+ if (_ROW_ > 7) return Max7219_Error(PSTR("Max7219_Clear_Row"), _ROW_);
+ #if _ROT == 90 || _ROT == 270
+ for (uint8_t _COL_ = 0; _COL_ <= 7; _COL_++) Max7219_LED_Off(_COL_, _ROW_);
+ #else
+ _Max7219_Set_Reg(_ROW_, 0);
+ #endif
}
-void Max7219_Set_Column(const uint8_t col, const uint8_t val) {
- if (col > 7) {
- SERIAL_ECHOPAIR("??? Max7219_Column(", (int)col);
- SERIAL_ECHOPAIR(",", (int)val);
- SERIAL_ECHOLNPGM(")");
- return;
- }
- LEDs[col] = val;
- Max7219(8 - col, LEDs[col]);
+void Max7219_Set_Column(const uint8_t _COL_, const uint8_t val) {
+ if (_COL_ > 7) return Max7219_Error(PSTR("Max7219_Set_Column"), _COL_);
+ #if _ROT == 90
+ _Max7219_Set_Reg(_COL_, val);
+ #elif _ROT == 180
+ for (uint8_t _ROW_ = 0; _ROW_ <= 7; _ROW_++) Max7219_LED_Set(_COL_, _ROW_, TEST(val, _ROW_));
+ #elif _ROT == 270
+ _Max7219_Set_Reg(_COL_, flipped(val));
+ #else
+ for (uint8_t _ROW_ = 0; _ROW_ <= 7; _ROW_++) Max7219_LED_Set(_COL_, _ROW_, TEST(val, _ROW_));
+ #endif
+}
+
+void Max7219_Clear_Column(const uint8_t _COL_) {
+ if (_COL_ > 7) return Max7219_Error(PSTR("Max7219_Clear_Column"), _COL_);
+ #if _ROT == 90 || _ROT == 270
+ _Max7219_Set_Reg(_COL_, 0);
+ #else
+ for (uint8_t _ROW_ = 0; _ROW_ <= 7; _ROW_++) Max7219_LED_Off(_COL_, _ROW_);
+ #endif
+}
+
+void Max7219_Clear() {
+ for (uint8_t r = 0; r < 8; r++) _Max7219_Set_Reg(r, 0);
+}
+
+void Max7219_Set_2_Rows(const uint8_t y, uint16_t val) {
+ if (y > 6) return Max7219_Error(PSTR("Max7219_Set_2_Rows"), y, val);
+ Max7219_Set_Row(y + 0, val & 0xFF); val >>= 8;
+ Max7219_Set_Row(y + 1, val & 0xFF);
+}
+
+void Max7219_Set_4_Rows(const uint8_t y, uint32_t val) {
+ if (y > 4) return Max7219_Error(PSTR("Max7219_Set_4_Rows"), y, val);
+ Max7219_Set_Row(y + 0, val & 0xFF); val >>= 8;
+ Max7219_Set_Row(y + 1, val & 0xFF); val >>= 8;
+ Max7219_Set_Row(y + 2, val & 0xFF); val >>= 8;
+ Max7219_Set_Row(y + 3, val & 0xFF);
+}
+
+void Max7219_Set_2_Columns(const uint8_t x, uint16_t val) {
+ if (x > 6) return Max7219_Error(PSTR("Max7219_Set_2_Columns"), x, val);
+ Max7219_Set_Column(x + 0, val & 0xFF); val >>= 8;
+ Max7219_Set_Column(x + 1, val & 0xFF);
+}
+
+void Max7219_Set_4_Columns(const uint8_t x, uint32_t val) {
+ if (x > 4) return Max7219_Error(PSTR("Max7219_Set_4_Columns"), x, val);
+ Max7219_Set_Column(x + 0, val & 0xFF); val >>= 8;
+ Max7219_Set_Column(x + 1, val & 0xFF); val >>= 8;
+ Max7219_Set_Column(x + 2, val & 0xFF); val >>= 8;
+ Max7219_Set_Column(x + 3, val & 0xFF);
}
void Max7219_register_setup() {
- //initiation of the max 7219
+ // Initialize the Max7219
Max7219(max7219_reg_scanLimit, 0x07);
Max7219(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits)
Max7219(max7219_reg_shutdown, 0x01); // not in shutdown mode
@@ -224,135 +284,169 @@ void Max7219_register_setup() {
// range: 0x00 to 0x0F
}
-void Max7219_init() {
- uint8_t i, x, y;
+#ifdef MAX7219_INIT_TEST
+#if (MAX7219_INIT_TEST + 0) == 2
+ inline void Max7219_spiral(const bool on, const uint16_t del) {
+ constexpr int8_t way[] = { 1, 0, 0, 1, -1, 0, 0, -1 };
+ int8_t px = 0, py = 0, dir = 0;
+ for (uint8_t i = 64; i--;) {
+ Max7219_LED_Set(px, py, on);
+ delay(del);
+ const int8_t x = px + way[dir], y = py + way[dir + 1];
+ if (!WITHIN(x, 0, 7) || !WITHIN(y, 0, 7) || BIT_7219(x, y) == on) dir = (dir + 2) & 0x7;
+ px += way[dir]; py += way[dir + 1];
+ }
+ }
+
+#else
+
+ inline void Max7219_colset(const uint8_t x, const bool on) {
+ for (uint8_t y = 0; y <= 7; y++) Max7219_LED_Set(x, y, on);
+ }
+ inline void Max7219_sweep(const int8_t dir, const uint16_t ms, const bool on) {
+ uint8_t x = dir > 0 ? 0 : 7;
+ for (uint8_t i = 8; i--; x += dir) {
+ Max7219_Set_Column(x, on ? 0xFF : 0x00);
+ delay(ms);
+ }
+ }
+
+#endif
+#endif // MAX7219_INIT_TEST
+
+void Max7219_init() {
SET_OUTPUT(MAX7219_DIN_PIN);
SET_OUTPUT(MAX7219_CLK_PIN);
-
OUT_WRITE(MAX7219_LOAD_PIN, HIGH);
delay(1);
Max7219_register_setup();
- for (i = 0; i <= 7; i++) { // empty registers, turn all LEDs off
+ for (uint8_t i = 0; i <= 7; i++) { // Empty registers to turn all LEDs off
LEDs[i] = 0x00;
- Max7219(i + 1, 0);
+ Max7219(max7219_reg_digit0 + i, 0);
}
- for (x = 0; x <= 7; x++) // Do an aesthetically pleasing pattern to fully test
- for (y = 0; y <= 7; y++) { // the Max7219 module and LEDs. First, turn them
- Max7219_LED_On(y, x); // all on.
- delay(3);
- }
-
- for (x = 0; x <= 7; x++) // Now, turn them all off.
- for (y = 0; y <= 7; y++) {
- Max7219_LED_Off(y, x);
- delay(3); // delay() is OK here. Max7219_init() is only called from
- } // setup() and nothing is running yet.
-
- delay(150);
-
- for (x = 8; x--;) // Now, do the same thing from the opposite direction
- for (y = 0; y <= 7; y++) {
- Max7219_LED_On(y, x);
- delay(2);
- }
-
- for (x = 8; x--;)
- for (y = 0; y <= 7; y++) {
- Max7219_LED_Off(y, x);
- delay(2);
- }
+ #ifdef MAX7219_INIT_TEST
+ #if (MAX7219_INIT_TEST + 0) == 2
+ Max7219_spiral(true, 8);
+ delay(150);
+ Max7219_spiral(false, 8);
+ #else
+ // Do an aesthetically-pleasing pattern to fully test the Max7219 module and LEDs.
+ // Light up and turn off columns, both forward and backward.
+ Max7219_sweep(1, 20, true);
+ Max7219_sweep(1, 20, false);
+ delay(150);
+ Max7219_sweep(-1, 20, true);
+ Max7219_sweep(-1, 20, false);
+ #endif
+ #endif
}
/**
- * These are sample debug features to demonstrate the usage of the 8x8 LED Matrix for debug purposes.
- * There is very little CPU burden added to the system by displaying information within the idle()
- * task.
- *
- * But with that said, if your debugging can be facilitated by making calls into the library from
- * other places in the code, feel free to do it. The CPU burden for a few calls to toggle an LED
- * or clear a row is not very significant.
+ * This code demonstrates some simple debugging using a single 8x8 LED Matrix. If your feature could
+ * benefit from matrix display, add its code here. Very little processing is required, so the 7219 is
+ * ideal for debugging when realtime feedback is important but serial output can't be used.
*/
+
+// Apply changes to update a marker
+inline void Max7219_Mark16(const uint8_t y, const uint8_t v1, const uint8_t v2) {
+ Max7219_LED_Off(v1 & 0x7, y + (v1 >= 8));
+ Max7219_LED_On(v2 & 0x7, y + (v2 >= 8));
+}
+
+// Apply changes to update a tail-to-head range
+inline void Max7219_Range16(const uint8_t y, const uint8_t ot, const uint8_t nt, const uint8_t oh, const uint8_t nh) {
+ if (ot != nt) for (uint8_t n = ot & 0xF; n != (nt & 0xF) && n != (nh & 0xF); n = (n + 1) & 0xF)
+ Max7219_LED_Off(n & 0x7, y + (n >= 8));
+ if (oh != nh) for (uint8_t n = (oh + 1) & 0xF; n != ((nh + 1) & 0xF); n = (n + 1) & 0xF)
+ Max7219_LED_On(n & 0x7, y + (n >= 8));
+}
+
+// Apply changes to update a quantity
+inline void Max7219_Quantity16(const uint8_t y, const uint8_t ov, const uint8_t nv) {
+ for (uint8_t i = MIN(nv, ov); i < MAX(nv, ov); i++)
+ Max7219_LED_Set(i >> 1, y + (i & 1), nv >= ov);
+}
+
void Max7219_idle_tasks() {
- #if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
- CRITICAL_SECTION_START
- #if MAX7219_DEBUG_STEPPER_HEAD || MAX7219_DEBUG_STEPPER_QUEUE
+ #define MAX7219_USE_HEAD (defined(MAX7219_DEBUG_PLANNER_HEAD) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
+ #define MAX7219_USE_TAIL (defined(MAX7219_DEBUG_PLANNER_TAIL) || defined(MAX7219_DEBUG_PLANNER_QUEUE))
+ #if MAX7219_USE_HEAD || MAX7219_USE_TAIL
+ CRITICAL_SECTION_START;
+ #if MAX7219_USE_HEAD
const uint8_t head = planner.block_buffer_head;
#endif
- #if MAX7219_DEBUG_STEPPER_TAIL || MAX7219_DEBUG_STEPPER_QUEUE
+ #if MAX7219_USE_TAIL
const uint8_t tail = planner.block_buffer_tail;
#endif
- CRITICAL_SECTION_END
+ CRITICAL_SECTION_END;
#endif
- static uint16_t refresh_cnt = 0; // The Max7219 circuit boards available for several dollars on eBay
- if (refresh_cnt++ > 50000) { // are vulnerable to electrical noise, especially with long wires
- Max7219_register_setup(); // next to high current wires. If the display becomes corrupted due
- Max7219_LED_Toggle(7, 0); // to electrical noise, this will fix it within a couple of seconds.
+ #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
+ static uint8_t refresh_cnt; // = 0
+ constexpr uint16_t refresh_limit = 5;
+ static millis_t next_blink = 0;
+ const millis_t ms = millis();
+ const bool do_blink = ELAPSED(ms, next_blink);
+ #else
+ static uint16_t refresh_cnt; // = 0
+ constexpr bool do_blink = true;
+ constexpr uint16_t refresh_limit = 50000;
+ #endif
+
+ // Some Max7219 units are vulnerable to electrical noise, especially
+ // with long wires next to high current wires. If the display becomes
+ // corrupted, this will fix it within a couple seconds.
+ if (do_blink && ++refresh_cnt >= refresh_limit) {
refresh_cnt = 0;
+ Max7219_register_setup();
}
#if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE)
- static millis_t next_blink = 0;
- if (ELAPSED(millis(), next_blink)) {
+ if (do_blink) {
Max7219_LED_Toggle(7, 7);
- next_blink = millis() + 750;
+ next_blink = ms + 1000;
}
#endif
- #ifdef MAX7219_DEBUG_STEPPER_HEAD
- static int16_t last_head_cnt = 0;
- if (last_head_cnt != head) {
- if (last_head_cnt < 8)
- Max7219_LED_Off(MAX7219_DEBUG_STEPPER_HEAD, last_head_cnt);
- else
- Max7219_LED_Off(MAX7219_DEBUG_STEPPER_HEAD + 1, last_head_cnt - 8);
+ #if defined(MAX7219_DEBUG_PLANNER_HEAD) && defined(MAX7219_DEBUG_PLANNER_TAIL) && MAX7219_DEBUG_PLANNER_HEAD == MAX7219_DEBUG_PLANNER_TAIL
+ static int16_t last_head_cnt = 0xF, last_tail_cnt = 0xF;
+
+ if (last_head_cnt != head || last_tail_cnt != tail) {
+ Max7219_Range16(MAX7219_DEBUG_PLANNER_HEAD, last_tail_cnt, tail, last_head_cnt, head);
last_head_cnt = head;
- if (head < 8)
- Max7219_LED_On(MAX7219_DEBUG_STEPPER_HEAD, head);
- else
- Max7219_LED_On(MAX7219_DEBUG_STEPPER_HEAD + 1, head - 8);
- }
- #endif
-
- #ifdef MAX7219_DEBUG_STEPPER_TAIL
- static int16_t last_tail_cnt = 0;
- if (last_tail_cnt != tail) {
- if (last_tail_cnt < 8)
- Max7219_LED_Off(MAX7219_DEBUG_STEPPER_TAIL, last_tail_cnt);
- else
- Max7219_LED_Off(MAX7219_DEBUG_STEPPER_TAIL + 1, last_tail_cnt - 8);
-
last_tail_cnt = tail;
- if (tail < 8)
- Max7219_LED_On(MAX7219_DEBUG_STEPPER_TAIL, tail);
- else
- Max7219_LED_On(MAX7219_DEBUG_STEPPER_TAIL + 1, tail - 8);
}
+
+ #else
+
+ #ifdef MAX7219_DEBUG_PLANNER_HEAD
+ static int16_t last_head_cnt = 0x1;
+ if (last_head_cnt != head) {
+ Max7219_Mark16(MAX7219_DEBUG_PLANNER_HEAD, last_head_cnt, head);
+ last_head_cnt = head;
+ }
+ #endif
+
+ #ifdef MAX7219_DEBUG_PLANNER_TAIL
+ static int16_t last_tail_cnt = 0x1;
+ if (last_tail_cnt != tail) {
+ Max7219_Mark16(MAX7219_DEBUG_PLANNER_TAIL, last_tail_cnt, tail);
+ last_tail_cnt = tail;
+ }
+ #endif
+
#endif
- #ifdef MAX7219_DEBUG_STEPPER_QUEUE
+ #ifdef MAX7219_DEBUG_PLANNER_QUEUE
static int16_t last_depth = 0;
- int16_t current_depth = head - tail;
- if (current_depth != last_depth) { // usually, no update will be needed.
- if (current_depth < 0) current_depth += BLOCK_BUFFER_SIZE;
- NOMORE(current_depth, BLOCK_BUFFER_SIZE);
- NOMORE(current_depth, 16); // if the BLOCK_BUFFER_SIZE is greater than 16, two lines
- // of LEDs is enough to see if the buffer is draining
-
- const uint8_t st = min(current_depth, last_depth),
- en = max(current_depth, last_depth);
- if (current_depth < last_depth)
- for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs
- Max7219_LED_Off(MAX7219_DEBUG_STEPPER_QUEUE + (i & 1), i / 2);
- else
- for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth
- Max7219_LED_On(MAX7219_DEBUG_STEPPER_QUEUE + (i & 1), i / 2);
-
+ const int16_t current_depth = (head - tail + BLOCK_BUFFER_SIZE) & (BLOCK_BUFFER_SIZE - 1) & 0xF;
+ if (current_depth != last_depth) {
+ Max7219_Quantity16(MAX7219_DEBUG_PLANNER_QUEUE, last_depth, current_depth);
last_depth = current_depth;
}
#endif
diff --git a/Marlin/Max7219_Debug_LEDs.h b/Marlin/Max7219_Debug_LEDs.h
index 3beccb0ea8..f00f231749 100644
--- a/Marlin/Max7219_Debug_LEDs.h
+++ b/Marlin/Max7219_Debug_LEDs.h
@@ -22,11 +22,9 @@
/**
* This module is off by default, but can be enabled to facilitate the display of
- * extra debug information during code development. It assumes the existence of a
- * Max7219 LED Matrix. A suitable device can be obtained on eBay similar to this:
- * http://www.ebay.com/itm/191781645249 for under $2.00 including shipping.
+ * extra debug information during code development.
*
- * Just connect up +5v and GND to give it power, then connect up the pins assigned
+ * Just connect up 5V and GND to give it power, then connect up the pins assigned
* in Configuration_adv.h. For example, on the Re-ARM you could use:
*
* #define MAX7219_CLK_PIN 77
@@ -35,28 +33,13 @@
*
* Max7219_init() is called automatically at startup, and then there are a number of
* support functions available to control the LEDs in the 8x8 grid.
- *
- * void Max7219_init();
- * void Max7219_PutByte(uint8_t data);
- * void Max7219(uint8_t reg, uint8_t data);
- * void Max7219_LED_Set(uint8_t row, uint8_t col, bool on);
- * void Max7219_LED_On(uint8_t col, uint8_t row);
- * void Max7219_LED_Off(uint8_t col, uint8_t row);
- * void Max7219_LED_Toggle(uint8_t row, uint8_t col);
- * void Max7219_Clear_Row(uint8_t row);
- * void Max7219_Clear_Column(uint8_t col);
- * void Max7219_Set_Row(uint8_t row, uint8_t val);
- * void Max7219_Set_2_Rows(uint8_t row, uint16_t val);
- * void Max7219_Set_4_Rows(uint8_t row, uint32_t val);
- * void Max7219_Set_Column(uint8_t col, uint8_t val);
- * void Max7219_idle_tasks();
*/
#ifndef __MAX7219_DEBUG_LEDS_H__
#define __MAX7219_DEBUG_LEDS_H__
//
-// define max7219 registers
+// MAX7219 registers
//
#define max7219_reg_noop 0x00
#define max7219_reg_digit0 0x01
@@ -68,23 +51,36 @@
#define max7219_reg_digit6 0x07
#define max7219_reg_digit7 0x08
-#define max7219_reg_intensity 0x0A
-#define max7219_reg_displayTest 0x0F
#define max7219_reg_decodeMode 0x09
+#define max7219_reg_intensity 0x0A
#define max7219_reg_scanLimit 0x0B
#define max7219_reg_shutdown 0x0C
+#define max7219_reg_displayTest 0x0F
void Max7219_init();
void Max7219_PutByte(uint8_t data);
+
+// Set a single register (e.g., a whole native row)
void Max7219(const uint8_t reg, const uint8_t data);
-void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on);
-void Max7219_LED_On(const uint8_t row, const uint8_t col);
-void Max7219_LED_Off(const uint8_t row, const uint8_t col);
-void Max7219_LED_Toggle(const uint8_t row, const uint8_t col);
-void Max7219_Clear_Row(const uint8_t row);
-void Max7219_Clear_Column(const uint8_t col);
-void Max7219_Set_Row(const uint8_t row, const uint8_t val);
+
+// Set a single LED by XY coordinate
+void Max7219_LED_Set(const uint8_t x, const uint8_t y, const bool on);
+void Max7219_LED_On(const uint8_t x, const uint8_t y);
+void Max7219_LED_Off(const uint8_t x, const uint8_t y);
+void Max7219_LED_Toggle(const uint8_t x, const uint8_t y);
+
+// Set all 8 LEDs in a single column
void Max7219_Set_Column(const uint8_t col, const uint8_t val);
+void Max7219_Clear_Column(const uint8_t col);
+
+// Set all 8 LEDs in a single row
+void Max7219_Set_Row(const uint8_t row, const uint8_t val);
+void Max7219_Clear_Row(const uint8_t row);
+
+// Quickly clear the whole matrix
+void Max7219_Clear();
+
+// Apply custom code to update the matrix
void Max7219_idle_tasks();
#endif // __MAX7219_DEBUG_LEDS_H__
diff --git a/Marlin/SanityCheck.h b/Marlin/SanityCheck.h
index 33c2e16093..1b9832ebc6 100644
--- a/Marlin/SanityCheck.h
+++ b/Marlin/SanityCheck.h
@@ -42,18 +42,21 @@
* the bleeding-edge source code, but sometimes this is not enough. This check
* forces a minimum config file revision. Otherwise Marlin will not build.
*/
-#if !defined(CONFIGURATION_H_VERSION) || CONFIGURATION_H_VERSION < REQUIRED_CONFIGURATION_H_VERSION
+#define HEXIFY(H) _CAT(0x,H)
+#if !defined(CONFIGURATION_H_VERSION) || HEXIFY(CONFIGURATION_H_VERSION) < HEXIFY(REQUIRED_CONFIGURATION_H_VERSION)
#error "You are using an old Configuration.h file, update it before building Marlin."
#endif
-#if !defined(CONFIGURATION_ADV_H_VERSION) || CONFIGURATION_ADV_H_VERSION < REQUIRED_CONFIGURATION_ADV_H_VERSION
+#if !defined(CONFIGURATION_ADV_H_VERSION) || HEXIFY(CONFIGURATION_ADV_H_VERSION) < HEXIFY(REQUIRED_CONFIGURATION_ADV_H_VERSION)
#error "You are using an old Configuration_adv.h file, update it before building Marlin."
#endif
/**
* Warnings for old configurations
*/
-#if !defined(X_BED_SIZE) || !defined(Y_BED_SIZE)
+#ifndef MOTHERBOARD
+ #error "MOTHERBOARD is required. Please update your configuration."
+#elif !defined(X_BED_SIZE) || !defined(Y_BED_SIZE)
#error "X_BED_SIZE and Y_BED_SIZE are now required! Please update your configuration."
#elif WATCH_TEMP_PERIOD > 500
#error "WATCH_TEMP_PERIOD now uses seconds instead of milliseconds."
@@ -272,6 +275,20 @@
#error "FILAMENT_CHANGE_LOAD_LENGTH is now FILAMENT_CHANGE_FAST_LOAD_LENGTH. Please update your configuration."
#elif ENABLED(LEVEL_BED_CORNERS) && !defined(LEVEL_CORNERS_INSET)
#error "LEVEL_BED_CORNERS requires a LEVEL_CORNERS_INSET value. Please update your Configuration.h."
+#elif defined(BEZIER_JERK_CONTROL)
+ #error "BEZIER_JERK_CONTROL is now S_CURVE_ACCELERATION. Please update your configuration."
+#elif defined(JUNCTION_DEVIATION_FACTOR)
+ #error "JUNCTION_DEVIATION_FACTOR is now JUNCTION_DEVIATION_MM. Please update your configuration."
+#elif defined(JUNCTION_ACCELERATION_FACTOR)
+ #error "JUNCTION_ACCELERATION_FACTOR is obsolete. Delete it from Configuration_adv.h."
+#elif defined(JUNCTION_ACCELERATION)
+ #error "JUNCTION_ACCELERATION is obsolete. Delete it from Configuration_adv.h."
+#elif defined(MAX7219_DEBUG_STEPPER_HEAD)
+ #error "MAX7219_DEBUG_STEPPER_HEAD is now MAX7219_DEBUG_PLANNER_HEAD. Please update your configuration."
+#elif defined(MAX7219_DEBUG_STEPPER_TAIL)
+ #error "MAX7219_DEBUG_STEPPER_TAIL is now MAX7219_DEBUG_PLANNER_TAIL. Please update your configuration."
+#elif defined(MAX7219_DEBUG_STEPPER_QUEUE)
+ #error "MAX7219_DEBUG_STEPPER_QUEUE is now MAX7219_DEBUG_PLANNER_QUEUE. Please update your configuration."
#endif
#define BOARD_MKS_13 -47
@@ -306,7 +323,7 @@
/**
* Serial
*/
-#if !(defined(__AVR__) && defined(USBCON))
+#if USE_MARLINSERIAL
#if ENABLED(SERIAL_XON_XOFF) && RX_BUFFER_SIZE < 1024
#error "SERIAL_XON_XOFF requires RX_BUFFER_SIZE >= 1024 for reliable transfers without drops."
#elif RX_BUFFER_SIZE && (RX_BUFFER_SIZE < 2 || !IS_POWER_OF_2(RX_BUFFER_SIZE))
@@ -894,8 +911,8 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
#if ENABLED(LCD_BED_LEVELING)
#if DISABLED(ULTIPANEL)
#error "LCD_BED_LEVELING requires an LCD controller."
- #elif !(ENABLED(MESH_BED_LEVELING) || (OLDSCHOOL_ABL && ENABLED(PROBE_MANUALLY)))
- #error "LCD_BED_LEVELING requires MESH_BED_LEVELING or ABL with PROBE_MANUALLY."
+ #elif !(ENABLED(MESH_BED_LEVELING) || OLDSCHOOL_ABL)
+ #error "LCD_BED_LEVELING requires MESH_BED_LEVELING or AUTO_BED_LEVELING."
#endif
#endif
@@ -919,15 +936,11 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
*/
#if ENABLED(Z_SAFE_HOMING)
#if HAS_BED_PROBE
- static_assert(WITHIN(Z_SAFE_HOMING_X_POINT, MIN_PROBE_X, MAX_PROBE_X),
- "Z_SAFE_HOMING_X_POINT is outside the probe region.");
- static_assert(WITHIN(Z_SAFE_HOMING_Y_POINT, MIN_PROBE_Y, MAX_PROBE_Y),
- "Z_SAFE_HOMING_Y_POINT is outside the probe region.");
+ static_assert(WITHIN(Z_SAFE_HOMING_X_POINT, MIN_PROBE_X, MAX_PROBE_X), "Z_SAFE_HOMING_X_POINT is outside the probe region.");
+ static_assert(WITHIN(Z_SAFE_HOMING_Y_POINT, MIN_PROBE_Y, MAX_PROBE_Y), "Z_SAFE_HOMING_Y_POINT is outside the probe region.");
#else
- static_assert(WITHIN(Z_SAFE_HOMING_X_POINT, X_MIN_POS, X_MAX_POS),
- "Z_SAFE_HOMING_X_POINT can't be reached by the nozzle.");
- static_assert(WITHIN(Z_SAFE_HOMING_Y_POINT, Y_MIN_POS, Y_MAX_POS),
- "Z_SAFE_HOMING_Y_POINT can't be reached by the nozzle.");
+ static_assert(WITHIN(Z_SAFE_HOMING_X_POINT, X_MIN_POS, X_MAX_POS), "Z_SAFE_HOMING_X_POINT can't be reached by the nozzle.");
+ static_assert(WITHIN(Z_SAFE_HOMING_Y_POINT, Y_MIN_POS, Y_MAX_POS), "Z_SAFE_HOMING_Y_POINT can't be reached by the nozzle.");
#endif
#endif // Z_SAFE_HOMING
@@ -965,8 +978,12 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
/**
* SAV_3DGLCD display options
*/
-#if ENABLED(U8GLIB_SSD1306) && ENABLED(U8GLIB_SH1106)
- #error "Only enable one SAV_3DGLCD display type: U8GLIB_SSD1306 or U8GLIB_SH1106."
+#if ENABLED(SAV_3DGLCD)
+ #if DISABLED(U8GLIB_SSD1306) && DISABLED(U8GLIB_SH1106)
+ #error "Enable a SAV_3DGLCD display type: U8GLIB_SSD1306 or U8GLIB_SH1106."
+ #elif ENABLED(U8GLIB_SSD1306) && ENABLED(U8GLIB_SH1106)
+ #error "Only enable one SAV_3DGLCD display type: U8GLIB_SSD1306 or U8GLIB_SH1106."
+ #endif
#endif
/**
@@ -1119,6 +1136,13 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
#error "TEMP_STAT_LEDS requires STAT_LED_RED_PIN or STAT_LED_BLUE_PIN, preferably both."
#endif
+/**
+ * LED Control Menu
+ */
+#if ENABLED(LED_CONTROL_MENU) && !HAS_COLOR_LEDS
+ #error "LED_CONTROL_MENU requires BLINKM, RGB_LED, RGBW_LED, PCA9632, or NEOPIXEL_LED."
+#endif
+
/**
* Basic 2-nozzle duplication mode
*/
@@ -1198,18 +1222,18 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
#if ENABLED(X_DUAL_ENDSTOPS)
#if !X2_USE_ENDSTOP
#error "You must set X2_USE_ENDSTOP with X_DUAL_ENDSTOPS."
- #elif X2_USE_ENDSTOP == _X_MIN_ && DISABLED(USE_XMIN_PLUG)
- #error "USE_XMIN_PLUG is required when X2_USE_ENDSTOP is _X_MIN_."
- #elif X2_USE_ENDSTOP == _X_MAX_ && DISABLED(USE_XMAX_PLUG)
- #error "USE_XMAX_PLUG is required when X2_USE_ENDSTOP is _X_MAX_."
- #elif X2_USE_ENDSTOP == _Y_MIN_ && DISABLED(USE_YMIN_PLUG)
- #error "USE_YMIN_PLUG is required when X2_USE_ENDSTOP is _Y_MIN_."
- #elif X2_USE_ENDSTOP == _Y_MAX_ && DISABLED(USE_YMAX_PLUG)
- #error "USE_YMAX_PLUG is required when X2_USE_ENDSTOP is _Y_MAX_."
- #elif X2_USE_ENDSTOP == _Z_MIN_ && DISABLED(USE_ZMIN_PLUG)
- #error "USE_ZMIN_PLUG is required when X2_USE_ENDSTOP is _Z_MIN_."
- #elif X2_USE_ENDSTOP == _Z_MAX_ && DISABLED(USE_ZMAX_PLUG)
- #error "USE_ZMAX_PLUG is required when X2_USE_ENDSTOP is _Z_MAX_."
+ #elif X2_USE_ENDSTOP == _XMIN_ && DISABLED(USE_XMIN_PLUG)
+ #error "USE_XMIN_PLUG is required when X2_USE_ENDSTOP is _XMIN_."
+ #elif X2_USE_ENDSTOP == _XMAX_ && DISABLED(USE_XMAX_PLUG)
+ #error "USE_XMAX_PLUG is required when X2_USE_ENDSTOP is _XMAX_."
+ #elif X2_USE_ENDSTOP == _YMIN_ && DISABLED(USE_YMIN_PLUG)
+ #error "USE_YMIN_PLUG is required when X2_USE_ENDSTOP is _YMIN_."
+ #elif X2_USE_ENDSTOP == _YMAX_ && DISABLED(USE_YMAX_PLUG)
+ #error "USE_YMAX_PLUG is required when X2_USE_ENDSTOP is _YMAX_."
+ #elif X2_USE_ENDSTOP == _ZMIN_ && DISABLED(USE_ZMIN_PLUG)
+ #error "USE_ZMIN_PLUG is required when X2_USE_ENDSTOP is _ZMIN_."
+ #elif X2_USE_ENDSTOP == _ZMAX_ && DISABLED(USE_ZMAX_PLUG)
+ #error "USE_ZMAX_PLUG is required when X2_USE_ENDSTOP is _ZMAX_."
#elif !HAS_X2_MIN && !HAS_X2_MAX
#error "X2_USE_ENDSTOP has been assigned to a nonexistent endstop!"
#elif ENABLED(DELTA)
@@ -1219,18 +1243,18 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
#if ENABLED(Y_DUAL_ENDSTOPS)
#if !Y2_USE_ENDSTOP
#error "You must set Y2_USE_ENDSTOP with Y_DUAL_ENDSTOPS."
- #elif Y2_USE_ENDSTOP == _X_MIN_ && DISABLED(USE_XMIN_PLUG)
- #error "USE_XMIN_PLUG is required when Y2_USE_ENDSTOP is _X_MIN_."
- #elif Y2_USE_ENDSTOP == _X_MAX_ && DISABLED(USE_XMAX_PLUG)
- #error "USE_XMAX_PLUG is required when Y2_USE_ENDSTOP is _X_MAX_."
- #elif Y2_USE_ENDSTOP == _Y_MIN_ && DISABLED(USE_YMIN_PLUG)
- #error "USE_YMIN_PLUG is required when Y2_USE_ENDSTOP is _Y_MIN_."
- #elif Y2_USE_ENDSTOP == _Y_MAX_ && DISABLED(USE_YMAX_PLUG)
- #error "USE_YMAX_PLUG is required when Y2_USE_ENDSTOP is _Y_MAX_."
- #elif Y2_USE_ENDSTOP == _Z_MIN_ && DISABLED(USE_ZMIN_PLUG)
- #error "USE_ZMIN_PLUG is required when Y2_USE_ENDSTOP is _Z_MIN_."
- #elif Y2_USE_ENDSTOP == _Z_MAX_ && DISABLED(USE_ZMAX_PLUG)
- #error "USE_ZMAX_PLUG is required when Y2_USE_ENDSTOP is _Z_MAX_."
+ #elif Y2_USE_ENDSTOP == _XMIN_ && DISABLED(USE_XMIN_PLUG)
+ #error "USE_XMIN_PLUG is required when Y2_USE_ENDSTOP is _XMIN_."
+ #elif Y2_USE_ENDSTOP == _XMAX_ && DISABLED(USE_XMAX_PLUG)
+ #error "USE_XMAX_PLUG is required when Y2_USE_ENDSTOP is _XMAX_."
+ #elif Y2_USE_ENDSTOP == _YMIN_ && DISABLED(USE_YMIN_PLUG)
+ #error "USE_YMIN_PLUG is required when Y2_USE_ENDSTOP is _YMIN_."
+ #elif Y2_USE_ENDSTOP == _YMAX_ && DISABLED(USE_YMAX_PLUG)
+ #error "USE_YMAX_PLUG is required when Y2_USE_ENDSTOP is _YMAX_."
+ #elif Y2_USE_ENDSTOP == _ZMIN_ && DISABLED(USE_ZMIN_PLUG)
+ #error "USE_ZMIN_PLUG is required when Y2_USE_ENDSTOP is _ZMIN_."
+ #elif Y2_USE_ENDSTOP == _ZMAX_ && DISABLED(USE_ZMAX_PLUG)
+ #error "USE_ZMAX_PLUG is required when Y2_USE_ENDSTOP is _ZMAX_."
#elif !HAS_Y2_MIN && !HAS_Y2_MAX
#error "Y2_USE_ENDSTOP has been assigned to a nonexistent endstop!"
#elif ENABLED(DELTA)
@@ -1240,18 +1264,18 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
#if ENABLED(Z_DUAL_ENDSTOPS)
#if !Z2_USE_ENDSTOP
#error "You must set Z2_USE_ENDSTOP with Z_DUAL_ENDSTOPS."
- #elif Z2_USE_ENDSTOP == _X_MIN_ && DISABLED(USE_XMIN_PLUG)
- #error "USE_XMIN_PLUG is required when Z2_USE_ENDSTOP is _X_MIN_."
- #elif Z2_USE_ENDSTOP == _X_MAX_ && DISABLED(USE_XMAX_PLUG)
- #error "USE_XMAX_PLUG is required when Z2_USE_ENDSTOP is _X_MAX_."
- #elif Z2_USE_ENDSTOP == _Y_MIN_ && DISABLED(USE_YMIN_PLUG)
- #error "USE_YMIN_PLUG is required when Z2_USE_ENDSTOP is _Y_MIN_."
- #elif Z2_USE_ENDSTOP == _Y_MAX_ && DISABLED(USE_YMAX_PLUG)
- #error "USE_YMAX_PLUG is required when Z2_USE_ENDSTOP is _Y_MAX_."
- #elif Z2_USE_ENDSTOP == _Z_MIN_ && DISABLED(USE_ZMIN_PLUG)
- #error "USE_ZMIN_PLUG is required when Z2_USE_ENDSTOP is _Z_MIN_."
- #elif Z2_USE_ENDSTOP == _Z_MAX_ && DISABLED(USE_ZMAX_PLUG)
- #error "USE_ZMAX_PLUG is required when Z2_USE_ENDSTOP is _Z_MAX_."
+ #elif Z2_USE_ENDSTOP == _XMIN_ && DISABLED(USE_XMIN_PLUG)
+ #error "USE_XMIN_PLUG is required when Z2_USE_ENDSTOP is _XMIN_."
+ #elif Z2_USE_ENDSTOP == _XMAX_ && DISABLED(USE_XMAX_PLUG)
+ #error "USE_XMAX_PLUG is required when Z2_USE_ENDSTOP is _XMAX_."
+ #elif Z2_USE_ENDSTOP == _YMIN_ && DISABLED(USE_YMIN_PLUG)
+ #error "USE_YMIN_PLUG is required when Z2_USE_ENDSTOP is _YMIN_."
+ #elif Z2_USE_ENDSTOP == _YMAX_ && DISABLED(USE_YMAX_PLUG)
+ #error "USE_YMAX_PLUG is required when Z2_USE_ENDSTOP is _YMAX_."
+ #elif Z2_USE_ENDSTOP == _ZMIN_ && DISABLED(USE_ZMIN_PLUG)
+ #error "USE_ZMIN_PLUG is required when Z2_USE_ENDSTOP is _ZMIN_."
+ #elif Z2_USE_ENDSTOP == _ZMAX_ && DISABLED(USE_ZMAX_PLUG)
+ #error "USE_ZMAX_PLUG is required when Z2_USE_ENDSTOP is _ZMAX_."
#elif !HAS_Z2_MIN && !HAS_Z2_MAX
#error "Z2_USE_ENDSTOP has been assigned to a nonexistent endstop!"
#elif ENABLED(DELTA)
@@ -1262,7 +1286,7 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
/**
* emergency-command parser
*/
-#if ENABLED(EMERGENCY_PARSER) && defined(__AVR__) && defined(USBCON)
+#if ENABLED(EMERGENCY_PARSER) && !USE_MARLINSERIAL
#error "EMERGENCY_PARSER does not work on boards with AT90USB processors (USBCON)."
#endif
@@ -1392,36 +1416,36 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
* Make sure HAVE_TMC26X is warranted
*/
#if ENABLED(HAVE_TMC26X) && !( \
- ENABLED( X_IS_TMC26X ) \
- || ENABLED( X2_IS_TMC26X ) \
- || ENABLED( Y_IS_TMC26X ) \
- || ENABLED( Y2_IS_TMC26X ) \
- || ENABLED( Z_IS_TMC26X ) \
- || ENABLED( Z2_IS_TMC26X ) \
- || ENABLED( E0_IS_TMC26X ) \
- || ENABLED( E1_IS_TMC26X ) \
- || ENABLED( E2_IS_TMC26X ) \
- || ENABLED( E3_IS_TMC26X ) \
- || ENABLED( E4_IS_TMC26X ) \
+ ENABLED( X_IS_TMC26X) \
+ || ENABLED(X2_IS_TMC26X) \
+ || ENABLED( Y_IS_TMC26X) \
+ || ENABLED(Y2_IS_TMC26X) \
+ || ENABLED( Z_IS_TMC26X) \
+ || ENABLED(Z2_IS_TMC26X) \
+ || ENABLED(E0_IS_TMC26X) \
+ || ENABLED(E1_IS_TMC26X) \
+ || ENABLED(E2_IS_TMC26X) \
+ || ENABLED(E3_IS_TMC26X) \
+ || ENABLED(E4_IS_TMC26X) \
)
#error "HAVE_TMC26X requires at least one TMC26X stepper to be set."
#endif
/**
- * Make sure HAVE_TMC2130 is warranted
+ * TMC2130 Requirements
*/
#if ENABLED(HAVE_TMC2130)
- #if !( ENABLED( X_IS_TMC2130 ) \
- || ENABLED( X2_IS_TMC2130 ) \
- || ENABLED( Y_IS_TMC2130 ) \
- || ENABLED( Y2_IS_TMC2130 ) \
- || ENABLED( Z_IS_TMC2130 ) \
- || ENABLED( Z2_IS_TMC2130 ) \
- || ENABLED( E0_IS_TMC2130 ) \
- || ENABLED( E1_IS_TMC2130 ) \
- || ENABLED( E2_IS_TMC2130 ) \
- || ENABLED( E3_IS_TMC2130 ) \
- || ENABLED( E4_IS_TMC2130 ) )
+ #if !( ENABLED( X_IS_TMC2130) \
+ || ENABLED(X2_IS_TMC2130) \
+ || ENABLED( Y_IS_TMC2130) \
+ || ENABLED(Y2_IS_TMC2130) \
+ || ENABLED( Z_IS_TMC2130) \
+ || ENABLED(Z2_IS_TMC2130) \
+ || ENABLED(E0_IS_TMC2130) \
+ || ENABLED(E1_IS_TMC2130) \
+ || ENABLED(E2_IS_TMC2130) \
+ || ENABLED(E3_IS_TMC2130) \
+ || ENABLED(E4_IS_TMC2130) )
#error "HAVE_TMC2130 requires at least one TMC2130 stepper to be set."
#elif ENABLED(HYBRID_THRESHOLD) && DISABLED(STEALTHCHOP)
#error "Enable STEALTHCHOP to use HYBRID_THRESHOLD."
@@ -1470,6 +1494,8 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
#error "SENSORLESS_HOMING requires Z_MIN_ENDSTOP_INVERTING and ENDSTOPPULLUP_ZMIN when homing to Z_MIN."
#elif Z_SENSORLESS && Z_HOME_DIR == 1 && (DISABLED(Z_MAX_ENDSTOP_INVERTING) || DISABLED(ENDSTOPPULLUP_ZMAX))
#error "SENSORLESS_HOMING requires Z_MAX_ENDSTOP_INVERTING and ENDSTOPPULLUP_ZMAX when homing to Z_MAX."
+ #elif ENABLED(ENDSTOP_NOISE_FILTER)
+ #error "SENSORLESS_HOMING is incompatible with ENDSTOP_NOISE_FILTER."
#endif
#endif
@@ -1489,38 +1515,36 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
#endif
/**
- * Make sure HAVE_TMC2208 is warranted
+ * TMC2208 Requirements
*/
-#if ENABLED(HAVE_TMC2208) && !( \
- ENABLED( X_IS_TMC2208 ) \
- || ENABLED( X2_IS_TMC2208 ) \
- || ENABLED( Y_IS_TMC2208 ) \
- || ENABLED( Y2_IS_TMC2208 ) \
- || ENABLED( Z_IS_TMC2208 ) \
- || ENABLED( Z2_IS_TMC2208 ) \
- || ENABLED( E0_IS_TMC2208 ) \
- || ENABLED( E1_IS_TMC2208 ) \
- || ENABLED( E2_IS_TMC2208 ) \
- || ENABLED( E3_IS_TMC2208 ) )
- #error "HAVE_TMC2208 requires at least one TMC2208 stepper to be set."
-#endif
-
-/**
- * TMC2208 software UART and ENDSTOP_INTERRUPTS both use pin change interrupts (PCI)
- */
-#if ENABLED(HAVE_TMC2208) && ENABLED(ENDSTOP_INTERRUPTS_FEATURE) && !( \
- defined(X_HARDWARE_SERIAL ) \
- || defined(X2_HARDWARE_SERIAL) \
- || defined(Y_HARDWARE_SERIAL ) \
- || defined(Y2_HARDWARE_SERIAL) \
- || defined(Z_HARDWARE_SERIAL ) \
- || defined(Z2_HARDWARE_SERIAL) \
- || defined(E0_HARDWARE_SERIAL) \
- || defined(E1_HARDWARE_SERIAL) \
- || defined(E2_HARDWARE_SERIAL) \
- || defined(E3_HARDWARE_SERIAL) \
- || defined(E4_HARDWARE_SERIAL) )
- #error "select hardware UART for TMC2208 to use both TMC2208 and ENDSTOP_INTERRUPTS_FEATURE."
+#if ENABLED(HAVE_TMC2208)
+ #if !( ENABLED( X_IS_TMC2208) \
+ || ENABLED(X2_IS_TMC2208) \
+ || ENABLED( Y_IS_TMC2208) \
+ || ENABLED(Y2_IS_TMC2208) \
+ || ENABLED( Z_IS_TMC2208) \
+ || ENABLED(Z2_IS_TMC2208) \
+ || ENABLED(E0_IS_TMC2208) \
+ || ENABLED(E1_IS_TMC2208) \
+ || ENABLED(E2_IS_TMC2208) \
+ || ENABLED(E3_IS_TMC2208) \
+ || ENABLED(E4_IS_TMC2208 ) )
+ #error "HAVE_TMC2208 requires at least one TMC2208 stepper to be set."
+ // Software UART and ENDSTOP_INTERRUPTS both use Pin Change interrupts (PCI)
+ #elif ENABLED(ENDSTOP_INTERRUPTS_FEATURE) && \
+ !( defined( X_HARDWARE_SERIAL) \
+ || defined(X2_HARDWARE_SERIAL) \
+ || defined( Y_HARDWARE_SERIAL) \
+ || defined(Y2_HARDWARE_SERIAL) \
+ || defined( Z_HARDWARE_SERIAL) \
+ || defined(Z2_HARDWARE_SERIAL) \
+ || defined(E0_HARDWARE_SERIAL) \
+ || defined(E1_HARDWARE_SERIAL) \
+ || defined(E2_HARDWARE_SERIAL) \
+ || defined(E3_HARDWARE_SERIAL) \
+ || defined(E4_HARDWARE_SERIAL) )
+ #error "Select *_HARDWARE_SERIAL to use both TMC2208 and ENDSTOP_INTERRUPTS_FEATURE."
+ #endif
#endif
#if ENABLED(HYBRID_THRESHOLD) && DISABLED(STEALTHCHOP)
@@ -1535,17 +1559,17 @@ static_assert(X_MAX_LENGTH >= X_BED_SIZE && Y_MAX_LENGTH >= Y_BED_SIZE,
* Make sure HAVE_L6470DRIVER is warranted
*/
#if ENABLED(HAVE_L6470DRIVER) && !( \
- ENABLED( X_IS_L6470 ) \
- || ENABLED( X2_IS_L6470 ) \
- || ENABLED( Y_IS_L6470 ) \
- || ENABLED( Y2_IS_L6470 ) \
- || ENABLED( Z_IS_L6470 ) \
- || ENABLED( Z2_IS_L6470 ) \
- || ENABLED( E0_IS_L6470 ) \
- || ENABLED( E1_IS_L6470 ) \
- || ENABLED( E2_IS_L6470 ) \
- || ENABLED( E3_IS_L6470 ) \
- || ENABLED( E4_IS_L6470 ) \
+ ENABLED( X_IS_L6470) \
+ || ENABLED(X2_IS_L6470) \
+ || ENABLED( Y_IS_L6470) \
+ || ENABLED(Y2_IS_L6470) \
+ || ENABLED( Z_IS_L6470) \
+ || ENABLED(Z2_IS_L6470) \
+ || ENABLED(E0_IS_L6470) \
+ || ENABLED(E1_IS_L6470) \
+ || ENABLED(E2_IS_L6470) \
+ || ENABLED(E3_IS_L6470) \
+ || ENABLED(E4_IS_L6470) \
)
#error "HAVE_L6470DRIVER requires at least one L6470 stepper to be set."
#endif
diff --git a/Marlin/SdBaseFile.cpp b/Marlin/SdBaseFile.cpp
index 3460b24d3f..3754fefb32 100644
--- a/Marlin/SdBaseFile.cpp
+++ b/Marlin/SdBaseFile.cpp
@@ -368,7 +368,7 @@ int8_t SdBaseFile::lsPrintNext(uint8_t flags, uint8_t indent) {
// print size if requested
if (!DIR_IS_SUBDIR(&dir) && (flags & LS_SIZE)) {
SERIAL_CHAR(' ');
- SERIAL_PROTOCOL(dir.fileSize);
+ SERIAL_ECHO(dir.fileSize);
}
SERIAL_EOL();
return DIR_IS_FILE(&dir) ? 1 : 2;
@@ -601,7 +601,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile, const uint8_t dname[11], uint8_t ofla
// search for file
while (dirFile->curPosition_ < dirFile->fileSize_) {
- index = 0XF & (dirFile->curPosition_ >> 5);
+ index = 0xF & (dirFile->curPosition_ >> 5);
p = dirFile->readDirCache();
if (!p) return false;
@@ -705,7 +705,7 @@ bool SdBaseFile::open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag) {
return false;
}
// open cached entry
- return openCachedEntry(index & 0XF, oflag);
+ return openCachedEntry(index & 0xF, oflag);
}
// open a cached directory entry. Assumes vol_ is initialized
@@ -775,7 +775,7 @@ bool SdBaseFile::openNext(SdBaseFile* dirFile, uint8_t oflag) {
vol_ = dirFile->vol_;
while (1) {
- index = 0XF & (dirFile->curPosition_ >> 5);
+ index = 0xF & (dirFile->curPosition_ >> 5);
// read entry into cache
p = dirFile->readDirCache();
@@ -902,11 +902,10 @@ int SdBaseFile::peek() {
return c;
}
-
// print uint8_t with width 2
-static void print2u(uint8_t v) {
+static void print2u(const uint8_t v) {
if (v < 10) SERIAL_CHAR('0');
- SERIAL_PRINT(v, DEC);
+ SERIAL_ECHO_F(v, DEC);
}
/**
@@ -927,7 +926,7 @@ static void print2u(uint8_t v) {
* \param[in] fatDate The date field from a directory entry.
*/
void SdBaseFile::printFatDate(uint16_t fatDate) {
- SERIAL_PROTOCOL(FAT_YEAR(fatDate));
+ SERIAL_ECHO(FAT_YEAR(fatDate));
SERIAL_CHAR('-');
print2u(FAT_MONTH(fatDate));
SERIAL_CHAR('-');
@@ -959,7 +958,7 @@ void SdBaseFile::printFatTime(uint16_t fatTime) {
bool SdBaseFile::printName() {
char name[FILENAME_LENGTH];
if (!getFilename(name)) return false;
- SERIAL_PROTOCOL(name);
+ SERIAL_ECHO(name);
return true;
}
@@ -1104,7 +1103,7 @@ dir_t* SdBaseFile::readDirCache() {
if (!isDir()) return 0;
// index of entry in cache
- i = (curPosition_ >> 5) & 0XF;
+ i = (curPosition_ >> 5) & 0xF;
// use read to locate and cache block
if (read() < 0) return 0;
@@ -1726,8 +1725,4 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
return -1;
}
-#if ALLOW_DEPRECATED_FUNCTIONS
- void (*SdBaseFile::oldDateTime_)(uint16_t &date, uint16_t &time) = 0;
-#endif
-
#endif // SDSUPPORT
diff --git a/Marlin/SdBaseFile.h b/Marlin/SdBaseFile.h
index 425c65f9b2..12216bdc3c 100644
--- a/Marlin/SdBaseFile.h
+++ b/Marlin/SdBaseFile.h
@@ -37,6 +37,8 @@
#include "SdFatConfig.h"
#include "SdVolume.h"
+#include
+
/**
* \struct filepos_t
* \brief internal type for istream
@@ -383,119 +385,6 @@ class SdBaseFile {
bool open(SdBaseFile* dirFile, const uint8_t dname[11], uint8_t oflag);
bool openCachedEntry(uint8_t cacheIndex, uint8_t oflags);
dir_t* readDirCache();
-
-// Deprecated functions
-#if ALLOW_DEPRECATED_FUNCTIONS
- public:
-
- /**
- * \deprecated Use:
- * bool contiguousRange(uint32_t* bgnBlock, uint32_t* endBlock);
- * \param[out] bgnBlock the first block address for the file.
- * \param[out] endBlock the last block address for the file.
- * \return true for success or false for failure.
- */
- bool contiguousRange(uint32_t& bgnBlock, uint32_t& endBlock) {
- return contiguousRange(&bgnBlock, &endBlock);
- }
-
- /**
- * \deprecated Use:
- * bool createContiguous(SdBaseFile* dirFile, const char* path, uint32_t size)
- * \param[in] dirFile The directory where the file will be created.
- * \param[in] path A path with a valid DOS 8.3 file name.
- * \param[in] size The desired file size.
- * \return true for success or false for failure.
- */
- bool createContiguous(SdBaseFile& dirFile, const char* path, uint32_t size) {
- return createContiguous(&dirFile, path, size);
- }
-
- /**
- * \deprecated Use:
- * static void dateTimeCallback(
- * void (*dateTime)(uint16_t* date, uint16_t* time));
- * \param[in] dateTime The user's call back function.
- */
- static void dateTimeCallback(
- void (*dateTime)(uint16_t &date, uint16_t &time)) {
- oldDateTime_ = dateTime;
- dateTime_ = dateTime ? oldToNew : 0;
- }
-
- /**
- * \deprecated Use:
- * bool open(SdBaseFile* dirFile, const char* path, uint8_t oflag);
- * \param[in] dirFile An open SdFat instance for the directory containing the
- * file to be opened.
- * \param[in] path A path with a valid 8.3 DOS name for the file.
- * \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive
- * OR of flags O_READ, O_WRITE, O_TRUNC, and O_SYNC.
- * \return true for success or false for failure.
- */
- bool open(SdBaseFile& dirFile, const char* path, uint8_t oflag) {
- return open(&dirFile, path, oflag);
- }
-
- /**
- * \deprecated Do not use in new apps
- * \param[in] dirFile An open SdFat instance for the directory containing the
- * file to be opened.
- * \param[in] path A path with a valid 8.3 DOS name for a file to be opened.
- * \return true for success or false for failure.
- */
- bool open(SdBaseFile& dirFile, const char* path) {
- return open(dirFile, path, O_RDWR);
- }
-
- /**
- * \deprecated Use:
- * bool open(SdBaseFile* dirFile, uint16_t index, uint8_t oflag);
- * \param[in] dirFile An open SdFat instance for the directory.
- * \param[in] index The \a index of the directory entry for the file to be
- * opened. The value for \a index is (directory file position)/32.
- * \param[in] oflag Values for \a oflag are constructed by a bitwise-inclusive
- * OR of flags O_READ, O_WRITE, O_TRUNC, and O_SYNC.
- * \return true for success or false for failure.
- */
- bool open(SdBaseFile& dirFile, uint16_t index, uint8_t oflag) {
- return open(&dirFile, index, oflag);
- }
-
- /**
- * \deprecated Use: bool openRoot(SdVolume* vol);
- * \param[in] vol The FAT volume containing the root directory to be opened.
- * \return true for success or false for failure.
- */
- bool openRoot(SdVolume& vol) { return openRoot(&vol); }
-
- /**
- * \deprecated Use: int8_t readDir(dir_t* dir);
- * \param[out] dir The dir_t struct that will receive the data.
- * \return bytes read for success zero for eof or -1 for failure.
- */
- int8_t readDir(dir_t& dir, char* longFilename) {
- return readDir(&dir, longFilename);
- }
-
- /**
- * \deprecated Use:
- * static uint8_t remove(SdBaseFile* dirFile, const char* path);
- * \param[in] dirFile The directory that contains the file.
- * \param[in] path The name of the file to be removed.
- * \return true for success or false for failure.
- */
- static bool remove(SdBaseFile& dirFile, const char* path) { return remove(&dirFile, path); }
-
- private:
- static void (*oldDateTime_)(uint16_t &date, uint16_t &time);
- static void oldToNew(uint16_t * const date, uint16_t * const time) {
- uint16_t d, t;
- oldDateTime_(d, t);
- *date = d;
- *time = t;
- }
-#endif // ALLOW_DEPRECATED_FUNCTIONS
};
#endif // _SDBASEFILE_H_
diff --git a/Marlin/SdFatConfig.h b/Marlin/SdFatConfig.h
index 606a66f171..cfa5e34d18 100644
--- a/Marlin/SdFatConfig.h
+++ b/Marlin/SdFatConfig.h
@@ -61,11 +61,6 @@
*/
#define ENDL_CALLS_FLUSH 0
-/**
- * Allow use of deprecated functions if ALLOW_DEPRECATED_FUNCTIONS is nonzero
- */
-#define ALLOW_DEPRECATED_FUNCTIONS 1
-
/**
* Allow FAT12 volumes if FAT12_SUPPORT is nonzero.
* FAT12 has not been well tested.
diff --git a/Marlin/SdVolume.cpp b/Marlin/SdVolume.cpp
index bf8abc5797..df781cb6b6 100644
--- a/Marlin/SdVolume.cpp
+++ b/Marlin/SdVolume.cpp
@@ -204,7 +204,7 @@ bool SdVolume::fatPut(uint32_t cluster, uint32_t value) {
index &= 0x1FF;
uint8_t tmp = value;
if (cluster & 1) {
- tmp = (cacheBuffer_.data[index] & 0XF) | tmp << 4;
+ tmp = (cacheBuffer_.data[index] & 0xF) | tmp << 4;
}
cacheBuffer_.data[index] = tmp;
index++;
diff --git a/Marlin/Version.h b/Marlin/Version.h
index cd02b97b9a..d151303ea9 100644
--- a/Marlin/Version.h
+++ b/Marlin/Version.h
@@ -35,7 +35,7 @@
/**
* Marlin release version identifier
*/
- #define SHORT_BUILD_VERSION "TM3D-1.1.8_M1"
+ #define SHORT_BUILD_VERSION "TM3D-1.1.8_M2"
/**
* Verbose version identifier which should contain a reference to the location
@@ -48,7 +48,7 @@
* here we define this default string as the date where the latest release
* version was tagged.
*/
- #define STRING_DISTRIBUTION_DATE "2018-04-26"
+ #define STRING_DISTRIBUTION_DATE "2018-07-07"
/**
* Required minimum Configuration.h and Configuration_adv.h file versions.
diff --git a/Marlin/boards.h b/Marlin/boards.h
index a7aceff081..18912cedab 100644
--- a/Marlin/boards.h
+++ b/Marlin/boards.h
@@ -156,6 +156,6 @@
#define BOARD_TEENSY2 84 // Teensy++2.0 (AT90USB1286) - CLI compile: HARDWARE_MOTHERBOARD=84 make
#define BOARD_5DPRINT 88 // 5DPrint D8 Driver Board
-#define MB(board) (MOTHERBOARD==BOARD_##board)
+#define MB(board) (defined(BOARD_##board) && MOTHERBOARD==BOARD_##board)
#endif // __BOARDS_H
diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp
index 581e0ec5af..5c4ff5e7d0 100644
--- a/Marlin/cardreader.cpp
+++ b/Marlin/cardreader.cpp
@@ -54,15 +54,13 @@ CardReader::CardReader() {
workDirDepth = 0;
ZERO(workDirParents);
- autostart_stilltocheck = true; //the SD start is delayed, because otherwise the serial cannot answer fast enough to make contact with the host software.
- autostart_index = 0;
+ // Disable autostart until card is initialized
+ autostart_index = -1;
//power to SD reader
#if SDPOWER > -1
OUT_WRITE(SDPOWER, HIGH);
- #endif // SDPOWER
-
- next_autostart_ms = millis() + 5000;
+ #endif
}
char *createFilename(char *buffer, const dir_t &p) { //buffer > 12characters
@@ -90,25 +88,25 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
uint8_t cnt = 0;
// Read the next entry from a directory
- while (parent.readDir(p, longFilename) > 0) {
+ while (parent.readDir(&p, longFilename) > 0) {
// If the entry is a directory and the action is LS_SerialPrint
if (DIR_IS_SUBDIR(&p) && lsAction != LS_Count && lsAction != LS_GetFilename) {
// Get the short name for the item, which we know is a folder
- char lfilename[FILENAME_LENGTH];
- createFilename(lfilename, p);
+ char dosFilename[FILENAME_LENGTH];
+ createFilename(dosFilename, p);
// Allocate enough stack space for the full path to a folder, trailing slash, and nul
- bool prepend_is_empty = (prepend[0] == '\0');
- int len = (prepend_is_empty ? 1 : strlen(prepend)) + strlen(lfilename) + 1 + 1;
+ const bool prepend_is_empty = (!prepend || prepend[0] == '\0');
+ const int len = (prepend_is_empty ? 1 : strlen(prepend)) + strlen(dosFilename) + 1 + 1;
char path[len];
// Append the FOLDERNAME12/ to the passed string.
// It contains the full path to the "parent" argument.
// We now have the full path to the item in this folder.
strcpy(path, prepend_is_empty ? "/" : prepend); // root slash if prepend is empty
- strcat(path, lfilename); // FILENAME_LENGTH-1 characters maximum
+ strcat(path, dosFilename); // FILENAME_LENGTH-1 characters maximum
strcat(path, "/"); // 1 character
// Serial.print(path);
@@ -116,11 +114,11 @@ void CardReader::lsDive(const char *prepend, SdFile parent, const char * const m
// Get a new directory object using the full path
// and dive recursively into it.
SdFile dir;
- if (!dir.open(parent, lfilename, O_READ)) {
+ if (!dir.open(&parent, dosFilename, O_READ)) {
if (lsAction == LS_SerialPrint) {
SERIAL_ECHO_START();
SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
- SERIAL_ECHOLN(lfilename);
+ SERIAL_ECHOLN(dosFilename);
}
}
lsDive(path, dir);
@@ -216,7 +214,7 @@ void CardReader::ls() {
// Open the sub-item as the new dive parent
SdFile dir;
- if (!dir.open(diveDir, segment, O_READ)) {
+ if (!dir.open(&diveDir, segment, O_READ)) {
SERIAL_EOL();
SERIAL_ECHO_START();
SERIAL_ECHOPGM(MSG_SD_CANT_OPEN_SUBDIR);
@@ -239,11 +237,11 @@ void CardReader::ls() {
*/
void CardReader::printFilename() {
if (file.isOpen()) {
- char lfilename[FILENAME_LENGTH];
- file.getFilename(lfilename);
- SERIAL_ECHO(lfilename);
+ char dosFilename[FILENAME_LENGTH];
+ file.getFilename(dosFilename);
+ SERIAL_ECHO(dosFilename);
#if ENABLED(LONG_FILENAME_HOST_SUPPORT)
- getfilename(0, lfilename);
+ getfilename(0, dosFilename);
if (longFilename[0]) {
SERIAL_ECHO(' ');
SERIAL_ECHO(longFilename);
@@ -264,16 +262,16 @@ void CardReader::initsd() {
#define SPI_SPEED SPI_FULL_SPEED
#endif
- if (!card.init(SPI_SPEED, SDSS)
+ if (!sd2card.init(SPI_SPEED, SDSS)
#if defined(LCD_SDSS) && (LCD_SDSS != SDSS)
- && !card.init(SPI_SPEED, LCD_SDSS)
+ && !sd2card.init(SPI_SPEED, LCD_SDSS)
#endif
) {
- //if (!card.init(SPI_HALF_SPEED,SDSS))
+ //if (!sd2card.init(SPI_HALF_SPEED,SDSS))
SERIAL_ECHO_START();
SERIAL_ECHOLNPGM(MSG_SD_INIT_FAIL);
}
- else if (!volume.init(&card)) {
+ else if (!volume.init(&sd2card)) {
SERIAL_ERROR_START();
SERIAL_ERRORLNPGM(MSG_SD_VOL_INIT_FAIL);
}
@@ -289,17 +287,6 @@ void CardReader::initsd() {
setroot();
}
-void CardReader::setroot() {
- /*if (!workDir.openRoot(&volume)) {
- SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
- }*/
- workDir = root;
- curDir = &workDir;
- #if ENABLED(SDCARD_SORT_ALPHA)
- presort();
- #endif
-}
-
void CardReader::release() {
sdprinting = false;
cardOK = false;
@@ -337,9 +324,9 @@ void CardReader::stopSDPrint(
#endif
}
-void CardReader::openLogFile(char* name) {
+void CardReader::openLogFile(char * const path) {
logging = true;
- openFile(name, false);
+ openFile(path, false);
}
void appendAtom(SdFile &file, char *& dst, uint8_t &cnt) {
@@ -362,7 +349,7 @@ void CardReader::getAbsFilename(char *t) {
*t = '\0';
}
-void CardReader::openFile(char* name, const bool read, const bool subcall/*=false*/) {
+void CardReader::openFile(char * const path, const bool read, const bool subcall/*=false*/) {
if (!cardOK) return;
@@ -382,7 +369,7 @@ void CardReader::openFile(char* name, const bool read, const bool subcall/*=fals
filespos[file_subcall_ctr] = sdpos;
SERIAL_ECHO_START();
- SERIAL_ECHOPAIR("SUBROUTINE CALL target:\"", name);
+ SERIAL_ECHOPAIR("SUBROUTINE CALL target:\"", path);
SERIAL_ECHOPAIR("\" parent:\"", proc_filenames[file_subcall_ctr]);
SERIAL_ECHOLNPAIR("\" pos", sdpos);
file_subcall_ctr++;
@@ -403,48 +390,14 @@ void CardReader::openFile(char* name, const bool read, const bool subcall/*=fals
SERIAL_ECHO_START();
SERIAL_ECHOPGM("Now ");
serialprintPGM(doing == 1 ? PSTR("doing") : PSTR("fresh"));
- SERIAL_ECHOLNPAIR(" file: ", name);
+ SERIAL_ECHOLNPAIR(" file: ", path);
}
stopSDPrint();
- SdFile myDir;
- curDir = &root;
- char *fname = name;
- char *dirname_start, *dirname_end;
-
- if (name[0] == '/') {
- dirname_start = &name[1];
- while (dirname_start != NULL) {
- dirname_end = strchr(dirname_start, '/');
- //SERIAL_ECHOPGM("start:");SERIAL_ECHOLN((int)(dirname_start - name));
- //SERIAL_ECHOPGM("end :");SERIAL_ECHOLN((int)(dirname_end - name));
- if (dirname_end != NULL && dirname_end > dirname_start) {
- char subdirname[FILENAME_LENGTH];
- strncpy(subdirname, dirname_start, dirname_end - dirname_start);
- subdirname[dirname_end - dirname_start] = '\0';
- if (!myDir.open(curDir, subdirname, O_READ)) {
- SERIAL_PROTOCOLPAIR(MSG_SD_OPEN_FILE_FAIL, subdirname);
- SERIAL_PROTOCOLCHAR('.');
- return;
- }
- else {
- //SERIAL_ECHOLNPGM("dive ok");
- }
-
- curDir = &myDir;
- dirname_start = dirname_end + 1;
- }
- else { // the remainder after all /fsa/fdsa/ is the filename
- fname = dirname_start;
- //SERIAL_ECHOLNPGM("remainder");
- //SERIAL_ECHOLN(fname);
- break;
- }
- }
- }
- else
- curDir = &workDir; // Relative paths start in current directory
+ SdFile *curDir;
+ const char * const fname = diveToFile(curDir, path, false);
+ if (!fname) return;
if (read) {
if (file.open(curDir, fname, O_READ)) {
@@ -474,7 +427,7 @@ void CardReader::openFile(char* name, const bool read, const bool subcall/*=fals
}
else {
saving = true;
- SERIAL_PROTOCOLLNPAIR(MSG_SD_WRITE_TO_FILE, name);
+ SERIAL_PROTOCOLLNPAIR(MSG_SD_WRITE_TO_FILE, path);
lcd_setstatus(fname);
}
}
@@ -485,40 +438,9 @@ void CardReader::removeFile(const char * const name) {
stopSDPrint();
- SdFile myDir;
- curDir = &root;
- const char *fname = name;
-
- char *dirname_start, *dirname_end;
- if (name[0] == '/') {
- dirname_start = strchr(name, '/') + 1;
- while (dirname_start != NULL) {
- dirname_end = strchr(dirname_start, '/');
- //SERIAL_ECHOPGM("start:");SERIAL_ECHOLN((int)(dirname_start - name));
- //SERIAL_ECHOPGM("end :");SERIAL_ECHOLN((int)(dirname_end - name));
- if (dirname_end != NULL && dirname_end > dirname_start) {
- char subdirname[FILENAME_LENGTH];
- strncpy(subdirname, dirname_start, dirname_end - dirname_start);
- subdirname[dirname_end - dirname_start] = 0;
- SERIAL_ECHOLN(subdirname);
- if (!myDir.open(curDir, subdirname, O_READ)) {
- SERIAL_PROTOCOLPAIR(MSG_SD_OPEN_FILE_FAIL, subdirname);
- SERIAL_PROTOCOLCHAR('.');
- SERIAL_EOL();
- return;
- }
-
- curDir = &myDir;
- dirname_start = dirname_end + 1;
- }
- else {
- fname = dirname_start;
- break;
- }
- }
- }
- else // Relative paths are rooted in the current directory
- curDir = &workDir;
+ SdFile *curDir;
+ const char * const fname = diveToFile(curDir, name, false);
+ if (!fname) return;
if (file.remove(curDir, fname)) {
SERIAL_PROTOCOLPGM("File deleted:");
@@ -566,40 +488,46 @@ void CardReader::write_command(char *buf) {
}
}
-void CardReader::checkautostart(bool force) {
- if (!force && (!autostart_stilltocheck || PENDING(millis(), next_autostart_ms)))
- return;
+//
+// Run the next autostart file. Called:
+// - On boot after successful card init
+// - After finishing the previous autostart file
+// - From the LCD command to run the autostart file
+//
- autostart_stilltocheck = false;
+void CardReader::checkautostart() {
- if (!cardOK) {
- initsd();
- if (!cardOK) return; // fail
- }
+ if (autostart_index < 0 || sdprinting) return;
- char autoname[10];
- sprintf_P(autoname, PSTR("auto%i.g"), autostart_index);
- for (int8_t i = 0; i < (int8_t)strlen(autoname); i++) autoname[i] = tolower(autoname[i]);
+ if (!cardOK) initsd();
- dir_t p;
-
- root.rewind();
-
- bool found = false;
- while (root.readDir(p, NULL) > 0) {
- for (int8_t i = (int8_t)strlen((char*)p.name); i--;) p.name[i] = tolower(p.name[i]);
- if (p.name[9] != '~' && strncmp((char*)p.name, autoname, 5) == 0) {
- openAndPrintFile(autoname);
- found = true;
+ if (cardOK
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ && !jobRecoverFileExists() // Don't run auto#.g when a resume file exists
+ #endif
+ ) {
+ char autoname[10];
+ sprintf_P(autoname, PSTR("auto%i.g"), int(autostart_index));
+ dir_t p;
+ root.rewind();
+ while (root.readDir(&p, NULL) > 0) {
+ for (int8_t i = (int8_t)strlen((char*)p.name); i--;) p.name[i] = tolower(p.name[i]);
+ if (p.name[9] != '~' && strncmp((char*)p.name, autoname, 5) == 0) {
+ openAndPrintFile(autoname);
+ autostart_index++;
+ return;
+ }
}
}
- if (!found)
- autostart_index = -1;
- else
- autostart_index++;
+ autostart_index = -1;
}
-void CardReader::closefile(bool store_location) {
+void CardReader::beginautostart() {
+ autostart_index = 0;
+ setroot();
+}
+
+void CardReader::closefile(const bool store_location) {
file.sync();
file.close();
saving = logging = false;
@@ -612,6 +540,7 @@ void CardReader::closefile(bool store_location) {
/**
* Get the name of a file in the current directory by index
+ * with optional name to match.
*/
void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) {
#if ENABLED(SDSORT_CACHE_NAMES)
@@ -628,35 +557,59 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) {
return;
}
#endif // SDSORT_CACHE_NAMES
- curDir = &workDir;
lsAction = LS_GetFilename;
nrFile_index = nr;
- curDir->rewind();
- lsDive(NULL, *curDir, match);
+ workDir.rewind();
+ lsDive(NULL, workDir, match);
}
uint16_t CardReader::getnrfilenames() {
- curDir = &workDir;
lsAction = LS_Count;
nrFiles = 0;
- curDir->rewind();
- lsDive(NULL, *curDir);
+ workDir.rewind();
+ lsDive(NULL, workDir);
//SERIAL_ECHOLN(nrFiles);
return nrFiles;
}
+/**
+ * Dive to the given file path, with optional echo.
+ * On exit set curDir and return the name part of the path.
+ * A NULL result indicates an unrecoverable error.
+ */
+const char* CardReader::diveToFile(SdFile*& curDir, const char * const path, const bool echo) {
+ SdFile myDir;
+ if (path[0] != '/') { curDir = &workDir; return path; }
+
+ curDir = &root;
+ const char *dirname_start = &path[1];
+ while (dirname_start) {
+ char * const dirname_end = strchr(dirname_start, '/');
+ if (dirname_end <= dirname_start) break;
+ const uint8_t len = dirname_end - dirname_start;
+ char dosSubdirname[len + 1];
+ strncpy(dosSubdirname, dirname_start, len);
+ dosSubdirname[len] = 0;
+
+ if (echo) SERIAL_ECHOLN(dosSubdirname);
+
+ if (!myDir.open(curDir, dosSubdirname, O_READ)) {
+ SERIAL_PROTOCOLPAIR(MSG_SD_OPEN_FILE_FAIL, dosSubdirname);
+ SERIAL_PROTOCOLCHAR('.');
+ SERIAL_EOL();
+ return NULL;
+ }
+ curDir = &myDir;
+ dirname_start = dirname_end + 1;
+ }
+ return dirname_start;
+}
+
void CardReader::chdir(const char * relpath) {
SdFile newDir;
- SdFile *parent = &root;
+ SdFile *parent = workDir.isOpen() ? &workDir : &root;
- if (workDir.isOpen()) parent = &workDir;
-
- if (!newDir.open(*parent, relpath, O_READ)) {
- SERIAL_ECHO_START();
- SERIAL_ECHOPGM(MSG_SD_CANT_ENTER_SUBDIR);
- SERIAL_ECHOLN(relpath);
- }
- else {
+ if (newDir.open(parent, relpath, O_READ)) {
workDir = newDir;
if (workDirDepth < MAX_DIR_DEPTH)
workDirParents[workDirDepth++] = workDir;
@@ -664,6 +617,11 @@ void CardReader::chdir(const char * relpath) {
presort();
#endif
}
+ else {
+ SERIAL_ECHO_START();
+ SERIAL_ECHOPGM(MSG_SD_CANT_ENTER_SUBDIR);
+ SERIAL_ECHOLN(relpath);
+ }
}
int8_t CardReader::updir() {
@@ -676,6 +634,16 @@ int8_t CardReader::updir() {
return workDirDepth;
}
+void CardReader::setroot() {
+ /*if (!workDir.openRoot(&volume)) {
+ SERIAL_ECHOLNPGM(MSG_SD_WORKDIR_FAIL);
+ }*/
+ workDir = root;
+ #if ENABLED(SDCARD_SORT_ALPHA)
+ presort();
+ #endif
+}
+
#if ENABLED(SDCARD_SORT_ALPHA)
/**
@@ -921,7 +889,7 @@ uint16_t CardReader::get_num_Files() {
}
void CardReader::printingHasFinished() {
- stepper.synchronize();
+ planner.synchronize();
file.close();
if (file_subcall_ctr > 0) { // Heading up to a parent file that called current as a procedure.
file_subcall_ctr--;
@@ -933,15 +901,11 @@ void CardReader::printingHasFinished() {
sdprinting = false;
#if ENABLED(POWER_LOSS_RECOVERY)
- openJobRecoveryFile(false);
- job_recovery_info.valid_head = job_recovery_info.valid_foot = 0;
- (void)saveJobRecoveryInfo();
- closeJobRecoveryFile();
- job_recovery_commands_count = 0;
+ removeJobRecoveryFile();
#endif
#if ENABLED(SD_FINISHED_STEPPERRELEASE) && defined(SD_FINISHED_RELEASECOMMAND)
- stepper.cleaning_buffer_counter = 1; // The command will fire from the Stepper ISR
+ planner.finish_and_disable();
#endif
print_job_timer.stop();
if (print_job_timer.duration() > 60)
@@ -983,20 +947,24 @@ void CardReader::printingHasFinished() {
SERIAL_PROTOCOLCHAR('.');
SERIAL_EOL();
}
- else
+ else if (!read)
SERIAL_PROTOCOLLNPAIR(MSG_SD_WRITE_TO_FILE, job_recovery_file_name);
}
void CardReader::closeJobRecoveryFile() { jobRecoveryFile.close(); }
bool CardReader::jobRecoverFileExists() {
- return jobRecoveryFile.open(&root, job_recovery_file_name, O_READ);
+ const bool exists = jobRecoveryFile.open(&root, job_recovery_file_name, O_READ);
+ if (exists) jobRecoveryFile.close();
+ return exists;
}
int16_t CardReader::saveJobRecoveryInfo() {
jobRecoveryFile.seekSet(0);
const int16_t ret = jobRecoveryFile.write(&job_recovery_info, sizeof(job_recovery_info));
- if (ret == -1) SERIAL_PROTOCOLLNPGM("Power-loss file write failed.");
+ #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
+ if (ret == -1) SERIAL_PROTOCOLLNPGM("Power-loss file write failed.");
+ #endif
return ret;
}
@@ -1005,10 +973,15 @@ void CardReader::printingHasFinished() {
}
void CardReader::removeJobRecoveryFile() {
- if (jobRecoveryFile.remove(&root, job_recovery_file_name))
- SERIAL_PROTOCOLLNPGM("Power-loss file deleted.");
- else
- SERIAL_PROTOCOLLNPGM("Power-loss file delete failed.");
+ job_recovery_info.valid_head = job_recovery_info.valid_foot = job_recovery_commands_count = 0;
+ if (jobRecoverFileExists()) {
+ closefile();
+ removeFile(job_recovery_file_name);
+ #if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
+ SERIAL_PROTOCOLPGM("Power-loss file delete");
+ serialprintPGM(jobRecoverFileExists() ? PSTR(" failed.\n") : PSTR("d.\n"));
+ #endif
+ }
}
#endif // POWER_LOSS_RECOVERY
diff --git a/Marlin/cardreader.h b/Marlin/cardreader.h
index a7bb1cd46f..15275c0729 100644
--- a/Marlin/cardreader.h
+++ b/Marlin/cardreader.h
@@ -32,8 +32,6 @@
#define MAX_DIR_DEPTH 10 // Maximum folder depth
#include "SdFile.h"
-#include "types.h"
-#include "enum.h"
class CardReader {
public:
@@ -41,16 +39,14 @@ public:
void initsd();
void write_command(char *buf);
- // Files auto[0-9].g on the sd card are performed in sequence.
- // This is to delay autostart and hence the initialisation of
- // the sd card to some seconds after the normal init, so the
- // device is available soon after a reset.
- void checkautostart(bool x);
- void openFile(char* name, const bool read, const bool subcall=false);
- void openLogFile(char* name);
+ void beginautostart();
+ void checkautostart();
+
+ void openFile(char * const path, const bool read, const bool subcall=false);
+ void openLogFile(char * const path);
void removeFile(const char * const name);
- void closefile(bool store_location=false);
+ void closefile(const bool store_location=false);
void release();
void openAndPrintFile(const char *name);
void startFileprint();
@@ -77,6 +73,8 @@ public:
int8_t updir();
void setroot();
+ const char* diveToFile(SdFile*& curDir, const char * const path, const bool echo);
+
uint16_t get_num_Files();
#if ENABLED(SDCARD_SORT_ALPHA)
@@ -116,12 +114,12 @@ public:
}
#endif
+public:
bool saving, logging, sdprinting, cardOK, filenameIsDir;
char filename[FILENAME_LENGTH], longFilename[LONG_FILENAME_LENGTH];
- int autostart_index;
-
+ int8_t autostart_index;
private:
- SdFile root, *curDir, workDir, workDirParents[MAX_DIR_DEPTH];
+ SdFile root, workDir, workDirParents[MAX_DIR_DEPTH];
uint8_t workDirDepth;
// Sort files and folders alphabetically.
@@ -174,7 +172,7 @@ private:
#endif // SDCARD_SORT_ALPHA
- Sd2Card card;
+ Sd2Card sd2card;
SdVolume volume;
SdFile file;
@@ -189,9 +187,6 @@ private:
char proc_filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH];
uint32_t filesize, sdpos;
- millis_t next_autostart_ms;
- bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
-
LsAction lsAction; //stored for recursion.
uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory.
char* diveDirName;
diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp
index a6632a6bcf..57d9de0e92 100644
--- a/Marlin/configuration_store.cpp
+++ b/Marlin/configuration_store.cpp
@@ -37,7 +37,7 @@
*/
// Change EEPROM version if the structure changes
-#define EEPROM_VERSION "V54"
+#define EEPROM_VERSION "V55"
#define EEPROM_OFFSET 100
// Check the integrity of data offsets.
@@ -62,7 +62,7 @@
#if HAS_TRINAMIC
#include "stepper_indirection.h"
#include "tmc_util.h"
- #define TMC_GET_PWMTHRS(P,Q) _tmc_thrs(stepper##Q.microsteps(), stepper##Q.TPWMTHRS(), planner.axis_steps_per_mm[P##_AXIS])
+ #define TMC_GET_PWMTHRS(A,Q) _tmc_thrs(stepper##Q.microsteps(), stepper##Q.TPWMTHRS(), planner.axis_steps_per_mm[_AXIS(A)])
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL)
@@ -73,6 +73,10 @@
#include "fwretract.h"
#endif
+#if ENABLED(PID_EXTRUSION_SCALING)
+ #define LPQ_LEN thermalManager.lpq_len
+#endif
+
#pragma pack(push, 1) // No padding between variables
typedef struct PID { float Kp, Ki, Kd; } PID;
@@ -93,16 +97,17 @@ typedef struct SettingsDataStruct {
//
uint8_t esteppers; // XYZE_N - XYZ
+ uint32_t planner_max_acceleration_mm_per_s2[XYZE_N], // M201 XYZE planner.max_acceleration_mm_per_s2[XYZE_N]
+ planner_min_segment_time_us; // M205 B planner.min_segment_time_us
float planner_axis_steps_per_mm[XYZE_N], // M92 XYZE planner.axis_steps_per_mm[XYZE_N]
- planner_max_feedrate_mm_s[XYZE_N]; // M203 XYZE planner.max_feedrate_mm_s[XYZE_N]
- uint32_t planner_max_acceleration_mm_per_s2[XYZE_N]; // M201 XYZE planner.max_acceleration_mm_per_s2[XYZE_N]
- float planner_acceleration, // M204 P planner.acceleration
+ planner_max_feedrate_mm_s[XYZE_N], // M203 XYZE planner.max_feedrate_mm_s[XYZE_N]
+ planner_acceleration, // M204 P planner.acceleration
planner_retract_acceleration, // M204 R planner.retract_acceleration
planner_travel_acceleration, // M204 T planner.travel_acceleration
planner_min_feedrate_mm_s, // M205 S planner.min_feedrate_mm_s
- planner_min_travel_feedrate_mm_s; // M205 T planner.min_travel_feedrate_mm_s
- uint32_t planner_min_segment_time_us; // M205 B planner.min_segment_time_us
- float planner_max_jerk[XYZE]; // M205 XYZE planner.max_jerk[XYZE]
+ planner_min_travel_feedrate_mm_s, // M205 T planner.min_travel_feedrate_mm_s
+ planner_max_jerk[XYZE], // M205 XYZE planner.max_jerk[XYZE]
+ planner_junction_deviation_mm; // M205 J planner.junction_deviation_mm
float home_offset[XYZ]; // M206 XYZ
@@ -183,7 +188,7 @@ typedef struct SettingsDataStruct {
//
PIDC hotendPID[MAX_EXTRUDERS]; // M301 En PIDC / M303 En U
- int lpq_len; // M301 L
+ int16_t lpq_len; // M301 L
//
// PIDTEMPBED
@@ -314,6 +319,10 @@ void MarlinSettings::postprocess() {
fwretract.refresh_autoretract();
#endif
+ #if ENABLED(JUNCTION_DEVIATION) && ENABLED(LIN_ADVANCE)
+ planner.recalculate_max_e_jerk();
+ #endif
+
// Refresh steps_to_mm with the reciprocal of axis_steps_per_mm
// and init stepper.count[], planner.position[] with current_position
planner.refresh_positioning();
@@ -393,7 +402,7 @@ void MarlinSettings::postprocess() {
* M500 - Store Configuration
*/
bool MarlinSettings::save() {
- float dummy = 0.0f;
+ float dummy = 0;
char ver[4] = "ERR";
uint16_t working_crc = 0;
@@ -412,17 +421,25 @@ void MarlinSettings::postprocess() {
const uint8_t esteppers = COUNT(planner.axis_steps_per_mm) - XYZ;
EEPROM_WRITE(esteppers);
+ EEPROM_WRITE(planner.max_acceleration_mm_per_s2);
+ EEPROM_WRITE(planner.min_segment_time_us);
EEPROM_WRITE(planner.axis_steps_per_mm);
EEPROM_WRITE(planner.max_feedrate_mm_s);
- EEPROM_WRITE(planner.max_acceleration_mm_per_s2);
-
EEPROM_WRITE(planner.acceleration);
EEPROM_WRITE(planner.retract_acceleration);
EEPROM_WRITE(planner.travel_acceleration);
EEPROM_WRITE(planner.min_feedrate_mm_s);
EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
- EEPROM_WRITE(planner.min_segment_time_us);
- EEPROM_WRITE(planner.max_jerk);
+
+ #if ENABLED(JUNCTION_DEVIATION)
+ const float planner_max_jerk[] = { float(DEFAULT_XJERK), float(DEFAULT_YJERK), float(DEFAULT_ZJERK), float(DEFAULT_EJERK) };
+ EEPROM_WRITE(planner_max_jerk);
+ EEPROM_WRITE(planner.junction_deviation_mm);
+ #else
+ EEPROM_WRITE(planner.max_jerk);
+ dummy = 0.02f;
+ EEPROM_WRITE(dummy);
+ #endif
_FIELD_TEST(home_offset);
@@ -464,7 +481,7 @@ void MarlinSettings::postprocess() {
EEPROM_WRITE(mesh_num_y);
EEPROM_WRITE(mbl.z_values);
#else // For disabled MBL write a default mesh
- dummy = 0.0f;
+ dummy = 0;
const uint8_t mesh_num_x = 3, mesh_num_y = 3;
EEPROM_WRITE(dummy); // z_offset
EEPROM_WRITE(mesh_num_x);
@@ -486,7 +503,7 @@ void MarlinSettings::postprocess() {
#if ABL_PLANAR
EEPROM_WRITE(planner.bed_level_matrix);
#else
- dummy = 0.0;
+ dummy = 0;
for (uint8_t q = 9; q--;) EEPROM_WRITE(dummy);
#endif
@@ -510,7 +527,7 @@ void MarlinSettings::postprocess() {
// For disabled Bilinear Grid write an empty 3x3 grid
const uint8_t grid_max_x = 3, grid_max_y = 3;
const int bilinear_start[2] = { 0 }, bilinear_grid_spacing[2] = { 0 };
- dummy = 0.0f;
+ dummy = 0;
EEPROM_WRITE(grid_max_x);
EEPROM_WRITE(grid_max_y);
EEPROM_WRITE(bilinear_grid_spacing);
@@ -548,7 +565,7 @@ void MarlinSettings::postprocess() {
_FIELD_TEST(x_endstop_adj);
// Write dual endstops in X, Y, Z order. Unused = 0.0
- dummy = 0.0f;
+ dummy = 0;
#if ENABLED(X_DUAL_ENDSTOPS)
EEPROM_WRITE(endstops.x_endstop_adj); // 1 float
#else
@@ -600,7 +617,7 @@ void MarlinSettings::postprocess() {
{
dummy = DUMMY_PID_VALUE; // When read, will not change the existing value
EEPROM_WRITE(dummy); // Kp
- dummy = 0.0f;
+ dummy = 0;
for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy); // Ki, Kd, Kc
}
@@ -609,9 +626,9 @@ void MarlinSettings::postprocess() {
_FIELD_TEST(lpq_len);
#if DISABLED(PID_EXTRUSION_SCALING)
- int lpq_len = 20;
+ const int16_t LPQ_LEN = 20;
#endif
- EEPROM_WRITE(lpq_len);
+ EEPROM_WRITE(LPQ_LEN);
#if DISABLED(PIDTEMPBED)
dummy = DUMMY_PID_VALUE;
@@ -846,7 +863,7 @@ void MarlinSettings::postprocess() {
#if ENABLED(LIN_ADVANCE)
EEPROM_WRITE(planner.extruder_advance_K);
#else
- dummy = 0.0f;
+ dummy = 0;
EEPROM_WRITE(dummy);
#endif
@@ -868,7 +885,7 @@ void MarlinSettings::postprocess() {
#if ENABLED(CNC_COORDINATE_SYSTEMS)
EEPROM_WRITE(coordinate_system); // 27 floats
#else
- dummy = 0.0f;
+ dummy = 0;
for (uint8_t q = MAX_COORDINATE_SYSTEMS * XYZ; q--;) EEPROM_WRITE(dummy);
#endif
@@ -883,7 +900,7 @@ void MarlinSettings::postprocess() {
EEPROM_WRITE(planner.xz_skew_factor);
EEPROM_WRITE(planner.yz_skew_factor);
#else
- dummy = 0.0f;
+ dummy = 0;
for (uint8_t q = 3; q--;) EEPROM_WRITE(dummy);
#endif
@@ -903,7 +920,7 @@ void MarlinSettings::postprocess() {
EEPROM_WRITE(dummy);
}
#else
- dummy = 0.0f;
+ dummy = 0;
for (uint8_t q = MAX_EXTRUDERS * 2; q--;) EEPROM_WRITE(dummy);
#endif
@@ -968,7 +985,6 @@ void MarlinSettings::postprocess() {
SERIAL_ECHOPAIR("(EEPROM=", stored_ver);
SERIAL_ECHOLNPGM(" Marlin=" EEPROM_VERSION ")");
#endif
- if (!validating) reset();
eeprom_error = true;
}
else {
@@ -991,17 +1007,20 @@ void MarlinSettings::postprocess() {
// Get only the number of E stepper parameters previously stored
// Any steppers added later are set to their defaults
- const float def1[] = DEFAULT_AXIS_STEPS_PER_UNIT, def2[] = DEFAULT_MAX_FEEDRATE;
- const uint32_t def3[] = DEFAULT_MAX_ACCELERATION;
- float tmp1[XYZ + esteppers], tmp2[XYZ + esteppers];
- uint32_t tmp3[XYZ + esteppers];
- EEPROM_READ(tmp1);
- EEPROM_READ(tmp2);
- EEPROM_READ(tmp3);
+ const uint32_t def1[] = DEFAULT_MAX_ACCELERATION;
+ const float def2[] = DEFAULT_AXIS_STEPS_PER_UNIT, def3[] = DEFAULT_MAX_FEEDRATE;
+
+ uint32_t tmp1[XYZ + esteppers];
+ EEPROM_READ(tmp1); // max_acceleration_mm_per_s2
+ EEPROM_READ(planner.min_segment_time_us);
+
+ float tmp2[XYZ + esteppers], tmp3[XYZ + esteppers];
+ EEPROM_READ(tmp2); // axis_steps_per_mm
+ EEPROM_READ(tmp3); // max_feedrate_mm_s
if (!validating) LOOP_XYZE_N(i) {
- planner.axis_steps_per_mm[i] = i < XYZ + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1];
- planner.max_feedrate_mm_s[i] = i < XYZ + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1];
- planner.max_acceleration_mm_per_s2[i] = i < XYZ + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1];
+ planner.max_acceleration_mm_per_s2[i] = i < XYZ + esteppers ? tmp1[i] : def1[i < COUNT(def1) ? i : COUNT(def1) - 1];
+ planner.axis_steps_per_mm[i] = i < XYZ + esteppers ? tmp2[i] : def2[i < COUNT(def2) ? i : COUNT(def2) - 1];
+ planner.max_feedrate_mm_s[i] = i < XYZ + esteppers ? tmp3[i] : def3[i < COUNT(def3) ? i : COUNT(def3) - 1];
}
EEPROM_READ(planner.acceleration);
@@ -1009,8 +1028,14 @@ void MarlinSettings::postprocess() {
EEPROM_READ(planner.travel_acceleration);
EEPROM_READ(planner.min_feedrate_mm_s);
EEPROM_READ(planner.min_travel_feedrate_mm_s);
- EEPROM_READ(planner.min_segment_time_us);
- EEPROM_READ(planner.max_jerk);
+
+ #if ENABLED(JUNCTION_DEVIATION)
+ for (uint8_t q = 4; q--;) EEPROM_READ(dummy);
+ EEPROM_READ(planner.junction_deviation_mm);
+ #else
+ EEPROM_READ(planner.max_jerk);
+ EEPROM_READ(dummy);
+ #endif
//
// Home Offset (M206)
@@ -1214,9 +1239,9 @@ void MarlinSettings::postprocess() {
_FIELD_TEST(lpq_len);
#if DISABLED(PID_EXTRUSION_SCALING)
- int lpq_len;
+ int16_t LPQ_LEN;
#endif
- EEPROM_READ(lpq_len);
+ EEPROM_READ(LPQ_LEN);
//
// Heated Bed PID
@@ -1340,7 +1365,7 @@ void MarlinSettings::postprocess() {
#endif
#if ENABLED(HYBRID_THRESHOLD)
- #define TMC_SET_PWMTHRS(P,Q) tmc_set_pwmthrs(stepper##Q, TMC_##Q, tmc_hybrid_threshold[TMC_##Q], planner.axis_steps_per_mm[P##_AXIS])
+ #define TMC_SET_PWMTHRS(A,Q) tmc_set_pwmthrs(stepper##Q, tmc_hybrid_threshold[TMC_##Q], planner.axis_steps_per_mm[_AXIS(A)])
uint32_t tmc_hybrid_threshold[TMC_AXES];
EEPROM_READ(tmc_hybrid_threshold);
if (!validating) {
@@ -1523,14 +1548,12 @@ void MarlinSettings::postprocess() {
#endif
}
- if (!validating) {
- if (eeprom_error) reset(); else postprocess();
- }
+ if (!validating && !eeprom_error) postprocess();
#if ENABLED(AUTO_BED_LEVELING_UBL)
- ubl.report_state();
-
if (!validating) {
+ ubl.report_state();
+
if (!ubl.sanity_check()) {
SERIAL_EOL();
#if ENABLED(EEPROM_CHITCHAT)
@@ -1595,7 +1618,7 @@ void MarlinSettings::postprocess() {
}
#endif
- int16_t MarlinSettings::meshes_start_index() {
+ uint16_t MarlinSettings::meshes_start_index() {
return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8; // Pad the end of configuration data so it can float up
// or down a little bit without disrupting the mesh data
}
@@ -1698,16 +1721,21 @@ void MarlinSettings::reset() {
planner.max_acceleration_mm_per_s2[i] = pgm_read_dword_near(&tmp3[i < COUNT(tmp3) ? i : COUNT(tmp3) - 1]);
}
+ planner.min_segment_time_us = DEFAULT_MINSEGMENTTIME;
planner.acceleration = DEFAULT_ACCELERATION;
planner.retract_acceleration = DEFAULT_RETRACT_ACCELERATION;
planner.travel_acceleration = DEFAULT_TRAVEL_ACCELERATION;
planner.min_feedrate_mm_s = DEFAULT_MINIMUMFEEDRATE;
planner.min_travel_feedrate_mm_s = DEFAULT_MINTRAVELFEEDRATE;
- planner.min_segment_time_us = DEFAULT_MINSEGMENTTIME;
- planner.max_jerk[X_AXIS] = DEFAULT_XJERK;
- planner.max_jerk[Y_AXIS] = DEFAULT_YJERK;
- planner.max_jerk[Z_AXIS] = DEFAULT_ZJERK;
- planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
+
+ #if ENABLED(JUNCTION_DEVIATION)
+ planner.junction_deviation_mm = float(JUNCTION_DEVIATION_MM);
+ #else
+ planner.max_jerk[X_AXIS] = DEFAULT_XJERK;
+ planner.max_jerk[Y_AXIS] = DEFAULT_YJERK;
+ planner.max_jerk[Z_AXIS] = DEFAULT_ZJERK;
+ planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
+ #endif
#if HAS_HOME_OFFSET
ZERO(home_offset);
@@ -1717,7 +1745,7 @@ void MarlinSettings::reset() {
constexpr float tmp4[XYZ][HOTENDS] = {
HOTEND_OFFSET_X,
HOTEND_OFFSET_Y
- #ifdef HOTEND_OFFSET_Z
+ #if HAS_HOTEND_OFFSET_Z
, HOTEND_OFFSET_Z
#else
, { 0 }
@@ -1803,7 +1831,7 @@ void MarlinSettings::reset() {
HOTEND_LOOP()
#endif
{
- PID_PARAM(Kp, e) = DEFAULT_Kp;
+ PID_PARAM(Kp, e) = float(DEFAULT_Kp);
PID_PARAM(Ki, e) = scalePID_i(DEFAULT_Ki);
PID_PARAM(Kd, e) = scalePID_d(DEFAULT_Kd);
#if ENABLED(PID_EXTRUSION_SCALING)
@@ -1811,7 +1839,7 @@ void MarlinSettings::reset() {
#endif
}
#if ENABLED(PID_EXTRUSION_SCALING)
- lpq_len = 20; // default last-position-queue size
+ thermalManager.lpq_len = 20; // default last-position-queue size
#endif
#endif // PIDTEMP
@@ -1872,7 +1900,7 @@ void MarlinSettings::reset() {
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE)
- for (uint8_t e = 0; e < E_STEPPERS; e++) {
+ for (uint8_t e = 0; e < EXTRUDERS; e++) {
filament_change_unload_length[e] = FILAMENT_CHANGE_UNLOAD_LENGTH;
filament_change_load_length[e] = FILAMENT_CHANGE_FAST_LOAD_LENGTH;
}
@@ -1891,12 +1919,12 @@ void MarlinSettings::reset() {
#define CONFIG_ECHO_START do{ if (!forReplay) SERIAL_ECHO_START(); }while(0)
#if HAS_TRINAMIC
- void say_M906() { SERIAL_ECHOPGM(" M906 "); }
+ void say_M906() { SERIAL_ECHOPGM(" M906"); }
#if ENABLED(HYBRID_THRESHOLD)
- void say_M913() { SERIAL_ECHOPGM(" M913 "); }
+ void say_M913() { SERIAL_ECHOPGM(" M913"); }
#endif
#if ENABLED(SENSORLESS_HOMING)
- void say_M914() { SERIAL_ECHOPGM(" M914 "); }
+ void say_M914() { SERIAL_ECHOPGM(" M914"); }
#endif
#endif
@@ -1904,6 +1932,16 @@ void MarlinSettings::reset() {
void say_M603() { SERIAL_ECHOPGM(" M603 "); }
#endif
+ inline void say_units(const bool colon=false) {
+ serialprintPGM(
+ #if ENABLED(INCH_MODE_SUPPORT)
+ parser.linear_unit_factor != 1.0 ? PSTR(" (in)") :
+ #endif
+ PSTR(" (mm)")
+ );
+ if (colon) SERIAL_ECHOLNPGM(":");
+ }
+
/**
* M503 - Report current settings in RAM
*
@@ -1920,13 +1958,15 @@ void MarlinSettings::reset() {
#define VOLUMETRIC_UNIT(N) (float(N) / (parser.volumetric_enabled ? parser.volumetric_unit_factor : parser.linear_unit_factor))
SERIAL_ECHOPGM(" G2");
SERIAL_CHAR(parser.linear_unit_factor == 1.0 ? '1' : '0');
- SERIAL_ECHOPGM(" ; Units in ");
- serialprintPGM(parser.linear_unit_factor == 1.0 ? PSTR("mm\n") : PSTR("inches\n"));
+ SERIAL_ECHOPGM(" ;");
+ say_units();
#else
#define LINEAR_UNIT(N) (N)
#define VOLUMETRIC_UNIT(N) (N)
- SERIAL_ECHOLNPGM(" G21 ; Units in mm");
+ SERIAL_ECHOPGM(" G21 ;");
+ say_units();
#endif
+ SERIAL_EOL();
#if ENABLED(ULTIPANEL)
@@ -2064,16 +2104,32 @@ void MarlinSettings::reset() {
if (!forReplay) {
CONFIG_ECHO_START;
- SERIAL_ECHOLNPGM("Advanced: S T B X Z E");
+ SERIAL_ECHOPGM("Advanced: B S T");
+ #if ENABLED(JUNCTION_DEVIATION)
+ SERIAL_ECHOPGM(" J");
+ #else
+ SERIAL_ECHOPGM(" X Y Z");
+ #endif
+ #if DISABLED(JUNCTION_DEVIATION) || ENABLED(LIN_ADVANCE)
+ SERIAL_ECHOPGM(" E");
+ #endif
+ SERIAL_EOL();
}
CONFIG_ECHO_START;
- SERIAL_ECHOPAIR(" M205 S", LINEAR_UNIT(planner.min_feedrate_mm_s));
+ SERIAL_ECHOPAIR(" M205 B", LINEAR_UNIT(planner.min_segment_time_us));
+ SERIAL_ECHOPAIR(" S", LINEAR_UNIT(planner.min_feedrate_mm_s));
SERIAL_ECHOPAIR(" T", LINEAR_UNIT(planner.min_travel_feedrate_mm_s));
- SERIAL_ECHOPAIR(" B", planner.min_segment_time_us);
- SERIAL_ECHOPAIR(" X", LINEAR_UNIT(planner.max_jerk[X_AXIS]));
- SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.max_jerk[Y_AXIS]));
- SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.max_jerk[Z_AXIS]));
- SERIAL_ECHOLNPAIR(" E", LINEAR_UNIT(planner.max_jerk[E_AXIS]));
+
+ #if ENABLED(JUNCTION_DEVIATION)
+ SERIAL_ECHOPAIR(" J", LINEAR_UNIT(planner.junction_deviation_mm));
+ #else
+ SERIAL_ECHOPAIR(" X", LINEAR_UNIT(planner.max_jerk[X_AXIS]));
+ SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(planner.max_jerk[Y_AXIS]));
+ SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(planner.max_jerk[Z_AXIS]));
+ SERIAL_ECHOPAIR(" E", LINEAR_UNIT(planner.max_jerk[E_AXIS]));
+ #endif
+
+ SERIAL_EOL();
#if HAS_M206_COMMAND
if (!forReplay) {
@@ -2096,7 +2152,7 @@ void MarlinSettings::reset() {
SERIAL_ECHOPAIR(" M218 T", (int)e);
SERIAL_ECHOPAIR(" X", LINEAR_UNIT(hotend_offset[X_AXIS][e]));
SERIAL_ECHOPAIR(" Y", LINEAR_UNIT(hotend_offset[Y_AXIS][e]));
- #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(SWITCHING_NOZZLE) ||ENABLED(PARKING_EXTRUDER)
+ #if HAS_HOTEND_OFFSET_Z
SERIAL_ECHOPAIR(" Z", LINEAR_UNIT(hotend_offset[Z_AXIS][e]));
#endif
SERIAL_EOL();
@@ -2148,7 +2204,7 @@ void MarlinSettings::reset() {
SERIAL_ECHOPAIR(" G29 S3 X", (int)px + 1);
SERIAL_ECHOPAIR(" Y", (int)py + 1);
SERIAL_ECHOPGM(" Z");
- SERIAL_PROTOCOL_F(LINEAR_UNIT(mbl.z_values[px][py]), 5);
+ SERIAL_ECHO_F(LINEAR_UNIT(mbl.z_values[px][py]), 5);
SERIAL_EOL();
}
}
@@ -2172,10 +2228,10 @@ void MarlinSettings::reset() {
for (uint8_t py = 0; py < GRID_MAX_POINTS_Y; py++) {
for (uint8_t px = 0; px < GRID_MAX_POINTS_X; px++) {
CONFIG_ECHO_START;
- SERIAL_ECHOPAIR(" G29 W I", (int)px + 1);
- SERIAL_ECHOPAIR(" J", (int)py + 1);
+ SERIAL_ECHOPAIR(" G29 W I", (int)px);
+ SERIAL_ECHOPAIR(" J", (int)py);
SERIAL_ECHOPGM(" Z");
- SERIAL_PROTOCOL_F(LINEAR_UNIT(z_values[px][py]), 5);
+ SERIAL_ECHO_F(LINEAR_UNIT(z_values[px][py]), 5);
SERIAL_EOL();
}
}
@@ -2262,7 +2318,7 @@ void MarlinSettings::reset() {
SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, e)));
#if ENABLED(PID_EXTRUSION_SCALING)
SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, e));
- if (e == 0) SERIAL_ECHOPAIR(" L", lpq_len);
+ if (e == 0) SERIAL_ECHOPAIR(" L", thermalManager.lpq_len);
#endif
SERIAL_EOL();
}
@@ -2277,7 +2333,7 @@ void MarlinSettings::reset() {
SERIAL_ECHOPAIR(" D", unscalePID_d(PID_PARAM(Kd, 0)));
#if ENABLED(PID_EXTRUSION_SCALING)
SERIAL_ECHOPAIR(" C", PID_PARAM(Kc, 0));
- SERIAL_ECHOPAIR(" L", lpq_len);
+ SERIAL_ECHOPAIR(" L", thermalManager.lpq_len);
#endif
SERIAL_EOL();
}
@@ -2338,7 +2394,8 @@ void MarlinSettings::reset() {
#if HAS_BED_PROBE
if (!forReplay) {
CONFIG_ECHO_START;
- SERIAL_ECHOLNPGM("Z-Probe Offset (mm):");
+ SERIAL_ECHOPGM("Z-Probe Offset");
+ say_units(true);
}
CONFIG_ECHO_START;
SERIAL_ECHOLNPAIR(" M851 Z", LINEAR_UNIT(zprobe_zoffset));
@@ -2378,49 +2435,56 @@ void MarlinSettings::reset() {
SERIAL_ECHOLNPGM("Stepper driver current:");
}
CONFIG_ECHO_START;
- #if X_IS_TRINAMIC
+ #if X_IS_TRINAMIC || Y_IS_TRINAMIC || Z_IS_TRINAMIC
say_M906();
- SERIAL_ECHOLNPAIR("X", stepperX.getCurrent());
#endif
- #if X2_IS_TRINAMIC
- say_M906();
- SERIAL_ECHOLNPAIR("I1 X", stepperX2.getCurrent());
+ #if X_IS_TRINAMIC
+ SERIAL_ECHOPAIR(" X", stepperX.getCurrent());
#endif
#if Y_IS_TRINAMIC
- say_M906();
- SERIAL_ECHOLNPAIR("Y", stepperY.getCurrent());
- #endif
- #if Y2_IS_TRINAMIC
- say_M906();
- SERIAL_ECHOLNPAIR("I1 Y", stepperY2.getCurrent());
+ SERIAL_ECHOPAIR(" Y", stepperY.getCurrent());
#endif
#if Z_IS_TRINAMIC
+ SERIAL_ECHOPAIR(" Z", stepperZ.getCurrent());
+ #endif
+ #if X_IS_TRINAMIC || Y_IS_TRINAMIC || Z_IS_TRINAMIC
+ SERIAL_EOL();
+ #endif
+ #if X2_IS_TRINAMIC || Y2_IS_TRINAMIC || Z2_IS_TRINAMIC
say_M906();
- SERIAL_ECHOLNPAIR("Z", stepperZ.getCurrent());
+ SERIAL_ECHOPGM(" I1");
+ #endif
+ #if X2_IS_TRINAMIC
+ SERIAL_ECHOPAIR(" X", stepperX2.getCurrent());
+ #endif
+ #if Y2_IS_TRINAMIC
+ SERIAL_ECHOPAIR(" Y", stepperY2.getCurrent());
#endif
#if Z2_IS_TRINAMIC
- say_M906();
- SERIAL_ECHOLNPAIR("I1 Z", stepperZ2.getCurrent());
+ SERIAL_ECHOPAIR(" Z", stepperZ2.getCurrent());
+ #endif
+ #if X2_IS_TRINAMIC || Y2_IS_TRINAMIC || Z2_IS_TRINAMIC
+ SERIAL_EOL();
#endif
#if E0_IS_TRINAMIC
say_M906();
- SERIAL_ECHOLNPAIR("T0 E", stepperE0.getCurrent());
+ SERIAL_ECHOLNPAIR(" T0 E", stepperE0.getCurrent());
#endif
#if E_STEPPERS > 1 && E1_IS_TRINAMIC
say_M906();
- SERIAL_ECHOLNPAIR("T1 E", stepperE1.getCurrent());
+ SERIAL_ECHOLNPAIR(" T1 E", stepperE1.getCurrent());
#endif
#if E_STEPPERS > 2 && E2_IS_TRINAMIC
say_M906();
- SERIAL_ECHOLNPAIR("T2 E", stepperE2.getCurrent());
+ SERIAL_ECHOLNPAIR(" T2 E", stepperE2.getCurrent());
#endif
#if E_STEPPERS > 3 && E3_IS_TRINAMIC
say_M906();
- SERIAL_ECHOLNPAIR("T3 E", stepperE3.getCurrent());
+ SERIAL_ECHOLNPAIR(" T3 E", stepperE3.getCurrent());
#endif
#if E_STEPPERS > 4 && E4_IS_TRINAMIC
say_M906();
- SERIAL_ECHOLNPAIR("T4 E", stepperE4.getCurrent());
+ SERIAL_ECHOLNPAIR(" T4 E", stepperE4.getCurrent());
#endif
SERIAL_EOL();
@@ -2433,49 +2497,56 @@ void MarlinSettings::reset() {
SERIAL_ECHOLNPGM("Hybrid Threshold:");
}
CONFIG_ECHO_START;
- #if X_IS_TRINAMIC
+ #if X_IS_TRINAMIC || Y_IS_TRINAMIC || Z_IS_TRINAMIC
say_M913();
- SERIAL_ECHOLNPAIR("X", TMC_GET_PWMTHRS(X, X));
#endif
- #if X2_IS_TRINAMIC
- say_M913();
- SERIAL_ECHOLNPAIR("I1 X", TMC_GET_PWMTHRS(X, X2));
+ #if X_IS_TRINAMIC
+ SERIAL_ECHOPAIR(" X", TMC_GET_PWMTHRS(X, X));
#endif
#if Y_IS_TRINAMIC
- say_M913();
- SERIAL_ECHOLNPAIR("Y", TMC_GET_PWMTHRS(Y, Y));
- #endif
- #if Y2_IS_TRINAMIC
- say_M913();
- SERIAL_ECHOLNPAIR("I1 Y", TMC_GET_PWMTHRS(Y, Y2));
+ SERIAL_ECHOPAIR(" Y", TMC_GET_PWMTHRS(Y, Y));
#endif
#if Z_IS_TRINAMIC
+ SERIAL_ECHOPAIR(" Z", TMC_GET_PWMTHRS(Z, Z));
+ #endif
+ #if X_IS_TRINAMIC || Y_IS_TRINAMIC || Z_IS_TRINAMIC
+ SERIAL_EOL();
+ #endif
+ #if X2_IS_TRINAMIC || Y2_IS_TRINAMIC || Z2_IS_TRINAMIC
say_M913();
- SERIAL_ECHOLNPAIR("Z", TMC_GET_PWMTHRS(Z, Z));
+ SERIAL_ECHOPGM(" I1");
+ #endif
+ #if X2_IS_TRINAMIC
+ SERIAL_ECHOPAIR(" X", TMC_GET_PWMTHRS(X, X2));
+ #endif
+ #if Y2_IS_TRINAMIC
+ SERIAL_ECHOPAIR(" Y", TMC_GET_PWMTHRS(Y, Y2));
#endif
#if Z2_IS_TRINAMIC
- say_M913();
- SERIAL_ECHOLNPAIR("I1 Z", TMC_GET_PWMTHRS(Z, Z2));
+ SERIAL_ECHOPAIR(" Z", TMC_GET_PWMTHRS(Z, Z2));
+ #endif
+ #if X2_IS_TRINAMIC || Y2_IS_TRINAMIC || Z2_IS_TRINAMIC
+ SERIAL_EOL();
#endif
#if E0_IS_TRINAMIC
say_M913();
- SERIAL_ECHOLNPAIR("T0 E", TMC_GET_PWMTHRS(E, E0));
+ SERIAL_ECHOLNPAIR(" T0 E", TMC_GET_PWMTHRS(E, E0));
#endif
#if E_STEPPERS > 1 && E1_IS_TRINAMIC
say_M913();
- SERIAL_ECHOLNPAIR("T1 E", TMC_GET_PWMTHRS(E, E1));
+ SERIAL_ECHOLNPAIR(" T1 E", TMC_GET_PWMTHRS(E, E1));
#endif
#if E_STEPPERS > 2 && E2_IS_TRINAMIC
say_M913();
- SERIAL_ECHOLNPAIR("T2 E", TMC_GET_PWMTHRS(E, E2));
+ SERIAL_ECHOLNPAIR(" T2 E", TMC_GET_PWMTHRS(E, E2));
#endif
#if E_STEPPERS > 3 && E3_IS_TRINAMIC
say_M913();
- SERIAL_ECHOLNPAIR("T3 E", TMC_GET_PWMTHRS(E, E3));
+ SERIAL_ECHOLNPAIR(" T3 E", TMC_GET_PWMTHRS(E, E3));
#endif
#if E_STEPPERS > 4 && E4_IS_TRINAMIC
say_M913();
- SERIAL_ECHOLNPAIR("T4 E", TMC_GET_PWMTHRS(E, E4));
+ SERIAL_ECHOLNPAIR(" T4 E", TMC_GET_PWMTHRS(E, E4));
#endif
SERIAL_EOL();
#endif // HYBRID_THRESHOLD
@@ -2489,38 +2560,42 @@ void MarlinSettings::reset() {
SERIAL_ECHOLNPGM("Sensorless homing threshold:");
}
CONFIG_ECHO_START;
- #ifdef X_HOMING_SENSITIVITY
- #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
- say_M914();
- SERIAL_ECHOLNPAIR("X", stepperX.sgt());
+ #define HAS_X_SENSORLESS (defined(X_HOMING_SENSITIVITY) && (ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)))
+ #define HAS_Y_SENSORLESS (defined(Y_HOMING_SENSITIVITY) && (ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)))
+ #define HAS_Z_SENSORLESS (defined(Z_HOMING_SENSITIVITY) && (ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)))
+ #if HAS_X_SENSORLESS || HAS_Y_SENSORLESS || HAS_Z_SENSORLESS
+ say_M914();
+ #if HAS_X_SENSORLESS
+ SERIAL_ECHOPAIR(" X", stepperX.sgt());
#endif
- #if ENABLED(X2_IS_TMC2130)
- say_M914();
- SERIAL_ECHOLNPAIR("I1 X", stepperX2.sgt());
+ #if HAS_Y_SENSORLESS
+ SERIAL_ECHOPAIR(" Y", stepperY.sgt());
#endif
+ #if HAS_Z_SENSORLESS
+ SERIAL_ECHOPAIR(" Z", stepperZ.sgt());
+ #endif
+ SERIAL_EOL();
#endif
- #ifdef Y_HOMING_SENSITIVITY
- #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
- say_M914();
- SERIAL_ECHOLNPAIR("Y", stepperY.sgt());
+
+ #define HAS_X2_SENSORLESS (defined(X_HOMING_SENSITIVITY) && ENABLED(X2_IS_TMC2130))
+ #define HAS_Y2_SENSORLESS (defined(Y_HOMING_SENSITIVITY) && ENABLED(Y2_IS_TMC2130))
+ #define HAS_Z2_SENSORLESS (defined(Z_HOMING_SENSITIVITY) && ENABLED(Z2_IS_TMC2130))
+ #if HAS_X2_SENSORLESS || HAS_Y2_SENSORLESS || HAS_Z2_SENSORLESS
+ say_M914();
+ SERIAL_ECHOPGM(" I1");
+ #if HAS_X2_SENSORLESS
+ SERIAL_ECHOPAIR(" X", stepperX2.sgt());
#endif
- #if ENABLED(Y2_IS_TMC2130)
- say_M914();
- SERIAL_ECHOLNPAIR("I1 Y", stepperY2.sgt());
+ #if HAS_Y2_SENSORLESS
+ SERIAL_ECHOPAIR(" Y", stepperY2.sgt());
#endif
+ #if HAS_Z2_SENSORLESS
+ SERIAL_ECHOPAIR(" Z", stepperZ2.sgt());
+ #endif
+ SERIAL_EOL();
#endif
- #ifdef Z_HOMING_SENSITIVITY
- #if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
- say_M914();
- SERIAL_ECHOLNPAIR("Z", stepperZ.sgt());
- #endif
- #if ENABLED(Z2_IS_TMC2130)
- say_M914();
- SERIAL_ECHOLNPAIR("I1 Z", stepperZ2.sgt());
- #endif
- #endif
- SERIAL_EOL();
- #endif
+
+ #endif // SENSORLESS_HOMING
#endif // HAS_TRINAMIC
diff --git a/Marlin/configuration_store.h b/Marlin/configuration_store.h
index 1f0a33c599..f7b50e0920 100644
--- a/Marlin/configuration_store.h
+++ b/Marlin/configuration_store.h
@@ -35,15 +35,16 @@ class MarlinSettings {
static bool save(); // Return 'true' if data was saved
FORCE_INLINE static bool init_eeprom() {
- bool success = true;
reset();
#if ENABLED(EEPROM_SETTINGS)
- success = save();
+ const bool success = save();
#if ENABLED(EEPROM_CHITCHAT)
if (success) report();
#endif
+ return success;
+ #else
+ return true;
#endif
- return success;
}
#if ENABLED(EEPROM_SETTINGS)
@@ -52,8 +53,8 @@ class MarlinSettings {
#if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
// That can store is enabled
- static int16_t meshes_start_index();
- FORCE_INLINE static int16_t meshes_end_index() { return meshes_end; }
+ static uint16_t meshes_start_index();
+ FORCE_INLINE static uint16_t meshes_end_index() { return meshes_end; }
static uint16_t calc_num_meshes();
static int mesh_slot_offset(const int8_t slot);
static void store_mesh(const int8_t slot);
@@ -83,8 +84,8 @@ class MarlinSettings {
#if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
// That can store is enabled
- static constexpr int16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always
- // live at the very end of the eeprom
+ static constexpr uint16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always
+ // live at the very end of the eeprom
#endif
diff --git a/Marlin/delay.h b/Marlin/delay.h
new file mode 100644
index 0000000000..5689b2b4c1
--- /dev/null
+++ b/Marlin/delay.h
@@ -0,0 +1,77 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (C) 2016 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 .
+ *
+ */
+
+/**
+ * AVR busy wait delay Cycles routines:
+ *
+ * DELAY_CYCLES(count): Delay execution in cycles
+ * DELAY_NS(count): Delay execution in nanoseconds
+ * DELAY_US(count): Delay execution in microseconds
+ */
+
+#ifndef MARLIN_DELAY_H
+#define MARLIN_DELAY_H
+
+#define nop() __asm__ __volatile__("nop;\n\t":::)
+
+FORCE_INLINE static void __delay_4cycles(uint8_t cy) {
+ __asm__ __volatile__(
+ L("1")
+ A("dec %[cnt]")
+ A("nop")
+ A("brne 1b")
+ : [cnt] "+r"(cy) // output: +r means input+output
+ : // input:
+ : "cc" // clobbers:
+ );
+}
+
+/* ---------------- Delay in cycles */
+FORCE_INLINE static void DELAY_CYCLES(uint16_t x) {
+
+ if (__builtin_constant_p(x)) {
+ #define MAXNOPS 4
+
+ if (x <= (MAXNOPS)) {
+ switch (x) { case 4: nop(); case 3: nop(); case 2: nop(); case 1: nop(); }
+ }
+ else {
+ const uint32_t rem = (x) % (MAXNOPS);
+ switch (rem) { case 3: nop(); case 2: nop(); case 1: nop(); }
+ if ((x = (x) / (MAXNOPS)))
+ __delay_4cycles(x); // if need more then 4 nop loop is more optimal
+ }
+
+ #undef MAXNOPS
+ }
+ else
+ __delay_4cycles(x / 4);
+}
+#undef nop
+
+/* ---------------- Delay in nanoseconds */
+#define DELAY_NS(x) DELAY_CYCLES( (x) * (F_CPU/1000000L) / 1000L )
+
+/* ---------------- Delay in microseconds */
+#define DELAY_US(x) DELAY_CYCLES( (x) * (F_CPU/1000000L) )
+
+#endif // MARLIN_DELAY_H
diff --git a/Marlin/digipot_mcp4018.cpp b/Marlin/digipot_mcp4018.cpp
index 06622d057f..5871fdb99c 100644
--- a/Marlin/digipot_mcp4018.cpp
+++ b/Marlin/digipot_mcp4018.cpp
@@ -89,7 +89,7 @@ static void i2c_send(const uint8_t channel, const byte v) {
// This is for the MCP4018 I2C based digipot
void digipot_i2c_set_current(uint8_t channel, float current) {
- i2c_send(channel, current_to_wiper(min(max(current, 0.0f), float(DIGIPOT_A4988_MAX_CURRENT))));
+ i2c_send(channel, current_to_wiper(MIN(MAX(current, 0), float(DIGIPOT_A4988_MAX_CURRENT))));
}
void digipot_i2c_init() {
diff --git a/Marlin/digipot_mcp4451.cpp b/Marlin/digipot_mcp4451.cpp
index d79915cc94..fed84b2645 100644
--- a/Marlin/digipot_mcp4451.cpp
+++ b/Marlin/digipot_mcp4451.cpp
@@ -50,7 +50,7 @@ static void i2c_send(const byte addr, const byte a, const byte b) {
// This is for the MCP4451 I2C based digipot
void digipot_i2c_set_current(uint8_t channel, float current) {
- current = min((float) max(current, 0.0f), DIGIPOT_I2C_MAX_CURRENT);
+ current = MIN((float) MAX(current, 0), DIGIPOT_I2C_MAX_CURRENT);
// these addresses are specific to Azteeg X3 Pro, can be set to others,
// In this case first digipot is at address A0=0, A1= 0, second one is at A0=0, A1= 1
byte addr = 0x2C; // channel 0-3
diff --git a/Marlin/dogm_bitmaps.h b/Marlin/dogm_bitmaps.h
index 78cff28dbd..42b94b7dbb 100644
--- a/Marlin/dogm_bitmaps.h
+++ b/Marlin/dogm_bitmaps.h
@@ -29,10 +29,11 @@
#include "MarlinConfig.h"
-//#define START_BMPHIGH // Costs 399 bytes more flash
#if ENABLED(SHOW_BOOTSCREEN)
+ //#define START_BMPHIGH // Costs 399 bytes more flash
+
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
#include "_Bootscreen.h"
@@ -129,387 +130,927 @@
#if ENABLED(CUSTOM_STATUS_SCREEN_IMAGE)
- // This file must define STATUS_SCREENWIDTH and status_screen{0, 1}_bmp.
+ // This file must define STATUS_SCREENWIDTH and status_screen[012]_bmp.
// It can also define STATUS_SCREEN_X, STATUS_SCREEN_{BED,FAN}_TEXT_X and
// STATUS_SCREEN_HOTEND_TEXT_X(i) to modify draw locations.
#include "_Statusscreen.h"
-#elif HAS_HEATED_BED
+#else // !CUSTOM_STATUS_SCREEN_IMAGE
- #define STATUS_SCREEN_X ( 8 + (HOTENDS ? 0 : 64))
- #define STATUS_SCREENWIDTH (120 - (HOTENDS ? 0 : 64))
+ // Can also be overridden in Configuration.h
+ // If you can afford it, try the 3-frame fan animation!
+ #ifndef FAN_ANIM_FRAMES
+ #define FAN_ANIM_FRAMES 2
+ #endif
- #if HOTENDS == 0
- const unsigned char status_screen0_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
- B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
- B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
- B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
- B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
- B00000000,B01000001,B00000100,B00000000,B00101100,B00000000,B11010000,
- B00000000,B10000010,B00001000,B00000000,B00100000,B00110000,B00010000,
- B00000000,B10000010,B00001000,B00000000,B00100000,B01111000,B00010000,
- B00000000,B01000001,B00000100,B00000000,B00100000,B11111100,B00010000,
- B00000000,B00100000,B10000010,B00000000,B00110000,B11111100,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
- B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
- };
- const unsigned char status_screen1_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
- B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
- B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
- B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
- B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
- B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
- B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
- B00000000,B01000001,B00000100,B00000000,B00101111,B00000011,B11010000,
- B00000000,B10000010,B00001000,B00000000,B00101111,B10000111,B11010000,
- B00000000,B10000010,B00001000,B00000000,B00100111,B10000111,B10010000,
- B00000000,B01000001,B00000100,B00000000,B00100011,B10000111,B00010000,
- B00000000,B00100000,B10000010,B00000000,B00110001,B10000110,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
- B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
- };
+ #if HAS_HEATED_BED
- #elif HOTENDS == 1
+ #define STATUS_SCREEN_X ( 8 + (HOTENDS ? 0 : 64))
+ #define STATUS_SCREENWIDTH (120 - (HOTENDS ? 0 : 64))
- const unsigned char status_screen0_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00101100,B00000000,B11010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B00110000,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B01111000,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100000,B11111100,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110000,B11111100,B00110000,
- B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
- };
- const unsigned char status_screen1_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00101111,B00000011,B11010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00101111,B10000111,B11010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100111,B10000111,B10010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100011,B10000111,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110001,B10000110,B00110000,
- B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
- };
+ #if HOTENDS == 0
- #elif HOTENDS == 2
+ #if FAN_ANIM_FRAMES == 3
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00111110,B00000000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00101111,B11000111,B11101000,
+ B00000000,B00000000,B00000000,B00000000,B00100111,B11000111,B11001000,
+ B00000000,B00100000,B10000010,B00000000,B00100001,B11111111,B00001000,
+ B00000000,B00010000,B01000001,B00000000,B00100000,B01111100,B00001000,
+ B00000000,B00010000,B01000001,B00000000,B00100000,B01111100,B00001000,
+ B00000000,B00100000,B10000010,B00000000,B00100000,B01111100,B00001000,
+ B00000000,B01000001,B00000100,B00000000,B00100001,B11111111,B00001000,
+ B00000000,B10000010,B00001000,B00000000,B00100111,B11000111,B11001000,
+ B00000000,B10000010,B00001000,B00000000,B00101111,B11000111,B11101000,
+ B00000000,B01000001,B00000100,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00100000,B10000010,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00000000,B11111111,B11111111,B11000000,B00111110,B00000000,B11111000,
+ B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00111110,B00110000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00110001,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00110000,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00100000,B11110000,B01101000,
+ B00000000,B00000000,B00000000,B00000000,B00100000,B00110001,B11101000,
+ B00000000,B00100000,B10000010,B00000000,B00100000,B00111001,B11101000,
+ B00000000,B00010000,B01000001,B00000000,B00100000,B01111111,B11111000,
+ B00000000,B00010000,B01000001,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00100000,B10000010,B00000000,B00111111,B11111100,B00001000,
+ B00000000,B01000001,B00000100,B00000000,B00101111,B00111000,B00001000,
+ B00000000,B10000010,B00001000,B00000000,B00101110,B00011000,B00001000,
+ B00000000,B10000010,B00001000,B00000000,B00101100,B00011110,B00001000,
+ B00000000,B01000001,B00000100,B00000000,B00110000,B00011110,B00011000,
+ B00000000,B00100000,B10000010,B00000000,B00110000,B00011111,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00000000,B11111111,B11111111,B11000000,B00111110,B00011000,B11111000,
+ B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen2_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00111110,B00011000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00110000,B00011111,B10011000,
+ B00000000,B00000000,B00000000,B00000000,B00110100,B00011111,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00101110,B00011110,B00001000,
+ B00000000,B00000000,B00000000,B00000000,B00101111,B00011100,B00001000,
+ B00000000,B00100000,B10000010,B00000000,B00101111,B10111000,B00001000,
+ B00000000,B00010000,B01000001,B00000000,B00111111,B11111100,B00001000,
+ B00000000,B00010000,B01000001,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00100000,B10000010,B00000000,B00100000,B01111111,B11111000,
+ B00000000,B01000001,B00000100,B00000000,B00100000,B00111011,B11101000,
+ B00000000,B10000010,B00001000,B00000000,B00100000,B01110001,B11101000,
+ B00000000,B10000010,B00001000,B00000000,B00100000,B11110000,B11101000,
+ B00000000,B01000001,B00000100,B00000000,B00110001,B11110000,B01011000,
+ B00000000,B00100000,B10000010,B00000000,B00110011,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00000000,B11111111,B11111111,B11000000,B00111110,B00110000,B11111000,
+ B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ #else
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
+ B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
+ B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
+ B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
+ B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
+ B00000000,B01000001,B00000100,B00000000,B00101100,B00000000,B11010000,
+ B00000000,B10000010,B00001000,B00000000,B00100000,B00110000,B00010000,
+ B00000000,B10000010,B00001000,B00000000,B00100000,B01111000,B00010000,
+ B00000000,B01000001,B00000100,B00000000,B00100000,B11111100,B00010000,
+ B00000000,B00100000,B10000010,B00000000,B00110000,B11111100,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
+ B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
+ B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
+ B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
+ B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
+ B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
+ B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
+ B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
+ B00000000,B01000001,B00000100,B00000000,B00101111,B00000011,B11010000,
+ B00000000,B10000010,B00001000,B00000000,B00101111,B10000111,B11010000,
+ B00000000,B10000010,B00001000,B00000000,B00100111,B10000111,B10010000,
+ B00000000,B01000001,B00000100,B00000000,B00100011,B10000111,B00010000,
+ B00000000,B00100000,B10000010,B00000000,B00110001,B10000110,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
+ B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
+ };
+ #endif
- const unsigned char status_screen0_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
- B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
- B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
- B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
- B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
- B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00101100,B00000000,B11010000,
- B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B00110000,B00010000,
- B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B01111000,B00010000,
- B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100000,B11111100,B00010000,
- B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110000,B11111100,B00110000,
- B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
- };
- const unsigned char status_screen1_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
- B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
- B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
- B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
- B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
- B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00101111,B00000011,B11010000,
- B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00101111,B10000111,B11010000,
- B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100111,B10000111,B10010000,
- B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100011,B10000111,B00010000,
- B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110001,B10000110,B00110000,
- B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
- };
+ #elif HOTENDS == 1
- #else // HOTENDS > 2
+ #if FAN_ANIM_FRAMES == 3
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00000000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B11000111,B11101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B11000111,B11001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100001,B11111111,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111100,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111100,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B01111100,B00001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100001,B11111111,B00001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100111,B11000111,B11001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00101111,B11000111,B11101000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00110111,B10000011,B11011000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110111,B10000011,B11011000,
+ B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111110,B00000000,B11111000,
+ B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00110000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11110000,B01101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110001,B11101000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B00111001,B11101000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111111,B11111000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00111111,B11111111,B11111000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00111111,B11111100,B00001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00101111,B00111000,B00001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00101110,B00011000,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00101100,B00011110,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00110000,B00011110,B00011000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110000,B00011111,B00011000,
+ B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111110,B00011000,B11111000,
+ B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen2_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00011000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011111,B10011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110100,B00011111,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00011110,B00001000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00011100,B00001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00101111,B10111000,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00111111,B11111100,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00111111,B11111111,B11111000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B01111111,B11111000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100000,B00111011,B11101000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B01110001,B11101000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B11110000,B11101000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00110001,B11110000,B01011000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110011,B11110000,B00011000,
+ B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111110,B00110000,B11111000,
+ B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ #else
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00101100,B00000000,B11010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B00110000,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B01111000,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100000,B11111100,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110000,B11111100,B00110000,
+ B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00101111,B00000011,B11010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00101111,B10000111,B11010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100111,B10000111,B10010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100011,B10000111,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110001,B10000110,B00110000,
+ B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
+ };
+ #endif
- const unsigned char status_screen0_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
- B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
- B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
- B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
- B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
- B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B01000001,B00000100,B00000000,B00101100,B00000000,B11010000,
- B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B10000010,B00001000,B00000000,B00100000,B00110000,B00010000,
- B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B10000010,B00001000,B00000000,B00100000,B01111000,B00010000,
- B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B01000001,B00000100,B00000000,B00100000,B11111100,B00010000,
- B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00100000,B10000010,B00000000,B00110000,B11111100,B00110000,
- B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
- };
- const unsigned char status_screen1_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
- B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
- B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
- B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
- B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
- B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B01000001,B00000100,B00000000,B00101111,B00000011,B11010000,
- B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B10000010,B00001000,B00000000,B00101111,B10000111,B11010000,
- B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B10000010,B00001000,B00000000,B00100111,B10000111,B10010000,
- B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B01000001,B00000100,B00000000,B00100011,B10000111,B00010000,
- B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00100000,B10000010,B00000000,B00110001,B10000110,B00110000,
- B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
- };
- #endif // HOTENDS
+ #elif HOTENDS == 2
-#else // !HAS_HEATED_BED
+ #if FAN_ANIM_FRAMES == 3
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00000000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B11000111,B11101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B11000111,B11001000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100001,B11111111,B00001000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111100,B00001000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111100,B00001000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B01111100,B00001000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100001,B11111111,B00001000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100111,B11000111,B11001000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00101111,B11000111,B11101000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00110111,B10000011,B11011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110111,B10000011,B11011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111110,B00000000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00110000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11110000,B01101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110001,B11101000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B00111001,B11101000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111111,B11111000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00111111,B11111111,B11111000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00111111,B11111100,B00001000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00101111,B00111000,B00001000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00101110,B00011000,B00001000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00101100,B00011110,B00001000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00110000,B00011110,B00011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110000,B00011111,B00011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111110,B00011000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen2_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00011000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011111,B10011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110100,B00011111,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00011110,B00001000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00011100,B00001000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00101111,B10111000,B00001000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00111111,B11111100,B00001000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00111111,B11111111,B11111000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B01111111,B11111000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100000,B00111011,B11101000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B01110001,B11101000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B11110000,B11101000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00110001,B11110000,B01011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110011,B11110000,B00011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111110,B00110000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ #else
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00101100,B00000000,B11010000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B00110000,B00010000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100000,B01111000,B00010000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100000,B11111100,B00010000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110000,B11111100,B00110000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00101111,B00000011,B11010000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00101111,B10000111,B11010000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B10000010,B00001000,B00000000,B00100111,B10000111,B10010000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B01000001,B00000100,B00000000,B00100011,B10000111,B00010000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B10000010,B00000000,B00110001,B10000110,B00110000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
+ };
+ #endif
- #define STATUS_SCREEN_X ( 8 + (HOTENDS ? 0 : 96))
- #define STATUS_SCREENWIDTH (120 - (HOTENDS ? 0 : 96))
+ #else // HOTENDS > 2
- #if HOTENDS == 0
- const unsigned char status_screen0_bmp[] PROGMEM = {
- B00111111,B11111111,B11110000,
- B00111000,B00000000,B01110000,
- B00110000,B11111100,B00110000,
- B00100000,B11111100,B00010000,
- B00100000,B01111000,B00010000,
- B00100000,B00110000,B00010000,
- B00101100,B00000000,B11010000,
- B00101110,B00110001,B11010000,
- B00101111,B01111011,B11010000,
- B00101111,B01111011,B11010000,
- B00101110,B00110001,B11010000,
- B00101100,B00000000,B11010000,
- B00100000,B00110000,B00010000,
- B00100000,B01111000,B00010000,
- B00100000,B11111100,B00010000,
- B00110000,B11111100,B00110000,
- B00111000,B00000000,B01110000,
- B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000
- };
- const unsigned char status_screen1_bmp[] PROGMEM = {
- B00111111,B11111111,B11110000,
- B00111000,B00000000,B01110000,
- B00110001,B10000110,B00110000,
- B00100011,B10000111,B00010000,
- B00100111,B10000111,B10010000,
- B00101111,B10000111,B11010000,
- B00101111,B00000011,B11010000,
- B00100000,B00110000,B00010000,
- B00100000,B01111000,B00010000,
- B00100000,B01111000,B00010000,
- B00100000,B00110000,B00010000,
- B00101111,B00000011,B11010000,
- B00101111,B10000111,B11010000,
- B00100111,B10000111,B10010000,
- B00100011,B10000111,B00010000,
- B00110001,B10000110,B00110000,
- B00111000,B00000000,B01110000,
- B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000
- };
+ #if FAN_ANIM_FRAMES == 3
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00000000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B11000111,B11101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B11000111,B11001000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00100000,B10000010,B00000000,B00100001,B11111111,B00001000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111100,B00001000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111100,B00001000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00100000,B10000010,B00000000,B00100000,B01111100,B00001000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B01000001,B00000100,B00000000,B00100001,B11111111,B00001000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B10000010,B00001000,B00000000,B00100111,B11000111,B11001000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B10000010,B00001000,B00000000,B00101111,B11000111,B11101000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B01000001,B00000100,B00000000,B00110111,B10000011,B11011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00100000,B10000010,B00000000,B00110111,B10000011,B11011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B11111111,B11111111,B11000000,B00111110,B00000000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00110000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11110000,B01101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110001,B11101000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00100000,B10000010,B00000000,B00100000,B00111001,B11101000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111111,B11111000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00010000,B01000001,B00000000,B00111111,B11111111,B11111000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00100000,B10000010,B00000000,B00111111,B11111100,B00001000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B01000001,B00000100,B00000000,B00101111,B00111000,B00001000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B10000010,B00001000,B00000000,B00101110,B00011000,B00001000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B10000010,B00001000,B00000000,B00101100,B00011110,B00001000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B01000001,B00000100,B00000000,B00110000,B00011110,B00011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00100000,B10000010,B00000000,B00110000,B00011111,B00011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B11111111,B11111111,B11000000,B00111110,B00011000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen2_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00011000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011111,B10011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110100,B00011111,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00011110,B00001000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00011100,B00001000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00100000,B10000010,B00000000,B00101111,B10111000,B00001000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00010000,B01000001,B00000000,B00111111,B11111100,B00001000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00010000,B01000001,B00000000,B00111111,B11111111,B11111000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00100000,B10000010,B00000000,B00100000,B01111111,B11111000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B01000001,B00000100,B00000000,B00100000,B00111011,B11101000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B10000010,B00001000,B00000000,B00100000,B01110001,B11101000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B10000010,B00001000,B00000000,B00100000,B11110000,B11101000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B01000001,B00000100,B00000000,B00110001,B11110000,B01011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00100000,B10000010,B00000000,B00110011,B11110000,B00011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B11111111,B11111111,B11000000,B00111110,B00110000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11111000
+ };
+ #else
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00010000,B01000001,B00000000,B00101111,B01111011,B11010000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00100000,B10000010,B00000000,B00101110,B00110001,B11010000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B01000001,B00000100,B00000000,B00101100,B00000000,B11010000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B10000010,B00001000,B00000000,B00100000,B00110000,B00010000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B10000010,B00001000,B00000000,B00100000,B01111000,B00010000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B01000001,B00000100,B00000000,B00100000,B11111100,B00010000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00100000,B10000010,B00000000,B00110000,B11111100,B00110000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00010000,B01000001,B00000000,B00100000,B01111000,B00010000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00100000,B10000010,B00000000,B00100000,B00110000,B00010000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B01000001,B00000100,B00000000,B00101111,B00000011,B11010000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B10000010,B00001000,B00000000,B00101111,B10000111,B11010000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B10000010,B00001000,B00000000,B00100111,B10000111,B10010000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B01000001,B00000100,B00000000,B00100011,B10000111,B00010000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00100000,B10000010,B00000000,B00110001,B10000110,B00110000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B11111111,B11111111,B11000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B11111111,B11111111,B11000000,B00000000,B00000000,B00000000
+ };
+ #endif
- #elif HOTENDS == 1
+ #endif // HOTENDS
- const unsigned char status_screen0_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
- B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
- };
- const unsigned char status_screen1_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
- B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
- B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
- B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
- };
+ #else // !HAS_HEATED_BED
- #elif HOTENDS == 2
+ #define STATUS_SCREEN_X ( 8 + (HOTENDS ? 0 : 96))
+ #define STATUS_SCREENWIDTH (120 - (HOTENDS ? 0 : 96))
- const unsigned char status_screen0_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
- B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
- B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
- B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
- B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
- B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
- B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
- B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
- B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
- };
- const unsigned char status_screen1_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
- B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
- B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
- B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
- B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
- B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
- B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
- };
+ #if HOTENDS == 0
- #else // HOTENDS > 2
+ #if FAN_ANIM_FRAMES == 3
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00111111,B11111111,B11111000,
+ B00111110,B00000000,B11111000,
+ B00111001,B00000001,B00111000,
+ B00110111,B10000011,B11011000,
+ B00110111,B10000011,B11011000,
+ B00101111,B11000111,B11101000,
+ B00100111,B11000111,B11001000,
+ B00100001,B11111111,B00001000,
+ B00100000,B01111100,B00001000,
+ B00100000,B01111100,B00001000,
+ B00100000,B01111100,B00001000,
+ B00100001,B11111111,B00001000,
+ B00100111,B11000111,B11001000,
+ B00101111,B11000111,B11101000,
+ B00110111,B10000011,B11011000,
+ B00110111,B10000011,B11011000,
+ B00111001,B00000001,B00111000,
+ B00111110,B00000000,B11111000,
+ B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00111111,B11111111,B11111000,
+ B00111110,B00110000,B11111000,
+ B00111001,B11110000,B00111000,
+ B00110001,B11110000,B00011000,
+ B00110000,B11110000,B00011000,
+ B00100000,B11110000,B01101000,
+ B00100000,B00110001,B11101000,
+ B00100000,B00111001,B11101000,
+ B00100000,B01111111,B11111000,
+ B00111111,B11111111,B11111000,
+ B00111111,B11111100,B00001000,
+ B00101111,B00111000,B00001000,
+ B00101110,B00011000,B00001000,
+ B00101100,B00011110,B00001000,
+ B00110000,B00011110,B00011000,
+ B00110000,B00011111,B00011000,
+ B00111000,B00011111,B00111000,
+ B00111110,B00011000,B11111000,
+ B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen2_bmp[] PROGMEM = {
+ B00111111,B11111111,B11111000,
+ B00111110,B00011000,B11111000,
+ B00111000,B00011111,B00111000,
+ B00110000,B00011111,B10011000,
+ B00110100,B00011111,B00011000,
+ B00101110,B00011110,B00001000,
+ B00101111,B00011100,B00001000,
+ B00101111,B10111000,B00001000,
+ B00111111,B11111100,B00001000,
+ B00111111,B11111111,B11111000,
+ B00100000,B01111111,B11111000,
+ B00100000,B00111011,B11101000,
+ B00100000,B01110001,B11101000,
+ B00100000,B11110000,B11101000,
+ B00110001,B11110000,B01011000,
+ B00110011,B11110000,B00011000,
+ B00111001,B11110000,B00111000,
+ B00111110,B00110000,B11111000,
+ B00111111,B11111111,B11111000
+ };
+ #else
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00111111,B11111111,B11110000,
+ B00111000,B00000000,B01110000,
+ B00110000,B11111100,B00110000,
+ B00100000,B11111100,B00010000,
+ B00100000,B01111000,B00010000,
+ B00100000,B00110000,B00010000,
+ B00101100,B00000000,B11010000,
+ B00101110,B00110001,B11010000,
+ B00101111,B01111011,B11010000,
+ B00101111,B01111011,B11010000,
+ B00101110,B00110001,B11010000,
+ B00101100,B00000000,B11010000,
+ B00100000,B00110000,B00010000,
+ B00100000,B01111000,B00010000,
+ B00100000,B11111100,B00010000,
+ B00110000,B11111100,B00110000,
+ B00111000,B00000000,B01110000,
+ B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00111111,B11111111,B11110000,
+ B00111000,B00000000,B01110000,
+ B00110001,B10000110,B00110000,
+ B00100011,B10000111,B00010000,
+ B00100111,B10000111,B10010000,
+ B00101111,B10000111,B11010000,
+ B00101111,B00000011,B11010000,
+ B00100000,B00110000,B00010000,
+ B00100000,B01111000,B00010000,
+ B00100000,B01111000,B00010000,
+ B00100000,B00110000,B00010000,
+ B00101111,B00000011,B11010000,
+ B00101111,B10000111,B11010000,
+ B00100111,B10000111,B10010000,
+ B00100011,B10000111,B00010000,
+ B00110001,B10000110,B00110000,
+ B00111000,B00000000,B01110000,
+ B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000
+ };
+ #endif
- const unsigned char status_screen0_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
- B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
- B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
- B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
- B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
- B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
- B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
- B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
- B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
- };
- const unsigned char status_screen1_bmp[] PROGMEM = {
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
- B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
- B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
- B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
- B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
- B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
- B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
- B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
- B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
- B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
- B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
- B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
- };
+ #elif HOTENDS == 1
- #endif // HOTENDS
+ #if FAN_ANIM_FRAMES == 3
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00000000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B11000111,B11101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B11000111,B11001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100001,B11111111,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111100,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111100,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111100,B00001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100001,B11111111,B00001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B11000111,B11001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B11000111,B11101000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00000000,B11111000,
+ B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00110000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11110000,B01101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110001,B11101000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00111001,B11101000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111111,B11111000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111100,B00001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00111000,B00001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00011000,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00011110,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011110,B00011000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011111,B00011000,
+ B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00011000,B11111000,
+ B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen2_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00011000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011111,B10011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110100,B00011111,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00011110,B00001000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00011100,B00001000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10111000,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111100,B00001000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111111,B11111000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00111011,B11101000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01110001,B11101000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11110000,B11101000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B11110000,B01011000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110011,B11110000,B00011000,
+ B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00110000,B11111000,
+ B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000
+ };
+ #else
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
+ B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
+ B00111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
+ B01111111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
+ B00011111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
+ };
+ #endif
-#endif // !HAS_HEATED_BED
+ #elif HOTENDS == 2
+
+ #if FAN_ANIM_FRAMES == 3
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00000000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B11000111,B11101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B11000111,B11001000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100001,B11111111,B00001000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111100,B00001000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111100,B00001000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111100,B00001000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100001,B11111111,B00001000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B11000111,B11001000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B11000111,B11101000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00000000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00110000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11110000,B01101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110001,B11101000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00111001,B11101000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111111,B11111000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111100,B00001000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00111000,B00001000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00011000,B00001000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00011110,B00001000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011110,B00011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011111,B00011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00011000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen2_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00011000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011111,B10011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110100,B00011111,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00011110,B00001000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00011100,B00001000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10111000,B00001000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111100,B00001000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111111,B11111000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00111011,B11101000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01110001,B11101000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11110000,B11101000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B11110000,B01011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110011,B11110000,B00011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00110000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000
+ };
+ #else
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
+ };
+ #endif
+
+ #else // HOTENDS > 2
+
+ #if FAN_ANIM_FRAMES == 3
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00000000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B11000111,B11101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B11000111,B11001000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100001,B11111111,B00001000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111100,B00001000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111100,B00001000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111100,B00001000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B00000000,B00000000,B00000000,B00100001,B11111111,B00001000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B00000000,B00000000,B00000000,B00100111,B11000111,B11001000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00101111,B11000111,B11101000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00110111,B10000011,B11011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111001,B00000001,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00000000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00110000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11110000,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11110000,B01101000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110001,B11101000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B00111001,B11101000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111111,B11111000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111100,B00001000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B00000000,B00000000,B00000000,B00101111,B00111000,B00001000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B00000000,B00000000,B00000000,B00101110,B00011000,B00001000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00101100,B00011110,B00001000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011110,B00011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011111,B00011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00011000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000
+ };
+ const unsigned char status_screen2_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00011000,B11111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00011111,B00111000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B00011111,B10011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110100,B00011111,B00011000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101110,B00011110,B00001000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00011100,B00001000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00101111,B10111000,B00001000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111100,B00001000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111111,B11111000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B00111011,B11101000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B00000000,B00000000,B00000000,B00100000,B01110001,B11101000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B11110000,B11101000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00110001,B11110000,B01011000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00110011,B11110000,B00011000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111001,B11110000,B00111000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00111110,B00110000,B11111000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11111000
+ };
+ #else
+ const unsigned char status_screen0_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00101111,B01111011,B11010000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00101110,B00110001,B11010000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B00000000,B00000000,B00000000,B00101100,B00000000,B11010000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B11111100,B00010000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00110000,B11111100,B00110000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
+ };
+ const unsigned char status_screen1_bmp[] PROGMEM = {
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
+ B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
+ B00111111,B11000000,B00000000,B00011111,B11100000,B00000000,B00011111,B11100000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B01111101,B11100000,B00000000,B00111100,B11110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B01111001,B11100000,B00000000,B00111011,B01110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B01111000,B00010000,
+ B01110101,B11100000,B00000000,B00111111,B01110000,B00000000,B00111111,B01110000,B00000000,B00000000,B00000000,B00000000,B00100000,B00110000,B00010000,
+ B00111101,B11000000,B00000000,B00011110,B11100000,B00000000,B00011100,B11100000,B00000000,B00000000,B00000000,B00000000,B00101111,B00000011,B11010000,
+ B00111101,B11000000,B00000000,B00011101,B11100000,B00000000,B00011111,B01100000,B00000000,B00000000,B00000000,B00000000,B00101111,B10000111,B11010000,
+ B01111101,B11100000,B00000000,B00111011,B11110000,B00000000,B00111011,B01110000,B00000000,B00000000,B00000000,B00000000,B00100111,B10000111,B10010000,
+ B01111101,B11100000,B00000000,B00111000,B01110000,B00000000,B00111100,B11110000,B00000000,B00000000,B00000000,B00000000,B00100011,B10000111,B00010000,
+ B01111111,B11100000,B00000000,B00111111,B11110000,B00000000,B00111111,B11110000,B00000000,B00000000,B00000000,B00000000,B00110001,B10000110,B00110000,
+ B00011111,B10000000,B00000000,B00001111,B11000000,B00000000,B00001111,B11000000,B00000000,B00000000,B00000000,B00000000,B00111000,B00000000,B01110000,
+ B00001111,B00000000,B00000000,B00000111,B10000000,B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00111111,B11111111,B11110000,
+ B00000110,B00000000,B00000000,B00000011,B00000000,B00000000,B00000011,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000
+ };
+ #endif
+
+ #endif // HOTENDS
+
+ #endif // !HAS_HEATED_BED
+
+#endif // !CUSTOM_STATUS_SCREEN_IMAGE
#if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY) || ENABLED(MESH_EDIT_GFX_OVERLAY)
-
const unsigned char cw_bmp[] PROGMEM = {
B00000011,B11111000,B00000000,
B00001111,B11111110,B00000000,
@@ -608,6 +1149,11 @@
#define CUSTOM_BOOTSCREEN_BMPHEIGHT (sizeof(custom_start_bmp) / (CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH))
#endif
+#ifndef FAN_ANIM_FRAMES
+ #define FAN_ANIM_FRAMES 2
+#elif FAN_ANIM_FRAMES > 3
+ #error "Only 3 fan animation frames currently supported."
+#endif
#ifndef STATUS_SCREEN_X
#define STATUS_SCREEN_X 0
#endif
@@ -630,12 +1176,7 @@
#define STATUS_SCREEN_FAN_TEXT_X 104
#endif
#ifndef STATUS_SCREEN_FAN_TEXT_Y
- #define STATUS_SCREEN_FAN_TEXT_Y 27
-#endif
-#ifndef FAN_ANIM_FRAMES
- #define FAN_ANIM_FRAMES 2
-#elif FAN_ANIM_FRAMES > 4
- #error "Only 4 fan animation frames currently supported."
+ #define STATUS_SCREEN_FAN_TEXT_Y (FAN_ANIM_FRAMES > 2 ? 28 : 27)
#endif
#define BMP_SIZE (STATUS_BMP_BYTEWIDTH) * (STATUS_SCREENHEIGHT)
diff --git a/Marlin/endstop_interrupts.h b/Marlin/endstop_interrupts.h
index 6ad4fa55a4..62c2ea8532 100644
--- a/Marlin/endstop_interrupts.h
+++ b/Marlin/endstop_interrupts.h
@@ -24,7 +24,7 @@
* Endstop Interrupts
*
* Without endstop interrupts the endstop pins must be polled continually in
- * the stepper-ISR via endstops.update(), most of the time finding no change.
+ * the temperature-ISR via endstops.update(), most of the time finding no change.
* With this feature endstops.update() is called only when we know that at
* least one endstop has changed state, saving valuable CPU cycles.
*
@@ -40,6 +40,9 @@
#include "macros.h"
+// One ISR for all EXT-Interrupts
+void endstop_ISR(void) { endstops.update(); }
+
/**
* Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
*
@@ -72,40 +75,30 @@
0 )
#endif
-volatile uint8_t e_hit = 0; // Different from 0 when the endstops should be tested in detail.
- // Must be reset to 0 by the test function when finished.
// Install Pin change interrupt for a pin. Can be called multiple times.
-void pciSetup(byte pin) {
+void pciSetup(const int8_t pin) {
SBI(*digitalPinToPCMSK(pin), digitalPinToPCMSKbit(pin)); // enable pin
SBI(PCIFR, digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
}
-// This is what is really done inside the interrupts.
-FORCE_INLINE void endstop_ISR_worker( void ) {
- e_hit = 2; // Because the detection of a e-stop hit has a 1 step debouncer it has to be called at least twice.
-}
-
-// Use one Routine to handle each group
-// One ISR for all EXT-Interrupts
-void endstop_ISR(void) { endstop_ISR_worker(); }
// Handlers for pin change interrupts
#ifdef PCINT0_vect
- ISR(PCINT0_vect) { endstop_ISR_worker(); }
+ ISR(PCINT0_vect) { endstop_ISR(); }
#endif
#ifdef PCINT1_vect
- ISR(PCINT1_vect) { endstop_ISR_worker(); }
+ ISR(PCINT1_vect) { endstop_ISR(); }
#endif
#ifdef PCINT2_vect
- ISR(PCINT2_vect) { endstop_ISR_worker(); }
+ ISR(PCINT2_vect) { endstop_ISR(); }
#endif
#ifdef PCINT3_vect
- ISR(PCINT3_vect) { endstop_ISR_worker(); }
+ ISR(PCINT3_vect) { endstop_ISR(); }
#endif
void setup_endstop_interrupts( void ) {
diff --git a/Marlin/endstops.cpp b/Marlin/endstops.cpp
index f51a11b8af..3cffff1832 100644
--- a/Marlin/endstops.cpp
+++ b/Marlin/endstops.cpp
@@ -31,18 +31,23 @@
#include "stepper.h"
#include "ultralcd.h"
-// TEST_ENDSTOP: test the old and the current status of an endstop
-#define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits & old_endstop_bits, ENDSTOP))
+#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
+ #include "endstop_interrupts.h"
+#endif
Endstops endstops;
// public:
bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
-volatile char Endstops::endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
+volatile uint8_t Endstops::hit_state;
-Endstops::esbits_t Endstops::current_endstop_bits = 0,
- Endstops::old_endstop_bits = 0;
+Endstops::esbits_t Endstops::live_state = 0;
+
+#if ENABLED(ENDSTOP_NOISE_FILTER)
+ Endstops::esbits_t Endstops::validated_live_state;
+ uint8_t Endstops::endstop_poll_count;
+#endif
#if HAS_BED_PROBE
volatile bool Endstops::z_probe_enabled = false;
@@ -169,10 +174,90 @@ void Endstops::init() {
#endif
#endif
+ #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
+ setup_endstop_interrupts();
+ #endif
+
+ // Enable endstops
+ enable_globally(
+ #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
+ true
+ #else
+ false
+ #endif
+ );
+
} // Endstops::init
+// Called from ISR: Poll endstop state if required
+void Endstops::poll() {
+
+ #if ENABLED(PINS_DEBUGGING)
+ run_monitor(); // report changes in endstop status
+ #endif
+
+ #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) && ENABLED(ENDSTOP_NOISE_FILTER)
+ if (endstop_poll_count) update();
+ #elif DISABLED(ENDSTOP_INTERRUPTS_FEATURE) || ENABLED(ENDSTOP_NOISE_FILTER)
+ update();
+ #endif
+}
+
+void Endstops::enable_globally(const bool onoff) {
+ enabled_globally = enabled = onoff;
+
+ #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
+ update();
+ #endif
+}
+
+// Enable / disable endstop checking
+void Endstops::enable(const bool onoff) {
+ enabled = onoff;
+
+ #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
+ update();
+ #endif
+}
+
+// Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
+void Endstops::not_homing() {
+ enabled = enabled_globally;
+
+ #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
+ update();
+ #endif
+}
+
+// If the last move failed to trigger an endstop, call kill
+void Endstops::validate_homing_move() {
+ if (!trigger_state()) kill(PSTR(MSG_ERR_HOMING_FAILED));
+ hit_on_purpose();
+}
+
+// Enable / disable endstop z-probe checking
+#if HAS_BED_PROBE
+ void Endstops::enable_z_probe(const bool onoff) {
+ z_probe_enabled = onoff;
+
+ #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
+ update();
+ #endif
+ }
+#endif
+
+#if ENABLED(PINS_DEBUGGING)
+ void Endstops::run_monitor() {
+ if (!monitor_flag) return;
+ static uint8_t monitor_count = 16; // offset this check from the others
+ monitor_count += _BV(1); // 15 Hz
+ monitor_count &= 0x7F;
+ if (!monitor_count) monitor(); // report changes in endstop status
+ }
+#endif
+
void Endstops::report_state() {
- if (endstop_hit_bits) {
+ if (hit_state) {
#if ENABLED(ULTRA_LCD)
char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
#define _SET_STOP_CHAR(A,C) (chr## A = C)
@@ -181,11 +266,11 @@ void Endstops::report_state() {
#endif
#define _ENDSTOP_HIT_ECHO(A,C) do{ \
- SERIAL_ECHOPAIR(" " STRINGIFY(A) ":", stepper.triggered_position_mm(A ##_AXIS)); \
+ SERIAL_ECHOPAIR(" " STRINGIFY(A) ":", planner.triggered_position_mm(_AXIS(A))); \
_SET_STOP_CHAR(A,C); }while(0)
#define _ENDSTOP_HIT_TEST(A,C) \
- if (TEST(endstop_hit_bits, A ##_MIN) || TEST(endstop_hit_bits, A ##_MAX)) \
+ if (TEST(hit_state, A ##_MIN) || TEST(hit_state, A ##_MAX)) \
_ENDSTOP_HIT_ECHO(A,C)
#define ENDSTOP_HIT_TEST_X() _ENDSTOP_HIT_TEST(X,'X')
@@ -200,7 +285,7 @@ void Endstops::report_state() {
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
#define P_AXIS Z_AXIS
- if (TEST(endstop_hit_bits, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
+ if (TEST(hit_state, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
#endif
SERIAL_EOL();
@@ -211,7 +296,7 @@ void Endstops::report_state() {
hit_on_purpose();
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
- if (stepper.abort_on_endstop_hit) {
+ if (planner.abort_on_endstop_hit) {
card.sdprinting = false;
card.closefile();
quickstop_stepper();
@@ -273,144 +358,31 @@ void Endstops::M119() {
#endif
} // Endstops::M119
-#if ENABLED(X_DUAL_ENDSTOPS)
- void Endstops::test_dual_x_endstops(const EndstopEnum es1, const EndstopEnum es2) {
- const byte x_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for X, bit 1 for X2
- if (x_test && stepper.current_block->steps[X_AXIS] > 0) {
- SBI(endstop_hit_bits, X_MIN);
- if (!stepper.performing_homing || (x_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
- stepper.kill_current_block();
- }
- }
-#endif
-#if ENABLED(Y_DUAL_ENDSTOPS)
- void Endstops::test_dual_y_endstops(const EndstopEnum es1, const EndstopEnum es2) {
- const byte y_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Y, bit 1 for Y2
- if (y_test && stepper.current_block->steps[Y_AXIS] > 0) {
- SBI(endstop_hit_bits, Y_MIN);
- if (!stepper.performing_homing || (y_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
- stepper.kill_current_block();
- }
- }
-#endif
-#if ENABLED(Z_DUAL_ENDSTOPS)
- void Endstops::test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2) {
- const byte z_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Z, bit 1 for Z2
- if (z_test && stepper.current_block->steps[Z_AXIS] > 0) {
- SBI(endstop_hit_bits, Z_MIN);
- if (!stepper.performing_homing || (z_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
- stepper.kill_current_block();
- }
- }
-#endif
+// The following routines are called from an ISR context. It could be the temperature ISR, the
+// endstop ISR or the Stepper ISR.
-// Check endstops - Called from ISR!
+#define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
+#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
+#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
+
+// Check endstops - Could be called from ISR!
void Endstops::update() {
- #define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
- #define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
- #define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
- #define _ENDSTOP_HIT(AXIS, MINMAX) SBI(endstop_hit_bits, _ENDSTOP(AXIS, MINMAX))
+ #if DISABLED(ENDSTOP_NOISE_FILTER)
+ if (!abort_enabled()) return;
+ #endif
- #define SET_BIT(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
- // UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
- #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT(current_endstop_bits, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
- // COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
- #define COPY_BIT(DST, SRC_BIT, DST_BIT) SET_BIT(DST, DST_BIT, TEST(DST, SRC_BIT))
-
- #define UPDATE_ENDSTOP(AXIS,MINMAX) do { \
- UPDATE_ENDSTOP_BIT(AXIS, MINMAX); \
- if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
- _ENDSTOP_HIT(AXIS, MINMAX); \
- stepper.endstop_triggered(_AXIS(AXIS)); \
- } \
- }while(0)
+ #define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
+ #define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT))
#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
// If G38 command is active check Z_MIN_PROBE for ALL movement
- if (G38_move) {
- UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
- if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) {
- if (stepper.current_block->steps[_AXIS(X)] > 0) { _ENDSTOP_HIT(X, MIN); stepper.endstop_triggered(_AXIS(X)); }
- else if (stepper.current_block->steps[_AXIS(Y)] > 0) { _ENDSTOP_HIT(Y, MIN); stepper.endstop_triggered(_AXIS(Y)); }
- else if (stepper.current_block->steps[_AXIS(Z)] > 0) { _ENDSTOP_HIT(Z, MIN); stepper.endstop_triggered(_AXIS(Z)); }
- G38_endstop_hit = true;
- }
- }
- #endif
-
- /**
- * Define conditions for checking endstops
- */
-
- #if IS_CORE
- #define S_(N) stepper.current_block->steps[CORE_AXIS_##N]
- #define D_(N) stepper.motor_direction(CORE_AXIS_##N)
- #endif
-
- #if CORE_IS_XY || CORE_IS_XZ
- /**
- * Head direction in -X axis for CoreXY and CoreXZ bots.
- *
- * If steps differ, both axes are moving.
- * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z, handled below)
- * If DeltaA == DeltaB, the movement is only in the 1st axis (X)
- */
- #if ENABLED(COREXY) || ENABLED(COREXZ)
- #define X_CMP ==
- #else
- #define X_CMP !=
- #endif
- #define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
- #define X_AXIS_HEAD X_HEAD
- #else
- #define X_MOVE_TEST stepper.current_block->steps[X_AXIS] > 0
- #define X_AXIS_HEAD X_AXIS
- #endif
-
- #if CORE_IS_XY || CORE_IS_YZ
- /**
- * Head direction in -Y axis for CoreXY / CoreYZ bots.
- *
- * If steps differ, both axes are moving
- * If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y)
- * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z)
- */
- #if ENABLED(COREYX) || ENABLED(COREYZ)
- #define Y_CMP ==
- #else
- #define Y_CMP !=
- #endif
- #define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
- #define Y_AXIS_HEAD Y_HEAD
- #else
- #define Y_MOVE_TEST stepper.current_block->steps[Y_AXIS] > 0
- #define Y_AXIS_HEAD Y_AXIS
- #endif
-
- #if CORE_IS_XZ || CORE_IS_YZ
- /**
- * Head direction in -Z axis for CoreXZ or CoreYZ bots.
- *
- * If steps differ, both axes are moving
- * If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y, already handled above)
- * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Z)
- */
- #if ENABLED(COREZX) || ENABLED(COREZY)
- #define Z_CMP ==
- #else
- #define Z_CMP !=
- #endif
- #define Z_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
- #define Z_AXIS_HEAD Z_HEAD
- #else
- #define Z_MOVE_TEST stepper.current_block->steps[Z_AXIS] > 0
- #define Z_AXIS_HEAD Z_AXIS
+ if (G38_move) UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
#endif
// With Dual X, endstops are only checked in the homing direction for the active extruder
#if ENABLED(DUAL_X_CARRIAGE)
- #define E0_ACTIVE stepper.current_block->active_extruder == 0
+ #define E0_ACTIVE stepper.movement_extruder() == 0
#define X_MIN_TEST ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
#define X_MAX_TEST ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
#else
@@ -418,127 +390,358 @@ void Endstops::update() {
#define X_MAX_TEST true
#endif
+ // Use HEAD for core axes, AXIS for others
+ #if CORE_IS_XY || CORE_IS_XZ
+ #define X_AXIS_HEAD X_HEAD
+ #else
+ #define X_AXIS_HEAD X_AXIS
+ #endif
+ #if CORE_IS_XY || CORE_IS_YZ
+ #define Y_AXIS_HEAD Y_HEAD
+ #else
+ #define Y_AXIS_HEAD Y_AXIS
+ #endif
+ #if CORE_IS_XZ || CORE_IS_YZ
+ #define Z_AXIS_HEAD Z_HEAD
+ #else
+ #define Z_AXIS_HEAD Z_AXIS
+ #endif
+
/**
- * Check and update endstops according to conditions
+ * Check and update endstops
*/
- if (stepper.current_block) {
+ #if HAS_X_MIN
+ #if ENABLED(X_DUAL_ENDSTOPS)
+ UPDATE_ENDSTOP_BIT(X, MIN);
+ #if HAS_X2_MIN
+ UPDATE_ENDSTOP_BIT(X2, MIN);
+ #else
+ COPY_LIVE_STATE(X_MIN, X2_MIN);
+ #endif
+ #else
+ UPDATE_ENDSTOP_BIT(X, MIN);
+ #endif
+ #endif
- if (X_MOVE_TEST) {
- if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
- #if HAS_X_MIN
- #if ENABLED(X_DUAL_ENDSTOPS)
- UPDATE_ENDSTOP_BIT(X, MIN);
- #if HAS_X2_MIN
- UPDATE_ENDSTOP_BIT(X2, MIN);
- #else
- COPY_BIT(current_endstop_bits, X_MIN, X2_MIN);
- #endif
- test_dual_x_endstops(X_MIN, X2_MIN);
- #else
- if (X_MIN_TEST) UPDATE_ENDSTOP(X, MIN);
- #endif
- #endif
- }
- else { // +direction
- #if HAS_X_MAX
- #if ENABLED(X_DUAL_ENDSTOPS)
- UPDATE_ENDSTOP_BIT(X, MAX);
- #if HAS_X2_MAX
- UPDATE_ENDSTOP_BIT(X2, MAX);
- #else
- COPY_BIT(current_endstop_bits, X_MAX, X2_MAX);
- #endif
- test_dual_x_endstops(X_MAX, X2_MAX);
- #else
- if (X_MAX_TEST) UPDATE_ENDSTOP(X, MAX);
- #endif
- #endif
+ #if HAS_X_MAX
+ #if ENABLED(X_DUAL_ENDSTOPS)
+ UPDATE_ENDSTOP_BIT(X, MAX);
+ #if HAS_X2_MAX
+ UPDATE_ENDSTOP_BIT(X2, MAX);
+ #else
+ COPY_LIVE_STATE(X_MAX, X2_MAX);
+ #endif
+ #else
+ UPDATE_ENDSTOP_BIT(X, MAX);
+ #endif
+ #endif
+
+ #if HAS_Y_MIN
+ #if ENABLED(Y_DUAL_ENDSTOPS)
+ UPDATE_ENDSTOP_BIT(Y, MIN);
+ #if HAS_Y2_MIN
+ UPDATE_ENDSTOP_BIT(Y2, MIN);
+ #else
+ COPY_LIVE_STATE(Y_MIN, Y2_MIN);
+ #endif
+ #else
+ UPDATE_ENDSTOP_BIT(Y, MIN);
+ #endif
+ #endif
+
+ #if HAS_Y_MAX
+ #if ENABLED(Y_DUAL_ENDSTOPS)
+ UPDATE_ENDSTOP_BIT(Y, MAX);
+ #if HAS_Y2_MAX
+ UPDATE_ENDSTOP_BIT(Y2, MAX);
+ #else
+ COPY_LIVE_STATE(Y_MAX, Y2_MAX);
+ #endif
+ #else
+ UPDATE_ENDSTOP_BIT(Y, MAX);
+ #endif
+ #endif
+
+ #if HAS_Z_MIN
+ #if ENABLED(Z_DUAL_ENDSTOPS)
+ UPDATE_ENDSTOP_BIT(Z, MIN);
+ #if HAS_Z2_MIN
+ UPDATE_ENDSTOP_BIT(Z2, MIN);
+ #else
+ COPY_LIVE_STATE(Z_MIN, Z2_MIN);
+ #endif
+ #elif ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
+ UPDATE_ENDSTOP_BIT(Z, MIN);
+ #elif Z_HOME_DIR < 0
+ UPDATE_ENDSTOP_BIT(Z, MIN);
+ #endif
+ #endif
+
+ // When closing the gap check the enabled probe
+ #if ENABLED(Z_MIN_PROBE_ENDSTOP)
+ UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
+ #endif
+
+ #if HAS_Z_MAX
+ // Check both Z dual endstops
+ #if ENABLED(Z_DUAL_ENDSTOPS)
+ UPDATE_ENDSTOP_BIT(Z, MAX);
+ #if HAS_Z2_MAX
+ UPDATE_ENDSTOP_BIT(Z2, MAX);
+ #else
+ COPY_LIVE_STATE(Z_MAX, Z2_MAX);
+ #endif
+ #elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
+ // If this pin isn't the bed probe it's the Z endstop
+ UPDATE_ENDSTOP_BIT(Z, MAX);
+ #endif
+ #endif
+
+ #if ENABLED(ENDSTOP_NOISE_FILTER)
+ /**
+ * Filtering out noise on endstops requires a delayed decision. Let's assume, due to noise,
+ * that 50% of endstop signal samples are good and 50% are bad (assuming normal distribution
+ * of random noise). Then the first sample has a 50% chance to be good or bad. The 2nd sample
+ * also has a 50% chance to be good or bad. The chances of 2 samples both being bad becomes
+ * 50% of 50%, or 25%. That was the previous implementation of Marlin endstop handling. It
+ * reduces chances of bad readings in half, at the cost of 1 extra sample period, but chances
+ * still exist. The only way to reduce them further is to increase the number of samples.
+ * To reduce the chance to 1% (1/128th) requires 7 samples (adding 7ms of delay).
+ */
+ static esbits_t old_live_state;
+ if (old_live_state != live_state) {
+ endstop_poll_count = 7;
+ old_live_state = live_state;
+ }
+ else if (endstop_poll_count && !--endstop_poll_count)
+ validated_live_state = live_state;
+
+ if (!abort_enabled()) return;
+
+ #endif
+
+ // Test the current status of an endstop
+ #define TEST_ENDSTOP(ENDSTOP) (TEST(state(), ENDSTOP))
+
+ // Record endstop was hit
+ #define _ENDSTOP_HIT(AXIS, MINMAX) SBI(hit_state, _ENDSTOP(AXIS, MINMAX))
+
+ // Call the endstop triggered routine for single endstops
+ #define PROCESS_ENDSTOP(AXIS,MINMAX) do { \
+ if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
+ _ENDSTOP_HIT(AXIS, MINMAX); \
+ planner.endstop_triggered(_AXIS(AXIS)); \
+ } \
+ }while(0)
+
+ // Call the endstop triggered routine for dual endstops
+ #define PROCESS_DUAL_ENDSTOP(AXIS1, AXIS2, MINMAX) do { \
+ const byte dual_hit = TEST_ENDSTOP(_ENDSTOP(AXIS1, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(AXIS2, MINMAX)) << 1); \
+ if (dual_hit) { \
+ _ENDSTOP_HIT(AXIS1, MINMAX); \
+ /* if not performing home or if both endstops were trigged during homing... */ \
+ if (!stepper.homing_dual_axis || dual_hit == 0x3) \
+ planner.endstop_triggered(_AXIS(AXIS1)); \
+ } \
+ }while(0)
+
+ #if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
+ // If G38 command is active check Z_MIN_PROBE for ALL movement
+ if (G38_move) {
+ if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) {
+ if (stepper.axis_is_moving(X_AXIS)) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(X_AXIS); }
+ else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(Y_AXIS); }
+ else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(Z_AXIS); }
+ G38_endstop_hit = true;
}
}
+ #endif
- if (Y_MOVE_TEST) {
- if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
- #if HAS_Y_MIN
- #if ENABLED(Y_DUAL_ENDSTOPS)
- UPDATE_ENDSTOP_BIT(Y, MIN);
- #if HAS_Y2_MIN
- UPDATE_ENDSTOP_BIT(Y2, MIN);
- #else
- COPY_BIT(current_endstop_bits, Y_MIN, Y2_MIN);
- #endif
- test_dual_y_endstops(Y_MIN, Y2_MIN);
- #else
- UPDATE_ENDSTOP(Y, MIN);
- #endif
+ // Now, we must signal, after validation, if an endstop limit is pressed or not
+ if (stepper.axis_is_moving(X_AXIS)) {
+ if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
+ #if HAS_X_MIN
+ #if ENABLED(X_DUAL_ENDSTOPS)
+ PROCESS_DUAL_ENDSTOP(X, X2, MIN);
+ #else
+ if (X_MIN_TEST) PROCESS_ENDSTOP(X, MIN);
#endif
- }
- else { // +direction
- #if HAS_Y_MAX
- #if ENABLED(Y_DUAL_ENDSTOPS)
- UPDATE_ENDSTOP_BIT(Y, MAX);
- #if HAS_Y2_MAX
- UPDATE_ENDSTOP_BIT(Y2, MAX);
- #else
- COPY_BIT(current_endstop_bits, Y_MAX, Y2_MAX);
- #endif
- test_dual_y_endstops(Y_MAX, Y2_MAX);
- #else
- UPDATE_ENDSTOP(Y, MAX);
- #endif
- #endif
- }
+ #endif
}
+ else { // +direction
+ #if HAS_X_MAX
+ #if ENABLED(X_DUAL_ENDSTOPS)
+ PROCESS_DUAL_ENDSTOP(X, X2, MAX);
+ #else
+ if (X_MAX_TEST) PROCESS_ENDSTOP(X, MAX);
+ #endif
+ #endif
+ }
+ }
- if (Z_MOVE_TEST) {
- if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
- #if HAS_Z_MIN
- #if ENABLED(Z_DUAL_ENDSTOPS)
- UPDATE_ENDSTOP_BIT(Z, MIN);
- #if HAS_Z2_MIN
- UPDATE_ENDSTOP_BIT(Z2, MIN);
- #else
- COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
- #endif
- test_dual_z_endstops(Z_MIN, Z2_MIN);
+ if (stepper.axis_is_moving(Y_AXIS)) {
+ if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
+ #if HAS_Y_MIN
+ #if ENABLED(Y_DUAL_ENDSTOPS)
+ PROCESS_DUAL_ENDSTOP(Y, Y2, MIN);
+ #else
+ PROCESS_ENDSTOP(Y, MIN);
+ #endif
+ #endif
+ }
+ else { // +direction
+ #if HAS_Y_MAX
+ #if ENABLED(Y_DUAL_ENDSTOPS)
+ PROCESS_DUAL_ENDSTOP(Y, Y2, MAX);
+ #else
+ PROCESS_ENDSTOP(Y, MAX);
+ #endif
+ #endif
+ }
+ }
+
+ if (stepper.axis_is_moving(Z_AXIS)) {
+ if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
+ #if HAS_Z_MIN
+ #if ENABLED(Z_DUAL_ENDSTOPS)
+ PROCESS_DUAL_ENDSTOP(Z, Z2, MIN);
+ #else
+ #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
+ if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN);
+ #elif ENABLED(Z_MIN_PROBE_ENDSTOP)
+ if (!z_probe_enabled) PROCESS_ENDSTOP(Z, MIN);
#else
- #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
- if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN);
- #else
- UPDATE_ENDSTOP(Z, MIN);
- #endif
+ PROCESS_ENDSTOP(Z, MIN);
#endif
#endif
+ #endif
- // When closing the gap check the enabled probe
- #if ENABLED(Z_MIN_PROBE_ENDSTOP)
- if (z_probe_enabled) {
- UPDATE_ENDSTOP(Z, MIN_PROBE);
- if (TEST_ENDSTOP(Z_MIN_PROBE)) SBI(endstop_hit_bits, Z_MIN_PROBE);
- }
- #endif
- }
- else { // Z +direction. Gantry up, bed down.
- #if HAS_Z_MAX
- // Check both Z dual endstops
- #if ENABLED(Z_DUAL_ENDSTOPS)
- UPDATE_ENDSTOP_BIT(Z, MAX);
- #if HAS_Z2_MAX
- UPDATE_ENDSTOP_BIT(Z2, MAX);
- #else
- COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
- #endif
- test_dual_z_endstops(Z_MAX, Z2_MAX);
+ // When closing the gap check the enabled probe
+ #if ENABLED(Z_MIN_PROBE_ENDSTOP)
+ if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN_PROBE);
+ #endif
+ }
+ else { // Z +direction. Gantry up, bed down.
+ #if HAS_Z_MAX
+ #if ENABLED(Z_DUAL_ENDSTOPS)
+ PROCESS_DUAL_ENDSTOP(Z, Z2, MAX);
+ #elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
// If this pin is not hijacked for the bed probe
// then it belongs to the Z endstop
- #elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
- UPDATE_ENDSTOP(Z, MAX);
- #endif
+ PROCESS_ENDSTOP(Z, MAX);
#endif
- }
+ #endif
}
-
- } // stepper.current_block
-
- old_endstop_bits = current_endstop_bits;
-
+ }
} // Endstops::update()
+
+#if ENABLED(PINS_DEBUGGING)
+
+ bool Endstops::monitor_flag = false;
+
+ /**
+ * monitors endstops & Z probe for changes
+ *
+ * If a change is detected then the LED is toggled and
+ * a message is sent out the serial port
+ *
+ * Yes, we could miss a rapid back & forth change but
+ * that won't matter because this is all manual.
+ *
+ */
+ void Endstops::monitor() {
+
+ static uint16_t old_live_state_local = 0;
+ static uint8_t local_LED_status = 0;
+ uint16_t live_state_local = 0;
+
+ #if HAS_X_MIN
+ if (READ(X_MIN_PIN)) SBI(live_state_local, X_MIN);
+ #endif
+ #if HAS_X_MAX
+ if (READ(X_MAX_PIN)) SBI(live_state_local, X_MAX);
+ #endif
+ #if HAS_Y_MIN
+ if (READ(Y_MIN_PIN)) SBI(live_state_local, Y_MIN);
+ #endif
+ #if HAS_Y_MAX
+ if (READ(Y_MAX_PIN)) SBI(live_state_local, Y_MAX);
+ #endif
+ #if HAS_Z_MIN
+ if (READ(Z_MIN_PIN)) SBI(live_state_local, Z_MIN);
+ #endif
+ #if HAS_Z_MAX
+ if (READ(Z_MAX_PIN)) SBI(live_state_local, Z_MAX);
+ #endif
+ #if HAS_Z_MIN_PROBE_PIN
+ if (READ(Z_MIN_PROBE_PIN)) SBI(live_state_local, Z_MIN_PROBE);
+ #endif
+ #if HAS_X2_MIN
+ if (READ(X2_MIN_PIN)) SBI(live_state_local, X2_MIN);
+ #endif
+ #if HAS_X2_MAX
+ if (READ(X2_MAX_PIN)) SBI(live_state_local, X2_MAX);
+ #endif
+ #if HAS_Y2_MIN
+ if (READ(Y2_MIN_PIN)) SBI(live_state_local, Y2_MIN);
+ #endif
+ #if HAS_Y2_MAX
+ if (READ(Y2_MAX_PIN)) SBI(live_state_local, Y2_MAX);
+ #endif
+ #if HAS_Z2_MIN
+ if (READ(Z2_MIN_PIN)) SBI(live_state_local, Z2_MIN);
+ #endif
+ #if HAS_Z2_MAX
+ if (READ(Z2_MAX_PIN)) SBI(live_state_local, Z2_MAX);
+ #endif
+
+ uint16_t endstop_change = live_state_local ^ old_live_state_local;
+
+ if (endstop_change) {
+ #if HAS_X_MIN
+ if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", TEST(live_state_local, X_MIN));
+ #endif
+ #if HAS_X_MAX
+ if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", TEST(live_state_local, X_MAX));
+ #endif
+ #if HAS_Y_MIN
+ if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", TEST(live_state_local, Y_MIN));
+ #endif
+ #if HAS_Y_MAX
+ if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", TEST(live_state_local, Y_MAX));
+ #endif
+ #if HAS_Z_MIN
+ if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", TEST(live_state_local, Z_MIN));
+ #endif
+ #if HAS_Z_MAX
+ if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", TEST(live_state_local, Z_MAX));
+ #endif
+ #if HAS_Z_MIN_PROBE_PIN
+ if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", TEST(live_state_local, Z_MIN_PROBE));
+ #endif
+ #if HAS_X2_MIN
+ if (TEST(endstop_change, X2_MIN)) SERIAL_PROTOCOLPAIR(" X2_MIN:", TEST(live_state_local, X2_MIN));
+ #endif
+ #if HAS_X2_MAX
+ if (TEST(endstop_change, X2_MAX)) SERIAL_PROTOCOLPAIR(" X2_MAX:", TEST(live_state_local, X2_MAX));
+ #endif
+ #if HAS_Y2_MIN
+ if (TEST(endstop_change, Y2_MIN)) SERIAL_PROTOCOLPAIR(" Y2_MIN:", TEST(live_state_local, Y2_MIN));
+ #endif
+ #if HAS_Y2_MAX
+ if (TEST(endstop_change, Y2_MAX)) SERIAL_PROTOCOLPAIR(" Y2_MAX:", TEST(live_state_local, Y2_MAX));
+ #endif
+ #if HAS_Z2_MIN
+ if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", TEST(live_state_local, Z2_MIN));
+ #endif
+ #if HAS_Z2_MAX
+ if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", TEST(live_state_local, Z2_MAX));
+ #endif
+ SERIAL_PROTOCOLPGM("\n\n");
+ analogWrite(LED_PIN, local_LED_status);
+ local_LED_status ^= 255;
+ old_live_state_local = live_state_local;
+ }
+ }
+
+#endif // PINS_DEBUGGING
diff --git a/Marlin/endstops.h b/Marlin/endstops.h
index 96cb3d089c..a6ea580d30 100644
--- a/Marlin/endstops.h
+++ b/Marlin/endstops.h
@@ -27,15 +27,29 @@
#ifndef __ENDSTOPS_H__
#define __ENDSTOPS_H__
-#include "enum.h"
#include "MarlinConfig.h"
+enum EndstopEnum : char {
+ X_MIN,
+ Y_MIN,
+ Z_MIN,
+ Z_MIN_PROBE,
+ X_MAX,
+ Y_MAX,
+ Z_MAX,
+ X2_MIN,
+ X2_MAX,
+ Y2_MIN,
+ Y2_MAX,
+ Z2_MIN,
+ Z2_MAX
+};
+
class Endstops {
public:
static bool enabled, enabled_globally;
- static volatile char endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
typedef uint16_t esbits_t;
@@ -49,20 +63,20 @@ class Endstops {
static float z_endstop_adj;
#endif
#else
- typedef byte esbits_t;
+ typedef uint8_t esbits_t;
#endif
- static esbits_t current_endstop_bits, old_endstop_bits;
+ private:
+ static esbits_t live_state;
+ static volatile uint8_t hit_state; // Use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT index
- Endstops() {
- enable_globally(
- #if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
- true
- #else
- false
- #endif
- );
- };
+ #if ENABLED(ENDSTOP_NOISE_FILTER)
+ static esbits_t validated_live_state;
+ static uint8_t endstop_poll_count; // Countdown from threshold for polling
+ #endif
+
+ public:
+ Endstops() {};
/**
* Initialize the endstop pins
@@ -70,14 +84,50 @@ class Endstops {
static void init();
/**
- * Update the endstops bits from the pins
+ * Are endstops or the probe set to abort the move?
+ */
+ FORCE_INLINE static bool abort_enabled() {
+ return (enabled
+ #if HAS_BED_PROBE
+ || z_probe_enabled
+ #endif
+ );
+ }
+
+ /**
+ * Periodic call to poll endstops if required. Called from temperature ISR
+ */
+ static void poll();
+
+ /**
+ * Update endstops bits from the pins. Apply filtering to get a verified state.
+ * If abort_enabled() and moving towards a triggered switch, abort the current move.
+ * Called from ISR contexts.
*/
static void update();
/**
- * Print an error message reporting the position when the endstops were last hit.
+ * Get Endstop hit state.
*/
- static void report_state(); //call from somewhere to create an serial error message with the locations the endstops where hit, in case they were triggered
+ FORCE_INLINE static uint8_t trigger_state() { return hit_state; }
+
+ /**
+ * Get current endstops state
+ */
+ FORCE_INLINE static esbits_t state() {
+ return
+ #if ENABLED(ENDSTOP_NOISE_FILTER)
+ validated_live_state
+ #else
+ live_state
+ #endif
+ ;
+ }
+
+ /**
+ * Report endstop hits to serial. Called from loop().
+ */
+ static void report_state();
/**
* Report endstop positions in response to M119
@@ -85,42 +135,34 @@ class Endstops {
static void M119();
// Enable / disable endstop checking globally
- static void enable_globally(bool onoff=true) { enabled_globally = enabled = onoff; }
+ static void enable_globally(const bool onoff=true);
// Enable / disable endstop checking
- static void enable(bool onoff=true) { enabled = onoff; }
+ static void enable(const bool onoff=true);
// Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
- static void not_homing() { enabled = enabled_globally; }
+ static void not_homing();
+
+ // If the last move failed to trigger an endstop, call kill
+ static void validate_homing_move();
// Clear endstops (i.e., they were hit intentionally) to suppress the report
- static void hit_on_purpose() { endstop_hit_bits = 0; }
+ FORCE_INLINE static void hit_on_purpose() { hit_state = 0; }
// Enable / disable endstop z-probe checking
#if HAS_BED_PROBE
static volatile bool z_probe_enabled;
- static void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; }
+ static void enable_z_probe(const bool onoff=true);
#endif
- private:
-
- #if ENABLED(X_DUAL_ENDSTOPS)
- static void test_dual_x_endstops(const EndstopEnum es1, const EndstopEnum es2);
- #endif
- #if ENABLED(Y_DUAL_ENDSTOPS)
- static void test_dual_y_endstops(const EndstopEnum es1, const EndstopEnum es2);
- #endif
- #if ENABLED(Z_DUAL_ENDSTOPS)
- static void test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2);
+ // Debugging of endstops
+ #if ENABLED(PINS_DEBUGGING)
+ static bool monitor_flag;
+ static void monitor();
+ static void run_monitor();
#endif
};
extern Endstops endstops;
-#if HAS_BED_PROBE
- #define ENDSTOPS_ENABLED (endstops.enabled || endstops.z_probe_enabled)
-#else
- #define ENDSTOPS_ENABLED endstops.enabled
-#endif
-
#endif // __ENDSTOPS_H__
diff --git a/Marlin/enum.h b/Marlin/enum.h
index 378e47f320..d525e8ee9b 100644
--- a/Marlin/enum.h
+++ b/Marlin/enum.h
@@ -28,10 +28,9 @@
/**
* Axis indices as enumerated constants
*
- * Special axis:
- * - A_AXIS and B_AXIS are used by COREXY printers
- * - X_HEAD and Y_HEAD is used for systems that don't have a 1:1 relationship
- * between X_AXIS and X Head movement, like CoreXY bots
+ * - X_AXIS, Y_AXIS, and Z_AXIS should be used for axes in Cartesian space
+ * - A_AXIS, B_AXIS, and C_AXIS should be used for Steppers, corresponding to XYZ on Cartesians
+ * - X_HEAD, Y_HEAD, and Z_HEAD should be used for Steppers on Core kinematics
*/
enum AxisEnum : unsigned char {
X_AXIS = 0,
@@ -88,22 +87,6 @@ enum DebugFlags : unsigned char {
DEBUG_ALL = 0xFF
};
-enum EndstopEnum : char {
- X_MIN,
- Y_MIN,
- Z_MIN,
- Z_MIN_PROBE,
- X_MAX,
- Y_MAX,
- Z_MAX,
- X2_MIN,
- X2_MAX,
- Y2_MIN,
- Y2_MAX,
- Z2_MIN,
- Z2_MAX
-};
-
#if ENABLED(ADVANCED_PAUSE_FEATURE)
enum AdvancedPauseMenuResponse : char {
ADVANCED_PAUSE_RESPONSE_WAIT_FOR,
diff --git a/Marlin/fastio.h b/Marlin/fastio.h
index 4b6ec4e495..839db99293 100644
--- a/Marlin/fastio.h
+++ b/Marlin/fastio.h
@@ -28,7 +28,6 @@
#include
-typedef int8_t pin_t;
#ifndef _FASTIO_ARDUINO_H_
#define _FASTIO_ARDUINO_H_
@@ -38,7 +37,7 @@ typedef int8_t pin_t;
#define AVR_ATmega1284_FAMILY (defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__))
#define AVR_ATmega2560_FAMILY (defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__))
#define AVR_ATmega2561_FAMILY (defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__))
-#define AVR_ATmega328_FAMILY (defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328p__))
+#define AVR_ATmega328_FAMILY (defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined(__AVR_ATmega328P__))
/**
* Include Ports and Functions
@@ -54,7 +53,7 @@ typedef int8_t pin_t;
#elif AVR_ATmega2561_FAMILY
#include "fastio_1281.h"
#else
- #error "Pins for this chip not defined in Arduino.h! If you have a working pins definition, please contribute!"
+ #error "No FastIO definition for the selected AVR Board."
#endif
#include "macros.h"
diff --git a/Marlin/fwretract.cpp b/Marlin/fwretract.cpp
index a913c364c3..997e49a7f9 100644
--- a/Marlin/fwretract.cpp
+++ b/Marlin/fwretract.cpp
@@ -107,7 +107,7 @@ void FWRetract::retract(const bool retracting
// G11 priority to recover the long retract if activated
if (!retracting) swapping = retracted_swap[active_extruder];
#else
- const bool swapping = false;
+ constexpr bool swapping = false;
#endif
/* // debugging
@@ -127,54 +127,48 @@ void FWRetract::retract(const bool retracting
SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
//*/
- const float old_feedrate_mm_s = feedrate_mm_s;
+ const float old_feedrate_mm_s = feedrate_mm_s,
+ renormalize = RECIPROCAL(planner.e_factor[active_extruder]),
+ base_retract = swapping ? swap_retract_length : retract_length,
+ old_z = current_position[Z_AXIS],
+ old_e = current_position[E_AXIS];
// The current position will be the destination for E and Z moves
set_destination_from_current();
- stepper.synchronize(); // Wait for buffered moves to complete
-
- const float renormalize = 1.0 / planner.e_factor[active_extruder];
if (retracting) {
// Retract by moving from a faux E position back to the current E position
feedrate_mm_s = retract_feedrate_mm_s;
- current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) * renormalize;
- sync_plan_position_e();
- prepare_move_to_destination(); // set_current_to_destination
+ destination[E_AXIS] -= base_retract * renormalize;
+ prepare_move_to_destination(); // set_current_to_destination
// Is a Z hop set, and has the hop not yet been done?
- // No double zlifting
- // Feedrate to the max
if (retract_zlift > 0.01 && !hop_amount) { // Apply hop only once
- const float old_z = current_position[Z_AXIS];
hop_amount += retract_zlift; // Add to the hop total (again, only once)
destination[Z_AXIS] += retract_zlift; // Raise Z by the zlift (M207 Z) amount
feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS]; // Maximum Z feedrate
prepare_move_to_destination(); // Raise up, set_current_to_destination
- current_position[Z_AXIS] = old_z; // Spoof the Z position in the planner
- SYNC_PLAN_POSITION_KINEMATIC();
}
}
else {
// If a hop was done and Z hasn't changed, undo the Z hop
if (hop_amount) {
- current_position[Z_AXIS] += hop_amount; // Set actual Z (due to the prior hop)
- SYNC_PLAN_POSITION_KINEMATIC(); // Spoof the Z position in the planner
+ current_position[Z_AXIS] += hop_amount; // Restore the actual Z position
+ SYNC_PLAN_POSITION_KINEMATIC(); // Unspoof the position planner
feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS]; // Z feedrate to max
prepare_move_to_destination(); // Lower Z, set_current_to_destination
hop_amount = 0.0; // Clear the hop amount
}
- // A retract multiplier has been added here to get faster swap recovery
+ destination[E_AXIS] += (base_retract + (swapping ? swap_retract_recover_length : retract_recover_length)) * renormalize;
feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s;
-
- current_position[E_AXIS] -= (swapping ? swap_retract_length + swap_retract_recover_length
- : retract_length + retract_recover_length) * renormalize;
- sync_plan_position_e();
prepare_move_to_destination(); // Recover E, set_current_to_destination
}
feedrate_mm_s = old_feedrate_mm_s; // Restore original feedrate
+ current_position[Z_AXIS] = old_z; // Restore Z and E positions
+ current_position[E_AXIS] = old_e;
+ SYNC_PLAN_POSITION_KINEMATIC(); // As if the move never took place
retracted[active_extruder] = retracting; // Active extruder now retracted / recovered
diff --git a/Marlin/language_cz.h b/Marlin/language_cz.h
index 95f3cdfba0..3002390b38 100644
--- a/Marlin/language_cz.h
+++ b/Marlin/language_cz.h
@@ -146,8 +146,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL Postupne")
#define MSG_LED_CONTROL _UxGT("LED Nastaveni")
-#define MSG_LEDS_ON _UxGT("Svetla Zap")
-#define MSG_LEDS_OFF _UxGT("Svetla Vyp")
+#define MSG_LEDS _UxGT("Svetla")
#define MSG_LED_PRESETS _UxGT("Svetla Predvolby")
#define MSG_SET_LEDS_RED _UxGT("Cervena")
#define MSG_SET_LEDS_ORANGE _UxGT("Oranzova")
diff --git a/Marlin/language_cz_utf8.h b/Marlin/language_cz_utf8.h
index 49ea9bd17e..f962d41a80 100644
--- a/Marlin/language_cz_utf8.h
+++ b/Marlin/language_cz_utf8.h
@@ -149,8 +149,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL Postupně")
#define MSG_LED_CONTROL _UxGT("LED Nastavení")
-#define MSG_LEDS_ON _UxGT("Světla Zap")
-#define MSG_LEDS_OFF _UxGT("Světla Vyp")
+#define MSG_LEDS _UxGT("Světla")
#define MSG_LED_PRESETS _UxGT("Světla Předvolby")
#define MSG_SET_LEDS_RED _UxGT("Červená")
#define MSG_SET_LEDS_ORANGE _UxGT("Oranžová")
diff --git a/Marlin/language_de.h b/Marlin/language_de.h
index e2d11f6fc9..c662ec25a2 100644
--- a/Marlin/language_de.h
+++ b/Marlin/language_de.h
@@ -311,8 +311,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("Schrittweises UBL")
#define MSG_LED_CONTROL _UxGT("LED Kontrolle")
-#define MSG_LEDS_ON _UxGT("Licht an")
-#define MSG_LEDS_OFF _UxGT("Licht aus")
+#define MSG_LEDS _UxGT("Licht")
#define MSG_LED_PRESETS _UxGT("Licht Einstellungen")
#define MSG_SET_LEDS_RED _UxGT("Rot")
#define MSG_SET_LEDS_ORANGE _UxGT("Orange")
diff --git a/Marlin/language_en.h b/Marlin/language_en.h
index 3654e704fc..1f5ad92508 100644
--- a/Marlin/language_en.h
+++ b/Marlin/language_en.h
@@ -371,11 +371,8 @@
#ifndef MSG_LED_CONTROL
#define MSG_LED_CONTROL _UxGT("LED Control")
#endif
-#ifndef MSG_LEDS_ON
- #define MSG_LEDS_ON _UxGT("Lights On")
-#endif
-#ifndef MSG_LEDS_OFF
- #define MSG_LEDS_OFF _UxGT("Lights Off")
+#ifndef MSG_LEDS
+ #define MSG_LEDS _UxGT("Lights")
#endif
#ifndef MSG_LED_PRESETS
#define MSG_LED_PRESETS _UxGT("Light Presets")
@@ -540,6 +537,9 @@
#ifndef MSG_VE_JERK
#define MSG_VE_JERK _UxGT("Ve-jerk")
#endif
+#ifndef MSG_JUNCTION_DEVIATION
+ #define MSG_JUNCTION_DEVIATION _UxGT("Junction Dev")
+#endif
#ifndef MSG_VELOCITY
#define MSG_VELOCITY _UxGT("Velocity")
#endif
@@ -666,6 +666,9 @@
#ifndef MSG_STOP_PRINT
#define MSG_STOP_PRINT _UxGT("Stop print")
#endif
+#ifndef MSG_POWER_LOSS_RECOVERY
+ #define MSG_POWER_LOSS_RECOVERY _UxGT("Power-Loss Recovery")
+#endif
#ifndef MSG_CARD_MENU
#define MSG_CARD_MENU _UxGT("Print from SD")
#endif
@@ -742,7 +745,7 @@
#define MSG_CNG_SDCARD _UxGT("Change SD card")
#endif
#ifndef MSG_ZPROBE_OUT
- #define MSG_ZPROBE_OUT _UxGT("Z probe out. bed")
+ #define MSG_ZPROBE_OUT _UxGT("Z Probe past bed")
#endif
#ifndef MSG_SKEW_FACTOR
#define MSG_SKEW_FACTOR _UxGT("Skew Factor")
@@ -769,7 +772,7 @@
#define MSG_FIRST _UxGT("first")
#endif
#ifndef MSG_ZPROBE_ZOFFSET
- #define MSG_ZPROBE_ZOFFSET _UxGT("Z Offset")
+ #define MSG_ZPROBE_ZOFFSET _UxGT("Probe Z Offset")
#endif
#ifndef MSG_BABYSTEP_X
#define MSG_BABYSTEP_X _UxGT("Babystep X")
diff --git a/Marlin/language_eu.h b/Marlin/language_eu.h
index d6e51bc250..c28eaa6f94 100644
--- a/Marlin/language_eu.h
+++ b/Marlin/language_eu.h
@@ -142,8 +142,7 @@
//#define MSG_UBL_Z_OFFSET_STOPPED _UxGT("Z-Offset Stopped")
//#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("Step-By-Step UBL")
#define MSG_LED_CONTROL _UxGT("LED ezarpenak")
-#define MSG_LEDS_ON _UxGT("Argiak piztu")
-#define MSG_LEDS_OFF _UxGT("Argiak itzali")
+#define MSG_LEDS _UxGT("Argiak")
#define MSG_LED_PRESETS _UxGT("Argi aurrehautaketak")
#define MSG_SET_LEDS_RED _UxGT("Gorria")
#define MSG_SET_LEDS_ORANGE _UxGT("Laranja")
diff --git a/Marlin/language_fr.h b/Marlin/language_fr.h
index 5da9084169..20d542433a 100644
--- a/Marlin/language_fr.h
+++ b/Marlin/language_fr.h
@@ -144,8 +144,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL Pas a pas")
#define MSG_LED_CONTROL _UxGT("Controle LED")
-#define MSG_LEDS_ON _UxGT("Lumiere ON")
-#define MSG_LEDS_OFF _UxGT("Lumiere OFF")
+#define MSG_LEDS _UxGT("Lumiere")
#define MSG_LED_PRESETS _UxGT("Preregl. LED.")
#define MSG_SET_LEDS_RED _UxGT("Rouge")
#define MSG_SET_LEDS_ORANGE _UxGT("Orange")
diff --git a/Marlin/language_fr_utf8.h b/Marlin/language_fr_utf8.h
index a54fb76c23..8365242255 100644
--- a/Marlin/language_fr_utf8.h
+++ b/Marlin/language_fr_utf8.h
@@ -145,8 +145,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL Pas à pas")
#define MSG_LED_CONTROL _UxGT("Contrôle LED")
-#define MSG_LEDS_ON _UxGT("Lumière ON")
-#define MSG_LEDS_OFF _UxGT("Lumière OFF")
+#define MSG_LEDS _UxGT("Lumière")
#define MSG_LED_PRESETS _UxGT("Préregl. LED")
#define MSG_SET_LEDS_RED _UxGT("Rouge")
#define MSG_SET_LEDS_ORANGE _UxGT("Orange")
diff --git a/Marlin/language_it.h b/Marlin/language_it.h
index 1439d3e5c6..e3b83312bb 100644
--- a/Marlin/language_it.h
+++ b/Marlin/language_it.h
@@ -56,13 +56,13 @@
#define MSG_HOME_OFFSETS_APPLIED _UxGT("Offset applicato")
#define MSG_SET_ORIGIN _UxGT("Imposta Origine")
#define MSG_PREHEAT_1 _UxGT("Preriscalda PLA")
-#define MSG_PREHEAT_1_N _UxGT("Prerisc.PLA ")
+#define MSG_PREHEAT_1_N _UxGT("Preris.PLA ")
#define MSG_PREHEAT_1_ALL MSG_PREHEAT_1_N _UxGT("Tutto")
#define MSG_PREHEAT_1_END MSG_PREHEAT_1_N _UxGT("Ugello")
#define MSG_PREHEAT_1_BEDONLY MSG_PREHEAT_1_N _UxGT("Piatto")
#define MSG_PREHEAT_1_SETTINGS MSG_PREHEAT_1_N _UxGT("conf")
#define MSG_PREHEAT_2 _UxGT("Preriscalda ABS")
-#define MSG_PREHEAT_2_N _UxGT("Prerisc.ABS ")
+#define MSG_PREHEAT_2_N _UxGT("Preris.ABS ")
#define MSG_PREHEAT_2_ALL MSG_PREHEAT_2_N _UxGT("Tutto")
#define MSG_PREHEAT_2_END MSG_PREHEAT_2_N _UxGT("Ugello")
#define MSG_PREHEAT_2_BEDONLY MSG_PREHEAT_2_N _UxGT("Piatto")
@@ -144,8 +144,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL passo passo")
#define MSG_LED_CONTROL _UxGT("Controllo LED")
-#define MSG_LEDS_ON _UxGT("Luci On")
-#define MSG_LEDS_OFF _UxGT("Luci Off")
+#define MSG_LEDS _UxGT("Luci")
#define MSG_LED_PRESETS _UxGT("Preset luci")
#define MSG_SET_LEDS_RED _UxGT("Rosso")
#define MSG_SET_LEDS_ORANGE _UxGT("Arancione")
diff --git a/Marlin/language_pt-br.h b/Marlin/language_pt-br.h
index 8793202517..4d9c64261c 100644
--- a/Marlin/language_pt-br.h
+++ b/Marlin/language_pt-br.h
@@ -145,8 +145,7 @@
#define MSG_UBL_Z_OFFSET_STOPPED _UxGT("Compensacao Z parou")
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL passo a passo")
#define MSG_LED_CONTROL _UxGT("Controle do LED")
-#define MSG_LEDS_ON _UxGT("Luz Acesa")
-#define MSG_LEDS_OFF _UxGT("Luz Apagada")
+#define MSG_LEDS _UxGT("Luz")
#define MSG_LED_PRESETS _UxGT("Configuracao da Luz")
#define MSG_SET_LEDS_RED _UxGT("Luz Vermelha")
#define MSG_SET_LEDS_ORANGE _UxGT("Luz Laranja")
diff --git a/Marlin/language_pt-br_utf8.h b/Marlin/language_pt-br_utf8.h
index 2e481e4810..b297b7b4b0 100644
--- a/Marlin/language_pt-br_utf8.h
+++ b/Marlin/language_pt-br_utf8.h
@@ -147,8 +147,7 @@
#define MSG_UBL_Z_OFFSET_STOPPED _UxGT("Compensação Z parou")
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL passo a passo")
#define MSG_LED_CONTROL _UxGT("Controle do LED")
-#define MSG_LEDS_ON _UxGT("Luz Acesa")
-#define MSG_LEDS_OFF _UxGT("Luz Apagada")
+#define MSG_LEDS _UxGT("Luz")
#define MSG_LED_PRESETS _UxGT("Configuração da Luz")
#define MSG_SET_LEDS_RED _UxGT("Luz Vermelha")
#define MSG_SET_LEDS_ORANGE _UxGT("Luz Laranja")
diff --git a/Marlin/language_ru.h b/Marlin/language_ru.h
index b7235ebb1d..0e54d6be0c 100644
--- a/Marlin/language_ru.h
+++ b/Marlin/language_ru.h
@@ -145,8 +145,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("Пошаговое UBL")
#define MSG_LED_CONTROL _UxGT("Настройки LED")
-#define MSG_LEDS_ON _UxGT("Включить подсветку")
-#define MSG_LEDS_OFF _UxGT("Выключить подсветку")
+#define MSG_LEDS _UxGT("Подсветку")
#define MSG_LED_PRESETS _UxGT("Предустановки света")
#define MSG_SET_LEDS_RED _UxGT("Красный свет")
#define MSG_SET_LEDS_ORANGE _UxGT("Оранжевый свет")
diff --git a/Marlin/language_sk_utf8.h b/Marlin/language_sk_utf8.h
index a7ce610c56..3b43007e54 100644
--- a/Marlin/language_sk_utf8.h
+++ b/Marlin/language_sk_utf8.h
@@ -43,6 +43,7 @@
#define MSG_SD_INSERTED _UxGT("Karta vložená")
#define MSG_SD_REMOVED _UxGT("Karta vybratá")
#define MSG_LCD_ENDSTOPS _UxGT("Endstopy") // max 8 znakov
+#define MSG_LCD_SOFT_ENDSTOPS _UxGT("Soft.endstopy")
#define MSG_MAIN _UxGT("Hlavná ponuka")
#define MSG_AUTOSTART _UxGT("Autoštart")
#define MSG_DISABLE_STEPPERS _UxGT("Uvolniť motory")
@@ -148,8 +149,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("UBL Postupne")
#define MSG_LED_CONTROL _UxGT("Nastavenie LED")
-#define MSG_LEDS_ON _UxGT("Zapnúť svetlo")
-#define MSG_LEDS_OFF _UxGT("Vypnúť svetlo")
+#define MSG_LEDS _UxGT("Svetlo")
#define MSG_LED_PRESETS _UxGT("Prednastavené farby")
#define MSG_SET_LEDS_RED _UxGT("Červená")
#define MSG_SET_LEDS_ORANGE _UxGT("Oranžová")
@@ -208,6 +208,7 @@
#define MSG_VC_JERK _UxGT("Vz-skok")
#endif
#define MSG_VE_JERK _UxGT("Ve-skok")
+#define MSG_JUNCTION_DEVIATION _UxGT("Junction Dev")
#define MSG_VELOCITY _UxGT("Rýchlosť")
#define MSG_VMAX _UxGT("Vmax ")
#define MSG_VMIN _UxGT("Vmin")
@@ -255,8 +256,9 @@
#define MSG_CARD_MENU _UxGT("Tlačiť z SD")
#define MSG_NO_CARD _UxGT("Žiadna SD karta")
#define MSG_DWELL _UxGT("Spím...")
-#define MSG_USERWAIT _UxGT("Čakám...")
+#define MSG_USERWAIT _UxGT("Kliknutím pokrač.")
#define MSG_PRINT_PAUSED _UxGT("Tlač pozastavená")
+#define MSG_PRINTING _UxGT("Tlačím...")
#define MSG_PRINT_ABORTED _UxGT("Tlač zrušená")
#define MSG_NO_MOVE _UxGT("Žiadny pohyb.")
#define MSG_KILLED _UxGT("PRERUŠENÉ. ")
@@ -318,6 +320,7 @@
#define MSG_DELTA_SETTINGS _UxGT("Delta nastavenia")
#define MSG_DELTA_AUTO_CALIBRATE _UxGT("Autokalibrácia")
#define MSG_DELTA_HEIGHT_CALIBRATE _UxGT("Nast.výšku delty")
+#define MSG_DELTA_Z_OFFSET_CALIBRATE _UxGT("Offset sondy Z")
#define MSG_DELTA_DIAG_ROD _UxGT("Diag rameno")
#define MSG_DELTA_HEIGHT _UxGT("Výška")
#define MSG_DELTA_RADIUS _UxGT("Polomer")
diff --git a/Marlin/language_zh_CN.h b/Marlin/language_zh_CN.h
index c62bbc77b2..3a1a065d5e 100644
--- a/Marlin/language_zh_CN.h
+++ b/Marlin/language_zh_CN.h
@@ -141,8 +141,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("一步步UBL") // "Step-By-Step UBL"
#define MSG_LED_CONTROL _UxGT("灯管控制") // "LED Control")
-#define MSG_LEDS_ON _UxGT("灯亮") // "Lights On")
-#define MSG_LEDS_OFF _UxGT("灯灭") // "Lights Off")
+#define MSG_LEDS _UxGT("灯") // "Lights")
#define MSG_LED_PRESETS _UxGT("灯预置") // "Light Presets")
#define MSG_SET_LEDS_RED _UxGT("红") // "Red")
#define MSG_SET_LEDS_ORANGE _UxGT("橙") // "Orange")
diff --git a/Marlin/language_zh_TW.h b/Marlin/language_zh_TW.h
index 4eb420f423..2a0399e358 100644
--- a/Marlin/language_zh_TW.h
+++ b/Marlin/language_zh_TW.h
@@ -141,8 +141,7 @@
#define MSG_UBL_STEP_BY_STEP_MENU _UxGT("一步步UBL") // "Step-By-Step UBL"
#define MSG_LED_CONTROL _UxGT("灯管控制") // "LED Control")
-#define MSG_LEDS_ON _UxGT("灯亮") // "Lights On")
-#define MSG_LEDS_OFF _UxGT("灯灭") // "Lights Off")
+#define MSG_LEDS _UxGT("灯") // "Lights")
#define MSG_LED_PRESETS _UxGT("灯预置") // "Light Presets")
#define MSG_SET_LEDS_RED _UxGT("红") // "Red")
#define MSG_SET_LEDS_ORANGE _UxGT("橙") // "Orange")
diff --git a/Marlin/least_squares_fit.cpp b/Marlin/least_squares_fit.cpp
index 66821ce58f..9e59804f09 100644
--- a/Marlin/least_squares_fit.cpp
+++ b/Marlin/least_squares_fit.cpp
@@ -59,7 +59,7 @@ int finish_incremental_LSF(struct linear_fit_data *lsf) {
lsf->xzbar = lsf->xzbar / N - lsf->xbar * lsf->zbar;
const float DD = lsf->x2bar * lsf->y2bar - sq(lsf->xybar);
- if (FABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy))
+ if (ABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy))
return 1;
lsf->A = (lsf->yzbar * lsf->xybar - lsf->xzbar * lsf->y2bar) / DD;
diff --git a/Marlin/least_squares_fit.h b/Marlin/least_squares_fit.h
index 9ed923ab49..68aa62b9c5 100644
--- a/Marlin/least_squares_fit.h
+++ b/Marlin/least_squares_fit.h
@@ -65,8 +65,8 @@ void inline incremental_WLSF(struct linear_fit_data *lsf, const float &x, const
lsf->xzbar += w * x * z;
lsf->yzbar += w * y * z;
lsf->N += w;
- lsf->max_absx = max(FABS(w * x), lsf->max_absx);
- lsf->max_absy = max(FABS(w * y), lsf->max_absy);
+ lsf->max_absx = MAX(ABS(w * x), lsf->max_absx);
+ lsf->max_absy = MAX(ABS(w * y), lsf->max_absy);
}
void inline incremental_LSF(struct linear_fit_data *lsf, const float &x, const float &y, const float &z) {
@@ -79,8 +79,8 @@ void inline incremental_LSF(struct linear_fit_data *lsf, const float &x, const f
lsf->xybar += x * y;
lsf->xzbar += x * z;
lsf->yzbar += y * z;
- lsf->max_absx = max(FABS(x), lsf->max_absx);
- lsf->max_absy = max(FABS(y), lsf->max_absy);
+ lsf->max_absx = MAX(ABS(x), lsf->max_absx);
+ lsf->max_absy = MAX(ABS(y), lsf->max_absy);
lsf->N += 1.0;
}
diff --git a/Marlin/macros.h b/Marlin/macros.h
index b09812ad2e..45c4334ae2 100644
--- a/Marlin/macros.h
+++ b/Marlin/macros.h
@@ -30,7 +30,7 @@
#define XYZ 3
// For use in macros that take a single axis letter
-#define _AXIS(AXIS) AXIS ##_AXIS
+#define _AXIS(A) (A##_AXIS)
#define _XMIN_ 100
#define _YMIN_ 200
@@ -47,55 +47,12 @@
#define _O2 __attribute__((optimize("O2")))
#define _O3 __attribute__((optimize("O3")))
-// Bracket code that shouldn't be interrupted
-#ifndef CRITICAL_SECTION_START
- #define CRITICAL_SECTION_START unsigned char _sreg = SREG; cli();
- #define CRITICAL_SECTION_END SREG = _sreg;
-#endif
-
// Clock speed factors
#define CYCLES_PER_MICROSECOND (F_CPU / 1000000L) // 16 or 20
#define INT0_PRESCALER 8
-// Highly granular delays for step pulses, etc.
-#define DELAY_0_NOP NOOP
-#define DELAY_1_NOP __asm__("nop\n\t")
-#define DELAY_2_NOP DELAY_1_NOP; DELAY_1_NOP
-#define DELAY_3_NOP DELAY_1_NOP; DELAY_2_NOP
-#define DELAY_4_NOP DELAY_1_NOP; DELAY_3_NOP
-#define DELAY_5_NOP DELAY_1_NOP; DELAY_4_NOP
-
-#define DELAY_NOPS(X) \
- switch (X) { \
- case 20: DELAY_1_NOP; case 19: DELAY_1_NOP; \
- case 18: DELAY_1_NOP; case 17: DELAY_1_NOP; \
- case 16: DELAY_1_NOP; case 15: DELAY_1_NOP; \
- case 14: DELAY_1_NOP; case 13: DELAY_1_NOP; \
- case 12: DELAY_1_NOP; case 11: DELAY_1_NOP; \
- case 10: DELAY_1_NOP; case 9: DELAY_1_NOP; \
- case 8: DELAY_1_NOP; case 7: DELAY_1_NOP; \
- case 6: DELAY_1_NOP; case 5: DELAY_1_NOP; \
- case 4: DELAY_1_NOP; case 3: DELAY_1_NOP; \
- case 2: DELAY_1_NOP; case 1: DELAY_1_NOP; \
- }
-
-#define DELAY_10_NOP DELAY_5_NOP; DELAY_5_NOP
-#define DELAY_20_NOP DELAY_10_NOP; DELAY_10_NOP
-
-#if CYCLES_PER_MICROSECOND == 16
- #define DELAY_1US DELAY_10_NOP; DELAY_5_NOP; DELAY_1_NOP
-#else
- #define DELAY_1US DELAY_20_NOP
-#endif
-#define DELAY_2US DELAY_1US; DELAY_1US
-#define DELAY_3US DELAY_1US; DELAY_2US
-#define DELAY_4US DELAY_1US; DELAY_3US
-#define DELAY_5US DELAY_1US; DELAY_4US
-#define DELAY_6US DELAY_1US; DELAY_5US
-#define DELAY_7US DELAY_1US; DELAY_6US
-#define DELAY_8US DELAY_1US; DELAY_7US
-#define DELAY_9US DELAY_1US; DELAY_8US
-#define DELAY_10US DELAY_1US; DELAY_9US
+// Nanoseconds per cycle
+#define NANOSECONDS_PER_CYCLE (1000000000.0 / F_CPU)
// Remove compiler warning on an unused variable
#define UNUSED(x) (void) (x)
@@ -104,12 +61,16 @@
#define STRINGIFY_(M) #M
#define STRINGIFY(M) STRINGIFY_(M)
+#define A(CODE) " " CODE "\n\t"
+#define L(CODE) CODE ":\n\t"
+
// Macros for bit masks
#undef _BV
-#define _BV(b) (1<<(b))
+#define _BV(b) (1 << (b))
#define TEST(n,b) !!((n)&_BV(b))
#define SBI(n,b) (n |= _BV(b))
#define CBI(n,b) (n &= ~_BV(b))
+#define SET_BIT_TO(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0)
#define _BV32(b) (1UL << (b))
#define TEST32(n,b) !!((n)&_BV32(b))
@@ -120,15 +81,14 @@
#define IS_POWER_OF_2(x) ((x) && !((x) & ((x) - 1)))
// Macros for maths shortcuts
-#ifndef M_PI
- #define M_PI 3.14159265358979323846
-#endif
-#define RADIANS(d) ((d)*M_PI/180.0)
-#define DEGREES(r) ((r)*180.0/M_PI)
+#undef M_PI
+#define M_PI 3.14159265358979323846f
+#define RADIANS(d) ((d)*M_PI/180.0f)
+#define DEGREES(r) ((r)*180.0f/M_PI)
#define HYPOT2(x,y) (sq(x)+sq(y))
-#define CIRCLE_AREA(R) (M_PI * sq(R))
-#define CIRCLE_CIRC(R) (2.0 * M_PI * (R))
+#define CIRCLE_AREA(R) (M_PI * sq(float(R)))
+#define CIRCLE_CIRC(R) (2 * M_PI * (float(R)))
#define SIGN(a) ((a>0)-(a<0))
#define IS_POWER_OF_2(x) ((x) && !((x) & ((x) - 1)))
@@ -136,6 +96,7 @@
// Macros to contrain values
#define NOLESS(v,n) do{ if (v < n) v = n; }while(0)
#define NOMORE(v,n) do{ if (v > n) v = n; }while(0)
+#define LIMIT(v,n1,n2) do{ if (v < n1) v = n1; else if (v > n2) v = n2; }while(0)
// Macros to support option testing
#define _CAT(a, ...) a ## __VA_ARGS__
@@ -143,9 +104,11 @@
#define SWITCH_ENABLED_true 1
#define SWITCH_ENABLED_0 0
#define SWITCH_ENABLED_1 1
+#define SWITCH_ENABLED_0x0 0
+#define SWITCH_ENABLED_0x1 1
#define SWITCH_ENABLED_ 1
#define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
-#define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
+#define DISABLED(b) !ENABLED(b)
#define WITHIN(V,L,H) ((V) >= (L) && (V) <= (H))
#define NUMERIC(a) WITHIN(a, '0', '9')
@@ -154,7 +117,7 @@
#define DECIMAL_SIGNED(a) (DECIMAL(a) || (a) == '-' || (a) == '+')
#define COUNT(a) (sizeof(a)/sizeof(*a))
#define ZERO(a) memset(a,0,sizeof(a))
-#define COPY(a,b) memcpy(a,b,min(sizeof(a),sizeof(b)))
+#define COPY(a,b) memcpy(a,b,MIN(sizeof(a),sizeof(b)))
// Macros for initializing arrays
#define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }
@@ -198,38 +161,74 @@
#define PENDING(NOW,SOON) ((long)(NOW-(SOON))<0)
#define ELAPSED(NOW,SOON) (!PENDING(NOW,SOON))
-#define MMM_TO_MMS(MM_M) ((MM_M)/60.0)
-#define MMS_TO_MMM(MM_S) ((MM_S)*60.0)
+#define MMM_TO_MMS(MM_M) ((MM_M)/60.0f)
+#define MMS_TO_MMM(MM_S) ((MM_S)*60.0f)
#define NOOP do{} while(0)
#define CEILING(x,y) (((x) + (y) - 1) / (y))
-#define MIN3(a, b, c) min(min(a, b), c)
-#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
-#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
-#define MAX3(a, b, c) max(max(a, b), c)
-#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
-#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
+// Avoid double evaluation of arguments on MIN/MAX/ABS
+#undef MIN
+#undef MAX
+#undef ABS
+#ifdef __cplusplus
-#define UNEAR_ZERO(x) ((x) < 0.000001)
-#define NEAR_ZERO(x) WITHIN(x, -0.000001, 0.000001)
+ // C++11 solution that is standards compliant. Return type is deduced automatically
+ template static inline constexpr auto MIN(const L lhs, const R rhs) -> decltype(lhs + rhs) {
+ return lhs < rhs ? lhs : rhs;
+ }
+ template static inline constexpr auto MAX(const L lhs, const R rhs) -> decltype(lhs + rhs){
+ return lhs > rhs ? lhs : rhs;
+ }
+ template static inline constexpr const T ABS(const T v) {
+ return v >= 0 ? v : -v;
+ }
+#else
+
+ // Using GCC extensions, but Travis GCC version does not like it and gives
+ // "error: statement-expressions are not allowed outside functions nor in template-argument lists"
+ #define MIN(a, b) \
+ ({__typeof__(a) _a = (a); \
+ __typeof__(b) _b = (b); \
+ _a < _b ? _a : _b;})
+
+ #define MAX(a, b) \
+ ({__typeof__(a) _a = (a); \
+ __typeof__(b) _b = (b); \
+ _a > _b ? _a : _b;})
+
+ #define ABS(a) \
+ ({__typeof__(a) _a = (a); \
+ _a >= 0 ? _a : -_a;})
+
+#endif
+
+#define MIN3(a, b, c) MIN(MIN(a, b), c)
+#define MIN4(a, b, c, d) MIN(MIN3(a, b, c), d)
+#define MIN5(a, b, c, d, e) MIN(MIN4(a, b, c, d), e)
+#define MAX3(a, b, c) MAX(MAX(a, b), c)
+#define MAX4(a, b, c, d) MAX(MAX3(a, b, c), d)
+#define MAX5(a, b, c, d, e) MAX(MAX4(a, b, c, d), e)
+
+#define UNEAR_ZERO(x) ((x) < 0.000001f)
+#define NEAR_ZERO(x) WITHIN(x, -0.000001f, 0.000001f)
#define NEAR(x,y) NEAR_ZERO((x)-(y))
-#define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x))
-#define FIXFLOAT(f) (f + (f < 0.0 ? -0.00001 : 0.00001))
+#define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0f : 1.0f / (x))
+#define FIXFLOAT(f) (f + (f < 0.0f ? -0.00005f : 0.00005f))
//
// Maths macros that can be overridden by HAL
//
-#define ATAN2(y, x) atan2(y, x)
-#define FABS(x) fabs(x)
-#define POW(x, y) pow(x, y)
-#define SQRT(x) sqrt(x)
-#define CEIL(x) ceil(x)
-#define FLOOR(x) floor(x)
-#define LROUND(x) lround(x)
-#define FMOD(x, y) fmod(x, y)
+#define ATAN2(y, x) atan2f(y, x)
+#define POW(x, y) powf(x, y)
+#define SQRT(x) sqrtf(x)
+#define RSQRT(x) (1 / sqrtf(x))
+#define CEIL(x) ceilf(x)
+#define FLOOR(x) floorf(x)
+#define LROUND(x) lroundf(x)
+#define FMOD(x, y) fmodf(x, y)
#define HYPOT(x,y) SQRT(HYPOT2(x,y))
#endif //__MACROS_H
diff --git a/Marlin/malyanlcd.cpp b/Marlin/malyanlcd.cpp
index 894b8ae642..e8d6c25143 100644
--- a/Marlin/malyanlcd.cpp
+++ b/Marlin/malyanlcd.cpp
@@ -45,8 +45,13 @@
#if ENABLED(MALYAN_LCD)
-#include "cardreader.h"
-#include "SdFatConfig.h"
+#if ENABLED(SDSUPPORT)
+ #include "cardreader.h"
+ #include "SdFatConfig.h"
+#else
+ #define LONG_FILENAME_LENGTH 0
+#endif
+
#include "temperature.h"
#include "planner.h"
#include "stepper.h"
@@ -57,6 +62,15 @@
#include "Marlin.h"
+#if USE_MARLINSERIAL
+ // Make an exception to use HardwareSerial too
+ #undef HardwareSerial_h
+ #include
+ #define USB_STATUS true
+#else
+ #define USB_STATUS Serial
+#endif
+
// On the Malyan M200, this will be Serial1. On a RAMPS board,
// it might not be.
#define LCD_SERIAL Serial1
@@ -72,7 +86,7 @@ int inbound_count;
// Everything written needs the high bit set.
void write_to_lcd_P(const char * const message) {
char encoded_message[MAX_CURLY_COMMAND];
- uint8_t message_length = min(strlen_P(message), sizeof(encoded_message));
+ uint8_t message_length = MIN(strlen_P(message), sizeof(encoded_message));
for (uint8_t i = 0; i < message_length; i++)
encoded_message[i] = pgm_read_byte(&message[i]) | 0x80;
@@ -82,7 +96,7 @@ void write_to_lcd_P(const char * const message) {
void write_to_lcd(const char * const message) {
char encoded_message[MAX_CURLY_COMMAND];
- const uint8_t message_length = min(strlen(message), sizeof(encoded_message));
+ const uint8_t message_length = MIN(strlen(message), sizeof(encoded_message));
for (uint8_t i = 0; i < message_length; i++)
encoded_message[i] = message[i] | 0x80;
@@ -132,8 +146,6 @@ void process_lcd_c_command(const char* command) {
void process_lcd_eb_command(const char* command) {
char elapsed_buffer[10];
duration_t elapsed;
- bool has_days;
- uint8_t len;
switch (command[0]) {
case '0': {
elapsed = print_job_timer.duration();
@@ -144,9 +156,17 @@ void process_lcd_eb_command(const char* command) {
PSTR("{T0:%03.0f/%03i}{T1:000/000}{TP:%03.0f/%03i}{TQ:%03i}{TT:%s}"),
thermalManager.degHotend(0),
thermalManager.degTargetHotend(0),
- thermalManager.degBed(),
- thermalManager.degTargetBed(),
- card.percentDone(),
+ #if HAS_HEATED_BED
+ thermalManager.degBed(),
+ thermalManager.degTargetBed(),
+ #else
+ 0, 0,
+ #endif
+ #if ENABLED(SDSUPPORT)
+ card.percentDone(),
+ #else
+ 0,
+ #endif
elapsed_buffer);
write_to_lcd(message_buffer);
} break;
@@ -223,51 +243,55 @@ void process_lcd_p_command(const char* command) {
switch (command[0]) {
case 'X':
- // cancel print
- write_to_lcd_P(PSTR("{SYS:CANCELING}"));
- card.stopSDPrint(
- #if SD_RESORT
- true
+ #if ENABLED(SDSUPPORT)
+ // cancel print
+ write_to_lcd_P(PSTR("{SYS:CANCELING}"));
+ card.stopSDPrint(
+ #if SD_RESORT
+ true
+ #endif
+ );
+ clear_command_queue();
+ quickstop_stepper();
+ print_job_timer.stop();
+ thermalManager.disable_all_heaters();
+ #if FAN_COUNT > 0
+ for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
#endif
- );
- clear_command_queue();
- quickstop_stepper();
- print_job_timer.stop();
- thermalManager.disable_all_heaters();
- #if FAN_COUNT > 0
- for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
+ wait_for_heatup = false;
+ write_to_lcd_P(PSTR("{SYS:STARTED}"));
#endif
- wait_for_heatup = false;
- write_to_lcd_P(PSTR("{SYS:STARTED}"));
break;
case 'H':
// Home all axis
enqueue_and_echo_commands_now_P(PSTR("G28"));
break;
default: {
- // Print file 000 - a three digit number indicating which
- // file to print in the SD card. If it's a directory,
- // then switch to the directory.
+ #if ENABLED(SDSUPPORT)
+ // Print file 000 - a three digit number indicating which
+ // file to print in the SD card. If it's a directory,
+ // then switch to the directory.
- // Find the name of the file to print.
- // It's needed to echo the PRINTFILE option.
- // The {S:L} command should've ensured the SD card was mounted.
- card.getfilename(atoi(command));
+ // Find the name of the file to print.
+ // It's needed to echo the PRINTFILE option.
+ // The {S:L} command should've ensured the SD card was mounted.
+ card.getfilename(atoi(command));
- // There may be a difference in how V1 and V2 LCDs handle subdirectory
- // prints. Investigate more. This matches the V1 motion controller actions
- // but the V2 LCD switches to "print" mode on {SYS:DIR} response.
- if (card.filenameIsDir) {
- card.chdir(card.filename);
- write_to_lcd_P(PSTR("{SYS:DIR}"));
- }
- else {
- char message_buffer[MAX_CURLY_COMMAND];
- sprintf_P(message_buffer, PSTR("{PRINTFILE:%s}"), card.filename);
- write_to_lcd(message_buffer);
- write_to_lcd_P(PSTR("{SYS:BUILD}"));
- card.openAndPrintFile(card.filename);
- }
+ // There may be a difference in how V1 and V2 LCDs handle subdirectory
+ // prints. Investigate more. This matches the V1 motion controller actions
+ // but the V2 LCD switches to "print" mode on {SYS:DIR} response.
+ if (card.filenameIsDir) {
+ card.chdir(card.filename);
+ write_to_lcd_P(PSTR("{SYS:DIR}"));
+ }
+ else {
+ char message_buffer[MAX_CURLY_COMMAND];
+ sprintf_P(message_buffer, PSTR("{PRINTFILE:%s}"), card.filename);
+ write_to_lcd(message_buffer);
+ write_to_lcd_P(PSTR("{SYS:BUILD}"));
+ card.openAndPrintFile(card.filename);
+ }
+ #endif
} break; // default
} // switch
}
@@ -292,7 +316,11 @@ void process_lcd_s_command(const char* command) {
char message_buffer[MAX_CURLY_COMMAND];
sprintf_P(message_buffer, PSTR("{T0:%03.0f/%03i}{T1:000/000}{TP:%03.0f/%03i}"),
thermalManager.degHotend(0), thermalManager.degTargetHotend(0),
- thermalManager.degBed(), thermalManager.degTargetBed()
+ #if HAS_HEATED_BED
+ thermalManager.degBed(), thermalManager.degTargetBed()
+ #else
+ 0, 0
+ #endif
);
write_to_lcd(message_buffer);
} break;
@@ -303,23 +331,25 @@ void process_lcd_s_command(const char* command) {
break;
case 'L': {
- if (!card.cardOK) card.initsd();
+ #if ENABLED(SDSUPPORT)
+ if (!card.cardOK) card.initsd();
- // A more efficient way to do this would be to
- // implement a callback in the ls_SerialPrint code, but
- // that requires changes to the core cardreader class that
- // would not benefit the majority of users. Since one can't
- // select a file for printing during a print, there's
- // little reason not to do it this way.
- char message_buffer[MAX_CURLY_COMMAND];
- uint16_t file_count = card.get_num_Files();
- for (uint16_t i = 0; i < file_count; i++) {
- card.getfilename(i);
- sprintf_P(message_buffer, card.filenameIsDir ? PSTR("{DIR:%s}") : PSTR("{FILE:%s}"), card.filename);
- write_to_lcd(message_buffer);
- }
+ // A more efficient way to do this would be to
+ // implement a callback in the ls_SerialPrint code, but
+ // that requires changes to the core cardreader class that
+ // would not benefit the majority of users. Since one can't
+ // select a file for printing during a print, there's
+ // little reason not to do it this way.
+ char message_buffer[MAX_CURLY_COMMAND];
+ uint16_t file_count = card.get_num_Files();
+ for (uint16_t i = 0; i < file_count; i++) {
+ card.getfilename(i);
+ sprintf_P(message_buffer, card.filenameIsDir ? PSTR("{DIR:%s}") : PSTR("{FILE:%s}"), card.filename);
+ write_to_lcd(message_buffer);
+ }
- write_to_lcd_P(PSTR("{SYS:OK}"));
+ write_to_lcd_P(PSTR("{SYS:OK}"));
+ #endif
} break;
default:
@@ -371,15 +401,15 @@ void process_lcd_command(const char* command) {
/**
* UC means connected.
* UD means disconnected
- * The stock firmware considers USB initialied as "connected."
+ * The stock firmware considers USB initialized as "connected."
*/
void update_usb_status(const bool forceUpdate) {
static bool last_usb_connected_status = false;
// This is mildly different than stock, which
// appears to use the usb discovery status.
// This is more logical.
- if (last_usb_connected_status != Serial || forceUpdate) {
- last_usb_connected_status = Serial;
+ if (last_usb_connected_status != USB_STATUS || forceUpdate) {
+ last_usb_connected_status = USB_STATUS;
write_to_lcd_P(last_usb_connected_status ? PSTR("{R:UC}\r\n") : PSTR("{R:UD}\r\n"));
}
}
@@ -390,7 +420,7 @@ void update_usb_status(const bool forceUpdate) {
* The optimize attribute fixes a register Compile
* error for amtel.
*/
-void lcd_update() _O2 {
+void _O2 lcd_update() {
static char inbound_buffer[MAX_CURLY_COMMAND];
// First report USB status.
@@ -408,15 +438,17 @@ void lcd_update() _O2 {
}
}
- // If there's a print in progress, we need to emit the status as
- // {TQ:}
- if (card.sdprinting) {
- // We also need to send: T:-2538.0 E:0
- // I have no idea what this means.
- char message_buffer[10];
- sprintf_P(message_buffer, PSTR("{TQ:%03i}"), card.percentDone());
- write_to_lcd(message_buffer);
- }
+ #if ENABLED(SDSUPPORT)
+ // If there's a print in progress, we need to emit the status as
+ // {TQ:}
+ if (card.sdprinting) {
+ // We also need to send: T:-2538.0 E:0
+ // I have no idea what this means.
+ char message_buffer[10];
+ sprintf_P(message_buffer, PSTR("{TQ:%03i}"), card.percentDone());
+ write_to_lcd(message_buffer);
+ }
+ #endif
}
/**
diff --git a/Marlin/mesh_bed_leveling.h b/Marlin/mesh_bed_leveling.h
index f3a374af59..cb95ad733f 100644
--- a/Marlin/mesh_bed_leveling.h
+++ b/Marlin/mesh_bed_leveling.h
@@ -72,22 +72,22 @@ public:
}
static int8_t cell_index_x(const float &x) {
- int8_t cx = (x - (MESH_MIN_X)) * (1.0 / (MESH_X_DIST));
+ int8_t cx = (x - (MESH_MIN_X)) * (1.0f / (MESH_X_DIST));
return constrain(cx, 0, (GRID_MAX_POINTS_X) - 2);
}
static int8_t cell_index_y(const float &y) {
- int8_t cy = (y - (MESH_MIN_Y)) * (1.0 / (MESH_Y_DIST));
+ int8_t cy = (y - (MESH_MIN_Y)) * (1.0f / (MESH_Y_DIST));
return constrain(cy, 0, (GRID_MAX_POINTS_Y) - 2);
}
static int8_t probe_index_x(const float &x) {
- int8_t px = (x - (MESH_MIN_X) + 0.5 * (MESH_X_DIST)) * (1.0 / (MESH_X_DIST));
+ int8_t px = (x - (MESH_MIN_X) + 0.5f * (MESH_X_DIST)) * (1.0f / (MESH_X_DIST));
return WITHIN(px, 0, GRID_MAX_POINTS_X - 1) ? px : -1;
}
static int8_t probe_index_y(const float &y) {
- int8_t py = (y - (MESH_MIN_Y) + 0.5 * (MESH_Y_DIST)) * (1.0 / (MESH_Y_DIST));
+ int8_t py = (y - (MESH_MIN_Y) + 0.5f * (MESH_Y_DIST)) * (1.0f / (MESH_Y_DIST));
return WITHIN(py, 0, GRID_MAX_POINTS_Y - 1) ? py : -1;
}
diff --git a/Marlin/nozzle.cpp b/Marlin/nozzle.cpp
index da43e264bf..8bff692e44 100644
--- a/Marlin/nozzle.cpp
+++ b/Marlin/nozzle.cpp
@@ -78,7 +78,7 @@
do_blocking_move_to(start.x, start.y, start.z);
const uint8_t zigs = objects << 1;
- const bool horiz = FABS(diffx) >= FABS(diffy); // Do a horizontal wipe?
+ const bool horiz = ABS(diffx) >= ABS(diffy); // Do a horizontal wipe?
const float P = (horiz ? diffx : diffy) / zigs; // Period of each zig / zag
const point_t *side;
for (uint8_t j = 0; j < strokes; j++) {
@@ -171,11 +171,11 @@
break;
case 2: // Raise by Z-park height
- do_blocking_move_to_z(min(current_position[Z_AXIS] + park.z, Z_MAX_POS), fr_z);
+ do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park.z, Z_MAX_POS), fr_z);
break;
default: // Raise to at least the Z-park height
- do_blocking_move_to_z(max(park.z, current_position[Z_AXIS]), fr_z);
+ do_blocking_move_to_z(MAX(park.z, current_position[Z_AXIS]), fr_z);
}
do_blocking_move_to_xy(park.x, park.y, fr_xy);
diff --git a/Marlin/parser.h b/Marlin/parser.h
index 6676f228db..949c489cd0 100644
--- a/Marlin/parser.h
+++ b/Marlin/parser.h
@@ -39,6 +39,8 @@
#include "serial.h"
#endif
+#define strtof strtod
+
/**
* GCode parser
*
@@ -153,7 +155,7 @@ public:
// Code is found in the string. If not found, value_ptr is unchanged.
// This allows "if (seen('A')||seen('B'))" to use the last-found value.
static bool seen(const char c) {
- const char *p = strchr(command_args, c);
+ char *p = strchr(command_args, c);
const bool b = !!p;
if (b) value_ptr = valid_float(&p[1]) ? &p[1] : (char*)NULL;
return b;
@@ -194,15 +196,15 @@ public:
if (c == '\0' || c == ' ') break;
if (c == 'E' || c == 'e') {
*e = '\0';
- const float ret = strtod(value_ptr, NULL);
+ const float ret = strtof(value_ptr, NULL);
*e = c;
return ret;
}
++e;
}
- return strtod(value_ptr, NULL);
+ return strtof(value_ptr, NULL);
}
- return 0.0;
+ return 0;
}
// Code value as a long or ulong
@@ -317,7 +319,7 @@ public:
// Provide simple value accessors with default option
FORCE_INLINE static float floatval(const char c, const float dval=0.0) { return seenval(c) ? value_float() : dval; }
- FORCE_INLINE static bool boolval(const char c) { return seenval(c) ? value_bool() : seen(c); }
+ FORCE_INLINE static bool boolval(const char c, const bool dval=false) { return seenval(c) ? value_bool() : (seen(c) ? true : dval); }
FORCE_INLINE static uint8_t byteval(const char c, const uint8_t dval=0) { return seenval(c) ? value_byte() : dval; }
FORCE_INLINE static int16_t intval(const char c, const int16_t dval=0) { return seenval(c) ? value_int() : dval; }
FORCE_INLINE static uint16_t ushortval(const char c, const uint16_t dval=0) { return seenval(c) ? value_ushort() : dval; }
diff --git a/Marlin/pins.h b/Marlin/pins.h
index 9cad2557af..20ba513a56 100644
--- a/Marlin/pins.h
+++ b/Marlin/pins.h
@@ -52,217 +52,217 @@
//
#if MB(RAMPS_OLD)
- #include "pins_RAMPS_OLD.h"
+ #include "pins_RAMPS_OLD.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_13_EFB)
- #include "pins_RAMPS_13.h"
+ #include "pins_RAMPS_13.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_13_EEB)
- #include "pins_RAMPS_13.h"
+ #include "pins_RAMPS_13.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_13_EFF)
- #include "pins_RAMPS_13.h"
+ #include "pins_RAMPS_13.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_13_EEF)
- #include "pins_RAMPS_13.h"
+ #include "pins_RAMPS_13.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_13_SF)
- #include "pins_RAMPS_13.h"
+ #include "pins_RAMPS_13.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_14_EFB)
- #include "pins_RAMPS.h"
+ #include "pins_RAMPS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_14_EEB)
- #include "pins_RAMPS.h"
+ #include "pins_RAMPS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_14_EFF)
- #include "pins_RAMPS.h"
+ #include "pins_RAMPS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_14_EEF)
- #include "pins_RAMPS.h"
+ #include "pins_RAMPS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_14_SF)
- #include "pins_RAMPS.h"
+ #include "pins_RAMPS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_PLUS_EFB)
- #include "pins_RAMPS_PLUS.h"
+ #include "pins_RAMPS_PLUS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_PLUS_EEB)
- #include "pins_RAMPS_PLUS.h"
+ #include "pins_RAMPS_PLUS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_PLUS_EFF)
- #include "pins_RAMPS_PLUS.h"
+ #include "pins_RAMPS_PLUS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_PLUS_EEF)
- #include "pins_RAMPS_PLUS.h"
+ #include "pins_RAMPS_PLUS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RAMPS_PLUS_SF)
- #include "pins_RAMPS_PLUS.h"
+ #include "pins_RAMPS_PLUS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
//
// RAMPS Derivatives - ATmega1280, ATmega2560
//
#elif MB(3DRAG)
- #include "pins_3DRAG.h" // ATmega1280, ATmega2560
+ #include "pins_3DRAG.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(K8200)
- #include "pins_K8200.h" // ATmega1280, ATmega2560 (3DRAG)
+ #include "pins_K8200.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560 (3DRAG)
#elif MB(K8400)
- #include "pins_K8400.h" // ATmega1280, ATmega2560 (3DRAG)
+ #include "pins_K8400.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560 (3DRAG)
#elif MB(BAM_DICE)
- #include "pins_RAMPS.h" // ATmega1280, ATmega2560
+ #include "pins_RAMPS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(BAM_DICE_DUE)
- #include "pins_BAM_DICE_DUE.h" // ATmega1280, ATmega2560
+ #include "pins_BAM_DICE_DUE.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(MKS_BASE)
- #include "pins_MKS_BASE.h" // ATmega1280, ATmega2560
+ #include "pins_MKS_BASE.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(MKS_BASE_15)
- #include "pins_MKS_BASE_15.h" // ATmega1280, ATmega2560
+ #include "pins_MKS_BASE_15.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(MKS_BASE_HEROIC)
- #include "pins_MKS_BASE_HEROIC.h" // ATmega1280, ATmega2560
+ #include "pins_MKS_BASE_HEROIC.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(MKS_GEN_13)
- #include "pins_MKS_GEN_13.h" // ATmega1280, ATmega2560
+ #include "pins_MKS_GEN_13.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(MKS_GEN_L)
- #include "pins_MKS_GEN_L.h" // ATmega1280, ATmega2560
+ #include "pins_MKS_GEN_L.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(ZRIB_V20)
- #include "pins_ZRIB_V20.h" // ATmega1280, ATmega2560 (MKS_GEN_13)
+ #include "pins_ZRIB_V20.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560 (MKS_GEN_13)
#elif MB(FELIX2)
- #include "pins_FELIX2.h" // ATmega1280, ATmega2560
+ #include "pins_FELIX2.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RIGIDBOARD)
- #include "pins_RIGIDBOARD.h" // ATmega1280, ATmega2560
+ #include "pins_RIGIDBOARD.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(RIGIDBOARD_V2)
- #include "pins_RIGIDBOARD_V2.h" // ATmega1280, ATmega2560
+ #include "pins_RIGIDBOARD_V2.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(SAINSMART_2IN1)
- #include "pins_SAINSMART_2IN1.h" // ATmega1280, ATmega2560
+ #include "pins_SAINSMART_2IN1.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(ULTIMAKER)
- #include "pins_ULTIMAKER.h" // ATmega1280, ATmega2560
+ #include "pins_ULTIMAKER.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(ULTIMAKER_OLD)
- #include "pins_ULTIMAKER_OLD.h" // ATmega1280, ATmega2560
+ #include "pins_ULTIMAKER_OLD.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(AZTEEG_X3)
- #include "pins_AZTEEG_X3.h" // ATmega2560
+ #include "pins_AZTEEG_X3.h" // ATmega2560 env:megaatmega2560
#elif MB(AZTEEG_X3_PRO)
- #include "pins_AZTEEG_X3_PRO.h" // ATmega2560
+ #include "pins_AZTEEG_X3_PRO.h" // ATmega2560 env:megaatmega2560
#elif MB(ULTIMAIN_2)
- #include "pins_ULTIMAIN_2.h" // ATmega2560
+ #include "pins_ULTIMAIN_2.h" // ATmega2560 env:megaatmega2560
#elif MB(RUMBA)
- #include "pins_RUMBA.h" // ATmega2560
+ #include "pins_RUMBA.h" // ATmega2560 env:megaatmega2560
#elif MB(BQ_ZUM_MEGA_3D)
- #include "pins_BQ_ZUM_MEGA_3D.h" // ATmega2560
+ #include "pins_BQ_ZUM_MEGA_3D.h" // ATmega2560 env:megaatmega2560
#elif MB(MAKEBOARD_MINI)
- #include "pins_MAKEBOARD_MINI.h" // ATmega2560
+ #include "pins_MAKEBOARD_MINI.h" // ATmega2560 env:megaatmega2560
#elif MB(TRIGORILLA_13)
- #include "pins_TRIGORILLA_13.h" // ATmega2560
+ #include "pins_TRIGORILLA_13.h" // ATmega2560 env:megaatmega2560
#elif MB(TRIGORILLA_14)
- #include "pins_TRIGORILLA_14.h" // ATmega2560
+ #include "pins_TRIGORILLA_14.h" // ATmega2560 env:megaatmega2560
#elif MB(RAMPS_ENDER_4)
- #include "pins_RAMPS_ENDER_4.h" // ATmega2560
+ #include "pins_RAMPS_ENDER_4.h" // ATmega2560 env:megaatmega2560
//
// Other ATmega1280, ATmega2560
//
#elif MB(CNCONTROLS_11)
- #include "pins_CNCONTROLS_11.h" // ATmega1280, ATmega2560
+ #include "pins_CNCONTROLS_11.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(CNCONTROLS_12)
- #include "pins_CNCONTROLS_12.h" // ATmega1280, ATmega2560
+ #include "pins_CNCONTROLS_12.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(MIGHTYBOARD_REVE)
- #include "pins_MIGHTYBOARD_REVE.h" // ATmega1280, ATmega2560
+ #include "pins_MIGHTYBOARD_REVE.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(CHEAPTRONIC)
- #include "pins_CHEAPTRONIC.h" // ATmega2560
+ #include "pins_CHEAPTRONIC.h" // ATmega2560 env:megaatmega2560
#elif MB(CHEAPTRONIC_V2)
- #include "pins_CHEAPTRONICv2.h" // ATmega2560
+ #include "pins_CHEAPTRONICv2.h" // ATmega2560 env:megaatmega2560
#elif MB(MEGATRONICS)
- #include "pins_MEGATRONICS.h" // ATmega2560
+ #include "pins_MEGATRONICS.h" // ATmega2560 env:megaatmega2560
#elif MB(MEGATRONICS_2)
- #include "pins_MEGATRONICS_2.h" // ATmega2560
+ #include "pins_MEGATRONICS_2.h" // ATmega2560 env:megaatmega2560
#elif MB(MEGATRONICS_3) || MB(MEGATRONICS_31)
- #include "pins_MEGATRONICS_3.h" // ATmega2560
+ #include "pins_MEGATRONICS_3.h" // ATmega2560 env:megaatmega2560
#elif MB(RAMBO)
- #include "pins_RAMBO.h" // ATmega2560
+ #include "pins_RAMBO.h" // ATmega2560 env:rambo
#elif MB(MINIRAMBO) || MB(MINIRAMBO_10A)
- #include "pins_MINIRAMBO.h" // ATmega2560
+ #include "pins_MINIRAMBO.h" // ATmega2560 env:rambo
#elif MB(EINSY_RAMBO)
- #include "pins_EINSY_RAMBO.h" // ATmega2560
+ #include "pins_EINSY_RAMBO.h" // ATmega2560 env:rambo
#elif MB(EINSY_RETRO)
- #include "pins_EINSY_RETRO.h" // ATmega2560
+ #include "pins_EINSY_RETRO.h" // ATmega2560 env:rambo
#elif MB(ELEFU_3)
- #include "pins_ELEFU_3.h" // ATmega2560
+ #include "pins_ELEFU_3.h" // ATmega2560 env:megaatmega2560
#elif MB(LEAPFROG)
- #include "pins_LEAPFROG.h" // ATmega1280, ATmega2560
+ #include "pins_LEAPFROG.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(MEGACONTROLLER)
- #include "pins_MEGACONTROLLER.h" // ATmega2560
+ #include "pins_MEGACONTROLLER.h" // ATmega2560 env:megaatmega2560
#elif MB(SCOOVO_X9H)
- #include "pins_SCOOVO_X9H.h" // ATmega2560
+ #include "pins_SCOOVO_X9H.h" // ATmega2560 env:rambo
#elif MB(GT2560_REV_A)
- #include "pins_GT2560_REV_A.h" // ATmega1280, ATmega2560
+ #include "pins_GT2560_REV_A.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
#elif MB(GT2560_REV_A_PLUS)
- #include "pins_GT2560_REV_A_PLUS.h" // ATmega1280, ATmega2560
+ #include "pins_GT2560_REV_A_PLUS.h" // ATmega1280, ATmega2560 env:megaatmega1280 env:megaatmega2560
//
// ATmega1281, ATmega2561
//
#elif MB(MINITRONICS)
- #include "pins_MINITRONICS.h" // ATmega1281
+ #include "pins_MINITRONICS.h" // ATmega1281 env:megaatmega1280
#elif MB(SILVER_GATE)
- #include "pins_SILVER_GATE.h" // ATmega2561
+ #include "pins_SILVER_GATE.h" // ATmega2561 env:megaatmega2560
//
// Sanguinololu and Derivatives - ATmega644P, ATmega1284P
//
#elif MB(SANGUINOLOLU_11)
- #include "pins_SANGUINOLOLU_11.h" // ATmega644P, ATmega1284P
+ #include "pins_SANGUINOLOLU_11.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(SANGUINOLOLU_12)
- #include "pins_SANGUINOLOLU_12.h" // ATmega644P, ATmega1284P
+ #include "pins_SANGUINOLOLU_12.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(MELZI)
- #include "pins_MELZI.h" // ATmega644P, ATmega1284P
+ #include "pins_MELZI.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(MELZI_MAKR3D)
- #include "pins_MELZI_MAKR3D.h" // ATmega644P, ATmega1284P
+ #include "pins_MELZI_MAKR3D.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(MELZI_CREALITY)
- #include "pins_MELZI_CREALITY.h" // ATmega644P, ATmega1284P
+ #include "pins_MELZI_CREALITY.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(MELZI_MALYAN)
- #include "pins_MELZI_MALYAN.h" // ATmega644P, ATmega1284P
+ #include "pins_MELZI_MALYAN.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(MELZI_TRONXY)
- #include "pins_MELZI_TRONXY.h" // ATmega644P, ATmega1284P
+ #include "pins_MELZI_TRONXY.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(STB_11)
- #include "pins_STB_11.h" // ATmega644P, ATmega1284P
+ #include "pins_STB_11.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(AZTEEG_X1)
- #include "pins_AZTEEG_X1.h" // ATmega644P, ATmega1284P
+ #include "pins_AZTEEG_X1.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
//
// Other ATmega644P, ATmega644, ATmega1284P
//
#elif MB(GEN3_MONOLITHIC)
- #include "pins_GEN3_MONOLITHIC.h" // ATmega644P
+ #include "pins_GEN3_MONOLITHIC.h" // ATmega644P env:sanguino_atmega644p
#elif MB(GEN3_PLUS)
- #include "pins_GEN3_PLUS.h" // ATmega644P, ATmega1284P
+ #include "pins_GEN3_PLUS.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(GEN6)
- #include "pins_GEN6.h" // ATmega644P, ATmega1284P
+ #include "pins_GEN6.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(GEN6_DELUXE)
- #include "pins_GEN6_DELUXE.h" // ATmega644P, ATmega1284P
+ #include "pins_GEN6_DELUXE.h" // ATmega644P, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(GEN7_CUSTOM)
- #include "pins_GEN7_CUSTOM.h" // ATmega644P, ATmega644, ATmega1284P
+ #include "pins_GEN7_CUSTOM.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(GEN7_12)
- #include "pins_GEN7_12.h" // ATmega644P, ATmega644, ATmega1284P
+ #include "pins_GEN7_12.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(GEN7_13)
- #include "pins_GEN7_13.h" // ATmega644P, ATmega644, ATmega1284P
+ #include "pins_GEN7_13.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(GEN7_14)
- #include "pins_GEN7_14.h" // ATmega644P, ATmega644, ATmega1284P
+ #include "pins_GEN7_14.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
#elif MB(OMCA_A)
- #include "pins_OMCA_A.h" // ATmega644
+ #include "pins_OMCA_A.h" // ATmega644 env:sanguino_atmega644p
#elif MB(OMCA)
- #include "pins_OMCA.h" // ATmega644P, ATmega644
+ #include "pins_OMCA.h" // ATmega644P, ATmega644 env:sanguino_atmega644p
#elif MB(ANET_10)
- #include "pins_ANET_10.h" // ATmega1284P
+ #include "pins_ANET_10.h" // ATmega1284P env:sanguino_atmega1284p
#elif MB(SETHI)
- #include "pins_SETHI.h" // ATmega644P, ATmega644, ATmega1284P
+ #include "pins_SETHI.h" // ATmega644P, ATmega644, ATmega1284P env:sanguino_atmega644p env:sanguino_atmega1284p
//
// Teensyduino - AT90USB1286, AT90USB1286P
//
#elif MB(TEENSYLU)
- #include "pins_TEENSYLU.h" // AT90USB1286, AT90USB1286P
+ #include "pins_TEENSYLU.h" // AT90USB1286, AT90USB1286P env:at90USB1286_CDC
#elif MB(PRINTRBOARD)
- #include "pins_PRINTRBOARD.h" // AT90USB1286
+ #include "pins_PRINTRBOARD.h" // AT90USB1286 env:at90USB1286_DFU
#elif MB(PRINTRBOARD_REVF)
- #include "pins_PRINTRBOARD_REVF.h" // AT90USB1286
+ #include "pins_PRINTRBOARD_REVF.h" // AT90USB1286 env:at90USB1286_DFU
#elif MB(BRAINWAVE)
- #include "pins_BRAINWAVE.h" // AT90USB646
+ #include "pins_BRAINWAVE.h" // AT90USB646 env:at90USB1286_CDC
#elif MB(BRAINWAVE_PRO)
- #include "pins_BRAINWAVE_PRO.h" // AT90USB1286
+ #include "pins_BRAINWAVE_PRO.h" // AT90USB1286 env:at90USB1286_CDC
#elif MB(SAV_MKI)
- #include "pins_SAV_MKI.h" // AT90USB1286
+ #include "pins_SAV_MKI.h" // AT90USB1286 env:at90USB1286_CDC
#elif MB(TEENSY2)
- #include "pins_TEENSY2.h" // AT90USB1286
+ #include "pins_TEENSY2.h" // AT90USB1286 env:teensy20
#elif MB(5DPRINT)
- #include "pins_5DPRINT.h" // AT90USB1286
+ #include "pins_5DPRINT.h" // AT90USB1286 ?env:at90USB1286_DFU
#else
#error "Unknown MOTHERBOARD value set in Configuration.h"
diff --git a/Marlin/pins_5DPRINT.h b/Marlin/pins_5DPRINT.h
index 0e8b5f6019..415cc23bce 100755
--- a/Marlin/pins_5DPRINT.h
+++ b/Marlin/pins_5DPRINT.h
@@ -132,7 +132,9 @@
#define HEATER_0_PIN 15 // C5
#define HEATER_BED_PIN 14 // C4
-#define FAN_PIN 16 // C6 PWM3A
+#ifndef FAN_PIN
+ #define FAN_PIN 16 // C6 PWM3A
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_ANET_10.h b/Marlin/pins_ANET_10.h
index d7c113d355..bdd277e35c 100644
--- a/Marlin/pins_ANET_10.h
+++ b/Marlin/pins_ANET_10.h
@@ -89,7 +89,7 @@
*/
#ifndef __AVR_ATmega1284P__
- #error "Oops! Make sure you have 'Anet V1.0', 'Anet V1.0 (Optiboot)' or 'Sanguino' selected from the 'Tools -> Boards' menu."
+ #error "Oops! Make sure you have 'Anet V1.0', 'Anet V1.0 (Optiboot)' or 'Sanguino' selected in the 'Tools -> Boards' menu and ATmega1284P selected in 'Tools -> Processor' menu."
#endif
#ifndef BOARD_NAME
@@ -133,7 +133,10 @@
//
#define HEATER_0_PIN 13 // (extruder)
#define HEATER_BED_PIN 12 // (bed)
-#define FAN_PIN 4
+
+#ifndef FAN_PIN
+ #define FAN_PIN 4
+#endif
//
// Misc. Functions
@@ -153,7 +156,7 @@
#if ENABLED(ULTRA_LCD) && ENABLED(NEWPANEL)
#define LCD_SDSS 28
#if ENABLED(ADC_KEYPAD)
- #define SERVO0_PIN 27 // free for BLTouch/3D-Touch
+ #define SERVO0_PIN 27 // free for BLTouch/3D-Touch
#define LCD_PINS_RS 28
#define LCD_PINS_ENABLE 29
#define LCD_PINS_D4 10
@@ -168,7 +171,7 @@
// Pin definitions for the Anet A6 Full Graphics display and the RepRapDiscount Full Graphics
// display using an adapter board // https://go.aisler.net/benlye/anet-lcd-adapter/pcb
// See below for alternative pin definitions for use with https://www.thingiverse.com/thing:2103748
- #define SERVO0_PIN 29 // free for BLTouch/3D-Touch
+ #define SERVO0_PIN 29 // free for BLTouch/3D-Touch
#define BEEPER_PIN 17
#define LCD_PINS_RS 27
#define LCD_PINS_ENABLE 28
@@ -177,13 +180,13 @@
#define BTN_EN2 10
#define BTN_ENC 16
#ifndef ST7920_DELAY_1
- #define ST7920_DELAY_1 DELAY_0_NOP
+ #define ST7920_DELAY_1 DELAY_NS(0)
#endif
#ifndef ST7920_DELAY_2
- #define ST7920_DELAY_2 DELAY_1_NOP
+ #define ST7920_DELAY_2 DELAY_NS(63)
#endif
#ifndef ST7920_DELAY_3
- #define ST7920_DELAY_3 DELAY_2_NOP
+ #define ST7920_DELAY_3 DELAY_NS(125)
#endif
#define STD_ENCODER_PULSES_PER_STEP 4
#define STD_ENCODER_STEPS_PER_MENU_ITEM 1
@@ -201,7 +204,7 @@
* published by oderwat on Thingiverse at https://www.thingiverse.com/thing:2103748.
*
* Using that adapter requires changing the pin definition as follows:
- * #define SERVO0_PIN 27 // free for BLTouch/3D-Touch
+ * #define SERVO0_PIN 27 // free for BLTouch/3D-Touch
* #define BEEPER_PIN 28
* #define LCD_PINS_RS 30
* #define LCD_PINS_ENABLE 29
diff --git a/Marlin/pins_AZTEEG_X3_PRO.h b/Marlin/pins_AZTEEG_X3_PRO.h
index 1010320679..fa17120651 100644
--- a/Marlin/pins_AZTEEG_X3_PRO.h
+++ b/Marlin/pins_AZTEEG_X3_PRO.h
@@ -24,22 +24,29 @@
* AZTEEG_X3_PRO (Arduino Mega) pin assignments
*/
+#ifndef __AVR_ATmega2560__
+ #error "Oops! Make sure you have 'Arduino Mega 2560' selected from the 'Tools -> Boards' menu."
+#endif
+
#if HOTENDS > 5 || E_STEPPERS > 5
#error "Azteeg X3 Pro supports up to 5 hotends / E-steppers. Comment out this line to continue."
#endif
-#if ENABLED(CASE_LIGHT_ENABLE) && !PIN_EXISTS(CASE_LIGHT)
- #define CASE_LIGHT_PIN 44 // Define before RAMPS pins include
-#endif
-
#define BOARD_NAME "Azteeg X3 Pro"
-#include "pins_RAMPS.h"
-
-#ifndef __AVR_ATmega2560__
- #error "Oops! Make sure you have 'Arduino Mega 2560' selected from the 'Tools -> Boards' menu."
+//
+// RAMPS pins overrides
+//
+#if ENABLED(CASE_LIGHT_ENABLE) && !PIN_EXISTS(CASE_LIGHT)
+ #define CASE_LIGHT_PIN 44
#endif
+#ifndef FAN_PIN
+ #define FAN_PIN 6
+#endif
+
+#include "pins_RAMPS.h"
+
// DIGIPOT slave addresses
#define DIGIPOT_I2C_ADDRESS_A 0x2C // unshifted slave address for first DIGIPOT 0x2C (0x58 <- 0x2C << 1)
#define DIGIPOT_I2C_ADDRESS_B 0x2E // unshifted slave address for second DIGIPOT 0x2E (0x5C <- 0x2E << 1)
@@ -116,9 +123,6 @@
#define HEATER_6_PIN 6
#define HEATER_7_PIN 11
-#undef FAN_PIN
-#define FAN_PIN 6 // Part Cooling System
-
#ifndef CONTROLLER_FAN_PIN
#define CONTROLLER_FAN_PIN 4 // Pin used for the fan to cool motherboard (-1 to disable)
#endif
diff --git a/Marlin/pins_BRAINWAVE.h b/Marlin/pins_BRAINWAVE.h
index 932619769b..a43c6be95c 100644
--- a/Marlin/pins_BRAINWAVE.h
+++ b/Marlin/pins_BRAINWAVE.h
@@ -115,7 +115,9 @@
#define HEATER_0_PIN 32 // A4 Extruder
#define HEATER_BED_PIN 18 // E6 Bed
-#define FAN_PIN 31 // A3 Fan
+#ifndef FAN_PIN
+ #define FAN_PIN 31 // A3 Fan
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_BRAINWAVE_PRO.h b/Marlin/pins_BRAINWAVE_PRO.h
index 872d868e10..49c8ab6b59 100644
--- a/Marlin/pins_BRAINWAVE_PRO.h
+++ b/Marlin/pins_BRAINWAVE_PRO.h
@@ -125,7 +125,9 @@
//
#define HEATER_0_PIN 27 // B7
#define HEATER_BED_PIN 26 // B6 Bed
-#define FAN_PIN 16 // C6 Fan, PWM3A
+#ifndef FAN_PIN
+ #define FAN_PIN 16 // C6 Fan, PWM3A
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_CHEAPTRONIC.h b/Marlin/pins_CHEAPTRONIC.h
index 6d1e45d870..e8f2c5f67e 100644
--- a/Marlin/pins_CHEAPTRONIC.h
+++ b/Marlin/pins_CHEAPTRONIC.h
@@ -69,8 +69,8 @@
//
// Heaters / Fans
//
-#define HEATER_0_PIN 19 // EXTRUDER 1
-#define HEATER_1_PIN 23 // EXTRUDER 2
+#define HEATER_0_PIN 19 // EXTRUDER 1
+#define HEATER_1_PIN 23 // EXTRUDER 2
#define HEATER_BED_PIN 22
//
diff --git a/Marlin/pins_CHEAPTRONICv2.h b/Marlin/pins_CHEAPTRONICv2.h
index e6840abeb2..eea57d23ec 100644
--- a/Marlin/pins_CHEAPTRONICv2.h
+++ b/Marlin/pins_CHEAPTRONICv2.h
@@ -31,6 +31,7 @@
#endif
#define BOARD_NAME "Cheaptronic v2.0"
+
//
// Limit Switches
//
@@ -80,10 +81,32 @@
//
// Heaters / Fans
//
-#define HEATER_0_PIN 6
-#define HEATER_1_PIN 7
-#define HEATER_2_PIN 8
-#define HEATER_BED_PIN 9
+#define HEATER_0_PIN 6
+#define HEATER_1_PIN 7
+#define HEATER_2_PIN 8
+#define HEATER_BED_PIN 9
+#ifndef FAN_PIN
+ #define FAN_PIN 3
+#endif
+#define FAN2_PIN 58 // additional fan or light control output
+
+//
+// Other board specific pins
+//
+#ifndef FIL_RUNOUT_PIN
+ #define FIL_RUNOUT_PIN 37 // board input labeled as F-DET
+#endif
+#define Z_MIN_PROBE_PIN 36 // additional external board input labeled as E-SENS (should be used for Z-probe)
+#define LED_PIN 13
+#define SPINDLE_ENABLE_PIN 4 // additional PWM pin 1 at JP1 connector - should be used for laser control too
+#define EXT_2 5 // additional PWM pin 2 at JP1 connector
+#define EXT_3 2 // additional PWM pin 3 at JP1 connector
+#define PS_ON_PIN 45
+#define KILL_PIN 46
+
+#ifndef FILWIDTH_PIN
+ #define FILWIDTH_PIN 11 // shared with TEMP_3 analog input
+#endif
//
// LCD
@@ -105,23 +128,3 @@
#define BTN_EN1 11
#define BTN_EN2 12
#define BTN_ENC 43
-
-//
-// Other board specific pins
-//
-#ifndef FIL_RUNOUT_PIN
- #define FIL_RUNOUT_PIN 37 // board input labeled as F-DET
-#endif
-#define Z_MIN_PROBE_PIN 36 // additional external board input labeled as E-SENS (should be used for Z-probe)
-#define LED_PIN 13
-#define SPINDLE_ENABLE_PIN 4 // additional PWM pin 1 at JP1 connector - should be used for laser control too
-#define EXT_2 5 // additional PWM pin 2 at JP1 connector
-#define EXT_3 2 // additional PWM pin 3 at JP1 connector
-#define FAN_PIN 3
-#define FAN2_PIN 58 // additional fan or light control output
-#define PS_ON_PIN 45
-#define KILL_PIN 46
-
-#ifndef FILWIDTH_PIN
- #define FILWIDTH_PIN 11 // shared with TEMP_3 analog input
-#endif
diff --git a/Marlin/pins_CNCONTROLS_11.h b/Marlin/pins_CNCONTROLS_11.h
index 8535288ece..0a32d04a18 100644
--- a/Marlin/pins_CNCONTROLS_11.h
+++ b/Marlin/pins_CNCONTROLS_11.h
@@ -65,7 +65,9 @@
#define HEATER_3_PIN 46
#define HEATER_BED_PIN 2
-//#define FAN_PIN 7 // common PWM pin for all tools
+#ifndef FAN_PIN
+ //#define FAN_PIN 7 // common PWM pin for all tools
+#endif
#define ORIG_E0_AUTO_FAN_PIN 7
#define ORIG_E1_AUTO_FAN_PIN 7
diff --git a/Marlin/pins_CNCONTROLS_12.h b/Marlin/pins_CNCONTROLS_12.h
index 9a849916f0..f073b19c96 100644
--- a/Marlin/pins_CNCONTROLS_12.h
+++ b/Marlin/pins_CNCONTROLS_12.h
@@ -65,7 +65,9 @@
#define HEATER_3_PIN 3
#define HEATER_BED_PIN 24
-#define FAN_PIN 5 // 5 is PWMtool3 -> 7 is common PWM pin for all tools
+#ifndef FAN_PIN
+ #define FAN_PIN 5 // 5 is PWMtool3 -> 7 is common PWM pin for all tools
+#endif
#define ORIG_E0_AUTO_FAN_PIN 7
#define ORIG_E1_AUTO_FAN_PIN 7
@@ -124,4 +126,4 @@
//#define UI2 37
#define STAT_LED_BLUE_PIN -1
-#define STAT_LED_RED_PIN 10 // TOOL_0_PWM_PIN
+#define STAT_LED_RED_PIN 10 // TOOL_0_PWM_PIN
diff --git a/Marlin/pins_EINSY_RAMBO.h b/Marlin/pins_EINSY_RAMBO.h
index b86e1530ac..b3c1d1caa0 100644
--- a/Marlin/pins_EINSY_RAMBO.h
+++ b/Marlin/pins_EINSY_RAMBO.h
@@ -117,7 +117,9 @@
#define HEATER_0_PIN 3
#define HEATER_BED_PIN 4
-#define FAN_PIN 8
+#ifndef FAN_PIN
+ #define FAN_PIN 8
+#endif
#define FAN1_PIN 6
//
diff --git a/Marlin/pins_EINSY_RETRO.h b/Marlin/pins_EINSY_RETRO.h
index 4b46427f30..df4f1c20be 100644
--- a/Marlin/pins_EINSY_RETRO.h
+++ b/Marlin/pins_EINSY_RETRO.h
@@ -134,7 +134,9 @@
#define HEATER_0_PIN 3
#define HEATER_BED_PIN 4
-#define FAN_PIN 8
+#ifndef FAN_PIN
+ #define FAN_PIN 8
+#endif
#define FAN1_PIN 6
//
diff --git a/Marlin/pins_ELEFU_3.h b/Marlin/pins_ELEFU_3.h
index 12631a901f..79a4bce712 100644
--- a/Marlin/pins_ELEFU_3.h
+++ b/Marlin/pins_ELEFU_3.h
@@ -90,7 +90,9 @@
#define HEATER_2_PIN 17 // 12V PWM3
#define HEATER_BED_PIN 44 // DOUBLE 12V PWM
-#define FAN_PIN 16 // 5V PWM
+#ifndef FAN_PIN
+ #define FAN_PIN 16 // 5V PWM
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_GEN3_MONOLITHIC.h b/Marlin/pins_GEN3_MONOLITHIC.h
index dae4046fd2..5d64e94290 100644
--- a/Marlin/pins_GEN3_MONOLITHIC.h
+++ b/Marlin/pins_GEN3_MONOLITHIC.h
@@ -68,11 +68,11 @@
//
#define X_STEP_PIN 15
#define X_DIR_PIN 18
-#define X_ENABLE_PIN 24 // actually uses Y_enable_pin
+#define X_ENABLE_PIN 24 // actually uses Y_enable_pin
#define Y_STEP_PIN 23
#define Y_DIR_PIN 22
-#define Y_ENABLE_PIN 24 // shared with X_enable_pin
+#define Y_ENABLE_PIN 24 // shared with X_enable_pin
#define Z_STEP_PIN 27
#define Z_DIR_PIN 28
@@ -95,7 +95,6 @@
//
// Misc. Functions
//
-#define PS_ON_PIN 14 // Alex, does this work on the card?
+#define PS_ON_PIN 14 // Alex, does this work on the card?
// Alex extras from Gen3+
-
diff --git a/Marlin/pins_GEN7_12.h b/Marlin/pins_GEN7_12.h
index 3bc38d7ee7..1afaae9abc 100644
--- a/Marlin/pins_GEN7_12.h
+++ b/Marlin/pins_GEN7_12.h
@@ -112,8 +112,8 @@
#define HEATER_0_PIN 4
#define HEATER_BED_PIN 3
-#if GEN7_VERSION < 13 // Gen7 v1.3 removed the fan pin
- #define FAN_PIN 31
+#if !defined(FAN_PIN) && GEN7_VERSION < 13 // Gen7 v1.3 removed the fan pin
+ #define FAN_PIN 31
#endif
//
diff --git a/Marlin/pins_GT2560_REV_A.h b/Marlin/pins_GT2560_REV_A.h
index 73b32bb40c..63f166ab32 100644
--- a/Marlin/pins_GT2560_REV_A.h
+++ b/Marlin/pins_GT2560_REV_A.h
@@ -81,7 +81,9 @@
#define HEATER_0_PIN 2
#define HEATER_1_PIN 3
#define HEATER_BED_PIN 4
-#define FAN_PIN 7
+#ifndef FAN_PIN
+ #define FAN_PIN 7
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_LEAPFROG.h b/Marlin/pins_LEAPFROG.h
index a7fffa5325..9a31520e8a 100644
--- a/Marlin/pins_LEAPFROG.h
+++ b/Marlin/pins_LEAPFROG.h
@@ -47,21 +47,21 @@
#define X_DIR_PIN 63
#define X_ENABLE_PIN 29
-#define Y_STEP_PIN 14 // A6
-#define Y_DIR_PIN 15 // A0
+#define Y_STEP_PIN 14 // A6
+#define Y_DIR_PIN 15 // A0
#define Y_ENABLE_PIN 39
-#define Z_STEP_PIN 31 // A2
-#define Z_DIR_PIN 32 // A6
-#define Z_ENABLE_PIN 30 // A1
+#define Z_STEP_PIN 31 // A2
+#define Z_DIR_PIN 32 // A6
+#define Z_ENABLE_PIN 30 // A1
-#define E0_STEP_PIN 34 // 34
-#define E0_DIR_PIN 35 // 35
-#define E0_ENABLE_PIN 33 // 33
+#define E0_STEP_PIN 34 // 34
+#define E0_DIR_PIN 35 // 35
+#define E0_ENABLE_PIN 33 // 33
-#define E1_STEP_PIN 37 // 37
-#define E1_DIR_PIN 40 // 40
-#define E1_ENABLE_PIN 36 // 36
+#define E1_STEP_PIN 37 // 37
+#define E1_DIR_PIN 40 // 40
+#define E1_ENABLE_PIN 36 // 36
//
// Temperature Sensors
@@ -74,9 +74,9 @@
// Heaters / Fans
//
#define HEATER_0_PIN 9
-#define HEATER_1_PIN 8 // 12
-#define HEATER_2_PIN 11 // 13
-#define HEATER_BED_PIN 10 // 14/15
+#define HEATER_1_PIN 8 // 12
+#define HEATER_2_PIN 11 // 13
+#define HEATER_BED_PIN 10 // 14/15
#define FAN_PIN 7
diff --git a/Marlin/pins_MEGACONTROLLER.h b/Marlin/pins_MEGACONTROLLER.h
index b2631901be..709dc413be 100644
--- a/Marlin/pins_MEGACONTROLLER.h
+++ b/Marlin/pins_MEGACONTROLLER.h
@@ -62,17 +62,17 @@
//
// Steppers
//
-#define X_STEP_PIN 62 // A8
-#define X_DIR_PIN 63 // A9
-#define X_ENABLE_PIN 61 // A7
+#define X_STEP_PIN 62 // A8
+#define X_DIR_PIN 63 // A9
+#define X_ENABLE_PIN 61 // A7
-#define Y_STEP_PIN 65 // A11
-#define Y_DIR_PIN 66 // A12
-#define Y_ENABLE_PIN 64 // A10
+#define Y_STEP_PIN 65 // A11
+#define Y_DIR_PIN 66 // A12
+#define Y_ENABLE_PIN 64 // A10
-#define Z_STEP_PIN 68 // A14
-#define Z_DIR_PIN 69 // A15
-#define Z_ENABLE_PIN 67 // A13
+#define Z_STEP_PIN 68 // A14
+#define Z_DIR_PIN 69 // A15
+#define Z_ENABLE_PIN 67 // A13
#define E0_STEP_PIN 23
#define E0_DIR_PIN 24
@@ -112,7 +112,9 @@
#define HEATER_1_PIN 34
#define HEATER_BED_PIN 28
-#define FAN_PIN 39
+#ifndef FAN_PIN
+ #define FAN_PIN 39
+#endif
#define FAN1_PIN 35
#define FAN2_PIN 36
diff --git a/Marlin/pins_MEGATRONICS.h b/Marlin/pins_MEGATRONICS.h
index acf1da0160..8b608eff88 100644
--- a/Marlin/pins_MEGATRONICS.h
+++ b/Marlin/pins_MEGATRONICS.h
@@ -53,13 +53,13 @@
#define X_DIR_PIN 28
#define X_ENABLE_PIN 24
-#define Y_STEP_PIN 60 // A6
-#define Y_DIR_PIN 61 // A7
+#define Y_STEP_PIN 60 // A6
+#define Y_DIR_PIN 61 // A7
#define Y_ENABLE_PIN 22
-#define Z_STEP_PIN 54 // A0
-#define Z_DIR_PIN 55 // A1
-#define Z_ENABLE_PIN 56 // A2
+#define Z_STEP_PIN 54 // A0
+#define Z_DIR_PIN 55 // A1
+#define Z_ENABLE_PIN 56 // A2
#define E0_STEP_PIN 31
#define E0_DIR_PIN 32
@@ -87,7 +87,9 @@
#define HEATER_1_PIN 8
#define HEATER_BED_PIN 10
-#define FAN_PIN 7 // IO pin. Buffer needed
+#ifndef FAN_PIN
+ #define FAN_PIN 7 // IO pin. Buffer needed
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_MEGATRONICS_2.h b/Marlin/pins_MEGATRONICS_2.h
index 2ae436674b..9bd8b4506d 100644
--- a/Marlin/pins_MEGATRONICS_2.h
+++ b/Marlin/pins_MEGATRONICS_2.h
@@ -101,7 +101,9 @@
#define HEATER_1_PIN 8
#define HEATER_BED_PIN 10
-#define FAN_PIN 7
+#ifndef FAN_PIN
+ #define FAN_PIN 7
+#endif
#define FAN1_PIN 6
//
diff --git a/Marlin/pins_MEGATRONICS_3.h b/Marlin/pins_MEGATRONICS_3.h
index c638b27865..119c63a585 100644
--- a/Marlin/pins_MEGATRONICS_3.h
+++ b/Marlin/pins_MEGATRONICS_3.h
@@ -118,7 +118,9 @@
#define HEATER_2_PIN 8
#define HEATER_BED_PIN 10
-#define FAN_PIN 6
+#ifndef FAN_PIN
+ #define FAN_PIN 6
+#endif
#define FAN1_PIN 7
//
diff --git a/Marlin/pins_MELZI_CREALITY.h b/Marlin/pins_MELZI_CREALITY.h
index b42075b76d..8bfd3b860a 100644
--- a/Marlin/pins_MELZI_CREALITY.h
+++ b/Marlin/pins_MELZI_CREALITY.h
@@ -55,13 +55,13 @@
// Alter timing for graphical display
#ifndef ST7920_DELAY_1
- #define ST7920_DELAY_1 DELAY_2_NOP
+ #define ST7920_DELAY_1 DELAY_NS(125)
#endif
#ifndef ST7920_DELAY_2
- #define ST7920_DELAY_2 DELAY_2_NOP
+ #define ST7920_DELAY_2 DELAY_NS(125)
#endif
#ifndef ST7920_DELAY_3
- #define ST7920_DELAY_3 DELAY_2_NOP
+ #define ST7920_DELAY_3 DELAY_NS(125)
#endif
#if ENABLED(MINIPANEL)
diff --git a/Marlin/pins_MELZI_MALYAN.h b/Marlin/pins_MELZI_MALYAN.h
index 3888b537d1..a81526f065 100644
--- a/Marlin/pins_MELZI_MALYAN.h
+++ b/Marlin/pins_MELZI_MALYAN.h
@@ -44,11 +44,11 @@
// Alter timing for graphical display
#ifndef ST7920_DELAY_1
- #define ST7920_DELAY_1 DELAY_2_NOP
+ #define ST7920_DELAY_1 DELAY_NS(125)
#endif
#ifndef ST7920_DELAY_2
- #define ST7920_DELAY_2 DELAY_2_NOP
+ #define ST7920_DELAY_2 DELAY_NS(125)
#endif
#ifndef ST7920_DELAY_3
- #define ST7920_DELAY_3 DELAY_2_NOP
+ #define ST7920_DELAY_3 DELAY_NS(125)
#endif
diff --git a/Marlin/pins_MELZI_TRONXY.h b/Marlin/pins_MELZI_TRONXY.h
index 7c66c50c60..0da7934302 100644
--- a/Marlin/pins_MELZI_TRONXY.h
+++ b/Marlin/pins_MELZI_TRONXY.h
@@ -51,11 +51,11 @@
#define BTN_ENC 26
#ifndef ST7920_DELAY_1
- #define ST7920_DELAY_1 DELAY_0_NOP
+ #define ST7920_DELAY_1 DELAY_NS(0)
#endif
#ifndef ST7920_DELAY_2
- #define ST7920_DELAY_2 DELAY_2_NOP
+ #define ST7920_DELAY_2 DELAY_NS(125)
#endif
#ifndef ST7920_DELAY_3
- #define ST7920_DELAY_3 DELAY_0_NOP
+ #define ST7920_DELAY_3 DELAY_NS(0)
#endif
diff --git a/Marlin/pins_MIGHTYBOARD_REVE.h b/Marlin/pins_MIGHTYBOARD_REVE.h
index 9a2fb539b2..989533d53e 100644
--- a/Marlin/pins_MIGHTYBOARD_REVE.h
+++ b/Marlin/pins_MIGHTYBOARD_REVE.h
@@ -134,14 +134,14 @@
// 2 E4 CS2
// 78 E2 SCK
//
-#define THERMO_SCK_PIN 78 // E2
-#define THERMO_DO_PIN 3 // E5
-#define THERMO_CS1 5 // E3
-#define THERMO_CS2 2 // E4
+#define THERMO_SCK_PIN 78 // E2
+#define THERMO_DO_PIN 3 // E5
+#define THERMO_CS1 5 // E3
+#define THERMO_CS2 2 // E4
-#define MAX6675_SS THERMO_CS1
-#define MAX6675_SCK_PIN THERMO_SCK_PIN
-#define MAX6675_DO_PIN THERMO_DO_PIN
+#define MAX6675_SS THERMO_CS1
+#define MAX6675_SCK_PIN THERMO_SCK_PIN
+#define MAX6675_DO_PIN THERMO_DO_PIN
//
// Augmentation for auto-assigning plugs
//
@@ -149,10 +149,10 @@
// 2 extruders or 1 extruder and a heated bed.
// With no heated bed, an additional 24V fan is possible.
//
-#define MOSFET_A_PIN 6 // H3
-#define MOSFET_B_PIN 11 // B5 - Rev A of this file had this pin assigned to 9
-#define MOSFET_C_PIN 45 // L4
-#define MOSFET_D_PIN 44 // L5
+#define MOSFET_A_PIN 6 // H3
+#define MOSFET_B_PIN 11 // B5 - Rev A of this file had this pin assigned to 9
+#define MOSFET_C_PIN 45 // L4
+#define MOSFET_D_PIN 44 // L5
#if HOTENDS > 1
#if TEMP_SENSOR_BED
@@ -172,23 +172,24 @@
#define HEATER_0_PIN MOSFET_A_PIN
#if ENABLED(IS_EFB) // Hotend, Fan, Bed
- #define FAN_PIN MOSFET_B_PIN
- #define HEATER_BED_PIN MOSFET_C_PIN
+ #define HEATER_BED_PIN MOSFET_C_PIN
#elif ENABLED(IS_EEF) // Hotend, Hotend, Fan
- #define HEATER_1_PIN MOSFET_B_PIN
- #define FAN_PIN MOSFET_C_PIN
+ #define HEATER_1_PIN MOSFET_B_PIN
#elif ENABLED(IS_EEB) // Hotend, Hotend, Bed
- #define HEATER_1_PIN MOSFET_B_PIN
- #define HEATER_BED_PIN MOSFET_C_PIN
+ #define HEATER_1_PIN MOSFET_B_PIN
+ #define HEATER_BED_PIN MOSFET_C_PIN
#elif ENABLED(IS_EFF) // Hotend, Fan, Fan
- #define FAN_PIN MOSFET_B_PIN
- #define FAN1_PIN MOSFET_C_PIN
-#elif ENABLED(IS_SF) // Spindle, Fan
- #define FAN_PIN MOSFET_C_PIN
+ #define FAN1_PIN MOSFET_C_PIN
#endif
#ifndef FAN_PIN
- #define FAN_PIN MOSFET_D_PIN
+ #if ENABLED(IS_EFB) || ENABLED(IS_EFF) // Hotend, Fan, Bed or Hotend, Fan, Fan
+ #define FAN_PIN MOSFET_B_PIN
+ #elif ENABLED(IS_EEF) || ENABLED(IS_SF) // Hotend, Hotend, Fan or Spindle, Fan
+ #define FAN_PIN MOSFET_C_PIN
+ #else
+ #define FAN_PIN MOSFET_D_PIN
+ #endif
#endif
//
@@ -200,37 +201,37 @@
//
// Misc. Functions
//
-#define LED_PIN 13 // B7
-#define CUTOFF_RESET_PIN 16 // H1
-#define CUTOFF_TEST_PIN 17 // H0
-#define CASE_LIGHT_PIN 44 // L5 MUST BE HARDWARE PWM
+#define LED_PIN 13 // B7
+#define CUTOFF_RESET_PIN 16 // H1
+#define CUTOFF_TEST_PIN 17 // H0
+#define CASE_LIGHT_PIN 44 // L5 MUST BE HARDWARE PWM
//
// LCD / Controller
//
#ifdef REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER
- #define LCD_PINS_RS 33 // C4: LCD-STROBE
- #define LCD_PINS_ENABLE 72 // J2: LEFT
- #define LCD_PINS_D4 35 // C2: LCD-CLK
- #define LCD_PINS_D5 32 // C5: RLED
- #define LCD_PINS_D6 34 // C3: LCD-DATA
- #define LCD_PINS_D7 31 // C6: GLED
+ #define LCD_PINS_RS 33 // C4: LCD-STROBE
+ #define LCD_PINS_ENABLE 72 // J2: LEFT
+ #define LCD_PINS_D4 35 // C2: LCD-CLK
+ #define LCD_PINS_D5 32 // C5: RLED
+ #define LCD_PINS_D6 34 // C3: LCD-DATA
+ #define LCD_PINS_D7 31 // C6: GLED
- #define BTN_EN2 75 // J4, UP
- #define BTN_EN1 73 // J3, DOWN
+ #define BTN_EN2 75 // J4, UP
+ #define BTN_EN1 73 // J3, DOWN
//STOP button connected as KILL_PIN
- #define KILL_PIN 14 // J1, RIGHT
+ #define KILL_PIN 14 // J1, RIGHT
//KILL - not connected
- #define BEEPER_PIN 8 // H5, SD_WP
+ #define BEEPER_PIN 8 // H5, SD_WP
- #define BTN_CENTER 15 // J0
- #define BTN_ENC BTN_CENTER
+ #define BTN_CENTER 15 // J0
+ #define BTN_ENC BTN_CENTER
//on board leds
- #define STAT_LED_RED_LED SERVO0_PIN // C1 (1280-EX1, DEBUG2)
- #define STAT_LED_BLUE_PIN SERVO1_PIN // C0 (1280-EX2, DEBUG3)
+ #define STAT_LED_RED_LED SERVO0_PIN // C1 (1280-EX1, DEBUG2)
+ #define STAT_LED_BLUE_PIN SERVO1_PIN // C0 (1280-EX2, DEBUG3)
#else
// Replicator uses a 3-wire SR controller with HD44780
@@ -238,18 +239,18 @@
//
#define SAV_3DLCD
- #define SR_DATA_PIN 34 // C3
- #define SR_CLK_PIN 35 // C2
- #define SR_STROBE_PIN 33 // C4
+ #define SR_DATA_PIN 34 // C3
+ #define SR_CLK_PIN 35 // C2
+ #define SR_STROBE_PIN 33 // C4
- #define BTN_UP 75 // J4
- #define BTN_DOWN 73 // J3
- #define BTN_LEFT 72 // J2
- #define BTN_RIGHT 14 // J1
- #define BTN_CENTER 15 // J0
- #define BTN_ENC BTN_CENTER
+ #define BTN_UP 75 // J4
+ #define BTN_DOWN 73 // J3
+ #define BTN_LEFT 72 // J2
+ #define BTN_RIGHT 14 // J1
+ #define BTN_CENTER 15 // J0
+ #define BTN_ENC BTN_CENTER
- #define BEEPER_PIN 4 // G5
+ #define BEEPER_PIN 4 // G5
#define STAT_LED_RED_PIN 32 // C5
#define STAT_LED_BLUE_PIN 31 // C6 (Actually green)
@@ -259,8 +260,8 @@
//
// SD Card
//
-#define SDSS 53 // B0
-#define SD_DETECT_PIN 9 // H6
+#define SDSS 53 // B0
+#define SD_DETECT_PIN 9 // H6
#define MAX_PIN THERMO_SCK_PIN
@@ -272,8 +273,6 @@
#define SPINDLE_DIR_PIN 67 // K5
-
-
// Check if all pins are defined in mega/pins_arduino.h
#include
static_assert(NUM_DIGITAL_PINS > MAX_PIN, "add missing pins to [arduino dir]/hardware/arduino/avr/variants/mega/pins_arduino.h based on fastio.h"
diff --git a/Marlin/pins_MINIRAMBO.h b/Marlin/pins_MINIRAMBO.h
index 609c0c867c..89335ea8d4 100644
--- a/Marlin/pins_MINIRAMBO.h
+++ b/Marlin/pins_MINIRAMBO.h
@@ -106,7 +106,9 @@
#endif
#define HEATER_BED_PIN 4
-#define FAN_PIN 8
+#ifndef FAN_PIN
+ #define FAN_PIN 8
+#endif
#define FAN1_PIN 6
//
diff --git a/Marlin/pins_MINITRONICS.h b/Marlin/pins_MINITRONICS.h
index fe2c9e0b54..f5fdac21d2 100644
--- a/Marlin/pins_MINITRONICS.h
+++ b/Marlin/pins_MINITRONICS.h
@@ -57,13 +57,13 @@
#define X_DIR_PIN 47
#define X_ENABLE_PIN 49
-#define Y_STEP_PIN 39 // A6
-#define Y_DIR_PIN 40 // A0
+#define Y_STEP_PIN 39 // A6
+#define Y_DIR_PIN 40 // A0
#define Y_ENABLE_PIN 38
-#define Z_STEP_PIN 42 // A2
-#define Z_DIR_PIN 43 // A6
-#define Z_ENABLE_PIN 41 // A1
+#define Z_STEP_PIN 42 // A2
+#define Z_DIR_PIN 43 // A6
+#define Z_ENABLE_PIN 41 // A1
#define E0_STEP_PIN 45
#define E0_DIR_PIN 44
@@ -83,11 +83,13 @@
//
// Heaters / Fans
//
-#define HEATER_0_PIN 7 // EXTRUDER 1
-#define HEATER_1_PIN 8 // EXTRUDER 2
-#define HEATER_BED_PIN 3 // BED
+#define HEATER_0_PIN 7 // EXTRUDER 1
+#define HEATER_1_PIN 8 // EXTRUDER 2
+#define HEATER_BED_PIN 3 // BED
-#define FAN_PIN 9
+#ifndef FAN_PIN
+ #define FAN_PIN 9
+#endif
//
// Misc. Functions
@@ -122,7 +124,7 @@
#define BTN_EN2 -1
#define BTN_ENC -1
- #define SD_DETECT_PIN -1 // Minitronics doesn't use this
+ #define SD_DETECT_PIN -1 // Minitronics doesn't use this
#endif
//
diff --git a/Marlin/pins_MKS_GEN_13.h b/Marlin/pins_MKS_GEN_13.h
index 70228e2f1f..e0e916b878 100644
--- a/Marlin/pins_MKS_GEN_13.h
+++ b/Marlin/pins_MKS_GEN_13.h
@@ -33,7 +33,7 @@
#error "MKS GEN 1.3/1.4 supports up to 2 hotends / E-steppers. Comment out this line to continue."
#endif
-#define BOARD_NAME "MKS GEN > v1.3"
+#define BOARD_NAME "MKS GEN >= v1.3"
//
// Heaters / Fans
diff --git a/Marlin/pins_MKS_GEN_L.h b/Marlin/pins_MKS_GEN_L.h
index dd4568e152..59c5bcf481 100644
--- a/Marlin/pins_MKS_GEN_L.h
+++ b/Marlin/pins_MKS_GEN_L.h
@@ -36,4 +36,17 @@
// Power outputs EFBF or EFBE
#define MOSFET_D_PIN 7
+//
+// CS Pins wired to avoid conflict with the LCD
+// See https://www.thingiverse.com/asset:66604
+//
+
+#ifndef X_CS_PIN
+ #define X_CS_PIN 59
+#endif
+
+#ifndef Y_CS_PIN
+ #define Y_CS_PIN 63
+#endif
+
#include "pins_RAMPS.h"
diff --git a/Marlin/pins_OMCA.h b/Marlin/pins_OMCA.h
index 8715efcd44..6ee6fabe6b 100644
--- a/Marlin/pins_OMCA.h
+++ b/Marlin/pins_OMCA.h
@@ -108,13 +108,13 @@
#define E0_DIR_PIN 21
#define E0_ENABLE_PIN 10
-#define E1_STEP_PIN -1 // 21
-#define E1_DIR_PIN -1 // 20
-#define E1_ENABLE_PIN -1 // 19
+#define E1_STEP_PIN -1 // 21
+#define E1_DIR_PIN -1 // 20
+#define E1_ENABLE_PIN -1 // 19
-#define E2_STEP_PIN -1 // 21
-#define E2_DIR_PIN -1 // 20
-#define E2_ENABLE_PIN -1 // 18
+#define E2_STEP_PIN -1 // 21
+#define E2_DIR_PIN -1 // 20
+#define E2_ENABLE_PIN -1 // 18
//
// Temperature Sensors
@@ -126,10 +126,12 @@
//
// Heaters / Fans
//
-#define HEATER_0_PIN 3 // DONE PWM on RIGHT connector
+#define HEATER_0_PIN 3 // DONE PWM on RIGHT connector
#define HEATER_BED_PIN 4
-#define FAN_PIN 14 // PWM on MIDDLE connector
+#ifndef FAN_PIN
+ #define FAN_PIN 14 // PWM on MIDDLE connector
+#endif
//
// Misc. Functions
@@ -145,4 +147,4 @@
#define __GS 18
#define __GD 13
-#define UNUSED_PWM 14 // PWM on LEFT connector
+#define UNUSED_PWM 14 // PWM on LEFT connector
diff --git a/Marlin/pins_OMCA_A.h b/Marlin/pins_OMCA_A.h
index 3686973c95..777c80b22f 100644
--- a/Marlin/pins_OMCA_A.h
+++ b/Marlin/pins_OMCA_A.h
@@ -107,12 +107,12 @@
#define E0_DIR_PIN 27
#define E0_ENABLE_PIN 24
-#define E1_STEP_PIN -1 // 19
-#define E1_DIR_PIN -1 // 18
+#define E1_STEP_PIN -1 // 19
+#define E1_DIR_PIN -1 // 18
#define E1_ENABLE_PIN 24
-#define E2_STEP_PIN -1 // 17
-#define E2_DIR_PIN -1 // 16
+#define E2_STEP_PIN -1 // 17
+#define E2_DIR_PIN -1 // 16
#define E2_ENABLE_PIN 24
//
@@ -125,7 +125,9 @@
//
#define HEATER_0_PIN 4
-#define FAN_PIN 3
+#ifndef FAN_PIN
+ #define FAN_PIN 3
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_PRINTRBOARD.h b/Marlin/pins_PRINTRBOARD.h
index a8197af9a4..42632d174a 100644
--- a/Marlin/pins_PRINTRBOARD.h
+++ b/Marlin/pins_PRINTRBOARD.h
@@ -74,11 +74,7 @@
// Limit Switches
//
#define X_STOP_PIN 47 // E3
-#if ENABLED(SDSUPPORT)
- #define Y_STOP_PIN 37 // E5 - Move Ystop to Estop socket
-#else
- #define Y_STOP_PIN 20 // B0 SS - Ystop in Ystop socket
-#endif
+#define Y_STOP_PIN 20 // B0 SS
#define Z_STOP_PIN 36 // E4
//
@@ -114,13 +110,14 @@
#define HEATER_2_PIN 45 // F7
#define HEATER_BED_PIN 14 // C4 PWM3C
-
-#define FAN_PIN 16 // C6 PWM3A
+#ifndef FAN_PIN
+ #define FAN_PIN 16 // C6 PWM3A
+#endif
//
// Misc. Functions
//
-#define SDSS 20 // B0 SS
+#define SDSS 26 // B6 SDCS
#define FILWIDTH_PIN 2 // Analog Input
//
@@ -146,16 +143,18 @@
#define BTN_EN2 3 // D3 RX1 JP2-7
#define BTN_ENC 45 // F7 TDI JP2-12
+ #undef SDSS
#define SDSS 43 // F5 TMS JP2-8
- #define STAT_LED_RED_PIN 12 // C2 JP11-14
- #define STAT_LED_BLUE_PIN 10 // C0 JP11-12
+ #define STAT_LED_RED_PIN 12 // C2 JP11-14
+ #define STAT_LED_BLUE_PIN 10 // C0 JP11-12
#elif ENABLED(LCD_I2C_PANELOLU2)
#define BTN_EN1 3 // D3 RX1 JP2-7
#define BTN_EN2 2 // D2 TX1 JP2-5
#define BTN_ENC 41 // F3 JP2-4
+ #undef SDSS
#define SDSS 38 // F0 B-THERM connector - use SD card on Panelolu2
#else
diff --git a/Marlin/pins_PRINTRBOARD_REVF.h b/Marlin/pins_PRINTRBOARD_REVF.h
index bf3a023c4d..8239a91586 100644
--- a/Marlin/pins_PRINTRBOARD_REVF.h
+++ b/Marlin/pins_PRINTRBOARD_REVF.h
@@ -190,7 +190,9 @@
#endif
#endif
-#define FAN_PIN 16 // C6 PWM3A
+#ifndef FAN_PIN
+ #define FAN_PIN 16 // C6 PWM3A
+#endif
//
// LCD / Controller
@@ -244,13 +246,13 @@
// increase delays
#ifndef ST7920_DELAY_1
- #define ST7920_DELAY_1 DELAY_5_NOP
+ #define ST7920_DELAY_1 DELAY_NS(313)
#endif
#ifndef ST7920_DELAY_2
- #define ST7920_DELAY_2 DELAY_5_NOP
+ #define ST7920_DELAY_2 DELAY_NS(313)
#endif
#ifndef ST7920_DELAY_3
- #define ST7920_DELAY_3 DELAY_5_NOP
+ #define ST7920_DELAY_3 DELAY_NS(313)
#endif
#else
diff --git a/Marlin/pins_RAMBO.h b/Marlin/pins_RAMBO.h
index bcc1b4f62d..f2ea3d33bd 100644
--- a/Marlin/pins_RAMBO.h
+++ b/Marlin/pins_RAMBO.h
@@ -127,7 +127,9 @@
#define HEATER_2_PIN 6
#define HEATER_BED_PIN 3
-#define FAN_PIN 8
+#ifndef FAN_PIN
+ #define FAN_PIN 8
+#endif
#define FAN1_PIN 6
#define FAN2_PIN 2
diff --git a/Marlin/pins_RAMPS_OLD.h b/Marlin/pins_RAMPS_OLD.h
index 951e3b000b..da047e2b0a 100644
--- a/Marlin/pins_RAMPS_OLD.h
+++ b/Marlin/pins_RAMPS_OLD.h
@@ -88,11 +88,15 @@
#if ENABLED(RAMPS_V_1_0)
#define HEATER_0_PIN 12
#define HEATER_BED_PIN -1
- #define FAN_PIN 11
+ #ifndef FAN_PIN
+ #define FAN_PIN 11
+ #endif
#else // RAMPS_V_1_1 or RAMPS_V_1_2
#define HEATER_0_PIN 10
#define HEATER_BED_PIN 8
- #define FAN_PIN 9
+ #ifndef FAN_PIN
+ #define FAN_PIN 9
+ #endif
#endif
//
diff --git a/Marlin/pins_RIGIDBOARD.h b/Marlin/pins_RIGIDBOARD.h
index 5bd06e40eb..e985963505 100644
--- a/Marlin/pins_RIGIDBOARD.h
+++ b/Marlin/pins_RIGIDBOARD.h
@@ -36,8 +36,8 @@
//
// MOSFET changes
//
-#define RAMPS_D10_PIN 9 // EXTRUDER 1
-#define MOSFET_D_PIN 12 // EXTRUDER 2 or FAN
+#define RAMPS_D10_PIN 9 // EXTRUDER 1
+#define MOSFET_D_PIN 12 // EXTRUDER 2 or FAN
#include "pins_RAMPS.h"
@@ -74,9 +74,9 @@
// SPI for Max6675 or Max31855 Thermocouple
#undef MAX6675_SS
#if DISABLED(SDSUPPORT)
- #define MAX6675_SS 53 // Don't use pin 53 if there is even the remote possibility of using Display/SD card
+ #define MAX6675_SS 53 // Don't use pin 53 if there is even the remote possibility of using Display/SD card
#else
- #define MAX6675_SS 49 // Don't use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
+ #define MAX6675_SS 49 // Don't use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present
#endif
//
@@ -85,8 +85,9 @@
#undef HEATER_BED_PIN
#define HEATER_BED_PIN 10
-#undef FAN_PIN
-#define FAN_PIN 8 // Same as RAMPS_13_EEF
+#ifndef FAN_PIN
+ #define FAN_PIN 8 // Same as RAMPS_13_EEF
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_RIGIDBOARD_V2.h b/Marlin/pins_RIGIDBOARD_V2.h
index dfac7051d5..2075892ab8 100644
--- a/Marlin/pins_RIGIDBOARD_V2.h
+++ b/Marlin/pins_RIGIDBOARD_V2.h
@@ -39,12 +39,12 @@
// Channels available for DAC, For Rigidboard there are 4
#define DAC_STEPPER_ORDER { 0, 1, 2, 3 }
-#define DAC_STEPPER_SENSE 0.05 // sense resistors on rigidboard stepper chips are .05 value
+#define DAC_STEPPER_SENSE 0.05 // sense resistors on rigidboard stepper chips are .05 value
#define DAC_STEPPER_ADDRESS 0
-#define DAC_STEPPER_MAX 4096 // was 5000 but max allowable value is actually 4096
-#define DAC_STEPPER_VREF 1 // internal Vref, gain 2x = 4.096V
-#define DAC_STEPPER_GAIN 1 // value of 1 here sets gain of 2
-#define DAC_DISABLE_PIN 42 // set low to enable DAC
+#define DAC_STEPPER_MAX 4096 // was 5000 but max allowable value is actually 4096
+#define DAC_STEPPER_VREF 1 // internal Vref, gain 2x = 4.096V
+#define DAC_STEPPER_GAIN 1 // value of 1 here sets gain of 2
+#define DAC_DISABLE_PIN 42 // set low to enable DAC
#define DAC_OR_ADDRESS 0x01
#ifndef DAC_MOTOR_CURRENT_DEFAULT
diff --git a/Marlin/pins_SANGUINOLOLU_11.h b/Marlin/pins_SANGUINOLOLU_11.h
index c27eab1c8a..0d9af5b5a8 100644
--- a/Marlin/pins_SANGUINOLOLU_11.h
+++ b/Marlin/pins_SANGUINOLOLU_11.h
@@ -100,7 +100,7 @@
#define Z_ENABLE_PIN 26
#define E0_ENABLE_PIN 14
- #if ENABLED(LCD_I2C_PANELOLU2)
+ #if !defined(FAN_PIN) && ENABLED(LCD_I2C_PANELOLU2)
#define FAN_PIN 4 // Uses Transistor1 (PWM) on Panelolu2's Sanguino Adapter Board to drive the fan
#endif
@@ -114,7 +114,7 @@
#endif
-#if MB(AZTEEG_X1) || MB(STB_11) || ENABLED(IS_MELZI)
+#if !defined(FAN_PIN) && (MB(AZTEEG_X1) || MB(STB_11) || ENABLED(IS_MELZI))
#define FAN_PIN 4 // Works for Panelolu2 too
#endif
@@ -239,13 +239,13 @@
#define BTN_EN2 30
#ifndef ST7920_DELAY_1
- #define ST7920_DELAY_1 DELAY_0_NOP
+ #define ST7920_DELAY_1 DELAY_NS(0)
#endif
#ifndef ST7920_DELAY_2
- #define ST7920_DELAY_2 DELAY_3_NOP
+ #define ST7920_DELAY_2 DELAY_NS(188)
#endif
#ifndef ST7920_DELAY_3
- #define ST7920_DELAY_3 DELAY_0_NOP
+ #define ST7920_DELAY_3 DELAY_NS(0)
#endif
#elif ENABLED(ZONESTAR_LCD) // For the Tronxy Melzi boards
diff --git a/Marlin/pins_SAV_MKI.h b/Marlin/pins_SAV_MKI.h
index 1241ee083f..8945594495 100644
--- a/Marlin/pins_SAV_MKI.h
+++ b/Marlin/pins_SAV_MKI.h
@@ -114,7 +114,9 @@
#define HEATER_0_PIN 15 // C5 PWM3B - Extruder
#define HEATER_BED_PIN 14 // C4 PWM3C - Bed
-#define FAN_PIN 16 // C6 PWM3A
+#ifndef FAN_PIN
+ #define FAN_PIN 16 // C6 PWM3A
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_SCOOVO_X9H.h b/Marlin/pins_SCOOVO_X9H.h
index c0852bf310..ea6685def4 100644
--- a/Marlin/pins_SCOOVO_X9H.h
+++ b/Marlin/pins_SCOOVO_X9H.h
@@ -91,7 +91,7 @@
#define E1_MS2_PIN 64
#define DIGIPOTSS_PIN 38
-#define DIGIPOT_CHANNELS {4,5,3,0,1} // X Y Z E0 E1 digipot channels to stepper driver mapping
+#define DIGIPOT_CHANNELS {4,5,3,0,1} // X Y Z E0 E1 digipot channels to stepper driver mapping
//
// Temperature Sensors
@@ -106,7 +106,9 @@
#define HEATER_1_PIN 7
#define HEATER_BED_PIN 3
-#define FAN_PIN 8
+#ifndef FAN_PIN
+ #define FAN_PIN 8
+#endif
#define FAN1_PIN 6
#define FAN2_PIN 2
diff --git a/Marlin/pins_SETHI.h b/Marlin/pins_SETHI.h
index 293373a6d7..801560e5e3 100644
--- a/Marlin/pins_SETHI.h
+++ b/Marlin/pins_SETHI.h
@@ -98,12 +98,13 @@
#define HEATER_0_PIN 4
#define HEATER_BED_PIN 3
-
-#if GEN7_VERSION >= 13
- // Gen7 v1.3 removed the fan pin
- #define FAN_PIN -1
-#else
- #define FAN_PIN 31
+#ifndef FAN_PIN
+ #if GEN7_VERSION >= 13
+ // Gen7 v1.3 removed the fan pin
+ #define FAN_PIN -1
+ #else
+ #define FAN_PIN 31
+ #endif
#endif
//
diff --git a/Marlin/pins_SILVER_GATE.h b/Marlin/pins_SILVER_GATE.h
index ca96a427c1..005c4c6eca 100644
--- a/Marlin/pins_SILVER_GATE.h
+++ b/Marlin/pins_SILVER_GATE.h
@@ -56,7 +56,9 @@
#define FIL_RUNOUT_PIN 34 // X_MAX unless overridden
#endif
-#define FAN_PIN 5
+#ifndef FAN_PIN
+ #define FAN_PIN 5
+#endif
#define HEATER_0_PIN 7
diff --git a/Marlin/pins_TEENSY2.h b/Marlin/pins_TEENSY2.h
index 16fcd46f10..736be6f73e 100644
--- a/Marlin/pins_TEENSY2.h
+++ b/Marlin/pins_TEENSY2.h
@@ -149,7 +149,9 @@
//
#define HEATER_0_PIN 15 // C5 PWM3B Extruder
#define HEATER_BED_PIN 14 // C4 PWM3C
-#define FAN_PIN 16 // C6 PWM3A Fan
+#ifndef FAN_PIN
+ #define FAN_PIN 16 // C6 PWM3A Fan
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_TEENSYLU.h b/Marlin/pins_TEENSYLU.h
index 33f78b2305..e733b98287 100755
--- a/Marlin/pins_TEENSYLU.h
+++ b/Marlin/pins_TEENSYLU.h
@@ -127,7 +127,9 @@
#define HEATER_0_PIN 15 // C5 PWM3B - Extruder
#define HEATER_BED_PIN 14 // C4 PWM3C
-#define FAN_PIN 16 // C6 PWM3A
+#ifndef FAN_PIN
+ #define FAN_PIN 16 // C6 PWM3A
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_TRIGORILLA_13.h b/Marlin/pins_TRIGORILLA_13.h
index e876da4671..0907eaf286 100644
--- a/Marlin/pins_TRIGORILLA_13.h
+++ b/Marlin/pins_TRIGORILLA_13.h
@@ -29,8 +29,9 @@
#endif
#define IS_RAMPS_EFB
-#define RAMPS_D9_PIN 44
-#define ORIG_E0_AUTO_FAN_PIN RAMPS_D9_PIN
+#define RAMPS_D9_PIN 44
+#define FAN2_PIN 9
+#define ORIG_E0_AUTO_FAN_PIN 9
#include "pins_RAMPS_13.h"
diff --git a/Marlin/pins_TRIGORILLA_14.h b/Marlin/pins_TRIGORILLA_14.h
index 3903e1dba5..70b0a930a9 100644
--- a/Marlin/pins_TRIGORILLA_14.h
+++ b/Marlin/pins_TRIGORILLA_14.h
@@ -30,11 +30,7 @@
#define IS_RAMPS_EFB
-#include "pins_RAMPS_13.h"
+#define FAN2_PIN 44
+#define ORIG_E0_AUTO_FAN_PIN 44
-#define FAN2_PIN 44
-
-#undef E1_STEP_PIN
-#undef E1_DIR_PIN
-#undef E1_ENABLE_PIN
-#undef E1_CS_PIN
+#include "pins_RAMPS.h"
diff --git a/Marlin/pins_ULTIMAIN_2.h b/Marlin/pins_ULTIMAIN_2.h
index c52b20c3e3..ea7a8325c0 100644
--- a/Marlin/pins_ULTIMAIN_2.h
+++ b/Marlin/pins_ULTIMAIN_2.h
@@ -93,7 +93,9 @@
#define HEATER_1_PIN 3
#define HEATER_BED_PIN 4
-#define FAN_PIN 7
+#ifndef FAN_PIN
+ #define FAN_PIN 7
+#endif
//
// Misc. Functions
diff --git a/Marlin/pins_ULTIMAKER.h b/Marlin/pins_ULTIMAKER.h
index 0d1a65431f..4b6488aede 100644
--- a/Marlin/pins_ULTIMAKER.h
+++ b/Marlin/pins_ULTIMAKER.h
@@ -99,7 +99,9 @@
#define HEATER_1_PIN 3
#define HEATER_BED_PIN 4
-#define FAN_PIN 7
+#ifndef FAN_PIN
+ #define FAN_PIN 7
+#endif
//
// Misc. Functions
diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp
index 6e2ecb04e5..7a73c50f6d 100644
--- a/Marlin/planner.cpp
+++ b/Marlin/planner.cpp
@@ -56,6 +56,10 @@
*
* IntersectionDistance[s1_, s2_, a_, d_] := (2 a d - s1^2 + s2^2)/(4 a)
*
+ * --
+ *
+ * The fast inverse function needed for Bézier interpolation for AVR
+ * was designed, written and tested by Eduardo José Tagle on April/2018
*/
#include "planner.h"
@@ -77,6 +81,10 @@
#include "power.h"
#endif
+// Delay for delivery of first block to the stepper ISR, if the queue contains 2 or
+// fewer movements. The delay is measured in milliseconds, and must be less than 250ms
+#define BLOCK_DELAY_FOR_1ST_MOVE 100
+
Planner planner;
// public:
@@ -85,40 +93,60 @@ Planner planner;
* A ring buffer of moves described in steps
*/
block_t Planner::block_buffer[BLOCK_BUFFER_SIZE];
-volatile uint8_t Planner::block_buffer_head, // Index of the next block to be pushed
- Planner::block_buffer_tail;
+volatile uint8_t Planner::block_buffer_head, // Index of the next block to be pushed
+ Planner::block_buffer_nonbusy, // Index of the first non-busy block
+ Planner::block_buffer_planned, // Index of the optimally planned block
+ Planner::block_buffer_tail; // Index of the busy block, if any
+uint16_t Planner::cleaning_buffer_counter; // A counter to disable queuing of blocks
+uint8_t Planner::delay_before_delivering; // This counter delays delivery of blocks when queue becomes empty to allow the opportunity of merging blocks
-float Planner::max_feedrate_mm_s[XYZE_N], // Max speeds in mm per second
- Planner::axis_steps_per_mm[XYZE_N],
- Planner::steps_to_mm[XYZE_N];
+uint32_t Planner::max_acceleration_mm_per_s2[XYZE_N], // (mm/s^2) M201 XYZE
+ Planner::max_acceleration_steps_per_s2[XYZE_N], // (steps/s^2) Derived from mm_per_s2
+ Planner::min_segment_time_us; // (µs) M205 B
+
+float Planner::max_feedrate_mm_s[XYZE_N], // (mm/s) M203 XYZE - Max speeds
+ Planner::axis_steps_per_mm[XYZE_N], // (steps) M92 XYZE - Steps per millimeter
+ Planner::steps_to_mm[XYZE_N], // (mm) Millimeters per step
+ Planner::min_feedrate_mm_s, // (mm/s) M205 S - Minimum linear feedrate
+ Planner::acceleration, // (mm/s^2) M204 S - Normal acceleration. DEFAULT ACCELERATION for all printing moves.
+ Planner::retract_acceleration, // (mm/s^2) M204 R - Retract acceleration. Filament pull-back and push-forward while standing still in the other axes
+ Planner::travel_acceleration, // (mm/s^2) M204 T - Travel acceleration. DEFAULT ACCELERATION for all NON printing moves.
+ Planner::min_travel_feedrate_mm_s; // (mm/s) M205 T - Minimum travel feedrate
+
+#if ENABLED(JUNCTION_DEVIATION)
+ float Planner::junction_deviation_mm; // (mm) M205 J
+ #if ENABLED(LIN_ADVANCE)
+ #if ENABLED(DISTINCT_E_FACTORS)
+ float Planner::max_e_jerk[EXTRUDERS]; // Calculated from junction_deviation_mm
+ #else
+ float Planner::max_e_jerk;
+ #endif
+ #endif
+#else
+ float Planner::max_jerk[XYZE]; // (mm/s^2) M205 XYZE - The largest speed change requiring no acceleration.
+#endif
+
+#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
+ bool Planner::abort_on_endstop_hit = false;
+#endif
#if ENABLED(DISTINCT_E_FACTORS)
uint8_t Planner::last_extruder = 0; // Respond to extruder change
+ #define _EINDEX (E_AXIS + active_extruder)
+#else
+ #define _EINDEX E_AXIS
#endif
int16_t Planner::flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); // Extrusion factor for each extruder
-float Planner::e_factor[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(1.0); // The flow percentage and volumetric multiplier combine to scale E movement
+float Planner::e_factor[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(1.0f); // The flow percentage and volumetric multiplier combine to scale E movement
#if DISABLED(NO_VOLUMETRICS)
float Planner::filament_size[EXTRUDERS], // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
- Planner::volumetric_area_nominal = CIRCLE_AREA((DEFAULT_NOMINAL_FILAMENT_DIA) * 0.5), // Nominal cross-sectional area
+ Planner::volumetric_area_nominal = CIRCLE_AREA(float(DEFAULT_NOMINAL_FILAMENT_DIA) * 0.5f), // Nominal cross-sectional area
Planner::volumetric_multiplier[EXTRUDERS]; // Reciprocal of cross-sectional area of filament (in mm^2). Pre-calculated to reduce computation in the planner
#endif
-uint32_t Planner::max_acceleration_steps_per_s2[XYZE_N],
- Planner::max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override by software
-
-uint32_t Planner::min_segment_time_us;
-
-// Initialized by settings.load()
-float Planner::min_feedrate_mm_s,
- Planner::acceleration, // Normal acceleration mm/s^2 DEFAULT ACCELERATION for all printing moves. M204 SXXXX
- Planner::retract_acceleration, // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
- Planner::travel_acceleration, // Travel acceleration mm/s^2 DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
- Planner::max_jerk[XYZE], // The largest speed change requiring no acceleration
- Planner::min_travel_feedrate_mm_s;
-
#if HAS_LEVELING
bool Planner::leveling_active = false; // Flag that auto bed leveling is enabled
#if ABL_PLANAR
@@ -149,7 +177,7 @@ float Planner::min_feedrate_mm_s,
#if ENABLED(AUTOTEMP)
float Planner::autotemp_max = 250,
Planner::autotemp_min = 210,
- Planner::autotemp_factor = 0.1;
+ Planner::autotemp_factor = 0.1f;
bool Planner::autotemp_enabled = false;
#endif
@@ -160,7 +188,7 @@ int32_t Planner::position[NUM_AXIS] = { 0 };
uint32_t Planner::cutoff_long;
float Planner::previous_speed[NUM_AXIS],
- Planner::previous_nominal_speed;
+ Planner::previous_nominal_speed_sqr;
#if ENABLED(DISABLE_INACTIVE_EXTRUDER)
uint8_t Planner::g_uc_extruder_last_move[EXTRUDERS] = { 0 };
@@ -197,82 +225,645 @@ void Planner::init() {
ZERO(position_float);
#endif
ZERO(previous_speed);
- previous_nominal_speed = 0.0;
+ previous_nominal_speed_sqr = 0;
#if ABL_PLANAR
bed_level_matrix.set_to_identity();
#endif
clear_block_buffer();
+ delay_before_delivering = 0;
}
+#if ENABLED(S_CURVE_ACCELERATION)
+
+ /**
+ * This routine returns 0x1000000 / d, getting the inverse as fast as possible.
+ * A fast-converging iterative Newton-Raphson method can reach full precision in
+ * just 1 iteration, and takes 211 cycles (worst case; the mean case is less, up
+ * to 30 cycles for small divisors), instead of the 500 cycles a normal division
+ * would take.
+ *
+ * Inspired by the following page:
+ * https://stackoverflow.com/questions/27801397/newton-raphson-division-with-big-integers
+ *
+ * Suppose we want to calculate floor(2 ^ k / B) where B is a positive integer
+ * Then, B must be <= 2^k, otherwise, the quotient is 0.
+ *
+ * The Newton - Raphson iteration for x = B / 2 ^ k yields:
+ * q[n + 1] = q[n] * (2 - q[n] * B / 2 ^ k)
+ *
+ * This can be rearranged to:
+ * q[n + 1] = q[n] * (2 ^ (k + 1) - q[n] * B) >> k
+ *
+ * Each iteration requires only integer multiplications and bit shifts.
+ * It doesn't necessarily converge to floor(2 ^ k / B) but in the worst case
+ * it eventually alternates between floor(2 ^ k / B) and ceil(2 ^ k / B).
+ * So it checks for this case and extracts floor(2 ^ k / B).
+ *
+ * A simple but important optimization for this approach is to truncate
+ * multiplications (i.e., calculate only the higher bits of the product) in the
+ * early iterations of the Newton - Raphson method. This is done so the results
+ * of the early iterations are far from the quotient. Then it doesn't matter if
+ * they are done inaccurately.
+ * It's important to pick a good starting value for x. Knowing how many
+ * digits the divisor has, it can be estimated:
+ *
+ * 2^k / x = 2 ^ log2(2^k / x)
+ * 2^k / x = 2 ^(log2(2^k)-log2(x))
+ * 2^k / x = 2 ^(k*log2(2)-log2(x))
+ * 2^k / x = 2 ^ (k-log2(x))
+ * 2^k / x >= 2 ^ (k-floor(log2(x)))
+ * floor(log2(x)) is simply the index of the most significant bit set.
+ *
+ * If this estimation can be improved even further the number of iterations can be
+ * reduced a lot, saving valuable execution time.
+ * The paper "Software Integer Division" by Thomas L.Rodeheffer, Microsoft
+ * Research, Silicon Valley,August 26, 2008, available at
+ * https://www.microsoft.com/en-us/research/wp-content/uploads/2008/08/tr-2008-141.pdf
+ * suggests, for its integer division algorithm, using a table to supply the first
+ * 8 bits of precision, then, due to the quadratic convergence nature of the
+ * Newton-Raphon iteration, just 2 iterations should be enough to get maximum
+ * precision of the division.
+ * By precomputing values of inverses for small denominator values, just one
+ * Newton-Raphson iteration is enough to reach full precision.
+ * This code uses the top 9 bits of the denominator as index.
+ *
+ * The AVR assembly function implements this C code using the data below:
+ *
+ * // For small divisors, it is best to directly retrieve the results
+ * if (d <= 110) return pgm_read_dword(&small_inv_tab[d]);
+ *
+ * // Compute initial estimation of 0x1000000/x -
+ * // Get most significant bit set on divider
+ * uint8_t idx = 0;
+ * uint32_t nr = d;
+ * if (!(nr & 0xFF0000)) {
+ * nr <<= 8; idx += 8;
+ * if (!(nr & 0xFF0000)) { nr <<= 8; idx += 8; }
+ * }
+ * if (!(nr & 0xF00000)) { nr <<= 4; idx += 4; }
+ * if (!(nr & 0xC00000)) { nr <<= 2; idx += 2; }
+ * if (!(nr & 0x800000)) { nr <<= 1; idx += 1; }
+ *
+ * // Isolate top 9 bits of the denominator, to be used as index into the initial estimation table
+ * uint32_t tidx = nr >> 15, // top 9 bits. bit8 is always set
+ * ie = inv_tab[tidx & 0xFF] + 256, // Get the table value. bit9 is always set
+ * x = idx <= 8 ? (ie >> (8 - idx)) : (ie << (idx - 8)); // Position the estimation at the proper place
+ *
+ * x = uint32_t((x * uint64_t(_BV(25) - x * d)) >> 24); // Refine estimation by newton-raphson. 1 iteration is enough
+ * const uint32_t r = _BV(24) - x * d; // Estimate remainder
+ * if (r >= d) x++; // Check whether to adjust result
+ * return uint32_t(x); // x holds the proper estimation
+ *
+ */
+ static uint32_t get_period_inverse(uint32_t d) {
+
+ static const uint8_t inv_tab[256] PROGMEM = {
+ 255,253,252,250,248,246,244,242,240,238,236,234,233,231,229,227,
+ 225,224,222,220,218,217,215,213,212,210,208,207,205,203,202,200,
+ 199,197,195,194,192,191,189,188,186,185,183,182,180,179,178,176,
+ 175,173,172,170,169,168,166,165,164,162,161,160,158,157,156,154,
+ 153,152,151,149,148,147,146,144,143,142,141,139,138,137,136,135,
+ 134,132,131,130,129,128,127,126,125,123,122,121,120,119,118,117,
+ 116,115,114,113,112,111,110,109,108,107,106,105,104,103,102,101,
+ 100,99,98,97,96,95,94,93,92,91,90,89,88,88,87,86,
+ 85,84,83,82,81,80,80,79,78,77,76,75,74,74,73,72,
+ 71,70,70,69,68,67,66,66,65,64,63,62,62,61,60,59,
+ 59,58,57,56,56,55,54,53,53,52,51,50,50,49,48,48,
+ 47,46,46,45,44,43,43,42,41,41,40,39,39,38,37,37,
+ 36,35,35,34,33,33,32,32,31,30,30,29,28,28,27,27,
+ 26,25,25,24,24,23,22,22,21,21,20,19,19,18,18,17,
+ 17,16,15,15,14,14,13,13,12,12,11,10,10,9,9,8,
+ 8,7,7,6,6,5,5,4,4,3,3,2,2,1,0,0
+ };
+
+ // For small denominators, it is cheaper to directly store the result.
+ // For bigger ones, just ONE Newton-Raphson iteration is enough to get
+ // maximum precision we need
+ static const uint32_t small_inv_tab[111] PROGMEM = {
+ 16777216,16777216,8388608,5592405,4194304,3355443,2796202,2396745,2097152,1864135,1677721,1525201,1398101,1290555,1198372,1118481,
+ 1048576,986895,932067,883011,838860,798915,762600,729444,699050,671088,645277,621378,599186,578524,559240,541200,
+ 524288,508400,493447,479349,466033,453438,441505,430185,419430,409200,399457,390167,381300,372827,364722,356962,
+ 349525,342392,335544,328965,322638,316551,310689,305040,299593,294337,289262,284359,279620,275036,270600,266305,
+ 262144,258111,254200,250406,246723,243148,239674,236298,233016,229824,226719,223696,220752,217885,215092,212369,
+ 209715,207126,204600,202135,199728,197379,195083,192841,190650,188508,186413,184365,182361,180400,178481,176602,
+ 174762,172960,171196,169466,167772,166111,164482,162885,161319,159783,158275,156796,155344,153919,152520
+ };
+
+ // For small divisors, it is best to directly retrieve the results
+ if (d <= 110) return pgm_read_dword(&small_inv_tab[d]);
+
+ register uint8_t r8 = d & 0xFF,
+ r9 = (d >> 8) & 0xFF,
+ r10 = (d >> 16) & 0xFF,
+ r2,r3,r4,r5,r6,r7,r11,r12,r13,r14,r15,r16,r17,r18;
+ register const uint8_t* ptab = inv_tab;
+
+ __asm__ __volatile__(
+ // %8:%7:%6 = interval
+ // r31:r30: MUST be those registers, and they must point to the inv_tab
+
+ A("clr %13") // %13 = 0
+
+ // Now we must compute
+ // result = 0xFFFFFF / d
+ // %8:%7:%6 = interval
+ // %16:%15:%14 = nr
+ // %13 = 0
+
+ // A plain division of 24x24 bits should take 388 cycles to complete. We will
+ // use Newton-Raphson for the calculation, and will strive to get way less cycles
+ // for the same result - Using C division, it takes 500cycles to complete .
+
+ A("clr %3") // idx = 0
+ A("mov %14,%6")
+ A("mov %15,%7")
+ A("mov %16,%8") // nr = interval
+ A("tst %16") // nr & 0xFF0000 == 0 ?
+ A("brne 2f") // No, skip this
+ A("mov %16,%15")
+ A("mov %15,%14") // nr <<= 8, %14 not needed
+ A("subi %3,-8") // idx += 8
+ A("tst %16") // nr & 0xFF0000 == 0 ?
+ A("brne 2f") // No, skip this
+ A("mov %16,%15") // nr <<= 8, %14 not needed
+ A("clr %15") // We clear %14
+ A("subi %3,-8") // idx += 8
+
+ // here %16 != 0 and %16:%15 contains at least 9 MSBits, or both %16:%15 are 0
+ L("2")
+ A("cpi %16,0x10") // (nr & 0xF00000) == 0 ?
+ A("brcc 3f") // No, skip this
+ A("swap %15") // Swap nibbles
+ A("swap %16") // Swap nibbles. Low nibble is 0
+ A("mov %14, %15")
+ A("andi %14,0x0F") // Isolate low nibble
+ A("andi %15,0xF0") // Keep proper nibble in %15
+ A("or %16, %14") // %16:%15 <<= 4
+ A("subi %3,-4") // idx += 4
+
+ L("3")
+ A("cpi %16,0x40") // (nr & 0xC00000) == 0 ?
+ A("brcc 4f") // No, skip this
+ A("add %15,%15")
+ A("adc %16,%16")
+ A("add %15,%15")
+ A("adc %16,%16") // %16:%15 <<= 2
+ A("subi %3,-2") // idx += 2
+
+ L("4")
+ A("cpi %16,0x80") // (nr & 0x800000) == 0 ?
+ A("brcc 5f") // No, skip this
+ A("add %15,%15")
+ A("adc %16,%16") // %16:%15 <<= 1
+ A("inc %3") // idx += 1
+
+ // Now %16:%15 contains its MSBit set to 1, or %16:%15 is == 0. We are now absolutely sure
+ // we have at least 9 MSBits available to enter the initial estimation table
+ L("5")
+ A("add %15,%15")
+ A("adc %16,%16") // %16:%15 = tidx = (nr <<= 1), we lose the top MSBit (always set to 1, %16 is the index into the inverse table)
+ A("add r30,%16") // Only use top 8 bits
+ A("adc r31,%13") // r31:r30 = inv_tab + (tidx)
+ A("lpm %14, Z") // %14 = inv_tab[tidx]
+ A("ldi %15, 1") // %15 = 1 %15:%14 = inv_tab[tidx] + 256
+
+ // We must scale the approximation to the proper place
+ A("clr %16") // %16 will always be 0 here
+ A("subi %3,8") // idx == 8 ?
+ A("breq 6f") // yes, no need to scale
+ A("brcs 7f") // If C=1, means idx < 8, result was negative!
+
+ // idx > 8, now %3 = idx - 8. We must perform a left shift. idx range:[1-8]
+ A("sbrs %3,0") // shift by 1bit position?
+ A("rjmp 8f") // No
+ A("add %14,%14")
+ A("adc %15,%15") // %15:16 <<= 1
+ L("8")
+ A("sbrs %3,1") // shift by 2bit position?
+ A("rjmp 9f") // No
+ A("add %14,%14")
+ A("adc %15,%15")
+ A("add %14,%14")
+ A("adc %15,%15") // %15:16 <<= 1
+ L("9")
+ A("sbrs %3,2") // shift by 4bits position?
+ A("rjmp 16f") // No
+ A("swap %15") // Swap nibbles. lo nibble of %15 will always be 0
+ A("swap %14") // Swap nibbles
+ A("mov %12,%14")
+ A("andi %12,0x0F") // isolate low nibble
+ A("andi %14,0xF0") // and clear it
+ A("or %15,%12") // %15:%16 <<= 4
+ L("16")
+ A("sbrs %3,3") // shift by 8bits position?
+ A("rjmp 6f") // No, we are done
+ A("mov %16,%15")
+ A("mov %15,%14")
+ A("clr %14")
+ A("jmp 6f")
+
+ // idx < 8, now %3 = idx - 8. Get the count of bits
+ L("7")
+ A("neg %3") // %3 = -idx = count of bits to move right. idx range:[1...8]
+ A("sbrs %3,0") // shift by 1 bit position ?
+ A("rjmp 10f") // No, skip it
+ A("asr %15") // (bit7 is always 0 here)
+ A("ror %14")
+ L("10")
+ A("sbrs %3,1") // shift by 2 bit position ?
+ A("rjmp 11f") // No, skip it
+ A("asr %15") // (bit7 is always 0 here)
+ A("ror %14")
+ A("asr %15") // (bit7 is always 0 here)
+ A("ror %14")
+ L("11")
+ A("sbrs %3,2") // shift by 4 bit position ?
+ A("rjmp 12f") // No, skip it
+ A("swap %15") // Swap nibbles
+ A("andi %14, 0xF0") // Lose the lowest nibble
+ A("swap %14") // Swap nibbles. Upper nibble is 0
+ A("or %14,%15") // Pass nibble from upper byte
+ A("andi %15, 0x0F") // And get rid of that nibble
+ L("12")
+ A("sbrs %3,3") // shift by 8 bit position ?
+ A("rjmp 6f") // No, skip it
+ A("mov %14,%15")
+ A("clr %15")
+ L("6") // %16:%15:%14 = initial estimation of 0x1000000 / d
+
+ // Now, we must refine the estimation present on %16:%15:%14 using 1 iteration
+ // of Newton-Raphson. As it has a quadratic convergence, 1 iteration is enough
+ // to get more than 18bits of precision (the initial table lookup gives 9 bits of
+ // precision to start from). 18bits of precision is all what is needed here for result
+
+ // %8:%7:%6 = d = interval
+ // %16:%15:%14 = x = initial estimation of 0x1000000 / d
+ // %13 = 0
+ // %3:%2:%1:%0 = working accumulator
+
+ // Compute 1<<25 - x*d. Result should never exceed 25 bits and should always be positive
+ A("clr %0")
+ A("clr %1")
+ A("clr %2")
+ A("ldi %3,2") // %3:%2:%1:%0 = 0x2000000
+ A("mul %6,%14") // r1:r0 = LO(d) * LO(x)
+ A("sub %0,r0")
+ A("sbc %1,r1")
+ A("sbc %2,%13")
+ A("sbc %3,%13") // %3:%2:%1:%0 -= LO(d) * LO(x)
+ A("mul %7,%14") // r1:r0 = MI(d) * LO(x)
+ A("sub %1,r0")
+ A("sbc %2,r1")
+ A("sbc %3,%13") // %3:%2:%1:%0 -= MI(d) * LO(x) << 8
+ A("mul %8,%14") // r1:r0 = HI(d) * LO(x)
+ A("sub %2,r0")
+ A("sbc %3,r1") // %3:%2:%1:%0 -= MIL(d) * LO(x) << 16
+ A("mul %6,%15") // r1:r0 = LO(d) * MI(x)
+ A("sub %1,r0")
+ A("sbc %2,r1")
+ A("sbc %3,%13") // %3:%2:%1:%0 -= LO(d) * MI(x) << 8
+ A("mul %7,%15") // r1:r0 = MI(d) * MI(x)
+ A("sub %2,r0")
+ A("sbc %3,r1") // %3:%2:%1:%0 -= MI(d) * MI(x) << 16
+ A("mul %8,%15") // r1:r0 = HI(d) * MI(x)
+ A("sub %3,r0") // %3:%2:%1:%0 -= MIL(d) * MI(x) << 24
+ A("mul %6,%16") // r1:r0 = LO(d) * HI(x)
+ A("sub %2,r0")
+ A("sbc %3,r1") // %3:%2:%1:%0 -= LO(d) * HI(x) << 16
+ A("mul %7,%16") // r1:r0 = MI(d) * HI(x)
+ A("sub %3,r0") // %3:%2:%1:%0 -= MI(d) * HI(x) << 24
+ // %3:%2:%1:%0 = (1<<25) - x*d [169]
+
+ // We need to multiply that result by x, and we are only interested in the top 24bits of that multiply
+
+ // %16:%15:%14 = x = initial estimation of 0x1000000 / d
+ // %3:%2:%1:%0 = (1<<25) - x*d = acc
+ // %13 = 0
+
+ // result = %11:%10:%9:%5:%4
+ A("mul %14,%0") // r1:r0 = LO(x) * LO(acc)
+ A("mov %4,r1")
+ A("clr %5")
+ A("clr %9")
+ A("clr %10")
+ A("clr %11") // %11:%10:%9:%5:%4 = LO(x) * LO(acc) >> 8
+ A("mul %15,%0") // r1:r0 = MI(x) * LO(acc)
+ A("add %4,r0")
+ A("adc %5,r1")
+ A("adc %9,%13")
+ A("adc %10,%13")
+ A("adc %11,%13") // %11:%10:%9:%5:%4 += MI(x) * LO(acc)
+ A("mul %16,%0") // r1:r0 = HI(x) * LO(acc)
+ A("add %5,r0")
+ A("adc %9,r1")
+ A("adc %10,%13")
+ A("adc %11,%13") // %11:%10:%9:%5:%4 += MI(x) * LO(acc) << 8
+
+ A("mul %14,%1") // r1:r0 = LO(x) * MIL(acc)
+ A("add %4,r0")
+ A("adc %5,r1")
+ A("adc %9,%13")
+ A("adc %10,%13")
+ A("adc %11,%13") // %11:%10:%9:%5:%4 = LO(x) * MIL(acc)
+ A("mul %15,%1") // r1:r0 = MI(x) * MIL(acc)
+ A("add %5,r0")
+ A("adc %9,r1")
+ A("adc %10,%13")
+ A("adc %11,%13") // %11:%10:%9:%5:%4 += MI(x) * MIL(acc) << 8
+ A("mul %16,%1") // r1:r0 = HI(x) * MIL(acc)
+ A("add %9,r0")
+ A("adc %10,r1")
+ A("adc %11,%13") // %11:%10:%9:%5:%4 += MI(x) * MIL(acc) << 16
+
+ A("mul %14,%2") // r1:r0 = LO(x) * MIH(acc)
+ A("add %5,r0")
+ A("adc %9,r1")
+ A("adc %10,%13")
+ A("adc %11,%13") // %11:%10:%9:%5:%4 = LO(x) * MIH(acc) << 8
+ A("mul %15,%2") // r1:r0 = MI(x) * MIH(acc)
+ A("add %9,r0")
+ A("adc %10,r1")
+ A("adc %11,%13") // %11:%10:%9:%5:%4 += MI(x) * MIH(acc) << 16
+ A("mul %16,%2") // r1:r0 = HI(x) * MIH(acc)
+ A("add %10,r0")
+ A("adc %11,r1") // %11:%10:%9:%5:%4 += MI(x) * MIH(acc) << 24
+
+ A("mul %14,%3") // r1:r0 = LO(x) * HI(acc)
+ A("add %9,r0")
+ A("adc %10,r1")
+ A("adc %11,%13") // %11:%10:%9:%5:%4 = LO(x) * HI(acc) << 16
+ A("mul %15,%3") // r1:r0 = MI(x) * HI(acc)
+ A("add %10,r0")
+ A("adc %11,r1") // %11:%10:%9:%5:%4 += MI(x) * HI(acc) << 24
+ A("mul %16,%3") // r1:r0 = HI(x) * HI(acc)
+ A("add %11,r0") // %11:%10:%9:%5:%4 += MI(x) * HI(acc) << 32
+
+ // At this point, %11:%10:%9 contains the new estimation of x.
+
+ // Finally, we must correct the result. Estimate remainder as
+ // (1<<24) - x*d
+ // %11:%10:%9 = x
+ // %8:%7:%6 = d = interval" "\n\t"
+ A("ldi %3,1")
+ A("clr %2")
+ A("clr %1")
+ A("clr %0") // %3:%2:%1:%0 = 0x1000000
+ A("mul %6,%9") // r1:r0 = LO(d) * LO(x)
+ A("sub %0,r0")
+ A("sbc %1,r1")
+ A("sbc %2,%13")
+ A("sbc %3,%13") // %3:%2:%1:%0 -= LO(d) * LO(x)
+ A("mul %7,%9") // r1:r0 = MI(d) * LO(x)
+ A("sub %1,r0")
+ A("sbc %2,r1")
+ A("sbc %3,%13") // %3:%2:%1:%0 -= MI(d) * LO(x) << 8
+ A("mul %8,%9") // r1:r0 = HI(d) * LO(x)
+ A("sub %2,r0")
+ A("sbc %3,r1") // %3:%2:%1:%0 -= MIL(d) * LO(x) << 16
+ A("mul %6,%10") // r1:r0 = LO(d) * MI(x)
+ A("sub %1,r0")
+ A("sbc %2,r1")
+ A("sbc %3,%13") // %3:%2:%1:%0 -= LO(d) * MI(x) << 8
+ A("mul %7,%10") // r1:r0 = MI(d) * MI(x)
+ A("sub %2,r0")
+ A("sbc %3,r1") // %3:%2:%1:%0 -= MI(d) * MI(x) << 16
+ A("mul %8,%10") // r1:r0 = HI(d) * MI(x)
+ A("sub %3,r0") // %3:%2:%1:%0 -= MIL(d) * MI(x) << 24
+ A("mul %6,%11") // r1:r0 = LO(d) * HI(x)
+ A("sub %2,r0")
+ A("sbc %3,r1") // %3:%2:%1:%0 -= LO(d) * HI(x) << 16
+ A("mul %7,%11") // r1:r0 = MI(d) * HI(x)
+ A("sub %3,r0") // %3:%2:%1:%0 -= MI(d) * HI(x) << 24
+ // %3:%2:%1:%0 = r = (1<<24) - x*d
+ // %8:%7:%6 = d = interval
+
+ // Perform the final correction
+ A("sub %0,%6")
+ A("sbc %1,%7")
+ A("sbc %2,%8") // r -= d
+ A("brcs 14f") // if ( r >= d)
+
+ // %11:%10:%9 = x
+ A("ldi %3,1")
+ A("add %9,%3")
+ A("adc %10,%13")
+ A("adc %11,%13") // x++
+ L("14")
+
+ // Estimation is done. %11:%10:%9 = x
+ A("clr __zero_reg__") // Make C runtime happy
+ // [211 cycles total]
+ : "=r" (r2),
+ "=r" (r3),
+ "=r" (r4),
+ "=d" (r5),
+ "=r" (r6),
+ "=r" (r7),
+ "+r" (r8),
+ "+r" (r9),
+ "+r" (r10),
+ "=d" (r11),
+ "=r" (r12),
+ "=r" (r13),
+ "=d" (r14),
+ "=d" (r15),
+ "=d" (r16),
+ "=d" (r17),
+ "=d" (r18),
+ "+z" (ptab)
+ :
+ : "r0", "r1", "cc"
+ );
+
+ // Return the result
+ return r11 | (uint16_t(r12) << 8) | (uint32_t(r13) << 16);
+ }
+
+#endif // S_CURVE_ACCELERATION
+
#define MINIMAL_STEP_RATE 120
/**
* Calculate trapezoid parameters, multiplying the entry- and exit-speeds
* by the provided factors.
+ **
+ * ############ VERY IMPORTANT ############
+ * NOTE that the PRECONDITION to call this function is that the block is
+ * NOT BUSY and it is marked as RECALCULATE. That WARRANTIES the Stepper ISR
+ * is not and will not use the block while we modify it, so it is safe to
+ * alter its values.
*/
void Planner::calculate_trapezoid_for_block(block_t* const block, const float &entry_factor, const float &exit_factor) {
+
uint32_t initial_rate = CEIL(block->nominal_rate * entry_factor),
final_rate = CEIL(block->nominal_rate * exit_factor); // (steps per second)
// Limit minimal step rate (Otherwise the timer will overflow.)
- NOLESS(initial_rate, MINIMAL_STEP_RATE);
- NOLESS(final_rate, MINIMAL_STEP_RATE);
+ NOLESS(initial_rate, uint32_t(MINIMAL_STEP_RATE));
+ NOLESS(final_rate, uint32_t(MINIMAL_STEP_RATE));
+
+ #if ENABLED(S_CURVE_ACCELERATION)
+ uint32_t cruise_rate = initial_rate;
+ #endif
const int32_t accel = block->acceleration_steps_per_s2;
// Steps required for acceleration, deceleration to/from nominal rate
- int32_t accelerate_steps = CEIL(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)),
- decelerate_steps = FLOOR(estimate_acceleration_distance(block->nominal_rate, final_rate, -accel)),
+ uint32_t accelerate_steps = CEIL(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)),
+ decelerate_steps = FLOOR(estimate_acceleration_distance(block->nominal_rate, final_rate, -accel));
// Steps between acceleration and deceleration, if any
- plateau_steps = block->step_event_count - accelerate_steps - decelerate_steps;
+ int32_t plateau_steps = block->step_event_count - accelerate_steps - decelerate_steps;
// Does accelerate_steps + decelerate_steps exceed step_event_count?
// Then we can't possibly reach the nominal rate, there will be no cruising.
// Use intersection_distance() to calculate accel / braking time in order to
// reach the final_rate exactly at the end of this block.
if (plateau_steps < 0) {
- accelerate_steps = CEIL(intersection_distance(initial_rate, final_rate, accel, block->step_event_count));
- NOLESS(accelerate_steps, 0); // Check limits due to numerical round-off
- accelerate_steps = min((uint32_t)accelerate_steps, block->step_event_count);//(We can cast here to unsigned, because the above line ensures that we are above zero)
+ const float accelerate_steps_float = CEIL(intersection_distance(initial_rate, final_rate, accel, block->step_event_count));
+ accelerate_steps = MIN(uint32_t(MAX(accelerate_steps_float, 0)), block->step_event_count);
plateau_steps = 0;
- }
- // block->accelerate_until = accelerate_steps;
- // block->decelerate_after = accelerate_steps+plateau_steps;
-
- CRITICAL_SECTION_START; // Fill variables used by the stepper in a critical section
- if (!TEST(block->flag, BLOCK_BIT_BUSY)) { // Don't update variables if block is busy.
- block->accelerate_until = accelerate_steps;
- block->decelerate_after = accelerate_steps + plateau_steps;
- block->initial_rate = initial_rate;
- block->final_rate = final_rate;
+ #if ENABLED(S_CURVE_ACCELERATION)
+ // We won't reach the cruising rate. Let's calculate the speed we will reach
+ cruise_rate = final_speed(initial_rate, accel, accelerate_steps);
+ #endif
}
- CRITICAL_SECTION_END;
+ #if ENABLED(S_CURVE_ACCELERATION)
+ else // We have some plateau time, so the cruise rate will be the nominal rate
+ cruise_rate = block->nominal_rate;
+ #endif
+
+ #if ENABLED(S_CURVE_ACCELERATION)
+ // Jerk controlled speed requires to express speed versus time, NOT steps
+ uint32_t acceleration_time = ((float)(cruise_rate - initial_rate) / accel) * (STEPPER_TIMER_RATE),
+ deceleration_time = ((float)(cruise_rate - final_rate) / accel) * (STEPPER_TIMER_RATE);
+
+ // And to offload calculations from the ISR, we also calculate the inverse of those times here
+ uint32_t acceleration_time_inverse = get_period_inverse(acceleration_time);
+ uint32_t deceleration_time_inverse = get_period_inverse(deceleration_time);
+ #endif
+
+ // Store new block parameters
+ block->accelerate_until = accelerate_steps;
+ block->decelerate_after = accelerate_steps + plateau_steps;
+ block->initial_rate = initial_rate;
+ #if ENABLED(S_CURVE_ACCELERATION)
+ block->acceleration_time = acceleration_time;
+ block->deceleration_time = deceleration_time;
+ block->acceleration_time_inverse = acceleration_time_inverse;
+ block->deceleration_time_inverse = deceleration_time_inverse;
+ block->cruise_rate = cruise_rate;
+ #endif
+ block->final_rate = final_rate;
}
-// "Junction jerk" in this context is the immediate change in speed at the junction of two blocks.
-// This method will calculate the junction jerk as the euclidean distance between the nominal
-// velocities of the respective blocks.
-//inline float junction_jerk(block_t *before, block_t *after) {
-// return SQRT(
-// POW((before->speed_x-after->speed_x), 2)+POW((before->speed_y-after->speed_y), 2));
-//}
+/* PLANNER SPEED DEFINITION
+ +--------+ <- current->nominal_speed
+ / \
+ current->entry_speed -> + \
+ | + <- next->entry_speed (aka exit speed)
+ +-------------+
+ time -->
+ Recalculates the motion plan according to the following basic guidelines:
+
+ 1. Go over every feasible block sequentially in reverse order and calculate the junction speeds
+ (i.e. current->entry_speed) such that:
+ a. No junction speed exceeds the pre-computed maximum junction speed limit or nominal speeds of
+ neighboring blocks.
+ b. A block entry speed cannot exceed one reverse-computed from its exit speed (next->entry_speed)
+ with a maximum allowable deceleration over the block travel distance.
+ c. The last (or newest appended) block is planned from a complete stop (an exit speed of zero).
+ 2. Go over every block in chronological (forward) order and dial down junction speed values if
+ a. The exit speed exceeds the one forward-computed from its entry speed with the maximum allowable
+ acceleration over the block travel distance.
+
+ When these stages are complete, the planner will have maximized the velocity profiles throughout the all
+ of the planner blocks, where every block is operating at its maximum allowable acceleration limits. In
+ other words, for all of the blocks in the planner, the plan is optimal and no further speed improvements
+ are possible. If a new block is added to the buffer, the plan is recomputed according to the said
+ guidelines for a new optimal plan.
+
+ To increase computational efficiency of these guidelines, a set of planner block pointers have been
+ created to indicate stop-compute points for when the planner guidelines cannot logically make any further
+ changes or improvements to the plan when in normal operation and new blocks are streamed and added to the
+ planner buffer. For example, if a subset of sequential blocks in the planner have been planned and are
+ bracketed by junction velocities at their maximums (or by the first planner block as well), no new block
+ added to the planner buffer will alter the velocity profiles within them. So we no longer have to compute
+ them. Or, if a set of sequential blocks from the first block in the planner (or a optimal stop-compute
+ point) are all accelerating, they are all optimal and can not be altered by a new block added to the
+ planner buffer, as this will only further increase the plan speed to chronological blocks until a maximum
+ junction velocity is reached. However, if the operational conditions of the plan changes from infrequently
+ used feed holds or feedrate overrides, the stop-compute pointers will be reset and the entire plan is
+ recomputed as stated in the general guidelines.
+
+ Planner buffer index mapping:
+ - block_buffer_tail: Points to the beginning of the planner buffer. First to be executed or being executed.
+ - block_buffer_head: Points to the buffer block after the last block in the buffer. Used to indicate whether
+ the buffer is full or empty. As described for standard ring buffers, this block is always empty.
+ - block_buffer_planned: Points to the first buffer block after the last optimally planned block for normal
+ streaming operating conditions. Use for planning optimizations by avoiding recomputing parts of the
+ planner buffer that don't change with the addition of a new block, as describe above. In addition,
+ this block can never be less than block_buffer_tail and will always be pushed forward and maintain
+ this requirement when encountered by the Planner::discard_current_block() routine during a cycle.
+
+ NOTE: Since the planner only computes on what's in the planner buffer, some motions with lots of short
+ line segments, like G2/3 arcs or complex curves, may seem to move slow. This is because there simply isn't
+ enough combined distance traveled in the entire buffer to accelerate up to the nominal speed and then
+ decelerate to a complete stop at the end of the buffer, as stated by the guidelines. If this happens and
+ becomes an annoyance, there are a few simple solutions: (1) Maximize the machine acceleration. The planner
+ will be able to compute higher velocity profiles within the same combined distance. (2) Maximize line
+ motion(s) distance per block to a desired tolerance. The more combined distance the planner has to use,
+ the faster it can go. (3) Maximize the planner buffer size. This also will increase the combined distance
+ for the planner to compute over. It also increases the number of computations the planner has to perform
+ to compute an optimal plan, so select carefully.
+*/
// The kernel called by recalculate() when scanning the plan from last to first entry.
void Planner::reverse_pass_kernel(block_t* const current, const block_t * const next) {
- if (!current || !next) return;
- // If entry speed is already at the maximum entry speed, no need to recheck. Block is cruising.
- // If not, block in state of acceleration or deceleration. Reset entry speed to maximum and
- // check for maximum allowable speed reductions to ensure maximum possible planned speed.
- float max_entry_speed = current->max_entry_speed;
- if (current->entry_speed != max_entry_speed) {
- // If nominal length true, max junction speed is guaranteed to be reached. Only compute
- // for max allowable speed if block is decelerating and nominal length is false.
- current->entry_speed = (TEST(current->flag, BLOCK_BIT_NOMINAL_LENGTH) || max_entry_speed <= next->entry_speed)
- ? max_entry_speed
- : min(max_entry_speed, max_allowable_speed(-current->acceleration, next->entry_speed, current->millimeters));
- SBI(current->flag, BLOCK_BIT_RECALCULATE);
+ if (current) {
+ // If entry speed is already at the maximum entry speed, and there was no change of speed
+ // in the next block, there is no need to recheck. Block is cruising and there is no need to
+ // compute anything for this block,
+ // If not, block entry speed needs to be recalculated to ensure maximum possible planned speed.
+ const float max_entry_speed_sqr = current->max_entry_speed_sqr;
+
+ // Compute maximum entry speed decelerating over the current block from its exit speed.
+ // If not at the maximum entry speed, or the previous block entry speed changed
+ if (current->entry_speed_sqr != max_entry_speed_sqr || (next && TEST(next->flag, BLOCK_BIT_RECALCULATE))) {
+
+ // If nominal length true, max junction speed is guaranteed to be reached.
+ // If a block can de/ac-celerate from nominal speed to zero within the length of the block, then
+ // the current block and next block junction speeds are guaranteed to always be at their maximum
+ // junction speeds in deceleration and acceleration, respectively. This is due to how the current
+ // block nominal speed limits both the current and next maximum junction speeds. Hence, in both
+ // the reverse and forward planners, the corresponding block junction speed will always be at the
+ // the maximum junction speed and may always be ignored for any speed reduction checks.
+
+ const float new_entry_speed_sqr = TEST(current->flag, BLOCK_BIT_NOMINAL_LENGTH)
+ ? max_entry_speed_sqr
+ : MIN(max_entry_speed_sqr, max_allowable_speed_sqr(-current->acceleration, next ? next->entry_speed_sqr : sq(float(MINIMUM_PLANNER_SPEED)), current->millimeters));
+ if (current->entry_speed_sqr != new_entry_speed_sqr) {
+
+ // Need to recalculate the block speed - Mark it now, so the stepper
+ // ISR does not consume the block before being recalculated
+ SBI(current->flag, BLOCK_BIT_RECALCULATE);
+
+ // But there is an inherent race condition here, as the block may have
+ // become BUSY just before being marked RECALCULATE, so check for that!
+ if (stepper.is_block_busy(current)) {
+ // Block became busy. Clear the RECALCULATE flag (no point in
+ // recalculating BUSY blocks). And don't set its speed, as it can't
+ // be updated at this time.
+ CBI(current->flag, BLOCK_BIT_RECALCULATE);
+ }
+ else {
+ // Block is not BUSY so this is ahead of the Stepper ISR:
+ // Just Set the new entry speed.
+ current->entry_speed_sqr = new_entry_speed_sqr;
+ }
+ }
+ }
}
}
@@ -281,49 +872,97 @@ void Planner::reverse_pass_kernel(block_t* const current, const block_t * const
* Once in reverse and once forward. This implements the reverse pass.
*/
void Planner::reverse_pass() {
- if (movesplanned() > 2) {
- const uint8_t endnr = BLOCK_MOD(block_buffer_tail + 1); // tail is running. tail+1 shouldn't be altered because it's connected to the running block.
- uint8_t blocknr = prev_block_index(block_buffer_head);
- block_t* current = &block_buffer[blocknr];
+ // Initialize block index to the last block in the planner buffer.
+ uint8_t block_index = prev_block_index(block_buffer_head);
- // Last/newest block in buffer:
- const float max_entry_speed = current->max_entry_speed;
- if (current->entry_speed != max_entry_speed) {
- // If nominal length true, max junction speed is guaranteed to be reached. Only compute
- // for max allowable speed if block is decelerating and nominal length is false.
- current->entry_speed = TEST(current->flag, BLOCK_BIT_NOMINAL_LENGTH)
- ? max_entry_speed
- : min(max_entry_speed, max_allowable_speed(-current->acceleration, MINIMUM_PLANNER_SPEED, current->millimeters));
- SBI(current->flag, BLOCK_BIT_RECALCULATE);
+ // Read the index of the last buffer planned block.
+ // The ISR may change it so get a stable local copy.
+ uint8_t planned_block_index = block_buffer_planned;
+
+ // If there was a race condition and block_buffer_planned was incremented
+ // or was pointing at the head (queue empty) break loop now and avoid
+ // planning already consumed blocks
+ if (planned_block_index == block_buffer_head) return;
+
+ // Reverse Pass: Coarsely maximize all possible deceleration curves back-planning from the last
+ // block in buffer. Cease planning when the last optimal planned or tail pointer is reached.
+ // NOTE: Forward pass will later refine and correct the reverse pass to create an optimal plan.
+ const block_t *next = NULL;
+ while (block_index != planned_block_index) {
+
+ // Perform the reverse pass
+ block_t *current = &block_buffer[block_index];
+
+ // Only consider non sync blocks
+ if (!TEST(current->flag, BLOCK_BIT_SYNC_POSITION)) {
+ reverse_pass_kernel(current, next);
+ next = current;
}
- do {
- const block_t * const next = current;
- blocknr = prev_block_index(blocknr);
- current = &block_buffer[blocknr];
- reverse_pass_kernel(current, next);
- } while (blocknr != endnr);
+ // Advance to the next
+ block_index = prev_block_index(block_index);
+
+ // The ISR could advance the block_buffer_planned while we were doing the reverse pass.
+ // We must try to avoid using an already consumed block as the last one - So follow
+ // changes to the pointer and make sure to limit the loop to the currently busy block
+ while (planned_block_index != block_buffer_planned) {
+
+ // If we reached the busy block or an already processed block, break the loop now
+ if (block_index == planned_block_index) return;
+
+ // Advance the pointer, following the busy block
+ planned_block_index = next_block_index(planned_block_index);
+ }
}
}
// The kernel called by recalculate() when scanning the plan from first to last entry.
-void Planner::forward_pass_kernel(const block_t * const previous, block_t* const current) {
- if (!previous) return;
+void Planner::forward_pass_kernel(const block_t* const previous, block_t* const current, const uint8_t block_index) {
+ if (previous) {
+ // If the previous block is an acceleration block, too short to complete the full speed
+ // change, adjust the entry speed accordingly. Entry speeds have already been reset,
+ // maximized, and reverse-planned. If nominal length is set, max junction speed is
+ // guaranteed to be reached. No need to recheck.
+ if (!TEST(previous->flag, BLOCK_BIT_NOMINAL_LENGTH) &&
+ previous->entry_speed_sqr < current->entry_speed_sqr) {
- // If the previous block is an acceleration block, but it is not long enough to complete the
- // full speed change within the block, we need to adjust the entry speed accordingly. Entry
- // speeds have already been reset, maximized, and reverse planned by reverse planner.
- // If nominal length is true, max junction speed is guaranteed to be reached. No need to recheck.
- if (!TEST(previous->flag, BLOCK_BIT_NOMINAL_LENGTH)) {
- if (previous->entry_speed < current->entry_speed) {
- float entry_speed = min(current->entry_speed,
- max_allowable_speed(-previous->acceleration, previous->entry_speed, previous->millimeters));
- // Check for junction speed change
- if (current->entry_speed != entry_speed) {
- current->entry_speed = entry_speed;
+ // Compute the maximum allowable speed
+ const float new_entry_speed_sqr = max_allowable_speed_sqr(-previous->acceleration, previous->entry_speed_sqr, previous->millimeters);
+
+ // If true, current block is full-acceleration and we can move the planned pointer forward.
+ if (new_entry_speed_sqr < current->entry_speed_sqr) {
+
+ // Mark we need to recompute the trapezoidal shape, and do it now,
+ // so the stepper ISR does not consume the block before being recalculated
SBI(current->flag, BLOCK_BIT_RECALCULATE);
+
+ // But there is an inherent race condition here, as the block maybe
+ // became BUSY, just before it was marked as RECALCULATE, so check
+ // if that is the case!
+ if (stepper.is_block_busy(current)) {
+ // Block became busy. Clear the RECALCULATE flag (no point in
+ // recalculating BUSY blocks and don't set its speed, as it can't
+ // be updated at this time.
+ CBI(current->flag, BLOCK_BIT_RECALCULATE);
+ }
+ else {
+ // Block is not BUSY, we won the race against the Stepper ISR:
+
+ // Always <= max_entry_speed_sqr. Backward pass sets this.
+ current->entry_speed_sqr = new_entry_speed_sqr; // Always <= max_entry_speed_sqr. Backward pass sets this.
+
+ // Set optimal plan pointer.
+ block_buffer_planned = block_index;
+ }
}
}
+
+ // Any block set at its maximum entry speed also creates an optimal plan up to this
+ // point in the buffer. When the plan is bracketed by either the beginning of the
+ // buffer and a maximum entry speed or two maximum entry speeds, every block in between
+ // cannot logically be further improved. Hence, we don't have to recompute them anymore.
+ if (current->entry_speed_sqr == current->max_entry_speed_sqr)
+ block_buffer_planned = block_index;
}
}
@@ -332,15 +971,37 @@ void Planner::forward_pass_kernel(const block_t * const previous, block_t* const
* Once in reverse and once forward. This implements the forward pass.
*/
void Planner::forward_pass() {
- block_t* block[3] = { NULL, NULL, NULL };
- for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
- block[0] = block[1];
- block[1] = block[2];
- block[2] = &block_buffer[b];
- forward_pass_kernel(block[0], block[1]);
+ // Forward Pass: Forward plan the acceleration curve from the planned pointer onward.
+ // Also scans for optimal plan breakpoints and appropriately updates the planned pointer.
+
+ // Begin at buffer planned pointer. Note that block_buffer_planned can be modified
+ // by the stepper ISR, so read it ONCE. It it guaranteed that block_buffer_planned
+ // will never lead head, so the loop is safe to execute. Also note that the forward
+ // pass will never modify the values at the tail.
+ uint8_t block_index = block_buffer_planned;
+
+ block_t *current;
+ const block_t * previous = NULL;
+ while (block_index != block_buffer_head) {
+
+ // Perform the forward pass
+ current = &block_buffer[block_index];
+
+ // Skip SYNC blocks
+ if (!TEST(current->flag, BLOCK_BIT_SYNC_POSITION)) {
+ // If there's no previous block or the previous block is not
+ // BUSY (thus, modifiable) run the forward_pass_kernel. Otherwise,
+ // the previous block became BUSY, so assume the current block's
+ // entry speed can't be altered (since that would also require
+ // updating the exit speed of the previous block).
+ if (!previous || !stepper.is_block_busy(previous))
+ forward_pass_kernel(previous, current, block_index);
+ previous = current;
+ }
+ // Advance to the previous
+ block_index = next_block_index(block_index);
}
- forward_pass_kernel(block[1], block[2]);
}
/**
@@ -349,72 +1010,119 @@ void Planner::forward_pass() {
* recalculate() after updating the blocks.
*/
void Planner::recalculate_trapezoids() {
- int8_t block_index = block_buffer_tail;
- block_t *current, *next = NULL;
+ // The tail may be changed by the ISR so get a local copy.
+ uint8_t block_index = block_buffer_tail,
+ head_block_index = block_buffer_head;
+ // Since there could be a sync block in the head of the queue, and the
+ // next loop must not recalculate the head block (as it needs to be
+ // specially handled), scan backwards to the first non-SYNC block.
+ while (head_block_index != block_index) {
+
+ // Go back (head always point to the first free block)
+ const uint8_t prev_index = prev_block_index(head_block_index);
+
+ // Get the pointer to the block
+ block_t *prev = &block_buffer[prev_index];
+
+ // If not dealing with a sync block, we are done. The last block is not a SYNC block
+ if (!TEST(prev->flag, BLOCK_BIT_SYNC_POSITION)) break;
+
+ // Examine the previous block. This and all following are SYNC blocks
+ head_block_index = prev_index;
+ }
+
+ // Go from the tail (currently executed block) to the first block, without including it)
+ block_t *current = NULL, *next = NULL;
+ float current_entry_speed = 0.0, next_entry_speed = 0.0;
+ while (block_index != head_block_index) {
- while (block_index != block_buffer_head) {
- current = next;
next = &block_buffer[block_index];
- if (current) {
- // Recalculate if current block entry or exit junction speed has changed.
- if (TEST(current->flag, BLOCK_BIT_RECALCULATE) || TEST(next->flag, BLOCK_BIT_RECALCULATE)) {
- // NOTE: Entry and exit factors always > 0 by all previous logic operations.
- const float nomr = 1.0 / current->nominal_speed;
- calculate_trapezoid_for_block(current, current->entry_speed * nomr, next->entry_speed * nomr);
- #if ENABLED(LIN_ADVANCE)
- if (current->use_advance_lead) {
- const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_mm[E_AXIS];
- current->max_adv_steps = current->nominal_speed * comp;
- current->final_adv_steps = next->entry_speed * comp;
+
+ // Skip sync blocks
+ if (!TEST(next->flag, BLOCK_BIT_SYNC_POSITION)) {
+ next_entry_speed = SQRT(next->entry_speed_sqr);
+
+ if (current) {
+ // Recalculate if current block entry or exit junction speed has changed.
+ if (TEST(current->flag, BLOCK_BIT_RECALCULATE) || TEST(next->flag, BLOCK_BIT_RECALCULATE)) {
+
+ // Mark the current block as RECALCULATE, to protect it from the Stepper ISR running it.
+ // Note that due to the above condition, there's a chance the current block isn't marked as
+ // RECALCULATE yet, but the next one is. That's the reason for the following line.
+ SBI(current->flag, BLOCK_BIT_RECALCULATE);
+
+ // But there is an inherent race condition here, as the block maybe
+ // became BUSY, just before it was marked as RECALCULATE, so check
+ // if that is the case!
+ if (!stepper.is_block_busy(current)) {
+ // Block is not BUSY, we won the race against the Stepper ISR:
+
+ // NOTE: Entry and exit factors always > 0 by all previous logic operations.
+ const float current_nominal_speed = SQRT(current->nominal_speed_sqr),
+ nomr = 1.0f / current_nominal_speed;
+ calculate_trapezoid_for_block(current, current_entry_speed * nomr, next_entry_speed * nomr);
+ #if ENABLED(LIN_ADVANCE)
+ if (current->use_advance_lead) {
+ const float comp = current->e_D_ratio * extruder_advance_K * axis_steps_per_mm[E_AXIS];
+ current->max_adv_steps = current_nominal_speed * comp;
+ current->final_adv_steps = next_entry_speed * comp;
+ }
+ #endif
}
- #endif
- CBI(current->flag, BLOCK_BIT_RECALCULATE); // Reset current only to ensure next trapezoid is computed
+
+ // Reset current only to ensure next trapezoid is computed - The
+ // stepper is free to use the block from now on.
+ CBI(current->flag, BLOCK_BIT_RECALCULATE);
+ }
}
+
+ current = next;
+ current_entry_speed = next_entry_speed;
}
+
block_index = next_block_index(block_index);
}
+
// Last/newest block in buffer. Exit speed is set with MINIMUM_PLANNER_SPEED. Always recalculated.
if (next) {
- const float nomr = 1.0 / next->nominal_speed;
- calculate_trapezoid_for_block(next, next->entry_speed * nomr, (MINIMUM_PLANNER_SPEED) * nomr);
- #if ENABLED(LIN_ADVANCE)
- if (next->use_advance_lead) {
- const float comp = next->e_D_ratio * extruder_advance_K * axis_steps_per_mm[E_AXIS];
- next->max_adv_steps = next->nominal_speed * comp;
- next->final_adv_steps = (MINIMUM_PLANNER_SPEED) * comp;
- }
- #endif
+
+ // Mark the next(last) block as RECALCULATE, to prevent the Stepper ISR running it.
+ // As the last block is always recalculated here, there is a chance the block isn't
+ // marked as RECALCULATE yet. That's the reason for the following line.
+ SBI(next->flag, BLOCK_BIT_RECALCULATE);
+
+ // But there is an inherent race condition here, as the block maybe
+ // became BUSY, just before it was marked as RECALCULATE, so check
+ // if that is the case!
+ if (!stepper.is_block_busy(current)) {
+ // Block is not BUSY, we won the race against the Stepper ISR:
+
+ const float next_nominal_speed = SQRT(next->nominal_speed_sqr),
+ nomr = 1.0f / next_nominal_speed;
+ calculate_trapezoid_for_block(next, next_entry_speed * nomr, float(MINIMUM_PLANNER_SPEED) * nomr);
+ #if ENABLED(LIN_ADVANCE)
+ if (next->use_advance_lead) {
+ const float comp = next->e_D_ratio * extruder_advance_K * axis_steps_per_mm[E_AXIS];
+ next->max_adv_steps = next_nominal_speed * comp;
+ next->final_adv_steps = (MINIMUM_PLANNER_SPEED) * comp;
+ }
+ #endif
+ }
+
+ // Reset next only to ensure its trapezoid is computed - The stepper is free to use
+ // the block from now on.
CBI(next->flag, BLOCK_BIT_RECALCULATE);
}
}
-/**
- * Recalculate the motion plan according to the following algorithm:
- *
- * 1. Go over every block in reverse order...
- *
- * Calculate a junction speed reduction (block_t.entry_factor) so:
- *
- * a. The junction jerk is within the set limit, and
- *
- * b. No speed reduction within one block requires faster
- * deceleration than the one, true constant acceleration.
- *
- * 2. Go over every block in chronological order...
- *
- * Dial down junction speed reduction values if:
- * a. The speed increase within one block would require faster
- * acceleration than the one, true constant acceleration.
- *
- * After that, all blocks will have an entry_factor allowing all speed changes to
- * be performed using only the one, true constant acceleration, and where no junction
- * jerk is jerkier than the set limit, Jerky. Finally it will:
- *
- * 3. Recalculate "trapezoids" for all blocks.
- */
void Planner::recalculate() {
- reverse_pass();
- forward_pass();
+ // Initialize block index to the last block in the planner buffer.
+ const uint8_t block_index = prev_block_index(block_buffer_head);
+ // If there is just one block, no planning can be done. Avoid it!
+ if (block_index != block_buffer_planned) {
+ reverse_pass();
+ forward_pass();
+ }
recalculate_trapezoids();
}
@@ -430,14 +1138,14 @@ void Planner::recalculate() {
for (uint8_t b = block_buffer_tail; b != block_buffer_head; b = next_block_index(b)) {
block_t* block = &block_buffer[b];
if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS]) {
- float se = (float)block->steps[E_AXIS] / block->step_event_count * block->nominal_speed; // mm/sec;
+ const float se = (float)block->steps[E_AXIS] / block->step_event_count * SQRT(block->nominal_speed_sqr); // mm/sec;
NOLESS(high, se);
}
}
float t = autotemp_min + high * autotemp_factor;
t = constrain(t, autotemp_min, autotemp_max);
- if (t < oldt) t = t * (1 - (AUTOTEMP_OLDWEIGHT)) + oldt * (AUTOTEMP_OLDWEIGHT);
+ if (t < oldt) t = t * (1 - float(AUTOTEMP_OLDWEIGHT)) + oldt * float(AUTOTEMP_OLDWEIGHT);
oldt = t;
thermalManager.setTargetHotend(t, 0);
}
@@ -540,8 +1248,8 @@ void Planner::check_axes_activity() {
#endif // FAN_KICKSTART_TIME > 0
- #ifdef FAN_MIN_PWM
- #define CALC_FAN_SPEED(f) (tail_fan_speed[f] ? ( FAN_MIN_PWM + (tail_fan_speed[f] * (255 - FAN_MIN_PWM)) / 255 ) : 0)
+ #if FAN_MIN_PWM != 0 || FAN_MAX_PWM != 255
+ #define CALC_FAN_SPEED(f) (tail_fan_speed[f] ? map(tail_fan_speed[f], 1, 255, FAN_MIN_PWM, FAN_MAX_PWM) : 0)
#else
#define CALC_FAN_SPEED(f) tail_fan_speed[f]
#endif
@@ -592,7 +1300,7 @@ void Planner::check_axes_activity() {
* Return 1.0 with volumetric off or a diameter of 0.0.
*/
inline float calculate_volumetric_multiplier(const float &diameter) {
- return (parser.volumetric_enabled && diameter) ? 1.0 / CIRCLE_AREA(diameter * 0.5) : 1.0;
+ return (parser.volumetric_enabled && diameter) ? 1.0f / CIRCLE_AREA(diameter * 0.5) : 1.0;
}
/**
@@ -616,18 +1324,18 @@ void Planner::check_axes_activity() {
*/
void Planner::calculate_volumetric_for_width_sensor(const int8_t encoded_ratio) {
// Reconstitute the nominal/measured ratio
- const float nom_meas_ratio = 1.0 + 0.01 * encoded_ratio,
+ const float nom_meas_ratio = 1 + 0.01f * encoded_ratio,
ratio_2 = sq(nom_meas_ratio);
volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = parser.volumetric_enabled
- ? ratio_2 / CIRCLE_AREA(filament_width_nominal * 0.5) // Volumetric uses a true volumetric multiplier
- : ratio_2; // Linear squares the ratio, which scales the volume
+ ? ratio_2 / CIRCLE_AREA(filament_width_nominal * 0.5f) // Volumetric uses a true volumetric multiplier
+ : ratio_2; // Linear squares the ratio, which scales the volume
refresh_e_factor(FILAMENT_SENSOR_EXTRUDER_NUM);
}
#endif
-#if PLANNER_LEVELING
+#if PLANNER_LEVELING || HAS_UBL_AND_CURVES
/**
* rx, ry, rz - Cartesian positions in mm
* Leveled XYZ on completion
@@ -679,6 +1387,10 @@ void Planner::check_axes_activity() {
#endif
}
+#endif
+
+#if PLANNER_LEVELING
+
void Planner::unapply_leveling(float raw[XYZ]) {
if (leveling_active) {
@@ -727,16 +1439,160 @@ void Planner::check_axes_activity() {
#endif // PLANNER_LEVELING
+void Planner::quick_stop() {
+
+ // Remove all the queued blocks. Note that this function is NOT
+ // called from the Stepper ISR, so we must consider tail as readonly!
+ // that is why we set head to tail - But there is a race condition that
+ // must be handled: The tail could change between the read and the assignment
+ // so this must be enclosed in a critical section
+
+ const bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+
+ // Drop all queue entries
+ block_buffer_nonbusy = block_buffer_planned = block_buffer_head = block_buffer_tail;
+
+ // Restart the block delay for the first movement - As the queue was
+ // forced to empty, there's no risk the ISR will touch this.
+ delay_before_delivering = BLOCK_DELAY_FOR_1ST_MOVE;
+
+ #if ENABLED(ULTRA_LCD)
+ // Clear the accumulated runtime
+ clear_block_buffer_runtime();
+ #endif
+
+ // Make sure to drop any attempt of queuing moves for at least 1 second
+ cleaning_buffer_counter = 1000;
+
+ // Reenable Stepper ISR
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
+
+ // And stop the stepper ISR
+ stepper.quick_stop();
+}
+
+void Planner::endstop_triggered(const AxisEnum axis) {
+ // Record stepper position and discard the current block
+ stepper.endstop_triggered(axis);
+}
+
+float Planner::triggered_position_mm(const AxisEnum axis) {
+ return stepper.triggered_position(axis) * steps_to_mm[axis];
+}
+
+void Planner::finish_and_disable() {
+ while (has_blocks_queued() || cleaning_buffer_counter) idle();
+ disable_all_steppers();
+}
+
+/**
+ * Get an axis position according to stepper position(s)
+ * For CORE machines apply translation from ABC to XYZ.
+ */
+float Planner::get_axis_position_mm(const AxisEnum axis) {
+ float axis_steps;
+ #if IS_CORE
+ // Requesting one of the "core" axes?
+ if (axis == CORE_AXIS_1 || axis == CORE_AXIS_2) {
+
+ // Protect the access to the position.
+ const bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+
+ // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
+ // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
+ axis_steps = 0.5f * (
+ axis == CORE_AXIS_2 ? CORESIGN(stepper.position(CORE_AXIS_1) - stepper.position(CORE_AXIS_2))
+ : stepper.position(CORE_AXIS_1) + stepper.position(CORE_AXIS_2)
+ );
+
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
+ }
+ else
+ axis_steps = stepper.position(axis);
+ #else
+ axis_steps = stepper.position(axis);
+ #endif
+ return axis_steps * steps_to_mm[axis];
+}
+
+/**
+ * Block until all buffered steps are executed / cleaned
+ */
+void Planner::synchronize() { while (has_blocks_queued() || cleaning_buffer_counter) idle(); }
+
/**
* Planner::_buffer_steps
*
- * Add a new linear movement to the buffer (in terms of steps).
+ * Add a new linear movement to the planner queue (in terms of steps).
*
* target - target position in steps units
* fr_mm_s - (target) speed of the move
* extruder - target extruder
+ * millimeters - the length of the movement, if known
+ *
+ * Returns true if movement was properly queued, false otherwise
*/
-void Planner::_buffer_steps(const int32_t (&target)[XYZE]
+bool Planner::_buffer_steps(const int32_t (&target)[XYZE]
+ #if HAS_POSITION_FLOAT
+ , const float (&target_float)[XYZE]
+ #endif
+ , float 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);
+
+ // Fill the block with the specified movement
+ if (!_populate_block(block, false, target
+ #if HAS_POSITION_FLOAT
+ , target_float
+ #endif
+ , fr_mm_s, extruder, millimeters
+ )) {
+ // Movement was not queued, probably because it was too short.
+ // Simply accept that as movement queued and done
+ return true;
+ }
+
+ // If this is the first added movement, reload the delay, otherwise, cancel it.
+ if (block_buffer_head == block_buffer_tail) {
+ // If it was the first queued block, restart the 1st block delivery delay, to
+ // give the planner an opportunity to queue more movements and plan them
+ // As there are no queued movements, the Stepper ISR will not touch this
+ // variable, so there is no risk setting this here (but it MUST be done
+ // before the following line!!)
+ delay_before_delivering = BLOCK_DELAY_FOR_1ST_MOVE;
+ }
+
+ // Move buffer head
+ block_buffer_head = next_buffer_head;
+
+ // Recalculate and optimize trapezoidal speed profiles
+ recalculate();
+
+ // Movement successfully queued!
+ return true;
+}
+
+/**
+ * Planner::_populate_block
+ *
+ * Fills a new linear movement in the block (in terms of steps).
+ *
+ * target - target position in steps units
+ * fr_mm_s - (target) speed of the move
+ * extruder - target extruder
+ *
+ * Returns true is movement is acceptable, false otherwise
+ */
+bool Planner::_populate_block(block_t * const block, bool split_move,
+ const int32_t (&target)[XYZE]
#if HAS_POSITION_FLOAT
, const float (&target_float)[XYZE]
#endif
@@ -750,7 +1606,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
int32_t de = target[E_AXIS] - position[E_AXIS];
/* <-- add a slash to enable
- SERIAL_ECHOPAIR(" _buffer_steps FR:", fr_mm_s);
+ SERIAL_ECHOPAIR(" _populate_block FR:", fr_mm_s);
SERIAL_ECHOPAIR(" A:", target[A_AXIS]);
SERIAL_ECHOPAIR(" (", da);
SERIAL_ECHOPAIR(" steps) B:", target[B_AXIS]);
@@ -776,7 +1632,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
}
#endif // PREVENT_COLD_EXTRUSION
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
- if (labs(de * e_factor[extruder]) > (int32_t)axis_steps_per_mm[E_AXIS_N] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int
+ if (ABS(de * e_factor[extruder]) > (int32_t)axis_steps_per_mm[E_AXIS_N] * (EXTRUDE_MAXLENGTH)) { // It's not important to get max. extrusion length in a precision < 1mm, so save some cycles and cast to int
position[E_AXIS] = target[E_AXIS]; // Behave as if the move really took place, but ignore E part
#if HAS_POSITION_FLOAT
position_float[E_AXIS] = target_float[E_AXIS];
@@ -817,17 +1673,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
if (de < 0) SBI(dm, E_AXIS);
const float esteps_float = de * e_factor[extruder];
- const int32_t esteps = abs(esteps_float) + 0.5;
-
- // Calculate the buffer head after we push this byte
- const uint8_t next_buffer_head = next_block_index(block_buffer_head);
-
- // If the buffer is full: good! That means we are well ahead of the robot.
- // Rest here until there is room in the buffer.
- while (block_buffer_tail == next_buffer_head) idle();
-
- // Prepare to set up new block
- block_t* block = &block_buffer[block_buffer_head];
+ const uint32_t esteps = ABS(esteps_float) + 0.5f;
// Clear all flags, including the "busy" bit
block->flag = 0x00;
@@ -838,38 +1684,44 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
// Number of steps for each axis
// See http://www.corexy.com/theory.html
#if CORE_IS_XY
- block->steps[A_AXIS] = labs(da + db);
- block->steps[B_AXIS] = labs(da - db);
- block->steps[Z_AXIS] = labs(dc);
+ block->steps[A_AXIS] = ABS(da + db);
+ block->steps[B_AXIS] = ABS(da - db);
+ block->steps[Z_AXIS] = ABS(dc);
#elif CORE_IS_XZ
- block->steps[A_AXIS] = labs(da + dc);
- block->steps[Y_AXIS] = labs(db);
- block->steps[C_AXIS] = labs(da - dc);
+ block->steps[A_AXIS] = ABS(da + dc);
+ block->steps[Y_AXIS] = ABS(db);
+ block->steps[C_AXIS] = ABS(da - dc);
#elif CORE_IS_YZ
- block->steps[X_AXIS] = labs(da);
- block->steps[B_AXIS] = labs(db + dc);
- block->steps[C_AXIS] = labs(db - dc);
+ block->steps[X_AXIS] = ABS(da);
+ block->steps[B_AXIS] = ABS(db + dc);
+ block->steps[C_AXIS] = ABS(db - dc);
#elif IS_SCARA
- block->steps[A_AXIS] = labs(da);
- block->steps[B_AXIS] = labs(db);
- block->steps[Z_AXIS] = labs(dc);
+ block->steps[A_AXIS] = ABS(da);
+ block->steps[B_AXIS] = ABS(db);
+ block->steps[Z_AXIS] = ABS(dc);
#else
// default non-h-bot planning
- block->steps[A_AXIS] = labs(da);
- block->steps[B_AXIS] = labs(db);
- block->steps[C_AXIS] = labs(dc);
+ block->steps[A_AXIS] = ABS(da);
+ block->steps[B_AXIS] = ABS(db);
+ block->steps[C_AXIS] = ABS(dc);
#endif
block->steps[E_AXIS] = esteps;
block->step_event_count = MAX4(block->steps[A_AXIS], block->steps[B_AXIS], block->steps[C_AXIS], esteps);
// Bail if this is a zero-length block
- if (block->step_event_count < MIN_STEPS_PER_SEGMENT) return;
+ if (block->step_event_count < MIN_STEPS_PER_SEGMENT) return false;
- // For a mixing extruder, get a magnified step_event_count for each
+ // For a mixing extruder, get a magnified esteps for each
#if ENABLED(MIXING_EXTRUDER)
for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
- block->mix_event_count[i] = mixing_factor[i] * block->step_event_count;
+ block->mix_steps[i] = mixing_factor[i] * (
+ #if ENABLED(LIN_ADVANCE)
+ esteps
+ #else
+ block->step_event_count
+ #endif
+ );
#endif
#if FAN_COUNT > 0
@@ -1058,7 +1910,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
delta_mm[E_AXIS] = esteps_float * steps_to_mm[E_AXIS_N];
if (block->steps[A_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[B_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[C_AXIS] < MIN_STEPS_PER_SEGMENT) {
- block->millimeters = FABS(delta_mm[E_AXIS]);
+ block->millimeters = ABS(delta_mm[E_AXIS]);
}
else if (!millimeters) {
block->millimeters = SQRT(
@@ -1076,18 +1928,19 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
else
block->millimeters = millimeters;
- const float inverse_millimeters = 1.0 / block->millimeters; // Inverse millimeters to remove multiple divides
+ const float inverse_millimeters = 1.0f / block->millimeters; // Inverse millimeters to remove multiple divides
// Calculate inverse time for this move. No divide by zero due to previous checks.
// Example: At 120mm/s a 60mm move takes 0.5s. So this will give 2.0.
float inverse_secs = fr_mm_s * inverse_millimeters;
- const uint8_t moves_queued = movesplanned();
+ // Get the number of non busy movements in queue (non busy means that they can be altered)
+ const uint8_t moves_queued = nonbusy_movesplanned();
// Slow down when the buffer starts to empty, rather than wait at the corner for a buffer refill
#if ENABLED(SLOWDOWN) || ENABLED(ULTRA_LCD) || defined(XY_FREQUENCY_LIMIT)
// Segment time im micro seconds
- uint32_t segment_time_us = LROUND(1000000.0 / inverse_secs);
+ uint32_t segment_time_us = LROUND(1000000.0f / inverse_secs);
#endif
#if ENABLED(SLOWDOWN)
@@ -1095,7 +1948,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
if (segment_time_us < min_segment_time_us) {
// buffer is draining, add extra time. The amount of time added increases if the buffer is still emptied more.
const uint32_t nst = segment_time_us + LROUND(2 * (min_segment_time_us - segment_time_us) / moves_queued);
- inverse_secs = 1000000.0 / nst;
+ inverse_secs = 1000000.0f / nst;
#if defined(XY_FREQUENCY_LIMIT) || ENABLED(ULTRA_LCD)
segment_time_us = nst;
#endif
@@ -1104,12 +1957,16 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
#endif
#if ENABLED(ULTRA_LCD)
- CRITICAL_SECTION_START
- block_buffer_runtime_us += segment_time_us;
- CRITICAL_SECTION_END
+ // Protect the access to the position.
+ const bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+
+ block_buffer_runtime_us += segment_time_us;
+
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
#endif
- block->nominal_speed = block->millimeters * inverse_secs; // (mm/sec) Always > 0
+ block->nominal_speed_sqr = sq(block->millimeters * inverse_secs); // (mm/sec)^2 Always > 0
block->nominal_rate = CEIL(block->step_event_count * inverse_secs); // (step/sec) Always > 0
#if ENABLED(FILAMENT_WIDTH_SENSOR)
@@ -1131,7 +1988,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
// Convert into an index into the measurement array
- filwidth_delay_index[0] = int8_t(filwidth_delay_dist * 0.1);
+ filwidth_delay_index[0] = int8_t(filwidth_delay_dist * 0.1f);
// If the index has changed (must have gone forward)...
if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
@@ -1147,9 +2004,9 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
#endif
// Calculate and limit speed in mm/sec for each axis
- float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
+ float current_speed[NUM_AXIS], speed_factor = 1.0f; // factor <1 decreases speed
LOOP_XYZE(i) {
- const float cs = FABS((current_speed[i] = delta_mm[i] * inverse_secs));
+ const float cs = ABS((current_speed[i] = delta_mm[i] * inverse_secs));
#if ENABLED(DISTINCT_E_FACTORS)
if (i == E_AXIS) i += extruder;
#endif
@@ -1187,7 +2044,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
const uint32_t max_x_segment_time = MAX3(xs0, xs1, xs2),
max_y_segment_time = MAX3(ys0, ys1, ys2),
- min_xy_segment_time = min(max_x_segment_time, max_y_segment_time);
+ min_xy_segment_time = MIN(max_x_segment_time, max_y_segment_time);
if (min_xy_segment_time < MAX_FREQ_TIME_US) {
const float low_sf = speed_factor * min_xy_segment_time / (MAX_FREQ_TIME_US);
NOMORE(speed_factor, low_sf);
@@ -1195,10 +2052,10 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
#endif // XY_FREQUENCY_LIMIT
// Correct the speed
- if (speed_factor < 1.0) {
+ if (speed_factor < 1.0f) {
LOOP_XYZE(i) current_speed[i] *= speed_factor;
- block->nominal_speed *= speed_factor;
block->nominal_rate *= speed_factor;
+ block->nominal_speed_sqr = block->nominal_speed_sqr * sq(speed_factor);
}
// Compute and limit the acceleration rate for the trapezoid generator.
@@ -1230,6 +2087,17 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
accel = CEIL((esteps ? acceleration : travel_acceleration) * steps_per_mm);
#if ENABLED(LIN_ADVANCE)
+
+ #if ENABLED(JUNCTION_DEVIATION)
+ #if ENABLED(DISTINCT_E_FACTORS)
+ #define MAX_E_JERK max_e_jerk[extruder]
+ #else
+ #define MAX_E_JERK max_e_jerk
+ #endif
+ #else
+ #define MAX_E_JERK max_jerk[E_AXIS]
+ #endif
+
/**
*
* Use LIN_ADVANCE for blocks if all these are true:
@@ -1257,13 +2125,12 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
// Check for unusual high e_D ratio to detect if a retract move was combined with the last print move due to min. steps per segment. Never execute this with advance!
// This assumes no one will use a retract length of 0mm < retr_length < ~0.2mm and no one will print 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament.
- if (block->e_D_ratio > 3.0)
+ if (block->e_D_ratio > 3.0f)
block->use_advance_lead = false;
else {
- const uint32_t max_accel_steps_per_s2 = max_jerk[E_AXIS] / (extruder_advance_K * block->e_D_ratio) * steps_per_mm;
+ const uint32_t max_accel_steps_per_s2 = MAX_E_JERK / (extruder_advance_K * block->e_D_ratio) * steps_per_mm;
#if ENABLED(LA_DEBUG)
- if (accel > max_accel_steps_per_s2)
- SERIAL_ECHOLNPGM("Acceleration limited.");
+ if (accel > max_accel_steps_per_s2) SERIAL_ECHOLNPGM("Acceleration limited.");
#endif
NOMORE(accel, max_accel_steps_per_s2);
}
@@ -1292,12 +2159,14 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
}
block->acceleration_steps_per_s2 = accel;
block->acceleration = accel / steps_per_mm;
- block->acceleration_rate = (long)(accel * 16777216.0 / ((F_CPU) * 0.125)); // * 8.388608
+ #if DISABLED(S_CURVE_ACCELERATION)
+ block->acceleration_rate = (uint32_t)(accel * (4096.0f * 4096.0f / (STEPPER_TIMER_RATE)));
+ #endif
#if ENABLED(LIN_ADVANCE)
if (block->use_advance_lead) {
- block->advance_speed = ((F_CPU) * 0.125) / (extruder_advance_K * block->e_D_ratio * block->acceleration * axis_steps_per_mm[E_AXIS]);
+ block->advance_speed = (STEPPER_TIMER_RATE) / (extruder_advance_K * block->e_D_ratio * block->acceleration * axis_steps_per_mm[E_AXIS_N]);
#if ENABLED(LA_DEBUG)
- if (extruder_advance_K * block->e_D_ratio * block->acceleration * 2 < block->nominal_speed * block->e_D_ratio)
+ if (extruder_advance_K * block->e_D_ratio * block->acceleration * 2 < SQRT(block->nominal_speed_sqr) * block->e_D_ratio)
SERIAL_ECHOLNPGM("More than 2 steps per eISR loop executed.");
if (block->advance_speed < 200)
SERIAL_ECHOLNPGM("eISR running at > 10kHz.");
@@ -1305,138 +2174,198 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
}
#endif
- // Initial limit on the segment entry velocity
- float vmax_junction;
+ float vmax_junction_sqr; // Initial limit on the segment entry velocity (mm/s)^2
- #if 0 // Use old jerk for now
+ #if ENABLED(JUNCTION_DEVIATION)
- float junction_deviation = 0.1;
+ /**
+ * Compute maximum allowable entry speed at junction by centripetal acceleration approximation.
+ * Let a circle be tangent to both previous and current path line segments, where the junction
+ * deviation is defined as the distance from the junction to the closest edge of the circle,
+ * colinear with the circle center. The circular segment joining the two paths represents the
+ * path of centripetal acceleration. Solve for max velocity based on max acceleration about the
+ * radius of the circle, defined indirectly by junction deviation. This may be also viewed as
+ * path width or max_jerk in the previous Grbl version. This approach does not actually deviate
+ * from path, but used as a robust way to compute cornering speeds, as it takes into account the
+ * nonlinearities of both the junction angle and junction velocity.
+ *
+ * NOTE: If the junction deviation value is finite, Grbl executes the motions in an exact path
+ * mode (G61). If the junction deviation value is zero, Grbl will execute the motion in an exact
+ * stop mode (G61.1) manner. In the future, if continuous mode (G64) is desired, the math here
+ * is exactly the same. Instead of motioning all the way to junction point, the machine will
+ * just follow the arc circle defined here. The Arduino doesn't have the CPU cycles to perform
+ * a continuous mode path, but ARM-based microcontrollers most certainly do.
+ *
+ * NOTE: The max junction speed is a fixed value, since machine acceleration limits cannot be
+ * changed dynamically during operation nor can the line move geometry. This must be kept in
+ * memory in the event of a feedrate override changing the nominal speeds of blocks, which can
+ * change the overall maximum entry speed conditions of all blocks.
+ *
+ * #######
+ * https://github.com/MarlinFirmware/Marlin/issues/10341#issuecomment-388191754
+ *
+ * hoffbaked: on May 10 2018 tuned and improved the GRBL algorithm for Marlin:
+ Okay! It seems to be working good. I somewhat arbitrarily cut it off at 1mm
+ on then on anything with less sides than an octagon. With this, and the
+ reverse pass actually recalculating things, a corner acceleration value
+ of 1000 junction deviation of .05 are pretty reasonable. If the cycles
+ can be spared, a better acos could be used. For all I know, it may be
+ already calculated in a different place. */
- // Compute path unit vector
- double unit_vec[XYZ] = {
+ // Unit vector of previous path line segment
+ static float previous_unit_vec[XYZE];
+
+ float unit_vec[] = {
delta_mm[A_AXIS] * inverse_millimeters,
delta_mm[B_AXIS] * inverse_millimeters,
- delta_mm[C_AXIS] * inverse_millimeters
+ delta_mm[C_AXIS] * inverse_millimeters,
+ delta_mm[E_AXIS] * inverse_millimeters
};
- /*
- Compute maximum allowable entry speed at junction by centripetal acceleration approximation.
-
- Let a circle be tangent to both previous and current path line segments, where the junction
- deviation is defined as the distance from the junction to the closest edge of the circle,
- collinear with the circle center.
-
- The circular segment joining the two paths represents the path of centripetal acceleration.
- Solve for max velocity based on max acceleration about the radius of the circle, defined
- indirectly by junction deviation.
-
- This may be also viewed as path width or max_jerk in the previous grbl version. This approach
- does not actually deviate from path, but used as a robust way to compute cornering speeds, as
- it takes into account the nonlinearities of both the junction angle and junction velocity.
- */
-
- vmax_junction = MINIMUM_PLANNER_SPEED; // Set default max junction speed
-
// Skip first block or when previous_nominal_speed is used as a flag for homing and offset cycles.
- if (moves_queued && !UNEAR_ZERO(previous_nominal_speed)) {
+ if (moves_queued && !UNEAR_ZERO(previous_nominal_speed_sqr)) {
// Compute cosine of angle between previous and current path. (prev_unit_vec is negative)
// NOTE: Max junction velocity is computed without sin() or acos() by trig half angle identity.
- const float cos_theta = - previous_unit_vec[X_AXIS] * unit_vec[X_AXIS]
- - previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS]
- - previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS];
- // Skip and use default max junction speed for 0 degree acute junction.
- if (cos_theta < 0.95) {
- vmax_junction = min(previous_nominal_speed, block->nominal_speed);
- // Skip and avoid divide by zero for straight junctions at 180 degrees. Limit to min() of nominal speeds.
- if (cos_theta > -0.95) {
- // Compute maximum junction velocity based on maximum acceleration and junction deviation
- float sin_theta_d2 = SQRT(0.5 * (1.0 - cos_theta)); // Trig half angle identity. Always positive.
- NOMORE(vmax_junction, SQRT(block->acceleration * junction_deviation * sin_theta_d2 / (1.0 - sin_theta_d2)));
+ float junction_cos_theta = -previous_unit_vec[X_AXIS] * unit_vec[X_AXIS]
+ -previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS]
+ -previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS]
+ -previous_unit_vec[E_AXIS] * unit_vec[E_AXIS]
+ ;
+
+ // NOTE: Computed without any expensive trig, sin() or acos(), by trig half angle identity of cos(theta).
+ if (junction_cos_theta > 0.999999f) {
+ // For a 0 degree acute junction, just set minimum junction speed.
+ vmax_junction_sqr = sq(float(MINIMUM_PLANNER_SPEED));
+ }
+ else {
+ NOLESS(junction_cos_theta, -0.999999f); // Check for numerical round-off to avoid divide by zero.
+
+ // Convert delta vector to unit vector
+ float junction_unit_vec[XYZE] = {
+ unit_vec[X_AXIS] - previous_unit_vec[X_AXIS],
+ unit_vec[Y_AXIS] - previous_unit_vec[Y_AXIS],
+ unit_vec[Z_AXIS] - previous_unit_vec[Z_AXIS],
+ unit_vec[E_AXIS] - previous_unit_vec[E_AXIS]
+ };
+ normalize_junction_vector(junction_unit_vec);
+
+ const float junction_acceleration = limit_value_by_axis_maximum(block->acceleration, junction_unit_vec),
+ sin_theta_d2 = SQRT(0.5f * (1.0f - junction_cos_theta)); // Trig half angle identity. Always positive.
+
+ vmax_junction_sqr = (junction_acceleration * junction_deviation_mm * sin_theta_d2) / (1.0f - sin_theta_d2);
+ if (block->millimeters < 1) {
+
+ // Fast acos approximation, minus the error bar to be safe
+ const float junction_theta = (RADIANS(-40) * sq(junction_cos_theta) - RADIANS(50)) * junction_cos_theta + RADIANS(90) - 0.18f;
+
+ // If angle is greater than 135 degrees (octagon), find speed for approximate arc
+ if (junction_theta > RADIANS(135)) {
+ const float limit_sqr = block->millimeters / (RADIANS(180) - junction_theta) * junction_acceleration;
+ NOMORE(vmax_junction_sqr, limit_sqr);
+ }
+ }
+ }
+
+ // Get the lowest speed
+ vmax_junction_sqr = MIN3(vmax_junction_sqr, block->nominal_speed_sqr, previous_nominal_speed_sqr);
+ }
+ else // Init entry speed to zero. Assume it starts from rest. Planner will correct this later.
+ vmax_junction_sqr = 0;
+
+ COPY(previous_unit_vec, unit_vec);
+
+ #else // Classic Jerk Limiting
+
+ /**
+ * Adapted from Průša MKS firmware
+ * https://github.com/prusa3d/Prusa-Firmware
+ *
+ * Start with a safe speed (from which the machine may halt to stop immediately).
+ */
+
+ // Exit speed limited by a jerk to full halt of a previous last segment
+ static float previous_safe_speed;
+
+ const float nominal_speed = SQRT(block->nominal_speed_sqr);
+ float safe_speed = nominal_speed;
+
+ uint8_t limited = 0;
+ LOOP_XYZE(i) {
+ const float jerk = ABS(current_speed[i]), maxj = max_jerk[i];
+ if (jerk > maxj) {
+ if (limited) {
+ const float mjerk = maxj * nominal_speed;
+ if (jerk * safe_speed > mjerk) safe_speed = mjerk / jerk;
+ }
+ else {
+ ++limited;
+ safe_speed = maxj;
}
}
}
- #endif
- /**
- * Adapted from Průša MKS firmware
- * https://github.com/prusa3d/Prusa-Firmware
- *
- * Start with a safe speed (from which the machine may halt to stop immediately).
- */
+ float vmax_junction;
+ if (moves_queued && !UNEAR_ZERO(previous_nominal_speed_sqr)) {
+ // Estimate a maximum velocity allowed at a joint of two successive segments.
+ // If this maximum velocity allowed is lower than the minimum of the entry / exit safe velocities,
+ // then the machine is not coasting anymore and the safe entry / exit velocities shall be used.
- // Exit speed limited by a jerk to full halt of a previous last segment
- static float previous_safe_speed;
+ // Factor to multiply the previous / current nominal velocities to get componentwise limited velocities.
+ float v_factor = 1;
+ limited = 0;
- float safe_speed = block->nominal_speed;
- uint8_t limited = 0;
- LOOP_XYZE(i) {
- const float jerk = FABS(current_speed[i]), maxj = max_jerk[i];
- if (jerk > maxj) {
- if (limited) {
- const float mjerk = maxj * block->nominal_speed;
- if (jerk * safe_speed > mjerk) safe_speed = mjerk / jerk;
- }
- else {
- ++limited;
- safe_speed = maxj;
+ // The junction velocity will be shared between successive segments. Limit the junction velocity to their minimum.
+ // Pick the smaller of the nominal speeds. Higher speed shall not be achieved at the junction during coasting.
+ const float previous_nominal_speed = SQRT(previous_nominal_speed_sqr);
+ vmax_junction = MIN(nominal_speed, previous_nominal_speed);
+
+ // Now limit the jerk in all axes.
+ const float smaller_speed_factor = vmax_junction / previous_nominal_speed;
+ LOOP_XYZE(axis) {
+ // Limit an axis. We have to differentiate: coasting, reversal of an axis, full stop.
+ float v_exit = previous_speed[axis] * smaller_speed_factor,
+ v_entry = current_speed[axis];
+ if (limited) {
+ v_exit *= v_factor;
+ v_entry *= v_factor;
+ }
+
+ // Calculate jerk depending on whether the axis is coasting in the same direction or reversing.
+ const float jerk = (v_exit > v_entry)
+ ? // coasting axis reversal
+ ( (v_entry > 0 || v_exit < 0) ? (v_exit - v_entry) : MAX(v_exit, -v_entry) )
+ : // v_exit <= v_entry coasting axis reversal
+ ( (v_entry < 0 || v_exit > 0) ? (v_entry - v_exit) : MAX(-v_exit, v_entry) );
+
+ if (jerk > max_jerk[axis]) {
+ v_factor *= max_jerk[axis] / jerk;
+ ++limited;
+ }
}
+ if (limited) vmax_junction *= v_factor;
+ // Now the transition velocity is known, which maximizes the shared exit / entry velocity while
+ // respecting the jerk factors, it may be possible, that applying separate safe exit / entry velocities will achieve faster prints.
+ const float vmax_junction_threshold = vmax_junction * 0.99f;
+ if (previous_safe_speed > vmax_junction_threshold && safe_speed > vmax_junction_threshold)
+ vmax_junction = safe_speed;
}
- }
-
- if (moves_queued && !UNEAR_ZERO(previous_nominal_speed)) {
- // Estimate a maximum velocity allowed at a joint of two successive segments.
- // If this maximum velocity allowed is lower than the minimum of the entry / exit safe velocities,
- // then the machine is not coasting anymore and the safe entry / exit velocities shall be used.
-
- // The junction velocity will be shared between successive segments. Limit the junction velocity to their minimum.
- // Pick the smaller of the nominal speeds. Higher speed shall not be achieved at the junction during coasting.
- vmax_junction = min(block->nominal_speed, previous_nominal_speed);
-
- // Factor to multiply the previous / current nominal velocities to get componentwise limited velocities.
- float v_factor = 1;
- limited = 0;
-
- // Now limit the jerk in all axes.
- const float smaller_speed_factor = vmax_junction / previous_nominal_speed;
- LOOP_XYZE(axis) {
- // Limit an axis. We have to differentiate: coasting, reversal of an axis, full stop.
- float v_exit = previous_speed[axis] * smaller_speed_factor,
- v_entry = current_speed[axis];
- if (limited) {
- v_exit *= v_factor;
- v_entry *= v_factor;
- }
-
- // Calculate jerk depending on whether the axis is coasting in the same direction or reversing.
- const float jerk = (v_exit > v_entry)
- ? // coasting axis reversal
- ( (v_entry > 0 || v_exit < 0) ? (v_exit - v_entry) : max(v_exit, -v_entry) )
- : // v_exit <= v_entry coasting axis reversal
- ( (v_entry < 0 || v_exit > 0) ? (v_entry - v_exit) : max(-v_exit, v_entry) );
-
- if (jerk > max_jerk[axis]) {
- v_factor *= max_jerk[axis] / jerk;
- ++limited;
- }
- }
- if (limited) vmax_junction *= v_factor;
- // Now the transition velocity is known, which maximizes the shared exit / entry velocity while
- // respecting the jerk factors, it may be possible, that applying separate safe exit / entry velocities will achieve faster prints.
- const float vmax_junction_threshold = vmax_junction * 0.99f;
- if (previous_safe_speed > vmax_junction_threshold && safe_speed > vmax_junction_threshold)
+ else
vmax_junction = safe_speed;
- }
- else
- vmax_junction = safe_speed;
+
+ previous_safe_speed = safe_speed;
+ vmax_junction_sqr = sq(vmax_junction);
+
+ #endif // Classic Jerk Limiting
// Max entry speed of this block equals the max exit speed of the previous block.
- block->max_entry_speed = vmax_junction;
+ block->max_entry_speed_sqr = vmax_junction_sqr;
// Initialize block entry speed. Compute based on deceleration to user-defined MINIMUM_PLANNER_SPEED.
- const float v_allowable = max_allowable_speed(-block->acceleration, MINIMUM_PLANNER_SPEED, block->millimeters);
- // If stepper ISR is disabled, this indicates buffer_segment wants to add a split block.
- // In this case start with the max. allowed speed to avoid an interrupted first move.
- block->entry_speed = STEPPER_ISR_ENABLED() ? MINIMUM_PLANNER_SPEED : min(vmax_junction, v_allowable);
+ const float v_allowable_sqr = max_allowable_speed_sqr(-block->acceleration, sq(float(MINIMUM_PLANNER_SPEED)), block->millimeters);
+
+ // If we are trying to add a split block, start with the
+ // max. allowed speed to avoid an interrupted first move.
+ block->entry_speed_sqr = !split_move ? sq(float(MINIMUM_PLANNER_SPEED)) : MIN(vmax_junction_sqr, v_allowable_sqr);
// Initialize planner efficiency flags
// Set flag if block will always reach maximum junction speed regardless of entry/exit speeds.
@@ -1446,26 +2375,56 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
// block nominal speed limits both the current and next maximum junction speeds. Hence, in both
// the reverse and forward planners, the corresponding block junction speed will always be at the
// the maximum junction speed and may always be ignored for any speed reduction checks.
- block->flag |= block->nominal_speed <= v_allowable ? BLOCK_FLAG_RECALCULATE | BLOCK_FLAG_NOMINAL_LENGTH : BLOCK_FLAG_RECALCULATE;
+ block->flag |= block->nominal_speed_sqr <= v_allowable_sqr ? BLOCK_FLAG_RECALCULATE | BLOCK_FLAG_NOMINAL_LENGTH : BLOCK_FLAG_RECALCULATE;
// Update previous path unit_vector and nominal speed
COPY(previous_speed, current_speed);
- previous_nominal_speed = block->nominal_speed;
- previous_safe_speed = safe_speed;
+ previous_nominal_speed_sqr = block->nominal_speed_sqr;
- // Move buffer head
- block_buffer_head = next_buffer_head;
-
- // Update the position (only when a move was queued)
+ // Update the position
static_assert(COUNT(target) > 1, "Parameter to _buffer_steps must be (&target)[XYZE]!");
COPY(position, target);
#if HAS_POSITION_FLOAT
COPY(position_float, target_float);
#endif
- recalculate();
+ // Movement was accepted
+ return true;
+} // _populate_block()
-} // _buffer_steps()
+/**
+ * Planner::buffer_sync_block
+ * Add a block to the buffer that just updates the position
+ */
+void Planner::buffer_sync_block() {
+ // Wait for the next available block
+ uint8_t next_buffer_head;
+ block_t * const block = get_next_free_block(next_buffer_head);
+
+ // Clear block
+ memset(block, 0, sizeof(block_t));
+
+ block->flag = BLOCK_FLAG_SYNC_POSITION;
+
+ block->position[A_AXIS] = position[A_AXIS];
+ block->position[B_AXIS] = position[B_AXIS];
+ block->position[C_AXIS] = position[C_AXIS];
+ block->position[E_AXIS] = position[E_AXIS];
+
+ // If this is the first added movement, reload the delay, otherwise, cancel it.
+ if (block_buffer_head == block_buffer_tail) {
+ // If it was the first queued block, restart the 1st block delivery delay, to
+ // give the planner an opportunity to queue more movements and plan them
+ // As there are no queued movements, the Stepper ISR will not touch this
+ // variable, so there is no risk setting this here (but it MUST be done
+ // before the following line!!)
+ delay_before_delivering = BLOCK_DELAY_FOR_1ST_MOVE;
+ }
+
+ block_buffer_head = next_buffer_head;
+
+ stepper.wake_up();
+} // buffer_sync_block()
/**
* Planner::buffer_segment
@@ -1479,7 +2438,11 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE]
* extruder - target extruder
* millimeters - the length of the movement, if known
*/
-void Planner::buffer_segment(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder, const float &millimeters/*=0.0*/) {
+bool Planner::buffer_segment(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder, const float &millimeters/*=0.0*/) {
+
+ // If we are cleaning, do not accept queuing of movements
+ if (cleaning_buffer_counter) return false;
+
// When changing extruders recalculate steps corresponding to the E position
#if ENABLED(DISTINCT_E_FACTORS)
if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
@@ -1537,48 +2500,18 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con
SERIAL_ECHOLNPGM(")");
//*/
- // Always split the first move into two (if not homing or probing)
- if (!has_blocks_queued()) {
-
- #define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
- const int32_t between[ABCE] = { _BETWEEN(A), _BETWEEN(B), _BETWEEN(C), _BETWEEN(E) };
-
- #if HAS_POSITION_FLOAT
- #define _BETWEEN_F(A) (position_float[A##_AXIS] + target_float[A##_AXIS]) * 0.5
- const float between_float[ABCE] = { _BETWEEN_F(A), _BETWEEN_F(B), _BETWEEN_F(C), _BETWEEN_F(E) };
- #endif
-
- DISABLE_STEPPER_DRIVER_INTERRUPT();
-
- _buffer_steps(between
- #if HAS_POSITION_FLOAT
- , between_float
- #endif
- , fr_mm_s, extruder, millimeters * 0.5
- );
-
- const uint8_t next = block_buffer_head;
-
- _buffer_steps(target
- #if HAS_POSITION_FLOAT
- , target_float
- #endif
- , fr_mm_s, extruder, millimeters * 0.5
- );
-
- SBI(block_buffer[next].flag, BLOCK_BIT_CONTINUED);
- ENABLE_STEPPER_DRIVER_INTERRUPT();
- }
- else
- _buffer_steps(target
+ // Queue the movement
+ if (
+ !_buffer_steps(target
#if HAS_POSITION_FLOAT
, target_float
#endif
, fr_mm_s, extruder, millimeters
- );
+ )
+ ) return false;
stepper.wake_up();
-
+ return true;
} // buffer_segment()
/**
@@ -1590,24 +2523,25 @@ void Planner::buffer_segment(const float &a, const float &b, const float &c, con
void Planner::_set_position_mm(const float &a, const float &b, const float &c, const float &e) {
#if ENABLED(DISTINCT_E_FACTORS)
- #define _EINDEX (E_AXIS + active_extruder)
last_extruder = active_extruder;
- #else
- #define _EINDEX E_AXIS
#endif
- const int32_t na = position[A_AXIS] = LROUND(a * axis_steps_per_mm[A_AXIS]),
- nb = position[B_AXIS] = LROUND(b * axis_steps_per_mm[B_AXIS]),
- nc = position[C_AXIS] = LROUND(c * axis_steps_per_mm[C_AXIS]),
- ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
+ position[A_AXIS] = LROUND(a * axis_steps_per_mm[A_AXIS]),
+ position[B_AXIS] = LROUND(b * axis_steps_per_mm[B_AXIS]),
+ position[C_AXIS] = LROUND(c * axis_steps_per_mm[C_AXIS]),
+ position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
#if HAS_POSITION_FLOAT
- position_float[X_AXIS] = a;
- position_float[Y_AXIS] = b;
- position_float[Z_AXIS] = c;
+ position_float[A_AXIS] = a;
+ position_float[B_AXIS] = b;
+ position_float[C_AXIS] = c;
position_float[E_AXIS] = e;
#endif
- stepper.set_position(na, nb, nc, ne);
- previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest.
- ZERO(previous_speed);
+ if (has_blocks_queued()) {
+ //previous_nominal_speed_sqr = 0.0; // Reset planner junction speeds. Assume start from rest.
+ //ZERO(previous_speed);
+ buffer_sync_block();
+ }
+ else
+ stepper.set_position(position[A_AXIS], position[B_AXIS], position[C_AXIS], position[E_AXIS]);
}
void Planner::set_position_mm_kinematic(const float (&cart)[XYZE]) {
@@ -1625,22 +2559,6 @@ void Planner::set_position_mm_kinematic(const float (&cart)[XYZE]) {
#endif
}
-/**
- * Sync from the stepper positions. (e.g., after an interrupted move)
- */
-void Planner::sync_from_steppers() {
- LOOP_XYZE(i) {
- position[i] = stepper.position((AxisEnum)i);
- #if HAS_POSITION_FLOAT
- position_float[i] = position[i] * steps_to_mm[i
- #if ENABLED(DISTINCT_E_FACTORS)
- + (i == E_AXIS ? active_extruder : 0)
- #endif
- ];
- #endif
- }
-}
-
/**
* Setters for planner position (also setting stepper position).
*/
@@ -1655,28 +2573,35 @@ void Planner::set_position_mm(const AxisEnum axis, const float &v) {
#if HAS_POSITION_FLOAT
position_float[axis] = v;
#endif
- stepper.set_position(axis, position[axis]);
- previous_speed[axis] = 0.0;
+ if (has_blocks_queued()) {
+ //previous_speed[axis] = 0.0;
+ buffer_sync_block();
+ }
+ else
+ stepper.set_position(axis, position[axis]);
}
// Recalculate the steps/s^2 acceleration rates, based on the mm/s^2
void Planner::reset_acceleration_rates() {
#if ENABLED(DISTINCT_E_FACTORS)
- #define HIGHEST_CONDITION (i < E_AXIS || i == E_AXIS + active_extruder)
+ #define AXIS_CONDITION (i < E_AXIS || i == E_AXIS + active_extruder)
#else
- #define HIGHEST_CONDITION true
+ #define AXIS_CONDITION true
#endif
uint32_t highest_rate = 1;
LOOP_XYZE_N(i) {
max_acceleration_steps_per_s2[i] = max_acceleration_mm_per_s2[i] * axis_steps_per_mm[i];
- if (HIGHEST_CONDITION) NOLESS(highest_rate, max_acceleration_steps_per_s2[i]);
+ if (AXIS_CONDITION) NOLESS(highest_rate, max_acceleration_steps_per_s2[i]);
}
- cutoff_long = 4294967295UL / highest_rate;
+ cutoff_long = 4294967295UL / highest_rate; // 0xFFFFFFFFUL
+ #if ENABLED(JUNCTION_DEVIATION) && ENABLED(LIN_ADVANCE)
+ recalculate_max_e_jerk();
+ #endif
}
// Recalculate position, steps_to_mm if axis_steps_per_mm changes!
void Planner::refresh_positioning() {
- LOOP_XYZE_N(i) steps_to_mm[i] = 1.0 / axis_steps_per_mm[i];
+ LOOP_XYZE_N(i) steps_to_mm[i] = 1.0f / axis_steps_per_mm[i];
set_position_mm_kinematic(current_position);
reset_acceleration_rates();
}
diff --git a/Marlin/planner.h b/Marlin/planner.h
index 61af55fc81..fd06be588c 100644
--- a/Marlin/planner.h
+++ b/Marlin/planner.h
@@ -36,7 +36,7 @@
#include "enum.h"
#include "Marlin.h"
-#if HAS_ABL
+#if ABL_PLANAR
#include "vector_3.h"
#endif
@@ -49,18 +49,18 @@ enum BlockFlagBit : char {
// from a safe speed (in consideration of jerking from zero speed).
BLOCK_BIT_NOMINAL_LENGTH,
- // The block is busy
- BLOCK_BIT_BUSY,
-
// The block is segment 2+ of a longer move
- BLOCK_BIT_CONTINUED
+ BLOCK_BIT_CONTINUED,
+
+ // Sync the stepper counts from the block
+ BLOCK_BIT_SYNC_POSITION
};
enum BlockFlag : char {
BLOCK_FLAG_RECALCULATE = _BV(BLOCK_BIT_RECALCULATE),
BLOCK_FLAG_NOMINAL_LENGTH = _BV(BLOCK_BIT_NOMINAL_LENGTH),
- BLOCK_FLAG_BUSY = _BV(BLOCK_BIT_BUSY),
- BLOCK_FLAG_CONTINUED = _BV(BLOCK_BIT_CONTINUED)
+ BLOCK_FLAG_CONTINUED = _BV(BLOCK_BIT_CONTINUED),
+ BLOCK_FLAG_SYNC_POSITION = _BV(BLOCK_BIT_SYNC_POSITION)
};
/**
@@ -74,41 +74,59 @@ enum BlockFlag : char {
*/
typedef struct {
- uint8_t flag; // Block flags (See BlockFlag enum above)
+ volatile uint8_t flag; // Block flags (See BlockFlag enum above) - Modified by ISR and main thread!
- unsigned char active_extruder; // The extruder to move (if E move)
+ // Fields used by the motion planner to manage acceleration
+ float nominal_speed_sqr, // The nominal speed for this block in (mm/sec)^2
+ entry_speed_sqr, // Entry speed at previous-current junction in (mm/sec)^2
+ max_entry_speed_sqr, // Maximum allowable junction entry speed in (mm/sec)^2
+ millimeters, // The total travel of this block in mm
+ acceleration; // acceleration mm/sec^2
- // Fields used by the Bresenham algorithm for tracing the line
- int32_t steps[NUM_AXIS]; // Step count along each axis
+ union {
+ // Data used by all move blocks
+ struct {
+ // Fields used by the Bresenham algorithm for tracing the line
+ uint32_t steps[NUM_AXIS]; // Step count along each axis
+ };
+ // Data used by all sync blocks
+ struct {
+ int32_t position[NUM_AXIS]; // New position to force when this sync block is executed
+ };
+ };
uint32_t step_event_count; // The number of step events required to complete this block
+ uint8_t active_extruder; // The extruder to move (if E move)
+
#if ENABLED(MIXING_EXTRUDER)
- uint32_t mix_event_count[MIXING_STEPPERS]; // Scaled step_event_count for the mixing steppers
+ uint32_t mix_steps[MIXING_STEPPERS]; // Scaled steps[E_AXIS] for the mixing steppers
#endif
- int32_t accelerate_until, // The index of the step event on which to stop acceleration
- decelerate_after, // The index of the step event on which to start decelerating
- acceleration_rate; // The acceleration rate used for acceleration calculation
+ // Settings for the trapezoid generator
+ uint32_t accelerate_until, // The index of the step event on which to stop acceleration
+ decelerate_after; // The index of the step event on which to start decelerating
+
+ #if ENABLED(S_CURVE_ACCELERATION)
+ uint32_t cruise_rate, // The actual cruise rate to use, between end of the acceleration phase and start of deceleration phase
+ acceleration_time, // Acceleration time and deceleration time in STEP timer counts
+ deceleration_time,
+ acceleration_time_inverse, // Inverse of acceleration and deceleration periods, expressed as integer. Scale depends on CPU being used
+ deceleration_time_inverse;
+ #else
+ uint32_t acceleration_rate; // The acceleration rate used for acceleration calculation
+ #endif
uint8_t direction_bits; // The direction bit set for this block (refers to *_DIRECTION_BIT in config.h)
// Advance extrusion
#if ENABLED(LIN_ADVANCE)
bool use_advance_lead;
- uint16_t advance_speed, // Timer value for extruder speed offset
+ uint16_t advance_speed, // STEP timer value for extruder speed offset ISR
max_adv_steps, // max. advance steps to get cruising speed pressure (not always nominal_speed!)
final_adv_steps; // advance steps due to exit speed
float e_D_ratio;
#endif
- // Fields used by the motion planner to manage acceleration
- float nominal_speed, // The nominal speed for this block in mm/sec
- entry_speed, // Entry speed at previous-current junction in mm/sec
- max_entry_speed, // Maximum allowable junction entry speed in mm/sec
- millimeters, // The total travel of this block in mm
- acceleration; // acceleration mm/sec^2
-
- // Settings for the trapezoid generator
uint32_t nominal_rate, // The nominal step rate for this block in step_events/sec
initial_rate, // The jerk-adjusted step rate at start of block
final_rate, // The minimal rate at exit
@@ -126,7 +144,7 @@ typedef struct {
} block_t;
-#define HAS_POSITION_FLOAT (ENABLED(LIN_ADVANCE) || ENABLED(SCARA_FEEDRATE_SCALING))
+#define HAS_POSITION_FLOAT (ENABLED(LIN_ADVANCE) || HAS_FEEDRATE_SCALING)
#define BLOCK_MOD(n) ((n)&(BLOCK_BUFFER_SIZE-1))
@@ -148,7 +166,12 @@ class Planner {
*/
static block_t block_buffer[BLOCK_BUFFER_SIZE];
static volatile uint8_t block_buffer_head, // Index of the next block to be pushed
+ block_buffer_nonbusy, // Index of the first non busy block
+ block_buffer_planned, // Index of the optimally planned block
block_buffer_tail; // Index of the busy block, if any
+ static uint16_t cleaning_buffer_counter; // A counter to disable queuing of blocks
+ static uint8_t delay_before_delivering; // This counter delays delivery of blocks when queue becomes empty to allow the opportunity of merging blocks
+
#if ENABLED(DISTINCT_E_FACTORS)
static uint8_t last_extruder; // Respond to extruder change
@@ -165,19 +188,30 @@ class Planner {
// May be auto-adjusted by a filament width sensor
#endif
- static float max_feedrate_mm_s[XYZE_N], // Max speeds in mm per second
- axis_steps_per_mm[XYZE_N],
- steps_to_mm[XYZE_N];
- static uint32_t max_acceleration_steps_per_s2[XYZE_N],
- max_acceleration_mm_per_s2[XYZE_N]; // Use M201 to override
+ static uint32_t max_acceleration_mm_per_s2[XYZE_N], // (mm/s^2) M201 XYZE
+ max_acceleration_steps_per_s2[XYZE_N], // (steps/s^2) Derived from mm_per_s2
+ min_segment_time_us; // (µs) M205 B
+ static float max_feedrate_mm_s[XYZE_N], // (mm/s) M203 XYZE - Max speeds
+ axis_steps_per_mm[XYZE_N], // (steps) M92 XYZE - Steps per millimeter
+ steps_to_mm[XYZE_N], // (mm) Millimeters per step
+ min_feedrate_mm_s, // (mm/s) M205 S - Minimum linear feedrate
+ acceleration, // (mm/s^2) M204 S - Normal acceleration. DEFAULT ACCELERATION for all printing moves.
+ retract_acceleration, // (mm/s^2) M204 R - Retract acceleration. Filament pull-back and push-forward while standing still in the other axes
+ travel_acceleration, // (mm/s^2) M204 T - Travel acceleration. DEFAULT ACCELERATION for all NON printing moves.
+ min_travel_feedrate_mm_s; // (mm/s) M205 T - Minimum travel feedrate
- static uint32_t min_segment_time_us; // Use 'M205 B<µs>' to override
- static float min_feedrate_mm_s,
- acceleration, // Normal acceleration mm/s^2 DEFAULT ACCELERATION for all printing moves. M204 SXXXX
- retract_acceleration, // Retract acceleration mm/s^2 filament pull-back and push-forward while standing still in the other axes M204 TXXXX
- travel_acceleration, // Travel acceleration mm/s^2 DEFAULT ACCELERATION for all NON printing moves. M204 MXXXX
- max_jerk[XYZE], // The largest speed change requiring no acceleration
- min_travel_feedrate_mm_s;
+ #if ENABLED(JUNCTION_DEVIATION)
+ static float junction_deviation_mm; // (mm) M205 J
+ #if ENABLED(LIN_ADVANCE)
+ #if ENABLED(DISTINCT_E_FACTORS)
+ static float max_e_jerk[EXTRUDERS]; // Calculated from junction_deviation_mm
+ #else
+ static float max_e_jerk;
+ #endif
+ #endif
+ #else
+ static float max_jerk[XYZE]; // (mm/s^2) M205 XYZE - The largest speed change requiring no acceleration.
+ #endif
#if HAS_LEVELING
static bool leveling_active; // Flag that bed leveling is enabled
@@ -216,6 +250,10 @@ class Planner {
#endif
#endif
+ #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
+ static bool abort_on_endstop_hit;
+ #endif
+
private:
/**
@@ -230,9 +268,9 @@ class Planner {
static float previous_speed[NUM_AXIS];
/**
- * Nominal speed of previous path line segment
+ * Nominal speed of previous path line segment (mm/s)^2
*/
- static float previous_nominal_speed;
+ static float previous_nominal_speed_sqr;
/**
* Limit where 64bit math is necessary for acceleration calculation
@@ -281,7 +319,7 @@ class Planner {
static void refresh_positioning();
FORCE_INLINE static void refresh_e_factor(const uint8_t e) {
- e_factor[e] = (flow_percentage[e] * 0.01
+ e_factor[e] = (flow_percentage[e] * 0.01f
#if DISABLED(NO_VOLUMETRICS)
* volumetric_multiplier[e]
#endif
@@ -291,15 +329,6 @@ class Planner {
// Manage fans, paste pressure, etc.
static void check_axes_activity();
- /**
- * Number of moves currently in the planner
- */
- FORCE_INLINE static uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail + BLOCK_BUFFER_SIZE); }
-
- FORCE_INLINE static void clear_block_buffer() { block_buffer_head = block_buffer_tail = 0; }
-
- FORCE_INLINE static bool is_full() { return block_buffer_tail == next_block_index(block_buffer_head); }
-
// Update multipliers based on new diameter measurements
static void calculate_volumetric_multipliers();
@@ -328,19 +357,19 @@ class Planner {
* Returns 0.0 if Z is past the specified 'Fade Height'.
*/
inline static float fade_scaling_factor_for_z(const float &rz) {
- static float z_fade_factor = 1.0;
+ static float z_fade_factor = 1;
if (z_fade_height) {
- if (rz >= z_fade_height) return 0.0;
+ if (rz >= z_fade_height) return 0;
if (last_fade_z != rz) {
last_fade_z = rz;
- z_fade_factor = 1.0 - rz * inverse_z_fade_height;
+ z_fade_factor = 1 - rz * inverse_z_fade_height;
}
return z_fade_factor;
}
- return 1.0;
+ return 1;
}
- FORCE_INLINE static void force_fade_recalc() { last_fade_z = -999.999; }
+ FORCE_INLINE static void force_fade_recalc() { last_fade_z = -999.999f; }
FORCE_INLINE static void set_z_fade_height(const float &zfh) {
z_fade_height = zfh > 0 ? zfh : 0;
@@ -356,7 +385,7 @@ class Planner {
FORCE_INLINE static float fade_scaling_factor_for_z(const float &rz) {
UNUSED(rz);
- return 1.0;
+ return 1;
}
FORCE_INLINE static bool leveling_active_at_z(const float &rz) { UNUSED(rz); return true; }
@@ -387,28 +416,58 @@ class Planner {
#endif // SKEW_CORRECTION
- #if PLANNER_LEVELING
-
- #define ARG_X float rx
- #define ARG_Y float ry
- #define ARG_Z float rz
-
+ #if PLANNER_LEVELING || HAS_UBL_AND_CURVES
/**
* Apply leveling to transform a cartesian position
* as it will be given to the planner and steppers.
*/
static void apply_leveling(float &rx, float &ry, float &rz);
- static void apply_leveling(float (&raw)[XYZ]) { apply_leveling(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]); }
+ FORCE_INLINE static void apply_leveling(float (&raw)[XYZ]) { apply_leveling(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]); }
+ #endif
+
+ #if PLANNER_LEVELING
+ #define ARG_X float rx
+ #define ARG_Y float ry
+ #define ARG_Z float rz
static void unapply_leveling(float raw[XYZ]);
-
#else
-
#define ARG_X const float &rx
#define ARG_Y const float &ry
#define ARG_Z const float &rz
-
#endif
+ // Number of moves currently in the planner including the busy block, if any
+ FORCE_INLINE static uint8_t movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_tail); }
+
+ // Number of nonbusy moves currently in the planner
+ FORCE_INLINE static uint8_t nonbusy_movesplanned() { return BLOCK_MOD(block_buffer_head - block_buffer_nonbusy); }
+
+ // Remove all blocks from the buffer
+ FORCE_INLINE static void clear_block_buffer() { block_buffer_nonbusy = block_buffer_planned = block_buffer_head = block_buffer_tail = 0; }
+
+ // Check if movement queue is full
+ FORCE_INLINE static bool is_full() { return block_buffer_tail == next_block_index(block_buffer_head); }
+
+ // Get count of movement slots free
+ FORCE_INLINE static uint8_t moves_free() { return BLOCK_BUFFER_SIZE - 1 - movesplanned(); }
+
+ /**
+ * Planner::get_next_free_block
+ *
+ * - Get the next head indices (passed by reference)
+ * - Wait for the number of spaces to open up in the planner
+ * - Return the first head block
+ */
+ FORCE_INLINE static block_t* get_next_free_block(uint8_t &next_buffer_head, const uint8_t count=1) {
+
+ // Wait until there are enough slots free
+ while (moves_free() < count) { idle(); }
+
+ // Return the first available block
+ next_buffer_head = next_block_index(block_buffer_head);
+ return &block_buffer[block_buffer_head];
+ }
+
/**
* Planner::_buffer_steps
*
@@ -418,14 +477,42 @@ class Planner {
* fr_mm_s - (target) speed of the move
* extruder - target extruder
* millimeters - the length of the movement, if known
+ *
+ * Returns true if movement was buffered, false otherwise
*/
- static void _buffer_steps(const int32_t (&target)[XYZE]
+ static bool _buffer_steps(const int32_t (&target)[XYZE]
#if HAS_POSITION_FLOAT
, const float (&target_float)[XYZE]
#endif
, float fr_mm_s, const uint8_t extruder, const float &millimeters=0.0
);
+ /**
+ * Planner::_populate_block
+ *
+ * Fills a new linear movement in the block (in terms of steps).
+ *
+ * target - target position in steps units
+ * fr_mm_s - (target) speed of the move
+ * extruder - target extruder
+ * millimeters - the length of the movement, if known
+ *
+ * Returns true is movement is acceptable, false otherwise
+ */
+ static bool _populate_block(block_t * const block, bool split_move,
+ const int32_t (&target)[XYZE]
+ #if HAS_POSITION_FLOAT
+ , const float (&target_float)[XYZE]
+ #endif
+ , float fr_mm_s, const uint8_t extruder, const float &millimeters=0.0
+ );
+
+ /**
+ * Planner::buffer_sync_block
+ * Add a block to the buffer that just updates the position
+ */
+ static void buffer_sync_block();
+
/**
* Planner::buffer_segment
*
@@ -438,7 +525,7 @@ class Planner {
* extruder - target extruder
* millimeters - the length of the movement, if known
*/
- static void buffer_segment(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder, const float &millimeters=0.0);
+ static bool buffer_segment(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder, const float &millimeters=0.0);
static void _set_position_mm(const float &a, const float &b, const float &c, const float &e);
@@ -455,11 +542,11 @@ class Planner {
* extruder - target extruder
* millimeters - the length of the movement, if known
*/
- FORCE_INLINE static void buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, const float &fr_mm_s, const uint8_t extruder, const float millimeters = 0.0) {
+ FORCE_INLINE static bool buffer_line(ARG_X, ARG_Y, ARG_Z, const float &e, const float &fr_mm_s, const uint8_t extruder, const float millimeters = 0.0) {
#if PLANNER_LEVELING && IS_CARTESIAN
apply_leveling(rx, ry, rz);
#endif
- buffer_segment(rx, ry, rz, e, fr_mm_s, extruder, millimeters);
+ return buffer_segment(rx, ry, rz, e, fr_mm_s, extruder, millimeters);
}
/**
@@ -472,7 +559,7 @@ class Planner {
* extruder - target extruder
* millimeters - the length of the movement, if known
*/
- FORCE_INLINE static void buffer_line_kinematic(const float (&cart)[XYZE], const float &fr_mm_s, const uint8_t extruder, const float millimeters = 0.0) {
+ FORCE_INLINE static bool buffer_line_kinematic(const float (&cart)[XYZE], const float &fr_mm_s, const uint8_t extruder, const float millimeters = 0.0) {
#if PLANNER_LEVELING
float raw[XYZ] = { cart[X_AXIS], cart[Y_AXIS], cart[Z_AXIS] };
apply_leveling(raw);
@@ -481,9 +568,9 @@ class Planner {
#endif
#if IS_KINEMATIC
inverse_kinematics(raw);
- buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], cart[E_AXIS], fr_mm_s, extruder, millimeters);
+ return buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], cart[E_AXIS], fr_mm_s, extruder, millimeters);
#else
- buffer_segment(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], cart[E_AXIS], fr_mm_s, extruder, millimeters);
+ return buffer_segment(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS], cart[E_AXIS], fr_mm_s, extruder, millimeters);
#endif
}
@@ -505,36 +592,50 @@ class Planner {
static void set_position_mm_kinematic(const float (&cart)[XYZE]);
static void set_position_mm(const AxisEnum axis, const float &v);
FORCE_INLINE static void set_z_position_mm(const float &z) { set_position_mm(Z_AXIS, z); }
- FORCE_INLINE static void set_e_position_mm(const float &e) { set_position_mm(AxisEnum(E_AXIS), e); }
+ FORCE_INLINE static void set_e_position_mm(const float &e) { set_position_mm(E_AXIS, e); }
/**
- * Sync from the stepper positions. (e.g., after an interrupted move)
+ * Get an axis position according to stepper position(s)
+ * For CORE machines apply translation from ABC to XYZ.
*/
- static void sync_from_steppers();
+ static float get_axis_position_mm(const AxisEnum axis);
+
+ // SCARA AB axes are in degrees, not mm
+ #if IS_SCARA
+ FORCE_INLINE static float get_axis_position_degrees(const AxisEnum axis) { return get_axis_position_mm(axis); }
+ #endif
+
+ // Called to force a quick stop of the machine (for example, when an emergency
+ // stop is required, or when endstops are hit)
+ static void quick_stop();
+
+ // Called when an endstop is triggered. Causes the machine to stop inmediately
+ static void endstop_triggered(const AxisEnum axis);
+
+ // Triggered position of an axis in mm (not core-savvy)
+ static float triggered_position_mm(const AxisEnum axis);
+
+ // Block until all buffered steps are executed / cleaned
+ static void synchronize();
+
+ // Wait for moves to finish and disable all steppers
+ static void finish_and_disable();
+
+ // Periodic tick to handle cleaning timeouts
+ // Called from the Temperature ISR at ~1kHz
+ static void tick() {
+ if (cleaning_buffer_counter) {
+ --cleaning_buffer_counter;
+ #if ENABLED(SD_FINISHED_STEPPERRELEASE) && defined(SD_FINISHED_RELEASECOMMAND)
+ if (!cleaning_buffer_counter) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
+ #endif
+ }
+ }
/**
* Does the buffer have any blocks queued?
*/
- static inline bool has_blocks_queued() { return (block_buffer_head != block_buffer_tail); }
-
- /**
- * "Discard" the block and "release" the memory.
- * Called when the current block is no longer needed.
- */
- FORCE_INLINE static void discard_current_block() {
- if (has_blocks_queued())
- block_buffer_tail = BLOCK_MOD(block_buffer_tail + 1);
- }
-
- /**
- * "Discard" the next block if it's continued.
- * Called after an interrupted move to throw away the rest of the move.
- */
- FORCE_INLINE static bool discard_continued_block() {
- const bool discard = has_blocks_queued() && TEST(block_buffer[block_buffer_tail].flag, BLOCK_BIT_CONTINUED);
- if (discard) discard_current_block();
- return discard;
- }
+ FORCE_INLINE static bool has_blocks_queued() { return (block_buffer_head != block_buffer_tail); }
/**
* The current block. NULL if the buffer is empty.
@@ -542,38 +643,71 @@ class Planner {
* WARNING: Called from Stepper ISR context!
*/
static block_t* get_current_block() {
- if (has_blocks_queued()) {
+
+ // Get the number of moves in the planner queue so far
+ const uint8_t nr_moves = movesplanned();
+
+ // If there are any moves queued ...
+ if (nr_moves) {
+
+ // If there is still delay of delivery of blocks running, decrement it
+ if (delay_before_delivering) {
+ --delay_before_delivering;
+ // If the number of movements queued is less than 3, and there is still time
+ // to wait, do not deliver anything
+ if (nr_moves < 3 && delay_before_delivering) return NULL;
+ delay_before_delivering = 0;
+ }
+
+ // If we are here, there is no excuse to deliver the block
block_t * const block = &block_buffer[block_buffer_tail];
- // If the block has no trapezoid calculated, it's unsafe to execute.
- if (movesplanned() > 1) {
- const block_t * const next = &block_buffer[next_block_index(block_buffer_tail)];
- if (TEST(block->flag, BLOCK_BIT_RECALCULATE) || TEST(next->flag, BLOCK_BIT_RECALCULATE))
- return NULL;
- }
- else if (TEST(block->flag, BLOCK_BIT_RECALCULATE))
- return NULL;
+ // No trapezoid calculated? Don't execute yet.
+ if (TEST(block->flag, BLOCK_BIT_RECALCULATE)) return NULL;
#if ENABLED(ULTRA_LCD)
block_buffer_runtime_us -= block->segment_time_us; // We can't be sure how long an active block will take, so don't count it.
#endif
- SBI(block->flag, BLOCK_BIT_BUSY);
+
+ // As this block is busy, advance the nonbusy block pointer
+ block_buffer_nonbusy = next_block_index(block_buffer_tail);
+
+ // Push block_buffer_planned pointer, if encountered.
+ if (block_buffer_tail == block_buffer_planned)
+ block_buffer_planned = block_buffer_nonbusy;
+
+ // Return the block
return block;
}
- else {
- #if ENABLED(ULTRA_LCD)
- clear_block_buffer_runtime(); // paranoia. Buffer is empty now - so reset accumulated time to zero.
- #endif
- return NULL;
- }
+
+ // The queue became empty
+ #if ENABLED(ULTRA_LCD)
+ clear_block_buffer_runtime(); // paranoia. Buffer is empty now - so reset accumulated time to zero.
+ #endif
+
+ return NULL;
+ }
+
+ /**
+ * "Discard" the block and "release" the memory.
+ * Called when the current block is no longer needed.
+ * NB: There MUST be a current block to call this function!!
+ */
+ FORCE_INLINE static void discard_current_block() {
+ if (has_blocks_queued())
+ block_buffer_tail = next_block_index(block_buffer_tail);
}
#if ENABLED(ULTRA_LCD)
static uint16_t block_buffer_runtime() {
- CRITICAL_SECTION_START
- millis_t bbru = block_buffer_runtime_us;
- CRITICAL_SECTION_END
+ bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+
+ millis_t bbru = block_buffer_runtime_us;
+
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
+
// To translate µs to ms a division by 1000 would be required.
// We introduce 2.4% error here by dividing by 1024.
// Doesn't matter because block_buffer_runtime_us is already too small an estimation.
@@ -584,9 +718,12 @@ class Planner {
}
static void clear_block_buffer_runtime() {
- CRITICAL_SECTION_START
- block_buffer_runtime_us = 0;
- CRITICAL_SECTION_END
+ bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+
+ block_buffer_runtime_us = 0;
+
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
}
#endif
@@ -598,13 +735,27 @@ class Planner {
static void autotemp_M104_M109();
#endif
+ #if ENABLED(JUNCTION_DEVIATION)
+ FORCE_INLINE static void recalculate_max_e_jerk() {
+ #define GET_MAX_E_JERK(N) SQRT(SQRT(0.5) * junction_deviation_mm * (N) * RECIPROCAL(1.0 - SQRT(0.5)))
+ #if ENABLED(LIN_ADVANCE)
+ #if ENABLED(DISTINCT_E_FACTORS)
+ for (uint8_t i = 0; i < EXTRUDERS; i++)
+ max_e_jerk[i] = GET_MAX_E_JERK(max_acceleration_mm_per_s2[E_AXIS + i]);
+ #else
+ max_e_jerk = GET_MAX_E_JERK(max_acceleration_mm_per_s2[E_AXIS]);
+ #endif
+ #endif
+ }
+ #endif
+
private:
/**
* Get the index of the next / previous block in the ring buffer
*/
- static constexpr int8_t next_block_index(const int8_t block_index) { return BLOCK_MOD(block_index + 1); }
- static constexpr int8_t prev_block_index(const int8_t block_index) { return BLOCK_MOD(block_index - 1); }
+ static constexpr uint8_t next_block_index(const uint8_t block_index) { return BLOCK_MOD(block_index + 1); }
+ static constexpr uint8_t prev_block_index(const uint8_t block_index) { return BLOCK_MOD(block_index - 1); }
/**
* Calculate the distance (not time) it takes to accelerate
@@ -629,18 +780,27 @@ class Planner {
}
/**
- * Calculate the maximum allowable speed at this point, in order
- * to reach 'target_velocity' using 'acceleration' within a given
+ * Calculate the maximum allowable speed squared at this point, in order
+ * to reach 'target_velocity_sqr' using 'acceleration' within a given
* 'distance'.
*/
- static float max_allowable_speed(const float &accel, const float &target_velocity, const float &distance) {
- return SQRT(sq(target_velocity) - 2 * accel * distance);
+ static float max_allowable_speed_sqr(const float &accel, const float &target_velocity_sqr, const float &distance) {
+ return target_velocity_sqr - 2 * accel * distance;
}
+ #if ENABLED(S_CURVE_ACCELERATION)
+ /**
+ * Calculate the speed reached given initial speed, acceleration and distance
+ */
+ static float final_speed(const float &initial_velocity, const float &accel, const float &distance) {
+ return SQRT(sq(initial_velocity) + 2 * accel * distance);
+ }
+ #endif
+
static void calculate_trapezoid_for_block(block_t* const block, const float &entry_factor, const float &exit_factor);
static void reverse_pass_kernel(block_t* const current, const block_t * const next);
- static void forward_pass_kernel(const block_t * const previous, block_t* const current);
+ static void forward_pass_kernel(const block_t * const previous, block_t* const current, uint8_t block_index);
static void reverse_pass();
static void forward_pass();
@@ -649,9 +809,26 @@ class Planner {
static void recalculate();
+ #if ENABLED(JUNCTION_DEVIATION)
+
+ FORCE_INLINE static void normalize_junction_vector(float (&vector)[XYZE]) {
+ float magnitude_sq = 0;
+ LOOP_XYZE(idx) if (vector[idx]) magnitude_sq += sq(vector[idx]);
+ const float inv_magnitude = RSQRT(magnitude_sq);
+ LOOP_XYZE(idx) vector[idx] *= inv_magnitude;
+ }
+
+ FORCE_INLINE static float limit_value_by_axis_maximum(const float &max_value, float (&unit_vec)[XYZE]) {
+ float limit_value = max_value;
+ LOOP_XYZE(idx) if (unit_vec[idx]) // Avoid divide by zero
+ NOMORE(limit_value, ABS(max_acceleration_mm_per_s2[idx] / unit_vec[idx]));
+ return limit_value;
+ }
+
+ #endif // JUNCTION_DEVIATION
};
-#define PLANNER_XY_FEEDRATE() (min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]))
+#define PLANNER_XY_FEEDRATE() (MIN(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]))
extern Planner planner;
diff --git a/Marlin/planner_bezier.cpp b/Marlin/planner_bezier.cpp
index 4686c571eb..fdb4bab86b 100644
--- a/Marlin/planner_bezier.cpp
+++ b/Marlin/planner_bezier.cpp
@@ -37,13 +37,12 @@
#include "Marlin.h"
// See the meaning in the documentation of cubic_b_spline().
-#define MIN_STEP 0.002
-#define MAX_STEP 0.1
-#define SIGMA 0.1
+#define MIN_STEP 0.002f
+#define MAX_STEP 0.1f
+#define SIGMA 0.1f
-/* Compute the linear interpolation between to real numbers.
-*/
-inline static float interp(float a, float b, float t) { return (1.0 - t) * a + t * b; }
+// Compute the linear interpolation between two real numbers.
+inline static float interp(float a, float b, float t) { return (1.0f - t) * a + t * b; }
/**
* Compute a Bézier curve using the De Casteljau's algorithm (see
@@ -65,7 +64,7 @@ inline static float eval_bezier(float a, float b, float c, float d, float t) {
* We approximate Euclidean distance with the sum of the coordinates
* offset (so-called "norm 1"), which is quicker to compute.
*/
-inline static float dist1(float x1, float y1, float x2, float y2) { return FABS(x1 - x2) + FABS(y1 - y2); }
+inline static float dist1(float x1, float y1, float x2, float y2) { return ABS(x1 - x2) + ABS(y1 - y2); }
/**
* The algorithm for computing the step is loosely based on the one in Kig
@@ -112,7 +111,7 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
first1 = position[Y_AXIS] + offset[1],
second0 = target[X_AXIS] + offset[2],
second1 = target[Y_AXIS] + offset[3];
- float t = 0.0;
+ float t = 0;
float bez_target[4];
bez_target[X_AXIS] = position[X_AXIS];
@@ -121,7 +120,7 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
millis_t next_idle_ms = millis() + 200UL;
- while (t < 1.0) {
+ while (t < 1) {
thermalManager.manage_heater();
millis_t now = millis();
@@ -134,16 +133,16 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
// close to a linear interpolation.
bool did_reduce = false;
float new_t = t + step;
- NOMORE(new_t, 1.0);
+ NOMORE(new_t, 1);
float new_pos0 = eval_bezier(position[X_AXIS], first0, second0, target[X_AXIS], new_t),
new_pos1 = eval_bezier(position[Y_AXIS], first1, second1, target[Y_AXIS], new_t);
for (;;) {
if (new_t - t < (MIN_STEP)) break;
- const float candidate_t = 0.5 * (t + new_t),
+ const float candidate_t = 0.5f * (t + new_t),
candidate_pos0 = eval_bezier(position[X_AXIS], first0, second0, target[X_AXIS], candidate_t),
candidate_pos1 = eval_bezier(position[Y_AXIS], first1, second1, target[Y_AXIS], candidate_t),
- interp_pos0 = 0.5 * (bez_target[X_AXIS] + new_pos0),
- interp_pos1 = 0.5 * (bez_target[Y_AXIS] + new_pos1);
+ interp_pos0 = 0.5f * (bez_target[X_AXIS] + new_pos0),
+ interp_pos1 = 0.5f * (bez_target[Y_AXIS] + new_pos1);
if (dist1(candidate_pos0, candidate_pos1, interp_pos0, interp_pos1) <= (SIGMA)) break;
new_t = candidate_t;
new_pos0 = candidate_pos0;
@@ -154,12 +153,12 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
// If we did not reduce the step, maybe we should enlarge it.
if (!did_reduce) for (;;) {
if (new_t - t > MAX_STEP) break;
- const float candidate_t = t + 2.0 * (new_t - t);
- if (candidate_t >= 1.0) break;
+ const float candidate_t = t + 2 * (new_t - t);
+ if (candidate_t >= 1) break;
const float candidate_pos0 = eval_bezier(position[X_AXIS], first0, second0, target[X_AXIS], candidate_t),
candidate_pos1 = eval_bezier(position[Y_AXIS], first1, second1, target[Y_AXIS], candidate_t),
- interp_pos0 = 0.5 * (bez_target[X_AXIS] + candidate_pos0),
- interp_pos1 = 0.5 * (bez_target[Y_AXIS] + candidate_pos1);
+ interp_pos0 = 0.5f * (bez_target[X_AXIS] + candidate_pos0),
+ interp_pos1 = 0.5f * (bez_target[Y_AXIS] + candidate_pos1);
if (dist1(new_pos0, new_pos1, interp_pos0, interp_pos1) > (SIGMA)) break;
new_t = candidate_t;
new_pos0 = candidate_pos0;
@@ -188,7 +187,16 @@ void cubic_b_spline(const float position[NUM_AXIS], const float target[NUM_AXIS]
bez_target[Z_AXIS] = interp(position[Z_AXIS], target[Z_AXIS], t);
bez_target[E_AXIS] = interp(position[E_AXIS], target[E_AXIS], t);
clamp_to_software_endstops(bez_target);
- planner.buffer_line_kinematic(bez_target, fr_mm_s, extruder);
+
+ #if HAS_UBL_AND_CURVES
+ float pos[XYZ] = { bez_target[X_AXIS], bez_target[Y_AXIS], bez_target[Z_AXIS] };
+ planner.apply_leveling(pos);
+ if (!planner.buffer_segment(pos[X_AXIS], pos[Y_AXIS], pos[Z_AXIS], bez_target[E_AXIS], fr_mm_s, active_extruder))
+ break;
+ #else
+ if (!planner.buffer_line_kinematic(bez_target, fr_mm_s, extruder))
+ break;
+ #endif
}
}
diff --git a/Marlin/power.cpp b/Marlin/power.cpp
index dbe2ff1dc2..df0579153a 100644
--- a/Marlin/power.cpp
+++ b/Marlin/power.cpp
@@ -49,8 +49,10 @@ bool Power::is_power_needed() {
if (controllerFanSpeed > 0) return true;
#endif
- if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON ||
- thermalManager.soft_pwm_amount_bed > 0
+ if (X_ENABLE_READ == X_ENABLE_ON || Y_ENABLE_READ == Y_ENABLE_ON || Z_ENABLE_READ == Z_ENABLE_ON
+ #if HAS_HEATED_BED
+ || thermalManager.soft_pwm_amount_bed > 0
+ #endif
|| E0_ENABLE_READ == E_ENABLE_ON // If any of the drivers are enabled...
#if E_STEPPERS > 1
|| E1_ENABLE_READ == E_ENABLE_ON
diff --git a/Marlin/power_loss_recovery.cpp b/Marlin/power_loss_recovery.cpp
index 5b5948b924..8534fd8fe0 100644
--- a/Marlin/power_loss_recovery.cpp
+++ b/Marlin/power_loss_recovery.cpp
@@ -42,58 +42,76 @@ job_recovery_info_t job_recovery_info;
JobRecoveryPhase job_recovery_phase = JOB_RECOVERY_IDLE;
uint8_t job_recovery_commands_count; //=0
char job_recovery_commands[BUFSIZE + APPEND_CMD_COUNT][MAX_CMD_SIZE];
-
// Extern
-extern uint8_t commands_in_queue, cmd_queue_index_r;
-
-// Private
-static char sd_filename[MAXPATHNAMELENGTH];
+extern uint8_t active_extruder, commands_in_queue, cmd_queue_index_r;
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
void debug_print_job_recovery(const bool recovery) {
- SERIAL_PROTOCOLPAIR("valid_head:", (int)job_recovery_info.valid_head);
- SERIAL_PROTOCOLLNPAIR(" valid_foot:", (int)job_recovery_info.valid_foot);
+ SERIAL_PROTOCOLLNPGM("---- Job Recovery Info ----");
+ SERIAL_PROTOCOLPAIR("valid_head:", int(job_recovery_info.valid_head));
+ SERIAL_PROTOCOLLNPAIR(" valid_foot:", int(job_recovery_info.valid_foot));
if (job_recovery_info.valid_head) {
if (job_recovery_info.valid_head == job_recovery_info.valid_foot) {
- SERIAL_PROTOCOLPGM("current_position");
- LOOP_XYZE(i) SERIAL_PROTOCOLPAIR(": ", job_recovery_info.current_position[i]);
+ SERIAL_PROTOCOLPGM("current_position: ");
+ LOOP_XYZE(i) {
+ SERIAL_PROTOCOL(job_recovery_info.current_position[i]);
+ if (i < E_AXIS) SERIAL_CHAR(',');
+ }
SERIAL_EOL();
SERIAL_PROTOCOLLNPAIR("feedrate: ", job_recovery_info.feedrate);
- SERIAL_PROTOCOLPGM("target_temperature");
- HOTEND_LOOP() SERIAL_PROTOCOLPAIR(": ", job_recovery_info.target_temperature[e]);
- SERIAL_EOL();
- SERIAL_PROTOCOLPGM("fanSpeeds");
- for(uint8_t i = 0; i < FAN_COUNT; i++) SERIAL_PROTOCOLPAIR(": ", job_recovery_info.fanSpeeds[i]);
+
+ #if HOTENDS > 1
+ SERIAL_PROTOCOLLNPAIR("active_hotend: ", int(job_recovery_info.active_hotend));
+ #endif
+
+ SERIAL_PROTOCOLPGM("target_temperature: ");
+ HOTEND_LOOP() {
+ SERIAL_PROTOCOL(job_recovery_info.target_temperature[e]);
+ if (e < HOTENDS - 1) SERIAL_CHAR(',');
+ }
SERIAL_EOL();
+
+ #if HAS_HEATED_BED
+ SERIAL_PROTOCOLLNPAIR("target_temperature_bed: ", job_recovery_info.target_temperature_bed);
+ #endif
+
+ #if FAN_COUNT
+ SERIAL_PROTOCOLPGM("fanSpeeds: ");
+ for (int8_t i = 0; i < FAN_COUNT; i++) {
+ SERIAL_PROTOCOL(job_recovery_info.fanSpeeds[i]);
+ if (i < FAN_COUNT - 1) SERIAL_CHAR(',');
+ }
+ SERIAL_EOL();
+ #endif
+
#if HAS_LEVELING
SERIAL_PROTOCOLPAIR("leveling: ", int(job_recovery_info.leveling));
SERIAL_PROTOCOLLNPAIR(" fade: ", int(job_recovery_info.fade));
#endif
- #if HAS_HEATED_BED
- SERIAL_PROTOCOLLNPAIR("target_temperature_bed: ", job_recovery_info.target_temperature_bed);
- #endif
- SERIAL_PROTOCOLLNPAIR("cmd_queue_index_r: ", job_recovery_info.cmd_queue_index_r);
- SERIAL_PROTOCOLLNPAIR("commands_in_queue: ", job_recovery_info.commands_in_queue);
+ SERIAL_PROTOCOLLNPAIR("cmd_queue_index_r: ", int(job_recovery_info.cmd_queue_index_r));
+ SERIAL_PROTOCOLLNPAIR("commands_in_queue: ", int(job_recovery_info.commands_in_queue));
if (recovery)
for (uint8_t i = 0; i < job_recovery_commands_count; i++) SERIAL_PROTOCOLLNPAIR("> ", job_recovery_commands[i]);
else
for (uint8_t i = 0; i < job_recovery_info.commands_in_queue; i++) SERIAL_PROTOCOLLNPAIR("> ", job_recovery_info.command_queue[i]);
- SERIAL_PROTOCOLLNPAIR("sd_filename: ", sd_filename);
+ SERIAL_PROTOCOLLNPAIR("sd_filename: ", job_recovery_info.sd_filename);
SERIAL_PROTOCOLLNPAIR("sdpos: ", job_recovery_info.sdpos);
SERIAL_PROTOCOLLNPAIR("print_job_elapsed: ", job_recovery_info.print_job_elapsed);
}
else
SERIAL_PROTOCOLLNPGM("INVALID DATA");
}
+ SERIAL_PROTOCOLLNPGM("---------------------------");
}
#endif // DEBUG_POWER_LOSS_RECOVERY
/**
- * Check for Print Job Recovery
- * If the file has a saved state, populate the job_recovery_commands queue
+ * Check for Print Job Recovery during setup()
+ *
+ * If a saved state exists, populate job_recovery_commands with
+ * commands to restore the machine state and continue the file.
*/
-void do_print_job_recovery() {
- //if (job_recovery_commands_count > 0) return;
+void check_print_job_recovery() {
memset(&job_recovery_info, 0, sizeof(job_recovery_info));
ZERO(job_recovery_commands);
@@ -102,7 +120,7 @@ void do_print_job_recovery() {
if (card.cardOK) {
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
- SERIAL_PROTOCOLLNPAIR("Init job recovery info. Size: ", (int)sizeof(job_recovery_info));
+ SERIAL_PROTOCOLLNPAIR("Init job recovery info. Size: ", int(sizeof(job_recovery_info)));
#endif
if (card.jobRecoverFileExists()) {
@@ -122,18 +140,24 @@ void do_print_job_recovery() {
strcpy_P(job_recovery_commands[ind++], PSTR("G92.0 Z0")); // Ensure Z is equal to 0
strcpy_P(job_recovery_commands[ind++], PSTR("G1 Z2")); // Raise Z by 2mm (we hope!)
strcpy_P(job_recovery_commands[ind++], PSTR("G28 R0"
- #if !IS_KINEMATIC
+ #if ENABLED(MARLIN_DEV_MODE)
+ " S"
+ #elif !IS_KINEMATIC
" X Y" // Home X and Y for Cartesian
#endif
));
+ char str_1[16], str_2[16];
+
#if HAS_LEVELING
- // Restore leveling state before G92 sets Z
- // This ensures the steppers correspond to the native Z
- sprintf_P(job_recovery_commands[ind++], PSTR("M420 S%i Z%s"), int(job_recovery_info.leveling), job_recovery_info.fade);
+ if (job_recovery_info.fade || job_recovery_info.leveling) {
+ // Restore leveling state before G92 sets Z
+ // This ensures the steppers correspond to the native Z
+ dtostrf(job_recovery_info.fade, 1, 1, str_1);
+ sprintf_P(job_recovery_commands[ind++], PSTR("M420 S%i Z%s"), int(job_recovery_info.leveling), str_1);
+ }
#endif
- char str_1[16], str_2[16];
dtostrf(job_recovery_info.current_position[Z_AXIS] + 2, 1, 3, str_1);
dtostrf(job_recovery_info.current_position[E_AXIS]
#if ENABLED(SAVE_EACH_CMD_MODE)
@@ -143,23 +167,21 @@ void do_print_job_recovery() {
);
sprintf_P(job_recovery_commands[ind++], PSTR("G92.0 Z%s E%s"), str_1, str_2); // Current Z + 2 and E
- strcpy_P(job_recovery_commands[ind++], PSTR("M117 Continuing..."));
-
- uint8_t r = job_recovery_info.cmd_queue_index_r;
- while (job_recovery_info.commands_in_queue) {
+ uint8_t r = job_recovery_info.cmd_queue_index_r, c = job_recovery_info.commands_in_queue;
+ while (c--) {
strcpy(job_recovery_commands[ind++], job_recovery_info.command_queue[r]);
- job_recovery_info.commands_in_queue--;
r = (r + 1) % BUFSIZE;
}
+ if (job_recovery_info.sd_filename[0] == '/') job_recovery_info.sd_filename[0] = ' ';
+ sprintf_P(job_recovery_commands[ind++], PSTR("M23 %s"), job_recovery_info.sd_filename);
+ sprintf_P(job_recovery_commands[ind++], PSTR("M24 S%ld T%ld"), job_recovery_info.sdpos, job_recovery_info.print_job_elapsed);
+
job_recovery_commands_count = ind;
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
debug_print_job_recovery(true);
#endif
-
- card.openFile(sd_filename, true);
- card.setIndex(job_recovery_info.sdpos);
}
else {
if (job_recovery_info.valid_head != job_recovery_info.valid_foot)
@@ -171,7 +193,7 @@ void do_print_job_recovery() {
}
/**
- * Save the current machine state to the "bin" file
+ * Save the current machine state to the power-loss recovery file
*/
void save_job_recovery_info() {
#if SAVE_INFO_INTERVAL_MS > 0
@@ -199,11 +221,20 @@ void save_job_recovery_info() {
// Machine state
COPY(job_recovery_info.current_position, current_position);
job_recovery_info.feedrate = feedrate_mm_s;
+
+ #if HOTENDS > 1
+ job_recovery_info.active_hotend = active_extruder;
+ #endif
+
COPY(job_recovery_info.target_temperature, thermalManager.target_temperature);
+
#if HAS_HEATED_BED
job_recovery_info.target_temperature_bed = thermalManager.target_temperature_bed;
#endif
- COPY(job_recovery_info.fanSpeeds, fanSpeeds);
+
+ #if FAN_COUNT
+ COPY(job_recovery_info.fanSpeeds, fanSpeeds);
+ #endif
#if HAS_LEVELING
job_recovery_info.leveling = planner.leveling_active;
@@ -222,14 +253,14 @@ void save_job_recovery_info() {
COPY(job_recovery_info.command_queue, command_queue);
// Elapsed print job time
- job_recovery_info.print_job_elapsed = print_job_timer.duration() * 1000UL;
+ job_recovery_info.print_job_elapsed = print_job_timer.duration();
// SD file position
- card.getAbsFilename(sd_filename);
+ card.getAbsFilename(job_recovery_info.sd_filename);
job_recovery_info.sdpos = card.getIndex();
#if ENABLED(DEBUG_POWER_LOSS_RECOVERY)
- SERIAL_PROTOCOLLNPGM("Saving job_recovery_info");
+ SERIAL_PROTOCOLLNPGM("Saving...");
debug_print_job_recovery(false);
#endif
diff --git a/Marlin/power_loss_recovery.h b/Marlin/power_loss_recovery.h
index f693b5f9ba..5f25d2c5b3 100644
--- a/Marlin/power_loss_recovery.h
+++ b/Marlin/power_loss_recovery.h
@@ -40,13 +40,21 @@ typedef struct {
// Machine state
float current_position[NUM_AXIS], feedrate;
- int16_t target_temperature[HOTENDS],
- fanSpeeds[FAN_COUNT];
+
+ #if HOTENDS > 1
+ uint8_t active_hotend;
+ #endif
+
+ int16_t target_temperature[HOTENDS];
#if HAS_HEATED_BED
int16_t target_temperature_bed;
#endif
+ #if FAN_COUNT
+ int16_t fanSpeeds[FAN_COUNT];
+ #endif
+
#if HAS_LEVELING
bool leveling;
float fade;
@@ -56,7 +64,8 @@ typedef struct {
uint8_t cmd_queue_index_r, commands_in_queue;
char command_queue[BUFSIZE][MAX_CMD_SIZE];
- // SD File position
+ // SD Filename and position
+ char sd_filename[MAXPATHNAMELENGTH];
uint32_t sdpos;
// Job elapsed time
@@ -70,20 +79,21 @@ extern job_recovery_info_t job_recovery_info;
enum JobRecoveryPhase : unsigned char {
JOB_RECOVERY_IDLE,
JOB_RECOVERY_MAYBE,
- JOB_RECOVERY_YES
+ JOB_RECOVERY_YES,
+ JOB_RECOVERY_DONE
};
extern JobRecoveryPhase job_recovery_phase;
#if HAS_LEVELING
- #define APPEND_CMD_COUNT 7
+ #define APPEND_CMD_COUNT 9
#else
- #define APPEND_CMD_COUNT 5
+ #define APPEND_CMD_COUNT 7
#endif
extern char job_recovery_commands[BUFSIZE + APPEND_CMD_COUNT][MAX_CMD_SIZE];
extern uint8_t job_recovery_commands_count;
-void do_print_job_recovery();
+void check_print_job_recovery();
void save_job_recovery_info();
#endif // _POWER_LOSS_RECOVERY_H_
diff --git a/Marlin/printcounter.cpp b/Marlin/printcounter.cpp
index 25212cde4e..d1de7d1754 100644
--- a/Marlin/printcounter.cpp
+++ b/Marlin/printcounter.cpp
@@ -60,7 +60,7 @@ millis_t PrintCounter::deltaDuration() {
return lastDuration - tmp;
}
-void PrintCounter::incFilamentUsed(double const &amount) {
+void PrintCounter::incFilamentUsed(float const &amount) {
#if ENABLED(DEBUG_PRINTCOUNTER)
debug(PSTR("incFilamentUsed"));
#endif
diff --git a/Marlin/printcounter.h b/Marlin/printcounter.h
index 89c61cb2e9..848d9715b8 100644
--- a/Marlin/printcounter.h
+++ b/Marlin/printcounter.h
@@ -31,20 +31,20 @@
#include "stopwatch.h"
#include
-struct printStatistics { // 16 bytes (20 with real doubles)
+struct printStatistics { // 16 bytes
//const uint8_t magic; // Magic header, it will always be 0x16
uint16_t totalPrints; // Number of prints
uint16_t finishedPrints; // Number of complete prints
uint32_t printTime; // Accumulated printing time
uint32_t longestPrint; // Longest successful print job
- double filamentUsed; // Accumulated filament consumed in mm
+ float filamentUsed; // Accumulated filament consumed in mm
};
class PrintCounter: public Stopwatch {
private:
typedef Stopwatch super;
- #if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM) || defined(CPU_32_BIT)
+ #if ENABLED(I2C_EEPROM) || ENABLED(SPI_EEPROM)
typedef uint32_t promdress;
#else
typedef uint16_t promdress;
@@ -122,7 +122,7 @@ class PrintCounter: public Stopwatch {
*
* @param amount The amount of filament used in mm
*/
- static void incFilamentUsed(double const &amount);
+ static void incFilamentUsed(float const &amount);
/**
* @brief Reset the Print Statistics
diff --git a/Marlin/runout.h b/Marlin/runout.h
index d94c21ef64..c4c88b6c15 100644
--- a/Marlin/runout.h
+++ b/Marlin/runout.h
@@ -48,7 +48,7 @@ class FilamentRunoutSensor {
if ((IS_SD_PRINTING || print_job_timer.isRunning()) && check() && !filament_ran_out) {
filament_ran_out = true;
enqueue_and_echo_commands_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
- stepper.synchronize();
+ planner.synchronize();
}
}
private:
diff --git a/Marlin/serial.h b/Marlin/serial.h
index dc1da87353..139f99c110 100644
--- a/Marlin/serial.h
+++ b/Marlin/serial.h
@@ -25,7 +25,10 @@
#include "MarlinConfig.h"
-#if defined(__AVR__) && defined(USBCON)
+#if USE_MARLINSERIAL
+ #include "MarlinSerial.h"
+ #define MYSERIAL0 customizedSerial
+#else
#include
#if ENABLED(BLUETOOTH)
extern HardwareSerial bluetoothSerial;
@@ -33,9 +36,6 @@
#else
#define MYSERIAL0 Serial
#endif // BLUETOOTH
-#else
- #include "MarlinSerial.h"
- #define MYSERIAL0 customizedSerial
#endif
extern const char echomagic[] PROGMEM;
diff --git a/Marlin/servo.cpp b/Marlin/servo.cpp
index 7a1c2b8c60..e1d11573ab 100644
--- a/Marlin/servo.cpp
+++ b/Marlin/servo.cpp
@@ -259,7 +259,7 @@ int8_t Servo::attach(const int pin, const int min, const int max) {
if (pin > 0) servo_info[this->servoIndex].Pin.nbr = pin;
pinMode(servo_info[this->servoIndex].Pin.nbr, OUTPUT); // set servo pin to output
- // todo min/max check: abs(min - MIN_PULSE_WIDTH) /4 < 128
+ // todo min/max check: ABS(min - MIN_PULSE_WIDTH) /4 < 128
this->min = (MIN_PULSE_WIDTH - min) / 4; //resolution of min/max is 4 uS
this->max = (MAX_PULSE_WIDTH - max) / 4;
diff --git a/Marlin/status_screen_DOGM.h b/Marlin/status_screen_DOGM.h
index 98431feda8..038351cc81 100644
--- a/Marlin/status_screen_DOGM.h
+++ b/Marlin/status_screen_DOGM.h
@@ -62,7 +62,7 @@ FORCE_INLINE void _draw_heater_status(const uint8_t x, const int8_t heater, cons
if (blink || !is_idle)
#endif
- _draw_centered_temp(0.5 + (
+ _draw_centered_temp(0.5f + (
#if HAS_HEATED_BED
isBed ? thermalManager.degTargetBed() :
#endif
@@ -71,8 +71,8 @@ FORCE_INLINE void _draw_heater_status(const uint8_t x, const int8_t heater, cons
);
}
- if (PAGE_CONTAINS(21, 28))
- _draw_centered_temp(0.5 + (
+ if (PAGE_CONTAINS(21, 28)) {
+ _draw_centered_temp(0.5f + (
#if HAS_HEATED_BED
isBed ? thermalManager.degBed() :
#endif
@@ -80,37 +80,43 @@ FORCE_INLINE void _draw_heater_status(const uint8_t x, const int8_t heater, cons
), x, 28
);
- if (PAGE_CONTAINS(17, 20)) {
- const uint8_t h = isBed ? 7 : HEAT_INDICATOR_X,
- y = isBed ? 18 : 17;
- if (
- #if HAS_HEATED_BED
- isBed ? thermalManager.isHeatingBed() :
- #endif
- thermalManager.isHeatingHotend(heater)
- ) {
- u8g.setColorIndex(0); // white on black
- u8g.drawBox(x + h, y, 2, 2);
- u8g.setColorIndex(1); // black on white
+ if (PAGE_CONTAINS(17, 20)) {
+ const uint8_t h = isBed ? 7 : HEAT_INDICATOR_X,
+ y = isBed ? 18 : 17;
+ if (
+ #if HAS_HEATED_BED
+ isBed ? thermalManager.isHeatingBed() :
+ #endif
+ thermalManager.isHeatingHotend(heater)
+ ) {
+ u8g.setColorIndex(0); // white on black
+ u8g.drawBox(x + h, y, 2, 2);
+ u8g.setColorIndex(1); // black on white
+ }
+ else
+ u8g.drawBox(x + h, y, 2, 2);
}
- else
- u8g.drawBox(x + h, y, 2, 2);
}
}
-FORCE_INLINE void _draw_axis_label(const AxisEnum axis, const char* const pstr, const bool blink) {
+//
+// Before homing, blink '123' <-> '???'.
+// Homed but unknown... '123' <-> ' '.
+// Homed and known, display constantly.
+//
+FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
if (blink)
- lcd_printPGM(pstr);
+ lcd_print(value);
else {
- if (!axis_homed[axis])
- u8g.print('?');
+ if (!TEST(axis_homed, axis))
+ while (const char c = *value++) lcd_print(c <= '.' ? c : '?');
else {
#if DISABLED(HOME_AFTER_DEACTIVATE) && DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
- if (!axis_known_position[axis])
- u8g.print(' ');
+ if (!TEST(axis_known_position, axis))
+ lcd_printPGM(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
else
#endif
- lcd_printPGM(pstr);
+ lcd_print(value);
}
}
}
@@ -118,36 +124,75 @@ FORCE_INLINE void _draw_axis_label(const AxisEnum axis, const char* const pstr,
inline void lcd_implementation_status_message(const bool blink) {
#if ENABLED(STATUS_MESSAGE_SCROLLING)
static bool last_blink = false;
- const uint8_t slen = lcd_strlen(lcd_status_message);
- const char *stat = lcd_status_message + status_scroll_pos;
- if (slen <= LCD_WIDTH)
- lcd_print_utf(stat); // The string isn't scrolling
+
+ // Get the UTF8 character count of the string
+ uint8_t slen = lcd_strlen(lcd_status_message);
+
+ // If the string fits into the LCD, just print it and do not scroll it
+ if (slen <= LCD_WIDTH) {
+
+ // The string isn't scrolling and may not fill the screen
+ lcd_print_utf(lcd_status_message);
+
+ // Fill the rest with spaces
+ while (slen < LCD_WIDTH) {
+ u8g.print(' ');
+ ++slen;
+ }
+ }
else {
- if (status_scroll_pos <= slen - LCD_WIDTH)
- lcd_print_utf(stat); // The string fills the screen
+ // String is larger than the available space in screen.
+
+ // Get a pointer to the next valid UTF8 character
+ const char *stat = lcd_status_message + status_scroll_offset;
+
+ // Get the string remaining length
+ const uint8_t rlen = lcd_strlen(stat);
+
+ // If we have enough characters to display
+ if (rlen >= LCD_WIDTH) {
+ // The remaining string fills the screen - Print it
+ lcd_print_utf(stat, LCD_WIDTH);
+ }
else {
- uint8_t chars = LCD_WIDTH;
- if (status_scroll_pos < slen) { // First string still visible
- lcd_print_utf(stat); // The string leaves space
- chars -= slen - status_scroll_pos; // Amount of space left
- }
- u8g.print('.'); // Always at 1+ spaces left, draw a dot
- if (--chars) {
- if (status_scroll_pos < slen + 1) // Draw a second dot if there's space
- --chars, u8g.print('.');
- if (chars) lcd_print_utf(lcd_status_message, chars); // Print a second copy of the message
+ // The remaining string does not completely fill the screen
+ lcd_print_utf(stat, LCD_WIDTH); // The string leaves space
+ uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters
+
+ u8g.print('.'); // Always at 1+ spaces left, draw a dot
+ if (--chars) { // Draw a second dot if there's space
+ u8g.print('.');
+ if (--chars) // Print a second copy of the message
+ lcd_print_utf(lcd_status_message, LCD_WIDTH - (rlen + 2));
}
}
- if (last_blink != blink) {
- last_blink = blink;
- // Skip any non-printing bytes
- if (status_scroll_pos < slen) while (!PRINTABLE(lcd_status_message[status_scroll_pos])) status_scroll_pos++;
- if (++status_scroll_pos >= slen + 2) status_scroll_pos = 0;
+ if (last_blink != blink) {
+ last_blink = blink;
+
+ // Adjust by complete UTF8 characters
+ if (status_scroll_offset < slen) {
+ status_scroll_offset++;
+ while (!START_OF_UTF8_CHAR(lcd_status_message[status_scroll_offset]))
+ status_scroll_offset++;
+ }
+ else
+ status_scroll_offset = 0;
}
}
#else
UNUSED(blink);
- lcd_print_utf(lcd_status_message);
+
+ // Get the UTF8 character count of the string
+ uint8_t slen = lcd_strlen(lcd_status_message);
+
+ // Just print the string to the LCD
+ lcd_print_utf(lcd_status_message, LCD_WIDTH);
+
+ // Fill the rest with spaces if there are missing spaces
+ while (slen < LCD_WIDTH) {
+ u8g.print(' ');
+ ++slen;
+ }
#endif
}
@@ -220,7 +265,7 @@ static void lcd_implementation_status_screen() {
#endif
#if HAS_FAN0
- if (PAGE_CONTAINS(20, 27)) {
+ if (PAGE_CONTAINS(STATUS_SCREEN_FAN_TEXT_Y - 7, STATUS_SCREEN_FAN_TEXT_Y)) {
// Fan
const int16_t per = ((fanSpeeds[0] + 1) * 100) / 256;
if (per) {
@@ -330,10 +375,6 @@ static void lcd_implementation_status_screen() {
#define XYZ_FRAME_HEIGHT INFO_FONT_HEIGHT + 1
#endif
- // Before homing the axis letters are blinking 'X' <-> '?'.
- // When axis is homed but axis_known_position is false the axis letters are blinking 'X' <-> ' '.
- // When everything is ok you see a constant 'X'.
-
static char xstring[5], ystring[5], zstring[7];
#if ENABLED(FILAMENT_LCD_DISPLAY)
static char wstring[5], mstring[4];
@@ -343,7 +384,7 @@ static void lcd_implementation_status_screen() {
if (page.page == 0) {
strcpy(xstring, ftostr4sign(LOGICAL_X_POSITION(current_position[X_AXIS])));
strcpy(ystring, ftostr4sign(LOGICAL_Y_POSITION(current_position[Y_AXIS])));
- strcpy(zstring, ftostr52sp(FIXFLOAT(LOGICAL_Z_POSITION(current_position[Z_AXIS]))));
+ strcpy(zstring, ftostr52sp(LOGICAL_Z_POSITION(current_position[Z_AXIS])));
#if ENABLED(FILAMENT_LCD_DISPLAY)
strcpy(wstring, ftostr12ns(filament_width_meas));
strcpy(mstring, itostr3(100.0 * (
@@ -370,19 +411,19 @@ static void lcd_implementation_status_screen() {
#endif
u8g.setPrintPos(0 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
- _draw_axis_label(X_AXIS, PSTR(MSG_X), blink);
+ lcd_printPGM(PSTR(MSG_X));
u8g.setPrintPos(0 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
- lcd_print(xstring);
+ _draw_axis_value(X_AXIS, xstring, blink);
u8g.setPrintPos(1 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
- _draw_axis_label(Y_AXIS, PSTR(MSG_Y), blink);
+ lcd_printPGM(PSTR(MSG_Y));
u8g.setPrintPos(1 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
- lcd_print(ystring);
+ _draw_axis_value(Y_AXIS, ystring, blink);
u8g.setPrintPos(2 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
- _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
+ lcd_printPGM(PSTR(MSG_Z));
u8g.setPrintPos(2 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
- lcd_print(zstring);
+ _draw_axis_value(Z_AXIS, zstring, blink);
#if DISABLED(XYZ_HOLLOW_FRAME)
u8g.setColorIndex(1); // black on white
diff --git a/Marlin/status_screen_lite_ST7920.h b/Marlin/status_screen_lite_ST7920.h
index 987aba4f76..2acb6a9736 100644
--- a/Marlin/status_screen_lite_ST7920.h
+++ b/Marlin/status_screen_lite_ST7920.h
@@ -615,36 +615,71 @@ void ST7920_Lite_Status_Screen::draw_feedrate_percentage(const uint8_t percentag
void ST7920_Lite_Status_Screen::draw_status_message(const char *str) {
set_ddram_address(DDRAM_LINE_4);
begin_data();
+ const uint8_t lcd_len = 16;
#if ENABLED(STATUS_MESSAGE_SCROLLING)
- const uint8_t lcd_len = 16;
- const uint8_t padding = 2;
- uint8_t str_len = strlen(str);
- // Trim whitespace at the end of the str, as for some reason
- // messages like "Card Inserted" are padded with many spaces
- while (str_len && str[str_len - 1] == ' ') str_len--;
+ uint8_t slen = lcd_strlen(str);
- if (str_len <= lcd_len) {
- // It all fits on the LCD without scrolling
+ // If the string fits into the LCD, just print it and do not scroll it
+ if (slen <= lcd_len) {
+
+ // The string isn't scrolling and may not fill the screen
write_str(str);
+
+ // Fill the rest with spaces
+ while (slen < lcd_len) {
+ write_byte(' ');
+ ++slen;
+ }
}
else {
- // Print the message repeatedly until covering the LCD
- uint8_t c = status_scroll_pos;
- for (uint8_t n = 0; n < lcd_len; n++) {
- write_byte(c < str_len ? str[c] : ' ');
- c++;
- c %= str_len + padding; // Wrap around
+ // String is larger than the available space in screen.
+
+ // Get a pointer to the next valid UTF8 character
+ const char *stat = str + status_scroll_offset;
+
+ // Get the string remaining length
+ const uint8_t rlen = lcd_strlen(stat);
+
+ // If we have enough characters to display
+ if (rlen >= lcd_len) {
+ // The remaining string fills the screen - Print it
+ write_str(stat, lcd_len);
+ }
+ else {
+ // The remaining string does not completely fill the screen
+ write_str(stat); // The string leaves space
+ uint8_t chars = lcd_len - rlen; // Amount of space left in characters
+
+ write_byte('.'); // Always at 1+ spaces left, draw a dot
+ if (--chars) { // Draw a second dot if there's space
+ write_byte('.');
+ if (--chars)
+ write_str(str, chars); // Print a second copy of the message
+ }
}
- // Scroll the message
- if (status_scroll_pos == str_len + padding)
- status_scroll_pos = 0;
+ // Adjust by complete UTF8 characters
+ if (status_scroll_offset < slen) {
+ status_scroll_offset++;
+ while (!START_OF_UTF8_CHAR(str[status_scroll_offset]))
+ status_scroll_offset++;
+ }
else
- status_scroll_pos++;
+ status_scroll_offset = 0;
}
#else
- write_str(str, 16);
+ // Get the UTF8 character count of the string
+ uint8_t slen = lcd_strlen(str);
+
+ // Just print the string to the LCD
+ write_str(str, lcd_len);
+
+ // Fill the rest with spaces if there are missing spaces
+ while (slen < lcd_len) {
+ write_byte(' ');
+ ++slen;
+ }
#endif
}
@@ -792,7 +827,7 @@ void ST7920_Lite_Status_Screen::update_status_or_position(bool forceUpdate) {
*/
if (forceUpdate || status_changed()) {
#if ENABLED(STATUS_MESSAGE_SCROLLING)
- status_scroll_pos = 0;
+ status_scroll_offset = 0;
#endif
#if STATUS_EXPIRE_SECONDS
countdown = lcd_status_message[0] ? STATUS_EXPIRE_SECONDS : 0;
@@ -833,9 +868,7 @@ void ST7920_Lite_Status_Screen::update_status_or_position(bool forceUpdate) {
#if ENABLED(DISABLE_REDUCED_ACCURACY_WARNING)
true
#else
- axis_known_position[X_AXIS] &&
- axis_known_position[Y_AXIS] &&
- axis_known_position[Z_AXIS]
+ all_axes_known()
#endif
);
}
diff --git a/Marlin/status_screen_lite_ST7920_class.h b/Marlin/status_screen_lite_ST7920_class.h
index 75cede08ca..289723479a 100644
--- a/Marlin/status_screen_lite_ST7920_class.h
+++ b/Marlin/status_screen_lite_ST7920_class.h
@@ -18,7 +18,7 @@
#define STATUS_SCREEN_LITE_ST7920_CLASS_H
#include "macros.h"
-#include "duration.h"
+#include "duration_t.h"
typedef const __FlashStringHelper *progmem_str;
diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp
index 92ad80700e..8c965c45da 100644
--- a/Marlin/stepper.cpp
+++ b/Marlin/stepper.cpp
@@ -41,8 +41,41 @@
* along with Grbl. If not, see .
*/
-/* The timer calculations of this module informed by the 'RepRap cartesian firmware' by Zack Smith
- and Philipp Tiefenbacher. */
+/**
+ * Timer calculations informed by the 'RepRap cartesian firmware' by Zack Smith
+ * and Philipp Tiefenbacher.
+ */
+
+/**
+ * __________________________
+ * /| |\ _________________ ^
+ * / | | \ /| |\ |
+ * / | | \ / | | \ s
+ * / | | | | | \ p
+ * / | | | | | \ e
+ * +-----+------------------------+---+--+---------------+----+ e
+ * | BLOCK 1 | BLOCK 2 | d
+ *
+ * time ----->
+ *
+ * The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
+ * first block->accelerate_until step_events_completed, then keeps going at constant speed until
+ * step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
+ * The slope of acceleration is calculated using v = u + at where t is the accumulated timer values of the steps so far.
+ */
+
+/**
+ * Marlin uses the Bresenham algorithm. For a detailed explanation of theory and
+ * method see https://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresenh.html
+ */
+
+/**
+ * Jerk controlled movements planner added Apr 2018 by Eduardo José Tagle.
+ * Equations based on Synthethos TinyG2 sources, but the fixed-point
+ * implementation is new, as we are running the ISR with a variable period.
+ * Also implemented the Bézier velocity curve evaluation in ARM assembler,
+ * to avoid impacting ISR speed.
+ */
#include "Marlin.h"
#include "stepper.h"
@@ -53,6 +86,7 @@
#include "language.h"
#include "cardreader.h"
#include "speed_lookuptable.h"
+#include "delay.h"
#if HAS_DIGIPOTSS
#include
@@ -62,14 +96,8 @@ Stepper stepper; // Singleton
// public:
-block_t* Stepper::current_block = NULL; // A pointer to the block currently being traced
-
-#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
- bool Stepper::abort_on_endstop_hit = false;
-#endif
-
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
- bool Stepper::performing_homing = false;
+ bool Stepper::homing_dual_axis = false;
#endif
#if HAS_MOTOR_CURRENT_PWM
@@ -78,88 +106,104 @@ block_t* Stepper::current_block = NULL; // A pointer to the block currently bei
// private:
-uint8_t Stepper::last_direction_bits = 0; // The next stepping-bits to be output
-int16_t Stepper::cleaning_buffer_counter = 0;
+block_t* Stepper::current_block = NULL; // A pointer to the block currently being traced
+
+uint8_t Stepper::last_direction_bits = 0,
+ Stepper::axis_did_move;
+
+bool Stepper::abort_current_block;
+
+#if DISABLED(MIXING_EXTRUDER)
+ uint8_t Stepper::last_moved_extruder = 0xFF;
+#endif
#if ENABLED(X_DUAL_ENDSTOPS)
- bool Stepper::locked_x_motor = false, Stepper::locked_x2_motor = false;
+ bool Stepper::locked_X_motor = false, Stepper::locked_X2_motor = false;
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
- bool Stepper::locked_y_motor = false, Stepper::locked_y2_motor = false;
+ bool Stepper::locked_Y_motor = false, Stepper::locked_Y2_motor = false;
#endif
#if ENABLED(Z_DUAL_ENDSTOPS)
- bool Stepper::locked_z_motor = false, Stepper::locked_z2_motor = false;
+ bool Stepper::locked_Z_motor = false, Stepper::locked_Z2_motor = false;
#endif
-long Stepper::counter_X = 0,
- Stepper::counter_Y = 0,
- Stepper::counter_Z = 0,
- Stepper::counter_E = 0;
+uint32_t Stepper::acceleration_time, Stepper::deceleration_time;
+uint8_t Stepper::steps_per_isr;
-volatile uint32_t Stepper::step_events_completed = 0; // The number of step events executed in the current block
+#if DISABLED(ADAPTIVE_STEP_SMOOTHING)
+ constexpr
+#endif
+ uint8_t Stepper::oversampling_factor;
+
+int32_t Stepper::delta_error[XYZE] = { 0 };
+
+uint32_t Stepper::advance_dividend[XYZE] = { 0 },
+ Stepper::advance_divisor = 0,
+ Stepper::step_events_completed = 0, // The number of step events executed in the current block
+ Stepper::accelerate_until, // The point from where we need to stop acceleration
+ Stepper::decelerate_after, // The point from where we need to start decelerating
+ Stepper::step_event_count; // The total event count for the current block
+
+#if ENABLED(MIXING_EXTRUDER)
+ int32_t Stepper::delta_error_m[MIXING_STEPPERS];
+ uint32_t Stepper::advance_dividend_m[MIXING_STEPPERS],
+ Stepper::advance_divisor_m;
+#else
+ int8_t Stepper::active_extruder; // Active extruder
+#endif
+
+#if ENABLED(S_CURVE_ACCELERATION)
+ int32_t __attribute__((used)) Stepper::bezier_A __asm__("bezier_A"); // A coefficient in Bézier speed curve with alias for assembler
+ int32_t __attribute__((used)) Stepper::bezier_B __asm__("bezier_B"); // B coefficient in Bézier speed curve with alias for assembler
+ int32_t __attribute__((used)) Stepper::bezier_C __asm__("bezier_C"); // C coefficient in Bézier speed curve with alias for assembler
+ uint32_t __attribute__((used)) Stepper::bezier_F __asm__("bezier_F"); // F coefficient in Bézier speed curve with alias for assembler
+ uint32_t __attribute__((used)) Stepper::bezier_AV __asm__("bezier_AV"); // AV coefficient in Bézier speed curve with alias for assembler
+ bool __attribute__((used)) Stepper::A_negative __asm__("A_negative"); // If A coefficient was negative
+ bool Stepper::bezier_2nd_half; // =false If Bézier curve has been initialized or not
+#endif
+
+uint32_t Stepper::nextMainISR = 0;
#if ENABLED(LIN_ADVANCE)
- uint32_t Stepper::LA_decelerate_after;
+ constexpr uint32_t LA_ADV_NEVER = 0xFFFFFFFF;
+ uint32_t Stepper::nextAdvanceISR = LA_ADV_NEVER,
+ Stepper::LA_isr_rate = LA_ADV_NEVER;
+ uint16_t Stepper::LA_current_adv_steps = 0,
+ Stepper::LA_final_adv_steps,
+ Stepper::LA_max_adv_steps;
- constexpr uint16_t ADV_NEVER = 65535;
+ int8_t Stepper::LA_steps = 0;
- uint16_t Stepper::nextMainISR = 0,
- Stepper::nextAdvanceISR = ADV_NEVER,
- Stepper::eISR_Rate = ADV_NEVER,
- Stepper::current_adv_steps = 0,
- Stepper::final_adv_steps,
- Stepper::max_adv_steps;
-
- int8_t Stepper::e_steps = 0;
-
- #if E_STEPPERS > 1
- int8_t Stepper::LA_active_extruder; // Copy from current executed block. Needed because current_block is set to NULL "too early".
- #else
- constexpr int8_t Stepper::LA_active_extruder;
- #endif
-
- bool Stepper::use_advance_lead;
+ bool Stepper::LA_use_advance_lead;
#endif // LIN_ADVANCE
-long Stepper::acceleration_time, Stepper::deceleration_time;
-
-volatile long Stepper::count_position[NUM_AXIS] = { 0 };
-volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
-
-#if ENABLED(MIXING_EXTRUDER)
- long Stepper::counter_m[MIXING_STEPPERS];
+int32_t Stepper::ticks_nominal = -1;
+#if DISABLED(S_CURVE_ACCELERATION)
+ uint32_t Stepper::acc_step_rate; // needed for deceleration start point
#endif
-uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
+volatile int32_t Stepper::endstops_trigsteps[XYZ];
-uint16_t Stepper::OCR1A_nominal,
- Stepper::acc_step_rate; // needed for deceleration start point
-
-volatile long Stepper::endstops_trigsteps[XYZ];
+volatile int32_t Stepper::count_position[NUM_AXIS] = { 0 };
+int8_t Stepper::count_direction[NUM_AXIS] = { 0, 0, 0, 0 };
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
- #define LOCKED_X_MOTOR locked_x_motor
- #define LOCKED_Y_MOTOR locked_y_motor
- #define LOCKED_Z_MOTOR locked_z_motor
- #define LOCKED_X2_MOTOR locked_x2_motor
- #define LOCKED_Y2_MOTOR locked_y2_motor
- #define LOCKED_Z2_MOTOR locked_z2_motor
- #define DUAL_ENDSTOP_APPLY_STEP(AXIS,v) \
- if (performing_homing) { \
- if (AXIS##_HOME_DIR < 0) { \
- if (!(TEST(endstops.old_endstop_bits, AXIS##_MIN) && count_direction[AXIS##_AXIS] < 0) && !LOCKED_##AXIS##_MOTOR) AXIS##_STEP_WRITE(v); \
- if (!(TEST(endstops.old_endstop_bits, AXIS##2_MIN) && count_direction[AXIS##_AXIS] < 0) && !LOCKED_##AXIS##2_MOTOR) AXIS##2_STEP_WRITE(v); \
- } \
- else { \
- if (!(TEST(endstops.old_endstop_bits, AXIS##_MAX) && count_direction[AXIS##_AXIS] > 0) && !LOCKED_##AXIS##_MOTOR) AXIS##_STEP_WRITE(v); \
- if (!(TEST(endstops.old_endstop_bits, AXIS##2_MAX) && count_direction[AXIS##_AXIS] > 0) && !LOCKED_##AXIS##2_MOTOR) AXIS##2_STEP_WRITE(v); \
- } \
- } \
- else { \
- AXIS##_STEP_WRITE(v); \
- AXIS##2_STEP_WRITE(v); \
+ #define DUAL_ENDSTOP_APPLY_STEP(A,V) \
+ if (homing_dual_axis) { \
+ if (A##_HOME_DIR < 0) { \
+ if (!(TEST(endstops.state(), A##_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \
+ if (!(TEST(endstops.state(), A##2_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \
+ } \
+ else { \
+ if (!(TEST(endstops.state(), A##_MAX) && count_direction[_AXIS(A)] > 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \
+ if (!(TEST(endstops.state(), A##2_MAX) && count_direction[_AXIS(A)] > 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \
+ } \
+ } \
+ else { \
+ A##_STEP_WRITE(V); \
+ A##2_STEP_WRITE(V); \
}
#endif
@@ -177,7 +221,7 @@ volatile long Stepper::endstops_trigsteps[XYZ];
X2_DIR_WRITE(v); \
} \
else { \
- if (current_block->active_extruder) X2_DIR_WRITE(v); else X_DIR_WRITE(v); \
+ if (movement_extruder()) X2_DIR_WRITE(v); else X_DIR_WRITE(v); \
}
#define X_APPLY_STEP(v,ALWAYS) \
if (extruder_duplication_enabled || ALWAYS) { \
@@ -185,7 +229,7 @@ volatile long Stepper::endstops_trigsteps[XYZ];
X2_STEP_WRITE(v); \
} \
else { \
- if (current_block->active_extruder) X2_STEP_WRITE(v); else X_STEP_WRITE(v); \
+ if (movement_extruder()) X2_STEP_WRITE(v); else X_STEP_WRITE(v); \
}
#else
#define X_APPLY_DIR(v,Q) X_DIR_WRITE(v)
@@ -217,84 +261,69 @@ volatile long Stepper::endstops_trigsteps[XYZ];
#endif
#if DISABLED(MIXING_EXTRUDER)
- #define E_APPLY_STEP(v,Q) E_STEP_WRITE(v)
+ #define E_APPLY_STEP(v,Q) E_STEP_WRITE(active_extruder, v)
#endif
// intRes = longIn1 * longIn2 >> 24
// uses:
-// r26 to store 0
-// r27 to store bits 16-23 of the 48bit result. The top bit is used to round the two byte result.
+// A[tmp] to store 0
+// B[tmp] to store bits 16-23 of the 48bit result. The top bit is used to round the two byte result.
// note that the lower two bytes and the upper byte of the 48bit result are not calculated.
// this can cause the result to be out by one as the lower bytes may cause carries into the upper ones.
-// B0 A0 are bits 24-39 and are the returned value
-// C1 B1 A1 is longIn1
-// D2 C2 B2 A2 is longIn2
+// B A are bits 24-39 and are the returned value
+// C B A is longIn1
+// D C B A is longIn2
//
-#define MultiU24X32toH16(intRes, longIn1, longIn2) \
- asm volatile ( \
- "clr r26 \n\t" \
- "mul %A1, %B2 \n\t" \
- "mov r27, r1 \n\t" \
- "mul %B1, %C2 \n\t" \
- "movw %A0, r0 \n\t" \
- "mul %C1, %C2 \n\t" \
- "add %B0, r0 \n\t" \
- "mul %C1, %B2 \n\t" \
- "add %A0, r0 \n\t" \
- "adc %B0, r1 \n\t" \
- "mul %A1, %C2 \n\t" \
- "add r27, r0 \n\t" \
- "adc %A0, r1 \n\t" \
- "adc %B0, r26 \n\t" \
- "mul %B1, %B2 \n\t" \
- "add r27, r0 \n\t" \
- "adc %A0, r1 \n\t" \
- "adc %B0, r26 \n\t" \
- "mul %C1, %A2 \n\t" \
- "add r27, r0 \n\t" \
- "adc %A0, r1 \n\t" \
- "adc %B0, r26 \n\t" \
- "mul %B1, %A2 \n\t" \
- "add r27, r1 \n\t" \
- "adc %A0, r26 \n\t" \
- "adc %B0, r26 \n\t" \
- "lsr r27 \n\t" \
- "adc %A0, r26 \n\t" \
- "adc %B0, r26 \n\t" \
- "mul %D2, %A1 \n\t" \
- "add %A0, r0 \n\t" \
- "adc %B0, r1 \n\t" \
- "mul %D2, %B1 \n\t" \
- "add %B0, r0 \n\t" \
- "clr r1 \n\t" \
- : \
- "=&r" (intRes) \
- : \
- "d" (longIn1), \
- "d" (longIn2) \
- : \
- "r26" , "r27" \
- )
+static FORCE_INLINE uint16_t MultiU24X32toH16(uint32_t longIn1, uint32_t longIn2) {
+ register uint8_t tmp1;
+ register uint8_t tmp2;
+ register uint16_t intRes;
+ __asm__ __volatile__(
+ A("clr %[tmp1]")
+ A("mul %A[longIn1], %B[longIn2]")
+ A("mov %[tmp2], r1")
+ A("mul %B[longIn1], %C[longIn2]")
+ A("movw %A[intRes], r0")
+ A("mul %C[longIn1], %C[longIn2]")
+ A("add %B[intRes], r0")
+ A("mul %C[longIn1], %B[longIn2]")
+ A("add %A[intRes], r0")
+ A("adc %B[intRes], r1")
+ A("mul %A[longIn1], %C[longIn2]")
+ A("add %[tmp2], r0")
+ A("adc %A[intRes], r1")
+ A("adc %B[intRes], %[tmp1]")
+ A("mul %B[longIn1], %B[longIn2]")
+ A("add %[tmp2], r0")
+ A("adc %A[intRes], r1")
+ A("adc %B[intRes], %[tmp1]")
+ A("mul %C[longIn1], %A[longIn2]")
+ A("add %[tmp2], r0")
+ A("adc %A[intRes], r1")
+ A("adc %B[intRes], %[tmp1]")
+ A("mul %B[longIn1], %A[longIn2]")
+ A("add %[tmp2], r1")
+ A("adc %A[intRes], %[tmp1]")
+ A("adc %B[intRes], %[tmp1]")
+ A("lsr %[tmp2]")
+ A("adc %A[intRes], %[tmp1]")
+ A("adc %B[intRes], %[tmp1]")
+ A("mul %D[longIn2], %A[longIn1]")
+ A("add %A[intRes], r0")
+ A("adc %B[intRes], r1")
+ A("mul %D[longIn2], %B[longIn1]")
+ A("add %B[intRes], r0")
+ A("clr r1")
+ : [intRes] "=&r" (intRes),
+ [tmp1] "=&r" (tmp1),
+ [tmp2] "=&r" (tmp2)
+ : [longIn1] "d" (longIn1),
+ [longIn2] "d" (longIn2)
+ : "cc"
+ );
+ return intRes;
+}
-// Some useful constants
-
-/**
- * __________________________
- * /| |\ _________________ ^
- * / | | \ /| |\ |
- * / | | \ / | | \ s
- * / | | | | | \ p
- * / | | | | | \ e
- * +-----+------------------------+---+--+---------------+----+ e
- * | BLOCK 1 | BLOCK 2 | d
- *
- * time ----->
- *
- * The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
- * first block->accelerate_until step_events_completed, then keeps going at constant speed until
- * step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
- * The slope of acceleration is calculated using v = u + at where t is the accumulated timer values of the steps so far.
- */
void Stepper::wake_up() {
// TCNT1 = 0;
ENABLE_STEPPER_DRIVER_INTERRUPT();
@@ -309,14 +338,14 @@ void Stepper::wake_up() {
*/
void Stepper::set_directions() {
- #define SET_STEP_DIR(AXIS) \
- if (motor_direction(AXIS ##_AXIS)) { \
- AXIS ##_APPLY_DIR(INVERT_## AXIS ##_DIR, false); \
- count_direction[AXIS ##_AXIS] = -1; \
+ #define SET_STEP_DIR(A) \
+ if (motor_direction(_AXIS(A))) { \
+ A##_APPLY_DIR(INVERT_## A##_DIR, false); \
+ count_direction[_AXIS(A)] = -1; \
} \
else { \
- AXIS ##_APPLY_DIR(!INVERT_## AXIS ##_DIR, false); \
- count_direction[AXIS ##_AXIS] = 1; \
+ A##_APPLY_DIR(!INVERT_## A##_DIR, false); \
+ count_direction[_AXIS(A)] = 1; \
}
#if HAS_X_DIR
@@ -330,260 +359,949 @@ void Stepper::set_directions() {
#endif
#if DISABLED(LIN_ADVANCE)
- if (motor_direction(E_AXIS)) {
- REV_E_DIR();
- count_direction[E_AXIS] = -1;
- }
- else {
- NORM_E_DIR();
- count_direction[E_AXIS] = 1;
- }
+ #if ENABLED(MIXING_EXTRUDER)
+ if (motor_direction(E_AXIS)) {
+ MIXING_STEPPERS_LOOP(j) REV_E_DIR(j);
+ count_direction[E_AXIS] = -1;
+ }
+ else {
+ MIXING_STEPPERS_LOOP(j) NORM_E_DIR(j);
+ count_direction[E_AXIS] = 1;
+ }
+ #else
+ if (motor_direction(E_AXIS)) {
+ REV_E_DIR(active_extruder);
+ count_direction[E_AXIS] = -1;
+ }
+ else {
+ NORM_E_DIR(active_extruder);
+ count_direction[E_AXIS] = 1;
+ }
+ #endif
#endif // !LIN_ADVANCE
+
+ // A small delay may be needed after changing direction
+ #if MINIMUM_STEPPER_DIR_DELAY > 0
+ DELAY_NS(MINIMUM_STEPPER_DIR_DELAY);
+ #endif
}
-#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
- extern volatile uint8_t e_hit;
-#endif
+#if ENABLED(S_CURVE_ACCELERATION)
+ /**
+ * This uses a quintic (fifth-degree) Bézier polynomial for the velocity curve, giving
+ * a "linear pop" velocity curve; with pop being the sixth derivative of position:
+ * velocity - 1st, acceleration - 2nd, jerk - 3rd, snap - 4th, crackle - 5th, pop - 6th
+ *
+ * The Bézier curve takes the form:
+ *
+ * V(t) = P_0 * B_0(t) + P_1 * B_1(t) + P_2 * B_2(t) + P_3 * B_3(t) + P_4 * B_4(t) + P_5 * B_5(t)
+ *
+ * Where 0 <= t <= 1, and V(t) is the velocity. P_0 through P_5 are the control points, and B_0(t)
+ * through B_5(t) are the Bernstein basis as follows:
+ *
+ * B_0(t) = (1-t)^5 = -t^5 + 5t^4 - 10t^3 + 10t^2 - 5t + 1
+ * B_1(t) = 5(1-t)^4 * t = 5t^5 - 20t^4 + 30t^3 - 20t^2 + 5t
+ * B_2(t) = 10(1-t)^3 * t^2 = -10t^5 + 30t^4 - 30t^3 + 10t^2
+ * B_3(t) = 10(1-t)^2 * t^3 = 10t^5 - 20t^4 + 10t^3
+ * B_4(t) = 5(1-t) * t^4 = -5t^5 + 5t^4
+ * B_5(t) = t^5 = t^5
+ * ^ ^ ^ ^ ^ ^
+ * | | | | | |
+ * A B C D E F
+ *
+ * Unfortunately, we cannot use forward-differencing to calculate each position through
+ * the curve, as Marlin uses variable timer periods. So, we require a formula of the form:
+ *
+ * V_f(t) = A*t^5 + B*t^4 + C*t^3 + D*t^2 + E*t + F
+ *
+ * Looking at the above B_0(t) through B_5(t) expanded forms, if we take the coefficients of t^5
+ * through t of the Bézier form of V(t), we can determine that:
+ *
+ * A = -P_0 + 5*P_1 - 10*P_2 + 10*P_3 - 5*P_4 + P_5
+ * B = 5*P_0 - 20*P_1 + 30*P_2 - 20*P_3 + 5*P_4
+ * C = -10*P_0 + 30*P_1 - 30*P_2 + 10*P_3
+ * D = 10*P_0 - 20*P_1 + 10*P_2
+ * E = - 5*P_0 + 5*P_1
+ * F = P_0
+ *
+ * Now, since we will (currently) *always* want the initial acceleration and jerk values to be 0,
+ * We set P_i = P_0 = P_1 = P_2 (initial velocity), and P_t = P_3 = P_4 = P_5 (target velocity),
+ * which, after simplification, resolves to:
+ *
+ * A = - 6*P_i + 6*P_t = 6*(P_t - P_i)
+ * B = 15*P_i - 15*P_t = 15*(P_i - P_t)
+ * C = -10*P_i + 10*P_t = 10*(P_t - P_i)
+ * D = 0
+ * E = 0
+ * F = P_i
+ *
+ * As the t is evaluated in non uniform steps here, there is no other way rather than evaluating
+ * the Bézier curve at each point:
+ *
+ * V_f(t) = A*t^5 + B*t^4 + C*t^3 + F [0 <= t <= 1]
+ *
+ * Floating point arithmetic execution time cost is prohibitive, so we will transform the math to
+ * use fixed point values to be able to evaluate it in realtime. Assuming a maximum of 250000 steps
+ * per second (driver pulses should at least be 2µS hi/2µS lo), and allocating 2 bits to avoid
+ * overflows on the evaluation of the Bézier curve, means we can use
+ *
+ * t: unsigned Q0.32 (0 <= t < 1) |range 0 to 0xFFFFFFFF unsigned
+ * A: signed Q24.7 , |range = +/- 250000 * 6 * 128 = +/- 192000000 = 0x0B71B000 | 28 bits + sign
+ * B: signed Q24.7 , |range = +/- 250000 *15 * 128 = +/- 480000000 = 0x1C9C3800 | 29 bits + sign
+ * C: signed Q24.7 , |range = +/- 250000 *10 * 128 = +/- 320000000 = 0x1312D000 | 29 bits + sign
+ * F: signed Q24.7 , |range = +/- 250000 * 128 = 32000000 = 0x01E84800 | 25 bits + sign
+ *
+ * The trapezoid generator state contains the following information, that we will use to create and evaluate
+ * the Bézier curve:
+ *
+ * blk->step_event_count [TS] = The total count of steps for this movement. (=distance)
+ * blk->initial_rate [VI] = The initial steps per second (=velocity)
+ * blk->final_rate [VF] = The ending steps per second (=velocity)
+ * and the count of events completed (step_events_completed) [CS] (=distance until now)
+ *
+ * Note the abbreviations we use in the following formulae are between []s
+ *
+ * For Any 32bit CPU:
+ *
+ * At the start of each trapezoid, calculate the coefficients A,B,C,F and Advance [AV], as follows:
+ *
+ * A = 6*128*(VF - VI) = 768*(VF - VI)
+ * B = 15*128*(VI - VF) = 1920*(VI - VF)
+ * C = 10*128*(VF - VI) = 1280*(VF - VI)
+ * F = 128*VI = 128*VI
+ * AV = (1<<32)/TS ~= 0xFFFFFFFF / TS (To use ARM UDIV, that is 32 bits) (this is computed at the planner, to offload expensive calculations from the ISR)
+ *
+ * And for each point, evaluate the curve with the following sequence:
+ *
+ * void lsrs(uint32_t& d, uint32_t s, int cnt) {
+ * d = s >> cnt;
+ * }
+ * void lsls(uint32_t& d, uint32_t s, int cnt) {
+ * d = s << cnt;
+ * }
+ * void lsrs(int32_t& d, uint32_t s, int cnt) {
+ * d = uint32_t(s) >> cnt;
+ * }
+ * void lsls(int32_t& d, uint32_t s, int cnt) {
+ * d = uint32_t(s) << cnt;
+ * }
+ * void umull(uint32_t& rlo, uint32_t& rhi, uint32_t op1, uint32_t op2) {
+ * uint64_t res = uint64_t(op1) * op2;
+ * rlo = uint32_t(res & 0xFFFFFFFF);
+ * rhi = uint32_t((res >> 32) & 0xFFFFFFFF);
+ * }
+ * void smlal(int32_t& rlo, int32_t& rhi, int32_t op1, int32_t op2) {
+ * int64_t mul = int64_t(op1) * op2;
+ * int64_t s = int64_t(uint32_t(rlo) | ((uint64_t(uint32_t(rhi)) << 32U)));
+ * mul += s;
+ * rlo = int32_t(mul & 0xFFFFFFFF);
+ * rhi = int32_t((mul >> 32) & 0xFFFFFFFF);
+ * }
+ * int32_t _eval_bezier_curve_arm(uint32_t curr_step) {
+ * register uint32_t flo = 0;
+ * register uint32_t fhi = bezier_AV * curr_step;
+ * register uint32_t t = fhi;
+ * register int32_t alo = bezier_F;
+ * register int32_t ahi = 0;
+ * register int32_t A = bezier_A;
+ * register int32_t B = bezier_B;
+ * register int32_t C = bezier_C;
+ *
+ * lsrs(ahi, alo, 1); // a = F << 31
+ * lsls(alo, alo, 31); //
+ * umull(flo, fhi, fhi, t); // f *= t
+ * umull(flo, fhi, fhi, t); // f>>=32; f*=t
+ * lsrs(flo, fhi, 1); //
+ * smlal(alo, ahi, flo, C); // a+=(f>>33)*C
+ * umull(flo, fhi, fhi, t); // f>>=32; f*=t
+ * lsrs(flo, fhi, 1); //
+ * smlal(alo, ahi, flo, B); // a+=(f>>33)*B
+ * umull(flo, fhi, fhi, t); // f>>=32; f*=t
+ * lsrs(flo, fhi, 1); // f>>=33;
+ * smlal(alo, ahi, flo, A); // a+=(f>>33)*A;
+ * lsrs(alo, ahi, 6); // a>>=38
+ *
+ * return alo;
+ * }
+ *
+ * This is rewritten in ARM assembly for optimal performance (43 cycles to execute).
+ *
+ * For AVR, the precision of coefficients is scaled so the Bézier curve can be evaluated in real-time:
+ * Let's reduce precision as much as possible. After some experimentation we found that:
+ *
+ * Assume t and AV with 24 bits is enough
+ * A = 6*(VF - VI)
+ * B = 15*(VI - VF)
+ * C = 10*(VF - VI)
+ * F = VI
+ * AV = (1<<24)/TS (this is computed at the planner, to offload expensive calculations from the ISR)
+ *
+ * Instead of storing sign for each coefficient, we will store its absolute value,
+ * and flag the sign of the A coefficient, so we can save to store the sign bit.
+ * It always holds that sign(A) = - sign(B) = sign(C)
+ *
+ * So, the resulting range of the coefficients are:
+ *
+ * t: unsigned (0 <= t < 1) |range 0 to 0xFFFFFF unsigned
+ * A: signed Q24 , range = 250000 * 6 = 1500000 = 0x16E360 | 21 bits
+ * B: signed Q24 , range = 250000 *15 = 3750000 = 0x393870 | 22 bits
+ * C: signed Q24 , range = 250000 *10 = 2500000 = 0x1312D0 | 21 bits
+ * F: signed Q24 , range = 250000 = 250000 = 0x0ED090 | 20 bits
+ *
+ * And for each curve, estimate its coefficients with:
+ *
+ * void _calc_bezier_curve_coeffs(int32_t v0, int32_t v1, uint32_t av) {
+ * // Calculate the Bézier coefficients
+ * if (v1 < v0) {
+ * A_negative = true;
+ * bezier_A = 6 * (v0 - v1);
+ * bezier_B = 15 * (v0 - v1);
+ * bezier_C = 10 * (v0 - v1);
+ * }
+ * else {
+ * A_negative = false;
+ * bezier_A = 6 * (v1 - v0);
+ * bezier_B = 15 * (v1 - v0);
+ * bezier_C = 10 * (v1 - v0);
+ * }
+ * bezier_F = v0;
+ * }
+ *
+ * And for each point, evaluate the curve with the following sequence:
+ *
+ * // unsigned multiplication of 24 bits x 24bits, return upper 16 bits
+ * void umul24x24to16hi(uint16_t& r, uint24_t op1, uint24_t op2) {
+ * r = (uint64_t(op1) * op2) >> 8;
+ * }
+ * // unsigned multiplication of 16 bits x 16bits, return upper 16 bits
+ * void umul16x16to16hi(uint16_t& r, uint16_t op1, uint16_t op2) {
+ * r = (uint32_t(op1) * op2) >> 16;
+ * }
+ * // unsigned multiplication of 16 bits x 24bits, return upper 24 bits
+ * void umul16x24to24hi(uint24_t& r, uint16_t op1, uint24_t op2) {
+ * r = uint24_t((uint64_t(op1) * op2) >> 16);
+ * }
+ *
+ * int32_t _eval_bezier_curve(uint32_t curr_step) {
+ * // To save computing, the first step is always the initial speed
+ * if (!curr_step)
+ * return bezier_F;
+ *
+ * uint16_t t;
+ * umul24x24to16hi(t, bezier_AV, curr_step); // t: Range 0 - 1^16 = 16 bits
+ * uint16_t f = t;
+ * umul16x16to16hi(f, f, t); // Range 16 bits (unsigned)
+ * umul16x16to16hi(f, f, t); // Range 16 bits : f = t^3 (unsigned)
+ * uint24_t acc = bezier_F; // Range 20 bits (unsigned)
+ * if (A_negative) {
+ * uint24_t v;
+ * umul16x24to24hi(v, f, bezier_C); // Range 21bits
+ * acc -= v;
+ * umul16x16to16hi(f, f, t); // Range 16 bits : f = t^4 (unsigned)
+ * umul16x24to24hi(v, f, bezier_B); // Range 22bits
+ * acc += v;
+ * umul16x16to16hi(f, f, t); // Range 16 bits : f = t^5 (unsigned)
+ * umul16x24to24hi(v, f, bezier_A); // Range 21bits + 15 = 36bits (plus sign)
+ * acc -= v;
+ * }
+ * else {
+ * uint24_t v;
+ * umul16x24to24hi(v, f, bezier_C); // Range 21bits
+ * acc += v;
+ * umul16x16to16hi(f, f, t); // Range 16 bits : f = t^4 (unsigned)
+ * umul16x24to24hi(v, f, bezier_B); // Range 22bits
+ * acc -= v;
+ * umul16x16to16hi(f, f, t); // Range 16 bits : f = t^5 (unsigned)
+ * umul16x24to24hi(v, f, bezier_A); // Range 21bits + 15 = 36bits (plus sign)
+ * acc += v;
+ * }
+ * return acc;
+ * }
+ * These functions are translated to assembler for optimal performance.
+ * Coefficient calculation takes 70 cycles. Bezier point evaluation takes 150 cycles.
+ */
+
+ // For AVR we use assembly to maximize speed
+ void Stepper::_calc_bezier_curve_coeffs(const int32_t v0, const int32_t v1, const uint32_t av) {
+
+ // Store advance
+ bezier_AV = av;
+
+ // Calculate the rest of the coefficients
+ register uint8_t r2 = v0 & 0xFF;
+ register uint8_t r3 = (v0 >> 8) & 0xFF;
+ register uint8_t r12 = (v0 >> 16) & 0xFF;
+ register uint8_t r5 = v1 & 0xFF;
+ register uint8_t r6 = (v1 >> 8) & 0xFF;
+ register uint8_t r7 = (v1 >> 16) & 0xFF;
+ register uint8_t r4,r8,r9,r10,r11;
+
+ __asm__ __volatile__(
+ /* Calculate the Bézier coefficients */
+ /* %10:%1:%0 = v0*/
+ /* %5:%4:%3 = v1*/
+ /* %7:%6:%10 = temporary*/
+ /* %9 = val (must be high register!)*/
+ /* %10 (must be high register!)*/
+
+ /* Store initial velocity*/
+ A("sts bezier_F, %0")
+ A("sts bezier_F+1, %1")
+ A("sts bezier_F+2, %10") /* bezier_F = %10:%1:%0 = v0 */
+
+ /* Get delta speed */
+ A("ldi %2,-1") /* %2 = 0xFF, means A_negative = true */
+ A("clr %8") /* %8 = 0 */
+ A("sub %0,%3")
+ A("sbc %1,%4")
+ A("sbc %10,%5") /* v0 -= v1, C=1 if result is negative */
+ A("brcc 1f") /* branch if result is positive (C=0), that means v0 >= v1 */
+
+ /* Result was negative, get the absolute value*/
+ A("com %10")
+ A("com %1")
+ A("neg %0")
+ A("sbc %1,%2")
+ A("sbc %10,%2") /* %10:%1:%0 +1 -> %10:%1:%0 = -(v0 - v1) = (v1 - v0) */
+ A("clr %2") /* %2 = 0, means A_negative = false */
+
+ /* Store negative flag*/
+ L("1")
+ A("sts A_negative, %2") /* Store negative flag */
+
+ /* Compute coefficients A,B and C [20 cycles worst case]*/
+ A("ldi %9,6") /* %9 = 6 */
+ A("mul %0,%9") /* r1:r0 = 6*LO(v0-v1) */
+ A("sts bezier_A, r0")
+ A("mov %6,r1")
+ A("clr %7") /* %7:%6:r0 = 6*LO(v0-v1) */
+ A("mul %1,%9") /* r1:r0 = 6*MI(v0-v1) */
+ A("add %6,r0")
+ A("adc %7,r1") /* %7:%6:?? += 6*MI(v0-v1) << 8 */
+ A("mul %10,%9") /* r1:r0 = 6*HI(v0-v1) */
+ A("add %7,r0") /* %7:%6:?? += 6*HI(v0-v1) << 16 */
+ A("sts bezier_A+1, %6")
+ A("sts bezier_A+2, %7") /* bezier_A = %7:%6:?? = 6*(v0-v1) [35 cycles worst] */
+
+ A("ldi %9,15") /* %9 = 15 */
+ A("mul %0,%9") /* r1:r0 = 5*LO(v0-v1) */
+ A("sts bezier_B, r0")
+ A("mov %6,r1")
+ A("clr %7") /* %7:%6:?? = 5*LO(v0-v1) */
+ A("mul %1,%9") /* r1:r0 = 5*MI(v0-v1) */
+ A("add %6,r0")
+ A("adc %7,r1") /* %7:%6:?? += 5*MI(v0-v1) << 8 */
+ A("mul %10,%9") /* r1:r0 = 5*HI(v0-v1) */
+ A("add %7,r0") /* %7:%6:?? += 5*HI(v0-v1) << 16 */
+ A("sts bezier_B+1, %6")
+ A("sts bezier_B+2, %7") /* bezier_B = %7:%6:?? = 5*(v0-v1) [50 cycles worst] */
+
+ A("ldi %9,10") /* %9 = 10 */
+ A("mul %0,%9") /* r1:r0 = 10*LO(v0-v1) */
+ A("sts bezier_C, r0")
+ A("mov %6,r1")
+ A("clr %7") /* %7:%6:?? = 10*LO(v0-v1) */
+ A("mul %1,%9") /* r1:r0 = 10*MI(v0-v1) */
+ A("add %6,r0")
+ A("adc %7,r1") /* %7:%6:?? += 10*MI(v0-v1) << 8 */
+ A("mul %10,%9") /* r1:r0 = 10*HI(v0-v1) */
+ A("add %7,r0") /* %7:%6:?? += 10*HI(v0-v1) << 16 */
+ A("sts bezier_C+1, %6")
+ " sts bezier_C+2, %7" /* bezier_C = %7:%6:?? = 10*(v0-v1) [65 cycles worst] */
+ : "+r" (r2),
+ "+d" (r3),
+ "=r" (r4),
+ "+r" (r5),
+ "+r" (r6),
+ "+r" (r7),
+ "=r" (r8),
+ "=r" (r9),
+ "=r" (r10),
+ "=d" (r11),
+ "+r" (r12)
+ :
+ : "r0", "r1", "cc", "memory"
+ );
+ }
+
+ FORCE_INLINE int32_t Stepper::_eval_bezier_curve(const uint32_t curr_step) {
+
+ // If dealing with the first step, save expensive computing and return the initial speed
+ if (!curr_step)
+ return bezier_F;
+
+ register uint8_t r0 = 0; /* Zero register */
+ register uint8_t r2 = (curr_step) & 0xFF;
+ register uint8_t r3 = (curr_step >> 8) & 0xFF;
+ register uint8_t r4 = (curr_step >> 16) & 0xFF;
+ register uint8_t r1,r5,r6,r7,r8,r9,r10,r11; /* Temporary registers */
+
+ __asm__ __volatile(
+ /* umul24x24to16hi(t, bezier_AV, curr_step); t: Range 0 - 1^16 = 16 bits*/
+ A("lds %9,bezier_AV") /* %9 = LO(AV)*/
+ A("mul %9,%2") /* r1:r0 = LO(bezier_AV)*LO(curr_step)*/
+ A("mov %7,r1") /* %7 = LO(bezier_AV)*LO(curr_step) >> 8*/
+ A("clr %8") /* %8:%7 = LO(bezier_AV)*LO(curr_step) >> 8*/
+ A("lds %10,bezier_AV+1") /* %10 = MI(AV)*/
+ A("mul %10,%2") /* r1:r0 = MI(bezier_AV)*LO(curr_step)*/
+ A("add %7,r0")
+ A("adc %8,r1") /* %8:%7 += MI(bezier_AV)*LO(curr_step)*/
+ A("lds r1,bezier_AV+2") /* r11 = HI(AV)*/
+ A("mul r1,%2") /* r1:r0 = HI(bezier_AV)*LO(curr_step)*/
+ A("add %8,r0") /* %8:%7 += HI(bezier_AV)*LO(curr_step) << 8*/
+ A("mul %9,%3") /* r1:r0 = LO(bezier_AV)*MI(curr_step)*/
+ A("add %7,r0")
+ A("adc %8,r1") /* %8:%7 += LO(bezier_AV)*MI(curr_step)*/
+ A("mul %10,%3") /* r1:r0 = MI(bezier_AV)*MI(curr_step)*/
+ A("add %8,r0") /* %8:%7 += LO(bezier_AV)*MI(curr_step) << 8*/
+ A("mul %9,%4") /* r1:r0 = LO(bezier_AV)*HI(curr_step)*/
+ A("add %8,r0") /* %8:%7 += LO(bezier_AV)*HI(curr_step) << 8*/
+ /* %8:%7 = t*/
+
+ /* uint16_t f = t;*/
+ A("mov %5,%7") /* %6:%5 = f*/
+ A("mov %6,%8")
+ /* %6:%5 = f*/
+
+ /* umul16x16to16hi(f, f, t); / Range 16 bits (unsigned) [17] */
+ A("mul %5,%7") /* r1:r0 = LO(f) * LO(t)*/
+ A("mov %9,r1") /* store MIL(LO(f) * LO(t)) in %9, we need it for rounding*/
+ A("clr %10") /* %10 = 0*/
+ A("clr %11") /* %11 = 0*/
+ A("mul %5,%8") /* r1:r0 = LO(f) * HI(t)*/
+ A("add %9,r0") /* %9 += LO(LO(f) * HI(t))*/
+ A("adc %10,r1") /* %10 = HI(LO(f) * HI(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%7") /* r1:r0 = HI(f) * LO(t)*/
+ A("add %9,r0") /* %9 += LO(HI(f) * LO(t))*/
+ A("adc %10,r1") /* %10 += HI(HI(f) * LO(t)) */
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%8") /* r1:r0 = HI(f) * HI(t)*/
+ A("add %10,r0") /* %10 += LO(HI(f) * HI(t))*/
+ A("adc %11,r1") /* %11 += HI(HI(f) * HI(t))*/
+ A("mov %5,%10") /* %6:%5 = */
+ A("mov %6,%11") /* f = %10:%11*/
+
+ /* umul16x16to16hi(f, f, t); / Range 16 bits : f = t^3 (unsigned) [17]*/
+ A("mul %5,%7") /* r1:r0 = LO(f) * LO(t)*/
+ A("mov %1,r1") /* store MIL(LO(f) * LO(t)) in %1, we need it for rounding*/
+ A("clr %10") /* %10 = 0*/
+ A("clr %11") /* %11 = 0*/
+ A("mul %5,%8") /* r1:r0 = LO(f) * HI(t)*/
+ A("add %1,r0") /* %1 += LO(LO(f) * HI(t))*/
+ A("adc %10,r1") /* %10 = HI(LO(f) * HI(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%7") /* r1:r0 = HI(f) * LO(t)*/
+ A("add %1,r0") /* %1 += LO(HI(f) * LO(t))*/
+ A("adc %10,r1") /* %10 += HI(HI(f) * LO(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%8") /* r1:r0 = HI(f) * HI(t)*/
+ A("add %10,r0") /* %10 += LO(HI(f) * HI(t))*/
+ A("adc %11,r1") /* %11 += HI(HI(f) * HI(t))*/
+ A("mov %5,%10") /* %6:%5 =*/
+ A("mov %6,%11") /* f = %10:%11*/
+ /* [15 +17*2] = [49]*/
+
+ /* %4:%3:%2 will be acc from now on*/
+
+ /* uint24_t acc = bezier_F; / Range 20 bits (unsigned)*/
+ A("clr %9") /* "decimal place we get for free"*/
+ A("lds %2,bezier_F")
+ A("lds %3,bezier_F+1")
+ A("lds %4,bezier_F+2") /* %4:%3:%2 = acc*/
+
+ /* if (A_negative) {*/
+ A("lds r0,A_negative")
+ A("or r0,%0") /* Is flag signalling negative? */
+ A("brne 3f") /* If yes, Skip next instruction if A was negative*/
+ A("rjmp 1f") /* Otherwise, jump */
+
+ /* uint24_t v; */
+ /* umul16x24to24hi(v, f, bezier_C); / Range 21bits [29] */
+ /* acc -= v; */
+ L("3")
+ A("lds %10, bezier_C") /* %10 = LO(bezier_C)*/
+ A("mul %10,%5") /* r1:r0 = LO(bezier_C) * LO(f)*/
+ A("sub %9,r1")
+ A("sbc %2,%0")
+ A("sbc %3,%0")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= HI(LO(bezier_C) * LO(f))*/
+ A("lds %11, bezier_C+1") /* %11 = MI(bezier_C)*/
+ A("mul %11,%5") /* r1:r0 = MI(bezier_C) * LO(f)*/
+ A("sub %9,r0")
+ A("sbc %2,r1")
+ A("sbc %3,%0")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= MI(bezier_C) * LO(f)*/
+ A("lds %1, bezier_C+2") /* %1 = HI(bezier_C)*/
+ A("mul %1,%5") /* r1:r0 = MI(bezier_C) * LO(f)*/
+ A("sub %2,r0")
+ A("sbc %3,r1")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= HI(bezier_C) * LO(f) << 8*/
+ A("mul %10,%6") /* r1:r0 = LO(bezier_C) * MI(f)*/
+ A("sub %9,r0")
+ A("sbc %2,r1")
+ A("sbc %3,%0")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= LO(bezier_C) * MI(f)*/
+ A("mul %11,%6") /* r1:r0 = MI(bezier_C) * MI(f)*/
+ A("sub %2,r0")
+ A("sbc %3,r1")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= MI(bezier_C) * MI(f) << 8*/
+ A("mul %1,%6") /* r1:r0 = HI(bezier_C) * LO(f)*/
+ A("sub %3,r0")
+ A("sbc %4,r1") /* %4:%3:%2:%9 -= HI(bezier_C) * LO(f) << 16*/
+
+ /* umul16x16to16hi(f, f, t); / Range 16 bits : f = t^3 (unsigned) [17]*/
+ A("mul %5,%7") /* r1:r0 = LO(f) * LO(t)*/
+ A("mov %1,r1") /* store MIL(LO(f) * LO(t)) in %1, we need it for rounding*/
+ A("clr %10") /* %10 = 0*/
+ A("clr %11") /* %11 = 0*/
+ A("mul %5,%8") /* r1:r0 = LO(f) * HI(t)*/
+ A("add %1,r0") /* %1 += LO(LO(f) * HI(t))*/
+ A("adc %10,r1") /* %10 = HI(LO(f) * HI(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%7") /* r1:r0 = HI(f) * LO(t)*/
+ A("add %1,r0") /* %1 += LO(HI(f) * LO(t))*/
+ A("adc %10,r1") /* %10 += HI(HI(f) * LO(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%8") /* r1:r0 = HI(f) * HI(t)*/
+ A("add %10,r0") /* %10 += LO(HI(f) * HI(t))*/
+ A("adc %11,r1") /* %11 += HI(HI(f) * HI(t))*/
+ A("mov %5,%10") /* %6:%5 =*/
+ A("mov %6,%11") /* f = %10:%11*/
+
+ /* umul16x24to24hi(v, f, bezier_B); / Range 22bits [29]*/
+ /* acc += v; */
+ A("lds %10, bezier_B") /* %10 = LO(bezier_B)*/
+ A("mul %10,%5") /* r1:r0 = LO(bezier_B) * LO(f)*/
+ A("add %9,r1")
+ A("adc %2,%0")
+ A("adc %3,%0")
+ A("adc %4,%0") /* %4:%3:%2:%9 += HI(LO(bezier_B) * LO(f))*/
+ A("lds %11, bezier_B+1") /* %11 = MI(bezier_B)*/
+ A("mul %11,%5") /* r1:r0 = MI(bezier_B) * LO(f)*/
+ A("add %9,r0")
+ A("adc %2,r1")
+ A("adc %3,%0")
+ A("adc %4,%0") /* %4:%3:%2:%9 += MI(bezier_B) * LO(f)*/
+ A("lds %1, bezier_B+2") /* %1 = HI(bezier_B)*/
+ A("mul %1,%5") /* r1:r0 = MI(bezier_B) * LO(f)*/
+ A("add %2,r0")
+ A("adc %3,r1")
+ A("adc %4,%0") /* %4:%3:%2:%9 += HI(bezier_B) * LO(f) << 8*/
+ A("mul %10,%6") /* r1:r0 = LO(bezier_B) * MI(f)*/
+ A("add %9,r0")
+ A("adc %2,r1")
+ A("adc %3,%0")
+ A("adc %4,%0") /* %4:%3:%2:%9 += LO(bezier_B) * MI(f)*/
+ A("mul %11,%6") /* r1:r0 = MI(bezier_B) * MI(f)*/
+ A("add %2,r0")
+ A("adc %3,r1")
+ A("adc %4,%0") /* %4:%3:%2:%9 += MI(bezier_B) * MI(f) << 8*/
+ A("mul %1,%6") /* r1:r0 = HI(bezier_B) * LO(f)*/
+ A("add %3,r0")
+ A("adc %4,r1") /* %4:%3:%2:%9 += HI(bezier_B) * LO(f) << 16*/
+
+ /* umul16x16to16hi(f, f, t); / Range 16 bits : f = t^5 (unsigned) [17]*/
+ A("mul %5,%7") /* r1:r0 = LO(f) * LO(t)*/
+ A("mov %1,r1") /* store MIL(LO(f) * LO(t)) in %1, we need it for rounding*/
+ A("clr %10") /* %10 = 0*/
+ A("clr %11") /* %11 = 0*/
+ A("mul %5,%8") /* r1:r0 = LO(f) * HI(t)*/
+ A("add %1,r0") /* %1 += LO(LO(f) * HI(t))*/
+ A("adc %10,r1") /* %10 = HI(LO(f) * HI(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%7") /* r1:r0 = HI(f) * LO(t)*/
+ A("add %1,r0") /* %1 += LO(HI(f) * LO(t))*/
+ A("adc %10,r1") /* %10 += HI(HI(f) * LO(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%8") /* r1:r0 = HI(f) * HI(t)*/
+ A("add %10,r0") /* %10 += LO(HI(f) * HI(t))*/
+ A("adc %11,r1") /* %11 += HI(HI(f) * HI(t))*/
+ A("mov %5,%10") /* %6:%5 =*/
+ A("mov %6,%11") /* f = %10:%11*/
+
+ /* umul16x24to24hi(v, f, bezier_A); / Range 21bits [29]*/
+ /* acc -= v; */
+ A("lds %10, bezier_A") /* %10 = LO(bezier_A)*/
+ A("mul %10,%5") /* r1:r0 = LO(bezier_A) * LO(f)*/
+ A("sub %9,r1")
+ A("sbc %2,%0")
+ A("sbc %3,%0")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= HI(LO(bezier_A) * LO(f))*/
+ A("lds %11, bezier_A+1") /* %11 = MI(bezier_A)*/
+ A("mul %11,%5") /* r1:r0 = MI(bezier_A) * LO(f)*/
+ A("sub %9,r0")
+ A("sbc %2,r1")
+ A("sbc %3,%0")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= MI(bezier_A) * LO(f)*/
+ A("lds %1, bezier_A+2") /* %1 = HI(bezier_A)*/
+ A("mul %1,%5") /* r1:r0 = MI(bezier_A) * LO(f)*/
+ A("sub %2,r0")
+ A("sbc %3,r1")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= HI(bezier_A) * LO(f) << 8*/
+ A("mul %10,%6") /* r1:r0 = LO(bezier_A) * MI(f)*/
+ A("sub %9,r0")
+ A("sbc %2,r1")
+ A("sbc %3,%0")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= LO(bezier_A) * MI(f)*/
+ A("mul %11,%6") /* r1:r0 = MI(bezier_A) * MI(f)*/
+ A("sub %2,r0")
+ A("sbc %3,r1")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= MI(bezier_A) * MI(f) << 8*/
+ A("mul %1,%6") /* r1:r0 = HI(bezier_A) * LO(f)*/
+ A("sub %3,r0")
+ A("sbc %4,r1") /* %4:%3:%2:%9 -= HI(bezier_A) * LO(f) << 16*/
+ A("jmp 2f") /* Done!*/
+
+ L("1")
+
+ /* uint24_t v; */
+ /* umul16x24to24hi(v, f, bezier_C); / Range 21bits [29]*/
+ /* acc += v; */
+ A("lds %10, bezier_C") /* %10 = LO(bezier_C)*/
+ A("mul %10,%5") /* r1:r0 = LO(bezier_C) * LO(f)*/
+ A("add %9,r1")
+ A("adc %2,%0")
+ A("adc %3,%0")
+ A("adc %4,%0") /* %4:%3:%2:%9 += HI(LO(bezier_C) * LO(f))*/
+ A("lds %11, bezier_C+1") /* %11 = MI(bezier_C)*/
+ A("mul %11,%5") /* r1:r0 = MI(bezier_C) * LO(f)*/
+ A("add %9,r0")
+ A("adc %2,r1")
+ A("adc %3,%0")
+ A("adc %4,%0") /* %4:%3:%2:%9 += MI(bezier_C) * LO(f)*/
+ A("lds %1, bezier_C+2") /* %1 = HI(bezier_C)*/
+ A("mul %1,%5") /* r1:r0 = MI(bezier_C) * LO(f)*/
+ A("add %2,r0")
+ A("adc %3,r1")
+ A("adc %4,%0") /* %4:%3:%2:%9 += HI(bezier_C) * LO(f) << 8*/
+ A("mul %10,%6") /* r1:r0 = LO(bezier_C) * MI(f)*/
+ A("add %9,r0")
+ A("adc %2,r1")
+ A("adc %3,%0")
+ A("adc %4,%0") /* %4:%3:%2:%9 += LO(bezier_C) * MI(f)*/
+ A("mul %11,%6") /* r1:r0 = MI(bezier_C) * MI(f)*/
+ A("add %2,r0")
+ A("adc %3,r1")
+ A("adc %4,%0") /* %4:%3:%2:%9 += MI(bezier_C) * MI(f) << 8*/
+ A("mul %1,%6") /* r1:r0 = HI(bezier_C) * LO(f)*/
+ A("add %3,r0")
+ A("adc %4,r1") /* %4:%3:%2:%9 += HI(bezier_C) * LO(f) << 16*/
+
+ /* umul16x16to16hi(f, f, t); / Range 16 bits : f = t^3 (unsigned) [17]*/
+ A("mul %5,%7") /* r1:r0 = LO(f) * LO(t)*/
+ A("mov %1,r1") /* store MIL(LO(f) * LO(t)) in %1, we need it for rounding*/
+ A("clr %10") /* %10 = 0*/
+ A("clr %11") /* %11 = 0*/
+ A("mul %5,%8") /* r1:r0 = LO(f) * HI(t)*/
+ A("add %1,r0") /* %1 += LO(LO(f) * HI(t))*/
+ A("adc %10,r1") /* %10 = HI(LO(f) * HI(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%7") /* r1:r0 = HI(f) * LO(t)*/
+ A("add %1,r0") /* %1 += LO(HI(f) * LO(t))*/
+ A("adc %10,r1") /* %10 += HI(HI(f) * LO(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%8") /* r1:r0 = HI(f) * HI(t)*/
+ A("add %10,r0") /* %10 += LO(HI(f) * HI(t))*/
+ A("adc %11,r1") /* %11 += HI(HI(f) * HI(t))*/
+ A("mov %5,%10") /* %6:%5 =*/
+ A("mov %6,%11") /* f = %10:%11*/
+
+ /* umul16x24to24hi(v, f, bezier_B); / Range 22bits [29]*/
+ /* acc -= v;*/
+ A("lds %10, bezier_B") /* %10 = LO(bezier_B)*/
+ A("mul %10,%5") /* r1:r0 = LO(bezier_B) * LO(f)*/
+ A("sub %9,r1")
+ A("sbc %2,%0")
+ A("sbc %3,%0")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= HI(LO(bezier_B) * LO(f))*/
+ A("lds %11, bezier_B+1") /* %11 = MI(bezier_B)*/
+ A("mul %11,%5") /* r1:r0 = MI(bezier_B) * LO(f)*/
+ A("sub %9,r0")
+ A("sbc %2,r1")
+ A("sbc %3,%0")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= MI(bezier_B) * LO(f)*/
+ A("lds %1, bezier_B+2") /* %1 = HI(bezier_B)*/
+ A("mul %1,%5") /* r1:r0 = MI(bezier_B) * LO(f)*/
+ A("sub %2,r0")
+ A("sbc %3,r1")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= HI(bezier_B) * LO(f) << 8*/
+ A("mul %10,%6") /* r1:r0 = LO(bezier_B) * MI(f)*/
+ A("sub %9,r0")
+ A("sbc %2,r1")
+ A("sbc %3,%0")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= LO(bezier_B) * MI(f)*/
+ A("mul %11,%6") /* r1:r0 = MI(bezier_B) * MI(f)*/
+ A("sub %2,r0")
+ A("sbc %3,r1")
+ A("sbc %4,%0") /* %4:%3:%2:%9 -= MI(bezier_B) * MI(f) << 8*/
+ A("mul %1,%6") /* r1:r0 = HI(bezier_B) * LO(f)*/
+ A("sub %3,r0")
+ A("sbc %4,r1") /* %4:%3:%2:%9 -= HI(bezier_B) * LO(f) << 16*/
+
+ /* umul16x16to16hi(f, f, t); / Range 16 bits : f = t^5 (unsigned) [17]*/
+ A("mul %5,%7") /* r1:r0 = LO(f) * LO(t)*/
+ A("mov %1,r1") /* store MIL(LO(f) * LO(t)) in %1, we need it for rounding*/
+ A("clr %10") /* %10 = 0*/
+ A("clr %11") /* %11 = 0*/
+ A("mul %5,%8") /* r1:r0 = LO(f) * HI(t)*/
+ A("add %1,r0") /* %1 += LO(LO(f) * HI(t))*/
+ A("adc %10,r1") /* %10 = HI(LO(f) * HI(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%7") /* r1:r0 = HI(f) * LO(t)*/
+ A("add %1,r0") /* %1 += LO(HI(f) * LO(t))*/
+ A("adc %10,r1") /* %10 += HI(HI(f) * LO(t))*/
+ A("adc %11,%0") /* %11 += carry*/
+ A("mul %6,%8") /* r1:r0 = HI(f) * HI(t)*/
+ A("add %10,r0") /* %10 += LO(HI(f) * HI(t))*/
+ A("adc %11,r1") /* %11 += HI(HI(f) * HI(t))*/
+ A("mov %5,%10") /* %6:%5 =*/
+ A("mov %6,%11") /* f = %10:%11*/
+
+ /* umul16x24to24hi(v, f, bezier_A); / Range 21bits [29]*/
+ /* acc += v; */
+ A("lds %10, bezier_A") /* %10 = LO(bezier_A)*/
+ A("mul %10,%5") /* r1:r0 = LO(bezier_A) * LO(f)*/
+ A("add %9,r1")
+ A("adc %2,%0")
+ A("adc %3,%0")
+ A("adc %4,%0") /* %4:%3:%2:%9 += HI(LO(bezier_A) * LO(f))*/
+ A("lds %11, bezier_A+1") /* %11 = MI(bezier_A)*/
+ A("mul %11,%5") /* r1:r0 = MI(bezier_A) * LO(f)*/
+ A("add %9,r0")
+ A("adc %2,r1")
+ A("adc %3,%0")
+ A("adc %4,%0") /* %4:%3:%2:%9 += MI(bezier_A) * LO(f)*/
+ A("lds %1, bezier_A+2") /* %1 = HI(bezier_A)*/
+ A("mul %1,%5") /* r1:r0 = MI(bezier_A) * LO(f)*/
+ A("add %2,r0")
+ A("adc %3,r1")
+ A("adc %4,%0") /* %4:%3:%2:%9 += HI(bezier_A) * LO(f) << 8*/
+ A("mul %10,%6") /* r1:r0 = LO(bezier_A) * MI(f)*/
+ A("add %9,r0")
+ A("adc %2,r1")
+ A("adc %3,%0")
+ A("adc %4,%0") /* %4:%3:%2:%9 += LO(bezier_A) * MI(f)*/
+ A("mul %11,%6") /* r1:r0 = MI(bezier_A) * MI(f)*/
+ A("add %2,r0")
+ A("adc %3,r1")
+ A("adc %4,%0") /* %4:%3:%2:%9 += MI(bezier_A) * MI(f) << 8*/
+ A("mul %1,%6") /* r1:r0 = HI(bezier_A) * LO(f)*/
+ A("add %3,r0")
+ A("adc %4,r1") /* %4:%3:%2:%9 += HI(bezier_A) * LO(f) << 16*/
+ L("2")
+ " clr __zero_reg__" /* C runtime expects r1 = __zero_reg__ = 0 */
+ : "+r"(r0),
+ "+r"(r1),
+ "+r"(r2),
+ "+r"(r3),
+ "+r"(r4),
+ "+r"(r5),
+ "+r"(r6),
+ "+r"(r7),
+ "+r"(r8),
+ "+r"(r9),
+ "+r"(r10),
+ "+r"(r11)
+ :
+ :"cc","r0","r1"
+ );
+ return (r2 | (uint16_t(r3) << 8)) | (uint32_t(r4) << 16);
+ }
+
+#endif // S_CURVE_ACCELERATION
/**
* Stepper Driver Interrupt
*
* Directly pulses the stepper motors at high frequency.
- * Timer 1 runs at a base frequency of 2MHz, with this ISR using OCR1A compare mode.
- *
- * OCR1A Frequency
- * 1 2 MHz
- * 50 40 KHz
- * 100 20 KHz - capped max rate
- * 200 10 KHz - nominal max rate
- * 2000 1 KHz - sleep rate
- * 4000 500 Hz - init rate
*/
-ISR(TIMER1_COMPA_vect) {
- /**
- * On AVR there is no hardware prioritization and preemption of
- * interrupts, so this emulates it. The UART has first priority
- * (otherwise, characters will be lost due to UART overflow).
- * Then: Stepper, Endstops, Temperature, and -finally- all others.
- *
- * This ISR needs to run with as little preemption as possible, so
- * the Temperature ISR is disabled here. Now only the UART, Endstops,
- * and Arduino-defined interrupts can preempt.
- */
- const bool temp_isr_was_enabled = TEMPERATURE_ISR_ENABLED();
- DISABLE_TEMPERATURE_INTERRUPT();
- DISABLE_STEPPER_DRIVER_INTERRUPT();
- sei();
- #if ENABLED(LIN_ADVANCE)
- Stepper::advance_isr_scheduler();
- #else
- Stepper::isr();
- #endif
+HAL_STEP_TIMER_ISR {
+ HAL_timer_isr_prologue(STEP_TIMER_NUM);
- // Disable global interrupts and reenable this ISR
- cli();
- ENABLE_STEPPER_DRIVER_INTERRUPT();
- // Reenable the temperature ISR (if it was enabled)
- if (temp_isr_was_enabled) ENABLE_TEMPERATURE_INTERRUPT();
+ Stepper::isr();
+
+ HAL_timer_isr_epilogue(STEP_TIMER_NUM);
}
+#define STEP_MULTIPLY(A,B) MultiU24X32toH16(A, B)
+
void Stepper::isr() {
+ DISABLE_ISRS();
- uint16_t ocr_val;
+ // Program timer compare for the maximum period, so it does NOT
+ // flag an interrupt while this ISR is running - So changes from small
+ // periods to big periods are respected and the timer does not reset to 0
+ HAL_timer_set_compare(STEP_TIMER_NUM, HAL_TIMER_TYPE_MAX);
- #define ENDSTOP_NOMINAL_OCR_VAL 3000 // Check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
- #define OCR_VAL_TOLERANCE 1000 // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
+ // Count of ticks for the next ISR
+ hal_timer_t next_isr_ticks = 0;
- #define _SPLIT(L) (ocr_val = (uint16_t)L)
- #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
+ // Limit the amount of iterations
+ uint8_t max_loops = 10;
- #define SPLIT(L) _SPLIT(L)
+ // We need this variable here to be able to use it in the following loop
+ hal_timer_t min_ticks;
+ do {
+ // Enable ISRs to reduce USART processing latency
+ ENABLE_ISRS();
- #else // !ENDSTOP_INTERRUPTS_FEATURE : Sample endstops between stepping ISRs
+ // Run main stepping pulse phase ISR if we have to
+ if (!nextMainISR) Stepper::stepper_pulse_phase_isr();
- static uint32_t step_remaining = 0;
+ #if ENABLED(LIN_ADVANCE)
+ // Run linear advance stepper ISR if we have to
+ if (!nextAdvanceISR) nextAdvanceISR = Stepper::advance_isr();
+ #endif
- #define SPLIT(L) do { \
- _SPLIT(L); \
- if (ENDSTOPS_ENABLED && L > ENDSTOP_NOMINAL_OCR_VAL) { \
- const uint16_t remainder = (uint16_t)L % (ENDSTOP_NOMINAL_OCR_VAL); \
- ocr_val = (remainder < OCR_VAL_TOLERANCE) ? ENDSTOP_NOMINAL_OCR_VAL + remainder : ENDSTOP_NOMINAL_OCR_VAL; \
- step_remaining = (uint16_t)L - ocr_val; \
- } \
- }while(0)
+ // ^== Time critical. NOTHING besides pulse generation should be above here!!!
- if (step_remaining && ENDSTOPS_ENABLED) { // Just check endstops - not yet time for a step
- endstops.update();
+ // Run main stepping block processing ISR if we have to
+ if (!nextMainISR) nextMainISR = Stepper::stepper_block_phase_isr();
- // Next ISR either for endstops or stepping
- ocr_val = step_remaining <= ENDSTOP_NOMINAL_OCR_VAL ? step_remaining : ENDSTOP_NOMINAL_OCR_VAL;
- step_remaining -= ocr_val;
- _NEXT_ISR(ocr_val);
- NOLESS(OCR1A, TCNT1 + 16);
- return;
- }
+ uint32_t interval =
+ #if ENABLED(LIN_ADVANCE)
+ MIN(nextAdvanceISR, nextMainISR) // Nearest time interval
+ #else
+ nextMainISR // Remaining stepper ISR time
+ #endif
+ ;
- #endif // !ENDSTOP_INTERRUPTS_FEATURE
+ // Limit the value to the maximum possible value of the timer
+ NOMORE(interval, HAL_TIMER_TYPE_MAX);
- //
- // When cleaning, discard the current block and run fast
- //
- if (cleaning_buffer_counter) {
- if (cleaning_buffer_counter < 0) { // Count up for endstop hit
- if (current_block) planner.discard_current_block(); // Discard the active block that led to the trigger
- if (!planner.discard_continued_block()) // Discard next CONTINUED block
- cleaning_buffer_counter = 0; // Keep discarding until non-CONTINUED
- }
- else {
+ // Compute the time remaining for the main isr
+ nextMainISR -= interval;
+
+ #if ENABLED(LIN_ADVANCE)
+ // Compute the time remaining for the advance isr
+ if (nextAdvanceISR != LA_ADV_NEVER) nextAdvanceISR -= interval;
+ #endif
+
+ /**
+ * This needs to avoid a race-condition caused by interleaving
+ * of interrupts required by both the LA and Stepper algorithms.
+ *
+ * Assume the following tick times for stepper pulses:
+ * Stepper ISR (S): 1 1000 2000 3000 4000
+ * Linear Adv. (E): 10 1010 2010 3010 4010
+ *
+ * The current algorithm tries to interleave them, giving:
+ * 1:S 10:E 1000:S 1010:E 2000:S 2010:E 3000:S 3010:E 4000:S 4010:E
+ *
+ * Ideal timing would yield these delta periods:
+ * 1:S 9:E 990:S 10:E 990:S 10:E 990:S 10:E 990:S 10:E
+ *
+ * But, since each event must fire an ISR with a minimum duration, the
+ * minimum delta might be 900, so deltas under 900 get rounded up:
+ * 900:S d900:E d990:S d900:E d990:S d900:E d990:S d900:E d990:S d900:E
+ *
+ * It works, but divides the speed of all motors by half, leading to a sudden
+ * reduction to 1/2 speed! Such jumps in speed lead to lost steps (not even
+ * accounting for double/quad stepping, which makes it even worse).
+ */
+
+ // Compute the tick count for the next ISR
+ next_isr_ticks += interval;
+
+ /**
+ * The following section must be done with global interrupts disabled.
+ * We want nothing to interrupt it, as that could mess the calculations
+ * we do for the next value to program in the period register of the
+ * stepper timer and lead to skipped ISRs (if the value we happen to program
+ * is less than the current count due to something preempting between the
+ * read and the write of the new period value).
+ */
+ DISABLE_ISRS();
+
+ /**
+ * Get the current tick value + margin
+ * Assuming at least 6µs between calls to this ISR...
+ * On AVR the ISR epilogue+prologue is estimated at 100 instructions - Give 8µs as margin
+ * On ARM the ISR epilogue+prologue is estimated at 20 instructions - Give 1µs as margin
+ */
+ min_ticks = HAL_timer_get_count(STEP_TIMER_NUM) + hal_timer_t((STEPPER_TIMER_TICKS_PER_US) * 8);
+
+ /**
+ * NB: If for some reason the stepper monopolizes the MPU, eventually the
+ * timer will wrap around (and so will 'next_isr_ticks'). So, limit the
+ * loop to 10 iterations. Beyond that, there's no way to ensure correct pulse
+ * timing, since the MCU isn't fast enough.
+ */
+ if (!--max_loops) next_isr_ticks = min_ticks;
+
+ // Advance pulses if not enough time to wait for the next ISR
+ } while (next_isr_ticks < min_ticks);
+
+ // Now 'next_isr_ticks' contains the period to the next Stepper ISR - And we are
+ // sure that the time has not arrived yet - Warrantied by the scheduler
+
+ // Set the next ISR to fire at the proper time
+ HAL_timer_set_compare(STEP_TIMER_NUM, hal_timer_t(next_isr_ticks));
+
+ // Don't forget to finally reenable interrupts
+ ENABLE_ISRS();
+}
+
+/**
+ * This phase of the ISR should ONLY create the pulses for the steppers.
+ * This prevents jitter caused by the interval between the start of the
+ * interrupt and the start of the pulses. DON'T add any logic ahead of the
+ * call to this method that might cause variation in the timing. The aim
+ * is to keep pulse timing as regular as possible.
+ */
+void Stepper::stepper_pulse_phase_isr() {
+
+ // If we must abort the current block, do so!
+ if (abort_current_block) {
+ abort_current_block = false;
+ if (current_block) {
+ axis_did_move = 0;
+ current_block = NULL;
planner.discard_current_block();
- --cleaning_buffer_counter; // Count down for abort print
- #if ENABLED(SD_FINISHED_STEPPERRELEASE) && defined(SD_FINISHED_RELEASECOMMAND)
- if (!cleaning_buffer_counter) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
- #endif
- }
- current_block = NULL; // Prep to get a new block after cleaning
- _NEXT_ISR(200); // Run at max speed - 10 KHz
- return;
- }
-
- // If there is no current block, attempt to pop one from the buffer
- if (!current_block) {
- // Anything in the buffer?
- if ((current_block = planner.get_current_block())) {
- trapezoid_generator_reset();
-
- // Initialize Bresenham counters to 1/2 the ceiling
- counter_X = counter_Y = counter_Z = counter_E = -(current_block->step_event_count >> 1);
-
- #if ENABLED(MIXING_EXTRUDER)
- MIXING_STEPPERS_LOOP(i)
- counter_m[i] = -(current_block->mix_event_count[i] >> 1);
- #endif
-
- step_events_completed = 0;
-
- #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
- e_hit = 2; // Needed for the case an endstop is already triggered before the new move begins.
- // No 'change' can be detected.
- #endif
-
- #if ENABLED(Z_LATE_ENABLE)
- if (current_block->steps[Z_AXIS] > 0) {
- enable_Z();
- _NEXT_ISR(2000); // Run at slow speed - 1 KHz
- return;
- }
- #endif
- }
- else {
- _NEXT_ISR(2000); // Run at slow speed - 1 KHz
- return;
}
}
- // Update endstops state, if enabled
- #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
- if (e_hit && ENDSTOPS_ENABLED) {
- endstops.update();
- e_hit--;
- }
- #else
- if (ENDSTOPS_ENABLED) endstops.update();
- #endif
+ // If there is no current block, do nothing
+ if (!current_block) return;
+
+ // Count of pending loops and events for this iteration
+ const uint32_t pending_events = step_event_count - step_events_completed;
+ uint8_t events_to_do = MIN(pending_events, steps_per_isr);
+
+ // Just update the value we will get at the end of the loop
+ step_events_completed += events_to_do;
+
+ // Get the timer count and estimate the end of the pulse
+ hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t(MIN_PULSE_TICKS);
+
+ const hal_timer_t added_step_ticks = hal_timer_t(ADDED_STEP_TICKS);
// Take multiple steps per interrupt (For high speed moves)
- bool all_steps_done = false;
- for (uint8_t i = step_loops; i--;) {
+ do {
- #define _COUNTER(AXIS) counter_## AXIS
#define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
#define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
- // Advance the Bresenham counter; start a pulse if the axis needs a step
+ // Start an active pulse, if Bresenham says so, and update position
#define PULSE_START(AXIS) do{ \
- _COUNTER(AXIS) += current_block->steps[_AXIS(AXIS)]; \
- if (_COUNTER(AXIS) > 0) { _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), 0); } \
- }while(0)
-
- // Advance the Bresenham counter; start a pulse if the axis needs a step
- #define STEP_TICK(AXIS) do { \
- if (_COUNTER(AXIS) > 0) { \
- _COUNTER(AXIS) -= current_block->step_event_count; \
+ delta_error[_AXIS(AXIS)] += advance_dividend[_AXIS(AXIS)]; \
+ if (delta_error[_AXIS(AXIS)] >= 0) { \
+ _APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), 0); \
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
} \
}while(0)
- // Stop an active pulse, if any
- #define PULSE_STOP(AXIS) _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), 0)
-
- /**
- * Estimate the number of cycles that the stepper logic already takes
- * up between the start and stop of the X stepper pulse.
- *
- * Currently this uses very modest estimates of around 5 cycles.
- * True values may be derived by careful testing.
- *
- * Once any delay is added, the cost of the delay code itself
- * may be subtracted from this value to get a more accurate delay.
- * Delays under 20 cycles (1.25µs) will be very accurate, using NOPs.
- * Longer delays use a loop. The resolution is 8 cycles.
- */
- #if HAS_X_STEP
- #define _CYCLE_APPROX_1 5
- #else
- #define _CYCLE_APPROX_1 0
- #endif
- #if ENABLED(X_DUAL_STEPPER_DRIVERS)
- #define _CYCLE_APPROX_2 _CYCLE_APPROX_1 + 4
- #else
- #define _CYCLE_APPROX_2 _CYCLE_APPROX_1
- #endif
- #if HAS_Y_STEP
- #define _CYCLE_APPROX_3 _CYCLE_APPROX_2 + 5
- #else
- #define _CYCLE_APPROX_3 _CYCLE_APPROX_2
- #endif
- #if ENABLED(Y_DUAL_STEPPER_DRIVERS)
- #define _CYCLE_APPROX_4 _CYCLE_APPROX_3 + 4
- #else
- #define _CYCLE_APPROX_4 _CYCLE_APPROX_3
- #endif
- #if HAS_Z_STEP
- #define _CYCLE_APPROX_5 _CYCLE_APPROX_4 + 5
- #else
- #define _CYCLE_APPROX_5 _CYCLE_APPROX_4
- #endif
- #if ENABLED(Z_DUAL_STEPPER_DRIVERS)
- #define _CYCLE_APPROX_6 _CYCLE_APPROX_5 + 4
- #else
- #define _CYCLE_APPROX_6 _CYCLE_APPROX_5
- #endif
- #if DISABLED(LIN_ADVANCE)
- #if ENABLED(MIXING_EXTRUDER)
- #define _CYCLE_APPROX_7 _CYCLE_APPROX_6 + (MIXING_STEPPERS) * 6
- #else
- #define _CYCLE_APPROX_7 _CYCLE_APPROX_6 + 5
- #endif
- #else
- #define _CYCLE_APPROX_7 _CYCLE_APPROX_6
- #endif
-
- #define CYCLES_EATEN_XYZE _CYCLE_APPROX_7
- #define EXTRA_CYCLES_XYZE (STEP_PULSE_CYCLES - (CYCLES_EATEN_XYZE))
-
- /**
- * If a minimum pulse time was specified get the timer 0 value.
- *
- * On AVR the TCNT0 timer has an 8x prescaler, so it increments every 8 cycles.
- * That's every 0.5µs on 16MHz and every 0.4µs on 20MHz.
- * 20 counts of TCNT0 -by itself- is a good pulse delay.
- * 10µs = 160 or 200 cycles.
- */
- #if EXTRA_CYCLES_XYZE > 20
- uint32_t pulse_start = TCNT0;
- #endif
+ // Stop an active pulse, if any, and adjust error term
+ #define PULSE_STOP(AXIS) do { \
+ if (delta_error[_AXIS(AXIS)] >= 0) { \
+ delta_error[_AXIS(AXIS)] -= advance_divisor; \
+ _APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), 0); \
+ } \
+ }while(0)
+ // Pulse start
#if HAS_X_STEP
PULSE_START(X);
#endif
@@ -594,65 +1312,49 @@ void Stepper::isr() {
PULSE_START(Z);
#endif
+ // Pulse E/Mixing extruders
#if ENABLED(LIN_ADVANCE)
+ // Tick the E axis, correct error term and update position
+ delta_error[E_AXIS] += advance_dividend[E_AXIS];
+ if (delta_error[E_AXIS] >= 0) {
+ count_position[E_AXIS] += count_direction[E_AXIS];
+ delta_error[E_AXIS] -= advance_divisor;
- counter_E += current_block->steps[E_AXIS];
- if (counter_E > 0) {
- #if DISABLED(MIXING_EXTRUDER)
- // Don't step E here for mixing extruder
- motor_direction(E_AXIS) ? --e_steps : ++e_steps;
- #endif
+ // Don't step E here - But remember the number of steps to perform
+ motor_direction(E_AXIS) ? --LA_steps : ++LA_steps;
}
-
- #if ENABLED(MIXING_EXTRUDER)
- // Step mixing steppers proportionally
- const bool dir = motor_direction(E_AXIS);
- MIXING_STEPPERS_LOOP(j) {
- counter_m[j] += current_block->steps[E_AXIS];
- if (counter_m[j] > 0) {
- counter_m[j] -= current_block->mix_event_count[j];
- dir ? --e_steps[j] : ++e_steps[j];
- }
- }
- #endif
-
#else // !LIN_ADVANCE - use linear interpolation for E also
-
#if ENABLED(MIXING_EXTRUDER)
- // Keep updating the single E axis
- counter_E += current_block->steps[E_AXIS];
- // Tick the counters used for this mix
+
+ // Tick the E axis
+ delta_error[E_AXIS] += advance_dividend[E_AXIS];
+ if (delta_error[E_AXIS] >= 0) {
+ count_position[E_AXIS] += count_direction[E_AXIS];
+ delta_error[E_AXIS] -= advance_divisor;
+ }
+
+ // Tick the counters used for this mix in proper proportion
MIXING_STEPPERS_LOOP(j) {
// Step mixing steppers (proportionally)
- counter_m[j] += current_block->steps[E_AXIS];
+ delta_error_m[j] += advance_dividend_m[j];
// Step when the counter goes over zero
- if (counter_m[j] > 0) En_STEP_WRITE(j, !INVERT_E_STEP_PIN);
+ if (delta_error_m[j] >= 0) E_STEP_WRITE(j, !INVERT_E_STEP_PIN);
}
+
#else // !MIXING_EXTRUDER
PULSE_START(E);
#endif
#endif // !LIN_ADVANCE
- #if HAS_X_STEP
- STEP_TICK(X);
- #endif
- #if HAS_Y_STEP
- STEP_TICK(Y);
- #endif
- #if HAS_Z_STEP
- STEP_TICK(Z);
+ #if MINIMUM_STEPPER_PULSE
+ // Just wait for the requested pulse duration
+ while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
#endif
- STEP_TICK(E); // Always tick the single E axis
-
- // For minimum pulse time wait before stopping pulses
- #if EXTRA_CYCLES_XYZE > 20
- while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
- pulse_start = TCNT0;
- #elif EXTRA_CYCLES_XYZE > 0
- DELAY_NOPS(EXTRA_CYCLES_XYZE);
- #endif
+ // Add the delay needed to ensure the maximum driver rate is enforced
+ if (signed(added_step_ticks) > 0) pulse_end += hal_timer_t(added_step_ticks);
+ // Pulse stop
#if HAS_X_STEP
PULSE_STOP(X);
#endif
@@ -666,9 +1368,9 @@ void Stepper::isr() {
#if DISABLED(LIN_ADVANCE)
#if ENABLED(MIXING_EXTRUDER)
MIXING_STEPPERS_LOOP(j) {
- if (counter_m[j] > 0) {
- counter_m[j] -= current_block->mix_event_count[j];
- En_STEP_WRITE(j, INVERT_E_STEP_PIN);
+ if (delta_error_m[j] >= 0) {
+ delta_error_m[j] -= advance_divisor_m;
+ E_STEP_WRITE(j, INVERT_E_STEP_PIN);
}
}
#else // !MIXING_EXTRUDER
@@ -676,263 +1378,478 @@ void Stepper::isr() {
#endif
#endif // !LIN_ADVANCE
- if (++step_events_completed >= current_block->step_event_count) {
- all_steps_done = true;
- break;
- }
+ // Decrement the count of pending pulses to do
+ --events_to_do;
// For minimum pulse time wait after stopping pulses also
- #if EXTRA_CYCLES_XYZE > 20
- if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
- #elif EXTRA_CYCLES_XYZE > 0
- if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
- #endif
-
- } // steps_loop
-
- // Calculate new timer value
- if (step_events_completed <= (uint32_t)current_block->accelerate_until) {
-
- MultiU24X32toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
- acc_step_rate += current_block->initial_rate;
-
- // upper limit
- NOMORE(acc_step_rate, current_block->nominal_rate);
-
- // step_rate to timer interval
- const uint16_t interval = calc_timer_interval(acc_step_rate);
-
- SPLIT(interval); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
- _NEXT_ISR(ocr_val);
-
- acceleration_time += interval;
-
- #if ENABLED(LIN_ADVANCE)
-
- if (current_block->use_advance_lead) {
- if (step_events_completed == step_loops || (e_steps && eISR_Rate != current_block->advance_speed)) {
- nextAdvanceISR = 0; // Wake up eISR on first acceleration loop and fire ISR if final adv_rate is reached
- eISR_Rate = current_block->advance_speed;
- }
- }
- else {
- eISR_Rate = ADV_NEVER;
- if (e_steps) nextAdvanceISR = 0;
- }
-
- #endif // LIN_ADVANCE
- }
- else if (step_events_completed > (uint32_t)current_block->decelerate_after) {
- uint16_t step_rate;
- MultiU24X32toH16(step_rate, deceleration_time, current_block->acceleration_rate);
-
- if (step_rate < acc_step_rate) { // Still decelerating?
- step_rate = acc_step_rate - step_rate;
- NOLESS(step_rate, current_block->final_rate);
+ if (events_to_do) {
+ // Just wait for the requested pulse duration
+ while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
+ #if MINIMUM_STEPPER_PULSE
+ // Add to the value, the time that the pulse must be active (to be used on the next loop)
+ pulse_end += hal_timer_t(MIN_PULSE_TICKS);
+ #endif
}
- else
- step_rate = current_block->final_rate;
- // step_rate to timer interval
- const uint16_t interval = calc_timer_interval(step_rate);
+ } while (events_to_do);
+}
- SPLIT(interval); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
- _NEXT_ISR(ocr_val);
+// This is the last half of the stepper interrupt: This one processes and
+// properly schedules blocks from the planner. This is executed after creating
+// the step pulses, so it is not time critical, as pulses are already done.
- deceleration_time += interval;
+uint32_t Stepper::stepper_block_phase_isr() {
- #if ENABLED(LIN_ADVANCE)
+ // If no queued movements, just wait 1ms for the next move
+ uint32_t interval = (STEPPER_TIMER_RATE / 1000);
- if (current_block->use_advance_lead) {
- if (step_events_completed <= (uint32_t)current_block->decelerate_after + step_loops || (e_steps && eISR_Rate != current_block->advance_speed)) {
- nextAdvanceISR = 0; // Wake up eISR on first deceleration loop
- eISR_Rate = current_block->advance_speed;
- }
+ // If there is a current block
+ if (current_block) {
+
+ // If current block is finished, reset pointer
+ if (step_events_completed >= step_event_count) {
+ axis_did_move = 0;
+ current_block = NULL;
+ planner.discard_current_block();
+ }
+ else {
+ // Step events not completed yet...
+
+ // Are we in acceleration phase ?
+ if (step_events_completed <= accelerate_until) { // Calculate new timer value
+
+ #if ENABLED(S_CURVE_ACCELERATION)
+ // Get the next speed to use (Jerk limited!)
+ uint32_t acc_step_rate =
+ acceleration_time < current_block->acceleration_time
+ ? _eval_bezier_curve(acceleration_time)
+ : current_block->cruise_rate;
+ #else
+ acc_step_rate = STEP_MULTIPLY(acceleration_time, current_block->acceleration_rate) + current_block->initial_rate;
+ NOMORE(acc_step_rate, current_block->nominal_rate);
+ #endif
+
+ // acc_step_rate is in steps/second
+
+ // step_rate to timer interval and steps per stepper isr
+ interval = calc_timer_interval(acc_step_rate, oversampling_factor, &steps_per_isr);
+ acceleration_time += interval;
+
+ #if ENABLED(LIN_ADVANCE)
+ if (LA_use_advance_lead) {
+ // Wake up eISR on first acceleration loop and fire ISR if final adv_rate is reached
+ if (step_events_completed == steps_per_isr || (LA_steps && LA_isr_rate != current_block->advance_speed)) {
+ nextAdvanceISR = 0;
+ LA_isr_rate = current_block->advance_speed;
+ }
+ }
+ else {
+ LA_isr_rate = LA_ADV_NEVER;
+ if (LA_steps) nextAdvanceISR = 0;
+ }
+ #endif // LIN_ADVANCE
}
+ // Are we in Deceleration phase ?
+ else if (step_events_completed > decelerate_after) {
+ uint32_t step_rate;
+
+ #if ENABLED(S_CURVE_ACCELERATION)
+ // If this is the 1st time we process the 2nd half of the trapezoid...
+ if (!bezier_2nd_half) {
+ // Initialize the Bézier speed curve
+ _calc_bezier_curve_coeffs(current_block->cruise_rate, current_block->final_rate, current_block->deceleration_time_inverse);
+ bezier_2nd_half = true;
+ // The first point starts at cruise rate. Just save evaluation of the Bézier curve
+ step_rate = current_block->cruise_rate;
+ }
+ else {
+ // Calculate the next speed to use
+ step_rate = deceleration_time < current_block->deceleration_time
+ ? _eval_bezier_curve(deceleration_time)
+ : current_block->final_rate;
+ }
+ #else
+
+ // Using the old trapezoidal control
+ step_rate = STEP_MULTIPLY(deceleration_time, current_block->acceleration_rate);
+ if (step_rate < acc_step_rate) { // Still decelerating?
+ step_rate = acc_step_rate - step_rate;
+ NOLESS(step_rate, current_block->final_rate);
+ }
+ else
+ step_rate = current_block->final_rate;
+ #endif
+
+ // step_rate is in steps/second
+
+ // step_rate to timer interval and steps per stepper isr
+ interval = calc_timer_interval(step_rate, oversampling_factor, &steps_per_isr);
+ deceleration_time += interval;
+
+ #if ENABLED(LIN_ADVANCE)
+ if (LA_use_advance_lead) {
+ if (step_events_completed <= decelerate_after + steps_per_isr ||
+ (LA_steps && LA_isr_rate != current_block->advance_speed)
+ ) {
+ nextAdvanceISR = 0; // Wake up eISR on first deceleration loop
+ LA_isr_rate = current_block->advance_speed;
+ }
+ }
+ else {
+ LA_isr_rate = LA_ADV_NEVER;
+ if (LA_steps) nextAdvanceISR = 0;
+ }
+ #endif // LIN_ADVANCE
+ }
+ // We must be in cruise phase otherwise
else {
- eISR_Rate = ADV_NEVER;
- if (e_steps) nextAdvanceISR = 0;
+
+ #if ENABLED(LIN_ADVANCE)
+ // If there are any esteps, fire the next advance_isr "now"
+ if (LA_steps && LA_isr_rate != current_block->advance_speed) nextAdvanceISR = 0;
+ #endif
+
+ // Calculate the ticks_nominal for this nominal speed, if not done yet
+ if (ticks_nominal < 0) {
+ // step_rate to timer interval and loops for the nominal speed
+ ticks_nominal = calc_timer_interval(current_block->nominal_rate, oversampling_factor, &steps_per_isr);
+ }
+
+ // The timer interval is just the nominal value for the nominal speed
+ interval = ticks_nominal;
+ }
+ }
+ }
+
+ // If there is no current block at this point, attempt to pop one from the buffer
+ // and prepare its movement
+ if (!current_block) {
+
+ // Anything in the buffer?
+ if ((current_block = planner.get_current_block())) {
+
+ // Sync block? Sync the stepper counts and return
+ while (TEST(current_block->flag, BLOCK_BIT_SYNC_POSITION)) {
+ _set_position(
+ current_block->position[A_AXIS], current_block->position[B_AXIS],
+ current_block->position[C_AXIS], current_block->position[E_AXIS]
+ );
+ planner.discard_current_block();
+
+ // Try to get a new block
+ if (!(current_block = planner.get_current_block()))
+ return interval; // No more queued movements!
}
- #endif // LIN_ADVANCE
- }
- else {
+ // Flag all moving axes for proper endstop handling
- #if ENABLED(LIN_ADVANCE)
+ #if IS_CORE
+ // Define conditions for checking endstops
+ #define S_(N) current_block->steps[CORE_AXIS_##N]
+ #define D_(N) TEST(current_block->direction_bits, CORE_AXIS_##N)
+ #endif
- // If we have esteps to execute, fire the next advance_isr "now"
- if (e_steps && eISR_Rate != current_block->advance_speed) nextAdvanceISR = 0;
+ #if CORE_IS_XY || CORE_IS_XZ
+ /**
+ * Head direction in -X axis for CoreXY and CoreXZ bots.
+ *
+ * If steps differ, both axes are moving.
+ * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z, handled below)
+ * If DeltaA == DeltaB, the movement is only in the 1st axis (X)
+ */
+ #if ENABLED(COREXY) || ENABLED(COREXZ)
+ #define X_CMP ==
+ #else
+ #define X_CMP !=
+ #endif
+ #define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
+ #else
+ #define X_MOVE_TEST !!current_block->steps[A_AXIS]
+ #endif
- #endif
+ #if CORE_IS_XY || CORE_IS_YZ
+ /**
+ * Head direction in -Y axis for CoreXY / CoreYZ bots.
+ *
+ * If steps differ, both axes are moving
+ * If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y)
+ * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z)
+ */
+ #if ENABLED(COREYX) || ENABLED(COREYZ)
+ #define Y_CMP ==
+ #else
+ #define Y_CMP !=
+ #endif
+ #define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
+ #else
+ #define Y_MOVE_TEST !!current_block->steps[B_AXIS]
+ #endif
- SPLIT(OCR1A_nominal); // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
- _NEXT_ISR(ocr_val);
+ #if CORE_IS_XZ || CORE_IS_YZ
+ /**
+ * Head direction in -Z axis for CoreXZ or CoreYZ bots.
+ *
+ * If steps differ, both axes are moving
+ * If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y, already handled above)
+ * If DeltaA == -DeltaB, the movement is only in the 2nd axis (Z)
+ */
+ #if ENABLED(COREZX) || ENABLED(COREZY)
+ #define Z_CMP ==
+ #else
+ #define Z_CMP !=
+ #endif
+ #define Z_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
+ #else
+ #define Z_MOVE_TEST !!current_block->steps[C_AXIS]
+ #endif
- // ensure we're running at the correct step rate, even if we just came off an acceleration
- step_loops = step_loops_nominal;
+ uint8_t axis_bits = 0;
+ if (X_MOVE_TEST) SBI(axis_bits, A_AXIS);
+ if (Y_MOVE_TEST) SBI(axis_bits, B_AXIS);
+ if (Z_MOVE_TEST) SBI(axis_bits, C_AXIS);
+ //if (!!current_block->steps[E_AXIS]) SBI(axis_bits, E_AXIS);
+ //if (!!current_block->steps[A_AXIS]) SBI(axis_bits, X_HEAD);
+ //if (!!current_block->steps[B_AXIS]) SBI(axis_bits, Y_HEAD);
+ //if (!!current_block->steps[C_AXIS]) SBI(axis_bits, Z_HEAD);
+ axis_did_move = axis_bits;
+
+ // No acceleration / deceleration time elapsed so far
+ acceleration_time = deceleration_time = 0;
+
+ uint8_t oversampling = 0; // Assume we won't use it
+
+ #if ENABLED(ADAPTIVE_STEP_SMOOTHING)
+ // At this point, we must decide if we can use Stepper movement axis smoothing.
+ uint32_t max_rate = current_block->nominal_rate; // Get the maximum rate (maximum event speed)
+ while (max_rate < MIN_STEP_ISR_FREQUENCY) {
+ max_rate <<= 1;
+ if (max_rate >= MAX_STEP_ISR_FREQUENCY_1X) break;
+ ++oversampling;
+ }
+ oversampling_factor = oversampling;
+ #endif
+
+ // Based on the oversampling factor, do the calculations
+ step_event_count = current_block->step_event_count << oversampling;
+
+ // Initialize Bresenham delta errors to 1/2
+ delta_error[X_AXIS] = delta_error[Y_AXIS] = delta_error[Z_AXIS] = delta_error[E_AXIS] = -int32_t(step_event_count);
+
+ // Calculate Bresenham dividends
+ advance_dividend[X_AXIS] = current_block->steps[X_AXIS] << 1;
+ advance_dividend[Y_AXIS] = current_block->steps[Y_AXIS] << 1;
+ advance_dividend[Z_AXIS] = current_block->steps[Z_AXIS] << 1;
+ advance_dividend[E_AXIS] = current_block->steps[E_AXIS] << 1;
+
+ // Calculate Bresenham divisor
+ advance_divisor = step_event_count << 1;
+
+ // No step events completed so far
+ step_events_completed = 0;
+
+ // Compute the acceleration and deceleration points
+ accelerate_until = current_block->accelerate_until << oversampling;
+ decelerate_after = current_block->decelerate_after << oversampling;
+
+ #if ENABLED(MIXING_EXTRUDER)
+ const uint32_t e_steps = (
+ #if ENABLED(LIN_ADVANCE)
+ current_block->steps[E_AXIS]
+ #else
+ step_event_count
+ #endif
+ );
+ MIXING_STEPPERS_LOOP(i) {
+ delta_error_m[i] = -int32_t(e_steps);
+ advance_dividend_m[i] = current_block->mix_steps[i] << 1;
+ }
+ advance_divisor_m = e_steps << 1;
+ #else
+ active_extruder = current_block->active_extruder;
+ #endif
+
+ // Initialize the trapezoid generator from the current block.
+ #if ENABLED(LIN_ADVANCE)
+ #if DISABLED(MIXING_EXTRUDER) && E_STEPPERS > 1
+ // If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
+ if (active_extruder != last_moved_extruder) LA_current_adv_steps = 0;
+ #endif
+
+ if ((LA_use_advance_lead = current_block->use_advance_lead)) {
+ LA_final_adv_steps = current_block->final_adv_steps;
+ LA_max_adv_steps = current_block->max_adv_steps;
+ }
+ #endif
+
+ if (current_block->direction_bits != last_direction_bits
+ #if DISABLED(MIXING_EXTRUDER)
+ || active_extruder != last_moved_extruder
+ #endif
+ ) {
+ last_direction_bits = current_block->direction_bits;
+ #if DISABLED(MIXING_EXTRUDER)
+ last_moved_extruder = active_extruder;
+ #endif
+ set_directions();
+ }
+
+ // At this point, we must ensure the movement about to execute isn't
+ // trying to force the head against a limit switch. If using interrupt-
+ // driven change detection, and already against a limit then no call to
+ // the endstop_triggered method will be done and the movement will be
+ // done against the endstop. So, check the limits here: If the movement
+ // is against the limits, the block will be marked as to be killed, and
+ // on the next call to this ISR, will be discarded.
+ endstops.update();
+
+ #if ENABLED(Z_LATE_ENABLE)
+ // If delayed Z enable, enable it now. This option will severely interfere with
+ // timing between pulses when chaining motion between blocks, and it could lead
+ // to lost steps in both X and Y axis, so avoid using it unless strictly necessary!!
+ if (current_block->steps[Z_AXIS]) enable_Z();
+ #endif
+
+ // Mark the time_nominal as not calculated yet
+ ticks_nominal = -1;
+
+ #if DISABLED(S_CURVE_ACCELERATION)
+ // Set as deceleration point the initial rate of the block
+ acc_step_rate = current_block->initial_rate;
+ #endif
+
+ #if ENABLED(S_CURVE_ACCELERATION)
+ // Initialize the Bézier speed curve
+ _calc_bezier_curve_coeffs(current_block->initial_rate, current_block->cruise_rate, current_block->acceleration_time_inverse);
+ // We haven't started the 2nd half of the trapezoid
+ bezier_2nd_half = false;
+ #endif
+
+ // Calculate the initial timer interval
+ interval = calc_timer_interval(current_block->initial_rate, oversampling_factor, &steps_per_isr);
+ }
}
- #if DISABLED(LIN_ADVANCE)
- NOLESS(OCR1A, TCNT1 + 16);
- #endif
-
- // If current block is finished, reset pointer
- if (all_steps_done) {
- current_block = NULL;
- planner.discard_current_block();
- }
+ // Return the interval to wait
+ return interval;
}
#if ENABLED(LIN_ADVANCE)
- #define CYCLES_EATEN_E (E_STEPPERS * 5)
- #define EXTRA_CYCLES_E (STEP_PULSE_CYCLES - (CYCLES_EATEN_E))
+ // Timer interrupt for E. LA_steps is set in the main routine
+ uint32_t Stepper::advance_isr() {
+ uint32_t interval;
- // Timer interrupt for E. e_steps is set in the main routine;
-
- void Stepper::advance_isr() {
-
- #if ENABLED(MK2_MULTIPLEXER) // For SNMM even-numbered steppers are reversed
- #define SET_E_STEP_DIR(INDEX) do{ if (e_steps) E0_DIR_WRITE(e_steps < 0 ? !INVERT_E## INDEX ##_DIR ^ TEST(INDEX, 0) : INVERT_E## INDEX ##_DIR ^ TEST(INDEX, 0)); }while(0)
- #elif ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
- #define SET_E_STEP_DIR(INDEX) do{ if (e_steps) { if (e_steps < 0) REV_E_DIR(); else NORM_E_DIR(); } }while(0)
- #else
- #define SET_E_STEP_DIR(INDEX) do{ if (e_steps) E## INDEX ##_DIR_WRITE(e_steps < 0 ? INVERT_E## INDEX ##_DIR : !INVERT_E## INDEX ##_DIR); }while(0)
- #endif
-
- #if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
- #define START_E_PULSE(INDEX) do{ if (e_steps) E_STEP_WRITE(!INVERT_E_STEP_PIN); }while(0)
- #define STOP_E_PULSE(INDEX) do{ if (e_steps) { E_STEP_WRITE(INVERT_E_STEP_PIN); e_steps < 0 ? ++e_steps : --e_steps; } }while(0)
- #else
- #define START_E_PULSE(INDEX) do{ if (e_steps) E## INDEX ##_STEP_WRITE(!INVERT_E_STEP_PIN); }while(0)
- #define STOP_E_PULSE(INDEX) do { if (e_steps) { e_steps < 0 ? ++e_steps : --e_steps; E## INDEX ##_STEP_WRITE(INVERT_E_STEP_PIN); } }while(0)
- #endif
-
- if (use_advance_lead) {
- if (step_events_completed > LA_decelerate_after && current_adv_steps > final_adv_steps) {
- e_steps--;
- current_adv_steps--;
- nextAdvanceISR = eISR_Rate;
+ if (LA_use_advance_lead) {
+ if (step_events_completed > decelerate_after && LA_current_adv_steps > LA_final_adv_steps) {
+ LA_steps--;
+ LA_current_adv_steps--;
+ interval = LA_isr_rate;
}
- else if (step_events_completed < LA_decelerate_after && current_adv_steps < max_adv_steps) {
- //step_events_completed <= (uint32_t)current_block->accelerate_until) {
- e_steps++;
- current_adv_steps++;
- nextAdvanceISR = eISR_Rate;
- }
- else {
- nextAdvanceISR = ADV_NEVER;
- eISR_Rate = ADV_NEVER;
+ else if (step_events_completed < decelerate_after && LA_current_adv_steps < LA_max_adv_steps) {
+ //step_events_completed <= (uint32_t)accelerate_until) {
+ LA_steps++;
+ LA_current_adv_steps++;
+ interval = LA_isr_rate;
}
+ else
+ interval = LA_isr_rate = LA_ADV_NEVER;
}
else
- nextAdvanceISR = ADV_NEVER;
+ interval = LA_ADV_NEVER;
- switch (LA_active_extruder) {
- case 0: SET_E_STEP_DIR(0); break;
- #if EXTRUDERS > 1
- case 1: SET_E_STEP_DIR(1); break;
- #if EXTRUDERS > 2
- case 2: SET_E_STEP_DIR(2); break;
- #if EXTRUDERS > 3
- case 3: SET_E_STEP_DIR(3); break;
- #if EXTRUDERS > 4
- case 4: SET_E_STEP_DIR(4); break;
- #endif // EXTRUDERS > 4
- #endif // EXTRUDERS > 3
- #endif // EXTRUDERS > 2
- #endif // EXTRUDERS > 1
- }
+ #if ENABLED(MIXING_EXTRUDER)
+ if (LA_steps >= 0)
+ MIXING_STEPPERS_LOOP(j) NORM_E_DIR(j);
+ else
+ MIXING_STEPPERS_LOOP(j) REV_E_DIR(j);
+ #else
+ if (LA_steps >= 0)
+ NORM_E_DIR(active_extruder);
+ else
+ REV_E_DIR(active_extruder);
+ #endif
+
+ // Get the timer count and estimate the end of the pulse
+ hal_timer_t pulse_end = HAL_timer_get_count(PULSE_TIMER_NUM) + hal_timer_t(MIN_PULSE_TICKS);
+
+ const hal_timer_t added_step_ticks = hal_timer_t(ADDED_STEP_TICKS);
// Step E stepper if we have steps
- while (e_steps) {
+ while (LA_steps) {
- #if EXTRA_CYCLES_E > 20
- uint32_t pulse_start = TCNT0;
+ // Set the STEP pulse ON
+ #if ENABLED(MIXING_EXTRUDER)
+ MIXING_STEPPERS_LOOP(j) {
+ // Step mixing steppers (proportionally)
+ delta_error_m[j] += advance_dividend_m[j];
+ // Step when the counter goes over zero
+ if (delta_error_m[j] >= 0) E_STEP_WRITE(j, !INVERT_E_STEP_PIN);
+ }
+ #else
+ E_STEP_WRITE(active_extruder, !INVERT_E_STEP_PIN);
#endif
- switch (LA_active_extruder) {
- case 0: START_E_PULSE(0); break;
- #if EXTRUDERS > 1
- case 1: START_E_PULSE(1); break;
- #if EXTRUDERS > 2
- case 2: START_E_PULSE(2); break;
- #if EXTRUDERS > 3
- case 3: START_E_PULSE(3); break;
- #if EXTRUDERS > 4
- case 4: START_E_PULSE(4); break;
- #endif // EXTRUDERS > 4
- #endif // EXTRUDERS > 3
- #endif // EXTRUDERS > 2
- #endif // EXTRUDERS > 1
- }
-
- // For minimum pulse time wait before stopping pulses
- #if EXTRA_CYCLES_E > 20
- while (EXTRA_CYCLES_E > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
- pulse_start = TCNT0;
- #elif EXTRA_CYCLES_E > 0
- DELAY_NOPS(EXTRA_CYCLES_E);
+ // Enforce a minimum duration for STEP pulse ON
+ #if MINIMUM_STEPPER_PULSE
+ // Just wait for the requested pulse duration
+ while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
#endif
- switch (LA_active_extruder) {
- case 0: STOP_E_PULSE(0); break;
- #if EXTRUDERS > 1
- case 1: STOP_E_PULSE(1); break;
- #if EXTRUDERS > 2
- case 2: STOP_E_PULSE(2); break;
- #if EXTRUDERS > 3
- case 3: STOP_E_PULSE(3); break;
- #if EXTRUDERS > 4
- case 4: STOP_E_PULSE(4); break;
- #endif // EXTRUDERS > 4
- #endif // EXTRUDERS > 3
- #endif // EXTRUDERS > 2
- #endif // EXTRUDERS > 1
- }
+ // Add the delay needed to ensure the maximum driver rate is enforced
+ if (signed(added_step_ticks) > 0) pulse_end += hal_timer_t(added_step_ticks);
+
+ LA_steps < 0 ? ++LA_steps : --LA_steps;
+
+ // Set the STEP pulse OFF
+ #if ENABLED(MIXING_EXTRUDER)
+ MIXING_STEPPERS_LOOP(j) {
+ if (delta_error_m[j] >= 0) {
+ delta_error_m[j] -= advance_divisor_m;
+ E_STEP_WRITE(j, INVERT_E_STEP_PIN);
+ }
+ }
+ #else
+ E_STEP_WRITE(active_extruder, INVERT_E_STEP_PIN);
+ #endif
// For minimum pulse time wait before looping
- #if EXTRA_CYCLES_E > 20
- if (e_steps) while (EXTRA_CYCLES_E > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
- #elif EXTRA_CYCLES_E > 0
- if (e_steps) DELAY_NOPS(EXTRA_CYCLES_E);
- #endif
+ // Just wait for the requested pulse duration
+ if (LA_steps) {
+ while (HAL_timer_get_count(PULSE_TIMER_NUM) < pulse_end) { /* nada */ }
+ #if MINIMUM_STEPPER_PULSE
+ // Add to the value, the time that the pulse must be active (to be used on the next loop)
+ pulse_end += hal_timer_t(MIN_PULSE_TICKS);
+ #endif
+ }
+ } // LA_steps
- } // e_steps
+ return interval;
}
-
- void Stepper::advance_isr_scheduler() {
- // Run main stepping ISR if flagged
- if (!nextMainISR) isr();
-
- // Run Advance stepping ISR if flagged
- if (!nextAdvanceISR) advance_isr();
-
- // Is the next advance ISR scheduled before the next main ISR?
- if (nextAdvanceISR <= nextMainISR) {
- // Set up the next interrupt
- OCR1A = nextAdvanceISR;
- // New interval for the next main ISR
- if (nextMainISR) nextMainISR -= nextAdvanceISR;
- // Will call Stepper::advance_isr on the next interrupt
- nextAdvanceISR = 0;
- }
- else {
- // The next main ISR comes first
- OCR1A = nextMainISR;
- // New interval for the next advance ISR, if any
- if (nextAdvanceISR && nextAdvanceISR != ADV_NEVER)
- nextAdvanceISR -= nextMainISR;
- // Will call Stepper::isr on the next interrupt
- nextMainISR = 0;
- }
-
- // Don't run the ISR faster than possible
- NOLESS(OCR1A, TCNT1 + 16);
- }
-
#endif // LIN_ADVANCE
+// Check if the given block is busy or not - Must not be called from ISR contexts
+// The current_block could change in the middle of the read by an Stepper ISR, so
+// we must explicitly prevent that!
+bool Stepper::is_block_busy(const block_t* const block) {
+ #define sw_barrier() asm volatile("": : :"memory");
+
+ // Keep reading until 2 consecutive reads return the same value,
+ // meaning there was no update in-between caused by an interrupt.
+ // This works because stepper ISRs happen at a slower rate than
+ // successive reads of a variable, so 2 consecutive reads with
+ // the same value means no interrupt updated it.
+ block_t* vold, *vnew = current_block;
+ sw_barrier();
+ do {
+ vold = vnew;
+ vnew = current_block;
+ sw_barrier();
+ } while (vold != vnew);
+
+ // Return if the block is busy or not
+ return block == vnew;
+}
+
void Stepper::init() {
// Init Digipot Motor Current
@@ -1026,9 +1943,6 @@ void Stepper::init() {
if (!E_ENABLE_ON) E4_ENABLE_WRITE(HIGH);
#endif
- // Init endstops and pullups
- endstops.init();
-
#define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
#define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
#define _DISABLE(AXIS) disable_## AXIS()
@@ -1065,38 +1979,25 @@ void Stepper::init() {
AXIS_INIT(Z, Z);
#endif
- #if HAS_E0_STEP
+ #if E_STEPPERS > 0 && HAS_E0_STEP
E_AXIS_INIT(0);
#endif
- #if HAS_E1_STEP
+ #if E_STEPPERS > 1 && HAS_E1_STEP
E_AXIS_INIT(1);
#endif
- #if HAS_E2_STEP
+ #if E_STEPPERS > 2 && HAS_E2_STEP
E_AXIS_INIT(2);
#endif
- #if HAS_E3_STEP
+ #if E_STEPPERS > 3 && HAS_E3_STEP
E_AXIS_INIT(3);
#endif
- #if HAS_E4_STEP
+ #if E_STEPPERS > 4 && HAS_E4_STEP
E_AXIS_INIT(4);
#endif
- // waveform generation = 0100 = CTC
- SET_WGM(1, CTC_OCRnA);
-
- // output mode = 00 (disconnected)
- SET_COMA(1, NORMAL);
-
- // Set the timer pre-scaler
- // Generally we use a divider of 8, resulting in a 2MHz timer
- // frequency on a 16MHz MCU. If you are going to change this, be
- // sure to regenerate speed_lookuptable.h with
- // create_speed_lookuptable.py
- SET_CS(1, PRESCALER_8); // CS 2 = 1/8 prescaler
-
// Init Stepper ISR to 122 Hz for quick starting
- OCR1A = 0x4000;
- TCNT1 = 0;
+ HAL_timer_start(STEP_TIMER_NUM, 122); // OCR1A = 0x4000
+
ENABLE_STEPPER_DRIVER_INTERRUPT();
endstops.enable(true); // Start with endstops active. After homing they can be disabled
@@ -1105,12 +2006,6 @@ void Stepper::init() {
set_directions(); // Init directions to last_direction_bits = 0
}
-
-/**
- * Block until all buffered steps are executed / cleaned
- */
-void Stepper::synchronize() { while (planner.has_blocks_queued() || cleaning_buffer_counter) idle(); }
-
/**
* Set the stepper positions directly in steps
*
@@ -1120,12 +2015,7 @@ void Stepper::synchronize() { while (planner.has_blocks_queued() || cleaning_buf
* This allows get_axis_position_mm to correctly
* derive the current XYZ position later on.
*/
-void Stepper::set_position(const long &a, const long &b, const long &c, const long &e) {
-
- synchronize(); // Bad to set stepper counts in the middle of a move
-
- CRITICAL_SECTION_START;
-
+void Stepper::_set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e) {
#if CORE_IS_XY
// corexy positioning
// these equations follow the form of the dA and dB equations on http://www.corexy.com/theory.html
@@ -1148,78 +2038,33 @@ void Stepper::set_position(const long &a, const long &b, const long &c, const lo
count_position[Y_AXIS] = b;
count_position[Z_AXIS] = c;
#endif
-
count_position[E_AXIS] = e;
- CRITICAL_SECTION_END;
-}
-
-void Stepper::set_position(const AxisEnum &axis, const long &v) {
- CRITICAL_SECTION_START;
- count_position[axis] = v;
- CRITICAL_SECTION_END;
-}
-
-void Stepper::set_e_position(const long &e) {
- CRITICAL_SECTION_START;
- count_position[E_AXIS] = e;
- CRITICAL_SECTION_END;
}
/**
* Get a stepper's position in steps.
*/
-long Stepper::position(const AxisEnum axis) {
- CRITICAL_SECTION_START;
- const long count_pos = count_position[axis];
- CRITICAL_SECTION_END;
- return count_pos;
-}
-
-/**
- * Get an axis position according to stepper position(s)
- * For CORE machines apply translation from ABC to XYZ.
- */
-float Stepper::get_axis_position_mm(const AxisEnum axis) {
- float axis_steps;
- #if IS_CORE
- // Requesting one of the "core" axes?
- if (axis == CORE_AXIS_1 || axis == CORE_AXIS_2) {
- CRITICAL_SECTION_START;
- // ((a1+a2)+(a1-a2))/2 -> (a1+a2+a1-a2)/2 -> (a1+a1)/2 -> a1
- // ((a1+a2)-(a1-a2))/2 -> (a1+a2-a1+a2)/2 -> (a2+a2)/2 -> a2
- axis_steps = 0.5f * (
- axis == CORE_AXIS_2 ? CORESIGN(count_position[CORE_AXIS_1] - count_position[CORE_AXIS_2])
- : count_position[CORE_AXIS_1] + count_position[CORE_AXIS_2]
- );
- CRITICAL_SECTION_END;
- }
- else
- axis_steps = position(axis);
- #else
- axis_steps = position(axis);
- #endif
- return axis_steps * planner.steps_to_mm[axis];
-}
-
-void Stepper::finish_and_disable() {
- synchronize();
- disable_all_steppers();
-}
-
-void Stepper::quick_stop() {
- DISABLE_STEPPER_DRIVER_INTERRUPT();
- kill_current_block();
- current_block = NULL;
- cleaning_buffer_counter = 5000;
- planner.clear_block_buffer();
- ENABLE_STEPPER_DRIVER_INTERRUPT();
- #if ENABLED(ULTRA_LCD)
- planner.clear_block_buffer_runtime();
- #endif
+int32_t Stepper::position(const AxisEnum axis) {
+ const bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+
+ const int32_t v = count_position[axis];
+
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
+ return v;
}
+// Signal endstops were triggered - This function can be called from
+// an ISR context (Temperature, Stepper or limits ISR), so we must
+// be very careful here. If the interrupt being preempted was the
+// Stepper ISR (this CAN happen with the endstop limits ISR) then
+// when the stepper ISR resumes, we must be very sure that the movement
+// is properly cancelled
void Stepper::endstop_triggered(const AxisEnum axis) {
+ const bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+
#if IS_CORE
endstops_trigsteps[axis] = 0.5f * (
@@ -1233,16 +2078,34 @@ void Stepper::endstop_triggered(const AxisEnum axis) {
#endif // !COREXY && !COREXZ && !COREYZ
- kill_current_block();
- cleaning_buffer_counter = -1; // Discard the rest of the move
+ // Discard the rest of the move if there is a current block
+ quick_stop();
+
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
+}
+
+int32_t Stepper::triggered_position(const AxisEnum axis) {
+ const bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+
+ const int32_t v = endstops_trigsteps[axis];
+
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
+
+ return v;
}
void Stepper::report_positions() {
- CRITICAL_SECTION_START;
- const long xpos = count_position[X_AXIS],
- ypos = count_position[Y_AXIS],
- zpos = count_position[Z_AXIS];
- CRITICAL_SECTION_END;
+
+ // Protect the access to the position.
+ const bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+
+ const int32_t xpos = count_position[X_AXIS],
+ ypos = count_position[Y_AXIS],
+ zpos = count_position[Z_AXIS];
+
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
#if CORE_IS_XY || CORE_IS_XZ || IS_DELTA || IS_SCARA
SERIAL_PROTOCOLPGM(MSG_COUNT_A);
@@ -1270,6 +2133,12 @@ void Stepper::report_positions() {
#if ENABLED(BABYSTEPPING)
+ #if MINIMUM_STEPPER_PULSE
+ #define STEP_PULSE_CYCLES ((MINIMUM_STEPPER_PULSE) * CYCLES_PER_MICROSECOND)
+ #else
+ #define STEP_PULSE_CYCLES 0
+ #endif
+
#if ENABLED(DELTA)
#define CYCLES_EATEN_BABYSTEP (2 * 15)
#else
@@ -1283,27 +2152,27 @@ void Stepper::report_positions() {
#define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
#if EXTRA_CYCLES_BABYSTEP > 20
- #define _SAVE_START const uint32_t pulse_start = TCNT0
- #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(TCNT0 - pulse_start) * (INT0_PRESCALER)) { /* nada */ }
+ #define _SAVE_START const hal_timer_t pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM)
+ #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
#else
#define _SAVE_START NOOP
#if EXTRA_CYCLES_BABYSTEP > 0
- #define _PULSE_WAIT DELAY_NOPS(EXTRA_CYCLES_BABYSTEP)
+ #define _PULSE_WAIT DELAY_NS(EXTRA_CYCLES_BABYSTEP * NANOSECONDS_PER_CYCLE)
#elif STEP_PULSE_CYCLES > 0
#define _PULSE_WAIT NOOP
#elif ENABLED(DELTA)
- #define _PULSE_WAIT delayMicroseconds(2);
+ #define _PULSE_WAIT DELAY_US(2);
#else
- #define _PULSE_WAIT delayMicroseconds(4);
+ #define _PULSE_WAIT DELAY_US(4);
#endif
#endif
#define BABYSTEP_AXIS(AXIS, INVERT, DIR) { \
const uint8_t old_dir = _READ_DIR(AXIS); \
_ENABLE(AXIS); \
- _SAVE_START; \
_APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^DIR^INVERT); \
- _PULSE_WAIT; \
+ DELAY_NS(400); /* DRV8825 */ \
+ _SAVE_START; \
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
_PULSE_WAIT; \
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
@@ -1374,6 +2243,8 @@ void Stepper::report_positions() {
Y_DIR_WRITE(INVERT_Y_DIR ^ z_direction);
Z_DIR_WRITE(INVERT_Z_DIR ^ z_direction);
+ DELAY_NS(400); // DRV8825
+
_SAVE_START;
X_STEP_WRITE(!INVERT_X_STEP_PIN);
diff --git a/Marlin/stepper.h b/Marlin/stepper.h
index f0b95ac06c..2ac9c7756a 100644
--- a/Marlin/stepper.h
+++ b/Marlin/stepper.h
@@ -43,56 +43,191 @@
#ifndef STEPPER_H
#define STEPPER_H
+#include "MarlinConfig.h"
+
+// Disable multiple steps per ISR
+//#define DISABLE_MULTI_STEPPING
+
+//
+// Estimate the amount of time the Stepper ISR will take to execute
+//
+
+#ifndef MINIMUM_STEPPER_PULSE
+ #define MINIMUM_STEPPER_PULSE 0UL
+#endif
+
+#ifndef MAXIMUM_STEPPER_RATE
+ #if MINIMUM_STEPPER_PULSE
+ #define MAXIMUM_STEPPER_RATE (1000000UL / (2UL * (unsigned long)(MINIMUM_STEPPER_PULSE)))
+ #else
+ #define MAXIMUM_STEPPER_RATE 500000UL
+ #endif
+#endif
+
+// The base ISR takes 752 cycles
+#define ISR_BASE_CYCLES 752UL
+
+// Linear advance base time is 32 cycles
+#if ENABLED(LIN_ADVANCE)
+ #define ISR_LA_BASE_CYCLES 32UL
+#else
+ #define ISR_LA_BASE_CYCLES 0UL
+#endif
+
+// S curve interpolation adds 160 cycles
+#if ENABLED(S_CURVE_ACCELERATION)
+ #define ISR_S_CURVE_CYCLES 160UL
+#else
+ #define ISR_S_CURVE_CYCLES 0UL
+#endif
+
+// Stepper Loop base cycles
+#define ISR_LOOP_BASE_CYCLES 32UL
+
+// To start the step pulse, in the worst case takes
+#define ISR_START_STEPPER_CYCLES 57UL
+
+// And each stepper (start + stop pulse) takes in worst case
+#define ISR_STEPPER_CYCLES 88UL
+
+// Add time for each stepper
+#ifdef HAS_X_STEP
+ #define ISR_START_X_STEPPER_CYCLES ISR_START_STEPPER_CYCLES
+ #define ISR_X_STEPPER_CYCLES ISR_STEPPER_CYCLES
+#else
+ #define ISR_START_X_STEPPER_CYCLES 0UL
+ #define ISR_X_STEPPER_CYCLES 0UL
+#endif
+#ifdef HAS_Y_STEP
+ #define ISR_START_Y_STEPPER_CYCLES ISR_START_STEPPER_CYCLES
+ #define ISR_Y_STEPPER_CYCLES ISR_STEPPER_CYCLES
+#else
+ #define ISR_START_Y_STEPPER_CYCLES 0UL
+ #define ISR_Y_STEPPER_CYCLES 0UL
+#endif
+#ifdef HAS_Z_STEP
+ #define ISR_START_Z_STEPPER_CYCLES ISR_START_STEPPER_CYCLES
+ #define ISR_Z_STEPPER_CYCLES ISR_STEPPER_CYCLES
+#else
+ #define ISR_START_Z_STEPPER_CYCLES 0UL
+ #define ISR_Z_STEPPER_CYCLES 0UL
+#endif
+
+// E is always interpolated, even for mixing extruders
+#define ISR_START_E_STEPPER_CYCLES ISR_START_STEPPER_CYCLES
+#define ISR_E_STEPPER_CYCLES ISR_STEPPER_CYCLES
+
+// If linear advance is disabled, then the loop also handles them
+#if DISABLED(LIN_ADVANCE) && ENABLED(MIXING_EXTRUDER)
+ #define ISR_START_MIXING_STEPPER_CYCLES ((MIXING_STEPPERS) * (ISR_START_STEPPER_CYCLES))
+ #define ISR_MIXING_STEPPER_CYCLES ((MIXING_STEPPERS) * (ISR_STEPPER_CYCLES))
+#else
+ #define ISR_START_MIXING_STEPPER_CYCLES 0UL
+ #define ISR_MIXING_STEPPER_CYCLES 0UL
+#endif
+
+// Calculate the minimum time to start all stepper pulses in the ISR loop
+#define MIN_ISR_START_LOOP_CYCLES (ISR_START_X_STEPPER_CYCLES + ISR_START_Y_STEPPER_CYCLES + ISR_START_Z_STEPPER_CYCLES + ISR_START_E_STEPPER_CYCLES + ISR_START_MIXING_STEPPER_CYCLES)
+
+// And the total minimum loop time, not including the base
+#define MIN_ISR_LOOP_CYCLES (ISR_X_STEPPER_CYCLES + ISR_Y_STEPPER_CYCLES + ISR_Z_STEPPER_CYCLES + ISR_E_STEPPER_CYCLES + ISR_MIXING_STEPPER_CYCLES)
+
+// Calculate the minimum MPU cycles needed per pulse to enforce, limited to the max stepper rate
+#define _MIN_STEPPER_PULSE_CYCLES(N) MAX((unsigned long)((F_CPU) / (MAXIMUM_STEPPER_RATE)), ((F_CPU) / 500000UL) * (N))
+#if MINIMUM_STEPPER_PULSE
+ #define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES((unsigned long)(MINIMUM_STEPPER_PULSE))
+#else
+ #define MIN_STEPPER_PULSE_CYCLES _MIN_STEPPER_PULSE_CYCLES(1UL)
+#endif
+
+// Calculate the minimum ticks of the PULSE timer that must elapse with the step pulse enabled
+// adding the "start stepper pulse" code section execution cycles to account for that not all
+// pulses start at the beginning of the loop, so an extra time must be added to compensate so
+// the last generated pulse (usually the extruder stepper) has the right length
+#define MIN_PULSE_TICKS (((PULSE_TIMER_TICKS_PER_US) * (unsigned long)(MINIMUM_STEPPER_PULSE)) + ((MIN_ISR_START_LOOP_CYCLES) / (unsigned long)(PULSE_TIMER_PRESCALE)))
+
+// Calculate the extra ticks of the PULSE timer between step pulses
+#define ADDED_STEP_TICKS (((MIN_STEPPER_PULSE_CYCLES) / (PULSE_TIMER_PRESCALE)) - (MIN_PULSE_TICKS))
+
+// But the user could be enforcing a minimum time, so the loop time is
+#define ISR_LOOP_CYCLES (ISR_LOOP_BASE_CYCLES + MAX(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LOOP_CYCLES))
+
+// If linear advance is enabled, then it is handled separately
+#if ENABLED(LIN_ADVANCE)
+
+ // Estimate the minimum LA loop time
+ #if ENABLED(MIXING_EXTRUDER)
+ #define MIN_ISR_LA_LOOP_CYCLES ((MIXING_STEPPERS) * (ISR_STEPPER_CYCLES))
+ #else
+ #define MIN_ISR_LA_LOOP_CYCLES ISR_STEPPER_CYCLES
+ #endif
+
+ // And the real loop time
+ #define ISR_LA_LOOP_CYCLES MAX(MIN_STEPPER_PULSE_CYCLES, MIN_ISR_LA_LOOP_CYCLES)
+
+#else
+ #define ISR_LA_LOOP_CYCLES 0UL
+#endif
+
+// Now estimate the total ISR execution time in cycles given a step per ISR multiplier
+#define ISR_EXECUTION_CYCLES(R) (((ISR_BASE_CYCLES + ISR_S_CURVE_CYCLES + (ISR_LOOP_CYCLES) * (R) + ISR_LA_BASE_CYCLES + ISR_LA_LOOP_CYCLES)) / (R))
+
+// The maximum allowable stepping frequency when doing x128-x1 stepping (in Hz)
+#define MAX_STEP_ISR_FREQUENCY_128X ((F_CPU) / ISR_EXECUTION_CYCLES(128))
+#define MAX_STEP_ISR_FREQUENCY_64X ((F_CPU) / ISR_EXECUTION_CYCLES(64))
+#define MAX_STEP_ISR_FREQUENCY_32X ((F_CPU) / ISR_EXECUTION_CYCLES(32))
+#define MAX_STEP_ISR_FREQUENCY_16X ((F_CPU) / ISR_EXECUTION_CYCLES(16))
+#define MAX_STEP_ISR_FREQUENCY_8X ((F_CPU) / ISR_EXECUTION_CYCLES(8))
+#define MAX_STEP_ISR_FREQUENCY_4X ((F_CPU) / ISR_EXECUTION_CYCLES(4))
+#define MAX_STEP_ISR_FREQUENCY_2X ((F_CPU) / ISR_EXECUTION_CYCLES(2))
+#define MAX_STEP_ISR_FREQUENCY_1X ((F_CPU) / ISR_EXECUTION_CYCLES(1))
+
+// The minimum allowable frequency for step smoothing will be 1/10 of the maximum nominal frequency (in Hz)
+#define MIN_STEP_ISR_FREQUENCY MAX_STEP_ISR_FREQUENCY_1X
+
+//
+// Stepper class definition
+//
+
#include "planner.h"
#include "speed_lookuptable.h"
#include "stepper_indirection.h"
#include "language.h"
#include "types.h"
-class Stepper;
-extern Stepper stepper;
-
-#define ENABLE_STEPPER_DRIVER_INTERRUPT() SBI(TIMSK1, OCIE1A)
-#define DISABLE_STEPPER_DRIVER_INTERRUPT() CBI(TIMSK1, OCIE1A)
-#define STEPPER_ISR_ENABLED() TEST(TIMSK1, OCIE1A)
-
// intRes = intIn1 * intIn2 >> 16
// uses:
// r26 to store 0
// r27 to store the byte 1 of the 24 bit result
-#define MultiU16X8toH16(intRes, charIn1, intIn2) \
- asm volatile ( \
- "clr r26 \n\t" \
- "mul %A1, %B2 \n\t" \
- "movw %A0, r0 \n\t" \
- "mul %A1, %A2 \n\t" \
- "add %A0, r1 \n\t" \
- "adc %B0, r26 \n\t" \
- "lsr r0 \n\t" \
- "adc %A0, r26 \n\t" \
- "adc %B0, r26 \n\t" \
- "clr r1 \n\t" \
- : \
- "=&r" (intRes) \
- : \
- "d" (charIn1), \
- "d" (intIn2) \
- : \
- "r26" \
- )
+static FORCE_INLINE uint16_t MultiU16X8toH16(uint8_t charIn1, uint16_t intIn2) {
+ register uint8_t tmp;
+ register uint16_t intRes;
+ __asm__ __volatile__ (
+ A("clr %[tmp]")
+ A("mul %[charIn1], %B[intIn2]")
+ A("movw %A[intRes], r0")
+ A("mul %[charIn1], %A[intIn2]")
+ A("add %A[intRes], r1")
+ A("adc %B[intRes], %[tmp]")
+ A("lsr r0")
+ A("adc %A[intRes], %[tmp]")
+ A("adc %B[intRes], %[tmp]")
+ A("clr r1")
+ : [intRes] "=&r" (intRes),
+ [tmp] "=&r" (tmp)
+ : [charIn1] "d" (charIn1),
+ [intIn2] "d" (intIn2)
+ : "cc"
+ );
+ return intRes;
+}
class Stepper {
public:
- static block_t* current_block; // A pointer to the block currently being traced
-
- #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
- static bool abort_on_endstop_hit;
- #endif
-
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
- static bool performing_homing;
+ static bool homing_dual_axis;
#endif
#if HAS_MOTOR_CURRENT_PWM
@@ -102,74 +237,92 @@ class Stepper {
static uint32_t motor_current_setting[3];
#endif
- static int16_t cleaning_buffer_counter;
-
private:
- static uint8_t last_direction_bits; // The next stepping-bits to be output
+ static block_t* current_block; // A pointer to the block currently being traced
+
+ static uint8_t last_direction_bits, // The next stepping-bits to be output
+ axis_did_move; // Last Movement in the given direction is not null, as computed when the last movement was fetched from planner
+
+ static bool abort_current_block; // Signals to the stepper that current block should be aborted
+
+ #if DISABLED(MIXING_EXTRUDER)
+ static uint8_t last_moved_extruder; // Last-moved extruder, as set when the last movement was fetched from planner
+ #endif
#if ENABLED(X_DUAL_ENDSTOPS)
- static bool locked_x_motor, locked_x2_motor;
+ static bool locked_X_motor, locked_X2_motor;
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
- static bool locked_y_motor, locked_y2_motor;
+ static bool locked_Y_motor, locked_Y2_motor;
#endif
#if ENABLED(Z_DUAL_ENDSTOPS)
- static bool locked_z_motor, locked_z2_motor;
+ static bool locked_Z_motor, locked_Z2_motor;
#endif
- // Counter variables for the Bresenham line tracer
- static long counter_X, counter_Y, counter_Z, counter_E;
- static volatile uint32_t step_events_completed; // The number of step events executed in the current block
+ static uint32_t acceleration_time, deceleration_time; // time measured in Stepper Timer ticks
+ static uint8_t steps_per_isr; // Count of steps to perform per Stepper ISR call
+ #if ENABLED(ADAPTIVE_STEP_SMOOTHING)
+ static uint8_t oversampling_factor; // Oversampling factor (log2(multiplier)) to increase temporal resolution of axis
+ #else
+ static constexpr uint8_t oversampling_factor = 0;
+ #endif
+
+ // Delta error variables for the Bresenham line tracer
+ static int32_t delta_error[XYZE];
+ static uint32_t advance_dividend[XYZE],
+ advance_divisor,
+ step_events_completed, // The number of step events executed in the current block
+ accelerate_until, // The point from where we need to stop acceleration
+ decelerate_after, // The point from where we need to start decelerating
+ step_event_count; // The total event count for the current block
+
+ // Mixing extruder mix delta_errors for bresenham tracing
+ #if ENABLED(MIXING_EXTRUDER)
+ static int32_t delta_error_m[MIXING_STEPPERS];
+ static uint32_t advance_dividend_m[MIXING_STEPPERS],
+ advance_divisor_m;
+ #define MIXING_STEPPERS_LOOP(VAR) \
+ for (uint8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
+ #else
+ static int8_t active_extruder; // Active extruder
+ #endif
+
+ #if ENABLED(S_CURVE_ACCELERATION)
+ static int32_t bezier_A, // A coefficient in Bézier speed curve
+ bezier_B, // B coefficient in Bézier speed curve
+ bezier_C; // C coefficient in Bézier speed curve
+ static uint32_t bezier_F, // F coefficient in Bézier speed curve
+ bezier_AV; // AV coefficient in Bézier speed curve
+ static bool A_negative, // If A coefficient was negative
+ bezier_2nd_half; // If Bézier curve has been initialized or not
+ #endif
+
+ static uint32_t nextMainISR; // time remaining for the next Step ISR
#if ENABLED(LIN_ADVANCE)
+ static uint32_t nextAdvanceISR, LA_isr_rate;
+ static uint16_t LA_current_adv_steps, LA_final_adv_steps, LA_max_adv_steps; // Copy from current executed block. Needed because current_block is set to NULL "too early".
+ static int8_t LA_steps;
+ static bool LA_use_advance_lead;
+ #endif // LIN_ADVANCE
- static uint32_t LA_decelerate_after; // Copy from current executed block. Needed because current_block is set to NULL "too early".
- static uint16_t nextMainISR, nextAdvanceISR, eISR_Rate, current_adv_steps,
- final_adv_steps, max_adv_steps; // Copy from current executed block. Needed because current_block is set to NULL "too early".
- #define _NEXT_ISR(T) nextMainISR = T
- static int8_t e_steps;
- static bool use_advance_lead;
- #if E_STEPPERS > 1
- static int8_t LA_active_extruder; // Copy from current executed block. Needed because current_block is set to NULL "too early".
- #else
- static constexpr int8_t LA_active_extruder = 0;
- #endif
+ static int32_t ticks_nominal;
+ #if DISABLED(S_CURVE_ACCELERATION)
+ static uint32_t acc_step_rate; // needed for deceleration start point
+ #endif
- #else // !LIN_ADVANCE
-
- #define _NEXT_ISR(T) OCR1A = T
-
- #endif // !LIN_ADVANCE
-
- static long acceleration_time, deceleration_time;
- static uint8_t step_loops, step_loops_nominal;
-
- static uint16_t OCR1A_nominal,
- acc_step_rate; // needed for deceleration start point
-
- static volatile long endstops_trigsteps[XYZ];
- static volatile long endstops_stepsTotal, endstops_stepsDone;
+ static volatile int32_t endstops_trigsteps[XYZ];
//
// Positions of stepper motors, in step units
//
- static volatile long count_position[NUM_AXIS];
+ static volatile int32_t count_position[NUM_AXIS];
//
// Current direction of stepper motors (+1 or -1)
//
- static volatile signed char count_direction[NUM_AXIS];
-
- //
- // Mixing extruder mix counters
- //
- #if ENABLED(MIXING_EXTRUDER)
- static long counter_m[MIXING_STEPPERS];
- #define MIXING_STEPPERS_LOOP(VAR) \
- for (uint8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++) \
- if (current_block->mix_event_count[VAR])
- #endif
+ static int8_t count_direction[NUM_AXIS];
public:
@@ -178,82 +331,64 @@ class Stepper {
//
Stepper() { };
- //
// Initialize stepper hardware
- //
static void init();
- //
// Interrupt Service Routines
- //
+ // The ISR scheduler
static void isr();
+ // The stepper pulse phase ISR
+ static void stepper_pulse_phase_isr();
+
+ // The stepper block processing phase ISR
+ static uint32_t stepper_block_phase_isr();
+
#if ENABLED(LIN_ADVANCE)
- static void advance_isr();
- static void advance_isr_scheduler();
+ // The Linear advance stepper ISR
+ static uint32_t advance_isr();
#endif
- //
- // Block until all buffered steps are executed
- //
- static void synchronize();
+ // Check if the given block is busy or not - Must not be called from ISR contexts
+ static bool is_block_busy(const block_t* const block);
- //
- // Set the current position in steps
- //
- static void set_position(const long &a, const long &b, const long &c, const long &e);
- static void set_position(const AxisEnum &a, const long &v);
- static void set_e_position(const long &e);
-
- //
- // Set direction bits for all steppers
- //
- static void set_directions();
-
- //
// Get the position of a stepper, in steps
- //
- static long position(const AxisEnum axis);
+ static int32_t position(const AxisEnum axis);
- //
// Report the positions of the steppers, in steps
- //
static void report_positions();
- //
- // Get the position (mm) of an axis based on stepper position(s)
- //
- static float get_axis_position_mm(const AxisEnum axis);
-
- //
- // SCARA AB axes are in degrees, not mm
- //
- #if IS_SCARA
- FORCE_INLINE static float get_axis_position_degrees(const AxisEnum axis) { return get_axis_position_mm(axis); }
- #endif
-
- //
// The stepper subsystem goes to sleep when it runs out of things to execute. Call this
// to notify the subsystem that it is time to go to work.
- //
static void wake_up();
- //
- // Wait for moves to finish and disable all steppers
- //
- static void finish_and_disable();
+ // Quickly stop all steppers
+ FORCE_INLINE static void quick_stop() { abort_current_block = true; }
- //
- // Quickly stop all steppers and clear the blocks queue
- //
- static void quick_stop();
-
- //
// The direction of a single motor
- //
FORCE_INLINE static bool motor_direction(const AxisEnum axis) { return TEST(last_direction_bits, axis); }
+ // The last movement direction was not null on the specified axis. Note that motor direction is not necessarily the same.
+ FORCE_INLINE static bool axis_is_moving(const AxisEnum axis) { return TEST(axis_did_move, axis); }
+
+ // The extruder associated to the last movement
+ FORCE_INLINE static uint8_t movement_extruder() {
+ return
+ #if ENABLED(MIXING_EXTRUDER)
+ 0
+ #else
+ last_moved_extruder
+ #endif
+ ;
+ }
+
+ // Handle a triggered endstop
+ static void endstop_triggered(const AxisEnum axis);
+
+ // Triggered position of an axis in steps
+ static int32_t triggered_position(const AxisEnum axis);
+
#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
static void digitalPotWrite(const int16_t address, const int16_t value);
static void digipot_current(const uint8_t driver, const int16_t current);
@@ -265,125 +400,117 @@ class Stepper {
static void microstep_readings();
#endif
+ #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
+ FORCE_INLINE static void set_homing_dual_axis(const bool state) { homing_dual_axis = state; }
+ #endif
#if ENABLED(X_DUAL_ENDSTOPS)
- FORCE_INLINE static void set_homing_flag_x(const bool state) { performing_homing = state; }
- FORCE_INLINE static void set_x_lock(const bool state) { locked_x_motor = state; }
- FORCE_INLINE static void set_x2_lock(const bool state) { locked_x2_motor = state; }
+ FORCE_INLINE static void set_x_lock(const bool state) { locked_X_motor = state; }
+ FORCE_INLINE static void set_x2_lock(const bool state) { locked_X2_motor = state; }
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
- FORCE_INLINE static void set_homing_flag_y(const bool state) { performing_homing = state; }
- FORCE_INLINE static void set_y_lock(const bool state) { locked_y_motor = state; }
- FORCE_INLINE static void set_y2_lock(const bool state) { locked_y2_motor = state; }
+ FORCE_INLINE static void set_y_lock(const bool state) { locked_Y_motor = state; }
+ FORCE_INLINE static void set_y2_lock(const bool state) { locked_Y2_motor = state; }
#endif
#if ENABLED(Z_DUAL_ENDSTOPS)
- FORCE_INLINE static void set_homing_flag_z(const bool state) { performing_homing = state; }
- FORCE_INLINE static void set_z_lock(const bool state) { locked_z_motor = state; }
- FORCE_INLINE static void set_z2_lock(const bool state) { locked_z2_motor = state; }
+ FORCE_INLINE static void set_z_lock(const bool state) { locked_Z_motor = state; }
+ FORCE_INLINE static void set_z2_lock(const bool state) { locked_Z2_motor = state; }
#endif
#if ENABLED(BABYSTEPPING)
static void babystep(const AxisEnum axis, const bool direction); // perform a short step with a single stepper motor, outside of any convention
#endif
- static inline void kill_current_block() {
- step_events_completed = current_block->step_event_count;
- }
-
- //
- // Handle a triggered endstop
- //
- static void endstop_triggered(const AxisEnum axis);
-
- //
- // Triggered position of an axis in mm (not core-savvy)
- //
- FORCE_INLINE static float triggered_position_mm(const AxisEnum axis) {
- return endstops_trigsteps[axis] * planner.steps_to_mm[axis];
- }
-
#if HAS_MOTOR_CURRENT_PWM
static void refresh_motor_power();
#endif
+ // Set the current position in steps
+ inline static void set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e) {
+ planner.synchronize();
+ const bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+ _set_position(a, b, c, e);
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
+ }
+
+ inline static void set_position(const AxisEnum a, const int32_t &v) {
+ planner.synchronize();
+
+ const bool was_enabled = STEPPER_ISR_ENABLED();
+ if (was_enabled) DISABLE_STEPPER_DRIVER_INTERRUPT();
+
+ count_position[a] = v;
+
+ if (was_enabled) ENABLE_STEPPER_DRIVER_INTERRUPT();
+ }
+
private:
- FORCE_INLINE static unsigned short calc_timer_interval(unsigned short step_rate) {
- unsigned short timer;
+ // Set the current position in steps
+ static void _set_position(const int32_t &a, const int32_t &b, const int32_t &c, const int32_t &e);
- NOMORE(step_rate, MAX_STEP_FREQUENCY);
+ // Set direction bits for all steppers
+ static void set_directions();
- if (step_rate > 20000) { // If steprate > 20kHz >> step 4 times
- step_rate >>= 2;
- step_loops = 4;
- }
- else if (step_rate > 10000) { // If steprate > 10kHz >> step 2 times
- step_rate >>= 1;
- step_loops = 2;
- }
- else {
- step_loops = 1;
- }
+ FORCE_INLINE static uint32_t calc_timer_interval(uint32_t step_rate, uint8_t scale, uint8_t* loops) {
+ uint32_t timer;
- NOLESS(step_rate, F_CPU / 500000);
- step_rate -= F_CPU / 500000; // Correct for minimal speed
+ // Scale the frequency, as requested by the caller
+ step_rate <<= scale;
+
+ uint8_t multistep = 1;
+ #if DISABLED(DISABLE_MULTI_STEPPING)
+
+ // The stepping frequency limits for each multistepping rate
+ static const uint32_t limit[] PROGMEM = {
+ ( MAX_STEP_ISR_FREQUENCY_1X ),
+ ( MAX_STEP_ISR_FREQUENCY_2X >> 1),
+ ( MAX_STEP_ISR_FREQUENCY_4X >> 2),
+ ( MAX_STEP_ISR_FREQUENCY_8X >> 3),
+ ( MAX_STEP_ISR_FREQUENCY_16X >> 4),
+ ( MAX_STEP_ISR_FREQUENCY_32X >> 5),
+ ( MAX_STEP_ISR_FREQUENCY_64X >> 6),
+ (MAX_STEP_ISR_FREQUENCY_128X >> 7)
+ };
+
+ // Select the proper multistepping
+ uint8_t idx = 0;
+ while (idx < 7 && step_rate > (uint32_t)pgm_read_dword(&limit[idx])) {
+ step_rate >>= 1;
+ multistep <<= 1;
+ ++idx;
+ };
+ #else
+ NOMORE(step_rate, uint32_t(MAX_STEP_ISR_FREQUENCY_1X));
+ #endif
+ *loops = multistep;
+
+ constexpr uint32_t min_step_rate = F_CPU / 500000U;
+ NOLESS(step_rate, min_step_rate);
+ step_rate -= min_step_rate; // Correct for minimal speed
if (step_rate >= (8 * 256)) { // higher step rate
- unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate >> 8)][0];
- unsigned char tmp_step_rate = (step_rate & 0x00FF);
- unsigned short gain = (unsigned short)pgm_read_word_near(table_address + 2);
- MultiU16X8toH16(timer, tmp_step_rate, gain);
- timer = (unsigned short)pgm_read_word_near(table_address) - timer;
+ const uint8_t tmp_step_rate = (step_rate & 0x00FF);
+ const uint16_t table_address = (uint16_t)&speed_lookuptable_fast[(uint8_t)(step_rate >> 8)][0],
+ gain = (uint16_t)pgm_read_word_near(table_address + 2);
+ timer = MultiU16X8toH16(tmp_step_rate, gain);
+ timer = (uint16_t)pgm_read_word_near(table_address) - timer;
}
else { // lower step rates
- unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0];
+ uint16_t table_address = (uint16_t)&speed_lookuptable_slow[0][0];
table_address += ((step_rate) >> 1) & 0xFFFC;
- timer = (unsigned short)pgm_read_word_near(table_address);
- timer -= (((unsigned short)pgm_read_word_near(table_address + 2) * (unsigned char)(step_rate & 0x0007)) >> 3);
- }
- if (timer < 100) { // (20kHz - this should never happen)
- timer = 100;
- SERIAL_PROTOCOL(MSG_STEPPER_TOO_HIGH);
- SERIAL_PROTOCOLLN(step_rate);
+ timer = (uint16_t)pgm_read_word_near(table_address)
+ - (((uint16_t)pgm_read_word_near(table_address + 2) * (uint8_t)(step_rate & 0x0007)) >> 3);
}
+ // (there is no need to limit the timer value here. All limits have been
+ // applied above, and AVR is able to keep up at 30khz Stepping ISR rate)
+
return timer;
}
- // Initialize the trapezoid generator from the current block.
- // Called whenever a new block begins.
- FORCE_INLINE static void trapezoid_generator_reset() {
-
- static int8_t last_extruder = -1;
-
- #if ENABLED(LIN_ADVANCE)
- #if E_STEPPERS > 1
- if (current_block->active_extruder != last_extruder) {
- current_adv_steps = 0; // If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
- LA_active_extruder = current_block->active_extruder;
- }
- #endif
-
- if ((use_advance_lead = current_block->use_advance_lead)) {
- LA_decelerate_after = current_block->decelerate_after;
- final_adv_steps = current_block->final_adv_steps;
- max_adv_steps = current_block->max_adv_steps;
- }
- #endif
-
- if (current_block->direction_bits != last_direction_bits || current_block->active_extruder != last_extruder) {
- last_direction_bits = current_block->direction_bits;
- last_extruder = current_block->active_extruder;
- set_directions();
- }
-
- deceleration_time = 0;
- // step_rate to timer interval
- OCR1A_nominal = calc_timer_interval(current_block->nominal_rate);
- // make a note of the number of step loops required at nominal speed
- step_loops_nominal = step_loops;
- acc_step_rate = current_block->initial_rate;
- acceleration_time = calc_timer_interval(acc_step_rate);
- _NEXT_ISR(acceleration_time);
-
- }
+ #if ENABLED(S_CURVE_ACCELERATION)
+ static void _calc_bezier_curve_coeffs(const int32_t v0, const int32_t v1, const uint32_t av);
+ static int32_t _eval_bezier_curve(const uint32_t curr_step);
+ #endif
#if HAS_DIGIPOTSS || HAS_MOTOR_CURRENT_PWM
static void digipot_init();
@@ -395,4 +522,6 @@ class Stepper {
};
+extern Stepper stepper;
+
#endif // STEPPER_H
diff --git a/Marlin/stepper_dac.cpp b/Marlin/stepper_dac.cpp
index 2013d20302..d5f713fedb 100644
--- a/Marlin/stepper_dac.cpp
+++ b/Marlin/stepper_dac.cpp
@@ -91,8 +91,8 @@
mcp4728_simpleCommand(UPDATE);
}
- static float dac_perc(int8_t n) { return 100.0 * mcp4728_getValue(dac_order[n]) * (1.0 / (DAC_STEPPER_MAX)); }
- static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * (1.0 / (DAC_STEPPER_SENSE)); }
+ static float dac_perc(int8_t n) { return 100.0f * mcp4728_getValue(dac_order[n]) * (1.0f / (DAC_STEPPER_MAX)); }
+ static float dac_amps(int8_t n) { return mcp4728_getDrvPct(dac_order[n]) * (DAC_STEPPER_MAX) * 0.125 * (1.0f / (DAC_STEPPER_SENSE)); }
uint8_t dac_current_get_percent(const AxisEnum axis) { return mcp4728_getDrvPct(dac_order[axis]); }
void dac_current_set_percents(const uint8_t pct[XYZE]) {
diff --git a/Marlin/stepper_indirection.cpp b/Marlin/stepper_indirection.cpp
index 8e3f7e9e22..32ef99a710 100644
--- a/Marlin/stepper_indirection.cpp
+++ b/Marlin/stepper_indirection.cpp
@@ -42,7 +42,7 @@
#include
#include
- #define _TMC26X_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_ENABLE_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_MAX_CURRENT, ST##_SENSE_RESISTOR)
+ #define _TMC26X_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_CS_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_MAX_CURRENT, ST##_SENSE_RESISTOR)
#if ENABLED(X_IS_TMC26X)
_TMC26X_DEFINE(X);
@@ -179,6 +179,10 @@
// Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
// https://www.trinamic.com/products/integrated-circuits/details/tmc2130/
void tmc2130_init(TMC2130Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
+ #if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD)
+ UNUSED(thrs);
+ UNUSED(spmm);
+ #endif
st.begin();
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
st.microsteps(microsteps);
@@ -196,12 +200,7 @@
st.stealthChop(1);
#if ENABLED(HYBRID_THRESHOLD)
st.stealth_max_speed(12650000UL*microsteps/(256*thrs*spmm));
- #else
- UNUSED(thrs);
- UNUSED(spmm);
#endif
- #elif ENABLED(SENSORLESS_HOMING)
- st.coolstep_min_speed(1024UL * 1024UL - 1UL);
#endif
st.GSTAT(); // Clear GSTAT
}
@@ -245,7 +244,7 @@
#if ENABLED(SENSORLESS_HOMING)
#define TMC_INIT_SGT(P,Q) stepper##Q.sgt(P##_HOMING_SENSITIVITY);
- #ifdef X_HOMING_SENSITIVITY
+ #if X_SENSORLESS
#if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
stepperX.sgt(X_HOMING_SENSITIVITY);
#endif
@@ -253,7 +252,7 @@
stepperX2.sgt(X_HOMING_SENSITIVITY);
#endif
#endif
- #ifdef Y_HOMING_SENSITIVITY
+ #if Y_SENSORLESS
#if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
stepperY.sgt(Y_HOMING_SENSITIVITY);
#endif
@@ -261,7 +260,7 @@
stepperY2.sgt(Y_HOMING_SENSITIVITY);
#endif
#endif
- #ifdef Z_HOMING_SENSITIVITY
+ #if Z_SENSORLESS
#if ENABLED(Z_IS_TMC2130) || ENABLED(IS_TRAMS)
stepperZ.sgt(Z_HOMING_SENSITIVITY);
#endif
diff --git a/Marlin/stepper_indirection.h b/Marlin/stepper_indirection.h
index 472b0884bf..3e67118d86 100644
--- a/Marlin/stepper_indirection.h
+++ b/Marlin/stepper_indirection.h
@@ -446,69 +446,54 @@ void reset_stepper_drivers(); // Called by settings.load / settings.reset
/**
* Extruder indirection for the single E axis
*/
-#if ENABLED(SWITCHING_EXTRUDER)
- #if EXTRUDERS == 2
- #define E_STEP_WRITE(v) E0_STEP_WRITE(v)
- #define NORM_E_DIR() do{ E0_DIR_WRITE(current_block->active_extruder ? INVERT_E0_DIR : !INVERT_E0_DIR); }while(0)
- #define REV_E_DIR() do{ E0_DIR_WRITE(current_block->active_extruder ? !INVERT_E0_DIR : INVERT_E0_DIR); }while(0)
- #elif EXTRUDERS > 4
- #define E_STEP_WRITE(v) do{ if (current_block->active_extruder < 2) { E0_STEP_WRITE(v); } else if (current_block->active_extruder < 4) { E1_STEP_WRITE(v); } else { E2_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E0_DIR_WRITE(INVERT_E0_DIR); break; case 2: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 3: E1_DIR_WRITE(INVERT_E1_DIR); break; case 4: E2_DIR_WRITE(!INVERT_E2_DIR); } }while(0)
- #define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(INVERT_E0_DIR); break; case 1: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 2: E1_DIR_WRITE(INVERT_E1_DIR); break; case 3: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 4: E2_DIR_WRITE(INVERT_E2_DIR); } }while(0)
+#if ENABLED(SWITCHING_EXTRUDER) // One stepper driver per two extruders, reversed on odd index
+ #if EXTRUDERS > 4
+ #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else if (E < 4) { E1_STEP_WRITE(V); } else { E2_STEP_WRITE(V); } }while(0)
+ #define NORM_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E0_DIR_WRITE( INVERT_E0_DIR); break; case 2: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 3: E1_DIR_WRITE( INVERT_E1_DIR); break; case 4: E2_DIR_WRITE(!INVERT_E2_DIR); } }while(0)
+ #define REV_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 2: E1_DIR_WRITE( INVERT_E1_DIR); break; case 3: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 4: E2_DIR_WRITE( INVERT_E2_DIR); } }while(0)
+ #elif EXTRUDERS > 3
+ #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0)
+ #define NORM_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E0_DIR_WRITE( INVERT_E0_DIR); break; case 2: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 3: E1_DIR_WRITE( INVERT_E1_DIR); } }while(0)
+ #define REV_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 2: E1_DIR_WRITE( INVERT_E1_DIR); break; case 3: E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
#elif EXTRUDERS > 2
- #define E_STEP_WRITE(v) do{ if (current_block->active_extruder < 2) { E0_STEP_WRITE(v); } else if (current_block->active_extruder < 4) { E1_STEP_WRITE(v); } else { E1_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E0_DIR_WRITE(INVERT_E0_DIR); break; case 2: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 3: E1_DIR_WRITE(INVERT_E1_DIR); } }while(0)
- #define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(INVERT_E0_DIR); break; case 1: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 2: E1_DIR_WRITE(INVERT_E1_DIR); break; case 3: E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
+ #define E_STEP_WRITE(E,V) do{ if (E < 2) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0)
+ #define NORM_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E0_DIR_WRITE( INVERT_E0_DIR); break; case 2: E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
+ #define REV_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 2: E1_DIR_WRITE( INVERT_E1_DIR); } }while(0)
+ #else
+ #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
+ #define NORM_E_DIR(E) do{ E0_DIR_WRITE(E ? INVERT_E0_DIR : !INVERT_E0_DIR); }while(0)
+ #define REV_E_DIR(E) do{ E0_DIR_WRITE(E ? !INVERT_E0_DIR : INVERT_E0_DIR); }while(0)
#endif
-#elif ENABLED(MK2_MULTIPLEXER) // Even-numbered steppers are reversed
- #define E_STEP_WRITE(v) E0_STEP_WRITE(v)
- #define NORM_E_DIR() do{ E0_DIR_WRITE(TEST(current_block->active_extruder, 0) ? !INVERT_E0_DIR: INVERT_E0_DIR); }while(0)
- #define REV_E_DIR() do{ E0_DIR_WRITE(TEST(current_block->active_extruder, 0) ? INVERT_E0_DIR: !INVERT_E0_DIR); }while(0)
-#elif EXTRUDERS > 4
- #define E_STEP_WRITE(v) do{ switch (current_block->active_extruder) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); break; case 3: E3_STEP_WRITE(v); break; case 4: E4_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(!INVERT_E2_DIR); break; case 3: E3_DIR_WRITE(!INVERT_E3_DIR); break; case 4: E4_DIR_WRITE(!INVERT_E4_DIR); } }while(0)
- #define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(INVERT_E2_DIR); break; case 3: E3_DIR_WRITE(INVERT_E3_DIR); break; case 4: E4_DIR_WRITE(INVERT_E4_DIR); } }while(0)
-#elif EXTRUDERS > 3
- #define E_STEP_WRITE(v) do{ switch (current_block->active_extruder) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); break; case 3: E3_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(!INVERT_E2_DIR); break; case 3: E3_DIR_WRITE(!INVERT_E3_DIR); } }while(0)
- #define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(INVERT_E2_DIR); break; case 3: E3_DIR_WRITE(INVERT_E3_DIR); } }while(0)
-#elif EXTRUDERS > 2
- #define E_STEP_WRITE(v) do{ switch (current_block->active_extruder) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(!INVERT_E2_DIR); } }while(0)
- #define REV_E_DIR() do{ switch (current_block->active_extruder) { case 0: E0_DIR_WRITE(INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(INVERT_E2_DIR); } }while(0)
-#elif EXTRUDERS > 1
+#elif ENABLED(MK2_MULTIPLEXER) // One multiplexed stepper driver, reversed on odd index
+ #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
+ #define NORM_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 0) ? !INVERT_E0_DIR: INVERT_E0_DIR); }while(0)
+ #define REV_E_DIR(E) do{ E0_DIR_WRITE(TEST(E, 0) ? INVERT_E0_DIR: !INVERT_E0_DIR); }while(0)
+#elif E_STEPPERS > 4
+ #define E_STEP_WRITE(E,V) do{ switch (E) { case 0: E0_STEP_WRITE(V); break; case 1: E1_STEP_WRITE(V); break; case 2: E2_STEP_WRITE(V); break; case 3: E3_STEP_WRITE(V); break; case 4: E4_STEP_WRITE(V); } }while(0)
+ #define NORM_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(!INVERT_E2_DIR); break; case 3: E3_DIR_WRITE(!INVERT_E3_DIR); break; case 4: E4_DIR_WRITE(!INVERT_E4_DIR); } }while(0)
+ #define REV_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E1_DIR_WRITE( INVERT_E1_DIR); break; case 2: E2_DIR_WRITE( INVERT_E2_DIR); break; case 3: E3_DIR_WRITE( INVERT_E3_DIR); break; case 4: E4_DIR_WRITE( INVERT_E4_DIR); } }while(0)
+#elif E_STEPPERS > 3
+ #define E_STEP_WRITE(E,V) do{ switch (E) { case 0: E0_STEP_WRITE(V); break; case 1: E1_STEP_WRITE(V); break; case 2: E2_STEP_WRITE(V); break; case 3: E3_STEP_WRITE(V); } }while(0)
+ #define NORM_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(!INVERT_E2_DIR); break; case 3: E3_DIR_WRITE(!INVERT_E3_DIR); } }while(0)
+ #define REV_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E1_DIR_WRITE( INVERT_E1_DIR); break; case 2: E2_DIR_WRITE( INVERT_E2_DIR); break; case 3: E3_DIR_WRITE( INVERT_E3_DIR); } }while(0)
+#elif E_STEPPERS > 2
+ #define E_STEP_WRITE(E,V) do{ switch (E) { case 0: E0_STEP_WRITE(V); break; case 1: E1_STEP_WRITE(V); break; case 2: E2_STEP_WRITE(V); } }while(0)
+ #define NORM_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE(!INVERT_E0_DIR); break; case 1: E1_DIR_WRITE(!INVERT_E1_DIR); break; case 2: E2_DIR_WRITE(!INVERT_E2_DIR); } }while(0)
+ #define REV_E_DIR(E) do{ switch (E) { case 0: E0_DIR_WRITE( INVERT_E0_DIR); break; case 1: E1_DIR_WRITE( INVERT_E1_DIR); break; case 2: E2_DIR_WRITE( INVERT_E2_DIR); } }while(0)
+#elif E_STEPPERS > 1
#if ENABLED(DUAL_X_CARRIAGE) || ENABLED(DUAL_NOZZLE_DUPLICATION_MODE)
- #define E_STEP_WRITE(v) do{ if (extruder_duplication_enabled) { E0_STEP_WRITE(v); E1_STEP_WRITE(v); } else if (current_block->active_extruder == 0) { E0_STEP_WRITE(v); } else { E1_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ if (extruder_duplication_enabled) { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); } else if (current_block->active_extruder == 0) { E0_DIR_WRITE(!INVERT_E0_DIR); } else { E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
- #define REV_E_DIR() do{ if (extruder_duplication_enabled) { E0_DIR_WRITE(INVERT_E0_DIR); E1_DIR_WRITE(INVERT_E1_DIR); } else if (current_block->active_extruder == 0) { E0_DIR_WRITE(INVERT_E0_DIR); } else { E1_DIR_WRITE(INVERT_E1_DIR); } }while(0)
+ #define E_STEP_WRITE(E,V) do{ if (extruder_duplication_enabled) { E0_STEP_WRITE(V); E1_STEP_WRITE(V); } else if (E == 0) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0)
+ #define NORM_E_DIR(E) do{ if (extruder_duplication_enabled) { E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); } else if (E == 0) { E0_DIR_WRITE(!INVERT_E0_DIR); } else { E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
+ #define REV_E_DIR(E) do{ if (extruder_duplication_enabled) { E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); } else if (E == 0) { E0_DIR_WRITE( INVERT_E0_DIR); } else { E1_DIR_WRITE( INVERT_E1_DIR); } }while(0)
#else
- #define E_STEP_WRITE(v) do{ if (current_block->active_extruder == 0) { E0_STEP_WRITE(v); } else { E1_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ if (current_block->active_extruder == 0) { E0_DIR_WRITE(!INVERT_E0_DIR); } else { E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
- #define REV_E_DIR() do{ if (current_block->active_extruder == 0) { E0_DIR_WRITE(INVERT_E0_DIR); } else { E1_DIR_WRITE(INVERT_E1_DIR); } }while(0)
- #endif
-#elif ENABLED(MIXING_EXTRUDER)
- #define E_STEP_WRITE(v) NOOP /* not used for mixing extruders! */
- #if MIXING_STEPPERS > 4
- #define En_STEP_WRITE(n,v) do{ switch (n) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); break; case 3: E3_STEP_WRITE(v); break; case 4: E4_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); E2_DIR_WRITE(!INVERT_E2_DIR); E3_DIR_WRITE(!INVERT_E3_DIR); E4_DIR_WRITE(!INVERT_E4_DIR); }while(0)
- #define REV_E_DIR() do{ E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); E2_DIR_WRITE( INVERT_E2_DIR); E3_DIR_WRITE( INVERT_E3_DIR); E4_DIR_WRITE( INVERT_E4_DIR); }while(0)
- #elif MIXING_STEPPERS > 3
- #define En_STEP_WRITE(n,v) do{ switch (n) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); break; case 3: E3_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); E2_DIR_WRITE(!INVERT_E2_DIR); E3_DIR_WRITE(!INVERT_E3_DIR); }while(0)
- #define REV_E_DIR() do{ E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); E2_DIR_WRITE( INVERT_E2_DIR); E3_DIR_WRITE( INVERT_E3_DIR); }while(0)
- #elif MIXING_STEPPERS > 2
- #define En_STEP_WRITE(n,v) do{ switch (n) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); break; case 2: E2_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); E2_DIR_WRITE(!INVERT_E2_DIR); }while(0)
- #define REV_E_DIR() do{ E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); E2_DIR_WRITE( INVERT_E2_DIR); }while(0)
- #else
- #define En_STEP_WRITE(n,v) do{ switch (n) { case 0: E0_STEP_WRITE(v); break; case 1: E1_STEP_WRITE(v); } }while(0)
- #define NORM_E_DIR() do{ E0_DIR_WRITE(!INVERT_E0_DIR); E1_DIR_WRITE(!INVERT_E1_DIR); }while(0)
- #define REV_E_DIR() do{ E0_DIR_WRITE( INVERT_E0_DIR); E1_DIR_WRITE( INVERT_E1_DIR); }while(0)
+ #define E_STEP_WRITE(E,V) do{ if (E == 0) { E0_STEP_WRITE(V); } else { E1_STEP_WRITE(V); } }while(0)
+ #define NORM_E_DIR(E) do{ if (E == 0) { E0_DIR_WRITE(!INVERT_E0_DIR); } else { E1_DIR_WRITE(!INVERT_E1_DIR); } }while(0)
+ #define REV_E_DIR(E) do{ if (E == 0) { E0_DIR_WRITE( INVERT_E0_DIR); } else { E1_DIR_WRITE( INVERT_E1_DIR); } }while(0)
#endif
#else
- #define E_STEP_WRITE(v) E0_STEP_WRITE(v)
- #define NORM_E_DIR() E0_DIR_WRITE(!INVERT_E0_DIR)
- #define REV_E_DIR() E0_DIR_WRITE(INVERT_E0_DIR)
+ #define E_STEP_WRITE(E,V) E0_STEP_WRITE(V)
+ #define NORM_E_DIR(E) E0_DIR_WRITE(!INVERT_E0_DIR)
+ #define REV_E_DIR(E) E0_DIR_WRITE( INVERT_E0_DIR)
#endif
#endif // STEPPER_INDIRECTION_H
diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp
index ca9b814bff..e287a47794 100644
--- a/Marlin/temperature.cpp
+++ b/Marlin/temperature.cpp
@@ -31,6 +31,8 @@
#include "planner.h"
#include "language.h"
#include "printcounter.h"
+#include "delay.h"
+#include "endstops.h"
#if ENABLED(HEATER_0_USES_MAX6675)
#include "MarlinSPI.h"
@@ -40,10 +42,6 @@
#include "stepper.h"
#endif
-#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
- #include "endstops.h"
-#endif
-
#if ENABLED(USE_WATCHDOG)
#include "watchdog.h"
#endif
@@ -52,12 +50,14 @@
#include "emergency_parser.h"
#endif
-#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
- static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
- static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
-#else
- static void* heater_ttbl_map[HOTENDS] = ARRAY_BY_HOTENDS((void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE, (void*)HEATER_2_TEMPTABLE, (void*)HEATER_3_TEMPTABLE, (void*)HEATER_4_TEMPTABLE);
- static uint8_t heater_ttbllen_map[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN, HEATER_2_TEMPTABLE_LEN, HEATER_3_TEMPTABLE_LEN, HEATER_4_TEMPTABLE_LEN);
+#if HOTEND_USES_THERMISTOR
+ #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
+ static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
+ static constexpr uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
+ #else
+ static void* heater_ttbl_map[HOTENDS] = ARRAY_BY_HOTENDS((void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE, (void*)HEATER_2_TEMPTABLE, (void*)HEATER_3_TEMPTABLE, (void*)HEATER_4_TEMPTABLE);
+ static constexpr uint8_t heater_ttbllen_map[HOTENDS] = ARRAY_BY_HOTENDS(HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN, HEATER_2_TEMPTABLE_LEN, HEATER_3_TEMPTABLE_LEN, HEATER_4_TEMPTABLE_LEN);
+ #endif
#endif
Temperature thermalManager;
@@ -235,6 +235,10 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
uint8_t Temperature::ADCKey_count = 0;
#endif
+#if ENABLED(PID_EXTRUSION_SCALING)
+ int16_t Temperature::lpq_len; // Initialized in configuration_store
+#endif
+
#if HAS_PID_HEATING
/**
@@ -382,13 +386,13 @@ uint8_t Temperature::soft_pwm_amount[HOTENDS];
SERIAL_PROTOCOLPAIR(MSG_T_MIN, min);
SERIAL_PROTOCOLPAIR(MSG_T_MAX, max);
if (cycles > 2) {
- Ku = (4.0 * d) / (M_PI * (max - min) * 0.5);
- Tu = ((float)(t_low + t_high) * 0.001);
+ Ku = (4.0f * d) / (M_PI * (max - min) * 0.5f);
+ Tu = ((float)(t_low + t_high) * 0.001f);
SERIAL_PROTOCOLPAIR(MSG_KU, Ku);
SERIAL_PROTOCOLPAIR(MSG_TU, Tu);
- workKp = 0.6 * Ku;
+ workKp = 0.6f * Ku;
workKi = 2 * workKp / Tu;
- workKd = workKp * Tu * 0.125;
+ workKd = workKp * Tu * 0.125f;
SERIAL_PROTOCOLLNPGM("\n" MSG_CLASSIC_PID);
SERIAL_PROTOCOLPAIR(MSG_KP, workKp);
SERIAL_PROTOCOLPAIR(MSG_KI, workKi);
@@ -629,7 +633,7 @@ float Temperature::get_pid_output(const int8_t e) {
#if ENABLED(PIDTEMP)
#if DISABLED(PID_OPENLOOP)
pid_error[HOTEND_INDEX] = target_temperature[HOTEND_INDEX] - current_temperature[HOTEND_INDEX];
- dTerm[HOTEND_INDEX] = PID_K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + PID_K1 * dTerm[HOTEND_INDEX];
+ dTerm[HOTEND_INDEX] = PID_K2 * PID_PARAM(Kd, HOTEND_INDEX) * (current_temperature[HOTEND_INDEX] - temp_dState[HOTEND_INDEX]) + float(PID_K1) * dTerm[HOTEND_INDEX];
temp_dState[HOTEND_INDEX] = current_temperature[HOTEND_INDEX];
#if HEATER_IDLE_HANDLER
if (heater_idle_timeout_exceeded[HOTEND_INDEX]) {
@@ -664,14 +668,14 @@ float Temperature::get_pid_output(const int8_t e) {
#if ENABLED(PID_EXTRUSION_SCALING)
cTerm[HOTEND_INDEX] = 0;
if (_HOTEND_TEST) {
- long e_position = stepper.position(E_AXIS);
+ const long e_position = stepper.position(E_AXIS);
if (e_position > last_e_position) {
lpq[lpq_ptr] = e_position - last_e_position;
last_e_position = e_position;
}
- else {
+ else
lpq[lpq_ptr] = 0;
- }
+
if (++lpq_ptr >= lpq_len) lpq_ptr = 0;
cTerm[HOTEND_INDEX] = (lpq[lpq_ptr] * planner.steps_to_mm[E_AXIS]) * PID_PARAM(Kc, HOTEND_INDEX);
pid_output += cTerm[HOTEND_INDEX];
@@ -785,8 +789,8 @@ void Temperature::manage_heater() {
updateTemperaturesFromRawValues(); // also resets the watchdog
#if ENABLED(HEATER_0_USES_MAX6675)
- if (current_temperature[0] > min(HEATER_0_MAXTEMP, MAX6675_TMAX - 1.0)) max_temp_error(0);
- if (current_temperature[0] < max(HEATER_0_MINTEMP, MAX6675_TMIN + .01)) min_temp_error(0);
+ if (current_temperature[0] > MIN(HEATER_0_MAXTEMP, MAX6675_TMAX - 1.0)) max_temp_error(0);
+ if (current_temperature[0] < MAX(HEATER_0_MINTEMP, MAX6675_TMIN + .01)) min_temp_error(0);
#endif
#if WATCH_HOTENDS || WATCH_THE_BED || DISABLED(PIDTEMPBED) || HAS_AUTO_FAN || HEATER_IDLE_HANDLER
@@ -819,7 +823,7 @@ void Temperature::manage_heater() {
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
// Make sure measured temperatures are close together
- if (FABS(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF)
+ if (ABS(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF)
_temp_error(0, PSTR(MSG_REDUNDANCY), PSTR(MSG_ERR_REDUNDANT_TEMP));
#endif
@@ -911,7 +915,29 @@ void Temperature::manage_heater() {
#endif // HAS_HEATED_BED
}
-#define PGM_RD_W(x) (short)pgm_read_word(&x)
+#define TEMP_AD595(RAW) ((RAW) * 5.0 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN) + TEMP_SENSOR_AD595_OFFSET)
+#define TEMP_AD8495(RAW) ((RAW) * 6.6 * 100.0 / 1024.0 / (OVERSAMPLENR) * (TEMP_SENSOR_AD8495_GAIN) + TEMP_SENSOR_AD8495_OFFSET)
+
+/**
+ * Bisect search for the range of the 'raw' value, then interpolate
+ * proportionally between the under and over values.
+ */
+#define SCAN_THERMISTOR_TABLE(TBL,LEN) do{ \
+ uint8_t l = 0, r = LEN, m; \
+ for (;;) { \
+ m = (l + r) >> 1; \
+ if (m == l || m == r) return (short)pgm_read_word(&TBL[LEN-1][1]); \
+ short v00 = pgm_read_word(&TBL[m-1][0]), \
+ v10 = pgm_read_word(&TBL[m-0][0]); \
+ if (raw < v00) r = m; \
+ else if (raw > v10) l = m; \
+ else { \
+ const short v01 = (short)pgm_read_word(&TBL[m-1][1]), \
+ v11 = (short)pgm_read_word(&TBL[m-0][1]); \
+ return v01 + (raw - v00) * float(v11 - v01) / float(v10 - v00); \
+ } \
+ } \
+}while(0)
// Derived from RepRap FiveD extruder::getTemperature()
// For hot end temperature measurement.
@@ -929,65 +955,73 @@ float Temperature::analog2temp(const int raw, const uint8_t e) {
return 0.0;
}
- #if ENABLED(HEATER_0_USES_MAX6675)
- if (e == 0) return 0.25 * raw;
+ switch (e) {
+ case 0:
+ #if ENABLED(HEATER_0_USES_MAX6675)
+ return raw * 0.25;
+ #elif ENABLED(HEATER_0_USES_AD595)
+ return TEMP_AD595(raw);
+ #elif ENABLED(HEATER_0_USES_AD8495)
+ return TEMP_AD8495(raw);
+ #else
+ break;
+ #endif
+ case 1:
+ #if ENABLED(HEATER_1_USES_AD595)
+ return TEMP_AD595(raw);
+ #elif ENABLED(HEATER_1_USES_AD8495)
+ return TEMP_AD8495(raw);
+ #else
+ break;
+ #endif
+ case 2:
+ #if ENABLED(HEATER_2_USES_AD595)
+ return TEMP_AD595(raw);
+ #elif ENABLED(HEATER_2_USES_AD8495)
+ return TEMP_AD8495(raw);
+ #else
+ break;
+ #endif
+ case 3:
+ #if ENABLED(HEATER_3_USES_AD595)
+ return TEMP_AD595(raw);
+ #elif ENABLED(HEATER_3_USES_AD8495)
+ return TEMP_AD8495(raw);
+ #else
+ break;
+ #endif
+ case 4:
+ #if ENABLED(HEATER_4_USES_AD595)
+ return TEMP_AD595(raw);
+ #elif ENABLED(HEATER_4_USES_AD8495)
+ return TEMP_AD8495(raw);
+ #else
+ break;
+ #endif
+ default: break;
+ }
+
+ #if HOTEND_USES_THERMISTOR
+ // Thermistor with conversion table?
+ const short(*tt)[][2] = (short(*)[][2])(heater_ttbl_map[e]);
+ SCAN_THERMISTOR_TABLE((*tt), heater_ttbllen_map[e]);
#endif
- if (heater_ttbl_map[e] != NULL) {
- float celsius = 0;
- uint8_t i;
- short(*tt)[][2] = (short(*)[][2])(heater_ttbl_map[e]);
-
- for (i = 1; i < heater_ttbllen_map[e]; i++) {
- if (PGM_RD_W((*tt)[i][0]) > raw) {
- celsius = PGM_RD_W((*tt)[i - 1][1]) +
- (raw - PGM_RD_W((*tt)[i - 1][0])) *
- (float)(PGM_RD_W((*tt)[i][1]) - PGM_RD_W((*tt)[i - 1][1])) /
- (float)(PGM_RD_W((*tt)[i][0]) - PGM_RD_W((*tt)[i - 1][0]));
- break;
- }
- }
-
- // Overflow: Set to last value in the table
- if (i == heater_ttbllen_map[e]) celsius = PGM_RD_W((*tt)[i - 1][1]);
-
- return celsius;
- }
- return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET;
+ return 0;
}
#if HAS_HEATED_BED
// Derived from RepRap FiveD extruder::getTemperature()
// For bed temperature measurement.
float Temperature::analog2tempBed(const int raw) {
- #if ENABLED(BED_USES_THERMISTOR)
- float celsius = 0;
- byte i;
-
- for (i = 1; i < BEDTEMPTABLE_LEN; i++) {
- if (PGM_RD_W(BEDTEMPTABLE[i][0]) > raw) {
- celsius = PGM_RD_W(BEDTEMPTABLE[i - 1][1]) +
- (raw - PGM_RD_W(BEDTEMPTABLE[i - 1][0])) *
- (float)(PGM_RD_W(BEDTEMPTABLE[i][1]) - PGM_RD_W(BEDTEMPTABLE[i - 1][1])) /
- (float)(PGM_RD_W(BEDTEMPTABLE[i][0]) - PGM_RD_W(BEDTEMPTABLE[i - 1][0]));
- break;
- }
- }
-
- // Overflow: Set to last value in the table
- if (i == BEDTEMPTABLE_LEN) celsius = PGM_RD_W(BEDTEMPTABLE[i - 1][1]);
-
- return celsius;
-
- #elif defined(BED_USES_AD595)
-
- return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET;
-
+ #if ENABLED(HEATER_BED_USES_THERMISTOR)
+ SCAN_THERMISTOR_TABLE(BEDTEMPTABLE, BEDTEMPTABLE_LEN);
+ #elif ENABLED(HEATER_BED_USES_AD595)
+ return TEMP_AD595(raw);
+ #elif ENABLED(HEATER_BED_USES_AD8495)
+ return TEMP_AD8495(raw);
#else
-
- UNUSED(raw);
return 0;
-
#endif
}
#endif // HAS_HEATED_BED
@@ -996,34 +1030,14 @@ float Temperature::analog2temp(const int raw, const uint8_t e) {
// Derived from RepRap FiveD extruder::getTemperature()
// For chamber temperature measurement.
float Temperature::analog2tempChamber(const int raw) {
- #if ENABLED(CHAMBER_USES_THERMISTOR)
- float celsius = 0;
- byte i;
-
- for (i = 1; i < CHAMBERTEMPTABLE_LEN; i++) {
- if (PGM_RD_W(CHAMBERTEMPTABLE[i][0]) > raw) {
- celsius = PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1]) +
- (raw - PGM_RD_W(CHAMBERTEMPTABLE[i - 1][0])) *
- (float)(PGM_RD_W(CHAMBERTEMPTABLE[i][1]) - PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1])) /
- (float)(PGM_RD_W(CHAMBERTEMPTABLE[i][0]) - PGM_RD_W(CHAMBERTEMPTABLE[i - 1][0]));
- break;
- }
- }
-
- // Overflow: Set to last value in the table
- if (i == CHAMBERTEMPTABLE_LEN) celsius = PGM_RD_W(CHAMBERTEMPTABLE[i - 1][1]);
-
- return celsius;
-
- #elif defined(CHAMBER_USES_AD595)
-
- return ((raw * ((5.0 * 100.0) / 1024.0) / OVERSAMPLENR) * (TEMP_SENSOR_AD595_GAIN)) + TEMP_SENSOR_AD595_OFFSET;
-
+ #if ENABLED(HEATER_CHAMBER_USES_THERMISTOR)
+ SCAN_THERMISTOR_TABLE(CHAMBERTEMPTABLE, CHAMBERTEMPTABLE_LEN);
+ #elif ENABLED(HEATER_CHAMBER_USES_AD595)
+ return TEMP_AD595(raw);
+ #elif ENABLED(HEATER_CHAMBER_USES_AD8495)
+ return TEMP_AD8495(raw);
#else
-
- UNUSED(raw);
return 0;
-
#endif
}
#endif // HAS_TEMP_CHAMBER
@@ -1038,8 +1052,7 @@ void Temperature::updateTemperaturesFromRawValues() {
#if ENABLED(HEATER_0_USES_MAX6675)
current_temperature_raw[0] = read_max6675();
#endif
- HOTEND_LOOP()
- current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
+ HOTEND_LOOP() current_temperature[e] = Temperature::analog2temp(current_temperature_raw[e], e);
#if HAS_HEATED_BED
current_temperature_bed = Temperature::analog2tempBed(current_temperature_bed_raw);
#endif
@@ -1058,9 +1071,7 @@ void Temperature::updateTemperaturesFromRawValues() {
watchdog_reset();
#endif
- CRITICAL_SECTION_START;
temp_meas_ready = false;
- CRITICAL_SECTION_END;
}
@@ -1068,7 +1079,7 @@ void Temperature::updateTemperaturesFromRawValues() {
// Convert raw Filament Width to millimeters
float Temperature::analog2widthFil() {
- return current_raw_filwidth * 5.0 * (1.0 / 16383.0);
+ return current_raw_filwidth * 5.0f * (1.0f / 16383.0);
}
/**
@@ -1080,8 +1091,8 @@ void Temperature::updateTemperaturesFromRawValues() {
* a return value of 1.
*/
int8_t Temperature::widthFil_to_size_ratio() {
- if (FABS(filament_width_nominal - filament_width_meas) <= FILWIDTH_ERROR_MARGIN)
- return int(100.0 * filament_width_nominal / filament_width_meas) - 100;
+ if (ABS(filament_width_nominal - filament_width_meas) <= FILWIDTH_ERROR_MARGIN)
+ return int(100.0f * filament_width_nominal / filament_width_meas) - 100;
return 0;
}
@@ -1103,7 +1114,9 @@ void Temperature::updateTemperaturesFromRawValues() {
*/
void Temperature::init() {
- #if MB(RUMBA) && (TEMP_SENSOR_0 == -1 || TEMP_SENSOR_1 == -1 || TEMP_SENSOR_2 == -1 || TEMP_SENSOR_BED == -1 || TEMP_SENSOR_CHAMBER == -1)
+ #if MB(RUMBA) && ( \
+ ENABLED(HEATER_0_USES_AD595) || ENABLED(HEATER_1_USES_AD595) || ENABLED(HEATER_2_USES_AD595) || ENABLED(HEATER_3_USES_AD595) || ENABLED(HEATER_4_USES_AD595) || ENABLED(HEATER_BED_USES_AD595) || ENABLED(HEATER_CHAMBER_USES_AD595) \
+ || ENABLED(HEATER_0_USES_AD8495) || ENABLED(HEATER_1_USES_AD8495) || ENABLED(HEATER_2_USES_AD8495) || ENABLED(HEATER_3_USES_AD8495) || ENABLED(HEATER_4_USES_AD8495) || ENABLED(HEATER_BED_USES_AD8495) || ENABLED(HEATER_CHAMBER_USES_AD8495))
// Disable RUMBA JTAG in case the thermocouple extension is plugged on top of JTAG connector
MCUCR = _BV(JTD);
MCUCR = _BV(JTD);
@@ -1169,43 +1182,36 @@ void Temperature::init() {
#endif // HEATER_0_USES_MAX6675
- #ifdef DIDR2
- #define ANALOG_SELECT(pin) do{ if (pin < 8) SBI(DIDR0, pin); else SBI(DIDR2, pin & 0x07); }while(0)
- #else
- #define ANALOG_SELECT(pin) do{ SBI(DIDR0, pin); }while(0)
- #endif
+ HAL_adc_init();
- // Set analog inputs
- ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADIF) | 0x07;
- DIDR0 = 0;
- #ifdef DIDR2
- DIDR2 = 0;
+ #if HAS_TEMP_ADC_0
+ HAL_ANALOG_SELECT(TEMP_0_PIN);
#endif
- #if HAS_TEMP_0
- ANALOG_SELECT(TEMP_0_PIN);
+ #if HAS_TEMP_ADC_1
+ HAL_ANALOG_SELECT(TEMP_1_PIN);
#endif
- #if HAS_TEMP_1
- ANALOG_SELECT(TEMP_1_PIN);
+ #if HAS_TEMP_ADC_2
+ HAL_ANALOG_SELECT(TEMP_2_PIN);
#endif
- #if HAS_TEMP_2
- ANALOG_SELECT(TEMP_2_PIN);
+ #if HAS_TEMP_ADC_3
+ HAL_ANALOG_SELECT(TEMP_3_PIN);
#endif
- #if HAS_TEMP_3
- ANALOG_SELECT(TEMP_3_PIN);
- #endif
- #if HAS_TEMP_4
- ANALOG_SELECT(TEMP_4_PIN);
+ #if HAS_TEMP_ADC_4
+ HAL_ANALOG_SELECT(TEMP_4_PIN);
#endif
#if HAS_HEATED_BED
- ANALOG_SELECT(TEMP_BED_PIN);
+ HAL_ANALOG_SELECT(TEMP_BED_PIN);
#endif
#if HAS_TEMP_CHAMBER
- ANALOG_SELECT(TEMP_CHAMBER_PIN);
+ HAL_ANALOG_SELECT(TEMP_CHAMBER_PIN);
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
- ANALOG_SELECT(FILWIDTH_PIN);
+ HAL_ANALOG_SELECT(FILWIDTH_PIN);
#endif
+ HAL_timer_start(TEMP_TIMER_NUM, TEMP_TIMER_FREQUENCY);
+ ENABLE_TEMPERATURE_INTERRUPT();
+
#if HAS_AUTO_FAN_0
#if E0_AUTO_FAN_PIN == FAN1_PIN
SET_OUTPUT(E0_AUTO_FAN_PIN);
@@ -1267,11 +1273,6 @@ void Temperature::init() {
#endif
#endif
- // Use timer0 for temperature measurement
- // Interleave temperature interrupt with millies interrupt
- OCR0B = 128;
- ENABLE_TEMPERATURE_INTERRUPT();
-
// Wait for temperature measurement to settle
delay(250);
@@ -1616,9 +1617,7 @@ void Temperature::disable_all_heaters() {
WRITE(MAX6675_SS, 0); // enable TT_MAX6675
- // ensure 100ns delay - a bit extra is fine
- asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz
- asm("nop");//50ns on 20Mhz, 62.5ns on 16Mhz
+ DELAY_NS(100); // Ensure 100ns delay
// Read a big-endian temperature value
max6675_temp = 0;
@@ -1661,20 +1660,20 @@ void Temperature::disable_all_heaters() {
* Get raw temperatures
*/
void Temperature::set_current_temp_raw() {
- #if HAS_TEMP_0 && DISABLED(HEATER_0_USES_MAX6675)
+ #if HAS_TEMP_ADC_0 && DISABLED(HEATER_0_USES_MAX6675)
current_temperature_raw[0] = raw_temp_value[0];
#endif
- #if HAS_TEMP_1
+ #if HAS_TEMP_ADC_1
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
redundant_temperature_raw = raw_temp_value[1];
#else
current_temperature_raw[1] = raw_temp_value[1];
#endif
- #if HAS_TEMP_2
+ #if HAS_TEMP_ADC_2
current_temperature_raw[2] = raw_temp_value[2];
- #if HAS_TEMP_3
+ #if HAS_TEMP_ADC_3
current_temperature_raw[3] = raw_temp_value[3];
- #if HAS_TEMP_4
+ #if HAS_TEMP_ADC_4
current_temperature_raw[4] = raw_temp_value[4];
#endif
#endif
@@ -1702,71 +1701,71 @@ void Temperature::set_current_temp_raw() {
*
*/
void endstop_monitor() {
- static uint16_t old_endstop_bits_local = 0;
+ static uint16_t old_live_state_local = 0;
static uint8_t local_LED_status = 0;
- uint16_t current_endstop_bits_local = 0;
+ uint16_t live_state_local = 0;
#if HAS_X_MIN
- if (READ(X_MIN_PIN)) SBI(current_endstop_bits_local, X_MIN);
+ if (READ(X_MIN_PIN)) SBI(live_state_local, X_MIN);
#endif
#if HAS_X_MAX
- if (READ(X_MAX_PIN)) SBI(current_endstop_bits_local, X_MAX);
+ if (READ(X_MAX_PIN)) SBI(live_state_local, X_MAX);
#endif
#if HAS_Y_MIN
- if (READ(Y_MIN_PIN)) SBI(current_endstop_bits_local, Y_MIN);
+ if (READ(Y_MIN_PIN)) SBI(live_state_local, Y_MIN);
#endif
#if HAS_Y_MAX
- if (READ(Y_MAX_PIN)) SBI(current_endstop_bits_local, Y_MAX);
+ if (READ(Y_MAX_PIN)) SBI(live_state_local, Y_MAX);
#endif
#if HAS_Z_MIN
- if (READ(Z_MIN_PIN)) SBI(current_endstop_bits_local, Z_MIN);
+ if (READ(Z_MIN_PIN)) SBI(live_state_local, Z_MIN);
#endif
#if HAS_Z_MAX
- if (READ(Z_MAX_PIN)) SBI(current_endstop_bits_local, Z_MAX);
+ if (READ(Z_MAX_PIN)) SBI(live_state_local, Z_MAX);
#endif
#if HAS_Z_MIN_PROBE_PIN
- if (READ(Z_MIN_PROBE_PIN)) SBI(current_endstop_bits_local, Z_MIN_PROBE);
+ if (READ(Z_MIN_PROBE_PIN)) SBI(live_state_local, Z_MIN_PROBE);
#endif
#if HAS_Z2_MIN
- if (READ(Z2_MIN_PIN)) SBI(current_endstop_bits_local, Z2_MIN);
+ if (READ(Z2_MIN_PIN)) SBI(live_state_local, Z2_MIN);
#endif
#if HAS_Z2_MAX
- if (READ(Z2_MAX_PIN)) SBI(current_endstop_bits_local, Z2_MAX);
+ if (READ(Z2_MAX_PIN)) SBI(live_state_local, Z2_MAX);
#endif
- uint16_t endstop_change = current_endstop_bits_local ^ old_endstop_bits_local;
+ uint16_t endstop_change = live_state_local ^ old_live_state_local;
if (endstop_change) {
#if HAS_X_MIN
- if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", !!TEST(current_endstop_bits_local, X_MIN));
+ if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", !!TEST(live_state_local, X_MIN));
#endif
#if HAS_X_MAX
- if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", !!TEST(current_endstop_bits_local, X_MAX));
+ if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", !!TEST(live_state_local, X_MAX));
#endif
#if HAS_Y_MIN
- if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", !!TEST(current_endstop_bits_local, Y_MIN));
+ if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", !!TEST(live_state_local, Y_MIN));
#endif
#if HAS_Y_MAX
- if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", !!TEST(current_endstop_bits_local, Y_MAX));
+ if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", !!TEST(live_state_local, Y_MAX));
#endif
#if HAS_Z_MIN
- if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", !!TEST(current_endstop_bits_local, Z_MIN));
+ if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", !!TEST(live_state_local, Z_MIN));
#endif
#if HAS_Z_MAX
- if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", !!TEST(current_endstop_bits_local, Z_MAX));
+ if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", !!TEST(live_state_local, Z_MAX));
#endif
#if HAS_Z_MIN_PROBE_PIN
- if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", !!TEST(current_endstop_bits_local, Z_MIN_PROBE));
+ if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", !!TEST(live_state_local, Z_MIN_PROBE));
#endif
#if HAS_Z2_MIN
- if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", !!TEST(current_endstop_bits_local, Z2_MIN));
+ if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", !!TEST(live_state_local, Z2_MIN));
#endif
#if HAS_Z2_MAX
- if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", !!TEST(current_endstop_bits_local, Z2_MAX));
+ if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", !!TEST(live_state_local, Z2_MAX));
#endif
SERIAL_PROTOCOLPGM("\n\n");
analogWrite(LED_PIN, local_LED_status);
local_LED_status ^= 255;
- old_endstop_bits_local = current_endstop_bits_local;
+ old_live_state_local = live_state_local;
}
}
#endif // PINS_DEBUGGING
@@ -1784,27 +1783,18 @@ void Temperature::set_current_temp_raw() {
* - Step the babysteps value for each axis towards 0
* - For PINS_DEBUGGING, monitor and report endstop pins
* - For ENDSTOP_INTERRUPTS_FEATURE check endstops if flagged
+ * - Call planner.tick to count down its "ignore" time
*/
-ISR(TIMER0_COMPB_vect) {
- /**
- * AVR has no hardware interrupt preemption, so emulate priorization
- * and preemption of this ISR by all others by disabling the timer
- * interrupt generation capability and reenabling global interrupts.
- * Any interrupt can then interrupt this handler and preempt it.
- * This ISR becomes the lowest priority one so the UART, Endstops
- * and Stepper ISRs can all preempt it.
- */
- DISABLE_TEMPERATURE_INTERRUPT();
- sei();
+HAL_TEMP_TIMER_ISR {
+ HAL_timer_isr_prologue(TEMP_TIMER_NUM);
Temperature::isr();
- // Disable global interrupts and reenable this ISR
- cli();
- ENABLE_TEMPERATURE_INTERRUPT();
+ HAL_timer_isr_epilogue(TEMP_TIMER_NUM);
}
void Temperature::isr() {
+
static int8_t temp_count = -1;
static ADCSensorState adc_sensor_state = StartupDelay;
static uint8_t pwm_count = _BV(SOFT_PWM_SCALE);
@@ -2098,13 +2088,6 @@ void Temperature::isr() {
* This gives each ADC 0.9765ms to charge up.
*/
- #define SET_ADMUX_ADCSRA(pin) ADMUX = _BV(REFS0) | (pin & 0x07); SBI(ADCSRA, ADSC)
- #ifdef MUX5
- #define START_ADC(pin) if (pin > 7) ADCSRB = _BV(MUX5); else ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
- #else
- #define START_ADC(pin) ADCSRB = 0; SET_ADMUX_ADCSRA(pin)
- #endif
-
switch (adc_sensor_state) {
case SensorsReady: {
@@ -2122,88 +2105,88 @@ void Temperature::isr() {
adc_sensor_state = (ADCSensorState)0; // Fall-through to start first sensor now
}
- #if HAS_TEMP_0
+ #if HAS_TEMP_ADC_0
case PrepareTemp_0:
- START_ADC(TEMP_0_PIN);
+ HAL_START_ADC(TEMP_0_PIN);
break;
case MeasureTemp_0:
- raw_temp_value[0] += ADC;
+ raw_temp_value[0] += HAL_READ_ADC;
break;
#endif
#if HAS_HEATED_BED
case PrepareTemp_BED:
- START_ADC(TEMP_BED_PIN);
+ HAL_START_ADC(TEMP_BED_PIN);
break;
case MeasureTemp_BED:
- raw_temp_bed_value += ADC;
+ raw_temp_bed_value += HAL_READ_ADC;
break;
#endif
#if HAS_TEMP_CHAMBER
case PrepareTemp_CHAMBER:
- START_ADC(TEMP_CHAMBER_PIN);
+ HAL_START_ADC(TEMP_CHAMBER_PIN);
break;
case MeasureTemp_CHAMBER:
- raw_temp_chamber_value += ADC;
+ raw_temp_chamber_value += HAL_READ_ADC;
break;
#endif
- #if HAS_TEMP_1
+ #if HAS_TEMP_ADC_1
case PrepareTemp_1:
- START_ADC(TEMP_1_PIN);
+ HAL_START_ADC(TEMP_1_PIN);
break;
case MeasureTemp_1:
- raw_temp_value[1] += ADC;
+ raw_temp_value[1] += HAL_READ_ADC;
break;
#endif
- #if HAS_TEMP_2
+ #if HAS_TEMP_ADC_2
case PrepareTemp_2:
- START_ADC(TEMP_2_PIN);
+ HAL_START_ADC(TEMP_2_PIN);
break;
case MeasureTemp_2:
- raw_temp_value[2] += ADC;
+ raw_temp_value[2] += HAL_READ_ADC;
break;
#endif
- #if HAS_TEMP_3
+ #if HAS_TEMP_ADC_3
case PrepareTemp_3:
- START_ADC(TEMP_3_PIN);
+ HAL_START_ADC(TEMP_3_PIN);
break;
case MeasureTemp_3:
- raw_temp_value[3] += ADC;
+ raw_temp_value[3] += HAL_READ_ADC;
break;
#endif
- #if HAS_TEMP_4
+ #if HAS_TEMP_ADC_4
case PrepareTemp_4:
- START_ADC(TEMP_4_PIN);
+ HAL_START_ADC(TEMP_4_PIN);
break;
case MeasureTemp_4:
- raw_temp_value[4] += ADC;
+ raw_temp_value[4] += HAL_READ_ADC;
break;
#endif
#if ENABLED(FILAMENT_WIDTH_SENSOR)
case Prepare_FILWIDTH:
- START_ADC(FILWIDTH_PIN);
+ HAL_START_ADC(FILWIDTH_PIN);
break;
case Measure_FILWIDTH:
- if (ADC > 102) { // Make sure ADC is reading > 0.5 volts, otherwise don't read.
+ if (HAL_READ_ADC > 102) { // Make sure ADC is reading > 0.5 volts, otherwise don't read.
raw_filwidth_value -= (raw_filwidth_value >> 7); // Subtract 1/128th of the raw_filwidth_value
- raw_filwidth_value += ((unsigned long)ADC << 7); // Add new ADC reading, scaled by 128
+ raw_filwidth_value += ((unsigned long)HAL_READ_ADC << 7); // Add new ADC reading, scaled by 128
}
break;
#endif
#if ENABLED(ADC_KEYPAD)
case Prepare_ADC_KEY:
- START_ADC(ADC_KEYPAD_PIN);
+ HAL_START_ADC(ADC_KEYPAD_PIN);
break;
case Measure_ADC_KEY:
if (ADCKey_count < 16) {
- raw_ADCKey_value = ADC;
+ raw_ADCKey_value = HAL_READ_ADC;
if (raw_ADCKey_value > 900) {
//ADC Key release
ADCKey_count = 0;
@@ -2321,26 +2304,11 @@ void Temperature::isr() {
}
#endif // BABYSTEPPING
- #if ENABLED(PINS_DEBUGGING)
- extern bool endstop_monitor_flag;
- // run the endstop monitor at 15Hz
- static uint8_t endstop_monitor_count = 16; // offset this check from the others
- if (endstop_monitor_flag) {
- endstop_monitor_count += _BV(1); // 15 Hz
- endstop_monitor_count &= 0x7F;
- if (!endstop_monitor_count) endstop_monitor(); // report changes in endstop status
- }
- #endif
+ // Poll endstops state, if required
+ endstops.poll();
- #if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
-
- extern volatile uint8_t e_hit;
-
- if (e_hit && ENDSTOPS_ENABLED) {
- endstops.update(); // call endstop update routine
- e_hit--;
- }
- #endif
+ // Periodically call the planner timer
+ planner.tick();
}
#if HAS_TEMP_SENSOR
diff --git a/Marlin/temperature.h b/Marlin/temperature.h
index 128007a831..1112e1799e 100644
--- a/Marlin/temperature.h
+++ b/Marlin/temperature.h
@@ -51,33 +51,31 @@
#if HOTENDS == 1
#define HOTEND_INDEX 0
- #define EXTRUDER_IDX 0
#else
#define HOTEND_INDEX e
- #define EXTRUDER_IDX active_extruder
#endif
/**
* States for ADC reading in the ISR
*/
enum ADCSensorState : char {
- #if HAS_TEMP_0
+ #if HAS_TEMP_ADC_0
PrepareTemp_0,
MeasureTemp_0,
#endif
- #if HAS_TEMP_1
+ #if HAS_TEMP_ADC_1
PrepareTemp_1,
MeasureTemp_1,
#endif
- #if HAS_TEMP_2
+ #if HAS_TEMP_ADC_2
PrepareTemp_2,
MeasureTemp_2,
#endif
- #if HAS_TEMP_3
+ #if HAS_TEMP_ADC_3
PrepareTemp_3,
MeasureTemp_3,
#endif
- #if HAS_TEMP_4
+ #if HAS_TEMP_ADC_4
PrepareTemp_4,
MeasureTemp_4,
#endif
@@ -106,17 +104,17 @@ enum ADCSensorState : char {
// get all oversampled sensor readings
#define MIN_ADC_ISR_LOOPS 10
-#define ACTUAL_ADC_SAMPLES max(int(MIN_ADC_ISR_LOOPS), int(SensorsReady))
+#define ACTUAL_ADC_SAMPLES MAX(int(MIN_ADC_ISR_LOOPS), int(SensorsReady))
#if HAS_PID_HEATING
- #define PID_K2 (1.0-PID_K1)
- #define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / (F_CPU / 64.0 / 256.0))
+ #define PID_K2 (1.0f-PID_K1)
+ #define PID_dT ((OVERSAMPLENR * float(ACTUAL_ADC_SAMPLES)) / (F_CPU / 64.0f / 256.0f))
// Apply the scale factors to the PID values
- #define scalePID_i(i) ( (i) * PID_dT )
- #define unscalePID_i(i) ( (i) / PID_dT )
- #define scalePID_d(d) ( (d) / PID_dT )
- #define unscalePID_d(d) ( (d) * PID_dT )
+ #define scalePID_i(i) ( (i) * float(PID_dT) )
+ #define unscalePID_i(i) ( (i) / float(PID_dT) )
+ #define scalePID_d(d) ( (d) / float(PID_dT) )
+ #define unscalePID_d(d) ( (d) * float(PID_dT) )
#endif
class Temperature {
@@ -196,7 +194,7 @@ class Temperature {
FORCE_INLINE static bool hotEnoughToExtrude(const uint8_t e) { return !tooColdToExtrude(e); }
FORCE_INLINE static bool targetHotEnoughToExtrude(const uint8_t e) { return !targetTooColdToExtrude(e); }
- private:
+ private:
static volatile bool temp_meas_ready;
static uint16_t raw_temp_value[MAX_EXTRUDERS];
@@ -304,6 +302,10 @@ class Temperature {
static uint8_t ADCKey_count;
#endif
+ #if ENABLED(PID_EXTRUSION_SCALING)
+ static int16_t lpq_len;
+ #endif
+
/**
* Instance Methods
*/
@@ -445,7 +447,7 @@ class Temperature {
#endif
target_temperature_bed =
#ifdef BED_MAXTEMP
- min(celsius, BED_MAXTEMP)
+ MIN(celsius, BED_MAXTEMP)
#else
celsius
#endif
@@ -468,7 +470,7 @@ class Temperature {
#endif
FORCE_INLINE static bool wait_for_heating(const uint8_t e) {
- return degTargetHotend(e) > TEMP_HYSTERESIS && abs(degHotend(e) - degTargetHotend(e)) > TEMP_HYSTERESIS;
+ return degTargetHotend(e) > TEMP_HYSTERESIS && ABS(degHotend(e) - degTargetHotend(e)) > TEMP_HYSTERESIS;
}
/**
@@ -503,7 +505,7 @@ class Temperature {
#if ENABLED(BABYSTEPPING)
static void babystep_axis(const AxisEnum axis, const int16_t distance) {
- if (axis_known_position[axis]) {
+ if (TEST(axis_known_position, axis)) {
#if IS_CORE
#if ENABLED(BABYSTEP_XY)
switch (axis) {
diff --git a/Marlin/thermistornames.h b/Marlin/thermistornames.h
index e444a9545b..c26a1fe91c 100644
--- a/Marlin/thermistornames.h
+++ b/Marlin/thermistornames.h
@@ -23,7 +23,9 @@
#undef THERMISTOR_NAME
// Thermcouples
-#if THERMISTOR_ID == -3
+#if THERMISTOR_ID == -4
+ #define THERMISTOR_NAME "AD8495"
+#elif THERMISTOR_ID == -3
#define THERMISTOR_NAME "MAX31855"
#elif THERMISTOR_ID == -2
#define THERMISTOR_NAME "MAX6675"
diff --git a/Marlin/thermistortable_501.h b/Marlin/thermistortable_501.h
new file mode 100644
index 0000000000..512ac0d8d8
--- /dev/null
+++ b/Marlin/thermistortable_501.h
@@ -0,0 +1,57 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (C) 2016 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 .
+ *
+ */
+
+// 100k Zonestar thermistor. Adjusted By Hally
+const short temptable_501[][2] PROGMEM = {
+ {OV( 1), 713},
+ {OV( 14), 300}, // Top rating 300C
+ {OV( 16), 290},
+ {OV( 19), 280},
+ {OV( 23), 270},
+ {OV( 27), 260},
+ {OV( 32), 250},
+ {OV( 30), 240},
+ {OV( 47), 230},
+ {OV( 57), 220},
+ {OV( 68), 210},
+ {OV( 84), 200},
+ {OV( 100), 190},
+ {OV( 128), 180},
+ {OV( 155), 170},
+ {OV( 189), 160},
+ {OV( 230), 150},
+ {OV( 278), 140},
+ {OV( 336), 130},
+ {OV( 402), 120},
+ {OV( 476), 110},
+ {OV( 554), 100},
+ {OV( 635), 90},
+ {OV( 713), 80},
+ {OV( 784), 70},
+ {OV( 846), 60},
+ {OV( 897), 50},
+ {OV( 937), 40},
+ {OV( 966), 30},
+ {OV( 986), 20},
+ {OV(1000), 10},
+ {OV(1010), 0}
+};
diff --git a/Marlin/thermistortable_70.h b/Marlin/thermistortable_70.h
index fd7838b809..2f9434e300 100644
--- a/Marlin/thermistortable_70.h
+++ b/Marlin/thermistortable_70.h
@@ -20,64 +20,23 @@
*
*/
+// Stock BQ Hephestos 2 100k thermistor.
+// Created on 29/12/2017 with an ambient temperature of 20C.
+// ANENG AN8009 DMM with a K-type probe used for measurements.
+
// R25 = 100 kOhm, beta25 = 4100 K, 4.7 kOhm pull-up, bqh2 stock thermistor
const short temptable_70[][2] PROGMEM = {
- { OV( 22), 300 },
- { OV( 24), 295 },
- { OV( 25), 290 },
- { OV( 27), 285 },
- { OV( 29), 280 },
- { OV( 32), 275 },
- { OV( 34), 270 },
- { OV( 37), 265 },
- { OV( 40), 260 },
- { OV( 43), 255 },
- { OV( 46), 250 },
- { OV( 50), 245 },
- { OV( 54), 240 },
- { OV( 59), 235 },
- { OV( 64), 230 },
- { OV( 70), 225 },
- { OV( 76), 220 },
- { OV( 83), 215 },
- { OV( 90), 210 },
- { OV( 99), 205 },
- { OV( 108), 200 },
- { OV( 118), 195 },
- { OV( 129), 190 },
- { OV( 141), 185 },
- { OV( 154), 180 },
- { OV( 169), 175 },
- { OV( 185), 170 },
- { OV( 203), 165 },
- { OV( 222), 160 },
- { OV( 243), 155 },
- { OV( 266), 150 },
- { OV( 290), 145 },
- { OV( 317), 140 },
- { OV( 346), 135 },
- { OV( 376), 130 },
- { OV( 408), 125 },
- { OV( 442), 120 },
- { OV( 477), 115 },
- { OV( 513), 110 },
- { OV( 551), 105 },
- { OV( 588), 100 },
- { OV( 626), 95 },
- { OV( 663), 90 },
- { OV( 699), 85 },
- { OV( 735), 80 },
- { OV( 768), 75 },
- { OV( 800), 70 },
- { OV( 829), 65 },
- { OV( 856), 60 },
- { OV( 881), 55 },
- { OV( 903), 50 },
- { OV( 922), 45 },
- { OV( 939), 40 },
- { OV( 954), 35 },
- { OV( 966), 30 },
- { OV( 977), 25 },
+ { OV( 18), 270 },
+ { OV( 27), 248 },
+ { OV( 34), 234 },
+ { OV( 45), 220 },
+ { OV( 61), 205 },
+ { OV( 86), 188 },
+ { OV( 123), 172 },
+ { OV( 420), 110 },
+ { OV( 590), 90 },
+ { OV( 845), 56 },
+ { OV( 970), 25 },
{ OV( 986), 20 },
{ OV( 994), 15 },
{ OV(1000), 10 },
diff --git a/Marlin/thermistortables.h b/Marlin/thermistortables.h
index 737fca816d..462337778d 100644
--- a/Marlin/thermistortables.h
+++ b/Marlin/thermistortables.h
@@ -56,6 +56,9 @@
#if ANY_THERMISTOR_IS(5) // 100k ParCan thermistor (104GT-2)
#include "thermistortable_5.h"
#endif
+#if ANY_THERMISTOR_IS(501) // 100k Zonestar thermistor
+ #include "thermistortable_501.h"
+#endif
#if ANY_THERMISTOR_IS(6) // 100k Epcos thermistor
#include "thermistortable_6.h"
#endif
@@ -132,7 +135,7 @@
#define _TT_NAME(_N) temptable_ ## _N
#define TT_NAME(_N) _TT_NAME(_N)
-#ifdef THERMISTORHEATER_0
+#if THERMISTORHEATER_0
#define HEATER_0_TEMPTABLE TT_NAME(THERMISTORHEATER_0)
#define HEATER_0_TEMPTABLE_LEN COUNT(HEATER_0_TEMPTABLE)
#elif defined(HEATER_0_USES_THERMISTOR)
@@ -142,7 +145,7 @@
#define HEATER_0_TEMPTABLE_LEN 0
#endif
-#ifdef THERMISTORHEATER_1
+#if THERMISTORHEATER_1
#define HEATER_1_TEMPTABLE TT_NAME(THERMISTORHEATER_1)
#define HEATER_1_TEMPTABLE_LEN COUNT(HEATER_1_TEMPTABLE)
#elif defined(HEATER_1_USES_THERMISTOR)
@@ -152,7 +155,7 @@
#define HEATER_1_TEMPTABLE_LEN 0
#endif
-#ifdef THERMISTORHEATER_2
+#if THERMISTORHEATER_2
#define HEATER_2_TEMPTABLE TT_NAME(THERMISTORHEATER_2)
#define HEATER_2_TEMPTABLE_LEN COUNT(HEATER_2_TEMPTABLE)
#elif defined(HEATER_2_USES_THERMISTOR)
@@ -162,7 +165,7 @@
#define HEATER_2_TEMPTABLE_LEN 0
#endif
-#ifdef THERMISTORHEATER_3
+#if THERMISTORHEATER_3
#define HEATER_3_TEMPTABLE TT_NAME(THERMISTORHEATER_3)
#define HEATER_3_TEMPTABLE_LEN COUNT(HEATER_3_TEMPTABLE)
#elif defined(HEATER_3_USES_THERMISTOR)
@@ -172,7 +175,7 @@
#define HEATER_3_TEMPTABLE_LEN 0
#endif
-#ifdef THERMISTORHEATER_4
+#if THERMISTORHEATER_4
#define HEATER_4_TEMPTABLE TT_NAME(THERMISTORHEATER_4)
#define HEATER_4_TEMPTABLE_LEN COUNT(HEATER_4_TEMPTABLE)
#elif defined(HEATER_4_USES_THERMISTOR)
@@ -185,21 +188,26 @@
#ifdef THERMISTORBED
#define BEDTEMPTABLE TT_NAME(THERMISTORBED)
#define BEDTEMPTABLE_LEN COUNT(BEDTEMPTABLE)
+#elif defined(HEATER_BED_USES_THERMISTOR)
+ #error "No bed thermistor table specified"
#else
- #ifdef BED_USES_THERMISTOR
- #error "No bed thermistor table specified"
- #endif
+ #define BEDTEMPTABLE_LEN 0
#endif
#ifdef THERMISTORCHAMBER
#define CHAMBERTEMPTABLE TT_NAME(THERMISTORCHAMBER)
#define CHAMBERTEMPTABLE_LEN COUNT(CHAMBERTEMPTABLE)
+#elif defined(HEATER_CHAMBER_USES_THERMISTOR)
+ #error "No chamber thermistor table specified"
#else
- #ifdef CHAMBER_USES_THERMISTOR
- #error "No chamber thermistor table specified"
- #endif
+ #define CHAMBERTEMPTABLE_LEN 0
#endif
+// The SCAN_THERMISTOR_TABLE macro needs alteration?
+static_assert(HEATER_0_TEMPTABLE_LEN < 128 && HEATER_1_TEMPTABLE_LEN < 128 && HEATER_2_TEMPTABLE_LEN < 128 && HEATER_3_TEMPTABLE_LEN < 128 && HEATER_4_TEMPTABLE_LEN < 128 && BEDTEMPTABLE_LEN < 128 && CHAMBERTEMPTABLE_LEN < 128,
+ "Temperature conversion tables over 127 entries need special consideration."
+);
+
// Set the high and low raw values for the heaters
// For thermistors the highest temperature results in the lowest ADC value
// For thermocouples the highest temperature results in the highest ADC value
@@ -249,7 +257,7 @@
#endif
#endif
#ifndef HEATER_BED_RAW_HI_TEMP
- #ifdef BED_USES_THERMISTOR
+ #ifdef HEATER_BED_USES_THERMISTOR
#define HEATER_BED_RAW_HI_TEMP 0
#define HEATER_BED_RAW_LO_TEMP 16383
#else
@@ -258,7 +266,7 @@
#endif
#endif
#ifndef HEATER_CHAMBER_RAW_HI_TEMP
- #ifdef CHAMBER_USES_THERMISTOR
+ #ifdef HEATER_CHAMBER_USES_THERMISTOR
#define HEATER_CHAMBER_RAW_HI_TEMP 0
#define HEATER_CHAMBER_RAW_LO_TEMP 16383
#else
diff --git a/Marlin/tmc_util.cpp b/Marlin/tmc_util.cpp
index edec89c134..662fbc176c 100644
--- a/Marlin/tmc_util.cpp
+++ b/Marlin/tmc_util.cpp
@@ -534,7 +534,7 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) {
TMC_REPORT("Run current", TMC_IRUN);
TMC_REPORT("Hold current", TMC_IHOLD);
TMC_REPORT("CS actual\t", TMC_CS_ACTUAL);
- TMC_REPORT("PWM scale", TMC_PWM_SCALE);
+ TMC_REPORT("PWM scale\t", TMC_PWM_SCALE);
TMC_REPORT("vsense\t", TMC_VSENSE);
TMC_REPORT("stealthChop", TMC_STEALTHCHOP);
TMC_REPORT("msteps\t", TMC_MICROSTEPS);
@@ -579,9 +579,9 @@ void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt) {
#if ENABLED(SENSORLESS_HOMING)
- void tmc_sensorless_homing(TMC2130Stepper &st, bool enable/*=true*/) {
+ void tmc_sensorless_homing(TMC2130Stepper &st, const bool enable/*=true*/) {
+ st.coolstep_min_speed(enable ? 1024UL * 1024UL - 1UL : 0);
#if ENABLED(STEALTHCHOP)
- st.coolstep_min_speed(enable ? 1024UL * 1024UL - 1UL : 0);
st.stealthChop(!enable);
#endif
st.diag1_stall(enable ? 1 : 0);
diff --git a/Marlin/tmc_util.h b/Marlin/tmc_util.h
index 60134b72a2..08d461e424 100644
--- a/Marlin/tmc_util.h
+++ b/Marlin/tmc_util.h
@@ -53,7 +53,7 @@ void tmc_get_current(TMC &st, const TMC_AxisEnum axis) {
_tmc_say_current(axis, st.getCurrent());
}
template
-void tmc_set_current(TMC &st, const TMC_AxisEnum axis, const int mA) {
+void tmc_set_current(TMC &st, const int mA) {
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
}
template
@@ -70,7 +70,7 @@ void tmc_get_pwmthrs(TMC &st, const TMC_AxisEnum axis, const uint16_t spmm) {
_tmc_say_pwmthrs(axis, _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm));
}
template
-void tmc_set_pwmthrs(TMC &st, const TMC_AxisEnum axis, const int32_t thrs, const uint32_t spmm) {
+void tmc_set_pwmthrs(TMC &st, const int32_t thrs, const uint32_t spmm) {
st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm));
}
template
@@ -78,7 +78,7 @@ void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) {
_tmc_say_sgt(axis, st.sgt());
}
template
-void tmc_set_sgt(TMC &st, const TMC_AxisEnum axis, const int8_t sgt_val) {
+void tmc_set_sgt(TMC &st, const int8_t sgt_val) {
st.sgt(sgt_val);
}
@@ -97,7 +97,7 @@ void monitor_tmc_driver();
* Defined here because of limitations with templates and headers.
*/
#if ENABLED(SENSORLESS_HOMING)
- void tmc_sensorless_homing(TMC2130Stepper &st, bool enable=true);
+ void tmc_sensorless_homing(TMC2130Stepper &st, const bool enable=true);
#endif
#if ENABLED(HAVE_TMC2130)
diff --git a/Marlin/ubl.h b/Marlin/ubl.h
index a293ee5ce4..873e5e6ec4 100644
--- a/Marlin/ubl.h
+++ b/Marlin/ubl.h
@@ -30,7 +30,6 @@
#include "Marlin.h"
#include "planner.h"
#include "math.h"
-#include "vector_3.h"
#include "configuration_store.h"
#define UBL_VERSION "1.01"
@@ -62,7 +61,6 @@ extern uint8_t ubl_cnt;
///////////////////////////////////////////////////////////////////////////////////////////////////////
#if ENABLED(ULTRA_LCD)
- extern char lcd_status_message[];
void lcd_quick_feedback(const bool clear_buttons);
#endif
@@ -118,7 +116,7 @@ class unified_bed_leveling {
static void reset();
static void invalidate();
static void set_all_mesh_points_to_value(const float value);
- static void adjust_mesh_to_mean(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
@@ -163,14 +161,14 @@ class 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 get_cell_index_x(const float &x) {
- const int8_t cx = (x - (MESH_MIN_X)) * (1.0 / (MESH_X_DIST));
+ const int8_t cx = (x - (MESH_MIN_X)) * (1.0f / (MESH_X_DIST));
return constrain(cx, 0, (GRID_MAX_POINTS_X) - 1); // -1 is appropriate if we want all movement to the X_MAX
} // position. But with this defined this way, it is possible
// to extrapolate off of this point even further out. Probably
// that is OK because something else should be keeping that from
// happening and should not be worried about at this level.
static int8_t get_cell_index_y(const float &y) {
- const int8_t cy = (y - (MESH_MIN_Y)) * (1.0 / (MESH_Y_DIST));
+ const int8_t cy = (y - (MESH_MIN_Y)) * (1.0f / (MESH_Y_DIST));
return constrain(cy, 0, (GRID_MAX_POINTS_Y) - 1); // -1 is appropriate if we want all movement to the Y_MAX
} // position. But with this defined this way, it is possible
// to extrapolate off of this point even further out. Probably
@@ -178,12 +176,12 @@ class unified_bed_leveling {
// happening and should not be worried about at this level.
static int8_t find_closest_x_index(const float &x) {
- const int8_t px = (x - (MESH_MIN_X) + (MESH_X_DIST) * 0.5) * (1.0 / (MESH_X_DIST));
+ const int8_t px = (x - (MESH_MIN_X) + (MESH_X_DIST) * 0.5f) * (1.0f / (MESH_X_DIST));
return WITHIN(px, 0, GRID_MAX_POINTS_X - 1) ? px : -1;
}
static int8_t find_closest_y_index(const float &y) {
- const int8_t py = (y - (MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * (1.0 / (MESH_Y_DIST));
+ const int8_t py = (y - (MESH_MIN_Y) + (MESH_Y_DIST) * 0.5f) * (1.0f / (MESH_Y_DIST));
return WITHIN(py, 0, GRID_MAX_POINTS_Y - 1) ? py : -1;
}
@@ -236,7 +234,7 @@ class unified_bed_leveling {
const float xratio = (rx0 - mesh_index_to_xpos(x1_i)) * (1.0 / (MESH_X_DIST)),
z1 = z_values[x1_i][yi];
- 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
+ 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.
}
@@ -270,7 +268,7 @@ class unified_bed_leveling {
const float yratio = (ry0 - mesh_index_to_ypos(y1_i)) * (1.0 / (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
+ 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.
}
@@ -296,11 +294,11 @@ class unified_bed_leveling {
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]);
+ 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]);
+ 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,
@@ -357,17 +355,11 @@ class unified_bed_leveling {
static void line_to_destination_cartesian(const float &fr, const uint8_t e);
#endif
- #define _CMPZ(a,b) (z_values[a][b] == z_values[a][b+1])
- #define CMPZ(a) (_CMPZ(a, 0) && _CMPZ(a, 1))
- #define ZZER(a) (z_values[a][0] == 0)
-
- FORCE_INLINE bool mesh_is_valid() {
- return !(
- ( CMPZ(0) && CMPZ(1) && CMPZ(2) // adjacent z values all equal?
- && ZZER(0) && ZZER(1) && ZZER(2) // all zero at the edge?
- )
- || isnan(z_values[0][0])
- );
+ inline static bool mesh_is_valid() {
+ for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
+ for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
+ if (isnan(z_values[x][y])) return false;
+ return true;
}
}; // class unified_bed_leveling
diff --git a/Marlin/ubl_G29.cpp b/Marlin/ubl_G29.cpp
index 494cbdf137..0286a76858 100644
--- a/Marlin/ubl_G29.cpp
+++ b/Marlin/ubl_G29.cpp
@@ -49,9 +49,6 @@
void _lcd_ubl_output_map_lcd();
#endif
- extern float meshedit_done;
- extern long babysteps_done;
-
#define SIZE_OF_LITTLE_RAISE 1
#define BIG_RAISE_NOT_NEEDED 0
@@ -65,8 +62,8 @@
unified_bed_leveling::g29_y_flag;
float unified_bed_leveling::g29_x_pos,
unified_bed_leveling::g29_y_pos,
- unified_bed_leveling::g29_card_thickness = 0.0,
- unified_bed_leveling::g29_constant = 0.0;
+ unified_bed_leveling::g29_card_thickness = 0,
+ unified_bed_leveling::g29_constant = 0;
#if HAS_BED_PROBE
int unified_bed_leveling::g29_grid_size;
@@ -292,13 +289,17 @@
void unified_bed_leveling::G29() {
- if (g29_parameter_parsing()) return; // abort if parsing the simple parameters causes a problem,
+ 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');
// Check for commands that require the printer to be homed
- if (axis_unhomed_error()) {
- const int8_t p_val = parser.intval('P', -1);
- if (p_val == 1 || p_val == 2 || p_val == 4 || parser.seen('J'))
- home_all_axes();
+ if (may_move) {
+ if (axis_unhomed_error()) home_all_axes();
+ #if ENABLED(DUAL_X_CARRIAGE)
+ if (active_extruder != 0) tool_change(0);
+ #endif
}
// Invalidate Mesh Points. This command is a little bit asymmetrical because
@@ -342,23 +343,23 @@
case 0:
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a bowl shape - similar to
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) { // a poorly calibrated Delta.
- const float p1 = 0.5 * (GRID_MAX_POINTS_X) - x,
- p2 = 0.5 * (GRID_MAX_POINTS_Y) - y;
- z_values[x][y] += 2.0 * HYPOT(p1, p2);
+ 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);
}
}
break;
case 1:
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) { // Create a diagonal line several Mesh cells thick that is raised
- z_values[x][x] += 9.999;
- z_values[x][x + (x < GRID_MAX_POINTS_Y - 1) ? 1 : -1] += 9.999; // We want the altered line several mesh points thick
+ 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
}
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.99;
+ z_values[x][y] += parser.seen('C') ? g29_constant : 9.99f;
break;
}
}
@@ -377,7 +378,7 @@
tilt_mesh_based_on_probed_grid(true /* true says to do 3-Point leveling */ );
restore_ubl_active_state_and_leave();
}
- do_blocking_move_to_xy(0.5 * (MESH_MAX_X - (MESH_MIN_X)), 0.5 * (MESH_MAX_Y - (MESH_MIN_Y)));
+ do_blocking_move_to_xy(0.5f * (MESH_MAX_X - (MESH_MIN_X)), 0.5f * (MESH_MAX_Y - (MESH_MIN_Y)));
report_current_position();
}
@@ -449,7 +450,7 @@
if (parser.seen('B')) {
g29_card_thickness = parser.has_value() ? parser.value_float() : measure_business_card_thickness((float) Z_CLEARANCE_BETWEEN_PROBES);
- if (FABS(g29_card_thickness) > 1.5) {
+ if (ABS(g29_card_thickness) > 1.5f) {
SERIAL_PROTOCOLLNPGM("?Error in Business Card measurement.");
return;
}
@@ -505,7 +506,7 @@
}
else {
const float cvf = parser.value_float();
- switch ((int)truncf(cvf * 10.0) - 30) { // 3.1 -> 1
+ switch ((int)truncf(cvf * 10.0f) - 30) { // 3.1 -> 1
#if ENABLED(UBL_G29_P31)
case 1: {
@@ -515,8 +516,8 @@
// P3.12 100X distance weighting
// P3.13 1000X distance weighting, approaches simple average of nearest points
- const float weight_power = (cvf - 3.10) * 100.0, // 3.12345 -> 2.345
- weight_factor = weight_power ? POW(10.0, weight_power) : 0;
+ 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;
@@ -539,7 +540,7 @@
#endif
break;
- case 5: adjust_mesh_to_mean(g29_constant); break;
+ case 5: adjust_mesh_to_mean(g29_c_flag, g29_constant); break;
case 6: shift_mesh_height(); break;
}
@@ -629,8 +630,8 @@
return;
}
- void unified_bed_leveling::adjust_mesh_to_mean(const float value) {
- float sum = 0.0;
+ void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) {
+ float sum = 0;
int n = 0;
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
@@ -644,7 +645,7 @@
//
// Sum the squares of difference from mean
//
- float sum_of_diff_squared = 0.0;
+ float sum_of_diff_squared = 0;
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
if (!isnan(z_values[x][y]))
@@ -660,7 +661,7 @@
SERIAL_ECHO_F(sigma, 6);
SERIAL_EOL();
- if (g29_c_flag)
+ if (cflag)
for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++)
for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++)
if (!isnan(z_values[x][y]))
@@ -751,7 +752,7 @@
STOW_PROBE();
- #if Z_AFTER_PROBING
+ #ifdef Z_AFTER_PROBING
move_z_after_probing();
#endif
@@ -782,7 +783,7 @@
float unified_bed_leveling::measure_point_with_encoder() {
KEEPALIVE_STATE(PAUSED_FOR_USER);
- move_z_with_encoder(0.01);
+ move_z_with_encoder(0.01f);
KEEPALIVE_STATE(IN_HANDLER);
return current_position[Z_AXIS];
}
@@ -793,9 +794,9 @@
lcd_external_control = true;
save_ubl_active_state_and_disable(); // Disable bed level correction for probing
- do_blocking_move_to(0.5 * (MESH_MAX_X - (MESH_MIN_X)), 0.5 * (MESH_MAX_Y - (MESH_MIN_Y)), in_height);
- //, min(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]) / 2.0);
- stepper.synchronize();
+ do_blocking_move_to(0.5f * (MESH_MAX_X - (MESH_MIN_X)), 0.5f * (MESH_MAX_Y - (MESH_MIN_Y)), in_height);
+ //, MIN(planner.max_feedrate_mm_s[X_AXIS], planner.max_feedrate_mm_s[Y_AXIS]) * 0.5f);
+ planner.synchronize();
SERIAL_PROTOCOLPGM("Place shim under nozzle");
LCD_MESSAGEPGM(MSG_UBL_BC_INSERT);
@@ -804,7 +805,7 @@
const float z1 = measure_point_with_encoder();
do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
- stepper.synchronize();
+ planner.synchronize();
SERIAL_PROTOCOLPGM("Remove shim");
LCD_MESSAGEPGM(MSG_UBL_BC_REMOVE);
@@ -814,7 +815,7 @@
do_blocking_move_to_z(current_position[Z_AXIS] + Z_CLEARANCE_BETWEEN_PROBES);
- const float thickness = abs(z1 - z2);
+ const float thickness = ABS(z1 - z2);
if (g29_verbose_level > 1) {
SERIAL_PROTOCOLPGM("Business Card is ");
@@ -870,8 +871,8 @@
serialprintPGM(parser.seen('B') ? PSTR(MSG_UBL_BC_INSERT) : PSTR(MSG_UBL_BC_INSERT2));
- const float z_step = 0.01; // existing behavior: 0.01mm per click, occasionally step
- //const float z_step = 1.0 / planner.axis_steps_per_mm[Z_AXIS]; // approx one step each click
+ 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
move_z_with_encoder(z_step);
@@ -909,7 +910,7 @@
lcd_quick_feedback(true);
#endif
- g29_constant = 0.0;
+ g29_constant = 0;
g29_repetition_cnt = 0;
g29_x_flag = parser.seenval('X');
@@ -1000,7 +1001,7 @@
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
if (parser.seenval('F')) {
const float fh = parser.value_float();
- if (!WITHIN(fh, 0.0, 100.0)) {
+ if (!WITHIN(fh, 0, 100)) {
SERIAL_PROTOCOLLNPGM("?(F)ade height for Bed Level Correction not plausible.\n");
return UBL_ERR;
}
@@ -1076,7 +1077,7 @@
SERIAL_EOL();
#endif
- adjust_mesh_to_mean(g29_constant);
+ adjust_mesh_to_mean(g29_c_flag, g29_constant);
#if HAS_BED_PROBE
SERIAL_PROTOCOLPGM("zprobe_zoffset: ");
@@ -1222,7 +1223,7 @@
mesh_index_pair out_mesh;
out_mesh.x_index = out_mesh.y_index = -1;
- out_mesh.distance = -99999.99;
+ out_mesh.distance = -99999.99f;
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
@@ -1238,7 +1239,7 @@
found_a_NAN = true;
int8_t closest_x = -1, closest_y = -1;
- float d1, d2 = 99999.9;
+ float d1, d2 = 99999.9f;
for (int8_t k = 0; k < GRID_MAX_POINTS_X; k++) {
for (int8_t l = 0; l < GRID_MAX_POINTS_Y; l++) {
if (!isnan(z_values[k][l])) {
@@ -1248,7 +1249,7 @@
// last half of the mesh (when every unprobed mesh point is one index
// from a probed location).
- d1 = HYPOT(i - k, j - l) + (1.0 / ((millis() % 47) + 13));
+ d1 = HYPOT(i - k, j - l) + (1.0f / ((millis() % 47) + 13));
if (d1 < d2) { // found a closer distance from invalid mesh point at (i,j) to defined mesh point at (k,l)
d2 = d1; // found a closer location with
@@ -1275,7 +1276,7 @@
if (!found_a_real && found_a_NAN) { // if the mesh is totally unpopulated, start the probing
out_mesh.x_index = GRID_MAX_POINTS_X / 2;
out_mesh.y_index = GRID_MAX_POINTS_Y / 2;
- out_mesh.distance = 1.0;
+ out_mesh.distance = 1;
}
return out_mesh;
}
@@ -1283,13 +1284,13 @@
mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const float &rx, const float &ry, const bool probe_as_reference, uint16_t bits[16]) {
mesh_index_pair out_mesh;
out_mesh.x_index = out_mesh.y_index = -1;
- out_mesh.distance = -99999.9;
+ out_mesh.distance = -99999.9f;
// Get our reference position. Either the nozzle or probe location.
const float px = rx - (probe_as_reference == USE_PROBE_AS_REFERENCE ? X_PROBE_OFFSET_FROM_EXTRUDER : 0),
py = ry - (probe_as_reference == USE_PROBE_AS_REFERENCE ? Y_PROBE_OFFSET_FROM_EXTRUDER : 0);
- float best_so_far = 99999.99;
+ float best_so_far = 99999.99f;
for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
@@ -1316,7 +1317,7 @@
// factor in the distance from the current location for the normal case
// so the nozzle isn't running all over the bed.
- distance += HYPOT(current_position[X_AXIS] - mx, current_position[Y_AXIS] - my) * 0.1;
+ distance += HYPOT(current_position[X_AXIS] - mx, current_position[Y_AXIS] - my) * 0.1f;
if (distance < best_so_far) {
best_so_far = distance; // We found a closer location with
out_mesh.x_index = i; // the specified type of mesh value.
@@ -1382,7 +1383,7 @@
const float rawx = mesh_index_to_xpos(location.x_index),
rawy = mesh_index_to_ypos(location.y_index);
- if (!position_is_reachable(rawx, rawy)) break; // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable
+ if (!position_is_reachable(rawx, rawy)) break; // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable
do_blocking_move_to(rawx, rawy, Z_CLEARANCE_BETWEEN_PROBES); // Move the nozzle to the edit point with probe clearance
@@ -1397,8 +1398,8 @@
lcd_refresh();
float new_z = z_values[location.x_index][location.y_index];
- if (isnan(new_z)) new_z = 0.0; // Invalid points begin at 0
- new_z = FLOOR(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place
+ 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);
@@ -1457,7 +1458,7 @@
if (z_values[x1][y1] < z_values[x2][y2]) // Angled downward?
z_values[x][y] = z_values[x1][y1]; // Use nearest (maybe a little too high.)
else
- z_values[x][y] = 2.0 * z_values[x1][y1] - z_values[x2][y2]; // Angled upward...
+ z_values[x][y] = 2.0f * z_values[x1][y1] - z_values[x2][y2]; // Angled upward...
return true;
}
return false;
@@ -1494,18 +1495,20 @@
#if HAS_BED_PROBE
+ #include "vector_3.h"
+
void unified_bed_leveling::tilt_mesh_based_on_probed_grid(const bool do_3_pt_leveling) {
- constexpr int16_t x_min = max(MIN_PROBE_X, MESH_MIN_X),
- x_max = min(MAX_PROBE_X, MESH_MAX_X),
- y_min = max(MIN_PROBE_Y, MESH_MIN_Y),
- y_max = min(MAX_PROBE_Y, MESH_MAX_Y);
+ constexpr int16_t x_min = MAX(MIN_PROBE_X, MESH_MIN_X),
+ x_max = MIN(MAX_PROBE_X, MESH_MAX_X),
+ y_min = MAX(MIN_PROBE_Y, MESH_MIN_Y),
+ y_max = MIN(MAX_PROBE_Y, MESH_MAX_Y);
bool abort_flag = false;
float measured_z;
- const float dx = float(x_max - x_min) / (g29_grid_size - 1.0),
- dy = float(y_max - y_min) / (g29_grid_size - 1.0);
+ const float dx = float(x_max - x_min) / (g29_grid_size - 1),
+ dy = float(y_max - y_min) / (g29_grid_size - 1);
struct linear_fit_data lsf_results;
@@ -1556,7 +1559,12 @@
incremental_LSF(&lsf_results, PROBE_PT_3_X, PROBE_PT_3_Y, measured_z);
}
}
-
+
+ STOW_PROBE();
+ #ifdef Z_AFTER_PROBING
+ move_z_after_probing();
+ #endif
+
if (abort_flag) {
SERIAL_ECHOPGM("?Error probing point. Aborting operation.\n");
return;
@@ -1612,15 +1620,18 @@
zig_zag ^= true;
}
- STOW_PROBE();
}
-
+ STOW_PROBE();
+ #ifdef Z_AFTER_PROBING
+ move_z_after_probing();
+ #endif
+
if (abort_flag || finish_incremental_LSF(&lsf_results)) {
SERIAL_ECHOPGM("Could not complete LSF!");
return;
}
- vector_3 normal = vector_3(lsf_results.A, lsf_results.B, 1.0000).get_normal();
+ vector_3 normal = vector_3(lsf_results.A, lsf_results.B, 1).get_normal();
if (g29_verbose_level > 2) {
SERIAL_ECHOPGM("bed plane normal = [");
@@ -1699,7 +1710,7 @@
* The only difference is just 3 points are used in the calculations. That fact guarantees
* each probed point should have an exact match when a 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.000
+ * numbers for those locations should be 0.
*/
#if 0
float t, t1, d;
@@ -1729,13 +1740,13 @@
SERIAL_EOL();
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
- d = t + normal.z * 0.000;
+ d = t + normal.z * 0;
SERIAL_ECHOPGM("D from home location with Z=0 : ");
SERIAL_ECHO_F(d, 6);
SERIAL_EOL();
t = normal.x * (Z_SAFE_HOMING_X_POINT) + normal.y * (Z_SAFE_HOMING_Y_POINT);
- d = t + get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT); // normal.z * 0.000;
+ d = t + get_z_correction(Z_SAFE_HOMING_X_POINT, Z_SAFE_HOMING_Y_POINT); // normal.z * 0;
SERIAL_ECHOPGM("D from home location using mesh value for Z: ");
SERIAL_ECHO_F(d, 6);
@@ -1766,7 +1777,7 @@
SERIAL_ECHOPGM("Extrapolating mesh...");
- const float weight_scaled = weight_factor * max(MESH_X_DIST, MESH_Y_DIST);
+ const float weight_scaled = weight_factor * MAX(MESH_X_DIST, MESH_Y_DIST);
for (uint8_t jx = 0; jx < GRID_MAX_POINTS_X; jx++)
for (uint8_t jy = 0; jy < GRID_MAX_POINTS_Y; jy++)
@@ -1786,7 +1797,7 @@
if (TEST(bitmap[jx], jy)) {
const float ry = mesh_index_to_ypos(jy),
rz = z_values[jx][jy],
- w = 1.0 + weight_scaled / HYPOT((rx - px), (ry - py));
+ w = 1 + weight_scaled / HYPOT((rx - px), (ry - py));
incremental_WLSF(&lsf_results, rx, ry, rz, w);
}
}
diff --git a/Marlin/ubl_motion.cpp b/Marlin/ubl_motion.cpp
index 24a3b7dc46..5272e20795 100644
--- a/Marlin/ubl_motion.cpp
+++ b/Marlin/ubl_motion.cpp
@@ -97,7 +97,7 @@
FINAL_MOVE:
// The distance is always MESH_X_DIST so multiply by the constant reciprocal.
- const float xratio = (end[X_AXIS] - mesh_index_to_xpos(cell_dest_xi)) * (1.0 / (MESH_X_DIST));
+ const float xratio = (end[X_AXIS] - mesh_index_to_xpos(cell_dest_xi)) * (1.0f / (MESH_X_DIST));
float z1 = z_values[cell_dest_xi ][cell_dest_yi ] + xratio *
(z_values[cell_dest_xi + 1][cell_dest_yi ] - z_values[cell_dest_xi][cell_dest_yi ]),
@@ -107,7 +107,7 @@
if (cell_dest_xi >= GRID_MAX_POINTS_X - 1) z1 = z2 = 0.0;
// X cell-fraction done. Interpolate the two Z offsets with the Y fraction for the final Z offset.
- const float yratio = (end[Y_AXIS] - mesh_index_to_ypos(cell_dest_yi)) * (1.0 / (MESH_Y_DIST)),
+ const float yratio = (end[Y_AXIS] - mesh_index_to_ypos(cell_dest_yi)) * (1.0f / (MESH_Y_DIST)),
z0 = cell_dest_yi < GRID_MAX_POINTS_Y - 1 ? (z1 + (z2 - z1) * yratio) * planner.fade_scaling_factor_for_z(end[Z_AXIS]) : 0.0;
// Undefined parts of the Mesh in z_values[][] are NAN.
@@ -257,7 +257,8 @@
z_position = end[Z_AXIS];
}
- planner.buffer_segment(rx, ry, z_position + z0, e_position, feed_rate, extruder);
+ if (!planner.buffer_segment(rx, ry, z_position + z0, e_position, feed_rate, extruder))
+ break;
} //else printf("FIRST MOVE PRUNED ");
}
@@ -314,7 +315,8 @@
e_position = end[E_AXIS];
z_position = end[Z_AXIS];
}
- planner.buffer_segment(rx, next_mesh_line_y, z_position + z0, e_position, feed_rate, extruder);
+ if (!planner.buffer_segment(rx, next_mesh_line_y, z_position + z0, e_position, feed_rate, extruder))
+ break;
current_yi += dyi;
yi_cnt--;
}
@@ -337,7 +339,8 @@
z_position = end[Z_AXIS];
}
- planner.buffer_segment(next_mesh_line_x, ry, z_position + z0, e_position, feed_rate, extruder);
+ if (!planner.buffer_segment(next_mesh_line_x, ry, z_position + z0, e_position, feed_rate, extruder))
+ break;
current_xi += dxi;
xi_cnt--;
}
@@ -366,7 +369,7 @@
inline void _O2 ubl_buffer_segment_raw(const float (&in_raw)[XYZE], const float &fr) {
#if ENABLED(SKEW_CORRECTION)
- float raw[XYZE] = { in_raw[X_AXIS], in_raw[Y_AXIS], in_raw[Z_AXIS], in_raw[E_AXIS] };
+ float raw[XYZE] = { in_raw[X_AXIS], in_raw[Y_AXIS], in_raw[Z_AXIS] };
planner.skew(raw[X_AXIS], raw[Y_AXIS], raw[Z_AXIS]);
#else
const float (&raw)[XYZE] = in_raw;
@@ -382,11 +385,11 @@
inverse_kinematics(raw); // this writes delta[ABC] from raw[XYZE]
// should move the feedrate scaling to scara inverse_kinematics
- const float adiff = FABS(delta[A_AXIS] - scara_oldA),
- bdiff = FABS(delta[B_AXIS] - scara_oldB);
+ const float adiff = ABS(delta[A_AXIS] - scara_oldA),
+ bdiff = ABS(delta[B_AXIS] - scara_oldB);
scara_oldA = delta[A_AXIS];
scara_oldB = delta[B_AXIS];
- float s_feedrate = max(adiff, bdiff) * scara_feed_factor;
+ float s_feedrate = MAX(adiff, bdiff) * scara_feed_factor;
planner.buffer_segment(delta[A_AXIS], delta[B_AXIS], delta[C_AXIS], in_raw[E_AXIS], s_feedrate, active_extruder);
@@ -432,19 +435,19 @@
#if IS_KINEMATIC
const float seconds = cartesian_xy_mm / feedrate; // seconds to move xy distance at requested rate
uint16_t segments = lroundf(delta_segments_per_second * seconds), // preferred number of segments for distance @ feedrate
- seglimit = lroundf(cartesian_xy_mm * (1.0 / (DELTA_SEGMENT_MIN_LENGTH))); // number of segments at minimum segment length
+ seglimit = lroundf(cartesian_xy_mm * (1.0f / (DELTA_SEGMENT_MIN_LENGTH))); // number of segments at minimum segment length
NOMORE(segments, seglimit); // limit to minimum segment length (fewer segments)
#else
- uint16_t segments = lroundf(cartesian_xy_mm * (1.0 / (DELTA_SEGMENT_MIN_LENGTH))); // cartesian fixed segment length
+ uint16_t segments = lroundf(cartesian_xy_mm * (1.0f / (DELTA_SEGMENT_MIN_LENGTH))); // cartesian fixed segment length
#endif
- NOLESS(segments, 1); // must have at least one segment
- const float inv_segments = 1.0 / segments; // divide once, multiply thereafter
+ NOLESS(segments, 1U); // must have at least one segment
+ const float inv_segments = 1.0f / segments; // divide once, multiply thereafter
#if IS_SCARA // scale the feed rate from mm/s to degrees/s
scara_feed_factor = cartesian_xy_mm * inv_segments * feedrate;
- scara_oldA = stepper.get_axis_position_degrees(A_AXIS);
- scara_oldB = stepper.get_axis_position_degrees(B_AXIS);
+ scara_oldA = planner.get_axis_position_degrees(A_AXIS);
+ scara_oldB = planner.get_axis_position_degrees(B_AXIS);
#endif
const float diff[XYZE] = {
@@ -492,8 +495,8 @@
// in top of loop and again re-find same adjacent cell and use it, just less efficient
// for mesh inset area.
- int8_t cell_xi = (raw[X_AXIS] - (MESH_MIN_X)) * (1.0 / (MESH_X_DIST)),
- cell_yi = (raw[Y_AXIS] - (MESH_MIN_Y)) * (1.0 / (MESH_Y_DIST));
+ int8_t cell_xi = (raw[X_AXIS] - (MESH_MIN_X)) * (1.0f / (MESH_X_DIST)),
+ cell_yi = (raw[Y_AXIS] - (MESH_MIN_Y)) * (1.0f / (MESH_Y_DIST));
cell_xi = constrain(cell_xi, 0, (GRID_MAX_POINTS_X) - 1);
cell_yi = constrain(cell_yi, 0, (GRID_MAX_POINTS_Y) - 1);
@@ -514,15 +517,15 @@
float cx = raw[X_AXIS] - x0, // cell-relative x and y
cy = raw[Y_AXIS] - y0;
- const float z_xmy0 = (z_x1y0 - z_x0y0) * (1.0 / (MESH_X_DIST)), // z slope per x along y0 (lower left to lower right)
- z_xmy1 = (z_x1y1 - z_x0y1) * (1.0 / (MESH_X_DIST)); // z slope per x along y1 (upper left to upper right)
+ const float z_xmy0 = (z_x1y0 - z_x0y0) * (1.0f / (MESH_X_DIST)), // z slope per x along y0 (lower left to lower right)
+ z_xmy1 = (z_x1y1 - z_x0y1) * (1.0f / (MESH_X_DIST)); // z slope per x along y1 (upper left to upper right)
float z_cxy0 = z_x0y0 + z_xmy0 * cx; // z height along y0 at cx (changes for each cx in cell)
const float z_cxy1 = z_x0y1 + z_xmy1 * cx, // z height along y1 at cx
z_cxyd = z_cxy1 - z_cxy0; // z height difference along cx from y0 to y1
- float z_cxym = z_cxyd * (1.0 / (MESH_Y_DIST)); // z slope per y along cx from y0 to y1 (changes for each cx in cell)
+ float z_cxym = z_cxyd * (1.0f / (MESH_Y_DIST)); // z slope per y along cx from y0 to y1 (changes for each cx in cell)
// float z_cxcy = z_cxy0 + z_cxym * cy; // interpolated mesh z height along cx at cy (do inside the segment loop)
@@ -531,7 +534,7 @@
// each change by a constant for fixed segment lengths.
const float z_sxy0 = z_xmy0 * diff[X_AXIS], // per-segment adjustment to z_cxy0
- z_sxym = (z_xmy1 - z_xmy0) * (1.0 / (MESH_Y_DIST)) * diff[X_AXIS]; // per-segment adjustment to z_cxym
+ z_sxym = (z_xmy1 - z_xmy0) * (1.0f / (MESH_Y_DIST)) * diff[X_AXIS]; // per-segment adjustment to z_cxym
for (;;) { // for all segments within this mesh cell
diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp
index 01859d5e15..6a20224a84 100644
--- a/Marlin/ultralcd.cpp
+++ b/Marlin/ultralcd.cpp
@@ -61,47 +61,30 @@
#include "fwretract.h"
#endif
-#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
- bool lcd_external_control; // = false
-#endif
-
#if ENABLED(POWER_LOSS_RECOVERY)
#include "power_loss_recovery.h"
#endif
-// Initialized by settings.load()
-int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
-
-#if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
- millis_t previous_lcd_status_ms = 0;
-#endif
-
-#if ENABLED(BABYSTEPPING)
- long babysteps_done = 0;
- #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
- static void lcd_babystep_zoffset();
- #else
- static void lcd_babystep_z();
- #endif
-#endif
-
-uint8_t lcd_status_update_delay = 1, // First update one loop delayed
- lcd_status_message_level; // Higher level blocks lower level
-
#if ENABLED(STATUS_MESSAGE_SCROLLING)
#if LONG_FILENAME_LENGTH > CHARSIZE * 2 * (LCD_WIDTH)
#define MAX_MESSAGE_LENGTH LONG_FILENAME_LENGTH
#else
#define MAX_MESSAGE_LENGTH CHARSIZE * 2 * (LCD_WIDTH)
#endif
- uint8_t status_scroll_pos = 0;
+ uint8_t status_scroll_offset = 0;
#else
#define MAX_MESSAGE_LENGTH CHARSIZE * (LCD_WIDTH)
#endif
char lcd_status_message[MAX_MESSAGE_LENGTH + 1];
+uint8_t lcd_status_update_delay = 1, // First update one loop delayed
+ lcd_status_message_level; // Higher level blocks lower level
-#if ENABLED(SCROLL_LONG_FILENAMES)
+#if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
+ millis_t previous_lcd_status_ms = 0;
+#endif
+
+#if ENABLED(ULTIPANEL) && ENABLED(SCROLL_LONG_FILENAMES)
uint8_t filename_scroll_pos, filename_scroll_max, filename_scroll_hash;
#endif
@@ -112,11 +95,22 @@ char lcd_status_message[MAX_MESSAGE_LENGTH + 1];
#if ENABLED(DOGLCD)
#include "ultralcd_impl_DOGM.h"
#include
+ bool drawing_screen, first_page; // = false
#else
#include "ultralcd_impl_HD44780.h"
+ constexpr bool first_page = true;
#endif
+// The main status screen
+void lcd_status_screen();
+
+millis_t next_lcd_update_ms;
+
+uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
+uint16_t max_display_update_time = 0;
+
#if ENABLED(ULTIPANEL)
+
#define DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(_type, _name, _strFunc) \
inline void lcd_implementation_drawmenu_setting_edit_ ## _name (const bool sel, const uint8_t row, const char* pstr, const char* pstr2, _type * const data, ...) { \
UNUSED(pstr2); \
@@ -134,39 +128,16 @@ char lcd_status_message[MAX_MESSAGE_LENGTH + 1];
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int16_t, int3, itostr3);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
- DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float32, ftostr32);
+ DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float43, ftostr43sign);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float5, ftostr5rj);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign);
- DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign);
+ DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52sign, ftostr52sign);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint32_t, long5, ftostr5rj);
#define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) DRAW_BOOL_SETTING(sel, row, pstr, data)
#define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) DRAW_BOOL_SETTING(sel, row, pstr, data)
#define lcd_implementation_drawmenu_setting_edit_accessor_bool(sel, row, pstr, pstr2, pget, pset) DRAW_BOOL_SETTING(sel, row, pstr, data)
-#endif // ULTIPANEL
-
-// The main status screen
-void lcd_status_screen();
-
-millis_t next_lcd_update_ms;
-
-uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to draw, decrements after every draw. Set to 2 in LCD routines so the LCD gets at least 1 full redraw (first redraw is partial)
-uint16_t max_display_update_time = 0;
-
-#if ENABLED(DOGLCD)
- bool drawing_screen, // = false
- first_page;
-#else
- constexpr bool first_page = true;
-#endif
-
-#if ENABLED(DAC_STEPPER_CURRENT)
- #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
- uint8_t driverPercent[XYZE];
-#endif
-
-#if ENABLED(ULTIPANEL)
#ifndef TALL_FONT_CORRECTION
#define TALL_FONT_CORRECTION 0
@@ -175,6 +146,27 @@ uint16_t max_display_update_time = 0;
bool no_reentry = false;
constexpr int8_t menu_bottom = LCD_HEIGHT - (TALL_FONT_CORRECTION);
+ // Initialized by settings.load()
+ int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
+
+ #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
+ bool lcd_external_control; // = false
+ #endif
+
+ #if ENABLED(BABYSTEPPING)
+ long babysteps_done = 0;
+ #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
+ static void lcd_babystep_zoffset();
+ #else
+ static void lcd_babystep_z();
+ #endif
+ #endif
+
+ #if ENABLED(DAC_STEPPER_CURRENT)
+ #include "stepper_dac.h" //was dac_mcp4728.h MarlinMain uses stepper dac for the m-codes
+ uint8_t driverPercent[XYZE];
+ #endif
+
////////////////////////////////////////////
///////////////// Menu Tree ////////////////
////////////////////////////////////////////
@@ -254,17 +246,17 @@ uint16_t max_display_update_time = 0;
void menu_edit_callback_ ## _name(); \
void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue); \
void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue); \
- void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
+ void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback=NULL, const bool live=false); \
typedef void _name##_void
DECLARE_MENU_EDIT_TYPE(int16_t, int3);
DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
DECLARE_MENU_EDIT_TYPE(float, float3);
- DECLARE_MENU_EDIT_TYPE(float, float32);
+ DECLARE_MENU_EDIT_TYPE(float, float52);
DECLARE_MENU_EDIT_TYPE(float, float43);
DECLARE_MENU_EDIT_TYPE(float, float5);
DECLARE_MENU_EDIT_TYPE(float, float51);
- DECLARE_MENU_EDIT_TYPE(float, float52);
+ DECLARE_MENU_EDIT_TYPE(float, float52sign);
DECLARE_MENU_EDIT_TYPE(float, float62);
DECLARE_MENU_EDIT_TYPE(uint32_t, long5);
@@ -475,7 +467,7 @@ uint16_t max_display_update_time = 0;
#if IS_KINEMATIC
bool processing_manual_move = false;
- float manual_move_offset = 0.0;
+ float manual_move_offset = 0;
#else
constexpr bool processing_manual_move = false;
#endif
@@ -500,6 +492,11 @@ uint16_t max_display_update_time = 0;
void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) {
if (currentScreen != screen) {
+ #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
+ // Shadow for editing the fade height
+ new_z_fade_height = planner.z_fade_height;
+ #endif
+
#if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING) && ENABLED(BABYSTEPPING)
static millis_t doubleclick_expire_ms = 0;
// Going to lcd_main_menu from status screen? Remember first click time.
@@ -508,7 +505,7 @@ uint16_t max_display_update_time = 0;
if (currentScreen == lcd_status_screen)
doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
}
- else if (screen == lcd_status_screen && currentScreen == lcd_main_menu && PENDING(millis(), doubleclick_expire_ms))
+ else if (screen == lcd_status_screen && currentScreen == lcd_main_menu && PENDING(millis(), doubleclick_expire_ms) && (planner.movesplanned() || IS_SD_PRINTING))
screen =
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
lcd_babystep_zoffset
@@ -566,7 +563,7 @@ uint16_t max_display_update_time = 0;
no_reentry = true;
const screenFunc_t old_screen = currentScreen;
lcd_goto_screen(_lcd_synchronize);
- stepper.synchronize(); // idle() is called until moves complete
+ planner.synchronize(); // idle() is called until moves complete
no_reentry = false;
lcd_goto_screen(old_screen);
}
@@ -625,7 +622,7 @@ uint16_t max_display_update_time = 0;
screen_changed = false;
}
if (screen_items > 0 && encoderLine >= screen_items - limit) {
- encoderLine = max(0, screen_items - limit);
+ encoderLine = MAX(0, screen_items - limit);
encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM);
}
if (is_menu) {
@@ -780,36 +777,44 @@ void kill_screen(const char* lcd_msg) {
lcd_kill_screen();
}
-#if ENABLED(ULTIPANEL)
+/**
+ *
+ * Audio feedback for controller clicks
+ *
+ */
+void lcd_buzz(const long duration, const uint16_t freq) {
+ #if ENABLED(LCD_USE_I2C_BUZZER)
+ lcd.buzz(duration, freq);
+ #elif PIN_EXISTS(BEEPER)
+ buzzer.tone(duration, freq);
+ #else
+ UNUSED(duration); UNUSED(freq);
+ #endif
+}
- /**
- *
- * Audio feedback for controller clicks
- *
- */
- void lcd_buzz(const long duration, const uint16_t freq) {
- #if ENABLED(LCD_USE_I2C_BUZZER)
- lcd.buzz(duration, freq);
- #elif PIN_EXISTS(BEEPER)
- buzzer.tone(duration, freq);
- #else
- UNUSED(duration); UNUSED(freq);
- #endif
- }
+void lcd_quick_feedback(const bool clear_buttons) {
- void lcd_quick_feedback(const bool clear_buttons) {
+ #if ENABLED(ULTIPANEL)
lcd_refresh();
if (clear_buttons) buttons = 0;
next_button_update_ms = millis() + 500;
+ #else
+ UNUSED(clear_buttons);
+ #endif
- // Buzz and wait. The delay is needed for buttons to settle!
- lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
+ // Buzz and wait. The delay is needed for buttons to settle!
+ lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
+
+ #if ENABLED(ULTIPANEL)
#if ENABLED(LCD_USE_I2C_BUZZER)
delay(10);
#elif PIN_EXISTS(BEEPER)
for (int8_t i = 5; i--;) { buzzer.tick(); delay(2); }
#endif
- }
+ #endif
+}
+
+#if ENABLED(ULTIPANEL)
void lcd_completion_feedback(const bool good/*=true*/) {
if (good) {
@@ -852,24 +857,17 @@ void kill_screen(const char* lcd_msg) {
bool abort_sd_printing; // =false
void lcd_sdcard_stop() {
+ wait_for_heatup = wait_for_user = false;
abort_sd_printing = true;
lcd_setstatusPGM(PSTR(MSG_PRINT_ABORTED), -1);
lcd_return_to_status();
-
- #if ENABLED(POWER_LOSS_RECOVERY)
- card.openJobRecoveryFile(false);
- job_recovery_info.valid_head = job_recovery_info.valid_foot = 0;
- (void)card.saveJobRecoveryInfo();
- card.closeJobRecoveryFile();
- job_recovery_commands_count = 0;
- #endif
}
#endif // SDSUPPORT
#if ENABLED(POWER_LOSS_RECOVERY)
- static void lcd_sdcard_recover_job() {
+ static void lcd_power_loss_recovery_resume() {
char cmd[20];
// Return to status now
@@ -877,49 +875,69 @@ void kill_screen(const char* lcd_msg) {
// Turn leveling off and home
enqueue_and_echo_commands_P(PSTR("M420 S0\nG28"
- #if !IS_KINEMATIC
+ #if ENABLED(MARLIN_DEV_MODE)
+ " S"
+ #elif !IS_KINEMATIC
" X Y"
#endif
));
#if HAS_HEATED_BED
- // Restore the bed temperature
- sprintf_P(cmd, PSTR("M190 S%i"), job_recovery_info.target_temperature_bed);
- enqueue_and_echo_command(cmd);
+ const int16_t bt = job_recovery_info.target_temperature_bed;
+ if (bt) {
+ // Restore the bed temperature
+ sprintf_P(cmd, PSTR("M190 S%i"), bt);
+ enqueue_and_echo_command(cmd);
+ }
#endif
// Restore all hotend temperatures
HOTEND_LOOP() {
- sprintf_P(cmd, PSTR("M109 S%i"), job_recovery_info.target_temperature[e]);
- enqueue_and_echo_command(cmd);
+ const int16_t et = job_recovery_info.target_temperature[e];
+ if (et) {
+ #if HOTENDS > 1
+ sprintf_P(cmd, PSTR("T%i"), e);
+ enqueue_and_echo_command(cmd);
+ #endif
+ sprintf_P(cmd, PSTR("M109 S%i"), et);
+ enqueue_and_echo_command(cmd);
+ }
}
+ #if HOTENDS > 1
+ sprintf_P(cmd, PSTR("T%i"), job_recovery_info.active_hotend);
+ enqueue_and_echo_command(cmd);
+ #endif
+
// Restore print cooling fan speeds
for (uint8_t i = 0; i < FAN_COUNT; i++) {
- sprintf_P(cmd, PSTR("M106 P%i S%i"), i, job_recovery_info.fanSpeeds[i]);
- enqueue_and_echo_command(cmd);
+ int16_t f = job_recovery_info.fanSpeeds[i];
+ if (f) {
+ sprintf_P(cmd, PSTR("M106 P%i S%i"), i, f);
+ enqueue_and_echo_command(cmd);
+ }
}
// Start draining the job recovery command queue
job_recovery_phase = JOB_RECOVERY_YES;
+ }
- // Resume the print job timer
- if (job_recovery_info.print_job_elapsed)
- print_job_timer.resume(job_recovery_info.print_job_elapsed);
-
- // Start getting commands from SD
- card.startFileprint();
+ static void lcd_power_loss_recovery_cancel() {
+ card.removeJobRecoveryFile();
+ card.autostart_index = 0;
+ lcd_return_to_status();
}
static void lcd_job_recovery_menu() {
defer_return_to_status = true;
START_MENU();
- MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_recover_job);
- MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
+ STATIC_ITEM(MSG_POWER_LOSS_RECOVERY);
+ MENU_ITEM(function, MSG_RESUME_PRINT, lcd_power_loss_recovery_resume);
+ MENU_ITEM(function, MSG_STOP_PRINT, lcd_power_loss_recovery_cancel);
END_MENU();
}
- #endif
+ #endif // POWER_LOSS_RECOVERY
#if ENABLED(MENU_ITEM_CASE_LIGHT)
@@ -1065,13 +1083,6 @@ void kill_screen(const char* lcd_msg) {
*
*/
- #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- void _lcd_goto_tune_menu() {
- lcd_goto_screen(lcd_tune_menu);
- new_z_fade_height = planner.z_fade_height;
- }
- #endif
-
void lcd_main_menu() {
START_MENU();
MENU_BACK(MSG_WATCH);
@@ -1098,18 +1109,11 @@ void kill_screen(const char* lcd_msg) {
MENU_ITEM_EDIT_CALLBACK(bool, MSG_CASE_LIGHT, (bool*)&case_light_on, update_case_light);
#endif
- if (planner.movesplanned() || IS_SD_PRINTING) {
- MENU_ITEM(submenu, MSG_TUNE,
- #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- _lcd_goto_tune_menu
- #else
- lcd_tune_menu
- #endif
- );
- }
- else {
+ if (planner.movesplanned() || IS_SD_PRINTING)
+ MENU_ITEM(submenu, MSG_TUNE, lcd_tune_menu);
+ else
MENU_ITEM(submenu, MSG_PREPARE, lcd_prepare_menu);
- }
+
MENU_ITEM(submenu, MSG_CONTROL, lcd_control_menu);
#if ENABLED(SDSUPPORT)
@@ -1271,13 +1275,13 @@ void kill_screen(const char* lcd_msg) {
ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
ubl.encoder_diff = 0;
- mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
+ mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005f / 2.0f;
mesh_edit_value = mesh_edit_accumulator;
encoderPosition = 0;
lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
- const int32_t rounded = (int32_t)(mesh_edit_value * 1000.0);
- mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
+ const int32_t rounded = (int32_t)(mesh_edit_value * 1000);
+ mesh_edit_value = float(rounded - (rounded % 5L)) / 1000;
}
if (lcdDrawUpdate) {
@@ -1394,13 +1398,20 @@ void kill_screen(const char* lcd_msg) {
//
MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
+ //
// Manual bed leveling, Bed Z:
+ //
#if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
#endif
- #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
+
+ //
+ // Leveling Fade Height
+ //
+ #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) && DISABLED(SLIM_LCD_MENUS)
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0, 100, _lcd_set_z_fade_height);
#endif
+
//
// Nozzle:
// Nozzle [1-4]:
@@ -1561,8 +1572,8 @@ void kill_screen(const char* lcd_msg) {
*
*/
void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb, const int16_t fan) {
- if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
- #if TEMP_SENSOR_BED != 0
+ if (temph > 0) thermalManager.setTargetHotend(MIN(heater_maxtemp[endnum], temph), endnum);
+ #if HAS_HEATED_BED
if (tempb >= 0) thermalManager.setTargetBed(tempb);
#else
UNUSED(tempb);
@@ -1579,10 +1590,10 @@ void kill_screen(const char* lcd_msg) {
lcd_return_to_status();
}
- #if TEMP_SENSOR_0 != 0
+ #if HAS_TEMP_HOTEND
void lcd_preheat_m1_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_e0_only() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
void lcd_preheat_m1_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_e0() { _lcd_preheat(0, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
#endif
@@ -1591,28 +1602,28 @@ void kill_screen(const char* lcd_msg) {
#if HOTENDS > 1
void lcd_preheat_m1_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_e1_only() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
void lcd_preheat_m1_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_e1() { _lcd_preheat(1, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
#endif
#if HOTENDS > 2
void lcd_preheat_m1_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_e2_only() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
void lcd_preheat_m1_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_e2() { _lcd_preheat(2, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
#endif
#if HOTENDS > 3
void lcd_preheat_m1_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_e3_only() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
void lcd_preheat_m1_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_e3() { _lcd_preheat(3, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
#endif
#if HOTENDS > 4
void lcd_preheat_m1_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], -1, lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_e4_only() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], -1, lcd_preheat_fan_speed[1]); }
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
void lcd_preheat_m1_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[0], lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_e4() { _lcd_preheat(4, lcd_preheat_hotend_temp[1], lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
#endif
@@ -1633,7 +1644,7 @@ void kill_screen(const char* lcd_msg) {
#endif // HOTENDS > 3
#endif // HOTENDS > 2
#endif // HOTENDS > 1
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
lcd_preheat_m1_e0();
#else
lcd_preheat_m1_e0_only();
@@ -1652,7 +1663,7 @@ void kill_screen(const char* lcd_msg) {
#endif // HOTENDS > 3
#endif // HOTENDS > 2
#endif // HOTENDS > 1
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
lcd_preheat_m2_e0();
#else
lcd_preheat_m2_e0_only();
@@ -1661,25 +1672,25 @@ void kill_screen(const char* lcd_msg) {
#endif // HOTENDS > 1
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
void lcd_preheat_m1_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[0], lcd_preheat_fan_speed[0]); }
void lcd_preheat_m2_bedonly() { _lcd_preheat(0, 0, lcd_preheat_bed_temp[1], lcd_preheat_fan_speed[1]); }
#endif
- #if TEMP_SENSOR_0 != 0 && (TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0)
+ #if HAS_TEMP_HOTEND || HAS_HEATED_BED
void lcd_preheat_m1_menu() {
START_MENU();
MENU_BACK(MSG_PREPARE);
#if HOTENDS == 1
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0);
MENU_ITEM(function, MSG_PREHEAT_1_END, lcd_preheat_m1_e0_only);
#else
MENU_ITEM(function, MSG_PREHEAT_1, lcd_preheat_m1_e0_only);
#endif
- #else
- #if TEMP_SENSOR_BED != 0
+ #elif HOTENDS > 1
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H1, lcd_preheat_m1_e0);
MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E1, lcd_preheat_m1_e0_only);
MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1);
@@ -1689,21 +1700,21 @@ void kill_screen(const char* lcd_msg) {
MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H2, lcd_preheat_m1_e1_only);
#endif
#if HOTENDS > 2
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2);
MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E3, lcd_preheat_m1_e2_only);
#else
MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H3, lcd_preheat_m1_e2_only);
#endif
#if HOTENDS > 3
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3);
MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E4, lcd_preheat_m1_e3_only);
#else
MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H4, lcd_preheat_m1_e3_only);
#endif
#if HOTENDS > 4
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_1_N MSG_H5, lcd_preheat_m1_e4);
MENU_ITEM(function, MSG_PREHEAT_1_END " " MSG_E5, lcd_preheat_m1_e4_only);
#else
@@ -1714,7 +1725,7 @@ void kill_screen(const char* lcd_msg) {
#endif // HOTENDS > 2
MENU_ITEM(function, MSG_PREHEAT_1_ALL, lcd_preheat_m1_all);
#endif // HOTENDS > 1
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_1_BEDONLY, lcd_preheat_m1_bedonly);
#endif
END_MENU();
@@ -1724,14 +1735,14 @@ void kill_screen(const char* lcd_msg) {
START_MENU();
MENU_BACK(MSG_PREPARE);
#if HOTENDS == 1
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0);
MENU_ITEM(function, MSG_PREHEAT_2_END, lcd_preheat_m2_e0_only);
#else
MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
#endif
- #else
- #if TEMP_SENSOR_BED != 0
+ #elif HOTENDS > 1
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H1, lcd_preheat_m2_e0);
MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E1, lcd_preheat_m2_e0_only);
MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1);
@@ -1741,21 +1752,21 @@ void kill_screen(const char* lcd_msg) {
MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H2, lcd_preheat_m2_e1_only);
#endif
#if HOTENDS > 2
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2);
MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E3, lcd_preheat_m2_e2_only);
#else
MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H3, lcd_preheat_m2_e2_only);
#endif
#if HOTENDS > 3
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3);
MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E4, lcd_preheat_m2_e3_only);
#else
MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H4, lcd_preheat_m2_e3_only);
#endif
#if HOTENDS > 4
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_2_N MSG_H5, lcd_preheat_m2_e4);
MENU_ITEM(function, MSG_PREHEAT_2_END " " MSG_E5, lcd_preheat_m2_e4_only);
#else
@@ -1766,13 +1777,13 @@ void kill_screen(const char* lcd_msg) {
#endif // HOTENDS > 2
MENU_ITEM(function, MSG_PREHEAT_2_ALL, lcd_preheat_m2_all);
#endif // HOTENDS > 1
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM(function, MSG_PREHEAT_2_BEDONLY, lcd_preheat_m2_bedonly);
#endif
END_MENU();
}
- #endif // TEMP_SENSOR_0 && (TEMP_SENSOR_1 || TEMP_SENSOR_2 || TEMP_SENSOR_3 || TEMP_SENSOR_4 || TEMP_SENSOR_BED)
+ #endif // HAS_TEMP_HOTEND || HAS_HEATED_BED
void lcd_cooldown() {
#if FAN_COUNT > 0
@@ -1804,11 +1815,7 @@ void kill_screen(const char* lcd_msg) {
#if ENABLED(SDSUPPORT) && ENABLED(MENU_ADDAUTOSTART)
- void lcd_autostart_sd() {
- card.autostart_index = 0;
- card.setroot();
- card.checkautostart(true);
- }
+ void lcd_autostart_sd() { card.beginautostart(); }
#endif
@@ -1877,7 +1884,7 @@ void kill_screen(const char* lcd_msg) {
#endif // LEVEL_BED_CORNERS
- #if ENABLED(LCD_BED_LEVELING)
+ #if ENABLED(LCD_BED_LEVELING) && (ENABLED(PROBE_MANUALLY) || ENABLED(MESH_BED_LEVELING))
/**
*
@@ -1961,7 +1968,7 @@ void kill_screen(const char* lcd_msg) {
//
if (encoderPosition) {
const float z = current_position[Z_AXIS] + float((int32_t)encoderPosition) * (MBL_Z_STEP);
- line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5));
+ line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5f, (LCD_PROBE_Z_RANGE) * 0.5f));
lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
encoderPosition = 0;
}
@@ -1971,7 +1978,7 @@ void kill_screen(const char* lcd_msg) {
//
if (lcdDrawUpdate) {
const float v = current_position[Z_AXIS];
- lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
+ lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001f : 0.0001f), '+'));
}
}
@@ -2021,8 +2028,7 @@ void kill_screen(const char* lcd_msg) {
void _lcd_level_bed_homing() {
if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_HOMING), NULL);
lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
- if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
- lcd_goto_screen(_lcd_level_bed_homing_done);
+ if (all_axes_homed()) lcd_goto_screen(_lcd_level_bed_homing_done);
}
#if ENABLED(PROBE_MANUALLY)
@@ -2034,92 +2040,15 @@ void kill_screen(const char* lcd_msg) {
*/
void _lcd_level_bed_continue() {
defer_return_to_status = true;
- axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
+ axis_homed = 0;
lcd_goto_screen(_lcd_level_bed_homing);
enqueue_and_echo_commands_P(PSTR("G28"));
}
- static bool new_level_state;
- void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(new_level_state); }
-
- /**
- * Step 1: Bed Level entry-point
- *
- * << Prepare
- * Auto Home (if homing needed)
- * Leveling On/Off (if data exists, and homed)
- * Fade Height: --- (Req: ENABLE_LEVELING_FADE_HEIGHT)
- * Mesh Z Offset: --- (Req: MESH_BED_LEVELING)
- * Z Probe Offset: --- (Req: HAS_BED_PROBE, Opt: BABYSTEP_ZPROBE_OFFSET)
- * Level Bed >
- * Level Corners > (if homed)
- * Load Settings (Req: EEPROM_SETTINGS)
- * Save Settings (Req: EEPROM_SETTINGS)
- */
- void lcd_bed_leveling() {
- START_MENU();
- MENU_BACK(MSG_PREPARE);
-
- #if DISABLED(MESH_BED_LEVELING)
- if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
- MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
- else
- #endif
- if (leveling_is_valid()) {
- new_level_state = planner.leveling_active;
- MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &new_level_state, _lcd_toggle_bed_leveling);
- }
-
- #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
- #endif
-
- //
- // MBL Z Offset
- //
- #if ENABLED(MESH_BED_LEVELING)
- MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
- #endif
-
- #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
- MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
- #elif HAS_BED_PROBE
- MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
- #endif
-
- MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
-
- #if ENABLED(LEVEL_BED_CORNERS)
- // Move to the next corner for leveling
- if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
- MENU_ITEM(submenu, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
- #endif
-
- #if ENABLED(EEPROM_SETTINGS)
- MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
- MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
- #endif
- END_MENU();
- }
-
- #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- void _lcd_goto_bed_leveling() {
- lcd_goto_screen(lcd_bed_leveling);
- new_z_fade_height = planner.z_fade_height;
- }
- #endif
-
#elif ENABLED(AUTO_BED_LEVELING_UBL)
void _lcd_ubl_level_bed();
- #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- void _lcd_goto_ubl_level_bed() {
- lcd_goto_screen(_lcd_ubl_level_bed);
- new_z_fade_height = planner.z_fade_height;
- }
- #endif
-
static int16_t ubl_storage_slot = 0,
custom_hotend_temp = 190,
side_points = 3,
@@ -2174,7 +2103,7 @@ void kill_screen(const char* lcd_msg) {
char UBL_LCD_GCODE[16];
const int ind = ubl_height_amount > 0 ? 9 : 10;
strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6 C -"));
- sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount));
+ sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), ABS(ubl_height_amount));
lcd_enqueue_command(UBL_LCD_GCODE);
}
@@ -2441,7 +2370,7 @@ void kill_screen(const char* lcd_msg) {
defer_return_to_status = true;
if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT < 3 ? 0 : (LCD_HEIGHT > 4 ? 2 : 1), PSTR(MSG_LEVEL_BED_HOMING));
lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
- if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
+ if (all_axes_homed()) {
ubl.lcd_map_control = true; // Return to the map screen
lcd_goto_screen(_lcd_ubl_output_map_lcd);
}
@@ -2474,12 +2403,10 @@ void kill_screen(const char* lcd_msg) {
void _lcd_do_nothing() {}
void _lcd_hard_stop() {
- stepper.quick_stop();
const screenFunc_t old_screen = currentScreen;
currentScreen = _lcd_do_nothing;
- while (planner.movesplanned()) idle();
+ planner.quick_stop();
currentScreen = old_screen;
- stepper.cleaning_buffer_counter = 0;
set_current_from_steppers_for_axis(ALL_AXES);
sync_plan_position();
}
@@ -2487,16 +2414,13 @@ void kill_screen(const char* lcd_msg) {
void _lcd_ubl_output_map_lcd() {
static int16_t step_scaler = 0;
- if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS]))
- return lcd_goto_screen(_lcd_ubl_map_homing);
-
if (use_click()) return _lcd_ubl_map_lcd_edit_cmd();
ENCODER_DIRECTION_NORMAL();
if (encoderPosition) {
step_scaler += (int32_t)encoderPosition;
x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
- if (abs(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0;
+ if (ABS(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0;
encoderPosition = 0;
lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
}
@@ -2536,8 +2460,8 @@ void kill_screen(const char* lcd_msg) {
* UBL Homing before LCD map
*/
void _lcd_ubl_output_map_lcd_cmd() {
- if (!(axis_known_position[X_AXIS] && axis_known_position[Y_AXIS] && axis_known_position[Z_AXIS])) {
- axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
+ if (!all_axes_known()) {
+ axis_homed = 0;
enqueue_and_echo_commands_P(PSTR("G28"));
}
lcd_goto_screen(_lcd_ubl_map_homing);
@@ -2633,13 +2557,92 @@ void kill_screen(const char* lcd_msg) {
MENU_ITEM(submenu, MSG_UBL_TOOLS, _lcd_ubl_tools_menu);
MENU_ITEM(gcode, MSG_UBL_INFO_UBL, PSTR("G29 W"));
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float62, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0.0, 100.0, _lcd_set_z_fade_height);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0, 100, _lcd_set_z_fade_height);
#endif
END_MENU();
}
#endif // AUTO_BED_LEVELING_UBL
+
+ #if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
+ void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(!planner.leveling_active); }
+ #endif
+
+ #if ENABLED(LCD_BED_LEVELING)
+
+ /**
+ * Step 1: Bed Level entry-point
+ *
+ * << Prepare
+ * Auto Home (if homing needed)
+ * Leveling On/Off (if data exists, and homed)
+ * Fade Height: --- (Req: ENABLE_LEVELING_FADE_HEIGHT)
+ * Mesh Z Offset: --- (Req: MESH_BED_LEVELING)
+ * Z Probe Offset: --- (Req: HAS_BED_PROBE, Opt: BABYSTEP_ZPROBE_OFFSET)
+ * Level Bed >
+ * Level Corners > (if homed)
+ * Load Settings (Req: EEPROM_SETTINGS)
+ * Save Settings (Req: EEPROM_SETTINGS)
+ */
+ void lcd_bed_leveling() {
+ START_MENU();
+ MENU_BACK(MSG_PREPARE);
+
+ const bool is_homed = all_axes_known();
+
+ // Auto Home if not using manual probing
+ #if DISABLED(PROBE_MANUALLY) && DISABLED(MESH_BED_LEVELING)
+ if (!is_homed) MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
+ #endif
+
+ // Level Bed
+ #if ENABLED(PROBE_MANUALLY) || ENABLED(MESH_BED_LEVELING)
+ // Manual leveling uses a guided procedure
+ MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
+ #else
+ // Automatic leveling can just run the G-code
+ MENU_ITEM(gcode, MSG_LEVEL_BED, is_homed ? PSTR("G29") : PSTR("G28\nG29"));
+ #endif
+
+ // Homed and leveling is valid? Then leveling can be toggled.
+ if (is_homed && leveling_is_valid()) {
+ bool new_level_state = planner.leveling_active;
+ MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &new_level_state, _lcd_toggle_bed_leveling);
+ }
+
+ // Z Fade Height
+ #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0, 100, _lcd_set_z_fade_height);
+ #endif
+
+ //
+ // MBL Z Offset
+ //
+ #if ENABLED(MESH_BED_LEVELING)
+ MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
+ #endif
+
+ #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
+ MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
+ #elif HAS_BED_PROBE
+ MENU_ITEM_EDIT(float52, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
+ #endif
+
+ #if ENABLED(LEVEL_BED_CORNERS)
+ // Move to the next corner for leveling
+ if (all_axes_homed()) MENU_ITEM(submenu, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
+ #endif
+
+ #if ENABLED(EEPROM_SETTINGS)
+ MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
+ MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
+ #endif
+ END_MENU();
+ }
+
+ #endif // LCD_BED_LEVELING
+
/**
*
* "Prepare" submenu
@@ -2658,7 +2661,7 @@ void kill_screen(const char* lcd_msg) {
// Move Axis
//
#if ENABLED(DELTA)
- if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
+ if (all_axes_homed())
#endif
MENU_ITEM(submenu, MSG_MOVE_AXIS, lcd_move_menu);
@@ -2676,30 +2679,33 @@ void kill_screen(const char* lcd_msg) {
// Level Bed
//
#if ENABLED(AUTO_BED_LEVELING_UBL)
- MENU_ITEM(submenu, MSG_UBL_LEVEL_BED,
- #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- _lcd_goto_ubl_level_bed
- #else
- _lcd_ubl_level_bed
- #endif
- );
+
+ MENU_ITEM(submenu, MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
+
#elif ENABLED(LCD_BED_LEVELING)
+
#if ENABLED(PROBE_MANUALLY)
if (!g29_in_progress)
#endif
- MENU_ITEM(submenu, MSG_BED_LEVELING,
- #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- _lcd_goto_bed_leveling
- #else
- lcd_bed_leveling
- #endif
- );
- #elif PLANNER_LEVELING && DISABLED(PROBE_MANUALLY) && DISABLED(SLIM_LCD_MENUS)
- MENU_ITEM(gcode, MSG_BED_LEVELING, PSTR("G28\nG29"));
+ MENU_ITEM(submenu, MSG_BED_LEVELING, lcd_bed_leveling);
+
+ #elif HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
+
+ #if DISABLED(PROBE_MANUALLY)
+ MENU_ITEM(gcode, MSG_LEVEL_BED, PSTR("G28\nG29"));
+ #endif
+ if (leveling_is_valid()) {
+ bool new_level_state = planner.leveling_active;
+ MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &new_level_state, _lcd_toggle_bed_leveling);
+ }
+ #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &new_z_fade_height, 0, 100, _lcd_set_z_fade_height);
+ #endif
+
#endif
#if ENABLED(LEVEL_BED_CORNERS) && DISABLED(LCD_BED_LEVELING)
- if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
+ if (all_axes_homed())
MENU_ITEM(function, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
#endif
@@ -2731,7 +2737,7 @@ void kill_screen(const char* lcd_msg) {
}
#endif // ADVANCED_PAUSE_FEATURE
- #if TEMP_SENSOR_0 != 0
+ #if HAS_TEMP_HOTEND
//
// Cooldown
@@ -2746,7 +2752,7 @@ void kill_screen(const char* lcd_msg) {
//
// Preheat for Material 1 and 2
//
- #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || TEMP_SENSOR_BED != 0
+ #if TEMP_SENSOR_1 != 0 || TEMP_SENSOR_2 != 0 || TEMP_SENSOR_3 != 0 || TEMP_SENSOR_4 != 0 || HAS_HEATED_BED
MENU_ITEM(submenu, MSG_PREHEAT_1, lcd_preheat_m1_menu);
MENU_ITEM(submenu, MSG_PREHEAT_2, lcd_preheat_m2_menu);
#else
@@ -2754,7 +2760,7 @@ void kill_screen(const char* lcd_msg) {
MENU_ITEM(function, MSG_PREHEAT_2, lcd_preheat_m2_e0_only);
#endif
- #endif // TEMP_SENSOR_0 != 0
+ #endif // HAS_TEMP_HOTEND
//
// BLTouch Self-Test and Reset
@@ -2803,7 +2809,7 @@ void kill_screen(const char* lcd_msg) {
do_blocking_move_to_xy(rx, ry);
lcd_synchronize();
- move_menu_scale = max(PROBE_MANUALLY_STEP, MIN_STEPS_PER_SEGMENT / float(DEFAULT_XYZ_STEPS_PER_UNIT));
+ move_menu_scale = MAX(PROBE_MANUALLY_STEP, MIN_STEPS_PER_SEGMENT / float(DEFAULT_XYZ_STEPS_PER_UNIT));
lcd_goto_screen(lcd_move_z);
}
@@ -2829,7 +2835,7 @@ void kill_screen(const char* lcd_msg) {
void _lcd_calibrate_homing() {
if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_HOMING));
lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
- if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
+ if (all_axes_homed())
lcd_goto_previous_menu();
}
@@ -2857,15 +2863,15 @@ void kill_screen(const char* lcd_msg) {
void lcd_delta_settings() {
START_MENU();
MENU_BACK(MSG_DELTA_CALIBRATE);
- MENU_ITEM_EDIT_CALLBACK(float52, MSG_DELTA_HEIGHT, &delta_height, delta_height - 10.0, delta_height + 10.0, _recalc_delta_settings);
- MENU_ITEM_EDIT_CALLBACK(float43, "Ex", &delta_endstop_adj[A_AXIS], -5.0, 5.0, _recalc_delta_settings);
- MENU_ITEM_EDIT_CALLBACK(float43, "Ey", &delta_endstop_adj[B_AXIS], -5.0, 5.0, _recalc_delta_settings);
- MENU_ITEM_EDIT_CALLBACK(float43, "Ez", &delta_endstop_adj[C_AXIS], -5.0, 5.0, _recalc_delta_settings);
- MENU_ITEM_EDIT_CALLBACK(float52, MSG_DELTA_RADIUS, &delta_radius, delta_radius - 5.0, delta_radius + 5.0, _recalc_delta_settings);
- MENU_ITEM_EDIT_CALLBACK(float43, "Tx", &delta_tower_angle_trim[A_AXIS], -5.0, 5.0, _recalc_delta_settings);
- MENU_ITEM_EDIT_CALLBACK(float43, "Ty", &delta_tower_angle_trim[B_AXIS], -5.0, 5.0, _recalc_delta_settings);
- MENU_ITEM_EDIT_CALLBACK(float43, "Tz", &delta_tower_angle_trim[C_AXIS], -5.0, 5.0, _recalc_delta_settings);
- MENU_ITEM_EDIT_CALLBACK(float52, MSG_DELTA_DIAG_ROD, &delta_diagonal_rod, delta_diagonal_rod - 5.0, delta_diagonal_rod + 5.0, _recalc_delta_settings);
+ MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_DELTA_HEIGHT, &delta_height, delta_height - 10, delta_height + 10, _recalc_delta_settings);
+ MENU_ITEM_EDIT_CALLBACK(float43, "Ex", &delta_endstop_adj[A_AXIS], -5, 5, _recalc_delta_settings);
+ MENU_ITEM_EDIT_CALLBACK(float43, "Ey", &delta_endstop_adj[B_AXIS], -5, 5, _recalc_delta_settings);
+ MENU_ITEM_EDIT_CALLBACK(float43, "Ez", &delta_endstop_adj[C_AXIS], -5, 5, _recalc_delta_settings);
+ MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_DELTA_RADIUS, &delta_radius, delta_radius - 5, delta_radius + 5, _recalc_delta_settings);
+ MENU_ITEM_EDIT_CALLBACK(float43, "Tx", &delta_tower_angle_trim[A_AXIS], -5, 5, _recalc_delta_settings);
+ MENU_ITEM_EDIT_CALLBACK(float43, "Ty", &delta_tower_angle_trim[B_AXIS], -5, 5, _recalc_delta_settings);
+ MENU_ITEM_EDIT_CALLBACK(float43, "Tz", &delta_tower_angle_trim[C_AXIS], -5, 5, _recalc_delta_settings);
+ MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_DELTA_DIAG_ROD, &delta_diagonal_rod, delta_diagonal_rod - 5, delta_diagonal_rod + 5, _recalc_delta_settings);
END_MENU();
}
@@ -2884,7 +2890,7 @@ void kill_screen(const char* lcd_msg) {
MENU_ITEM(submenu, MSG_DELTA_SETTINGS, lcd_delta_settings);
#if ENABLED(DELTA_CALIBRATION_MENU)
MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
- if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
+ if (all_axes_homed()) {
MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
@@ -2921,7 +2927,7 @@ void kill_screen(const char* lcd_msg) {
destination[manual_move_axis] += manual_move_offset;
// Reset for the next move
- manual_move_offset = 0.0;
+ manual_move_offset = 0;
manual_move_axis = (int8_t)NO_AXIS;
// DELTA and SCARA machines use segmented moves, which could fill the planner during the call to
@@ -2961,7 +2967,7 @@ void kill_screen(const char* lcd_msg) {
#endif
manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
#endif
- manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
+ manual_move_start_time = millis() + (move_menu_scale < 0.99f ? 0UL : 250UL); // delay for bigger moves
manual_move_axis = (int8_t)axis;
}
@@ -3045,7 +3051,7 @@ void kill_screen(const char* lcd_msg) {
+ manual_move_offset
#endif
, axis);
- lcd_implementation_drawedit(name, move_menu_scale >= 0.1 ? ftostr41sign(pos) : ftostr43sign(pos));
+ lcd_implementation_drawedit(name, move_menu_scale >= 0.1f ? ftostr41sign(pos) : ftostr43sign(pos));
}
}
void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
@@ -3130,9 +3136,9 @@ void kill_screen(const char* lcd_msg) {
move_menu_scale = scale;
lcd_goto_screen(_manual_move_func_ptr);
}
- void lcd_move_menu_10mm() { _goto_manual_move(10.0); }
- void lcd_move_menu_1mm() { _goto_manual_move( 1.0); }
- void lcd_move_menu_01mm() { _goto_manual_move( 0.1); }
+ void lcd_move_menu_10mm() { _goto_manual_move(10); }
+ void lcd_move_menu_1mm() { _goto_manual_move( 1); }
+ void lcd_move_menu_01mm() { _goto_manual_move( 0.1f); }
void _lcd_move_distance_menu(const AxisEnum axis, const screenFunc_t func) {
_manual_move_func_ptr = func;
@@ -3180,7 +3186,7 @@ void kill_screen(const char* lcd_msg) {
*/
#if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
- #define _MOVE_XYZ_ALLOWED (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
+ #define _MOVE_XYZ_ALLOWED (all_axes_homed())
#else
#define _MOVE_XYZ_ALLOWED true
#endif
@@ -3218,7 +3224,7 @@ void kill_screen(const char* lcd_msg) {
else
MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
- #if ENABLED(SWITCHING_EXTRUDER)
+ #if ENABLED(SWITCHING_EXTRUDER) || ENABLED(SWITCHING_NOZZLE)
#if EXTRUDERS == 4
switch (active_extruder) {
@@ -3250,20 +3256,36 @@ void kill_screen(const char* lcd_msg) {
#endif
- MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
- #if E_MANUAL > 1
- MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
- MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
- #if E_MANUAL > 2
+ #if ENABLED(SWITCHING_EXTRUDER) || ENABLED(SWITCHING_NOZZLE)
+
+ // Only the current...
+ MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
+ // ...and the non-switching
+ #if E_MANUAL == 5
+ MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
+ #elif E_MANUAL == 3
MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
- #if E_MANUAL > 3
- MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
- #if E_MANUAL > 4
- MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
- #endif // E_MANUAL > 4
- #endif // E_MANUAL > 3
- #endif // E_MANUAL > 2
- #endif // E_MANUAL > 1
+ #endif
+
+ #else
+
+ // Independent extruders with one E-stepper per hotend
+ MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
+ #if E_MANUAL > 1
+ MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
+ MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
+ #if E_MANUAL > 2
+ MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
+ #if E_MANUAL > 3
+ MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
+ #if E_MANUAL > 4
+ MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
+ #endif // E_MANUAL > 4
+ #endif // E_MANUAL > 3
+ #endif // E_MANUAL > 2
+ #endif // E_MANUAL > 1
+
+ #endif
END_MENU();
}
@@ -3283,7 +3305,7 @@ void kill_screen(const char* lcd_msg) {
lcd_completion_feedback();
}
- #if ENABLED(EEPROM_SETTINGS)
+ #if ENABLED(EEPROM_SETTINGS) && DISABLED(SLIM_LCD_MENUS)
static void lcd_init_eeprom() {
lcd_completion_feedback(settings.init_eeprom());
@@ -3308,7 +3330,7 @@ void kill_screen(const char* lcd_msg) {
#if DISABLED(NO_VOLUMETRICS) || ENABLED(ADVANCED_PAUSE_FEATURE)
MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
#elif ENABLED(LIN_ADVANCE)
- MENU_ITEM_EDIT(float32, MSG_ADVANCE_K, &planner.extruder_advance_K, 0, 999);
+ MENU_ITEM_EDIT(float52, MSG_ADVANCE_K, &planner.extruder_advance_K, 0, 999);
#endif
#if HAS_LCD_CONTRAST
@@ -3489,11 +3511,11 @@ void kill_screen(const char* lcd_msg) {
//
// Autotemp, Min, Max, Fact
//
- #if ENABLED(AUTOTEMP) && (TEMP_SENSOR_0 != 0)
+ #if ENABLED(AUTOTEMP) && HAS_TEMP_HOTEND
MENU_ITEM_EDIT(bool, MSG_AUTOTEMP, &planner.autotemp_enabled);
- MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, HEATER_0_MAXTEMP - 15);
- MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, HEATER_0_MAXTEMP - 15);
- MENU_ITEM_EDIT(float32, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
+ MENU_ITEM_EDIT(float3, MSG_MIN, &planner.autotemp_min, 0, float(HEATER_0_MAXTEMP) - 15);
+ MENU_ITEM_EDIT(float3, MSG_MAX, &planner.autotemp_max, 0, float(HEATER_0_MAXTEMP) - 15);
+ MENU_ITEM_EDIT(float52, MSG_FACTOR, &planner.autotemp_factor, 0.0, 1.0);
#endif
//
@@ -3509,9 +3531,9 @@ void kill_screen(const char* lcd_msg) {
#define _PID_BASE_MENU_ITEMS(ELABEL, eindex) \
raw_Ki = unscalePID_i(PID_PARAM(Ki, eindex)); \
raw_Kd = unscalePID_d(PID_PARAM(Kd, eindex)); \
- MENU_ITEM_EDIT(float52, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
- MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_I ELABEL, &raw_Ki, 0.01, 9990, copy_and_scalePID_i_E ## eindex); \
- MENU_ITEM_EDIT_CALLBACK(float52, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
+ MENU_ITEM_EDIT(float52sign, MSG_PID_P ELABEL, &PID_PARAM(Kp, eindex), 1, 9990); \
+ MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_PID_I ELABEL, &raw_Ki, 0.01f, 9990, copy_and_scalePID_i_E ## eindex); \
+ MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_PID_D ELABEL, &raw_Kd, 1, 9990, copy_and_scalePID_d_E ## eindex)
#if ENABLED(PID_EXTRUSION_SCALING)
#define _PID_MENU_ITEMS(ELABEL, eindex) \
@@ -3575,8 +3597,8 @@ void kill_screen(const char* lcd_msg) {
#define MINTEMP_ALL MIN3(HEATER_0_MINTEMP, HEATER_1_MINTEMP, HEATER_2_MINTEMP)
#define MAXTEMP_ALL MAX3(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP, HEATER_2_MAXTEMP)
#elif HOTENDS > 1
- #define MINTEMP_ALL min(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
- #define MAXTEMP_ALL max(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
+ #define MINTEMP_ALL MIN(HEATER_0_MINTEMP, HEATER_1_MINTEMP)
+ #define MAXTEMP_ALL MAX(HEATER_0_MAXTEMP, HEATER_1_MAXTEMP)
#else
#define MINTEMP_ALL HEATER_0_MINTEMP
#define MAXTEMP_ALL HEATER_0_MAXTEMP
@@ -3584,10 +3606,10 @@ void kill_screen(const char* lcd_msg) {
START_MENU();
MENU_BACK(MSG_TEMPERATURE);
MENU_ITEM_EDIT(int3, MSG_FAN_SPEED, &lcd_preheat_fan_speed[material], 0, 255);
- #if TEMP_SENSOR_0 != 0
+ #if HAS_TEMP_HOTEND
MENU_ITEM_EDIT(int3, MSG_NOZZLE, &lcd_preheat_hotend_temp[material], MINTEMP_ALL, MAXTEMP_ALL - 15);
#endif
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
MENU_ITEM_EDIT(int3, MSG_BED, &lcd_preheat_bed_temp[material], BED_MINTEMP, BED_MAXTEMP - 15);
#endif
#if ENABLED(EEPROM_SETTINGS)
@@ -3632,7 +3654,7 @@ void kill_screen(const char* lcd_msg) {
if (e == active_extruder)
_planner_refresh_positioning();
else
- planner.steps_to_mm[E_AXIS + e] = 1.0 / planner.axis_steps_per_mm[E_AXIS + e];
+ planner.steps_to_mm[E_AXIS + e] = 1.0f / planner.axis_steps_per_mm[E_AXIS + e];
}
void _planner_refresh_e0_positioning() { _planner_refresh_e_positioning(0); }
void _planner_refresh_e1_positioning() { _planner_refresh_e_positioning(1); }
@@ -3653,32 +3675,32 @@ void kill_screen(const char* lcd_msg) {
MENU_BACK(MSG_MOTION);
// M203 Max Feedrate
- MENU_ITEM_EDIT(float3, MSG_VMAX MSG_A, &planner.max_feedrate_mm_s[A_AXIS], 1, 999);
- MENU_ITEM_EDIT(float3, MSG_VMAX MSG_B, &planner.max_feedrate_mm_s[B_AXIS], 1, 999);
- MENU_ITEM_EDIT(float3, MSG_VMAX MSG_C, &planner.max_feedrate_mm_s[C_AXIS], 1, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_A, &planner.max_feedrate_mm_s[A_AXIS], 1, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_B, &planner.max_feedrate_mm_s[B_AXIS], 1, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_C, &planner.max_feedrate_mm_s[C_AXIS], 1, 999);
#if ENABLED(DISTINCT_E_FACTORS)
- MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
- MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
- MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS + active_extruder], 1, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E1, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E2, &planner.max_feedrate_mm_s[E_AXIS + 1], 1, 999);
#if E_STEPPERS > 2
- MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E3, &planner.max_feedrate_mm_s[E_AXIS + 2], 1, 999);
#if E_STEPPERS > 3
- MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E4, &planner.max_feedrate_mm_s[E_AXIS + 3], 1, 999);
#if E_STEPPERS > 4
- MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E5, &planner.max_feedrate_mm_s[E_AXIS + 4], 1, 999);
#endif // E_STEPPERS > 4
#endif // E_STEPPERS > 3
#endif // E_STEPPERS > 2
#else
- MENU_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMAX MSG_E, &planner.max_feedrate_mm_s[E_AXIS], 1, 999);
#endif
// M205 S Min Feedrate
- MENU_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VMIN, &planner.min_feedrate_mm_s, 0, 999);
// M205 T Min Travel Feedrate
- MENU_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VTRAV_MIN, &planner.min_travel_feedrate_mm_s, 0, 999);
END_MENU();
}
@@ -3689,34 +3711,34 @@ void kill_screen(const char* lcd_msg) {
MENU_BACK(MSG_MOTION);
// M204 P Acceleration
- MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
+ MENU_MULTIPLIER_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);
// M204 R Retract Acceleration
- MENU_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
+ MENU_MULTIPLIER_ITEM_EDIT(float5, MSG_A_RETRACT, &planner.retract_acceleration, 100, 99000);
// M204 T Travel Acceleration
- MENU_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
+ MENU_MULTIPLIER_ITEM_EDIT(float5, MSG_A_TRAVEL, &planner.travel_acceleration, 100, 99000);
// M201 settings
- MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_A, &planner.max_acceleration_mm_per_s2[A_AXIS], 100, 99000, _reset_acceleration_rates);
- MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_B, &planner.max_acceleration_mm_per_s2[B_AXIS], 100, 99000, _reset_acceleration_rates);
- MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_C, &planner.max_acceleration_mm_per_s2[C_AXIS], 10, 99000, _reset_acceleration_rates);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_A, &planner.max_acceleration_mm_per_s2[A_AXIS], 100, 99000, _reset_acceleration_rates);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_B, &planner.max_acceleration_mm_per_s2[B_AXIS], 100, 99000, _reset_acceleration_rates);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_C, &planner.max_acceleration_mm_per_s2[C_AXIS], 10, 99000, _reset_acceleration_rates);
#if ENABLED(DISTINCT_E_FACTORS)
- MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
- MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
- MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS + active_extruder], 100, 99000, _reset_acceleration_rates);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E1, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_e0_acceleration_rate);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E2, &planner.max_acceleration_mm_per_s2[E_AXIS + 1], 100, 99000, _reset_e1_acceleration_rate);
#if E_STEPPERS > 2
- MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E3, &planner.max_acceleration_mm_per_s2[E_AXIS + 2], 100, 99000, _reset_e2_acceleration_rate);
#if E_STEPPERS > 3
- MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E4, &planner.max_acceleration_mm_per_s2[E_AXIS + 3], 100, 99000, _reset_e3_acceleration_rate);
#if E_STEPPERS > 4
- MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E5, &planner.max_acceleration_mm_per_s2[E_AXIS + 4], 100, 99000, _reset_e4_acceleration_rate);
#endif // E_STEPPERS > 4
#endif // E_STEPPERS > 3
#endif // E_STEPPERS > 2
#else
- MENU_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(long5, MSG_AMAX MSG_E, &planner.max_acceleration_mm_per_s2[E_AXIS], 100, 99000, _reset_acceleration_rates);
#endif
END_MENU();
@@ -3727,14 +3749,18 @@ void kill_screen(const char* lcd_msg) {
START_MENU();
MENU_BACK(MSG_MOTION);
- MENU_ITEM_EDIT(float3, MSG_VA_JERK, &planner.max_jerk[A_AXIS], 1, 990);
- MENU_ITEM_EDIT(float3, MSG_VB_JERK, &planner.max_jerk[B_AXIS], 1, 990);
- #if ENABLED(DELTA)
- MENU_ITEM_EDIT(float3, MSG_VC_JERK, &planner.max_jerk[C_AXIS], 1, 990);
+ #if ENABLED(JUNCTION_DEVIATION)
+ MENU_ITEM_EDIT_CALLBACK(float43, MSG_JUNCTION_DEVIATION, &planner.junction_deviation_mm, 0.01f, 0.3f, planner.recalculate_max_e_jerk);
#else
- MENU_ITEM_EDIT(float52, MSG_VC_JERK, &planner.max_jerk[C_AXIS], 0.1, 990);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VA_JERK, &planner.max_jerk[A_AXIS], 1, 990);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VB_JERK, &planner.max_jerk[B_AXIS], 1, 990);
+ #if ENABLED(DELTA)
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VC_JERK, &planner.max_jerk[C_AXIS], 1, 990);
+ #else
+ MENU_MULTIPLIER_ITEM_EDIT(float52sign, MSG_VC_JERK, &planner.max_jerk[C_AXIS], 0.1f, 990);
+ #endif
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
#endif
- MENU_ITEM_EDIT(float3, MSG_VE_JERK, &planner.max_jerk[E_AXIS], 1, 990);
END_MENU();
}
@@ -3783,7 +3809,7 @@ void kill_screen(const char* lcd_msg) {
#if ENABLED(BABYSTEP_ZPROBE_OFFSET)
MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
#elif HAS_BED_PROBE
- MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
+ MENU_ITEM_EDIT(float52, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
#endif
#if DISABLED(SLIM_LCD_MENUS)
@@ -3804,7 +3830,7 @@ void kill_screen(const char* lcd_msg) {
// M540 S - Abort on endstop hit when SD printing
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
- MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &stepper.abort_on_endstop_hit);
+ MENU_ITEM_EDIT(bool, MSG_ENDSTOP_ABORT, &planner.abort_on_endstop_hit);
#endif
END_MENU();
@@ -3821,7 +3847,7 @@ void kill_screen(const char* lcd_msg) {
MENU_BACK(MSG_CONTROL);
#if ENABLED(LIN_ADVANCE)
- MENU_ITEM_EDIT(float32, MSG_ADVANCE_K, &planner.extruder_advance_K, 0, 999);
+ MENU_ITEM_EDIT(float52, MSG_ADVANCE_K, &planner.extruder_advance_K, 0, 999);
#endif
#if DISABLED(NO_VOLUMETRICS)
@@ -3829,17 +3855,17 @@ void kill_screen(const char* lcd_msg) {
if (parser.volumetric_enabled) {
#if EXTRUDERS == 1
- MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &planner.filament_size[0], 1.5, 3.25, planner.calculate_volumetric_multipliers);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &planner.filament_size[0], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#else // EXTRUDERS > 1
- MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5, 3.25, planner.calculate_volumetric_multipliers);
- MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &planner.filament_size[0], 1.5, 3.25, planner.calculate_volumetric_multipliers);
- MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &planner.filament_size[1], 1.5, 3.25, planner.calculate_volumetric_multipliers);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM, &planner.filament_size[active_extruder], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E1, &planner.filament_size[0], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E2, &planner.filament_size[1], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#if EXTRUDERS > 2
- MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &planner.filament_size[2], 1.5, 3.25, planner.calculate_volumetric_multipliers);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E3, &planner.filament_size[2], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#if EXTRUDERS > 3
- MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &planner.filament_size[3], 1.5, 3.25, planner.calculate_volumetric_multipliers);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E4, &planner.filament_size[3], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#if EXTRUDERS > 4
- MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &planner.filament_size[4], 1.5, 3.25, planner.calculate_volumetric_multipliers);
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float43, MSG_FILAMENT_DIAM MSG_DIAM_E5, &planner.filament_size[4], 1.5f, 3.25f, planner.calculate_volumetric_multipliers);
#endif // EXTRUDERS > 4
#endif // EXTRUDERS > 3
#endif // EXTRUDERS > 2
@@ -3852,39 +3878,39 @@ void kill_screen(const char* lcd_msg) {
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
EXTRUDE_MAXLENGTH
#else
- 999.0f
+ 999
#endif
;
#if EXTRUDERS == 1
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD, &filament_change_unload_length[0], 0.0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD, &filament_change_unload_length[0], 0, extrude_maxlength);
#else // EXTRUDERS > 1
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD, &filament_change_unload_length[active_extruder], 0.0, extrude_maxlength);
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E1, &filament_change_unload_length[0], 0.0, extrude_maxlength);
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E2, &filament_change_unload_length[1], 0.0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD, &filament_change_unload_length[active_extruder], 0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E1, &filament_change_unload_length[0], 0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E2, &filament_change_unload_length[1], 0, extrude_maxlength);
#if EXTRUDERS > 2
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E3, &filament_change_unload_length[2], 0.0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E3, &filament_change_unload_length[2], 0, extrude_maxlength);
#if EXTRUDERS > 3
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E4, &filament_change_unload_length[3], 0.0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E4, &filament_change_unload_length[3], 0, extrude_maxlength);
#if EXTRUDERS > 4
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E5, &filament_change_unload_length[4], 0.0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_UNLOAD MSG_DIAM_E5, &filament_change_unload_length[4], 0, extrude_maxlength);
#endif // EXTRUDERS > 4
#endif // EXTRUDERS > 3
#endif // EXTRUDERS > 2
#endif // EXTRUDERS > 1
#if EXTRUDERS == 1
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD, &filament_change_load_length[0], 0.0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD, &filament_change_load_length[0], 0, extrude_maxlength);
#else // EXTRUDERS > 1
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD, &filament_change_load_length[active_extruder], 0.0, extrude_maxlength);
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E1, &filament_change_load_length[0], 0.0, extrude_maxlength);
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E2, &filament_change_load_length[1], 0.0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD, &filament_change_load_length[active_extruder], 0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E1, &filament_change_load_length[0], 0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E2, &filament_change_load_length[1], 0, extrude_maxlength);
#if EXTRUDERS > 2
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E3, &filament_change_load_length[2], 0.0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E3, &filament_change_load_length[2], 0, extrude_maxlength);
#if EXTRUDERS > 3
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E4, &filament_change_load_length[3], 0.0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E4, &filament_change_load_length[3], 0, extrude_maxlength);
#if EXTRUDERS > 4
- MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E5, &filament_change_load_length[4], 0.0, extrude_maxlength);
+ MENU_MULTIPLIER_ITEM_EDIT(float3, MSG_FILAMENT_LOAD MSG_DIAM_E5, &filament_change_load_length[4], 0, extrude_maxlength);
#endif // EXTRUDERS > 4
#endif // EXTRUDERS > 3
#endif // EXTRUDERS > 2
@@ -3906,15 +3932,15 @@ void kill_screen(const char* lcd_msg) {
START_MENU();
MENU_BACK(MSG_CONTROL);
MENU_ITEM_EDIT_CALLBACK(bool, MSG_AUTORETRACT, &fwretract.autoretract_enabled, fwretract.refresh_autoretract);
- MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &fwretract.retract_length, 0, 100);
+ MENU_ITEM_EDIT(float52sign, MSG_CONTROL_RETRACT, &fwretract.retract_length, 0, 100);
#if EXTRUDERS > 1
- MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &fwretract.swap_retract_length, 0, 100);
+ MENU_ITEM_EDIT(float52sign, MSG_CONTROL_RETRACT_SWAP, &fwretract.swap_retract_length, 0, 100);
#endif
MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACTF, &fwretract.retract_feedrate_mm_s, 1, 999);
- MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_ZLIFT, &fwretract.retract_zlift, 0, 999);
- MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER, &fwretract.retract_recover_length, -100, 100);
+ MENU_ITEM_EDIT(float52sign, MSG_CONTROL_RETRACT_ZLIFT, &fwretract.retract_zlift, 0, 999);
+ MENU_ITEM_EDIT(float52sign, MSG_CONTROL_RETRACT_RECOVER, &fwretract.retract_recover_length, -100, 100);
#if EXTRUDERS > 1
- MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &fwretract.swap_retract_recover_length, -100, 100);
+ MENU_ITEM_EDIT(float52sign, MSG_CONTROL_RETRACT_RECOVER_SWAP, &fwretract.swap_retract_recover_length, -100, 100);
#endif
MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &fwretract.retract_recover_feedrate_mm_s, 1, 999);
#if EXTRUDERS > 1
@@ -4105,7 +4131,7 @@ void kill_screen(const char* lcd_msg) {
STATIC_ITEM(MSG_INFO_MAX_TEMP ": " STRINGIFY(HEATER_4_MAXTEMP), false);
#endif
- #if TEMP_SENSOR_BED != 0
+ #if HAS_HEATED_BED
#undef THERMISTOR_ID
#define THERMISTOR_ID TEMP_SENSOR_BED
#include "thermistornames.h"
@@ -4229,10 +4255,8 @@ void kill_screen(const char* lcd_msg) {
void lcd_led_menu() {
START_MENU();
MENU_BACK(MSG_MAIN);
- if (leds.lights_on)
- MENU_ITEM(function, MSG_LEDS_OFF, leds.toggle);
- else
- MENU_ITEM(function, MSG_LEDS_ON, leds.toggle);
+ bool led_on = leds.lights_on;
+ MENU_ITEM_EDIT_CALLBACK(bool, MSG_LEDS, &led_on, leds.toggle);
MENU_ITEM(function, MSG_SET_LEDS_DEFAULT, leds.set_default);
#if ENABLED(LED_COLOR_PRESETS)
MENU_ITEM(submenu, MSG_LED_PRESETS, lcd_led_presets_menu);
@@ -4786,17 +4810,16 @@ void kill_screen(const char* lcd_msg) {
if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
if (lcdDrawUpdate) \
- lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale))); \
+ lcd_implementation_drawedit(editLabel, _strFunc(((_type)((int32_t)encoderPosition + minEditValue)) * (1.0f / _scale))); \
if (lcd_clicked || (liveEdit && lcdDrawUpdate)) { \
- _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0 / _scale); \
+ _type value = ((_type)((int32_t)encoderPosition + minEditValue)) * (1.0f / _scale); \
if (editValue != NULL) *((_type*)editValue) = value; \
- if (liveEdit) (*callbackFunc)(); \
+ if (callbackFunc && (liveEdit || lcd_clicked)) (*callbackFunc)(); \
if (lcd_clicked) lcd_goto_previous_menu(); \
} \
return use_click(); \
} \
void menu_edit_ ## _name() { _menu_edit_ ## _name(); } \
- void menu_edit_callback_ ## _name() { if (_menu_edit_ ## _name()) (*callbackFunc)(); } \
void _menu_action_setting_edit_ ## _name(const char * const pstr, _type* const ptr, const _type minValue, const _type maxValue) { \
lcd_save_previous_screen(); \
lcd_refresh(); \
@@ -4807,28 +4830,27 @@ void kill_screen(const char* lcd_msg) {
maxEditValue = maxValue * _scale - minEditValue; \
encoderPosition = (*ptr) * _scale - minEditValue; \
} \
- void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
- _menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
- currentScreen = menu_edit_ ## _name; \
- } \
void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live) { \
_menu_action_setting_edit_ ## _name(pstr, ptr, minValue, maxValue); \
- currentScreen = menu_edit_callback_ ## _name; \
+ currentScreen = menu_edit_ ## _name; \
callbackFunc = callback; \
liveEdit = live; \
} \
- typedef void _name
+ FORCE_INLINE void menu_action_setting_edit_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue) { \
+ menu_action_setting_edit_callback_ ## _name(pstr, ptr, minValue, maxValue); \
+ } \
+ typedef void _name##_void
- DEFINE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01);
DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1);
DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1);
- DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
- DEFINE_MENU_EDIT_TYPE(float, float32, ftostr32, 100.0);
- DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000.0);
- DEFINE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01);
- DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0);
- DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0);
- DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0);
+ DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0f);
+ DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52, 100.0f);
+ DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000.0f);
+ DEFINE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01f);
+ DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0f);
+ DEFINE_MENU_EDIT_TYPE(float, float52sign, ftostr52sign, 100.0f);
+ DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0f);
+ DEFINE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01f);
/**
*
@@ -4902,7 +4924,7 @@ void kill_screen(const char* lcd_msg) {
if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
#endif
- if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
+ if (all_axes_homed()) {
#if ENABLED(DELTA) || Z_HOME_DIR != -1
if (REPRAPWORLD_KEYPAD_MOVE_Z_UP) reprapworld_keypad_move_z_up();
#endif
@@ -5031,7 +5053,7 @@ void lcd_init() {
int16_t lcd_strlen(const char* s) {
int16_t i = 0, j = 0;
while (s[i]) {
- if (PRINTABLE(s[i])) j++;
+ if (START_OF_UTF8_CHAR(s[i])) j++;
i++;
}
return j;
@@ -5040,7 +5062,7 @@ int16_t lcd_strlen(const char* s) {
int16_t lcd_strlen_P(const char* s) {
int16_t j = 0;
while (pgm_read_byte(s)) {
- if (PRINTABLE(pgm_read_byte(s))) j++;
+ if (START_OF_UTF8_CHAR(pgm_read_byte(s))) j++;
s++;
}
return j;
@@ -5131,16 +5153,19 @@ void lcd_update() {
#if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
- const bool sd_status = IS_SD_INSERTED;
+ const uint8_t sd_status = (uint8_t)IS_SD_INSERTED;
if (sd_status != lcd_sd_status && lcd_detected()) {
- bool old_sd_status = lcd_sd_status; // prevent re-entry to this block!
+ uint8_t old_sd_status = lcd_sd_status; // prevent re-entry to this block!
lcd_sd_status = sd_status;
if (sd_status) {
- safe_delay(1000); // some boards need a delay or the LCD won't show the new status
+ safe_delay(500); // Some boards need a delay to get settled
card.initsd();
- if (old_sd_status != 2) LCD_MESSAGEPGM(MSG_SD_INSERTED);
+ if (old_sd_status == 2)
+ card.beginautostart(); // Initial boot
+ else
+ LCD_MESSAGEPGM(MSG_SD_INSERTED);
}
else {
card.release();
@@ -5194,7 +5219,7 @@ void lcd_update() {
#endif
- const bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
+ const bool encoderPastThreshold = (ABS(encoderDiff) >= ENCODER_PULSES_PER_STEP);
if (encoderPastThreshold || lcd_clicked) {
if (encoderPastThreshold) {
int32_t encoderMultiplier = 1;
@@ -5202,12 +5227,12 @@ void lcd_update() {
#if ENABLED(ENCODER_RATE_MULTIPLIER)
if (encoderRateMultiplierEnabled) {
- int32_t encoderMovementSteps = abs(encoderDiff) / ENCODER_PULSES_PER_STEP;
+ int32_t encoderMovementSteps = ABS(encoderDiff) / ENCODER_PULSES_PER_STEP;
if (lastEncoderMovementMillis) {
// Note that the rate is always calculated between two passes through the
// loop and that the abs of the encoderDiff value is tracked.
- float encoderStepRate = float(encoderMovementSteps) / float(ms - lastEncoderMovementMillis) * 1000.0;
+ float encoderStepRate = float(encoderMovementSteps) / float(ms - lastEncoderMovementMillis) * 1000;
if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
@@ -5251,7 +5276,7 @@ void lcd_update() {
lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
}
- #if ENABLED(SCROLL_LONG_FILENAMES)
+ #if ENABLED(ULTIPANEL) && ENABLED(SCROLL_LONG_FILENAMES)
// If scrolling of long file names is enabled and we are in the sd card menu,
// cause a refresh to occur until all the text has scrolled into view.
if (currentScreen == lcd_sdcard_menu && filename_scroll_pos < filename_scroll_max && !lcd_status_update_delay--) {
@@ -5365,30 +5390,8 @@ void lcd_update() {
} // ELAPSED(ms, next_lcd_update_ms)
}
-inline void pad_message_string() {
- uint8_t i = 0, j = 0;
- char c;
- lcd_status_message[MAX_MESSAGE_LENGTH] = '\0';
- while ((c = lcd_status_message[i]) && j < LCD_WIDTH) {
- if (PRINTABLE(c)) j++;
- i++;
- }
- if (true
- #if ENABLED(STATUS_MESSAGE_SCROLLING)
- && j < LCD_WIDTH
- #endif
- ) {
- // pad with spaces to fill up the line
- while (j++ < LCD_WIDTH) lcd_status_message[i++] = ' ';
- // chop off at the edge
- lcd_status_message[i] = '\0';
- }
-}
-
void lcd_finishstatus(const bool persist=false) {
- pad_message_string();
-
#if !(ENABLED(LCD_PROGRESS_BAR) && (PROGRESS_MSG_EXPIRE > 0))
UNUSED(persist);
#endif
@@ -5406,7 +5409,7 @@ void lcd_finishstatus(const bool persist=false) {
#endif
#if ENABLED(STATUS_MESSAGE_SCROLLING)
- status_scroll_pos = 0;
+ status_scroll_offset = 0;
#endif
}
@@ -5418,7 +5421,26 @@ bool lcd_hasstatus() { return (lcd_status_message[0] != '\0'); }
void lcd_setstatus(const char * const message, const bool persist) {
if (lcd_status_message_level > 0) return;
- strncpy(lcd_status_message, message, MAX_MESSAGE_LENGTH);
+
+ // Here we have a problem. The message is encoded in UTF8, so
+ // arbitrarily cutting it will be a problem. We MUST be sure
+ // that there is no cutting in the middle of a multibyte character!
+
+ // Get a pointer to the null terminator
+ const char* pend = message + strlen(message);
+
+ // If length of supplied UTF8 string is greater than
+ // our buffer size, start cutting whole UTF8 chars
+ while ((pend - message) > MAX_MESSAGE_LENGTH) {
+ --pend;
+ while (!START_OF_UTF8_CHAR(*pend)) --pend;
+ };
+
+ // At this point, we have the proper cut point. Use it
+ uint8_t maxLen = pend - message;
+ strncpy(lcd_status_message, message, maxLen);
+ lcd_status_message[maxLen] = '\0';
+
lcd_finishstatus(persist);
}
@@ -5426,7 +5448,26 @@ void lcd_setstatusPGM(const char * const message, int8_t level) {
if (level < 0) level = lcd_status_message_level = 0;
if (level < lcd_status_message_level) return;
lcd_status_message_level = level;
- strncpy_P(lcd_status_message, message, MAX_MESSAGE_LENGTH);
+
+ // Here we have a problem. The message is encoded in UTF8, so
+ // arbitrarily cutting it will be a problem. We MUST be sure
+ // that there is no cutting in the middle of a multibyte character!
+
+ // Get a pointer to the null terminator
+ const char* pend = message + strlen_P(message);
+
+ // If length of supplied UTF8 string is greater than
+ // our buffer size, start cutting whole UTF8 chars
+ while ((pend - message) > MAX_MESSAGE_LENGTH) {
+ --pend;
+ while (!START_OF_UTF8_CHAR(pgm_read_byte(pend))) --pend;
+ };
+
+ // At this point, we have the proper cut point. Use it
+ uint8_t maxLen = pend - message;
+ strncpy_P(lcd_status_message, message, maxLen);
+ lcd_status_message[maxLen] = '\0';
+
lcd_finishstatus(level > 0);
}
@@ -5500,11 +5541,9 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
#if BUTTON_EXISTS(EN1)
if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
#endif
-
#if BUTTON_EXISTS(EN2)
if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
#endif
-
#if BUTTON_EXISTS(ENC)
if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
#endif
diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h
index 5adbf148e7..e03efceba1 100644
--- a/Marlin/ultralcd.h
+++ b/Marlin/ultralcd.h
@@ -41,20 +41,6 @@
#include "Marlin.h"
- #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
- extern bool lcd_external_control;
- #else
- constexpr bool lcd_external_control = false;
- #endif
-
- extern int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
-
- #if ENABLED(LCD_BED_LEVELING)
- extern bool lcd_wait_for_move;
- #else
- constexpr bool lcd_wait_for_move = false;
- #endif
-
int16_t lcd_strlen(const char* s);
int16_t lcd_strlen_P(const char* s);
bool lcd_hasstatus();
@@ -74,6 +60,8 @@
void lcd_buzz(const long duration, const uint16_t freq);
#endif
+ void lcd_quick_feedback(const bool clear_buttons); // Audible feedback for a button click - could also be visual
+
#if ENABLED(LCD_PROGRESS_BAR) && PROGRESS_MSG_EXPIRE > 0
void dontExpireStatus();
#endif
@@ -99,7 +87,7 @@
#define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0)
#define BUTTON_PRESSED(BN) !READ(BTN_## BN)
- #if ENABLED(ULTIPANEL)
+ #if ENABLED(ULTIPANEL) // LCD with a click-wheel input
extern bool defer_return_to_status;
@@ -107,30 +95,22 @@
typedef void (*screenFunc_t)();
typedef void (*menuAction_t)();
+ extern int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
+
+ #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
+ extern bool lcd_external_control;
+ #else
+ constexpr bool lcd_external_control = false;
+ #endif
+
+ #if ENABLED(LCD_BED_LEVELING)
+ extern bool lcd_wait_for_move;
+ #else
+ constexpr bool lcd_wait_for_move = false;
+ #endif
+
void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder=0);
- // Encoder click is directly connected
-
- #define BLEN_A 0
- #define BLEN_B 1
-
- #define EN_A (_BV(BLEN_A))
- #define EN_B (_BV(BLEN_B))
-
- #if BUTTON_EXISTS(ENC)
- #define BLEN_C 2
- #define EN_C (_BV(BLEN_C))
- #endif
-
- #if BUTTON_EXISTS(BACK)
- #define BLEN_D 3
- #define EN_D _BV(BLEN_D)
- #define LCD_BACK_CLICKED (buttons & EN_D)
- #endif
-
- extern volatile uint8_t buttons; // The last-checked buttons in a bit array.
- void lcd_buttons_update();
- void lcd_quick_feedback(const bool clear_buttons); // Audible feedback for a button click - could also be visual
void lcd_completion_feedback(const bool good=true);
#if ENABLED(ADVANCED_PAUSE_FEATURE)
@@ -138,7 +118,7 @@
void lcd_advanced_pause_show_message(const AdvancedPauseMessage message,
const AdvancedPauseMode mode=ADVANCED_PAUSE_MODE_PAUSE_PRINT,
const uint8_t extruder=active_extruder);
- #endif // ADVANCED_PAUSE_FEATURE
+ #endif
#if ENABLED(G26_MESH_VALIDATION)
void lcd_chirp();
@@ -151,10 +131,6 @@
float lcd_z_offset_edit();
#endif
- #else
-
- inline void lcd_buttons_update() {}
-
#endif
#if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
@@ -202,12 +178,6 @@
#define REPRAPWORLD_KEYPAD_MOVE_HOME (buttons_reprapworld_keypad & KEYPAD_HOME)
#define REPRAPWORLD_KEYPAD_MOVE_MENU (buttons_reprapworld_keypad & KEYPAD_EN_C)
- #if BUTTON_EXISTS(ENC)
- #define LCD_CLICKED ((buttons & EN_C) || REPRAPWORLD_KEYPAD_MOVE_MENU)
- #else
- #define LCD_CLICKED REPRAPWORLD_KEYPAD_MOVE_MENU
- #endif
-
#define REPRAPWORLD_KEYPAD_PRESSED (buttons_reprapworld_keypad & ( \
EN_REPRAPWORLD_KEYPAD_F3 | \
EN_REPRAPWORLD_KEYPAD_F2 | \
@@ -219,14 +189,6 @@
EN_REPRAPWORLD_KEYPAD_LEFT) \
)
- #elif ENABLED(NEWPANEL)
-
- #define LCD_CLICKED (buttons & EN_C)
-
- #else
-
- #define LCD_CLICKED false
-
#endif
#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
@@ -239,7 +201,6 @@
constexpr bool lcd_wait_for_move = false;
inline void lcd_refresh() {}
- inline void lcd_buttons_update() {}
inline bool lcd_hasstatus() { return false; }
inline void lcd_setstatus(const char* const message, const bool persist=false) { UNUSED(message); UNUSED(persist); }
inline void lcd_setstatusPGM(const char* const message, const int8_t level=0) { UNUSED(message); UNUSED(level); }
@@ -249,6 +210,51 @@
#endif // ULTRA_LCD
+#if ENABLED(ULTIPANEL)
+
+ #if ENABLED(NEWPANEL) // Uses digital switches, not a shift register
+
+ // Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
+ #define BLEN_A 0
+ #define BLEN_B 1
+
+ #define EN_A _BV(BLEN_A)
+ #define EN_B _BV(BLEN_B)
+
+ #if BUTTON_EXISTS(ENC)
+ #define BLEN_C 2
+ #define EN_C _BV(BLEN_C)
+ #endif
+
+ #if BUTTON_EXISTS(BACK)
+ #define BLEN_D 3
+ #define EN_D _BV(BLEN_D)
+ #define LCD_BACK_CLICKED (buttons & EN_D)
+ #endif
+
+ #endif // NEWPANEL
+
+ extern volatile uint8_t buttons; // The last-checked buttons in a bit array.
+ void lcd_buttons_update();
+
+#else
+
+ inline void lcd_buttons_update() {}
+
+#endif
+
+#if ENABLED(REPRAPWORLD_KEYPAD)
+ #ifdef EN_C
+ #define LCD_CLICKED ((buttons & EN_C) || REPRAPWORLD_KEYPAD_MOVE_MENU)
+ #else
+ #define LCD_CLICKED REPRAPWORLD_KEYPAD_MOVE_MENU
+ #endif
+#elif defined(EN_C)
+ #define LCD_CLICKED (buttons & EN_C)
+#else
+ #define LCD_CLICKED false
+#endif
+
#define LCD_MESSAGEPGM(x) lcd_setstatusPGM(PSTR(x))
#define LCD_ALERTMESSAGEPGM(x) lcd_setalertstatusPGM(PSTR(x))
diff --git a/Marlin/ultralcd_impl_DOGM.h b/Marlin/ultralcd_impl_DOGM.h
index 0094b2da53..c5fd1999cb 100644
--- a/Marlin/ultralcd_impl_DOGM.h
+++ b/Marlin/ultralcd_impl_DOGM.h
@@ -33,31 +33,23 @@
* License: http://opensource.org/licenses/BSD-3-Clause
*/
+/**
+ * Implementation of the LCD display routines for a DOGM128 graphic display.
+ * These are common LCD 128x64 pixel graphic displays.
+ */
+
#ifndef ULTRALCD_IMPL_DOGM_H
#define ULTRALCD_IMPL_DOGM_H
#include "MarlinConfig.h"
-/**
- * Implementation of the LCD display routines for a DOGM128 graphic display.
- * These are common LCD 128x64 pixel graphic displays.
- */
+#include
+
#include "ultralcd.h"
-
-#if ENABLED(U8GLIB_ST7920)
- #include "ultralcd_st7920_u8glib_rrd.h"
-#endif
-
-#if ENABLED(U8GLIB_ST7565_64128N)
- #include "ultralcd_st7565_u8glib_VIKI.h"
-#endif
-
#include "dogm_bitmaps.h"
#include "utility.h"
#include "duration_t.h"
-#include
-
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "ubl.h"
#endif
@@ -68,6 +60,14 @@
#undef USE_SMALL_INFOFONT
#endif
+#if ENABLED(U8GLIB_ST7920)
+ #include "ultralcd_st7920_u8glib_rrd.h"
+#endif
+
+#if ENABLED(U8GLIB_ST7565_64128N)
+ #include "ultralcd_st7565_u8glib_VIKI.h"
+#endif
+
#if ENABLED(USE_SMALL_INFOFONT)
#include "dogm_font_data_6x9_marlin.h"
#define FONT_STATUSMENU_NAME u8g_font_6x9
@@ -603,7 +603,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor
if (filename_scroll_hash != name_hash) { // If the hash changed...
filename_scroll_hash = name_hash; // Save the new hash
- filename_scroll_max = max(0, lcd_strlen(longFilename) - maxlen); // Update the scroll limit
+ filename_scroll_max = MAX(0, lcd_strlen(longFilename) - maxlen); // Update the scroll limit
filename_scroll_pos = 0; // Reset scroll to the start
lcd_status_update_delay = 8; // Don't scroll right away
}
@@ -691,10 +691,10 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
if (PAGE_UNDER(7)) {
u8g.setPrintPos(5, 7);
lcd_print("X:");
- lcd_print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
+ lcd_print(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
u8g.setPrintPos(74, 7);
lcd_print("Y:");
- lcd_print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
+ lcd_print(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
}
// Print plot position
diff --git a/Marlin/ultralcd_impl_HD44780.h b/Marlin/ultralcd_impl_HD44780.h
index ac40d643cf..e2be71332b 100644
--- a/Marlin/ultralcd_impl_HD44780.h
+++ b/Marlin/ultralcd_impl_HD44780.h
@@ -67,19 +67,19 @@ extern volatile uint8_t buttons; //an extended version of the last checked butt
#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'
- #define B_LE (BUTTON_LEFT< '???'.
+// Homed but unknown... '123' <-> ' '.
+// Homed and known, display constantly.
+//
+FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
+ lcd_print('X' + uint8_t(axis));
if (blink)
- lcd_printPGM(pstr);
+ lcd.print(value);
else {
- if (!axis_homed[axis])
- lcd.write('?');
+ if (!TEST(axis_homed, axis))
+ while (const char c = *value++) lcd_print(c <= '.' ? c : '?');
else {
#if DISABLED(HOME_AFTER_DEACTIVATE) && DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
- if (!axis_known_position[axis])
- lcd.write(' ');
+ if (!TEST(axis_known_position, axis))
+ lcd_printPGM(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
else
#endif
- lcd_printPGM(pstr);
+ lcd.print(value);
}
}
}
@@ -719,7 +752,7 @@ static void lcd_implementation_status_screen() {
//
// Hotend 1 or Bed Temperature
//
- #if HOTENDS > 1 || TEMP_SENSOR_BED
+ #if HOTENDS > 1 || HAS_HEATED_BED
lcd.setCursor(8, 0);
#if HOTENDS > 1
@@ -730,7 +763,7 @@ static void lcd_implementation_status_screen() {
_draw_heater_status(-1, -1, blink);
#endif
- #endif // HOTENDS > 1 || TEMP_SENSOR_BED
+ #endif // HOTENDS > 1 || HAS_HEATED_BED
#else // LCD_WIDTH >= 20
@@ -742,7 +775,7 @@ static void lcd_implementation_status_screen() {
//
// Hotend 1 or Bed Temperature
//
- #if HOTENDS > 1 || TEMP_SENSOR_BED
+ #if HOTENDS > 1 || HAS_HEATED_BED
lcd.setCursor(10, 0);
#if HOTENDS > 1
_draw_heater_status(1, LCD_STR_THERMOMETER[0], blink);
@@ -755,7 +788,7 @@ static void lcd_implementation_status_screen() {
), blink);
#endif
- #endif // HOTENDS > 1 || TEMP_SENSOR_BED != 0
+ #endif // HOTENDS > 1 || HAS_HEATED_BED
#endif // LCD_WIDTH >= 20
@@ -784,7 +817,7 @@ static void lcd_implementation_status_screen() {
// If the first line has two extruder temps,
// show more temperatures on the next line
- #if HOTENDS > 2 || (HOTENDS > 1 && TEMP_SENSOR_BED)
+ #if HOTENDS > 2 || (HOTENDS > 1 && HAS_HEATED_BED)
#if HOTENDS > 2
_draw_heater_status(2, LCD_STR_THERMOMETER[0], blink);
@@ -798,28 +831,22 @@ static void lcd_implementation_status_screen() {
LCD_BEDTEMP_CHAR
), blink);
- #else // HOTENDS <= 2 && (HOTENDS <= 1 || !TEMP_SENSOR_BED)
- // Before homing the axis letters are blinking 'X' <-> '?'.
- // When axis is homed but axis_known_position is false the axis letters are blinking 'X' <-> ' '.
- // When everything is ok you see a constant 'X'.
+ #else // HOTENDS <= 2 && (HOTENDS <= 1 || !HAS_HEATED_BED)
- _draw_axis_label(X_AXIS, PSTR(MSG_X), blink);
- lcd.print(ftostr4sign(LOGICAL_X_POSITION(current_position[X_AXIS])));
+ _draw_axis_value(X_AXIS, ftostr4sign(LOGICAL_X_POSITION(current_position[X_AXIS])), blink);
lcd.write(' ');
- _draw_axis_label(Y_AXIS, PSTR(MSG_Y), blink);
- lcd.print(ftostr4sign(LOGICAL_Y_POSITION(current_position[Y_AXIS])));
+ _draw_axis_value(Y_AXIS, ftostr4sign(LOGICAL_Y_POSITION(current_position[Y_AXIS])), blink);
- #endif // HOTENDS <= 2 && (HOTENDS <= 1 || !TEMP_SENSOR_BED)
+ #endif // HOTENDS <= 2 && (HOTENDS <= 1 || !HAS_HEATED_BED)
#endif // LCD_WIDTH >= 20
lcd.setCursor(LCD_WIDTH - 8, 1);
- _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
- lcd.print(ftostr52sp(FIXFLOAT(LOGICAL_Z_POSITION(current_position[Z_AXIS]))));
+ _draw_axis_value(Z_AXIS, ftostr52sp(LOGICAL_Z_POSITION(current_position[Z_AXIS])), blink);
- #if HAS_LEVELING && !TEMP_SENSOR_BED
+ #if HAS_LEVELING && !HAS_HEATED_BED
lcd.write(planner.leveling_active || blink ? '_' : ' ');
#endif
@@ -897,38 +924,82 @@ static void lcd_implementation_status_screen() {
#if ENABLED(STATUS_MESSAGE_SCROLLING)
static bool last_blink = false;
- const uint8_t slen = lcd_strlen(lcd_status_message);
- const char *stat = lcd_status_message + status_scroll_pos;
- if (slen <= LCD_WIDTH)
- lcd_print_utf(stat); // The string isn't scrolling
+
+ // Get the UTF8 character count of the string
+ uint8_t slen = lcd_strlen(lcd_status_message);
+
+ // If the string fits into the LCD, just print it and do not scroll it
+ if (slen <= LCD_WIDTH) {
+
+ // The string isn't scrolling and may not fill the screen
+ lcd_print_utf(lcd_status_message);
+
+ // Fill the rest with spaces
+ while (slen < LCD_WIDTH) {
+ lcd.write(' ');
+ ++slen;
+ }
+ }
else {
- if (status_scroll_pos <= slen - LCD_WIDTH)
- lcd_print_utf(stat); // The string fills the screen
+ // String is larger than the available space in screen.
+
+ // Get a pointer to the next valid UTF8 character
+ const char *stat = lcd_status_message + status_scroll_offset;
+
+ // Get the string remaining length
+ const uint8_t rlen = lcd_strlen(stat);
+
+ // If we have enough characters to display
+ if (rlen >= LCD_WIDTH) {
+ // The remaining string fills the screen - Print it
+ lcd_print_utf(stat, LCD_WIDTH);
+ }
else {
- uint8_t chars = LCD_WIDTH;
- if (status_scroll_pos < slen) { // First string still visible
- lcd_print_utf(stat); // The string leaves space
- chars -= slen - status_scroll_pos; // Amount of space left
- }
- lcd.write('.'); // Always at 1+ spaces left, draw a dot
- if (--chars) {
- if (status_scroll_pos < slen + 1) // Draw a second dot if there's space
- --chars, lcd.write('.');
- if (chars) lcd_print_utf(lcd_status_message, chars); // Print a second copy of the message
+
+ // The remaining string does not completely fill the screen
+ lcd_print_utf(stat, LCD_WIDTH); // The string leaves space
+ uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters
+
+ lcd.write('.'); // Always at 1+ spaces left, draw a dot
+ if (--chars) { // Draw a second dot if there's space
+ lcd.write('.');
+ if (--chars)
+ lcd_print_utf(lcd_status_message, chars); // Print a second copy of the message
}
}
if (last_blink != blink) {
last_blink = blink;
- // Skip any non-printing bytes
- if (status_scroll_pos < slen) while (!PRINTABLE(lcd_status_message[status_scroll_pos])) status_scroll_pos++;
- if (++status_scroll_pos >= slen + 2) status_scroll_pos = 0;
+
+ // Adjust by complete UTF8 characters
+ if (status_scroll_offset < slen) {
+ status_scroll_offset++;
+ while (!START_OF_UTF8_CHAR(lcd_status_message[status_scroll_offset]))
+ status_scroll_offset++;
+ }
+ else
+ status_scroll_offset = 0;
}
}
#else
- lcd_print_utf(lcd_status_message);
+ UNUSED(blink);
+
+ // Get the UTF8 character count of the string
+ uint8_t slen = lcd_strlen(lcd_status_message);
+
+ // Just print the string to the LCD
+ lcd_print_utf(lcd_status_message, LCD_WIDTH);
+
+ // Fill the rest with spaces if there are missing spaces
+ while (slen < LCD_WIDTH) {
+ lcd.write(' ');
+ ++slen;
+ }
#endif
+
}
+
+
#if ENABLED(ULTIPANEL)
#if ENABLED(ADVANCED_PAUSE_FEATURE)
@@ -1034,7 +1105,7 @@ static void lcd_implementation_status_screen() {
name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor
if (filename_scroll_hash != name_hash) { // If the hash changed...
filename_scroll_hash = name_hash; // Save the new hash
- filename_scroll_max = max(0, lcd_strlen(longFilename) - n); // Update the scroll limit
+ filename_scroll_max = MAX(0, lcd_strlen(longFilename) - n); // Update the scroll limit
filename_scroll_pos = 0; // Reset scroll to the start
lcd_status_update_delay = 8; // Don't scroll right away
}
@@ -1226,10 +1297,10 @@ static void lcd_implementation_status_screen() {
* Show X and Y positions
*/
_XLABEL(_PLOT_X, 0);
- lcd.print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
+ lcd.print(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
_YLABEL(_LCD_W_POS, 0);
- lcd.print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
+ lcd.print(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
lcd.setCursor(_PLOT_X, 0);
@@ -1347,7 +1418,7 @@ static void lcd_implementation_status_screen() {
//dump_custom_char("at entry:", &new_char);
clear_custom_char(&new_char);
- const uint8_t ypix = min(upper_left.y_pixel_offset + pixels_per_y_mesh_pnt, ULTRA_Y_PIXELS_PER_CHAR);
+ const uint8_t ypix = MIN(upper_left.y_pixel_offset + pixels_per_y_mesh_pnt, ULTRA_Y_PIXELS_PER_CHAR);
for (j = upper_left.y_pixel_offset; j < ypix; j++) {
i = upper_left.x_pixel_mask;
for (k = 0; k < pixels_per_x_mesh_pnt; k++) {
@@ -1462,9 +1533,9 @@ static void lcd_implementation_status_screen() {
* Show all values at right of screen
*/
_XLABEL(_LCD_W_POS, 1);
- lcd.print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
+ lcd.print(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
_YLABEL(_LCD_W_POS, 2);
- lcd.print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
+ lcd.print(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
/**
* Show the location value
diff --git a/Marlin/ultralcd_st7565_u8glib_VIKI.h b/Marlin/ultralcd_st7565_u8glib_VIKI.h
index 7f589e2ecf..9ab142b2e8 100644
--- a/Marlin/ultralcd_st7565_u8glib_VIKI.h
+++ b/Marlin/ultralcd_st7565_u8glib_VIKI.h
@@ -24,6 +24,7 @@
#define ULCDST7565_H
#include
+#include "delay.h"
#define ST7565_CLK_PIN DOGLCD_SCK
#define ST7565_DAT_PIN DOGLCD_MOSI
@@ -38,9 +39,9 @@
#pragma GCC optimize (3)
// If you want you can define your own set of delays in Configuration.h
-//#define ST7565_DELAY_1 DELAY_0_NOP
-//#define ST7565_DELAY_2 DELAY_0_NOP
-//#define ST7565_DELAY_3 DELAY_0_NOP
+//#define ST7565_DELAY_1 DELAY_NS(0)
+//#define ST7565_DELAY_2 DELAY_NS(0)
+//#define ST7565_DELAY_3 DELAY_NS(0)
/*
#define ST7565_DELAY_1 u8g_10MicroDelay()
@@ -49,25 +50,25 @@
*/
#if F_CPU >= 20000000
- #define CPU_ST7565_DELAY_1 DELAY_0_NOP
- #define CPU_ST7565_DELAY_2 DELAY_0_NOP
- #define CPU_ST7565_DELAY_3 DELAY_1_NOP
+ #define CPU_ST7565_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7565_DELAY_2 DELAY_NS(0)
+ #define CPU_ST7565_DELAY_3 DELAY_NS(63)
#elif MB(3DRAG) || MB(K8200) || MB(K8400)
- #define CPU_ST7565_DELAY_1 DELAY_0_NOP
- #define CPU_ST7565_DELAY_2 DELAY_3_NOP
- #define CPU_ST7565_DELAY_3 DELAY_0_NOP
+ #define CPU_ST7565_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7565_DELAY_2 DELAY_NS(188)
+ #define CPU_ST7565_DELAY_3 DELAY_NS(0)
#elif MB(MINIRAMBO)
- #define CPU_ST7565_DELAY_1 DELAY_0_NOP
- #define CPU_ST7565_DELAY_2 DELAY_4_NOP
- #define CPU_ST7565_DELAY_3 DELAY_0_NOP
+ #define CPU_ST7565_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7565_DELAY_2 DELAY_NS(250)
+ #define CPU_ST7565_DELAY_3 DELAY_NS(0)
#elif MB(RAMBO)
- #define CPU_ST7565_DELAY_1 DELAY_0_NOP
- #define CPU_ST7565_DELAY_2 DELAY_0_NOP
- #define CPU_ST7565_DELAY_3 DELAY_0_NOP
+ #define CPU_ST7565_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7565_DELAY_2 DELAY_NS(0)
+ #define CPU_ST7565_DELAY_3 DELAY_NS(0)
#elif F_CPU == 16000000
- #define CPU_ST7565_DELAY_1 DELAY_0_NOP
- #define CPU_ST7565_DELAY_2 DELAY_0_NOP
- #define CPU_ST7565_DELAY_3 DELAY_1_NOP
+ #define CPU_ST7565_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7565_DELAY_2 DELAY_NS(0)
+ #define CPU_ST7565_DELAY_3 DELAY_NS(63)
#else
#error "No valid condition for delays in 'ultralcd_st7565_u8glib_VIKI.h'"
#endif
@@ -115,16 +116,32 @@
#endif // !HARDWARE_SPI
-#if defined(DOGM_SPI_DELAY_US) && DOGM_SPI_DELAY_US > 0
- #define U8G_DELAY() delayMicroseconds(DOGM_SPI_DELAY_US)
+#if DOGM_SPI_DELAY_US > 0
+ #define U8G_DELAY() DELAY_US(DOGM_SPI_DELAY_US)
#else
#define U8G_DELAY() u8g_10MicroDelay()
#endif
-#define ST7565_CS() { WRITE(ST7565_CS_PIN,1); U8G_DELAY(); }
-#define ST7565_NCS() { WRITE(ST7565_CS_PIN,0); }
-#define ST7565_A0() { WRITE(ST7565_A0_PIN,1); U8G_DELAY(); }
-#define ST7565_NA0() { WRITE(ST7565_A0_PIN,0); }
+#define ST7565_CS() do{ WRITE(ST7565_CS_PIN, HIGH); U8G_DELAY(); }while(0)
+#define ST7565_NCS() WRITE(ST7565_CS_PIN, LOW)
+#define ST7565_A0() do{ WRITE(ST7565_A0_PIN, HIGH); U8G_DELAY(); }while(0)
+#define ST7565_NA0() WRITE(ST7565_A0_PIN, LOW)
+
+#define ST7565_ADC_REVERSE(N) ST7565_WRITE_BYTE(0xA0 | ((N) & 0x1))
+#define ST7565_BIAS_MODE(N) ST7565_WRITE_BYTE(0xA2 | ((N) & 0x1))
+#define ST7565_ALL_PIX(N) ST7565_WRITE_BYTE(0xA4 | ((N) & 0x1))
+#define ST7565_INVERTED(N) ST7565_WRITE_BYTE(0xA6 | ((N) & 0x1))
+#define ST7565_ON(N) ST7565_WRITE_BYTE(0xAE | ((N) & 0x1))
+#define ST7565_OUT_MODE(N) ST7565_WRITE_BYTE(0xC0 | ((N) & 0x1) << 3)
+#define ST7565_POWER_CONTROL(N) ST7565_WRITE_BYTE(0x28 | (N))
+#define ST7565_V0_RATIO(N) ST7565_WRITE_BYTE(0x10 | ((N) & 0x7)) // Specific to Displaytech 64128N? (ST7565 is 0x20 | N)
+#define ST7565_CONTRAST(N) do{ ST7565_WRITE_BYTE(0x81); ST7565_WRITE_BYTE(N); }while(0)
+
+#define ST7565_COLUMN_ADR(N) do{ ST7565_WRITE_BYTE(0x10 | (((N) >> 4) & 0xF)); ST7565_WRITE_BYTE((N) & 0xF); }while(0)
+#define ST7565_PAGE_ADR(N) ST7565_WRITE_BYTE(0xB0 | (N))
+#define ST7565_START_LINE(N) ST7565_WRITE_BYTE(0x40 | (N))
+#define ST7565_SLEEP_MODE() ST7565_WRITE_BYTE(0xAC)
+#define ST7565_NOOP() ST7565_WRITE_BYTE(0xE3)
uint8_t u8g_dev_st7565_64128n_2x_VIKI_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
switch (msg) {
@@ -136,109 +153,103 @@ uint8_t u8g_dev_st7565_64128n_2x_VIKI_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg
OUT_WRITE(ST7565_CLK_PIN, LOW);
#if HARDWARE_SPI
- OUT_WRITE(SDSS, 1); // must be set to an output first or else will never go into master mode
- SPCR = 0x50; // enable SPI in master mode at fast speed
- SPSR = 1; // kick it up to 2x speed mode
+ OUT_WRITE(SDSS, 1); // must be set to an output first or else will never go into master mode
+ SPCR = 0x50; // enable SPI in master mode at fast speed
+ SPSR = 1; // kick it up to 2x speed mode
#endif
OUT_WRITE(ST7565_A0_PIN, LOW);
- ST7565_CS(); /* disable chip */
- ST7565_NA0(); /* instruction mode */
- ST7565_NCS(); /* enable chip */
+ ST7565_CS(); // chip select off
+ ST7565_NA0(); // instruction mode
+ ST7565_NCS(); // chip select
- ST7565_WRITE_BYTE(0x0A2); /* 0x0A2: LCD bias 1/9 (according to Displaytech 64128N datasheet) */
- ST7565_WRITE_BYTE(0x0A0); /* Normal ADC Select (according to Displaytech 64128N datasheet) */
+ ST7565_BIAS_MODE(0); // 0xA2: LCD bias 1/9 (according to Displaytech 64128N datasheet)
+ ST7565_ADC_REVERSE(0); // Normal (not flipped) ADC Select (according to Displaytech 64128N datasheet)
- ST7565_WRITE_BYTE(0x0C8); /* common output mode: set scan direction normal operation/SHL Select; 0x0C0 --> SHL = 0; normal; 0x0C8 --> SHL = 1 */
- ST7565_WRITE_BYTE(0x040); /* Display start line for Displaytech 64128N */
+ ST7565_OUT_MODE(1); // common output mode: set scan direction normal operation/SHL Select; 0x0C0 --> SHL = 0; normal; 0x0C8 --> SHL = 1
+ ST7565_START_LINE(0); // Display start line for Displaytech 64128N
- ST7565_WRITE_BYTE(0x028 | 0x04); /* power control: turn on voltage converter */
- //U8G_ESC_DLY(50); /* delay 50 ms - hangs after a reset if used */
+ ST7565_POWER_CONTROL(0x4); // power control: turn on Booster
+ U8G_ESC_DLY(50); // delay 50 ms - hangs after a reset if used
- ST7565_WRITE_BYTE(0x028 | 0x06); /* power control: turn on voltage regulator */
- //U8G_ESC_DLY(50); /* delay 50 ms - hangs after a reset if used */
+ ST7565_POWER_CONTROL(0x6); // power control: turn on Booster, Voltage Regulator
+ U8G_ESC_DLY(50); // delay 50 ms - hangs after a reset if used
- ST7565_WRITE_BYTE(0x028 | 0x07); /* power control: turn on voltage follower */
- //U8G_ESC_DLY(50); /* delay 50 ms - hangs after a reset if used */
+ ST7565_POWER_CONTROL(0x7); // power control: turn on Booster, Voltage Regulator, Voltage Follower
+ U8G_ESC_DLY(50); // delay 50 ms - hangs after a reset if used
- ST7565_WRITE_BYTE(0x010); /* Set V0 voltage resistor ratio. Setting for controlling brightness of Displaytech 64128N */
+ ST7565_V0_RATIO(0); // Set V0 Voltage Resistor ratio. Setting for controlling brightness of Displaytech 64128N
- ST7565_WRITE_BYTE(0x0A6); /* display normal, bit val 0: LCD pixel off. */
+ ST7565_INVERTED(0); // display normal, bit val 0: LCD pixel off.
- ST7565_WRITE_BYTE(0x081); /* set contrast */
- ST7565_WRITE_BYTE(0x01E); /* Contrast value. Setting for controlling brightness of Displaytech 64128N */
+ ST7565_CONTRAST(0x1E); // Contrast value. Setting for controlling contrast of Displaytech 64128N
- ST7565_WRITE_BYTE(0x0AF); /* display on */
+ ST7565_ON(1); // display on
- U8G_ESC_DLY(100); /* delay 100 ms */
- ST7565_WRITE_BYTE(0x0A5); /* display all points; ST7565 */
- U8G_ESC_DLY(100); /* delay 100 ms */
- U8G_ESC_DLY(100); /* delay 100 ms */
- ST7565_WRITE_BYTE(0x0A4); /* normal display */
- ST7565_CS(); /* disable chip */
- } /* end of sequence */
+ U8G_ESC_DLY(100); // delay 100 ms
+ ST7565_ALL_PIX(1); // display all points; ST7565
+ U8G_ESC_DLY(100); // delay 100 ms
+ U8G_ESC_DLY(100); // delay 100 ms
+ ST7565_ALL_PIX(0); // normal display
+ ST7565_CS(); // chip select off
+ } // end of sequence
break;
case U8G_DEV_MSG_STOP: break;
case U8G_DEV_MSG_PAGE_NEXT: {
- u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
- ST7565_CS(); /* disable chip */
- ST7565_NA0(); /* instruction mode */
- ST7565_NCS(); /* enable chip */
- ST7565_WRITE_BYTE(0x010); /* set upper 4 bit of the col adr to 0x10 */
- ST7565_WRITE_BYTE(0x000); /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
- /* end of sequence */
- ST7565_WRITE_BYTE(0x0B0 | (2*pb->p.page));; /* select current page (ST7565R) */
- ST7565_A0(); /* data mode */
- ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)pb->buf);
- ST7565_CS(); /* disable chip */
- ST7565_NA0(); /* instruction mode */
- ST7565_NCS(); /* enable chip */
- ST7565_WRITE_BYTE(0x010); /* set upper 4 bit of the col adr to 0x10 */
- ST7565_WRITE_BYTE(0x000); /* set lower 4 bit of the col adr to 0x00. Changed for DisplayTech 64128N */
- /* end of sequence */
- ST7565_WRITE_BYTE(0x0B0 | (2*pb->p.page+1)); /* select current page (ST7565R) */
- ST7565_A0(); /* data mode */
- ST7560_WriteSequence( (uint8_t) pb->width, (uint8_t *)(pb->buf)+pb->width);
- ST7565_CS(); /* disable chip */
+ u8g_pb_t *pb = (u8g_pb_t*)(dev->dev_mem);
+ ST7565_CS(); // chip select off
+ ST7565_NA0(); // instruction mode
+ ST7565_NCS(); // chip select
+ ST7565_COLUMN_ADR(0x00); // high 4 bits to 0, low 4 bits to 0. Changed for DisplayTech 64128N
+ // end of sequence
+ ST7565_PAGE_ADR(2 * pb->p.page); // select current page (ST7565R)
+ ST7565_A0(); // data mode
+ ST7560_WriteSequence((uint8_t)pb->width, (uint8_t*)pb->buf);
+ ST7565_CS(); // chip select off
+ ST7565_NA0(); // instruction mode
+ ST7565_NCS(); // chip select
+ ST7565_COLUMN_ADR(0x00); // high 4 bits to 0, low 4 bits to 0
+ // end of sequence
+ ST7565_PAGE_ADR(2 * pb->p.page + 1); // select current page (ST7565R)
+ ST7565_A0(); // data mode
+ ST7560_WriteSequence((uint8_t)pb->width, (uint8_t*)(pb->buf) + pb->width);
+ ST7565_CS(); // chip select off
}
break;
case U8G_DEV_MSG_CONTRAST:
ST7565_NCS();
- ST7565_NA0(); /* instruction mode */
- ST7565_WRITE_BYTE(0x081);
- ST7565_WRITE_BYTE((*(uint8_t *)arg) >> 2);
- ST7565_CS(); /* disable chip */
+ ST7565_NA0(); // instruction mode
+ ST7565_CONTRAST((*(uint8_t*)arg) >> 2);
+ ST7565_CS(); // chip select off
return 1;
case U8G_DEV_MSG_SLEEP_ON:
- ST7565_NA0(); /* instruction mode */
- ST7565_NCS(); /* enable chip */
- ST7565_WRITE_BYTE(0x0AC); /* static indicator off */
- ST7565_WRITE_BYTE(0x000); /* indicator register set (not sure if this is required) */
- ST7565_WRITE_BYTE(0x0AE); /* display off */
- ST7565_WRITE_BYTE(0x0A5); /* all points on */
- ST7565_CS(); /* disable chip , bugfix 12 nov 2014 */
- /* end of sequence */
+ ST7565_NA0(); // instruction mode
+ ST7565_NCS(); // chip select
+ ST7565_SLEEP_MODE(); // static indicator off
+ //ST7565_WRITE_BYTE(0x00); // indicator register set (not sure if this is required)
+ ST7565_ON(0); // display off
+ ST7565_ALL_PIX(1); // all points on
+ ST7565_CS(); // chip select off
return 1;
case U8G_DEV_MSG_SLEEP_OFF:
- ST7565_NA0(); /* instruction mode */
- ST7565_NCS(); /* enable chip */
- ST7565_WRITE_BYTE(0x0A4); /* all points off */
- ST7565_WRITE_BYTE(0x0AF); /* display on */
- U8G_ESC_DLY(50); /* delay 50 ms */
- ST7565_CS(); /* disable chip , bugfix 12 nov 2014 */
- /* end of sequence */
+ ST7565_NA0(); // instruction mode
+ ST7565_NCS(); // chip select
+ ST7565_ALL_PIX(0); // all points off
+ ST7565_ON(1); // display on
+ U8G_ESC_DLY(50); // delay 50 ms
+ ST7565_CS(); // chip select off
return 1;
}
return u8g_dev_pb16v1_base_fn(u8g, dev, msg, arg);
}
-uint8_t u8g_dev_st7565_64128n_2x_VIKI_buf[LCD_PIXEL_WIDTH*2] U8G_NOCOMMON;
+uint8_t u8g_dev_st7565_64128n_2x_VIKI_buf[LCD_PIXEL_WIDTH * 2] U8G_NOCOMMON;
u8g_pb_t u8g_dev_st7565_64128n_2x_VIKI_pb = {{16, LCD_PIXEL_HEIGHT, 0, 0, 0}, LCD_PIXEL_WIDTH, u8g_dev_st7565_64128n_2x_VIKI_buf};
u8g_dev_t u8g_dev_st7565_64128n_2x_VIKI_sw_spi = {u8g_dev_st7565_64128n_2x_VIKI_fn, &u8g_dev_st7565_64128n_2x_VIKI_pb, &u8g_com_null_fn};
diff --git a/Marlin/ultralcd_st7920_u8glib_rrd.h b/Marlin/ultralcd_st7920_u8glib_rrd.h
index 3b379726f2..db6224e478 100644
--- a/Marlin/ultralcd_st7920_u8glib_rrd.h
+++ b/Marlin/ultralcd_st7920_u8glib_rrd.h
@@ -24,6 +24,7 @@
#define ULCDST7920_H
#include
+#include "delay.h"
#define ST7920_CLK_PIN LCD_PINS_D4
#define ST7920_DAT_PIN LCD_PINS_ENABLE
@@ -40,30 +41,34 @@
#pragma GCC optimize (3)
// If you want you can define your own set of delays in Configuration.h
-//#define ST7920_DELAY_1 DELAY_0_NOP
-//#define ST7920_DELAY_2 DELAY_0_NOP
-//#define ST7920_DELAY_3 DELAY_0_NOP
+//#define ST7920_DELAY_1 DELAY_NS(0)
+//#define ST7920_DELAY_2 DELAY_NS(0)
+//#define ST7920_DELAY_3 DELAY_NS(0)
#if F_CPU >= 20000000
- #define CPU_ST7920_DELAY_1 DELAY_0_NOP
- #define CPU_ST7920_DELAY_2 DELAY_0_NOP
- #define CPU_ST7920_DELAY_3 DELAY_1_NOP
+ #define CPU_ST7920_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7920_DELAY_2 DELAY_NS(0)
+ #define CPU_ST7920_DELAY_3 DELAY_NS(50)
#elif MB(3DRAG) || MB(K8200) || MB(K8400) || MB(SILVER_GATE)
- #define CPU_ST7920_DELAY_1 DELAY_0_NOP
- #define CPU_ST7920_DELAY_2 DELAY_3_NOP
- #define CPU_ST7920_DELAY_3 DELAY_0_NOP
+ #define CPU_ST7920_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7920_DELAY_2 DELAY_NS(188)
+ #define CPU_ST7920_DELAY_3 DELAY_NS(0)
#elif MB(MINIRAMBO)
- #define CPU_ST7920_DELAY_1 DELAY_0_NOP
- #define CPU_ST7920_DELAY_2 DELAY_4_NOP
- #define CPU_ST7920_DELAY_3 DELAY_0_NOP
+ #define CPU_ST7920_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7920_DELAY_2 DELAY_NS(250)
+ #define CPU_ST7920_DELAY_3 DELAY_NS(0)
#elif MB(RAMBO)
- #define CPU_ST7920_DELAY_1 DELAY_0_NOP
- #define CPU_ST7920_DELAY_2 DELAY_0_NOP
- #define CPU_ST7920_DELAY_3 DELAY_0_NOP
+ #define CPU_ST7920_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7920_DELAY_2 DELAY_NS(0)
+ #define CPU_ST7920_DELAY_3 DELAY_NS(0)
+#elif MB(BQ_ZUM_MEGA_3D)
+ #define CPU_ST7920_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7920_DELAY_2 DELAY_NS(0)
+ #define CPU_ST7920_DELAY_3 DELAY_NS(189)
#elif F_CPU == 16000000
- #define CPU_ST7920_DELAY_1 DELAY_0_NOP
- #define CPU_ST7920_DELAY_2 DELAY_0_NOP
- #define CPU_ST7920_DELAY_3 DELAY_1_NOP
+ #define CPU_ST7920_DELAY_1 DELAY_NS(0)
+ #define CPU_ST7920_DELAY_2 DELAY_NS(0)
+ #define CPU_ST7920_DELAY_3 DELAY_NS(63)
#else
#error "No valid condition for delays in 'ultralcd_st7920_u8glib_rrd.h'"
#endif
@@ -95,8 +100,8 @@ static void ST7920_SWSPI_SND_8BIT(uint8_t val) {
ST7920_SND_BIT; // 8
}
-#if defined(DOGM_SPI_DELAY_US) && DOGM_SPI_DELAY_US > 0
- #define U8G_DELAY() delayMicroseconds(DOGM_SPI_DELAY_US)
+#if DOGM_SPI_DELAY_US > 0
+ #define U8G_DELAY() DELAY_US(DOGM_SPI_DELAY_US)
#else
#define U8G_DELAY() u8g_10MicroDelay()
#endif
diff --git a/Marlin/utf_mapper.h b/Marlin/utf_mapper.h
index c49e6fc4e7..aacf2f11d5 100644
--- a/Marlin/utf_mapper.h
+++ b/Marlin/utf_mapper.h
@@ -144,7 +144,7 @@
#endif // DISPLAY_CHARSET_HD44780
#endif // SIMULATE_ROMFONT
-#define PRINTABLE(C) (((C) & 0xC0u) != 0x80u)
+#define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80u)
#if ENABLED(MAPPER_C2C3)
diff --git a/Marlin/utility.cpp b/Marlin/utility.cpp
index 63ee94bd06..88a0503d5e 100644
--- a/Marlin/utility.cpp
+++ b/Marlin/utility.cpp
@@ -40,7 +40,7 @@ void safe_delay(millis_t ms) {
uint8_t *ptr = (uint8_t *)data;
while (cnt--) {
*crc = (uint16_t)(*crc ^ (uint16_t)(((uint16_t)*ptr++) << 8));
- for (uint8_t x = 0; x < 8; x++)
+ for (uint8_t i = 0; i < 8; i++)
*crc = (uint16_t)((*crc & 0x8000) ? ((uint16_t)(*crc << 1) ^ 0x1021) : (*crc << 1));
}
}
@@ -57,193 +57,190 @@ void safe_delay(millis_t ms) {
#define MINUSOR(n, alt) (n >= 0 ? (alt) : (n = -n, '-'))
// Convert unsigned int to string 123 format
- char* i8tostr3(const uint8_t xx) {
- conv[4] = RJDIGIT(xx, 100);
- conv[5] = RJDIGIT(xx, 10);
- conv[6] = DIGIMOD(xx, 1);
+ char* i8tostr3(const uint8_t i) {
+ conv[4] = RJDIGIT(i, 100);
+ conv[5] = RJDIGIT(i, 10);
+ conv[6] = DIGIMOD(i, 1);
return &conv[4];
}
// Convert signed int to rj string with 123 or -12 format
- char* itostr3(const int x) {
- int xx = x;
- conv[4] = MINUSOR(xx, RJDIGIT(xx, 100));
- conv[5] = RJDIGIT(xx, 10);
- conv[6] = DIGIMOD(xx, 1);
+ char* itostr3(int i) {
+ conv[4] = MINUSOR(i, RJDIGIT(i, 100));
+ conv[5] = RJDIGIT(i, 10);
+ conv[6] = DIGIMOD(i, 1);
return &conv[4];
}
// Convert unsigned int to lj string with 123 format
- char* itostr3left(const int xx) {
+ char* itostr3left(const int i) {
char *str = &conv[6];
- *str = DIGIMOD(xx, 1);
- if (xx >= 10) {
- *(--str) = DIGIMOD(xx, 10);
- if (xx >= 100)
- *(--str) = DIGIMOD(xx, 100);
+ *str = DIGIMOD(i, 1);
+ if (i >= 10) {
+ *(--str) = DIGIMOD(i, 10);
+ if (i >= 100)
+ *(--str) = DIGIMOD(i, 100);
}
return str;
}
// Convert signed int to rj string with 1234, _123, -123, _-12, or __-1 format
- char *itostr4sign(const int x) {
- const bool neg = x < 0;
- const int xx = neg ? -x : x;
- if (x >= 1000) {
- conv[3] = DIGIMOD(xx, 1000);
- conv[4] = DIGIMOD(xx, 100);
- conv[5] = DIGIMOD(xx, 10);
+ char* itostr4sign(const int i) {
+ const bool neg = i < 0;
+ const int ii = neg ? -i : i;
+ if (i >= 1000) {
+ conv[3] = DIGIMOD(ii, 1000);
+ conv[4] = DIGIMOD(ii, 100);
+ conv[5] = DIGIMOD(ii, 10);
+ }
+ else if (ii >= 100) {
+ conv[3] = neg ? '-' : ' ';
+ conv[4] = DIGIMOD(ii, 100);
+ conv[5] = DIGIMOD(ii, 10);
}
else {
- if (xx >= 100) {
- conv[3] = neg ? '-' : ' ';
- conv[4] = DIGIMOD(xx, 100);
- conv[5] = DIGIMOD(xx, 10);
+ conv[3] = ' ';
+ conv[4] = ' ';
+ if (ii >= 10) {
+ conv[4] = neg ? '-' : ' ';
+ conv[5] = DIGIMOD(ii, 10);
}
else {
- conv[3] = ' ';
- conv[4] = ' ';
- if (xx >= 10) {
- conv[4] = neg ? '-' : ' ';
- conv[5] = DIGIMOD(xx, 10);
- }
- else {
- conv[5] = neg ? '-' : ' ';
- }
+ conv[5] = neg ? '-' : ' ';
}
}
- conv[6] = DIGIMOD(xx, 1);
+ conv[6] = DIGIMOD(ii, 1);
return &conv[3];
}
// Convert unsigned float to string with 1.23 format
- char* ftostr12ns(const float &x) {
- const long xx = (x < 0 ? -x : x) * 100;
- conv[3] = DIGIMOD(xx, 100);
+ char* ftostr12ns(const float &f) {
+ const long i = ((f < 0 ? -f : f) * 1000 + 5) / 10;
+ conv[3] = DIGIMOD(i, 100);
conv[4] = '.';
- conv[5] = DIGIMOD(xx, 10);
- conv[6] = DIGIMOD(xx, 1);
+ conv[5] = DIGIMOD(i, 10);
+ conv[6] = DIGIMOD(i, 1);
return &conv[3];
}
// Convert signed float to fixed-length string with 023.45 / -23.45 format
- char *ftostr32(const float &x) {
- long xx = x * 100;
- conv[1] = MINUSOR(xx, DIGIMOD(xx, 10000));
- conv[2] = DIGIMOD(xx, 1000);
- conv[3] = DIGIMOD(xx, 100);
+ char* ftostr52(const float &f) {
+ long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
+ conv[1] = MINUSOR(i, DIGIMOD(i, 10000));
+ conv[2] = DIGIMOD(i, 1000);
+ conv[3] = DIGIMOD(i, 100);
conv[4] = '.';
- conv[5] = DIGIMOD(xx, 10);
- conv[6] = DIGIMOD(xx, 1);
+ conv[5] = DIGIMOD(i, 10);
+ conv[6] = DIGIMOD(i, 1);
return &conv[1];
}
#if ENABLED(LCD_DECIMAL_SMALL_XY)
// Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
- char *ftostr4sign(const float &fx) {
- const int x = fx * 10;
- if (!WITHIN(x, -99, 999)) return itostr4sign((int)fx);
- const bool neg = x < 0;
- const int xx = neg ? -x : x;
- conv[3] = neg ? '-' : (xx >= 100 ? DIGIMOD(xx, 100) : ' ');
- conv[4] = DIGIMOD(xx, 10);
+ char* ftostr4sign(const float &f) {
+ const int i = (f * 100 + (f < 0 ? -5: 5)) / 10;
+ if (!WITHIN(i, -99, 999)) return itostr4sign((int)f);
+ const bool neg = i < 0;
+ const int ii = neg ? -i : i;
+ conv[3] = neg ? '-' : (ii >= 100 ? DIGIMOD(ii, 100) : ' ');
+ conv[4] = DIGIMOD(ii, 10);
conv[5] = '.';
- conv[6] = DIGIMOD(xx, 1);
+ conv[6] = DIGIMOD(ii, 1);
return &conv[3];
}
#endif // LCD_DECIMAL_SMALL_XY
// Convert float to fixed-length string with +123.4 / -123.4 format
- char* ftostr41sign(const float &x) {
- int xx = x * 10;
- conv[1] = MINUSOR(xx, '+');
- conv[2] = DIGIMOD(xx, 1000);
- conv[3] = DIGIMOD(xx, 100);
- conv[4] = DIGIMOD(xx, 10);
+ char* ftostr41sign(const float &f) {
+ int i = (f * 100 + (f < 0 ? -5: 5)) / 10;
+ conv[1] = MINUSOR(i, '+');
+ conv[2] = DIGIMOD(i, 1000);
+ conv[3] = DIGIMOD(i, 100);
+ conv[4] = DIGIMOD(i, 10);
conv[5] = '.';
- conv[6] = DIGIMOD(xx, 1);
+ conv[6] = DIGIMOD(i, 1);
return &conv[1];
}
// Convert signed float to string (6 digit) with -1.234 / _0.000 / +1.234 format
- char* ftostr43sign(const float &x, char plus/*=' '*/) {
- long xx = x * 1000;
- conv[1] = xx ? MINUSOR(xx, plus) : ' ';
- conv[2] = DIGIMOD(xx, 1000);
+ char* ftostr43sign(const float &f, char plus/*=' '*/) {
+ long i = (f * 10000 + (f < 0 ? -5: 5)) / 10;
+ conv[1] = i ? MINUSOR(i, plus) : ' ';
+ conv[2] = DIGIMOD(i, 1000);
conv[3] = '.';
- conv[4] = DIGIMOD(xx, 100);
- conv[5] = DIGIMOD(xx, 10);
- conv[6] = DIGIMOD(xx, 1);
+ conv[4] = DIGIMOD(i, 100);
+ conv[5] = DIGIMOD(i, 10);
+ conv[6] = DIGIMOD(i, 1);
return &conv[1];
}
// Convert unsigned float to rj string with 12345 format
- char* ftostr5rj(const float &x) {
- const long xx = x < 0 ? -x : x;
- conv[2] = RJDIGIT(xx, 10000);
- conv[3] = RJDIGIT(xx, 1000);
- conv[4] = RJDIGIT(xx, 100);
- conv[5] = RJDIGIT(xx, 10);
- conv[6] = DIGIMOD(xx, 1);
+ char* ftostr5rj(const float &f) {
+ const long i = ((f < 0 ? -f : f) * 10 + 5) / 10;
+ conv[2] = RJDIGIT(i, 10000);
+ conv[3] = RJDIGIT(i, 1000);
+ conv[4] = RJDIGIT(i, 100);
+ conv[5] = RJDIGIT(i, 10);
+ conv[6] = DIGIMOD(i, 1);
return &conv[2];
}
// Convert signed float to string with +1234.5 format
- char* ftostr51sign(const float &x) {
- long xx = x * 10;
- conv[0] = MINUSOR(xx, '+');
- conv[1] = DIGIMOD(xx, 10000);
- conv[2] = DIGIMOD(xx, 1000);
- conv[3] = DIGIMOD(xx, 100);
- conv[4] = DIGIMOD(xx, 10);
+ char* ftostr51sign(const float &f) {
+ long i = (f * 100 + (f < 0 ? -5: 5)) / 10;
+ conv[0] = MINUSOR(i, '+');
+ conv[1] = DIGIMOD(i, 10000);
+ conv[2] = DIGIMOD(i, 1000);
+ conv[3] = DIGIMOD(i, 100);
+ conv[4] = DIGIMOD(i, 10);
conv[5] = '.';
- conv[6] = DIGIMOD(xx, 1);
+ conv[6] = DIGIMOD(i, 1);
return conv;
}
// Convert signed float to string with +123.45 format
- char* ftostr52sign(const float &x) {
- long xx = x * 100;
- conv[0] = MINUSOR(xx, '+');
- conv[1] = DIGIMOD(xx, 10000);
- conv[2] = DIGIMOD(xx, 1000);
- conv[3] = DIGIMOD(xx, 100);
+ char* ftostr52sign(const float &f) {
+ long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
+ conv[0] = MINUSOR(i, '+');
+ conv[1] = DIGIMOD(i, 10000);
+ conv[2] = DIGIMOD(i, 1000);
+ conv[3] = DIGIMOD(i, 100);
conv[4] = '.';
- conv[5] = DIGIMOD(xx, 10);
- conv[6] = DIGIMOD(xx, 1);
+ conv[5] = DIGIMOD(i, 10);
+ conv[6] = DIGIMOD(i, 1);
return conv;
}
// Convert unsigned float to string with 1234.56 format omitting trailing zeros
- char* ftostr62rj(const float &x) {
- const long xx = (x < 0 ? -x : x) * 100;
- conv[0] = RJDIGIT(xx, 100000);
- conv[1] = RJDIGIT(xx, 10000);
- conv[2] = RJDIGIT(xx, 1000);
- conv[3] = DIGIMOD(xx, 100);
+ char* ftostr62rj(const float &f) {
+ const long i = ((f < 0 ? -f : f) * 1000 + 5) / 10;
+ conv[0] = RJDIGIT(i, 100000);
+ conv[1] = RJDIGIT(i, 10000);
+ conv[2] = RJDIGIT(i, 1000);
+ conv[3] = DIGIMOD(i, 100);
conv[4] = '.';
- conv[5] = DIGIMOD(xx, 10);
- conv[6] = DIGIMOD(xx, 1);
+ conv[5] = DIGIMOD(i, 10);
+ conv[6] = DIGIMOD(i, 1);
return conv;
}
// Convert signed float to space-padded string with -_23.4_ format
- char* ftostr52sp(const float &x) {
- long xx = x * 100;
+ char* ftostr52sp(const float &f) {
+ long i = (f * 1000 + (f < 0 ? -5: 5)) / 10;
uint8_t dig;
- conv[1] = MINUSOR(xx, RJDIGIT(xx, 10000));
- conv[2] = RJDIGIT(xx, 1000);
- conv[3] = DIGIMOD(xx, 100);
+ conv[1] = MINUSOR(i, RJDIGIT(i, 10000));
+ conv[2] = RJDIGIT(i, 1000);
+ conv[3] = DIGIMOD(i, 100);
- if ((dig = xx % 10)) { // second digit after decimal point?
+ if ((dig = i % 10)) { // second digit after decimal point?
conv[4] = '.';
- conv[5] = DIGIMOD(xx, 10);
+ conv[5] = DIGIMOD(i, 10);
conv[6] = DIGIT(dig);
}
else {
- if ((dig = (xx / 10) % 10)) { // first digit after decimal point?
+ if ((dig = (i / 10) % 10)) { // first digit after decimal point?
conv[4] = '.';
conv[5] = DIGIT(dig);
}
diff --git a/Marlin/utility.h b/Marlin/utility.h
index f79c2b1a6f..991d66289a 100644
--- a/Marlin/utility.h
+++ b/Marlin/utility.h
@@ -43,13 +43,13 @@ void safe_delay(millis_t ms);
char* itostr3left(const int xx);
// Convert signed int to rj string with _123, -123, _-12, or __-1 format
- char *itostr4sign(const int x);
+ char* itostr4sign(const int x);
// Convert unsigned float to string with 1.23 format
char* ftostr12ns(const float &x);
// Convert signed float to fixed-length string with 023.45 / -23.45 format
- char* ftostr32(const float &x);
+ char* ftostr52(const float &x);
// Convert float to fixed-length string with +123.4 / -123.4 format
char* ftostr41sign(const float &x);
@@ -73,14 +73,14 @@ void safe_delay(millis_t ms);
char* ftostr62rj(const float &x);
// Convert float to rj string with 123 or -12 format
- FORCE_INLINE char *ftostr3(const float &x) { return itostr3((int)x); }
+ FORCE_INLINE char* ftostr3(const float &x) { return itostr3(int(x + (x < 0 ? -0.5f : 0.5f))); }
#if ENABLED(LCD_DECIMAL_SMALL_XY)
// Convert float to rj string with 1234, _123, 12.3, _1.2, -123, _-12, or -1.2 format
- char *ftostr4sign(const float &fx);
+ char* ftostr4sign(const float &fx);
#else
// Convert float to rj string with 1234, _123, -123, __12, _-12, ___1, or __-1 format
- FORCE_INLINE char *ftostr4sign(const float &x) { return itostr4sign((int)x); }
+ FORCE_INLINE char* ftostr4sign(const float &x) { return itostr4sign(int(x + (x < 0 ? -0.5f : 0.5f))); }
#endif
#endif // ULTRA_LCD || (DEBUG_LEVELING_FEATURE && (MESH_BED_LEVELING || (HAS_ABL && !ABL_PLANAR)))
diff --git a/Marlin/vector_3.cpp b/Marlin/vector_3.cpp
index aebc8c9737..e5afd9e831 100644
--- a/Marlin/vector_3.cpp
+++ b/Marlin/vector_3.cpp
@@ -41,7 +41,7 @@
#include "MarlinConfig.h"
-#if HAS_ABL
+#if ABL_PLANAR || (HAS_BED_PROBE && ENABLED(AUTO_BED_LEVELING_UBL))
#include "vector_3.h"
#include "serial.h"
@@ -69,7 +69,7 @@ vector_3 vector_3::get_normal() {
float vector_3::get_length() { return SQRT(sq(x) + sq(y) + sq(z)); }
void vector_3::normalize() {
- const float inv_length = 1.0 / get_length();
+ const float inv_length = RSQRT(sq(x) + sq(y) + sq(z));
x *= inv_length;
y *= inv_length;
z *= inv_length;