Prusa3d Marlin fork
Classes | Enumerations | Functions | Variables
MMU2 Namespace Reference

New MMU2 protocol logic.

Classes

struct  ReportingRAII
 
struct  Version
 
class  MMU2
 
struct  pos3d
 @TODO hmmm, 12 bytes... may be we can reduce that More...
 
struct  OldMMUFWDetector
 
class  DropOutFilter
 Filter of short consecutive drop outs which are recovered instantly. More...
 
class  ProtocolLogic
 Logic layer of the MMU vs. printer communication protocol. More...
 
struct  TuneItem
 
struct  _menu_tune_data_t
 
struct  TryLoadUnloadReporter
 
class  MMU2Serial
 A minimal serial interface for the MMU. More...
 

Enumerations

enum  : uint8_t { FILAMENT_UNKNOWN = 0xffU }
 
enum class  FilamentState : uint_fast8_t { NOT_PRESENT = 0 , AT_FSENSOR = 1 , IN_NOZZLE = 2 , UNAVAILABLE = 3 }
 
enum  StepStatus : uint_fast8_t {
  Processing = 0 , MessageReady , Finished , Interrupted ,
  CommunicationTimeout , ProtocolError , CommandRejected , CommandError ,
  VersionMismatch , PrinterError , CommunicationRecovered , ButtonPushed
}
 ProtocolLogic stepping statuses. More...
 
enum class  ReportErrorHookStates : uint8_t { RENDER_ERROR_SCREEN = 0 , MONITOR_SELECTION = 1 , DISMISS_ERROR_SCREEN = 2 }
 
enum  CommandInProgress : uint8_t {
  NoCommand = 0 , CutFilament = 'K' , EjectFilament = 'E' , Homing = 'H' ,
  LoadFilament = 'L' , Reset = 'X' , ToolChange = 'T' , UnloadFilament = 'U'
}
 
enum  SoundType { Prompt = 2 , Confirm = 3 }
 
enum class  xState : uint_fast8_t { Active , Connecting , Stopped }
 

Functions

template<typename F >
void waitForHotendTargetTemp (uint16_t delay, F f)
 
void WaitForHotendTargetTempBeep ()
 
bool __attribute__ ((noinline)) MMU2
 
template<class InputIt , class UnaryPredicate >
constexpr InputIt find_if_cx (InputIt first, InputIt last, UnaryPredicate p)
 
static constexpr uint8_t FindErrorIndex (uint16_t pec)
 
constexpr ErrorCode operator& (ErrorCode a, ErrorCode b)
 
constexpr bool ContainsBit (ErrorCode ec, ErrorCode mask)
 
uint8_t PrusaErrorCodeIndex (ErrorCode ec)
 
uint16_t PrusaErrorCode (uint8_t i)
 
const char * PrusaErrorTitle (uint8_t i)
 
const char * PrusaErrorDesc (uint8_t i)
 
uint8_t PrusaErrorButtons (uint8_t i)
 
const char * PrusaErrorButtonTitle (uint8_t bi)
 
const char * PrusaErrorButtonMore ()
 
Buttons ButtonPressed (ErrorCode ec)
 
Buttons ButtonAvailable (ErrorCode ec)
 
void SetButtonResponse (ButtonOperations rsp)
 
FilamentState WhereIsFilament ()
 
void LogErrorEvent_P (const char *msg)
 
void LogEchoEvent_P (const char *msg)
 
void extruder_move (float distance, float feed_rate)
 
void extruder_schedule_turning (float feed_rate)
 
float move_raise_z (float delta)
 
void planner_abort_queued_moves ()
 
void planner_synchronize ()
 
bool planner_any_moves ()
 
float stepper_get_machine_position_E_mm ()
 
float planner_get_current_position_E ()
 
void planner_set_current_position_E (float e)
 
pos3d planner_current_position ()
 
void motion_do_blocking_move_to_xy (float rx, float ry, float feedRate_mm_s)
 
void motion_do_blocking_move_to_z (float z, float feedRate_mm_s)
 
void nozzle_park ()
 
bool marlin_printingIsActive ()
 
void marlin_manage_heater ()
 
void marlin_manage_inactivity (bool b)
 
void marlin_idle (bool b)
 
void marlin_refresh_print_state_in_ram ()
 
void marlin_clear_print_state_in_ram ()
 
void marlin_stop_and_save_print_to_ram ()
 
int16_t thermal_degTargetHotend ()
 
int16_t thermal_degHotend ()
 
