Browse Source

Creality Ender 3 v2 (#17719)

Scott Lahteine 4 years ago
parent
commit
f4c258dc23
No account linked to committer's email address
37 changed files with 5376 additions and 79 deletions
  1. 1
    0
      .github/workflows/test-builds.yml
  2. 10
    0
      Marlin/Configuration.h
  3. 6
    2
      Marlin/src/HAL/STM32F1/timers.h
  4. 42
    2
      Marlin/src/MarlinCore.cpp
  5. 1
    0
      Marlin/src/core/boards.h
  6. 10
    4
      Marlin/src/core/serial.h
  7. 11
    3
      Marlin/src/feature/bltouch.h
  8. 5
    0
      Marlin/src/feature/powerloss.cpp
  9. 4
    0
      Marlin/src/feature/powerloss.h
  10. 8
    0
      Marlin/src/gcode/bedlevel/abl/G29.cpp
  11. 7
    0
      Marlin/src/gcode/calibrate/G28.cpp
  12. 2
    2
      Marlin/src/gcode/sd/M24_M25.cpp
  13. 9
    0
      Marlin/src/inc/Conditionals_LCD.h
  14. 5
    1
      Marlin/src/inc/Conditionals_post.h
  15. 3
    1
      Marlin/src/inc/SanityCheck.h
  16. 7
    0
      Marlin/src/lcd/dwin/README.md
  17. 3390
    0
      Marlin/src/lcd/dwin/dwin.cpp
  18. 379
    0
      Marlin/src/lcd/dwin/dwin.h
  19. 302
    0
      Marlin/src/lcd/dwin/dwin_lcd.cpp
  20. 111
    0
      Marlin/src/lcd/dwin/dwin_lcd.h
  21. 263
    0
      Marlin/src/lcd/dwin/eeprom_BL24CXX.cpp
  22. 86
    0
      Marlin/src/lcd/dwin/eeprom_BL24CXX.h
  23. 249
    0
      Marlin/src/lcd/dwin/rotary_encoder.cpp
  24. 105
    0
      Marlin/src/lcd/dwin/rotary_encoder.h
  25. 35
    32
      Marlin/src/lcd/ultralcd.cpp
  26. 20
    9
      Marlin/src/lcd/ultralcd.h
  27. 30
    9
      Marlin/src/module/configuration_store.cpp
  28. 23
    4
      Marlin/src/module/temperature.cpp
  29. 2
    0
      Marlin/src/pins/pins.h
  30. 1
    1
      Marlin/src/pins/stm32f1/pins_BTT_SKR_MINI_V1_1.h
  31. 167
    0
      Marlin/src/pins/stm32f1/pins_CREALITY_V4.h
  32. 20
    9
      Marlin/src/sd/cardreader.cpp
  33. 1
    0
      Marlin/src/sd/cardreader.h
  34. 14
    0
      buildroot/share/PlatformIO/ldscripts/creality.ld
  35. 16
    0
      buildroot/share/PlatformIO/scripts/creality.py
  36. 15
    0
      buildroot/share/tests/STM32F103RET6_creality-tests
  37. 16
    0
      platformio.ini

+ 1
- 0
.github/workflows/test-builds.yml View File

67
         - rumba32_f446ve
67
         - rumba32_f446ve
68
         - rumba32_mks
68
         - rumba32_mks
69
         - mks_robin_pro
69
         - mks_robin_pro
70
+        - STM32F103RET6_creality
70
 
71
 
71
         # Put lengthy tests last
72
         # Put lengthy tests last
72
 
73
 

+ 10
- 0
Marlin/Configuration.h View File

905
 //#define BLTOUCH
905
 //#define BLTOUCH
906
 
906
 
907
 /**
907
 /**
908
+ * Pressure sensor with a BLTouch-like interface
909
+ */
910
+//#define CREALITY_TOUCH
911
+
912
+/**
908
  * Touch-MI Probe by hotends.fr
913
  * Touch-MI Probe by hotends.fr
909
  *
914
  *
910
  * This probe is deployed and activated by moving the X-axis to a magnet at the edge of the bed.
915
  * This probe is deployed and activated by moving the X-axis to a magnet at the edge of the bed.
2131
 //#define SPI_GRAPHICAL_TFT
2136
 //#define SPI_GRAPHICAL_TFT
2132
 
2137
 
2133
 //
2138
 //
2139
+// Ender-3 v2 OEM display. A DWIN display with Rotary Encoder.
2140
+//
2141
+//#define DWIN_CREALITY_LCD
2142
+
2143
+//
2134
 // ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
2144
 // ADS7843/XPT2046 ADC Touchscreen such as ILI9341 2.8
2135
 //
2145
 //
2136
 //#define TOUCH_BUTTONS
2146
 //#define TOUCH_BUTTONS

+ 6
- 2
Marlin/src/HAL/STM32F1/timers.h View File

44
 
44
 
45
 #define HAL_TIMER_RATE uint32_t(F_CPU)  // frequency of timers peripherals
45
 #define HAL_TIMER_RATE uint32_t(F_CPU)  // frequency of timers peripherals
46
 
46
 
47
-#define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
48
-#define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
47
+#ifndef STEP_TIMER_CHAN
48
+  #define STEP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
49
+#endif
50
+#ifndef TEMP_TIMER_CHAN
51
+  #define TEMP_TIMER_CHAN 1 // Channel of the timer to use for compare and interrupts
52
+#endif
49
 
53
 
50
 /**
54
 /**
51
  * Note: Timers may be used by platforms and libraries
55
  * Note: Timers may be used by platforms and libraries

+ 42
- 2
Marlin/src/MarlinCore.cpp View File

65
   #include "lcd/extui/lib/mks_ui/inc/draw_ui.h"
65
   #include "lcd/extui/lib/mks_ui/inc/draw_ui.h"
66
 #endif
66
 #endif
67
 
67
 
68
+#if ENABLED(DWIN_CREALITY_LCD)
69
+  #include "lcd/dwin/dwin.h"
70
+  #include "lcd/dwin/dwin_lcd.h"
71
+  #include "lcd/dwin/rotary_encoder.h"
72
+#endif
73
+
74
+#if ENABLED(IIC_BL24CXX_EEPROM)
75
+  #include "lcd/dwin/eeprom_BL24CXX.h"
76
+#endif
77
+
68
 #if ENABLED(DIRECT_STEPPING)
78
 #if ENABLED(DIRECT_STEPPING)
69
   #include "feature/direct_stepping.h"
79
   #include "feature/direct_stepping.h"
70
 #endif
80
 #endif
689
   // Handle SD Card insert / remove
699
   // Handle SD Card insert / remove
690
   TERN_(SDSUPPORT, card.manage_media());
700
   TERN_(SDSUPPORT, card.manage_media());
691
 
701
 
702
+  // Handle UI input / draw events
703
+  TERN(DWIN_CREALITY_LCD, DWIN_Update(), ui.update());
704
+
692
   // Handle USB Flash Drive insert / remove
705
   // Handle USB Flash Drive insert / remove
693
   TERN_(USB_FLASH_DRIVE_SUPPORT, Sd2Card::idle());
706
   TERN_(USB_FLASH_DRIVE_SUPPORT, Sd2Card::idle());
694
 
707
 
962
   // UI must be initialized before EEPROM
975
   // UI must be initialized before EEPROM
963
   // (because EEPROM code calls the UI).
976
   // (because EEPROM code calls the UI).
964
 
977
 
965
-  SETUP_RUN(ui.init());
966
-  SETUP_RUN(ui.reset_status());       // Load welcome message early. (Retained if no errors exist.)
978
+  #if ENABLED(DWIN_CREALITY_LCD)
979
+    delay(800);   // Required delay (since boot?)
980
+    SERIAL_ECHOPGM("\nDWIN handshake ");
981
+    if (DWIN_Handshake()) SERIAL_ECHOLNPGM("ok."); else SERIAL_ECHOLNPGM("error.");
982
+    DWIN_Frame_SetDir(1); // Orientation 90°
983
+    DWIN_UpdateLCD();     // Show bootscreen (first image)
984
+  #else
985
+    SETUP_RUN(ui.init());
986
+    #if HAS_SPI_LCD && ENABLED(SHOW_BOOTSCREEN)
987
+      SETUP_RUN(ui.show_bootscreen());
988
+    #endif
989
+    SETUP_RUN(ui.reset_status());     // Load welcome message early. (Retained if no errors exist.)
990
+  #endif
967
 
991
 
968
   #if BOTH(HAS_SPI_LCD, SHOW_BOOTSCREEN)
992
   #if BOTH(HAS_SPI_LCD, SHOW_BOOTSCREEN)
969
     SETUP_RUN(ui.show_bootscreen());
993
     SETUP_RUN(ui.show_bootscreen());
1143
     SETUP_RUN(mmu2.init());
1167
     SETUP_RUN(mmu2.init());
1144
   #endif
1168
   #endif
1145
 
1169
 
1170
+  #if ENABLED(IIC_BL24CXX_EEPROM)
1171
+    BL24CXX::init();
1172
+    const uint8_t err = BL24CXX::check();
1173
+    SERIAL_ECHO_TERNARY(err, "I2C_EEPROM Check ", "failed", "succeeded", "!\n");
1174
+  #endif
1175
+
1176
+  #if ENABLED(DWIN_CREALITY_LCD)
1177
+    Encoder_Configuration();
1178
+    HMI_Init();
1179
+    HMI_StartFrame(true);
1180
+  #endif
1181
+
1182
+  #if HAS_SERVICE_INTERVALS && DISABLED(DWIN_CREALITY_LCD)
1183
+    ui.reset_status(true);  // Show service messages or keep current status
1184
+  #endif
1185
+
1146
   #if ENABLED(MAX7219_DEBUG)
1186
   #if ENABLED(MAX7219_DEBUG)
1147
     SETUP_RUN(max7219.init());
1187
     SETUP_RUN(max7219.init());
1148
   #endif
1188
   #endif

+ 1
- 0
Marlin/src/core/boards.h View File

310
 #define BOARD_CCROBOT_MEEB_3DP        4029  // ccrobot-online.com MEEB_3DP (STM32F103RC)
310
 #define BOARD_CCROBOT_MEEB_3DP        4029  // ccrobot-online.com MEEB_3DP (STM32F103RC)
311
 #define BOARD_CHITU3D_V5              4030  // Chitu3D TronXY X5SA V5 Board
311
 #define BOARD_CHITU3D_V5              4030  // Chitu3D TronXY X5SA V5 Board
312
 #define BOARD_CHITU3D_V6              4031  // Chitu3D TronXY X5SA V5 Board
312
 #define BOARD_CHITU3D_V6              4031  // Chitu3D TronXY X5SA V5 Board
313
+#define BOARD_CREALITY_V4             4032  // Creality v4.x (STM32F103RE)
313
 
314
 
314
 //
315
 //
315
 // ARM Cortex-M4F
316
 // ARM Cortex-M4F

+ 10
- 4
Marlin/src/core/serial.h View File

51
   extern int8_t serial_port_index;
51
   extern int8_t serial_port_index;
52
   #define _PORT_REDIRECT(n,p)   REMEMBER(n,serial_port_index,p)
52
   #define _PORT_REDIRECT(n,p)   REMEMBER(n,serial_port_index,p)
53
   #define _PORT_RESTORE(n)      RESTORE(n)
53
   #define _PORT_RESTORE(n)      RESTORE(n)
54
-  #define SERIAL_OUT(WHAT, V...) do{ \
55
-    if (!serial_port_index || serial_port_index == SERIAL_BOTH) (void)MYSERIAL0.WHAT(V); \
56
-    if ( serial_port_index) (void)MYSERIAL1.WHAT(V); \
57
-  }while(0)
54
+
55
+  #ifdef SERIAL_CATCHALL
56
+    #define SERIAL_OUT(WHAT, V...) (void)CAT(MYSERIAL,SERIAL_CATCHALL).WHAT(V)
57
+  #else
58
+    #define SERIAL_OUT(WHAT, V...) do{ \
59
+      if (!serial_port_index || serial_port_index == SERIAL_BOTH) (void)MYSERIAL0.WHAT(V); \
60
+      if ( serial_port_index) (void)MYSERIAL1.WHAT(V); \
61
+    }while(0)
62
+  #endif
63
+
58
   #define SERIAL_ASSERT(P)      if(serial_port_index!=(P)){ debugger(); }
64
   #define SERIAL_ASSERT(P)      if(serial_port_index!=(P)){ debugger(); }
59
 #else
65
 #else
60
   #define _PORT_REDIRECT(n,p)   NOOP
66
   #define _PORT_REDIRECT(n,p)   NOOP

+ 11
- 3
Marlin/src/feature/bltouch.h View File

26
 // BLTouch commands are sent as servo angles
26
 // BLTouch commands are sent as servo angles
27
 typedef unsigned char BLTCommand;
27
 typedef unsigned char BLTCommand;
28
 
28
 
29
-#define BLTOUCH_DEPLOY          10
29
+#if ENABLED(CREALITY_TOUCH)
30
+  #define STOW_ALARM         false
31
+  #define BLTOUCH_DEPLOY       170
32
+  #define BLTOUCH_STOW          20
33
+#else
34
+  #define STOW_ALARM          true
35
+  #define BLTOUCH_DEPLOY        10
36
+  #define BLTOUCH_STOW          90
37
+#endif
38
+
30
 #define BLTOUCH_SW_MODE         60
39
 #define BLTOUCH_SW_MODE         60
31
-#define BLTOUCH_STOW            90
32
 #define BLTOUCH_SELFTEST       120
40
 #define BLTOUCH_SELFTEST       120
33
 #define BLTOUCH_MODE_STORE     130
41
 #define BLTOUCH_MODE_STORE     130
34
 #define BLTOUCH_5V_MODE        140
42
 #define BLTOUCH_5V_MODE        140
95
 
103
 
96
 private:
104
 private:
97
   FORCE_INLINE static bool _deploy_query_alarm() { return command(BLTOUCH_DEPLOY, BLTOUCH_DEPLOY_DELAY); }
105
   FORCE_INLINE static bool _deploy_query_alarm() { return command(BLTOUCH_DEPLOY, BLTOUCH_DEPLOY_DELAY); }
98
-  FORCE_INLINE static bool _stow_query_alarm()   { return command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY); }
106
+  FORCE_INLINE static bool _stow_query_alarm()   { return command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY) == STOW_ALARM; }
99
 
107
 
100
   static void clear();
108
   static void clear();
101
   static bool command(const BLTCommand cmd, const millis_t &ms);
109
   static bool command(const BLTCommand cmd, const millis_t &ms);

+ 5
- 0
Marlin/src/feature/powerloss.cpp View File

40
 uint32_t PrintJobRecovery::cmd_sdpos, // = 0
40
 uint32_t PrintJobRecovery::cmd_sdpos, // = 0
41
          PrintJobRecovery::sdpos[BUFSIZE];
41
          PrintJobRecovery::sdpos[BUFSIZE];
42
 
42
 
43
+#if ENABLED(DWIN_CREALITY_LCD)
44
+  bool PrintJobRecovery::dwin_flag; // = false
45
+#endif
46
+
43
 #include "../sd/cardreader.h"
47
 #include "../sd/cardreader.h"
44
 #include "../lcd/ultralcd.h"
48
 #include "../lcd/ultralcd.h"
45
 #include "../gcode/queue.h"
49
 #include "../gcode/queue.h"
105
     load();
109
     load();
106
     if (!valid()) return cancel();
110
     if (!valid()) return cancel();
107
     queue.inject_P(PSTR("M1000 S"));
111
     queue.inject_P(PSTR("M1000 S"));
112
+    TERN_(DWIN_CREALITY_LCD, dwin_flag = true);
108
   }
113
   }
109
 }
114
 }
110
 
115
 

+ 4
- 0
Marlin/src/feature/powerloss.h View File

121
     static uint32_t cmd_sdpos,        //!< SD position of the next command
121
     static uint32_t cmd_sdpos,        //!< SD position of the next command
122
                     sdpos[BUFSIZE];   //!< SD positions of queued commands
122
                     sdpos[BUFSIZE];   //!< SD positions of queued commands
123
 
123
 
124
+    #if ENABLED(DWIN_CREALITY_LCD)
125
+      static bool dwin_flag;
126
+    #endif
127
+
124
     static void init();
128
     static void init();
125
     static void prepare();
129
     static void prepare();
126
 
130
 

+ 8
- 0
Marlin/src/gcode/bedlevel/abl/G29.cpp View File

60
   #include "../../../lcd/extui/ui_api.h"
60
   #include "../../../lcd/extui/ui_api.h"
61
 #endif
61
 #endif
62
 
62
 
63
+#if ENABLED(DWIN_CREALITY_LCD)
64
+  #include "../../../lcd/dwin/dwin.h"
65
+#endif
66
+
63
 #if HAS_MULTI_HOTEND
67
 #if HAS_MULTI_HOTEND
64
   #include "../../../module/tool_change.h"
68
   #include "../../../module/tool_change.h"
65
 #endif
69
 #endif
888
     process_subcommands_now_P(PSTR(Z_PROBE_END_SCRIPT));
892
     process_subcommands_now_P(PSTR(Z_PROBE_END_SCRIPT));
889
   #endif
893
   #endif
890
 
894
 
895
+  #if ENABLED(DWIN_CREALITY_LCD)
896
+    DWIN_CompletedLeveling();
897
+  #endif
898
+
891
   report_current_position();
899
   report_current_position();
892
 
900
 
893
   if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G29");
901
   if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< G29");

+ 7
- 0
Marlin/src/gcode/calibrate/G28.cpp View File

46
 #endif
46
 #endif
47
 
47
 
48
 #include "../../lcd/ultralcd.h"
48
 #include "../../lcd/ultralcd.h"
49
+#if ENABLED(DWIN_CREALITY_LCD)
50
+  #include "../../lcd/dwin/dwin.h"
51
+#endif
49
 
52
 
50
 #if HAS_L64XX                         // set L6470 absolute position registers to counts
53
 #if HAS_L64XX                         // set L6470 absolute position registers to counts
51
   #include "../../libs/L64XX/L64XX_Marlin.h"
54
   #include "../../libs/L64XX/L64XX_Marlin.h"
209
     log_machine_info();
212
     log_machine_info();
210
   }
213
   }
211
 
214
 
215
+  TERN_(DWIN_CREALITY_LCD, HMI_flag.home_flag = true);
216
+
212
   #if ENABLED(DUAL_X_CARRIAGE)
217
   #if ENABLED(DUAL_X_CARRIAGE)
213
     bool IDEX_saved_duplication_state = extruder_duplication_enabled;
218
     bool IDEX_saved_duplication_state = extruder_duplication_enabled;
214
     DualXMode IDEX_saved_mode = dual_x_carriage_mode;
219
     DualXMode IDEX_saved_mode = dual_x_carriage_mode;
475
 
480
 
476
   ui.refresh();
481
   ui.refresh();
477
 
482
 
483
+  TERN_(DWIN_CREALITY_LCD, DWIN_CompletedHoming());
484
+
478
   report_current_position();
485
   report_current_position();
479
 
486
 
480
   if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))
487
   if (ENABLED(NANODLP_Z_SYNC) && (doZ || ENABLED(NANODLP_ALL_AXIS)))

+ 2
- 2
Marlin/src/gcode/sd/M24_M25.cpp View File

31
 
31
 
32
 #if ENABLED(PARK_HEAD_ON_PAUSE)
32
 #if ENABLED(PARK_HEAD_ON_PAUSE)
33
   #include "../../feature/pause.h"
33
   #include "../../feature/pause.h"
34
-  #include "../queue.h"
35
 #endif
34
 #endif
36
 
35
 
37
 #if ENABLED(HOST_ACTION_COMMANDS)
36
 #if ENABLED(HOST_ACTION_COMMANDS)
98
     #endif
97
     #endif
99
 
98
 
100
     print_job_timer.pause();
99
     print_job_timer.pause();
101
-    ui.reset_status();
100
+
101
+    TERN(DWIN_CREALITY_LCD,,ui.reset_status());
102
 
102
 
103
     #if ENABLED(HOST_ACTION_COMMANDS)
103
     #if ENABLED(HOST_ACTION_COMMANDS)
104
       TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_PAUSE_RESUME, PSTR("Pause SD"), PSTR("Resume")));
104
       TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_PAUSE_RESUME, PSTR("Pause SD"), PSTR("Resume")));

+ 9
- 0
Marlin/src/inc/Conditionals_LCD.h View File

529
   #define UNUSED_E(E) UNUSED(E)
529
   #define UNUSED_E(E) UNUSED(E)
530
 #endif
530
 #endif
531
 
531
 
532
+#if ENABLED(DWIN_CREALITY_LCD)
533
+  #define SERIAL_CATCHALL 0
534
+#endif
535
+
536
+// Pressure sensor with a BLTouch-like interface
537
+#if ENABLED(CREALITY_TOUCH)
538
+  #define BLTOUCH
539
+#endif
540
+
532
 /**
541
 /**
533
  * The BLTouch Probe emulates a servo probe
542
  * The BLTouch Probe emulates a servo probe
534
  * and uses "special" angles for its state.
543
  * and uses "special" angles for its state.

+ 5
- 1
Marlin/src/inc/Conditionals_post.h View File

2465
 #endif
2465
 #endif
2466
 
2466
 
2467
 // Number of VFAT entries used. Each entry has 13 UTF-16 characters
2467
 // Number of VFAT entries used. Each entry has 13 UTF-16 characters
2468
-#define MAX_VFAT_ENTRIES TERN(SCROLL_LONG_FILENAMES, 5, 2)
2468
+#if EITHER(SCROLL_LONG_FILENAMES, DWIN_CREALITY_LCD)
2469
+  #define MAX_VFAT_ENTRIES (5)
2470
+#else
2471
+  #define MAX_VFAT_ENTRIES (2)
2472
+#endif
2469
 
2473
 
2470
 // Nozzle park for Delta
2474
 // Nozzle park for Delta
2471
 #if BOTH(NOZZLE_PARK_FEATURE, DELTA)
2475
 #if BOTH(NOZZLE_PARK_FEATURE, DELTA)

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

1165
   + ENABLED(FIX_MOUNTED_PROBE) \
1165
   + ENABLED(FIX_MOUNTED_PROBE) \
1166
   + ENABLED(NOZZLE_AS_PROBE) \
1166
   + ENABLED(NOZZLE_AS_PROBE) \
1167
   + (HAS_Z_SERVO_PROBE && DISABLED(BLTOUCH)) \
1167
   + (HAS_Z_SERVO_PROBE && DISABLED(BLTOUCH)) \
1168
-  + ENABLED(BLTOUCH) \
1168
+  + ENABLED(BLTOUCH) && DISABLED(CREALITY_TOUCH) \
1169
+  + ENABLED(CREALITY_TOUCH) \
1169
   + ENABLED(TOUCH_MI_PROBE) \
1170
   + ENABLED(TOUCH_MI_PROBE) \
1170
   + ENABLED(SOLENOID_PROBE) \
1171
   + ENABLED(SOLENOID_PROBE) \
1171
   + ENABLED(Z_PROBE_ALLEN_KEY) \
1172
   + ENABLED(Z_PROBE_ALLEN_KEY) \
2150
   + ENABLED(FYSETC_MINI_12864_2_1) \
2151
   + ENABLED(FYSETC_MINI_12864_2_1) \
2151
   + ENABLED(FYSETC_GENERIC_12864_1_1) \
2152
   + ENABLED(FYSETC_GENERIC_12864_1_1) \
2152
   + ENABLED(CR10_STOCKDISPLAY) \
2153
   + ENABLED(CR10_STOCKDISPLAY) \
2154
+  + ENABLED(DWIN_CREALITY_LCD) \
2153
   + ENABLED(ANET_FULL_GRAPHICS_LCD) \
2155
   + ENABLED(ANET_FULL_GRAPHICS_LCD) \
2154
   + ENABLED(AZSMZ_12864) \
2156
   + ENABLED(AZSMZ_12864) \
2155
   + ENABLED(SILVER_GATE_GLCD_CONTROLLER) \
2157
   + ENABLED(SILVER_GATE_GLCD_CONTROLLER) \

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

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.

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


+ 379
- 0
Marlin/src/lcd/dwin/dwin.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+ * DWIN by Creality3D
26
+ */
27
+
28
+#include "dwin_lcd.h"
29
+#include "rotary_encoder.h"
30
+#include "eeprom_BL24CXX.h"
31
+
32
+#include <stdint.h>
33
+
34
+#define MACHINE_SIZE    "220x220x250"
35
+#define CORP_WEBSITE_C  "www.cxsw3d.com"
36
+#define CORP_WEBSITE_E  "www.creality.com"
37
+
38
+/*********************************/
39
+
40
+#define MENU_CHAR_LIMIT  24
41
+
42
+/*fan speed limit*/
43
+#define FanOn           255
44
+#define FanOff          0
45
+
46
+/*print speed limit*/
47
+#define max_print_speed   999
48
+#define min_print_speed   10
49
+
50
+/*Temp limit*/
51
+#define max_E_Temp    (HEATER_0_MAXTEMP - 15)
52
+#define min_E_Temp    HEATER_0_MINTEMP
53
+#define max_Bed_Temp  (BED_MAXTEMP  - 10)
54
+#define min_Bed_Temp  BED_MINTEMP
55
+
56
+/*Feedspeed limit*/  // max feedspeed = DEFAULT_MAX_FEEDRATE * 2
57
+#define min_MaxFeedspeed      1
58
+#define min_MaxAcceleration   1
59
+#define min_MaxCorner         0.1
60
+#define min_Step              1
61
+
62
+#define FEEDRATE_E      (60)
63
+
64
+// mininum unit (0.1) : multiple (10)
65
+#define MinUnitMult   10
66
+
67
+#define Encoder_wait    20
68
+#define DWIN_SCROLL_UPDATE_INTERVAL 2000
69
+#define DWIN_REMAIN_TIME_UPDATE_INTERVAL 20000
70
+
71
+enum processID {
72
+  /*Process ID*/
73
+  MainMenu,
74
+  SelectFile,
75
+  Prepare,
76
+  Control,
77
+  Leveling,
78
+  PrintProcess,
79
+  AxisMove,
80
+  TemperatureID,
81
+  Motion,
82
+  Info,
83
+  Tune,
84
+  PLAPreheat,
85
+  ABSPreheat,
86
+  MaxSpeed,
87
+  MaxSpeed_value,
88
+  MaxAcceleration,
89
+  MaxAcceleration_value,
90
+  MaxCorner,
91
+  MaxCorner_value,
92
+  Step,
93
+  Step_value,
94
+
95
+  /*Last Process ID*/
96
+  Last_Prepare,
97
+
98
+  /*Back Process ID*/
99
+  Back_Main,
100
+  Back_Print,
101
+
102
+  /*Date variable ID*/
103
+  Move_X,
104
+  Move_Y,
105
+  Move_Z,
106
+  Extruder,
107
+  Homeoffset,
108
+  ETemp,
109
+  BedTemp,
110
+  FanSpeed,
111
+  PrintSpeed,
112
+
113
+  /*Window ID*/
114
+  Print_window,
115
+  Popup_Window
116
+};
117
+
118
+/*Picture ID*/
119
+#define Start_Process       0
120
+#define Language_English    1
121
+#define Language_Chinese    2
122
+
123
+/*ICON ID*/
124
+#define ICON                      0x09
125
+#define ICON_LOGO                  0
126
+#define ICON_Print_0               1
127
+#define ICON_Print_1               2
128
+#define ICON_Prepare_0             3
129
+#define ICON_Prepare_1             4
130
+#define ICON_Control_0             5
131
+#define ICON_Control_1             6
132
+#define ICON_Leveling_0            7
133
+#define ICON_Leveling_1            8
134
+#define ICON_HotendTemp            9
135
+#define ICON_BedTemp              10
136
+#define ICON_Speed                11
137
+#define ICON_Zoffset              12
138
+#define ICON_Back                 13
139
+#define ICON_File                 14
140
+#define ICON_PrintTime            15
141
+#define ICON_RemainTime           16
142
+#define ICON_Setup_0              17
143
+#define ICON_Setup_1              18
144
+#define ICON_Pause_0              19
145
+#define ICON_Pause_1              20
146
+#define ICON_Continue_0           21
147
+#define ICON_Continue_1           22
148
+#define ICON_Stop_0               23
149
+#define ICON_Stop_1               24
150
+#define ICON_Bar                  25
151
+#define ICON_More                 26
152
+
153
+#define ICON_Axis                 27
154
+#define ICON_CloseMotor           28
155
+#define ICON_Homing               29
156
+#define ICON_SetHome              30
157
+#define ICON_PLAPreheat           31
158
+#define ICON_ABSPreheat           32
159
+#define ICON_Cool                 33
160
+#define ICON_Language             34
161
+
162
+#define ICON_MoveX                35
163
+#define ICON_MoveY                36
164
+#define ICON_MoveZ                37
165
+#define ICON_Extruder             38
166
+
167
+#define ICON_Temperature          40
168
+#define ICON_Motion               41
169
+#define ICON_WriteEEPROM          42
170
+#define ICON_ReadEEPROM           43
171
+#define ICON_ResumeEEPROM         44
172
+#define ICON_Info                 45
173
+
174
+#define ICON_SetEndTemp           46
175
+#define ICON_SetBedTemp           47
176
+#define ICON_FanSpeed             48
177
+#define ICON_SetPLAPreheat        49
178
+#define ICON_SetABSPreheat        50
179
+
180
+#define ICON_MaxSpeed             51
181
+#define ICON_MaxAccelerated       52
182
+#define ICON_MaxCorner            53
183
+#define ICON_Step                 54
184
+#define ICON_PrintSize            55
185
+#define ICON_Version              56
186
+#define ICON_Contact              57
187
+#define ICON_StockConfiguraton    58
188
+#define ICON_MaxSpeedX            59
189
+#define ICON_MaxSpeedY            60
190
+#define ICON_MaxSpeedZ            61
191
+#define ICON_MaxSpeedE            62
192
+#define ICON_MaxAccX              63
193
+#define ICON_MaxAccY              64
194
+#define ICON_MaxAccZ              65
195
+#define ICON_MaxAccE              66
196
+#define ICON_MaxSpeedCornerX      67
197
+#define ICON_MaxSpeedCornerY      68
198
+#define ICON_MaxSpeedCornerZ      69
199
+#define ICON_MaxSpeedCornerE      70
200
+#define ICON_StepX                71
201
+#define ICON_StepY                72
202
+#define ICON_StepZ                73
203
+#define ICON_StepE                74
204
+#define ICON_Setspeed             75
205
+#define ICON_SetZOffset           76
206
+#define ICON_Rectangle            77
207
+#define ICON_BLTouch              78
208
+#define ICON_TempTooLow           79
209
+#define ICON_AutoLeveling         80
210
+#define ICON_TempTooHigh          81
211
+#define ICON_NoTips_C             82
212
+#define ICON_NoTips_E             83
213
+#define ICON_Continue_C           84
214
+#define ICON_Continue_E           85
215
+#define ICON_Cancel_C             86
216
+#define ICON_Cancel_E             87
217
+#define ICON_Confirm_C            88
218
+#define ICON_Confirm_E            89
219
+#define ICON_Info_0               90
220
+#define ICON_Info_1               91
221
+
222
+/*
223
+* 3-.0:字号大小,0x00-0x09,对应字体大小于下:
224
+* 0x00=6*12   0x01=8*16   0x02=10*20  0x03=12*24  0x04=14*28
225
+* 0x05=16*32  0x06=20*40  0x07=24*48  0x08=28*56  0x09=32*64
226
+*/
227
+#define font6x12  0x00
228
+#define font8x16  0x01
229
+#define font10x20 0x02
230
+#define font12x24 0x03
231
+#define font14x28 0x04
232
+#define font16x32 0x05
233
+#define font20x40 0x06
234
+#define font24x48 0x07
235
+#define font28x56 0x08
236
+#define font32x64 0x09
237
+
238
+/* Colour */
239
+#define White             0xFFFF
240
+#define Background_window 0x31E8  // 弹窗背景色
241
+#define Background_blue   0x1125  // 暗蓝背景色
242
+#define Background_black  0x0841  // 黑色背景色
243
+#define Font_window       0xD6BA  // 弹窗字体背景色
244
+#define Line_Color        0x3A6A  // 分割线颜色
245
+#define Rectangle_Color   0xEE2F  // 蓝色方块光标颜色
246
+#define Percent_Color     0xFE29  // 百分比颜色
247
+#define BarFill_Color     0x10E4  // 进度条填充色
248
+#define Select_Color      0x33BB  // 选中色
249
+
250
+extern int checkkey, last_checkkey;
251
+extern float zprobe_zoffset;
252
+extern char print_filename[16];
253
+
254
+extern millis_t heat_time;
255
+
256
+typedef struct {
257
+  int16_t E_Temp          = 0;
258
+  int16_t Bed_Temp        = 0;
259
+  int16_t Fan_speed       = 0;
260
+  int16_t print_speed     = 100;
261
+  float Max_Feedspeed       = 0;
262
+  float Max_Acceleration    = 0;
263
+  float Max_Corner          = 0;
264
+  float Max_Step           = 0;
265
+  float Move_X_scale        = 0;
266
+  float Move_Y_scale        = 0;
267
+  float Move_Z_scale        = 0;
268
+  float Move_E_scale        = 0;
269
+  float offset_value        = 0;
270
+  char show_mode            = 0;    // -1: Temperature control    0: Printing temperature
271
+  int16_t preheat_hotend_temp[2];
272
+  int16_t preheat_bed_temp[2];
273
+  uint8_t preheat_fan_speed[2];
274
+} HMI_value_t;
275
+
276
+typedef struct {
277
+  bool language_flag;  // 0: EN, 1: CN
278
+  bool pause_flag:1;
279
+  bool print_finish:1;
280
+  bool confirm_flag:1;
281
+  bool select_flag:1;
282
+  bool home_flag:1;
283
+  bool heat_flag:1;  // 0: heating done  1: during heating
284
+  bool ETempTooLow_flag:1;
285
+  bool leveling_offset_flag:1;
286
+  char feedspeed_flag;
287
+  char acc_flag;
288
+  char corner_flag;
289
+  char step_flag;
290
+} HMI_Flag;
291
+
292
+extern HMI_value_t HMI_ValueStruct;
293
+extern HMI_Flag    HMI_flag;
294
+
295
+/* Language */
296
+void lcd_select_language(void);
297
+void set_english_to_eeprom(void);
298
+void set_chinese_to_eeprom(void);
299
+
300
+/* Show ICON*/
301
+void ICON_Print(bool show);
302
+void ICON_Prepare(bool show);
303
+void ICON_Control(bool show);
304
+void ICON_Leveling(bool show);
305
+void ICON_StartInfo(bool show);
306
+
307
+void ICON_Setting(bool show);
308
+void ICON_Pause(bool show);
309
+void ICON_Continue(bool show);
310
+void ICON_Stop(bool show);
311
+
312
+/* Popup window tips */
313
+void Popup_Window_Temperature(const bool toohigh);
314
+void Popup_Window_ETempTooLow(void);
315
+void Popup_Window_Resume(void);
316
+void Popup_Window_Home(void);
317
+void Popup_Window_Leveling(void);
318
+
319
+void Goto_PrintProcess(void);
320
+void Goto_MainMenu(void);
321
+
322
+/* Variable control */
323
+void HMI_Move_X(void);
324
+void HMI_Move_Y(void);
325
+void HMI_Move_Z(void);
326
+void HMI_Move_E(void);
327
+
328
+void HMI_Zoffset(void);
329
+void HMI_ETemp(void);
330
+void HMI_BedTemp(void);
331
+void HMI_FanSpeed(void);
332
+void HMI_PrintSpeed(void);
333
+
334
+void HMI_MaxFeedspeedXYZE(void);
335
+void HMI_MaxAccelerationXYZE(void);
336
+void HMI_MaxCornerXYZE(void);
337
+void HMI_StepXYZE(void);
338
+
339
+void update_variable(void);
340
+void show_plus_or_minus(uint8_t size, uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value);
341
+
342
+/* SD Card */
343
+void HMI_SDCardInit(void);
344
+void HMI_SDCardUpdate(void);
345
+
346
+/* Main Process */
347
+void Icon_print(bool value);
348
+void Icon_control(bool value);
349
+void Icon_temperature(bool value);
350
+void Icon_leveling(bool value);
351
+
352
+/* Other */
353
+bool Pause_HeatStatus();
354
+void HMI_StartFrame(const bool with_update); // 开机画面
355
+void HMI_MainMenu(void);          // 主进程画面
356
+void HMI_SelectFile(void);        // 文件页
357
+void HMI_Printing(void);          // 打印页
358
+void HMI_Prepare(void);           // 准备页
359
+void HMI_Control(void);           // 控制页
360
+void HMI_Leveling(void);          // 调平页
361
+void HMI_AxisMove(void);          // 轴移动菜单
362
+void HMI_Temperature(void);       // 温度菜单
363
+void HMI_Motion(void);            // 运动菜单
364
+void HMI_Info(void);              // 信息菜单
365
+void HMI_Tune(void);              // 调整菜单
366
+void HMI_PLAPreheatSetting(void); // PLA预热设置
367
+void HMI_ABSPreheatSetting(void); // ABS预热设置
368
+void HMI_MaxSpeed(void);          // 最大速度子菜单
369
+void HMI_MaxAcceleration(void);   // 最大加速度子菜单
370
+void HMI_MaxCorner(void);         // 最大拐角速度子菜单
371
+void HMI_Step(void);              // 传动比
372
+
373
+void HMI_Init(void);
374
+void DWIN_Update(void);
375
+void EachMomentUpdate(void);
376
+void DWIN_HandleScreen(void);
377
+
378
+void DWIN_CompletedHoming(void);
379
+void DWIN_CompletedLeveling(void);

+ 302
- 0
Marlin/src/lcd/dwin/dwin_lcd.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/********************************************************************************
24
+ * @file     dwin_lcd.c
25
+ * @author   LEO / Creality3D
26
+ * @date     2019/07/18
27
+ * @version  2.0.1
28
+ * @brief    迪文屏控制操作函数
29
+ ********************************************************************************/
30
+
31
+#include "../../inc/MarlinConfigPre.h"
32
+
33
+#if ENABLED(DWIN_CREALITY_LCD)
34
+
35
+#include "../../inc/MarlinConfig.h"
36
+
37
+#include "dwin_lcd.h"
38
+#include <string.h> // for memset
39
+
40
+// Make sure DWIN_SendBuf is large enough to hold the largest
41
+// printed string plus the draw command and tail.
42
+uint8_t DWIN_SendBuf[11 + 24] = { 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, char * const string) {
66
+  const size_t len = strlen(string);
67
+  memcpy(&DWIN_SendBuf[i+1], string, len);
68
+  i += len;
69
+}
70
+
71
+/*发送当前BUF中的数据以及包尾数据 len:整包数据长度*/
72
+inline void DWIN_Send(size_t &i) {
73
+  ++i;
74
+  LOOP_L_N(n, i) {  MYSERIAL1.write(DWIN_SendBuf[n]);
75
+                    delayMicroseconds(1); }
76
+  LOOP_L_N(n, 4) {  MYSERIAL1.write(DWIN_BufTail[n]);
77
+                    delayMicroseconds(1); }
78
+}
79
+
80
+/*----------------------------------------------系统变量函数----------------------------------------------*/
81
+/*握手 1: 握手成功  2: 握手失败*/
82
+bool DWIN_Handshake(void) {
83
+  size_t i = 0;
84
+  DWIN_Byte(i, 0x00);
85
+  DWIN_Send(i);
86
+
87
+  while (MYSERIAL1.available() > 0 && recnum < (signed)sizeof(databuf)) {
88
+    databuf[recnum] = MYSERIAL1.read();
89
+    // ignore the invalid data
90
+    if (databuf[0] != FHONE) { // prevent the program from running.
91
+      if (recnum > 0) {
92
+        recnum = 0;
93
+        ZERO(databuf);
94
+      }
95
+      continue;
96
+    }
97
+    delay(10);
98
+    recnum++;
99
+  }
100
+
101
+  return ( recnum >= 3
102
+        && databuf[0] == FHONE
103
+        && databuf[1] == '\0'
104
+        && databuf[2] == 'O'
105
+        && databuf[3] == 'K' );
106
+}
107
+
108
+/*设定背光亮度 luminance:亮度(0x00~0xFF)*/
109
+void DWIN_Backlight_SetLuminance(const uint8_t luminance) {
110
+  size_t i = 0;
111
+  DWIN_Byte(i, 0x30);
112
+  DWIN_Byte(i, _MAX(luminance, 0x1F));
113
+  DWIN_Send(i);
114
+}
115
+
116
+/*设定画面显示方向 dir:0,0°; 1,90°; 2,180°; 3,270°*/
117
+void DWIN_Frame_SetDir(uint8_t dir) {
118
+  size_t i = 0;
119
+  DWIN_Byte(i, 0x34);
120
+  DWIN_Byte(i, 0x5A);
121
+  DWIN_Byte(i, 0xA5);
122
+  DWIN_Byte(i, dir);
123
+  DWIN_Send(i);
124
+}
125
+
126
+/*更新显示*/
127
+void DWIN_UpdateLCD(void) {
128
+  size_t i = 0;
129
+  DWIN_Byte(i, 0x3D);
130
+  DWIN_Send(i);
131
+}
132
+
133
+/*----------------------------------------------绘图相关函数----------------------------------------------*/
134
+/*画面清屏 color:清屏颜色*/
135
+void DWIN_Frame_Clear(const uint16_t color) {
136
+  size_t i = 0;
137
+  DWIN_Byte(i, 0x01);
138
+  DWIN_Word(i, color);
139
+  DWIN_Send(i);
140
+}
141
+
142
+/*画面画线 color:线段颜色 xStart:X起始坐标 yStart:Y起始坐标 xEnd:X终止坐标 yEnd:Y终止坐标*/
143
+void DWIN_Draw_Line(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
144
+  size_t i = 0;
145
+  DWIN_Byte(i, 0x03);
146
+  DWIN_Word(i, color);
147
+  DWIN_Word(i, xStart);
148
+  DWIN_Word(i, yStart);
149
+  DWIN_Word(i, xEnd);
150
+  DWIN_Word(i, yEnd);
151
+  DWIN_Send(i);
152
+}
153
+
154
+/*画面画矩形 mode:0,外框;1,填充;2,异或填充 color:颜色 xStart/yStart:矩形左上坐标 xEnd/yEnd:矩形右下坐标*/
155
+void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color,
156
+                         uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
157
+  size_t i = 0;
158
+  DWIN_Byte(i, 0x05);
159
+  DWIN_Byte(i, mode);
160
+  DWIN_Word(i, color);
161
+  DWIN_Word(i, xStart);
162
+  DWIN_Word(i, yStart);
163
+  DWIN_Word(i, xEnd);
164
+  DWIN_Word(i, yEnd);
165
+  DWIN_Send(i);
166
+}
167
+
168
+/*画面区域移动 mode:0,环移;1,平移 dir:0,向左移动;1,向右移动;2,向上移动;3,向下移动 dis:移动距离
169
+                color:填充颜色 xStart/yStart:选定区域左上坐标 xEnd/yEnd:选定区域右下坐标*/
170
+void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
171
+                         uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd) {
172
+  size_t i = 0;
173
+  DWIN_Byte(i, 0x09);
174
+  DWIN_Byte(i, (mode << 7) | dir);
175
+  DWIN_Word(i, dis);
176
+  DWIN_Word(i, color);
177
+  DWIN_Word(i, xStart);
178
+  DWIN_Word(i, yStart);
179
+  DWIN_Word(i, xEnd);
180
+  DWIN_Word(i, yEnd);
181
+  DWIN_Send(i);
182
+}
183
+
184
+/*----------------------------------------------文本相关函数----------------------------------------------*/
185
+/*画面显示字符串 widthAdjust:true,自调整字符宽度;false,不调整字符宽度 bShow:true,显示背景色;false,不显示背景色 size:字号大小
186
+                  color:字符颜色 bColor:背景颜色 x/y:字符串左上坐标 *string:字符串*/
187
+void DWIN_Draw_String(bool widthAdjust, bool bShow, uint8_t size,
188
+                      uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, char *string) {
189
+  size_t i = 0;
190
+  DWIN_Byte(i, 0x11);
191
+  DWIN_Byte(i, (widthAdjust? 0x80:0x00) | (bShow? 0x40:0x00) | size);
192
+  DWIN_Word(i, color);
193
+  DWIN_Word(i, bColor);
194
+  DWIN_Word(i, x);
195
+  DWIN_Word(i, y);
196
+  DWIN_String(i, string);
197
+  DWIN_Send(i);
198
+}
199
+
200
+/*画面显示正整数 bShow:true,显示背景色;false,不显示背景色 zeroFill:true,补零;false,不补零 zeroMode:1,无效0显示为0; 0,无效0显示为空格 size:字号大小
201
+                  color:字符颜色 bColor:背景颜色 iNum:位数 x/y:变量左上坐标 value:整型变量*/
202
+void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
203
+                          uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint16_t value) {
204
+  size_t i = 0;
205
+  DWIN_Byte(i, 0x14);
206
+  DWIN_Byte(i, (bShow? 0x80:0x00) | (zeroFill? 0x20:0x00) | (zeroMode? 0x10:0x00) | size);
207
+  DWIN_Word(i, color);
208
+  DWIN_Word(i, bColor);
209
+  DWIN_Byte(i, iNum);
210
+  DWIN_Byte(i, 0); // fNum
211
+  DWIN_Word(i, x);
212
+  DWIN_Word(i, y);
213
+  #if 0
214
+    for (char count = 0; count < 8; count++) {
215
+      DWIN_Byte(i, value);
216
+      value >>= 8;
217
+      if ((value&0xFF) == 0x00) break;
218
+    }
219
+  #else
220
+    // Write a big-endian 64 bit integer
221
+    const size_t p = i + 1;
222
+    for (char count = 8; count--;) { // 7..0
223
+      ++i;
224
+      DWIN_SendBuf[p + count] = value;
225
+      value >>= 8;
226
+    }
227
+  #endif
228
+
229
+  DWIN_Send(i);
230
+}
231
+
232
+/*画面显示浮点数 bShow:true,显示背景色;false,不显示背景色 zeroFill:true,补零;false,不补零 zeroMode:1,无效0显示为0; 0,无效0显示为空格 size:字号大小
233
+                  color:字符颜色 bColor:背景颜色 iNum:整数位数 fNum:小数位数 x/y:变量左上坐标 value:浮点数变量*/
234
+void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
235
+                            uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value) {
236
+  //uint8_t *fvalue = (uint8_t*)&value;
237
+  size_t i = 0;
238
+  DWIN_Byte(i, 0x14);
239
+  DWIN_Byte(i, (bShow? 0x80:0x00) | (zeroFill? 0x20:0x00) | (zeroMode? 0x10:0x00) | size);
240
+  DWIN_Word(i, color);
241
+  DWIN_Word(i, bColor);
242
+  DWIN_Byte(i, iNum);
243
+  DWIN_Byte(i, fNum);
244
+  DWIN_Word(i, x);
245
+  DWIN_Word(i, y);
246
+  DWIN_Long(i, value);
247
+  /*
248
+  DWIN_Byte(i, fvalue[3]);
249
+  DWIN_Byte(i, fvalue[2]);
250
+  DWIN_Byte(i, fvalue[1]);
251
+  DWIN_Byte(i, fvalue[0]);
252
+  */
253
+  DWIN_Send(i);
254
+}
255
+
256
+/*----------------------------------------------图片相关函数----------------------------------------------*/
257
+/*jpg图片显示并缓存在#0虚拟显示区 id:图片ID*/
258
+void DWIN_JPG_ShowAndCache(const uint8_t id) {
259
+  size_t i = 0;
260
+  DWIN_Word(i, 0x2200);
261
+  DWIN_Byte(i, id);
262
+  DWIN_Send(i);     //AA 23 00 00 00 00 08 00 01 02 03 CC 33 C3 3C
263
+}
264
+
265
+/*图标显示 libID:图标库ID picID:图标ID x/y:图标左上坐标*/
266
+void DWIN_ICON_Show(uint8_t libID, uint8_t picID, uint16_t x, uint16_t y) {
267
+  NOMORE(x, DWIN_WIDTH - 1);
268
+  NOMORE(y, DWIN_HEIGHT - 1); // -- ozy -- srl
269
+  size_t i = 0;
270
+  DWIN_Byte(i, 0x23);
271
+  DWIN_Word(i, x);
272
+  DWIN_Word(i, y);
273
+  DWIN_Byte(i, 0x80 | libID);
274
+  DWIN_Byte(i, picID);
275
+  DWIN_Send(i);
276
+}
277
+
278
+/*jpg图片解压到#1虚拟显示区 id:图片ID*/
279
+void DWIN_JPG_CacheToN(uint8_t n, uint8_t id) {
280
+  size_t i = 0;
281
+  DWIN_Byte(i, 0x25);
282
+  DWIN_Byte(i, n);
283
+  DWIN_Byte(i, id);
284
+  DWIN_Send(i);
285
+}
286
+
287
+/*从虚拟显示区复制区域至当前画面 cacheID:虚拟区号 xStart/yStart:虚拟区左上坐标 xEnd/yEnd:虚拟区右下坐标 x/y:当前画面粘贴坐标*/
288
+void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart,
289
+                         uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y) {
290
+  size_t i = 0;
291
+  DWIN_Byte(i, 0x27);
292
+  DWIN_Byte(i, 0x80 | cacheID);
293
+  DWIN_Word(i, xStart);
294
+  DWIN_Word(i, yStart);
295
+  DWIN_Word(i, xEnd);
296
+  DWIN_Word(i, yEnd);
297
+  DWIN_Word(i, x);
298
+  DWIN_Word(i, y);
299
+  DWIN_Send(i);
300
+}
301
+
302
+#endif // DWIN_CREALITY_LCD

