From dac242cd2f3e71490ec5fc3b7d35eadeadd0f420 Mon Sep 17 00:00:00 2001 From: sanni Date: Fri, 19 Jul 2024 22:18:22 +0200 Subject: [PATCH] Flash: Add progress bar to read/verify/blankcheck flashrom --- Cart_Reader/FLASH.ino | 63 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 8 deletions(-) diff --git a/Cart_Reader/FLASH.ino b/Cart_Reader/FLASH.ino index 48568df..f0788e0 100644 --- a/Cart_Reader/FLASH.ino +++ b/Cart_Reader/FLASH.ino @@ -1526,7 +1526,15 @@ void eraseFlash29F1610() { // Set data pins to input again dataIn8(); - busyCheck29F1610(); + // Read the status register + byte statusReg = readByte_Flash(0); + + while ((statusReg & 0x80) != 0x80) { + statusReg = readByte_Flash(0); + // Blink led + blinkLED(); + delay(100); + } } // Delay between write operations based on status register @@ -1857,16 +1865,33 @@ void writeFlashLH28F0XX() { Common flashrom functions *****************************************/ void blankcheck_Flash() { - println_Msg(F("Please wait...")); - display_Update(); + + //Initialize progress bar + uint32_t processedProgressBar = 0; + uint32_t totalProgressBar = flashSize; + draw_progressbar(0, totalProgressBar); blank = 1; - for (unsigned long currByte = 0; currByte < flashSize; currByte++) { - // Check if all bytes are 0xFF - if (readByte_Flash(currByte) != 0xFF) { - currByte = flashSize; - blank = 0; + for (unsigned long currBuffer = 0; currBuffer < flashSize; currBuffer += 512) { + // Fill buffer + for (int c = 0; c < 512; c++) { + // Read byte + sdBuffer[c] = readByte_Flash(currBuffer + c); } + // Check if all bytes are 0xFF + for (uint32_t currByte = 0; currByte < 512; currByte++) { + if (sdBuffer[currByte] != 0xFF) { + currByte = 512; + currBuffer = flashSize; + blank = 0; + } + } + // Update progress bar + processedProgressBar += 512; + draw_progressbar(processedProgressBar, totalProgressBar); + // Blink led + if (currBuffer % 25600 == 0) + blinkLED(); } if (blank) { println_Msg(F("Flashrom is empty")); @@ -1898,6 +1923,11 @@ void verifyFlash(byte romChips) { fileSize = 0; } + //Initialize progress bar + uint32_t processedProgressBar = 0; + uint32_t totalProgressBar = fileSize; + draw_progressbar(0, totalProgressBar); + for (unsigned long currByte = 0; currByte < fileSize; currByte += 512) { //fill sdBuffer myFile.read(sdBuffer, 512); @@ -1906,6 +1936,12 @@ void verifyFlash(byte romChips) { blank++; } } + // Update progress bar + processedProgressBar += 512; + draw_progressbar(processedProgressBar, totalProgressBar); + // Blink led + if (currByte % 25600 == 0) + blinkLED(); } if (blank == 0) { println_Msg(F("Flashrom verified OK")); @@ -1927,11 +1963,22 @@ void readFlash() { createFolderAndOpenFile("FLASH", NULL, "FL", "bin"); + //Initialize progress bar + uint32_t processedProgressBar = 0; + uint32_t totalProgressBar = flashSize; + draw_progressbar(0, totalProgressBar); + for (unsigned long currByte = 0; currByte < flashSize; currByte += 512) { for (int c = 0; c < 512; c++) { sdBuffer[c] = readByte_Flash(currByte + c); } myFile.write(sdBuffer, 512); + // Update progress bar + processedProgressBar += 512; + draw_progressbar(processedProgressBar, totalProgressBar); + // Blink led + if (currByte % 25600 == 0) + blinkLED(); } // Close the file: