Skip to content

Commit

Permalink
✨ CR-6 SE
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jan 22, 2024
1 parent 22fc07d commit a3367e7
Show file tree
Hide file tree
Showing 21 changed files with 2,071 additions and 59 deletions.
5 changes: 4 additions & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3173,13 +3173,16 @@
* - Download https://github.com/CrealityOfficial/Ender-3S1/archive/3S1_Plus_Screen.zip
* - Copy the downloaded DWIN_SET folder to the SD card.
*
* CREALITY_TOUCH
* - CR-6 OEM touch screen. A DWIN display with touch.
*
* Flash display with DGUS Displays for Marlin:
* - Format the SD card to FAT32 with an allocation size of 4kb.
* - Download files as specified for your type of display.
* - Plug the microSD card into the back of the display.
* - Boot the display and wait for the update to complete.
*
* :[ 'ORIGIN', 'FYSETC', 'HYPRECY', 'MKS', 'RELOADED', 'IA_CREALITY', 'E3S1PRO' ]
* :[ 'ORIGIN', 'FYSETC', 'HYPRECY', 'MKS', 'RELOADED', 'IA_CREALITY', 'E3S1PRO', 'CREALITY_TOUCH' ]
*/
//#define DGUS_LCD_UI ORIGIN
#if DGUS_UI_IS(MKS)
Expand Down
17 changes: 9 additions & 8 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,14 @@
#define HAS_E_TEMP_SENSOR (0 REPEAT(EXTRUDERS, _HAS_E_TEMP))
#define TEMP_SENSOR_IS_MAX_TC(T) (TEMP_SENSOR(T) == -5 || TEMP_SENSOR(T) == -3 || TEMP_SENSOR(T) == -2)

#define _UI_NONE 0
#define _UI_ORIGIN 101
#define _UI_FYSETC 102
#define _UI_HIPRECY 103
#define _UI_MKS 104
#define _UI_RELOADED 105
#define _UI_IA_CREALITY 106
#define _UI_E3S1PRO 107
#define _UI_NONE 0
#define _UI_ORIGIN 101
#define _UI_FYSETC 102
#define _UI_HIPRECY 103
#define _UI_MKS 104
#define _UI_RELOADED 105
#define _UI_IA_CREALITY 106
#define _UI_E3S1PRO 107
#define _UI_CREALITY_TOUCH 108
#define _DGUS_UI_IS(N) || (CAT(_UI_, DGUS_LCD_UI) == CAT(_UI_, N))
#define DGUS_UI_IS(V...) (0 MAP(_DGUS_UI_IS, V))
2 changes: 1 addition & 1 deletion Marlin/src/feature/runout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void event_filament_runout(const uint8_t extruder) {

//action:out_of_filament
#if ENABLED(HOST_PROMPT_SUPPORT)
hostui.prompt_do(PROMPT_FILAMENT_RUNOUT, F("FilamentRunout T"), tool); //action:out_of_filament
hostui.prompt_do(PROMPT_FILAMENT_RUNOUT, F("filamentRunout T"), tool); //action:out_of_filament
#endif

const bool run_runout_script = !runout.host_handling;
Expand Down
4 changes: 3 additions & 1 deletion Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,8 @@
#define DGUS_LCD_UI_IA_CREALITY 1
#elif DGUS_UI_IS(E3S1PRO)
#define DGUS_LCD_UI_E3S1PRO 1
#elif DGUS_UI_IS(CREALITY_TOUCH)
#define DGUS_LCD_UI_CREALITY_TOUCH 1
#endif

/**
Expand Down Expand Up @@ -1025,7 +1027,7 @@
// Aliases for LCD features
#if !DGUS_UI_IS(NONE) || ENABLED(ANYCUBIC_LCD_VYPER)
#define HAS_DGUS_LCD 1
#if DGUS_UI_IS(ORIGIN, FYSETC, HIPRECY, MKS)
#if DGUS_UI_IS(ORIGIN, FYSETC, HIPRECY, MKS, CREALITY_TOUCH)
#define HAS_DGUS_LCD_CLASSIC 1
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -3328,7 +3328,7 @@
#endif

// Number of VFAT entries used. Each entry has 13 UTF-16 characters
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI)
#if ANY(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2, TFT_COLOR_UI, DGUS_LCD_UI_CREALITY_TOUCH)
#define VFAT_ENTRIES_LIMIT 5
#else
#define VFAT_ENTRIES_LIMIT 2
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2633,7 +2633,7 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i
+ (DISABLED(IS_LEGACY_TFT) && ENABLED(TFT_GENERIC)) \
+ (ENABLED(IS_LEGACY_TFT) && COUNT_ENABLED(TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI)) \
+ COUNT_ENABLED(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON, ANYCUBIC_TFT35, ANYCUBIC_LCD_VYPER) \
+ 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(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) \
+ COUNT_ENABLED(ENDER2_STOCKDISPLAY, CR10_STOCKDISPLAY) \
+ COUNT_ENABLED(DWIN_CREALITY_LCD, DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI, DWIN_MARLINUI_PORTRAIT, DWIN_MARLINUI_LANDSCAPE) \
+ COUNT_ENABLED(FYSETC_MINI_12864_X_X, FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_GENERIC_12864_1_1) \
Expand Down
68 changes: 63 additions & 5 deletions Marlin/src/lcd/extui/dgus/DGUSDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,27 @@ void DGUSDisplay::initDisplay() {
requestScreen(TERN(SHOW_BOOTSCREEN, DGUS_SCREEN_BOOT, DGUS_SCREEN_MAIN));
}

#if DGUS_LCD_UI_CREALITY_TOUCH

DGUS_ScreenID DGUSDisplay::displayRequest = DGUS_SCREEN_BOOT;

void DGUSDisplay::readCurrentScreen() { readVariable(0x14 /*PIC_NOW*/); }

