From e402593d1c3cf7bbafd0c54d9d9eeb84b3669d56 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Sun, 14 Feb 2021 07:51:20 +0100 Subject: [PATCH] Fix for #230, added $LIM command --- .gitattributes | 3 +- drivers/ESP32/grbl/grbl.h | 2 +- drivers/ESP32/grbl/limits.c | 51 +- drivers/ESP32/grbl/motion_control.c | 2 + drivers/ESP32/grbl/report.c | 36 +- drivers/ESP32/grbl/report.h | 1 + drivers/ESP32/grbl/system.c | 1 + drivers/ESP32/grbl/tool_change.c | 4 +- .../IMXRT1062/grblHAL_Teensy4/src/driver.c | 60 +- .../IMXRT1062/grblHAL_Teensy4/src/grbl/grbl.h | 2 +- .../grblHAL_Teensy4/src/grbl/limits.c | 51 +- .../grblHAL_Teensy4/src/grbl/motion_control.c | 2 + .../grblHAL_Teensy4/src/grbl/report.c | 36 +- .../grblHAL_Teensy4/src/grbl/report.h | 1 + .../grblHAL_Teensy4/src/grbl/system.c | 1 + drivers/LPC1769/src/grbl/grbl.h | 2 +- drivers/LPC1769/src/grbl/limits.c | 51 +- drivers/LPC1769/src/grbl/motion_control.c | 2 + drivers/LPC1769/src/grbl/report.c | 36 +- drivers/LPC1769/src/grbl/report.h | 1 + drivers/LPC1769/src/grbl/system.c | 1 + drivers/MSP430F5529/grbl/grbl.h | 2 +- drivers/MSP430F5529/grbl/limits.c | 51 +- drivers/MSP430F5529/grbl/motion_control.c | 2 + drivers/MSP430F5529/grbl/report.c | 36 +- drivers/MSP430F5529/grbl/report.h | 1 + drivers/MSP430F5529/grbl/system.c | 1 + drivers/MSP430F5529/grbl/tool_change.c | 4 +- drivers/MSP432/driver.c | 12 +- drivers/MSP432/grbl/grbl.h | 2 +- drivers/MSP432/grbl/limits.c | 51 +- drivers/MSP432/grbl/motion_control.c | 2 + drivers/MSP432/grbl/report.c | 36 +- drivers/MSP432/grbl/report.h | 1 + drivers/MSP432/grbl/system.c | 1 + drivers/MSP432/grbl/tool_change.c | 4 +- drivers/MSP432/i2c.c | 6 +- drivers/MSP432E401Y/grbl/grbl.h | 2 +- drivers/MSP432E401Y/grbl/limits.c | 51 +- drivers/MSP432E401Y/grbl/motion_control.c | 2 + drivers/MSP432E401Y/grbl/report.c | 36 +- drivers/MSP432E401Y/grbl/report.h | 1 + drivers/MSP432E401Y/grbl/system.c | 1 + drivers/MSP432E401Y/grbl/tool_change.c | 4 +- drivers/PSoC5/grbl/grbl.h | 2 +- drivers/PSoC5/grbl/limits.c | 51 +- drivers/PSoC5/grbl/motion_control.c | 2 + drivers/PSoC5/grbl/report.c | 36 +- drivers/PSoC5/grbl/report.h | 1 + drivers/PSoC5/grbl/system.c | 1 + drivers/PSoC5/grbl/tool_change.c | 4 +- .../.cortex-debug.peripherals.state.json | 1 + .../.cortex-debug.registers.state.json | 1 + drivers/RP2040/.vscode/launch.json | 27 + drivers/RP2040/.vscode/settings.json | 4 + drivers/RP2040/eeprom/eeprom.h | 29 + drivers/RP2040/eeprom/eeprom_24AAxxx.c | 123 ++++ drivers/RP2040/eeprom/eeprom_24LC16B.c | 120 ++++ drivers/RP2040/grbl/grbl.h | 2 +- drivers/RP2040/grbl/limits.c | 51 +- drivers/RP2040/grbl/motion_control.c | 2 + drivers/RP2040/grbl/report.c | 36 +- drivers/RP2040/grbl/report.h | 1 + drivers/RP2040/grbl/system.c | 1 + drivers/RP2040/grbl/tool_change.c | 4 +- drivers/RP2040/sdcard/sdcard.c | 645 ++++++++++++++++++ drivers/RP2040/sdcard/sdcard.h | 65 ++ drivers/SAM3X8E/grblHAL_Due/src/driver.c | 111 ++- drivers/SAM3X8E/grblHAL_Due/src/grbl/grbl.h | 2 +- drivers/SAM3X8E/grblHAL_Due/src/grbl/limits.c | 51 +- .../grblHAL_Due/src/grbl/motion_control.c | 2 + drivers/SAM3X8E/grblHAL_Due/src/grbl/report.c | 36 +- drivers/SAM3X8E/grblHAL_Due/src/grbl/report.h | 1 + drivers/SAM3X8E/grblHAL_Due/src/grbl/system.c | 1 + .../SAMD21/grblHAL_MKRZERO/src/grbl/grbl.h | 2 +- .../SAMD21/grblHAL_MKRZERO/src/grbl/limits.c | 51 +- .../grblHAL_MKRZERO/src/grbl/motion_control.c | 2 + .../SAMD21/grblHAL_MKRZERO/src/grbl/report.c | 36 +- .../SAMD21/grblHAL_MKRZERO/src/grbl/report.h | 1 + .../SAMD21/grblHAL_MKRZERO/src/grbl/system.c | 1 + .../grblHAL_MKRZERO/src/grbl/tool_change.c | 4 +- drivers/STM32F1xx/grbl/grbl.h | 2 +- drivers/STM32F1xx/grbl/limits.c | 51 +- drivers/STM32F1xx/grbl/motion_control.c | 2 + drivers/STM32F1xx/grbl/report.c | 36 +- drivers/STM32F1xx/grbl/report.h | 1 + drivers/STM32F1xx/grbl/system.c | 1 + drivers/STM32F1xx/grbl/tool_change.c | 4 +- drivers/STM32F3xx/grbl/grbl.h | 2 +- drivers/STM32F3xx/grbl/limits.c | 51 +- drivers/STM32F3xx/grbl/motion_control.c | 2 + drivers/STM32F3xx/grbl/report.c | 36 +- drivers/STM32F3xx/grbl/report.h | 1 + drivers/STM32F3xx/grbl/system.c | 1 + drivers/STM32F3xx/grbl/tool_change.c | 4 +- drivers/STM32F4xx/grbl/grbl.h | 2 +- drivers/STM32F4xx/grbl/limits.c | 51 +- drivers/STM32F4xx/grbl/motion_control.c | 2 + drivers/STM32F4xx/grbl/report.c | 36 +- drivers/STM32F4xx/grbl/report.h | 1 + drivers/STM32F4xx/grbl/system.c | 1 + drivers/STM32F4xx/grbl/tool_change.c | 4 +- drivers/Simulator/grbl/grbl.h | 2 +- drivers/Simulator/grbl/limits.c | 51 +- drivers/Simulator/grbl/motion_control.c | 2 + drivers/Simulator/grbl/report.c | 36 +- drivers/Simulator/grbl/report.h | 1 + drivers/Simulator/grbl/system.c | 1 + drivers/Simulator/grbl/tool_change.c | 4 +- drivers/TM4C123/grbl/grbl.h | 2 +- drivers/TM4C123/grbl/limits.c | 51 +- drivers/TM4C123/grbl/motion_control.c | 2 + drivers/TM4C123/grbl/report.c | 36 +- drivers/TM4C123/grbl/report.h | 1 + drivers/TM4C123/grbl/system.c | 1 + drivers/TM4C123/grbl/tool_change.c | 4 +- drivers/TM4C129/grbl/grbl.h | 2 +- drivers/TM4C129/grbl/limits.c | 51 +- drivers/TM4C129/grbl/motion_control.c | 2 + drivers/TM4C129/grbl/report.c | 36 +- drivers/TM4C129/grbl/report.h | 1 + drivers/TM4C129/grbl/system.c | 1 + drivers/TM4C129/grbl/tool_change.c | 4 +- grbl/grbl.h | 2 +- grbl/limits.c | 51 +- grbl/motion_control.c | 2 + grbl/report.c | 36 +- grbl/report.h | 1 + grbl/system.c | 1 + 129 files changed, 2216 insertions(+), 624 deletions(-) create mode 100644 drivers/RP2040/.vscode/.cortex-debug.peripherals.state.json create mode 100644 drivers/RP2040/.vscode/.cortex-debug.registers.state.json create mode 100644 drivers/RP2040/.vscode/launch.json create mode 100644 drivers/RP2040/.vscode/settings.json create mode 100644 drivers/RP2040/eeprom/eeprom.h create mode 100644 drivers/RP2040/eeprom/eeprom_24AAxxx.c create mode 100644 drivers/RP2040/eeprom/eeprom_24LC16B.c create mode 100644 drivers/RP2040/sdcard/sdcard.c create mode 100644 drivers/RP2040/sdcard/sdcard.h diff --git a/.gitattributes b/.gitattributes index bdb0cabc..eb84b66b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ # Auto detect text files and perform LF normalization -* text=auto +* text=auto eol=lf + # Custom for Visual Studio *.cs diff=csharp diff --git a/drivers/ESP32/grbl/grbl.h b/drivers/ESP32/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/ESP32/grbl/grbl.h +++ b/drivers/ESP32/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/ESP32/grbl/limits.c b/drivers/ESP32/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/ESP32/grbl/limits.c +++ b/drivers/ESP32/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/ESP32/grbl/motion_control.c b/drivers/ESP32/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/ESP32/grbl/motion_control.c +++ b/drivers/ESP32/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/ESP32/grbl/report.c b/drivers/ESP32/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/ESP32/grbl/report.c +++ b/drivers/ESP32/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/ESP32/grbl/report.h b/drivers/ESP32/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/ESP32/grbl/report.h +++ b/drivers/ESP32/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/ESP32/grbl/system.c b/drivers/ESP32/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/ESP32/grbl/system.c +++ b/drivers/ESP32/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/ESP32/grbl/tool_change.c b/drivers/ESP32/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/ESP32/grbl/tool_change.c +++ b/drivers/ESP32/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/IMXRT1062/grblHAL_Teensy4/src/driver.c b/drivers/IMXRT1062/grblHAL_Teensy4/src/driver.c index 52b51abe..982fde21 100644 --- a/drivers/IMXRT1062/grblHAL_Teensy4/src/driver.c +++ b/drivers/IMXRT1062/grblHAL_Teensy4/src/driver.c @@ -878,21 +878,21 @@ inline static limit_signals_t limitsGetState() { limit_signals_t signals = {0}; - signals.min.mask = signals.max.mask = settings.limits.invert.mask; + signals.min.mask = signals.min2.mask = settings.limits.invert.mask; signals.min.x = (LimitX.reg->DR & LimitX.bit) != 0; #ifdef X2_LIMIT_PIN - signals.max.x = (LimitX2.reg->DR & LimitX2.bit) != 0; + signals.min2.x = (LimitX2.reg->DR & LimitX2.bit) != 0; #endif signals.min.y = (LimitY.reg->DR & LimitY.bit) != 0; #ifdef Y2_LIMIT_PIN - signals.max.y = (LimitY2.reg->DR & LimitY2.bit) != 0; + signals.min2.y = (LimitY2.reg->DR & LimitY2.bit) != 0; #endif signals.min.z = (LimitZ.reg->DR & LimitZ.bit) != 0; #ifdef Z2_LIMIT_PIN - signals.max.z = (LimitZ2.reg->DR & LimitZ2.bit) != 0; + signals.min2.z = (LimitZ2.reg->DR & LimitZ2.bit) != 0; #endif #ifdef A_LIMIT_PIN @@ -907,7 +907,7 @@ inline static limit_signals_t limitsGetState() if(settings.limits.invert.mask) { signals.min.value ^= settings.limits.invert.mask; - signals.max.value ^= settings.limits.invert.mask; + signals.min2.value ^= settings.limits.invert.mask; } return signals; @@ -972,50 +972,6 @@ static void StepperDisableMotors (axes_signals_t axes, squaring_mode_t mode) motors_2.mask = (mode == SquaringMode_B || mode == SquaringMode_Both ? axes.mask : 0) ^ AXES_BITMASK; } -// Returns limit state as an axes_signals_t variable. -// Each bitfield bit indicates an axis limit, where triggered is 1 and not triggered is 0. -static limit_signals_t limitsGetHomeState() -{ - limit_signals_t signals = {0}; - - if(motors_1.mask) { - - signals.min.mask = settings.limits.invert.mask; - - if(motors_1.x) - signals.min.x = (LimitX.reg->DR & LimitX.bit) != 0; - if(motors_1.y) - signals.min.y = (LimitY.reg->DR & LimitY.bit) != 0; - if(motors_1.z) - signals.min.z = (LimitZ.reg->DR & LimitZ.bit) != 0; - - if (settings.limits.invert.mask) - signals.min.mask ^= settings.limits.invert.mask; - } - - if(motors_2.mask) { - - signals.max.mask = settings.limits.invert.mask; - -#ifdef X2_LIMIT_PIN - if(motors_2.x) - signals.max.x = (LimitX2.reg->DR & LimitX2.bit) != 0; -#endif -#ifdef Y2_LIMIT_PIN - if(motors_2.y) - signals.max.y = (LimitY2.reg->DR & LimitY2.bit) != 0; -#endif -#ifdef Z2_LIMIT_PIN - if(motors_2.z) - signals.max.z = (LimitZ2.reg->DR & LimitZ2.bit) != 0; -#endif - if (settings.limits.invert.mask) - signals.max.mask ^= settings.limits.invert.mask; - } - - return signals; -} - #endif // Enable/disable limit pins interrupt. @@ -1036,10 +992,6 @@ static void limitsEnable (bool on, bool homing) inputpin[i].gpio.reg->IMR &= ~inputpin[i].gpio.bit; // Disable interrupt. } } while(i); - -#ifdef SQUARING_ENABLED - hal.homing.get_state = homing ? limitsGetHomeState : limitsGetState; -#endif } // Returns system state as a control_signals_t bitmap variable. @@ -2130,7 +2082,7 @@ bool driver_init (void) options[strlen(options) - 1] = '\0'; hal.info = "iMXRT1062"; - hal.driver_version = "210212"; + hal.driver_version = "210214"; #ifdef BOARD_NAME hal.board = BOARD_NAME; #endif diff --git a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/grbl.h b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/grbl.h +++ b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/limits.c b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/limits.c +++ b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/motion_control.c b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/motion_control.c +++ b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/report.c b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/report.c +++ b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/report.h b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/report.h +++ b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/system.c b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/system.c +++ b/drivers/IMXRT1062/grblHAL_Teensy4/src/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/LPC1769/src/grbl/grbl.h b/drivers/LPC1769/src/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/LPC1769/src/grbl/grbl.h +++ b/drivers/LPC1769/src/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/LPC1769/src/grbl/limits.c b/drivers/LPC1769/src/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/LPC1769/src/grbl/limits.c +++ b/drivers/LPC1769/src/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/LPC1769/src/grbl/motion_control.c b/drivers/LPC1769/src/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/LPC1769/src/grbl/motion_control.c +++ b/drivers/LPC1769/src/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/LPC1769/src/grbl/report.c b/drivers/LPC1769/src/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/LPC1769/src/grbl/report.c +++ b/drivers/LPC1769/src/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/LPC1769/src/grbl/report.h b/drivers/LPC1769/src/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/LPC1769/src/grbl/report.h +++ b/drivers/LPC1769/src/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/LPC1769/src/grbl/system.c b/drivers/LPC1769/src/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/LPC1769/src/grbl/system.c +++ b/drivers/LPC1769/src/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/MSP430F5529/grbl/grbl.h b/drivers/MSP430F5529/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/MSP430F5529/grbl/grbl.h +++ b/drivers/MSP430F5529/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/MSP430F5529/grbl/limits.c b/drivers/MSP430F5529/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/MSP430F5529/grbl/limits.c +++ b/drivers/MSP430F5529/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/MSP430F5529/grbl/motion_control.c b/drivers/MSP430F5529/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/MSP430F5529/grbl/motion_control.c +++ b/drivers/MSP430F5529/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/MSP430F5529/grbl/report.c b/drivers/MSP430F5529/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/MSP430F5529/grbl/report.c +++ b/drivers/MSP430F5529/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/MSP430F5529/grbl/report.h b/drivers/MSP430F5529/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/MSP430F5529/grbl/report.h +++ b/drivers/MSP430F5529/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/MSP430F5529/grbl/system.c b/drivers/MSP430F5529/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/MSP430F5529/grbl/system.c +++ b/drivers/MSP430F5529/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/MSP430F5529/grbl/tool_change.c b/drivers/MSP430F5529/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/MSP430F5529/grbl/tool_change.c +++ b/drivers/MSP430F5529/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/MSP432/driver.c b/drivers/MSP432/driver.c index 44906a5f..eb444a21 100644 --- a/drivers/MSP432/driver.c +++ b/drivers/MSP432/driver.c @@ -207,7 +207,7 @@ inline __attribute__((always_inline)) static void set_dir_outputs (axes_signals_ static void stepperEnable (axes_signals_t enable) { enable.value ^= settings.steppers.enable_invert.mask; -#if TRINAMIC_ENABLE == 2130 && TRINAMIC_I2C +#if TRINAMIC_ENABLE && TRINAMIC_I2C axes_signals_t tmc_enable = trinamic_stepper_enable(enable); #if !CNC_BOOSTERPACK // Trinamic BoosterPack does not support mixed drivers if(!tmc_enable.z) @@ -420,7 +420,7 @@ static void limitsEnable (bool on, bool homing) BITBAND_PERI(LIMIT_PORT_Z->IE, Z_LIMIT_PIN) = on; #endif -#if TRINAMIC_ENABLE == 2130 +#if TRINAMIC_ENABLE trinamic_homing(homing); #endif } @@ -1199,7 +1199,7 @@ static bool driver_setup (settings_t *settings) STEP_PORT->DIR |= STEP_MASK; DIRECTION_PORT->DIR |= DIRECTION_MASK; -#if !(TRINAMIC_ENABLE == 2130 && TRINAMIC_I2C) +#if !(TRINAMIC_ENABLE && TRINAMIC_I2C) STEPPERS_DISABLE_Z_PORT->DIR |= STEPPERS_DISABLE_Z_BIT; STEPPERS_DISABLE_XY_PORT->DIR |= STEPPERS_DISABLE_X_BIT; #endif @@ -1515,7 +1515,7 @@ bool driver_init (void) serial2Init(19200); #endif -#if TRINAMIC_ENABLE == 2130 +#if TRINAMIC_ENABLE trinamic_init(); #endif @@ -1778,7 +1778,7 @@ void KEYPAD_IRQHandler (void) KEYPAD_PORT->IFG &= ~iflags; -#elif TRINAMIC_ENABLE == 2130 && TRINAMIC_I2C +#elif TRINAMIC_ENABLE && TRINAMIC_I2C void TRINAMIC_DIAG_IRQHandler (void) { @@ -1800,7 +1800,7 @@ void TRINAMIC_DIAG_IRQHandler (void) } #endif -#if KEYPAD_ENABLE || (TRINAMIC_ENABLE == 2130 && TRINAMIC_I2C) +#if KEYPAD_ENABLE || (TRINAMIC_ENABLE && TRINAMIC_I2C) } #endif diff --git a/drivers/MSP432/grbl/grbl.h b/drivers/MSP432/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/MSP432/grbl/grbl.h +++ b/drivers/MSP432/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/MSP432/grbl/limits.c b/drivers/MSP432/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/MSP432/grbl/limits.c +++ b/drivers/MSP432/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/MSP432/grbl/motion_control.c b/drivers/MSP432/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/MSP432/grbl/motion_control.c +++ b/drivers/MSP432/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/MSP432/grbl/report.c b/drivers/MSP432/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/MSP432/grbl/report.c +++ b/drivers/MSP432/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/MSP432/grbl/report.h b/drivers/MSP432/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/MSP432/grbl/report.h +++ b/drivers/MSP432/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/MSP432/grbl/system.c b/drivers/MSP432/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/MSP432/grbl/system.c +++ b/drivers/MSP432/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/MSP432/grbl/tool_change.c b/drivers/MSP432/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/MSP432/grbl/tool_change.c +++ b/drivers/MSP432/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/MSP432/i2c.c b/drivers/MSP432/i2c.c index d76da3e8..6acc41cc 100644 --- a/drivers/MSP432/i2c.c +++ b/drivers/MSP432/i2c.c @@ -254,14 +254,14 @@ TMC_spi_status_t tmc_spi_read (trinamic_motor_t driver, TMC_spi_datagram_t *data TMC_spi_status_t status = 0; if(driver.axis != axis) { - i2c.buffer[0] = driver.axis; + i2c.buffer[0] = driver.axis | 0x80; I2C_Send(I2C_ADR_I2CBRIDGE, 1, true); axis = driver.axis; } memset(i2c.buffer, 0, sizeof(i2c.buffer)); - + i2c.buffer[0] = datagram->addr.idx; res = I2C_ReadRegister(I2C_ADR_I2CBRIDGE, 5, true); status = (uint8_t)*res++; @@ -280,7 +280,7 @@ TMC_spi_status_t tmc_spi_write (trinamic_motor_t driver, TMC_spi_datagram_t *dat while(i2cIsBusy); if(driver.axis != axis) { - i2c.buffer[0] = driver.axis; + i2c.buffer[0] = driver.axis | 0x80; I2C_Send(I2C_ADR_I2CBRIDGE, 1, true); while(i2cIsBusy); diff --git a/drivers/MSP432E401Y/grbl/grbl.h b/drivers/MSP432E401Y/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/MSP432E401Y/grbl/grbl.h +++ b/drivers/MSP432E401Y/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/MSP432E401Y/grbl/limits.c b/drivers/MSP432E401Y/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/MSP432E401Y/grbl/limits.c +++ b/drivers/MSP432E401Y/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/MSP432E401Y/grbl/motion_control.c b/drivers/MSP432E401Y/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/MSP432E401Y/grbl/motion_control.c +++ b/drivers/MSP432E401Y/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/MSP432E401Y/grbl/report.c b/drivers/MSP432E401Y/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/MSP432E401Y/grbl/report.c +++ b/drivers/MSP432E401Y/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/MSP432E401Y/grbl/report.h b/drivers/MSP432E401Y/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/MSP432E401Y/grbl/report.h +++ b/drivers/MSP432E401Y/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/MSP432E401Y/grbl/system.c b/drivers/MSP432E401Y/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/MSP432E401Y/grbl/system.c +++ b/drivers/MSP432E401Y/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/MSP432E401Y/grbl/tool_change.c b/drivers/MSP432E401Y/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/MSP432E401Y/grbl/tool_change.c +++ b/drivers/MSP432E401Y/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/PSoC5/grbl/grbl.h b/drivers/PSoC5/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/PSoC5/grbl/grbl.h +++ b/drivers/PSoC5/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/PSoC5/grbl/limits.c b/drivers/PSoC5/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/PSoC5/grbl/limits.c +++ b/drivers/PSoC5/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/PSoC5/grbl/motion_control.c b/drivers/PSoC5/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/PSoC5/grbl/motion_control.c +++ b/drivers/PSoC5/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/PSoC5/grbl/report.c b/drivers/PSoC5/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/PSoC5/grbl/report.c +++ b/drivers/PSoC5/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/PSoC5/grbl/report.h b/drivers/PSoC5/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/PSoC5/grbl/report.h +++ b/drivers/PSoC5/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/PSoC5/grbl/system.c b/drivers/PSoC5/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/PSoC5/grbl/system.c +++ b/drivers/PSoC5/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/PSoC5/grbl/tool_change.c b/drivers/PSoC5/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/PSoC5/grbl/tool_change.c +++ b/drivers/PSoC5/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/RP2040/.vscode/.cortex-debug.peripherals.state.json b/drivers/RP2040/.vscode/.cortex-debug.peripherals.state.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/drivers/RP2040/.vscode/.cortex-debug.peripherals.state.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/drivers/RP2040/.vscode/.cortex-debug.registers.state.json b/drivers/RP2040/.vscode/.cortex-debug.registers.state.json new file mode 100644 index 00000000..0637a088 --- /dev/null +++ b/drivers/RP2040/.vscode/.cortex-debug.registers.state.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/drivers/RP2040/.vscode/launch.json b/drivers/RP2040/.vscode/launch.json new file mode 100644 index 00000000..461bbc6c --- /dev/null +++ b/drivers/RP2040/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Pico Debug", + "cwd": "${workspaceRoot}", + "executable": "${command:cmake.launchTargetPath}", + "request": "launch", + "type": "cortex-debug", + "servertype": "openocd", + // This may need to be arm-none-eabi-gdb depending on your system + "gdbPath" : "gdb-multiarch", + "device": "RP2040", + "configFiles": [ + "interface/raspberrypi-swd.cfg", + "target/rp2040.cfg" + ], + "svdFile": "${env:PICO_SDK_PATH}/src/rp2040/hardware_regs/rp2040.svd", + "runToMain": true, + // Work around for stopping at main on restart + "postRestartCommands": [ + "break main", + "continue" + ] + } + ] +} diff --git a/drivers/RP2040/.vscode/settings.json b/drivers/RP2040/.vscode/settings.json new file mode 100644 index 00000000..d1941d08 --- /dev/null +++ b/drivers/RP2040/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", + "editor.fontSize": 12 +} \ No newline at end of file diff --git a/drivers/RP2040/eeprom/eeprom.h b/drivers/RP2040/eeprom/eeprom.h new file mode 100644 index 00000000..5e07fec2 --- /dev/null +++ b/drivers/RP2040/eeprom/eeprom.h @@ -0,0 +1,29 @@ +/* + + eeprom.h - plugin for for I2C EEPROM or FRAM + + Part of grblHAL + + Copyright (c) 2017-2020 Terje Io + + Grbl is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Grbl is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Grbl. If not, see . + +*/ + +#ifndef _EEPROM_H_ +#define _EEPROM_H_ + +void i2c_eeprom_init (void); + +#endif diff --git a/drivers/RP2040/eeprom/eeprom_24AAxxx.c b/drivers/RP2040/eeprom/eeprom_24AAxxx.c new file mode 100644 index 00000000..8f3fbb0e --- /dev/null +++ b/drivers/RP2040/eeprom/eeprom_24AAxxx.c @@ -0,0 +1,123 @@ +/* + + eeprom_24AAxxx.c - plugin for for I2C EEPROM (Microchip 24AAxxx > 16kbit, 2 byte address) + + NOTE: only tested with 24AA256 + + Part of grblHAL + + Copyright (c) 2020 Terje Io + + Grbl is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Grbl is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Grbl. If not, see . + +*/ + +#include "driver.h" + +#if EEPROM_ENABLE >= 2 + +#include "grbl/hal.h" +#include "grbl/nuts_bolts.h" + +#define EEPROM_I2C_ADDRESS (0xA0 >> 1) +#if EEPROM_ENABLE == 2 +#define EEPROM_PAGE_SIZE 64 +#else +#define EEPROM_PAGE_SIZE 32 +#endif + +static nvs_transfer_t i2c = { .word_addr_bytes = 2 }; + +static uint8_t getByte (uint32_t addr) +{ + uint8_t value = 0; + + i2c.address = EEPROM_I2C_ADDRESS; + i2c.word_addr = addr; + i2c.data = &value; + i2c.count = 1; + + i2c_nvs_transfer(&i2c, true); + + return value; +} + +static void putByte (uint32_t addr, uint8_t new_value) +{ + i2c.address = EEPROM_I2C_ADDRESS; + i2c.word_addr = addr; + i2c.data = &new_value; + i2c.count = 1; + + i2c_nvs_transfer(&i2c, false); +} + +static nvs_transfer_result_t writeBlock (uint32_t destination, uint8_t *source, uint32_t size, bool with_checksum) +{ + uint32_t remaining = size; + uint8_t *target = source; + + while(remaining > 0) { + i2c.address = EEPROM_I2C_ADDRESS; + i2c.word_addr = destination; + i2c.count = EEPROM_PAGE_SIZE - (destination & (EEPROM_PAGE_SIZE - 1)); + i2c.count = remaining < i2c.count ? remaining : i2c.count; + i2c.data = target; + remaining -= i2c.count; + target += i2c.count; + destination += i2c.count; + + i2c_nvs_transfer(&i2c, false); + } + + if(size > 0 && with_checksum) + putByte(destination, calc_checksum(source, size)); + + return NVS_TransferResult_OK; +} + +static nvs_transfer_result_t readBlock (uint8_t *destination, uint32_t source, uint32_t size, bool with_checksum) +{ + uint32_t remaining = size; + uint8_t *target = destination; + + while(remaining) { + i2c.address = EEPROM_I2C_ADDRESS; + i2c.word_addr = source; + i2c.count = remaining > 255 ? 255 : (uint8_t)remaining; + i2c.data = target; + remaining -= i2c.count; + target += i2c.count; + source += i2c.count; + + i2c_nvs_transfer(&i2c, true); + } + + return with_checksum ? (calc_checksum(destination, size) == getByte(source) ? NVS_TransferResult_OK : NVS_TransferResult_Failed) : NVS_TransferResult_OK; +} + +void i2c_eeprom_init (void) +{ +#if EEPROM_IS_FRAM + hal.nvs.type = NVS_FRAM; +#else + hal.nvs.type = NVS_EEPROM; +#endif + hal.nvs.get_byte = getByte; + hal.nvs.put_byte = putByte; + hal.nvs.memcpy_to_nvs = writeBlock; + hal.nvs.memcpy_from_nvs = readBlock; +} + +#endif diff --git a/drivers/RP2040/eeprom/eeprom_24LC16B.c b/drivers/RP2040/eeprom/eeprom_24LC16B.c new file mode 100644 index 00000000..da3aa7ff --- /dev/null +++ b/drivers/RP2040/eeprom/eeprom_24LC16B.c @@ -0,0 +1,120 @@ +/* + + eeprom_24LC16B.c - plugin for for I2C EEPROM (Microchip 24LC16B) + + Part of grblHAL + + Copyright (c) 2017-2020 Terje Io + + Grbl is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Grbl is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Grbl. If not, see . + +*/ + +#include "driver.h" + +#if EEPROM_ENABLE == 1 + +#include "grbl/hal.h" +#include "grbl/nuts_bolts.h" + +#define EEPROM_I2C_ADDRESS (0xA0 >> 1) +#define EEPROM_ADDR_BITS_LO 8 +#define EEPROM_BLOCK_SIZE (2 ^ EEPROM_LO_ADDR_BITS) +#define EEPROM_PAGE_SIZE 16 + +static nvs_transfer_t i2c = { .word_addr_bytes = 1 }; + +static uint8_t getByte (uint32_t addr) +{ + uint8_t value = 0; + + i2c.address = EEPROM_I2C_ADDRESS | (addr >> 8); + i2c.word_addr = addr & 0xFF; + i2c.data = &value; + i2c.count = 1; + + i2c_nvs_transfer(&i2c, true); + + return value; +} + +static void putByte (uint32_t addr, uint8_t new_value) +{ + i2c.address = EEPROM_I2C_ADDRESS | (addr >> 8); + i2c.word_addr = addr & 0xFF; + i2c.data = &new_value; + i2c.count = 1; + + i2c_nvs_transfer(&i2c, false); +} + + +static nvs_transfer_result_t writeBlock (uint32_t destination, uint8_t *source, uint32_t size, bool with_checksum) +{ + uint32_t remaining = size; + uint8_t *target = source; + + while(remaining > 0) { + i2c.address = EEPROM_I2C_ADDRESS | (destination >> EEPROM_ADDR_BITS_LO); + i2c.word_addr = destination & 0xFF; + i2c.count = EEPROM_PAGE_SIZE - (destination & (EEPROM_PAGE_SIZE - 1)); + i2c.count = remaining < i2c.count ? remaining : i2c.count; + i2c.data = target; + remaining -= i2c.count; + target += i2c.count; + destination += i2c.count; + + i2c_nvs_transfer(&i2c, false); + } + + if(size > 0 && with_checksum) + putByte(destination, calc_checksum(source, size)); + + return NVS_TransferResult_OK; +} + +static nvs_transfer_result_t readBlock (uint8_t *destination, uint32_t source, uint32_t size, bool with_checksum) +{ + uint32_t remaining = size; + uint8_t *target = destination; + + while(remaining) { + i2c.address = EEPROM_I2C_ADDRESS | (source >> 8); + i2c.word_addr = source & 0xFF; + i2c.count = remaining > 255 ? 255 : (uint8_t)remaining; + i2c.data = target; + remaining -= i2c.count; + target += i2c.count; + source += i2c.count; + + i2c_nvs_transfer(&i2c, true); + } + + return with_checksum ? (calc_checksum(destination, size) == getByte(source) ? NVS_TransferResult_OK : NVS_TransferResult_Failed) : NVS_TransferResult_OK; +} + +void i2c_eeprom_init (void) +{ +#if EEPROM_IS_FRAM + hal.nvs.type = NVS_FRAM; +#else + hal.nvs.type = NVS_EEPROM; +#endif + hal.nvs.get_byte = getByte; + hal.nvs.put_byte = putByte; + hal.nvs.memcpy_to_nvs = writeBlock; + hal.nvs.memcpy_from_nvs = readBlock; +} + +#endif diff --git a/drivers/RP2040/grbl/grbl.h b/drivers/RP2040/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/RP2040/grbl/grbl.h +++ b/drivers/RP2040/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/RP2040/grbl/limits.c b/drivers/RP2040/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/RP2040/grbl/limits.c +++ b/drivers/RP2040/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/RP2040/grbl/motion_control.c b/drivers/RP2040/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/RP2040/grbl/motion_control.c +++ b/drivers/RP2040/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/RP2040/grbl/report.c b/drivers/RP2040/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/RP2040/grbl/report.c +++ b/drivers/RP2040/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/RP2040/grbl/report.h b/drivers/RP2040/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/RP2040/grbl/report.h +++ b/drivers/RP2040/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/RP2040/grbl/system.c b/drivers/RP2040/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/RP2040/grbl/system.c +++ b/drivers/RP2040/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/RP2040/grbl/tool_change.c b/drivers/RP2040/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/RP2040/grbl/tool_change.c +++ b/drivers/RP2040/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/RP2040/sdcard/sdcard.c b/drivers/RP2040/sdcard/sdcard.c new file mode 100644 index 00000000..212a08cd --- /dev/null +++ b/drivers/RP2040/sdcard/sdcard.c @@ -0,0 +1,645 @@ +/* + sdcard.c - SDCard plugin for FatFs + + Part of grblHAL + + Copyright (c) 2018-2021 Terje Io + + Grbl is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Grbl is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Grbl. If not, see . +*/ + +#include "sdcard.h" + +#if SDCARD_ENABLE + +#include +#include +#include + +#if defined(ESP_PLATFORM) || defined(STM32_PLATFORM) || defined(__LPC17XX__) || defined(__IMXRT1062__) +#define NEW_FATFS +#endif + +#ifdef ARDUINO + #include "../grbl/report.h" + #include "../grbl/protocol.h" + #include "../grbl/state_machine.h" + #ifdef __IMXRT1062__ + #include "uSDFS.h" + #define SDCARD_DEV "1:/" + static FATFS fs; + #endif +#else + #include "grbl/report.h" + #include "grbl/protocol.h" + #include "grbl/state_machine.h" +#endif + +#ifdef __IMXRT1062__ +const char *dev = "1:/"; +#elif defined(NEW_FATFS) +const char *dev = ""; +#endif + +#ifndef SDCARD_DEV +#define SDCARD_DEV "" +#endif + +#if defined(STM32_PLATFORM) || defined(__LPC17XX__) || defined(__IMXRT1062__) +#define UINT32FMT "%lu" +#endif + +#ifndef UINT32FMT +#define UINT32FMT "%u" +#endif + +// https://e2e.ti.com/support/tools/ccs/f/81/t/428524?Linking-error-unresolved-symbols-rom-h-pinout-c- + +/* uses fatfs - http://www.elm-chan.org/fsw/ff/00index_e.html */ + +#define MAX_PATHLEN 128 +#define LCAPS(c) ((c >= 'A' && c <= 'Z') ? c | 0x20 : c) + +#if FF_USE_LFN +//#define _USE_LFN FF_USE_LFN +#define _MAX_LFN FF_MAX_LFN +#endif + +char const *const filetypes[] = { + "nc", + "gcode", + "txt", + "text", + "tap", + "ngc", + "" +}; + +static FIL cncfile; + +typedef enum { + Filename_Filtered = 0, + Filename_Valid, + Filename_Invalid +} file_status_t; + +typedef struct +{ + FATFS *fs; + FIL *handle; + char name[50]; + size_t size; + size_t pos; + uint32_t line; + uint8_t eol; +} file_t; + +static file_t file = { + .fs = NULL, + .handle = NULL, + .size = 0, + .pos = 0 +}; + +static bool frewind = false; +static io_stream_t active_stream; +static driver_reset_ptr driver_reset; +static on_report_command_help_ptr on_report_command_help; +static on_realtime_report_ptr on_realtime_report; +static on_state_change_ptr state_change_requested; +static on_program_completed_ptr on_program_completed; +static on_report_options_ptr on_report_options; + +static void sdcard_end_job (void); +static void sdcard_report (stream_write_ptr stream_write, report_tracking_flags_t report); +static void trap_state_change_request(uint_fast16_t state); +static void sdcard_on_program_completed (program_flow_t program_flow); +//static report_t active_reports; + +#ifdef __MSP432E401Y__ +/*---------------------------------------------------------*/ +/* User Provided Timer Function for FatFs module */ +/*---------------------------------------------------------*/ +/* This is a real time clock service to be called from */ +/* FatFs module. Any valid time must be returned even if */ +/* the system does not support a real time clock. */ + +DWORD fatfs_getFatTime (void) +{ + + return ((2007UL-1980) << 25) // Year = 2007 + | (6UL << 21) // Month = June + | (5UL << 16) // Day = 5 + | (11U << 11) // Hour = 11 + | (38U << 5) // Min = 38 + | (0U >> 1) // Sec = 0 + ; + +} +#endif + +static file_status_t allowed (char *filename, bool is_file) +{ + uint_fast8_t idx = 0; + char filetype[8], *ftptr; + file_status_t status = is_file ? Filename_Filtered : Filename_Valid; + + if(is_file && (ftptr = strrchr(filename, '.'))) { + ftptr++; + if(strlen(ftptr) > sizeof(filetype) - 1) + return status; + while(ftptr[idx]) { + filetype[idx] = LCAPS(ftptr[idx]); + idx++; + } + filetype[idx] = '\0'; + idx = 0; + while(status == Filename_Filtered && filetypes[idx][0]) { + if(!strcmp(filetype, filetypes[idx])) + status = Filename_Valid; + idx++;; + } + } + + if(status == Filename_Valid) { + if(strchr(filename, ' ') || + strchr(filename, CMD_STATUS_REPORT) || + strchr(filename, CMD_CYCLE_START) || + strchr(filename, CMD_FEED_HOLD)) + status = Filename_Invalid; + //TODO: check for top bit set characters + } + + return status; +} + +static inline char *get_name (FILINFO *file) +{ +#if _USE_LFN + return *file->lfname == '\0' ? file->fname : file->lfname; +#else + return file->fname; +#endif +} + +static FRESULT scan_dir (char *path, uint_fast8_t depth, char *buf) +{ +#if defined(ESP_PLATFORM) + FF_DIR dir; +#else + DIR dir; +#endif + FILINFO fno; + FRESULT res; + file_status_t status; + bool subdirs = false; +#if _USE_LFN + static TCHAR lfn[_MAX_LFN + 1]; /* Buffer to store the LFN */ + fno.lfname = lfn; + fno.lfsize = sizeof(lfn); +#endif + + if((res = f_opendir(&dir, path)) != FR_OK) + return res; + + // Pass 1: Scan files + while(true) { + + if((res = f_readdir(&dir, &fno)) != FR_OK || fno.fname[0] == '\0') + break; + + subdirs |= fno.fattrib & AM_DIR; + + if(!(fno.fattrib & AM_DIR) && (status = allowed(get_name(&fno), true)) != Filename_Filtered) { + sprintf(buf, "[FILE:%s/%s|SIZE:" UINT32FMT "%s]" ASCII_EOL, path, get_name(&fno), (uint32_t)fno.fsize, status == Filename_Invalid ? "|UNUSABLE" : ""); + hal.stream.write(buf); + } + } + + if((subdirs = (subdirs && --depth))) + f_readdir(&dir, NULL); // Rewind + + // Pass 2: Scan directories + while(subdirs) { + + if((res = f_readdir(&dir, &fno)) != FR_OK || fno.fname[0] == '\0') + break; + + if(fno.fattrib & AM_DIR) { // It is a directory + size_t pathlen = strlen(path); + if(pathlen + strlen(get_name(&fno)) > (MAX_PATHLEN - 1)) + break; + sprintf(&path[pathlen], "/%s", get_name(&fno)); + if((res = scan_dir(path, depth, buf)) != FR_OK) + break; + path[pathlen] = '\0'; + } + } + +#ifdef NEW_FATFS + f_closedir(&dir); +#endif + + return res; +} + +static void file_close (void) +{ + if(file.handle) { + f_close(file.handle); + file.handle = NULL; + } +} + +static bool file_open (char *filename) +{ + if(file.handle) + file_close(); + + if(f_open(&cncfile, filename, FA_READ) == FR_OK) { + file.handle = &cncfile; + file.size = f_size(file.handle); + file.pos = 0; + file.line = 0; + file.eol = false; + char *leafname = strrchr(filename, '/'); + strncpy(file.name, leafname ? leafname + 1 : filename, sizeof(file.name)); + file.name[sizeof(file.name) - 1] = '\0'; + } + + return file.handle != NULL; +} + +static int16_t file_read (void) +{ + signed char c; + UINT count; + + if(f_read(file.handle, &c, 1, &count) == FR_OK && count == 1) + file.pos = f_tell(file.handle); + else + c = -1; + + if(c == '\r' || c == '\n') + file.eol++; + else + file.eol = 0; + + return (int16_t)c; +} + +static bool sdcard_mount (void) +{ +#ifdef __MSP432E401Y__ + return SDFatFS_open(Board_SDFatFS0, 0) != NULL; +#else + if(file.fs == NULL) + #ifdef __IMXRT1062__ + file.fs = &fs; + #else + file.fs = malloc(sizeof(FATFS)); + #endif + + #ifdef NEW_FATFS + if(file.fs && f_mount(file.fs, dev, 1) != FR_OK) { + #else + if(file.fs && f_mount(0, file.fs) != FR_OK) { + #endif + #ifndef __IMXRT1062__ + free(file.fs); + #endif + file.fs = NULL; + } + #if defined(__IMXRT1062__) + else if(f_chdrive(dev) != FR_OK) + file.fs = NULL; + #endif + + return file.fs != NULL; +#endif +} + +static status_code_t sdcard_ls (void) +{ + char path[MAX_PATHLEN] = "", name[80]; // NB! also used as work area when recursing directories + + return scan_dir(path, 10, name) == FR_OK ? Status_OK : Status_SDFailedOpenDir; +} + +static void sdcard_end_job (void) +{ + file_close(); + + if(grbl.on_realtime_report == sdcard_report) + grbl.on_realtime_report = on_realtime_report; + + if(grbl.on_program_completed == sdcard_on_program_completed) + grbl.on_program_completed = on_program_completed; + + if(grbl.on_state_change == trap_state_change_request) + grbl.on_state_change = state_change_requested; + + memcpy(&hal.stream, &active_stream, sizeof(io_stream_t)); // Restore stream pointers + hal.stream.reset_read_buffer(); // and flush input buffer + on_realtime_report = NULL; + state_change_requested = NULL; + + report_init_fns(); + + frewind = false; +} + +static int16_t sdcard_read (void) +{ + int16_t c = -1; + sys_state_t state = state_get(); + + if(file.eol == 1) + file.line++; + + if(file.handle) { + + if(state == STATE_IDLE || (state & (STATE_CYCLE|STATE_HOLD|STATE_CHECK_MODE))) + c = file_read(); + + if(c == -1) { // EOF or error reading or grbl problem + file_close(); + if(file.eol == 0) // Return newline if line was incorrectly terminated + c = '\n'; + } + + } else if(state == STATE_IDLE) // TODO: end on ok count match line count? + sdcard_end_job(); + + return c; +} + +static int16_t await_cycle_start (void) +{ + return -1; +} + +// Drop input from current stream except realtime commands +static ISR_CODE bool drop_input_stream (char c) +{ + active_stream.enqueue_realtime_command(c); + + return true; +} + +static void trap_state_change_request (sys_state_t state) +{ + if(state == STATE_CYCLE) { + + if(hal.stream.read == await_cycle_start) + hal.stream.read = sdcard_read; + + if(grbl.on_state_change== trap_state_change_request) { + grbl.on_state_change = state_change_requested; + state_change_requested = NULL; + } + } + + if(state_change_requested) + state_change_requested(state); +} + +static status_code_t trap_status_report (status_code_t status_code) +{ + if(status_code != Status_OK) { // TODO: all errors should terminate job? + char buf[50]; // TODO: check if extended error reports are permissible + sprintf(buf, "error:%d in SD file at line " UINT32FMT ASCII_EOL, (uint8_t)status_code, file.line); + hal.stream.write(buf); + sdcard_end_job(); + } + + return status_code; +} + +static void sdcard_report (stream_write_ptr stream_write, report_tracking_flags_t report) +{ + if(hal.stream.read != await_cycle_start) { + char *pct_done = ftoa((float)file.pos / (float)file.size * 100.0f, 1); + + if(state_get() != STATE_IDLE && !strncmp(pct_done, "100.0", 5)) + strcpy(pct_done, "99.9"); + + stream_write("|SD:"); + stream_write(pct_done); + stream_write(","); + stream_write(file.name); + } + + if(on_realtime_report) + on_realtime_report(stream_write, report); +} + +static void sdcard_restart_msg (sys_state_t state) +{ + report_feedback_message(Message_CycleStartToRerun); +} + +static void sdcard_on_program_completed (program_flow_t program_flow) +{ + frewind = frewind || program_flow == ProgramFlow_CompletedM2; // || program_flow == ProgramFlow_CompletedM30; + + if(frewind) { + f_lseek(file.handle, 0); + file.pos = file.line = 0; + file.eol = false; + hal.stream.read = await_cycle_start; + if(grbl.on_state_change != trap_state_change_request) { + state_change_requested = grbl.on_state_change; + grbl.on_state_change = trap_state_change_request; + } + protocol_enqueue_rt_command(sdcard_restart_msg); + } else + sdcard_end_job(); + + if(on_program_completed) + on_program_completed(program_flow); +} + +#if M6_ENABLE + +static bool sdcard_suspend (bool suspend) +{ + if(suspend) { + hal.stream.reset_read_buffer(); + hal.stream.read = active_stream.read; // Restore normal stream input for tool change (jog etc) + hal.stream.enqueue_realtime_command = active_stream.enqueue_realtime_command; + grbl.report.status_message = report_status_message; // as well as normal status messages reporting + } else { + hal.stream.read = sdcard_read; // Resume reading from SD card + hal.stream.enqueue_realtime_command = drop_input_stream; + grbl.report.status_message = trap_status_report; // and redirect status messages back to us + } + + return true; +} +#endif + +static status_code_t sd_cmd_file (sys_state_t state, char *args) +{ + status_code_t retval = Status_Unhandled; + + if(args) { + if (!(state == STATE_IDLE || state == STATE_CHECK_MODE)) + retval = Status_SystemGClock; + else { + if(file_open(args)) { + gc_state.last_error = Status_OK; // Start with no errors + grbl.report.status_message(Status_OK); // and confirm command to originator + memcpy(&active_stream, &hal.stream, sizeof(io_stream_t)); // Save current stream pointers + hal.stream.type = StreamType_SDCard; // then redirect to read from SD card instead + hal.stream.read = sdcard_read; // ... + hal.stream.enqueue_realtime_command = drop_input_stream; // Drop input from current stream except realtime commands +#if M6_ENABLE + hal.stream.suspend_read = sdcard_suspend; // ... +#else + hal.stream.suspend_read = NULL; // ... +#endif + on_realtime_report = grbl.on_realtime_report; + grbl.on_realtime_report = sdcard_report; // Add percent complete to real time report + + on_program_completed = grbl.on_program_completed; + grbl.on_program_completed = sdcard_on_program_completed; + + grbl.report.status_message = trap_status_report; // Redirect status message reports here + retval = Status_OK; + } else + retval = Status_SDReadError; + } + } else { + frewind = false; + retval = sdcard_ls(); // (re)use line buffer for reporting filenames + } + + return retval; +} + +static status_code_t sd_cmd_mount (sys_state_t state, char *args) +{ + frewind = false; + + return sdcard_mount() ? Status_OK : Status_SDMountError; +} + +static status_code_t sd_cmd_rewind (sys_state_t state, char *args) +{ + frewind = true; + + return Status_OK; +} + +static status_code_t sd_cmd_to_output (sys_state_t state, char *args) +{ + status_code_t retval = Status_Unhandled; + + if (!(state == STATE_IDLE || state == STATE_CHECK_MODE)) + retval = Status_SystemGClock; + else if(args) { + if(file_open(args)) { + int16_t c; + char buf[2] = {0}; + while((c = file_read()) != -1) { + buf[0] = (char)c; + hal.stream.write(buf); + } + file_close(); + retval = Status_OK; + } else + retval = Status_SDReadError; + } + + return retval; +} + +static void sdcard_reset (void) +{ + if(hal.stream.type == StreamType_SDCard) { + if(file.line > 0) { + char buf[70]; + sprintf(buf, "[MSG:Reset during streaming of SD file at line: " UINT32FMT "]" ASCII_EOL, file.line); + hal.stream.write(buf); + } + sdcard_end_job(); + } + + driver_reset(); +} + +static void onReportCommandHelp (void) +{ + hal.stream.write("$F - list files on SD card" ASCII_EOL); + hal.stream.write("$F= - run SD card file" ASCII_EOL); + hal.stream.write("$FM - mount SD card" ASCII_EOL); + hal.stream.write("$FR - enable rewind mode for next SD card file to run" ASCII_EOL); + hal.stream.write("$F< - dump SD card file to output" ASCII_EOL); + + if(on_report_command_help) + on_report_command_help(); +} + +static void onReportOptions (bool newopt) +{ + on_report_options(newopt); + + if(newopt) + hal.stream.write(",SD"); + else + hal.stream.write("[PLUGIN:SDCARD v1.00]" ASCII_EOL); +} + +const sys_command_t sdcard_command_list[] = { + {"F", false, sd_cmd_file}, + {"FM", true, sd_cmd_mount}, + {"FR", true, sd_cmd_rewind}, + {"F<", false, sd_cmd_to_output}, +}; + +static sys_commands_t sdcard_commands = { + .n_commands = sizeof(sdcard_command_list) / sizeof(sys_command_t), + .commands = sdcard_command_list +}; + +sys_commands_t *sdcard_get_commands() +{ + return &sdcard_commands; +} + +void sdcard_init (void) +{ + driver_reset = hal.driver_reset; + hal.driver_reset = sdcard_reset; + + sdcard_commands.on_get_commands = grbl.on_get_commands; + grbl.on_get_commands = sdcard_get_commands; + + on_report_command_help = grbl.on_report_command_help; + grbl.on_report_command_help = onReportCommandHelp; + + on_report_options = grbl.on_report_options; + grbl.on_report_options = onReportOptions; +} + +FATFS *sdcard_getfs (void) +{ + if(file.fs == NULL) + sdcard_mount(); + + return file.fs; +} + +#endif diff --git a/drivers/RP2040/sdcard/sdcard.h b/drivers/RP2040/sdcard/sdcard.h new file mode 100644 index 00000000..35f7e452 --- /dev/null +++ b/drivers/RP2040/sdcard/sdcard.h @@ -0,0 +1,65 @@ +/* + sdcard.h - SDCard plugin for FatFs + + Part of grblHAL + + Copyright (c) 2018-2021 Terje Io + + Grbl is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Grbl is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Grbl. If not, see . +*/ + +#ifndef _SDCARD_H_ +#define _SDCARD_H_ + +#ifdef ARDUINO +#include "../driver.h" +#include "../grbl/hal.h" +#else +#include "driver.h" +#include "grbl/hal.h" +#endif + +#if SDCARD_ENABLE + +#if defined(STM32F103xB) || defined(STM32F401xC) || defined(STM32F407xx) || defined(STM32F411xE) || defined(STM32F446xx) +#define STM32_PLATFORM +#endif + +#ifdef __MSP432E401Y__ +#include "fatfs/ff.h" +#include "fatfs/diskio.h" +#include +#include +#elif defined(ESP_PLATFORM) +#include "esp_vfs_fat.h" +#elif defined(__LPC176x__) +#include "fatfs/ff.h" +#include "fatfs/diskio.h" +#elif defined(ARDUINO_SAMD_MKRZERO) +#include "../../ff.h" +#include "../../diskio.h" +#elif defined(STM32_PLATFORM) || defined(__LPC17XX__) || defined(__IMXRT1062__) +#include "ff.h" +#include "diskio.h" +#else +#include "fatfs/src/ff.h" +#include "fatfs/src/diskio.h" +#endif + +void sdcard_init (void); +FATFS *sdcard_getfs(void); + +#endif // SDCARD_ENABLE + +#endif diff --git a/drivers/SAM3X8E/grblHAL_Due/src/driver.c b/drivers/SAM3X8E/grblHAL_Due/src/driver.c index 6ad69a69..4e2e87df 100644 --- a/drivers/SAM3X8E/grblHAL_Due/src/driver.c +++ b/drivers/SAM3X8E/grblHAL_Due/src/driver.c @@ -441,42 +441,60 @@ inline static limit_signals_t limitsGetState() limit_signals_t signals = {0}; signals.min.mask = signals.max.mask = settings.limits.invert.mask; +#ifdef SQUARING_ENABLED + signals.min2.mask = settings.limits.invert.mask; +#endif signals.min.x = BITBAND_PERI(X_LIMIT_PORT->PIO_PDSR, X_LIMIT_PIN); signals.min.y = BITBAND_PERI(Y_LIMIT_PORT->PIO_PDSR, Y_LIMIT_PIN); signals.min.z = BITBAND_PERI(Z_LIMIT_PORT->PIO_PDSR, Z_LIMIT_PIN); - #ifdef A_LIMIT_PIN +#ifdef A_LIMIT_PIN signals.min.a = BITBAND_PERI(A_LIMIT_PORT->PIO_PDSR, A_LIMIT_PIN); - #endif - #ifdef B_LIMIT_PIN +#endif +#ifdef B_LIMIT_PIN signals.min.b = BITBAND_PERI(B_LIMIT_PORT->PIO_PDSR, B_LIMIT_PIN); - #endif - #ifdef C_LIMIT_PIN +#endif +#ifdef C_LIMIT_PIN signals.min.c = BITBAND_PERI(C_LIMIT_PORT->PIO_PDSR, C_LIMIT_PIN); - #endif +#endif - #ifdef X_LIMIT_PIN_MAX +#ifdef X_LIMIT_PIN_MAX + #if X_AUTO_SQUARE + signals.min2.x = BITBAND_PERI(X_LIMIT_PORT_MAX->PIO_PDSR, X_LIMIT_PIN_MAX); + #else signals.max.x = BITBAND_PERI(X_LIMIT_PORT_MAX->PIO_PDSR, X_LIMIT_PIN_MAX); #endif - #ifdef Y_LIMIT_PIN_MAX +#endif +#ifdef Y_LIMIT_PIN_MAX + #if Y_AUTO_SQUARE + signals.min2.y = BITBAND_PERI(Y_LIMIT_PORT_MAX->PIO_PDSR, Y_LIMIT_PIN_MAX); + #else signals.max.y = BITBAND_PERI(Y_LIMIT_PORT_MAX->PIO_PDSR, Y_LIMIT_PIN_MAX); #endif - #ifdef Z_LIMIT_PIN_MAX +#endif +#ifdef Z_LIMIT_PIN_MAX + #if Z_AUTO_SQUARE + signals.min2.z = BITBAND_PERI(Z_LIMIT_PORT_MAX->PIO_PDSR, Z_LIMIT_PIN_MAX); + #else signals.max.z = BITBAND_PERI(Z_LIMIT_PORT_MAX->PIO_PDSR, Z_LIMIT_PIN_MAX); #endif - #ifdef A_LIMIT_PIN_MAX +#endif +#ifdef A_LIMIT_PIN_MAX signals.max.a = BITBAND_PERI(A_LIMIT_PORT_MAX->PIO_PDSR, A_LIMIT_PIN_MAX); - #endif - #ifdef B_LIMIT_PIN_MAX +#endif +#ifdef B_LIMIT_PIN_MAX signals.max.b = BITBAND_PERI(B_LIMIT_PORT_MAX->PIO_PDSR, B_LIMIT_PIN_MAX); - #endif - #ifdef C_LIMIT_PIN_MAX +#endif +#ifdef C_LIMIT_PIN_MAX signals.max.c = BITBAND_PERI(C_LIMIT_PORT_MAX->PIO_PDSR, C_LIMIT_PIN_MAX); - #endif +#endif if (settings.limits.invert.mask) { signals.min.value ^= settings.limits.invert.mask; signals.max.value ^= settings.limits.invert.mask; +#ifdef SQUARING_ENABLED + signals.min2.mask ^= settings.limits.invert.mask; +#endif } return signals; @@ -497,15 +515,15 @@ inline static limit_signals_t limitsGetState() signals.min.z = BITBAND_PERI(Z_LIMIT_PORT->PIO_PDSR, Z_LIMIT_PIN); - #ifdef A_LIMIT_PIN +#ifdef A_LIMIT_PIN signals.min.a = BITBAND_PERI(A_LIMIT_PORT->PIO_PDSR, A_LIMIT_PIN); - #endif - #ifdef B_LIMIT_PIN +#endif +#ifdef B_LIMIT_PIN signals.min.b = BITBAND_PERI(B_LIMIT_PORT->PIO_PDSR, B_LIMIT_PIN); - #endif - #ifdef C_LIMIT_PIN +#endif +#ifdef C_LIMIT_PIN signals.min.c = BITBAND_PERI(C_LIMIT_PORT->PIO_PDSR, C_LIMIT_PIN); - #endif +#endif if (settings.limits.invert.mask) signals.min.value ^= settings.limits.invert.mask; @@ -541,50 +559,6 @@ static void StepperDisableMotors (axes_signals_t axes, squaring_mode_t mode) motors_2.mask = (mode == SquaringMode_B || mode == SquaringMode_Both ? axes.mask : 0) ^ AXES_BITMASK; } -// Returns limit state as an axes_signals_t variable. -// Each bitfield bit indicates an axis limit, where triggered is 1 and not triggered is 0. -inline static limit_signals_t limitsGetHomeState() -{ - limit_signals_t signals = {0}; - - if(motors_1.mask) { - - signals.min.mask = settings.limits.invert.mask; - - if(motors_1.x) - signals.min.x = BITBAND_PERI(X_LIMIT_PORT->PIO_PDSR, X_LIMIT_PIN); - if(motors_1.y) - signals.min.y = BITBAND_PERI(Y_LIMIT_PORT->PIO_PDSR, Y_LIMIT_PIN); - if(motors_1.z) - signals.min.z = BITBAND_PERI(Z_LIMIT_PORT->PIO_PDSR, Z_LIMIT_PIN);; - - if (settings.limits.invert.mask) - signals.min.mask ^= settings.limits.invert.mask; - } - - if(motors_2.mask) { - - signals.max.mask = settings.limits.invert.mask; - -#ifdef X_LIMIT_PIN_MAX - if(motors_2.x) - signals.max.x = BITBAND_PERI(X_LIMIT_PORT_MAX->PIO_PDSR, X_LIMIT_PIN_MAX); -#endif -#ifdef Y_LIMIT_PIN_MAX - if(motors_2.y) - signals.max.y = BITBAND_PERI(Y_LIMIT_PORT_MAX->PIO_PDSR, Y_LIMIT_PIN_MAX); -#endif -#ifdef Z_LIMIT_PIN_MAX - if(motors_2.z) - signals.max.z = BITBAND_PERI(Z_LIMIT_PORT_MAX->PIO_PDSR, Z_LIMIT_PIN_MAX); -#endif - if (settings.limits.invert.mask) - signals.max.mask ^= settings.limits.invert.mask; - } - - return signals; -} - #endif // Enable/disable limit pins interrupt @@ -603,10 +577,6 @@ static void limitsEnable (bool on, bool homing) } } while(i); - #ifdef SQUARING_ENABLED - hal.homing.get_state = homing ? limitsGetHomeState : limitsGetState; - #endif - #if TRINAMIC_ENABLE == 2130 trinamic_homing(homing); #endif @@ -1468,7 +1438,7 @@ bool driver_init (void) NVIC_EnableIRQ(SysTick_IRQn); hal.info = "SAM3X8E"; - hal.driver_version = "210211"; + hal.driver_version = "210214"; #ifdef BOARD_NAME hal.board = BOARD_NAME; #endif @@ -1490,7 +1460,6 @@ bool driver_init (void) hal.limits.enable = limitsEnable; hal.limits.get_state = limitsGetState; - hal.homing.get_state = limitsGetState; hal.coolant.set_state = coolantSetState; hal.coolant.get_state = coolantGetState; diff --git a/drivers/SAM3X8E/grblHAL_Due/src/grbl/grbl.h b/drivers/SAM3X8E/grblHAL_Due/src/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/SAM3X8E/grblHAL_Due/src/grbl/grbl.h +++ b/drivers/SAM3X8E/grblHAL_Due/src/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/SAM3X8E/grblHAL_Due/src/grbl/limits.c b/drivers/SAM3X8E/grblHAL_Due/src/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/SAM3X8E/grblHAL_Due/src/grbl/limits.c +++ b/drivers/SAM3X8E/grblHAL_Due/src/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/SAM3X8E/grblHAL_Due/src/grbl/motion_control.c b/drivers/SAM3X8E/grblHAL_Due/src/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/SAM3X8E/grblHAL_Due/src/grbl/motion_control.c +++ b/drivers/SAM3X8E/grblHAL_Due/src/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/SAM3X8E/grblHAL_Due/src/grbl/report.c b/drivers/SAM3X8E/grblHAL_Due/src/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/SAM3X8E/grblHAL_Due/src/grbl/report.c +++ b/drivers/SAM3X8E/grblHAL_Due/src/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/SAM3X8E/grblHAL_Due/src/grbl/report.h b/drivers/SAM3X8E/grblHAL_Due/src/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/SAM3X8E/grblHAL_Due/src/grbl/report.h +++ b/drivers/SAM3X8E/grblHAL_Due/src/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/SAM3X8E/grblHAL_Due/src/grbl/system.c b/drivers/SAM3X8E/grblHAL_Due/src/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/SAM3X8E/grblHAL_Due/src/grbl/system.c +++ b/drivers/SAM3X8E/grblHAL_Due/src/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/grbl.h b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/grbl.h +++ b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/limits.c b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/limits.c +++ b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/motion_control.c b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/motion_control.c +++ b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/report.c b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/report.c +++ b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/report.h b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/report.h +++ b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/system.c b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/system.c +++ b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/tool_change.c b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/tool_change.c +++ b/drivers/SAMD21/grblHAL_MKRZERO/src/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/STM32F1xx/grbl/grbl.h b/drivers/STM32F1xx/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/STM32F1xx/grbl/grbl.h +++ b/drivers/STM32F1xx/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/STM32F1xx/grbl/limits.c b/drivers/STM32F1xx/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/STM32F1xx/grbl/limits.c +++ b/drivers/STM32F1xx/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/STM32F1xx/grbl/motion_control.c b/drivers/STM32F1xx/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/STM32F1xx/grbl/motion_control.c +++ b/drivers/STM32F1xx/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/STM32F1xx/grbl/report.c b/drivers/STM32F1xx/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/STM32F1xx/grbl/report.c +++ b/drivers/STM32F1xx/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/STM32F1xx/grbl/report.h b/drivers/STM32F1xx/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/STM32F1xx/grbl/report.h +++ b/drivers/STM32F1xx/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/STM32F1xx/grbl/system.c b/drivers/STM32F1xx/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/STM32F1xx/grbl/system.c +++ b/drivers/STM32F1xx/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/STM32F1xx/grbl/tool_change.c b/drivers/STM32F1xx/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/STM32F1xx/grbl/tool_change.c +++ b/drivers/STM32F1xx/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/STM32F3xx/grbl/grbl.h b/drivers/STM32F3xx/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/STM32F3xx/grbl/grbl.h +++ b/drivers/STM32F3xx/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/STM32F3xx/grbl/limits.c b/drivers/STM32F3xx/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/STM32F3xx/grbl/limits.c +++ b/drivers/STM32F3xx/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/STM32F3xx/grbl/motion_control.c b/drivers/STM32F3xx/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/STM32F3xx/grbl/motion_control.c +++ b/drivers/STM32F3xx/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/STM32F3xx/grbl/report.c b/drivers/STM32F3xx/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/STM32F3xx/grbl/report.c +++ b/drivers/STM32F3xx/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/STM32F3xx/grbl/report.h b/drivers/STM32F3xx/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/STM32F3xx/grbl/report.h +++ b/drivers/STM32F3xx/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/STM32F3xx/grbl/system.c b/drivers/STM32F3xx/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/STM32F3xx/grbl/system.c +++ b/drivers/STM32F3xx/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/STM32F3xx/grbl/tool_change.c b/drivers/STM32F3xx/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/STM32F3xx/grbl/tool_change.c +++ b/drivers/STM32F3xx/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/STM32F4xx/grbl/grbl.h b/drivers/STM32F4xx/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/STM32F4xx/grbl/grbl.h +++ b/drivers/STM32F4xx/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/STM32F4xx/grbl/limits.c b/drivers/STM32F4xx/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/STM32F4xx/grbl/limits.c +++ b/drivers/STM32F4xx/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/STM32F4xx/grbl/motion_control.c b/drivers/STM32F4xx/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/STM32F4xx/grbl/motion_control.c +++ b/drivers/STM32F4xx/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/STM32F4xx/grbl/report.c b/drivers/STM32F4xx/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/STM32F4xx/grbl/report.c +++ b/drivers/STM32F4xx/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/STM32F4xx/grbl/report.h b/drivers/STM32F4xx/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/STM32F4xx/grbl/report.h +++ b/drivers/STM32F4xx/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/STM32F4xx/grbl/system.c b/drivers/STM32F4xx/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/STM32F4xx/grbl/system.c +++ b/drivers/STM32F4xx/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/STM32F4xx/grbl/tool_change.c b/drivers/STM32F4xx/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/STM32F4xx/grbl/tool_change.c +++ b/drivers/STM32F4xx/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/Simulator/grbl/grbl.h b/drivers/Simulator/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/Simulator/grbl/grbl.h +++ b/drivers/Simulator/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/Simulator/grbl/limits.c b/drivers/Simulator/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/Simulator/grbl/limits.c +++ b/drivers/Simulator/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/Simulator/grbl/motion_control.c b/drivers/Simulator/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/Simulator/grbl/motion_control.c +++ b/drivers/Simulator/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/Simulator/grbl/report.c b/drivers/Simulator/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/Simulator/grbl/report.c +++ b/drivers/Simulator/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/Simulator/grbl/report.h b/drivers/Simulator/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/Simulator/grbl/report.h +++ b/drivers/Simulator/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/Simulator/grbl/system.c b/drivers/Simulator/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/Simulator/grbl/system.c +++ b/drivers/Simulator/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/Simulator/grbl/tool_change.c b/drivers/Simulator/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/Simulator/grbl/tool_change.c +++ b/drivers/Simulator/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/TM4C123/grbl/grbl.h b/drivers/TM4C123/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/TM4C123/grbl/grbl.h +++ b/drivers/TM4C123/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/TM4C123/grbl/limits.c b/drivers/TM4C123/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/TM4C123/grbl/limits.c +++ b/drivers/TM4C123/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/TM4C123/grbl/motion_control.c b/drivers/TM4C123/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/TM4C123/grbl/motion_control.c +++ b/drivers/TM4C123/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/TM4C123/grbl/report.c b/drivers/TM4C123/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/TM4C123/grbl/report.c +++ b/drivers/TM4C123/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/TM4C123/grbl/report.h b/drivers/TM4C123/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/TM4C123/grbl/report.h +++ b/drivers/TM4C123/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/TM4C123/grbl/system.c b/drivers/TM4C123/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/TM4C123/grbl/system.c +++ b/drivers/TM4C123/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/TM4C123/grbl/tool_change.c b/drivers/TM4C123/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/TM4C123/grbl/tool_change.c +++ b/drivers/TM4C123/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/drivers/TM4C129/grbl/grbl.h b/drivers/TM4C129/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/drivers/TM4C129/grbl/grbl.h +++ b/drivers/TM4C129/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/drivers/TM4C129/grbl/limits.c b/drivers/TM4C129/grbl/limits.c index 0b715618..340be0f3 100644 --- a/drivers/TM4C129/grbl/limits.c +++ b/drivers/TM4C129/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/drivers/TM4C129/grbl/motion_control.c b/drivers/TM4C129/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/drivers/TM4C129/grbl/motion_control.c +++ b/drivers/TM4C129/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/drivers/TM4C129/grbl/report.c b/drivers/TM4C129/grbl/report.c index 95833018..4ca13627 100644 --- a/drivers/TM4C129/grbl/report.c +++ b/drivers/TM4C129/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/drivers/TM4C129/grbl/report.h b/drivers/TM4C129/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/drivers/TM4C129/grbl/report.h +++ b/drivers/TM4C129/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/drivers/TM4C129/grbl/system.c b/drivers/TM4C129/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/drivers/TM4C129/grbl/system.c +++ b/drivers/TM4C129/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT diff --git a/drivers/TM4C129/grbl/tool_change.c b/drivers/TM4C129/grbl/tool_change.c index 65ae0c46..797c6664 100644 --- a/drivers/TM4C129/grbl/tool_change.c +++ b/drivers/TM4C129/grbl/tool_change.c @@ -467,7 +467,9 @@ status_code_t tc_probe_workpiece (void) if(ok && protocol_buffer_synchronize()) { sync_position(); block_cycle_start = false; - report_message("Remove any touch plate and press cycle start to continue.", Message_Plain); + report_message(settings.tool_change.mode == ToolChange_Manual_G59_3 + ? "Press cycle start to continue." + : "Remove any touch plate and press cycle start to continue.", Message_Plain); } return ok ? Status_OK : Status_GCodeToolError; diff --git a/grbl/grbl.h b/grbl/grbl.h index 05d9f9df..15bb95af 100644 --- a/grbl/grbl.h +++ b/grbl/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210131" +#define GRBL_VERSION_BUILD "20210214" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/grbl/limits.c b/grbl/limits.c index 0b715618..340be0f3 100644 --- a/grbl/limits.c +++ b/grbl/limits.c @@ -69,10 +69,24 @@ ISR_CODE axes_signals_t limit_signals_merge (limit_signals_t signals) } // Merge (bitwise or) home switch inputs (typically aquired from limits.min and limits.min2). -ISR_CODE axes_signals_t homing_signals_merge (limit_signals_t signals) +ISR_CODE static axes_signals_t homing_signals_select (limit_signals_t signals, axes_signals_t auto_square, squaring_mode_t mode) { axes_signals_t state; + switch(mode) { + + case SquaringMode_A: + signals.min.mask &= ~auto_square.mask; + break; + + case SquaringMode_B: + signals.min2.mask &= ~auto_square.mask; + break; + + default: + break; + } + state.mask = signals.min.mask | signals.min2.mask; return state; @@ -185,8 +199,8 @@ static bool limits_pull_off (axes_signals_t axis, float distance) if (rt_exec & EXEC_SAFETY_DOOR) system_set_exec_alarm(Alarm_HomingFailDoor); - // Homing failure condition: Homing switch still engaged after pull-off motion - if (homing_signals_merge(hal.homing.get_state()).mask & axis.mask) + // Homing failure condition: Homing switch(es) still engaged after pull-off motion + if (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & axis.mask) system_set_exec_alarm(Alarm_FailPulloff); if (sys.rt_exec_alarm) { @@ -227,8 +241,10 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar uint_fast8_t step_pin[N_AXIS], n_active_axis, dual_motor_axis = 0; float target[N_AXIS]; float max_travel = 0.0f, homing_rate = settings.homing.seek_rate; - bool approach = true, autosquare_check = false, both_motors = !!auto_square.mask; + bool approach = true, autosquare_check = false; axes_signals_t axislock, homing_state; + limit_signals_t limits_state; + squaring_mode_t squaring_mode = SquaringMode_Both; plan_line_data_t plan_data; // Initialize plan data struct for homing motion. @@ -313,22 +329,16 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar if (approach) { // Check homing switches state. Lock out cycle axes when they change. - homing_state = homing_signals_merge(hal.homing.get_state()); + homing_state = homing_signals_select(limits_state = hal.homing.get_state(), auto_square, squaring_mode); // Auto squaring check - if(both_motors && (homing_state.mask & auto_square.mask)) { - both_motors = false; - homing_state.mask &= ~auto_square.mask; - hal.stepper.disable_motors(auto_square, SquaringMode_A); - if(hal.homing.get_state().min2.mask & auto_square.mask) { - hal.stepper.disable_motors(auto_square, SquaringMode_B); - if(hal.homing.get_state().min.mask & auto_square.mask) { - homing_state.mask |= auto_square.mask; - hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); - } - } - if((autosquare_check = (homing_state.mask & auto_square.mask) == 0)) + if((homing_state.mask & auto_square.mask) && squaring_mode == SquaringMode_Both) { + if((autosquare_check = (limits_state.min.mask & auto_square.mask) != (limits_state.min2.mask & auto_square.mask))) { initial_trigger_position = sys.position[dual_motor_axis]; + homing_state.mask &= ~auto_square.mask; + squaring_mode = (limits_state.min.mask & auto_square.mask) ? SquaringMode_A : SquaringMode_B; + hal.stepper.disable_motors(auto_square, squaring_mode); + } } idx = N_AXIS; @@ -371,7 +381,7 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar system_set_exec_alarm(Alarm_HomingFailDoor); // Homing failure condition: Homing switch(es) still engaged after pull-off motion - if (!approach && (homing_signals_merge(hal.homing.get_state()).mask & cycle.mask)) + if (!approach && (homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask & cycle.mask)) system_set_exec_alarm(Alarm_FailPulloff); // Homing failure condition: Limit switch not found during approach. @@ -411,8 +421,9 @@ static bool limits_homing_cycle (axes_signals_t cycle, axes_signals_t auto_squar homing_rate = settings.homing.seek_rate; } - if((both_motors = !!auto_square.mask)) { + if(auto_square.mask) { autosquare_check = false; + squaring_mode = SquaringMode_Both; hal.stepper.disable_motors((axes_signals_t){0}, SquaringMode_Both); } @@ -472,7 +483,7 @@ bool limits_go_home (axes_signals_t cycle) if(auto_squared.mask != auto_square.mask) return false; // Attempt at squaring more than one auto squared axis at the same time. - if((auto_squared.mask & homing_signals_merge(hal.homing.get_state()).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) + if((auto_squared.mask & homing_signals_select(hal.homing.get_state(), (axes_signals_t){0}, SquaringMode_Both).mask) && !limits_pull_off(auto_square, settings.homing.pulloff * HOMING_AXIS_LOCATE_SCALAR)) return false; // Auto squaring with limit switch asserted is not allowed. } diff --git a/grbl/motion_control.c b/grbl/motion_control.c index 598d8b74..7629bfe2 100644 --- a/grbl/motion_control.c +++ b/grbl/motion_control.c @@ -752,6 +752,8 @@ status_code_t mc_homing_cycle (axes_signals_t cycle) { bool home_all = cycle.mask == 0; + memset(&sys.last_event.limits, 0, sizeof(limit_signals_t)); + if(settings.homing.flags.manual && (home_all ? sys.homing.mask : (cycle.mask & sys.homing.mask)) == 0) { if(home_all) diff --git a/grbl/report.c b/grbl/report.c index 95833018..4ca13627 100644 --- a/grbl/report.c +++ b/grbl/report.c @@ -1775,6 +1775,19 @@ status_code_t report_setting_group_details (bool by_id, char *prefix) return Status_OK; } +static char *add_limits (char *buf, limit_signals_t limits) +{ + buf = axis_signals_tostring(buf, limits.min); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.min2); + *buf++ = ','; + buf = axis_signals_tostring(buf, limits.max2); + + return buf; +} + status_code_t report_last_signals_event (sys_state_t state, char *args) { char *append = &buf[12]; @@ -1783,13 +1796,7 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) append = control_signals_tostring(append, sys.last_event.control); *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.min2); - *append++ = ','; - append = axis_signals_tostring(append, sys.last_event.limits.max2); + append = add_limits(append, sys.last_event.limits); hal.stream.write(buf); hal.stream.write("]" ASCII_EOL); @@ -1797,6 +1804,21 @@ status_code_t report_last_signals_event (sys_state_t state, char *args) return Status_OK; } +status_code_t report_current_limit_state (sys_state_t state, char *args) +{ + char *append = &buf[8]; + + strcpy(buf, "[LIMITS:"); + + append = add_limits(append, hal.limits.get_state()); + + hal.stream.write(buf); + hal.stream.write("]" ASCII_EOL); + + return Status_OK; +} + + // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args) { diff --git a/grbl/report.h b/grbl/report.h index 833779ce..5a6f14d2 100644 --- a/grbl/report.h +++ b/grbl/report.h @@ -92,6 +92,7 @@ status_code_t report_setting_group_details (bool by_id, char *prefix); status_code_t report_settings_details (bool human_readable, setting_id_t setting, setting_group_t group); status_code_t report_last_signals_event (sys_state_t state, char *args); +status_code_t report_current_limit_state (sys_state_t state, char *args); // Prints spindle data (encoder pulse and index count, angular position). status_code_t report_spindle_data (sys_state_t state, char *args); diff --git a/grbl/system.c b/grbl/system.c index 7548c71c..3eddbb96 100644 --- a/grbl/system.c +++ b/grbl/system.c @@ -203,6 +203,7 @@ const sys_command_t sys_commands[] = { {"E*", true, enumerate_all}, {"RST", false, settings_reset}, {"LEV", true, report_last_signals_event}, + {"LIM", true, report_current_limit_state}, {"SD", false, report_spindle_data}, {"SR", false, spindle_reset_data}, #ifdef DEBUGOUT