From ce9c81dfa12ebde0a0a55663523c782afecbd85c Mon Sep 17 00:00:00 2001 From: ellensp <530024+ellensp@users.noreply.github.com> Date: Tue, 7 Jun 2022 18:59:21 +1200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Media=20Change=20followup=20(#24?= =?UTF-8?q?302)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Followup to #24015 --- Marlin/src/HAL/SAMD51/HAL.cpp | 2 +- Marlin/src/inc/Conditionals_post.h | 32 ++++++++++++------- Marlin/src/inc/SanityCheck.h | 3 +- .../anycubic_i3mega/anycubic_i3mega_lcd.cpp | 4 +-- .../lcd/extui/dgus_reloaded/DGUSRxHandler.cpp | 4 +-- .../extui/mks_ui/tft_lvgl_configuration.cpp | 3 +- Marlin/src/lcd/marlinui.cpp | 2 +- Marlin/src/lcd/menu/menu_main.cpp | 4 +-- Marlin/src/lcd/menu/menu_media.cpp | 2 +- Marlin/src/sd/cardreader.cpp | 19 +++++------ Marlin/src/sd/cardreader.h | 2 +- 11 files changed, 42 insertions(+), 35 deletions(-) diff --git a/Marlin/src/HAL/SAMD51/HAL.cpp b/Marlin/src/HAL/SAMD51/HAL.cpp index 648e0a4f144b..bd1c98bfa1d9 100644 --- a/Marlin/src/HAL/SAMD51/HAL.cpp +++ b/Marlin/src/HAL/SAMD51/HAL.cpp @@ -598,7 +598,7 @@ void MarlinHAL::dma_init() { void MarlinHAL::init() { TERN_(DMA_IS_REQUIRED, dma_init()); #if ENABLED(SDSUPPORT) - #if SD_CONNECTION_IS(ONBOARD) && PIN_EXISTS(SD_DETECT) + #if HAS_SD_DETECT && SD_CONNECTION_IS(ONBOARD) SET_INPUT_PULLUP(SD_DETECT_PIN); #endif OUT_WRITE(SDSS, HIGH); // Try to set SDSS inactive before any other SPI users start up diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 95edb81fccec..dd6b165328fe 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -435,20 +435,28 @@ #define HAS_SHARED_MEDIA 1 #endif - // Set SD_DETECT_STATE based on hardware if not overridden - #if PIN_EXISTS(SD_DETECT) && !defined(SD_DETECT_STATE) - #if BOTH(HAS_MARLINUI_MENU, ELB_FULL_GRAPHIC_CONTROLLER) && (SD_CONNECTION_IS(LCD) || !defined(SDCARD_CONNECTION)) - #define SD_DETECT_STATE HIGH - #else - #define SD_DETECT_STATE LOW - #endif - #endif - // Extender cable doesn't support SD_DETECT_PIN #if ENABLED(NO_SD_DETECT) #undef SD_DETECT_PIN #endif + // Not onboard or custom cable + #if SD_CONNECTION_IS(LCD) || !defined(SDCARD_CONNECTION) + #define SD_CONNECTION_TYPICAL 1 + #endif + + // Set SD_DETECT_STATE based on hardware if not overridden + #if PIN_EXISTS(SD_DETECT) + #define HAS_SD_DETECT 1 + #ifndef SD_DETECT_STATE + #if ALL(SD_CONNECTION_TYPICAL, HAS_MARLINUI_MENU, ELB_FULL_GRAPHIC_CONTROLLER) + #define SD_DETECT_STATE HIGH + #else + #define SD_DETECT_STATE LOW + #endif + #endif + #endif + #if DISABLED(USB_FLASH_DRIVE_SUPPORT) || BOTH(MULTI_VOLUME, VOLUME_SD_ONBOARD) #if ENABLED(SDIO_SUPPORT) #define NEED_SD2CARD_SDIO 1 @@ -457,10 +465,10 @@ #endif #endif -#endif + #if HAS_SD_DETECT && NONE(HAS_GRAPHICAL_TFT, LCD_USE_DMA_FSMC, HAS_FSMC_GRAPHICAL_TFT, HAS_SPI_GRAPHICAL_TFT, IS_DWIN_MARLINUI, EXTENSIBLE_UI, HAS_DWIN_E3V2) + #define REINIT_NOISY_LCD 1 // Have the LCD re-init on SD insertion + #endif -#if PIN_EXISTS(SD_DETECT) && NONE(HAS_GRAPHICAL_TFT, LCD_USE_DMA_FSMC, HAS_FSMC_GRAPHICAL_TFT, HAS_SPI_GRAPHICAL_TFT, IS_DWIN_MARLINUI, EXTENSIBLE_UI, HAS_DWIN_E3V2) - #define REINIT_NOISY_LCD 1 // Have the LCD re-init on SD insertion #endif /** diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 28913492a4a3..4e5d3a96aaea 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -879,9 +879,10 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS /** * SD Card Settings */ -#if ALL(SDSUPPORT, ELB_FULL_GRAPHIC_CONTROLLER, HAS_MARLINUI_MENU) && PIN_EXISTS(SD_DETECT) && SD_DETECT_STATE != HIGH && (SD_CONNECTION_IS(LCD) || !defined(SDCARD_CONNECTION)) +#if ALL(SDSUPPORT, HAS_SD_DETECT, SD_CONNECTION_TYPICAL, ELB_FULL_GRAPHIC_CONTROLLER, HAS_MARLINUI_MENU) && SD_DETECT_STATE == LOW #error "SD_DETECT_STATE must be set HIGH for SD on the ELB_FULL_GRAPHIC_CONTROLLER." #endif +#undef SD_CONNECTION_TYPICAL /** * SD File Sorting diff --git a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp index c382af3fe2e5..0da8bb36a780 100644 --- a/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp +++ b/Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp @@ -86,7 +86,7 @@ void AnycubicTFTClass::OnSetup() { delay_ms(10); // Init the state of the key pins running on the TFT - #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT) + #if BOTH(SDSUPPORT, HAS_SD_DETECT) SET_INPUT_PULLUP(SD_DETECT_PIN); #endif #if ENABLED(FILAMENT_RUNOUT_SENSOR) @@ -916,7 +916,7 @@ void AnycubicTFTClass::GetCommandFromTFT() { } void AnycubicTFTClass::DoSDCardStateCheck() { - #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT) + #if BOTH(SDSUPPORT, HAS_SD_DETECT) bool isInserted = isMediaInserted(); if (isInserted) SENDLINE_DBG_PGM("J00", "TFT Serial Debug: SD card state changed... isInserted"); diff --git a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp index cef9c772e9df..88fe30a0273f 100644 --- a/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp +++ b/Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp @@ -47,9 +47,7 @@ void DGUSRxHandler::ScreenChange(DGUS_VP &vp, void *data_ptr) { if (vp.addr == DGUS_Addr::SCREENCHANGE_SD) { #if ENABLED(SDSUPPORT) - #if !PIN_EXISTS(SD_DETECT) - card.mount(); - #endif + IF_DISABLED(HAS_SD_DETECT, card.mount()); if (!ExtUI::isMediaInserted()) { dgus_screen_handler.SetStatusMessage(GET_TEXT_F(MSG_NO_MEDIA)); diff --git a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp index 378521031509..38612358110b 100644 --- a/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp +++ b/Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp @@ -137,8 +137,7 @@ void tft_lvgl_init() { uint16_t usb_flash_loop = 1000; #if ENABLED(MULTI_VOLUME) && !HAS_SD_HOST_DRIVE SET_INPUT_PULLUP(SD_DETECT_PIN); - if (READ(SD_DETECT_PIN) == LOW) card.changeMedia(&card.media_driver_sdcard); - else card.changeMedia(&card.media_driver_usbFlash); + card.changeMedia(IS_SD_INSERTED() ? &card.media_driver_sdcard : &card.media_driver_usbFlash); #endif do { card.media_driver_usbFlash.idle(); diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 0765ef40a915..d0c966303324 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -1756,7 +1756,7 @@ void MarlinUI::init() { if (old_status < 2) { #if ENABLED(EXTENSIBLE_UI) ExtUI::onMediaRemoved(); - #elif PIN_EXISTS(SD_DETECT) + #elif HAS_SD_DETECT LCD_MESSAGE(MSG_MEDIA_REMOVED); #if HAS_MARLINUI_MENU if (!defer_return_to_status) return_to_status(); diff --git a/Marlin/src/lcd/menu/menu_main.cpp b/Marlin/src/lcd/menu/menu_main.cpp index fdedddb6ddda..518f1e0f502d 100644 --- a/Marlin/src/lcd/menu/menu_main.cpp +++ b/Marlin/src/lcd/menu/menu_main.cpp @@ -246,7 +246,7 @@ void menu_main() { if (card_detected) { if (!card_open) { - #if PIN_EXISTS(SD_DETECT) + #if HAS_SD_DETECT GCODES_ITEM(MSG_CHANGE_MEDIA, F("M21")); // M21 Change Media #else // - or - ACTION_ITEM(MSG_RELEASE_MEDIA, []{ // M22 Release Media @@ -262,7 +262,7 @@ void menu_main() { } } else { - #if PIN_EXISTS(SD_DETECT) + #if HAS_SD_DETECT ACTION_ITEM(MSG_NO_MEDIA, nullptr); // "No Media" #else GCODES_ITEM(MSG_ATTACH_MEDIA, F("M21")); // M21 Attach Media diff --git a/Marlin/src/lcd/menu/menu_media.cpp b/Marlin/src/lcd/menu/menu_media.cpp index e979f04e119d..20ef6e3d198f 100644 --- a/Marlin/src/lcd/menu/menu_media.cpp +++ b/Marlin/src/lcd/menu/menu_media.cpp @@ -122,7 +122,7 @@ void menu_media_filelist() { BACK_ITEM_F(TERN1(BROWSE_MEDIA_ON_INSERT, screen_history_depth) ? GET_TEXT_F(MSG_MAIN) : GET_TEXT_F(MSG_BACK)); #endif if (card.flag.workDirIsRoot) { - #if !PIN_EXISTS(SD_DETECT) + #if !HAS_SD_DETECT ACTION_ITEM(MSG_REFRESH, []{ encoderTopLine = 0; card.mount(); }); #endif } diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 0aa06e47c9f4..5e03795692da 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -171,7 +171,7 @@ CardReader::CardReader() { workDirDepth = 0; ZERO(workDirParents); - #if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT) + #if BOTH(SDSUPPORT, HAS_SD_DETECT) SET_INPUT_PULLUP(SD_DETECT_PIN); #endif @@ -456,10 +456,11 @@ void CardReader::mount() { if (flag.mounted) cdroot(); - #if ENABLED(USB_FLASH_DRIVE_SUPPORT) || PIN_EXISTS(SD_DETECT) - else if (marlin_state != MF_INITIALIZING) - LCD_ALERTMESSAGE(MSG_MEDIA_INIT_FAIL); - #endif + else { + #if EITHER(HAS_SD_DETECT, USB_FLASH_DRIVE_SUPPORT) + if (marlin_state != MF_INITIALIZING) LCD_ALERTMESSAGE(MSG_MEDIA_INIT_FAIL); + #endif + } ui.refresh(); } @@ -496,15 +497,15 @@ void CardReader::manage_media() { if (TERN1(SD_IGNORE_AT_STARTUP, old_stat != 2)) mount(); if (!isMounted()) { // Not mounted? stat = 0; - IF_DISABLED(SD_IGNORE_AT_STARTUP, prev_stat = 0); + #if HAS_SD_DETECT && DISABLED(SD_IGNORE_AT_STARTUP) + prev_stat = 0; + #endif } TERN_(RESET_STEPPERS_ON_MEDIA_INSERT, reset_stepper_drivers()); // Workaround for Cheetah bug } else { - #if PIN_EXISTS(SD_DETECT) - release(); // Card is released - #endif + TERN_(HAS_SD_DETECT, release()); // Card is released } ui.media_changed(old_stat, stat); // Update the UI or flag an error diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index 483ab8139584..d2f462c2a777 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -362,7 +362,7 @@ class CardReader { #if ENABLED(USB_FLASH_DRIVE_SUPPORT) #define IS_SD_INSERTED() DiskIODriver_USBFlash::isInserted() -#elif PIN_EXISTS(SD_DETECT) +#elif HAS_SD_DETECT #define IS_SD_INSERTED() (READ(SD_DETECT_PIN) == SD_DETECT_STATE) #else // No card detect line? Assume the card is inserted.