From 17e9328187baed24924c8596371a623367412042 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Tue, 28 Jun 2022 15:29:33 -0300 Subject: [PATCH 1/7] Create MarlinFile abstraction --- Marlin/src/HAL/STM32/eeprom_sdcard.cpp | 4 +- Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp | 4 +- Marlin/src/feature/powerloss.cpp | 2 +- Marlin/src/feature/powerloss.h | 2 +- Marlin/src/lcd/e3v2/jyersui/dwin.cpp | 2 +- Marlin/src/lcd/e3v2/proui/dwin.cpp | 2 +- .../archim2-flash/media_file_reader.h | 2 +- Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp | 2 +- Marlin/src/lcd/extui/mks_ui/draw_ui.cpp | 4 +- Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp | 2 +- Marlin/src/lcd/extui/mks_ui/pic_manager.cpp | 6 +- Marlin/src/lcd/extui/mks_ui/wifi_module.cpp | 10 +-- Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp | 2 +- Marlin/src/sd/SdFile.h | 2 + Marlin/src/sd/Storage.h | 74 +++++++++++++++++++ Marlin/src/sd/cardreader.cpp | 42 +++++------ Marlin/src/sd/cardreader.h | 20 ++--- Marlin/src/sd/disk_io_driver.h | 1 + 18 files changed, 130 insertions(+), 53 deletions(-) create mode 100644 Marlin/src/sd/Storage.h diff --git a/Marlin/src/HAL/STM32/eeprom_sdcard.cpp b/Marlin/src/HAL/STM32/eeprom_sdcard.cpp index 473b656f9a3c..f1928363ba5d 100644 --- a/Marlin/src/HAL/STM32/eeprom_sdcard.cpp +++ b/Marlin/src/HAL/STM32/eeprom_sdcard.cpp @@ -48,7 +48,7 @@ static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE]; bool PersistentStore::access_start() { if (!card.isMounted()) return false; - SdFile file, root = card.getroot(); + MarlinFile file, root = card.getroot(); if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) return true; @@ -63,7 +63,7 @@ bool PersistentStore::access_start() { bool PersistentStore::access_finish() { if (!card.isMounted()) return false; - SdFile file, root = card.getroot(); + MarlinFile file, root = card.getroot(); int bytes_written = 0; if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) { bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE); diff --git a/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp b/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp index d608ccee1441..d36a4a6c8763 100644 --- a/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp +++ b/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp @@ -47,7 +47,7 @@ static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE]; bool PersistentStore::access_start() { if (!card.isMounted()) return false; - SdFile file, root = card.getroot(); + MarlinFile file, root = card.getroot(); if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) return true; // false aborts the save @@ -62,7 +62,7 @@ bool PersistentStore::access_start() { bool PersistentStore::access_finish() { if (!card.isMounted()) return false; - SdFile file, root = card.getroot(); + MarlinFile file, root = card.getroot(); int bytes_written = 0; if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) { bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE); diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index d4450adcd853..de4b5f31c762 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -33,7 +33,7 @@ bool PrintJobRecovery::enabled; // Initialized by settings.load() -SdFile PrintJobRecovery::file; +MarlinFile PrintJobRecovery::file; job_recovery_info_t PrintJobRecovery::info; const char PrintJobRecovery::filename[5] = "/PLR"; uint8_t PrintJobRecovery::queue_index_r; diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index 33d9dc007c0d..25507b8b2148 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -138,7 +138,7 @@ class PrintJobRecovery { public: static const char filename[5]; - static SdFile file; + static MarlinFile file; static job_recovery_info_t info; static uint8_t queue_index_r; //!< Queue index of the active command diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index 5f1507feb332..52b9cdd72474 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp @@ -4562,7 +4562,7 @@ void CrealityDWINClass::Start_Print(bool sd) { if (sd) { #if ENABLED(POWER_LOSS_RECOVERY) if (recovery.valid()) { - SdFile *diveDir = nullptr; + MarlinFile *diveDir = nullptr; const char * const fname = card.diveToFile(true, diveDir, recovery.info.sd_filename); card.selectFileByName(fname); } diff --git a/Marlin/src/lcd/e3v2/proui/dwin.cpp b/Marlin/src/lcd/e3v2/proui/dwin.cpp index 07b134471b58..df0127764bf6 100644 --- a/Marlin/src/lcd/e3v2/proui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/proui/dwin.cpp @@ -1523,7 +1523,7 @@ void EachMomentUpdate() { DWINUI::Draw_Button(BTN_Cancel, 26, 280); DWINUI::Draw_Button(BTN_Continue, 146, 280); } - SdFile *dir = nullptr; + MarlinFile *dir = nullptr; const char * const filename = card.diveToFile(true, dir, recovery.info.sd_filename); card.selectFileByName(filename); DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 207, card.longest_filename()); diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/media_file_reader.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/media_file_reader.h index eb76bb9b2b2c..4a02091c4008 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/media_file_reader.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/media_file_reader.h @@ -32,7 +32,7 @@ class MediaFileReader { private: #if ENABLED(SDSUPPORT) - SdFile root, file; + MarlinFile root, file; #endif public: diff --git a/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp b/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp index a69c54bcff63..b085ae8282cc 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp @@ -90,7 +90,7 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) { char *cur_name; cur_name = strrchr(list_file.file_name[sel_id], '/'); - SdFile file, *curDir; + MarlinFile file, *curDir; card.abortFilePrintNow(); const char * const fname = card.diveToFile(false, curDir, cur_name); if (!fname) return; diff --git a/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp index 6a8333fd66df..c437f7049c27 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp @@ -647,8 +647,8 @@ char *creat_title_text() { char *cur_name = strrchr(list_file.file_name[sel_id], '/'); - SdFile file; - SdFile *curDir; + MarlinFile file; + MarlinFile *curDir; const char * const fname = card.diveToFile(false, curDir, cur_name); if (!fname) return; if (file.open(curDir, fname, O_READ)) { diff --git a/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp b/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp index 00bb9833fc72..3d59e49feb33 100644 --- a/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp +++ b/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp @@ -727,7 +727,7 @@ void disp_assets_update_progress(FSTR_P const fmsg) { uint8_t mks_test_flag = 0; const char *MKSTestPath = "MKS_TEST"; void mks_test_get() { - SdFile dir, root = card.getroot(); + MarlinFile dir, root = card.getroot(); if (dir.open(&root, MKSTestPath, O_RDONLY)) mks_test_flag = 0x1E; } diff --git a/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp b/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp index c618127980bb..201de649f311 100644 --- a/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp +++ b/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp @@ -403,8 +403,8 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) { #define ASSET_TYPE_TITLE_LOGO 2 #define ASSET_TYPE_G_PREVIEW 3 #define ASSET_TYPE_FONT 4 - static void loadAsset(SdFile &dir, dir_t& entry, FSTR_P const fn, int8_t assetType) { - SdFile file; + static void loadAsset(MarlinFile &dir, dir_t& entry, FSTR_P const fn, int8_t assetType) { + MarlinFile file; char dosFilename[FILENAME_LENGTH]; createFilename(dosFilename, entry); if (!file.open(&dir, dosFilename, O_READ)) { @@ -488,7 +488,7 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) { void UpdateAssets() { if (!card.isMounted()) return; - SdFile dir, root = card.getroot(); + MarlinFile dir, root = card.getroot(); if (dir.open(&root, assetsPath, O_RDONLY)) { disp_assets_update(); diff --git a/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp b/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp index 23a39aabc469..a25312a539ef 100644 --- a/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp +++ b/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp @@ -736,7 +736,7 @@ int32_t lastFragment = 0; char saveFilePath[50]; -static SdFile upload_file, *upload_curDir; +static MarlinFile upload_file, *upload_curDir; static filepos_t pos; int write_to_file(char *buf, int len) { @@ -974,8 +974,8 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { if (!gcode_preview_over) { char *cur_name = strrchr(list_file.file_name[sel_id], '/'); - SdFile file; - SdFile *curDir; + MarlinFile file; + MarlinFile *curDir; card.abortFilePrintNow(); const char * const fname = card.diveToFile(false, curDir, cur_name); if (!fname) return; @@ -1595,7 +1595,7 @@ static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) { } } upload_file.close(); - SdFile file, *curDir; + MarlinFile file, *curDir; const char * const fname = card.diveToFile(false, curDir, saveFilePath); if (file.open(curDir, fname, O_RDWR)) { gCfgItems.curFilesize = file.fileSize(); @@ -1969,7 +1969,7 @@ void mks_wifi_firmware_update() { if (wifi_upload(0) >= 0) { card.removeFile((char *)ESP_FIRMWARE_FILE_RENAME); - SdFile file, *curDir; + MarlinFile file, *curDir; const char * const fname = card.diveToFile(false, curDir, ESP_FIRMWARE_FILE); if (file.open(curDir, fname, O_READ)) { file.rename(curDir, (char *)ESP_FIRMWARE_FILE_RENAME); diff --git a/Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp b/Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp index c07cc47a3689..948349c2e9ae 100644 --- a/Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp +++ b/Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp @@ -86,7 +86,7 @@ static const uint32_t defaultTimeout = 500; static const uint32_t eraseTimeout = 15000; static const uint32_t blockWriteTimeout = 200; static const uint32_t blockWriteInterval = 15; // 15ms is long enough, 10ms is mostly too short -static SdFile update_file, *update_curDir; +static MarlinFile update_file, *update_curDir; // Messages corresponding to result codes, should make sense when followed by " error" const char *resultMessages[] = { diff --git a/Marlin/src/sd/SdFile.h b/Marlin/src/sd/SdFile.h index 1ff05828d272..3876e0ba8392 100644 --- a/Marlin/src/sd/SdFile.h +++ b/Marlin/src/sd/SdFile.h @@ -53,3 +53,5 @@ class SdFile : public SdBaseFile { void write_P(PGM_P str); void writeln_P(PGM_P str); }; + +using MarlinFile = SdFile; \ No newline at end of file diff --git a/Marlin/src/sd/Storage.h b/Marlin/src/sd/Storage.h new file mode 100644 index 000000000000..0ebfc6fdd70b --- /dev/null +++ b/Marlin/src/sd/Storage.h @@ -0,0 +1,74 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +/** + * Marlin Storage Architecture: + * + * DiskIODriver: + * Do all low level IO with the underline hardware or block device: SPI, SDIO, OTG + * + * FilesystemDriver: + * Handle the filesystem format / implementation. Uses the io driver to read and write data. + * Sd2Card is the very first and current filesystem implementation on Marlin, supporting FAT. + * FatFS - Work in progress. + * + * + * Marlin Abstractions: + * + * Using this names allow us to isolate filesystem driver code, keeping all Marlin code agnostic. + * + * MarlinFilesystem: + * Abstraction of systemwide filesystem operation. + * + * MarlinVolume: + * Abstraction of a filesystem volume. + * + * MarlinFile: + * Abstraction of a generic file. Using this name allow us to isolate filesystem driver code, + * keeping all Marlin code agnostic. + * + * PrintFromStorage: + * Class to handle printing from any attached storage. + * + */ + +/* + +Interface definition. Don't need to be compiled, as we use duck typing allowing drivers +to just use type alias. + +Class MarlinVolume { +public: +}; + +Class MarlinFile { +public: +}; + +Class MarlinFilesystem { +public: + static void init(); + static MarlinVolume* openVolume(const char *); +}; + +*/ \ No newline at end of file diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 3fff79653933..4ea1a3d7e912 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -78,7 +78,7 @@ IF_DISABLED(NO_SD_AUTOSTART, uint8_t CardReader::autofile_index); // = 0 // private: -SdFile CardReader::root, CardReader::workDir, CardReader::workDirParents[MAX_DIR_DEPTH]; +MarlinFile CardReader::root, CardReader::workDir, CardReader::workDirParents[MAX_DIR_DEPTH]; uint8_t CardReader::workDirDepth; #if ENABLED(SDCARD_SORT_ALPHA) @@ -133,7 +133,7 @@ uint8_t CardReader::workDirDepth; DiskIODriver* CardReader::driver = nullptr; SdVolume CardReader::volume; -SdFile CardReader::file; +MarlinFile CardReader::file; #if HAS_MEDIA_SUBCALLS uint8_t CardReader::file_subcall_ctr; @@ -227,7 +227,7 @@ bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, // // Get the number of (compliant) items in the folder // -int CardReader::countItems(SdFile dir) { +int CardReader::countItems(MarlinFile dir) { dir_t p; int c = 0; while (dir.readDir(&p, longFilename) > 0) @@ -243,7 +243,7 @@ int CardReader::countItems(SdFile dir) { // // Get file/folder info for an item by index // -void CardReader::selectByIndex(SdFile dir, const uint8_t index) { +void CardReader::selectByIndex(MarlinFile dir, const uint8_t index) { dir_t p; for (uint8_t cnt = 0; dir.readDir(&p, longFilename) > 0;) { if (is_visible_entity(p)) { @@ -259,7 +259,7 @@ void CardReader::selectByIndex(SdFile dir, const uint8_t index) { // // Get file/folder info for an item by name // -void CardReader::selectByName(SdFile dir, const char * const match) { +void CardReader::selectByName(MarlinFile dir, const char * const match) { dir_t p; for (uint8_t cnt = 0; dir.readDir(&p, longFilename) > 0; cnt++) { if (is_visible_entity(p)) { @@ -280,7 +280,7 @@ void CardReader::selectByName(SdFile dir, const char * const match) { * good addition. */ void CardReader::printListing( - SdFile parent, const char * const prepend + MarlinFile parent, const char * const prepend OPTARG(CUSTOM_FIRMWARE_UPLOAD, bool onlyBin/*=false*/) OPTARG(LONG_FILENAME_HOST_SUPPORT, const bool includeLongNames/*=false*/) OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/) @@ -298,7 +298,7 @@ void CardReader::printListing( // Get a new directory object using the full path // and dive recursively into it. - SdFile child; // child.close() in destructor + MarlinFile child; // child.close() in destructor if (child.open(&parent, dosFilename, O_READ)) { #if ENABLED(LONG_FILENAME_HOST_SUPPORT) if (includeLongNames) { @@ -367,7 +367,7 @@ void CardReader::ls( // Zero out slashes to make segments for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0'; - SdFile diveDir = root; // start from the root for segment 1 + MarlinFile diveDir = root; // start from the root for segment 1 for (i = 0; i < pathLen;) { if (path[i] == '\0') i++; // move past a single nul @@ -396,7 +396,7 @@ void CardReader::ls( // SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment); // Open the sub-item as the new dive parent - SdFile dir; + MarlinFile dir; if (!dir.open(&diveDir, segment, O_READ)) { SERIAL_EOL(); SERIAL_ECHO_START(); @@ -595,7 +595,7 @@ void CardReader::getAbsFilenameInCWD(char *dst) { *dst++ = '/'; uint8_t cnt = 1; - auto appendAtom = [&](SdFile &file) { + auto appendAtom = [&](MarlinFile &file) { file.getDosName(dst); while (*dst && cnt < MAXPATHNAMELENGTH) { dst++; cnt++; } if (cnt < MAXPATHNAMELENGTH) { *dst = '/'; dst++; cnt++; } @@ -674,7 +674,7 @@ void CardReader::openFileRead(const char * const path, const uint8_t subcall_typ abortFilePrintNow(); - SdFile *diveDir; + MarlinFile *diveDir; const char * const fname = diveToFile(true, diveDir, path); if (!fname) return; @@ -710,7 +710,7 @@ void CardReader::openFileWrite(const char * const path) { abortFilePrintNow(); - SdFile *diveDir; + MarlinFile *diveDir; const char * const fname = diveToFile(false, diveDir, path); if (!fname) return; @@ -739,7 +739,7 @@ bool CardReader::fileExists(const char * const path) { DEBUG_ECHOLNPGM("fileExists: ", path); // Dive to the file's directory and get the base name - SdFile *diveDir = nullptr; + MarlinFile *diveDir = nullptr; const char * const fname = diveToFile(false, diveDir, path); if (!fname) return false; @@ -749,7 +749,7 @@ bool CardReader::fileExists(const char * const path) { //diveDir->close(); // Try to open the file and return the result - SdFile tmpFile; + MarlinFile tmpFile; const bool success = tmpFile.open(diveDir, fname, O_READ); if (success) tmpFile.close(); return success; @@ -763,7 +763,7 @@ void CardReader::removeFile(const char * const name) { //abortFilePrintNow(); - SdFile *itsDirPtr; + MarlinFile *itsDirPtr; const char * const fname = diveToFile(false, itsDirPtr, name); if (!fname) return; @@ -911,23 +911,23 @@ uint16_t CardReader::countFilesInWorkDir() { * - The workDir points to the last-set navigation target by cd, cdup, cdroot, or diveToFile(true, ...) * * On exit: - * - Your curDir pointer contains an SdFile reference to the file's directory. + * - Your curDir pointer contains an MarlinFile reference to the file's directory. * - If update_cwd was 'true' the workDir now points to the file's directory. * * Returns a pointer to the last segment (filename) of the given DOS 8.3 path. - * On exit, inDirPtr contains an SdFile reference to the file's directory. + * On exit, inDirPtr contains an MarlinFile reference to the file's directory. * * A nullptr result indicates an unrecoverable error. * * NOTE: End the path with a slash to dive to a folder. In this case the * returned filename will be blank (points to the end of the path). */ -const char* CardReader::diveToFile(const bool update_cwd, SdFile* &inDirPtr, const char * const path, const bool echo/*=false*/) { +const char* CardReader::diveToFile(const bool update_cwd, MarlinFile* &inDirPtr, const char * const path, const bool echo/*=false*/) { DEBUG_SECTION(est, "diveToFile", true); // Track both parent and subfolder - static SdFile newDir1, newDir2; - SdFile *sub = &newDir1, *startDirPtr; + static MarlinFile newDir1, newDir2; + MarlinFile *sub = &newDir1, *startDirPtr; // Parsing the path string const char *atom_ptr = path; @@ -1009,7 +1009,7 @@ const char* CardReader::diveToFile(const bool update_cwd, SdFile* &inDirPtr, con } void CardReader::cd(const char * relpath) { - SdFile newDir, *parent = &getWorkDir(); + MarlinFile newDir, *parent = &getWorkDir(); if (newDir.open(parent, relpath, O_READ)) { workDir = newDir; diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index d2f462c2a777..1da0056a38b0 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -114,7 +114,7 @@ class CardReader { static void changeMedia(DiskIODriver *_driver) { driver = _driver; } - static SdFile getroot() { return root; } + static MarlinFile getroot() { return root; } static void mount(); static void release(); @@ -188,12 +188,12 @@ class CardReader { * Relative paths apply to the workDir. * * update_cwd: Pass 'true' to update the workDir on success. - * inDirPtr: On exit your pointer points to the target SdFile. + * inDirPtr: On exit your pointer points to the target MarlinFile. * A nullptr indicates failure. * path: Start with '/' for abs path. End with '/' to get a folder ref. * echo: Set 'true' to print the path throughout the loop. */ - static const char* diveToFile(const bool update_cwd, SdFile* &inDirPtr, const char * const path, const bool echo=false); + static const char* diveToFile(const bool update_cwd, MarlinFile* &inDirPtr, const char * const path, const bool echo=false); #if ENABLED(SDCARD_SORT_ALPHA) static void presort(); @@ -227,7 +227,7 @@ class CardReader { // Current Working Dir - Set by cd, cdup, cdroot, and diveToFile(true, ...) static char* getWorkDirName() { workDir.getDosName(filename); return filename; } - static SdFile& getWorkDir() { return workDir.isOpen() ? workDir : root; } + static MarlinFile& getWorkDir() { return workDir.isOpen() ? workDir : root; } // Print File stats static uint32_t getFileSize() { return filesize; } @@ -266,7 +266,7 @@ class CardReader { // // Working directory and parents // - static SdFile root, workDir, workDirParents[MAX_DIR_DEPTH]; + static MarlinFile root, workDir, workDirParents[MAX_DIR_DEPTH]; static uint8_t workDirDepth; // @@ -327,7 +327,7 @@ class CardReader { static DiskIODriver *driver; static SdVolume volume; - static SdFile file; + static MarlinFile file; static uint32_t filesize, // Total size of the current file, in bytes sdpos; // Index most recently read (one behind file.getPos) @@ -345,11 +345,11 @@ class CardReader { // Directory items // static bool is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin=false)); - static int countItems(SdFile dir); - static void selectByIndex(SdFile dir, const uint8_t index); - static void selectByName(SdFile dir, const char * const match); + static int countItems(MarlinFile dir); + static void selectByIndex(MarlinFile dir, const uint8_t index); + static void selectByName(MarlinFile dir, const char * const match); static void printListing( - SdFile parent, const char * const prepend + MarlinFile parent, const char * const prepend OPTARG(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin=false) OPTARG(LONG_FILENAME_HOST_SUPPORT, const bool includeLongNames=false) OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong=nullptr) diff --git a/Marlin/src/sd/disk_io_driver.h b/Marlin/src/sd/disk_io_driver.h index 02e2b3c73991..3e2d688aea72 100644 --- a/Marlin/src/sd/disk_io_driver.h +++ b/Marlin/src/sd/disk_io_driver.h @@ -22,6 +22,7 @@ #pragma once #include +#include "SdInfo.h" /** * DiskIO Interface From 7b49f38210edb7b7d148447449f050062a382790 Mon Sep 17 00:00:00 2001 From: Victor Oliveira Date: Tue, 28 Jun 2022 19:24:43 -0300 Subject: [PATCH 2/7] MarlinVolume --- Marlin/src/sd/SdVolume.h | 2 ++ Marlin/src/sd/cardreader.cpp | 2 +- Marlin/src/sd/cardreader.h | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Marlin/src/sd/SdVolume.h b/Marlin/src/sd/SdVolume.h index b8e70ca9d7f5..b392e7682269 100644 --- a/Marlin/src/sd/SdVolume.h +++ b/Marlin/src/sd/SdVolume.h @@ -199,3 +199,5 @@ class SdVolume { bool readBlock(uint32_t block, uint8_t *dst) { return sdCard_->readBlock(block, dst); } bool writeBlock(uint32_t block, const uint8_t *dst) { return sdCard_->writeBlock(block, dst); } }; + +using MarlinVolume = SdVolume; \ No newline at end of file diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 4ea1a3d7e912..bd0a334d3aa7 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -132,7 +132,7 @@ uint8_t CardReader::workDirDepth; #endif DiskIODriver* CardReader::driver = nullptr; -SdVolume CardReader::volume; +MarlinVolume CardReader::volume; MarlinFile CardReader::file; #if HAS_MEDIA_SUBCALLS diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index 1da0056a38b0..ee13b4aba5bc 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -326,7 +326,7 @@ class CardReader { #endif // SDCARD_SORT_ALPHA static DiskIODriver *driver; - static SdVolume volume; + static MarlinVolume volume; static MarlinFile file; static uint32_t filesize, // Total size of the current file, in bytes From 3eea9e6b6c4c72bd30c2ecbc61d5c5a283c40096 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 6 Jul 2022 15:52:51 -0500 Subject: [PATCH 3/7] cleanup --- Marlin/src/sd/SdFile.h | 2 +- Marlin/src/sd/SdVolume.h | 2 +- Marlin/src/sd/{Storage.h => storage_.h} | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) rename Marlin/src/sd/{Storage.h => storage_.h} (88%) diff --git a/Marlin/src/sd/SdFile.h b/Marlin/src/sd/SdFile.h index 3876e0ba8392..9fbf8a343724 100644 --- a/Marlin/src/sd/SdFile.h +++ b/Marlin/src/sd/SdFile.h @@ -54,4 +54,4 @@ class SdFile : public SdBaseFile { void writeln_P(PGM_P str); }; -using MarlinFile = SdFile; \ No newline at end of file +using MarlinFile = SdFile; diff --git a/Marlin/src/sd/SdVolume.h b/Marlin/src/sd/SdVolume.h index b392e7682269..309777303092 100644 --- a/Marlin/src/sd/SdVolume.h +++ b/Marlin/src/sd/SdVolume.h @@ -200,4 +200,4 @@ class SdVolume { bool writeBlock(uint32_t block, const uint8_t *dst) { return sdCard_->writeBlock(block, dst); } }; -using MarlinVolume = SdVolume; \ No newline at end of file +using MarlinVolume = SdVolume; diff --git a/Marlin/src/sd/Storage.h b/Marlin/src/sd/storage_.h similarity index 88% rename from Marlin/src/sd/Storage.h rename to Marlin/src/sd/storage_.h index 0ebfc6fdd70b..0e23067a31e5 100644 --- a/Marlin/src/sd/Storage.h +++ b/Marlin/src/sd/storage_.h @@ -1,6 +1,6 @@ /** * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm @@ -26,23 +26,23 @@ * * DiskIODriver: * Do all low level IO with the underline hardware or block device: SPI, SDIO, OTG - * + * * FilesystemDriver: * Handle the filesystem format / implementation. Uses the io driver to read and write data. * Sd2Card is the very first and current filesystem implementation on Marlin, supporting FAT. * FatFS - Work in progress. - * - * + * + * * Marlin Abstractions: - * + * * Using this names allow us to isolate filesystem driver code, keeping all Marlin code agnostic. - * + * * MarlinFilesystem: * Abstraction of systemwide filesystem operation. - * + * * MarlinVolume: - * Abstraction of a filesystem volume. - * + * Abstraction of a filesystem volume. + * * MarlinFile: * Abstraction of a generic file. Using this name allow us to isolate filesystem driver code, * keeping all Marlin code agnostic. @@ -52,9 +52,9 @@ * */ -/* +/* -Interface definition. Don't need to be compiled, as we use duck typing allowing drivers +Interface definition. Doesn't need to be compiled, as we use duck typing allowing drivers to just use type alias. Class MarlinVolume { @@ -71,4 +71,4 @@ Class MarlinFilesystem { static MarlinVolume* openVolume(const char *); }; -*/ \ No newline at end of file +*/ From f3e2ea4cb56eee7b420db09c4bcf6f87d04c5fbc Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 6 Jul 2022 15:53:45 -0500 Subject: [PATCH 4/7] rename --- Marlin/src/sd/{storage_.h => storage.h} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Marlin/src/sd/{storage_.h => storage.h} (100%) diff --git a/Marlin/src/sd/storage_.h b/Marlin/src/sd/storage.h similarity index 100% rename from Marlin/src/sd/storage_.h rename to Marlin/src/sd/storage.h From 3b0e75c88575146445224702d9637409a0f45c74 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 1 Dec 2022 23:46:41 -0600 Subject: [PATCH 5/7] followup --- Marlin/src/sd/cardreader.cpp | 1 - Marlin/src/sd/cardreader.h | 1 - 2 files changed, 2 deletions(-) diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index d9b61cefed8a..d428ed842adb 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -281,7 +281,6 @@ void CardReader::selectByName(MarlinFile dir, const char * const match) { * good addition. */ void CardReader::printListing(MarlinFile parent, const char * const prepend, const uint8_t lsflags - OPTARG(CUSTOM_FIRMWARE_UPLOAD, bool onlyBin/*=false*/) OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/) ) { const bool includeTime = TERN0(M20_TIMESTAMP_SUPPORT, TEST(lsflags, LS_TIMESTAMP)); diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index c63c0d94522c..f481ffd94aef 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -346,7 +346,6 @@ class CardReader { static void selectByName(MarlinFile dir, const char * const match); static void printListing( MarlinFile parent, const char * const prepend, const uint8_t lsflags - OPTARG(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin=false) OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong=nullptr) ); From 8adc4cb5d97f8514acaa7286dff4acb6a6917dbf Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 4 Feb 2023 02:07:03 -0600 Subject: [PATCH 6/7] post merge --- Marlin/src/sd/storage.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/src/sd/storage.h b/Marlin/src/sd/storage.h index 0e23067a31e5..75e636ecc6d6 100644 --- a/Marlin/src/sd/storage.h +++ b/Marlin/src/sd/storage.h @@ -1,6 +1,6 @@ /** * Marlin 3D Printer Firmware - * Copyright (c) 2022 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * Copyright (c) 2023 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] * * Based on Sprinter and grbl. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm @@ -54,8 +54,8 @@ /* -Interface definition. Doesn't need to be compiled, as we use duck typing allowing drivers -to just use type alias. +Interface definition. Doesn't need to be compiled, as we use duck typing, +allowing drivers to just use type alias. Class MarlinVolume { public: From eb7e4f838292958765411840eddbc97f0ddb08a0 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 4 Feb 2023 02:07:40 -0600 Subject: [PATCH 7/7] MarlinFile => MediaFile --- Marlin/src/HAL/STM32/eeprom_sdcard.cpp | 4 +- Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp | 4 +- Marlin/src/feature/powerloss.cpp | 2 +- Marlin/src/feature/powerloss.h | 2 +- Marlin/src/lcd/e3v2/jyersui/dwin.cpp | 2 +- Marlin/src/lcd/e3v2/proui/dwin.cpp | 2 +- .../archim2-flash/media_file_reader.h | 2 +- Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp | 2 +- Marlin/src/lcd/extui/mks_ui/draw_ui.cpp | 4 +- Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp | 2 +- Marlin/src/lcd/extui/mks_ui/pic_manager.cpp | 6 +-- Marlin/src/lcd/extui/mks_ui/wifi_module.cpp | 10 ++--- Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp | 2 +- Marlin/src/sd/SdFile.h | 2 +- Marlin/src/sd/cardreader.cpp | 42 +++++++++---------- Marlin/src/sd/cardreader.h | 20 ++++----- Marlin/src/sd/storage.h | 8 ++-- 17 files changed, 58 insertions(+), 58 deletions(-) diff --git a/Marlin/src/HAL/STM32/eeprom_sdcard.cpp b/Marlin/src/HAL/STM32/eeprom_sdcard.cpp index f1928363ba5d..1b5c0ae5b2c0 100644 --- a/Marlin/src/HAL/STM32/eeprom_sdcard.cpp +++ b/Marlin/src/HAL/STM32/eeprom_sdcard.cpp @@ -48,7 +48,7 @@ static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE]; bool PersistentStore::access_start() { if (!card.isMounted()) return false; - MarlinFile file, root = card.getroot(); + MediaFile file, root = card.getroot(); if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) return true; @@ -63,7 +63,7 @@ bool PersistentStore::access_start() { bool PersistentStore::access_finish() { if (!card.isMounted()) return false; - MarlinFile file, root = card.getroot(); + MediaFile file, root = card.getroot(); int bytes_written = 0; if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) { bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE); diff --git a/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp b/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp index d36a4a6c8763..9cfa97c1ab6e 100644 --- a/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp +++ b/Marlin/src/HAL/STM32F1/eeprom_sdcard.cpp @@ -47,7 +47,7 @@ static char _ALIGN(4) HAL_eeprom_data[MARLIN_EEPROM_SIZE]; bool PersistentStore::access_start() { if (!card.isMounted()) return false; - MarlinFile file, root = card.getroot(); + MediaFile file, root = card.getroot(); if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) return true; // false aborts the save @@ -62,7 +62,7 @@ bool PersistentStore::access_start() { bool PersistentStore::access_finish() { if (!card.isMounted()) return false; - MarlinFile file, root = card.getroot(); + MediaFile file, root = card.getroot(); int bytes_written = 0; if (file.open(&root, EEPROM_FILENAME, O_CREAT | O_WRITE | O_TRUNC)) { bytes_written = file.write(HAL_eeprom_data, MARLIN_EEPROM_SIZE); diff --git a/Marlin/src/feature/powerloss.cpp b/Marlin/src/feature/powerloss.cpp index de4b5f31c762..2825f4d4f219 100644 --- a/Marlin/src/feature/powerloss.cpp +++ b/Marlin/src/feature/powerloss.cpp @@ -33,7 +33,7 @@ bool PrintJobRecovery::enabled; // Initialized by settings.load() -MarlinFile PrintJobRecovery::file; +MediaFile PrintJobRecovery::file; job_recovery_info_t PrintJobRecovery::info; const char PrintJobRecovery::filename[5] = "/PLR"; uint8_t PrintJobRecovery::queue_index_r; diff --git a/Marlin/src/feature/powerloss.h b/Marlin/src/feature/powerloss.h index fa7da4b2c742..d241fdb74c8e 100644 --- a/Marlin/src/feature/powerloss.h +++ b/Marlin/src/feature/powerloss.h @@ -138,7 +138,7 @@ class PrintJobRecovery { public: static const char filename[5]; - static MarlinFile file; + static MediaFile file; static job_recovery_info_t info; static uint8_t queue_index_r; //!< Queue index of the active command diff --git a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp index 784ddc4a6518..8894150c9885 100644 --- a/Marlin/src/lcd/e3v2/jyersui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/jyersui/dwin.cpp @@ -4663,7 +4663,7 @@ void CrealityDWINClass::Start_Print(bool sd) { if (sd) { #if ENABLED(POWER_LOSS_RECOVERY) if (recovery.valid()) { - MarlinFile *diveDir = nullptr; + MediaFile *diveDir = nullptr; const char * const fname = card.diveToFile(true, diveDir, recovery.info.sd_filename); card.selectFileByName(fname); } diff --git a/Marlin/src/lcd/e3v2/proui/dwin.cpp b/Marlin/src/lcd/e3v2/proui/dwin.cpp index f5e79cd035cf..c45aae6044de 100644 --- a/Marlin/src/lcd/e3v2/proui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/proui/dwin.cpp @@ -1347,7 +1347,7 @@ void EachMomentUpdate() { DWINUI::Draw_Button(BTN_Cancel, 26, 280); DWINUI::Draw_Button(BTN_Continue, 146, 280); } - MarlinFile *dir = nullptr; + MediaFile *dir = nullptr; const char * const filename = card.diveToFile(true, dir, recovery.info.sd_filename); card.selectFileByName(filename); DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 207, card.longest_filename()); diff --git a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/media_file_reader.h b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/media_file_reader.h index 4a02091c4008..9a20c2a038d7 100644 --- a/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/media_file_reader.h +++ b/Marlin/src/lcd/extui/ftdi_eve_touch_ui/archim2-flash/media_file_reader.h @@ -32,7 +32,7 @@ class MediaFileReader { private: #if ENABLED(SDSUPPORT) - MarlinFile root, file; + MediaFile root, file; #endif public: diff --git a/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp b/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp index b085ae8282cc..a214e7d1e0e7 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_dialog.cpp @@ -90,7 +90,7 @@ static void btn_ok_event_cb(lv_obj_t *btn, lv_event_t event) { char *cur_name; cur_name = strrchr(list_file.file_name[sel_id], '/'); - MarlinFile file, *curDir; + MediaFile file, *curDir; card.abortFilePrintNow(); const char * const fname = card.diveToFile(false, curDir, cur_name); if (!fname) return; diff --git a/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp b/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp index c437f7049c27..b510e3c0c6f3 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_ui.cpp @@ -647,8 +647,8 @@ char *creat_title_text() { char *cur_name = strrchr(list_file.file_name[sel_id], '/'); - MarlinFile file; - MarlinFile *curDir; + MediaFile file; + MediaFile *curDir; const char * const fname = card.diveToFile(false, curDir, cur_name); if (!fname) return; if (file.open(curDir, fname, O_READ)) { diff --git a/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp b/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp index 3d59e49feb33..0c6315d43870 100644 --- a/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp +++ b/Marlin/src/lcd/extui/mks_ui/mks_hardware.cpp @@ -727,7 +727,7 @@ void disp_assets_update_progress(FSTR_P const fmsg) { uint8_t mks_test_flag = 0; const char *MKSTestPath = "MKS_TEST"; void mks_test_get() { - MarlinFile dir, root = card.getroot(); + MediaFile dir, root = card.getroot(); if (dir.open(&root, MKSTestPath, O_RDONLY)) mks_test_flag = 0x1E; } diff --git a/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp b/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp index 201de649f311..d642d81f6baa 100644 --- a/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp +++ b/Marlin/src/lcd/extui/mks_ui/pic_manager.cpp @@ -403,8 +403,8 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) { #define ASSET_TYPE_TITLE_LOGO 2 #define ASSET_TYPE_G_PREVIEW 3 #define ASSET_TYPE_FONT 4 - static void loadAsset(MarlinFile &dir, dir_t& entry, FSTR_P const fn, int8_t assetType) { - MarlinFile file; + static void loadAsset(MediaFile &dir, dir_t& entry, FSTR_P const fn, int8_t assetType) { + MediaFile file; char dosFilename[FILENAME_LENGTH]; createFilename(dosFilename, entry); if (!file.open(&dir, dosFilename, O_READ)) { @@ -488,7 +488,7 @@ uint32_t Pic_Info_Write(uint8_t *P_name, uint32_t P_size) { void UpdateAssets() { if (!card.isMounted()) return; - MarlinFile dir, root = card.getroot(); + MediaFile dir, root = card.getroot(); if (dir.open(&root, assetsPath, O_RDONLY)) { disp_assets_update(); diff --git a/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp b/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp index a25312a539ef..a8d30b442a9b 100644 --- a/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp +++ b/Marlin/src/lcd/extui/mks_ui/wifi_module.cpp @@ -736,7 +736,7 @@ int32_t lastFragment = 0; char saveFilePath[50]; -static MarlinFile upload_file, *upload_curDir; +static MediaFile upload_file, *upload_curDir; static filepos_t pos; int write_to_file(char *buf, int len) { @@ -974,8 +974,8 @@ static void wifi_gcode_exec(uint8_t *cmd_line) { if (!gcode_preview_over) { char *cur_name = strrchr(list_file.file_name[sel_id], '/'); - MarlinFile file; - MarlinFile *curDir; + MediaFile file; + MediaFile *curDir; card.abortFilePrintNow(); const char * const fname = card.diveToFile(false, curDir, cur_name); if (!fname) return; @@ -1595,7 +1595,7 @@ static void file_fragment_msg_handle(uint8_t * msg, uint16_t msgLen) { } } upload_file.close(); - MarlinFile file, *curDir; + MediaFile file, *curDir; const char * const fname = card.diveToFile(false, curDir, saveFilePath); if (file.open(curDir, fname, O_RDWR)) { gCfgItems.curFilesize = file.fileSize(); @@ -1969,7 +1969,7 @@ void mks_wifi_firmware_update() { if (wifi_upload(0) >= 0) { card.removeFile((char *)ESP_FIRMWARE_FILE_RENAME); - MarlinFile file, *curDir; + MediaFile file, *curDir; const char * const fname = card.diveToFile(false, curDir, ESP_FIRMWARE_FILE); if (file.open(curDir, fname, O_READ)) { file.rename(curDir, (char *)ESP_FIRMWARE_FILE_RENAME); diff --git a/Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp b/Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp index 948349c2e9ae..18a311303ccf 100644 --- a/Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp +++ b/Marlin/src/lcd/extui/mks_ui/wifi_upload.cpp @@ -86,7 +86,7 @@ static const uint32_t defaultTimeout = 500; static const uint32_t eraseTimeout = 15000; static const uint32_t blockWriteTimeout = 200; static const uint32_t blockWriteInterval = 15; // 15ms is long enough, 10ms is mostly too short -static MarlinFile update_file, *update_curDir; +static MediaFile update_file, *update_curDir; // Messages corresponding to result codes, should make sense when followed by " error" const char *resultMessages[] = { diff --git a/Marlin/src/sd/SdFile.h b/Marlin/src/sd/SdFile.h index 9fbf8a343724..81eeadf5b571 100644 --- a/Marlin/src/sd/SdFile.h +++ b/Marlin/src/sd/SdFile.h @@ -54,4 +54,4 @@ class SdFile : public SdBaseFile { void writeln_P(PGM_P str); }; -using MarlinFile = SdFile; +using MediaFile = SdFile; diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 74b35165cef6..fb2721a2b282 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -79,7 +79,7 @@ IF_DISABLED(NO_SD_AUTOSTART, uint8_t CardReader::autofile_index); // = 0 // private: -MarlinFile CardReader::root, CardReader::workDir, CardReader::workDirParents[MAX_DIR_DEPTH]; +MediaFile CardReader::root, CardReader::workDir, CardReader::workDirParents[MAX_DIR_DEPTH]; uint8_t CardReader::workDirDepth; #if ENABLED(SDCARD_SORT_ALPHA) @@ -134,7 +134,7 @@ uint8_t CardReader::workDirDepth; DiskIODriver* CardReader::driver = nullptr; MarlinVolume CardReader::volume; -MarlinFile CardReader::file; +MediaFile CardReader::file; #if HAS_MEDIA_SUBCALLS uint8_t CardReader::file_subcall_ctr; @@ -228,7 +228,7 @@ bool CardReader::is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, // // Get the number of (compliant) items in the folder // -int CardReader::countItems(MarlinFile dir) { +int CardReader::countItems(MediaFile dir) { dir_t p; int c = 0; while (dir.readDir(&p, longFilename) > 0) @@ -244,7 +244,7 @@ int CardReader::countItems(MarlinFile dir) { // // Get file/folder info for an item by index // -void CardReader::selectByIndex(MarlinFile dir, const uint8_t index) { +void CardReader::selectByIndex(MediaFile dir, const uint8_t index) { dir_t p; for (uint8_t cnt = 0; dir.readDir(&p, longFilename) > 0;) { if (is_visible_entity(p)) { @@ -260,7 +260,7 @@ void CardReader::selectByIndex(MarlinFile dir, const uint8_t index) { // // Get file/folder info for an item by name // -void CardReader::selectByName(MarlinFile dir, const char * const match) { +void CardReader::selectByName(MediaFile dir, const char * const match) { dir_t p; for (uint8_t cnt = 0; dir.readDir(&p, longFilename) > 0; cnt++) { if (is_visible_entity(p)) { @@ -280,7 +280,7 @@ void CardReader::selectByName(MarlinFile dir, const char * const match) { * this can blow up the stack, so a 'depth' parameter would be a * good addition. */ -void CardReader::printListing(MarlinFile parent, const char * const prepend, const uint8_t lsflags +void CardReader::printListing(MediaFile parent, const char * const prepend, const uint8_t lsflags OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong/*=nullptr*/) ) { const bool includeTime = TERN0(M20_TIMESTAMP_SUPPORT, TEST(lsflags, LS_TIMESTAMP)); @@ -304,7 +304,7 @@ void CardReader::printListing(MarlinFile parent, const char * const prepend, con // Get a new directory object using the full path // and dive recursively into it. - MarlinFile child; // child.close() in destructor + MediaFile child; // child.close() in destructor if (child.open(&parent, dosFilename, O_READ)) { #if ENABLED(LONG_FILENAME_HOST_SUPPORT) if (includeLong) { @@ -375,7 +375,7 @@ void CardReader::ls(const uint8_t lsflags) { // Zero out slashes to make segments for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0'; - MarlinFile diveDir = root; // start from the root for segment 1 + MediaFile diveDir = root; // start from the root for segment 1 for (i = 0; i < pathLen;) { if (path[i] == '\0') i++; // move past a single nul @@ -404,7 +404,7 @@ void CardReader::ls(const uint8_t lsflags) { // SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment); // Open the sub-item as the new dive parent - MarlinFile dir; + MediaFile dir; if (!dir.open(&diveDir, segment, O_READ)) { SERIAL_EOL(); SERIAL_ECHO_START(); @@ -604,7 +604,7 @@ void CardReader::getAbsFilenameInCWD(char *dst) { *dst++ = '/'; uint8_t cnt = 1; - auto appendAtom = [&](MarlinFile &file) { + auto appendAtom = [&](MediaFile &file) { file.getDosName(dst); while (*dst && cnt < MAXPATHNAMELENGTH) { dst++; cnt++; } if (cnt < MAXPATHNAMELENGTH) { *dst = '/'; dst++; cnt++; } @@ -683,7 +683,7 @@ void CardReader::openFileRead(const char * const path, const uint8_t subcall_typ abortFilePrintNow(); - MarlinFile *diveDir; + MediaFile *diveDir; const char * const fname = diveToFile(true, diveDir, path); if (!fname) return openFailed(path); @@ -719,7 +719,7 @@ void CardReader::openFileWrite(const char * const path) { abortFilePrintNow(); - MarlinFile *diveDir; + MediaFile *diveDir; const char * const fname = diveToFile(false, diveDir, path); if (!fname) return openFailed(path); @@ -747,7 +747,7 @@ bool CardReader::fileExists(const char * const path) { DEBUG_ECHOLNPGM("fileExists: ", path); // Dive to the file's directory and get the base name - MarlinFile *diveDir = nullptr; + MediaFile *diveDir = nullptr; const char * const fname = diveToFile(false, diveDir, path); if (!fname) return false; @@ -757,7 +757,7 @@ bool CardReader::fileExists(const char * const path) { //diveDir->close(); // Try to open the file and return the result - MarlinFile tmpFile; + MediaFile tmpFile; const bool success = tmpFile.open(diveDir, fname, O_READ); if (success) tmpFile.close(); return success; @@ -771,7 +771,7 @@ void CardReader::removeFile(const char * const name) { //abortFilePrintNow(); - MarlinFile *itsDirPtr; + MediaFile *itsDirPtr; const char * const fname = diveToFile(false, itsDirPtr, name); if (!fname) return; @@ -919,23 +919,23 @@ uint16_t CardReader::countFilesInWorkDir() { * - The workDir points to the last-set navigation target by cd, cdup, cdroot, or diveToFile(true, ...) * * On exit: - * - Your curDir pointer contains an MarlinFile reference to the file's directory. + * - Your curDir pointer contains an MediaFile reference to the file's directory. * - If update_cwd was 'true' the workDir now points to the file's directory. * * Returns a pointer to the last segment (filename) of the given DOS 8.3 path. - * On exit, inDirPtr contains an MarlinFile reference to the file's directory. + * On exit, inDirPtr contains an MediaFile reference to the file's directory. * * A nullptr result indicates an unrecoverable error. * * NOTE: End the path with a slash to dive to a folder. In this case the * returned filename will be blank (points to the end of the path). */ -const char* CardReader::diveToFile(const bool update_cwd, MarlinFile* &inDirPtr, const char * const path, const bool echo/*=false*/) { +const char* CardReader::diveToFile(const bool update_cwd, MediaFile* &inDirPtr, const char * const path, const bool echo/*=false*/) { DEBUG_SECTION(est, "diveToFile", true); // Track both parent and subfolder - static MarlinFile newDir1, newDir2; - MarlinFile *sub = &newDir1, *startDirPtr; + static MediaFile newDir1, newDir2; + MediaFile *sub = &newDir1, *startDirPtr; // Parsing the path string const char *atom_ptr = path; @@ -1017,7 +1017,7 @@ const char* CardReader::diveToFile(const bool update_cwd, MarlinFile* &inDirPtr, } void CardReader::cd(const char * relpath) { - MarlinFile newDir, *parent = &getWorkDir(); + MediaFile newDir, *parent = &getWorkDir(); if (newDir.open(parent, relpath, O_READ)) { workDir = newDir; diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index f481ffd94aef..86acb1b8628c 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -116,7 +116,7 @@ class CardReader { static void changeMedia(DiskIODriver *_driver) { driver = _driver; } - static MarlinFile getroot() { return root; } + static MediaFile getroot() { return root; } static void mount(); static void release(); @@ -190,12 +190,12 @@ class CardReader { * Relative paths apply to the workDir. * * update_cwd: Pass 'true' to update the workDir on success. - * inDirPtr: On exit your pointer points to the target MarlinFile. + * inDirPtr: On exit your pointer points to the target MediaFile. * A nullptr indicates failure. * path: Start with '/' for abs path. End with '/' to get a folder ref. * echo: Set 'true' to print the path throughout the loop. */ - static const char* diveToFile(const bool update_cwd, MarlinFile* &inDirPtr, const char * const path, const bool echo=false); + static const char* diveToFile(const bool update_cwd, MediaFile* &inDirPtr, const char * const path, const bool echo=false); #if ENABLED(SDCARD_SORT_ALPHA) static void presort(); @@ -223,7 +223,7 @@ class CardReader { // Current Working Dir - Set by cd, cdup, cdroot, and diveToFile(true, ...) static char* getWorkDirName() { workDir.getDosName(filename); return filename; } - static MarlinFile& getWorkDir() { return workDir.isOpen() ? workDir : root; } + static MediaFile& getWorkDir() { return workDir.isOpen() ? workDir : root; } // Print File stats static uint32_t getFileSize() { return filesize; } @@ -262,7 +262,7 @@ class CardReader { // // Working directory and parents // - static MarlinFile root, workDir, workDirParents[MAX_DIR_DEPTH]; + static MediaFile root, workDir, workDirParents[MAX_DIR_DEPTH]; static uint8_t workDirDepth; // @@ -323,7 +323,7 @@ class CardReader { static DiskIODriver *driver; static MarlinVolume volume; - static MarlinFile file; + static MediaFile file; static uint32_t filesize, // Total size of the current file, in bytes sdpos; // Index most recently read (one behind file.getPos) @@ -341,11 +341,11 @@ class CardReader { // Directory items // static bool is_visible_entity(const dir_t &p OPTARG(CUSTOM_FIRMWARE_UPLOAD, const bool onlyBin=false)); - static int countItems(MarlinFile dir); - static void selectByIndex(MarlinFile dir, const uint8_t index); - static void selectByName(MarlinFile dir, const char * const match); + static int countItems(MediaFile dir); + static void selectByIndex(MediaFile dir, const uint8_t index); + static void selectByName(MediaFile dir, const char * const match); static void printListing( - MarlinFile parent, const char * const prepend, const uint8_t lsflags + MediaFile parent, const char * const prepend, const uint8_t lsflags OPTARG(LONG_FILENAME_HOST_SUPPORT, const char * const prependLong=nullptr) ); diff --git a/Marlin/src/sd/storage.h b/Marlin/src/sd/storage.h index 75e636ecc6d6..3510e04bbe55 100644 --- a/Marlin/src/sd/storage.h +++ b/Marlin/src/sd/storage.h @@ -37,13 +37,13 @@ * * Using this names allow us to isolate filesystem driver code, keeping all Marlin code agnostic. * - * MarlinFilesystem: + * MediaFilesystem: * Abstraction of systemwide filesystem operation. * * MarlinVolume: * Abstraction of a filesystem volume. * - * MarlinFile: + * MediaFile: * Abstraction of a generic file. Using this name allow us to isolate filesystem driver code, * keeping all Marlin code agnostic. * @@ -61,11 +61,11 @@ Class MarlinVolume { public: }; -Class MarlinFile { +Class MediaFile { public: }; -Class MarlinFilesystem { +Class MediaFilesystem { public: static void init(); static MarlinVolume* openVolume(const char *);