Browse Source

✨ Ender-3 V2 with Jyers UI (#22422)

Jyers 2 years ago
parent
commit
43a9c71ef7
No account linked to committer's email address

+ 5
- 0
Marlin/Configuration.h View File

@@ -2757,6 +2757,11 @@
2757 2757
 //#define DWIN_CREALITY_LCD
2758 2758
 
2759 2759
 //
2760
+// Ender-3 v2 OEM display with enhancements by Jacob Myers
2761
+//
2762
+//#define DWIN_CREALITY_LCD_JYERSUI
2763
+
2764
+//
2760 2765
 // MarlinUI for Creality's DWIN display (and others)
2761 2766
 //
2762 2767
 //#define DWIN_MARLINUI_PORTRAIT

+ 1
- 1
Marlin/Configuration_adv.h View File

@@ -1196,7 +1196,7 @@
1196 1196
 
1197 1197
 // @section lcd
1198 1198
 
1199
-#if EITHER(IS_ULTIPANEL, EXTENSIBLE_UI)
1199
+#if ANY(HAS_LCD_MENU, EXTENSIBLE_UI, HAS_DWIN_E3V2)
1200 1200
   #define MANUAL_FEEDRATE { 50*60, 50*60, 4*60, 2*60 } // (mm/min) Feedrates for manual moves along X, Y, Z, E from panel
1201 1201
   #define FINE_MANUAL_MOVE 0.025    // (mm) Smallest manual move (< 0.1mm) applying to Z on most machines
1202 1202
   #if IS_ULTIPANEL

+ 3
- 0
Marlin/src/MarlinCore.cpp View File

@@ -77,6 +77,9 @@
77 77
 #if ENABLED(DWIN_CREALITY_LCD)
78 78
   #include "lcd/e3v2/creality/dwin.h"
79 79
   #include "lcd/e3v2/creality/rotary_encoder.h"
80
+#elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
81
+  #include "lcd/e3v2/jyersui/dwin.h"
82
+  #include "lcd/e3v2/jyersui/rotary_encoder.h"
80 83
 #endif
81 84
 
82 85
 #if ENABLED(EXTENSIBLE_UI)

+ 4
- 0
Marlin/src/gcode/feature/powerloss/M1000.cpp View File

@@ -30,6 +30,8 @@
30 30
 #include "../../../lcd/marlinui.h"
31 31
 #if ENABLED(EXTENSIBLE_UI)
32 32
   #include "../../../lcd/extui/ui_api.h"
33
+#elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
34
+  #include "../../../lcd/e3v2/jyersui/dwin.h" // Temporary fix until it can be better implemented
33 35
 #endif
34 36
 
35 37
 #define DEBUG_OUT ENABLED(DEBUG_POWER_LOSS_RECOVERY)
@@ -64,6 +66,8 @@ void GcodeSuite::M1000() {
64 66
         ui.goto_screen(menu_job_recovery);
65 67
       #elif ENABLED(DWIN_CREALITY_LCD)
66 68
         recovery.dwin_flag = true;
69
+      #elif ENABLED(DWIN_CREALITY_LCD_JYERSUI) // Temporary fix until it can be better implemented
70
+        CrealityDWIN.Popup_Handler(Resume);
67 71
       #elif ENABLED(EXTENSIBLE_UI)
68 72
         ExtUI::onPowerLossResume();
69 73
       #else

+ 7
- 3
Marlin/src/inc/Conditionals_LCD.h View File

@@ -493,6 +493,10 @@
493 493
 #endif
494 494
 
495 495
 // Aliases for LCD features
496
+#if ANY(DWIN_CREALITY_LCD, DWIN_CREALITY_LCD_JYERSUI)
497
+  #define HAS_DWIN_E3V2 1
498
+#endif
499
+
496 500
 #if IS_ULTRA_LCD
497 501
   #define HAS_WIRED_LCD 1
498 502
   #if ENABLED(DOGLCD)
@@ -507,11 +511,11 @@
507 511
   #endif
508 512
 #endif
509 513
 
510
-#if EITHER(HAS_WIRED_LCD, EXTENSIBLE_UI)
514
+#if ANY(HAS_WIRED_LCD, EXTENSIBLE_UI, DWIN_CREALITY_LCD_JYERSUI)
511 515
   #define HAS_DISPLAY 1
512 516
 #endif
513 517
 
514
-#if ANY(HAS_DISPLAY, DWIN_CREALITY_LCD, GLOBAL_STATUS_MESSAGE)
518
+#if ANY(HAS_DISPLAY, HAS_DWIN_E3V2, GLOBAL_STATUS_MESSAGE)
515 519
   #define HAS_STATUS_MESSAGE 1
516 520
 #endif
517 521
 
@@ -1101,7 +1105,7 @@
1101 1105
   #define HAS_ETHERNET 1
1102 1106
 #endif
1103 1107
 
1104
-#if EITHER(DWIN_CREALITY_LCD, IS_DWIN_MARLINUI)
1108
+#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
1105 1109
   #define SERIAL_CATCHALL 0
1106 1110
   #ifndef LCD_SERIAL_PORT
1107 1111
     #if MB(BTT_SKR_MINI_E3_V1_0, BTT_SKR_MINI_E3_V1_2, BTT_SKR_MINI_E3_V2_0, BTT_SKR_E3_TURBO)

+ 1
- 1
Marlin/src/inc/Conditionals_adv.h View File

@@ -594,7 +594,7 @@
594 594
 #if EITHER(MIN_SOFTWARE_ENDSTOPS, MAX_SOFTWARE_ENDSTOPS)
595 595
   #define HAS_SOFTWARE_ENDSTOPS 1
596 596
 #endif
597
-#if ANY(EXTENSIBLE_UI, IS_NEWPANEL, EMERGENCY_PARSER, HAS_ADC_BUTTONS, DWIN_CREALITY_LCD)
597
+#if ANY(EXTENSIBLE_UI, IS_NEWPANEL, EMERGENCY_PARSER, HAS_ADC_BUTTONS, HAS_DWIN_E3V2)
598 598
   #define HAS_RESUME_CONTINUE 1
599 599
 #endif
600 600
 

+ 7
- 3
Marlin/src/inc/Conditionals_post.h View File

@@ -421,6 +421,10 @@
421 421
   #endif
422 422
 #endif
423 423
 
424
+#if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
425
+  #define HAS_LCD_BRIGHTNESS 1
426
+#endif
427
+
424 428
 /**
425 429
  * Override the SD_DETECT_STATE set in Configuration_adv.h
426 430
  * and enable sharing of onboard SD host drives (all platforms but AGCM4)
@@ -2828,7 +2832,7 @@
2828 2832
   #define HAS_TEMPERATURE 1
2829 2833
 #endif
2830 2834
 
2831
-#if HAS_TEMPERATURE && EITHER(HAS_LCD_MENU, DWIN_CREALITY_LCD)
2835
+#if HAS_TEMPERATURE && EITHER(HAS_LCD_MENU, HAS_DWIN_E3V2)
2832 2836
   #ifdef PREHEAT_6_LABEL
2833 2837
     #define PREHEAT_COUNT 6
2834 2838
   #elif defined(PREHEAT_5_LABEL)
@@ -2949,7 +2953,7 @@
2949 2953
  * Advanced Pause - Filament Change
2950 2954
  */
2951 2955
 #if ENABLED(ADVANCED_PAUSE_FEATURE)
2952
-  #if EITHER(HAS_LCD_MENU, EXTENSIBLE_UI) || BOTH(EMERGENCY_PARSER, HOST_PROMPT_SUPPORT)
2956
+  #if ANY(HAS_LCD_MENU, EXTENSIBLE_UI, DWIN_CREALITY_LCD_JYERSUI) || BOTH(EMERGENCY_PARSER, HOST_PROMPT_SUPPORT)
2953 2957
     #define M600_PURGE_MORE_RESUMABLE 1
2954 2958
   #endif
2955 2959
   #ifndef FILAMENT_CHANGE_SLOW_LOAD_LENGTH
@@ -3205,7 +3209,7 @@
3205 3209
 #endif
3206 3210
 
3207 3211
 // Number of VFAT entries used. Each entry has 13 UTF-16 characters
3208
-#if EITHER(SCROLL_LONG_FILENAMES, DWIN_CREALITY_LCD)
3212
+#if EITHER(SCROLL_LONG_FILENAMES, HAS_DWIN_E3V2)
3209 3213
   #define MAX_VFAT_ENTRIES (5)
3210 3214
 #else
3211 3215
   #define MAX_VFAT_ENTRIES (2)

+ 3
- 5
Marlin/src/inc/SanityCheck.h View File

@@ -807,10 +807,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
807 807
   #elif PROGRESS_MSG_EXPIRE < 0
808 808
     #error "PROGRESS_MSG_EXPIRE must be greater than or equal to 0."
809 809
   #endif
810
-#elif ENABLED(LCD_SET_PROGRESS_MANUALLY)
811
-  #if NONE(HAS_MARLINUI_U8GLIB, HAS_GRAPHICAL_TFT, HAS_MARLINUI_HD44780, EXTENSIBLE_UI, IS_DWIN_MARLINUI)
812
-    #error "LCD_SET_PROGRESS_MANUALLY requires LCD_PROGRESS_BAR, Character LCD, Graphical LCD, TFT, EXTENSIBLE_UI, OR DWIN MarlinUI."
813
-  #endif
810
+#elif ENABLED(LCD_SET_PROGRESS_MANUALLY) && NONE(HAS_MARLINUI_U8GLIB, HAS_GRAPHICAL_TFT, HAS_MARLINUI_HD44780, EXTENSIBLE_UI, HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
811
+  #error "LCD_SET_PROGRESS_MANUALLY requires LCD_PROGRESS_BAR, Character LCD, Graphical LCD, TFT, DWIN_CREALITY_LCD, DWIN_CREALITY_LCD_JYERSUI, DWIN_MARLINUI_*, or EXTENSIBLE_UI."
814 812
 #endif
815 813
 
816 814
 #if ENABLED(USE_M73_REMAINING_TIME) && DISABLED(LCD_SET_PROGRESS_MANUALLY)
@@ -2657,7 +2655,7 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
2657 2655
   + COUNT_ENABLED(ANYCUBIC_LCD_I3MEGA, ANYCUBIC_LCD_CHIRON, ANYCUBIC_TFT35) \
2658 2656
   + COUNT_ENABLED(DGUS_LCD_UI_ORIGIN, DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_HIPRECY, DGUS_LCD_UI_MKS, DGUS_LCD_UI_RELOADED) \
2659 2657
   + COUNT_ENABLED(ENDER2_STOCKDISPLAY, CR10_STOCKDISPLAY) \
2660
-  + COUNT_ENABLED(DWIN_CREALITY_LCD, DWIN_MARLINUI_PORTRAIT, DWIN_MARLINUI_LANDSCAPE) \
2658
+  + COUNT_ENABLED(DWIN_CREALITY_LCD, DWIN_CREALITY_LCD_JYERSUI, DWIN_MARLINUI_PORTRAIT, DWIN_MARLINUI_LANDSCAPE) \
2661 2659
   + COUNT_ENABLED(FYSETC_MINI_12864_X_X, FYSETC_MINI_12864_1_2, FYSETC_MINI_12864_2_0, FYSETC_MINI_12864_2_1, FYSETC_GENERIC_12864_1_1) \
2662 2660
   + COUNT_ENABLED(LCD_SAINSMART_I2C_1602, LCD_SAINSMART_I2C_2004) \
2663 2661
   + COUNT_ENABLED(MKS_12864OLED, MKS_12864OLED_SSD1306) \

+ 1
- 1
Marlin/src/lcd/buttons.h View File

@@ -75,7 +75,7 @@
75 75
   #endif
76 76
 #endif
77 77
 
78
-#if EITHER(HAS_DIGITAL_BUTTONS, DWIN_CREALITY_LCD)
78
+#if EITHER(HAS_DIGITAL_BUTTONS, HAS_DWIN_E3V2)
79 79
   // Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
80 80
   #define BLEN_A 0
81 81
   #define BLEN_B 1

+ 7
- 2
Marlin/src/lcd/e3v2/creality/rotary_encoder.cpp View File

@@ -122,8 +122,13 @@ ENCODER_DiffState Encoder_ReceiveAnalyze() {
122 122
   }
123 123
 
124 124
   if (ABS(temp_diff) >= ENCODER_PULSES_PER_STEP) {
125
-    if (temp_diff > 0) temp_diffState = ENCODER_DIFF_CW;
126
-    else temp_diffState = ENCODER_DIFF_CCW;
125
+    #if ENABLED(REVERSE_ENCODER_DIRECTION)
126
+      if (temp_diff > 0) temp_diffState = ENCODER_DIFF_CCW;
127
+      else temp_diffState = ENCODER_DIFF_CW;
128
+    #else
129
+      if (temp_diff > 0) temp_diffState = ENCODER_DIFF_CW;
130
+      else temp_diffState = ENCODER_DIFF_CCW;
131
+    #endif
127 132
 
128 133
     #if ENABLED(ENCODER_RATE_MULTIPLIER)
129 134
 

+ 7
- 0
Marlin/src/lcd/e3v2/jyersui/README.md View File

@@ -0,0 +1,7 @@
1
+# DWIN for Creality Ender 3 v2
2
+
3
+Marlin's Ender 3 v2 support requires the `DWIN_SET` included with the Ender 3 V2 [example configuration](https://github.com/MarlinFirmware/Configurations/tree/bugfix-2.0.x/config/examples/Creality/Ender-3%20V2).
4
+
5
+## Easy Install
6
+
7
+Copy the `DWIN_SET` folder onto a Micro-SD card and insert the card into the slot on the DWIN screen. Cycle the machine and wait for the screen to go from blue to orange. Turn the machine off and remove the SD card. When you turn on the machine the screen will display a "Creality" loading screen.

+ 5041
- 0
Marlin/src/lcd/e3v2/jyersui/dwin.cpp
File diff suppressed because it is too large
View File


+ 364
- 0
Marlin/src/lcd/e3v2/jyersui/dwin.h View File

@@ -0,0 +1,364 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * lcd/e3v2/jyersui/dwin.h
26
+ */
27
+
28
+#include "dwin_lcd.h"
29
+#include "rotary_encoder.h"
30
+#include "../../../libs/BL24CXX.h"
31
+#include "../../../inc/MarlinConfigPre.h"
32
+
33
+enum processID : uint8_t {
34
+  Main, Print, Menu, Value, Option, File, Popup, Confirm, Wait
35
+};
36
+
37
+enum PopupID : uint8_t {
38
+  Pause, Stop, Resume, SaveLevel, ETemp, ConfFilChange, PurgeMore, MeshSlot,
39
+  Level, Home, MoveWait, Heating,  FilLoad, FilChange, TempWarn, Runout, PIDWait, Resuming, ManualProbing,
40
+  FilInsert, HeaterTime, UserInput, LevelError, InvalidMesh, UI, Complete
41
+};
42
+
43
+enum menuID : uint8_t {
44
+  MainMenu,
45
+    Prepare,
46
+      Move,
47
+      HomeMenu,
48
+      ManualLevel,
49
+      ZOffset,
50
+      Preheat,
51
+      ChangeFilament,
52
+    Control,
53
+      TempMenu,
54
+        PID,
55
+          HotendPID,
56
+          BedPID,
57
+        Preheat1,
58
+        Preheat2,
59
+        Preheat3,
60
+        Preheat4,
61
+        Preheat5,
62
+      Motion,
63
+        HomeOffsets,
64
+        MaxSpeed,
65
+        MaxAcceleration,
66
+        MaxJerk,
67
+        Steps,
68
+      Visual,
69
+        ColorSettings,
70
+      Advanced,
71
+        ProbeMenu,
72
+      Info,
73
+    Leveling,
74
+      LevelManual,
75
+      LevelView,
76
+      MeshViewer,
77
+      LevelSettings,
78
+      ManualMesh,
79
+      UBLMesh,
80
+    InfoMain,
81
+  Tune,
82
+  PreheatHotend
83
+};
84
+
85
+#define Start_Process       0
86
+#define Language_English    1
87
+#define Language_Chinese    2
88
+
89
+#define ICON                7 // Icon set file 7.ICO
90
+
91
+#define ICON_LOGO                  0
92
+#define ICON_Print_0               1
93
+#define ICON_Print_1               2
94
+#define ICON_Prepare_0             3
95
+#define ICON_Prepare_1             4
96
+#define ICON_Control_0             5
97
+#define ICON_Control_1             6
98
+#define ICON_Leveling_0            7
99
+#define ICON_Leveling_1            8
100
+#define ICON_HotendTemp            9
101
+#define ICON_BedTemp              10
102
+#define ICON_Speed                11
103
+#define ICON_Zoffset              12
104
+#define ICON_Back                 13
105
+#define ICON_File                 14
106
+#define ICON_PrintTime            15
107
+#define ICON_RemainTime           16
108
+#define ICON_Setup_0              17
109
+#define ICON_Setup_1              18
110
+#define ICON_Pause_0              19
111
+#define ICON_Pause_1              20
112
+#define ICON_Continue_0           21
113
+#define ICON_Continue_1           22
114
+#define ICON_Stop_0               23
115
+#define ICON_Stop_1               24
116
+#define ICON_Bar                  25
117
+#define ICON_More                 26
118
+
119
+#define ICON_Axis                 27
120
+#define ICON_CloseMotor           28
121
+#define ICON_Homing               29
122
+#define ICON_SetHome              30
123
+#define ICON_PLAPreheat           31
124
+#define ICON_ABSPreheat           32
125
+#define ICON_Cool                 33
126
+#define ICON_Language             34
127
+
128
+#define ICON_MoveX                35
129
+#define ICON_MoveY                36
130
+#define ICON_MoveZ                37
131
+#define ICON_Extruder             38
132
+
133
+#define ICON_Temperature          40
134
+#define ICON_Motion               41
135
+#define ICON_WriteEEPROM          42
136
+#define ICON_ReadEEPROM           43
137
+#define ICON_ResumeEEPROM         44
138
+#define ICON_Info                 45
139
+
140
+#define ICON_SetEndTemp           46
141
+#define ICON_SetBedTemp           47
142
+#define ICON_FanSpeed             48
143
+#define ICON_SetPLAPreheat        49
144
+#define ICON_SetABSPreheat        50
145
+
146
+#define ICON_MaxSpeed             51
147
+#define ICON_MaxAccelerated       52
148
+#define ICON_MaxJerk              53
149
+#define ICON_Step                 54
150
+#define ICON_PrintSize            55
151
+#define ICON_Version              56
152
+#define ICON_Contact              57
153
+#define ICON_StockConfiguraton    58
154
+#define ICON_MaxSpeedX            59
155
+#define ICON_MaxSpeedY            60
156
+#define ICON_MaxSpeedZ            61
157
+#define ICON_MaxSpeedE            62
158
+#define ICON_MaxAccX              63
159
+#define ICON_MaxAccY              64
160
+#define ICON_MaxAccZ              65
161
+#define ICON_MaxAccE              66
162
+#define ICON_MaxSpeedJerkX        67
163
+#define ICON_MaxSpeedJerkY        68
164
+#define ICON_MaxSpeedJerkZ        69
165
+#define ICON_MaxSpeedJerkE        70
166
+#define ICON_StepX                71
167
+#define ICON_StepY                72
168
+#define ICON_StepZ                73
169
+#define ICON_StepE                74
170
+#define ICON_Setspeed             75
171
+#define ICON_SetZOffset           76
172
+#define ICON_Rectangle            77
173
+#define ICON_BLTouch              78
174
+#define ICON_TempTooLow           79
175
+#define ICON_AutoLeveling         80
176
+#define ICON_TempTooHigh          81
177
+#define ICON_NoTips_C             82
178
+#define ICON_NoTips_E             83
179
+#define ICON_Continue_C           84
180
+#define ICON_Continue_E           85
181
+#define ICON_Cancel_C             86
182
+#define ICON_Cancel_E             87
183
+#define ICON_Confirm_C            88
184
+#define ICON_Confirm_E            89
185
+#define ICON_Info_0               90
186
+#define ICON_Info_1               91
187
+
188
+// Custom icons
189
+#if ENABLED(DWIN_CREALITY_LCD_CUSTOM_ICONS)
190
+  // index of every custom icon should be >= CUSTOM_ICON_START
191
+  #define CUSTOM_ICON_START         ICON_Checkbox_F
192
+  #define ICON_Checkbox_F           200
193
+  #define ICON_Checkbox_T           201
194
+  #define ICON_Fade                 202
195
+  #define ICON_Mesh                 203
196
+  #define ICON_Tilt                 204
197
+  #define ICON_Brightness           205
198
+  #define ICON_AxisD                249
199
+  #define ICON_AxisBR               250
200
+  #define ICON_AxisTR               251
201
+  #define ICON_AxisBL               252
202
+  #define ICON_AxisTL               253
203
+  #define ICON_AxisC                254
204
+#else
205
+  #define ICON_Fade                 ICON_Version
206
+  #define ICON_Mesh                 ICON_Version
207
+  #define ICON_Tilt                 ICON_Version
208
+  #define ICON_Brightness           ICON_Version
209
+  #define ICON_AxisD                ICON_Axis
210
+  #define ICON_AxisBR               ICON_Axis
211
+  #define ICON_AxisTR               ICON_Axis
212
+  #define ICON_AxisBL               ICON_Axis
213
+  #define ICON_AxisTL               ICON_Axis
214
+  #define ICON_AxisC                ICON_Axis
215
+#endif
216
+
217
+#define font6x12  0x00
218
+#define font8x16  0x01
219
+#define font10x20 0x02
220
+#define font12x24 0x03
221
+#define font14x28 0x04
222
+#define font16x32 0x05
223
+#define font20x40 0x06
224
+#define font24x48 0x07
225
+#define font28x56 0x08
226
+#define font32x64 0x09
227
+
228
+enum colorID : uint8_t {
229
+  Default, White, Green, Cyan, Blue, Magenta, Red, Orange, Yellow, Brown, Black
230
+};
231
+
232
+#define Custom_Colors       10
233
+#define Color_White         0xFFFF
234
+#define Color_Light_White   0xBDD7
235
+#define Color_Green         0x07E0
236
+#define Color_Light_Green   0x3460
237
+#define Color_Cyan          0x07FF
238
+#define Color_Light_Cyan    0x04F3
239
+#define Color_Blue          0x015F
240
+#define Color_Light_Blue    0x3A6A
241
+#define Color_Magenta       0xF81F
242
+#define Color_Light_Magenta 0x9813
243
+#define Color_Red           0xF800
244
+#define Color_Light_Red     0x8800
245
+#define Color_Orange        0xFA20
246
+#define Color_Light_Orange  0xFBC0
247
+#define Color_Yellow        0xFF0F
248
+#define Color_Light_Yellow  0x8BE0
249
+#define Color_Brown         0xCC27
250
+#define Color_Light_Brown   0x6204
251
+#define Color_Black         0x0000
252
+#define Color_Grey          0x18E3
253
+#define Color_Bg_Window     0x31E8  // Popup background color
254
+#define Color_Bg_Blue       0x1125  // Dark blue background color
255
+#define Color_Bg_Black      0x0841  // Black background color
256
+#define Color_Bg_Red        0xF00F  // Red background color
257
+#define Popup_Text_Color    0xD6BA  // Popup font background color
258
+#define Line_Color          0x3A6A  // Split line color
259
+#define Rectangle_Color     0xEE2F  // Blue square cursor color
260
+#define Percent_Color       0xFE29  // Percentage color
261
+#define BarFill_Color       0x10E4  // Fill color of progress bar
262
+#define Select_Color        0x33BB  // Selected color
263
+#define Check_Color         0x4E5C  // Check-box check color
264
+#define Confirm_Color   	  0x34B9
265
+#define Cancel_Color        0x3186
266
+
267
+class CrealityDWINClass {
268
+public:
269
+  static constexpr size_t eeprom_data_size = 48;
270
+  static struct EEPROM_Settings { // use bit fields to save space, max 48 bytes
271
+    bool time_format_textual : 1;
272
+    bool beeperenable : 1;
273
+    #if ENABLED(AUTO_BED_LEVELING_UBL)
274
+      uint8_t tilt_grid_size : 3;
275
+    #endif
276
+    uint16_t corner_pos : 10;
277
+    uint8_t cursor_color : 4;
278
+    uint8_t menu_split_line : 4;
279
+    uint8_t menu_top_bg : 4;
280
+    uint8_t menu_top_txt : 4;
281
+    uint8_t highlight_box : 4;
282
+    uint8_t progress_percent : 4;
283
+    uint8_t progress_time : 4;
284
+    uint8_t status_bar_text : 4;
285
+    uint8_t status_area_text : 4;
286
+    uint8_t coordinates_text : 4;
287
+    uint8_t coordinates_split_line : 4;
288
+  } eeprom_settings;
289
+
290
+  static constexpr const char * const color_names[11] = { "Default", "White", "Green", "Cyan", "Blue", "Magenta", "Red", "Orange", "Yellow", "Brown", "Black" };
291
+  static constexpr const char * const preheat_modes[3] = { "Both", "Hotend", "Bed" };
292
+
293
+  static void Clear_Screen(uint8_t e=3);
294
+  static void Draw_Float(float value, uint8_t row, bool selected=false, uint8_t minunit=10);
295
+  static void Draw_Option(uint8_t value, const char * const * options, uint8_t row, bool selected=false, bool color=false);
296
+  static uint16_t GetColor(uint8_t color, uint16_t original, bool light=false);
297
+  static void Draw_Checkbox(uint8_t row, bool value);
298
+  static void Draw_Title(const char * title);
299
+  static void Draw_Menu_Item(uint8_t row, uint8_t icon=0, const char * const label1=nullptr, const char * const label2=nullptr, bool more=false, bool centered=false);
300
+  static void Draw_Menu(uint8_t menu, uint8_t select=0, uint8_t scroll=0);
301
+  static void Redraw_Menu(bool lastprocess=true, bool lastselection=false, bool lastmenu=false);
302
+  static void Redraw_Screen();
303
+
304
+  static void Main_Menu_Icons();
305
+  static void Draw_Main_Menu(uint8_t select=0);
306
+  static void Print_Screen_Icons();
307
+  static void Draw_Print_Screen();
308
+  static void Draw_Print_Filename(const bool reset=false);
309
+  static void Draw_Print_ProgressBar();
310
+  #if ENABLED(USE_M73_REMAINING_TIME)
311
+    static void Draw_Print_ProgressRemain();
312
+  #endif
313
+  static void Draw_Print_ProgressElapsed();
314
+  static void Draw_Print_confirm();
315
+  static void Draw_SD_Item(uint8_t item, uint8_t row);
316
+  static void Draw_SD_List(bool removed=false);
317
+  static void Draw_Status_Area(bool icons=false);
318
+  static void Draw_Popup(PGM_P const line1, PGM_P const line2, PGM_P const line3, uint8_t mode, uint8_t icon=0);
319
+  static void Popup_Select();
320
+  static void Update_Status_Bar(bool refresh=false);
321
+
322
+  #if ENABLED(AUTO_BED_LEVELING_UBL)
323
+    static void Draw_Bed_Mesh(int16_t selected = -1, uint8_t gridline_width = 1, uint16_t padding_x = 8, uint16_t padding_y_top = 40 + 53 - 7);
324
+    static void Set_Mesh_Viewer_Status();
325
+  #endif
326
+
327
+  static const char * Get_Menu_Title(uint8_t menu);
328
+  static uint8_t Get_Menu_Size(uint8_t menu);
329
+  static void Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw=true);
330
+
331
+  static void Popup_Handler(PopupID popupid, bool option = false);
332
+  static void Confirm_Handler(PopupID popupid);
333
+
334
+  static void Main_Menu_Control();
335
+  static void Menu_Control();
336
+  static void Value_Control();
337
+  static void Option_Control();
338
+  static void File_Control();
339
+  static void Print_Screen_Control();
340
+  static void Popup_Control();
341
+  static void Confirm_Control();
342
+
343
+  static void Setup_Value(float value, float min, float max, float unit, uint8_t type);
344
+  static void Modify_Value(float &value, float min, float max, float unit, void (*f)()=nullptr);
345
+  static void Modify_Value(uint8_t &value, float min, float max, float unit, void (*f)()=nullptr);
346
+  static void Modify_Value(uint16_t &value, float min, float max, float unit, void (*f)()=nullptr);
347
+  static void Modify_Value(int16_t &value, float min, float max, float unit, void (*f)()=nullptr);
348
+  static void Modify_Value(uint32_t &value, float min, float max, float unit, void (*f)()=nullptr);
349
+  static void Modify_Value(int8_t &value, float min, float max, float unit, void (*f)()=nullptr);
350
+  static void Modify_Option(uint8_t value, const char * const * options, uint8_t max);
351
+
352
+  static void Update_Status(const char * const text);
353
+  static void Start_Print(bool sd);
354
+  static void Stop_Print();
355
+  static void Update();
356
+  static void State_Update();
357
+  static void Screen_Update();
358
+  static void AudioFeedback(const bool success=true);
359
+  static void Save_Settings(char *buff);
360
+  static void Load_Settings(const char *buff);
361
+  static void Reset_Settings();
362
+};
363
+
364
+extern CrealityDWINClass CrealityDWIN;

+ 474
- 0
Marlin/src/lcd/e3v2/jyersui/dwin_lcd.cpp View File

@@ -0,0 +1,474 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/********************************************************************************
24
+ * @file     lcd/e3v2/jyersui/dwin_lcd.cpp
25
+ * @brief    DWIN screen control functions
26
+ ********************************************************************************/
27
+
28
+#include "../../../inc/MarlinConfigPre.h"
29
+
30
+#if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
31
+
32
+#include "../../../inc/MarlinConfig.h"
33
+
34
+#include "dwin_lcd.h"
35
+#include <string.h> // for memset
36
+
37
+//#define DEBUG_OUT 1
38
+#include "../../../core/debug_out.h"
39
+
40
+// Make sure DWIN_SendBuf is large enough to hold the largest string plus draw command and tail.
41
+// Assume the narrowest (6 pixel) font and 2-byte gb2312-encoded characters.
42
+uint8_t DWIN_SendBuf[11 + DWIN_WIDTH / 6 * 2] = { 0xAA };
43
+uint8_t DWIN_BufTail[4] = { 0xCC, 0x33, 0xC3, 0x3C };
44
+uint8_t databuf[26] = { 0 };
45
+uint8_t receivedType;
46
+
47
+int recnum = 0;
48
+
49
+inline void DWIN_Byte(size_t &i, const uint16_t bval) {
50
+  DWIN_SendBuf[++i] = bval;
51
+}
52
+
53
+inline void DWIN_Word(size_t &i, const uint16_t wval) {
54
+  DWIN_SendBuf[++i] = wval >> 8;
55
+  DWIN_SendBuf[++i] = wval & 0xFF;
56
+}
57
+
58
+inline void DWIN_Long(size_t &i, const uint32_t lval) {
59
+  DWIN_SendBuf[++i] = (lval >> 24) & 0xFF;
60
+  DWIN_SendBuf[++i] = (lval >> 16) & 0xFF;
61
+  DWIN_SendBuf[++i] = (lval >>  8) & 0xFF;
62
+  DWIN_SendBuf[++i] = lval & 0xFF;
63
+}
64
+
65
+inline void DWIN_String(size_t &i, const char * const string) {
66
+  const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, strlen(string));
67
+  memcpy(&DWIN_SendBuf[i + 1], string, len);
68
+  i += len;
69
+}
70
+
71
+inline void DWIN_String(size_t &i, const __FlashStringHelper * string) {
72
+  if (!string) return;
73
+  const size_t len = strlen_P((PGM_P)string); // cast it to PGM_P, which is basically const char *, and measure it using the _P version of strlen.
74
+  if (len == 0) return;
75
+  memcpy(&DWIN_SendBuf[i + 1], string, len);
76
+  i += len;
77
+}
78
+
79
+// Send the data in the buffer and the packet end
80
+inline void DWIN_Send(size_t &i) {
81
+  ++i;
82
+  LOOP_L_N(n, i) { LCD_SERIAL.write(DWIN_SendBuf[n]); delayMicroseconds(1); }
83
+  LOOP_L_N(n, 4) { LCD_SERIAL.write(DWIN_BufTail[n]); delayMicroseconds(1); }
84
+}
85
+
86
+/*-------------------------------------- System variable function --------------------------------------*/
87
+
88
+// Handshake (1: Success, 0: Fail)
89
+bool DWIN_Handshake(void) {
90
+  #ifndef LCD_BAUDRATE
91
+    #define LCD_BAUDRATE 115200
92
+  #endif
93
+  LCD_SERIAL.begin(LCD_BAUDRATE);
94
+  const millis_t serial_connect_timeout = millis() + 1000UL;
95
+  while (!LCD_SERIAL && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
96
+
97
+  size_t i = 0;
98
+  DWIN_Byte(i, 0x00);
99
+  DWIN_Send(i);
100
+
101
+  while (LCD_SERIAL.available() > 0 && recnum < (signed)sizeof(databuf)) {
102
+    databuf[recnum] = LCD_SERIAL.read();
103
+    // ignore the invalid data
104
+    if (databuf[0] != FHONE) { // prevent the program from running.
105
+      if (recnum > 0) {
106
+        recnum = 0;
107
+        ZERO(databuf);
108
+      }
109
+      continue;
110
+    }
111
+    delay(10);
112
+    recnum++;
113
+  }
114
+
115
+  return ( recnum >= 3
116
+        && databuf[0] == FHONE
117
+        && databuf[1] == '\0'
118
+        && databuf[2] == 'O'
119
+        && databuf[3] == 'K' );
120
+}
121
+
122
+// Set the backlight luminance
123
+//  luminance: (0x00-0xFF)
124
+void DWIN_Backlight_SetLuminance(const uint8_t luminance) {
125
+  size_t i = 0;
126
+  DWIN_Byte(i, 0x30);
127
+  DWIN_Byte(i, luminance);
128
+  DWIN_Send(i);
129
+}
130
+
131
+// Set screen display direction
132
+//  dir: 0=0°, 1=90°, 2=180°, 3=270°
133
+void DWIN_Frame_SetDir(uint8_t dir) {
134
+  size_t i = 0;
135
+  DWIN_Byte(i, 0x34);
136
+  DWIN_Byte(i, 0x5A);
137
+  DWIN_Byte(i, 0xA5);
138
+  DWIN_Byte(i, dir);
139
+  DWIN_Send(i);
140
+}
141
+
142
+// Update display
143
+void DWIN_UpdateLCD(void) {
144
+  size_t i = 0;
145
+  DWIN_Byte(i, 0x3D);
146
+  DWIN_Send(i);
147
+}
148
+
149
+/*---------------------------------------- Drawing functions ----------------------------------------*/
150
+
151
+// Clear screen
152
+//  color: Clear screen color
153
+void DWIN_Frame_Clear(const uint16_t color) {
154
+  size_t i = 0;
155
+  DWIN_Byte(i, 0x01);
156
+  DWIN_Word(i, color);
157
+  DWIN_Send(i);
158
+}
159
+
160
+// Draw a point
161
+//  color: Pixel segment color
162
+//  width: point width   0x01-0x0F
163
+//  height: point height 0x01-0x0F
164
+//  x,y: upper left point
165
+void DWIN_Draw_Point(uint16_t color, uint8_t width, uint8_t height, uint16_t x, uint16_t y) {
166
+  size_t i = 0;
167
+  DWIN_Byte(i, 0x02);
168
+  DWIN_Word(i, color);
169
+  DWIN_Byte(i, width);
170
+  DWIN_Byte(i, height);
171
+  DWIN_Word(i, x);
172
+  DWIN_Word(i, y);
173
+  DWIN_Send(i);
174
+}
175
+
176
+// Draw a line
177
+//  color: Line segment color
178
+//  xStart/yStart: Start point
179
+//  xEnd/yEnd: End point
180
+void DWIN_Draw_Line(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
181
+  size_t i = 0;
182
+  DWIN_Byte(i, 0x03);
183
+  DWIN_Word(i, color);
184
+  DWIN_Word(i, xStart);
185
+  DWIN_Word(i, yStart);
186
+  DWIN_Word(i, xEnd);
187
+  DWIN_Word(i, yEnd);
188
+  DWIN_Send(i);
189
+}
190
+
191
+// Draw a rectangle
192
+//  mode: 0=frame, 1=fill, 2=XOR fill
193
+//  color: Rectangle color
194
+//  xStart/yStart: upper left point
195
+//  xEnd/yEnd: lower right point
196
+void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color,
197
+                         uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
198
+  size_t i = 0;
199
+  DWIN_Byte(i, 0x05);
200
+  DWIN_Byte(i, mode);
201
+  DWIN_Word(i, color);
202
+  DWIN_Word(i, xStart);
203
+  DWIN_Word(i, yStart);
204
+  DWIN_Word(i, xEnd);
205
+  DWIN_Word(i, yEnd);
206
+  DWIN_Send(i);
207
+}
208
+
209
+//Color: color
210
+//x/y: Upper-left coordinate of the first pixel
211
+void DWIN_Draw_DegreeSymbol(uint16_t Color, uint16_t x, uint16_t y) {
212
+  DWIN_Draw_Point(Color, 1, 1, x + 1, y);
213
+  DWIN_Draw_Point(Color, 1, 1, x + 2, y);
214
+  DWIN_Draw_Point(Color, 1, 1, x, y + 1);
215
+  DWIN_Draw_Point(Color, 1, 1, x + 3, y + 1);
216
+  DWIN_Draw_Point(Color, 1, 1, x, y + 2);
217
+  DWIN_Draw_Point(Color, 1, 1, x + 3, y + 2);
218
+  DWIN_Draw_Point(Color, 1, 1, x + 1, y + 3);
219
+  DWIN_Draw_Point(Color, 1, 1, x + 2, y + 3);
220
+}
221
+
222
+// Move a screen area
223
+//  mode: 0, circle shift; 1, translation
224
+//  dir: 0=left, 1=right, 2=up, 3=down
225
+//  dis: Distance
226
+//  color: Fill color
227
+//  xStart/yStart: upper left point
228
+//  xEnd/yEnd: bottom right point
229
+void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
230
+                         uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
231
+  size_t i = 0;
232
+  DWIN_Byte(i, 0x09);
233
+  DWIN_Byte(i, (mode << 7) | dir);
234
+  DWIN_Word(i, dis);
235
+  DWIN_Word(i, color);
236
+  DWIN_Word(i, xStart);
237
+  DWIN_Word(i, yStart);
238
+  DWIN_Word(i, xEnd);
239
+  DWIN_Word(i, yEnd);
240
+  DWIN_Send(i);
241
+}
242
+
243
+/*---------------------------------------- Text related functions ----------------------------------------*/
244
+
245
+// Draw a string
246
+//  widthAdjust: true=self-adjust character width; false=no adjustment
247
+//  bShow: true=display background color; false=don't display background color
248
+//  size: Font size
249
+//  color: Character color
250
+//  bColor: Background color
251
+//  x/y: Upper-left coordinate of the string
252
+//  *string: The string
253
+void DWIN_Draw_String(bool widthAdjust, bool bShow, uint8_t size,
254
+                      uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * string) {
255
+  size_t i = 0;
256
+  DWIN_Byte(i, 0x11);
257
+  // Bit 7: widthAdjust
258
+  // Bit 6: bShow
259
+  // Bit 5-4: Unused (0)
260
+  // Bit 3-0: size
261
+  DWIN_Byte(i, (widthAdjust * 0x80) | (bShow * 0x40) | size);
262
+  DWIN_Word(i, color);
263
+  DWIN_Word(i, bColor);
264
+  DWIN_Word(i, x);
265
+  DWIN_Word(i, y);
266
+  DWIN_String(i, string);
267
+  DWIN_Send(i);
268
+}
269
+
270
+// Draw a positive integer
271
+//  bShow: true=display background color; false=don't display background color
272
+//  zeroFill: true=zero fill; false=no zero fill
273
+//  zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
274
+//  size: Font size
275
+//  color: Character color
276
+//  bColor: Background color
277
+//  iNum: Number of digits
278
+//  x/y: Upper-left coordinate
279
+//  value: Integer value
280
+void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
281
+                          uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint16_t value) {
282
+  size_t i = 0;
283
+  DWIN_Byte(i, 0x14);
284
+  // Bit 7: bshow
285
+  // Bit 6: 1 = signed; 0 = unsigned number;
286
+  // Bit 5: zeroFill
287
+  // Bit 4: zeroMode
288
+  // Bit 3-0: size
289
+  DWIN_Byte(i, (bShow * 0x80) | (zeroFill * 0x20) | (zeroMode * 0x10) | size);
290
+  DWIN_Word(i, color);
291
+  DWIN_Word(i, bColor);
292
+  DWIN_Byte(i, iNum);
293
+  DWIN_Byte(i, 0); // fNum
294
+  DWIN_Word(i, x);
295
+  DWIN_Word(i, y);
296
+  #if 0
297
+    for (char count = 0; count < 8; count++) {
298
+      DWIN_Byte(i, value);
299
+      value >>= 8;
300
+      if (!(value & 0xFF)) break;
301
+    }
302
+  #else
303
+    // Write a big-endian 64 bit integer
304
+    const size_t p = i + 1;
305
+    for (char count = 8; count--;) { // 7..0
306
+      ++i;
307
+      DWIN_SendBuf[p + count] = value;
308
+      value >>= 8;
309
+    }
310
+  #endif
311
+
312
+  DWIN_Send(i);
313
+}
314
+
315
+// Draw a floating point number
316
+//  bShow: true=display background color; false=don't display background color
317
+//  zeroFill: true=zero fill; false=no zero fill
318
+//  zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
319
+//  size: Font size
320
+//  color: Character color
321
+//  bColor: Background color
322
+//  iNum: Number of whole digits
323
+//  fNum: Number of decimal digits
324
+//  x/y: Upper-left point
325
+//  value: Float value
326
+void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
327
+                            uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value) {
328
+  //uint8_t *fvalue = (uint8_t*)&value;
329
+  size_t i = 0;
330
+  DWIN_Byte(i, 0x14);
331
+  DWIN_Byte(i, (bShow * 0x80) | (zeroFill * 0x20) | (zeroMode * 0x10) | size);
332
+  DWIN_Word(i, color);
333
+  DWIN_Word(i, bColor);
334
+  DWIN_Byte(i, iNum);
335
+  DWIN_Byte(i, fNum);
336
+  DWIN_Word(i, x);
337
+  DWIN_Word(i, y);
338
+  DWIN_Long(i, value);
339
+  /*
340
+  DWIN_Byte(i, fvalue[3]);
341
+  DWIN_Byte(i, fvalue[2]);
342
+  DWIN_Byte(i, fvalue[1]);
343
+  DWIN_Byte(i, fvalue[0]);
344
+  */
345
+  DWIN_Send(i);
346
+}
347
+
348
+/*---------------------------------------- Picture related functions ----------------------------------------*/
349
+
350
+// Draw JPG and cached in #0 virtual display area
351
+// id: Picture ID
352
+void DWIN_JPG_ShowAndCache(const uint8_t id) {
353
+  size_t i = 0;
354
+  DWIN_Word(i, 0x2200);
355
+  DWIN_Byte(i, id);
356
+  DWIN_Send(i);     // AA 23 00 00 00 00 08 00 01 02 03 CC 33 C3 3C
357
+}
358
+
359
+// Draw an Icon
360
+//  libID: Icon library ID
361
+//  picID: Icon ID
362
+//  x/y: Upper-left point
363
+void DWIN_ICON_Show(uint8_t libID, uint8_t picID, uint16_t x, uint16_t y) {
364
+  NOMORE(x, DWIN_WIDTH - 1);
365
+  NOMORE(y, DWIN_HEIGHT - 1); // -- ozy -- srl
366
+  size_t i = 0;
367
+  DWIN_Byte(i, 0x23);
368
+  DWIN_Word(i, x);
369
+  DWIN_Word(i, y);
370
+  DWIN_Byte(i, 0x80 | libID);
371
+  DWIN_Byte(i, picID);
372
+  DWIN_Send(i);
373
+}
374
+
375
+// Unzip the JPG picture to a virtual display area
376
+//  n: Cache index
377
+//  id: Picture ID
378
+void DWIN_JPG_CacheToN(uint8_t n, uint8_t id) {
379
+  size_t i = 0;
380
+  DWIN_Byte(i, 0x25);
381
+  DWIN_Byte(i, n);
382
+  DWIN_Byte(i, id);
383
+  DWIN_Send(i);
384
+}
385
+
386
+// Copy area from virtual display area to current screen
387
+//  cacheID: virtual area number
388
+//  xStart/yStart: Upper-left of virtual area
389
+//  xEnd/yEnd: Lower-right of virtual area
390
+//  x/y: Screen paste point
391
+void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart,
392
+                         uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y) {
393
+  size_t i = 0;
394
+  DWIN_Byte(i, 0x27);
395
+  DWIN_Byte(i, 0x80 | cacheID);
396
+  DWIN_Word(i, xStart);
397
+  DWIN_Word(i, yStart);
398
+  DWIN_Word(i, xEnd);
399
+  DWIN_Word(i, yEnd);
400
+  DWIN_Word(i, x);
401
+  DWIN_Word(i, y);
402
+  DWIN_Send(i);
403
+}
404
+
405
+// Animate a series of icons
406
+//  animID: Animation ID; 0x00-0x0F
407
+//  animate: true on; false off;
408
+//  libID: Icon library ID
409
+//  picIDs: Icon starting ID
410
+//  picIDe: Icon ending ID
411
+//  x/y: Upper-left point
412
+//  interval: Display time interval, unit 10mS
413
+void DWIN_ICON_Animation(uint8_t animID, bool animate, uint8_t libID, uint8_t picIDs, uint8_t picIDe, uint16_t x, uint16_t y, uint16_t interval) {
414
+  NOMORE(x, DWIN_WIDTH - 1);
415
+  NOMORE(y, DWIN_HEIGHT - 1); // -- ozy -- srl
416
+  size_t i = 0;
417
+  DWIN_Byte(i, 0x28);
418
+  DWIN_Word(i, x);
419
+  DWIN_Word(i, y);
420
+  // Bit 7: animation on or off
421
+  // Bit 6: start from begin or end
422
+  // Bit 5-4: unused (0)
423
+  // Bit 3-0: animID
424
+  DWIN_Byte(i, (animate * 0x80) | 0x40 | animID);
425
+  DWIN_Byte(i, libID);
426
+  DWIN_Byte(i, picIDs);
427
+  DWIN_Byte(i, picIDe);
428
+  DWIN_Byte(i, interval);
429
+  DWIN_Send(i);
430
+}
431
+
432
+// Animation Control
433
+//  state: 16 bits, each bit is the state of an animation id
434
+void DWIN_ICON_AnimationControl(uint16_t state) {
435
+  size_t i = 0;
436
+  DWIN_Byte(i, 0x28);
437
+  DWIN_Word(i, state);
438
+  DWIN_Send(i);
439
+}
440
+
441
+/*---------------------------------------- Memory functions ----------------------------------------*/
442
+// The LCD has an additional 32KB SRAM and 16KB Flash
443
+
444
+// Data can be written to the sram and save to one of the jpeg page files
445
+
446
+// Write Data Memory
447
+//  command 0x31
448
+//  Type: Write memory selection; 0x5A=SRAM; 0xA5=Flash
449
+//  Address: Write data memory address; 0x000-0x7FFF for SRAM; 0x000-0x3FFF for Flash
450
+//  Data: data
451
+//
452
+//  Flash writing returns 0xA5 0x4F 0x4B
453
+
454
+// Read Data Memory
455
+//  command 0x32
456
+//  Type: Read memory selection; 0x5A=SRAM; 0xA5=Flash
457
+//  Address: Read data memory address; 0x000-0x7FFF for SRAM; 0x000-0x3FFF for Flash
458
+//  Length: leangth of data to read; 0x01-0xF0
459
+//
460
+//  Response:
461
+//    Type, Address, Length, Data
462
+
463
+// Write Picture Memory
464
+//  Write the contents of the 32KB SRAM data memory into the designated image memory space
465
+//  Issued: 0x5A, 0xA5, PIC_ID
466
+//  Response: 0xA5 0x4F 0x4B
467
+//
468
+//  command 0x33
469
+//  0x5A, 0xA5
470
+//  PicId: Picture Memory location, 0x00-0x0F
471
+//
472
+//  Flash writing returns 0xA5 0x4F 0x4B
473
+
474
+#endif // DWIN_CREALITY_LCD_JYERSUI

