Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
Synced with new repo
Browse files Browse the repository at this point in the history
See changelog for details.
  • Loading branch information
terjeio committed May 17, 2021
1 parent 4b95f3f commit 9f405ba
Show file tree
Hide file tree
Showing 331 changed files with 9,624 additions and 3,713 deletions.
15 changes: 13 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
## grblHAL changelog

2021-03-14:
Build 20210515:

* Fixed G43 "bug" by changing to LinuxCNC specification. NIST specification is ambiguous.
* Added acceleration override handling, to be used by OpenPNP plugin M-code.

Build 20210505:

* Some bug fixes: relative canned cycles repeat error, comment handling...
* Check mode changes to allow use with SD card streaming.
* Internal buffer changes for reducing RAM footprint. Some HAL extensions.

Build 20210314:

* Added support for tool change protocol to networking protocols using shared stream buffer.
* Added `$S` system command for toggling single step mode, when enabled cycle start has to be issued after each block.
* Some bug fixes.

2021-02-07:
Build 20210207:

* Added `#define BOARD_MY_MACHINE` option in _my_machine.h_ for building using _my_machine-map.c_, this for simpler handling of user defined pin mappings.
_my_machine-map.c_ is __*not*__ part of the distributed source and must by added to the project by the user before enabled, typically by copying an existing map file.
Expand Down
9 changes: 6 additions & 3 deletions drivers/ESP32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ OPTION(BOARD_BDRING_V4 "Compile for bdring v4 3-axis board" ON)
OPTION(BOARD_BDRING_I2S6A "Compile for bdring 6-axis I2S board - untested!" OFF)
OPTION(BOARD_CNC_BOOSTERPACK "Compile for CNC BoosterPack" OFF)
OPTION(BOARD_ESPDUINO32 "Compile for ESPDUINO-32 Wemos D1 R32" OFF)
OPTION(BOARD_SOURCERABBIT_4AXIS "Compile for SourceRabbit 4-axis board" OFF)
OPTION(BOARD_MY_MACHINE "Compile for my_machine_map.h" OFF)

# The following plugins/options are supported:
Expand Down Expand Up @@ -36,7 +37,7 @@ OPTION(EEPROM "Compile with I2C EEPROM support" OFF)
OPTION(FRAM "Compile with I2C FRAM support" OFF)
OPTION(NOPROBE "Compile without probe support" OFF)

set(SDCARD_SOURCE sdcard/sdcard.c)
set(SDCARD_SOURCE sdcard/sdcard.c sdcard/ymodem.c)
set(KEYPAD_SOURCE keypad/keypad.c)
set(TRINAMIC_SOURCE motors/trinamic.c trinamic/tmc2130.c trinamic/tmc2130hal.c trinamic/common.c trinamic/tmc_interface.c)
set(NETWORKING_SOURCE wifi.c dns_server.c web/backend.c web/upload.c networking/TCPStream.c networking/WsStream.c networking/base64.c networking/sha1.c networking/urldecode.c networking/strutils.c networking/utils.c networking/multipartparser.c )
Expand Down Expand Up @@ -104,8 +105,7 @@ if(EEPROM OR FRAM OR BOARD_CNC_BOOSTERPACK)
list (APPEND SRCS ${EEPROM_SOURCE})
endif()

idf_component_register(SRCS "${SRCS}"
INCLUDE_DIRS ".")
idf_component_register(SRCS "${SRCS}" INCLUDE_DIRS ".")

