Prusa MINI Firmware overview
mmu2.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4  *
5  * Based on Sprinter and grbl.
6  * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 #pragma once
23 
24 #include "../../inc/MarlinConfig.h"
25 
26 #if HAS_FILAMENT_SENSOR
27  #include "../runout.h"
28 #endif
29 
30 struct E_Step;
31 
32 class MMU2 {
33 public:
34  MMU2();
35 
36  static void init();
37  static void reset();
38  static void mmu_loop();
39  static void tool_change(uint8_t index);
40  static void tool_change(const char* special);
41  static uint8_t get_current_tool();
42  static void set_filament_type(uint8_t index, uint8_t type);
43 
44  #if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
45  static bool unload();
46  static void load_filament(uint8_t);
47  static void load_all();
48  static bool load_filament_to_nozzle(uint8_t index);
49  static bool eject_filament(uint8_t index, bool recover);
50  #endif
51 
52 private:
53  static bool rx_str_P(const char* str);
54  static void tx_str_P(const char* str);
55  static void tx_printf_P(const char* format, int argument);
56  static void tx_printf_P(const char* format, int argument1, int argument2);
57  static void clear_rx_buffer();
58 
59  static bool rx_ok();
60  static bool rx_start();
61  static void check_version();
62 
63  static void command(const uint8_t cmd);
64  static bool get_response();
65  static void manage_response(const bool move_axes, const bool turn_off_nozzle);
66 
67  #if HAS_LCD_MENU && ENABLED(MMU2_MENUS)
68  static void load_to_nozzle();
69  static void filament_ramming();
70  static void execute_extruder_sequence(const E_Step * sequence, int steps);
71  #endif
72 
73  static void filament_runout();
74 
75  static bool enabled, ready, mmu_print_saved;
76  static uint8_t cmd, cmd_arg, last_cmd, extruder;
77  static int8_t state;
78  static volatile int8_t finda;
79  static volatile bool finda_runout_valid;
80  static int16_t version, buildnr;
81  static millis_t last_request, next_P0_request;
82  static char rx_buffer[16], tx_buffer[16];
83 
84  static inline void set_runout_valid(const bool valid) {
85  finda_runout_valid = valid;
86  #if HAS_FILAMENT_SENSOR
87  if (valid) runout.reset();
88  #endif
89  }
90 
91 };
92 
93 extern MMU2 mmu2;
WITHIN
#define WITHIN(N, L, H)
Definition: macros.h:195
XYZval::z
T z
Definition: types.h:286
enable_E0
#define enable_E0()
Definition: Marlin.h:260
GET_TEXT
#define GET_TEXT(MSG)
Definition: multi_language.h:72
Temperature::tooColdToExtrude
static FORCE_INLINE bool tooColdToExtrude(const uint8_t)
Definition: temperature.h:314
MMU2::get_current_tool
static uint8_t get_current_tool()
Planner::synchronize
static void synchronize()
Definition: planner.cpp:1556
Temperature::degTargetHotend
static FORCE_INLINE int16_t degTargetHotend(const uint8_t E_NAME)
Definition: temperature.h:562
PROGMEM
#define PROGMEM
Definition: pgmspace.h:29
queue
GCodeQueue queue
Definition: queue.cpp:28
LOW
#define LOW
Definition: wiring_constants.h:70
DEBUG_EOL
#define DEBUG_EOL()
Definition: debug_out.h:86
DEBUG_ECHOLNPGM
#define DEBUG_ECHOLNPGM(...)
Definition: debug_out.h:79
host_prompt_do
void host_prompt_do(const PromptReason type, const char *const pstr, const char *const pbtn)
Definition: marlin_server.cpp:1103
do_blocking_move_to_z
void do_blocking_move_to_z(const float &rz, const feedRate_t &fr_mm_s)
Definition: motion.cpp:450
type
uint8_t type
Definition: UsbCore.h:184
do_blocking_move_to_xy
void do_blocking_move_to_xy(const float &rx, const float &ry, const feedRate_t &fr_mm_s)
Definition: motion.cpp:454
DEBUG_ECHO_F
#define DEBUG_ECHO_F(...)
Definition: debug_out.h:76
XYZEval::e
T e
Definition: types.h:383
i
uint8_t i
Definition: screen_test_graph.c:72
STRINGIFY
#define STRINGIFY(M)
Definition: macros.h:73
kill
void kill(PGM_P const lcd_error, PGM_P const lcd_component, const bool steppers_off)
Definition: Marlin.cpp:718
millis
uint32_t millis(void)
Definition: wiring_time.c:29
SET_OUTPUT
#define SET_OUTPUT(IO)
Definition: fastio.h:101
MMU2
Definition: mmu2.h:32
MMU2::reset
static void reset()
DEBUG_ECHOLNPAIR
#define DEBUG_ECHOLNPAIR(...)
Definition: debug_out.h:82
SERIAL_ECHO_START
#define SERIAL_ECHO_START()
Definition: serial.h:179
DEBUG_ECHO_START
#define DEBUG_ECHO_START()
Definition: debug_out.h:72
feedRate_t
float feedRate_t
Definition: types.h:80
sprintf_P
#define sprintf_P(s,...)
Definition: pgmspace.h:72
KEEPALIVE_STATE
#define KEEPALIVE_STATE(N)
Definition: gcode.h:365
mmu2
MMU2 mmu2
disable_E0
#define disable_E0()
Definition: Marlin.h:261
strlen_P
#define strlen_P(s)
Definition: pgmspace.h:61
wait_for_user
bool wait_for_user
Definition: Marlin.cpp:188
pgm_read_byte
#define pgm_read_byte(addr)
Definition: pgmspace.h:95
PSTR
#define PSTR(str)
Definition: pgmspace.h:31
MMU2::init
static void init()
current_position
xyze_pos_t current_position
Definition: motion.cpp:102
MMU2::MMU2
MMU2()
COUNT
#define COUNT(a)
Definition: macros.h:200
line_to_current_position
void line_to_current_position(const feedRate_t &fr_mm_s)
Definition: motion.cpp:285
runout
FilamentMonitor runout
TFilamentMonitor::reset
static void reset()
Definition: runout.h:76
MMU2::mmu_loop
static void mmu_loop()
WRITE
#define WRITE(IO, V)
Definition: fastio.h:96
pgm_read_float
#define pgm_read_float(addr)
Definition: pgmspace.h:109
SERIAL_ECHOLNPAIR
#define SERIAL_ECHOLNPAIR(V...)
Definition: serial.h:144
ELAPSED
#define ELAPSED(NOW, SOON)
Definition: millis_t.h:29
mmu2.h
uint8_t
const uint8_t[]
Definition: 404_html.c:3
ui
MarlinUI ui
SERIAL_ERROR_MSG
#define SERIAL_ERROR_MSG(S)
Definition: serial.h:184
HIGH
#define HIGH
Definition: wiring_constants.h:71
DEC
#define DEC
Definition: Print.h:29
DEBUG_ECHOPAIR
#define DEBUG_ECHOPAIR(...)
Definition: debug_out.h:80
MMM_TO_MMS
#define MMM_TO_MMS(MM_M)
Definition: types.h:83
safe_delay
void safe_delay(millis_t ms)
Definition: utility.cpp:28
XYZval< float >
GCodeQueue::inject_P
static void inject_P(PGM_P const pgcode)
Definition: queue.cpp:206
MMU2::set_filament_type
static void set_filament_type(uint8_t index, uint8_t type)
SERIAL_ECHOLNPGM
#define SERIAL_ECHOLNPGM(S)
Definition: serial.h:174
MSG_ACTIVE_EXTRUDER
#define MSG_ACTIVE_EXTRUDER
Definition: language.h:183
nozzle
Nozzle nozzle
Definition: nozzle.cpp:29
idle
void idle()
Definition: Marlin.cpp:629
thermalManager
Temperature thermalManager
Definition: temperature.cpp:89
millis_t
uint32_t millis_t
Definition: millis_t.h:26
BUZZ
#define BUZZ(d, f)
Definition: buzzer.h:126
active_extruder
constexpr uint8_t active_extruder
Definition: motion.h:107
MMU2::tool_change
static void tool_change(uint8_t index)
planner
Planner planner
Definition: planner.cpp:111
all_axes_homed
FORCE_INLINE bool all_axes_homed()
Definition: motion.h:44