+ 218
- 0
Marlin/src/lcd/e3v2/jyersui/dwin_lcd.h View File

@@ -0,0 +1,218 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/********************************************************************************
25
+ * @file     lcd/e3v2/jyersui/dwin_lcd.h
26
+ * @brief    DWIN screen control functions
27
+ ********************************************************************************/
28
+
29
+#include <stdint.h>
30
+
31
+#define RECEIVED_NO_DATA         0x00
32
+#define RECEIVED_SHAKE_HAND_ACK  0x01
33
+
34
+#define FHONE                    0xAA
35
+
36
+#define DWIN_SCROLL_UP   2
37
+#define DWIN_SCROLL_DOWN 3
38
+
39
+#define DWIN_WIDTH  272
40
+#define DWIN_HEIGHT 480
41
+
42
+/*-------------------------------------- System variable function --------------------------------------*/
43
+
44
+// Handshake (1: Success, 0: Fail)
45
+bool DWIN_Handshake(void);
46
+
47
+// Common DWIN startup
48
+void DWIN_Startup(void);
49
+
50
+// Set the backlight luminance
51
+//  luminance: (0x00-0xFF)
52
+void DWIN_Backlight_SetLuminance(const uint8_t luminance);
53
+
54
+// Set screen display direction
55
+//  dir: 0=0°, 1=90°, 2=180°, 3=270°
56
+void DWIN_Frame_SetDir(uint8_t dir);
57
+
58
+// Update display
59
+void DWIN_UpdateLCD(void);
60
+
61
+/*---------------------------------------- Drawing functions ----------------------------------------*/
62
+
63
+// Clear screen
64
+//  color: Clear screen color
65
+void DWIN_Frame_Clear(const uint16_t color);
66
+
67
+// Draw a point
68
+//  color: Line segment color
69
+//  width: point width   0x01-0x0F
70
+//  height: point height 0x01-0x0F
71
+//  x,y: upper left point
72
+void DWIN_Draw_Point(uint16_t color, uint8_t width, uint8_t height, uint16_t x, uint16_t y);
73
+
74
+// Draw a line
75
+//  color: Line segment color
76
+//  xStart/yStart: Start point
77
+//  xEnd/yEnd: End point
78
+void DWIN_Draw_Line(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
79
+
80
+// Draw a Horizontal line
81
+//  color: Line segment color
82
+//  xStart/yStart: Start point
83
+//  xLength: Line Length
84
+inline void DWIN_Draw_HLine(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xLength) {
85
+  DWIN_Draw_Line(color, xStart, yStart, xStart + xLength - 1, yStart);
86
+}
87
+
88
+// Draw a Vertical line
89
+//  color: Line segment color
90
+//  xStart/yStart: Start point
91
+//  yLength: Line Length
92
+inline void DWIN_Draw_VLine(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t yLength) {
93
+  DWIN_Draw_Line(color, xStart, yStart, xStart, yStart + yLength - 1);
94
+}
95
+
96
+// Draw a rectangle
97
+//  mode: 0=frame, 1=fill, 2=XOR fill
98
+//  color: Rectangle color
99
+//  xStart/yStart: upper left point
100
+//  xEnd/yEnd: lower right point
101
+void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color,
102
+                         uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
103
+
104
+// Draw a box
105
+//  mode: 0=frame, 1=fill, 2=XOR fill
106
+//  color: Rectangle color
107
+//  xStart/yStart: upper left point
108
+//  xSize/ySize: box size
109
+inline void DWIN_Draw_Box(uint8_t mode, uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xSize, uint16_t ySize) {
110
+  DWIN_Draw_Rectangle(mode, color, xStart, yStart, xStart + xSize - 1, yStart + ySize - 1);
111
+}
112
+
113
+//Color: color
114
+//x: upper left point
115
+//y: bottom right point
116
+void DWIN_Draw_DegreeSymbol(uint16_t Color, uint16_t x, uint16_t y);
117
+
118
+// Move a screen area
119
+//  mode: 0, circle shift; 1, translation
120
+//  dir: 0=left, 1=right, 2=up, 3=down
121
+//  dis: Distance
122
+//  color: Fill color
123
+//  xStart/yStart: upper left point
124
+//  xEnd/yEnd: bottom right point
125
+void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
126
+                         uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
127
+
128
+/*---------------------------------------- Text related functions ----------------------------------------*/
129
+
130
+// Draw a string
131
+//  widthAdjust: true=self-adjust character width; false=no adjustment
132
+//  bShow: true=display background color; false=don't display background color
133
+//  size: Font size
134
+//  color: Character color
135
+//  bColor: Background color
136
+//  x/y: Upper-left coordinate of the string
137
+//  *string: The string
138
+void DWIN_Draw_String(bool widthAdjust, bool bShow, uint8_t size,
139
+                      uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * string);
140
+
141
+class __FlashStringHelper;
142
+
143
+inline void DWIN_Draw_String(bool widthAdjust, bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const __FlashStringHelper *title) {
144
+  // Note that this won't work on AVR. This is for 32-bit systems only!
145
+  // Are __FlashStringHelper versions worth keeping?
146
+  DWIN_Draw_String(widthAdjust, bShow, size, color, bColor, x, y, reinterpret_cast<const char*>(title));
147
+}
148
+
149
+// Draw a positive integer
150
+//  bShow: true=display background color; false=don't display background color
151
+//  zeroFill: true=zero fill; false=no zero fill
152
+//  zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
153
+//  size: Font size
154
+//  color: Character color
155
+//  bColor: Background color
156
+//  iNum: Number of digits
157
+//  x/y: Upper-left coordinate
158
+//  value: Integer value
159
+void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
160
+                          uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint16_t value);
161
+
162
+// Draw a floating point number
163
+//  bShow: true=display background color; false=don't display background color
164
+//  zeroFill: true=zero fill; false=no zero fill
165
+//  zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
166
+//  size: Font size
167
+//  color: Character color
168
+//  bColor: Background color
169
+//  iNum: Number of whole digits
170
+//  fNum: Number of decimal digits
171
+//  x/y: Upper-left point
172
+//  value: Float value
173
+void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
174
+                            uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value);
175
+
176
+/*---------------------------------------- Picture related functions ----------------------------------------*/
177
+
178
+// Draw JPG and cached in #0 virtual display area
179
+// id: Picture ID
180
+void DWIN_JPG_ShowAndCache(const uint8_t id);
181
+
182
+// Draw an Icon
183
+//  libID: Icon library ID
184
+//  picID: Icon ID
185
+//  x/y: Upper-left point
186
+void DWIN_ICON_Show(uint8_t libID, uint8_t picID, uint16_t x, uint16_t y);
187
+
188
+// Unzip the JPG picture to a virtual display area
189
+//  n: Cache index
190
+//  id: Picture ID
191
+void DWIN_JPG_CacheToN(uint8_t n, uint8_t id);
192
+
193
+// Unzip the JPG picture to virtual display area #1
194
+//  id: Picture ID
195
+inline void DWIN_JPG_CacheTo1(uint8_t id) { DWIN_JPG_CacheToN(1, id); }
196
+
197
+// Copy area from virtual display area to current screen
198
+//  cacheID: virtual area number
199
+//  xStart/yStart: Upper-left of virtual area
200
+//  xEnd/yEnd: Lower-right of virtual area
201
+//  x/y: Screen paste point
202
+void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart,
203
+                         uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y);
204
+
205
+// Animate a series of icons
206
+//  animID: Animation ID  up to 16
207
+//  animate: animation on or off
208
+//  libID: Icon library ID
209
+//  picIDs: Icon starting ID
210
+//  picIDe: Icon ending ID
211
+//  x/y: Upper-left point
212
+//  interval: Display time interval, unit 10mS
213
+void DWIN_ICON_Animation(uint8_t animID, bool animate, uint8_t libID, uint8_t picIDs,
214
+                         uint8_t picIDe, uint16_t x, uint16_t y, uint16_t interval);
215
+
216
+// Animation Control
217
+//  state: 16 bits, each bit is the state of an animation id
218
+void DWIN_ICON_AnimationControl(uint16_t state);