void thermal_setExtrudeMintemp (int16_t t)
 
void thermal_setTargetHotend (int16_t t)
 
void safe_delay_keep_alive (uint16_t t)
 
void Enable_E0 ()
 
void Disable_E0 ()
 
bool all_axes_homed ()
 
static void planner_line_to_current_position (float feedRate_mm_s)
 
static void planner_line_to_current_position_sync (float feedRate_mm_s)
 
float planner_get_machine_position_E_mm ()
 
void power_on ()
 
void power_off ()
 
void reset ()
 
const char * ProgressCodeToText (ProgressCode pc)
 
constexpr char NibbleToChar (uint8_t c)
 
void BeginReport (CommandInProgress cip, ProgressCode ec)
 Called at the begin of every MMU operation.
 
void EndReport (CommandInProgress cip, ProgressCode ec)
 Called at the end of every MMU operation.
 
void ReportErrorHookDynamicRender (void)
 Renders any characters that will be updated live on the MMU error screen. Currently, this is FINDA and Filament Sensor status and Extruder temperature. More...
 
static void ReportErrorHookStaticRender (uint8_t ei)
 Renders any characters that are static on the MMU error screen i.e. they don't change. More...
 
void ReportErrorHookSensorLineRender ()
 Renders the static part of the sensor state line. Also used by "resuming temperature screen".
 
static uint8_t ReportErrorHookMonitor (uint8_t ei)
 Monitors the LCD button selection without blocking MMU communication. More...
 
void CheckErrorScreenUserInput ()
 Checks for error screen user input, if the error screen is open.
 
bool TuneMenuEntered ()
 
void ReportErrorHook (CommandInProgress cip, ErrorCode ec, uint8_t es)
 Called when the MMU or MK3S sends operation error (even repeatedly). Render MMU error screen on the LCD. This must be non-blocking and allow the MMU and printer to communicate with each other. More...
 
void ReportProgressHook (CommandInProgress cip, ProgressCode ec)
 Called when the MMU sends operation progress update.
 
void DisableMMUInSettings ()
 Disables MMU in EEPROM.
 
void IncrementLoadFails ()
 
void IncrementMMUFails ()
 Increments EEPROM cell - number of MMU errors.
 
bool cutter_enabled ()
 
void MakeSound (SoundType s)
 
static void FullScreenMsg (const char *pgmS, uint8_t slot)
 
void FullScreenMsgCut (uint8_t slot)
 
void FullScreenMsgEject (uint8_t slot)
 
void FullScreenMsgTest (uint8_t slot)
 
void FullScreenMsgLoad (uint8_t slot)
 
void FullScreenMsgRestoringTemperature ()
 
void ScreenUpdateEnable ()
 
void ScreenClear ()
 
struct MMU2::TuneItem __attribute__ ((packed))
 
void tuneIdlerStallguardThresholdMenu ()
 
void tuneIdlerStallguardThreshold ()
 
bool MMUAvailable ()
 
bool UseMMU ()
 Global Enable/Disable use MMU (to be stored in EEPROM)
 

Variables

MMU2 mmu2
 
static ButtonOperations buttonSelectedOperation = ButtonOperations::NoOperation
 
static const char MSG_PROGRESS_OK[] PROGMEM_I1 = ISTR("OK")
 
static const char *const progressTexts[] PROGMEM
 
static constexpr uint8_t supportedMmuFWVersion[3] PROGMEM = { mmuVersionMajor, mmuVersionMinor, mmuVersionPatch }
 
static constexpr uint8_t MAX_RETRIES = 3U
 
constexpr uint32_t linkLayerTimeout = 2000
 default link layer communication timeout
 
constexpr uint32_t dataLayerTimeout = linkLayerTimeout * 3
 data layer communication timeout
 
constexpr uint32_t heartBeatPeriod = linkLayerTimeout / 2
 period of heart beat messages (Q0)
 
enum ReportErrorHookStates ReportErrorHookState = ReportErrorHookStates::RENDER_ERROR_SCREEN
 
static bool is_mmu_error_monitor_active
 
static bool putErrorScreenToSleep
 
static const TuneItem TuneItems[] PROGMEM
 
struct MMU2::_menu_tune_data_t __attribute__
 
MMU2Serial mmu2Serial
 
static constexpr uint8_t mmuVersionMajor = 3
 
static constexpr uint8_t mmuVersionMinor = 0
 
static constexpr uint8_t mmuVersionPatch = 2
 

Enumeration Type Documentation