target_compile_definitions("${COMPONENT_LIB}" PUBLIC GRBL_ESP32)
target_compile_definitions("${COMPONENT_LIB}" PUBLIC OVERRIDE_MY_MACHINE)
Expand All @@ -120,6 +120,8 @@ elseif(BOARD_ESPDUINO32)
target_compile_definitions("${COMPONENT_LIB}" PUBLIC BOARD_ESPDUINO32)
elseif(BOARD_CNC_BOOSTERPACK)
target_compile_definitions("${COMPONENT_LIB}" PUBLIC BOARD_CNC_BOOSTERPACK)
elseif(BOARD_SOURCERABBIT_4AXIS)
target_compile_definitions("${COMPONENT_LIB}" PUBLIC BOARD_SOURCERABBIT_4AXIS)
elseif(BOARD_MY_MACHINE)
target_compile_definitions("${COMPONENT_LIB}" PUBLIC BOARD_MY_MACHINE)
endif()
Expand Down Expand Up @@ -190,6 +192,7 @@ unset(BOARD_BDRING_V4 CACHE)
unset(BOARD_BDRING_I2S6A CACHE)
unset(BOARD_CNC_BOOSTERPACK CACHE)
unset(BOARD_ESPDUINO32 CACHE)
unset(BOARD_SOURCERABBIT_4AXIS CACHE)
unset(BOARD_MY_MACHINE CACHE)

unset(Networking CACHE)
Expand Down
4 changes: 2 additions & 2 deletions drivers/ESP32/main/bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ bool BTStreamPutC (const char c)
if(txbuffer.head < BT_TX_BUFFER_SIZE)
txbuffer.data[txbuffer.head++] = c;

