Skip to content

Commit

Permalink
✨ Ender 3 S1 Pro/Plus stock touchscreen (#25905)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <[email protected]>
  • Loading branch information
strnk and thinkyhead authored Jul 1, 2023
1 parent f766a90 commit b77e2a5
Show file tree
Hide file tree
Showing 42 changed files with 5,478 additions and 76 deletions.
6 changes: 5 additions & 1 deletion Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -3107,13 +3107,17 @@
* - Download https://github.com/InsanityAutomation/Marlin/raw/CrealityDwin_2.0/TM3D_Combined480272_Landscape_V7.7z
* - Copy the downloaded DWIN_SET folder to the SD card.
*
* E3S1PRO (T5UID1)
* - Download https://github.com/CrealityOfficial/Ender-3S1/archive/3S1_Plus_Screen.zip
* - Copy the downloaded DWIN_SET folder to the SD card.
*
* 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' ]
* :[ 'ORIGIN', 'FYSETC', 'HYPRECY', 'MKS', 'RELOADED', 'IA_CREALITY', 'E3S1PRO' ]
*/
//#define DGUS_LCD_UI ORIGIN
#if DGUS_UI_IS(MKS)
Expand Down
16 changes: 16 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -2015,6 +2015,22 @@
#define DGUS_UI_WAITING_STATUS 10
#define DGUS_UI_WAITING_STATUS_PERIOD 8 // Increase to slower waiting status looping
#endif

#elif DGUS_UI_IS(E3S1PRO)
/**
* The stock Ender-3 S1 Pro/Plus display firmware has rather poor SD file handling.
*
* The autoscroll is mainly useful for status messages, filenames, and the "About" page.
*
* NOTE: The Advanced SD Card option is affected by the stock touchscreen firmware, so
* pages 5 and up will display "4/4". This may get fixed in a screen firmware update.
*/
#define DGUS_SOFTWARE_AUTOSCROLL // Enable long text software auto-scroll
#define DGUS_AUTOSCROLL_START_CYCLES 1 // Refresh cycles without scrolling at the beginning of text strings
#define DGUS_AUTOSCROLL_END_CYCLES 1 // ... at the end of text strings

#define DGUS_ADVANCED_SDCARD // Allow more than 20 files and navigating directories
#define DGUS_USERCONFIRM // Reuse the SD Card page to show various messages
#endif
#endif // HAS_DGUS_LCD

Expand Down
76 changes: 76 additions & 0 deletions Marlin/src/core/endianness.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#pragma once

#include "../core/types.h"
#include "../core/macros.h"

#ifdef __cplusplus

namespace Endianness {
static constexpr uint32_t _dword = 0x01020304;
static constexpr uint8_t _lsb = (const uint8_t&)_dword;

static constexpr bool cpuIsLittleEndian = _lsb == 0x04;
static constexpr bool cpuIsBigEndian = _lsb == 0x01;
static_assert(cpuIsLittleEndian ^ cpuIsBigEndian, "Unknown CPU endianness");

// constexpr byte swapping for integral types
template<typename T> static constexpr typename Private::enable_if<Private::is_integral<T>::value, T>::type swap(T V, T swappedV=(T)0, size_t byteIndex=0) {
return byteIndex == sizeof(T)
? swappedV
: swap<T>((T)(V >> 8), (swappedV << 8) | (V & (T)0xFF), byteIndex + 1);
}

// constexpr byte swapping for types derived from integral types (e.g. enums)
template<typename T> static constexpr typename Private::enable_if<
Private::is_same<uint16_t, typename Private::underlying_type<T>::type>::value, T>::type swap(T V) { return (T)swap<uint16_t>((uint16_t)V); }
template<typename T> static constexpr typename Private::enable_if<
Private::is_same<uint32_t, typename Private::underlying_type<T>::type>::value, T>::type swap(T V) { return (T)swap<uint32_t>((uint32_t)V); }
template<typename T> static constexpr typename Private::enable_if<
Private::is_same<uint64_t, typename Private::underlying_type<T>::type>::value, T>::type swap(T V) { return (T)swap<uint64_t>((uint64_t)V); }

// Generic byte swapping
// CANNOT be used to initialize constexpr declarations
template<typename T> static constexpr typename Private::enable_if<!Private::is_integral<T>::value && !Private::is_enum<T>::value, T>::type swap(T V) {
union {
T val;
char byte[sizeof(T)];
} src{}, dst{};

src.val = V;
for (uint8_t i = 0; i < sizeof(T); ++i) dst.byte[i] = src.byte[sizeof(T) - i - 1];
return dst.val;
}

// Convert to / from known endianness, depending on the host endianness
template<typename T> static constexpr T toBE(T V) { return cpuIsLittleEndian ? swap(V) : V; }
template<typename T> static constexpr T toLE(T V) { return cpuIsLittleEndian ? V : swap(V); }
template<typename T> static constexpr T fromBE(T V) { return cpuIsLittleEndian ? swap(V) : V; }
template<typename T> static constexpr T fromLE(T V) { return cpuIsLittleEndian ? V : swap(V); }

// Reads a big/little endian from a pointer and converts it to the host endianness
template<typename T> static constexpr T fromBE_P(void* V) { return fromBE(*(T*)V); }
template<typename T> static constexpr T fromLE_P(void* V) { return fromLE(*(T*)V); }
};

#endif // __cplusplus
35 changes: 35 additions & 0 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,41 @@

template <typename T, typename ... Args> struct first_type_of { typedef T type; };
template <typename T> struct first_type_of<T> { typedef T type; };

// remove const/volatile type qualifiers
template<typename T> struct remove_const { typedef T type; };
template<typename T> struct remove_const<T const> { typedef T type; };

template<typename T> struct remove_volatile { typedef T type; };
template<typename T> struct remove_volatile<T volatile> { typedef T type; };

template<typename T> struct remove_cv { typedef typename remove_const<typename remove_volatile<T>::type>::type type; };

// test if type is integral
template<typename> struct _is_integral { enum { value = false }; };
template<> struct _is_integral<unsigned char> { enum { value = true }; };
template<> struct _is_integral<unsigned short> { enum { value = true }; };
template<> struct _is_integral<unsigned int> { enum { value = true }; };
template<> struct _is_integral<unsigned long> { enum { value = true }; };
template<> struct _is_integral<unsigned long long> { enum { value = true }; };
template<> struct _is_integral<char> { enum { value = true }; };
template<> struct _is_integral<short> { enum { value = true }; };
template<> struct _is_integral<int> { enum { value = true }; };
template<> struct _is_integral<long> { enum { value = true }; };
template<> struct _is_integral<long long> { enum { value = true }; };
template<typename T> struct is_integral : public _is_integral<typename remove_cv<T>::type> {};
}

