From a24bf52fa442ac14b217c2e98091dc161c5118ba Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 24 Jun 2021 15:23:52 -0500 Subject: [PATCH] Tweak MKS hardware test --- .../lcd/extui/mks_ui/draw_error_message.cpp | 5 +- .../src/lcd/extui/mks_ui/draw_ready_print.cpp | 5 +- Marlin/src/lcd/extui/mks_ui/draw_ui.cpp | 10 +- .../lcd/extui/mks_ui/mks_hardware_test.cpp | 134 ++++++++---------- .../src/lcd/extui/mks_ui/mks_hardware_test.h | 6 +- Marlin/src/lcd/extui/mks_ui/pic_manager.cpp | 5 +- .../extui/mks_ui/tft_lvgl_configuration.cpp | 7 +- Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h | 1 + 8 files changed, 88 insertions(+), 85 deletions(-) diff --git a/Marlin/src/lcd/extui/mks_ui/draw_error_message.cpp b/Marlin/src/lcd/extui/mks_ui/draw_error_message.cpp index 3297b9da2772e..7ee2617326f0b 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_error_message.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_error_message.cpp @@ -29,9 +29,12 @@ #include "tft_lvgl_configuration.h" #include "SPI_TFT.h" -#include "mks_hardware_test.h" #include "../../../inc/MarlinConfig.h" +#if ENABLED(MKS_TEST) + #include "mks_hardware_test.h" +#endif + static lv_obj_t *scr; void lv_draw_error_message(PGM_P const msg) { 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 0ad74fd45f8fc..5f9932a2b311c 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_ready_print.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_ready_print.cpp @@ -27,7 +27,6 @@ #include "draw_tool.h" #include #include "tft_lvgl_configuration.h" -#include "mks_hardware_test.h" #include "draw_ui.h" #include @@ -40,6 +39,10 @@ #include "draw_touch_calibration.h" #endif +#if ENABLED(MKS_TEST) + #include "mks_hardware_test.h" +#endif + #include #define ICON_POS_Y 38 diff --git a/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp index 146165363d0e1..30e08e03ed455 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp @@ -30,7 +30,6 @@ #include "pic_manager.h" #include "draw_ui.h" -#include "mks_hardware_test.h" #include @@ -52,6 +51,10 @@ #include "draw_touch_calibration.h" #endif +#if ENABLED(MKS_TEST) + #include "mks_hardware_test.h" +#endif + CFG_ITMES gCfgItems; UI_CFG uiCfg; DISP_STATE_STACK disp_state_stack; @@ -1362,7 +1365,10 @@ void print_time_count() { void LV_TASK_HANDLER() { lv_task_handler(); - if (mks_test_flag == 0x1E) mks_hardware_test(); + + #if ENABLED(MKS_TEST) + if (mks_test_flag == 0x1E) mks_hardware_test(); + #endif TERN_(HAS_GCODE_PREVIEW, disp_pre_gcode(2, 36)); diff --git a/Marlin/src/lcd/extui/mks_ui/mks_hardware_test.cpp b/Marlin/src/lcd/extui/mks_ui/mks_hardware_test.cpp index bcb3cdb6a27e5..67f1eed10f9f3 100644 --- a/Marlin/src/lcd/extui/mks_ui/mks_hardware_test.cpp +++ b/Marlin/src/lcd/extui/mks_ui/mks_hardware_test.cpp @@ -27,7 +27,6 @@ #include "tft_lvgl_configuration.h" #include "draw_ready_print.h" -#include "mks_hardware_test.h" #include "draw_ui.h" #include "pic_manager.h" #include @@ -36,51 +35,51 @@ #include "../../../module/temperature.h" #include "../../../sd/cardreader.h" -uint8_t pw_det_sta, pw_off_sta, mt_det_sta, mt_det3_sta; -#if PIN_EXISTS(MT_DET_2) - uint8_t mt_det2_sta; -#endif -uint8_t endstopx1_sta, endstopx2_sta, endstopy1_sta, endstopy2_sta, endstopz1_sta, endstopz2_sta; -void test_gpio_readlevel_L() { - #if ENABLED(MKS_TEST) +#if ENABLED(MKS_TEST) + + #include "mks_hardware_test.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; + + void test_gpio_readlevel_L() { volatile uint32_t itest; WRITE(WIFI_IO0_PIN, HIGH); itest = 10000; - while (itest--); - pw_det_sta = (READ(MKS_TEST_POWER_LOSS_PIN) == 0); - pw_off_sta = (READ(MKS_TEST_PS_ON_PIN) == 0); - mt_det_sta = (READ(MT_DET_1_PIN) == 0); + while (itest--); // Counting to 10000 takes some amount of time + pw_det_sta = (READ(MKS_TEST_POWER_LOSS_PIN) == LOW); + pw_off_sta = (READ(MKS_TEST_PS_ON_PIN) == LOW); + mt_det_sta = (READ(MT_DET_1_PIN) == LOW); #if PIN_EXISTS(MT_DET_2) - mt_det2_sta = (READ(MT_DET_2_PIN) == 0); + mt_det2_sta = (READ(MT_DET_2_PIN) == LOW); #endif - endstopx1_sta = (READ(X_MIN_PIN) == 0); - endstopy1_sta = (READ(Y_MIN_PIN) == 0); - endstopz1_sta = (READ(Z_MIN_PIN) == 0); - endstopz2_sta = (READ(Z_MAX_PIN) == 0); - #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); + } -void test_gpio_readlevel_H() { - #if ENABLED(MKS_TEST) + void test_gpio_readlevel_H() { volatile uint32_t itest; WRITE(WIFI_IO0_PIN, LOW); itest = 10000; while (itest--); - pw_det_sta = (READ(MKS_TEST_POWER_LOSS_PIN) == 1); - pw_off_sta = (READ(MKS_TEST_PS_ON_PIN) == 1); - mt_det_sta = (READ(MT_DET_1_PIN) == 1); + pw_det_sta = (READ(MKS_TEST_POWER_LOSS_PIN) == HIGH); + pw_off_sta = (READ(MKS_TEST_PS_ON_PIN) == HIGH); + mt_det_sta = (READ(MT_DET_1_PIN) == HIGH); #if PIN_EXISTS(MT_DET_2) - mt_det2_sta = (READ(MT_DET_2_PIN) == 1); + mt_det2_sta = (READ(MT_DET_2_PIN) == HIGH); #endif - endstopx1_sta = (READ(X_MIN_PIN) == 1); - endstopy1_sta = (READ(Y_MIN_PIN) == 1); - endstopz1_sta = (READ(Z_MIN_PIN) == 1); - endstopz2_sta = (READ(Z_MAX_PIN) == 1); - #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); + } -void init_test_gpio() { - #ifdef MKS_TEST + void init_test_gpio() { SET_INPUT_PULLUP(X_MIN_PIN); SET_INPUT_PULLUP(Y_MIN_PIN); SET_INPUT_PULLUP(Z_MIN_PIN); @@ -102,7 +101,7 @@ void init_test_gpio() { SET_OUTPUT(Y_ENABLE_PIN); SET_OUTPUT(Z_ENABLE_PIN); SET_OUTPUT(E0_ENABLE_PIN); - #if !MB(MKS_ROBIN_E3P) + #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) SET_OUTPUT(E1_ENABLE_PIN); #endif @@ -110,11 +109,11 @@ void init_test_gpio() { WRITE(Y_ENABLE_PIN, LOW); WRITE(Z_ENABLE_PIN, LOW); WRITE(E0_ENABLE_PIN, LOW); - #if !MB(MKS_ROBIN_E3P) + #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) WRITE(E1_ENABLE_PIN, LOW); #endif - #if MB(MKS_ROBIN_E3P) + #if ENABLED(MKS_HARDWARE_TEST_ONLY_E0) SET_INPUT_PULLUP(PA1); SET_INPUT_PULLUP(PA3); SET_INPUT_PULLUP(PC2); @@ -123,68 +122,56 @@ void init_test_gpio() { SET_INPUT_PULLUP(PE6); SET_INPUT_PULLUP(PE7); #endif - #endif -} + } -void mks_test_beeper() { - #ifdef MKS_TEST + void mks_test_beeper() { WRITE(BEEPER_PIN, HIGH); delay(100); WRITE(BEEPER_PIN, LOW); delay(100); - #endif -} + } -void mks_gpio_test() { - #if ENABLED(MKS_TEST) + void mks_gpio_test() { init_test_gpio(); test_gpio_readlevel_L(); test_gpio_readlevel_H(); test_gpio_readlevel_L(); - if ((pw_det_sta == 1) - && (pw_off_sta == 1) - && (mt_det_sta == 1) + if (pw_det_sta && pw_off_sta && mt_det_sta #if PIN_EXISTS(MT_DET_2) - && (mt_det2_sta == 1) + && mt_det2_sta #endif - #if MB(MKS_ROBIN_E3P) - && (READ(PA1) == 0) - && (READ(PA3) == 0) - && (READ(PC2) == 0) - && (READ(PD8) == 0) - && (READ(PE5) == 0) - && (READ(PE6) == 0) - && (READ(PE7) == 0) + #if ENABLED(MKS_HARDWARE_TEST_ONLY_E0) + && (READ(PA1) == LOW) + && (READ(PA3) == LOW) + && (READ(PC2) == LOW) + && (READ(PD8) == LOW) + && (READ(PE5) == LOW) + && (READ(PE6) == LOW) + && (READ(PE7) == LOW) #endif ) disp_det_ok(); else disp_det_error(); - if ( (endstopx1_sta == 1) - && (endstopy1_sta == 1) - && (endstopz1_sta == 1) - && (endstopz2_sta == 1) - ) + if (endstopx1_sta && endstopy1_sta && endstopz1_sta && endstopz2_sta) disp_Limit_ok(); else disp_Limit_error(); - #endif -} + } -void mks_hardware_test() { - #if ENABLED(MKS_TEST) + void mks_hardware_test() { if (millis() % 2000 < 1000) { WRITE(X_DIR_PIN, LOW); WRITE(Y_DIR_PIN, LOW); WRITE(Z_DIR_PIN, LOW); WRITE(E0_DIR_PIN, LOW); - #if !MB(MKS_ROBIN_E3P) + #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) WRITE(E1_DIR_PIN, LOW); #endif thermalManager.fan_speed[0] = 255; - #if !MB(MKS_ROBIN_E3P) + #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) WRITE(HEATER_1_PIN, HIGH); // HE1 #endif WRITE(HEATER_0_PIN, HIGH); // HE0 @@ -195,21 +182,18 @@ void mks_hardware_test() { WRITE(Y_DIR_PIN, HIGH); WRITE(Z_DIR_PIN, HIGH); WRITE(E0_DIR_PIN, HIGH); - #if !MB(MKS_ROBIN_E3P) + #if DISABLED(MKS_HARDWARE_TEST_ONLY_E0) WRITE(E1_DIR_PIN, HIGH); #endif thermalManager.fan_speed[0] = 0; - #if !MB(MKS_ROBIN_E3P) + #if 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 ( (endstopx1_sta == 1) && (endstopx2_sta == 1) - && (endstopy1_sta == 1) && (endstopy2_sta == 1) - && (endstopz1_sta == 1) && (endstopz2_sta == 1) - ) { + if (endstopx1_sta && endstopx2_sta && endstopy1_sta && endstopy2_sta && endstopz1_sta && endstopz2_sta) { // nothing here } else { @@ -217,9 +201,9 @@ void mks_hardware_test() { if (disp_state == PRINT_READY_UI) mks_disp_test(); + } - #endif -} +#endif // MKS_TEST static const uint16_t ASCII_Table_16x24[] PROGMEM = { // Space ' ' diff --git a/Marlin/src/lcd/extui/mks_ui/mks_hardware_test.h b/Marlin/src/lcd/extui/mks_ui/mks_hardware_test.h index 0e2d8096bac9c..1b46d4b0e61e1 100644 --- a/Marlin/src/lcd/extui/mks_ui/mks_hardware_test.h +++ b/Marlin/src/lcd/extui/mks_ui/mks_hardware_test.h @@ -24,10 +24,12 @@ #include void mks_gpio_test(); +void mks_hardware_test(); +void mks_test_get(); + void disp_char_1624(uint16_t x, uint16_t y, uint8_t c, uint16_t charColor, uint16_t bkColor); void disp_string(uint16_t x, uint16_t y, const char * string, uint16_t charColor, uint16_t bkColor); -void mks_hardware_test(); void disp_assets_update(); void disp_assets_update_progress(const char *msg); -void mks_test_get(); + extern uint8_t mks_test_flag; diff --git a/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp b/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp index da7b1929cec09..03e408e32a381 100644 --- a/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp +++ b/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp @@ -27,7 +27,10 @@ #include "draw_ui.h" #include "pic_manager.h" #include "draw_ready_print.h" -#include "mks_hardware_test.h" + +#if ENABLED(MKS_TEST) + #include "mks_hardware_test.h" +#endif #include "SPIFlashStorage.h" #include "../../../libs/W25Qxx.h" diff --git a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp index 25e6ec314627f..7f84277ef07b0 100644 --- a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp @@ -139,10 +139,9 @@ void tft_lvgl_init() { #if ENABLED(SDSUPPORT) UpdateAssets(); watchdog_refresh(); // LVGL init takes time + mks_test_get(); #endif - mks_test_get(); - touch.Init(); lv_init(); @@ -232,7 +231,9 @@ void tft_lvgl_init() { if (ready) lv_draw_ready_print(); - if (mks_test_flag == 0x1E) mks_gpio_test(); + #if ENABLED(MKS_TEST) + if (mks_test_flag == 0x1E) mks_gpio_test(); + #endif } void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) { diff --git a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h index 14664bda39403..c7850903e7bfc 100644 --- a/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h +++ b/Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h @@ -36,6 +36,7 @@ #define BOARD_INFO_NAME "MKS Robin E3P" #define BOARD_NO_NATIVE_USB +#define MKS_HARDWARE_TEST_ONLY_E0 // // Release PB4 (Y_ENABLE_PIN) from JTAG NRST role