+ 261
- 0
Marlin/src/lcd/e3v2/jyersui/rotary_encoder.cpp View File

@@ -0,0 +1,261 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/*****************************************************************************
24
+ * @file     lcd/e3v2/jyersui/rotary_encoder.cpp
25
+ * @brief    Rotary encoder functions
26
+ *****************************************************************************/
27
+
28
+#include "../../../inc/MarlinConfigPre.h"
29
+
30
+#if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
31
+
32
+#include "rotary_encoder.h"
33
+#include "../../buttons.h"
34
+
35
+#include "../../../MarlinCore.h"
36
+#include "../../marlinui.h"
37
+#include "../../../HAL/shared/Delay.h"
38
+
39
+#if HAS_BUZZER
40
+  #include "../../../libs/buzzer.h"
41
+  #include "dwin.h"
42
+#endif
43
+
44
+#include <stdlib.h>
45
+
46
+#ifndef ENCODER_PULSES_PER_STEP
47
+  #define ENCODER_PULSES_PER_STEP 4
48
+#endif
49
+
50
+ENCODER_Rate EncoderRate;
51
+
52
+// Buzzer
53
+void Encoder_tick() {
54
+  #if PIN_EXISTS(BEEPER)
55
+    if (CrealityDWIN.eeprom_settings.beeperenable) {
56
+      WRITE(BEEPER_PIN, HIGH);
57
+      delay(10);
58
+      WRITE(BEEPER_PIN, LOW);
59
+    }
60
+  #endif
61
+}
62
+
63
+// Encoder initialization
64
+void Encoder_Configuration() {
65
+  #if BUTTON_EXISTS(EN1)
66
+    SET_INPUT_PULLUP(BTN_EN1);
67
+  #endif
68
+  #if BUTTON_EXISTS(EN2)
69
+    SET_INPUT_PULLUP(BTN_EN2);
70
+  #endif
71
+  #if BUTTON_EXISTS(ENC)
72
+    SET_INPUT_PULLUP(BTN_ENC);
73
+  #endif
74
+  #if PIN_EXISTS(BEEPER)
75
+    SET_OUTPUT(BEEPER_PIN);
76
+  #endif
77
+}
78
+
79
+// Analyze encoder value and return state
80
+ENCODER_DiffState Encoder_ReceiveAnalyze() {
81
+  const millis_t now = millis();
82
+  static uint8_t lastEncoderBits;
83
+  uint8_t newbutton = 0;
84
+  static signed char temp_diff = 0;
85
+
86
+  ENCODER_DiffState temp_diffState = ENCODER_DIFF_NO;
87
+  if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
88
+  if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
89
+  if (BUTTON_PRESSED(ENC)) {
90
+    static millis_t next_click_update_ms;
91
+    if (ELAPSED(now, next_click_update_ms)) {
92
+      next_click_update_ms = millis() + 300;
93
+      Encoder_tick();
94
+      #if PIN_EXISTS(LCD_LED)
95
+        //LED_Action();
96
+      #endif
97
+      if (ui.backlight) return ENCODER_DIFF_ENTER;
98
+      ui.refresh_brightness();
99
+    }
100
+    else return ENCODER_DIFF_NO;
101
+  }
102
+  if (newbutton != lastEncoderBits) {
103
+    switch (newbutton) {
104
+      case ENCODER_PHASE_0:
105
+             if (lastEncoderBits == ENCODER_PHASE_3) temp_diff++;
106
+        else if (lastEncoderBits == ENCODER_PHASE_1) temp_diff--;
107
+        break;
108
+      case ENCODER_PHASE_1:
109
+             if (lastEncoderBits == ENCODER_PHASE_0) temp_diff++;
110
+        else if (lastEncoderBits == ENCODER_PHASE_2) temp_diff--;
111
+        break;
112
+      case ENCODER_PHASE_2:
113
+             if (lastEncoderBits == ENCODER_PHASE_1) temp_diff++;
114
+        else if (lastEncoderBits == ENCODER_PHASE_3) temp_diff--;
115
+        break;
116
+      case ENCODER_PHASE_3:
117
+             if (lastEncoderBits == ENCODER_PHASE_2) temp_diff++;
118
+        else if (lastEncoderBits == ENCODER_PHASE_0) temp_diff--;
119
+        break;
120
+    }
121
+    lastEncoderBits = newbutton;
122
+  }
123
+
124
+  if (ABS(temp_diff) >= ENCODER_PULSES_PER_STEP) {
125
+    #if ENABLED(REVERSE_ENCODER_DIRECTION)
126
+      if (temp_diff > 0) temp_diffState = ENCODER_DIFF_CCW;
127
+      else temp_diffState = ENCODER_DIFF_CW;
128
+    #else
129
+      if (temp_diff > 0) temp_diffState = ENCODER_DIFF_CW;
130
+      else temp_diffState = ENCODER_DIFF_CCW;
131
+    #endif
132
+
133
+    #if ENABLED(ENCODER_RATE_MULTIPLIER)
134
+
135
+      millis_t ms = millis();
136
+      int32_t encoderMultiplier = 1;
137
+
138
+      // if must encoder rati multiplier
139
+      if (EncoderRate.enabled) {
140
+        const float abs_diff = ABS(temp_diff),
141
+                    encoderMovementSteps = abs_diff / (ENCODER_PULSES_PER_STEP);
142
+        if (EncoderRate.lastEncoderTime) {
143
+          // Note that the rate is always calculated between two passes through the
144
+          // loop and that the abs of the temp_diff value is tracked.
145
+          const float encoderStepRate = encoderMovementSteps / float(ms - EncoderRate.lastEncoderTime) * 1000;
146
+               if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC) encoderMultiplier = 100;
147
+          else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC)  encoderMultiplier = 10;
148
+          else if (encoderStepRate >= ENCODER_5X_STEPS_PER_SEC)   encoderMultiplier = 5;
149
+        }
150
+        EncoderRate.lastEncoderTime = ms;
151
+      }
152
+
153
+    #else
154
+
155
+      constexpr int32_t encoderMultiplier = 1;
156
+
157
+    #endif
158
+
159
+    // EncoderRate.encoderMoveValue += (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
160
+    EncoderRate.encoderMoveValue = (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
161
+    if (EncoderRate.encoderMoveValue < 0) EncoderRate.encoderMoveValue = -EncoderRate.encoderMoveValue;
162
+
163
+    temp_diff = 0;
164
+  }
165
+  return temp_diffState;
166
+}
167
+
168
+#if PIN_EXISTS(LCD_LED)
169
+
170
+  // Take the low 24 valid bits  24Bit: G7 G6 G5 G4 G3 G2 G1 G0 R7 R6 R5 R4 R3 R2 R1 R0 B7 B6 B5 B4 B3 B2 B1 B0
171
+  uint16_t LED_DataArray[LED_NUM];
172
+
173
+  // LED light operation
174
+  void LED_Action() {
175
+    LED_Control(RGB_SCALE_WARM_WHITE,0x0F);
176
+    delay(30);
177
+    LED_Control(RGB_SCALE_WARM_WHITE,0x00);
178
+  }
179
+
180
+  // LED initialization
181
+  void LED_Configuration() {
182
+    SET_OUTPUT(LCD_LED_PIN);
183
+  }
184
+
185
+  // LED write data
186
+  void LED_WriteData() {
187
+    uint8_t tempCounter_LED, tempCounter_Bit;
188
+    for (tempCounter_LED = 0; tempCounter_LED < LED_NUM; tempCounter_LED++) {
189
+      for (tempCounter_Bit = 0; tempCounter_Bit < 24; tempCounter_Bit++) {
190
+        if (LED_DataArray[tempCounter_LED] & (0x800000 >> tempCounter_Bit)) {
191
+          LED_DATA_HIGH;
192
+          DELAY_NS(300);
193
+          LED_DATA_LOW;
194
+          DELAY_NS(200);
195
+        }
196
+        else {
197
+          LED_DATA_HIGH;
198
+          LED_DATA_LOW;
199
+          DELAY_NS(200);
200
+        }
201
+      }
202
+    }
203
+  }
204
+
205
+  // LED control
206
+  //  RGB_Scale: RGB color ratio
207
+  //  luminance: brightness (0~0xFF)
208
+  void LED_Control(const uint8_t RGB_Scale, const uint8_t luminance) {
209
+    for (uint8_t i = 0; i < LED_NUM; i++) {
210
+      LED_DataArray[i] = 0;
211
+      switch (RGB_Scale) {
212
+        case RGB_SCALE_R10_G7_B5: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 7/10) << 16 | luminance * 5/10; break;
213
+        case RGB_SCALE_R10_G7_B4: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 7/10) << 16 | luminance * 4/10; break;
214
+        case RGB_SCALE_R10_G8_B7: LED_DataArray[i] = (luminance * 10/10) << 8 | (luminance * 8/10) << 16 | luminance * 7/10; break;
215
+      }
216
+    }
217
+    LED_WriteData();
218
+  }
219
+
220
+  // LED gradient control
221
+  //  RGB_Scale: RGB color ratio
222
+  //  luminance: brightness (0~0xFF)
223
+  //  change_Time: gradient time (ms)
224
+  void LED_GraduallyControl(const uint8_t RGB_Scale, const uint8_t luminance, const uint16_t change_Interval) {
225
+    struct { uint8_t g, r, b; } led_data[LED_NUM];
226
+    for (uint8_t i = 0; i < LED_NUM; i++) {
227
+      switch (RGB_Scale) {
228
+        case RGB_SCALE_R10_G7_B5:
229
+          led_data[i] = { luminance * 7/10, luminance * 10/10, luminance * 5/10 };
230
+          break;
231
+        case RGB_SCALE_R10_G7_B4:
232
+          led_data[i] = { luminance * 7/10, luminance * 10/10, luminance * 4/10 };
233
+          break;
234
+        case RGB_SCALE_R10_G8_B7:
235
+          led_data[i] = { luminance * 8/10, luminance * 10/10, luminance * 7/10 };
236
+          break;
237
+      }
238
+    }
239
+
240
+    struct { bool g, r, b; } led_flag = { false, false, false };
241
+    for (uint8_t i = 0; i < LED_NUM; i++) {
242
+      while (1) {
243
+        const uint8_t g = uint8_t(LED_DataArray[i] >> 16),
244
+                      r = uint8_t(LED_DataArray[i] >> 8),
245
+                      b = uint8_t(LED_DataArray[i]);
246
+        if (g == led_data[i].g) led_flag.g = true;
247
+        else LED_DataArray[i] += (g > led_data[i].g) ? -0x010000 : 0x010000;
248
+        if (r == led_data[i].r) led_flag.r = true;
249
+        else LED_DataArray[i] += (r > led_data[i].r) ? -0x000100 : 0x000100;
250
+        if (b == led_data[i].b) led_flag.b = true;
251
+        else LED_DataArray[i] += (b > led_data[i].b) ? -0x000001 : 0x000001;
252
+        LED_WriteData();
253
+        if (led_flag.r && led_flag.g && led_flag.b) break;
254
+        delay(change_Interval);
255
+      }
256
+    }
257
+  }
258
+
259
+#endif // LCD_LED
260
+
261
+#endif // DWIN_CREALITY_LCD_JYERSUI