+ 111
- 0
Marlin/src/lcd/dwin/dwin_lcd.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/********************************************************************************
25
+ * @file     dwin_lcd.h
26
+ * @author   LEO / Creality3D
27
+ * @date     2019/07/18
28
+ * @version  2.0.1
29
+ * @brief    迪文屏控制操作函数
30
+ ********************************************************************************/
31
+
32
+#include <stdint.h>
33
+
34
+#define RECEIVED_NO_DATA         0x00
35
+#define RECEIVED_SHAKE_HAND_ACK  0x01
36
+
37
+#define FHONE                    0xAA
38
+
39
+#define DWIN_SCROLL_UP   2
40
+#define DWIN_SCROLL_DOWN 3
41
+
42
+#define DWIN_WIDTH  272
43
+#define DWIN_HEIGHT 480
44
+
45
+/*接收数据解析 返回值:true,接收到数据;false,未接收到数据*/
46
+bool DWIN_ReceiveAnalyze(void);
47
+
48
+/*发送当前BUF中的数据以及包尾数据 len:整包数据长度*/
49
+void DWIN_Send_BufTail(const uint8_t len);
50
+
51
+/*----------------------------------------------系统变量函数----------------------------------------------*/
52
+/*握手 1: 握手成功  2: 握手失败*/
53
+bool DWIN_Handshake(void);
54
+
55
+/*设定背光亮度 luminance:亮度(0x00~0xFF)*/
56
+void DWIN_Backlight_SetLuminance(const uint8_t luminance);
57
+
58
+/*设定画面显示方向 dir:0,0°; 1,90°; 2,180°; 3,270°*/
59
+void DWIN_Frame_SetDir(uint8_t dir);
60
+
61
+/*更新显示*/
62
+void DWIN_UpdateLCD(void);
63
+
64
+/*----------------------------------------------绘图相关函数----------------------------------------------*/
65
+/*画面清屏 color:清屏颜色*/
66
+void DWIN_Frame_Clear(const uint16_t color);
67
+
68
+/*画面画线 color:线段颜色 xStart:X起始坐标 yStart:Y起始坐标 xEnd:X终止坐标 yEnd:Y终止坐标*/
69
+void DWIN_Draw_Line(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
70
+
71
+/*画面画矩形 mode:0,外框;1,填充;2,异或填充 color:颜色 xStart/yStart:矩形左上坐标 xEnd/yEnd:矩形右下坐标*/
72
+void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color,
73
+                         uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
74
+
75
+/*画面区域移动 mode:0,环移;1,平移 dir:0,向左移动;1,向右移动;2,向上移动;3,向下移动 dis:移动距离
76
+                color:填充颜色 xStart/yStart:选定区域左上坐标 xEnd/yEnd:选定区域右下坐标*/
77
+void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
78
+                         uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
79
+
80
+/*----------------------------------------------文本相关函数----------------------------------------------*/
81
+/*画面显示字符串 widthAdjust:true,自调整字符宽度;false,不调整字符宽度 bShow:true,显示背景色;false,不显示背景色 size:字号大小
82
+                  color:字符颜色 bColor:背景颜色 x/y:字符串左上坐标 *string:字符串*/
83
+void DWIN_Draw_String(bool widthAdjust, bool bShow, uint8_t size,
84
+                      uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, char *string);
85
+
86
+/*画面显示正整数 bShow:true,显示背景色;false,不显示背景色 zeroFill:true,补零;false,不补零 zeroMode:1,无效0显示为0; 0,无效0显示为空格 size:字号大小
87
+                  color:字符颜色 bColor:背景颜色 iNum:位数 x/y:变量左上坐标 value:整型变量*/
88
+void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
89
+                          uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint16_t value);
90
+
91
+/*画面显示浮点数 bShow:true,显示背景色;false,不显示背景色 zeroFill:true,补零;false,不补零 zeroMode:1,无效0显示为0; 0,无效0显示为空格 size:字号大小
92
+                  color:字符颜色 bColor:背景颜色 iNum:整数位数 fNum:小数位数 x/y:变量左上坐标 value:浮点数变量*/
93
+void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
94
+                            uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value);
95
+
96
+/*----------------------------------------------图片相关函数----------------------------------------------*/
97
+/*jpg图片显示并缓存在#0虚拟显示区 id:图片ID*/
98
+void DWIN_JPG_ShowAndCache(const uint8_t id);
99
+
100
+/*图标显示 libID:图标库ID picID:图标ID x/y:图标左上坐标*/
101
+void DWIN_ICON_Show(uint8_t libID, uint8_t picID, uint16_t x, uint16_t y);
102
+
103
+/*jpg图片解压到#1虚拟显示区 id:图片ID*/
104
+void DWIN_JPG_CacheToN(uint8_t n, uint8_t id);
105
+
106
+/*jpg图片解压到#1虚拟显示区 id:图片ID*/
107
+inline void DWIN_JPG_CacheTo1(uint8_t id) { DWIN_JPG_CacheToN(1, id); }
108
+
109
+/*从虚拟显示区复制区域至当前画面 cacheID:虚拟区号 xStart/yStart:虚拟区左上坐标 xEnd/yEnd:虚拟区右下坐标 x/y:当前画面粘贴坐标*/
110
+void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart,
111
+                         uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y);

