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.

tft_lvgl_configuration.cpp 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. #include "../../../inc/MarlinConfigPre.h"
  23. #if HAS_TFT_LVGL_UI
  24. #include "SPI_TFT.h"
  25. #include "tft_lvgl_configuration.h"
  26. #include "draw_ready_print.h"
  27. #include "pic_manager.h"
  28. #include "mks_hardware.h"
  29. #include "draw_ui.h"
  30. #include "SPIFlashStorage.h"
  31. #include <lvgl.h>
  32. #include "../../../MarlinCore.h"
  33. #include "../../../inc/MarlinConfig.h"
  34. #include HAL_PATH(../../../HAL, tft/xpt2046.h)
  35. #include "../../marlinui.h"
  36. XPT2046 touch;
  37. #if ENABLED(POWER_LOSS_RECOVERY)
  38. #include "../../../feature/powerloss.h"
  39. #endif
  40. #if HAS_SERVOS
  41. #include "../../../module/servo.h"
  42. #endif
  43. #if EITHER(PROBE_TARE, HAS_Z_SERVO_PROBE)
  44. #include "../../../module/probe.h"
  45. #endif
  46. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  47. #include "../../tft_io/touch_calibration.h"
  48. #include "draw_touch_calibration.h"
  49. #endif
  50. #if ENABLED(MKS_WIFI_MODULE)
  51. #include "wifi_module.h"
  52. #endif
  53. #include <SPI.h>
  54. #ifndef TFT_WIDTH
  55. #define TFT_WIDTH 480
  56. #endif
  57. #ifndef TFT_HEIGHT
  58. #define TFT_HEIGHT 320
  59. #endif
  60. #if HAS_SPI_FLASH_FONT
  61. void init_gb2312_font();
  62. #endif
  63. static lv_disp_buf_t disp_buf;
  64. lv_group_t* g;
  65. #if ENABLED(SDSUPPORT)
  66. void UpdateAssets();
  67. #endif
  68. uint16_t DeviceCode = 0x9488;
  69. extern uint8_t sel_id;
  70. uint8_t bmp_public_buf[14 * 1024];
  71. uint8_t public_buf[513];
  72. extern bool flash_preview_begin, default_preview_flg, gcode_preview_over;
  73. void SysTick_Callback() {
  74. lv_tick_inc(1);
  75. print_time_count();
  76. #if ENABLED(MKS_WIFI_MODULE)
  77. if (tips_disp.timer == TIPS_TIMER_START)
  78. tips_disp.timer_count++;
  79. #endif
  80. if (uiCfg.filament_loading_time_flg) {
  81. uiCfg.filament_loading_time_cnt++;
  82. uiCfg.filament_rate = uint32_t(100.0f * uiCfg.filament_loading_time_cnt / SEC_TO_MS(uiCfg.filament_loading_time) + 0.5f);
  83. if (uiCfg.filament_loading_time_cnt >= SEC_TO_MS(uiCfg.filament_loading_time)) {
  84. uiCfg.filament_loading_time_cnt = 0;
  85. uiCfg.filament_loading_time_flg = false;
  86. uiCfg.filament_loading_completed = true;
  87. }
  88. }
  89. if (uiCfg.filament_unloading_time_flg) {
  90. uiCfg.filament_unloading_time_cnt++;
  91. uiCfg.filament_rate = uint32_t(100.0f * uiCfg.filament_unloading_time_cnt / SEC_TO_MS(uiCfg.filament_unloading_time) + 0.5f);
  92. if (uiCfg.filament_unloading_time_cnt >= SEC_TO_MS(uiCfg.filament_unloading_time)) {
  93. uiCfg.filament_unloading_time_cnt = 0;
  94. uiCfg.filament_unloading_time_flg = false;
  95. uiCfg.filament_unloading_completed = true;
  96. uiCfg.filament_rate = 100;
  97. }
  98. }
  99. }
  100. void tft_lvgl_init() {
  101. W25QXX.init(SPI_QUARTER_SPEED);
  102. gCfgItems_init();
  103. ui_cfg_init();
  104. disp_language_init();
  105. watchdog_refresh(); // LVGL init takes time
  106. // Init TFT first!
  107. SPI_TFT.spi_init(SPI_FULL_SPEED);
  108. SPI_TFT.LCD_init();
  109. watchdog_refresh(); // LVGL init takes time
  110. #if ENABLED(USB_FLASH_DRIVE_SUPPORT)
  111. uint16_t usb_flash_loop = 1000;
  112. #if ENABLED(MULTI_VOLUME) && !HAS_SD_HOST_DRIVE
  113. SET_INPUT_PULLUP(SD_DETECT_PIN);
  114. if (READ(SD_DETECT_PIN) == LOW) card.changeMedia(&card.media_driver_sdcard);
  115. else card.changeMedia(&card.media_driver_usbFlash);
  116. #endif
  117. do {
  118. card.media_driver_usbFlash.idle();
  119. watchdog_refresh();
  120. delay(2);
  121. } while (!card.media_driver_usbFlash.isInserted() && usb_flash_loop--);
  122. card.mount();
  123. #elif HAS_LOGO_IN_FLASH
  124. delay(1000);
  125. watchdog_refresh();
  126. delay(1000);
  127. #endif
  128. watchdog_refresh(); // LVGL init takes time
  129. #if ENABLED(SDSUPPORT)
  130. UpdateAssets();
  131. watchdog_refresh(); // LVGL init takes time
  132. TERN_(MKS_TEST, mks_test_get());
  133. #endif
  134. touch.Init();
  135. lv_init();
  136. lv_disp_buf_init(&disp_buf, bmp_public_buf, nullptr, LV_HOR_RES_MAX * 14); // Initialize the display buffer
  137. lv_disp_drv_t disp_drv; // Descriptor of a display driver
  138. lv_disp_drv_init(&disp_drv); // Basic initialization
  139. disp_drv.flush_cb = my_disp_flush; // Set your driver function
  140. disp_drv.buffer = &disp_buf; // Assign the buffer to the display
  141. lv_disp_drv_register(&disp_drv); // Finally register the driver
  142. lv_indev_drv_t indev_drv;
  143. lv_indev_drv_init(&indev_drv); // Descriptor of a input device driver
  144. indev_drv.type = LV_INDEV_TYPE_POINTER; // Touch pad is a pointer-like device
  145. indev_drv.read_cb = my_touchpad_read; // Set your driver function
  146. lv_indev_drv_register(&indev_drv); // Finally register the driver
  147. #if HAS_ROTARY_ENCODER
  148. g = lv_group_create();
  149. lv_indev_drv_t enc_drv;
  150. lv_indev_drv_init(&enc_drv);
  151. enc_drv.type = LV_INDEV_TYPE_ENCODER;
  152. enc_drv.read_cb = my_mousewheel_read;
  153. lv_indev_t * enc_indev = lv_indev_drv_register(&enc_drv);
  154. lv_indev_set_group(enc_indev, g);
  155. #endif
  156. lv_fs_drv_t spi_flash_drv;
  157. lv_fs_drv_init(&spi_flash_drv);
  158. spi_flash_drv.letter = 'F';
  159. spi_flash_drv.open_cb = spi_flash_open_cb;
  160. spi_flash_drv.close_cb = spi_flash_close_cb;
  161. spi_flash_drv.read_cb = spi_flash_read_cb;
  162. spi_flash_drv.seek_cb = spi_flash_seek_cb;
  163. spi_flash_drv.tell_cb = spi_flash_tell_cb;
  164. lv_fs_drv_register(&spi_flash_drv);
  165. lv_fs_drv_t sd_drv;
  166. lv_fs_drv_init(&sd_drv);
  167. sd_drv.letter = 'S';
  168. sd_drv.open_cb = sd_open_cb;
  169. sd_drv.close_cb = sd_close_cb;
  170. sd_drv.read_cb = sd_read_cb;
  171. sd_drv.seek_cb = sd_seek_cb;
  172. sd_drv.tell_cb = sd_tell_cb;
  173. lv_fs_drv_register(&sd_drv);
  174. systick_attach_callback(SysTick_Callback);
  175. TERN_(HAS_SPI_FLASH_FONT, init_gb2312_font());
  176. tft_style_init();
  177. filament_pin_setup();
  178. lv_encoder_pin_init();
  179. #if ENABLED(MKS_WIFI_MODULE)
  180. mks_esp_wifi_init();
  181. mks_wifi_firmware_update();
  182. #endif
  183. TERN_(HAS_SERVOS, servo_init());
  184. TERN_(HAS_Z_SERVO_PROBE, probe.servo_probe_init());
  185. bool ready = true;
  186. #if ENABLED(POWER_LOSS_RECOVERY)
  187. recovery.load();
  188. if (recovery.valid()) {
  189. ready = false;
  190. if (gCfgItems.from_flash_pic)
  191. flash_preview_begin = true;
  192. else
  193. default_preview_flg = true;
  194. uiCfg.print_state = REPRINTING;
  195. #if ENABLED(LONG_FILENAME_HOST_SUPPORT)
  196. strncpy(public_buf_m, recovery.info.sd_filename, sizeof(public_buf_m));
  197. card.printLongPath(public_buf_m);
  198. strncpy(list_file.long_name[sel_id], card.longFilename, sizeof(list_file.long_name[0]));
  199. #else
  200. strncpy(list_file.long_name[sel_id], recovery.info.sd_filename, sizeof(list_file.long_name[0]));
  201. #endif
  202. lv_draw_printing();
  203. }
  204. #endif
  205. if (ready) lv_draw_ready_print();
  206. #if BOTH(MKS_TEST, SDSUPPORT)
  207. if (mks_test_flag == 0x1E) mks_gpio_test();
  208. #endif
  209. }
  210. static lv_disp_drv_t* disp_drv_p;
  211. #if ENABLED(USE_SPI_DMA_TC)
  212. bool lcd_dma_trans_lock = false;
  213. #endif
  214. void dmc_tc_handler(struct __DMA_HandleTypeDef * hdma) {
  215. #if ENABLED(USE_SPI_DMA_TC)
  216. lv_disp_flush_ready(disp_drv_p);
  217. lcd_dma_trans_lock = false;
  218. TFT_SPI::Abort();
  219. #endif
  220. }
  221. void my_disp_flush(lv_disp_drv_t * disp, const lv_area_t * area, lv_color_t * color_p) {
  222. uint16_t width = area->x2 - area->x1 + 1,
  223. height = area->y2 - area->y1 + 1;
  224. TERN_(USE_SPI_DMA_TC, disp_drv_p = disp);
  225. SPI_TFT.setWindow((uint16_t)area->x1, (uint16_t)area->y1, width, height);
  226. #if ENABLED(USE_SPI_DMA_TC)
  227. lcd_dma_trans_lock = true;
  228. SPI_TFT.tftio.WriteSequenceIT((uint16_t*)color_p, width * height);
  229. TFT_SPI::DMAtx.XferCpltCallback = dmc_tc_handler;
  230. #else
  231. SPI_TFT.tftio.WriteSequence((uint16_t*)color_p, width * height);
  232. lv_disp_flush_ready(disp_drv_p); // Indicate you are ready with the flushing
  233. #endif
  234. W25QXX.init(SPI_QUARTER_SPEED);
  235. }
  236. #if ENABLED(USE_SPI_DMA_TC)
  237. bool get_lcd_dma_lock() { return lcd_dma_trans_lock; }
  238. #endif
  239. void lv_fill_rect(lv_coord_t x1, lv_coord_t y1, lv_coord_t x2, lv_coord_t y2, lv_color_t bk_color) {
  240. uint16_t width, height;
  241. width = x2 - x1 + 1;
  242. height = y2 - y1 + 1;
  243. SPI_TFT.setWindow((uint16_t)x1, (uint16_t)y1, width, height);
  244. SPI_TFT.tftio.WriteMultiple(bk_color.full, width * height);
  245. W25QXX.init(SPI_QUARTER_SPEED);
  246. }
  247. #define TICK_CYCLE 1
  248. unsigned int getTickDiff(unsigned int curTick, unsigned int lastTick) {
  249. return TICK_CYCLE * (lastTick <= curTick ? (curTick - lastTick) : (0xFFFFFFFF - lastTick + curTick));
  250. }
  251. static bool get_point(int16_t *x, int16_t *y) {
  252. if (!touch.getRawPoint(x, y)) return false;
  253. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  254. const calibrationState state = touch_calibration.get_calibration_state();
  255. if (state >= CALIBRATION_TOP_LEFT && state <= CALIBRATION_BOTTOM_RIGHT) {
  256. if (touch_calibration.handleTouch(*x, *y)) lv_update_touch_calibration_screen();
  257. return false;
  258. }
  259. *x = int16_t((int32_t(*x) * touch_calibration.calibration.x) >> 16) + touch_calibration.calibration.offset_x;
  260. *y = int16_t((int32_t(*y) * touch_calibration.calibration.y) >> 16) + touch_calibration.calibration.offset_y;
  261. #else
  262. *x = int16_t((int32_t(*x) * TOUCH_CALIBRATION_X) >> 16) + TOUCH_OFFSET_X;
  263. *y = int16_t((int32_t(*y) * TOUCH_CALIBRATION_Y) >> 16) + TOUCH_OFFSET_Y;
  264. #endif
  265. return true;
  266. }
  267. bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data) {
  268. static int16_t last_x = 0, last_y = 0;
  269. if (get_point(&last_x, &last_y)) {
  270. #if TFT_ROTATION == TFT_ROTATE_180
  271. data->point.x = TFT_WIDTH - last_x;
  272. data->point.y = TFT_HEIGHT - last_y;
  273. #else
  274. data->point.x = last_x;
  275. data->point.y = last_y;
  276. #endif
  277. data->state = LV_INDEV_STATE_PR;
  278. }
  279. else {
  280. #if TFT_ROTATION == TFT_ROTATE_180
  281. data->point.x = TFT_WIDTH - last_x;
  282. data->point.y = TFT_HEIGHT - last_y;
  283. #else
  284. data->point.x = last_x;
  285. data->point.y = last_y;
  286. #endif
  287. data->state = LV_INDEV_STATE_REL;
  288. }
  289. return false; // Return `false` since no data is buffering or left to read
  290. }
  291. int16_t enc_diff = 0;
  292. lv_indev_state_t state = LV_INDEV_STATE_REL;
  293. bool my_mousewheel_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data) {
  294. (void) indev_drv; // Unused
  295. data->state = state;
  296. data->enc_diff = enc_diff;
  297. enc_diff = 0;
  298. return false; // No more data to read so return false
  299. }
  300. extern uint8_t currentFlashPage;
  301. // spi_flash
  302. uint32_t pic_read_base_addr = 0, pic_read_addr_offset = 0;
  303. lv_fs_res_t spi_flash_open_cb (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode) {
  304. static char last_path_name[30];
  305. if (strcasecmp(last_path_name, path) != 0) {
  306. pic_read_base_addr = lv_get_pic_addr((uint8_t *)path);
  307. strcpy(last_path_name, path);
  308. }
  309. else {
  310. W25QXX.init(SPI_QUARTER_SPEED);
  311. currentFlashPage = 0;
  312. }
  313. pic_read_addr_offset = pic_read_base_addr;
  314. return LV_FS_RES_OK;
  315. }
  316. lv_fs_res_t spi_flash_close_cb (lv_fs_drv_t * drv, void * file_p) {
  317. lv_fs_res_t res = LV_FS_RES_OK;
  318. /* Add your code here */
  319. pic_read_addr_offset = pic_read_base_addr;
  320. return res;
  321. }
  322. lv_fs_res_t spi_flash_read_cb (lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br) {
  323. lv_pic_test((uint8_t *)buf, pic_read_addr_offset, btr);
  324. *br = btr;
  325. return LV_FS_RES_OK;
  326. }
  327. lv_fs_res_t spi_flash_seek_cb(lv_fs_drv_t * drv, void * file_p, uint32_t pos) {
  328. #if HAS_SPI_FLASH_COMPRESSION
  329. if (pos == 4) {
  330. uint8_t bmp_header[4];
  331. SPIFlash.beginRead(pic_read_base_addr);
  332. SPIFlash.readData(bmp_header, 4);
  333. currentFlashPage = 1;
  334. }
  335. pic_read_addr_offset = pic_read_base_addr;
  336. #else
  337. pic_read_addr_offset = pic_read_base_addr + pos;
  338. #endif
  339. return LV_FS_RES_OK;
  340. }
  341. lv_fs_res_t spi_flash_tell_cb(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) {
  342. *pos_p = pic_read_addr_offset - pic_read_base_addr;
  343. return LV_FS_RES_OK;
  344. }
  345. // sd
  346. char *cur_namefff;
  347. uint32_t sd_read_base_addr = 0, sd_read_addr_offset = 0, small_image_size = 409;
  348. lv_fs_res_t sd_open_cb (lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode) {
  349. char name_buf[100];
  350. *name_buf = '/';
  351. strcpy(name_buf + 1, path);
  352. char *temp = strstr(name_buf, ".bin");
  353. if (temp) strcpy(temp, ".GCO");
  354. sd_read_base_addr = lv_open_gcode_file((char *)name_buf);
  355. sd_read_addr_offset = sd_read_base_addr;
  356. if (sd_read_addr_offset == UINT32_MAX) return LV_FS_RES_NOT_EX;
  357. // find small image size
  358. card.read(public_buf, 512);
  359. public_buf[511] = '\0';
  360. const char* eol = strpbrk((const char*)public_buf, "\n\r");
  361. small_image_size = (uintptr_t)eol - (uintptr_t)((uint32_t *)(&public_buf[0])) + 1;
  362. return LV_FS_RES_OK;
  363. }
  364. lv_fs_res_t sd_close_cb (lv_fs_drv_t * drv, void * file_p) {
  365. /* Add your code here */
  366. lv_close_gcode_file();
  367. return LV_FS_RES_OK;
  368. }
  369. lv_fs_res_t sd_read_cb (lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br) {
  370. if (btr == 200) {
  371. lv_gcode_file_read((uint8_t *)buf);
  372. //pic_read_addr_offset += 208;
  373. *br = 200;
  374. }
  375. else if (btr == 4) {
  376. uint8_t header_pic[4] = { 0x04, 0x90, 0x81, 0x0C };
  377. memcpy(buf, header_pic, 4);
  378. *br = 4;
  379. }
  380. return LV_FS_RES_OK;
  381. }
  382. lv_fs_res_t sd_seek_cb(lv_fs_drv_t * drv, void * file_p, uint32_t pos) {
  383. sd_read_addr_offset = sd_read_base_addr + (pos - 4) / 200 * small_image_size;
  384. lv_gcode_file_seek(sd_read_addr_offset);
  385. return LV_FS_RES_OK;
  386. }
  387. lv_fs_res_t sd_tell_cb(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p) {
  388. if (sd_read_addr_offset) *pos_p = 0;
  389. else *pos_p = (sd_read_addr_offset - sd_read_base_addr) / small_image_size * 200 + 4;
  390. return LV_FS_RES_OK;
  391. }
  392. void lv_encoder_pin_init() {
  393. #if BUTTON_EXISTS(EN1)
  394. SET_INPUT_PULLUP(BTN_EN1);
  395. #endif
  396. #if BUTTON_EXISTS(EN2)
  397. SET_INPUT_PULLUP(BTN_EN2);
  398. #endif
  399. #if BUTTON_EXISTS(ENC)
  400. SET_INPUT_PULLUP(BTN_ENC);
  401. #endif
  402. #if BUTTON_EXISTS(BACK)
  403. SET_INPUT_PULLUP(BTN_BACK);
  404. #endif
  405. #if BUTTON_EXISTS(UP)
  406. SET_INPUT(BTN_UP);
  407. #endif
  408. #if BUTTON_EXISTS(DWN)
  409. SET_INPUT(BTN_DWN);
  410. #endif
  411. #if BUTTON_EXISTS(LFT)
  412. SET_INPUT(BTN_LFT);
  413. #endif
  414. #if BUTTON_EXISTS(RT)
  415. SET_INPUT(BTN_RT);
  416. #endif
  417. }
  418. #if 1 // HAS_ENCODER_ACTION
  419. void lv_update_encoder() {
  420. static uint32_t encoder_time1;
  421. uint32_t tmpTime, diffTime = 0;
  422. tmpTime = millis();
  423. diffTime = getTickDiff(tmpTime, encoder_time1);
  424. if (diffTime > 50) {
  425. #if HAS_ENCODER_WHEEL
  426. #if ANY_BUTTON(EN1, EN2, ENC, BACK)
  427. uint8_t newbutton = 0;
  428. if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
  429. if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
  430. if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
  431. if (BUTTON_PRESSED(BACK)) newbutton |= EN_D;
  432. #else
  433. constexpr uint8_t newbutton = 0;
  434. #endif
  435. static uint8_t buttons = 0;
  436. buttons = newbutton;
  437. static uint8_t lastEncoderBits;
  438. #define encrot0 0
  439. #define encrot1 1
  440. #define encrot2 2
  441. uint8_t enc = 0;
  442. if (buttons & EN_A) enc |= B01;
  443. if (buttons & EN_B) enc |= B10;
  444. if (enc != lastEncoderBits) {
  445. switch (enc) {
  446. case encrot1:
  447. if (lastEncoderBits == encrot0) {
  448. enc_diff--;
  449. encoder_time1 = tmpTime;
  450. }
  451. break;
  452. case encrot2:
  453. if (lastEncoderBits == encrot0) {
  454. enc_diff++;
  455. encoder_time1 = tmpTime;
  456. }
  457. break;
  458. }
  459. lastEncoderBits = enc;
  460. }
  461. static uint8_t last_button_state = LV_INDEV_STATE_REL;
  462. const uint8_t enc_c = (buttons & EN_C) ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
  463. if (enc_c != last_button_state) {
  464. state = enc_c ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
  465. last_button_state = enc_c;
  466. }
  467. #endif // HAS_ENCODER_WHEEL
  468. } // next_button_update_ms
  469. }
  470. #endif // HAS_ENCODER_ACTION
  471. #if __PLAT_NATIVE_SIM__
  472. #include <lv_misc/lv_log.h>
  473. typedef void (*lv_log_print_g_cb_t)(lv_log_level_t level, const char *, uint32_t, const char *);
  474. extern "C" void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb) {}
  475. #endif
  476. #endif // HAS_TFT_LVGL_UI