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.

u8g_dev_tft_upscale_from_128x64.cpp 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * u8g_dev_tft_320x240_upscale_from_128x64.cpp
  24. *
  25. * Universal 8bit Graphics Library
  26. *
  27. * Copyright (c) 2011, olikraus@gmail.com
  28. * All rights reserved.
  29. *
  30. * Redistribution and use in source and binary forms, with or without modification,
  31. * are permitted provided that the following conditions are met:
  32. *
  33. * Redistributions of source code must retain the above copyright notice, this list
  34. * of conditions and the following disclaimer.
  35. *
  36. * Redistributions in binary form must reproduce the above copyright notice, this
  37. * list of conditions and the following disclaimer in the documentation and/or other
  38. * materials provided with the distribution.
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  41. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  42. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  43. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  44. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  45. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  46. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  47. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  48. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  49. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  50. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  51. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  52. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  53. */
  54. #include "../../inc/MarlinConfig.h"
  55. #if HAS_MARLINUI_U8GLIB && (PIN_EXISTS(FSMC_CS) || ENABLED(SPI_GRAPHICAL_TFT))
  56. #include "HAL_LCD_com_defines.h"
  57. #include "ultralcd_DOGM.h"
  58. #include <string.h>
  59. #if EITHER(LCD_USE_DMA_FSMC, LCD_USE_DMA_SPI)
  60. #define HAS_LCD_IO 1
  61. #endif
  62. #include "../tft_io/tft_io.h"
  63. TFT_IO tftio;
  64. #define WIDTH LCD_PIXEL_WIDTH
  65. #define HEIGHT LCD_PIXEL_HEIGHT
  66. #define PAGE_HEIGHT 8
  67. #include "../scaled_tft.h"
  68. #define UPSCALE0(M) ((M) * (GRAPHICAL_TFT_UPSCALE))
  69. #define UPSCALE(A,M) (UPSCALE0(M) + (A))
  70. #define X_HI (UPSCALE(TFT_PIXEL_OFFSET_X, WIDTH) - 1)
  71. #define Y_HI (UPSCALE(TFT_PIXEL_OFFSET_Y, HEIGHT) - 1)
  72. // see https://ee-programming-notepad.blogspot.com/2016/10/16-bit-color-generator-picker.html
  73. #define COLOR_BLACK 0x0000 // #000000
  74. #define COLOR_WHITE 0xFFFF // #FFFFFF
  75. #define COLOR_SILVER 0xC618 // #C0C0C0
  76. #define COLOR_GREY 0x7BEF // #808080
  77. #define COLOR_DARKGREY 0x4208 // #404040
  78. #define COLOR_DARKGREY2 0x39E7 // #303030
  79. #define COLOR_DARK 0x0003 // Some dark color
  80. #define COLOR_RED 0xF800 // #FF0000
  81. #define COLOR_LIME 0x7E00 // #00FF00
  82. #define COLOR_BLUE 0x001F // #0000FF
  83. #define COLOR_YELLOW 0xFFE0 // #FFFF00
  84. #define COLOR_MAGENTA 0xF81F // #FF00FF
  85. #define COLOR_FUCHSIA 0xF81F // #FF00FF
  86. #define COLOR_CYAN 0x07FF // #00FFFF
  87. #define COLOR_AQUA 0x07FF // #00FFFF
  88. #define COLOR_MAROON 0x7800 // #800000
  89. #define COLOR_GREEN 0x03E0 // #008000
  90. #define COLOR_NAVY 0x000F // #000080
  91. #define COLOR_OLIVE 0x8400 // #808000
  92. #define COLOR_PURPLE 0x8010 // #800080
  93. #define COLOR_TEAL 0x0410 // #008080
  94. #define COLOR_ORANGE 0xFC00 // #FF7F00
  95. #ifndef TFT_MARLINUI_COLOR
  96. #define TFT_MARLINUI_COLOR COLOR_WHITE
  97. #endif
  98. #ifndef TFT_MARLINBG_COLOR
  99. #define TFT_MARLINBG_COLOR COLOR_BLACK
  100. #endif
  101. #ifndef TFT_DISABLED_COLOR
  102. #define TFT_DISABLED_COLOR COLOR_DARK
  103. #endif
  104. #ifndef TFT_BTCANCEL_COLOR
  105. #define TFT_BTCANCEL_COLOR COLOR_RED
  106. #endif
  107. #ifndef TFT_BTARROWS_COLOR
  108. #define TFT_BTARROWS_COLOR COLOR_BLUE
  109. #endif
  110. #ifndef TFT_BTOKMENU_COLOR
  111. #define TFT_BTOKMENU_COLOR COLOR_RED
  112. #endif
  113. static void setWindow(u8g_t *u8g, u8g_dev_t *dev, uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
  114. tftio.set_window(Xmin, Ymin, Xmax, Ymax);
  115. }
  116. #if HAS_TOUCH_XPT2046
  117. static const uint8_t buttonD[] = {
  118. B01111111,B11111111,B11111111,B11111110,
  119. B10000000,B00000000,B00000000,B00000001,
  120. B10000000,B00000000,B00000000,B00000001,
  121. B10000000,B00000000,B00000000,B00000001,
  122. B10000000,B00000000,B00000000,B00000001,
  123. B10000000,B00000000,B00000000,B00000001,
  124. B10000000,B00011000,B00110000,B00000001,
  125. B10000000,B00001100,B01100000,B00000001,
  126. B10000000,B00000110,B11000000,B00000001,
  127. B10000000,B00000011,B10000000,B00000001,
  128. B10000000,B00000011,B10000000,B00000001,
  129. B10000000,B00000110,B11000000,B00000001,
  130. B10000000,B00001100,B01100000,B00000001,
  131. B10000000,B00011000,B00110000,B00000001,
  132. B10000000,B00000000,B00000000,B00000001,
  133. B10000000,B00000000,B00000000,B00000001,
  134. B10000000,B00000000,B00000000,B00000001,
  135. B10000000,B00000000,B00000000,B00000001,
  136. B10000000,B00000000,B00000000,B00000001,
  137. B01111111,B11111111,B11111111,B11111110,
  138. };
  139. #if ENABLED(REVERSE_MENU_DIRECTION)
  140. static const uint8_t buttonA[] = {
  141. B01111111,B11111111,B11111111,B11111110,
  142. B10000000,B00000000,B00000000,B00000001,
  143. B10000000,B00000000,B00000000,B00000001,
  144. B10000000,B00000000,B00000000,B00000001,
  145. B10000000,B00000000,B00000000,B00000001,
  146. B10000000,B11100000,B00000000,B00000001,
  147. B10000000,B11100000,B00000000,B00000001,
  148. B10000000,B11100000,B00000000,B00000001,
  149. B10000000,B11100000,B00000000,B00000001,
  150. B10000000,B11100000,B00111111,B11100001,
  151. B10000111,B11111100,B00111111,B11100001,
  152. B10000011,B11111000,B00000000,B00000001,
  153. B10000001,B11110000,B00000000,B00000001,
  154. B10000000,B11100000,B00000000,B00000001,
  155. B10000000,B01000000,B00000000,B00000001,
  156. B10000000,B00000000,B00000000,B00000001,
  157. B10000000,B00000000,B00000000,B00000001,
  158. B10000000,B00000000,B00000000,B00000001,
  159. B10000000,B00000000,B00000000,B00000001,
  160. B01111111,B11111111,B11111111,B11111110,
  161. };
  162. static const uint8_t buttonB[] = {
  163. B01111111,B11111111,B11111111,B11111110,
  164. B10000000,B00000000,B00000000,B00000001,
  165. B10000000,B00000000,B00000000,B00000001,
  166. B10000000,B00000000,B00000000,B00000001,
  167. B10000000,B00000000,B00000000,B00000001,
  168. B10000000,B01100000,B00000010,B00000001,
  169. B10000000,B01100000,B00000111,B00000001,
  170. B10000000,B01100000,B00001111,B10000001,
  171. B10000000,B01100000,B00011111,B11000001,
  172. B10000111,B11111110,B00111111,B11100001,
  173. B10000111,B11111110,B00000111,B00000001,
  174. B10000000,B01100000,B00000111,B00000001,
  175. B10000000,B01100000,B00000111,B00000001,
  176. B10000000,B01100000,B00000111,B00000001,
  177. B10000000,B01100000,B00000111,B00000001,
  178. B10000000,B00000000,B00000000,B00000001,
  179. B10000000,B00000000,B00000000,B00000001,
  180. B10000000,B00000000,B00000000,B00000001,
  181. B10000000,B00000000,B00000000,B00000001,
  182. B01111111,B11111111,B11111111,B11111110,
  183. };
  184. #else
  185. static const uint8_t buttonA[] = {
  186. B01111111,B11111111,B11111111,B11111110,
  187. B10000000,B00000000,B00000000,B00000001,
  188. B10000000,B00000000,B00000000,B00000001,
  189. B10000000,B00000000,B00000000,B00000001,
  190. B10000000,B00000000,B00000000,B00000001,
  191. B10000000,B01000000,B00000000,B00000001,
  192. B10000000,B11100000,B00000000,B00000001,
  193. B10000001,B11110000,B00000000,B00000001,
  194. B10000011,B11111000,B00000000,B00000001,
  195. B10000111,B11111100,B00111111,B11100001,
  196. B10000000,B11100000,B00111111,B11100001,
  197. B10000000,B11100000,B00000000,B00000001,
  198. B10000000,B11100000,B00000000,B00000001,
  199. B10000000,B11100000,B00000000,B00000001,
  200. B10000000,B11100000,B00000000,B00000001,
  201. B10000000,B00000000,B00000000,B00000001,
  202. B10000000,B00000000,B00000000,B00000001,
  203. B10000000,B00000000,B00000000,B00000001,
  204. B10000000,B00000000,B00000000,B00000001,
  205. B01111111,B11111111,B11111111,B11111110,
  206. };
  207. static const uint8_t buttonB[] = {
  208. B01111111,B11111111,B11111111,B11111110,
  209. B10000000,B00000000,B00000000,B00000001,
  210. B10000000,B00000000,B00000000,B00000001,
  211. B10000000,B00000000,B00000000,B00000001,
  212. B10000000,B00000000,B00000000,B00000001,
  213. B10000000,B01100000,B00000111,B00000001,
  214. B10000000,B01100000,B00000111,B00000001,
  215. B10000000,B01100000,B00000111,B00000001,
  216. B10000000,B01100000,B00000111,B00000001,
  217. B10000111,B11111110,B00000111,B00000001,
  218. B10000111,B11111110,B00111111,B11100001,
  219. B10000000,B01100000,B00011111,B11000001,
  220. B10000000,B01100000,B00001111,B10000001,
  221. B10000000,B01100000,B00000111,B00000001,
  222. B10000000,B01100000,B00000010,B00000001,
  223. B10000000,B00000000,B00000000,B00000001,
  224. B10000000,B00000000,B00000000,B00000001,
  225. B10000000,B00000000,B00000000,B00000001,
  226. B10000000,B00000000,B00000000,B00000001,
  227. B01111111,B11111111,B11111111,B11111110,
  228. };
  229. #endif
  230. static const uint8_t buttonC[] = {
  231. B01111111,B11111111,B11111111,B11111110,
  232. B10000000,B00000000,B00000000,B00000001,
  233. B10000000,B00000000,B00000000,B00000001,
  234. B10000000,B00000000,B00000000,B00000001,
  235. B10000000,B00000000,B00000000,B00000001,
  236. B10000000,B00000000,B00000000,B00000001,
  237. B10000000,B00000000,B00011100,B00000001,
  238. B10000000,B00000100,B00011100,B00000001,
  239. B10000000,B00001100,B00011100,B00000001,
  240. B10000000,B00011111,B11111100,B00000001,
  241. B10000000,B00111111,B11111100,B00000001,
  242. B10000000,B00011111,B11111100,B00000001,
  243. B10000000,B00001100,B00000000,B00000001,
  244. B10000000,B00000100,B00000000,B00000001,
  245. B10000000,B00000000,B00000000,B00000001,
  246. B10000000,B00000000,B00000000,B00000001,
  247. B10000000,B00000000,B00000000,B00000001,
  248. B10000000,B00000000,B00000000,B00000001,
  249. B10000000,B00000000,B00000000,B00000001,
  250. B01111111,B11111111,B11111111,B11111110,
  251. };
  252. #define BUTTON_SIZE_X 32
  253. #define BUTTON_SIZE_Y 20
  254. // 14, 90, 166, 242, 185 are the original values upscaled 2x.
  255. #define BUTTOND_X_LO UPSCALE0(14 / 2)
  256. #define BUTTOND_X_HI (UPSCALE(BUTTOND_X_LO, BUTTON_SIZE_X) - 1)
  257. #define BUTTONA_X_LO UPSCALE0(90 / 2)
  258. #define BUTTONA_X_HI (UPSCALE(BUTTONA_X_LO, BUTTON_SIZE_X) - 1)
  259. #define BUTTONB_X_LO UPSCALE0(166 / 2)
  260. #define BUTTONB_X_HI (UPSCALE(BUTTONB_X_LO, BUTTON_SIZE_X) - 1)
  261. #define BUTTONC_X_LO UPSCALE0(242 / 2)
  262. #define BUTTONC_X_HI (UPSCALE(BUTTONC_X_LO, BUTTON_SIZE_X) - 1)
  263. #define BUTTON_Y_LO UPSCALE0(140 / 2) + 44 // 184 2x, 254 3x
  264. #define BUTTON_Y_HI (UPSCALE(BUTTON_Y_LO, BUTTON_SIZE_Y) - 1)
  265. void drawImage(const uint8_t *data, u8g_t *u8g, u8g_dev_t *dev, uint16_t length, uint16_t height, uint16_t color) {
  266. uint16_t buffer[BUTTON_SIZE_X * sq(GRAPHICAL_TFT_UPSCALE)];
  267. if (length > BUTTON_SIZE_X) return;
  268. for (uint16_t i = 0; i < height; i++) {
  269. uint16_t k = 0;
  270. for (uint16_t j = 0; j < length; j++) {
  271. uint16_t v = TFT_MARLINBG_COLOR;
  272. if (*(data + (i * (length >> 3) + (j >> 3))) & (0x80 >> (j & 7)))
  273. v = color;
  274. else
  275. v = TFT_MARLINBG_COLOR;
  276. LOOP_L_N(n, GRAPHICAL_TFT_UPSCALE) buffer[k++] = v;
  277. }
  278. #if HAS_LCD_IO
  279. LOOP_S_L_N(n, 1, GRAPHICAL_TFT_UPSCALE)
  280. for (uint16_t l = 0; l < UPSCALE0(length); l++)
  281. buffer[l + n * UPSCALE0(length)] = buffer[l];
  282. tftio.WriteSequence(buffer, length * sq(GRAPHICAL_TFT_UPSCALE));
  283. #else
  284. for (uint8_t i = GRAPHICAL_TFT_UPSCALE; i--;)
  285. u8g_WriteSequence(u8g, dev, k << 1, (uint8_t*)buffer);
  286. #endif
  287. }
  288. }
  289. #endif // HAS_TOUCH_XPT2046
  290. // Used to fill RGB565 (16bits) background
  291. inline void memset2(const void *ptr, uint16_t fill, size_t cnt) {
  292. uint16_t* wptr = (uint16_t*)ptr;
  293. for (size_t i = 0; i < cnt; i += 2) { *wptr = fill; wptr++; }
  294. }
  295. static bool preinit = true;
  296. static uint8_t page;
  297. uint8_t u8g_dev_tft_320x240_upscale_from_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) {
  298. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  299. #if HAS_LCD_IO
  300. static uint16_t bufferA[WIDTH * sq(GRAPHICAL_TFT_UPSCALE)], bufferB[WIDTH * sq(GRAPHICAL_TFT_UPSCALE)];
  301. uint16_t* buffer = &bufferA[0];
  302. #else
  303. uint16_t buffer[WIDTH * GRAPHICAL_TFT_UPSCALE]; // 16-bit RGB 565 pixel line buffer
  304. #endif
  305. switch (msg) {
  306. case U8G_DEV_MSG_INIT:
  307. dev->com_fn(u8g, U8G_COM_MSG_INIT, U8G_SPI_CLK_CYCLE_NONE, NULL);
  308. tftio.Init();
  309. tftio.InitTFT();
  310. if (preinit) {
  311. preinit = false;
  312. return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
  313. }
  314. // Clear Screen
  315. setWindow(u8g, dev, 0, 0, (TFT_WIDTH) - 1, (TFT_HEIGHT) - 1);
  316. #if HAS_LCD_IO
  317. tftio.WriteMultiple(TFT_MARLINBG_COLOR, uint32_t(TFT_WIDTH) * (TFT_HEIGHT));
  318. #else
  319. memset2(buffer, TFT_MARLINBG_COLOR, (TFT_WIDTH) / 2);
  320. for (uint16_t i = 0; i < (TFT_HEIGHT) * sq(GRAPHICAL_TFT_UPSCALE); i++)
  321. u8g_WriteSequence(u8g, dev, (TFT_WIDTH) / 2, (uint8_t *)buffer);
  322. #endif
  323. // Bottom buttons
  324. #if HAS_TOUCH_XPT2046
  325. setWindow(u8g, dev, BUTTOND_X_LO, BUTTON_Y_LO, BUTTOND_X_HI, BUTTON_Y_HI);
  326. drawImage(buttonD, u8g, dev, 32, 20, TFT_BTCANCEL_COLOR);
  327. setWindow(u8g, dev, BUTTONA_X_LO, BUTTON_Y_LO, BUTTONA_X_HI, BUTTON_Y_HI);
  328. drawImage(buttonA, u8g, dev, 32, 20, TFT_BTARROWS_COLOR);
  329. setWindow(u8g, dev, BUTTONB_X_LO, BUTTON_Y_LO, BUTTONB_X_HI, BUTTON_Y_HI);
  330. drawImage(buttonB, u8g, dev, 32, 20, TFT_BTARROWS_COLOR);
  331. setWindow(u8g, dev, BUTTONC_X_LO, BUTTON_Y_LO, BUTTONC_X_HI, BUTTON_Y_HI);
  332. drawImage(buttonC, u8g, dev, 32, 20, TFT_BTOKMENU_COLOR);
  333. #endif // HAS_TOUCH_XPT2046
  334. return 0;
  335. case U8G_DEV_MSG_STOP: preinit = true; break;
  336. case U8G_DEV_MSG_PAGE_FIRST:
  337. page = 0;
  338. setWindow(u8g, dev, TFT_PIXEL_OFFSET_X, TFT_PIXEL_OFFSET_Y, X_HI, Y_HI);
  339. break;
  340. case U8G_DEV_MSG_PAGE_NEXT:
  341. if (++page > (HEIGHT / PAGE_HEIGHT)) return 1;
  342. LOOP_L_N(y, PAGE_HEIGHT) {
  343. uint32_t k = 0;
  344. #if HAS_LCD_IO
  345. buffer = (y & 1) ? bufferB : bufferA;
  346. #endif
  347. for (uint16_t i = 0; i < (uint32_t)pb->width; i++) {
  348. const uint8_t b = *(((uint8_t *)pb->buf) + i);
  349. const uint16_t c = TEST(b, y) ? TFT_MARLINUI_COLOR : TFT_MARLINBG_COLOR;
  350. LOOP_L_N(n, GRAPHICAL_TFT_UPSCALE) buffer[k++] = c;
  351. }
  352. #if HAS_LCD_IO
  353. LOOP_S_L_N(n, 1, GRAPHICAL_TFT_UPSCALE)
  354. for (uint16_t l = 0; l < UPSCALE0(WIDTH); l++)
  355. buffer[l + n * UPSCALE0(WIDTH)] = buffer[l];
  356. tftio.WriteSequence(buffer, COUNT(bufferA));
  357. #else
  358. uint8_t* bufptr = (uint8_t*) buffer;
  359. for (uint8_t i = GRAPHICAL_TFT_UPSCALE; i--;) {
  360. LOOP_S_L_N(n, 0, GRAPHICAL_TFT_UPSCALE * 2) {
  361. u8g_WriteSequence(u8g, dev, WIDTH, &bufptr[WIDTH * n]);
  362. }
  363. }
  364. #endif
  365. }
  366. break;
  367. case U8G_DEV_MSG_SLEEP_ON:
  368. // Enter Sleep Mode (10h)
  369. return 1;
  370. case U8G_DEV_MSG_SLEEP_OFF:
  371. // Sleep Out (11h)
  372. return 1;
  373. }
  374. return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg);
  375. }
  376. static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT
  377. uint8_t u8g_com_hal_tft_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
  378. if (msgInitCount) {
  379. if (msg == U8G_COM_MSG_INIT) msgInitCount--;
  380. if (msgInitCount) return -1;
  381. }
  382. static uint8_t isCommand;
  383. switch (msg) {
  384. case U8G_COM_MSG_STOP: break;
  385. case U8G_COM_MSG_INIT:
  386. u8g_SetPIOutput(u8g, U8G_PI_RESET);
  387. u8g_Delay(50);
  388. isCommand = 0;
  389. break;
  390. case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1)
  391. isCommand = arg_val == 0 ? 1 : 0;
  392. break;
  393. case U8G_COM_MSG_RESET:
  394. u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
  395. break;
  396. case U8G_COM_MSG_WRITE_BYTE:
  397. tftio.DataTransferBegin(DATASIZE_8BIT);
  398. if (isCommand)
  399. tftio.WriteReg(arg_val);
  400. else
  401. tftio.WriteData((uint16_t)arg_val);
  402. tftio.DataTransferEnd();
  403. break;
  404. case U8G_COM_MSG_WRITE_SEQ:
  405. tftio.DataTransferBegin(DATASIZE_16BIT);
  406. for (uint8_t i = 0; i < arg_val; i += 2)
  407. tftio.WriteData(*(uint16_t *)(((uint32_t)arg_ptr) + i));
  408. tftio.DataTransferEnd();
  409. break;
  410. }
  411. return 1;
  412. }
  413. U8G_PB_DEV(u8g_dev_tft_320x240_upscale_from_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tft_320x240_upscale_from_128x64_fn, U8G_COM_HAL_TFT_FN);
  414. #endif // HAS_MARLINUI_U8GLIB && FSMC_CS