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.

pic_manager.cpp 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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 "string.h"
  25. #include "draw_ui.h"
  26. #include "pic_manager.h"
  27. #include "draw_ready_print.h"
  28. #include "mks_hardware_test.h"
  29. #include "SPIFlashStorage.h"
  30. #include "../../../../libs/W25Qxx.h"
  31. #include "../../../../sd/cardreader.h"
  32. #include "../../../../MarlinCore.h"
  33. extern uint16_t DeviceCode;
  34. #if ENABLED(SDSUPPORT)
  35. extern char *createFilename(char * const buffer, const dir_t &p);
  36. #endif
  37. static const char assets[][LONG_FILENAME_LENGTH] = {
  38. // Homing screen
  39. "bmp_zeroAll.bin",
  40. "bmp_zero.bin",
  41. "bmp_zeroX.bin",
  42. "bmp_zeroY.bin",
  43. "bmp_zeroZ.bin",
  44. "bmp_manual_off.bin",
  45. // Tool screen
  46. "bmp_preHeat.bin",
  47. "bmp_extruct.bin",
  48. "bmp_mov.bin",
  49. "bmp_leveling.bin",
  50. "bmp_filamentchange.bin",
  51. "bmp_more.bin",
  52. // Fan screen
  53. "bmp_Add.bin",
  54. "bmp_Dec.bin",
  55. "bmp_speed255.bin",
  56. "bmp_speed127.bin",
  57. "bmp_speed0.bin",
  58. "bmp_bed.bin",
  59. "bmp_step1_degree.bin",
  60. "bmp_step5_degree.bin",
  61. "bmp_step10_degree.bin",
  62. // Extrusion screen
  63. "bmp_in.bin",
  64. "bmp_out.bin",
  65. "bmp_extru1.bin",
  66. #if HAS_MULTI_EXTRUDER
  67. "bmp_extru2.bin",
  68. #endif
  69. "bmp_speed_high.bin",
  70. "bmp_speed_slow.bin",
  71. "bmp_speed_normal.bin",
  72. "bmp_step1_mm.bin",
  73. "bmp_step5_mm.bin",
  74. "bmp_step10_mm.bin",
  75. // Select file screen
  76. "bmp_pageUp.bin",
  77. "bmp_pageDown.bin",
  78. "bmp_back.bin", //TODO: why two back buttons? Why not just one? (return / back)
  79. "bmp_dir.bin",
  80. "bmp_file.bin",
  81. // Move motor screen
  82. // TODO: 6 equal icons, just in diffenct rotation... it may be optimized too
  83. "bmp_xAdd.bin",
  84. "bmp_xDec.bin",
  85. "bmp_yAdd.bin",
  86. "bmp_yDec.bin",
  87. "bmp_zAdd.bin",
  88. "bmp_zDec.bin",
  89. "bmp_step_move0_1.bin",
  90. "bmp_step_move1.bin",
  91. "bmp_step_move10.bin",
  92. // Operation screen
  93. "bmp_auto_off.bin",
  94. "bmp_speed.bin",
  95. "bmp_fan.bin",
  96. "bmp_temp.bin",
  97. "bmp_extrude_opr.bin",
  98. "bmp_move_opr.bin",
  99. // Change speed screen
  100. "bmp_step1_percent.bin",
  101. "bmp_step5_percent.bin",
  102. "bmp_step10_percent.bin",
  103. "bmp_extruct_sel.bin",
  104. "bmp_mov_changespeed.bin",
  105. "bmp_mov_sel.bin",
  106. "bmp_speed_extruct.bin",
  107. // Printing screen
  108. "bmp_pause.bin",
  109. "bmp_resume.bin",
  110. "bmp_stop.bin",
  111. "bmp_ext1_state.bin",
  112. #if HAS_MULTI_EXTRUDER
  113. "bmp_ext2_state.bin",
  114. #endif
  115. "bmp_bed_state.bin",
  116. "bmp_fan_state.bin",
  117. "bmp_time_state.bin",
  118. "bmp_zpos_state.bin",
  119. "bmp_operate.bin",
  120. // Manual Level screen (only if auto level is disabled)
  121. #if DISABLED(AUTO_BED_LEVELING_BILINEAR)
  122. "bmp_leveling1.bin",
  123. "bmp_leveling2.bin",
  124. "bmp_leveling3.bin",
  125. "bmp_leveling4.bin",
  126. "bmp_leveling5.bin",
  127. #endif
  128. // Language Select screen
  129. #if HAS_LANG_SELECT_SCREEN
  130. "bmp_language.bin",
  131. "bmp_simplified_cn.bin",
  132. "bmp_simplified_cn_sel.bin",
  133. "bmp_traditional_cn.bin",
  134. "bmp_traditional_cn_sel.bin",
  135. "bmp_english.bin",
  136. "bmp_english_sel.bin",
  137. "bmp_russian.bin",
  138. "bmp_russian_sel.bin",
  139. "bmp_spanish.bin",
  140. "bmp_spanish_sel.bin",
  141. "bmp_french.bin",
  142. "bmp_french_sel.bin",
  143. "bmp_italy.bin",
  144. "bmp_italy_sel.bin",
  145. #endif // HAS_LANG_SELECT_SCREEN
  146. // G-code preview
  147. #if HAS_GCODE_DEFAULT_VIEW_IN_FLASH
  148. "bmp_preview.bin",
  149. #endif
  150. #if HAS_LOGO_IN_FLASH
  151. "bmp_logo.bin",
  152. #endif
  153. // Settings screen
  154. "bmp_about.bin",
  155. "bmp_eeprom_settings.bin",
  156. "bmp_machine_para.bin",
  157. "bmp_function1.bin",
  158. // Start screen
  159. "bmp_printing.bin",
  160. "bmp_set.bin",
  161. "bmp_tool.bin",
  162. // Base icons
  163. "bmp_arrow.bin",
  164. "bmp_back70x40.bin",
  165. "bmp_value_blank.bin",
  166. "bmp_blank_sel.bin",
  167. "bmp_disable.bin",
  168. "bmp_enable.bin",
  169. "bmp_return.bin",
  170. #if ENABLED(MKS_WIFI_MODULE)
  171. // Wifi screen
  172. "bmp_wifi.bin",
  173. "bmp_cloud.bin",
  174. #endif
  175. // Babystep screen
  176. "bmp_baby_move0_01.bin",
  177. "bmp_baby_move0_05.bin",
  178. "bmp_baby_move0_1.bin",
  179. // More screen
  180. "bmp_custom1.bin",
  181. "bmp_custom2.bin",
  182. "bmp_custom3.bin",
  183. "bmp_custom4.bin",
  184. "bmp_custom5.bin",
  185. "bmp_custom6.bin",
  186. "bmp_custom7.bin"
  187. };
  188. #if HAS_SPI_FLASH_FONT
  189. static char fonts[][LONG_FILENAME_LENGTH] = { "FontUNIGBK.bin" };
  190. #endif
  191. uint8_t currentFlashPage = 0;
  192. uint32_t lv_get_pic_addr(uint8_t *Pname) {
  193. uint8_t Pic_cnt;
  194. uint8_t i, j;
  195. PIC_MSG PIC;
  196. uint32_t tmp_cnt = 0;
  197. uint32_t addr = 0;
  198. currentFlashPage = 0;
  199. #if ENABLED(MARLIN_DEV_MODE)
  200. SERIAL_ECHOLNPAIR("Getting picture SPI Flash Address: ", (const char*)Pname);
  201. #endif
  202. W25QXX.init(SPI_QUARTER_SPEED);
  203. W25QXX.SPI_FLASH_BufferRead(&Pic_cnt, PIC_COUNTER_ADDR, 1);
  204. if (Pic_cnt == 0xFF) Pic_cnt = 0;
  205. for (i = 0; i < Pic_cnt; i++) {
  206. j = 0;
  207. do {
  208. W25QXX.SPI_FLASH_BufferRead(&PIC.name[j], PIC_NAME_ADDR + tmp_cnt, 1);
  209. tmp_cnt++;
  210. } while (PIC.name[j++] != '\0');
  211. if ((strcasecmp((char*)Pname, (char*)PIC.name)) == 0) {
  212. if (DeviceCode == 0x9488 || DeviceCode == 0x5761)
  213. addr = PIC_DATA_ADDR_TFT35 + i * PER_PIC_MAX_SPACE_TFT35;
  214. else
  215. addr = PIC_DATA_ADDR_TFT32 + i * PER_PIC_MAX_SPACE_TFT32;
  216. return addr;
  217. }
  218. }
  219. return addr;
  220. }
  221. const char *assetsPath = "assets";
  222. const char *bakPath = "_assets";
  223. void spiFlashErase_PIC() {
  224. volatile uint32_t pic_sectorcnt = 0;
  225. W25QXX.init(SPI_QUARTER_SPEED);
  226. //erase 0x001000 -64K
  227. for (pic_sectorcnt = 0; pic_sectorcnt < (64 - 4) / 4; pic_sectorcnt++) {
  228. watchdog_refresh();
  229. W25QXX.SPI_FLASH_SectorErase(PICINFOADDR + pic_sectorcnt * 4 * 1024);
  230. }
  231. //erase 64K -- 6M
  232. for (pic_sectorcnt = 0; pic_sectorcnt < (PIC_SIZE_xM * 1024 / 64 - 1); pic_sectorcnt++) {
  233. watchdog_refresh();
  234. W25QXX.SPI_FLASH_BlockErase((pic_sectorcnt + 1) * 64 * 1024);
  235. }
  236. }
  237. #if HAS_SPI_FLASH_FONT
  238. void spiFlashErase_FONT() {
  239. volatile uint32_t Font_sectorcnt = 0;
  240. W25QXX.init(SPI_QUARTER_SPEED);
  241. for (Font_sectorcnt = 0; Font_sectorcnt < 32-1; Font_sectorcnt++) {
  242. watchdog_refresh();
  243. W25QXX.SPI_FLASH_BlockErase(FONTINFOADDR + Font_sectorcnt * 64 * 1024);
  244. }
  245. }
  246. #endif
  247. uint32_t LogoWrite_Addroffset = 0;
  248. uint8_t Pic_Logo_Write(uint8_t *LogoName, uint8_t *Logo_Wbuff, uint32_t LogoWriteSize) {
  249. if (LogoWriteSize <= 0) return 0;
  250. W25QXX.SPI_FLASH_BufferWrite(Logo_Wbuff, PIC_LOGO_ADDR + LogoWrite_Addroffset, LogoWriteSize);
  251. for (uint32_t i = 0; i < LogoWriteSize; i++) {
  252. uint8_t temp1;
  253. W25QXX.SPI_FLASH_BufferRead(&temp1, PIC_LOGO_ADDR + LogoWrite_Addroffset + i, 1);
  254. if (*(Logo_Wbuff + i) != temp1) return 0;
  255. }
  256. LogoWrite_Addroffset += LogoWriteSize;
  257. const uint32_t logo_maxsize = DeviceCode == 0x9488 || DeviceCode == 0x5761 ? LOGO_MAX_SIZE_TFT35 : LOGO_MAX_SIZE_TFT32;
  258. if (LogoWrite_Addroffset >= logo_maxsize) LogoWrite_Addroffset = 0;
  259. return 1;
  260. }
  261. uint32_t TitleLogoWrite_Addroffset = 0;
  262. uint8_t Pic_TitleLogo_Write(uint8_t *TitleLogoName, uint8_t *TitleLogo_Wbuff, uint32_t TitleLogoWriteSize) {
  263. if (TitleLogoWriteSize <= 0)
  264. return 0;
  265. if ((DeviceCode == 0x9488) || (DeviceCode == 0x5761))
  266. W25QXX.SPI_FLASH_BufferWrite(TitleLogo_Wbuff, PIC_ICON_LOGO_ADDR_TFT35 + TitleLogoWrite_Addroffset, TitleLogoWriteSize);
  267. else
  268. W25QXX.SPI_FLASH_BufferWrite(TitleLogo_Wbuff, PIC_ICON_LOGO_ADDR_TFT32 + TitleLogoWrite_Addroffset, TitleLogoWriteSize);
  269. TitleLogoWrite_Addroffset += TitleLogoWriteSize;
  270. if (TitleLogoWrite_Addroffset >= TITLELOGO_MAX_SIZE)
  271. TitleLogoWrite_Addroffset = 0;
  272. return 1;
  273. }
  274. uint32_t default_view_addroffset_r = 0;
  275. void default_view_Write(uint8_t *default_view__Rbuff, uint32_t default_view_Writesize) {
  276. W25QXX.SPI_FLASH_BufferWrite(default_view__Rbuff, DEFAULT_VIEW_ADDR_TFT35 + default_view_addroffset_r, default_view_Writesize);
  277. default_view_addroffset_r += default_view_Writesize;
  278. if (default_view_addroffset_r >= DEFAULT_VIEW_MAX_SIZE)
  279. default_view_addroffset_r = 0;
  280. }
  281. uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
  282. uint8_t pic_counter = 0;
  283. uint32_t Pic_SaveAddr;
  284. uint32_t Pic_SizeSaveAddr;
  285. uint32_t Pic_NameSaveAddr;
  286. uint8_t Pname_temp;
  287. uint32_t i, j;
  288. uint32_t name_len = 0;
  289. uint32_t SaveName_len = 0;
  290. union union32 size_tmp;
  291. W25QXX.SPI_FLASH_BufferRead(&pic_counter, PIC_COUNTER_ADDR, 1);
  292. if (pic_counter == 0xFF)
  293. pic_counter = 0;
  294. if ((DeviceCode == 0x9488) || (DeviceCode == 0x5761))
  295. Pic_SaveAddr = PIC_DATA_ADDR_TFT35 + pic_counter * PER_PIC_MAX_SPACE_TFT35;
  296. else
  297. Pic_SaveAddr = PIC_DATA_ADDR_TFT32 + pic_counter * PER_PIC_MAX_SPACE_TFT32;
  298. for (j = 0; j < pic_counter; j++) {
  299. do {
  300. W25QXX.SPI_FLASH_BufferRead(&Pname_temp, PIC_NAME_ADDR + SaveName_len, 1);
  301. SaveName_len++;
  302. } while (Pname_temp != '\0');
  303. }
  304. i = 0;
  305. while ((*(P_name + i) != '\0')) {
  306. i++;
  307. name_len++;
  308. }
  309. Pic_NameSaveAddr = PIC_NAME_ADDR + SaveName_len;
  310. W25QXX.SPI_FLASH_BufferWrite(P_name, Pic_NameSaveAddr, name_len + 1);
  311. Pic_SizeSaveAddr = PIC_SIZE_ADDR + 4 * pic_counter;
  312. size_tmp.dwords = P_size;
  313. W25QXX.SPI_FLASH_BufferWrite(size_tmp.bytes, Pic_SizeSaveAddr, 4);
  314. pic_counter++;
  315. W25QXX.SPI_FLASH_SectorErase(PIC_COUNTER_ADDR);
  316. W25QXX.SPI_FLASH_BufferWrite(&pic_counter, PIC_COUNTER_ADDR, 1);
  317. return Pic_SaveAddr;
  318. }
  319. #if ENABLED(SDSUPPORT)
  320. static void dosName2LongName(const char dosName[11], char* longName) {
  321. uint8_t j = 0;
  322. LOOP_L_N(i, 11) {
  323. if (i == 8) longName[j++] = '.';
  324. if (dosName[i] == '\0' || dosName[i] == ' ') continue;
  325. longName[j++] = dosName[i];
  326. }
  327. longName[j] = '\0';
  328. }
  329. static int8_t arrayFindStr(const char arr[][LONG_FILENAME_LENGTH], uint8_t arraySize, const char* str) {
  330. for (uint8_t a = 0; a < arraySize; a++) {
  331. if (strcasecmp(arr[a], str) == 0)
  332. return a;
  333. }
  334. return -1;
  335. }
  336. #if ENABLED(MARLIN_DEV_MODE)
  337. static uint32_t totalSizes = 0, totalCompressed = 0;
  338. #endif
  339. #define ASSET_TYPE_ICON 0
  340. #define ASSET_TYPE_LOGO 1
  341. #define ASSET_TYPE_TITLE_LOGO 2
  342. #define ASSET_TYPE_G_PREVIEW 3
  343. #define ASSET_TYPE_FONT 4
  344. static void loadAsset(SdFile &dir, dir_t& entry, const char *fn, int8_t assetType) {
  345. SdFile file;
  346. char dosFilename[FILENAME_LENGTH];
  347. createFilename(dosFilename, entry);
  348. if (!file.open(&dir, dosFilename, O_READ)) {
  349. #if ENABLED(MARLIN_DEV_MODE)
  350. SERIAL_ECHOLNPAIR("Error opening Asset: ", fn);
  351. #endif
  352. return;
  353. }
  354. watchdog_refresh();
  355. disp_assets_update_progress(fn);
  356. W25QXX.init(SPI_QUARTER_SPEED);
  357. uint16_t pbr;
  358. uint32_t pfileSize;
  359. uint32_t totalSizeLoaded = 0;
  360. uint32_t Pic_Write_Addr;
  361. pfileSize = file.fileSize();
  362. totalSizeLoaded += pfileSize;
  363. if (assetType == ASSET_TYPE_LOGO) {
  364. do {
  365. watchdog_refresh();
  366. pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
  367. Pic_Logo_Write((uint8_t *)fn, public_buf, pbr);
  368. } while (pbr >= BMP_WRITE_BUF_LEN);
  369. }
  370. else if (assetType == ASSET_TYPE_TITLE_LOGO) {
  371. do {
  372. watchdog_refresh();
  373. pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
  374. Pic_TitleLogo_Write((uint8_t *)fn, public_buf, pbr);
  375. } while (pbr >= BMP_WRITE_BUF_LEN);
  376. }
  377. else if (assetType == ASSET_TYPE_G_PREVIEW) {
  378. do {
  379. watchdog_refresh();
  380. pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
  381. default_view_Write(public_buf, pbr);
  382. } while (pbr >= BMP_WRITE_BUF_LEN);
  383. }
  384. else if (assetType == ASSET_TYPE_ICON) {
  385. Pic_Write_Addr = Pic_Info_Write((uint8_t *)fn, pfileSize);
  386. SPIFlash.beginWrite(Pic_Write_Addr);
  387. #if HAS_SPI_FLASH_COMPRESSION
  388. do {
  389. watchdog_refresh();
  390. pbr = file.read(public_buf, SPI_FLASH_PageSize);
  391. TERN_(MARLIN_DEV_MODE, totalSizes += pbr);
  392. SPIFlash.writeData(public_buf, SPI_FLASH_PageSize);
  393. } while (pbr >= SPI_FLASH_PageSize);
  394. #else
  395. do {
  396. pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
  397. W25QXX.SPI_FLASH_BufferWrite(public_buf, Pic_Write_Addr, pbr);
  398. Pic_Write_Addr += pbr;
  399. } while (pbr >= BMP_WRITE_BUF_LEN);
  400. #endif
  401. #if ENABLED(MARLIN_DEV_MODE)
  402. SERIAL_ECHOLNPAIR("Space used: ", fn, " - ", (SPIFlash.getCurrentPage() + 1) * SPI_FLASH_PageSize / 1024, "KB");
  403. totalCompressed += (SPIFlash.getCurrentPage() + 1) * SPI_FLASH_PageSize;
  404. #endif
  405. SPIFlash.endWrite();
  406. }
  407. else if (assetType == ASSET_TYPE_FONT) {
  408. Pic_Write_Addr = UNIGBK_FLASH_ADDR;
  409. do {
  410. watchdog_refresh();
  411. pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
  412. W25QXX.SPI_FLASH_BufferWrite(public_buf, Pic_Write_Addr, pbr);
  413. Pic_Write_Addr += pbr;
  414. } while (pbr >= BMP_WRITE_BUF_LEN);
  415. }
  416. file.close();
  417. #if ENABLED(MARLIN_DEV_MODE)
  418. SERIAL_ECHOLNPAIR("Asset added: ", fn);
  419. #endif
  420. }
  421. void UpdateAssets() {
  422. if (!card.isMounted()) return;
  423. SdFile dir, root = card.getroot();
  424. if (dir.open(&root, assetsPath, O_RDONLY)) {
  425. disp_assets_update();
  426. disp_assets_update_progress("Erasing pics...");
  427. watchdog_refresh();
  428. spiFlashErase_PIC();
  429. #if HAS_SPI_FLASH_FONT
  430. disp_assets_update_progress("Erasing fonts...");
  431. watchdog_refresh();
  432. spiFlashErase_FONT();
  433. #endif
  434. disp_assets_update_progress("Reading files...");
  435. dir_t d;
  436. while (dir.readDir(&d, card.longFilename) > 0) {
  437. // If we dont get a long name, but gets a short one, try it
  438. if (card.longFilename[0] == 0 && d.name[0] != 0)
  439. dosName2LongName((const char*)d.name, card.longFilename);
  440. if (card.longFilename[0] == 0) continue;
  441. if (card.longFilename[0] == '.') continue;
  442. int8_t a = arrayFindStr(assets, COUNT(assets), card.longFilename);
  443. if (a >= 0 && a < (int8_t)COUNT(assets)) {
  444. uint8_t assetType = ASSET_TYPE_ICON;
  445. if (strstr(assets[a], "_logo"))
  446. assetType = ASSET_TYPE_LOGO;
  447. else if (strstr(assets[a], "_titlelogo"))
  448. assetType = ASSET_TYPE_TITLE_LOGO;
  449. else if (strstr(assets[a], "_preview"))
  450. assetType = ASSET_TYPE_G_PREVIEW;
  451. loadAsset(dir, d, assets[a], assetType);
  452. continue;
  453. }
  454. #if HAS_SPI_FLASH_FONT
  455. a = arrayFindStr(fonts, COUNT(fonts), card.longFilename);
  456. if (a >= 0 && a < (int8_t)COUNT(fonts))
  457. loadAsset(dir, d, fonts[a], ASSET_TYPE_FONT);
  458. #endif
  459. }
  460. dir.rename(&root, bakPath);
  461. }
  462. dir.close();
  463. #if ENABLED(MARLIN_DEV_MODE)
  464. uint8_t pic_counter = 0;
  465. W25QXX.SPI_FLASH_BufferRead(&pic_counter, PIC_COUNTER_ADDR, 1);
  466. SERIAL_ECHOLNPAIR("Total assets loaded: ", pic_counter);
  467. SERIAL_ECHOLNPAIR("Total Uncompressed: ", totalSizes, ", Compressed: ", totalCompressed);
  468. #endif
  469. }
  470. #if HAS_SPI_FLASH_FONT
  471. void spi_flash_read_test() { W25QXX.SPI_FLASH_BufferRead(public_buf, UNIGBK_FLASH_ADDR, BMP_WRITE_BUF_LEN); }
  472. #endif
  473. #endif // SDSUPPORT
  474. void Pic_Read(uint8_t *Pname, uint8_t *P_Rbuff) {
  475. uint8_t i, j;
  476. uint8_t Pic_cnt;
  477. uint32_t tmp_cnt = 0;
  478. PIC_MSG PIC;
  479. W25QXX.SPI_FLASH_BufferRead(&Pic_cnt, PIC_COUNTER_ADDR, 1);
  480. if (Pic_cnt == 0xFF)
  481. Pic_cnt = 0;
  482. for (i = 0; i < Pic_cnt; i++) {
  483. j = 0;
  484. do {
  485. W25QXX.SPI_FLASH_BufferRead(&PIC.name[j], PIC_NAME_ADDR + tmp_cnt, 1);
  486. tmp_cnt++;
  487. } while (PIC.name[j++] != '\0');
  488. //pic size
  489. W25QXX.SPI_FLASH_BufferRead(PIC.size.bytes, PIC_SIZE_ADDR + i * 4, 4);
  490. if ((strcmp((char*)Pname, (char*)PIC.name)) == 0) {
  491. W25QXX.SPI_FLASH_BufferRead((uint8_t *)P_Rbuff, PIC_DATA_ADDR_TFT35 + i * PER_PIC_MAX_SPACE_TFT35, PIC.size.dwords);
  492. break;
  493. }
  494. }
  495. }
  496. void lv_pic_test(uint8_t *P_Rbuff, uint32_t addr, uint32_t size) {
  497. #if HAS_SPI_FLASH_COMPRESSION
  498. if (currentFlashPage == 0)
  499. SPIFlash.beginRead(addr);
  500. SPIFlash.readData(P_Rbuff, size);
  501. currentFlashPage++;
  502. #else
  503. W25QXX.init(SPI_QUARTER_SPEED);
  504. W25QXX.SPI_FLASH_BufferRead((uint8_t *)P_Rbuff, addr, size);
  505. #endif
  506. }
  507. #if HAS_SPI_FLASH_FONT
  508. void get_spi_flash_data(const char *rec_buf, int addr, int size) {
  509. W25QXX.init(SPI_QUARTER_SPEED);
  510. W25QXX.SPI_FLASH_BufferRead((uint8_t *)rec_buf, UNIGBK_FLASH_ADDR + addr, size);
  511. }
  512. #endif
  513. uint32_t logo_addroffset = 0;
  514. void Pic_Logo_Read(uint8_t *LogoName, uint8_t *Logo_Rbuff, uint32_t LogoReadsize) {
  515. W25QXX.init(SPI_QUARTER_SPEED);
  516. W25QXX.SPI_FLASH_BufferRead(Logo_Rbuff, PIC_LOGO_ADDR + logo_addroffset, LogoReadsize);
  517. logo_addroffset += LogoReadsize;
  518. if (logo_addroffset >= LOGO_MAX_SIZE_TFT35)
  519. logo_addroffset = 0;
  520. }
  521. uint32_t default_view_addroffset = 0;
  522. void default_view_Read(uint8_t *default_view_Rbuff, uint32_t default_view_Readsize) {
  523. W25QXX.init(SPI_QUARTER_SPEED);
  524. W25QXX.SPI_FLASH_BufferRead(default_view_Rbuff, DEFAULT_VIEW_ADDR_TFT35 + default_view_addroffset, default_view_Readsize);
  525. default_view_addroffset += default_view_Readsize;
  526. if (default_view_addroffset >= DEFAULT_VIEW_MAX_SIZE)
  527. default_view_addroffset = 0;
  528. }
  529. #if HAS_BAK_VIEW_IN_FLASH
  530. uint32_t flash_view_addroffset = 0;
  531. void flash_view_Read(uint8_t *flash_view_Rbuff, uint32_t flash_view_Readsize) {
  532. W25QXX.init(SPI_QUARTER_SPEED);
  533. W25QXX.SPI_FLASH_BufferRead(flash_view_Rbuff, BAK_VIEW_ADDR_TFT35 + flash_view_addroffset, flash_view_Readsize);
  534. flash_view_addroffset += flash_view_Readsize;
  535. if (flash_view_addroffset >= FLASH_VIEW_MAX_SIZE)
  536. flash_view_addroffset = 0;
  537. }
  538. #endif
  539. #endif // HAS_TFT_LVGL_UI