My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

dwin_api.h 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../../../inc/MarlinConfig.h"
  24. #if ENABLED(DWIN_MARLINUI_LANDSCAPE)
  25. #define DWIN_WIDTH 480
  26. #define DWIN_HEIGHT 272
  27. #else
  28. #define DWIN_WIDTH 272
  29. #define DWIN_HEIGHT 480
  30. #endif
  31. #define RECEIVED_NO_DATA 0x00
  32. #define RECEIVED_SHAKE_HAND_ACK 0x01
  33. #define FHONE 0xAA
  34. #define DWIN_SCROLL_UP 2
  35. #define DWIN_SCROLL_DOWN 3
  36. // Make sure DWIN_SendBuf is large enough to hold the largest string plus draw command and tail.
  37. // Assume the narrowest (6 pixel) font and 2-byte gb2312-encoded characters.
  38. extern uint8_t DWIN_SendBuf[11 + DWIN_WIDTH / 6 * 2];
  39. extern uint8_t DWIN_BufTail[4];
  40. extern uint8_t databuf[26];
  41. inline void DWIN_Byte(size_t &i, const uint16_t bval) {
  42. DWIN_SendBuf[++i] = bval;
  43. }
  44. inline void DWIN_Word(size_t &i, const uint16_t wval) {
  45. DWIN_SendBuf[++i] = wval >> 8;
  46. DWIN_SendBuf[++i] = wval & 0xFF;
  47. }
  48. inline void DWIN_Long(size_t &i, const uint32_t lval) {
  49. DWIN_SendBuf[++i] = (lval >> 24) & 0xFF;
  50. DWIN_SendBuf[++i] = (lval >> 16) & 0xFF;
  51. DWIN_SendBuf[++i] = (lval >> 8) & 0xFF;
  52. DWIN_SendBuf[++i] = lval & 0xFF;
  53. }
  54. // Send the data in the buffer plus the packet tail
  55. void DWIN_Send(size_t &i);
  56. inline void DWIN_Text(size_t &i, const char * const string, uint16_t rlimit=0xFFFF) {
  57. if (!string) return;
  58. const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, _MIN(strlen(string), rlimit));
  59. if (len == 0) return;
  60. memcpy(&DWIN_SendBuf[i+1], string, len);
  61. i += len;
  62. }
  63. inline void DWIN_Text(size_t &i, FSTR_P string, uint16_t rlimit=0xFFFF) {
  64. if (!string) return;
  65. const size_t len = _MIN(sizeof(DWIN_SendBuf) - i, _MIN(rlimit, strlen_P(FTOP(string))));
  66. if (len == 0) return;
  67. memcpy_P(&DWIN_SendBuf[i+1], string, len);
  68. i += len;
  69. }
  70. /*-------------------------------------- System variable function --------------------------------------*/
  71. // Handshake (1: Success, 0: Fail)
  72. bool DWIN_Handshake();
  73. // DWIN startup
  74. void DWIN_Startup();
  75. #if HAS_LCD_BRIGHTNESS
  76. // Set the backlight brightness
  77. // brightness: (0x00-0xFF)
  78. void DWIN_LCD_Brightness(const uint8_t brightness);
  79. #endif
  80. // Set screen display direction
  81. // dir: 0=0°, 1=90°, 2=180°, 3=270°
  82. void DWIN_Frame_SetDir(uint8_t dir);
  83. // Update display
  84. void DWIN_UpdateLCD();
  85. /*---------------------------------------- Drawing functions ----------------------------------------*/
  86. // Clear screen
  87. // color: Clear screen color
  88. void DWIN_Frame_Clear(const uint16_t color);
  89. // Draw a point
  90. // color: point color
  91. // width: point width 0x01-0x0F
  92. // height: point height 0x01-0x0F
  93. // x,y: upper left point
  94. void DWIN_Draw_Point(uint16_t color, uint8_t width, uint8_t height, uint16_t x, uint16_t y);
  95. // Draw a line
  96. // color: Line segment color
  97. // xStart/yStart: Start point
  98. // xEnd/yEnd: End point
  99. void DWIN_Draw_Line(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
  100. // Draw a Horizontal line
  101. // color: Line segment color
  102. // xStart/yStart: Start point
  103. // xLength: Line Length
  104. inline void DWIN_Draw_HLine(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xLength) {
  105. DWIN_Draw_Line(color, xStart, yStart, xStart + xLength - 1, yStart);
  106. }
  107. // Draw a Vertical line
  108. // color: Line segment color
  109. // xStart/yStart: Start point
  110. // yLength: Line Length
  111. inline void DWIN_Draw_VLine(uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t yLength) {
  112. DWIN_Draw_Line(color, xStart, yStart, xStart, yStart + yLength - 1);
  113. }
  114. // Draw a rectangle
  115. // mode: 0=frame, 1=fill, 2=XOR fill
  116. // color: Rectangle color
  117. // xStart/yStart: upper left point
  118. // xEnd/yEnd: lower right point
  119. void DWIN_Draw_Rectangle(uint8_t mode, uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
  120. // Draw a box
  121. // mode: 0=frame, 1=fill, 2=XOR fill
  122. // color: Rectangle color
  123. // xStart/yStart: upper left point
  124. // xSize/ySize: box size
  125. inline void DWIN_Draw_Box(uint8_t mode, uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xSize, uint16_t ySize) {
  126. DWIN_Draw_Rectangle(mode, color, xStart, yStart, xStart + xSize - 1, yStart + ySize - 1);
  127. }
  128. // Move a screen area
  129. // mode: 0, circle shift; 1, translation
  130. // dir: 0=left, 1=right, 2=up, 3=down
  131. // dis: Distance
  132. // color: Fill color
  133. // xStart/yStart: upper left point
  134. // xEnd/yEnd: bottom right point
  135. void DWIN_Frame_AreaMove(uint8_t mode, uint8_t dir, uint16_t dis,
  136. uint16_t color, uint16_t xStart, uint16_t yStart, uint16_t xEnd, uint16_t yEnd);
  137. /*---------------------------------------- Text related functions ----------------------------------------*/
  138. // Draw a string
  139. // bShow: true=display background color; false=don't display background color
  140. // size: Font size
  141. // color: Character color
  142. // bColor: Background color
  143. // x/y: Upper-left coordinate of the string
  144. // *string: The string
  145. // rlimit: For draw less chars than string length use rlimit
  146. 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);
  147. inline void DWIN_Draw_String(bool bShow, uint8_t size, uint16_t color, uint16_t bColor, uint16_t x, uint16_t y, FSTR_P const ftitle) {
  148. #ifdef __AVR__
  149. char ctitle[strlen_P(FTOP(ftitle)) + 1];
  150. strcpy_P(ctitle, FTOP(ftitle));
  151. DWIN_Draw_String(bShow, size, color, bColor, x, y, ctitle);
  152. #else
  153. DWIN_Draw_String(bShow, size, color, bColor, x, y, FTOP(ftitle));
  154. #endif
  155. }
  156. // Draw a positive integer
  157. // bShow: true=display background color; false=don't display background color
  158. // zeroFill: true=zero fill; false=no zero fill
  159. // zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
  160. // size: Font size
  161. // color: Character color
  162. // bColor: Background color
  163. // iNum: Number of digits
  164. // x/y: Upper-left coordinate
  165. // value: Integer value
  166. void DWIN_Draw_IntValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
  167. uint16_t bColor, uint8_t iNum, uint16_t x, uint16_t y, uint32_t value);
  168. // Draw a floating point number
  169. // bShow: true=display background color; false=don't display background color
  170. // zeroFill: true=zero fill; false=no zero fill
  171. // zeroMode: 1=leading 0 displayed as 0; 0=leading 0 displayed as a space
  172. // size: Font size
  173. // color: Character color
  174. // bColor: Background color
  175. // iNum: Number of whole digits
  176. // fNum: Number of decimal digits
  177. // x/y: Upper-left point
  178. // value: Float value
  179. void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
  180. uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, int32_t value);
  181. // Draw a floating point number
  182. // value: positive unscaled float value
  183. void DWIN_Draw_FloatValue(uint8_t bShow, bool zeroFill, uint8_t zeroMode, uint8_t size, uint16_t color,
  184. uint16_t bColor, uint8_t iNum, uint8_t fNum, uint16_t x, uint16_t y, float value);
  185. /*---------------------------------------- Picture related functions ----------------------------------------*/
  186. // Draw JPG and cached in #0 virtual display area
  187. // id: Picture ID
  188. void DWIN_JPG_ShowAndCache(const uint8_t id);
  189. // Draw an Icon
  190. // libID: Icon library ID
  191. // picID: Icon ID
  192. // x/y: Upper-left point
  193. void DWIN_ICON_Show(uint8_t libID, uint8_t picID, uint16_t x, uint16_t y);
  194. // Draw an Icon
  195. // 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
  196. // BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
  197. // BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
  198. // libID: Icon library ID
  199. // picID: Icon ID
  200. // x/y: Upper-left point
  201. void DWIN_ICON_Show(bool IBD, bool BIR, bool BFI, uint8_t libID, uint8_t picID, uint16_t x, uint16_t y);
  202. // Draw an Icon from SRAM
  203. // 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
  204. // BIR: Background image restoration: 0=Background image is not restored, 1=Automatically use virtual display area image for background restoration
  205. // BFI: Background filtering strength: 0=normal, 1=enhanced, (only valid when the icon background display=0)
  206. // x/y: Upper-left point
  207. // addr: SRAM address
  208. void DWIN_ICON_Show(bool IBD, bool BIR, bool BFI, uint16_t x, uint16_t y, uint16_t addr);
  209. // Unzip the JPG picture to a virtual display area
  210. // n: Cache index
  211. // id: Picture ID
  212. void DWIN_JPG_CacheToN(uint8_t n, uint8_t id);
  213. // Unzip the JPG picture to virtual display area #1
  214. // id: Picture ID
  215. inline void DWIN_JPG_CacheTo1(uint8_t id) { DWIN_JPG_CacheToN(1, id); }
  216. // Animate a series of icons
  217. // animID: Animation ID up to 16
  218. // animate: animation on or off
  219. // libID: Icon library ID
  220. // picIDs: Icon starting ID
  221. // picIDe: Icon ending ID
  222. // x/y: Upper-left point
  223. // interval: Display time interval, unit 10mS
  224. void DWIN_ICON_Animation(uint8_t animID, bool animate, uint8_t libID, uint8_t picIDs, uint8_t picIDe, uint16_t x, uint16_t y, uint16_t interval);
  225. // Animation Control
  226. // state: 16 bits, each bit is the state of an animation id
  227. void DWIN_ICON_AnimationControl(uint16_t state);