void DGUSDisplay::resetDisplay() {
DEBUG_ECHOLNPGM("resetDisplay");
const unsigned char resetCommand[] = { 0x55, 0xAA, 0x5A, 0xA5 };
writeVariable(0x04, resetCommand, sizeof(resetCommand));
}

void DGUSDisplay::readVariable(uint16_t adr) {
writeHeader(adr, DGUS_CMD_READVAR, sizeof(uint8_t));

// Specify to read one byte
LCD_SERIAL.write(static_cast<uint8_t>(1));
}

#endif

void DGUSDisplay::writeVariable(uint16_t adr, const void *values, uint8_t valueslen, bool isstr) {
const char* myvalues = static_cast<const char*>(values);
bool strend = !myvalues;
Expand Down Expand Up @@ -204,11 +225,48 @@ void DGUSDisplay::processRx() {
| Command DataLen (in Words) */
if (command == DGUS_CMD_READVAR) {
const uint16_t vp = tmp[0] << 8 | tmp[1];
DGUS_VP_Variable ramcopy;
if (populate_VPVar(vp, &ramcopy)) {
if (ramcopy.set_by_display_handler)
ramcopy.set_by_display_handler(ramcopy, &tmp[3]);
}

#if DGUS_LCD_UI_CREALITY_TOUCH

if (vp == 0x14 /*PIC_Now*/) {
const uint16_t screen_id = tmp[3] << 8 | tmp[4];
// In the code below DGUS_SCREEN_BOOT acts as a sentinel
if (screen_id == 255) {
// DGUS OS sometimes randomly sends 255 back as an answer. Possible buffer overrun?
readCurrentScreen(); // Request again
}
else if (displayRequest != DGUS_SCREEN_BOOT && screen_id != displayRequest) {
// 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.
// 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
DEBUG_ECHOPGM(" Got a response on the current screen: ", screen_id);
DEBUG_ECHOLNPGM(" - however, we've requested screen ", displayRequest);
}
else {
displayRequest = DGUS_SCREEN_BOOT;
if (current_screen_update_callback)
current_screen_update_callback(static_cast<DGUS_ScreenID>(screen_id));
}
}
else {
DGUS_VP_Variable ramcopy;
if (populate_VPVar(vp, &ramcopy)) {
if (ramcopy.set_by_display_handler)
ramcopy.set_by_display_handler(ramcopy, &tmp[3]);
}

// Always ask for a screen update so we can send a screen update earlier, this prevents a flash of unstyled screen
readCurrentScreen();
}

#else

DGUS_VP_Variable ramcopy;
if (populate_VPVar(vp, &ramcopy)) {
if (ramcopy.set_by_display_handler)
ramcopy.set_by_display_handler(ramcopy, &tmp[3]);
}

#endif

rx_datagram_state = DGUS_IDLE;
break;
Expand Down
31 changes: 27 additions & 4 deletions Marlin/src/lcd/extui/dgus/DGUSDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ typedef enum : uint8_t {

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

#if DGUS_LCD_UI_CREALITY_TOUCH
typedef void (*screenUpdateCallback_t)(DGUS_ScreenID screen);
#endif

// Low-Level access to the display.
class DGUSDisplay {
public:

DGUSDisplay() = default;

static void initDisplay();
#if DGUS_LCD_UI_CREALITY_TOUCH
static void resetDisplay();
#endif

// Variable access.
static void writeVariable(uint16_t adr, const void *values, uint8_t valueslen, bool isstr=false);
Expand All @@ -68,7 +75,13 @@ class DGUSDisplay {
static void writeVariable(uint16_t adr, int8_t value);
static void writeVariable(uint16_t adr, long value);

// Utility functions for bridging ui_api and dbus
#if DGUS_LCD_UI_CREALITY_TOUCH
// Until now I did not need to actively read from the display.
// (I extensively use the auto upload of the display)
static void readVariable(uint16_t adr);
#endif

// Utility functions for bridging ui_api and dgus
template<typename T, float(*Getter)(const T), T selector, typename WireType=uint16_t>
static void setVariable(DGUS_VP_Variable &var) {
writeVariable(var.VP, (WireType)Getter(selector));
Expand All @@ -80,14 +93,16 @@ class DGUSDisplay {
Setter(newvalue, selector);
}

// Until now I did not need to actively read from the display. That's why there is no ReadVariable
// (I extensively use the auto upload of the display)

// Force display into another screen.
// (And trigger update of containing VPs)
// (to implement a pop up message, which may not be nested)
static void requestScreen(const DGUS_ScreenID screenID);

#if DGUS_LCD_UI_CREALITY_TOUCH
// Request the current displayed screen - will be passed to current_screen_update_callback
static void readCurrentScreen();
#endif

// Periodic tasks, eg. Rx-Queue handling.
static void loop();

Expand All @@ -99,6 +114,10 @@ class DGUSDisplay {
// (both boils down that the display answered to our chatting)
static bool isInitialized() { return initialized; }

#if DGUS_LCD_UI_CREALITY_TOUCH
static screenUpdateCallback_t current_screen_update_callback;
#endif

private:
static void writeHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen);
static void writePGM(const char str[], uint8_t len);
Expand All @@ -107,6 +126,10 @@ class DGUSDisplay {
static rx_datagram_state_t rx_datagram_state;
static uint8_t rx_datagram_len;
static bool initialized, no_reentrance;

#if DGUS_LCD_UI_CREALITY_TOUCH
static DGUS_ScreenID displayRequest;
#endif
};

extern DGUSDisplay dgus;
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/lcd/extui/dgus/DGUSDisplayDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,6 @@ extern const struct DGUS_VP_Variable ListOfVP[];
#include "fysetc/DGUSDisplayDef.h"
#elif DGUS_LCD_UI_HIPRECY
#include "hiprecy/DGUSDisplayDef.h"
#elif DGUS_LCD_UI_CREALITY_TOUCH
#include "creality/DGUSDisplayDef.h"
#endif
2 changes: 2 additions & 0 deletions Marlin/src/lcd/extui/dgus/DGUSScreenHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#include "fysetc/DGUSScreenHandler.h"
#elif DGUS_LCD_UI_HIPRECY
#include "hiprecy/DGUSScreenHandler.h"
#elif DGUS_LCD_UI_CREALITY_TOUCH
#include "creality/DGUSScreenHandler.h"
#endif

extern DGUSScreenHandlerClass screen;
Expand Down
Loading

0 comments on commit a3367e7

Please sign in to comment.