Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/bugfix-2.0.x' into bf2_xy_freq…
Browse files Browse the repository at this point in the history
…_fun
  • Loading branch information
thinkyhead committed Apr 26, 2020
2 parents 0c6345b + 21067ab commit 008067a
Show file tree
Hide file tree
Showing 41 changed files with 263 additions and 131 deletions.
2 changes: 2 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,8 @@
#if ENABLED(NOZZLE_PARK_FEATURE)
// Specify a park position as { X, Y, Z_raise }
#define NOZZLE_PARK_POINT { (X_MIN_POS + 10), (Y_MAX_POS - 10), 20 }
//#define NOZZLE_PARK_X_ONLY // X move only is required to park
//#define NOZZLE_PARK_Y_ONLY // Y move only is required to park
#define NOZZLE_PARK_Z_RAISE_MIN 2 // (mm) Always raise Z by at least this distance
#define NOZZLE_PARK_XY_FEEDRATE 100 // (mm/s) X and Y axes feedrate (also used for delta Z axis)
#define NOZZLE_PARK_Z_FEEDRATE 5 // (mm/s) Z axis feedrate (not used for delta printers)
Expand Down
19 changes: 19 additions & 0 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -3273,6 +3273,25 @@
{ 10.0, 700 }, \
{ -10.0, 400 }, \
{ -50.0, 2000 }
#endif

// Using a sensor like the MMU2S
//#define PRUSA_MMU2_S_MODE
#if ENABLED(PRUSA_MMU2_S_MODE)
#define MMU2_C0_RETRY 5 // Number of retries (total time = timeout*retries)

#define MMU2_CAN_LOAD_FEEDRATE 800 // (mm/m)
#define MMU2_CAN_LOAD_SEQUENCE \
{ 0.1, MMU2_CAN_LOAD_FEEDRATE }, \
{ 60.0, MMU2_CAN_LOAD_FEEDRATE }, \
{ -52.0, MMU2_CAN_LOAD_FEEDRATE }

#define MMU2_CAN_LOAD_RETRACT 6.0 // (mm) Keep under the distance between Load Sequence values
#define MMU2_CAN_LOAD_DEVIATION 0.8 // (mm) Acceptable deviation

#define MMU2_CAN_LOAD_INCREMENT 0.2 // (mm) To reuse within MMU2 module
#define MMU2_CAN_LOAD_INCREMENT_SEQUENCE \
{ -MMU2_CAN_LOAD_INCREMENT, MMU2_CAN_LOAD_FEEDRATE }

#endif

Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/HAL/shared/eeprom_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
// Private Variables
// ------------------------

static uint8_t eeprom_device_address = 0x50;
static constexpr uint8_t eeprom_device_address = I2C_ADDRESS(0x50);

