From d5f520388077e697209b02f64e5ade61599df970 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 15 Sep 2019 03:10:59 -0500 Subject: [PATCH] Use "mount" as card verb --- Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp | 10 ++++----- Marlin/src/HAL/HAL_LPC1768/main.cpp | 2 +- .../HAL/HAL_STM32/persistent_store_sdcard.cpp | 4 ++-- .../HAL_STM32F1/persistent_store_sdcard.cpp | 4 ++-- Marlin/src/Marlin.cpp | 3 +-- Marlin/src/feature/binary_protocol.h | 2 +- Marlin/src/feature/power_loss_recovery.cpp | 4 ++-- Marlin/src/gcode/sdcard/M21_M22.cpp | 2 +- Marlin/src/gcode/sdcard/M26.cpp | 2 +- Marlin/src/gcode/sdcard/M30.cpp | 2 +- Marlin/src/gcode/sdcard/M32.cpp | 2 +- Marlin/src/lcd/extensible_ui/ui_api.cpp | 8 +++---- Marlin/src/lcd/extui_malyan_lcd.cpp | 2 +- Marlin/src/lcd/menu/menu_main.cpp | 2 +- Marlin/src/lcd/menu/menu_media.cpp | 4 ++-- Marlin/src/lcd/ultralcd.cpp | 2 +- Marlin/src/sd/cardreader.cpp | 22 +++++++++---------- Marlin/src/sd/cardreader.h | 8 +++---- 18 files changed, 42 insertions(+), 43 deletions(-) diff --git a/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp b/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp index 6f777d8f9e..7df535b91b 100644 --- a/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp +++ b/Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp @@ -19,7 +19,7 @@ void sd_mmc_spi_mem_init(void) { } Ctrl_status sd_mmc_spi_test_unit_ready(void) { - if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected()) + if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted()) return CTRL_NO_PRESENT; return CTRL_GOOD; } @@ -27,7 +27,7 @@ Ctrl_status sd_mmc_spi_test_unit_ready(void) { // NOTE: This function is defined as returning the address of the last block // in the card, which is cardSize() - 1 Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) { - if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected()) + if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted()) return CTRL_NO_PRESENT; *nb_sector = card.getSd2Card().cardSize() - 1; return CTRL_GOOD; @@ -43,7 +43,7 @@ bool sd_mmc_spi_wr_protect(void) { } bool sd_mmc_spi_removal(void) { - if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected()) + if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted()) return true; return false; } @@ -62,7 +62,7 @@ uint8_t sector_buf[SD_MMC_BLOCK_SIZE]; // #define DEBUG_MMC Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) { - if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected()) + if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted()) return CTRL_NO_PRESENT; #ifdef DEBUG_MMC @@ -99,7 +99,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) { } Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) { - if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isDetected()) + if (!IS_SD_INSERTED() || IS_SD_PRINTING() || IS_SD_FILE_OPEN() || !card.isMounted()) return CTRL_NO_PRESENT; #ifdef DEBUG_MMC diff --git a/Marlin/src/HAL/HAL_LPC1768/main.cpp b/Marlin/src/HAL/HAL_LPC1768/main.cpp index b7b5040a20..dc6ad7b2e9 100644 --- a/Marlin/src/HAL/HAL_LPC1768/main.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/main.cpp @@ -158,7 +158,7 @@ void HAL_idletask(void) { // the disk if Marlin has it mounted. Unfortuately there is currently no way // to unmount the disk from the LCD menu. // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN()) - if (card.isDetected()) + if (card.isMounted()) MSC_Aquire_Lock(); else MSC_Release_Lock(); diff --git a/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp index 33bff7a7a8..6ce63073c4 100644 --- a/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp +++ b/Marlin/src/HAL/HAL_STM32/persistent_store_sdcard.cpp @@ -47,7 +47,7 @@ static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE]; #define EEPROM_FILENAME "eeprom.dat" bool PersistentStore::access_start() { - if (!card.isDetected()) return false; + if (!card.isMounted()) return false; SdFile file, root = card.getroot(); if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) @@ -62,7 +62,7 @@ static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE]; } bool PersistentStore::access_finish() { - if (!card.isDetected()) return false; + if (!card.isMounted()) return false; SdFile file, root = card.getroot(); int bytes_written = 0; diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp index ea7b46f4dd..38d5803f58 100644 --- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp @@ -48,7 +48,7 @@ static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE]; #define EEPROM_FILENAME "eeprom.dat" bool PersistentStore::access_start() { - if (!card.isDetected()) return false; + if (!card.isMounted()) return false; SdFile file, root = card.getroot(); if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) @@ -63,7 +63,7 @@ static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE]; } bool PersistentStore::access_finish() { - if (!card.isDetected()) return false; + if (!card.isMounted()) return false; SdFile file, root = card.getroot(); int bytes_written = 0; diff --git a/Marlin/src/Marlin.cpp b/Marlin/src/Marlin.cpp index 662a14a828..7d2cb53f0e 100644 --- a/Marlin/src/Marlin.cpp +++ b/Marlin/src/Marlin.cpp @@ -982,8 +982,7 @@ void setup() { #endif #if ENABLED(SDSUPPORT) - // Auto-mount the SD - card.initsd(); + card.mount(); // Mount the SD card before settings.first_load #endif // Load data from EEPROM if available (or use defaults) diff --git a/Marlin/src/feature/binary_protocol.h b/Marlin/src/feature/binary_protocol.h index d1219081cf..58817f66ba 100644 --- a/Marlin/src/feature/binary_protocol.h +++ b/Marlin/src/feature/binary_protocol.h @@ -76,7 +76,7 @@ private: static bool file_open(char* filename) { if (!dummy_transfer) { - card.initsd(); + card.mount(); card.openFile(filename, false); if (!card.isFileOpen()) return false; } diff --git a/Marlin/src/feature/power_loss_recovery.cpp b/Marlin/src/feature/power_loss_recovery.cpp index 269d759ae6..3420f205f6 100644 --- a/Marlin/src/feature/power_loss_recovery.cpp +++ b/Marlin/src/feature/power_loss_recovery.cpp @@ -98,8 +98,8 @@ void PrintJobRecovery::changed() { */ void PrintJobRecovery::check() { if (enabled) { - if (!card.isDetected()) card.initsd(); - if (card.isDetected()) { + if (!card.isMounted()) card.mount(); + if (card.isMounted()) { load(); if (!valid()) return purge(); queue.inject_P(PSTR("M1000 S")); diff --git a/Marlin/src/gcode/sdcard/M21_M22.cpp b/Marlin/src/gcode/sdcard/M21_M22.cpp index 91b117602d..9362db0808 100644 --- a/Marlin/src/gcode/sdcard/M21_M22.cpp +++ b/Marlin/src/gcode/sdcard/M21_M22.cpp @@ -30,7 +30,7 @@ /** * M21: Init SD Card */ -void GcodeSuite::M21() { card.initsd(); } +void GcodeSuite::M21() { card.mount(); } /** * M22: Release SD Card diff --git a/Marlin/src/gcode/sdcard/M26.cpp b/Marlin/src/gcode/sdcard/M26.cpp index e14ee5b349..0003758804 100644 --- a/Marlin/src/gcode/sdcard/M26.cpp +++ b/Marlin/src/gcode/sdcard/M26.cpp @@ -31,7 +31,7 @@ * M26: Set SD Card file index */ void GcodeSuite::M26() { - if (card.isDetected() && parser.seenval('S')) + if (card.isMounted() && parser.seenval('S')) card.setIndex(parser.value_long()); } diff --git a/Marlin/src/gcode/sdcard/M30.cpp b/Marlin/src/gcode/sdcard/M30.cpp index f4e67c0a4a..2f318687ad 100644 --- a/Marlin/src/gcode/sdcard/M30.cpp +++ b/Marlin/src/gcode/sdcard/M30.cpp @@ -31,7 +31,7 @@ * M30 : Delete SD Card file */ void GcodeSuite::M30() { - if (card.isDetected()) { + if (card.isMounted()) { card.closefile(); card.removeFile(parser.string_arg); } diff --git a/Marlin/src/gcode/sdcard/M32.cpp b/Marlin/src/gcode/sdcard/M32.cpp index dde94c1d89..7e838fe2f5 100644 --- a/Marlin/src/gcode/sdcard/M32.cpp +++ b/Marlin/src/gcode/sdcard/M32.cpp @@ -42,7 +42,7 @@ void GcodeSuite::M32() { if (IS_SD_PRINTING()) planner.synchronize(); - if (card.isDetected()) { + if (card.isMounted()) { const bool call_procedure = parser.boolval('P'); card.openFile(parser.string_arg, true, call_procedure); diff --git a/Marlin/src/lcd/extensible_ui/ui_api.cpp b/Marlin/src/lcd/extensible_ui/ui_api.cpp index 9d29c1f1a0..3b4818030e 100644 --- a/Marlin/src/lcd/extensible_ui/ui_api.cpp +++ b/Marlin/src/lcd/extensible_ui/ui_api.cpp @@ -911,7 +911,7 @@ namespace ExtUI { } bool isMediaInserted() { - return IFSD(IS_SD_INSERTED() && card.isDetected(), false); + return IFSD(IS_SD_INSERTED() && card.isMounted(), false); } void pausePrint() { @@ -1008,14 +1008,14 @@ void MarlinUI::update() { if (sd_status != last_sd_status) { last_sd_status = sd_status; if (sd_status) { - card.initsd(); - if (card.isDetected()) + card.mount(); + if (card.isMounted()) ExtUI::onMediaInserted(); else ExtUI::onMediaError(); } else { - const bool ok = card.isDetected(); + const bool ok = card.isMounted(); card.release(); if (ok) ExtUI::onMediaRemoved(); } diff --git a/Marlin/src/lcd/extui_malyan_lcd.cpp b/Marlin/src/lcd/extui_malyan_lcd.cpp index d6fb84ac72..91235184c4 100644 --- a/Marlin/src/lcd/extui_malyan_lcd.cpp +++ b/Marlin/src/lcd/extui_malyan_lcd.cpp @@ -298,7 +298,7 @@ void process_lcd_s_command(const char* command) { case 'L': { #if ENABLED(SDSUPPORT) - if (!card.isDetected()) card.initsd(); + if (!card.isMounted()) card.mount(); // A more efficient way to do this would be to // implement a callback in the ls_SerialPrint code, but diff --git a/Marlin/src/lcd/menu/menu_main.cpp b/Marlin/src/lcd/menu/menu_main.cpp index 1ccbfd38bb..df43a09c72 100644 --- a/Marlin/src/lcd/menu/menu_main.cpp +++ b/Marlin/src/lcd/menu/menu_main.cpp @@ -101,7 +101,7 @@ void menu_main() { const bool busy = IS_SD_PRINTING() || print_job_timer.isRunning() #if ENABLED(SDSUPPORT) - , card_detected = card.isDetected() + , card_detected = card.isMounted() , card_open = card_detected && card.isFileOpen() #endif ; diff --git a/Marlin/src/lcd/menu/menu_media.cpp b/Marlin/src/lcd/menu/menu_media.cpp index 7625e37c2d..cb83807fb6 100644 --- a/Marlin/src/lcd/menu/menu_media.cpp +++ b/Marlin/src/lcd/menu/menu_media.cpp @@ -34,7 +34,7 @@ #if !PIN_EXISTS(SD_DETECT) void lcd_sd_refresh() { encoderTopLine = 0; - card.initsd(); + card.mount(); } #endif @@ -146,7 +146,7 @@ void menu_media() { MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh); #endif } - else if (card.isDetected()) + else if (card.isMounted()) MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir); if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) { diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 0e397f3685..1f42696bd3 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -842,7 +842,7 @@ void MarlinUI::update() { if (sd_status) { safe_delay(500); // Some boards need a delay to get settled - card.initsd(); + card.mount(); if (old_sd_status == 2) card.beginautostart(); // Initial boot else diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index e692f84b9a..77bc84d594 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -123,7 +123,7 @@ CardReader::CardReader() { //sort_reverse = false; #endif #endif - flag.sdprinting = flag.detected = flag.saving = flag.logging = false; + flag.sdprinting = flag.mounted = flag.saving = flag.logging = false; filesize = sdpos = 0; file_subcall_ctr = 0; @@ -329,8 +329,8 @@ void CardReader::printFilename() { SERIAL_EOL(); } -void CardReader::initsd() { - flag.detected = false; +void CardReader::mount() { + flag.mounted = false; if (root.isOpen()) root.close(); #ifndef SPI_SPEED @@ -350,7 +350,7 @@ void CardReader::initsd() { else if (!root.openRoot(&volume)) SERIAL_ERROR_MSG(MSG_SD_OPENROOT_FAIL); else { - flag.detected = true; + flag.mounted = true; SERIAL_ECHO_MSG(MSG_SD_CARD_OK); #if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) settings.first_load(); @@ -363,7 +363,7 @@ void CardReader::initsd() { void CardReader::release() { stopSDPrint(); - flag.detected = false; + flag.mounted = false; } void CardReader::openAndPrintFile(const char *name) { @@ -375,7 +375,7 @@ void CardReader::openAndPrintFile(const char *name) { } void CardReader::startFileprint() { - if (isDetected()) { + if (isMounted()) { flag.sdprinting = true; #if SD_RESORT flush_presort(); @@ -425,7 +425,7 @@ void CardReader::getAbsFilename(char *t) { void CardReader::openFile(char * const path, const bool read, const bool subcall/*=false*/) { - if (!isDetected()) return; + if (!isMounted()) return; uint8_t doing = 0; if (isFileOpen()) { // Replacing current file or doing a subroutine @@ -499,7 +499,7 @@ void CardReader::openFile(char * const path, const bool read, const bool subcall } void CardReader::removeFile(const char * const name) { - if (!isDetected()) return; + if (!isMounted()) return; //stopSDPrint(); @@ -558,12 +558,12 @@ void CardReader::checkautostart() { if (autostart_index < 0 || flag.sdprinting) return; - if (!isDetected()) initsd(); + if (!isMounted()) mount(); #if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) else settings.first_load(); #endif - if (isDetected() + if (isMounted() #if ENABLED(POWER_LOSS_RECOVERY) && !recovery.valid() // Don't run auto#.g when a resume file exists #endif @@ -1049,7 +1049,7 @@ void CardReader::printingHasFinished() { } void CardReader::openJobRecoveryFile(const bool read) { - if (!isDetected()) return; + if (!isMounted()) return; if (recovery.file.isOpen()) return; if (!recovery.file.open(&root, recovery.filename, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC)) SERIAL_ECHOLNPAIR(MSG_SD_OPEN_FILE_FAIL, recovery.filename, "."); diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index c78df1949c..94e2a9821c 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -39,7 +39,7 @@ typedef struct { bool saving:1, logging:1, sdprinting:1, - detected:1, + mounted:1, filenameIsDir:1, abort_sd_printing:1 #if ENABLED(BINARY_FILE_TRANSFER) @@ -52,7 +52,7 @@ class CardReader { public: CardReader(); - static void initsd(); + static void mount(); static void write_command(char *buf); static void beginautostart(); @@ -111,8 +111,8 @@ public: #endif static inline void pauseSDPrint() { flag.sdprinting = false; } - static inline bool isDetected() { return flag.detected; } - static inline bool isFileOpen() { return isDetected() && file.isOpen(); } + static inline bool isMounted() { return flag.mounted; } + static inline bool isFileOpen() { return isMounted() && file.isOpen(); } static inline bool isPaused() { return isFileOpen() && !flag.sdprinting; } static inline bool isPrinting() { return flag.sdprinting; } static inline bool eof() { return sdpos >= filesize; }