Use "mount" as card verb

This commit is contained in:
Scott Lahteine 2019-09-15 03:10:59 -05:00
parent 2386c147ad
commit d5f5203880
18 changed files with 42 additions and 43 deletions

View file

@ -19,7 +19,7 @@ void sd_mmc_spi_mem_init(void) {
} }
Ctrl_status sd_mmc_spi_test_unit_ready(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_NO_PRESENT;
return CTRL_GOOD; 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 // NOTE: This function is defined as returning the address of the last block
// in the card, which is cardSize() - 1 // in the card, which is cardSize() - 1
Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) { 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; return CTRL_NO_PRESENT;
*nb_sector = card.getSd2Card().cardSize() - 1; *nb_sector = card.getSd2Card().cardSize() - 1;
return CTRL_GOOD; return CTRL_GOOD;
@ -43,7 +43,7 @@ bool sd_mmc_spi_wr_protect(void) {
} }
bool sd_mmc_spi_removal(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 true;
return false; return false;
} }
@ -62,7 +62,7 @@ uint8_t sector_buf[SD_MMC_BLOCK_SIZE];
// #define DEBUG_MMC // #define DEBUG_MMC
Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) { 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; return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC #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) { 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; return CTRL_NO_PRESENT;
#ifdef DEBUG_MMC #ifdef DEBUG_MMC

View file

@ -158,7 +158,7 @@ void HAL_idletask(void) {
// the disk if Marlin has it mounted. Unfortuately there is currently no way // the disk if Marlin has it mounted. Unfortuately there is currently no way
// to unmount the disk from the LCD menu. // to unmount the disk from the LCD menu.
// if (IS_SD_PRINTING() || IS_SD_FILE_OPEN()) // if (IS_SD_PRINTING() || IS_SD_FILE_OPEN())
if (card.isDetected()) if (card.isMounted())
MSC_Aquire_Lock(); MSC_Aquire_Lock();
else else
MSC_Release_Lock(); MSC_Release_Lock();

View file

@ -47,7 +47,7 @@ static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
#define EEPROM_FILENAME "eeprom.dat" #define EEPROM_FILENAME "eeprom.dat"
bool PersistentStore::access_start() { bool PersistentStore::access_start() {
if (!card.isDetected()) return false; if (!card.isMounted()) return false;
SdFile file, root = card.getroot(); SdFile file, root = card.getroot();
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) 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() { bool PersistentStore::access_finish() {
if (!card.isDetected()) return false; if (!card.isMounted()) return false;
SdFile file, root = card.getroot(); SdFile file, root = card.getroot();
int bytes_written = 0; int bytes_written = 0;

View file

@ -48,7 +48,7 @@ static char _ALIGN(4) HAL_eeprom_data[HAL_EEPROM_SIZE];
#define EEPROM_FILENAME "eeprom.dat" #define EEPROM_FILENAME "eeprom.dat"
bool PersistentStore::access_start() { bool PersistentStore::access_start() {
if (!card.isDetected()) return false; if (!card.isMounted()) return false;
SdFile file, root = card.getroot(); SdFile file, root = card.getroot();
if (!file.open(&root, EEPROM_FILENAME, O_RDONLY)) 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() { bool PersistentStore::access_finish() {
if (!card.isDetected()) return false; if (!card.isMounted()) return false;
SdFile file, root = card.getroot(); SdFile file, root = card.getroot();
int bytes_written = 0; int bytes_written = 0;

View file

@ -982,8 +982,7 @@ void setup() {
#endif #endif
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
// Auto-mount the SD card.mount(); // Mount the SD card before settings.first_load
card.initsd();
#endif #endif
// Load data from EEPROM if available (or use defaults) // Load data from EEPROM if available (or use defaults)

View file

@ -76,7 +76,7 @@ private:
static bool file_open(char* filename) { static bool file_open(char* filename) {
if (!dummy_transfer) { if (!dummy_transfer) {
card.initsd(); card.mount();
card.openFile(filename, false); card.openFile(filename, false);
if (!card.isFileOpen()) return false; if (!card.isFileOpen()) return false;
} }

View file

@ -98,8 +98,8 @@ void PrintJobRecovery::changed() {
*/ */
void PrintJobRecovery::check() { void PrintJobRecovery::check() {
if (enabled) { if (enabled) {
if (!card.isDetected()) card.initsd(); if (!card.isMounted()) card.mount();
if (card.isDetected()) { if (card.isMounted()) {
load(); load();
if (!valid()) return purge(); if (!valid()) return purge();
queue.inject_P(PSTR("M1000 S")); queue.inject_P(PSTR("M1000 S"));

View file

@ -30,7 +30,7 @@
/** /**
* M21: Init SD Card * M21: Init SD Card
*/ */
void GcodeSuite::M21() { card.initsd(); } void GcodeSuite::M21() { card.mount(); }
/** /**
* M22: Release SD Card * M22: Release SD Card

View file

@ -31,7 +31,7 @@
* M26: Set SD Card file index * M26: Set SD Card file index
*/ */
void GcodeSuite::M26() { void GcodeSuite::M26() {
if (card.isDetected() && parser.seenval('S')) if (card.isMounted() && parser.seenval('S'))
card.setIndex(parser.value_long()); card.setIndex(parser.value_long());
} }

View file

@ -31,7 +31,7 @@
* M30 <filename>: Delete SD Card file * M30 <filename>: Delete SD Card file
*/ */
void GcodeSuite::M30() { void GcodeSuite::M30() {
if (card.isDetected()) { if (card.isMounted()) {
card.closefile(); card.closefile();
card.removeFile(parser.string_arg); card.removeFile(parser.string_arg);
} }

View file

@ -42,7 +42,7 @@
void GcodeSuite::M32() { void GcodeSuite::M32() {
if (IS_SD_PRINTING()) planner.synchronize(); if (IS_SD_PRINTING()) planner.synchronize();
if (card.isDetected()) { if (card.isMounted()) {
const bool call_procedure = parser.boolval('P'); const bool call_procedure = parser.boolval('P');
card.openFile(parser.string_arg, true, call_procedure); card.openFile(parser.string_arg, true, call_procedure);

View file

@ -911,7 +911,7 @@ namespace ExtUI {
} }
bool isMediaInserted() { bool isMediaInserted() {
return IFSD(IS_SD_INSERTED() && card.isDetected(), false); return IFSD(IS_SD_INSERTED() && card.isMounted(), false);
} }
void pausePrint() { void pausePrint() {
@ -1008,14 +1008,14 @@ void MarlinUI::update() {
if (sd_status != last_sd_status) { if (sd_status != last_sd_status) {
last_sd_status = sd_status; last_sd_status = sd_status;
if (sd_status) { if (sd_status) {
card.initsd(); card.mount();
if (card.isDetected()) if (card.isMounted())
ExtUI::onMediaInserted(); ExtUI::onMediaInserted();
else else
ExtUI::onMediaError(); ExtUI::onMediaError();
} }
else { else {
const bool ok = card.isDetected(); const bool ok = card.isMounted();
card.release(); card.release();
if (ok) ExtUI::onMediaRemoved(); if (ok) ExtUI::onMediaRemoved();
} }

View file

@ -298,7 +298,7 @@ void process_lcd_s_command(const char* command) {
case 'L': { case 'L': {
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
if (!card.isDetected()) card.initsd(); if (!card.isMounted()) card.mount();
// A more efficient way to do this would be to // A more efficient way to do this would be to
// implement a callback in the ls_SerialPrint code, but // implement a callback in the ls_SerialPrint code, but

View file

@ -101,7 +101,7 @@ void menu_main() {
const bool busy = IS_SD_PRINTING() || print_job_timer.isRunning() const bool busy = IS_SD_PRINTING() || print_job_timer.isRunning()
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
, card_detected = card.isDetected() , card_detected = card.isMounted()
, card_open = card_detected && card.isFileOpen() , card_open = card_detected && card.isFileOpen()
#endif #endif
; ;

View file

@ -34,7 +34,7 @@
#if !PIN_EXISTS(SD_DETECT) #if !PIN_EXISTS(SD_DETECT)
void lcd_sd_refresh() { void lcd_sd_refresh() {
encoderTopLine = 0; encoderTopLine = 0;
card.initsd(); card.mount();
} }
#endif #endif
@ -146,7 +146,7 @@ void menu_media() {
MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh); MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
#endif #endif
} }
else if (card.isDetected()) else if (card.isMounted())
MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir); MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) { if (ui.should_draw()) for (uint16_t i = 0; i < fileCnt; i++) {

View file

@ -842,7 +842,7 @@ void MarlinUI::update() {
if (sd_status) { if (sd_status) {
safe_delay(500); // Some boards need a delay to get settled safe_delay(500); // Some boards need a delay to get settled
card.initsd(); card.mount();
if (old_sd_status == 2) if (old_sd_status == 2)
card.beginautostart(); // Initial boot card.beginautostart(); // Initial boot
else else

View file

@ -123,7 +123,7 @@ CardReader::CardReader() {
//sort_reverse = false; //sort_reverse = false;
#endif #endif
#endif #endif
flag.sdprinting = flag.detected = flag.saving = flag.logging = false; flag.sdprinting = flag.mounted = flag.saving = flag.logging = false;
filesize = sdpos = 0; filesize = sdpos = 0;
file_subcall_ctr = 0; file_subcall_ctr = 0;
@ -329,8 +329,8 @@ void CardReader::printFilename() {
SERIAL_EOL(); SERIAL_EOL();
} }
void CardReader::initsd() { void CardReader::mount() {
flag.detected = false; flag.mounted = false;
if (root.isOpen()) root.close(); if (root.isOpen()) root.close();
#ifndef SPI_SPEED #ifndef SPI_SPEED
@ -350,7 +350,7 @@ void CardReader::initsd() {
else if (!root.openRoot(&volume)) else if (!root.openRoot(&volume))
SERIAL_ERROR_MSG(MSG_SD_OPENROOT_FAIL); SERIAL_ERROR_MSG(MSG_SD_OPENROOT_FAIL);
else { else {
flag.detected = true; flag.mounted = true;
SERIAL_ECHO_MSG(MSG_SD_CARD_OK); SERIAL_ECHO_MSG(MSG_SD_CARD_OK);
#if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM) #if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
settings.first_load(); settings.first_load();
@ -363,7 +363,7 @@ void CardReader::initsd() {
void CardReader::release() { void CardReader::release() {
stopSDPrint(); stopSDPrint();
flag.detected = false; flag.mounted = false;
} }
void CardReader::openAndPrintFile(const char *name) { void CardReader::openAndPrintFile(const char *name) {
@ -375,7 +375,7 @@ void CardReader::openAndPrintFile(const char *name) {
} }
void CardReader::startFileprint() { void CardReader::startFileprint() {
if (isDetected()) { if (isMounted()) {
flag.sdprinting = true; flag.sdprinting = true;
#if SD_RESORT #if SD_RESORT
flush_presort(); flush_presort();
@ -425,7 +425,7 @@ void CardReader::getAbsFilename(char *t) {
void CardReader::openFile(char * const path, const bool read, const bool subcall/*=false*/) { void CardReader::openFile(char * const path, const bool read, const bool subcall/*=false*/) {
if (!isDetected()) return; if (!isMounted()) return;
uint8_t doing = 0; uint8_t doing = 0;
if (isFileOpen()) { // Replacing current file or doing a subroutine 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) { void CardReader::removeFile(const char * const name) {
if (!isDetected()) return; if (!isMounted()) return;
//stopSDPrint(); //stopSDPrint();
@ -558,12 +558,12 @@ void CardReader::checkautostart() {
if (autostart_index < 0 || flag.sdprinting) return; 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) #if ENABLED(EEPROM_SETTINGS) && NONE(FLASH_EEPROM_EMULATION, SPI_EEPROM, I2C_EEPROM)
else settings.first_load(); else settings.first_load();
#endif #endif
if (isDetected() if (isMounted()
#if ENABLED(POWER_LOSS_RECOVERY) #if ENABLED(POWER_LOSS_RECOVERY)
&& !recovery.valid() // Don't run auto#.g when a resume file exists && !recovery.valid() // Don't run auto#.g when a resume file exists
#endif #endif
@ -1049,7 +1049,7 @@ void CardReader::printingHasFinished() {
} }
void CardReader::openJobRecoveryFile(const bool read) { void CardReader::openJobRecoveryFile(const bool read) {
if (!isDetected()) return; if (!isMounted()) return;
if (recovery.file.isOpen()) return; if (recovery.file.isOpen()) return;
if (!recovery.file.open(&root, recovery.filename, read ? O_READ : O_CREAT | O_WRITE | O_TRUNC | O_SYNC)) 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, "."); SERIAL_ECHOLNPAIR(MSG_SD_OPEN_FILE_FAIL, recovery.filename, ".");

View file

@ -39,7 +39,7 @@ typedef struct {
bool saving:1, bool saving:1,
logging:1, logging:1,
sdprinting:1, sdprinting:1,
detected:1, mounted:1,
filenameIsDir:1, filenameIsDir:1,
abort_sd_printing:1 abort_sd_printing:1
#if ENABLED(BINARY_FILE_TRANSFER) #if ENABLED(BINARY_FILE_TRANSFER)
@ -52,7 +52,7 @@ class CardReader {
public: public:
CardReader(); CardReader();
static void initsd(); static void mount();
static void write_command(char *buf); static void write_command(char *buf);
static void beginautostart(); static void beginautostart();
@ -111,8 +111,8 @@ public:
#endif #endif
static inline void pauseSDPrint() { flag.sdprinting = false; } static inline void pauseSDPrint() { flag.sdprinting = false; }
static inline bool isDetected() { return flag.detected; } static inline bool isMounted() { return flag.mounted; }
static inline bool isFileOpen() { return isDetected() && file.isOpen(); } static inline bool isFileOpen() { return isMounted() && file.isOpen(); }
static inline bool isPaused() { return isFileOpen() && !flag.sdprinting; } static inline bool isPaused() { return isFileOpen() && !flag.sdprinting; }
static inline bool isPrinting() { return flag.sdprinting; } static inline bool isPrinting() { return flag.sdprinting; }
static inline bool eof() { return sdpos >= filesize; } static inline bool eof() { return sdpos >= filesize; }