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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  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.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. #if ENABLED(MULTI_VOLUME)
  176. "bmp_usb_disk.bin",
  177. // "bmp_usb_disk_sel.bin",
  178. "bmp_sd.bin",
  179. // "bmp_sd_sel.bin",
  180. #endif
  181. // Babystep screen
  182. "bmp_baby_move0_01.bin",
  183. "bmp_baby_move0_05.bin",
  184. "bmp_baby_move0_1.bin",
  185. // More screen
  186. "bmp_custom1.bin",
  187. "bmp_custom2.bin",
  188. "bmp_custom3.bin",
  189. "bmp_custom4.bin",
  190. "bmp_custom5.bin",
  191. "bmp_custom6.bin",
  192. "bmp_custom7.bin"
  193. };
  194. #if HAS_SPI_FLASH_FONT
  195. static char fonts[][LONG_FILENAME_LENGTH] = { "FontUNIGBK.bin" };
  196. #endif
  197. uint8_t currentFlashPage = 0;
  198. uint32_t lv_get_pic_addr(uint8_t *Pname) {
  199. uint8_t Pic_cnt;
  200. uint8_t i, j;
  201. PIC_MSG PIC;
  202. uint32_t tmp_cnt = 0;
  203. uint32_t addr = 0;
  204. currentFlashPage = 0;
  205. #if ENABLED(MARLIN_DEV_MODE)
  206. SERIAL_ECHOLNPAIR("Getting picture SPI Flash Address: ", (const char*)Pname);
  207. #endif
  208. W25QXX.init(SPI_QUARTER_SPEED);
  209. W25QXX.SPI_FLASH_BufferRead(&Pic_cnt, PIC_COUNTER_ADDR, 1);
  210. if (Pic_cnt == 0xFF) Pic_cnt = 0;
  211. for (i = 0; i < Pic_cnt; i++) {
  212. j = 0;
  213. do {
  214. W25QXX.SPI_FLASH_BufferRead(&PIC.name[j], PIC_NAME_ADDR + tmp_cnt, 1);
  215. tmp_cnt++;
  216. } while (PIC.name[j++] != '\0');
  217. if ((strcasecmp((char*)Pname, (char*)PIC.name)) == 0) {
  218. if (DeviceCode == 0x9488 || DeviceCode == 0x5761)
  219. addr = PIC_DATA_ADDR_TFT35 + i * PER_PIC_MAX_SPACE_TFT35;
  220. else
  221. addr = PIC_DATA_ADDR_TFT32 + i * PER_PIC_MAX_SPACE_TFT32;
  222. return addr;
  223. }
  224. }
  225. return addr;
  226. }
  227. const char *assetsPath = "assets";
  228. const char *bakPath = "_assets";
  229. void spiFlashErase_PIC() {
  230. volatile uint32_t pic_sectorcnt = 0;
  231. W25QXX.init(SPI_QUARTER_SPEED);
  232. //erase 0x001000 -64K
  233. for (pic_sectorcnt = 0; pic_sectorcnt < (64 - 4) / 4; pic_sectorcnt++) {
  234. watchdog_refresh();
  235. W25QXX.SPI_FLASH_SectorErase(PICINFOADDR + pic_sectorcnt * 4 * 1024);
  236. }
  237. //erase 64K -- 6M
  238. for (pic_sectorcnt = 0; pic_sectorcnt < (PIC_SIZE_xM * 1024 / 64 - 1); pic_sectorcnt++) {
  239. watchdog_refresh();
  240. W25QXX.SPI_FLASH_BlockErase((pic_sectorcnt + 1) * 64 * 1024);
  241. }
  242. }
  243. #if HAS_SPI_FLASH_FONT
  244. void spiFlashErase_FONT() {
  245. volatile uint32_t Font_sectorcnt = 0;
  246. W25QXX.init(SPI_QUARTER_SPEED);
  247. for (Font_sectorcnt = 0; Font_sectorcnt < 32-1; Font_sectorcnt++) {
  248. watchdog_refresh();
  249. W25QXX.SPI_FLASH_BlockErase(FONTINFOADDR + Font_sectorcnt * 64 * 1024);
  250. }
  251. }
  252. #endif
  253. uint32_t LogoWrite_Addroffset = 0;
  254. uint8_t Pic_Logo_Write(uint8_t *LogoName, uint8_t *Logo_Wbuff, uint32_t LogoWriteSize) {
  255. if (LogoWriteSize <= 0) return 0;
  256. W25QXX.SPI_FLASH_BufferWrite(Logo_Wbuff, PIC_LOGO_ADDR + LogoWrite_Addroffset, LogoWriteSize);
  257. for (uint32_t i = 0; i < LogoWriteSize; i++) {
  258. uint8_t temp1;
  259. W25QXX.SPI_FLASH_BufferRead(&temp1, PIC_LOGO_ADDR + LogoWrite_Addroffset + i, 1);
  260. if (*(Logo_Wbuff + i) != temp1) return 0;
  261. }
  262. LogoWrite_Addroffset += LogoWriteSize;
  263. const uint32_t logo_maxsize = DeviceCode == 0x9488 || DeviceCode == 0x5761 ? LOGO_MAX_SIZE_TFT35 : LOGO_MAX_SIZE_TFT32;
  264. if (LogoWrite_Addroffset >= logo_maxsize) LogoWrite_Addroffset = 0;
  265. return 1;
  266. }
  267. uint32_t TitleLogoWrite_Addroffset = 0;
  268. uint8_t Pic_TitleLogo_Write(uint8_t *TitleLogoName, uint8_t *TitleLogo_Wbuff, uint32_t TitleLogoWriteSize) {
  269. if (TitleLogoWriteSize <= 0)
  270. return 0;
  271. if ((DeviceCode == 0x9488) || (DeviceCode == 0x5761))
  272. W25QXX.SPI_FLASH_BufferWrite(TitleLogo_Wbuff, PIC_ICON_LOGO_ADDR_TFT35 + TitleLogoWrite_Addroffset, TitleLogoWriteSize);
  273. else
  274. W25QXX.SPI_FLASH_BufferWrite(TitleLogo_Wbuff, PIC_ICON_LOGO_ADDR_TFT32 + TitleLogoWrite_Addroffset, TitleLogoWriteSize);
  275. TitleLogoWrite_Addroffset += TitleLogoWriteSize;
  276. if (TitleLogoWrite_Addroffset >= TITLELOGO_MAX_SIZE)
  277. TitleLogoWrite_Addroffset = 0;
  278. return 1;
  279. }
  280. uint32_t default_view_addroffset_r = 0;
  281. void default_view_Write(uint8_t *default_view__Rbuff, uint32_t default_view_Writesize) {
  282. W25QXX.SPI_FLASH_BufferWrite(default_view__Rbuff, DEFAULT_VIEW_ADDR_TFT35 + default_view_addroffset_r, default_view_Writesize);
  283. default_view_addroffset_r += default_view_Writesize;
  284. if (default_view_addroffset_r >= DEFAULT_VIEW_MAX_SIZE)
  285. default_view_addroffset_r = 0;
  286. }
  287. uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) {
  288. uint8_t pic_counter = 0;
  289. uint32_t Pic_SaveAddr;
  290. uint32_t Pic_SizeSaveAddr;
  291. uint32_t Pic_NameSaveAddr;
  292. uint8_t Pname_temp;
  293. uint32_t i, j;
  294. uint32_t name_len = 0;
  295. uint32_t SaveName_len = 0;
  296. union union32 size_tmp;
  297. W25QXX.SPI_FLASH_BufferRead(&pic_counter, PIC_COUNTER_ADDR, 1);
  298. if (pic_counter == 0xFF)
  299. pic_counter = 0;
  300. if ((DeviceCode == 0x9488) || (DeviceCode == 0x5761))
  301. Pic_SaveAddr = PIC_DATA_ADDR_TFT35 + pic_counter * PER_PIC_MAX_SPACE_TFT35;
  302. else
  303. Pic_SaveAddr = PIC_DATA_ADDR_TFT32 + pic_counter * PER_PIC_MAX_SPACE_TFT32;
  304. for (j = 0; j < pic_counter; j++) {
  305. do {
  306. W25QXX.SPI_FLASH_BufferRead(&Pname_temp, PIC_NAME_ADDR + SaveName_len, 1);
  307. SaveName_len++;
  308. } while (Pname_temp != '\0');
  309. }
  310. i = 0;
  311. while ((*(P_name + i) != '\0')) {
  312. i++;
  313. name_len++;
  314. }
  315. Pic_NameSaveAddr = PIC_NAME_ADDR + SaveName_len;
  316. W25QXX.SPI_FLASH_BufferWrite(P_name, Pic_NameSaveAddr, name_len + 1);
  317. Pic_SizeSaveAddr = PIC_SIZE_ADDR + 4 * pic_counter;
  318. size_tmp.dwords = P_size;
  319. W25QXX.SPI_FLASH_BufferWrite(size_tmp.bytes, Pic_SizeSaveAddr, 4);
  320. pic_counter++;
  321. W25QXX.SPI_FLASH_SectorErase(PIC_COUNTER_ADDR);
  322. W25QXX.SPI_FLASH_BufferWrite(&pic_counter, PIC_COUNTER_ADDR, 1);
  323. return Pic_SaveAddr;
  324. }
  325. #if ENABLED(SDSUPPORT)
  326. static void dosName2LongName(const char dosName[11], char *longName) {
  327. uint8_t j = 0;
  328. LOOP_L_N(i, 11) {
  329. if (i == 8) longName[j++] = '.';
  330. if (dosName[i] == '\0' || dosName[i] == ' ') continue;
  331. longName[j++] = dosName[i];
  332. }
  333. longName[j] = '\0';
  334. }
  335. static int8_t arrayFindStr(const char arr[][LONG_FILENAME_LENGTH], uint8_t arraySize, const char *str) {
  336. for (uint8_t a = 0; a < arraySize; a++) {
  337. if (strcasecmp(arr[a], str) == 0)
  338. return a;
  339. }
  340. return -1;
  341. }
  342. #if ENABLED(MARLIN_DEV_MODE)
  343. static uint32_t totalSizes = 0, totalCompressed = 0;
  344. #endif
  345. #define ASSET_TYPE_ICON 0
  346. #define ASSET_TYPE_LOGO 1
  347. #define ASSET_TYPE_TITLE_LOGO 2
  348. #define ASSET_TYPE_G_PREVIEW 3
  349. #define ASSET_TYPE_FONT 4
  350. static void loadAsset(SdFile &dir, dir_t& entry, const char *fn, int8_t assetType) {
  351. SdFile file;
  352. char dosFilename[FILENAME_LENGTH];
  353. createFilename(dosFilename, entry);
  354. if (!file.open(&dir, dosFilename, O_READ)) {
  355. #if ENABLED(MARLIN_DEV_MODE)
  356. SERIAL_ECHOLNPAIR("Error opening Asset: ", fn);
  357. #endif
  358. return;
  359. }
  360. watchdog_refresh();
  361. disp_assets_update_progress(fn);
  362. W25QXX.init(SPI_QUARTER_SPEED);
  363. uint16_t pbr;
  364. uint32_t pfileSize;
  365. uint32_t totalSizeLoaded = 0;
  366. uint32_t Pic_Write_Addr;
  367. pfileSize = file.fileSize();
  368. totalSizeLoaded += pfileSize;
  369. if (assetType == ASSET_TYPE_LOGO) {
  370. do {
  371. watchdog_refresh();
  372. pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
  373. Pic_Logo_Write((uint8_t *)fn, public_buf, pbr);
  374. } while (pbr >= BMP_WRITE_BUF_LEN);
  375. }
  376. else if (assetType == ASSET_TYPE_TITLE_LOGO) {
  377. do {
  378. watchdog_refresh();
  379. pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
  380. Pic_TitleLogo_Write((uint8_t *)fn, public_buf, pbr);
  381. } while (pbr >= BMP_WRITE_BUF_LEN);
  382. }
  383. else if (assetType == ASSET_TYPE_G_PREVIEW) {
  384. do {
  385. watchdog_refresh();
  386. pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
  387. default_view_Write(public_buf, pbr);
  388. } while (pbr >= BMP_WRITE_BUF_LEN);
  389. }
  390. else if (assetType == ASSET_TYPE_ICON) {
  391. Pic_Write_Addr = Pic_Info_Write((uint8_t *)fn, pfileSize);
  392. SPIFlash.beginWrite(Pic_Write_Addr);
  393. #if HAS_SPI_FLASH_COMPRESSION
  394. do {
  395. watchdog_refresh();
  396. pbr = file.read(public_buf, SPI_FLASH_PageSize);
  397. TERN_(MARLIN_DEV_MODE, totalSizes += pbr);
  398. SPIFlash.writeData(public_buf, SPI_FLASH_PageSize);
  399. } while (pbr >= SPI_FLASH_PageSize);
  400. #else
  401. do {
  402. pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
  403. W25QXX.SPI_FLASH_BufferWrite(public_buf, Pic_Write_Addr, pbr);
  404. Pic_Write_Addr += pbr;
  405. } while (pbr >= BMP_WRITE_BUF_LEN);
  406. #endif
  407. #if ENABLED(MARLIN_DEV_MODE)
  408. SERIAL_ECHOLNPAIR("Space used: ", fn, " - ", (SPIFlash.getCurrentPage() + 1) * SPI_FLASH_PageSize / 1024, "KB");
  409. totalCompressed += (SPIFlash.getCurrentPage() + 1) * SPI_FLASH_PageSize;
  410. #endif
  411. SPIFlash.endWrite();
  412. }
  413. else if (assetType == ASSET_TYPE_FONT) {
  414. Pic_Write_Addr = UNIGBK_FLASH_ADDR;
  415. do {
  416. watchdog_refresh();
  417. pbr = file.read(public_buf, BMP_WRITE_BUF_LEN);
  418. W25QXX.SPI_FLASH_BufferWrite(public_buf, Pic_Write_Addr, pbr);
  419. Pic_Write_Addr += pbr;
  420. } while (pbr >= BMP_WRITE_BUF_LEN);
  421. }
  422. file.close();
  423. #if ENABLED(MARLIN_DEV_MODE)
  424. SERIAL_ECHOLNPAIR("Asset added: ", fn);
  425. #endif
  426. }
  427. void UpdateAssets() {
  428. if (!card.isMounted()) return;
  429. SdFile dir, root = card.getroot();
  430. if (dir.open(&root, assetsPath, O_RDONLY)) {
  431. disp_assets_update();
  432. disp_assets_update_progress("Erasing pics...");
  433. watchdog_refresh();
  434. spiFlashErase_PIC();
  435. #if HAS_SPI_FLASH_FONT
  436. disp_assets_update_progress("Erasing fonts...");
  437. watchdog_refresh();
  438. spiFlashErase_FONT();
  439. #endif
  440. disp_assets_update_progress("Reading files...");
  441. dir_t d;
  442. while (dir.readDir(&d, card.longFilename) > 0) {
  443. // If we don't get a long name, but gets a short one, try it
  444. if (card.longFilename[0] == 0 && d.name[0] != 0)
  445. dosName2LongName((const char*)d.name, card.longFilename);
  446. if (card.longFilename[0] == 0) continue;
  447. if (card.longFilename[0] == '.') continue;
  448. int8_t a = arrayFindStr(assets, COUNT(assets), card.longFilename);
  449. if (a >= 0 && a < (int8_t)COUNT(assets)) {
  450. uint8_t assetType = ASSET_TYPE_ICON;
  451. if (strstr(assets[a], "_logo"))
  452. assetType = ASSET_TYPE_LOGO;
  453. else if (strstr(assets[a], "_titlelogo"))
  454. assetType = ASSET_TYPE_TITLE_LOGO;
  455. else if (strstr(assets[a], "_preview"))
  456. assetType = ASSET_TYPE_G_PREVIEW;
  457. loadAsset(dir, d, assets[a], assetType);
  458. continue;
  459. }
  460. #if HAS_SPI_FLASH_FONT
  461. a = arrayFindStr(fonts, COUNT(fonts), card.longFilename);
  462. if (a >= 0 && a < (int8_t)COUNT(fonts))
  463. loadAsset(dir, d, fonts[a], ASSET_TYPE_FONT);
  464. #endif
  465. }
  466. dir.rename(&root, bakPath);
  467. }
  468. dir.close();
  469. #if ENABLED(MARLIN_DEV_MODE)
  470. uint8_t pic_counter = 0;
  471. W25QXX.SPI_FLASH_BufferRead(&pic_counter, PIC_COUNTER_ADDR, 1);
  472. SERIAL_ECHOLNPAIR("Total assets loaded: ", pic_counter);
  473. SERIAL_ECHOLNPAIR("Total Uncompressed: ", totalSizes, ", Compressed: ", totalCompressed);
  474. #endif
  475. }
  476. #if HAS_SPI_FLASH_FONT
  477. void spi_flash_read_test() { W25QXX.SPI_FLASH_BufferRead(public_buf, UNIGBK_FLASH_ADDR, BMP_WRITE_BUF_LEN); }
  478. #endif
  479. #endif // SDSUPPORT
  480. void Pic_Read(uint8_t *Pname, uint8_t *P_Rbuff) {
  481. uint8_t i, j;
  482. uint8_t Pic_cnt;
  483. uint32_t tmp_cnt = 0;
  484. PIC_MSG PIC;
  485. W25QXX.SPI_FLASH_BufferRead(&Pic_cnt, PIC_COUNTER_ADDR, 1);
  486. if (Pic_cnt == 0xFF)
  487. Pic_cnt = 0;
  488. for (i = 0; i < Pic_cnt; i++) {
  489. j = 0;
  490. do {
  491. W25QXX.SPI_FLASH_BufferRead(&PIC.name[j], PIC_NAME_ADDR + tmp_cnt, 1);
  492. tmp_cnt++;
  493. } while (PIC.name[j++] != '\0');
  494. //pic size
  495. W25QXX.SPI_FLASH_BufferRead(PIC.size.bytes, PIC_SIZE_ADDR + i * 4, 4);
  496. if ((strcmp((char*)Pname, (char*)PIC.name)) == 0) {
  497. W25QXX.SPI_FLASH_BufferRead((uint8_t *)P_Rbuff, PIC_DATA_ADDR_TFT35 + i * PER_PIC_MAX_SPACE_TFT35, PIC.size.dwords);
  498. break;
  499. }
  500. }
  501. }
  502. void lv_pic_test(uint8_t *P_Rbuff, uint32_t addr, uint32_t size) {
  503. #if HAS_SPI_FLASH_COMPRESSION
  504. if (currentFlashPage == 0)
  505. SPIFlash.beginRead(addr);
  506. SPIFlash.readData(P_Rbuff, size);
  507. currentFlashPage++;
  508. #else
  509. W25QXX.init(SPI_QUARTER_SPEED);
  510. W25QXX.SPI_FLASH_BufferRead((uint8_t *)P_Rbuff, addr, size);
  511. #endif
  512. }
  513. #if HAS_SPI_FLASH_FONT
  514. void get_spi_flash_data(const char *rec_buf, int addr, int size) {
  515. W25QXX.init(SPI_QUARTER_SPEED);
  516. W25QXX.SPI_FLASH_BufferRead((uint8_t *)rec_buf, UNIGBK_FLASH_ADDR + addr, size);
  517. }
  518. #endif
  519. uint32_t logo_addroffset = 0;
  520. void Pic_Logo_Read(uint8_t *LogoName, uint8_t *Logo_Rbuff, uint32_t LogoReadsize) {
  521. W25QXX.init(SPI_QUARTER_SPEED);
  522. W25QXX.SPI_FLASH_BufferRead(Logo_Rbuff, PIC_LOGO_ADDR + logo_addroffset, LogoReadsize);
  523. logo_addroffset += LogoReadsize;
  524. if (logo_addroffset >= LOGO_MAX_SIZE_TFT35)
  525. logo_addroffset = 0;
  526. }
  527. uint32_t default_view_addroffset = 0;
  528. void default_view_Read(uint8_t *default_view_Rbuff, uint32_t default_view_Readsize) {
  529. W25QXX.init(SPI_QUARTER_SPEED);
  530. W25QXX.SPI_FLASH_BufferRead(default_view_Rbuff, DEFAULT_VIEW_ADDR_TFT35 + default_view_addroffset, default_view_Readsize);
  531. default_view_addroffset += default_view_Readsize;
  532. if (default_view_addroffset >= DEFAULT_VIEW_MAX_SIZE)
  533. default_view_addroffset = 0;
  534. }
  535. #if HAS_BAK_VIEW_IN_FLASH
  536. uint32_t flash_view_addroffset = 0;
  537. void flash_view_Read(uint8_t *flash_view_Rbuff, uint32_t flash_view_Readsize) {
  538. W25QXX.init(SPI_QUARTER_SPEED);
  539. W25QXX.SPI_FLASH_BufferRead(flash_view_Rbuff, BAK_VIEW_ADDR_TFT35 + flash_view_addroffset, flash_view_Readsize);
  540. flash_view_addroffset += flash_view_Readsize;
  541. if (flash_view_addroffset >= FLASH_VIEW_MAX_SIZE)
  542. flash_view_addroffset = 0;
  543. }
  544. #endif
  545. #endif // HAS_TFT_LVGL_UI