+ 91
- 0
Marlin/src/lcd/e3v2/jyersui/rotary_encoder.h View File

@@ -0,0 +1,91 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/*****************************************************************************
25
+  * @file     lcd/e3v2/jyersui/rotary_encoder.h
26
+  * @brief    Rotary encoder functions
27
+  ****************************************************************************/
28
+
29
+#include "../../../inc/MarlinConfig.h"
30
+
31
+/*********************** Encoder Set ***********************/
32
+
33
+typedef struct {
34
+  bool enabled = false;
35
+  int encoderMoveValue = 0;
36
+  millis_t lastEncoderTime = 0;
37
+} ENCODER_Rate;
38
+
39
+extern ENCODER_Rate EncoderRate;
40
+
41
+typedef enum {
42
+  ENCODER_DIFF_NO    = 0,  // no state
43
+  ENCODER_DIFF_CW    = 1,  // clockwise rotation
44
+  ENCODER_DIFF_CCW   = 2,  // counterclockwise rotation
45
+  ENCODER_DIFF_ENTER = 3   // click
46
+} ENCODER_DiffState;
47
+
48
+// Encoder initialization
49
+void Encoder_Configuration();
50
+
51
+// Analyze encoder value and return state
52
+ENCODER_DiffState Encoder_ReceiveAnalyze();
53
+
54
+/*********************** Encoder LED ***********************/
55
+
56
+#if PIN_EXISTS(LCD_LED)
57
+
58
+  #define LED_NUM  4
59
+  #define LED_DATA_HIGH  WRITE(LCD_LED_PIN, 1)
60
+  #define LED_DATA_LOW   WRITE(LCD_LED_PIN, 0)
61
+
62
+  #define RGB_SCALE_R10_G7_B5  1
63
+  #define RGB_SCALE_R10_G7_B4  2
64
+  #define RGB_SCALE_R10_G8_B7  3
65
+  #define RGB_SCALE_NEUTRAL_WHITE RGB_SCALE_R10_G7_B5
66
+  #define RGB_SCALE_WARM_WHITE    RGB_SCALE_R10_G7_B4
67
+  #define RGB_SCALE_COOL_WHITE    RGB_SCALE_R10_G8_B7
68
+
69
+  extern unsigned int LED_DataArray[LED_NUM];
70
+
71
+  // LED light operation
72
+  void LED_Action();
73
+
74
+  // LED initialization
75
+  void LED_Configuration();
76
+
77
+  // LED write data
78
+  void LED_WriteData();
79
+
80
+  // LED control
81
+  //  RGB_Scale: RGB color ratio
82
+  //  luminance: brightness (0~0xFF)
83
+  void LED_Control(const uint8_t RGB_Scale, const uint8_t luminance);
84
+
85
+  // LED gradient control
86
+  //  RGB_Scale: RGB color ratio
87
+  //  luminance: brightness (0~0xFF)
88
+  //  change_Time: gradient time (ms)
89
+  void LED_GraduallyControl(const uint8_t RGB_Scale, const uint8_t luminance, const uint16_t change_Interval);
90
+
91
+#endif // LCD_LED

