My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dwin_lcd.h 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /**
  2. * DWIN UI Enhanced implementation
  3. * Author: Miguel A. Risco-Castillo
  4. * Version: 3.6.1
  5. * Date: 2021/08/29
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. *
  20. */
  21. /********************************************************************************
  22. * @file lcd/e3v2/enhanced/dwin_lcd.h
  23. * @author LEO / Creality3D - Enhanced by Miguel A. Risco-Castillo
  24. * @date 2021/08/29
  25. * @version 2.1.1
  26. * @brief DWIN screen control functions
  27. ********************************************************************************/
  28. #pragma once
  29. #include <stdint.h>
  30. #define RECEIVED_NO_DATA 0x00
  31. #define RECEIVED_SHAKE_HAND_ACK 0x01
  32. #define FHONE 0xAA
  33. #define DWIN_SCROLL_UP 2
  34. #define DWIN_SCROLL_DOWN 3
  35. #define DWIN_WIDTH 272
  36. #define DWIN_HEIGHT 480
  37. #define DWIN_DataLength (DWIN_WIDTH / 6 * 2)
  38. /*-------------------------------------- System variable function --------------------------------------*/
  39. // Handshake (1: Success, 0: Fail)
  40. bool DWIN_Handshake(void);
  41. // Set the backlight luminance
  42. // luminance: (0x00-0xFF)
  43. void DWIN_Backlight_SetLuminance(const uint8_t luminance);
  44. // Set screen display direction
  45. // dir: 0=0°, 1=90°, 2=180°, 3=270°
  46. void DWIN_Frame_SetDir(uint8_t dir);
  47. // Update display
  48. void DWIN_UpdateLCD(void);
  49. /*---------------------------------------- Drawing functions ----------------------------------------*/
  50. // Clear screen
  51. // color: Clear screen color
  52. void DWIN_Frame_Clear(const uint16_t color);
  53. // Draw a point
  54. // color: point color
  55. // width: point width 0x01-0x0F
  56. // height: point height 0x01-0x0F
  57. // x,y: upper left point
  58. void DWIN_Draw_Point(uint16_t color, uint8_t width, uint8_t height, uint16_t x, uint16_t y);
  59. // Draw a line
  60. // color: Line segment color
  61. // xStart/yStart: Start point
  62. // xEnd/yEnd: End point
  63. void DWIN_Draw_Line(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
  64. // Draw a Horizontal line
  65. // color: Line segment color
  66. // xStart/yStart: Start point
  67. // xLength: Line Length
  68. inline void DWIN_Draw_HLine(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xLength) {
  69. DWIN_Draw_Line(color, xStart, yStart, xStart + xLength - 1, yStart);
  70. }
  71. // Draw a Vertical line
  72. // color: Line segment color
  73. // xStart/yStart: Start point
  74. // yLength: Line Length
  75. inline void DWIN_Draw_VLine(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t yLength) {
  76. DWIN_Draw_Line(color, xStart, yStart, xStart, yStart + yLength - 1);
  77. }
  78. // Draw a rectangle
  79. // mode: 0=frame, 1=fill, 2=XOR fill
  80. // color: Rectangle color
  81. // xStart/yStart: upper left point
  82. // xEnd/yEnd: lower right point
  83. void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
  84. // Draw a box
  85. // mode: 0=frame, 1=fill, 2=XOR fill
  86. // color: Rectangle color
  87. // xStart/yStart: upper left point
  88. // xSize/ySize: box size
  89. inline void DWIN_Draw_Box(uint8_t mode, uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xSize, uint16_t ySize) {
  90. DWIN_Draw_Rectangle(mode, color, xStart, yStart, xStart + xSize - 1, yStart + ySize - 1);
  91. }
  92. // Move a screen area
  93. // mode: 0, circle shift; 1, translation
  94. // dir: 0=left, 1=right, 2=up, 3=down
  95. // dis: Distance
  96. // color: Fill color
  97. // xStart/yStart: upper left point
  98. // xEnd/yEnd: bottom right point
  99. void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
  100. uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
  101. /*---------------------------------------- Text related functions ----------------------------------------*/
  102. // Draw a string
  103. // widthAdjust: true=self-adjust character width; false=no adjustment
  104. // bShow: true=display background color; false=don't display background color
  105. // size: Font size
  106. // color: Character color
  107. // bColor: Background color
  108. // x/y: Upper-left coordinate of the string
  109. // *string: The string
  110. // rlimit: For draw less chars than string length use rlimit
  111. void DWIN_Draw_String(bool widthAdjust, bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * const string, uint16_t rlimit = 0xFFFF);
  112. inline void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const char * const string, uint16_t rlimit = 0xFFFF) {
  113. DWIN_Draw_String(0, bShow, size, color, bColor, x, y, string, rlimit);
  114. }
  115. class __FlashStringHelper;
  116. inline void DWIN_Draw_String(bool widthAdjust, bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const __FlashStringHelper *title) {
  117. DWIN_Draw_String(widthAdjust, bShow, size, color, bColor, x, y, (char *)title);
  118. }
  119. inline void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, const __FlashStringHelper *title) {
  120. DWIN_Draw_String(0, bShow, size, color, bColor, x, y, (char *)title);
  121. }
  122. // Draw a positive integer
  123. // bShow: true=display background color; false=don't display background color
  124. // zeroFill: true=zero fill; false=no zero fill
  125. // zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
  126. // size: Font size
  127. // color: Character color
  128. // bColor: Background color
  129. // iNum: Number of digits
  130. // x/y: Upper-left coordinate
  131. // value: Integer value
  132. void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
  133. uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint16_t value);
  134. // Draw a positive floating point number
  135. // bShow: true=display background color; false=don't display background color
  136. // zeroFill: true=zero fill; false=no zero fill
  137. // zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
  138. // size: Font size
  139. // color: Character color
  140. // bColor: Background color
  141. // iNum: Number of whole digits
  142. // fNum: Number of decimal digits
  143. // x/y: Upper-left point
  144. // value: Scaled positive float value
  145. void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
  146. uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, long value);
  147. /*---------------------------------------- Picture related functions ----------------------------------------*/
  148. // Display QR code
  149. // The size of the QR code is (46*QR_Pixel)*(46*QR_Pixel) dot matrix
  150. // QR_Pixel: The pixel size occupied by each point of the QR code: 0x01-0x0F (1-16)
  151. // (Nx, Ny): The coordinates of the upper left corner displayed by the QR code
  152. // str: multi-bit data
  153. void DWIN_Draw_QR(uint8_t QR_Pixel, uint16_t x, uint16_t y, char *string);
  154. inline void DWIN_Draw_QR(uint8_t QR_Pixel, uint16_t x, uint16_t y, const __FlashStringHelper *title) {
  155. DWIN_Draw_QR(QR_Pixel, x, y, (char *)title);
  156. }
  157. // Draw JPG and cached in #0 virtual display area
  158. // id: Picture ID
  159. void DWIN_JPG_ShowAndCache(const uint8_t id);
  160. // Draw an Icon
  161. // IBD: The icon background display: 0=Background filtering is not displayed, 1=Background display \\When setting the background filtering not to display, the background must be pure black
  162. // BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
  163. // BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
  164. // libID: Icon library ID
  165. // picID: Icon ID
  166. // x/y: Upper-left point
  167. void DWIN_ICON_Show(uint8_t IBD, uint8_t BIR, uint8_t BFI, uint8_t libID, uint8_t picID, uint16_t x, uint16_t y);
  168. // Draw an Icon with transparent background
  169. // libID: Icon library ID
  170. // picID: Icon ID
  171. // x/y: Upper-left point
  172. inline void DWIN_ICON_Show(uint8_t libID, uint8_t picID, uint16_t x, uint16_t y) {
  173. DWIN_ICON_Show(0, 0, 1, libID, picID, x, y);
  174. }
  175. // Draw an Icon from SRAM
  176. // IBD: The icon background display: 0=Background filtering is not displayed, 1=Background display \\When setting the background filtering not to display, the background must be pure black
  177. // BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
  178. // BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
  179. // x/y: Upper-left point
  180. // addr: SRAM address
  181. void DWIN_ICON_Show(uint8_t IBD, uint8_t BIR, uint8_t BFI, uint16_t x, uint16_t y, uint16_t addr);
  182. // Unzip the JPG picture to a virtual display area
  183. // n: Cache index
  184. // id: Picture ID
  185. void DWIN_JPG_CacheToN(uint8_t n, uint8_t id);
  186. // Unzip the JPG picture to virtual display area #1
  187. // id: Picture ID
  188. inline void DWIN_JPG_CacheTo1(uint8_t id) { DWIN_JPG_CacheToN(1, id); }
  189. // Copy area from current virtual display area to current screen
  190. // xStart/yStart: Upper-left of virtual area
  191. // xEnd/yEnd: Lower-right of virtual area
  192. // x/y: Screen paste point
  193. void DWIN_Frame_AreaCopy(uint16_t xStart, uint16_t yStart,
  194. uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y);
  195. // Copy area from virtual display area to current screen
  196. // IBD: background display: 0=Background filtering is not displayed, 1=Background display \\When setting the background filtering not to display, the background must be pure black
  197. // BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
  198. // BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
  199. // cacheID: virtual area number
  200. // xStart/yStart: Upper-left of virtual area
  201. // xEnd/yEnd: Lower-right of virtual area
  202. // x/y: Screen paste point
  203. void DWIN_Frame_AreaCopy(uint8_t IBD, uint8_t BIR, uint8_t BFI, uint8_t cacheID, uint16_t xStart, uint16_t yStart,
  204. uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y);
  205. // Copy area from virtual display area to current screen with transparent background
  206. // cacheID: virtual area number
  207. // xStart/yStart: Upper-left of virtual area
  208. // xEnd/yEnd: Lower-right of virtual area
  209. // x/y: Screen paste point
  210. inline void DWIN_Frame_AreaCopy(uint8_t cacheID, uint16_t xStart, uint16_t yStart,
  211. uint16_t xEnd, uint16_t yEnd, uint16_t x, uint16_t y) {
  212. DWIN_Frame_AreaCopy(0, 0, 1, cacheID, xStart, yStart, xEnd, yEnd, x, y);
  213. }
  214. // Animate a series of icons
  215. // animID: Animation ID up to 16
  216. // animate: animation on or off
  217. // libID: Icon library ID
  218. // picIDs: Icon starting ID
  219. // picIDe: Icon ending ID
  220. // x/y: Upper-left point
  221. // interval: Display time interval, unit 10mS
  222. void DWIN_ICON_Animation(uint8_t animID, bool animate, uint8_t libID, uint8_t picIDs,
  223. uint8_t picIDe, uint16_t x, uint16_t y, uint16_t interval);
  224. // Animation Control
  225. // state: 16 bits, each bit is the state of an animation id
  226. void DWIN_ICON_AnimationControl(uint16_t state);
  227. // Set LCD Brightness 0x00-0x0F
  228. void DWIN_LCD_Brightness(const uint8_t brightness);
  229. // Write buffer data to the SRAM or Flash
  230. // mem: 0x5A=32KB SRAM, 0xA5=16KB Flash
  231. // addr: start address
  232. // length: Bytes to write
  233. // data: address of the buffer with data
  234. void DWIN_WriteToMem(uint8_t mem, uint16_t addr, uint16_t length, uint8_t *data);
  235. // Write the contents of the 32KB SRAM data memory into the designated image memory space.
  236. // picID: Picture memory space location, 0x00-0x0F, each space is 32Kbytes
  237. void DWIN_SRAMToPic(uint8_t picID);