Skip to content

Commit

Permalink
Update FLASH.ino
Browse files Browse the repository at this point in the history
  • Loading branch information
sanni committed Aug 9, 2024
1 parent 70e450a commit 3c04277
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions Cart_Reader/FLASH.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ void verifyFlash(byte currChip, byte totalChips, boolean reversed) {
blank = 0;

// Adjust filesize to fit flashchip
adjustFileSize(currChip, totalChips, reversed);
adjustFileSizeOffset(currChip, totalChips, reversed);

//Initialize progress bar
uint32_t processedProgressBar = 0;
Expand Down Expand Up @@ -2857,19 +2857,30 @@ void identifyCFI_Flash() {
display_Update();
}

// Adjust file size to fit flash chip
void adjustFileSize(byte currChip, byte totalChips, boolean reversed) {
// 1 flash chip
if ((currChip == 1) && (totalChips == 1) && reversed) {
myFile.seekSet(4194304);
// Adjust file size to fit flash chip and goto needed file offset
void adjustFileSizeOffset(byte currChip, byte totalChips, boolean reversed) {
// 1*2MB, 1*4MB or 1*8MB
if ((currChip == 1) && (totalChips == 1)) {
if (reversed)
myFile.seekSet(4194304);
}
// 2 flash chips

// 2*2MB or 2*4MB
else if ((currChip == 1) && (totalChips == 2)) {
if (fileSize > flashSize / 2)
if (reversed) {
fileSize = fileSize - flashSize / 2;
myFile.seekSet(4194304);
} else if (fileSize > flashSize / 2)
fileSize = flashSize / 2;
} else if ((currChip == 2) && (totalChips == 2) && (fileSize > flashSize / 2)) {
fileSize = fileSize - flashSize / 2;
myFile.seekSet(flashSize / 2);

} else if ((currChip == 2) && (totalChips == 2)) {
if (reversed) {
fileSize = flashSize / 2;
myFile.seekSet(0);
} else if (fileSize > flashSize / 2) {
fileSize = fileSize - flashSize / 2;
myFile.seekSet(flashSize / 2);
}
}

// 4*2MB
Expand Down Expand Up @@ -2966,7 +2977,7 @@ void writeCFI_Flash(byte currChip, byte totalChips, boolean reversed) {
}

// Adjust filesize to fit flashchip
adjustFileSize(currChip, totalChips, reversed);
adjustFileSizeOffset(currChip, totalChips, reversed);

print_Msg(F("Writing flash"));

Expand Down

0 comments on commit 3c04277

Please sign in to comment.