+ 1
- 1
Marlin/src/lcd/extui/ui_api.h View File

@@ -195,7 +195,7 @@ namespace ExtUI {
195 195
   #endif
196 196
 
197 197
   inline void simulateUserClick() {
198
-    #if EITHER(HAS_LCD_MENU, EXTENSIBLE_UI)
198
+    #if ANY(HAS_LCD_MENU, EXTENSIBLE_UI, DWIN_CREALITY_LCD_JYERSUI)
199 199
       ui.lcd_clicked = true;
200 200
     #endif
201 201
   }

+ 19
- 11
Marlin/src/lcd/marlinui.cpp View File

@@ -48,6 +48,8 @@ MarlinUI ui;
48 48
 
49 49
 #if ENABLED(DWIN_CREALITY_LCD)
50 50
   #include "e3v2/creality/dwin.h"
51
+#elif ENABLED(DWIN_CREALITY_LCD_JYERSUI)
52
+  #include "e3v2/jyersui/dwin.h"
51 53
 #endif
52 54
 
53 55
 #if ENABLED(LCD_PROGRESS_BAR) && !IS_TFTGLCD_PANEL
@@ -99,6 +101,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
99 101
     backlight = !!value;
100 102
     if (backlight) brightness = constrain(value, MIN_LCD_BRIGHTNESS, MAX_LCD_BRIGHTNESS);
101 103
     // Set brightness on enabled LCD here
104
+    TERN_(DWIN_CREALITY_LCD_JYERSUI, DWIN_Backlight_SetLuminance(backlight ? brightness : 0));
102 105
   }