+ 263
- 0
Marlin/src/lcd/dwin/eeprom_BL24CXX.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/********************************************************************************
24
+ * @file     eeprom_BL24CXX.cpp
25
+ * @brief    i2c EEPROM for Ender 3 v2 board (4.2.2)
26
+ ********************************************************************************/
27
+
28
+#include "../../inc/MarlinConfig.h"
29
+
30
+#if ENABLED(IIC_BL24CXX_EEPROM)
31
+
32
+#include "eeprom_BL24CXX.h"
33
+#include "../../MarlinCore.h"
34
+
35
+#include <stdlib.h>
36
+
37
+/******************** IIC ********************/
38
+
39
+// 初始化IIC
40
+void IIC::init() {
41
+  SET_OUTPUT(IIC_EEPROM_SDA);
42
+  SET_OUTPUT(IIC_EEPROM_SCL);
43
+
44
+  IIC_SCL_1();
45
+  IIC_SDA_1();
46
+}
47
+
48
+// 产生IIC起始信号
49
+void IIC::start() {
50
+  SDA_OUT();      // sda线输出
51
+  IIC_SDA_1();
52
+  IIC_SCL_1();
53
+  delay_us(4);
54
+  IIC_SDA_0(); // START:when CLK is high, DATA change form high to low
55
+  delay_us(4);
56
+  IIC_SCL_0(); // 钳住I2C总线,准备发送或接收数据
57
+}
58
+
59
+// 产生IIC停止信号
60
+void IIC::stop() {
61
+  SDA_OUT(); // sda线输出
62
+  IIC_SCL_0();
63
+  IIC_SDA_0(); // STOP:when CLK is high DATA change form low to high
64
+  delay_us(4);
65
+  IIC_SCL_1();
66
+  IIC_SDA_1(); // 发送I2C总线结束信号
67
+  delay_us(4);
68
+}
69
+
70
+// 等待应答信号到来
71
+// 返回值:1,接收应答失败
72
+//         0,接收应答成功
73
+uint8_t IIC::wait_ack() {
74
+  uint8_t ucErrTime=0;
75
+  SDA_IN();      // SDA设置为输入
76
+  IIC_SDA_1();delay_us(1);
77
+  IIC_SCL_1();delay_us(1);
78
+  while (READ_SDA()) {
79
+    ucErrTime++;
80
+    if (ucErrTime>250) {
81
+      stop();
82
+      return 1;
83
+    }
84
+  }
85
+  IIC_SCL_0(); // 时钟输出0
86
+  return 0;
87
+}
88
+
89
+// 产生ACK应答
90
+void IIC::ack() {
91
+  IIC_SCL_0();
92
+  SDA_OUT();
93
+  IIC_SDA_0();
94
+  delay_us(2);
95
+  IIC_SCL_1();
96
+  delay_us(2);
97
+  IIC_SCL_0();
98
+}
99
+
100
+// 不产生ACK应答
101
+void IIC::nAck() {
102
+  IIC_SCL_0();
103
+  SDA_OUT();
104
+  IIC_SDA_1();
105
+  delay_us(2);
106
+  IIC_SCL_1();
107
+  delay_us(2);
108
+  IIC_SCL_0();
109
+}
110
+
111
+// IIC发送一个字节
112
+// 返回从机有无应答
113
+// 1,有应答
114
+// 0,无应答
115
+void IIC::send_byte(uint8_t txd) {
116
+  SDA_OUT();
117
+  IIC_SCL_0(); // 拉低时钟开始数据传输
118
+  LOOP_L_N(t, 8) {
119
+    // IIC_SDA = (txd & 0x80) >> 7;
120
+    if (txd & 0x80) IIC_SDA_1(); else IIC_SDA_0();
121
+    txd <<= 1;
122
+    delay_us(2);   // 对TEA5767这三个延时都是必须的
123
+    IIC_SCL_1();
124
+    delay_us(2);
125
+    IIC_SCL_0();
126
+    delay_us(2);
127
+  }
128
+}
129
+
130
+// 读1个字节,ack=1时,发送ACK,ack=0,发送nACK
131
+uint8_t IIC::read_byte(unsigned char ack_chr) {
132
+  unsigned char receive = 0;
133
+  SDA_IN(); // SDA设置为输入
134
+  LOOP_L_N(i, 8) {
135
+    IIC_SCL_0();
136
+    delay_us(2);
137
+    IIC_SCL_1();
138
+    receive <<= 1;
139
+    if (READ_SDA()) receive++;
140
+    delay_us(1);
141
+  }
142
+  ack_chr ? ack() : nAck(); // 发送ACK / 发送nACK
143
+  return receive;
144
+}
145
+
146
+/******************** EEPROM ********************/
147
+
148
+// 初始化IIC接口
149
+void BL24CXX::init() { IIC::init(); }
150
+
151
+// 在BL24CXX指定地址读出一个数据
152
+// ReadAddr:开始读数的地址
153
+// 返回值  :读到的数据
154
+uint8_t BL24CXX::readOneByte(uint16_t ReadAddr) {
155
+  uint8_t temp = 0;
156
+  IIC::start();
157
+  if (EE_TYPE > BL24C16) {
158
+    IIC::send_byte(0xA0);     // 发送写命令
159
+    IIC::wait_ack();
160
+    IIC::send_byte(ReadAddr >> 8); // 发送高地址
161
+    IIC::wait_ack();
162
+  }
163
+  else
164
+    IIC::send_byte(0xA0 + ((ReadAddr >> 8) << 1));   // 发送器件地址0xA0,写数据
165
+
166
+  IIC::wait_ack();
167
+  IIC::send_byte(ReadAddr & 0xFF); // 发送低地址
168
+  IIC::wait_ack();
169
+  IIC::start();
170
+  IIC::send_byte(0xA1);           // 进入接收模式
171
+  IIC::wait_ack();
172
+  temp = IIC::read_byte(0);
173
+  IIC::stop(); // 产生一个停止条件
174
+  return temp;
175
+}
176
+
177
+// 在BL24CXX指定地址写入一个数据
178
+// WriteAddr  :写入数据的目的地址
179
+// DataToWrite:要写入的数据
180
+void BL24CXX::writeOneByte(uint16_t WriteAddr, uint8_t DataToWrite) {
181
+  IIC::start();
182
+  if (EE_TYPE > BL24C16) {
183
+    IIC::send_byte(0xA0);      // 发送写命令
184
+    IIC::wait_ack();
185
+    IIC::send_byte(WriteAddr >> 8); // 发送高地址
186
+  }
187
+  else {
188
+    IIC::send_byte(0xA0 + ((WriteAddr >> 8) << 1));   // 发送器件地址0xA0,写数据
189
+  }
190
+  IIC::wait_ack();
191
+  IIC::send_byte(WriteAddr & 0xFF); // 发送低地址
192
+  IIC::wait_ack();
193
+  IIC::send_byte(DataToWrite);     // 发送字节
194
+  IIC::wait_ack();
195
+  IIC::stop(); // 产生一个停止条件
196
+  delay(10);
197
+}
198
+
199
+// 在BL24CXX里面的指定地址开始写入长度为Len的数据
200
+// 该函数用于写入16bit或者32bit的数据.
201
+// WriteAddr  :开始写入的地址
202
+// DataToWrite:数据数组首地址
203
+// Len        :要写入数据的长度2,4
204
+void BL24CXX::writeLenByte(uint16_t WriteAddr, uint32_t DataToWrite, uint8_t Len) {
205
+  LOOP_L_N(t, Len)
206
+    writeOneByte(WriteAddr + t, (DataToWrite >> (8 * t)) & 0xFF);
207
+}
208
+
209
+// 在BL24CXX里面的指定地址开始读出长度为Len的数据
210
+// 该函数用于读出16bit或者32bit的数据.
211
+// ReadAddr   :开始读出的地址
212
+// 返回值     :数据
213
+// Len        :要读出数据的长度2,4
214
+uint32_t BL24CXX::readLenByte(uint16_t ReadAddr, uint8_t Len) {
215
+  uint32_t temp = 0;
216
+  LOOP_L_N(t, Len) {
217
+    temp <<= 8;
218
+    temp += readOneByte(ReadAddr + Len - t - 1);
219
+  }
220
+  return temp;
221
+}
222
+
223
+// 检查BL24CXX是否正常
224
+// 这里用了24XX的最后一个地址(255)来存储标志字.
225
+// 如果用其他24C系列,这个地址要修改
226
+// 返回1:检测失败
227
+// 返回0:检测成功
228
+uint8_t BL24CXX::check() {
229
+  uint8_t temp;
230
+  temp = readOneByte(255); // 避免每次开机都写BL24CXX
231
+  if (temp == 'U') return 0;
232
+  else { // 排除第一次初始化的情况
233
+    writeOneByte(255, 'U');
234
+    temp = readOneByte(255);
235
+    if (temp == 'U') return 0;
236
+  }
237
+  return 1;
238
+}
239
+
240
+// 在BL24CXX里面的指定地址开始读出指定个数的数据
241
+// ReadAddr :开始读出的地址 对24c02为0~255
242
+// pBuffer  :数据数组首地址
243
+// NumToRead:要读出数据的个数
244
+void BL24CXX::read(uint16_t ReadAddr, uint8_t *pBuffer, uint16_t NumToRead) {
245
+  while (NumToRead) {
246
+    *pBuffer++ = readOneByte(ReadAddr++);
247
+    NumToRead--;
248
+  }
249
+}
250
+
251
+// 在BL24CXX里面的指定地址开始写入指定个数的数据
252
+// WriteAddr :开始写入的地址 对24c02为0~255
253
+// pBuffer   :数据数组首地址
254
+// NumToWrite:要写入数据的个数
255
+void BL24CXX::write(uint16_t WriteAddr, uint8_t *pBuffer, uint16_t NumToWrite) {
256
+  while (NumToWrite--) {
257
+    writeOneByte(WriteAddr, *pBuffer);
258
+    WriteAddr++;
259
+    pBuffer++;
260
+  }
261
+}
262
+
263
+#endif // IIC_BL24CXX_EEPROM

