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

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