◆ FilamentState

enum MMU2::FilamentState : uint_fast8_t
strong

Possible states of filament from the perspective of presence in various parts of the printer Beware, the numeric codes are important and sent into the MMU

Enumerator
NOT_PRESENT 

filament sensor doesn't see the filament

AT_FSENSOR 

filament detected by the filament sensor, but the nozzle has not detected the filament yet

IN_NOZZLE 

filament detected by the filament sensor and also loaded in the nozzle

UNAVAILABLE 

sensor not available (likely not connected due broken cable)

◆ StepStatus

enum MMU2::StepStatus : uint_fast8_t
Enumerator
MessageReady 

a message has been successfully decoded from the received bytes

Finished 

Scope finished successfully.

Interrupted 

received "Finished" message related to a different command than originally issued (most likely the MMU restarted while doing something)

CommunicationTimeout 

the MMU failed to respond to a request within a specified time frame

ProtocolError 

bytes read from the MMU didn't form a valid response

CommandRejected 

the MMU rejected the command due to some other command in progress, may be the user is operating the MMU locally (button commands)

CommandError 

the command in progress stopped due to unrecoverable error, user interaction required

VersionMismatch 

the MMU reports its firmware version incompatible with our implementation

PrinterError 

printer's explicit error - MMU is fine, but the printer was unable to complete the requested operation

ButtonPushed 

The MMU reported the user pushed one of its three buttons.

◆ xState

enum MMU2::xState : uint_fast8_t
strong

States of a printer with the MMU:

  • Active
  • Connecting
  • Stopped

When the printer's FW starts, the MMU mode is either Stopped or NotResponding (based on user's preference). When the MMU successfully establishes communication, the state changes to Active.

Enumerator
Active 

MMU has been detected, connected, communicates and is ready to be worked with.

Connecting 

MMU is connected but it doesn't communicate (yet). The user wants the MMU, but it is not ready to be worked with.

Stopped 

The user doesn't want the printer to work with the MMU. The MMU itself is not powered and does not work at all.

Function Documentation

◆ ButtonAvailable()

Buttons MMU2::MMU2::ButtonAvailable ( ErrorCode  ec)
Returns
button index/code based on currently processed error/screen Used as a subfunction of ButtonPressed. Does not clear the "pressed" button upon exit

◆ ButtonPressed()

Buttons MMU2::MMU2::ButtonPressed ( ErrorCode  ec)
Returns
button index/code based on currently processed error/screen Clears the "pressed" button upon exit

◆ cutter_enabled()

bool MMU2::MMU2::cutter_enabled ( )
Returns
true when Cutter is enabled in the menus

◆ IncrementLoadFails()

void MMU2::MMU2::IncrementLoadFails ( )

Increments EEPROM cell - number of failed loads into the nozzle Note: technically, this is not an MMU error but an error of the printer.

◆ LogEchoEvent_P()

void MMU2::MMU2::LogEchoEvent_P ( const char *  msg_P)