103 106
 #endif
104 107
 
@@ -136,6 +139,21 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
136 139
   bool MarlinUI::lcd_clicked;
137 140
 #endif
138 141
 
142
+#if EITHER(HAS_WIRED_LCD, DWIN_CREALITY_LCD_JYERSUI)
143
+
144
+  bool MarlinUI::get_blink() {
145
+    static uint8_t blink = 0;
146
+    static millis_t next_blink_ms = 0;
147
+    millis_t ms = millis();
148
+    if (ELAPSED(ms, next_blink_ms)) {
149
+      blink ^= 0xFF;
150
+      next_blink_ms = ms + 1000 - (LCD_UPDATE_INTERVAL) / 2;
151
+    }
152
+    return blink != 0;
153
+  }
154
+
155
+#endif
156
+
139 157
 #if HAS_WIRED_LCD
140 158
 
141 159
   #if HAS_MARLINUI_U8GLIB
@@ -415,17 +433,6 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
415 433
     TERN_(HAS_ENCODER_ACTION, encoderDiff = 0);
416 434
   }
417 435
 
418
-  bool MarlinUI::get_blink() {
419
-    static uint8_t blink = 0;
420
-    static millis_t next_blink_ms = 0;
421
-    millis_t ms = millis();
422
-    if (ELAPSED(ms, next_blink_ms)) {
423
-      blink ^= 0xFF;
424
-      next_blink_ms = ms + 1000 - (LCD_UPDATE_INTERVAL) / 2;
425
-    }
426
-    return blink != 0;
427
-  }
428
-
429 436
   ////////////////////////////////////////////