if(c == '\n') {
if(c == ASCII_LF) {
enqueue_tx_chunk(txbuffer.head, (uint8_t *)txbuffer.data);
txbuffer.head = 0;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ static void esp_spp_cb (esp_spp_cb_event_t event, esp_spp_cb_param_t *param)

case ESP_SPP_INIT_EVT:
esp_bt_dev_set_device_name(bluetooth.device_name);
esp_bt_gap_set_scan_mode(ESP_BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE);
esp_bt_gap_set_scan_mode(ESP_BT_CONNECTABLE, ESP_BT_GENERAL_DISCOVERABLE);
esp_spp_start_srv(ESP_SPP_SEC_AUTHENTICATE, ESP_SPP_ROLE_SLAVE, 0, bluetooth.service_name);
break;

Expand Down
3 changes: 2 additions & 1 deletion drivers/ESP32/main/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Part of grblHAL
Copyright (c) 2018-2020 Terje Io
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
Expand Down Expand Up @@ -34,6 +34,7 @@ char *bluetooth_get_client_mac (void);
uint32_t BTStreamAvailable (void);
uint16_t BTStreamRXFree (void);
int16_t BTStreamGetC (void);
bool BTStreamPutC (const char c);
bool BTStreamSuspendInput (bool suspend);
void BTStreamWriteS (const char *data);
void BTStreamFlush (void);
Expand Down
8 changes: 6 additions & 2 deletions drivers/ESP32/main/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const io_stream_t serial_stream = {
.read = serialRead,
.write = serialWriteS,
.write_all = serialWriteS,
.write_char = serialPutC,
.get_rx_buffer_available = serialRXFree,
.reset_read_buffer = serialFlush,
.cancel_read_buffer = serialCancel,
Expand Down Expand Up @@ -187,6 +188,7 @@ const io_stream_t telnet_stream = {
.read = TCPStreamGetC,
.write = TCPStreamWriteS,
.write_all = tcpStreamWriteS,
.write_char = TCPStreamPutC,
.get_rx_buffer_available = TCPStreamRxFree,
.reset_read_buffer = TCPStreamRxFlush,
.cancel_read_buffer = TCPStreamRxCancel,
Expand All @@ -201,6 +203,7 @@ const io_stream_t websocket_stream = {
.read = WsStreamGetC,
.write = WsStreamWriteS,
.write_all = tcpStreamWriteS,
.write_char = WsStreamPutC,
.get_rx_buffer_available = WsStreamRxFree,
.reset_read_buffer = WsStreamRxFlush,
.cancel_read_buffer = WsStreamRxCancel,
Expand All @@ -223,6 +226,7 @@ const io_stream_t bluetooth_stream = {
.read = BTStreamGetC,
.write = BTStreamWriteS,
.write_all = btStreamWriteS,
.write_char = BTStreamPutC,
.get_rx_buffer_available = BTStreamRXFree,
.reset_read_buffer = BTStreamFlush,
.cancel_read_buffer = BTStreamCancel,
Expand Down Expand Up @@ -1474,7 +1478,7 @@ bool driver_init (void)
serialInit();

hal.info = "ESP32";
hal.driver_version = "210314";
hal.driver_version = "210423";
#ifdef BOARD_NAME
hal.board = BOARD_NAME;
#endif
Expand Down Expand Up @@ -1622,7 +1626,7 @@ bool driver_init (void)

// grbl_esp32_if_init();

my_plugin_init();
// my_plugin_init(); causes run time crash for some silly reason

// no need to move version check before init - compiler will fail any mismatch for existing entries
return hal.version == 8;
Expand Down
2 changes: 2 additions & 0 deletions drivers/ESP32/main/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ typedef struct {
#include "bdring_i2s_6_axis_map.h"
#elif defined(BOARD_ESPDUINO32)
#include "espduino-32_wemos_d1_r32_uno_map.h"
#elif defined(BOARD_SOURCERABBIT_4AXIS)
#include "sourcerabbit_4axis.h"
#elif defined(BOARD_MY_MACHINE)
#include "my_machine_map.h"
#else // default board - NOTE: NOT FINAL VERSION!
Expand Down
1 change: 1 addition & 0 deletions drivers/ESP32/main/grbl/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@
// for professional CNC machines, regardless of where the limit switches are located. Set this
// define to 1 to force Grbl to always set the machine origin at the homed location despite switch orientation.
//#define HOMING_FORCE_SET_ORIGIN // Default disabled. Uncomment to enable.
#define HOMING_FORCE_SET_ORIGIN 1

// To prevent the homing cycle from racking the dual axis, when one limit triggers before the
// other due to switch failure or noise, the homing cycle will automatically abort if the second
Expand Down
54 changes: 54 additions & 0 deletions drivers/ESP32/main/grbl/crossbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,60 @@
#ifndef _CROSSBAR_H_
#define _CROSSBAR_H_

typedef enum {
Input_Probe = 0,
Input_Reset,
Input_FeedHold,
Input_CycleStart,
Input_SafetyDoor,
Input_LimitsOverride,
Input_EStop,
Input_ModeSelect,
Input_LimitX,
Input_LimitX_Max,
Input_LimitY,
Input_LimitY_Max,
Input_LimitZ,
Input_LimitZ_Max,
Input_LimitA,
Input_LimitA_Max,
Input_LimitB,
Input_LimitB_Max,
Input_LimitC,
Input_LimitC_Max,
Input_KeypadStrobe,
Input_QEI_A,
Input_QEI_B,
Input_QEI_Select,
Input_QEI_Index,
Input_SpindleIndex,
Input_Aux0,
Input_Aux1,
Input_Aux2,
Input_Aux3
} pin_function_t;

typedef enum {
IRQ_Mode_None = 0b00,
IRQ_Mode_Change = 0b01,
IRQ_Mode_Rising = 0b10,
IRQ_Mode_Falling = 0b11
} pin_irq_mode_t;

typedef enum {
PinGroup_Control = (1<<0),
PinGroup_Limit = (1<<1),
PinGroup_Probe = (1<<2),
PinGroup_Keypad = (1<<3),
PinGroup_MPG = (1<<4),
PinGroup_QEI = (1<<5),
PinGroup_QEI_Select = (1<<6),
PinGroup_SpindlePulse = (1<<7),
PinGroup_SpindleIndex = (1<<8),
PinGroup_AuxInput = (1<<9),
PinGroup_AuxOutput = (1<<10)
} pin_group_t;

typedef bool (*xbar_get_value_ptr)(void);
typedef void (*xbar_set_value_ptr)(bool on);
typedef void (*xbar_event_ptr)(bool on);
Expand Down
2 changes: 2 additions & 0 deletions drivers/ESP32/main/grbl/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ typedef enum {
Status_MotorFault = 51,
Status_SettingValueOutOfRange = 52,
Status_SettingDisabled = 53,
Status_GcodeInvalidRetractPosition = 54,

// Some error codes as defined in bdring's ESP32 port
Status_SDMountError = 60,
Expand Down Expand Up @@ -156,6 +157,7 @@ PROGMEM static const status_detail_t status_detail[] = {
{ Status_MotorFault, "Motor fault", "Motor fault." },
{ Status_SettingValueOutOfRange, "Value out of range.", "Setting value is out of range." },
{ Status_SettingDisabled, "Setting disabled", "Setting is not available, possibly due to limited driver support." },
{ Status_GcodeInvalidRetractPosition, "Invalid gcode ID:54", "Retract position is less than drill depth." },
{ Status_SDMountError, "SD Card", "SD Card mount failed." },
{ Status_SDReadError, "SD Card", "SD Card file open/read failed." },
{ Status_SDFailedOpenDir, "SD Card", "SD Card directory listing failed." },
Expand Down
53 changes: 28 additions & 25 deletions drivers/ESP32/main/grbl/gcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,7 @@ status_code_t gc_execute_block(char *block, char *message)
// NOTE: The NIST g-code standard vaguely states that when a tool length offset is changed,
// there cannot be any axis motion or coordinate offsets updated. Meaning G43, G43.1, and G49
// all are explicit axis commands, regardless if they require axis words or not.

if (axis_command)
FAIL(Status_GcodeAxisCommandConflict); // [Axis word/command conflict] }

axis_command = AxisCommand_ToolLengthOffset;
// NOTE: cannot find the NIST statement referenced above, changed to match LinuxCNC behaviour in build 20210513.
if (int_value == 49) // G49
gc_block.modal.tool_offset_mode = ToolLengthOffset_Cancel;
#ifdef N_TOOLS
Expand All @@ -649,9 +645,12 @@ status_code_t gc_execute_block(char *block, char *message)
else if (mantissa == 20) // G43.2
gc_block.modal.tool_offset_mode = ToolLengthOffset_ApplyAdditional;
#endif
else if (mantissa == 10) // G43.1
else if (mantissa == 10) { // G43.1
if (axis_command)
FAIL(Status_GcodeAxisCommandConflict); // [Axis word/command conflict] }
axis_command = AxisCommand_ToolLengthOffset;
gc_block.modal.tool_offset_mode = ToolLengthOffset_EnableDynamic;
else
} else
FAIL(Status_GcodeUnsupportedCommand); // [Unsupported G43.x command]
mantissa = 0; // Set to zero to indicate valid non-integer G command.
break;
Expand Down Expand Up @@ -1316,7 +1315,9 @@ status_code_t gc_execute_block(char *block, char *message)
// Pre-convert XYZ coordinate values to millimeters, if applicable.
uint_fast8_t idx = N_AXIS;
if (gc_block.modal.units_imperial) do { // Axes indices are consistent, so loop may be used.
if (bit_istrue(axis_words.mask, bit(--idx)))
idx--;
// if (bit_istrue(axis_words.mask, bit(idx)) && bit_isfalse(settings.steppers.is_rotational.mask, bit(idx)))
if (bit_istrue(axis_words.mask, bit(idx)))
gc_block.values.xyz[idx] *= MM_PER_INCH;
} while(idx);

Expand Down Expand Up @@ -1412,13 +1413,13 @@ status_code_t gc_execute_block(char *block, char *message)

// [14. Tool length compensation ]: G43.1 and G49 are always supported, G43 and G43.2 if N_TOOLS defined.
// [G43.1 Errors]: Motion command in same line.
// [G43.2 Errors]: Motion command in same line. Tool number not in the tool table,
// NOTE: Although not explicitly stated so, G43.1 should be applied to only one valid
// axis that is configured (in config.h). There should be an error if the configured axis
// is absent or if any of the other axis words are present.
if (axis_command == AxisCommand_ToolLengthOffset) { // Indicates called in block.
// [G43.2 Errors]: Tool number not in the tool table,
if (command_words.G8) { // Indicates called in block.

#ifdef TOOL_LENGTH_OFFSET_AXIS
// NOTE: Although not explicitly stated so, G43.1 should be applied to only one valid
// axis that is configured (in config.h). There should be an error if the configured axis
// is absent or if any of the other axis words are present.
if(gc_block.modal.tool_offset_mode == ToolLengthOffset_EnableDynamic) {
if (axis_words.mask ^ bit(TOOL_LENGTH_OFFSET_AXIS))
FAIL(Status_GcodeG43DynamicAxisError);
Expand Down Expand Up @@ -1819,24 +1820,24 @@ status_code_t gc_execute_block(char *block, char *message)
else if(gc_block.values.l <= 0)
FAIL(Status_NonPositiveValue); // [L <= 0]

if (value_words.r) {
gc_state.canned.retract_position = gc_block.values.r;
if(gc_state.modal.distance_incremental)
gc_state.canned.retract_position += gc_state.position[plane.axis_linear];
gc_state.canned.retract_position = gc_block.modal.coord_system.xyz[plane.axis_linear] + gc_state.canned.retract_position;
}
if(value_words.r)
gc_state.canned.retract_position = gc_block.values.r + (gc_block.modal.distance_incremental
? gc_state.position[plane.axis_linear]
: gc_get_block_offset(&gc_block, plane.axis_linear));

idx = N_AXIS;
do {
if(bit_istrue(axis_words.mask, bit(--idx))) {
gc_state.canned.xyz[idx] = gc_block.values.xyz[idx];
if(idx != plane.axis_linear)
gc_state.canned.xyz[idx] -= gc_state.position[idx];
else if(gc_block.modal.distance_incremental)
gc_state.canned.xyz[idx] = gc_state.canned.retract_position + (gc_state.canned.xyz[idx] - gc_state.position[idx]);
}
} while(idx);

if(gc_state.canned.retract_position < gc_state.canned.xyz[plane.axis_linear])
FAIL(Status_GcodeAxisCommandConflict);
FAIL(Status_GcodeInvalidRetractPosition);

value_words.r = value_words.l = Off; // Remove single-meaning value words.

Expand Down Expand Up @@ -2030,7 +2031,9 @@ status_code_t gc_execute_block(char *block, char *message)
if (gc_block.modal.units_imperial) {
idx = 3;
do { // Axes indices are consistent, so loop may be used to save flash space.
if (ijk_words.mask & bit(--idx))
idx--;
// if (ijk_words.mask & bit(idx) && bit_isfalse(settings.steppers.is_rotational.mask, bit(idx)))
if (ijk_words.mask & bit(idx))
gc_block.values.ijk[idx] *= MM_PER_INCH;
} while(idx);
}
Expand Down Expand Up @@ -2412,7 +2415,7 @@ status_code_t gc_execute_block(char *block, char *message)
// NOTE: If G43 were supported, its operation wouldn't be any different from G43.1 in terms
// of execution. The error-checking step would simply load the offset value into the correct
// axis of the block XYZ value array.
if (axis_command == AxisCommand_ToolLengthOffset) { // Indicates a change.
if (command_words.G8) { // Indicates a change.

bool tlo_changed = false;

Expand Down Expand Up @@ -2725,11 +2728,11 @@ status_code_t gc_execute_block(char *block, char *message)
hal.coolant.set_state(gc_state.modal.coolant);
sys.report.spindle = On; // Set to report change immediately
sys.report.coolant = On; // ...

if(grbl.on_program_completed)
grbl.on_program_completed(gc_state.modal.program_flow);
}

if(grbl.on_program_completed)
grbl.on_program_completed(gc_state.modal.program_flow, check_mode);

// Clear any pending output commands
while(output_commands) {
output_command_t *next = output_commands->next;
Expand Down
2 changes: 1 addition & 1 deletion drivers/ESP32/main/grbl/grbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#else
#define GRBL_VERSION "1.1f"
#endif
#define GRBL_VERSION_BUILD "20210313"
#define GRBL_VERSION_BUILD "20210513"

// The following symbols are set here if not already set by the compiler or in config.h
// Do NOT change here!
Expand Down
Loading

0 comments on commit 9f405ba

Please sign in to comment.