From 6c0bd647a5a758bc8da995b9288553d7abf647f9 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Sun, 8 Aug 2021 12:47:41 +0200 Subject: [PATCH] Added optional HAL entry point for stepper motor enumeration, improved optional driver support files. --- README.md | 2 +- changelog.md | 12 ++++++++ driver_opts.h | 5 ++++ grbl.h | 2 +- hal.h | 26 +++++++++++++++++ motor_pins.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++--- nvs_buffer.c | 3 +- platform.h | 2 +- plugins_init.h | 5 ---- stream.c | 2 +- 10 files changed, 123 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 09dda7a..4fc8dd7 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 20210726, see the [changelog](changelog.md) for details. +Latest build date is 20210803, see the [changelog](changelog.md) for details. --- diff --git a/changelog.md b/changelog.md index f833e07..70a833a 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,17 @@ ## grblHAL changelog +Build 20210803: + +Core: +* Added optional HAL entry point for stepper motor enumeration (axis vs. motor id). Used by motors plugin. +* Improved optional driver support files. + +Drivers & plugins: +* Added F103RC support and a board map for the BTT SKR MINI E3 V2.0 to the STMF1xx driver. +* Added tentative plasma plugin support to the SAM3X8E \(Arduino Due\) driver. +* Updated motors plugin to match updated [Trinamic library](https://github.com/terjeio/Trinamic-library), added support for TMC2209++. +* Some minor bug fixes and improvements. + Build 20210726: Core: diff --git a/driver_opts.h b/driver_opts.h index 38cf62c..7d00305 100644 --- a/driver_opts.h +++ b/driver_opts.h @@ -102,6 +102,11 @@ #ifndef TRINAMIC_I2C #define TRINAMIC_I2C 0 #endif +#if TRINAMIC_ENABLE && TRINAMIC_I2C +#define TRINAMIC_MOTOR_ENABLE 1 +#else +#define TRINAMIC_MOTOR_ENABLE 0 +#endif #ifndef TRINAMIC_DEV #define TRINAMIC_DEV 0 #endif diff --git a/grbl.h b/grbl.h index 6e2c16b..02bfd91 100644 --- a/grbl.h +++ b/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_VERSION_BUILD "20210715" +#define GRBL_VERSION_BUILD "20210803" // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/hal.h b/hal.h index 3a05c51..76e57dd 100644 --- a/hal.h +++ b/hal.h @@ -323,10 +323,35 @@ typedef struct { control_signals_callback_ptr interrupt_callback; //!< Callback for informing about control switches events. _Set by the core at startup. } control_signals_ptrs_t; + /************** * Steppers * **************/ +/*! \brief Motor vs. axis mapping +__NOTE:__ id and axis values are equal for primary motors, unequal for secondary (ganged) motors. +*/ +typedef union { + uint32_t value; + struct { + uint32_t id : 8, + axis : 8; + }; +} motor_map_t; + +/*! \brief Signature of the callback function to receive motor vs. axis mappings. +\param motor a motor_map_t struct. +*/ +typedef void (*motor_iterator_callback_ptr)(motor_map_t motor); + + +/*! \brief Pointer to function for iterating over stepper motor vs. axis mappings. + +\param callback pointer to a #motor_iterator_callback_ptr function to be called for each motor. +*/ +typedef void (*motor_iterator_ptr)(motor_iterator_callback_ptr callback); + + /*! \brief Pointer to function for enabling all stepper motors and the main stepper interrupt. The first interrupt should be generated after a short delay to allow the drivers time to apply power to the motors. @@ -418,6 +443,7 @@ typedef struct { stepper_interrupt_callback_ptr interrupt_callback; //!< Callback for informing about the next step pulse to output. _Set by the core at startup._ stepper_get_auto_squared_ptr get_auto_squared; //!< Optional handler getting which axes are configured for auto squaring. stepper_output_step_ptr output_step; //!< Optional handler for outputting a single step pulse. _Experimental._ + motor_iterator_ptr motor_iterator; //!< Optional handler iteration over motor vs. axis mappings. Required for the motors plugin (Trinamic drivers). } stepper_ptrs_t; diff --git a/motor_pins.h b/motor_pins.h index 63bedfb..996524f 100644 --- a/motor_pins.h +++ b/motor_pins.h @@ -373,13 +373,13 @@ #endif // Z_DOUBLED #ifdef X_DOUBLED -#undef X_DOUBLED +#define X2_MOTOR (N_AXIS + X_DOUBLED - 1) #endif #ifdef Y_DOUBLED -#undef Y_DOUBLED +#define Y2_MOTOR (N_AXIS + Y_DOUBLED - 1) #endif #ifdef Z_DOUBLED -#undef Z_DOUBLED +#define Z2_MOTOR (N_AXIS + Z_DOUBLED - 1) #endif #endif // N_GANGED @@ -609,9 +609,21 @@ #endif #ifndef STEPPERS_ENABLE_MASK + #ifdef STEPPERS_ENABLE_BIT #define STEPPERS_ENABLE_MASK STEPPERS_ENABLE_BIT #else + +#if N_AXIS >=4 && !defined(A_ENABLE_BIT) +#define A_ENABLE_BIT 0 +#endif +#if N_AXIS >=5 && !defined(B_ENABLE_BIT) +#define B_ENABLE_BIT 0 +#endif +#if N_AXIS >= 6 && !defined(C_ENABLE_BIT) +#define C_ENABLE_BIT 0 +#endif + #if N_AXIS == 3 #define STEPPERS_ENABLE_MASK (X_ENABLE_BIT|Y_ENABLE_BIT|Z_ENABLE_BIT) #elif N_AXIS == 4 @@ -626,9 +638,33 @@ #define STEPPERS_ENABLE_MASK (X_ENABLE_BIT|Y_ENABLE_BIT|Z_ENABLE_BIT|A_ENABLE_BIT|B_ENABLE_BIT|C_ENABLE_BIT|U_ENABLE_BIT|V_ENABLE_BIT) #endif #endif -#endif + +#endif // STEPPERS_ENABLE_MASK #ifndef LIMIT_MASK + +#if N_AXIS >=4 && !defined(A_LIMIT_BIT) +#ifdef A_LIMIT_PIN +#define A_LIMIT_BIT (1<=5 && !defined(B_LIMIT_BIT) +#ifdef B_LIMIT_PIN +#define B_LIMIT_BIT (1<= 6 && !defined(C_LIMIT_BIT) +#ifdef A_LIMIT_PIN +#define C_LIMIT_BIT (1<= GRBL_NVS_SIZE); - nvsbuffer = malloc(NVS_SIZE); + if((nvsbuffer = malloc(NVS_SIZE))) + memset(nvsbuffer, 0, NVS_SIZE); return nvsbuffer != NULL; } diff --git a/platform.h b/platform.h index cbd33ca..9e1c738 100644 --- a/platform.h +++ b/platform.h @@ -21,7 +21,7 @@ #pragma once -#if defined(STM32F103xB) || defined(STM32F401xC) || defined(STM32F407xx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F756xx) +#if defined(STM32F103xB) || defined(STM32F103xE) || defined(STM32F401xC) || defined(STM32F407xx) || defined(STM32F411xE) || defined(STM32F446xx) || defined(STM32F756xx) #define STM32_PLATFORM #endif diff --git a/plugins_init.h b/plugins_init.h index 5b0948a..3be81c5 100644 --- a/plugins_init.h +++ b/plugins_init.h @@ -23,11 +23,6 @@ along with Grbl. If not, see . */ -#if PLASMA_ENABLE - extern void plasma_init (void); - plasma_init(); -#endif - #if TRINAMIC_ENABLE extern bool trinamic_init (void); trinamic_init(); diff --git a/stream.c b/stream.c index f13af52..9127085 100644 --- a/stream.c +++ b/stream.c @@ -41,7 +41,7 @@ int16_t stream_get_null (void) return SERIAL_NO_DATA; } -static bool await_toolchange_ack (char c) +ISR_CODE static bool await_toolchange_ack (char c) { if(c == CMD_TOOL_ACK && !stream.rxbuffer->backup) { memcpy(&rxbackup, stream.rxbuffer, sizeof(stream_rx_buffer_t));