+ 86
- 0
Marlin/src/lcd/dwin/eeprom_BL24CXX.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/********************************************************************************
25
+ * @file     eeprom_BL24CXX.h
26
+ * @brief    i2c EEPROM for Ender 3 v2 board (4.2.2)
27
+ ********************************************************************************/
28
+
29
+#include <libmaple/gpio.h>
30
+
31
+/******************** IIC ********************/
32
+
33
+//IO方向设置
34
+#define SDA_IN()  do{ PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH &= 0XFFFF0FFF; PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH |= 8 << 12; }while(0)
35
+#define SDA_OUT() do{ PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH &= 0XFFFF0FFF; PIN_MAP[IIC_EEPROM_SDA].gpio_device->regs->CRH |= 3 << 12; }while(0)
36
+
37
+//IO操作函数
38
+#define IIC_SCL_0()   WRITE(IIC_EEPROM_SCL, LOW)
39
+#define IIC_SCL_1()   WRITE(IIC_EEPROM_SCL, HIGH)
40
+#define IIC_SDA_0()   WRITE(IIC_EEPROM_SDA, LOW)
41
+#define IIC_SDA_1()   WRITE(IIC_EEPROM_SDA, HIGH)
42
+#define READ_SDA()    READ(IIC_EEPROM_SDA)
43
+
44
+class BL24CXX;
45
+
46
+// IIC所有操作函数
47
+class IIC {
48
+friend class BL24CXX;
49
+protected:
50
+  static void init();                // 初始化IIC的IO口
51
+  static void start();               // 发送IIC开始信号
52
+  static void stop();                // 发送IIC停止信号
53
+  static void send_byte(uint8_t txd); // IIC发送一个字节
54
+  static uint8_t read_byte(unsigned char ack); // IIC读取一个字节
55
+  static uint8_t wait_ack();         // IIC等待ACK信号
56
+  static void ack();                 // IIC发送ACK信号
57
+  static void nAck();                // IIC不发送ACK信号
58
+
59
+  static void write_one_byte(uint8_t daddr, uint8_t addr, uint8_t data);
60
+  static uint8_t read_one_byte(uint8_t daddr, uint8_t addr);
61
+};
62
+
63
+/******************** EEPROM ********************/
64
+
65
+#define BL24C01     127
66
+#define BL24C02     255
67
+#define BL24C04     511
68
+#define BL24C08    1023
69
+#define BL24C16    2047
70
+#define BL24C32    4095
71
+#define BL24C64    8191
72
+#define BL24C128  16383
73
+#define BL24C256  32767
74
+#define EE_TYPE BL24C16
75
+
76
+class BL24CXX {
77
+public:
78
+  static void init(); //初始化IIC
79
+  static uint8_t check();  //检查器件
80
+  static uint8_t readOneByte(uint16_t ReadAddr);                       //指定地址读取一个字节
81
+  static void writeOneByte(uint16_t WriteAddr, uint8_t DataToWrite);   //指定地址写入一个字节
82
+  static void writeLenByte(uint16_t WriteAddr, uint32_t DataToWrite, uint8_t Len);//指定地址开始写入指定长度的数据
83
+  static uint32_t readLenByte(uint16_t ReadAddr, uint8_t Len);         //指定地址开始读取指定长度数据
84
+  static void write(uint16_t WriteAddr, uint8_t *pBuffer, uint16_t NumToWrite);  //从指定地址开始写入指定长度的数据
85
+  static void read(uint16_t ReadAddr, uint8_t *pBuffer, uint16_t NumToRead);     //从指定地址开始读出指定长度的数据
86
+};

