Skip to content

Commit ae1e325

Browse files
committed
✨ CR-6 SE
1 parent 585cbbb commit ae1e325

20 files changed

+2067
-59
lines changed

Marlin/Configuration.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3265,13 +3265,16 @@
32653265
* - Download https://github.com/CrealityOfficial/Ender-3S1/archive/3S1_Plus_Screen.zip
32663266
* - Copy the downloaded DWIN_SET folder to the SD card.
32673267
*
3268+
* CREALITY_TOUCH
3269+
* - CR-6 OEM touch screen. A DWIN display with touch.
3270+
*
32683271
* Flash display with DGUS Displays for Marlin:
32693272
* - Format the SD card to FAT32 with an allocation size of 4kb.
32703273
* - Download files as specified for your type of display.
32713274
* - Plug the microSD card into the back of the display.
32723275
* - Boot the display and wait for the update to complete.
32733276
*
3274-
* :[ 'ORIGIN', 'FYSETC', 'HYPRECY', 'MKS', 'RELOADED', 'IA_CREALITY', 'E3S1PRO' ]
3277+
* :[ 'ORIGIN', 'FYSETC', 'HYPRECY', 'MKS', 'RELOADED', 'IA_CREALITY', 'E3S1PRO', 'CREALITY_TOUCH' ]
32753278
*/
32763279
//#define DGUS_LCD_UI ORIGIN
32773280
#if DGUS_UI_IS(MKS)

Marlin/src/core/macros.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -756,13 +756,14 @@
756756
#define HAS_E_TEMP_SENSOR (0 REPEAT(EXTRUDERS, _HAS_E_TEMP))
757757
#define TEMP_SENSOR_IS_MAX_TC(T) (TEMP_SENSOR(T) == -5 || TEMP_SENSOR(T) == -3 || TEMP_SENSOR(T) == -2)
758758

759-
#define _UI_NONE 0
760-
#define _UI_ORIGIN 101
761-
#define _UI_FYSETC 102
762-
#define _UI_HIPRECY 103
763-
#define _UI_MKS 104
764-
#define _UI_RELOADED 105
765-
#define _UI_IA_CREALITY 106
766-
#define _UI_E3S1PRO 107
759+
#define _UI_NONE 0
760+
#define _UI_ORIGIN 101
761+
#define _UI_FYSETC 102
762+
#define _UI_HIPRECY 103
763+
#define _UI_MKS 104
764+
#define _UI_RELOADED 105
765+
#define _UI_IA_CREALITY 106
766+
#define _UI_E3S1PRO 107
767+
#define _UI_CREALITY_TOUCH 108
767768
#define _DGUS_UI_IS(N) || (CAT(_UI_, DGUS_LCD_UI) == CAT(_UI_, N))
768769
#define DGUS_UI_IS(V...) (0 MAP(_DGUS_UI_IS, V))

Marlin/src/inc/Conditionals-2-LCD.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@
9292
#define DGUS_LCD_UI_IA_CREALITY 1
9393
#elif DGUS_UI_IS(E3S1PRO)
9494
#define DGUS_LCD_UI_E3S1PRO 1
95+
#elif DGUS_UI_IS(CREALITY_TOUCH)
96+
#define DGUS_LCD_UI_CREALITY_TOUCH 1
9597
#endif
9698

