🩹 Media Change followup (#24302)

Followup to #24015
This commit is contained in:
ellensp 2022-06-07 18:59:21 +12:00 committed by Scott Lahteine
parent 85e8d1f9fa
commit 48d03ca0a9
11 changed files with 42 additions and 35 deletions

View File

@ -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

View File

@ -517,20 +517,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
@ -539,10 +547,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
/**

View File

@ -891,9 +891,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

View File

@ -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");

View File

@ -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));

View File

@ -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();

View File

@ -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();

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -362,7 +362,7 @@ private:
#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.