430 437
   ///////////// Keypad Handling //////////////
431 438
   ////////////////////////////////////////////
@@ -1468,6 +1475,7 @@ constexpr uint8_t epps = ENCODER_PULSES_PER_STEP;
1468 1475
 
1469 1476
     TERN_(EXTENSIBLE_UI, ExtUI::onStatusChanged(status_message));
1470 1477
     TERN_(DWIN_CREALITY_LCD, DWIN_StatusChanged(status_message));
1478
+    TERN_(DWIN_CREALITY_LCD_JYERSUI, CrealityDWIN.Update_Status(status_message));
1471 1479
   }
1472 1480
 
1473 1481
   #if ENABLED(STATUS_MESSAGE_SCROLLING)

+ 10
- 5
Marlin/src/lcd/marlinui.h View File

@@ -55,7 +55,7 @@
55 55
   #include "../module/printcounter.h"
56 56
 #endif
57 57
 
58
-#if ENABLED(ADVANCED_PAUSE_FEATURE) && EITHER(HAS_LCD_MENU, EXTENSIBLE_UI)
58
+#if ENABLED(ADVANCED_PAUSE_FEATURE) && ANY(HAS_LCD_MENU, EXTENSIBLE_UI, DWIN_CREALITY_LCD_JYERSUI)
59 59
   #include "../feature/pause.h"
60 60
   #include "../module/motion.h" // for active_extruder
61 61
 #endif
@@ -76,8 +76,6 @@
76 76
     uint8_t get_ADC_keyValue();
77 77
   #endif
78 78
 
79
-  #define LCD_UPDATE_INTERVAL TERN(HAS_TOUCH_BUTTONS, 50, 100)
80
-
81 79
   #if HAS_LCD_MENU
82 80
 
