diff --git a/README.md b/README.md index 8b8e477..b52e61f 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It has been written to complement grblHAL and has features such as proper keyboa --- -Latest build date is 20211029, see the [changelog](changelog.md) for details. +Latest build date is 20211109, see the [changelog](changelog.md) for details. __NOTE:__ Drivers built with more than three axes configured \(`N_AXIS` > `3`\) will force a settings reset when upgraded. Backup and restore of settings is recommended for these. --- diff --git a/changelog.md b/changelog.md index 37afbe4..08aa0dc 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,26 @@ ## grblHAL changelog -Build 2021029: +Build 20211108: + +Core: +* Renamed default hostnames/device names from _Grbl_ to _grblHAL_. +* Added early application of constraints for feedrate and spindle RPM overrides to avoid variable under/overflow. From PR#83. +* Added higher level \(than generic GPIO\) interrupt handler registration to HAL. +* Added optional MCU peripheral \(other than GPIO\) pin registration to HAL. For `$pins` report. +* Added region for [third party plugin](https://github.com/grblHAL/plugins#i-have-written-a-plugin-and-i-want-to-make-it-available-to-grblhal-users) init functions to _plugins_init.h_. + +Plugins: +* Modified keypad plugin to claim strobe interrupt only when using I2C, added `KEYPAD_ENABLE 2` option to _my_machine.h_ to not claim it. +* Fixed botched include in Bluetooth plugin, added pin description to claimed UART pins. +* Made Modbus plugin configuration symbols settable from compiler command line, added pin description to claimed UART pins. + +Drivers: +* Updated most to provide peripheral pin info to `$pins` report. +* Some bug fixes. + +--- + +Build 20211029: Core: * Fixed variable name typo. @@ -13,7 +33,9 @@ Drivers: * Updated for HAL function pointer rename, multiple Modbus clients where relevant. * Added support for using UART8 as serial port in iMXRT1062 driver. -Build 2021024: +--- + +Build 20211024: Core: * Moved @ G59.3 probing event call earlier in code, added check for X and Y homed. @@ -28,7 +50,7 @@ Drivers: --- -Build 2021019: +Build 20211019: Core: * Some minor changes to better support Trinamic drivers, probing and drivers/boards with limited number of control inputs \(cycle start, feed hold, ...\). @@ -46,7 +68,7 @@ Templates: --- -Build 2021015: +Build 20211015: Core: * Improved `grbl.on_probe_fixture` event signature by adding pointer to the pending tool when fired when M6 is executing \(NULL if not\) and a flag indicating that the current XY-position is within 5mm of G59.3. @@ -61,7 +83,7 @@ Templates: --- -Build 2021010: +Build 20211010: Core: * Added enum and associated get function for system defined named parameters. diff --git a/crossbar.h b/crossbar.h index d995cc6..7ce2ed1 100644 --- a/crossbar.h +++ b/crossbar.h @@ -52,7 +52,8 @@ typedef enum { Input_LimitV_Max, Input_MISO, Input_RX, - Input_KeypadStrobe, + Input_KeypadStrobe, // To be deprecated? + Input_I2CStrobe, Input_QEI_A, Input_QEI_B, Input_QEI_Select, @@ -171,6 +172,7 @@ PROGMEM static const pin_name_t pin_names[] = { { .function = Input_MISO, .name = "MISO" }, { .function = Input_RX, .name = "RX" }, { .function = Input_KeypadStrobe, .name = "Keypad strobe" }, + { .function = Input_I2CStrobe, .name = "I2C strobe" }, { .function = Input_QEI_A, .name = "QEI A" }, { .function = Input_QEI_B, .name = "QEI B" }, { .function = Input_QEI_Select, .name = "QEI select" }, @@ -284,6 +286,18 @@ typedef enum { IRQ_Mode_All = 0b11111 //!< 0b11111 (0x1F) - only used to report port capability. } pin_irq_mode_t; +typedef enum { + IRQ_I2C_Strobe = 0 +} irq_type_t; + +typedef bool (*irq_callback_ptr)(uint_fast8_t id, bool level); + +typedef struct driver_irq_handler { + irq_type_t type; + irq_callback_ptr callback; + struct driver_irq_handler *next; +} driver_irq_handler_t; + typedef enum { PullMode_None = 0b00, PullMode_Up = 0b01, @@ -335,4 +349,18 @@ typedef struct { xbar_event_ptr on_event; } xbar_t; +typedef struct { + pin_function_t function; + pin_group_t group; + void *port; + uint_fast8_t pin; + pin_mode_t mode; + const char *description; +} periph_pin_t; + +typedef struct periph_signal { + periph_pin_t pin; + struct periph_signal *next; +} periph_signal_t; + #endif diff --git a/driver_opts.h b/driver_opts.h index e577d67..ce3e1b7 100644 --- a/driver_opts.h +++ b/driver_opts.h @@ -84,6 +84,15 @@ #ifndef KEYPAD_ENABLE #define KEYPAD_ENABLE 0 #endif +#if KEYPAD_ENABLE == 1 +#ifdef I2C_STROBE_ENABLE +#undef I2C_STROBE_ENABLE +#endif +#define I2C_STROBE_ENABLE 1 +#endif +#ifndef I2C_STROBE_ENABLE +#define I2C_STROBE_ENABLE 0 +#endif #ifndef EEPROM_ENABLE #define EEPROM_ENABLE 0 #endif @@ -132,9 +141,6 @@ #ifndef ODOMETER_ENABLE #define ODOMETER_ENABLE 0 #endif -#ifndef BLUETOOTH_ENABLE -#define BLUETOOTH_ENABLE 0 -#endif #ifndef OPENPNP_ENABLE #define OPENPNP_ENABLE 0 #endif @@ -145,6 +151,19 @@ #define LIMITS_OVERRIDE_ENABLE 0 #endif +#ifndef BLUETOOTH_ENABLE +#define BLUETOOTH_ENABLE 0 +#endif +#if BLUETOOTH_ENABLE +#ifndef BLUETOOTH_DEVICE +#define BLUETOOTH_DEVICE "grblHAL" +#endif +#ifndef BLUETOOTH_SERVICE +#define BLUETOOTH_SERVICE "grblHAL Serial Port" // Minimum 8 characters, or blank for open +#endif +#endif + + #ifdef ENABLE_SAFETY_DOOR_INPUT_PIN #define SAFETY_DOOR_ENABLE 1 #else @@ -218,7 +237,7 @@ #if ETHERNET_ENABLE #ifndef NETWORK_HOSTNAME -#define NETWORK_HOSTNAME "GRBL" +#define NETWORK_HOSTNAME "grblHAL" #endif #ifndef NETWORK_IPMODE #define NETWORK_IPMODE 1 // 0 = static, 1 = DHCP, 2 = AutoIP diff --git a/errors.h b/errors.h index c7d6ef5..a00d944 100644 --- a/errors.h +++ b/errors.h @@ -108,7 +108,7 @@ typedef enum { typedef struct { status_code_t id; - const char *name; + const char *xname; const char *description; } status_detail_t; diff --git a/grbl.h b/grbl.h index ab42228..27b9798 100644 --- a/grbl.h +++ b/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20211029" +#define GRBL_VERSION_BUILD "20211107" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/grbllib.c b/grbllib.c index c907542..82cb1d2 100644 --- a/grbllib.c +++ b/grbllib.c @@ -85,6 +85,11 @@ void dummy_bool_handler (bool arg) // NOOP } +static bool dummy_irq_claim (irq_type_t irq, uint_fast8_t id, irq_callback_ptr callback) +{ + return false; +} + // main entry point int grbl_enter (void) @@ -108,6 +113,7 @@ int grbl_enter (void) hal.driver_reset = dummy_handler; hal.irq_enable = dummy_handler; hal.irq_disable = dummy_handler; + hal.irq_claim = dummy_irq_claim; hal.nvs.size = GRBL_NVS_SIZE; hal.limits.interrupt_callback = limit_interrupt_handler; hal.control.interrupt_callback = control_interrupt_handler; diff --git a/hal.h b/hal.h index f429d32..215082b 100644 --- a/hal.h +++ b/hal.h @@ -170,6 +170,23 @@ typedef struct { ioport_register_interrupt_handler_ptr register_interrupt_handler; } io_port_t; +/*! \brief Pointer to function for registering information about a peripheral pin. +\param pin as periph_pin_t struct containing pin information. +*/ +typedef void (*register_periph_pin_ptr)(const periph_pin_t *pin); + +/*! \brief Pointer to function for setting pin description for a peripheral pin. +\param function as #pin_function_t enum. +\param group as #pin_group_t enum. +\param s pointer to null terminated description string. +*/ +typedef void (*set_periph_pin_description_ptr)(const pin_function_t function, const pin_group_t group, const char *description); + +typedef struct { + register_periph_pin_ptr register_pin; //!< Opional handler for registering information about a peripheral pin (with the driver). + set_periph_pin_description_ptr set_pin_description; //!< Optional handler for setting a description of a peripheral pin. +} periph_port_t; + /*! \brief Pointer to callback function for pin enumerations. \param pin pointer to the \a xbar_t structure holding the pin information. */ @@ -610,6 +627,13 @@ typedef struct { encoder_reset_ptr reset; //!< Optional handler for resetting data for an encoder. } encoder_ptrs_t; +/*! \brief Pointer to function for claiming higher level interrupt requests (irq). +\param irq irq type as a #irq_type_t enum value. +\param id irq id, normally 0, > 0 if there are several sources for the same irq type. +\param callback function as a \a irq_callback_ptr function pointer. +*/ +typedef bool (*irq_claim_ptr)(irq_type_t irq, uint_fast8_t id, irq_callback_ptr callback); + /*! \brief HAL structure used for the driver interface. This structure contains properties and function pointers (to handlers) that the core uses to communicate with the driver. @@ -674,6 +698,9 @@ typedef struct { //! \brief Optional handler to enable global interrupts. void (*irq_disable)(void); + //! \brief Optional handler for claiming higher level interrupts. Set to a dummy handler on startup. + irq_claim_ptr irq_claim; + limits_ptrs_t limits; //!< Handlers for limit switches. homing_ptrs_t homing; //!< Handlers for limit switches, used by homing cycle. control_signals_ptrs_t control; //!< Handlers for control switches. @@ -686,6 +713,7 @@ typedef struct { probe_ptrs_t probe; //!< Optional handlers for probe input(s). tool_ptrs_t tool; //!< Optional handlers for tool changes. io_port_t port; //!< Optional handlers for axuillary I/O (adds support for M62-M66). + periph_port_t periph_port; //!< Optional handlers for peripheral pin registration. driver_reset_ptr driver_reset; //!< Optional handler, called on soft resets. Set to a dummy handler by the core at startup. nvs_io_t nvs; //!< Optional handlers for storing/retrieving settings and data to/from non-volatile storage (NVS). enumerate_pins_ptr enumerate_pins; //!< Optional handler for enumerating pins used by the driver. diff --git a/nuts_bolts.h b/nuts_bolts.h index 6411481..ef41c55 100644 --- a/nuts_bolts.h +++ b/nuts_bolts.h @@ -156,21 +156,24 @@ typedef enum { #define STRLEN_COORDVALUE (MAX_INT_DIGITS + N_DECIMAL_COORDVALUE_INCH + 1) // 8.4 format - excluding terminating null // Useful macros -#define clear_vector(a) memset(a, 0, sizeof(a)) #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif -#define isequal_position_vector(a,b) !memcmp(a, b, sizeof(coord_data_t)) +#ifndef constrain +#define constrain(val, min, max) ((val) < (min) ? (min) : ((val) > (max) ? (max) : (val))) +#endif +#define clear_vector(a) memset(a, 0, sizeof(a)) +#define isequal_position_vector(a, b) !memcmp(a, b, sizeof(coord_data_t)) // Bit field and masking macros #ifndef bit #define bit(n) (1UL << n) #endif -#define bit_true(x,mask) (x) |= (mask) -#define bit_false(x,mask) (x) &= ~(mask) +#define bit_true(x, mask) (x) |= (mask) +#define bit_false(x, mask) (x) &= ~(mask) #define BIT_SET(x, bit, v) { if (v) { x |= (bit); } else { x &= ~(bit); } } #define bit_istrue(x, mask) ((x & (mask)) != 0) diff --git a/pin_bits_masks.h b/pin_bits_masks.h index b5ecbba..8de4a16 100644 --- a/pin_bits_masks.h +++ b/pin_bits_masks.h @@ -94,8 +94,8 @@ #define PROBE_BIT (1<alarms[idx].id), ","); - write_quoted(list->alarms[idx].name, ","); + write_quoted("N/A", ","); +// write_quoted(list->alarms[idx].name, ","); write_quoted(list->alarms[idx].description ? list->alarms[idx].description : "", NULL); hal.stream.write(ASCII_EOL); } else { hal.stream.write("[ALARMCODE:"); hal.stream.write(uitoa(list->alarms[idx].id)); hal.stream.write(vbar); - hal.stream.write(list->alarms[idx].name); +// hal.stream.write(list->alarms[idx].name); hal.stream.write(vbar); if(list->alarms[idx].description) hal.stream.write(list->alarms[idx].description); @@ -1882,14 +1883,15 @@ status_code_t report_error_details (bool grbl_format) if(grbl_format) { write_quoted(uitoa(list->errors[idx].id), ","); - write_quoted(list->errors[idx].name, ","); + write_quoted("N/A", ","); +// write_quoted(list->errors[idx].name, ","); write_quoted(list->errors[idx].description ? list->errors[idx].description : "", NULL); hal.stream.write(ASCII_EOL); } else { hal.stream.write("[ERRORCODE:"); hal.stream.write(uitoa(list->errors[idx].id)); hal.stream.write(vbar); - hal.stream.write(list->errors[idx].name); +// hal.stream.write(list->errors[idx].name); hal.stream.write(vbar); if(list->errors[idx].description) hal.stream.write(list->errors[idx].description); diff --git a/spindle_control.c b/spindle_control.c index e003167..02afa03 100644 --- a/spindle_control.c +++ b/spindle_control.c @@ -34,7 +34,7 @@ void spindle_set_override (uint_fast8_t speed_override) if(sys.override.control.spindle_rpm_disable) return; - speed_override = max(min(speed_override, MAX_SPINDLE_RPM_OVERRIDE), MIN_SPINDLE_RPM_OVERRIDE); + speed_override = constrain(speed_override, MIN_SPINDLE_RPM_OVERRIDE, MAX_SPINDLE_RPM_OVERRIDE); if ((uint8_t)speed_override != sys.override.spindle_rpm) { sys.override.spindle_rpm = (uint8_t)speed_override; diff --git a/stream.h b/stream.h index db334a8..42da06b 100644 --- a/stream.h +++ b/stream.h @@ -196,6 +196,7 @@ typedef bool (*disable_rx_stream_ptr)(bool disable); //! Properties and handlers for stream I/O typedef struct { stream_type_t type; //!< Type of stream. + uint8_t instance; //!< Instance of stream type, starts from 0. bool connected; //!< Set to true by the driver if stream is connected. _Optional._ Under consideration. get_stream_buffer_count_ptr get_rx_buffer_free; //!< Handler for getting number of free characters in the input buffer. stream_write_ptr write; //!< Handler for writing string to current output stream only.