// ------------------------
// Public functions
Expand All @@ -54,7 +54,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {

eeprom_init();

Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
Wire.beginTransmission(eeprom_device_address);
Wire.write((int)(eeprom_address >> 8)); // MSB
Wire.write((int)(eeprom_address & 0xFF)); // LSB
Wire.write(value);
Expand All @@ -70,7 +70,7 @@ void eeprom_write_byte(uint8_t *pos, unsigned char value) {
void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
eeprom_init();

Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
Wire.beginTransmission(eeprom_device_address);
Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
Wire.endTransmission();
Expand All @@ -82,7 +82,7 @@ void eeprom_update_block(const void *pos, void* eeprom_address, size_t n) {
flag |= Wire.read() ^ ptr[c];

if (flag) {
Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
Wire.beginTransmission(eeprom_device_address);
Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
Wire.write((uint8_t*)pos, n);
Expand All @@ -99,7 +99,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {

eeprom_init();

Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
Wire.beginTransmission(eeprom_device_address);
Wire.write((int)(eeprom_address >> 8)); // MSB
Wire.write((int)(eeprom_address & 0xFF)); // LSB
Wire.endTransmission();
Expand All @@ -111,7 +111,7 @@ uint8_t eeprom_read_byte(uint8_t *pos) {
void eeprom_read_block(void* pos, const void* eeprom_address, size_t n) {
eeprom_init();

Wire.beginTransmission(I2C_ADDRESS(eeprom_device_address));
Wire.beginTransmission(eeprom_device_address);
Wire.write((int)((unsigned)eeprom_address >> 8)); // MSB
Wire.write((int)((unsigned)eeprom_address & 0xFF)); // LSB
Wire.endTransmission();
Expand Down
6 changes: 1 addition & 5 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,7 @@
#define FMOD(x, y) fmodf(x, y)
#define HYPOT(x,y) SQRT(HYPOT2(x,y))

#ifdef TARGET_LPC1768
#define I2C_ADDRESS(A) ((A) << 1)
#else
#define I2C_ADDRESS(A) A
#endif
#define I2C_ADDRESS(A) (TERN(TARGET_LPC1768, (A) << 1, A))

// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
#define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/encoder_i2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ int32_t I2CPositionEncoder::get_raw_count() {

encoderCount.val = 0x00;

if (Wire.requestFrom((int)i2cAddress, 3) != 3) {
if (Wire.requestFrom(I2C_ADDRESS(i2cAddress), 3) != 3) {
//houston, we have a problem...
H = I2CPE_MAG_SIG_NF;
return 0;
Expand Down Expand Up @@ -744,7 +744,7 @@ void I2CPositionEncodersMgr::report_module_firmware(const uint8_t address) {
Wire.endTransmission();

// Read value
if (Wire.requestFrom((int)address, 32)) {
if (Wire.requestFrom(I2C_ADDRESS(address), 32)) {
char c;
while (Wire.available() > 0 && (c = (char)Wire.read()) > 0)
SERIAL_ECHO(c);
Expand Down
128 changes: 97 additions & 31 deletions Marlin/src/feature/mmu2/mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ MMU2 mmu2;
#define mmuSerial MMU2_SERIAL

bool MMU2::enabled, MMU2::ready, MMU2::mmu_print_saved;
#if ENABLED(PRUSA_MMU2_S_MODE)
bool MMU2::mmu2s_triggered;
#endif
uint8_t MMU2::cmd, MMU2::cmd_arg, MMU2::last_cmd, MMU2::extruder;
int8_t MMU2::state = 0;
volatile int8_t MMU2::finda = 1;
Expand All @@ -106,8 +109,14 @@ char MMU2::rx_buffer[MMU_RX_SIZE], MMU2::tx_buffer[MMU_TX_SIZE];
feedRate_t feedRate; //!< feed rate in mm/s
};

static constexpr E_Step ramming_sequence[] PROGMEM = { MMU2_RAMMING_SEQUENCE };
static constexpr E_Step load_to_nozzle_sequence[] PROGMEM = { MMU2_LOAD_TO_NOZZLE_SEQUENCE };
static constexpr E_Step
ramming_sequence[] PROGMEM = { MMU2_RAMMING_SEQUENCE }
, load_to_nozzle_sequence[] PROGMEM = { MMU2_LOAD_TO_NOZZLE_SEQUENCE }
#if ENABLED(PRUSA_MMU2_S_MODE)
, can_load_sequence[] PROGMEM = { MMU2_CAN_LOAD_SEQUENCE }
, can_load_increment_sequence[] PROGMEM = { MMU2_CAN_LOAD_INCREMENT_SEQUENCE }
#endif
;

#endif // MMU2_MENUS

Expand Down Expand Up @@ -228,6 +237,7 @@ void MMU2::mmu_loop() {

enabled = true;
state = 1;
TERN_(PRUSA_MMU2_S_MODE, mmu2s_triggered = false);
}
break;

Expand Down Expand Up @@ -291,6 +301,8 @@ void MMU2::mmu_loop() {
tx_str_P(PSTR("P0\n"));
state = 2; // wait for response
}

TERN_(PRUSA_MMU2_S_MODE, check_filament());
break;

case 2: // response to command P0
Expand All @@ -309,6 +321,7 @@ void MMU2::mmu_loop() {
else if (ELAPSED(millis(), last_request + MMU_P0_TIMEOUT)) // Resend request after timeout (3s)
state = 1;

TERN_(PRUSA_MMU2_S_MODE, check_filament());
break;

case 3: // response to mmu commands
Expand All @@ -327,6 +340,7 @@ void MMU2::mmu_loop() {
}
state = 1;
}
TERN_(PRUSA_MMU2_S_MODE, check_filament());
break;
}
}
Expand Down Expand Up @@ -437,6 +451,33 @@ void MMU2::check_version() {
}
}

static bool mmu2_not_responding() {
LCD_MESSAGEPGM(MSG_MMU2_NOT_RESPONDING);
BUZZ(100, 659);
BUZZ(200, 698);
BUZZ(100, 659);
BUZZ(300, 440);
BUZZ(100, 659);
}

#if ENABLED(PRUSA_MMU2_S_MODE)

bool MMU2::load_to_gears() {
command(MMU_CMD_C0);
manage_response(true, true);
LOOP_L_N(i, MMU2_C0_RETRY) { // Keep loading until filament reaches gears
if (mmu2s_triggered) break;
command(MMU_CMD_C0);
manage_response(true, true);
check_filament();
}
const bool success = mmu2s_triggered && can_load();
if (!success) mmu2_not_responding();
return success;
}

#endif

/**
* Handle tool change
*/
Expand All @@ -452,18 +493,15 @@ void MMU2::tool_change(uint8_t index) {
ui.status_printf_P(0, GET_TEXT(MSG_MMU2_LOADING_FILAMENT), int(index + 1));

command(MMU_CMD_T0 + index);

manage_response(true, true);

command(MMU_CMD_C0);
extruder = index; //filament change is finished
active_extruder = 0;

ENABLE_AXIS_E0();

SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder));

if (load_to_gears()) {
extruder = index; // filament change is finished
active_extruder = 0;
ENABLE_AXIS_E0();
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(STR_ACTIVE_EXTRUDER, int(extruder));
}
ui.reset_status();
}

Expand Down Expand Up @@ -500,12 +538,13 @@ void MMU2::tool_change(const char* special) {
DISABLE_AXIS_E0();
command(MMU_CMD_T0 + index);
manage_response(true, true);
command(MMU_CMD_C0);
mmu_loop();

ENABLE_AXIS_E0();
extruder = index;
active_extruder = 0;
if (load_to_gears()) {
mmu_loop();
ENABLE_AXIS_E0();
extruder = index;
active_extruder = 0;
}
} break;

case 'c': {
Expand Down Expand Up @@ -579,12 +618,7 @@ void MMU2::manage_response(const bool move_axes, const bool turn_off_nozzle) {

if (turn_off_nozzle) thermalManager.setTargetHotend(0, active_extruder);

LCD_MESSAGEPGM(MSG_MMU2_NOT_RESPONDING);
BUZZ(100, 659);
BUZZ(200, 698);
BUZZ(100, 659);
BUZZ(300, 440);
BUZZ(100, 659);
mmu2_not_responding();
}
}
else if (mmu_print_saved) {
Expand Down Expand Up @@ -632,6 +666,39 @@ void MMU2::filament_runout() {
planner.synchronize();
}

#if ENABLED(PRUSA_MMU2_S_MODE)
void MMU2::check_filament() {
const bool runout = READ(FIL_RUNOUT_PIN) ^ (FIL_RUNOUT_INVERTING);
if (runout && !mmu2s_triggered) {
DEBUG_ECHOLNPGM("MMU <= 'A'");
tx_str_P(PSTR("A\n"));
}
mmu2s_triggered = runout;
}

bool MMU2::can_load() {
execute_extruder_sequence((const E_Step *)can_load_sequence, COUNT(can_load_sequence));

int filament_detected_count = 0;
const int steps = MMU2_CAN_LOAD_RETRACT / MMU2_CAN_LOAD_INCREMENT;
DEBUG_ECHOLNPGM("MMU can_load:");
LOOP_L_N(i, steps) {
execute_extruder_sequence((const E_Step *)can_load_increment_sequence, COUNT(can_load_increment_sequence));
check_filament(); // Don't trust the idle function
DEBUG_CHAR(mmu2s_triggered ? 'O' : 'o');
if (mmu2s_triggered) ++filament_detected_count;
}

if (filament_detected_count <= steps - (MMU2_CAN_LOAD_DEVIATION / MMU2_CAN_LOAD_INCREMENT)) {
DEBUG_ECHOLNPGM(" failed.");
return false;
}

DEBUG_ECHOLNPGM(" succeeded.");
return true;
}
#endif

#if BOTH(HAS_LCD_MENU, MMU2_MENUS)

// Load filament into MMU2
Expand All @@ -656,20 +723,19 @@ void MMU2::filament_runout() {
LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
return false;
}
else {
command(MMU_CMD_T0 + index);
manage_response(true, true);
command(MMU_CMD_C0);
mmu_loop();

command(MMU_CMD_T0 + index);
manage_response(true, true);

const bool success = load_to_gears();
if (success) {
mmu_loop();
extruder = index;
active_extruder = 0;

load_to_nozzle();

BUZZ(200, 404);
return true;
}
return success;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions Marlin/src/feature/mmu2/mmu2.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,17 @@ class MMU2 {

static void filament_runout();

#if ENABLED(PRUSA_MMU2_S_MODE)
static bool mmu2s_triggered;
static void check_filament();
static bool can_load();
static bool load_to_gears();
#else
FORCE_INLINE static bool load_to_gears() { return true; }
#endif

static bool enabled, ready, mmu_print_saved;

static uint8_t cmd, cmd_arg, last_cmd, extruder;
static int8_t state;
static volatile int8_t finda;
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/twibus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ bool TWIBus::request(const uint8_t bytes) {
debug(PSTR("request"), bytes);

// requestFrom() is a blocking function
if (Wire.requestFrom(addr, bytes) == 0) {
debug("request fail", addr);
if (Wire.requestFrom(I2C_ADDRESS(addr), bytes) == 0) {
debug("request fail", I2C_ADDRESS(addr));
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/feature/pause/M600.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void GcodeSuite::M600() {

#if ENABLED(HOME_BEFORE_FILAMENT_CHANGE)
// Don't allow filament change without homing first
if (axes_need_homing()) home_all_axes();
if (!all_axes_known()) home_all_axes();
#endif

#if EXTRUDERS > 1
Expand Down
6 changes: 4 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -2462,8 +2462,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#if HAS_I2C_DIGIPOT
#if BOTH(DIGIPOT_MCP4018, DIGIPOT_MCP4451)
#error "Enable only one of DIGIPOT_MCP4018 or DIGIPOT_MCP4451."
#elif !defined(DIGIPOTS_I2C_SDA_X) || !defined(DIGIPOTS_I2C_SDA_Y) || !defined(DIGIPOTS_I2C_SDA_Z) \
|| !defined(DIGIPOTS_I2C_SDA_E0) || !defined(DIGIPOTS_I2C_SDA_E1)
#elif !MB(MKS_SBASE) \
&& (!defined(DIGIPOTS_I2C_SDA_X) || !defined(DIGIPOTS_I2C_SDA_Y) || !defined(DIGIPOTS_I2C_SDA_Z) || !defined(DIGIPOTS_I2C_SDA_E0) || !defined(DIGIPOTS_I2C_SDA_E1))
#error "DIGIPOT_MCP4018/4451 requires DIGIPOTS_I2C_SDA_* pins to be defined."
#endif
#endif
Expand Down Expand Up @@ -2740,6 +2740,8 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
#error "PRUSA_MMU2 requires NOZZLE_PARK_FEATURE."
#elif EXTRUDERS != 5
#error "PRUSA_MMU2 requires EXTRUDERS = 5."
#elif ENABLED(PRUSA_MMU2_S_MODE) && DISABLED(FILAMENT_RUNOUT_SENSOR)
#error "PRUSA_MMU2_S_MODE requires FILAMENT_RUNOUT_SENSOR. Enable it to continue."
#elif DISABLED(ADVANCED_PAUSE_FEATURE)
static_assert(nullptr == strstr(MMU2_FILAMENT_RUNOUT_SCRIPT, "M600"), "ADVANCED_PAUSE_FEATURE is required to use M600 with PRUSA_MMU2.");
#endif
Expand Down
Loading

0 comments on commit 008067a

Please sign in to comment.