83 81
     #include "lcdprint.h"
@@ -95,6 +93,10 @@
95 93
 
96 94
 #endif // HAS_WIRED_LCD
97 95
 
96
+#if EITHER(HAS_WIRED_LCD, DWIN_CREALITY_LCD_JYERSUI)
97
+  #define LCD_UPDATE_INTERVAL TERN(HAS_TOUCH_BUTTONS, 50, 100)
98
+#endif
99
+
98 100
 #if HAS_MARLINUI_U8GLIB
99 101
   enum MarlinFont : uint8_t {
100 102
     FONT_STATUSMENU = 1,
@@ -363,6 +365,10 @@ public:
363 365
       static void poweroff();
364 366
     #endif
365 367
 
368
+    #if EITHER(HAS_WIRED_LCD, DWIN_CREALITY_LCD_JYERSUI)
369
+      static bool get_blink();
370
+    #endif
371
+
366 372
     #if HAS_WIRED_LCD
367 373
 
368 374
       static millis_t next_button_update_ms;
@@ -451,7 +457,6 @@ public:
451 457
       static bool did_first_redraw;
452 458
     #endif
453 459
 
454
-    static bool get_blink();
455 460
     static void kill_screen(PGM_P const lcd_error, PGM_P const lcd_component);
456 461
     static void draw_kill_screen();
457 462
 
@@ -580,7 +585,7 @@ public:
580 585
     static inline bool use_click() { return false; }
581 586
   #endif
582 587
 
583
-  #if ENABLED(ADVANCED_PAUSE_FEATURE) && EITHER(HAS_LCD_MENU, EXTENSIBLE_UI)
588
+  #if ENABLED(ADVANCED_PAUSE_FEATURE) && ANY(HAS_LCD_MENU, EXTENSIBLE_UI, DWIN_CREALITY_LCD_JYERSUI)
584 589
     static void pause_show_message(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=active_extruder);
585 590
   #else
586 591
     static inline void _pause_show_message() {}

+ 37
- 0
Marlin/src/module/settings.cpp View File

@@ -73,6 +73,10 @@
73 73
   #include "../lcd/extui/ui_api.h"
74 74
 #endif
75 75
 
76
+#if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
77
+  #include "../lcd/e3v2/jyersui/dwin.h"
78
+#endif
79
+
76 80
 #if HAS_SERVOS
77 81
   #include "servo.h"
78 82
 #endif
@@ -442,6 +446,13 @@ typedef struct SettingsDataStruct {
442 446
   #endif
443 447
 
444 448
   //
449
+  // DWIN_CREALITY_LCD_JYERSUI
450
+  //
451
+  #if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
452
+    uint8_t dwin_settings[CrealityDWIN.eeprom_data_size];
453
+  #endif
454
+
455
+  //
445 456
   // CASELIGHT_USES_BRIGHTNESS
446 457
   //
447 458
   #if CASELIGHT_USES_BRIGHTNESS
@@ -1347,6 +1358,18 @@ void MarlinSettings::postprocess() {
1347 1358
     #endif
1348 1359
 
1349 1360
     //
1361
+    // Creality UI Settings
1362
+    //
1363
+    #if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
1364
+    {
1365
+      char dwin_settings[CrealityDWIN.eeprom_data_size] = { 0 };
1366
+      CrealityDWIN.Save_Settings(dwin_settings);
1367
+      _FIELD_TEST(dwin_settings);
1368
+      EEPROM_WRITE(dwin_settings);
1369
+    }
1370
+    #endif
1371
+
1372
+    //
1350 1373
     // Case Light Brightness
1351 1374
     //
1352 1375
     #if CASELIGHT_USES_BRIGHTNESS
@@ -2226,6 +2249,18 @@ void MarlinSettings::postprocess() {
2226 2249
       #endif
2227 2250
 
2228 2251
       //
2252
+      // Creality UI Settings
2253
+      //
2254
+      #if ENABLED(DWIN_CREALITY_LCD_JYERSUI)
2255
+      {
2256
+        const char dwin_settings[CrealityDWIN.eeprom_data_size] = { 0 };
2257
+        _FIELD_TEST(dwin_settings);
2258
+        EEPROM_READ(dwin_settings);
2259
+        if (!validating) CrealityDWIN.Load_Settings(dwin_settings);
2260
+      }
2261
+      #endif
2262
+
2263
+      //
2229 2264
       // Case Light Brightness
2230 2265
       //
2231 2266
       #if CASELIGHT_USES_BRIGHTNESS
@@ -2622,6 +2657,8 @@ void MarlinSettings::reset() {
2622 2657
 
2623 2658
   TERN_(EXTENSIBLE_UI, ExtUI::onFactoryReset());
2624 2659
 
2660
+  TERN_(DWIN_CREALITY_LCD_JYERSUI, CrealityDWIN.Reset_Settings());
2661
+
2625 2662
   //
2626 2663
   // Case Light Brightness
2627 2664
   //

+ 1
- 1
Marlin/src/pins/lpc1768/pins_BTT_SKR_V1_4.h View File

@@ -266,7 +266,7 @@
266 266
 #define EXP2_09_PIN                        P0_15
267 267
 #define EXP2_10_PIN                        P0_17
268 268
 
269
-#if EITHER(DWIN_CREALITY_LCD, IS_DWIN_MARLINUI)
269
+#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
270 270
 
271 271
   // RET6 DWIN ENCODER LCD
272 272
   #define BTN_ENC                    EXP1_06_PIN

+ 2
- 2
Marlin/src/pins/lpc1769/pins_BTT_SKR_E3_TURBO.h View File

@@ -197,8 +197,8 @@
197 197
 #define EXP1_09_PIN                        P0_16
198 198
 #define EXP1_10_PIN                        P2_08
199 199
 
200
-#if ENABLED(DWIN_CREALITY_LCD)
201
-  #error "DWIN_CREALITY_LCD requires a custom cable with TX = P0_15, RX = P0_16. Comment out this line to continue."
200
+#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
201
+  #error "Ender-3 V2 display requires a custom cable with TX = P0_15, RX = P0_16. Comment out this line to continue."
202 202
 
203 203
  /**
204 204
   *          Ender 3 V2 display                       SKR E3 Turbo (EXP1)                Ender 3 V2 display --> SKR E3 Turbo

+ 1
- 1
Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_E3_common.h View File

@@ -134,7 +134,7 @@
134 134
   #define EXP1_3                            PB7
135 135
 #endif
136 136
 
137
-#if EITHER(DWIN_CREALITY_LCD, IS_DWIN_MARLINUI)
137
+#if EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
138 138
   /**
139 139
    *        ------              ------              ------
140 140
    *   VCC | 1  2 | GND    VCC | 1  2 | GND    GND |  2 1 | VCC

+ 1
- 1
Marlin/src/pins/stm32f1/pins_CREALITY_V4.h View File

@@ -186,7 +186,7 @@
186 186
     #error "Define RET6_12864_LCD or VET6_12864_LCD to select pins for CR10_STOCKDISPLAY with the Creality V4 controller."
187 187
   #endif
188 188
 
189
-#elif EITHER(DWIN_CREALITY_LCD, IS_DWIN_MARLINUI)
189
+#elif EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
190 190
 
191 191
   // RET6 DWIN ENCODER LCD
192 192
   #define BTN_ENC                           PB14

+ 1
- 1
Marlin/src/pins/stm32f1/pins_CREALITY_V4210.h View File

@@ -216,7 +216,7 @@
216 216
   #define BTN_EN1                    EXP1_08_PIN
217 217
   #define BTN_EN2                    EXP1_06_PIN
218 218
 
219
-#elif EITHER(DWIN_CREALITY_LCD, IS_DWIN_MARLINUI)
219
+#elif EITHER(HAS_DWIN_E3V2, IS_DWIN_MARLINUI)
220 220
 
221 221
   // RET6 DWIN ENCODER LCD
222 222
   #define BTN_ENC                           PB14

+ 5
- 0
buildroot/tests/STM32F103RET6_creality View File

@@ -13,6 +13,11 @@ use_example_configs "Creality/Ender-3 V2/CrealityUI"
13 13
 opt_enable MARLIN_DEV_MODE BUFFER_MONITORING
14 14
 exec_test $1 $2 "Ender 3 v2 with CrealityUI" "$3"
15 15
 
16
+use_example_configs "Creality/Ender-3 V2/CrealityUI"
17
+opt_disable DWIN_CREALITY_LCD
18
+opt_enable DWIN_CREALITY_LCD_JYERSUI
19
+exec_test $1 $2 "Ender 3 v2 with JyersUI" "$3"
20
+
16 21
 use_example_configs "Creality/Ender-3 V2/MarlinUI"
17 22
 opt_add SDCARD_EEPROM_EMULATION
18 23
 exec_test $1 $2 "Ender 3 v2 with MarlinUI" "$3"

+ 1
- 0
ini/features.ini View File

@@ -45,6 +45,7 @@ I2C_EEPROM                             = src_filter=+<src/HAL/shared/eeprom_if_i
45 45
 SOFT_I2C_EEPROM                        = SlowSoftI2CMaster, SlowSoftWire=https://github.com/felias-fogg/SlowSoftWire/archive/master.zip
46 46
 SPI_EEPROM                             = src_filter=+<src/HAL/shared/eeprom_if_spi.cpp>
47 47
 DWIN_CREALITY_LCD                      = src_filter=+<src/lcd/e3v2/creality>
48
+DWIN_CREALITY_LCD_JYERSUI              = src_filter=+<src/lcd/e3v2/jyersui>
48 49
 DWIN_MARLINUI_.+                       = src_filter=+<src/lcd/e3v2/marlinui>
49 50
 HAS_GRAPHICAL_TFT                      = src_filter=+<src/lcd/tft>
50 51
 IS_TFTGLCD_PANEL                       = src_filter=+<src/lcd/TFTGLCD>

+ 1
- 1
platformio.ini View File

@@ -49,8 +49,8 @@ extra_scripts      =
49 49
 lib_deps           =
50 50
 default_src_filter = +<src/*> -<src/config> -<src/HAL> +<src/HAL/shared>
51 51
   -<src/lcd/HD44780> -<src/lcd/TFTGLCD> -<src/lcd/dogm> -<src/lcd/tft> -<src/lcd/tft_io>
52
-  -<src/lcd/e3v2/creality> -<src/lcd/e3v2/marlinui>
53 52
   -<src/HAL/STM32/tft> -<src/HAL/STM32F1/tft>
53
+  -<src/lcd/e3v2/creality> -<src/lcd/e3v2/jyersui> -<src/lcd/e3v2/marlinui>
54 54
   -<src/lcd/menu>
55 55
   -<src/lcd/menu/game/game.cpp> -<src/lcd/menu/game/brickout.cpp> -<src/lcd/menu/game/invaders.cpp>
56 56
   -<src/lcd/menu/game/maze.cpp> -<src/lcd/menu/game/snake.cpp>

Loading…
Cancel
Save