// enum type check and regression to its underlying integral.
namespace Private {
template<typename T> struct is_enum { enum { value = __is_enum(T) }; };

template<typename T, bool = is_enum<T>::value> struct _underlying_type { using type = __underlying_type(T); };
template<typename T> struct _underlying_type<T, false> { };

template<typename T> struct underlying_type : public _underlying_type<T> { };
}

// C++11 solution using SFINAE to detect the existence of a member in a class at compile time.
// It creates a HasMember<Type> structure containing 'value' set to true if the member exists
#define HAS_MEMBER_IMPL(Member) \
Expand Down Expand Up @@ -712,5 +746,6 @@
#define _UI_MKS 104
#define _UI_RELOADED 105
#define _UI_IA_CREALITY 106
#define _UI_E3S1PRO 107
#define _DGUS_UI_IS(N) || (CAT(_UI_, DGUS_LCD_UI) == CAT(_UI_, N))
#define DGUS_UI_IS(V...) (0 MAP(_DGUS_UI_IS, V))
47 changes: 26 additions & 21 deletions Marlin/src/feature/runout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@ void event_filament_runout(const uint8_t extruder) {

const bool run_runout_script = !runout.host_handling;

const bool park_or_pause = (false
#ifdef FILAMENT_RUNOUT_SCRIPT
|| strstr(FILAMENT_RUNOUT_SCRIPT, "M600")
|| strstr(FILAMENT_RUNOUT_SCRIPT, "M125")
|| TERN0(ADVANCED_PAUSE_FEATURE, strstr(FILAMENT_RUNOUT_SCRIPT, "M25"))
#endif
);

#if ENABLED(HOST_ACTION_COMMANDS)
if (run_runout_script
&& ( strstr(FILAMENT_RUNOUT_SCRIPT, "M600")
|| strstr(FILAMENT_RUNOUT_SCRIPT, "M125")
|| TERN0(ADVANCED_PAUSE_FEATURE, strstr(FILAMENT_RUNOUT_SCRIPT, "M25"))
)
) {
if (run_runout_script && park_or_pause) {
hostui.paused(false);
}
else {
Expand All @@ -126,22 +129,24 @@ void event_filament_runout(const uint8_t extruder) {
SERIAL_EOL();
#endif // HOST_ACTION_COMMANDS

if (run_runout_script) {
#if MULTI_FILAMENT_SENSOR
MString<strlen(FILAMENT_RUNOUT_SCRIPT)> script;
script.setf(F(FILAMENT_RUNOUT_SCRIPT), AS_CHAR(tool));
#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
SERIAL_ECHOLNPGM("Runout Command: ", &script);
#endif
queue.inject(&script);
#else
#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
SERIAL_ECHOPGM("Runout Command: ");
SERIAL_ECHOLNPGM(FILAMENT_RUNOUT_SCRIPT);
#ifdef FILAMENT_RUNOUT_SCRIPT
if (run_runout_script) {
#if MULTI_FILAMENT_SENSOR
MString<strlen(FILAMENT_RUNOUT_SCRIPT)> script;
script.setf(F(FILAMENT_RUNOUT_SCRIPT), AS_CHAR(tool));
#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
SERIAL_ECHOLNPGM("Runout Command: ", &script);
#endif
queue.inject(&script);
#else
#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
SERIAL_ECHOPGM("Runout Command: ");
SERIAL_ECHOLNPGM(FILAMENT_RUNOUT_SCRIPT);
#endif
queue.inject(F(FILAMENT_RUNOUT_SCRIPT));
#endif
queue.inject(F(FILAMENT_RUNOUT_SCRIPT));
#endif
}
}
#endif
}

#endif // HAS_FILAMENT_SENSOR
2 changes: 2 additions & 0 deletions Marlin/src/inc/Conditionals_LCD.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
#define DGUS_LCD_UI_RELOADED 1
#elif DGUS_UI_IS(IA_CREALITY)
#define DGUS_LCD_UI_IA_CREALITY 1
#elif DGUS_UI_IS(E3S1PRO)
#define DGUS_LCD_UI_E3S1PRO 1
#endif

/**
Expand Down
1 change: 1 addition & 0 deletions Marlin/src/inc/MarlinConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "../core/utility.h"
#include "../core/mstring.h"
#include "../core/serial.h"
#include "../core/endianness.h"

#endif

Expand Down
37 changes: 36 additions & 1 deletion Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
#error "You can't enable FIL_RUNOUT8_PULLUP and FIL_RUNOUT8_PULLDOWN at the same time."
#elif FILAMENT_RUNOUT_DISTANCE_MM < 0
#error "FILAMENT_RUNOUT_DISTANCE_MM must be greater than or equal to zero."
#elif DISABLED(ADVANCED_PAUSE_FEATURE)
#elif DISABLED(ADVANCED_PAUSE_FEATURE) && defined(FILAMENT_RUNOUT_SCRIPT)
static_assert(nullptr == strstr(FILAMENT_RUNOUT_SCRIPT, "M600"), "ADVANCED_PAUSE_FEATURE is required to use M600 with FILAMENT_RUNOUT_SENSOR.");
#endif
#endif
Expand Down Expand Up @@ -3994,6 +3994,41 @@ static_assert(_PLUS_TEST(3), "DEFAULT_MAX_ACCELERATION values must be positive."
#endif
#endif

/**
* Require certain features for DGUS_LCD_UI E3S1PRO.
*/
#if DGUS_UI_IS(E3S1PRO)
#if BUFSIZE < 4
#error "DGUS_LCD_UI E3S1PRO requires a BUFSIZE of at least 4."
#elif !(HOTENDS == 1)
#error "DGUS_LCD_UI E3S1PRO requires 1 hotend."
#elif !(EXTRUDERS == 1)
#error "DGUS_LCD_UI E3S1PRO requires at least 1 extruder."
#elif !HAS_HEATED_BED
#error "DGUS_LCD_UI E3S1PRO requires a heated bed."
#elif FAN_COUNT < 1
#error "DGUS_LCD_UI E3S1PRO requires a fan."
#elif !HAS_BED_PROBE
#error "DGUS_LCD_UI E3S1PRO requires a bed probe."
#elif !HAS_MESH
#error "DGUS_LCD_UI E3S1PRO requires mesh leveling."
#elif !HAS_MEDIA
#error "DGUS_LCD_UI E3S1PRO requires SDSUPPORT."
#elif DISABLED(POWER_LOSS_RECOVERY)
#error "DGUS_LCD_UI E3S1PRO requires POWER_LOSS_RECOVERY."
#elif DISABLED(LCD_BED_TRAMMING)
#error "DGUS_LCD_UI E3S1PRO requires LCD_BED_TRAMMING."
#elif DISABLED(BABYSTEP_ALWAYS_AVAILABLE)
#error "DGUS_LCD_UI E3S1PRO requires BABYSTEP_ALWAYS_AVAILABLE."
#elif DISABLED(BABYSTEP_ZPROBE_OFFSET)
#error "DGUS_LCD_UI E3S1PRO requires BABYSTEP_ZPROBE_OFFSET."
#elif !defined(PREHEAT_1_TEMP_HOTEND) || !defined(PREHEAT_2_TEMP_HOTEND)
#error "DGUS_LCD_UI E3S1PRO requires 2 preheating presets."
#elif ENABLED(AUTO_BED_LEVELING_UBL) && DISABLED(UBL_SAVE_ACTIVE_ON_M500)
#warning "Without UBL_SAVE_ACTIVE_ON_M500, your mesh will not be saved when using the touchscreen."
#endif
#endif

// JTAG support in the HAL
#if ENABLED(DISABLE_DEBUG) && !defined(JTAGSWD_DISABLE)
#error "DISABLE_DEBUG is not supported for the selected MCU/Board."
Expand Down
10 changes: 4 additions & 6 deletions Marlin/src/lcd/extui/dgus/fysetc/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,18 @@

if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes.
switch (swap16(*(uint16_t*)val_ptr)) {
case 0: { // Resume
if (ExtUI::isPrintingFromMediaPaused()) {
ExtUI::resumePrint();
}
} break;
case 0: // Resume
if (ExtUI::isPrintingFromMediaPaused()) ExtUI::resumePrint();
break;

case 1: // Pause

gotoScreen(DGUS_SCREEN_SDPRINTMANIPULATION);
if (!ExtUI::isPrintingFromMediaPaused()) {
ExtUI::pausePrint();
//ExtUI::mks_pausePrint();
}
break;

case 2: // Abort
handleUserConfirmationPopUp(VP_SD_AbortPrintConfirmed, nullptr, PSTR("Abort printing"), filelist.filename(), PSTR("?"), true, true, false, true);
break;
Expand Down
Loading

0 comments on commit b77e2a5

Please sign in to comment.