+ 249
- 0
Marlin/src/lcd/dwin/rotary_encoder.cpp View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+  ******************************************************************************
25
+  * @file     rotary_encoder.cpp
26
+  * @author   LEO / Creality3D
27
+  * @date     2019/07/06
28
+  * @version  2.0.1
29
+  * @brief    旋转编码器操作函数
30
+  ******************************************************************************
31
+**/
32
+
33
+#include "../../inc/MarlinConfigPre.h"
34
+
35
+#if ENABLED(DWIN_CREALITY_LCD)
36
+
37
+#include "rotary_encoder.h"
38
+
39
+#include "../../MarlinCore.h"
40
+#include "../../HAL/shared/Delay.h"
41
+
42
+#if HAS_BUZZER
43
+  #include "../../libs/buzzer.h"
44
+#endif
45
+
46
+#include <stdlib.h>
47
+
48
+ENCODER_Rate EncoderRate;
49
+
50
+/*蜂鸣器响*/
51
+void Encoder_tick(void) {
52
+  WRITE(BEEPER_PIN,1);
53
+  delay(10);
54
+  WRITE(BEEPER_PIN,0);
55
+}
56
+
57
+/*编码器初始化 PB12:Encoder_A PB13:Encoder_B PB14:Encoder_C*/
58
+void Encoder_Configuration(void) {
59
+  #if BUTTON_EXISTS(EN1)
60
+    SET_INPUT_PULLUP(BTN_EN1);
61
+  #endif
62
+  #if BUTTON_EXISTS(EN2)
63
+    SET_INPUT_PULLUP(BTN_EN2);
64
+  #endif
65
+  #if BUTTON_EXISTS(ENC)
66
+    SET_INPUT_PULLUP(BTN_ENC);
67
+  #endif
68
+  #ifdef BEEPER_PIN
69
+    SET_OUTPUT(BEEPER_PIN);
70
+  #endif
71
+}
72
+
73
+millis_t next_click_update_ms;
74
+/*接收数据解析 返回值:ENCODER_DIFF_NO,无状态; ENCODER_DIFF_CW,顺时针旋转; ENCODER_DIFF_CCW,逆时针旋转; ENCODER_DIFF_ENTER,按下*/
75
+ENCODER_DiffState Encoder_ReceiveAnalyze(void) {
76
+  const millis_t now = millis();
77
+  static unsigned char lastEncoderBits;
78
+  unsigned char newbutton = 0;
79
+  static signed char temp_diff = 0;
80
+
81
+  ENCODER_DiffState temp_diffState = ENCODER_DIFF_NO;
82
+  if (BUTTON_PRESSED(EN1)) newbutton |= 0x01;
83
+  if (BUTTON_PRESSED(EN2)) newbutton |= 0x02;
84
+  if (BUTTON_PRESSED(ENC)) {
85
+    if (ELAPSED(now, next_click_update_ms)) {
86
+      next_click_update_ms = millis() + 300;
87
+      Encoder_tick();
88
+      #if PIN_EXISTS(LCD_LED)
89
+        //LED_Action();
90
+      #endif
91
+      return ENCODER_DIFF_ENTER;
92
+    }
93
+    else return ENCODER_DIFF_NO;
94
+  }
95
+  if (newbutton != lastEncoderBits) {
96
+    switch (newbutton) {
97
+      case ENCODER_PHASE_0: {
98
+        if (lastEncoderBits == ENCODER_PHASE_3) temp_diff++;
99
+        else if (lastEncoderBits == ENCODER_PHASE_1) temp_diff--;
100
+      }break;
101
+      case ENCODER_PHASE_1: {
102
+        if (lastEncoderBits == ENCODER_PHASE_0) temp_diff++;
103
+        else if (lastEncoderBits == ENCODER_PHASE_2) temp_diff--;
104
+      }break;
105
+      case ENCODER_PHASE_2: {
106
+        if (lastEncoderBits == ENCODER_PHASE_1) temp_diff++;
107
+        else if (lastEncoderBits == ENCODER_PHASE_3) temp_diff--;
108
+      }break;
109
+      case ENCODER_PHASE_3: {
110
+        if (lastEncoderBits == ENCODER_PHASE_2) temp_diff++;
111
+        else if (lastEncoderBits == ENCODER_PHASE_0) temp_diff--;
112
+      }break;
113
+    }
114
+    lastEncoderBits = newbutton;
115
+  }
116
+
117
+  if (abs(temp_diff) >= ENCODER_PULSES_PER_STEP) {
118
+    if (temp_diff > 0) temp_diffState = ENCODER_DIFF_CW;
119
+    else temp_diffState = ENCODER_DIFF_CCW;
120
+
121
+    #if ENABLED(ENCODER_RATE_MULTIPLIER)
122
+
123
+      millis_t ms = millis();
124
+      int32_t encoderMultiplier = 1;
125
+
126
+      // if must encoder rati multiplier
127
+      if (EncoderRate.encoderRateEnabled) {
128
+        const float abs_diff = ABS(temp_diff);
129
+        const float encoderMovementSteps = abs_diff / (ENCODER_PULSES_PER_STEP);
130
+        if (EncoderRate.lastEncoderTime) {
131
+          // Note that the rate is always calculated between two passes through the
132
+          // loop and that the abs of the temp_diff value is tracked.
133
+          const float encoderStepRate = encoderMovementSteps / float(ms - EncoderRate.lastEncoderTime) * 1000;
134
+          if (encoderStepRate >= ENCODER_100X_STEPS_PER_SEC)  encoderMultiplier = 100;
135
+          else if (encoderStepRate >= ENCODER_10X_STEPS_PER_SEC) encoderMultiplier = 10;
136
+          else if (encoderStepRate >= ENCODER_5X_STEPS_PER_SEC) encoderMultiplier = 5;
137
+        }
138
+        EncoderRate.lastEncoderTime = ms;
139
+      }
140
+    #else
141
+      constexpr int32_t encoderMultiplier = 1;
142
+    #endif // ENCODER_RATE_MULTIPLIER
143
+
144
+    // EncoderRate.encoderMoveValue += (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
145
+    EncoderRate.encoderMoveValue = (temp_diff * encoderMultiplier) / (ENCODER_PULSES_PER_STEP);
146
+    if (EncoderRate.encoderMoveValue < 0) EncoderRate.encoderMoveValue = -EncoderRate.encoderMoveValue;
147
+
148
+    temp_diff = 0;
149
+  }
150
+  return temp_diffState;
151
+}
152
+
153
+#if PIN_EXISTS(LCD_LED)
154
+
155
+  /*取低24位有效  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*/
156
+  unsigned int LED_DataArray[LED_NUM];
157
+
158
+  /*LED灯操作*/
159
+  void LED_Action(void) {
160
+    LED_Control(RGB_SCALE_WARM_WHITE,0x0F);
161
+    delay(30);
162
+    LED_Control(RGB_SCALE_WARM_WHITE,0x00);
163
+  }
164
+
165
+  /*LED初始化*/
166
+  void LED_Configuration(void) {
167
+    SET_OUTPUT(LCD_LED_PIN);
168
+  }
169
+
170
+  /*LED写数据*/
171
+  void LED_WriteData(void) {
172
+    unsigned char tempCounter_LED, tempCounter_Bit;
173
+    for (tempCounter_LED = 0; tempCounter_LED < LED_NUM; tempCounter_LED++) {
174
+      for (tempCounter_Bit = 0; tempCounter_Bit < 24; tempCounter_Bit++) {
175
+        if (LED_DataArray[tempCounter_LED] & (0x800000 >> tempCounter_Bit)) {
176
+          LED_DATA_HIGH;
177
+          DELAY_NS(300);
178
+          LED_DATA_LOW;
179
+          DELAY_NS(200);
180
+        }
181
+        else {
182
+          LED_DATA_HIGH;
183
+          LED_DATA_LOW;
184
+          DELAY_NS(200);
185
+        }
186
+      }
187
+    }
188
+  }
189
+
190
+  /*LED控制 RGB_Scale:RGB色彩配比 luminance:亮度(0~0xFF)*/
191
+  void LED_Control(unsigned char RGB_Scale, unsigned char luminance) {
192
+    unsigned char temp_Counter;
193
+    for (temp_Counter = 0; temp_Counter < LED_NUM; temp_Counter++) {
194
+      LED_DataArray[temp_Counter] = 0;
195
+      switch(RGB_Scale) {
196
+        case RGB_SCALE_R10_G7_B5: LED_DataArray[temp_Counter] = (luminance*10/10) << 8 | (luminance*7/10) << 16 | luminance*5/10; break;
197
+        case RGB_SCALE_R10_G7_B4: LED_DataArray[temp_Counter] = (luminance*10/10) << 8 | (luminance*7/10) << 16 | luminance*4/10; break;
198
+        case RGB_SCALE_R10_G8_B7: LED_DataArray[temp_Counter] = (luminance*10/10) << 8 | (luminance*8/10) << 16 | luminance*7/10; break;
199
+      }
200
+    }
201
+    LED_WriteData();
202
+  }
203
+
204
+  /*LED渐变控制 RGB_Scale:RGB色彩配比 luminance:亮度(0~0xFF) change_Time:渐变时间(ms)*/
205
+  void LED_GraduallyControl(unsigned char RGB_Scale, unsigned char luminance, unsigned int change_Interval) {
206
+    unsigned char temp_Counter;
207
+    unsigned char LED_R_Data[LED_NUM], LED_G_Data[LED_NUM], LED_B_Data[LED_NUM];
208
+    bool LED_R_Flag = 0, LED_G_Flag = 0, LED_B_Flag = 0;
209
+
210
+    for (temp_Counter = 0; temp_Counter < LED_NUM; temp_Counter++) {
211
+      switch(RGB_Scale) {
212
+        case RGB_SCALE_R10_G7_B5: {
213
+          LED_R_Data[temp_Counter] = luminance*10/10;
214
+          LED_G_Data[temp_Counter] = luminance*7/10;
215
+          LED_B_Data[temp_Counter] = luminance*5/10;
216
+        }break;
217
+        case RGB_SCALE_R10_G7_B4: {
218
+          LED_R_Data[temp_Counter] = luminance*10/10;
219
+          LED_G_Data[temp_Counter] = luminance*7/10;
220
+          LED_B_Data[temp_Counter] = luminance*4/10;
221
+        }break;
222
+        case RGB_SCALE_R10_G8_B7: {
223
+          LED_R_Data[temp_Counter] = luminance*10/10;
224
+          LED_G_Data[temp_Counter] = luminance*8/10;
225
+          LED_B_Data[temp_Counter] = luminance*7/10;
226
+        }break;
227
+      }
228
+    }
229
+      for (temp_Counter = 0; temp_Counter < LED_NUM; temp_Counter++) {
230
+        if ((unsigned char)(LED_DataArray[temp_Counter] >> 8) > LED_R_Data[temp_Counter]) LED_DataArray[temp_Counter] -= 0x000100;
231
+        else if ((unsigned char)(LED_DataArray[temp_Counter] >> 8) < LED_R_Data[temp_Counter]) LED_DataArray[temp_Counter] += 0x000100;
232
+    while (1) {
233
+        else LED_R_Flag = 1;
234
+        if ((unsigned char)(LED_DataArray[temp_Counter]>>16) > LED_G_Data[temp_Counter]) LED_DataArray[temp_Counter] -= 0x010000;
235
+        else if ((unsigned char)(LED_DataArray[temp_Counter]>>16) < LED_G_Data[temp_Counter]) LED_DataArray[temp_Counter] += 0x010000;
236
+        else LED_G_Flag = 1;
237
+        if ((unsigned char)LED_DataArray[temp_Counter] > LED_B_Data[temp_Counter]) LED_DataArray[temp_Counter] -= 0x000001;
238
+        else if ((unsigned char)LED_DataArray[temp_Counter] < LED_B_Data[temp_Counter]) LED_DataArray[temp_Counter] += 0x000001;
239
+        else LED_B_Flag = 1;
240
+      }
241
+      LED_WriteData();
242
+      if (LED_R_Flag && LED_G_Flag && LED_B_Flag) break;
243
+      else delay(change_Interval);
244
+    }
245
+  }
246
+
247
+#endif
248
+
249
+#endif // DWIN_CREALITY_LCD

