From 8ddec618cd6549295214b220d045f919942705e3 Mon Sep 17 00:00:00 2001 From: bdring Date: Wed, 3 Feb 2021 14:52:28 -0600 Subject: [PATCH] Updates from PWM_ISR_Fix branch (#755) - $Message/Level - ISR safe ledcWrite --- Grbl_Esp32/src/Config.h | 4 +--- Grbl_Esp32/src/Grbl.h | 2 +- Grbl_Esp32/src/Report.cpp | 8 ++++++-- Grbl_Esp32/src/Report.h | 6 +++--- Grbl_Esp32/src/SettingsDefinitions.cpp | 27 ++++++++++++++++++++------ Grbl_Esp32/src/SettingsDefinitions.h | 2 ++ Grbl_Esp32/src/Spindles/PWMSpindle.cpp | 11 ++++++++++- 7 files changed, 44 insertions(+), 16 deletions(-) diff --git a/Grbl_Esp32/src/Config.h b/Grbl_Esp32/src/Config.h index f22e88aa..2feece69 100644 --- a/Grbl_Esp32/src/Config.h +++ b/Grbl_Esp32/src/Config.h @@ -47,7 +47,7 @@ Some features should not be changed. See notes below. // that the machine file might choose to undefine. // Note: HOMING_CYCLES are now settings -#define SUPPORT_TASK_CORE 1 // Reference: CONFIG_ARDUINO_RUNNING_CORE = 1 +#define SUPPORT_TASK_CORE 1 // Reference: CONFIG_ARDUINO_RUNNING_CORE = 1 // Inverts pin logic of the control command pins based on a mask. This essentially means you can use // normally-closed switches on the specified pins, rather than the default normally-open switches. @@ -87,8 +87,6 @@ const int MAX_N_AXIS = 6; # define LIMIT_MASK B0 #endif -#define GRBL_MSG_LEVEL MsgLevel::Info // what level of [MSG:....] do you want to see 0=all off - // Serial baud rate // OK to change, but the ESP32 boot text is 115200, so you will not see that is your // serial monitor, sender, etc uses a different value than 115200 diff --git a/Grbl_Esp32/src/Grbl.h b/Grbl_Esp32/src/Grbl.h index 26b446e9..f42b4b85 100644 --- a/Grbl_Esp32/src/Grbl.h +++ b/Grbl_Esp32/src/Grbl.h @@ -23,7 +23,7 @@ // Grbl versioning system const char* const GRBL_VERSION = "1.3a"; -const char* const GRBL_VERSION_BUILD = "20210129"; +const char* const GRBL_VERSION_BUILD = "20210203"; //#include #include diff --git a/Grbl_Esp32/src/Report.cpp b/Grbl_Esp32/src/Report.cpp index 67d4fddd..da8b5316 100644 --- a/Grbl_Esp32/src/Report.cpp +++ b/Grbl_Esp32/src/Report.cpp @@ -111,9 +111,13 @@ void grbl_msg_sendf(uint8_t client, MsgLevel level, const char* format, ...) { if (client == CLIENT_INPUT) { return; } - if (level > GRBL_MSG_LEVEL) { - return; + + if (message_level != NULL) { // might be null before messages are setup + if (level > static_cast(message_level->get())) { + return; + } } + char loc_buf[100]; char* temp = loc_buf; va_list arg; diff --git a/Grbl_Esp32/src/Report.h b/Grbl_Esp32/src/Report.h index 5b128b5d..2ffcecee 100644 --- a/Grbl_Esp32/src/Report.h +++ b/Grbl_Esp32/src/Report.h @@ -52,8 +52,8 @@ enum class Message : uint8_t { #define CLIENT_ALL 0xFF #define CLIENT_COUNT 5 // total number of client types regardless if they are used -enum class MsgLevel : uint8_t { - None = 0, // set GRBL_MSG_LEVEL in config.h to the level you want to see +enum class MsgLevel : int8_t { // Use $Message/Level + None = 0, Error = 1, Warning = 2, Info = 3, @@ -128,4 +128,4 @@ char* reportAxisLimitsMsg(uint8_t axis); char* reportAxisNameMsg(uint8_t axis); char* reportAxisNameMsg(uint8_t axis, uint8_t dual_axis); -void reportTaskStackSize(UBaseType_t& saved); +void reportTaskStackSize(UBaseType_t& saved); diff --git a/Grbl_Esp32/src/SettingsDefinitions.cpp b/Grbl_Esp32/src/SettingsDefinitions.cpp index 15072d3b..bde5e97f 100644 --- a/Grbl_Esp32/src/SettingsDefinitions.cpp +++ b/Grbl_Esp32/src/SettingsDefinitions.cpp @@ -57,6 +57,8 @@ IntSetting* spindle_pwm_bit_precision; EnumSetting* spindle_type; +EnumSetting* message_level; + enum_opt_t spindleTypes = { // clang-format off { "NONE", int8_t(SpindleType::NONE) }, @@ -71,6 +73,17 @@ enum_opt_t spindleTypes = { // clang-format on }; +enum_opt_t messageLevels = { + // clang-format off + { "None", int8_t(MsgLevel::None) }, + { "Error", int8_t(MsgLevel::Error) }, + { "Warning", int8_t(MsgLevel::Warning) }, + { "Info", int8_t(MsgLevel::Info) }, + { "Debug", int8_t(MsgLevel::Debug) }, + { "Verbose", int8_t(MsgLevel::Verbose) }, + // clang-format on +}; + AxisSettings* x_axis_settings; AxisSettings* y_axis_settings; AxisSettings* z_axis_settings; @@ -256,16 +269,16 @@ void make_settings() { b_axis_settings = axis_settings[B_AXIS]; c_axis_settings = axis_settings[C_AXIS]; for (axis = MAX_N_AXIS - 1; axis >= 0; axis--) { - def = &axis_defaults[axis]; - auto setting = - new IntSetting(EXTENDED, WG, makeGrblName(axis, 170), makename(def->name, "StallGuard"), def->stallguard, -64, 255, postMotorSetting); + def = &axis_defaults[axis]; + auto setting = new IntSetting( + EXTENDED, WG, makeGrblName(axis, 170), makename(def->name, "StallGuard"), def->stallguard, -64, 255, postMotorSetting); setting->setAxis(axis); axis_settings[axis]->stallguard = setting; } for (axis = MAX_N_AXIS - 1; axis >= 0; axis--) { - def = &axis_defaults[axis]; - auto setting = - new IntSetting(EXTENDED, WG, makeGrblName(axis, 160), makename(def->name, "Microsteps"), def->microsteps, 0, 256, postMotorSetting); + def = &axis_defaults[axis]; + auto setting = new IntSetting( + EXTENDED, WG, makeGrblName(axis, 160), makename(def->name, "Microsteps"), def->microsteps, 0, 256, postMotorSetting); setting->setAxis(axis); axis_settings[axis]->microsteps = setting; } @@ -395,4 +408,6 @@ void make_settings() { user_macro2 = new StringSetting(EXTENDED, WG, NULL, "User/Macro2", DEFAULT_USER_MACRO2); user_macro1 = new StringSetting(EXTENDED, WG, NULL, "User/Macro1", DEFAULT_USER_MACRO1); user_macro0 = new StringSetting(EXTENDED, WG, NULL, "User/Macro0", DEFAULT_USER_MACRO0); + + message_level = +new EnumSetting(NULL, EXTENDED, WG, NULL, "Message/Level", static_cast(MsgLevel::Info), &messageLevels, NULL); } diff --git a/Grbl_Esp32/src/SettingsDefinitions.h b/Grbl_Esp32/src/SettingsDefinitions.h index 7315637a..95c229e9 100644 --- a/Grbl_Esp32/src/SettingsDefinitions.h +++ b/Grbl_Esp32/src/SettingsDefinitions.h @@ -65,3 +65,5 @@ extern StringSetting* user_macro0; extern StringSetting* user_macro1; extern StringSetting* user_macro2; extern StringSetting* user_macro3; + +extern EnumSetting* message_level; diff --git a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp index 23477494..ba364768 100644 --- a/Grbl_Esp32/src/Spindles/PWMSpindle.cpp +++ b/Grbl_Esp32/src/Spindles/PWMSpindle.cpp @@ -20,6 +20,7 @@ */ #include "PWMSpindle.h" +#include "soc/ledc_struct.h" // ======================= PWM ============================== /* @@ -222,7 +223,15 @@ namespace Spindles { duty = (1 << _pwm_precision) - duty; } - ledcWrite(_pwm_chan_num, duty); + //ledcWrite(_pwm_chan_num, duty); + + // This was ledcWrite, but this is called from an ISR + // and ledcWrite uses RTOS features not compatible with ISRs + LEDC.channel_group[0].channel[0].duty.duty = duty << 4; + bool on = !!duty; + LEDC.channel_group[0].channel[0].conf0.sig_out_en = on; + LEDC.channel_group[0].channel[0].conf1.duty_start = on; + LEDC.channel_group[0].channel[0].conf0.clk_en = on; } void PWM::set_enable_pin(bool enable) {