Skip to content

Commit

Permalink
Tweak MKS hardware test
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jun 24, 2021
1 parent c347ebd commit c226226
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 85 deletions.
5 changes: 4 additions & 1 deletion Marlin/src/lcd/extui/mks_ui/draw_error_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 4 additions & 1 deletion Marlin/src/lcd/extui/mks_ui/draw_ready_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "draw_tool.h"
#include <lv_conf.h>
#include "tft_lvgl_configuration.h"
#include "mks_hardware_test.h"
#include "draw_ui.h"

#include <lvgl.h>
Expand All @@ -40,6 +39,10 @@
#include "draw_touch_calibration.h"
#endif

#if ENABLED(MKS_TEST)
#include "mks_hardware_test.h"
#endif

#include <stdio.h>

#define ICON_POS_Y 38
Expand Down
10 changes: 8 additions & 2 deletions Marlin/src/lcd/extui/mks_ui/draw_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "pic_manager.h"

#include "draw_ui.h"
#include "mks_hardware_test.h"

#include <SPI.h>

Expand All @@ -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;
Expand Down Expand Up @@ -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));

Expand Down
134 changes: 59 additions & 75 deletions Marlin/src/lcd/extui/mks_ui/mks_hardware_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <lvgl.h>
Expand All @@ -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);
Expand All @@ -102,19 +101,19 @@ 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

WRITE(X_ENABLE_PIN, LOW);
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);
Expand All @@ -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
Expand All @@ -195,31 +182,28 @@ 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 {
}

if (disp_state == PRINT_READY_UI)
mks_disp_test();
}

#endif
}
#endif // MKS_TEST

static const uint16_t ASCII_Table_16x24[] PROGMEM = {
// Space ' '
Expand Down
6 changes: 4 additions & 2 deletions Marlin/src/lcd/extui/mks_ui/mks_hardware_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
#include <lvgl.h>

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;
5 changes: 4 additions & 1 deletion Marlin/src/lcd/extui/mks_ui/pic_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/pins/stm32f1/pins_MKS_ROBIN_E3P.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c226226

Please sign in to comment.