Report the msg into the general logging subsystem (through Marlin's SERIAL_ECHO stuff)

Parameters
msgpointer to a string in PROGMEM On the AVR platform this variant reads the input string from PROGMEM. On the ARM platform it calls LogErrorEvent directly (silently expecting the compiler to optimize it away)

◆ LogErrorEvent_P()

void MMU2::MMU2::LogErrorEvent_P ( const char *  msg_P)

Report the msg into the general logging subsystem (through Marlin's SERIAL_ECHO stuff)

Parameters
msgpointer to a string in PROGMEM On the AVR platform this variant reads the input string from PROGMEM. On the ARM platform it calls LogErrorEvent directly (silently expecting the compiler to optimize it away)
Todo:
Decide MMU errors on serial line

◆ MMUAvailable()

bool MMU2::MMUAvailable ( )
Returns
true if the MMU is communicating and available can change at runtime

◆ PrusaErrorButtonMore()

const char * MMU2::MMU2::PrusaErrorButtonMore ( )
Returns
pointer to a PROGMEM string representing the "More" button

◆ PrusaErrorButtons()

uint8_t MMU2::MMU2::PrusaErrorButtons ( uint8_t  i)
Returns
Btns pair of buttons for a particular Prusa-Error-Codes error
Parameters
iindex of the error - obtained by calling ErrorCodeIndex

◆ PrusaErrorButtonTitle()

const char * MMU2::MMU2::PrusaErrorButtonTitle ( uint8_t  bi)
Returns
pointer to a PROGMEM string representing the Title of a button
Parameters
iindex of the error - obtained by calling PrusaErrorButtons + extracting low or high nibble from the Btns pair

◆ PrusaErrorCode()

uint16_t MMU2::MMU2::PrusaErrorCode ( uint8_t  i)
Returns
the actual numerical value of the Prusa-Error-Codes error
Parameters
iindex of the error - obtained by calling ErrorCodeIndex

◆ PrusaErrorCodeIndex()

uint8_t MMU2::MMU2::PrusaErrorCodeIndex ( ErrorCode  ec)

Translates MMU2::ErrorCode into an index of Prusa-Error-Codes Basically this is the way to obtain an index into all other functions in this API

◆ PrusaErrorDesc()

const char * MMU2::MMU2::PrusaErrorDesc ( uint8_t  i)
Returns
pointer to a PROGMEM string representing the multi-page Description of the Prusa-Error-Codes error
Parameters
iindex of the error - obtained by calling ErrorCodeIndex

◆ PrusaErrorTitle()

const char * MMU2::MMU2::PrusaErrorTitle ( uint8_t  i)
Returns
pointer to a PROGMEM string representing the Title of the Prusa-Error-Codes error
Parameters
iindex of the error - obtained by calling ErrorCodeIndex

◆ ReportErrorHook()

void MMU2::MMU2::ReportErrorHook ( CommandInProgress  cip,
ErrorCode  ec,
uint8_t  es 
)
Parameters
[in]ecerror code
[in]eserror source

◆ ReportErrorHookDynamicRender()

void MMU2::MMU2::ReportErrorHookDynamicRender ( void  )

Remders the sensor status line. Also used by the "resume temperature" screen.

◆ ReportErrorHookMonitor()

static uint8_t MMU2::ReportErrorHookMonitor ( uint8_t  ei)
static
Parameters
[in]eiError code index
Returns
0 if there is no knob click – 1 if user clicked 'More' and firmware should render the error screen when ReportErrorHook is called next – 2 if the user selects an operation and we would like to exit the error screen. The MMU will raise the menu again if the error is not solved.

Button menu

|01234567890123456789|
| |
| |
| |
|>(left) |
----------------------
Three choices
|>(left)>(mid)>(righ)|
----------------------
Two choices
----------------------
|>(left) >(mid) |
----------------------

◆ ReportErrorHookStaticRender()

static void MMU2::ReportErrorHookStaticRender ( uint8_t  ei)
static
Parameters
[in]eiError code index

Show an error screen When an MMU error occurs, the LCD content will look like this: |01234567890123456789| |MMU FW update needed| <- title/header of the error: max 20 characters |prusa.io/04504 | <- URL max 20 characters |FI:1 FS:1 5>3 t201°| <- status line, t is thermometer symbol |>Retry >Done >W| <- buttons

◆ SetButtonResponse()

void MMU2::MMU2::SetButtonResponse ( ButtonOperations  rsp)

Sets the selected button for later pick-up by the MMU state machine. Used to save the GUI selection/decoupling

◆ TuneMenuEntered()

bool MMU2::MMU2::TuneMenuEntered ( )

Return true if the error screen is sleeping in the background Error screen sleeps when the firmware is rendering complementary UI to resolve the error screen, for example tuning Idler Stallguard Threshold

Variable Documentation

◆ mmu2

MMU2 MMU2::MMU2::mmu2

following Marlin's way of doing stuff - one and only instance of MMU implementation in the code base

  • avoiding buggy singletons on the AVR platform

◆ PROGMEM [1/2]

constexpr uint8_t supportedMmuFWVersion [3] MMU2::PROGMEM = { mmuVersionMajor, mmuVersionMinor, mmuVersionPatch }
staticconstexpr

Beware - on AVR/MK3S: Changing the supportedMmuVersion numbers requires patching MSG_DESC_FW_UPDATE_NEEDED and all its related translations by hand.

The message reads: "MMU FW version is incompatible with printer FW.Update to version 2.1.9."

Currently, this is not possible to perform automatically at compile time with the existing languages/translations infrastructure. To save space a "dumb" solution was chosen + a few static_assert checks in errors_list.h preventing the code from compiling when the string doesn't match.

◆ PROGMEM [2/2]

const TuneItem TuneItems [] MMU2::PROGMEM
static
Initial value:
= {
{ (uint8_t)Register::Selector_sg_thrs_R, 1, 4},
{ (uint8_t)Register::Idler_sg_thrs_R, 2, 10},
}