From f8f68f9259cc486fd36147f4f9d1e474940510dd Mon Sep 17 00:00:00 2001 From: ellensp Date: Thu, 22 Jul 2021 09:31:11 +1200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20MKS=20Hardware=20Test=20followup?= =?UTF-8?q?=20(#22414)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Scott Lahteine --- .../lcd/extui/mks_ui/draw_media_select.cpp | 4 +- .../src/lcd/extui/mks_ui/draw_ready_print.cpp | 12 +- Marlin/src/lcd/extui/mks_ui/draw_tool.cpp | 4 +- .../extui/mks_ui/draw_touch_calibration.cpp | 6 +- Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp | 188 ++++++++++++++---- Marlin/src/lcd/extui/mks_ui/mks_hardware.h | 2 + .../src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h | 6 + buildroot/tests/mks_robin_nano35 | 1 + buildroot/tests/mks_robin_nano35_maple | 1 + 9 files changed, 170 insertions(+), 54 deletions(-) diff --git a/Marlin/src/lcd/extui/mks_ui/draw_media_select.cpp b/Marlin/src/lcd/extui/mks_ui/draw_media_select.cpp index 0394ed6009..81c82dc02d 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_media_select.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_media_select.cpp @@ -39,7 +39,7 @@ enum { }; #if ENABLED(MKS_TEST) - extern uint8_t curent_disp_ui; + extern uint8_t current_disp_ui; #endif static void event_handler(lv_obj_t *obj, lv_event_t event) { @@ -49,7 +49,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { case ID_T_USB_DISK: card.changeMedia(&card.media_driver_usbFlash); break; case ID_T_SD_DISK: card.changeMedia(&card.media_driver_sdcard); break; case ID_T_RETURN: - TERN_(MKS_TEST, curent_disp_ui = 1); + TERN_(MKS_TEST, current_disp_ui = 1); lv_draw_ready_print(); return; } diff --git a/Marlin/src/lcd/extui/mks_ui/draw_ready_print.cpp b/Marlin/src/lcd/extui/mks_ui/draw_ready_print.cpp index 6f24d81b49..d324d8d7be 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_ready_print.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_ready_print.cpp @@ -61,7 +61,7 @@ static lv_obj_t *buttonExt1, *labelExt1, *buttonFanstate, *labelFan; #endif #if ENABLED(MKS_TEST) - uint8_t curent_disp_ui = 0; + uint8_t current_disp_ui = 0; #endif enum { ID_TOOL = 1, ID_SET, ID_PRINT, ID_INFO_EXT, ID_INFO_BED, ID_INFO_FAN }; @@ -106,8 +106,10 @@ void disp_det_error() { lv_obj_t *e1, *e2, *e3, *bed; void mks_disp_test() { char buf[30] = {0}; - sprintf_P(buf, PSTR("e1:%d"), thermalManager.wholeDegHotend(0)); - lv_label_set_text(e1, buf); + #if HAS_HOTEND + sprintf_P(buf, PSTR("e1:%d"), thermalManager.wholeDegHotend(0)); + lv_label_set_text(e1, buf); + #endif #if HAS_MULTI_HOTEND sprintf_P(buf, PSTR("e2:%d"), thermalManager.wholeDegHotend(1)); lv_label_set_text(e2, buf); @@ -126,7 +128,7 @@ void lv_draw_ready_print() { ZERO(disp_state_stack._disp_state); scr = lv_screen_create(PRINT_READY_UI, ""); - if (TERN0(SDSUPPORT, mks_test_flag == 0x1E)) { + if (mks_test_flag == 0x1E) { // Create image buttons buttonTool = lv_imgbtn_create(scr, "F:/bmp_tool.bin", event_handler, ID_TOOL); @@ -147,7 +149,7 @@ void lv_draw_ready_print() { #if HAS_MULTI_HOTEND e2 = lv_label_create_empty(scr); lv_obj_set_pos(e2, 20, 45); - sprintf_P(buf, PSTR("e1: %d"), thermalManager.wholeDegHotend(1)); + sprintf_P(buf, PSTR("e2: %d"), thermalManager.wholeDegHotend(1)); lv_label_set_text(e2, buf); #endif #if HAS_HEATED_BED diff --git a/Marlin/src/lcd/extui/mks_ui/draw_tool.cpp b/Marlin/src/lcd/extui/mks_ui/draw_tool.cpp index 16c1448b3c..8b9747972d 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_tool.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_tool.cpp @@ -45,7 +45,7 @@ enum { }; #if ENABLED(MKS_TEST) - extern uint8_t curent_disp_ui; + extern uint8_t current_disp_ui; #endif static void event_handler(lv_obj_t *obj, lv_event_t event) { @@ -75,7 +75,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { lv_draw_more(); break; case ID_T_RETURN: - TERN_(MKS_TEST, curent_disp_ui = 1); + TERN_(MKS_TEST, current_disp_ui = 1); lv_draw_ready_print(); break; } diff --git a/Marlin/src/lcd/extui/mks_ui/draw_touch_calibration.cpp b/Marlin/src/lcd/extui/mks_ui/draw_touch_calibration.cpp index a4470a4c87..e10a07c6de 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_touch_calibration.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_touch_calibration.cpp @@ -34,6 +34,10 @@ static lv_obj_t *scr; static lv_obj_t *status_label; +#if ENABLED(MKS_TEST) + extern uint8_t current_disp_ui; +#endif + static void event_handler(lv_obj_t *obj, lv_event_t event); enum { @@ -93,7 +97,7 @@ static void event_handler(lv_obj_t *obj, lv_event_t event) { if (event != LV_EVENT_RELEASED) return; switch (obj->mks_obj_id) { case ID_TC_RETURN: - TERN_(MKS_TEST, curent_disp_ui = 1); + TERN_(MKS_TEST, current_disp_ui = 1); lv_clear_touch_calibration_screen(); draw_return_ui(); break; diff --git a/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp b/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp index 3c7eb55532..5cd1a4c525 100644 --- a/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp +++ b/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp @@ -38,12 +38,44 @@ #if ENABLED(MKS_TEST) #include "mks_hardware.h" + #include "../../../module/endstops.h" bool pw_det_sta, pw_off_sta, mt_det_sta; #if PIN_EXISTS(MT_DET_2) bool mt_det2_sta; #endif - bool endstopx1_sta, endstopx2_sta, endstopy1_sta, endstopy2_sta, endstopz1_sta, endstopz2_sta; + #if HAS_X_MIN || HAS_X_MAX + bool endstopx1_sta; + #else + constexpr static bool endstopx1_sta = true; + #endif + #if HAS_X2_MIN || HAS_X2_MAX + bool endstopx2_sta; + #else + constexpr static bool endstopx2_sta = true; + #endif + #if HAS_Y_MIN || HAS_Y_MAX + bool endstopy1_sta; + #else + constexpr static bool endstopy1_sta = true; + #endif + #if HAS_Y2_MIN || HAS_Y2_MAX + bool endstopy2_sta; + #else + constexpr static bool endstopy2_sta = true; + #endif + #if HAS_Z_MIN || HAS_Z_MAX + bool endstopz1_sta; + #else + constexpr static bool endstopz1_sta = true; + #endif + #if HAS_Z2_MIN || HAS_Z2_MAX + bool endstopz2_sta; + #else + constexpr static bool endstopz2_sta = true; + #endif + + #define ESTATE(S) (READ(S##_PIN) != S##_ENDSTOP_INVERTING) void test_gpio_readlevel_L() { WRITE(WIFI_IO0_PIN, HIGH); @@ -54,10 +86,36 @@ #if PIN_EXISTS(MT_DET_2) mt_det2_sta = (READ(MT_DET_2_PIN) == LOW); #endif - endstopx1_sta = (READ(X_MIN_PIN) == LOW); - endstopy1_sta = (READ(Y_MIN_PIN) == LOW); - endstopz1_sta = (READ(Z_MIN_PIN) == LOW); - endstopz2_sta = (READ(Z_MAX_PIN) == LOW); + #if HAS_X_MIN + endstopx1_sta = ESTATE(X_MIN); + #elif HAS_X_MAX + endstopx1_sta = ESTATE(X_MAX); + #endif + #if HAS_X2_MIN + endstopx2_sta = ESTATE(X2_MIN); + #elif HAS_X2_MAX + endstopx2_sta = ESTATE(X2_MAX); + #endif + #if HAS_Y_MIN + endstopy1_sta = ESTATE(Y_MIN); + #elif HAS_Y_MAX + endstopy1_sta = ESTATE(Y_MAX); + #endif + #if HAS_Y2_MIN + endstopy2_sta = ESTATE(Y2_MIN); + #elif HAS_Y2_MAX + endstopy2_sta = ESTATE(Y2_MAX); + #endif + #if HAS_Z_MIN + endstopz1_sta = ESTATE(Z_MIN); + #elif HAS_Z_MAX + endstopz1_sta = ESTATE(Z_MAX); + #endif + #if HAS_Z2_MIN + endstopz2_sta = ESTATE(Z2_MIN); + #elif HAS_Z2_MAX + endstopz2_sta = ESTATE(Z2_MAX); + #endif } void test_gpio_readlevel_H() { @@ -69,44 +127,66 @@ #if PIN_EXISTS(MT_DET_2) mt_det2_sta = (READ(MT_DET_2_PIN) == HIGH); #endif - endstopx1_sta = (READ(X_MIN_PIN) == HIGH); - endstopy1_sta = (READ(Y_MIN_PIN) == HIGH); - endstopz1_sta = (READ(Z_MIN_PIN) == HIGH); - endstopz2_sta = (READ(Z_MAX_PIN) == HIGH); + #if HAS_X_MIN + endstopx1_sta = !ESTATE(X_MIN); + #elif HAS_X_MAX + endstopx1_sta = !ESTATE(X_MAX); + #endif + #if HAS_X2_MIN + endstopx2_sta = !ESTATE(X2_MIN); + #elif HAS_X2_MAX + endstopx2_sta = !ESTATE(X2_MAX); + #endif + #if HAS_Y_MIN + endstopy1_sta = !ESTATE(Y_MIN); + #elif HAS_Y_MAX + endstopy1_sta = !ESTATE(Y_MAX); + #endif + #if HAS_Y2_MIN + endstopy2_sta = !ESTATE(Y2_MIN); + #elif HAS_Y2_MAX + endstopy2_sta = !ESTATE(Y2_MAX); + #endif + #if HAS_Z_MIN + endstopz1_sta = !ESTATE(Z_MIN); + #elif HAS_Z_MAX + endstopz1_sta = !ESTATE(Z_MAX); + #endif + #if HAS_Z2_MIN + endstopz2_sta = !ESTATE(Z2_MIN); + #elif HAS_Z2_MAX + endstopz2_sta = !ESTATE(Z2_MAX); + #endif } void init_test_gpio() { - SET_INPUT_PULLUP(X_MIN_PIN); - SET_INPUT_PULLUP(Y_MIN_PIN); - SET_INPUT_PULLUP(Z_MIN_PIN); - SET_INPUT_PULLUP(Z_MAX_PIN); + endstops.init(); SET_OUTPUT(WIFI_IO0_PIN); - SET_INPUT_PULLUP(MT_DET_1_PIN); + #if PIN_EXISTS(MT_DET_1) + SET_INPUT_PULLUP(MT_DET_1_PIN); + #endif #if PIN_EXISTS(MT_DET_2) SET_INPUT_PULLUP(MT_DET_2_PIN); #endif SET_INPUT_PULLUP(MKS_TEST_POWER_LOSS_PIN); SET_INPUT_PULLUP(MKS_TEST_PS_ON_PIN); - SET_INPUT_PULLUP(SERVO0_PIN); - SET_OUTPUT(X_ENABLE_PIN); - SET_OUTPUT(Y_ENABLE_PIN); - SET_OUTPUT(Z_ENABLE_PIN); - SET_OUTPUT(E0_ENABLE_PIN); - #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) - SET_OUTPUT(E1_ENABLE_PIN); + OUT_WRITE(X_ENABLE_PIN, LOW); + #if HAS_Y_AXIS + OUT_WRITE(Y_ENABLE_PIN, LOW); #endif - - WRITE(X_ENABLE_PIN, LOW); - WRITE(Y_ENABLE_PIN, LOW); - WRITE(Z_ENABLE_PIN, LOW); - WRITE(E0_ENABLE_PIN, LOW); - #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) - WRITE(E1_ENABLE_PIN, LOW); + #if HAS_Z_AXIS + OUT_WRITE(Z_ENABLE_PIN, LOW); + #endif + #if HAS_EXTRUDERS + OUT_WRITE(E0_ENABLE_PIN, LOW); + #endif + #if HAS_MULTI_EXTRUDER && DISABLED(MKS_HARDWARE_TEST_ONLY_E0) + OUT_WRITE(E1_ENABLE_PIN, LOW); #endif #if ENABLED(MKS_HARDWARE_TEST_ONLY_E0) @@ -161,34 +241,54 @@ void mks_hardware_test() { if (millis() % 2000 < 1000) { + thermalManager.fan_speed[0] = 255; WRITE(X_DIR_PIN, LOW); - WRITE(Y_DIR_PIN, LOW); - WRITE(Z_DIR_PIN, LOW); - WRITE(E0_DIR_PIN, LOW); - #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) + #if HAS_Y_AXIS + WRITE(Y_DIR_PIN, LOW); + #endif + #if HAS_Z_AXIS + WRITE(Z_DIR_PIN, LOW); + #endif + #if HAS_EXTRUDERS + WRITE(E0_DIR_PIN, LOW); + #endif + #if HAS_MULTI_EXTRUDER && DISABLED(MKS_HARDWARE_TEST_ONLY_E0) WRITE(E1_DIR_PIN, LOW); #endif - thermalManager.fan_speed[0] = 255; - #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) + #if HAS_MULTI_HOTEND && DISABLED(MKS_HARDWARE_TEST_ONLY_E0) WRITE(HEATER_1_PIN, HIGH); // HE1 #endif - WRITE(HEATER_0_PIN, HIGH); // HE0 - WRITE(HEATER_BED_PIN, HIGH); // HOT-BED + #if HAS_HOTEND + WRITE(HEATER_0_PIN, HIGH); // HE0 + #endif + #if HAS_HEATED_BED + WRITE(HEATER_BED_PIN, HIGH); // HOT-BED + #endif } else { + thermalManager.fan_speed[0] = 0; WRITE(X_DIR_PIN, HIGH); - WRITE(Y_DIR_PIN, HIGH); - WRITE(Z_DIR_PIN, HIGH); - WRITE(E0_DIR_PIN, HIGH); - #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) + #if HAS_Y_AXIS + WRITE(Y_DIR_PIN, HIGH); + #endif + #if HAS_Y_AXIS + WRITE(Z_DIR_PIN, HIGH); + #endif + #if HAS_EXTRUDERS + WRITE(E0_DIR_PIN, HIGH); + #endif + #if HAS_MULTI_EXTRUDER && DISABLED(MKS_HARDWARE_TEST_ONLY_E0) WRITE(E1_DIR_PIN, HIGH); #endif - thermalManager.fan_speed[0] = 0; - #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) + #if HAS_MULTI_HOTEND && DISABLED(MKS_HARDWARE_TEST_ONLY_E0) WRITE(HEATER_1_PIN, LOW); // HE1 #endif - WRITE(HEATER_0_PIN, LOW); // HE0 - WRITE(HEATER_BED_PIN, LOW); // HOT-BED + #if HAS_HOTEND + WRITE(HEATER_0_PIN, LOW); // HE0 + #endif + #if HAS_HEATED_BED + WRITE(HEATER_BED_PIN, LOW); // HOT-BED + #endif } if (endstopx1_sta && endstopx2_sta && endstopy1_sta && endstopy2_sta && endstopz1_sta && endstopz2_sta) { diff --git a/Marlin/src/lcd/extui/mks_ui/mks_hardware.h b/Marlin/src/lcd/extui/mks_ui/mks_hardware.h index f41c4e18ac..5313265662 100644 --- a/Marlin/src/lcd/extui/mks_ui/mks_hardware.h +++ b/Marlin/src/lcd/extui/mks_ui/mks_hardware.h @@ -31,6 +31,8 @@ void mks_test_get(); void mks_gpio_test(); extern uint8_t mks_test_flag; +#else + #define mks_test_flag 0 #endif // String display and assets diff --git a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h index 178e75ab7f..182506f11e 100644 --- a/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h +++ b/Marlin/src/pins/stm32f4/pins_MKS_ROBIN_NANO_V3.h @@ -220,6 +220,12 @@ #define WIFI_RESET_PIN PE9 // MKS ESP WIFI RESET PIN #endif +// MKS TEST +#if ENABLED(MKS_TEST) + #define MKS_TEST_POWER_LOSS_PIN PA13 // PW_DET + #define MKS_TEST_PS_ON_PIN PB2 // PW_OFF +#endif + // // Onboard SD card // diff --git a/buildroot/tests/mks_robin_nano35 b/buildroot/tests/mks_robin_nano35 index 99ff2623bb..bd16fe48e9 100755 --- a/buildroot/tests/mks_robin_nano35 +++ b/buildroot/tests/mks_robin_nano35 @@ -22,6 +22,7 @@ use_example_configs Mks/Robin opt_set MOTHERBOARD BOARD_MKS_ROBIN_NANO_V2 opt_disable TFT_INTERFACE_FSMC opt_enable TFT_INTERFACE_SPI MKS_WIFI_MODULE +opt_add MKS_TEST exec_test $1 $2 "MKS Robin v2 nano Emulated DOGM SPI, MKS_WIFI_MODULE" "$3" # diff --git a/buildroot/tests/mks_robin_nano35_maple b/buildroot/tests/mks_robin_nano35_maple index f1549a8103..ebd5466ce6 100755 --- a/buildroot/tests/mks_robin_nano35_maple +++ b/buildroot/tests/mks_robin_nano35_maple @@ -32,6 +32,7 @@ use_example_configs Mks/Robin opt_set MOTHERBOARD BOARD_MKS_ROBIN_NANO_V2 opt_disable TFT_INTERFACE_FSMC TFT_COLOR_UI TOUCH_SCREEN TFT_RES_320x240 SERIAL_PORT_2 opt_enable TFT_INTERFACE_SPI TFT_LVGL_UI TFT_RES_480x320 MKS_WIFI_MODULE +opt_add MKS_TEST exec_test $1 $2 "MKS Robin v2 nano LVGL SPI w/ WiFi" "$3" #