+ 105
- 0
Marlin/src/lcd/dwin/rotary_encoder.h View File

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (c) 2020 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
23
+
24
+/**
25
+  ******************************************************************************
26
+  * @file     rotary_encoder.h
27
+  * @author   LEO / Creality3D
28
+  * @date     2019/07/06
29
+  * @version  2.0.1
30
+  * @brief    旋转编码器操作函数
31
+  ******************************************************************************
32
+**/
33
+
34
+#include "../../inc/MarlinConfig.h"
35
+#include "../../MarlinCore.h"
36
+
37
+/*********************** Encoder Set ***********************/
38
+
39
+#define ENCODER_PHASE_0  0
40
+#define ENCODER_PHASE_1  2
41
+#define ENCODER_PHASE_2  3
42
+#define ENCODER_PHASE_3  1
43
+
44
+#define ENCODER_PULSES_PER_STEP  4
45
+
46
+#define BUTTON_PRESSED(BN) !READ(BTN_## BN)
47
+
48
+typedef struct {
49
+  bool encoderRateEnabled = 0;
50
+  int encoderMoveValue = 0;
51
+  millis_t lastEncoderTime = 0;
52
+} ENCODER_Rate;
53
+
54
+extern ENCODER_Rate EncoderRate;
55
+
56
+typedef enum {
57
+  ENCODER_DIFF_NO    = 0,
58
+	ENCODER_DIFF_CW    = 1,
59
+  ENCODER_DIFF_CCW   = 2,
60
+	ENCODER_DIFF_ENTER = 3
61
+} ENCODER_DiffState;
62
+
63
+/*编码器初始化 PB12:Encoder_A PB13:Encoder_B PB14:Encoder_C*/
64
+void Encoder_Configuration(void);
65
+
66
+/*接收数据解析 返回值:ENCODER_DIFF_NO,无状态; ENCODER_DIFF_CW,顺时针旋转; ENCODER_DIFF_CCW,逆时针旋转; ENCODER_DIFF_ENTER,按下*/
67
+ENCODER_DiffState Encoder_ReceiveAnalyze(void);
68
+
69
+
70
+/*********************** Encoder LED ***********************/
71
+
72
+#if PIN_EXISTS(LCD_LED)
73
+
74
+  #define LED_NUM  4
75
+  #define LED_DATA_HIGH  WRITE(LCD_LED_PIN, 1)
76
+  #define LED_DATA_LOW   WRITE(LCD_LED_PIN, 0)
77
+
78
+  #define RGB_SCALE_R10_G7_B5  1
79
+  #define RGB_SCALE_R10_G7_B4  2
80
+  #define RGB_SCALE_R10_G8_B7  3
81
+  #define RGB_SCALE_NEUTRAL_WHITE  RGB_SCALE_R10_G7_B5 //正白
82
+  #define RGB_SCALE_WARM_WHITE  RGB_SCALE_R10_G7_B4 //暖白
83
+  #define RGB_SCALE_COOL_WHITE  RGB_SCALE_R10_G8_B7 //冷白
84
+
85
+  extern unsigned int LED_DataArray[LED_NUM];
86
+
87
+  /*状态LED初始化*/
88
+  void STATE_LED_Configuration(void);
89
+
90
+	/*LED灯操作*/
91
+  void LED_Action(void);
92
+
93
+  /*LED初始化*/
94
+  void LED_Configuration(void);
95
+
96
+  /*LED写数据*/
97
+  void LED_WriteData(void);
98
+
99
+  /*LED控制 RGB_Scale:RGB色彩配比 luminance:亮度(0~0xFF)*/
100
+  void LED_Control(unsigned char RGB_Scale, unsigned char luminance);
101
+
102
+  /*LED渐变控制 RGB_Scale:RGB色彩配比 luminance:亮度(0~0xFF) change_Time:渐变时间(ms)*/
103
+  void LED_GraduallyControl(unsigned char RGB_Scale, unsigned char luminance, unsigned int change_Interval);
104
+
105
+#endif

+ 35
- 32
Marlin/src/lcd/ultralcd.cpp View File

40
   #include "../gcode/queue.h"
40
   #include "../gcode/queue.h"
41
   #include "fontutils.h"
41
   #include "fontutils.h"
42
   #include "../sd/cardreader.h"
42
   #include "../sd/cardreader.h"
43
-  #if ENABLED(EXTENSIBLE_UI)
43
+  #if EITHER(EXTENSIBLE_UI, DWIN_CREALITY_LCD)
44
     #define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80u)
44
     #define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80u)
45
   #endif
45
   #endif
46
 #endif
46
 #endif
56
   #else
56
   #else
57
     constexpr uint8_t MAX_MESSAGE_LENGTH = MAX_LANG_CHARSIZE * (LCD_WIDTH);
57
     constexpr uint8_t MAX_MESSAGE_LENGTH = MAX_LANG_CHARSIZE * (LCD_WIDTH);
58
   #endif
58
   #endif
59
-#elif ENABLED(EXTENSIBLE_UI)
59
+#elif EITHER(EXTENSIBLE_UI, DWIN_CREALITY_LCD)
60
   constexpr uint8_t MAX_MESSAGE_LENGTH = 63;
60
   constexpr uint8_t MAX_MESSAGE_LENGTH = 63;
61
 #endif
61
 #endif
62
 
62
 
145
   volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
145
   volatile int8_t encoderDiff; // Updated in update_buttons, added to encoderPosition every LCD update
146
 #endif
146
 #endif
147
 
147
 
148
-#if HAS_LCD_MENU
149
-  #include "menu/menu.h"
150
-  #include "../sd/cardreader.h"
148
+#if ENABLED(SDSUPPORT)
151
 
149
 
152
-  #if ENABLED(SDSUPPORT)
150
+  #include "../sd/cardreader.h"
153
 
151
 
154
-    #if ENABLED(SCROLL_LONG_FILENAMES)
155
-      uint8_t MarlinUI::filename_scroll_pos, MarlinUI::filename_scroll_max;
156
-    #endif
152
+  #if MARLINUI_SCROLL_NAME
153
+    uint8_t MarlinUI::filename_scroll_pos, MarlinUI::filename_scroll_max;
154
+  #endif
157
 
155
 
158
-    const char * MarlinUI::scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll) {
159
-      const char *outstr = theCard.longest_filename();
160
-      if (theCard.longFilename[0]) {
161
-        #if ENABLED(SCROLL_LONG_FILENAMES)
162
-          if (doScroll) {
163
-            for (uint8_t l = FILENAME_LENGTH; l--;)
164
-              hash = ((hash << 1) | (hash >> 7)) ^ theCard.filename[l];      // rotate, xor
165
-            static uint8_t filename_scroll_hash;
166
-            if (filename_scroll_hash != hash) {                              // If the hash changed...
167
-              filename_scroll_hash = hash;                                   // Save the new hash
168
-              filename_scroll_max = _MAX(0, utf8_strlen(theCard.longFilename) - maxlen); // Update the scroll limit
169
-              filename_scroll_pos = 0;                                       // Reset scroll to the start
170
-              lcd_status_update_delay = 8;                                   // Don't scroll right away
171
-            }
172
-            outstr += filename_scroll_pos;
156
+  const char * MarlinUI::scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll) {
157
+    const char *outstr = theCard.longest_filename();
158
+    if (theCard.longFilename[0]) {
159
+      #if MARLINUI_SCROLL_NAME
160
+        if (doScroll) {
161
+          for (uint8_t l = FILENAME_LENGTH; l--;)
162
+            hash = ((hash << 1) | (hash >> 7)) ^ theCard.filename[l];      // rotate, xor
163
+          static uint8_t filename_scroll_hash;
164
+          if (filename_scroll_hash != hash) {                              // If the hash changed...
165
+            filename_scroll_hash = hash;                                   // Save the new hash
166
+            filename_scroll_max = _MAX(0, utf8_strlen(theCard.longFilename) - maxlen); // Update the scroll limit
167
+            filename_scroll_pos = 0;                                       // Reset scroll to the start
168
+            lcd_status_update_delay = 8;                                   // Don't scroll right away
173
           }
169
           }
174
-        #else
175
-          theCard.longFilename[maxlen] = '\0'; // cutoff at screen edge
176
-        #endif
177
-      }
178
-      return outstr;
170
+          outstr += filename_scroll_pos;
171
+        }
172
+      #else
173
+        theCard.longFilename[maxlen] = '\0'; // cutoff at screen edge
174
+      #endif
179
     }
175
     }
176
+    return outstr;
177
+  }
180
 
178
 
181
-  #endif
179
+#endif
180
+
181
+#if HAS_LCD_MENU
182
+  #include "menu/menu.h"
182
 
183
 
183
   screenFunc_t MarlinUI::currentScreen; // Initialized in CTOR
184
   screenFunc_t MarlinUI::currentScreen; // Initialized in CTOR
184
   bool MarlinUI::screen_changed;
185
   bool MarlinUI::screen_changed;
1579
         set_status_P(eeprom_err(msgid));
1580
         set_status_P(eeprom_err(msgid));
1580
       #endif
1581
       #endif
1581
     }
1582
     }
1582
-  #endif
1583
-#endif
1583
+
1584
+  #endif // EEPROM_AUTO_INIT
1585
+
1586
+#endif // EEPROM_SETTINGS

+ 20
- 9
Marlin/src/lcd/ultralcd.h View File

27
   #include "../libs/buzzer.h"
27
   #include "../libs/buzzer.h"
28
 #endif
28
 #endif
29
 
29
 
30
+#if ENABLED(SDSUPPORT)
31
+  #include "../sd/cardreader.h"
32
+#endif
33
+
30
 #if EITHER(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY)
34
 #if EITHER(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY)
31
   #define HAS_ENCODER_ACTION 1
35
   #define HAS_ENCODER_ACTION 1
32
 #endif
36
 #endif
111
 
115
 
112
   #endif // HAS_LCD_MENU
116
   #endif // HAS_LCD_MENU
113
 
117
 
114
-#endif
118
+#endif // HAS_SPI_LCD
115
 
119
 
116
 // REPRAPWORLD_KEYPAD (and ADC_KEYPAD)
120
 // REPRAPWORLD_KEYPAD (and ADC_KEYPAD)
117
 #if ENABLED(REPRAPWORLD_KEYPAD)
121
 #if ENABLED(REPRAPWORLD_KEYPAD)
287
     static void init_lcd();
291
     static void init_lcd();
288
     FORCE_INLINE static void refresh() { refresh(LCDVIEW_CLEAR_CALL_REDRAW); }
292
     FORCE_INLINE static void refresh() { refresh(LCDVIEW_CLEAR_CALL_REDRAW); }
289
   #else
293
   #else
294
+    #if ENABLED(DWIN_CREALITY_LCD)
295
+      static void refresh();
296
+    #else
297
+      static inline void refresh()  {}
298
+    #endif
290
     static inline bool detected() { return true; }
299
     static inline bool detected() { return true; }
291
     static inline void init_lcd() {}
300
     static inline void init_lcd() {}
292
-    static inline void refresh()  {}
293
   #endif
301
   #endif
294
 
302
 
295
   #if HAS_DISPLAY
303
   #if HAS_DISPLAY
451
 
459
 
452
   #endif
460
   #endif
453
 
461
 
462
+  #if ENABLED(SDSUPPORT)
463
+    #if BOTH(SCROLL_LONG_FILENAMES, HAS_LCD_MENU)
464
+      #define MARLINUI_SCROLL_NAME 1
465
+    #endif
466
+    #if MARLINUI_SCROLL_NAME
467
+      static uint8_t filename_scroll_pos, filename_scroll_max;
468
+    #endif
469
+    static const char * scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll);
470
+  #endif
471
+
454
   #if HAS_LCD_MENU
