diff --git a/canbus.c b/canbus.c index dc38595..29bf792 100644 --- a/canbus.c +++ b/canbus.c @@ -31,7 +31,7 @@ #define CANBUS_BUFFER_LEN 8 #endif #ifndef CANBUS_BAUDRATE -#define CANBUS_BAUDRATE 0 // 125,000 +#define CANBUS_BAUDRATE 0 // 125000 #endif typedef struct { @@ -96,8 +96,8 @@ ISR_CODE static bool ISR_FUNC(canbus_queue_rx)(canbus_message_t message, can_rx_ uint8_t next_head = (rx_buffer.head + 1) % CANBUS_BUFFER_LEN; if((ok = next_head != rx_buffer.tail)) { - rx_buffer.rx[next_head].callback = callback; - rx_buffer.rx[next_head].message = message; + rx_buffer.rx[rx_buffer.head].callback = callback; + rx_buffer.rx[rx_buffer.head].message = message; rx_buffer.head = next_head; } @@ -132,8 +132,6 @@ static status_code_t canbus_set_baud (setting_id_t id, uint_fast16_t value) { settings.canbus_baud = value; - can_set_baud(baud[settings.canbus_baud]); - return can_set_baud(baud[settings.canbus_baud]) ? Status_OK : Status_SettingValueOutOfRange; } diff --git a/changelog.md b/changelog.md index 7f93d3d..74723a9 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,21 @@ ## grblHAL changelog +Build 20240709 + +Core: + +* For developers: added printf style debug output function and corresponding macro. See _grbl/stream.h_ for details. Added `grbl.on_report_ngc_parameters` event. + +* Fixed silly mistakes in CAN code. Ref. [issue #179](https://github.com/grblHAL/STM32F4xx/issues/179#issuecomment-2217912406). + +Drivers: + +* SAM3X8E: [PR #25](https://github.com/grblHAL/SAM3X8E/pull/25), adds missing guards around references. + +* STM32F1xx: added tentative board map for Creality v4.4.2 and v4.4.7. Ref. [issue #33](https://github.com/grblHAL/STM32F1xx/issues/33). Not tested! + +--- + Build 20240704 Core: @@ -13,7 +29,7 @@ Drivers: * ESP32: fixed WebUI regression. Ref. [issue #116](https://github.com/grblHAL/ESP32/issues/116). -* STM32F7xx, STM32F4xx: Added lowlevel CANbus API and enabled it for some boards. +* STM32F7xx, STM32F4xx: added lowlevel CANbus API and enabled it for some boards. --- diff --git a/core_handlers.h b/core_handlers.h index e099d2e..405cfec 100644 --- a/core_handlers.h +++ b/core_handlers.h @@ -95,6 +95,7 @@ typedef void (*on_unknown_accessory_override_ptr)(uint8_t cmd); typedef bool (*on_unknown_realtime_cmd_ptr)(char c); typedef void (*on_report_handlers_init_ptr)(void); typedef void (*on_report_options_ptr)(bool newopt); +typedef void (*on_report_ngc_parameters_ptr)(void); typedef void (*on_report_command_help_ptr)(void); typedef const char *(*on_setting_get_description_ptr)(setting_id_t id); typedef void (*on_global_settings_restore_ptr)(void); @@ -156,6 +157,7 @@ typedef struct { on_execute_realtime_ptr on_execute_delay; on_unknown_accessory_override_ptr on_unknown_accessory_override; on_report_options_ptr on_report_options; + on_report_ngc_parameters_ptr on_report_ngc_parameters; on_report_command_help_ptr on_report_command_help; //!< Deprecated, use system_register_commands() to register new commands. on_rt_reports_added_ptr on_rt_reports_added; on_global_settings_restore_ptr on_global_settings_restore; diff --git a/grbl.h b/grbl.h index fdc0090..8f1cfa5 100644 --- a/grbl.h +++ b/grbl.h @@ -42,7 +42,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20240704 +#define GRBL_BUILD 20240709 #define GRBL_URL "https://github.com/grblHAL" diff --git a/messages.h b/messages.h index 0b1a8fb..3983fed 100644 --- a/messages.h +++ b/messages.h @@ -53,7 +53,8 @@ typedef enum { typedef enum { Message_Plain = 0, Message_Info, - Message_Warning + Message_Warning, + Message_Debug } message_type_t; typedef struct { diff --git a/report.c b/report.c index edbd558..3247ab4 100644 --- a/report.c +++ b/report.c @@ -21,7 +21,7 @@ */ /* - This file functions as the primary feedback interface for Grbl. Any outgoing data, such + This file functions as the primary feedback interface for grblHAL. Any outgoing data, such as the protocol status messages, feedback messages, and status reports, are stored here. For the most part, these functions primarily are called from protocol.c methods. If a different style feedback is desired (i.e. JSON), then a user can change these following @@ -267,6 +267,10 @@ void report_message (const char *msg, message_type_t type) hal.stream.write("Warning: "); break; + case Message_Debug: + hal.stream.write("Debug: "); + break; + default: break; } @@ -405,7 +409,7 @@ status_code_t report_help (char *args) } -// Grbl settings print out. +// grblHAL settings print out. static int cmp_settings (const void *a, const void *b) { @@ -508,7 +512,7 @@ void report_grbl_settings (bool all, void *data) // Prints current probe parameters. Upon a probe command, these parameters are updated upon a // successful probe or upon a failed probe with the G38.3 without errors command (if supported). -// These values are retained until Grbl is power-cycled, whereby they will be re-zeroed. +// These values are retained until grblHAL is power-cycled, whereby they will be re-zeroed. void report_probe_parameters (void) { // Report in terms of machine position. @@ -581,7 +585,7 @@ status_code_t report_named_ngc_parameter (char *arg) #endif -// Prints Grbl NGC parameters (coordinate offsets, probing, tool table) +// Prints grblHAL NGC parameters (coordinate offsets, probing, tool table) void report_ngc_parameters (void) { uint_fast8_t idx; @@ -656,6 +660,9 @@ void report_ngc_parameters (void) hal.stream.write(get_axis_value(sys.tlo_reference[plane.axis_linear] / settings.axis[plane.axis_linear].steps_per_mm)); hal.stream.write("]" ASCII_EOL); } + + if(grbl.on_report_ngc_parameters) + grbl.on_report_ngc_parameters(); } static inline bool is_g92_active (void) @@ -1082,8 +1089,8 @@ void report_build_info (char *line, bool extended) } -// Prints the character string line Grbl has received from the user, which has been pre-parsed, -// and has been sent into protocol_execute_line() routine to be executed by Grbl. +// Prints the character string line grblHAL has received from the user, which has been pre-parsed, +// and has been sent into protocol_execute_line() routine to be executed by grblHAL. void report_echo_line_received (char *line) { hal.stream.write("[echo: "); diff --git a/stream.c b/stream.c index c80b814..1154748 100644 --- a/stream.c +++ b/stream.c @@ -26,6 +26,14 @@ #include "protocol.h" #include "state_machine.h" +#if defined(DEBUG) || defined(DEBUGOUT) +#include +#include +#ifndef DEBUG_BUFFER +#define DEBUG_BUFFER 100 +#endif +#endif + static stream_rx_buffer_t rxbackup; typedef struct { @@ -664,6 +672,20 @@ void debug_writeln (const char *s) } } +void debug_printf (const char *fmt, ...) +{ + char debug_out[DEBUG_BUFFER]; + + va_list args; + va_start(args, fmt); + vsnprintf(debug_out, sizeof(debug_out) - 1, fmt, args); + va_end(args); + + debug_writeln(debug_out); + while(hal.stream.get_tx_buffer_count()) // Wait until message is delivered + grbl.on_execute_realtime(state_get()); +} + static bool debug_claim_stream (io_stream_properties_t const *stream) { io_stream_t const *claimed = NULL; @@ -694,4 +716,29 @@ bool debug_stream_init (void) return hal.debug.write == debug_write; } +#elif defined(DEBUG) + +void debug_printf (const char *fmt, ...) +{ + char debug_out[DEBUG_BUFFER]; + + va_list args; + va_start(args, fmt); + vsnprintf(debug_out, sizeof(debug_out) - 1, fmt, args); + va_end(args); + + if(hal.stream.write) { + report_message(debug_out, Message_Debug); + while(hal.stream.get_tx_buffer_count()) // Wait until message is delivered + grbl.on_execute_realtime(state_get()); + } +} + +#else + +void debug_printf (const char *fmt, ...) +{ + // NOOP +} + #endif diff --git a/stream.h b/stream.h index 3b41f85..8a3983f 100644 --- a/stream.h +++ b/stream.h @@ -5,18 +5,18 @@ Copyright (c) 2019-2023 Terje Io - Grbl is free software: you can redistribute it and/or modify + grblHAL 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, + grblHAL 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 + 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 . + along with grblHAL. If not, see . */ /*! \file @@ -357,11 +357,21 @@ io_stream_t const *stream_open_instance (uint8_t instance, uint32_t baud_rate, s bool stream_set_description (const io_stream_t *stream, const char *description); +void debug_printf(const char *fmt, ...); + +#if defined(DEBUG) || defined(DEBUGOUT) +#define DEBUG_PRINT 1 #ifdef DEBUGOUT void debug_write (const char *s); void debug_writeln (const char *s); bool debug_stream_init (void); #endif +#else +#define DEBUG_PRINT 0 +#endif + +#define debug_print(fmt, ...) \ + do { if(DEBUG_PRINT) debug_printf(fmt, __VA_ARGS__); } while(0) #ifdef __cplusplus }