Skip to content

fix slow screen updates issue 24298 #24302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Marlin/src/HAL/SAMD51/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 20 additions & 12 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

/**
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -893,9 +893,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
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/extui/anycubic_i3mega/anycubic_i3mega_lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 1 addition & 3 deletions Marlin/src/lcd/extui/dgus_reloaded/DGUSRxHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/lcd/extui/mks_ui/tft_lvgl_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/marlinui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_media.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 10 additions & 9 deletions Marlin/src/sd/cardreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/sd/cardreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down