472
   #if HAS_LCD_MENU
455
 
473
 
456
     #if ENABLED(TOUCH_BUTTONS)
474
     #if ENABLED(TOUCH_BUTTONS)
464
       static void enable_encoder_multiplier(const bool onoff);
482
       static void enable_encoder_multiplier(const bool onoff);
465
     #endif
483
     #endif
466
 
484
 
467
-    #if ENABLED(SDSUPPORT)
468
-      #if ENABLED(SCROLL_LONG_FILENAMES)
469
-        static uint8_t filename_scroll_pos, filename_scroll_max;
470
-      #endif
471
-      static const char * scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll);
472
-    #endif
473
-
474
     #if IS_KINEMATIC
485
     #if IS_KINEMATIC
475
       static bool processing_manual_move;
486
       static bool processing_manual_move;
476
     #else
487
     #else

+ 30
- 9
Marlin/src/module/configuration_store.cpp View File

50
 #include "planner.h"
50
 #include "planner.h"
51
 #include "stepper.h"
51
 #include "stepper.h"
52
 #include "temperature.h"
52
 #include "temperature.h"
53
+
54
+#if ENABLED(DWIN_CREALITY_LCD)
55
+  #include "../lcd/dwin/dwin.h"
56
+#endif
57
+
53
 #include "../lcd/ultralcd.h"
58
 #include "../lcd/ultralcd.h"
54
 #include "../libs/vector_3.h"   // for matrix_3x3
59
 #include "../libs/vector_3.h"   // for matrix_3x3
55
 #include "../gcode/gcode.h"
60
 #include "../gcode/gcode.h"
804
         const int16_t (&ui_preheat_hotend_temp)[2]  = ui.preheat_hotend_temp,
809
         const int16_t (&ui_preheat_hotend_temp)[2]  = ui.preheat_hotend_temp,
805
                       (&ui_preheat_bed_temp)[2]     = ui.preheat_bed_temp;
810
                       (&ui_preheat_bed_temp)[2]     = ui.preheat_bed_temp;
806
         const uint8_t (&ui_preheat_fan_speed)[2]    = ui.preheat_fan_speed;
811
         const uint8_t (&ui_preheat_fan_speed)[2]    = ui.preheat_fan_speed;
812
+      #elif ENABLED(DWIN_CREALITY_LCD)
813
+        const int16_t (&ui_preheat_hotend_temp)[2]  = HMI_ValueStruct.preheat_hotend_temp,
814
+                      (&ui_preheat_bed_temp)[2]     = HMI_ValueStruct.preheat_bed_temp;
815
+        const uint8_t (&ui_preheat_fan_speed)[2]    = HMI_ValueStruct.preheat_fan_speed;
807
       #else
816
       #else
808
         constexpr int16_t ui_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
817
         constexpr int16_t ui_preheat_hotend_temp[2] = { PREHEAT_1_TEMP_HOTEND, PREHEAT_2_TEMP_HOTEND },
809
                           ui_preheat_bed_temp[2]    = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED };
818
                           ui_preheat_bed_temp[2]    = { PREHEAT_1_TEMP_BED, PREHEAT_2_TEMP_BED };
1664
           int16_t (&ui_preheat_hotend_temp)[2]  = ui.preheat_hotend_temp,
1673
           int16_t (&ui_preheat_hotend_temp)[2]  = ui.preheat_hotend_temp,
1665
                   (&ui_preheat_bed_temp)[2]     = ui.preheat_bed_temp;
1674
                   (&ui_preheat_bed_temp)[2]     = ui.preheat_bed_temp;
1666
           uint8_t (&ui_preheat_fan_speed)[2]    = ui.preheat_fan_speed;
1675
           uint8_t (&ui_preheat_fan_speed)[2]    = ui.preheat_fan_speed;
1667
-        #else
1676
+       #elif ENABLED(DWIN_CREALITY_LCD)
1677
+          int16_t (&ui_preheat_hotend_temp)[2]  = HMI_ValueStruct.preheat_hotend_temp,
1678
+                  (&ui_preheat_bed_temp)[2]     = HMI_ValueStruct.preheat_bed_temp;
1679
+          uint8_t (&ui_preheat_fan_speed)[2]    = HMI_ValueStruct.preheat_fan_speed;
1680
+       #else
1668
           int16_t ui_preheat_hotend_temp[2], ui_preheat_bed_temp[2];
1681
           int16_t ui_preheat_hotend_temp[2], ui_preheat_bed_temp[2];
1669
           uint8_t ui_preheat_fan_speed[2];
1682
           uint8_t ui_preheat_fan_speed[2];
1670
         #endif
1683
         #endif
2539
   //
2552
   //
2540
   // Preheat parameters
2553
   // Preheat parameters
2541
   //
2554
   //
2542
-
2543
-  #if HAS_HOTEND && HAS_LCD_MENU
2544
-    ui.preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
2545
-    ui.preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
2546
-    ui.preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
2547
-    ui.preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
2548
-    ui.preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
2549
-    ui.preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
2555
+  #if HAS_HOTEND
2556
+    #if ENABLED(DWIN_CREALITY_LCD)
2557
+      HMI_ValueStruct.preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
2558
+      HMI_ValueStruct.preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
2559
+      HMI_ValueStruct.preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
2560
+      HMI_ValueStruct.preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
2561
+      HMI_ValueStruct.preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
2562
+      HMI_ValueStruct.preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
2563
+    #elif HAS_LCD_MENU
2564
+      ui.preheat_hotend_temp[0] = PREHEAT_1_TEMP_HOTEND;
2565
+      ui.preheat_hotend_temp[1] = PREHEAT_2_TEMP_HOTEND;
2566
+      ui.preheat_bed_temp[0] = PREHEAT_1_TEMP_BED;
2567
+      ui.preheat_bed_temp[1] = PREHEAT_2_TEMP_BED;
2568
+      ui.preheat_fan_speed[0] = PREHEAT_1_FAN_SPEED;
2569
+      ui.preheat_fan_speed[1] = PREHEAT_2_FAN_SPEED;
2570
+    #endif
2550
   #endif
2571
   #endif
2551
 
2572
 
2552
   //
2573
   //

+ 23
- 4
Marlin/src/module/temperature.cpp View File

32
 #include "../HAL/shared/Delay.h"
32
 #include "../HAL/shared/Delay.h"
33
 
33
 
34
 #include "../lcd/ultralcd.h"
34
 #include "../lcd/ultralcd.h"
35
+
36
+#if ENABLED(DWIN_CREALITY_LCD)
37
+  #include "../lcd/dwin/dwin.h"
38
+#endif
39
+
35
 #if ENABLED(EXTENSIBLE_UI)
40
 #if ENABLED(EXTENSIBLE_UI)
36
   #include "../lcd/extui/ui_api.h"
41
   #include "../lcd/extui/ui_api.h"
37
 #endif
42
 #endif
560
         #define MAX_CYCLE_TIME_PID_AUTOTUNE 20L
565
         #define MAX_CYCLE_TIME_PID_AUTOTUNE 20L
561
       #endif
566
       #endif
562
       if (((ms - t1) + (ms - t2)) > (MAX_CYCLE_TIME_PID_AUTOTUNE * 60L * 1000L)) {
567
       if (((ms - t1) + (ms - t2)) > (MAX_CYCLE_TIME_PID_AUTOTUNE * 60L * 1000L)) {
568
+        TERN_(DWIN_CREALITY_LCD, Popup_Window_Temperature(0));
563
         TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TUNING_TIMEOUT));
569
         TERN_(EXTENSIBLE_UI, ExtUI::onPidTuning(ExtUI::result_t::PID_TUNING_TIMEOUT));
564
         SERIAL_ECHOLNPGM(STR_PID_TIMEOUT);
570
         SERIAL_ECHOLNPGM(STR_PID_TIMEOUT);
565
         break;
571
         break;
612
 
618
 
613
         goto EXIT_M303;
619
         goto EXIT_M303;
614
       }
620
       }
615
-      ui.update();
621
+      TERN(DWIN_CREALITY_LCD, DWIN_Update(), ui.update());
616
     }
622
     }
617
 
623
 
618
     disable_all_heaters();
624
     disable_all_heaters();
794
 }
800
 }
795
 
801
 
796
 void Temperature::max_temp_error(const heater_ind_t heater) {
802
 void Temperature::max_temp_error(const heater_ind_t heater) {
803
+  TERN_(DWIN_CREALITY_LCD, Popup_Window_Temperature(1));
797
   _temp_error(heater, PSTR(STR_T_MAXTEMP), GET_TEXT(MSG_ERR_MAXTEMP));
804
   _temp_error(heater, PSTR(STR_T_MAXTEMP), GET_TEXT(MSG_ERR_MAXTEMP));
798
 }
805
 }
799
 
806
 
800
 void Temperature::min_temp_error(const heater_ind_t heater) {
807
 void Temperature::min_temp_error(const heater_ind_t heater) {
808
+  TERN_(DWIN_CREALITY_LCD, Popup_Window_Temperature(0));
801
   _temp_error(heater, PSTR(STR_T_MINTEMP), GET_TEXT(MSG_ERR_MINTEMP));
809
   _temp_error(heater, PSTR(STR_T_MINTEMP), GET_TEXT(MSG_ERR_MINTEMP));
802
 }
810
 }
803
 
811
 
1029
       #if WATCH_HOTENDS
1037
       #if WATCH_HOTENDS
1030
         // Make sure temperature is increasing
1038
         // Make sure temperature is increasing
1031
         if (watch_hotend[e].next_ms && ELAPSED(ms, watch_hotend[e].next_ms)) {  // Time to check this extruder?
1039
         if (watch_hotend[e].next_ms && ELAPSED(ms, watch_hotend[e].next_ms)) {  // Time to check this extruder?
1032
-          if (degHotend(e) < watch_hotend[e].target)                            // Failed to increase enough?
1040
+          if (degHotend(e) < watch_hotend[e].target) {                          // Failed to increase enough?
1041
+            TERN_(DWIN_CREALITY_LCD, Popup_Window_Temperature(0));
1033
             _temp_error((heater_ind_t)e, str_t_heating_failed, GET_TEXT(MSG_HEATING_FAILED_LCD));
1042
             _temp_error((heater_ind_t)e, str_t_heating_failed, GET_TEXT(MSG_HEATING_FAILED_LCD));
1043
+          }
1034
           else                                                                  // Start again if the target is still far off
1044
           else                                                                  // Start again if the target is still far off
1035
             start_watching_hotend(e);
1045
             start_watching_hotend(e);
1036
         }
1046
         }
1071
     #if WATCH_BED
1081
     #if WATCH_BED
1072
       // Make sure temperature is increasing
1082
       // Make sure temperature is increasing
1073
       if (watch_bed.elapsed(ms)) {        // Time to check the bed?
1083
       if (watch_bed.elapsed(ms)) {        // Time to check the bed?
1074
-        if (degBed() < watch_bed.target)                                // Failed to increase enough?
1084
+        if (degBed() < watch_bed.target) {                              // Failed to increase enough?
1085
+          TERN_(DWIN_CREALITY_LCD, Popup_Window_Temperature(0));
1075
           _temp_error(H_BED, str_t_heating_failed, GET_TEXT(MSG_HEATING_FAILED_LCD));
1086
           _temp_error(H_BED, str_t_heating_failed, GET_TEXT(MSG_HEATING_FAILED_LCD));
1087
+        }
1076
         else                                                            // Start again if the target is still far off
1088
         else                                                            // Start again if the target is still far off
1077
           start_watching_bed();
1089
           start_watching_bed();
1078
       }
1090
       }
1981
         sm.state = TRRunaway;
1993
         sm.state = TRRunaway;
1982
 
1994
 
1983
       case TRRunaway:
1995
       case TRRunaway:
1996
+        TERN_(DWIN_CREALITY_LCD, Popup_Window_Temperature(0));
1984
         _temp_error(heater_id, str_t_thermal_runaway, GET_TEXT(MSG_THERMAL_RUNAWAY));
1997
         _temp_error(heater_id, str_t_thermal_runaway, GET_TEXT(MSG_THERMAL_RUNAWAY));
1985
     }
1998
     }
1986
   }
1999
   }
3082
       } while (wait_for_heatup && TEMP_CONDITIONS);
3095
       } while (wait_for_heatup && TEMP_CONDITIONS);
3083
 
3096
 
3084
       if (wait_for_heatup) {
3097
       if (wait_for_heatup) {
3085
-        ui.reset_status();
3098
+        #if ENABLED(DWIN_CREALITY_LCD)
3099
+          HMI_flag.heat_flag = 0;
3100
+          duration_t elapsed = print_job_timer.duration();  // print timer
3101
+          heat_time = elapsed.value;
3102
+        #else
3103
+          ui.reset_status();
3104
+        #endif
3086
         TERN_(PRINTER_EVENT_LEDS, printerEventLEDs.onHeatingDone());
3105
         TERN_(PRINTER_EVENT_LEDS, printerEventLEDs.onHeatingDone());
3087
       }
3106
       }
3088
 
3107
 

+ 2
- 0
Marlin/src/pins/pins.h View File

544
   #include "stm32f1/pins_CHITU3D_V5.h"          // STM32F1                                env:chitu_f103 env:chitu_v5_gpio_init
544
   #include "stm32f1/pins_CHITU3D_V5.h"          // STM32F1                                env:chitu_f103 env:chitu_v5_gpio_init
545
 #elif MB(CHITU3D_V6)
545
 #elif MB(CHITU3D_V6)
546
   #include "stm32f1/pins_CHITU3D_V6.h"          // STM32F1                                env:chitu_f103
546
   #include "stm32f1/pins_CHITU3D_V6.h"          // STM32F1                                env:chitu_f103
547
+#elif MB(CREALITY_V4)
548
+  #include "stm32f1/pins_CREALITY_V4.h"         // STM32F1                                env:STM32F103RET6_creality
547
 
549
 
548
 //
550
 //
549
 // ARM Cortex-M4F
551
 // ARM Cortex-M4F

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

201
   #define MOSI_PIN                          PA7
201
   #define MOSI_PIN                          PA7
202
   #define SS_PIN                            PA4
202
   #define SS_PIN                            PA4
203
 #endif
203
 #endif
204
-#define ON_BOARD_SPI_DEVICE 1                     //SPI1
204
+#define ON_BOARD_SPI_DEVICE 1                     // SPI1
205
 #define ONBOARD_SD_CS_PIN                   PA4   // Chip select for "System" SD card
205
 #define ONBOARD_SD_CS_PIN                   PA4   // Chip select for "System" SD card
206
 
206
 
207
 #if HAS_GRAPHICAL_LCD
