Skip to content

Commit

Permalink
Multi-platform DWIN_CREALITY_LCD support (MarlinFirmware#20738)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
2 people authored and zillarob committed Feb 25, 2021
1 parent 6f16931 commit a09ce8b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 23 deletions.
5 changes: 3 additions & 2 deletions Marlin/src/HAL/STM32F1/HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@
#else
#error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#endif

#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
#if HAS_DGUS_LCD
#define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
#endif
#endif

// Set interrupt grouping for this MCU
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,9 @@

#if ENABLED(DWIN_CREALITY_LCD)
#define SERIAL_CATCHALL 0
#ifndef LCD_SERIAL_PORT
#define LCD_SERIAL_PORT 3 // Creality 4.x board
#endif
#endif

/**
Expand Down
15 changes: 11 additions & 4 deletions Marlin/src/lcd/dwin/dwin_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,27 @@ inline void DWIN_String(size_t &i, const __FlashStringHelper * string) {
// Send the data in the buffer and the packet end
inline void DWIN_Send(size_t &i) {
++i;
LOOP_L_N(n, i) { MYSERIAL1.write(DWIN_SendBuf[n]); delayMicroseconds(1); }
LOOP_L_N(n, 4) { MYSERIAL1.write(DWIN_BufTail[n]); delayMicroseconds(1); }
LOOP_L_N(n, i) { LCD_SERIAL.write(DWIN_SendBuf[n]); delayMicroseconds(1); }
LOOP_L_N(n, 4) { LCD_SERIAL.write(DWIN_BufTail[n]); delayMicroseconds(1); }
}

/*-------------------------------------- System variable function --------------------------------------*/

// Handshake (1: Success, 0: Fail)
bool DWIN_Handshake(void) {
#ifndef LCD_BAUDRATE
#define LCD_BAUDRATE 115200
#endif
LCD_SERIAL.begin(LCD_BAUDRATE);
const millis_t serial_connect_timeout = millis() + 1000UL;
while (!LCD_SERIAL && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }

size_t i = 0;
DWIN_Byte(i, 0x00);
DWIN_Send(i);

while (MYSERIAL1.available() > 0 && recnum < (signed)sizeof(databuf)) {
databuf[recnum] = MYSERIAL1.read();
while (LCD_SERIAL.available() > 0 && recnum < (signed)sizeof(databuf)) {
databuf[recnum] = LCD_SERIAL.read();
// ignore the invalid data
if (databuf[0] != FHONE) { // prevent the program from running.
if (recnum > 0) {
Expand Down
21 changes: 14 additions & 7 deletions Marlin/src/lcd/dwin/e3v2/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,14 +497,21 @@ inline void Draw_Back_First(const bool is_sel=true) {
if (is_sel) Draw_Menu_Cursor(0);
}

inline bool Apply_Encoder(const ENCODER_DiffState &encoder_diffState, auto &valref) {
if (encoder_diffState == ENCODER_DIFF_CW)
valref += EncoderRate.encoderMoveValue;
else if (encoder_diffState == ENCODER_DIFF_CCW)
valref -= EncoderRate.encoderMoveValue;
else if (encoder_diffState == ENCODER_DIFF_ENTER)
return true;
#define APPLY_ENCODER_F \
if (encoder_diffState == ENCODER_DIFF_CW) \
valref += EncoderRate.encoderMoveValue; \
else if (encoder_diffState == ENCODER_DIFF_CCW) \
valref -= EncoderRate.encoderMoveValue; \
else if (encoder_diffState == ENCODER_DIFF_ENTER) \
return true; \
return false;

inline bool Apply_Encoder(const ENCODER_DiffState &encoder_diffState, int16_t &valref) {
APPLY_ENCODER_F
}

inline bool Apply_Encoder(const ENCODER_DiffState &encoder_diffState, float &valref) {
APPLY_ENCODER_F
}

//
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/lcd/dwin/e3v2/dwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ typedef struct {
float Move_E_scale = 0;
#endif
float offset_value = 0;
char show_mode = 0; // -1: Temperature control 0: Printing temperature
TERN_(__STM32F1__, signed)
char show_mode = 0; // -1: Temperature control 0: Printing temperature
} HMI_value_t;

#define DWIN_CHINESE 123
Expand Down
15 changes: 6 additions & 9 deletions Marlin/src/lcd/extui/lib/anycubic_i3mega/anycubic_i3mega_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,15 +592,12 @@ void AnycubicTFTClass::GetCommandFromTFT() {
} break;

case 5: { // A5 GET CURRENT COORDINATE
float xPostition = ExtUI::getAxisPosition_mm(ExtUI::X);
float yPostition = ExtUI::getAxisPosition_mm(ExtUI::Y);
float zPostition = ExtUI::getAxisPosition_mm(ExtUI::Z);
SEND_PGM("A5V X: ");
LCD_SERIAL.print(xPostition);
SEND_PGM(" Y: ");
LCD_SERIAL.print(yPostition);
SEND_PGM(" Z: ");
LCD_SERIAL.print(zPostition);
const float xPosition = ExtUI::getAxisPosition_mm(ExtUI::X),
yPosition = ExtUI::getAxisPosition_mm(ExtUI::Y),
zPosition = ExtUI::getAxisPosition_mm(ExtUI::Z);
SEND_PGM("A5V X: "); LCD_SERIAL.print(xPosition);
SEND_PGM( " Y: "); LCD_SERIAL.print(yPosition);
SEND_PGM( " Z: "); LCD_SERIAL.print(zPosition);
SENDLINE_PGM("");
} break;

Expand Down

0 comments on commit a09ce8b

Please sign in to comment.