9799
/**
@@ -543,7 +545,7 @@
543545
// Aliases for LCD features
544546
#if !DGUS_UI_IS(NONE) || ENABLED(ANYCUBIC_LCD_VYPER)
545547
#define HAS_DGUS_LCD 1
546-
#if DGUS_UI_IS(ORIGIN, FYSETC, HIPRECY, MKS)
548+
#if DGUS_UI_IS(ORIGIN, FYSETC, HIPRECY, MKS, CREALITY_TOUCH)
547549
#define HAS_DGUS_LCD_CLASSIC 1
548550
#endif
549551
#endif

Marlin/src/inc/Conditionals-5-post.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3482,7 +3482,7 @@
34823482
#endif
34833483

34843484
// Number of VFAT entries used. Each entry has 13 UTF-16 characters
3485-
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI)
3485+
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI, DGUS_LCD_UI_CREALITY_TOUCH)
34863486
#define VFAT_ENTRIES_LIMIT 5
34873487
#else
34883488
#define VFAT_ENTRIES_LIMIT 2

Marlin/src/inc/SanityCheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,7 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i
28092809
+ (DISABLED(IS_LEGACY_TFT) && ENABLED(TFT_GENERIC)) \
28102810
+ (ENABLED(IS_LEGACY_TFT) && COUNT_ENABLED(TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI)) \
28112811
+ COUNT_ENABLED(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON, ANYCUBIC_TFT35, ANYCUBIC_LCD_VYPER) \
2812-
+ DGUS_UI_IS(ORIGIN) + DGUS_UI_IS(FYSETC) + DGUS_UI_IS(HIPRECY) + DGUS_UI_IS(MKS) + DGUS_UI_IS(RELOADED) + DGUS_UI_IS(IA_CREALITY) \
2812+
+ DGUS_UI_IS(ORIGIN) + DGUS_UI_IS(FYSETC) + DGUS_UI_IS(HIPRECY) + DGUS_UI_IS(MKS) + DGUS_UI_IS(RELOADED) + DGUS_UI_IS(IA_CREALITY) + DGUS_UI_IS(CREALITY_TOUCH) \
28132813
+ COUNT_ENABLED(ENDER2_STOCKDISPLAY, CR10_STOCKDISPLAY) \
28142814
+ COUNT_ENABLED(DWIN_CREALITY_LCD, DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI, DWIN_MARLINUI_PORTRAIT, DWIN_MARLINUI_LANDSCAPE, SOVOL_SV06_RTS) \
28152815
+ COUNT_ENABLED(FYSETC_MINI_12864_X_X, FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_GENERIC_12864_1_1) \

Marlin/src/lcd/extui/dgus/DGUSDisplay.cpp

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,27 @@ void DGUSDisplay::writeVariable(uint16_t adr, const void *values, uint8_t values
106106
}
107107
}
108108

109+
#if DGUS_LCD_UI_CREALITY_TOUCH
110+
111+
DGUS_ScreenID DGUSDisplay::displayRequest = DGUS_SCREEN_BOOT;
112+
113+
void DGUSDisplay::readCurrentScreen() { readVariable(0x14 /*PIC_NOW*/); }
114+
115+
void DGUSDisplay::resetDisplay() {
116+
DEBUG_ECHOLNPGM("resetDisplay");
117+
const unsigned char resetCommand[] = { 0x55, 0xAA, 0x5A, 0xA5 };
118+
writeVariable(0x04, resetCommand, sizeof(resetCommand));
119+
}
120+
121+
void DGUSDisplay::readVariable(uint16_t adr) {
122+
writeHeader(adr, DGUS_CMD_READVAR, sizeof(uint8_t));
123+
124+
// Specify to read one byte
125+
LCD_SERIAL.write(static_cast<uint8_t>(1));
126+
}
127+
128+
#endif // DWIN_CREALITY_TOUCHLCD
129+
109130
void DGUSDisplay::writeVariable(uint16_t adr, uint16_t value) {
110131
value = (value & 0xFFU) << 8U | (value >> 8U);
111132
writeVariable(adr, static_cast<const void*>(&value), sizeof(uint16_t));
@@ -204,11 +225,48 @@ void DGUSDisplay::processRx() {
204225
| Command DataLen (in Words) */
205226
if (command == DGUS_CMD_READVAR) {
206227
const uint16_t vp = tmp[0] << 8 | tmp[1];
207-
DGUS_VP_Variable ramcopy;
208-
if (populate_VPVar(vp, &ramcopy)) {
209-
if (ramcopy.set_by_display_handler)
210-
ramcopy.set_by_display_handler(ramcopy, &tmp[3]);
211-
}
228+
229+
#if DGUS_LCD_UI_CREALITY_TOUCH
230+
231+
if (vp == 0x14 /*PIC_Now*/) {
232+
const uint16_t screen_id = tmp[3] << 8 | tmp[4];
233+
// In the code below DGUS_SCREEN_BOOT acts as a sentinel
234+
if (screen_id == 255) {
235+
// DGUS OS sometimes randomly sends 255 back as an answer. Possible buffer overrun?
236+
readCurrentScreen(); // Request again
237+
}
238+
else if (displayRequest != DGUS_SCREEN_BOOT && screen_id != displayRequest) {
239+
// A display was requested. If the screen didn't yet switch to that display, we won't give that value back, otherwise the code gets confused.
240+
// The DWIN display mostly honours the PIC_SET requests from the firmware, so after a while we may want to nudge it to the correct screen
241+
DEBUG_ECHOPGM(" Got a response on the current screen: ", screen_id);
242+
DEBUG_ECHOLNPGM(" - however, we've requested screen ", displayRequest);
243+
}
244+
else {
245+
displayRequest = DGUS_SCREEN_BOOT;
246+
if (current_screen_update_callback)
247+
current_screen_update_callback(static_cast<DGUS_ScreenID>(screen_id));
248+
}
249+
}
250+
else {
251+
DGUS_VP_Variable ramcopy;
252+
if (populate_VPVar(vp, &ramcopy)) {
253+
if (ramcopy.set_by_display_handler)
254+
ramcopy.set_by_display_handler(ramcopy, &tmp[3]);
255+
}
256+
257+
// Always ask for a screen update so we can send a screen update earlier, this prevents a flash of unstyled screen
258+
readCurrentScreen();
259+
}
260+
261+
#else // !DWIN_CREALITY_TOUCHLCD
262+
263+
DGUS_VP_Variable ramcopy;
264+
if (populate_VPVar(vp, &ramcopy)) {
265+
if (ramcopy.set_by_display_handler)
266+
ramcopy.set_by_display_handler(ramcopy, &tmp[3]);
267+
}
268+
269+
#endif
212270

213271
rx_datagram_state = DGUS_IDLE;
214272
break;

Marlin/src/lcd/extui/dgus/DGUSDisplay.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,20 @@ typedef enum : uint8_t {
5151

5252
constexpr uint16_t swap16(const uint16_t value) { return (value & 0xFFU) << 8U | (value >> 8U); }
5353

54+
#if DGUS_LCD_UI_CREALITY_TOUCH
55+
typedef void (*screenUpdateCallback_t)(DGUS_ScreenID screen);
56+
#endif
57+
5458
// Low-Level access to the display.
5559
class DGUSDisplay {
5660
public:
5761

5862
DGUSDisplay() = default;
5963

6064
static void initDisplay();
65+
#if DGUS_LCD_UI_CREALITY_TOUCH
66+
static void resetDisplay();
67+
#endif
6168

6269
// Variable access.
6370
static void writeVariable_P(uint16_t adr, const void *values, uint8_t valueslen, bool isstr=false);
@@ -85,6 +92,12 @@ class DGUSDisplay {
8592
writeVariable(adr, (const void *)zhstr, vallen, true);
8693
}
8794

95+
#if DGUS_LCD_UI_CREALITY_TOUCH
96+
// Until now I did not need to actively read from the display.
97+
// (I extensively use the auto upload of the display)
98+
static void readVariable(uint16_t adr);
99+
#endif
100+
88101
// Utility functions for bridging ui_api and dgus
89102
template<typename T, float(*Getter)(const T), T selector, typename WireType=uint16_t>
90103
static void setVariable(DGUS_VP_Variable &var) {
@@ -97,14 +110,16 @@ class DGUSDisplay {
97110
Setter(newvalue, selector);
98111
}
99112

100-
// Until now I did not need to actively read from the display. That's why there is no ReadVariable
101-
// (I extensively use the auto upload of the display)
102-
103113
// Force display into another screen.
104114
// (And trigger update of containing VPs)
105115
// (to implement a pop up message, which may not be nested)
106116
static void requestScreen(const DGUS_ScreenID screenID);
107117

118+
#if DGUS_LCD_UI_CREALITY_TOUCH
119+
// Request the current displayed screen - will be passed to current_screen_update_callback
120+
static void readCurrentScreen();
121+
#endif
122+
108123
// Periodic tasks, eg. Rx-Queue handling.
109124
static void loop();
110125

@@ -116,6 +131,10 @@ class DGUSDisplay {
116131
// (both boils down that the display answered to our chatting)
117132
static bool isInitialized() { return initialized; }
118133

134+
#if DGUS_LCD_UI_CREALITY_TOUCH
135+
static screenUpdateCallback_t current_screen_update_callback;
136+
#endif
137+
119138
private:
120139
static void writeHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen);
121140
static void writePGM(const char str[], uint8_t len);
@@ -124,6 +143,10 @@ class DGUSDisplay {
124143
static rx_datagram_state_t rx_datagram_state;
125144
static uint8_t rx_datagram_len;
126145
static bool initialized, no_reentrance;
146+
147+
#if DGUS_LCD_UI_CREALITY_TOUCH
148+
static DGUS_ScreenID displayRequest;
149+
#endif
127150
};
128151

129152
extern DGUSDisplay dgus;

Marlin/src/lcd/extui/dgus/DGUSDisplayDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ extern const struct DGUS_VP_Variable ListOfVP[];
5454
#include "fysetc/DGUSDisplayDef.h"
5555
#elif DGUS_LCD_UI_HIPRECY
5656
#include "hiprecy/DGUSDisplayDef.h"
57+
#elif DGUS_LCD_UI_CREALITY_TOUCH
58+
#include "creality/DGUSDisplayDef.h"
5759
#endif

Marlin/src/lcd/extui/dgus/DGUSScreenHandler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
#include "fysetc/DGUSScreenHandler.h"
5555
#elif DGUS_LCD_UI_HIPRECY
5656
#include "hiprecy/DGUSScreenHandler.h"
57+
#elif DGUS_LCD_UI_CREALITY_TOUCH
58+
#include "creality/DGUSScreenHandler.h"
5759
#endif
5860

5961
extern DGUSScreenHandlerClass screen;

0 commit comments

Comments
 (0)