207
 #if HAS_GRAPHICAL_LCD

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

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * CREALITY (STM32F103) board pin assignments
25
+ */
26
+
27
+#ifndef __STM32F1__
28
+  #error "Oops! Select an STM32F1 board in 'Tools > Board.'"
29
+#endif
30
+
31
+#if HOTENDS > 1 || E_STEPPERS > 1
32
+  #error "CREALITY supports up to 1 hotends / E-steppers. Comment out this line to continue."
33
+#endif
34
+
35
+#define BOARD_INFO_NAME      "CREALITY V4"
36
+#define DEFAULT_MACHINE_NAME "Ender 3 V2"
37
+
38
+//
39
+// EEPROM
40
+//
41
+
42
+/* I2C */
43
+#define IIC_BL24CXX_EEPROM                        // EEPROM on I2C-0
44
+//#define E2END 0x3FFF                            // 16Kb (24c16)
45
+#define IIC_EEPROM_SDA                      PA11
46
+#define IIC_EEPROM_SCL                      PA12
47
+
48
+// SD EEPROM was in your original build, so...
49
+#define SDCARD_EEPROM_EMULATION
50
+
51
+/* SPI */
52
+//#define SPI_EEPROM                              // EEPROM on SPI-0
53
+//#define SPI_CHAN_EEPROM1        ?
54
+//#define SPI_EEPROM1_CS          ?
55
+// 2K EEPROM
56
+//#define SPI_EEPROM2_CS          ?
57
+// 32Mb FLASH
58
+//#define SPI_FLASH_CS            ?
59
+
60
+/* FLASH */
61
+//#define FLASH_EEPROM_EMULATION
62
+
63
+//
64
+// Servos
65
+//
66
+#define SERVO0_PIN                          PB0   // BLTouch OUT
67
+
68
+//
69
+// Limit Switches
70
+//
71
+#define X_STOP_PIN                          PA5
72
+#define Y_STOP_PIN                          PA6
73
+#define Z_STOP_PIN                          PA7
74
+
75
+#define Z_PROBE_PIN                         PB1   // BLTouch IN
76
+
77
+//
78
+// Steppers
79
+//
80
+#define X_ENABLE_PIN                        PC3
81
+#define X_STEP_PIN                          PC2
82
+#define X_DIR_PIN                           PB9
83
+
84
+#define Y_ENABLE_PIN                        PC3
85
+#define Y_STEP_PIN                          PB8
86
+#define Y_DIR_PIN                           PB7
87
+
88
+#define Z_ENABLE_PIN                        PC3
89
+#define Z_STEP_PIN                          PB6
90
+#define Z_DIR_PIN                           PB5
91
+
92
+#define E0_ENABLE_PIN                       PC3
93
+#define E0_STEP_PIN                         PB4
94
+#define E0_DIR_PIN                          PB3
95
+
96
+//
97
+// Release PB4 (Y_ENABLE_PIN) from JTAG NRST role
98
+//
99
+#define DISABLE_DEBUG
100
+
101
+//
102
+// Temperature Sensors
103
+//
104
+#define TEMP_0_PIN                          PC5   // TH1
105
+#define TEMP_BED_PIN                        PC4   // TB1
106
+
107
+//
108
+// Heaters / Fans
109
+//
110
+#define HEATER_0_PIN                        PA1   // HEATER1
111
+#define HEATER_BED_PIN                      PA2   // HOT BED
112
+
113
+#define FAN_PIN                             PA0   // FAN
114
+#define FAN_SOFT_PWM
115
+
116
+//
117
+// SD Card
118
+//
119
+#define SD_DETECT_PIN                       PC7
120
+#define SDCARD_CONNECTION                ONBOARD
121
+#define ON_BOARD_SPI_DEVICE 1
122
+#define ONBOARD_SD_CS_PIN                   PA4  // SDSS
123
+#define SDIO_SUPPORT
124
+
125
+#if ENABLED(RET6_12864_LCD)
126
+
127
+  /* RET6 12864 LCD */
128
+  #define LCD_PINS_RS                       PB12
129
+  #define LCD_PINS_ENABLE                   PB15
130
+  #define LCD_PINS_D4                       PB13
131
+
132
+  #define BTN_ENC                           PB2
133
+  #define BTN_EN1                           PB10
134
+  #define BTN_EN2                           PB14
135
+
136
+  #define BEEPER_PIN                        PC6
137
+#elif ENABLED(VET6_12864_LCD)
138
+
139
+  /* VET6 12864 LCD */
140
+  #define LCD_PINS_RS                       PA4
141
+  #define LCD_PINS_ENABLE                   PA7
142
+  #define LCD_PINS_D4                       PA5
143
+
144
+  #define BTN_ENC                           PC5
145
+  #define BTN_EN1                           PB10
146
+  #define BTN_EN2                           PA6
147
+
148
+#elif ENABLED(DWIN_CREALITY_LCD)
149
+
150
+  /* RET6 DWIN ENCODER LCD */
151
+  #define BTN_ENC                           PB14
152
+  #define BTN_EN1                           PB15
153
+  #define BTN_EN2                           PB12
154
+
155
+  //#define LCD_LED_PIN                     PB2
156
+  #define BEEPER_PIN                        PB13
157
+
158
+#elif ENABLED(DWIN_VET6_CREALITY_LCD)
159
+
160
+  /* VET6 DWIN ENCODER LCD */
161
+  #define BTN_ENC                           PA6
162
+  #define BTN_EN1                           PA7
163
+  #define BTN_EN2                           PA4
164
+
165
+  #define BEEPER_PIN                        PA5
166
+
167
+#endif

+ 20
- 9
Marlin/src/sd/cardreader.cpp View File

28
 
28
 
29
 #include "../MarlinCore.h"
29
 #include "../MarlinCore.h"
30
 #include "../lcd/ultralcd.h"
30
 #include "../lcd/ultralcd.h"
31
+
32
+#if ENABLED(DWIN_CREALITY_LCD)
33
+  #include "../lcd/dwin/dwin.h"
34
+#endif
35
+
31
 #include "../module/planner.h"        // for synchronize
36
 #include "../module/planner.h"        // for synchronize
32
 #include "../module/printcounter.h"
37
 #include "../module/printcounter.h"
33
 #include "../gcode/queue.h"
38
 #include "../gcode/queue.h"
385
 void CardReader::manage_media() {
390
 void CardReader::manage_media() {
386
   static uint8_t prev_stat = TERN(INIT_SDCARD_ON_BOOT, 2, 0);
391
   static uint8_t prev_stat = TERN(INIT_SDCARD_ON_BOOT, 2, 0);
387
   uint8_t stat = uint8_t(IS_SD_INSERTED());
392
   uint8_t stat = uint8_t(IS_SD_INSERTED());
388
-  if (stat != prev_stat && ui.detected()) {
393
+  if (stat == prev_stat) return;
394
+
395
+  flag.workDirIsRoot = true;          // Return to root on mount/release
396
+
397
+  if (ui.detected()) {
389
 
398
 
390
     uint8_t old_stat = prev_stat;
399
     uint8_t old_stat = prev_stat;
391
     prev_stat = stat;                 // Change now to prevent re-entry
400
     prev_stat = stat;                 // Change now to prevent re-entry
420
 void CardReader::release() {
429
 void CardReader::release() {
421
   endFilePrint();
430
   endFilePrint();
422
   flag.mounted = false;
431
   flag.mounted = false;
432
+  flag.workDirIsRoot = true;
433
+  nrFiles = 0;
423
 }
434
 }
424
 
435
 
425
 void CardReader::openAndPrintFile(const char *name) {
436
 void CardReader::openAndPrintFile(const char *name) {
440
 
451
 
441
 void CardReader::endFilePrint(TERN_(SD_RESORT, const bool re_sort/*=false*/)) {
452
 void CardReader::endFilePrint(TERN_(SD_RESORT, const bool re_sort/*=false*/)) {
442
   TERN_(ADVANCED_PAUSE_FEATURE, did_pause_print = 0);
453
   TERN_(ADVANCED_PAUSE_FEATURE, did_pause_print = 0);
454
+  TERN_(DWIN_CREALITY_LCD, HMI_flag.print_finish = flag.sdprinting);
443
   flag.sdprinting = flag.abort_sd_printing = false;
455
   flag.sdprinting = flag.abort_sd_printing = false;
444
   if (isFileOpen()) file.close();
456
   if (isFileOpen()) file.close();
445
   TERN_(SD_RESORT, if (re_sort) presort());
457
   TERN_(SD_RESORT, if (re_sort) presort());
944
             #if HAS_FOLDER_SORTING
956
             #if HAS_FOLDER_SORTING
945
               const uint16_t bit = i & 0x07, ind = i >> 3;
957
               const uint16_t bit = i & 0x07, ind = i >> 3;
946
               if (bit == 0) isDir[ind] = 0x00;
958
               if (bit == 0) isDir[ind] = 0x00;
947
-              if (flag.filenameIsDir) isDir[ind] |= _BV(bit);
959
+              if (flag.filenameIsDir) SBI(isDir[ind], bit);
948
             #endif
960
             #endif
949
           #endif
961
           #endif
950
         }
962
         }
972
             #if HAS_FOLDER_SORTING
984
             #if HAS_FOLDER_SORTING
973
               #if ENABLED(SDSORT_USES_RAM)
985
               #if ENABLED(SDSORT_USES_RAM)
974
                 // Folder sorting needs an index and bit to test for folder-ness.
986
                 // Folder sorting needs an index and bit to test for folder-ness.
975
-                #define _SORT_CMP_DIR(fs) IS_DIR(o1) == IS_DIR(o2) ? _SORT_CMP_NODIR() : IS_DIR(fs > 0 ? o1 : o2)
987
+                #define _SORT_CMP_DIR(fs) (IS_DIR(o1) == IS_DIR(o2) ? _SORT_CMP_NODIR() : IS_DIR(fs > 0 ? o1 : o2))
976
               #else
988
               #else
977
                 #define _SORT_CMP_DIR(fs) ((dir1 == flag.filenameIsDir) ? _SORT_CMP_NODIR() : (fs > 0 ? dir1 : !dir1))
989
                 #define _SORT_CMP_DIR(fs) ((dir1 == flag.filenameIsDir) ? _SORT_CMP_NODIR() : (fs > 0 ? dir1 : !dir1))
978
               #endif
990
               #endif
1062
 #endif // SDCARD_SORT_ALPHA
1074
 #endif // SDCARD_SORT_ALPHA
1063
 
1075
 
1064
 uint16_t CardReader::get_num_Files() {
1076
 uint16_t CardReader::get_num_Files() {
1065
-  return
1066
-    #if ENABLED(SDCARD_SORT_ALPHA) && SDSORT_USES_RAM && SDSORT_CACHE_NAMES
1077
+  if (!isMounted()) return 0;
1078
+  return (
1079
+    #if ALL(SDCARD_SORT_ALPHA, SDSORT_USES_RAM, SDSORT_CACHE_NAMES)
1067
       nrFiles // no need to access the SD card for filenames
1080
       nrFiles // no need to access the SD card for filenames
1068
     #else
1081
     #else
1069
       countFilesInWorkDir()
1082
       countFilesInWorkDir()
1070
     #endif
1083
     #endif
1071
-  ;
1084
+  );
1072
 }
1085
 }
1073
 
1086
 
1074
 //
1087
 //
1084
     startFileprint();
1097
     startFileprint();
1085
   }
1098
   }
1086
   else {
1099
   else {
1087
-    endFilePrint();
1088
-
1089
-    TERN_(SDCARD_SORT_ALPHA, presort());
1100
+    endFilePrint(TERN_(SD_RESORT, true));
1090
 
1101
 
1091
     marlin_state = MF_SD_COMPLETE;
1102
     marlin_state = MF_SD_COMPLETE;
1092
   }
1103
   }

+ 1
- 0
Marlin/src/sd/cardreader.h View File

152
 
152
 
153
   static inline bool isFileOpen() { return isMounted() && file.isOpen(); }
153
   static inline bool isFileOpen() { return isMounted() && file.isOpen(); }
154
   static inline uint32_t getIndex() { return sdpos; }
154
   static inline uint32_t getIndex() { return sdpos; }
155
+  static inline uint32_t getFileSize() { return filesize; }
155
   static inline bool eof() { return sdpos >= filesize; }
156
   static inline bool eof() { return sdpos >= filesize; }
156
   static inline void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); }
157
   static inline void setIndex(const uint32_t index) { sdpos = index; file.seekSet(index); }
157
   static inline char* getWorkDirName() { workDir.getDosName(filename); return filename; }
158
   static inline char* getWorkDirName() { workDir.getDosName(filename); return filename; }

+ 14
- 0
buildroot/share/PlatformIO/ldscripts/creality.ld View File

1
+MEMORY
2
+{
3
+  ram (rwx) : ORIGIN = 0x20000000, LENGTH = 64K - 40
4
+  rom (rx)  : ORIGIN = 0x08007000, LENGTH = 512K - 28K
5
+}
6
+
7
+/* Provide memory region aliases for common.inc */
8
+REGION_ALIAS("REGION_TEXT", rom);
9
+REGION_ALIAS("REGION_DATA", ram);
10
+REGION_ALIAS("REGION_BSS", ram);
11
+REGION_ALIAS("REGION_RODATA", rom);
12
+
13
+/* Let common.inc handle the real work. */
14
+INCLUDE common.inc

+ 16
- 0
buildroot/share/PlatformIO/scripts/creality.py View File

1
+import os
2
+Import("env")
3
+
4
+# Relocate firmware from 0x08000000 to 0x08007000
5
+for define in env['CPPDEFINES']:
6
+    if define[0] == "VECT_TAB_ADDR":
7
+        env['CPPDEFINES'].remove(define)
8
+env['CPPDEFINES'].append(("VECT_TAB_ADDR", "0x08007000"))
9
+
10
+custom_ld_script = os.path.abspath("buildroot/share/PlatformIO/ldscripts/creality.ld")
11
+for i, flag in enumerate(env["LINKFLAGS"]):
12
+    if "-Wl,-T" in flag:
13
+        env["LINKFLAGS"][i] = "-Wl,-T" + custom_ld_script
14
+    elif flag == "-T":
15
+        env["LINKFLAGS"][i + 1] = custom_ld_script
16
+

+ 15
- 0
buildroot/share/tests/STM32F103RET6_creality-tests View File

1
+#!/usr/bin/env bash
2
+#
3
+# Build tests for STM32F103RET6_creality
4
+#
5
+
6
+# exit on first failure
7
+set -e
8
+
9
+#
10
+# Build with configs included in the PR
11
+#
12
+use_example_configs "Creality/Ender-3 V2"
13
+exec_test $1 $2 "Ender 3 v2"
14
+
15
+restore_configs

+ 16
- 0
platformio.ini View File

690
 build_flags   = ${env:chitu_f103.build_flags} -DCHITU_V5_Z_MIN_BUGFIX
690
 build_flags   = ${env:chitu_f103.build_flags} -DCHITU_V5_Z_MIN_BUGFIX
691
 
691
 
692
 #
692
 #
693
+# Creality (STM32F103RET6)
694
+#
695
+[env:STM32F103RET6_creality]
696
+platform        = ${common_stm32f1.platform}
697
+extends         = common_stm32f1
698
+board           = genericSTM32F103RC
699
+build_flags     = !python Marlin/src/HAL/STM32F1/build_flags.py
700
+  ${common.build_flags} -std=gnu++14 -DSTM32_XL_DENSITY -DTEMP_TIMER_CHAN=4
701
+extra_scripts   = buildroot/share/PlatformIO/scripts/creality.py
702
+lib_ignore      = ${common_stm32f1.lib_ignore}
703
+  LiquidCrystal, LiquidTWI2, U8glib-HAL, Adafruit_MAX31865, Arduino-L6470, SailfishLCD, SlowSoftI2CMaster
704
+debug_tool      = jlink
705
+upload_protocol = jlink
706
+monitor_speed   = 115200
707
+
708
+#
693
 # STM32F401VE
709
 # STM32F401VE
694
 # 'STEVAL-3DP001V1' STM32F401VE board - https://www.st.com/en/evaluation-tools/steval-3dp001v1.html
710
 # 'STEVAL-3DP001V1' STM32F401VE board - https://www.st.com/en/evaluation-tools/steval-3dp001v1.html
695
 #
711
 #

Loading…
Cancel
Save