diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index cd48edad3..841bd16c2 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1044,7 +1044,10 @@ void setup() { timer2_init(); // enables functional millis - MMU2::mmu2.Start(); + if (eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED)) + { + MMU2::mmu2.Start(); + } ultralcd_init(); diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 44b41bfa5..f78acc259 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -334,7 +334,8 @@ static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEP | ^ | ^ | ^ | 04h 4 | ^ | bad_pullup_temp_isr | ^ | ^ | ^ | ^ | ^ | 05h 5 | ^ | bad_pullup_step_isr | ^ | ^ | 0x0D03 3321 | uint8_t | EEPROM_FW_CRASH_FLAG | 01h 1 | ff/00 | Last FW crash reason (dump_crash_reason) | D21/D22 | D3 Ax0d03 C1 -| 0x0D03 3320 | uint8_t | EEPROM_FSENSOR_JAM_DETECTION | 01h 1 | ff/01 | fsensor pat9125 jam detection feature | LCD menu | D3 Ax0d02 C1 +| 0x0D02 3320 | uint8_t | EEPROM_FSENSOR_JAM_DETECTION | 01h 1 | ff/01 | fsensor pat9125 jam detection feature | LCD menu | D3 Ax0d02 C1 +| 0x0D01 3319 | uint8_t | EEPROM_MMU_ENABLED | 01h 1 | ff/01 | MMU enabled | LCD menu | D3 Ax0d01 C1 | Address begin | Bit/Type | Name | Valid values | Default/FactoryReset | Description | Gcode/Function| Debug code | :--: | :--: | :--: | :--: | :--: | :--: | :--: | :--: @@ -559,8 +560,9 @@ static Sheets * const EEPROM_Sheets_base = (Sheets*)(EEPROM_SHEETS_BASE); #define EEPROM_TEMP_MODEL_E (EEPROM_TEMP_MODEL_W-4) // float #define EEPROM_FSENSOR_JAM_DETECTION (EEPROM_TEMP_MODEL_E-1) // uint8_t +#define EEPROM_MMU_ENABLED (EEPROM_FSENSOR_JAM_DETECTION-1) // uint8_t //This is supposed to point to last item to allow EEPROM overrun check. Please update when adding new items. -#define EEPROM_LAST_ITEM EEPROM_FSENSOR_JAM_DETECTION +#define EEPROM_LAST_ITEM EEPROM_MMU_ENABLED // !!!!! // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!! // !!!!! diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 0c0abc9e2..c40856687 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -103,7 +103,7 @@ void MMU2::Start() { mmu2Serial.begin(MMU_BAUD); - // PowerOn(); we cannot do that on MK3, but at least reset the MMU + PowerOn(); // I repurposed this to serve as our EEPROM disable toggle. Reset(ResetForm::ResetPin); mmu2Serial.flush(); // make sure the UART buffer is clear before starting communication @@ -117,7 +117,7 @@ void MMU2::Start() { void MMU2::Stop() { StopKeepPowered(); - PowerOff(); + PowerOff(); // This also disables the MMU in the EEPROM. } void MMU2::StopKeepPowered(){ @@ -146,6 +146,8 @@ void MMU2::TriggerResetPin(){ void MMU2::PowerCycle(){ // cut the power to the MMU and after a while restore it // Sadly, MK3/S/+ cannot do this + // NOTE: the below will toggle the EEPROM var. Should we + // assert this function is never called in the MK3 FW? Do we even care? PowerOff(); delay_keep_alive(1000); PowerOn(); @@ -511,6 +513,10 @@ void MMU2::CheckUserInput(){ break; case RestartMMU: Reset(ResetPin); // we cannot do power cycle on the MK3 + // ... but mmu2_power.cpp knows this and triggers a soft-reset instead. + break; + case DisableMMU: + Stop(); // Poweroff handles updating the EEPROM shutoff. break; case StopPrint: // @@TODO not sure if we shall handle this high level operation at this spot diff --git a/Firmware/mmu2/buttons.h b/Firmware/mmu2/buttons.h index 73413289a..0e407e43b 100644 --- a/Firmware/mmu2/buttons.h +++ b/Firmware/mmu2/buttons.h @@ -28,6 +28,7 @@ enum Buttons : uint8_t { // performed on the printer's side RestartMMU, StopPrint, + DisableMMU, NoButton = 0xff // shall be kept last }; diff --git a/Firmware/mmu2_error_converter.cpp b/Firmware/mmu2_error_converter.cpp index 0ff906699..54c345590 100644 --- a/Firmware/mmu2_error_converter.cpp +++ b/Firmware/mmu2_error_converter.cpp @@ -247,7 +247,14 @@ Buttons ButtonPressed(uint16_t ec) { break; } break; - + case ERR_SYSTEM_FW_UPDATE_NEEDED: + switch (buttonSelectedOperation) { + case ButtonOperations::RestartMMU: // "Restart MMU" + return DisableMMU; + default: + break; + } + break; case ERR_SYSTEM_FILAMENT_ALREADY_LOADED: switch (buttonSelectedOperation) { case ButtonOperations::Unload: // "Unload" diff --git a/Firmware/mmu2_power.cpp b/Firmware/mmu2_power.cpp index 7096358e4..77f8b0c79 100644 --- a/Firmware/mmu2_power.cpp +++ b/Firmware/mmu2_power.cpp @@ -3,19 +3,36 @@ #include "pins.h" #include "fastio.h" #include +#include "mmu2.h" +#include "eeprom.h" namespace MMU2 { -// sadly, on MK3 we cannot do this on HW -void power_on() { } +// sadly, on MK3 we cannot do actual power cycle on HW... +// so we just block the MMU via EEPROM var instead. +void power_on() +{ + if (!eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED)) + { + eeprom_update_byte((uint8_t *)EEPROM_MMU_ENABLED, true); + } +} -void power_off() { } +void power_off() +{ + if (eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED)) + { + eeprom_update_byte((uint8_t *)EEPROM_MMU_ENABLED, false); + } +} void reset() { #ifdef MMU_HWRESET // HW - pulse reset pin WRITE(MMU_RST_PIN, 0); _delay_us(100); WRITE(MMU_RST_PIN, 1); +#else + MMU2::Reset(MMU2::Software); #endif // otherwise HW reset is not available } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 7676cd69a..37ac7cc0c 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4347,6 +4347,25 @@ while(0) #define SETTINGS_CUTTER #endif //MMU_HAS_CUTTER +static void mmu_enable_switch() +{ + uint8_t current_state = eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED); + // EEPROM update is handled by the stop and start functions. + if (current_state) + { + MMU2::mmu2.Stop(); + } + else + { + MMU2::mmu2.Start(); + } +} + +static void mmu_reset() +{ + MMU2::mmu2.Reset(MMU2::MMU2::ResetForm::Software); +} + #ifdef TMC2130 #define SETTINGS_SILENT_MODE \ do\ @@ -4796,6 +4815,13 @@ static void lcd_settings_menu() SETTINGS_CUTTER; + MENU_ITEM_TOGGLE_P(PSTR("MMU"), eeprom_read_byte((uint8_t *)EEPROM_MMU_ENABLED) ? _T(MSG_ON) : _T(MSG_OFF), mmu_enable_switch); + + if (MMU2::mmu2.Enabled()) + { + MENU_ITEM_FUNCTION_P(PSTR("Reset MMU"), mmu_reset); + } + MENU_ITEM_TOGGLE_P(_T(MSG_FANS_CHECK), fans_check_enabled ? _T(MSG_ON) : _T(MSG_OFF), lcd_set_fan_check); SETTINGS_SILENT_MODE;