From 2554d219255c23ae5621efeb9295fe9c9d76cceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Mon, 2 Aug 2021 12:20:10 +0000 Subject: [PATCH 01/83] Use uint8_t when using axis enum Saves 76 bytes of flash memory --- Firmware/Marlin.h | 4 ++-- Firmware/Marlin_main.cpp | 12 ++++++------ Firmware/ultralcd.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index c2c5ca933..e6c5685d0 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -294,9 +294,9 @@ extern int8_t lcd_change_fil_state; extern float default_retraction; #ifdef TMC2130 -void homeaxis(int axis, uint8_t cnt = 1, uint8_t* pstep = 0); +void homeaxis(uint8_t axis, uint8_t cnt = 1, uint8_t* pstep = 0); #else -void homeaxis(int axis, uint8_t cnt = 1); +void homeaxis(uint8_t axis, uint8_t cnt = 1); #endif //TMC2130 diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d1bc83a15..32dc71062 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2034,9 +2034,9 @@ DEFINE_PGM_READ_ANY(signed char, byte); #define XYZ_CONSTS_FROM_CONFIG(type, array, CONFIG) \ static const PROGMEM type array##_P[3] = \ { X_##CONFIG, Y_##CONFIG, Z_##CONFIG }; \ -static inline type array(int axis) \ +static inline type array(uint8_t axis) \ { return pgm_read_any(&array##_P[axis]); } \ -type array##_ext(int axis) \ +type array##_ext(uint8_t axis) \ { return pgm_read_any(&array##_P[axis]); } XYZ_CONSTS_FROM_CONFIG(float, base_min_pos, MIN_POS); @@ -2046,7 +2046,7 @@ XYZ_CONSTS_FROM_CONFIG(float, max_length, MAX_LENGTH); XYZ_CONSTS_FROM_CONFIG(float, home_retract_mm, HOME_RETRACT_MM); XYZ_CONSTS_FROM_CONFIG(signed char, home_dir, HOME_DIR); -static void axis_is_at_home(int axis) { +static void axis_is_at_home(uint8_t axis) { current_position[axis] = base_home_pos(axis) + cs.add_homing[axis]; min_pos[axis] = base_min_pos(axis) + cs.add_homing[axis]; max_pos[axis] = base_max_pos(axis) + cs.add_homing[axis]; @@ -2362,9 +2362,9 @@ static void check_Z_crash(void) #endif //TMC2130 #ifdef TMC2130 -void homeaxis(int axis, uint8_t cnt, uint8_t* pstep) +void homeaxis(uint8_t axis, uint8_t cnt, uint8_t* pstep) #else -void homeaxis(int axis, uint8_t cnt) +void homeaxis(uint8_t axis, uint8_t cnt) #endif //TMC2130 { bool endstops_enabled = enable_endstops(true); //RP: endstops should be allways enabled durring homing @@ -2835,7 +2835,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon { current_position[X_AXIS] = 0;current_position[Y_AXIS] = 0; - int x_axis_home_dir = home_dir(X_AXIS); + uint8_t x_axis_home_dir = home_dir(X_AXIS); plan_set_position_curposXYZE(); destination[X_AXIS] = 1.5 * max_length(X_AXIS) * x_axis_home_dir;destination[Y_AXIS] = 1.5 * max_length(Y_AXIS) * home_dir(Y_AXIS); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 81fef9674..d7b2a02cc 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -161,8 +161,8 @@ static void lcd_belttest_v(); static void lcd_selftest_v(); #ifdef TMC2130 -static void reset_crash_det(unsigned char axis); -static bool lcd_selfcheck_axis_sg(unsigned char axis); +static void reset_crash_det(uint8_t axis); +static bool lcd_selfcheck_axis_sg(uint8_t axis); #else static bool lcd_selfcheck_axis(int _axis, int _travel); static bool lcd_selfcheck_pulleys(int axis); @@ -7706,14 +7706,14 @@ bool lcd_selftest() #ifdef TMC2130 -static void reset_crash_det(unsigned char axis) { +static void reset_crash_det(uint8_t axis) { current_position[axis] += 10; plan_buffer_line_curposXYZE(manual_feedrate[0] / 60); st_synchronize(); if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true; } -static bool lcd_selfcheck_axis_sg(unsigned char axis) { +static bool lcd_selfcheck_axis_sg(uint8_t axis) { // each axis length is measured twice float axis_length, current_position_init, current_position_final; float measured_axis_length[2]; From a54a133968156d194e294e3a196ee15b9dbc1a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Mon, 2 Aug 2021 19:20:51 +0000 Subject: [PATCH 02/83] Use memset instead of nested for-loop to zero a 2d array Saves 26 bytes of flash memory and removes two 'int' types --- Firmware/mesh_bed_leveling.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Firmware/mesh_bed_leveling.cpp b/Firmware/mesh_bed_leveling.cpp index 344d41e3f..aa969340c 100644 --- a/Firmware/mesh_bed_leveling.cpp +++ b/Firmware/mesh_bed_leveling.cpp @@ -10,9 +10,7 @@ mesh_bed_leveling::mesh_bed_leveling() { reset(); } void mesh_bed_leveling::reset() { active = 0; - for (int y = 0; y < MESH_NUM_Y_POINTS; y++) - for (int x = 0; x < MESH_NUM_X_POINTS; x++) - z_values[y][x] = 0; + memset(z_values, 0, sizeof(float) * MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS); } static inline bool vec_undef(const float v[2]) From 05ed5b9668eb341116102e79b3a849a81f081c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Tue, 3 Aug 2021 21:35:28 +0000 Subject: [PATCH 03/83] Improve lcd_selftest_screen_step() parameter types Saves 62 bytes of flash memory --- Firmware/ultralcd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index d7b2a02cc..91010b691 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -207,7 +207,7 @@ enum class TestError : uint_least8_t }; static int lcd_selftest_screen(TestScreen screen, int _progress, int _progress_scale, bool _clear, int _delay); -static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator); +static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name, const char *_indicator); static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite, bool _default=false); @@ -8547,7 +8547,7 @@ static int lcd_selftest_screen(TestScreen screen, int _progress, int _progress_s return (_progress >= _progress_scale * 2) ? 0 : _progress; } -static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name_PROGMEM, const char *_indicator) +static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name_PROGMEM, const char *_indicator) { lcd_set_cursor(_col, _row); uint8_t strlenNameP = strlen_P(_name_PROGMEM); From 1946c58d21cf60cdbeeb2d49a4769e96e7981f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Tue, 3 Aug 2021 21:46:11 +0000 Subject: [PATCH 04/83] 1. Remove redundant variable 'inters' 2. 'gh' variable can be 1 byte instead of 2 This saves 26 bytes of flash memory --- Firmware/ultralcd.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 91010b691..e580eba3e 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -610,15 +610,14 @@ void lcdui_print_status_line(void) else if ((IS_SD_PRINTING) && (custom_message_type == CustomMsg::Status)) { // If printing from SD, show what we are printing const char* longFilenameOLD = (card.longFilename[0] ? card.longFilename : card.filename); if(strlen(longFilenameOLD) > LCD_WIDTH) { - int inters = 0; - int gh = scrollstuff; - while (((gh - scrollstuff) < LCD_WIDTH) && (inters == 0)) { + uint8_t gh = scrollstuff; + while (((gh - scrollstuff) < LCD_WIDTH)) { if (longFilenameOLD[gh] == '\0') { lcd_set_cursor(gh - scrollstuff, 3); lcd_print(longFilenameOLD[gh - 1]); scrollstuff = 0; gh = scrollstuff; - inters = 1; + break; } else { lcd_set_cursor(gh - scrollstuff, 3); lcd_print(longFilenameOLD[gh - 1]); From 8d7d1698ee1e86812f06518889e68b2912300754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Tue, 3 Aug 2021 21:48:26 +0000 Subject: [PATCH 05/83] Remove unused global variable 'chunkHead' No change in memory on my end, but it is one less 'int' :) --- Firmware/Marlin_main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 32dc71062..06d38a782 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1759,7 +1759,6 @@ void trace(); #define CHUNK_SIZE 64 // bytes #define SAFETY_MARGIN 1 char chunk[CHUNK_SIZE+SAFETY_MARGIN]; -int chunkHead = 0; void serial_read_stream() { From b716c208d783c106353443b066408ebfcb258d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Tue, 3 Aug 2021 22:42:01 +0000 Subject: [PATCH 06/83] Various optimisation to change int to uint8_t This commit saves 174 bytes of flash memory --- Firmware/Marlin_main.cpp | 12 ++++++------ Firmware/lcd.cpp | 2 +- Firmware/mesh_bed_calibration.cpp | 2 +- Firmware/planner.cpp | 2 +- Firmware/tmc2130.cpp | 2 +- Firmware/ultralcd.cpp | 6 +++--- Firmware/ultralcd.h | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 06d38a782..493ad68f2 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5293,7 +5293,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) */ case 75: { - for (int i = 40; i <= 110; i++) + for (uint8_t i = 40; i <= 110; i++) printf_P(_N("%d %.2f"), i, temp_comp_interpolation(i)); } break; @@ -7791,8 +7791,8 @@ Sigma_Exit: */ case 300: // M300 { - int beepS = code_seen('S') ? code_value() : 110; - int beepP = code_seen('P') ? code_value() : 1000; + uint16_t beepS = code_seen('S') ? code_value() : 110; + uint16_t beepP = code_seen('P') ? code_value() : 1000; if (beepS > 0) { #if BEEPER > 0 @@ -11487,8 +11487,8 @@ void restore_print_from_eeprom(bool mbl_was_active) { depth = eeprom_read_byte((uint8_t*)EEPROM_DIR_DEPTH); MYSERIAL.println(int(depth)); - for (int i = 0; i < depth; i++) { - for (int j = 0; j < 8; j++) { + for (uint8_t i = 0; i < depth; i++) { + for (uint8_t j = 0; j < 8; j++) { dir_name[j] = eeprom_read_byte((uint8_t*)EEPROM_DIRS + j + 8 * i); } dir_name[8] = '\0'; @@ -11497,7 +11497,7 @@ void restore_print_from_eeprom(bool mbl_was_active) { card.chdir(dir_name, false); } - for (int i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { filename[i] = eeprom_read_byte((uint8_t*)EEPROM_FILENAME + i); } filename[8] = '\0'; diff --git a/Firmware/lcd.cpp b/Firmware/lcd.cpp index 37b70f1a1..024f973f9 100644 --- a/Firmware/lcd.cpp +++ b/Firmware/lcd.cpp @@ -344,7 +344,7 @@ void lcd_createChar_P(uint8_t location, const uint8_t* charmap) { location &= 0x7; // we only have 8 locations 0-7 lcd_command(LCD_SETCGRAMADDR | (location << 3)); - for (int i=0; i<8; i++) + for (uint8_t i = 0; i < 8; i++) lcd_send(pgm_read_byte(&charmap[i]), HIGH); } diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index ef83e5735..f97851059 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -2240,7 +2240,7 @@ BedSkewOffsetDetectionResultType find_bed_offset_and_skew(int8_t verbosity_level /// Retry point scanning if a point with bad data appears. /// Bad data could be cause by "cold" sensor. /// This behavior vanishes after few point scans so retry will help. - for (int retries = 0; retries <= 1; ++retries) { + for (uint8_t retries = 0; retries <= 1; ++retries) { bool retry = false; for (int k = 0; k < 4; ++k) { // Don't let the manage_inactivity() function remove power from the motors. diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index b6d012b24..5c89a5456 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1023,7 +1023,7 @@ Having the real displacement of the head, we can calculate the total movement le // Calculate speed in mm/second for each axis. No divide by zero due to previous checks. float inverse_second = feed_rate * inverse_millimeters; - int moves_queued = moves_planned(); + uint8_t moves_queued = moves_planned(); // slow down when de buffer starts to empty, rather than wait at the corner for a buffer refill #ifdef SLOWDOWN diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index dbce5ea07..30712379e 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -911,7 +911,7 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000) uint8_t s = 0; //current segment int8_t b; //encoded bit value int8_t dA; //delta value - int i; //microstep index + uint8_t i; //microstep index uint32_t reg = 0; //tmc2130 register tmc2130_wr_MSLUTSTART(axis, 0, amp); for (i = 0; i < 256; i++) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index e580eba3e..5ed326a04 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -693,7 +693,7 @@ void lcdui_print_status_line(void) } // Fill the rest of line to have nice and clean output - for(int fillspace = 0; fillspace < LCD_WIDTH; fillspace++) + for(uint8_t fillspace = 0; fillspace < LCD_WIDTH; fillspace++) if ((lcd_status_message[fillspace] <= 31 )) lcd_print(' '); } @@ -2737,7 +2737,7 @@ void lcd_menu_statistics() } -static void _lcd_move(const char *name, int axis, int min, int max) +static void _lcd_move(const char *name, uint8_t axis, int min, int max) { if (homing_flag || mesh_bed_leveling_flag) { @@ -3920,7 +3920,7 @@ static void prusa_statistics_case0(uint8_t statnr){ prusa_stat_printinfo(); } -void prusa_statistics(int _message, uint8_t _fil_nr) { +void prusa_statistics(uint8_t _message, uint8_t _fil_nr) { #ifdef DEBUG_DISABLE_PRUSA_STATISTICS return; #endif //DEBUG_DISABLE_PRUSA_STATISTICS diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 68b933d02..06763556b 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -41,7 +41,7 @@ void lcd_pause_print(); void lcd_pause_usb_print(); void lcd_resume_print(); void lcd_print_stop(); -void prusa_statistics(int _message, uint8_t _col_nr = 0); +void prusa_statistics(uint8_t _message, uint8_t _col_nr = 0); unsigned char lcd_choose_color(); void lcd_load_filament_color_check(); //void lcd_mylang(); From db1e5a203b60393ae810cd1e4e3a3d10c049def1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Fri, 6 Aug 2021 15:03:35 +0000 Subject: [PATCH 07/83] Change temp_runaway_status from float to uint8_t and its enum Saves 90 bytes of flash, and 12 bytes of SRAM --- Firmware/temperature.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 3765589b8..7e48575a7 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -204,7 +204,7 @@ static float analog2tempAmbient(int raw); #endif static void updateTemperaturesFromRawValues(); -enum TempRunawayStates +enum TempRunawayStates : uint8_t { TempRunaway_INACTIVE = 0, TempRunaway_PREHEAT = 1, @@ -220,7 +220,7 @@ enum TempRunawayStates //=========================================================================== #if (defined (TEMP_RUNAWAY_BED_HYSTERESIS) && TEMP_RUNAWAY_BED_TIMEOUT > 0) || (defined (TEMP_RUNAWAY_EXTRUDER_HYSTERESIS) && TEMP_RUNAWAY_EXTRUDER_TIMEOUT > 0) -static float temp_runaway_status[4]; +static uint8_t temp_runaway_status[4]; static float temp_runaway_target[4]; static float temp_runaway_timer[4]; static int temp_runaway_error_counter[4]; From e6a7abf2c1a3991b3b18815a92df3c54f6de5346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Fri, 6 Aug 2021 15:08:46 +0000 Subject: [PATCH 08/83] Change temp_runaway_timer from float to uint32_t Saves 32 bytes of flash Also change temp_runaway_error_counter from int to uint16_t to be specific --- Firmware/temperature.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 7e48575a7..abeaa2646 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -222,8 +222,8 @@ enum TempRunawayStates : uint8_t #if (defined (TEMP_RUNAWAY_BED_HYSTERESIS) && TEMP_RUNAWAY_BED_TIMEOUT > 0) || (defined (TEMP_RUNAWAY_EXTRUDER_HYSTERESIS) && TEMP_RUNAWAY_EXTRUDER_TIMEOUT > 0) static uint8_t temp_runaway_status[4]; static float temp_runaway_target[4]; -static float temp_runaway_timer[4]; -static int temp_runaway_error_counter[4]; +static uint32_t temp_runaway_timer[4]; +static uint16_t temp_runaway_error_counter[4]; static void temp_runaway_check(int _heater_id, float _target_temperature, float _current_temperature, float _output, bool _isbed); static void temp_runaway_stop(bool isPreheat, bool isBed); @@ -1244,7 +1244,7 @@ void temp_runaway_check(int _heater_id, float _target_temperature, float _curren { float __delta; float __hysteresis = 0; - int __timeout = 0; + uint16_t __timeout = 0; bool temp_runaway_check_active = false; static float __preheat_start[2] = { 0,0}; //currently just bed and one extruder static int __preheat_counter[2] = { 0,0}; From d8a14842c503ff8f050bcd09539ec0ff3a6c8ffd Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 11:34:38 +0300 Subject: [PATCH 09/83] Remove unused `skip_debug_msg` flag --- Firmware/tmc2130.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index dbce5ea07..71f2f44fb 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -71,8 +71,6 @@ uint16_t tmc2130_sg_cnt[4] = {0, 0, 0, 0}; bool tmc2130_sg_change = false; #endif -bool skip_debug_msg = false; - #define DBG(args...) //printf_P(args) #ifndef _n @@ -403,7 +401,6 @@ void tmc2130_check_overtemp() for (uint_least8_t i = 0; i < 4; i++) { uint32_t drv_status = 0; - skip_debug_msg = true; tmc2130_rd(i, TMC2130_REG_DRV_STATUS, &drv_status); if (drv_status & ((uint32_t)1 << 26)) { // BIT 26 - over temp prewarning ~120C (+-20C) From 9d1e54e685476dba757fbf8142c5916881913cb2 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 11:48:28 +0300 Subject: [PATCH 10/83] Tmc2130 use ShortTimer instead of custom timer implementation --- Firmware/tmc2130.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 71f2f44fb..66ac59632 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -8,6 +8,7 @@ #include "ultralcd.h" #include "language.h" #include "spi.h" +#include "Timer.h" #define TMC2130_GCONF_NORMAL 0x00000000 // spreadCycle #define TMC2130_GCONF_SGSENS 0x00003180 // spreadCycle with stallguard (stall activates DIAG0 and DIAG1 [pushpull]) @@ -71,6 +72,9 @@ uint16_t tmc2130_sg_cnt[4] = {0, 0, 0, 0}; bool tmc2130_sg_change = false; #endif +//used for triggering a periodic check (1s) of the overtemperature pre-warning flag at ~120C (+-20C) +ShortTimer tmc2130_overtemp_timer; + #define DBG(args...) //printf_P(args) #ifndef _n @@ -392,11 +396,9 @@ bool tmc2130_wait_standstill_xy(int timeout) return standstill; } - void tmc2130_check_overtemp() { - static uint32_t checktime = 0; - if (_millis() - checktime > 1000 ) + if (tmc2130_overtemp_timer.expired(1000) || !tmc2130_overtemp_timer.running()) { for (uint_least8_t i = 0; i < 4; i++) { @@ -412,7 +414,7 @@ void tmc2130_check_overtemp() } } - checktime = _millis(); + tmc2130_overtemp_timer.start(); #ifdef DEBUG_CRASHDET_COUNTERS tmc2130_sg_change = true; #endif From f64c6c2a39bfc3ca8dd264b7409e889898e1acc8 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 11:48:47 +0300 Subject: [PATCH 11/83] Remove unused Stepper.cpp variables --- Firmware/stepper.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index c9cb8bebc..611f25477 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -134,7 +134,6 @@ static uint16_t OCR1A_nominal; static uint8_t step_loops_nominal; volatile long endstops_trigsteps[3]={0,0,0}; -volatile long endstops_stepsTotal,endstops_stepsDone; static volatile bool endstop_x_hit=false; static volatile bool endstop_y_hit=false; static volatile bool endstop_z_hit=false; From a5f1f23fe272327775a5dd786e16d2c390e3a154 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 13:01:11 +0300 Subject: [PATCH 12/83] TimeNow && TimeSent --- Firmware/cmdqueue.cpp | 18 +++++------------- Firmware/cmdqueue.h | 3 --- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 3bde33362..7cd0c4635 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -26,8 +26,7 @@ int serial_count = 0; //index of character read from serial line boolean comment_mode = false; char *strchr_pointer; // just a pointer to find chars in the command string like X, Y, Z, E, etc -unsigned long TimeSent = _millis(); -unsigned long TimeNow = _millis(); +ShortTimer farm_incomplete_command_timeout_timer; long gcode_N = 0; long gcode_LastN = 0; @@ -396,14 +395,8 @@ void get_command() while (((MYSERIAL.available() > 0 && !saved_printing) || (MYSERIAL.available() > 0 && isPrintPaused)) && !cmdqueue_serial_disabled) { //is print is saved (crash detection or filament detection), dont process data from serial line char serial_char = MYSERIAL.read(); -/* if (selectedSerialPort == 1) - { - selectedSerialPort = 0; - MYSERIAL.write(serial_char); // for debuging serial line 2 in farm_mode - selectedSerialPort = 1; - } */ //RP - removed - TimeSent = _millis(); - TimeNow = _millis(); + + farm_incomplete_command_timeout_timer.start(); if (serial_char < 0) // Ignore extended ASCII characters. These characters have no meaning in the G-code apart from the file names @@ -537,9 +530,8 @@ void get_command() } } // end of serial line processing loop - if(farm_mode){ - TimeNow = _millis(); - if ( ((TimeNow - TimeSent) > 800) && (serial_count > 0) ) { + if(farm_mode && (serial_count > 0)){ + if (farm_incomplete_command_timeout_timer.expired(800)) { cmdbuffer[bufindw+serial_count+CMDHDRSIZE] = 0; bufindw += strlen(cmdbuffer+bufindw+CMDHDRSIZE) + (1 + CMDHDRSIZE); diff --git a/Firmware/cmdqueue.h b/Firmware/cmdqueue.h index bb9e174dc..f9cbd9bbc 100644 --- a/Firmware/cmdqueue.h +++ b/Firmware/cmdqueue.h @@ -52,9 +52,6 @@ extern int serial_count; extern boolean comment_mode; extern char *strchr_pointer; -extern unsigned long TimeSent; -extern unsigned long TimeNow; - extern long gcode_N; extern long gcode_LastN; extern long Stopped_gcode_LastN; From 78362419dafcdf322bce1ed1c0b0bd835fdeaca4 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 13:01:28 +0300 Subject: [PATCH 13/83] nIRsensorLastTime --- Firmware/fsensor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 4eac7bd08..36dc630a5 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -124,7 +124,7 @@ uint16_t fsensor_oq_sh_sum; ClFsensorPCB oFsensorPCB; ClFsensorActionNA oFsensorActionNA; bool bIRsensorStateFlag=false; -unsigned long nIRsensorLastTime; +ShortTimer tIRsensorCheckTimer; #endif //IR_SENSOR_ANALOG void fsensor_stop_and_save_print(void) @@ -693,11 +693,11 @@ void fsensor_update(void) if(!bIRsensorStateFlag) { bIRsensorStateFlag=true; - nIRsensorLastTime=_millis(); + tIRsensorCheckTimer.start(); } else { - if((_millis()-nIRsensorLastTime)>IR_SENSOR_STEADY) + if(tIRsensorCheckTimer.expired(IR_SENSOR_STEADY)) { uint8_t nMUX1,nMUX2; uint16_t nADC; From 42c393764f287868ae0ae910ad25eb9521d877db Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 13:26:07 +0300 Subject: [PATCH 14/83] Adjust temperature runaway extruder count --- Firmware/temperature.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 3765589b8..c7fa599c2 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -220,10 +220,10 @@ enum TempRunawayStates //=========================================================================== #if (defined (TEMP_RUNAWAY_BED_HYSTERESIS) && TEMP_RUNAWAY_BED_TIMEOUT > 0) || (defined (TEMP_RUNAWAY_EXTRUDER_HYSTERESIS) && TEMP_RUNAWAY_EXTRUDER_TIMEOUT > 0) -static float temp_runaway_status[4]; -static float temp_runaway_target[4]; -static float temp_runaway_timer[4]; -static int temp_runaway_error_counter[4]; +static float temp_runaway_status[1 + EXTRUDERS]; +static float temp_runaway_target[1 + EXTRUDERS]; +static float temp_runaway_timer[1 + EXTRUDERS]; +static int temp_runaway_error_counter[1 + EXTRUDERS]; static void temp_runaway_check(int _heater_id, float _target_temperature, float _current_temperature, float _output, bool _isbed); static void temp_runaway_stop(bool isPreheat, bool isBed); From 9684806e003edf2bca842de6bb89ac057d390976 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 14:12:19 +0300 Subject: [PATCH 15/83] Change arduino IO to fastio where possible --- Firmware/Marlin_main.cpp | 4 +- Firmware/Sd2Card.cpp | 19 +- Firmware/Sd2Card.h | 24 +-- Firmware/Sd2PinMap.h | 364 --------------------------------------- Firmware/cardreader.cpp | 11 +- Firmware/fastio.h | 8 +- Firmware/fsensor.cpp | 9 +- Firmware/mmu.cpp | 12 +- Firmware/stepper.cpp | 68 ++++---- Firmware/ultralcd.cpp | 4 +- 10 files changed, 66 insertions(+), 457 deletions(-) delete mode 100644 Firmware/Sd2PinMap.h diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d1bc83a15..d7375b511 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9051,8 +9051,8 @@ Sigma_Exit: disable_e1(); disable_e2(); - pinMode(E_MUX0_PIN, OUTPUT); - pinMode(E_MUX1_PIN, OUTPUT); + SET_OUTPUT(E_MUX0_PIN); + SET_OUTPUT(E_MUX1_PIN); _delay(100); SERIAL_ECHO_START; diff --git a/Firmware/Sd2Card.cpp b/Firmware/Sd2Card.cpp index d1d350563..0e8fc4515 100644 --- a/Firmware/Sd2Card.cpp +++ b/Firmware/Sd2Card.cpp @@ -205,14 +205,14 @@ uint32_t Sd2Card::cardSize() { } //------------------------------------------------------------------------------ void Sd2Card::chipSelectHigh() { - digitalWrite(chipSelectPin_, HIGH); + WRITE(SDSS, 1); } //------------------------------------------------------------------------------ void Sd2Card::chipSelectLow() { #ifndef SOFTWARE_SPI spiInit(spiRate_); #endif // SOFTWARE_SPI - digitalWrite(chipSelectPin_, LOW); + WRITE(SDSS, 0); } //------------------------------------------------------------------------------ /** Erase a range of blocks. @@ -283,26 +283,25 @@ bool Sd2Card::eraseSingleBlockEnable() { * the value zero, false, is returned for failure. The reason for failure * can be determined by calling errorCode() and errorData(). */ -bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) { +bool Sd2Card::init(uint8_t sckRateID) { errorCode_ = type_ = 0; - chipSelectPin_ = chipSelectPin; // 16-bit init start time allows over a minute uint16_t t0 = (uint16_t)_millis(); uint32_t arg; // set pin modes - pinMode(chipSelectPin_, OUTPUT); chipSelectHigh(); - pinMode(SPI_MISO_PIN, INPUT); - pinMode(SPI_MOSI_PIN, OUTPUT); - pinMode(SPI_SCK_PIN, OUTPUT); + SET_OUTPUT(SDSS); + SET_INPUT(MISO); + SET_OUTPUT(MOSI); + SET_OUTPUT(SCK); #ifndef SOFTWARE_SPI // SS must be in output mode even it is not chip select - pinMode(SS_PIN, OUTPUT); + SET_OUTPUT(SS); // set SS high - may be chip select for another SPI device #if SET_SPI_SS_HIGH - digitalWrite(SS_PIN, HIGH); + WRITE(SS, 1); #endif // SET_SPI_SS_HIGH // set SCK rate for initialization commands spiRate_ = SPI_SD_INIT_RATE; diff --git a/Firmware/Sd2Card.h b/Firmware/Sd2Card.h index f4cc59d76..6fb700e70 100644 --- a/Firmware/Sd2Card.h +++ b/Firmware/Sd2Card.h @@ -28,7 +28,6 @@ * \brief Sd2Card class for V2 SD/SDHC cards */ #include "SdFatConfig.h" -#include "Sd2PinMap.h" #include "SdInfo.h" //------------------------------------------------------------------------------ // SPI speed is F_CPU/2^(1 + index), 0 <= index <= 6 @@ -133,22 +132,7 @@ uint8_t const SD_CARD_TYPE_SDHC = 3; //------------------------------------------------------------------------------ // SPI pin definitions - do not edit here - change in SdFatConfig.h // -#ifndef SOFTWARE_SPI -// hardware pin defs -/** The default chip select pin for the SD card is SS. */ -uint8_t const SD_CHIP_SELECT_PIN = SS_PIN; -// The following three pins must not be redefined for hardware SPI. -/** SPI Master Out Slave In pin */ -uint8_t const SPI_MOSI_PIN = MOSI_PIN; -/** SPI Master In Slave Out pin */ -uint8_t const SPI_MISO_PIN = MISO_PIN; -/** SPI Clock pin */ -uint8_t const SPI_SCK_PIN = SCK_PIN; - -#else // SOFTWARE_SPI - -/** SPI chip select pin */ -uint8_t const SD_CHIP_SELECT_PIN = SOFT_SPI_CS_PIN; +#ifdef SOFTWARE_SPI /** SPI Master Out Slave In pin */ uint8_t const SPI_MOSI_PIN = SOFT_SPI_MOSI_PIN; /** SPI Master In Slave Out pin */ @@ -181,12 +165,11 @@ class Sd2Card { int errorData() const {return status_;} /** * Initialize an SD flash memory card with default clock rate and chip - * select pin. See sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin). + * select pin. See sd2Card::init(uint8_t sckRateID). * * \return true for success or false for failure. */ - bool init(uint8_t sckRateID = SPI_FULL_SPEED, - uint8_t chipSelectPin = SD_CHIP_SELECT_PIN); + bool init(uint8_t sckRateID = SPI_FULL_SPEED); bool readBlock(uint32_t block, uint8_t* dst); /** * Read a card's CID register. The CID contains card identification @@ -232,7 +215,6 @@ class Sd2Card { private: //---------------------------------------------------------------------------- - uint8_t chipSelectPin_; uint8_t errorCode_; uint8_t spiRate_; uint8_t status_; diff --git a/Firmware/Sd2PinMap.h b/Firmware/Sd2PinMap.h deleted file mode 100644 index da50958f0..000000000 --- a/Firmware/Sd2PinMap.h +++ /dev/null @@ -1,364 +0,0 @@ -/* Arduino SdFat Library - * Copyright (C) 2010 by William Greiman - * - * This file is part of the Arduino SdFat Library - * - * This Library 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. - * - * This Library 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 - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with the Arduino SdFat Library. If not, see - * . - */ -// Warning this file was generated by a program. -#include "Marlin.h" -#ifdef SDSUPPORT - -#ifndef Sd2PinMap_h -#define Sd2PinMap_h -#include -//------------------------------------------------------------------------------ -/** struct for mapping digital pins */ -struct pin_map_t { - volatile uint8_t* ddr; - volatile uint8_t* pin; - volatile uint8_t* port; - uint8_t bit; -}; -//------------------------------------------------------------------------------ -#if defined(__AVR_ATmega1280__)\ -|| defined(__AVR_ATmega2560__) -// Mega - -#undef MOSI_PIN -#undef MISO_PIN -// SPI port -uint8_t const SS_PIN = 53; // B0 -uint8_t const MOSI_PIN = 51; // B2 -uint8_t const MISO_PIN = 50; // B3 -uint8_t const SCK_PIN = 52; // B1 - -static const pin_map_t digitalPinMap[] = { - {&DDRE, &PINE, &PORTE, 0}, // E0 0 - {&DDRE, &PINE, &PORTE, 1}, // E1 1 - {&DDRE, &PINE, &PORTE, 4}, // E4 2 - {&DDRE, &PINE, &PORTE, 5}, // E5 3 - {&DDRG, &PING, &PORTG, 5}, // G5 4 - {&DDRE, &PINE, &PORTE, 3}, // E3 5 - {&DDRH, &PINH, &PORTH, 3}, // H3 6 - {&DDRH, &PINH, &PORTH, 4}, // H4 7 - {&DDRH, &PINH, &PORTH, 5}, // H5 8 - {&DDRH, &PINH, &PORTH, 6}, // H6 9 - {&DDRB, &PINB, &PORTB, 4}, // B4 10 - {&DDRB, &PINB, &PORTB, 5}, // B5 11 - {&DDRB, &PINB, &PORTB, 6}, // B6 12 - {&DDRB, &PINB, &PORTB, 7}, // B7 13 - {&DDRJ, &PINJ, &PORTJ, 1}, // J1 14 - {&DDRJ, &PINJ, &PORTJ, 0}, // J0 15 - {&DDRH, &PINH, &PORTH, 1}, // H1 16 - {&DDRH, &PINH, &PORTH, 0}, // H0 17 - {&DDRD, &PIND, &PORTD, 3}, // D3 18 - {&DDRD, &PIND, &PORTD, 2}, // D2 19 - {&DDRD, &PIND, &PORTD, 1}, // D1 20 - {&DDRD, &PIND, &PORTD, 0}, // D0 21 - {&DDRA, &PINA, &PORTA, 0}, // A0 22 - {&DDRA, &PINA, &PORTA, 1}, // A1 23 - {&DDRA, &PINA, &PORTA, 2}, // A2 24 - {&DDRA, &PINA, &PORTA, 3}, // A3 25 - {&DDRA, &PINA, &PORTA, 4}, // A4 26 - {&DDRA, &PINA, &PORTA, 5}, // A5 27 - {&DDRA, &PINA, &PORTA, 6}, // A6 28 - {&DDRA, &PINA, &PORTA, 7}, // A7 29 - {&DDRC, &PINC, &PORTC, 7}, // C7 30 - {&DDRC, &PINC, &PORTC, 6}, // C6 31 - {&DDRC, &PINC, &PORTC, 5}, // C5 32 - {&DDRC, &PINC, &PORTC, 4}, // C4 33 - {&DDRC, &PINC, &PORTC, 3}, // C3 34 - {&DDRC, &PINC, &PORTC, 2}, // C2 35 - {&DDRC, &PINC, &PORTC, 1}, // C1 36 - {&DDRC, &PINC, &PORTC, 0}, // C0 37 - {&DDRD, &PIND, &PORTD, 7}, // D7 38 - {&DDRG, &PING, &PORTG, 2}, // G2 39 - {&DDRG, &PING, &PORTG, 1}, // G1 40 - {&DDRG, &PING, &PORTG, 0}, // G0 41 - {&DDRL, &PINL, &PORTL, 7}, // L7 42 - {&DDRL, &PINL, &PORTL, 6}, // L6 43 - {&DDRL, &PINL, &PORTL, 5}, // L5 44 - {&DDRL, &PINL, &PORTL, 4}, // L4 45 - {&DDRL, &PINL, &PORTL, 3}, // L3 46 - {&DDRL, &PINL, &PORTL, 2}, // L2 47 - {&DDRL, &PINL, &PORTL, 1}, // L1 48 - {&DDRL, &PINL, &PORTL, 0}, // L0 49 - {&DDRB, &PINB, &PORTB, 3}, // B3 50 - {&DDRB, &PINB, &PORTB, 2}, // B2 51 - {&DDRB, &PINB, &PORTB, 1}, // B1 52 - {&DDRB, &PINB, &PORTB, 0}, // B0 53 - {&DDRF, &PINF, &PORTF, 0}, // F0 54 - {&DDRF, &PINF, &PORTF, 1}, // F1 55 - {&DDRF, &PINF, &PORTF, 2}, // F2 56 - {&DDRF, &PINF, &PORTF, 3}, // F3 57 - {&DDRF, &PINF, &PORTF, 4}, // F4 58 - {&DDRF, &PINF, &PORTF, 5}, // F5 59 - {&DDRF, &PINF, &PORTF, 6}, // F6 60 - {&DDRF, &PINF, &PORTF, 7}, // F7 61 - {&DDRK, &PINK, &PORTK, 0}, // K0 62 - {&DDRK, &PINK, &PORTK, 1}, // K1 63 - {&DDRK, &PINK, &PORTK, 2}, // K2 64 - {&DDRK, &PINK, &PORTK, 3}, // K3 65 - {&DDRK, &PINK, &PORTK, 4}, // K4 66 - {&DDRK, &PINK, &PORTK, 5}, // K5 67 - {&DDRK, &PINK, &PORTK, 6}, // K6 68 - {&DDRK, &PINK, &PORTK, 7} // K7 69 -}; -//------------------------------------------------------------------------------ -#elif defined(__AVR_ATmega644P__)\ -|| defined(__AVR_ATmega644__)\ -|| defined(__AVR_ATmega1284P__) -// Sanguino - -// Two Wire (aka I2C) ports -uint8_t const SDA_PIN = 17; // C1 -uint8_t const SCL_PIN = 18; // C2 - -// SPI port -uint8_t const SS_PIN = 4; // B4 -uint8_t const MOSI_PIN = 5; // B5 -uint8_t const MISO_PIN = 6; // B6 -uint8_t const SCK_PIN = 7; // B7 - -static const pin_map_t digitalPinMap[] = { - {&DDRB, &PINB, &PORTB, 0}, // B0 0 - {&DDRB, &PINB, &PORTB, 1}, // B1 1 - {&DDRB, &PINB, &PORTB, 2}, // B2 2 - {&DDRB, &PINB, &PORTB, 3}, // B3 3 - {&DDRB, &PINB, &PORTB, 4}, // B4 4 - {&DDRB, &PINB, &PORTB, 5}, // B5 5 - {&DDRB, &PINB, &PORTB, 6}, // B6 6 - {&DDRB, &PINB, &PORTB, 7}, // B7 7 - {&DDRD, &PIND, &PORTD, 0}, // D0 8 - {&DDRD, &PIND, &PORTD, 1}, // D1 9 - {&DDRD, &PIND, &PORTD, 2}, // D2 10 - {&DDRD, &PIND, &PORTD, 3}, // D3 11 - {&DDRD, &PIND, &PORTD, 4}, // D4 12 - {&DDRD, &PIND, &PORTD, 5}, // D5 13 - {&DDRD, &PIND, &PORTD, 6}, // D6 14 - {&DDRD, &PIND, &PORTD, 7}, // D7 15 - {&DDRC, &PINC, &PORTC, 0}, // C0 16 - {&DDRC, &PINC, &PORTC, 1}, // C1 17 - {&DDRC, &PINC, &PORTC, 2}, // C2 18 - {&DDRC, &PINC, &PORTC, 3}, // C3 19 - {&DDRC, &PINC, &PORTC, 4}, // C4 20 - {&DDRC, &PINC, &PORTC, 5}, // C5 21 - {&DDRC, &PINC, &PORTC, 6}, // C6 22 - {&DDRC, &PINC, &PORTC, 7}, // C7 23 - {&DDRA, &PINA, &PORTA, 7}, // A7 24 - {&DDRA, &PINA, &PORTA, 6}, // A6 25 - {&DDRA, &PINA, &PORTA, 5}, // A5 26 - {&DDRA, &PINA, &PORTA, 4}, // A4 27 - {&DDRA, &PINA, &PORTA, 3}, // A3 28 - {&DDRA, &PINA, &PORTA, 2}, // A2 29 - {&DDRA, &PINA, &PORTA, 1}, // A1 30 - {&DDRA, &PINA, &PORTA, 0} // A0 31 -}; -//------------------------------------------------------------------------------ -#elif defined(__AVR_ATmega32U4__) -// Teensy 2.0 - -// Two Wire (aka I2C) ports -uint8_t const SDA_PIN = 6; // D1 -uint8_t const SCL_PIN = 5; // D0 - -// SPI port -uint8_t const SS_PIN = 0; // B0 -uint8_t const MOSI_PIN = 2; // B2 -uint8_t const MISO_PIN = 3; // B3 -uint8_t const SCK_PIN = 1; // B1 - -static const pin_map_t digitalPinMap[] = { - {&DDRB, &PINB, &PORTB, 0}, // B0 0 - {&DDRB, &PINB, &PORTB, 1}, // B1 1 - {&DDRB, &PINB, &PORTB, 2}, // B2 2 - {&DDRB, &PINB, &PORTB, 3}, // B3 3 - {&DDRB, &PINB, &PORTB, 7}, // B7 4 - {&DDRD, &PIND, &PORTD, 0}, // D0 5 - {&DDRD, &PIND, &PORTD, 1}, // D1 6 - {&DDRD, &PIND, &PORTD, 2}, // D2 7 - {&DDRD, &PIND, &PORTD, 3}, // D3 8 - {&DDRC, &PINC, &PORTC, 6}, // C6 9 - {&DDRC, &PINC, &PORTC, 7}, // C7 10 - {&DDRD, &PIND, &PORTD, 6}, // D6 11 - {&DDRD, &PIND, &PORTD, 7}, // D7 12 - {&DDRB, &PINB, &PORTB, 4}, // B4 13 - {&DDRB, &PINB, &PORTB, 5}, // B5 14 - {&DDRB, &PINB, &PORTB, 6}, // B6 15 - {&DDRF, &PINF, &PORTF, 7}, // F7 16 - {&DDRF, &PINF, &PORTF, 6}, // F6 17 - {&DDRF, &PINF, &PORTF, 5}, // F5 18 - {&DDRF, &PINF, &PORTF, 4}, // F4 19 - {&DDRF, &PINF, &PORTF, 1}, // F1 20 - {&DDRF, &PINF, &PORTF, 0}, // F0 21 - {&DDRD, &PIND, &PORTD, 4}, // D4 22 - {&DDRD, &PIND, &PORTD, 5}, // D5 23 - {&DDRE, &PINE, &PORTE, 6} // E6 24 -}; -//------------------------------------------------------------------------------ -#elif defined(__AVR_AT90USB646__)\ -|| defined(__AVR_AT90USB1286__) -// Teensy++ 1.0 & 2.0 - -// Two Wire (aka I2C) ports -uint8_t const SDA_PIN = 1; // D1 -uint8_t const SCL_PIN = 0; // D0 - -// SPI port -uint8_t const SS_PIN = 20; // B0 -uint8_t const MOSI_PIN = 22; // B2 -uint8_t const MISO_PIN = 23; // B3 -uint8_t const SCK_PIN = 21; // B1 - -static const pin_map_t digitalPinMap[] = { - {&DDRD, &PIND, &PORTD, 0}, // D0 0 - {&DDRD, &PIND, &PORTD, 1}, // D1 1 - {&DDRD, &PIND, &PORTD, 2}, // D2 2 - {&DDRD, &PIND, &PORTD, 3}, // D3 3 - {&DDRD, &PIND, &PORTD, 4}, // D4 4 - {&DDRD, &PIND, &PORTD, 5}, // D5 5 - {&DDRD, &PIND, &PORTD, 6}, // D6 6 - {&DDRD, &PIND, &PORTD, 7}, // D7 7 - {&DDRE, &PINE, &PORTE, 0}, // E0 8 - {&DDRE, &PINE, &PORTE, 1}, // E1 9 - {&DDRC, &PINC, &PORTC, 0}, // C0 10 - {&DDRC, &PINC, &PORTC, 1}, // C1 11 - {&DDRC, &PINC, &PORTC, 2}, // C2 12 - {&DDRC, &PINC, &PORTC, 3}, // C3 13 - {&DDRC, &PINC, &PORTC, 4}, // C4 14 - {&DDRC, &PINC, &PORTC, 5}, // C5 15 - {&DDRC, &PINC, &PORTC, 6}, // C6 16 - {&DDRC, &PINC, &PORTC, 7}, // C7 17 - {&DDRE, &PINE, &PORTE, 6}, // E6 18 - {&DDRE, &PINE, &PORTE, 7}, // E7 19 - {&DDRB, &PINB, &PORTB, 0}, // B0 20 - {&DDRB, &PINB, &PORTB, 1}, // B1 21 - {&DDRB, &PINB, &PORTB, 2}, // B2 22 - {&DDRB, &PINB, &PORTB, 3}, // B3 23 - {&DDRB, &PINB, &PORTB, 4}, // B4 24 - {&DDRB, &PINB, &PORTB, 5}, // B5 25 - {&DDRB, &PINB, &PORTB, 6}, // B6 26 - {&DDRB, &PINB, &PORTB, 7}, // B7 27 - {&DDRA, &PINA, &PORTA, 0}, // A0 28 - {&DDRA, &PINA, &PORTA, 1}, // A1 29 - {&DDRA, &PINA, &PORTA, 2}, // A2 30 - {&DDRA, &PINA, &PORTA, 3}, // A3 31 - {&DDRA, &PINA, &PORTA, 4}, // A4 32 - {&DDRA, &PINA, &PORTA, 5}, // A5 33 - {&DDRA, &PINA, &PORTA, 6}, // A6 34 - {&DDRA, &PINA, &PORTA, 7}, // A7 35 - {&DDRE, &PINE, &PORTE, 4}, // E4 36 - {&DDRE, &PINE, &PORTE, 5}, // E5 37 - {&DDRF, &PINF, &PORTF, 0}, // F0 38 - {&DDRF, &PINF, &PORTF, 1}, // F1 39 - {&DDRF, &PINF, &PORTF, 2}, // F2 40 - {&DDRF, &PINF, &PORTF, 3}, // F3 41 - {&DDRF, &PINF, &PORTF, 4}, // F4 42 - {&DDRF, &PINF, &PORTF, 5}, // F5 43 - {&DDRF, &PINF, &PORTF, 6}, // F6 44 - {&DDRF, &PINF, &PORTF, 7} // F7 45 -}; -//------------------------------------------------------------------------------ -#elif defined(__AVR_ATmega168__)\ -||defined(__AVR_ATmega168P__)\ -||defined(__AVR_ATmega328P__) -// 168 and 328 Arduinos - -// Two Wire (aka I2C) ports -uint8_t const SDA_PIN = 18; // C4 -uint8_t const SCL_PIN = 19; // C5 - -// SPI port -uint8_t const SS_PIN = 10; // B2 -uint8_t const MOSI_PIN = 11; // B3 -uint8_t const MISO_PIN = 12; // B4 -uint8_t const SCK_PIN = 13; // B5 - -static const pin_map_t digitalPinMap[] = { - {&DDRD, &PIND, &PORTD, 0}, // D0 0 - {&DDRD, &PIND, &PORTD, 1}, // D1 1 - {&DDRD, &PIND, &PORTD, 2}, // D2 2 - {&DDRD, &PIND, &PORTD, 3}, // D3 3 - {&DDRD, &PIND, &PORTD, 4}, // D4 4 - {&DDRD, &PIND, &PORTD, 5}, // D5 5 - {&DDRD, &PIND, &PORTD, 6}, // D6 6 - {&DDRD, &PIND, &PORTD, 7}, // D7 7 - {&DDRB, &PINB, &PORTB, 0}, // B0 8 - {&DDRB, &PINB, &PORTB, 1}, // B1 9 - {&DDRB, &PINB, &PORTB, 2}, // B2 10 - {&DDRB, &PINB, &PORTB, 3}, // B3 11 - {&DDRB, &PINB, &PORTB, 4}, // B4 12 - {&DDRB, &PINB, &PORTB, 5}, // B5 13 - {&DDRC, &PINC, &PORTC, 0}, // C0 14 - {&DDRC, &PINC, &PORTC, 1}, // C1 15 - {&DDRC, &PINC, &PORTC, 2}, // C2 16 - {&DDRC, &PINC, &PORTC, 3}, // C3 17 - {&DDRC, &PINC, &PORTC, 4}, // C4 18 - {&DDRC, &PINC, &PORTC, 5} // C5 19 -}; -#else // defined(__AVR_ATmega1280__) -#error unknown chip -#endif // defined(__AVR_ATmega1280__) -//------------------------------------------------------------------------------ -static const uint8_t digitalPinCount = sizeof(digitalPinMap)/sizeof(pin_map_t); - -uint8_t badPinNumber(void) - __attribute__((error("Pin number is too large or not a constant"))); - -static inline __attribute__((always_inline)) - bool getPinMode(uint8_t pin) { - if (__builtin_constant_p(pin) && pin < digitalPinCount) { - return (*digitalPinMap[pin].ddr >> digitalPinMap[pin].bit) & 1; - } else { - return badPinNumber(); - } -} -static inline __attribute__((always_inline)) - void setPinMode(uint8_t pin, uint8_t mode) { - if (__builtin_constant_p(pin) && pin < digitalPinCount) { - if (mode) { - *digitalPinMap[pin].ddr |= 1 << digitalPinMap[pin].bit; - } else { - *digitalPinMap[pin].ddr &= ~(1 << digitalPinMap[pin].bit); - } - } else { - badPinNumber(); - } -} -static inline __attribute__((always_inline)) - bool fastDigitalRead(uint8_t pin) { - if (__builtin_constant_p(pin) && pin < digitalPinCount) { - return (*digitalPinMap[pin].pin >> digitalPinMap[pin].bit) & 1; - } else { - return badPinNumber(); - } -} -static inline __attribute__((always_inline)) - void fastDigitalWrite(uint8_t pin, uint8_t value) { - if (__builtin_constant_p(pin) && pin < digitalPinCount) { - if (value) { - *digitalPinMap[pin].port |= 1 << digitalPinMap[pin].bit; - } else { - *digitalPinMap[pin].port &= ~(1 << digitalPinMap[pin].bit); - } - } else { - badPinNumber(); - } -} -#endif // Sd2PinMap_h - - -#endif diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index 41fee385f..d4fd92ed1 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -204,20 +204,13 @@ void CardReader::initsd(bool doPresort/* = true*/) if(root.isOpen()) root.close(); #ifdef SDSLOW - if (!card.init(SPI_HALF_SPEED,SDSS) - #if defined(LCD_SDSS) && (LCD_SDSS != SDSS) - && !card.init(SPI_HALF_SPEED,LCD_SDSS) - #endif + if (!card.init(SPI_HALF_SPEED) ) #else - if (!card.init(SPI_FULL_SPEED,SDSS) - #if defined(LCD_SDSS) && (LCD_SDSS != SDSS) - && !card.init(SPI_FULL_SPEED,LCD_SDSS) - #endif + if (!card.init(SPI_FULL_SPEED) ) #endif { - //if (!card.init(SPI_HALF_SPEED,SDSS)) SERIAL_ECHO_START; SERIAL_ECHOLNRPGM(_n("SD init fail"));////MSG_SD_INIT_FAIL } diff --git a/Firmware/fastio.h b/Firmware/fastio.h index 855c000e2..b857cbc0b 100644 --- a/Firmware/fastio.h +++ b/Firmware/fastio.h @@ -931,10 +931,10 @@ pins #define TXD DIO1 // SPI -#define SCK DIO52 -#define MISO DIO50 -#define MOSI DIO51 -#define SS DIO53 +#define SCK 52 +#define MISO 50 +#define MOSI 51 +#define SS 53 // TWI (I2C) #define SCL DIO21 diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index 36dc630a5..ac7d202e4 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -349,7 +349,7 @@ bool fsensor_check_autoload(void) if (!fsensor_enabled) return false; if (!fsensor_autoload_enabled) return false; if (ir_sensor_detected) { - if (digitalRead(IR_SENSOR_PIN) == 1) { + if (READ(IR_SENSOR_PIN)) { fsensor_watch_autoload = true; } else if (fsensor_watch_autoload == true) { @@ -591,9 +591,8 @@ ISR(FSENSOR_INT_PIN_VECT) void fsensor_setup_interrupt(void) { - - pinMode(FSENSOR_INT_PIN, OUTPUT); - digitalWrite(FSENSOR_INT_PIN, LOW); + WRITE(FSENSOR_INT_PIN, 0); + SET_OUTPUT(FSENSOR_INT_PIN); fsensor_int_pin_old = 0; //pciSetup(FSENSOR_INT_PIN); @@ -687,7 +686,7 @@ void fsensor_update(void) #else //PAT9125 if (CHECK_FSENSOR && ir_sensor_detected) { - if(digitalRead(IR_SENSOR_PIN)) + if (READ(IR_SENSOR_PIN)) { // IR_SENSOR_PIN ~ H #ifdef IR_SENSOR_ANALOG if(!bIRsensorStateFlag) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index abc84c34d..89aeea3e6 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -149,8 +149,8 @@ int8_t mmu_rx_start(void) void mmu_init(void) { #ifdef MMU_HWRESET - digitalWrite(MMU_RST_PIN, HIGH); - pinMode(MMU_RST_PIN, OUTPUT); //setup reset pin + WRITE(MMU_RST_PIN, 1); + SET_OUTPUT(MMU_RST_PIN); //setup reset pin #endif //MMU_HWRESET uart2_init(); //init uart2 _delay_ms(10); //wait 10ms for sure @@ -490,9 +490,9 @@ void mmu_loop(void) void mmu_reset(void) { #ifdef MMU_HWRESET //HW - pulse reset pin - digitalWrite(MMU_RST_PIN, LOW); + WRITE(MMU_RST_PIN, 0); _delay_us(100); - digitalWrite(MMU_RST_PIN, HIGH); + WRITE(MMU_RST_PIN, 1); #else //SW - send X0 command mmu_puts_P(PSTR("X0\n")); #endif @@ -927,8 +927,8 @@ void change_extr(int mmu_extruder = extr; - pinMode(E_MUX0_PIN, OUTPUT); - pinMode(E_MUX1_PIN, OUTPUT); + SET_OUTPUT(E_MUX0_PIN); + SET_OUTPUT(E_MUX1_PIN); switch (extr) { case 1: diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 611f25477..e102159a6 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -1563,9 +1563,9 @@ void st_current_init() //Initialize Digipot Motor Current #ifdef MOTOR_CURRENT_PWM_XY_PIN uint8_t SilentMode = eeprom_read_byte((uint8_t*)EEPROM_SILENT); SilentModeMenu = SilentMode; - pinMode(MOTOR_CURRENT_PWM_XY_PIN, OUTPUT); - pinMode(MOTOR_CURRENT_PWM_Z_PIN, OUTPUT); - pinMode(MOTOR_CURRENT_PWM_E_PIN, OUTPUT); + SET_OUTPUT(MOTOR_CURRENT_PWM_XY_PIN); + SET_OUTPUT(MOTOR_CURRENT_PWM_Z_PIN); + SET_OUTPUT(MOTOR_CURRENT_PWM_E_PIN); if((SilentMode == SILENT_MODE_OFF) || (farm_mode) ){ motor_current_setting[0] = motor_current_setting_loud[0]; @@ -1604,20 +1604,20 @@ void microstep_init() { #if defined(E1_MS1_PIN) && E1_MS1_PIN > -1 - pinMode(E1_MS1_PIN,OUTPUT); - pinMode(E1_MS2_PIN,OUTPUT); + SET_OUTPUT(E1_MS1_PIN); + SET_OUTPUT(E1_MS2_PIN); #endif #if defined(X_MS1_PIN) && X_MS1_PIN > -1 const uint8_t microstep_modes[] = MICROSTEP_MODES; - pinMode(X_MS1_PIN,OUTPUT); - pinMode(X_MS2_PIN,OUTPUT); - pinMode(Y_MS1_PIN,OUTPUT); - pinMode(Y_MS2_PIN,OUTPUT); - pinMode(Z_MS1_PIN,OUTPUT); - pinMode(Z_MS2_PIN,OUTPUT); - pinMode(E0_MS1_PIN,OUTPUT); - pinMode(E0_MS2_PIN,OUTPUT); + SET_OUTPUT(X_MS1_PIN); + SET_OUTPUT(X_MS2_PIN); + SET_OUTPUT(Y_MS1_PIN); + SET_OUTPUT(Y_MS2_PIN); + SET_OUTPUT(Z_MS1_PIN); + SET_OUTPUT(Z_MS2_PIN); + SET_OUTPUT(E0_MS1_PIN); + SET_OUTPUT(E0_MS2_PIN); for(int i=0;i<=4;i++) microstep_mode(i,microstep_modes[i]); #endif } @@ -1629,22 +1629,22 @@ void microstep_ms(uint8_t driver, int8_t ms1, int8_t ms2) { if(ms1 > -1) switch(driver) { - case 0: digitalWrite( X_MS1_PIN,ms1); break; - case 1: digitalWrite( Y_MS1_PIN,ms1); break; - case 2: digitalWrite( Z_MS1_PIN,ms1); break; - case 3: digitalWrite(E0_MS1_PIN,ms1); break; + case 0: WRITE( X_MS1_PIN,ms1); break; + case 1: WRITE( Y_MS1_PIN,ms1); break; + case 2: WRITE( Z_MS1_PIN,ms1); break; + case 3: WRITE(E0_MS1_PIN,ms1); break; #if defined(E1_MS1_PIN) && E1_MS1_PIN > -1 - case 4: digitalWrite(E1_MS1_PIN,ms1); break; + case 4: WRITE(E1_MS1_PIN,ms1); break; #endif } if(ms2 > -1) switch(driver) { - case 0: digitalWrite( X_MS2_PIN,ms2); break; - case 1: digitalWrite( Y_MS2_PIN,ms2); break; - case 2: digitalWrite( Z_MS2_PIN,ms2); break; - case 3: digitalWrite(E0_MS2_PIN,ms2); break; + case 0: WRITE( X_MS2_PIN,ms2); break; + case 1: WRITE( Y_MS2_PIN,ms2); break; + case 2: WRITE( Z_MS2_PIN,ms2); break; + case 3: WRITE(E0_MS2_PIN,ms2); break; #if defined(E1_MS2_PIN) && E1_MS2_PIN > -1 - case 4: digitalWrite(E1_MS2_PIN,ms2); break; + case 4: WRITE(E1_MS2_PIN,ms2); break; #endif } } @@ -1663,23 +1663,23 @@ void microstep_mode(uint8_t driver, uint8_t stepping_mode) void microstep_readings() { - SERIAL_PROTOCOLPGM("MS1,MS2 Pins\n"); + SERIAL_PROTOCOLNPGM("MS1,MS2 Pins"); SERIAL_PROTOCOLPGM("X: "); - SERIAL_PROTOCOL( digitalRead(X_MS1_PIN)); - SERIAL_PROTOCOLLN( digitalRead(X_MS2_PIN)); + SERIAL_PROTOCOL( READ(X_MS1_PIN)); + SERIAL_PROTOCOLLN( READ(X_MS2_PIN)); SERIAL_PROTOCOLPGM("Y: "); - SERIAL_PROTOCOL( digitalRead(Y_MS1_PIN)); - SERIAL_PROTOCOLLN( digitalRead(Y_MS2_PIN)); + SERIAL_PROTOCOL( READ(Y_MS1_PIN)); + SERIAL_PROTOCOLLN( READ(Y_MS2_PIN)); SERIAL_PROTOCOLPGM("Z: "); - SERIAL_PROTOCOL( digitalRead(Z_MS1_PIN)); - SERIAL_PROTOCOLLN( digitalRead(Z_MS2_PIN)); + SERIAL_PROTOCOL( READ(Z_MS1_PIN)); + SERIAL_PROTOCOLLN( READ(Z_MS2_PIN)); SERIAL_PROTOCOLPGM("E0: "); - SERIAL_PROTOCOL( digitalRead(E0_MS1_PIN)); - SERIAL_PROTOCOLLN( digitalRead(E0_MS2_PIN)); + SERIAL_PROTOCOL( READ(E0_MS1_PIN)); + SERIAL_PROTOCOLLN( READ(E0_MS2_PIN)); #if defined(E1_MS1_PIN) && E1_MS1_PIN > -1 SERIAL_PROTOCOLPGM("E1: "); - SERIAL_PROTOCOL( digitalRead(E1_MS1_PIN)); - SERIAL_PROTOCOLLN( digitalRead(E1_MS2_PIN)); + SERIAL_PROTOCOL( READ(E1_MS1_PIN)); + SERIAL_PROTOCOLLN( READ(E1_MS2_PIN)); #endif } #endif //TMC2130 diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 81fef9674..704274d9b 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4719,7 +4719,7 @@ void lcd_v2_calibration() bool loaded = false; if (fsensor_enabled && ir_sensor_detected) { - loaded = (digitalRead(IR_SENSOR_PIN) == 0); + loaded = !READ(IR_SENSOR_PIN); } else { @@ -8690,7 +8690,7 @@ void ultralcd_init() #endif #if defined (SDSUPPORT) && defined(SDCARDDETECT) && (SDCARDDETECT > 0) - pinMode(SDCARDDETECT, INPUT); + SET_INPUT(SDCARDDETECT); WRITE(SDCARDDETECT, HIGH); lcd_oldcardstatus = IS_SD_INSERTED; #endif//(SDCARDDETECT > 0) From 9abae2fd97cf3fafbd7fd8e42448a2a9df7eae18 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 14:22:12 +0300 Subject: [PATCH 16/83] Remove maxlimit_status --- Firmware/planner.cpp | 10 ++++------ Firmware/planner.h | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index b6d012b24..5750ce6e8 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -1044,14 +1044,12 @@ Having the real displacement of the head, we can calculate the total movement le // Calculate and limit speed in mm/sec for each axis float current_speed[4]; float speed_factor = 1.0; //factor <=1 do decrease speed -// maxlimit_status &= ~0xf; for(int i=0; i < 4; i++) { current_speed[i] = delta_mm[i] * inverse_second; if(fabs(current_speed[i]) > max_feedrate[i]) { speed_factor = min(speed_factor, max_feedrate[i] / fabs(current_speed[i])); - maxlimit_status |= (1 << i); } } @@ -1133,13 +1131,13 @@ Having the real displacement of the head, we can calculate the total movement le // Limit acceleration per axis //FIXME Vojtech: One shall rather limit a projection of the acceleration vector instead of using the limit. if(((float)block->acceleration_st * (float)block->steps_x.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[X_AXIS]) - { block->acceleration_st = axis_steps_per_sqr_second[X_AXIS]; maxlimit_status |= (X_AXIS_MASK << 4); } + { block->acceleration_st = axis_steps_per_sqr_second[X_AXIS]; } if(((float)block->acceleration_st * (float)block->steps_y.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[Y_AXIS]) - { block->acceleration_st = axis_steps_per_sqr_second[Y_AXIS]; maxlimit_status |= (Y_AXIS_MASK << 4); } + { block->acceleration_st = axis_steps_per_sqr_second[Y_AXIS]; } if(((float)block->acceleration_st * (float)block->steps_e.wide / (float)block->step_event_count.wide) > axis_steps_per_sqr_second[E_AXIS]) - { block->acceleration_st = axis_steps_per_sqr_second[E_AXIS]; maxlimit_status |= (Z_AXIS_MASK << 4); } + { block->acceleration_st = axis_steps_per_sqr_second[E_AXIS]; } if(((float)block->acceleration_st * (float)block->steps_z.wide / (float)block->step_event_count.wide ) > axis_steps_per_sqr_second[Z_AXIS]) - { block->acceleration_st = axis_steps_per_sqr_second[Z_AXIS]; maxlimit_status |= (E_AXIS_MASK << 4); } + { block->acceleration_st = axis_steps_per_sqr_second[Z_AXIS]; } } // Acceleration of the segment, in mm/sec^2 block->acceleration = block->acceleration_st / steps_per_mm; diff --git a/Firmware/planner.h b/Firmware/planner.h index f7fd849e0..919905530 100644 --- a/Firmware/planner.h +++ b/Firmware/planner.h @@ -192,7 +192,6 @@ extern unsigned long* max_acceleration_units_per_sq_second; extern unsigned long axis_steps_per_sqr_second[NUM_AXIS]; extern long position[NUM_AXIS]; -extern uint8_t maxlimit_status; #ifdef AUTOTEMP From f22b9260ae9922e2f4873d87693f1469f2d21221 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 14:24:40 +0300 Subject: [PATCH 17/83] Fix build --- Firmware/stepper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index e102159a6..dddb9449d 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -1663,7 +1663,7 @@ void microstep_mode(uint8_t driver, uint8_t stepping_mode) void microstep_readings() { - SERIAL_PROTOCOLNPGM("MS1,MS2 Pins"); + SERIAL_PROTOCOLLNPGM("MS1,MS2 Pins"); SERIAL_PROTOCOLPGM("X: "); SERIAL_PROTOCOL( READ(X_MS1_PIN)); SERIAL_PROTOCOLLN( READ(X_MS2_PIN)); From 6dd59985eeed7b640624552c3bad8ed0ceef6948 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 14:57:49 +0300 Subject: [PATCH 18/83] Disable PRUSA M28 --- Firmware/Marlin_main.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d7375b511..0b8181241 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -213,7 +213,9 @@ static LongTimer crashDetTimer; bool mesh_bed_leveling_flag = false; bool mesh_bed_run_from_menu = false; +#ifdef PRUSA_M28 bool prusa_sd_card_upload = false; +#endif unsigned int status_number = 0; @@ -1721,6 +1723,7 @@ void setup() #endif //WATCHDOG } +#ifdef PRUSA_M28 static inline void crash_and_burn(dump_crash_reason reason) { @@ -1825,6 +1828,7 @@ void serial_read_stream() { } } } +#endif //PRUSA_M28 /** @@ -1915,12 +1919,14 @@ void loop() } #endif +#ifdef PRUSA_M28 if (prusa_sd_card_upload) { //we read byte-by byte serial_read_stream(); } - else + else +#endif { get_command(); @@ -2559,9 +2565,12 @@ void retract(bool retracting, bool swapretract = false) { } //retract #endif //FWRETRACT +#ifdef PRUSA_M28 void trace() { Sound_MakeCustom(25,440,true); } +#endif + /* void ramming() { // float tmp[4] = DEFAULT_MAX_FEEDRATE; @@ -4564,12 +4573,16 @@ void process_commands() #endif // SDSUPPORT - } else if (code_seen_P(PSTR("M28"))) { // PRUSA M28 + } +#ifdef PRUSA_M28 + else if (code_seen_P(PSTR("M28"))) { // PRUSA M28 trace(); prusa_sd_card_upload = true; card.openFileWrite(strchr_pointer+4); - } else if (code_seen_P(PSTR("SN"))) { // PRUSA SN + } +#endif //PRUSA_M28 + else if (code_seen_P(PSTR("SN"))) { // PRUSA SN char SN[20]; eeprom_read_block(SN, (uint8_t*)EEPROM_PRUSA_SN, 20); if (SN[19]) From 9951e3da52dbfb3787ce1de4e5512ad95cf4d09a Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 15:04:35 +0300 Subject: [PATCH 19/83] Sound enums as uint8_t --- Firmware/sound.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/sound.h b/Firmware/sound.h index a80d01550..9e01f31bd 100644 --- a/Firmware/sound.h +++ b/Firmware/sound.h @@ -4,13 +4,13 @@ #define e_SOUND_MODE_NULL 0xFF -typedef enum +typedef enum : uint8_t {e_SOUND_MODE_LOUD,e_SOUND_MODE_ONCE,e_SOUND_MODE_SILENT,e_SOUND_MODE_BLIND} eSOUND_MODE; #define e_SOUND_MODE_DEFAULT e_SOUND_MODE_LOUD -typedef enum +typedef enum : uint8_t {e_SOUND_TYPE_ButtonEcho,e_SOUND_TYPE_EncoderEcho,e_SOUND_TYPE_StandardPrompt,e_SOUND_TYPE_StandardConfirm,e_SOUND_TYPE_StandardWarning,e_SOUND_TYPE_StandardAlert,e_SOUND_TYPE_EncoderMove,e_SOUND_TYPE_BlindAlert} eSOUND_TYPE; -typedef enum +typedef enum : uint8_t {e_SOUND_CLASS_Echo,e_SOUND_CLASS_Prompt,e_SOUND_CLASS_Confirm,e_SOUND_CLASS_Warning,e_SOUND_CLASS_Alert} eSOUND_CLASS; From a5cd99a9179d608928c7010d133bf58e4d8d65d8 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 15:24:47 +0300 Subject: [PATCH 20/83] Disable unimplemented PID_ADD_EXTRUSION_RATE --- Firmware/Configuration_adv.h | 2 +- Firmware/temperature.h | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index 59590b6f1..f1de79cb6 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -13,7 +13,7 @@ #ifdef PIDTEMP // this adds an experimental additional term to the heating power, proportional to the extrusion speed. // if Kc is chosen well, the additional required power due to increased melting should be compensated. - #define PID_ADD_EXTRUSION_RATE + // #define PID_ADD_EXTRUSION_RATE #ifdef PID_ADD_EXTRUSION_RATE #define DEFAULT_Kc (1) //heating power=Kc*(e_speed) #endif diff --git a/Firmware/temperature.h b/Firmware/temperature.h index 0bf944724..2941e6306 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -23,9 +23,8 @@ #include "Marlin.h" #include "planner.h" -#ifdef PID_ADD_EXTRUSION_RATE - #include "stepper.h" -#endif + +#include "stepper.h" #include "config.h" @@ -91,7 +90,10 @@ extern bool bedPWMDisabled; #ifdef PIDTEMP extern int pid_cycle, pid_number_of_cycles; - extern float Kc,_Kp,_Ki,_Kd; + extern float _Kp,_Ki,_Kd; +#ifdef PID_ADD_EXTRUSION_RATE + extern float Kc; +#endif extern bool pid_tuning_finished; float scalePID_i(float i); float scalePID_d(float d); From 4aae88afdfe2c3736a3680fad11cd1de4e240bd2 Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sun, 30 May 2021 17:48:07 +0300 Subject: [PATCH 21/83] M42 optimization --- Firmware/Marlin_main.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0b8181241..ec47816f9 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -351,7 +351,7 @@ static float next_feedrate; // Original feedrate saved during homing moves static float saved_feedrate; -const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42 +const int8_t sensitive_pins[] PROGMEM = SENSITIVE_PINS; // Sensitive pin list for M42 //static float tt = 0; //static float bt = 0; @@ -6116,13 +6116,13 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) case 42: if (code_seen('S')) { - int pin_status = code_value(); - int pin_number = LED_PIN; - if (code_seen('P') && pin_status >= 0 && pin_status <= 255) + uint8_t pin_status = code_value_uint8(); + int8_t pin_number = LED_PIN; + if (code_seen('P')) pin_number = code_value(); - for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(int)); i++) + for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(int8_t)); i++) { - if (sensitive_pins[i] == pin_number) + if ((int8_t)pgm_read_byte(&sensitive_pins[i]) == pin_number) { pin_number = -1; break; From 42a5f7dc20eb58e9f91c133838fa4c1782d4626b Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Sat, 5 Jun 2021 12:42:03 +0300 Subject: [PATCH 22/83] Fix M226 --- Firmware/Marlin_main.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index ec47816f9..6ff7db3ae 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6120,7 +6120,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) int8_t pin_number = LED_PIN; if (code_seen('P')) pin_number = code_value(); - for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(int8_t)); i++) + for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(*sensitive_pins)); i++) { if ((int8_t)pgm_read_byte(&sensitive_pins[i]) == pin_number) { @@ -7698,9 +7698,9 @@ Sigma_Exit: if(pin_state >= -1 && pin_state <= 1){ - for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(int)); i++) + for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(*sensitive_pins)); i++) { - if (sensitive_pins[i] == pin_number) + if (((int8_t)pgm_read_byte(&sensitive_pins[i]) == pin_number)) { pin_number = -1; break; From 623762bd50d008389b538571173ea2e6507279cf Mon Sep 17 00:00:00 2001 From: Voinea Dragos Date: Tue, 22 Jun 2021 13:18:36 +0300 Subject: [PATCH 23/83] Fix build --- Firmware/Marlin_main.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 6ff7db3ae..bf0c51ad6 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1723,8 +1723,6 @@ void setup() #endif //WATCHDOG } -#ifdef PRUSA_M28 - static inline void crash_and_burn(dump_crash_reason reason) { WRITE(BEEPER, HIGH); @@ -1756,7 +1754,7 @@ void stack_error() { crash_and_burn(dump_crash_reason::stack_error); } - +#ifdef PRUSA_M28 void trace(); #define CHUNK_SIZE 64 // bytes From 7535fa3a4437e70416bd41c164db77014ff1b184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 8 Aug 2021 18:48:20 +0000 Subject: [PATCH 24/83] Remove unused variable Saves 2 bytes of SRAM --- Firmware/cardreader.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Firmware/cardreader.h b/Firmware/cardreader.h index f7e3acc94..32a024529 100644 --- a/Firmware/cardreader.h +++ b/Firmware/cardreader.h @@ -136,7 +136,6 @@ private: bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware. int16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory. - char* diveDirName; bool diveSubfolder (const char *&fileName); void lsDive(const char *prepend, SdFile parent, const char * const match=NULL, LsAction lsAction = LS_GetFilename, ls_param lsParams = ls_param()); From 261f31182573db4bee4e89f007290a6cbb3db7b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 8 Aug 2021 19:45:29 +0000 Subject: [PATCH 25/83] Change two arrays from int to uint8_t __preheat_counter has max value of 16 __preheat_errors has max value of 5 Saves 58 bytes of flash memory and 4 bytes of SRAM --- Firmware/temperature.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index abeaa2646..4faf1341e 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -1247,8 +1247,8 @@ void temp_runaway_check(int _heater_id, float _target_temperature, float _curren uint16_t __timeout = 0; bool temp_runaway_check_active = false; static float __preheat_start[2] = { 0,0}; //currently just bed and one extruder - static int __preheat_counter[2] = { 0,0}; - static int __preheat_errors[2] = { 0,0}; + static uint8_t __preheat_counter[2] = { 0,0}; + static uint8_t __preheat_errors[2] = { 0,0}; if (_millis() - temp_runaway_timer[_heater_id] > 2000) From f81db567930b1e2faa4b28567e5a72fd00b0f810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 8 Aug 2021 19:53:37 +0000 Subject: [PATCH 26/83] temp_runaway_check() parameter _heater_id should be uint8_t Saves 58 bytes of flash --- Firmware/temperature.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 4faf1341e..67fb496e0 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -225,7 +225,7 @@ static float temp_runaway_target[4]; static uint32_t temp_runaway_timer[4]; static uint16_t temp_runaway_error_counter[4]; -static void temp_runaway_check(int _heater_id, float _target_temperature, float _current_temperature, float _output, bool _isbed); +static void temp_runaway_check(uint8_t _heater_id, float _target_temperature, float _current_temperature, float _output, bool _isbed); static void temp_runaway_stop(bool isPreheat, bool isBed); #endif @@ -683,7 +683,7 @@ void manage_heater() temp_runaway_check(0, target_temperature_bed, current_temperature_bed, (int)soft_pwm_bed, true); #endif - for(int e = 0; e < EXTRUDERS; e++) + for(uint8_t e = 0; e < EXTRUDERS; e++) { #ifdef TEMP_RUNAWAY_EXTRUDER_HYSTERESIS @@ -1240,7 +1240,7 @@ void tp_init() } #if (defined (TEMP_RUNAWAY_BED_HYSTERESIS) && TEMP_RUNAWAY_BED_TIMEOUT > 0) || (defined (TEMP_RUNAWAY_EXTRUDER_HYSTERESIS) && TEMP_RUNAWAY_EXTRUDER_TIMEOUT > 0) -void temp_runaway_check(int _heater_id, float _target_temperature, float _current_temperature, float _output, bool _isbed) +void temp_runaway_check(uint8_t _heater_id, float _target_temperature, float _current_temperature, float _output, bool _isbed) { float __delta; float __hysteresis = 0; From a8d16d29491a1f262f13c7902c5b7681c1ab4170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 14 Aug 2021 21:35:30 +0000 Subject: [PATCH 27/83] Use memset to zero previous_speed array Saves 150 bytes of flash memory --- Firmware/planner.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/Firmware/planner.cpp b/Firmware/planner.cpp index 3361e1a17..2b77c58e3 100644 --- a/Firmware/planner.cpp +++ b/Firmware/planner.cpp @@ -459,10 +459,7 @@ void plan_init() { #ifdef LIN_ADVANCE memset(position_float, 0, sizeof(position_float)); // clear position #endif - previous_speed[0] = 0.0; - previous_speed[1] = 0.0; - previous_speed[2] = 0.0; - previous_speed[3] = 0.0; + memset(previous_speed, 0, sizeof(previous_speed)); previous_nominal_speed = 0.0; plan_reset_next_e_queue = false; plan_reset_next_e_sched = false; @@ -678,10 +675,7 @@ void planner_abort_hard() #endif // Resets planner junction speeds. Assumes start from rest. previous_nominal_speed = 0.0; - previous_speed[0] = 0.0; - previous_speed[1] = 0.0; - previous_speed[2] = 0.0; - previous_speed[3] = 0.0; + memset(previous_speed, 0, sizeof(previous_speed)); plan_reset_next_e_queue = false; plan_reset_next_e_sched = false; @@ -1412,10 +1406,7 @@ void plan_set_position(float x, float y, float z, const float &e) #endif st_set_position(position[X_AXIS], position[Y_AXIS], position[Z_AXIS], position[E_AXIS]); previous_nominal_speed = 0.0; // Resets planner junction speeds. Assumes start from rest. - previous_speed[0] = 0.0; - previous_speed[1] = 0.0; - previous_speed[2] = 0.0; - previous_speed[3] = 0.0; + memset(previous_speed, 0, sizeof(previous_speed)); } // Only useful in the bed leveling routine, when the mesh bed leveling is off. From 52aa5a5f00564d6f67ebaba383f9b90675ed3ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 14 Aug 2021 21:43:00 +0000 Subject: [PATCH 28/83] Use inlined function set_destination_to_current() in more places Saves 70 bytes of flash memory --- Firmware/Marlin_main.cpp | 12 ++++++------ Firmware/mesh_bed_calibration.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 284262d6a..2821d213b 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2827,7 +2827,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon enable_endstops(true); - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); feedrate = 0.0; #if Z_HOME_DIR > 0 // If homing away from BED do Z first @@ -3850,7 +3850,7 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float plan_set_e_position(lastpos[E_AXIS]); memcpy(current_position, lastpos, sizeof(lastpos)); - memcpy(destination, current_position, sizeof(current_position)); + set_destination_to_current(); //Recover feed rate feedmultiply = feedmultiplyBckp; @@ -9115,7 +9115,7 @@ Sigma_Exit: #if EXTRUDERS > 1 if (tmp_extruder != active_extruder) { // Save current position to return to after applying extruder offset - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); // Offset extruder (only by XY) int i; for (i = 0; i < 2; i++) { @@ -11442,7 +11442,7 @@ bool recover_machine_state_after_power_panic() // 5) Set the physical positions from the logical positions using the world2machine transformation // This is only done to inizialize Z/E axes with physical locations, since X/Y are unknown. clamp_to_software_endstops(current_position); - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); plan_set_position_curposXYZE(); SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial "); print_world_coordinates(); @@ -11775,7 +11775,7 @@ void stop_and_save_print_to_ram(float z_move, float e_move) plan_buffer_line(saved_pos[X_AXIS], saved_pos[Y_AXIS], saved_pos[Z_AXIS] + z_move, saved_pos[E_AXIS] + e_move, homing_feedrate[Z_AXIS], active_extruder); st_synchronize(); //wait moving memcpy(current_position, saved_pos, sizeof(saved_pos)); - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); #endif waiting_inside_plan_buffer_line_print_aborted = true; //unroll the stack } @@ -11843,7 +11843,7 @@ void restore_print_from_ram_and_continue(float e_move) feedmultiply = saved_feedmultiply2; memcpy(current_position, saved_pos, sizeof(saved_pos)); - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); if (saved_printing_type == PRINTING_TYPE_SD) { //was sd printing card.setIndex(saved_sdpos); sdpos_atomic = saved_sdpos; diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index f97851059..23d7c8736 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -2852,7 +2852,7 @@ bool sample_mesh_and_store_reference() current_position[Y_AXIS] = BED_Y0; world2machine_clamp(current_position[X_AXIS], current_position[Y_AXIS]); go_to_current(homing_feedrate[X_AXIS]/60); - memcpy(destination, current_position, sizeof(destination)); + set_destination_to_current(); enable_endstops(true); homeaxis(Z_AXIS); From 58213814cf06784f097d4f2551371efbf870992b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 14 Aug 2021 21:55:21 +0000 Subject: [PATCH 29/83] Replace for-loop with memcpy Saves 22 bytes of flash memory --- Firmware/Marlin_main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 2821d213b..e669c58ad 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9767,9 +9767,8 @@ void prepare_arc_move(char isclockwise) { // As far as the parser is concerned, the position is now == target. In reality the // motion control system might still be processing the action and the real tool position // in any intermediate location. - for(int8_t i=0; i < NUM_AXIS; i++) { - current_position[i] = destination[i]; - } + set_current_to_destination(); + previous_millis_cmd = _millis(); } From cdd7ea30f409fba8c65a230f2e9a37a7d6d1947d Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 11 Aug 2021 11:28:09 +0300 Subject: [PATCH 30/83] Fix LUT loop --- Firmware/tmc2130.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 8f29cd480..1a77d7791 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -909,11 +909,11 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000) uint8_t x[3] = {255,255,255}; //X segment bounds (MSLUTSEL) uint8_t s = 0; //current segment int8_t b; //encoded bit value - int8_t dA; //delta value - uint8_t i; //microstep index + int8_t dA; //delta value + uint8_t i = 0; //microstep index uint32_t reg = 0; //tmc2130 register tmc2130_wr_MSLUTSTART(axis, 0, amp); - for (i = 0; i < 256; i++) + do { if ((i & 0x1f) == 0) reg = 0; @@ -965,7 +965,7 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000) else reg >>= 1; // printf("%3d\t%3d\t%2d\t%2d\t%2d\t%2d %08x\n", i, vA, dA, b, w[s], s, reg); - } + } while (i++ != 255); tmc2130_wr_MSLUTSEL(axis, x[0], x[1], x[2], w[0], w[1], w[2], w[3]); } From 800f44509d29f6896ae576ea82c340207092a02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Thu, 19 Aug 2021 21:20:30 +0000 Subject: [PATCH 31/83] Change row_offsets[] to uint8_t Saves 10 bytes of flash, and 4 bytes of SRAM --- Firmware/lcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/lcd.cpp b/Firmware/lcd.cpp index 024f973f9..bee207493 100644 --- a/Firmware/lcd.cpp +++ b/Firmware/lcd.cpp @@ -331,7 +331,7 @@ void lcd_no_autoscroll(void) void lcd_set_cursor(uint8_t col, uint8_t row) { - int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; + uint8_t row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; if (row >= LCD_HEIGHT) row = LCD_HEIGHT - 1; // we count rows starting w/0 lcd_currline = row; From a26651e7aa4e5061bd7b8407e33e8b984a06e0c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Thu, 19 Aug 2021 21:22:00 +0000 Subject: [PATCH 32/83] Change return types of two functions uint8_t These functions aren't used but they should return the appropriate type. --- Firmware/Sd2Card.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Sd2Card.h b/Firmware/Sd2Card.h index 6fb700e70..ae78f6d7b 100644 --- a/Firmware/Sd2Card.h +++ b/Firmware/Sd2Card.h @@ -160,9 +160,9 @@ class Sd2Card { /** * \return error code for last error. See Sd2Card.h for a list of error codes. */ - int errorCode() const {return errorCode_;} + uint8_t errorCode() const {return errorCode_;} /** \return error data for last error. */ - int errorData() const {return status_;} + uint8_t errorData() const {return status_;} /** * Initialize an SD flash memory card with default clock rate and chip * select pin. See sd2Card::init(uint8_t sckRateID). From 77cce1fc05a5837063fd472d55b2b5975802778c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 21 Aug 2021 20:30:22 +0000 Subject: [PATCH 33/83] Replace three lines by one function call which does the same thing Saves 42 bytes of flash memory --- Firmware/menu.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index fe58686cf..32efbcd0b 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -152,9 +152,7 @@ void menu_submenu_no_reset(menu_func_t submenu) uint8_t menu_item_ret(void) { - lcd_beeper_quick_feedback(); - lcd_draw_update = 2; - lcd_button_pressed = false; + lcd_quick_feedback(); return 1; } From 66782e9c9dc21ced6ccfaec5c904a3ce09e76917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Wed, 25 Aug 2021 12:17:54 +0000 Subject: [PATCH 34/83] setTargetHotend expect an uint8_t, not int for second parameter also change _usb_timer to ShortTimer Saves 28 bytes of Flash and 1 byte of SRAM --- Firmware/Marlin_main.cpp | 6 +++--- Firmware/temperature.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index e669c58ad..23fbc128e 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -364,7 +364,7 @@ static unsigned long safetytimer_inactive_time = DEFAULT_SAFETYTIMER_TIME_MINS*6 unsigned long starttime=0; unsigned long stoptime=0; -unsigned long _usb_timer = 0; +ShortTimer _usb_timer; bool Stopped=false; @@ -1894,11 +1894,11 @@ void loop() { KEEPALIVE_STATE(NOT_BUSY); - if ((usb_printing_counter > 0) && ((_millis()-_usb_timer) > 1000)) + if ((usb_printing_counter > 0) && _usb_timer.expired(1000)) { is_usb_printing = true; usb_printing_counter--; - _usb_timer = _millis(); + _usb_timer.start(); // reset timer } if (usb_printing_counter == 0) { diff --git a/Firmware/temperature.h b/Firmware/temperature.h index 2941e6306..f03ea6201 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -168,7 +168,7 @@ static inline void setTargetHotendSafe(const float &celsius, uint8_t extruder) // Doesn't save FLASH when not inlined. static inline void setAllTargetHotends(const float &celsius) { - for(int i=0;i Date: Thu, 26 Aug 2021 17:17:16 +0000 Subject: [PATCH 35/83] Convert mmu_last_request and mmu_last_response to ShortTimer Saves 180 bytes of flash and 2 byte of SRAM --- Firmware/mmu.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 89aeea3e6..0a2df3e9a 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -76,8 +76,8 @@ int16_t mmu_version = -1; int16_t mmu_buildnr = -1; -uint32_t mmu_last_request = 0; -uint32_t mmu_last_response = 0; +ShortTimer mmu_last_request; +ShortTimer mmu_last_response; MmuCmd mmu_last_cmd = MmuCmd::None; uint16_t mmu_power_failures = 0; @@ -113,7 +113,7 @@ int mmu_puts_P(const char* str) { mmu_clr_rx_buf(); //clear rx buffer int r = fputs_P(str, uart2io); //send command - mmu_last_request = _millis(); + mmu_last_request.start(); return r; } @@ -125,7 +125,7 @@ int mmu_printf_P(const char* format, ...) mmu_clr_rx_buf(); //clear rx buffer int r = vfprintf_P(uart2io, format, args); //send command va_end(args); - mmu_last_request = _millis(); + mmu_last_request.start(); return r; } @@ -133,7 +133,7 @@ int mmu_printf_P(const char* format, ...) int8_t mmu_rx_ok(void) { int8_t res = uart2_rx_str_P(PSTR("ok\n")); - if (res == 1) mmu_last_response = _millis(); + if (res == 1) mmu_last_response.start(); return res; } @@ -141,7 +141,7 @@ int8_t mmu_rx_ok(void) int8_t mmu_rx_start(void) { int8_t res = uart2_rx_str_P(PSTR("start\n")); - if (res == 1) mmu_last_response = _millis(); + if (res == 1) mmu_last_response.start(); return res; } @@ -350,7 +350,7 @@ void mmu_loop(void) mmu_printf_P(PSTR("M%d\n"), SilentModeMenu_MMU); mmu_state = S::SwitchMode; } - else if ((mmu_last_response + 300) < _millis()) //request every 300ms + else if (mmu_last_response.expired(300)) //request every 300ms { #ifndef IR_SENSOR if(check_for_ir_sensor()) ir_sensor_detected = true; @@ -398,7 +398,7 @@ void mmu_loop(void) if (mmu_cmd == MmuCmd::None) mmu_ready = true; } - else if ((mmu_last_request + MMU_P0_TIMEOUT) < _millis()) + else if (mmu_last_request.expired(MMU_P0_TIMEOUT)) { //resend request after timeout (30s) mmu_state = S::Idle; } @@ -424,7 +424,7 @@ void mmu_loop(void) mmu_ready = true; mmu_state = S::Idle; } - else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis()) + else if (mmu_last_request.expired(MMU_CMD_TIMEOUT)) { //resend request after timeout (5 min) if (mmu_last_cmd != MmuCmd::None) { @@ -467,7 +467,7 @@ void mmu_loop(void) mmu_ready = true; mmu_state = S::Idle; } - else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis()) + else if (mmu_last_request.expired(MMU_CMD_TIMEOUT)) { //timeout 45 s mmu_state = S::Idle; } @@ -479,7 +479,7 @@ void mmu_loop(void) eeprom_update_byte((uint8_t*)EEPROM_MMU_STEALTH, SilentModeMenu_MMU); mmu_state = S::Idle; } - else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis()) + else if (mmu_last_request.expired(MMU_CMD_TIMEOUT)) { //timeout 45 s mmu_state = S::Idle; } From 762a5db125c73ebaedb873af10014371c4393372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Thu, 26 Aug 2021 17:36:07 +0000 Subject: [PATCH 36/83] Convert previous_millis_cmd to LongTimer Saves 196 bytes of Flash but adds 1 byte of SRAM --- Firmware/Marlin_main.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 23fbc128e..115e4aa3a 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -357,7 +357,7 @@ const int8_t sensitive_pins[] PROGMEM = SENSITIVE_PINS; // Sensitive pin list fo //static float bt = 0; //Inactivity shutdown variables -static unsigned long previous_millis_cmd = 0; +static LongTimer previous_millis_cmd; unsigned long max_inactive_time = 0; static unsigned long stepper_inactive_time = DEFAULT_STEPPER_DEACTIVE_TIME*1000l; static unsigned long safetytimer_inactive_time = DEFAULT_SAFETYTIMER_TIME_MINS*60*1000ul; @@ -2060,7 +2060,7 @@ static int setup_for_endstop_move(bool enable_endstops_now = true) { saved_feedrate = feedrate; int l_feedmultiply = feedmultiply; feedmultiply = 100; - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); enable_endstops(enable_endstops_now); return l_feedmultiply; @@ -2074,7 +2074,7 @@ static void clean_up_after_endstop_move(int original_feedmultiply) { feedrate = saved_feedrate; feedmultiply = original_feedmultiply; - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); } @@ -2518,7 +2518,7 @@ void home_xy() void refresh_cmd_timeout(void) { - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); } #ifdef FWRETRACT @@ -2823,7 +2823,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon saved_feedrate = feedrate; int l_feedmultiply = feedmultiply; feedmultiply = 100; - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); enable_endstops(true); @@ -3006,7 +3006,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon feedrate = saved_feedrate; feedmultiply = l_feedmultiply; - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); endstops_hit_on_purpose(); #ifndef MESH_BED_LEVELING //-// Oct 2019 :: this part of code is (from) now probably un-compilable @@ -4359,7 +4359,7 @@ void process_commands() } lcd_ignore_click(); //call lcd_ignore_click also for else ??? st_synchronize(); - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); if (codenum > 0 ) { codenum += _millis(); // keep track of when we started waiting KEEPALIVE_STATE(PAUSED_FOR_USER); @@ -4987,7 +4987,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) if(codenum != 0) LCD_MESSAGERPGM(_n("Sleep..."));////MSG_DWELL st_synchronize(); codenum += _millis(); // keep track of when we started waiting - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); while(_millis() < codenum) { manage_heater(); manage_inactivity(); @@ -6722,7 +6722,7 @@ Sigma_Exit: if (farm_mode) { prusa_statistics(2); }; //starttime=_millis(); - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); } break; @@ -6786,7 +6786,7 @@ Sigma_Exit: KEEPALIVE_STATE(IN_HANDLER); heating_status = 4; - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); } #endif break; @@ -9565,7 +9565,7 @@ void FlushSerialRequestResend() // Execution of a command from a SD card will not be confirmed. void ClearToSend() { - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); if (buflen && ((CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB) || (CMDBUFFER_CURRENT_TYPE == CMDBUFFER_CURRENT_TYPE_USB_WITH_LINENR))) SERIAL_PROTOCOLLNRPGM(MSG_OK); } @@ -9741,7 +9741,7 @@ void mesh_plan_buffer_line(const float &x, const float &y, const float &z, const void prepare_move() { clamp_to_software_endstops(destination); - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); // Do not use feedmultiply for E or Z only moves if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) { @@ -9769,7 +9769,7 @@ void prepare_arc_move(char isclockwise) { // in any intermediate location. set_current_to_destination(); - previous_millis_cmd = _millis(); + previous_millis_cmd.start(); } #if defined(CONTROLLERFAN_PIN) && CONTROLLERFAN_PIN > -1 @@ -10026,11 +10026,11 @@ if(0) get_command(); } - if( (_millis() - previous_millis_cmd) > max_inactive_time ) + if(previous_millis_cmd.expired(max_inactive_time)) if(max_inactive_time) kill(_n("Inactivity Shutdown"), 4); if(stepper_inactive_time) { - if( (_millis() - previous_millis_cmd) > stepper_inactive_time ) + if(previous_millis_cmd.expired(stepper_inactive_time)) { if(blocks_queued() == false && ignore_stepper_queue == false) { disable_x(); @@ -10077,7 +10077,7 @@ if(0) controllerFan(); //Check if fan should be turned on to cool stepper drivers down #endif #ifdef EXTRUDER_RUNOUT_PREVENT - if( (_millis() - previous_millis_cmd) > EXTRUDER_RUNOUT_SECONDS*1000 ) + if(previous_millis_cmd.expired(EXTRUDER_RUNOUT_SECONDS*1000)) if(degHotend(active_extruder)>EXTRUDER_RUNOUT_MINTEMP) { bool oldstatus=READ(E0_ENABLE_PIN); @@ -10090,7 +10090,7 @@ if(0) current_position[E_AXIS]=oldepos; destination[E_AXIS]=oldedes; plan_set_e_position(oldepos); - previous_millis_cmd=_millis(); + previous_millis_cmd.start(); st_synchronize(); WRITE(E0_ENABLE_PIN,oldstatus); } From a1abd094dd398d627d6a3bc35edd1825e62c840a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Thu, 26 Aug 2021 20:49:19 +0000 Subject: [PATCH 37/83] Convert autostart_atmillis to ShortTimer Saves 34 bytes of flash and 1 byte of SRAM --- Firmware/cardreader.cpp | 5 ++--- Firmware/cardreader.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index d4fd92ed1..c23559c98 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -25,7 +25,6 @@ CardReader::CardReader() cardOK = false; saving = false; logging = false; - autostart_atmillis=0; workDirDepth = 0; file_subcall_ctr=0; memset(workDirParents, 0, sizeof(workDirParents)); @@ -39,7 +38,7 @@ CardReader::CardReader() WRITE(SDPOWER,HIGH); #endif //SDPOWER - autostart_atmillis=_millis()+5000; + autostart_atmillis.start(); // reset timer } char *createFilename(char *buffer,const dir_t &p) //buffer>12characters @@ -619,7 +618,7 @@ void CardReader::checkautostart(bool force) { if(!autostart_stilltocheck) return; - if(autostart_atmillis<_millis()) + if(autostart_atmillis.expired(5000)) return; } autostart_stilltocheck=false; diff --git a/Firmware/cardreader.h b/Firmware/cardreader.h index 32a024529..d13caa08b 100644 --- a/Firmware/cardreader.h +++ b/Firmware/cardreader.h @@ -130,7 +130,7 @@ private: char filenames[SD_PROCEDURE_DEPTH][MAXPATHNAMELENGTH]; uint32_t filesize; //int16_t n; - unsigned long autostart_atmillis; + ShortTimer autostart_atmillis; uint32_t sdpos ; bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware. From 37fd9d1b119f83b4b2552e8b59de83757c682595 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Thu, 26 Aug 2021 20:56:45 +0000 Subject: [PATCH 38/83] Convert NcTime to ShortTimer The variable is only used in ultralcd.cpp so I made it static there and deleted it from Marlin_main.cpp Saves 24 bytes of flash and 1 byte of SRAM --- Firmware/Marlin.h | 1 - Firmware/Marlin_main.cpp | 1 - Firmware/ultralcd.cpp | 6 +++--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index e6c5685d0..e3b3fa393 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -330,7 +330,6 @@ extern unsigned int status_number; extern unsigned int heating_status_counter; extern char snmm_filaments_used; extern unsigned long PingTime; -extern unsigned long NcTime; extern bool no_response; extern uint8_t important_status; extern uint8_t saved_filament_type; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 115e4aa3a..ac28ec085 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -161,7 +161,6 @@ CardReader card; #endif unsigned long PingTime = _millis(); -unsigned long NcTime; uint8_t mbl_z_probe_nr = 3; //numer of Z measurements for each point in mesh bed leveling calibration diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 669cdd71c..2cfa73ada 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -55,7 +55,7 @@ int clock_interval = 0; - +static ShortTimer NcTime; static void lcd_sd_updir(); static void lcd_mesh_bed_leveling_settings(); #ifdef LCD_BL_PIN @@ -8705,10 +8705,10 @@ void lcd_printer_connected() { } static void lcd_send_status() { - if (farm_mode && no_response && ((_millis() - NcTime) > (NC_TIME * 1000))) { + if (farm_mode && no_response && (NcTime.expired(NC_TIME * 1000))) { //send important status messages periodicaly prusa_statistics(important_status, saved_filament_type); - NcTime = _millis(); + NcTime.start(); #ifdef FARM_CONNECT_MESSAGE lcd_connect_printer(); #endif //FARM_CONNECT_MESSAGE From 802b8860c862f1e8cca82146ab70c0a0cadf2629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Thu, 26 Aug 2021 21:04:48 +0000 Subject: [PATCH 39/83] Convert mmu_last_finda_response to ShortTimer Saves 48 bytes of Flash, 1 byte of SRAM --- Firmware/mmu.cpp | 6 +++--- Firmware/mmu.h | 3 ++- Firmware/ultralcd.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 0a2df3e9a..0d6ebe4c2 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -70,7 +70,6 @@ uint8_t mmu_extruder = MMU_FILAMENT_UNKNOWN; uint8_t tmp_extruder = MMU_FILAMENT_UNKNOWN; int8_t mmu_finda = -1; -uint32_t mmu_last_finda_response = 0; int16_t mmu_version = -1; @@ -78,6 +77,7 @@ int16_t mmu_buildnr = -1; ShortTimer mmu_last_request; ShortTimer mmu_last_response; +ShortTimer mmu_last_finda_response; MmuCmd mmu_last_cmd = MmuCmd::None; uint16_t mmu_power_failures = 0; @@ -265,7 +265,7 @@ void mmu_loop(void) if (mmu_rx_ok() > 0) { fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer - mmu_last_finda_response = _millis(); + mmu_last_finda_response.start(); FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda); puts_P(PSTR("MMU - ENABLED")); mmu_enabled = true; @@ -378,7 +378,7 @@ void mmu_loop(void) if (mmu_rx_ok() > 0) { fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer - mmu_last_finda_response = _millis(); + mmu_last_finda_response.start(); FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda); //printf_P(PSTR("Eact: %d\n"), int(e_active())); if (!mmu_finda && CHECK_FSENSOR && fsensor_enabled) { diff --git a/Firmware/mmu.h b/Firmware/mmu.h index 30b8e1af9..40a6dc727 100644 --- a/Firmware/mmu.h +++ b/Firmware/mmu.h @@ -4,6 +4,7 @@ #define MMU_H #include +#include "Timer.h" extern bool mmu_enabled; @@ -14,7 +15,7 @@ extern uint8_t mmu_extruder; extern uint8_t tmp_extruder; extern int8_t mmu_finda; -extern uint32_t mmu_last_finda_response; +extern ShortTimer mmu_last_finda_response; extern bool ir_sensor_detected; extern int16_t mmu_version; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 2cfa73ada..19961b44d 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3839,7 +3839,7 @@ static void lcd_show_sensors_state() uint8_t idler_state = STATE_NA; pinda_state = READ(Z_MIN_PIN); - if (mmu_enabled && ((_millis() - mmu_last_finda_response) < 1000ul) ) + if (mmu_enabled && mmu_last_finda_response.expired(1000)) { finda_state = mmu_finda; } From 6a9bab02f794575c1c0449de8d71651e36b7f221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Thu, 26 Aug 2021 21:18:55 +0000 Subject: [PATCH 40/83] Convert display_time to ShortTimer Saves 24 bytes of flash, 1 byte of SRAM --- Firmware/ultralcd.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 19961b44d..8a27dbca6 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -87,7 +87,7 @@ int farm_timer = 8; uint8_t farm_status = 0; bool printer_connected = true; -unsigned long display_time; //just timer for showing pid finished message on lcd; +static ShortTimer display_time; //just timer for showing pid finished message on lcd; float pid_temp = DEFAULT_PID_TEMP; static bool forceMenuExpire = false; @@ -1344,10 +1344,10 @@ void lcd_commands() else { SERIAL_ECHOPGM("Invalid PID cal. results. Not stored to EEPROM."); } - display_time = _millis(); + display_time.start(); lcd_commands_step = 1; } - if ((lcd_commands_step == 1) && ((_millis()- display_time)>2000)) { //calibration finished message + if ((lcd_commands_step == 1) && display_time.expired(2000)) { //calibration finished message lcd_setstatuspgm(_T(WELCOME_MSG)); custom_message_type = CustomMsg::Status; pid_temp = DEFAULT_PID_TEMP; From ef8083a1485545cb6bd351939eb8213ee12b6da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Fri, 27 Aug 2021 08:10:18 +0000 Subject: [PATCH 41/83] crashDetTimer can be ShortTimer Expired value is less than 65535 Saves 8 bytes of flash and 2 bytes of SRAM --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index ac28ec085..259baaa98 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -205,7 +205,7 @@ unsigned long pause_time = 0; unsigned long start_pause_print = _millis(); unsigned long t_fan_rising_edge = _millis(); LongTimer safetyTimer; -static LongTimer crashDetTimer; +static ShortTimer crashDetTimer; //unsigned long load_filament_time; From 42778cae832e5b192ca693b621c5e4aeabe549ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Fri, 27 Aug 2021 08:34:22 +0000 Subject: [PATCH 42/83] Remove unused kicktime timer The variable is only set and never actually used Saves 8 bytes of flash and 4 bytes of SRAM --- Firmware/Marlin.h | 3 --- Firmware/Marlin_main.cpp | 4 ---- 2 files changed, 7 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index e3b3fa393..ac5da8d5c 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -320,9 +320,6 @@ extern bool is_usb_printing; extern bool homing_flag; extern bool loading_flag; extern unsigned int usb_printing_counter; - -extern unsigned long kicktime; - extern unsigned long total_filament_used; void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time); extern unsigned int heating_status; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 259baaa98..138a490cf 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -195,8 +195,6 @@ int bowden_length[4] = {385, 385, 385, 385}; bool is_usb_printing = false; bool homing_flag = false; -unsigned long kicktime = _millis()+100000; - unsigned int usb_printing_counter; int8_t lcd_change_fil_state = 0; @@ -4601,8 +4599,6 @@ void process_commands() eeprom_update_word(reinterpret_cast(&(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)),0); } else if(code_seen_P(PSTR("Beat"))) { // PRUSA Beat - // Kick farm link timer - kicktime = _millis(); } else if(code_seen_P(PSTR("FR"))) { // PRUSA FR // Factory full reset From aa0a86bf13d1f8ee7da72262b05f2d1474ffb5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Fri, 27 Aug 2021 09:01:09 +0000 Subject: [PATCH 43/83] Remove internal Prusa command 'Beat' It doesn't seem to do anything. Saves 22 bytes of flash --- Firmware/Marlin_main.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 138a490cf..50dcced50 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4490,7 +4490,7 @@ void process_commands() Set of internal PRUSA commands #### Usage - PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] + PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | FR ] #### Parameters - `Ping` @@ -4508,7 +4508,6 @@ void process_commands() - `Rev`- Prints filament size, elelectronics, nozzle type - `Lang` - Reset the language - `Lz` - - `Beat` - Kick farm link timer - `FR` - Full factory reset - `nozzle set ` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4` - `nozzle D` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4` @@ -4598,8 +4597,6 @@ void process_commands() } else if(code_seen_P(PSTR("Lz"))) { // PRUSA Lz eeprom_update_word(reinterpret_cast(&(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)),0); - } else if(code_seen_P(PSTR("Beat"))) { // PRUSA Beat - } else if(code_seen_P(PSTR("FR"))) { // PRUSA FR // Factory full reset factory_reset(0); From 2d614a8d41893145dc5e1ded4e59c36de66e04e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 28 Aug 2021 16:52:30 +0000 Subject: [PATCH 44/83] Change usb_printing_counter to uint8_t It is assigned max value of 10 Saves 26 byte of flash and 1 byte of SRAM --- Firmware/Marlin.h | 2 +- Firmware/Marlin_main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index ac5da8d5c..fc7257213 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -319,7 +319,7 @@ extern int bowden_length[4]; extern bool is_usb_printing; extern bool homing_flag; extern bool loading_flag; -extern unsigned int usb_printing_counter; +extern uint8_t usb_printing_counter; extern unsigned long total_filament_used; void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time); extern unsigned int heating_status; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 50dcced50..4f8c88b3f 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -195,7 +195,7 @@ int bowden_length[4] = {385, 385, 385, 385}; bool is_usb_printing = false; bool homing_flag = false; -unsigned int usb_printing_counter; +uint8_t usb_printing_counter; int8_t lcd_change_fil_state = 0; From 22f23dff36560a6b573ae6391b2d87554204ed59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 28 Aug 2021 17:00:24 +0000 Subject: [PATCH 45/83] Change heating_status to uint8_t Saves 66 byte of flash and 1 byte of SRAM --- Firmware/Marlin.h | 2 +- Firmware/Marlin_main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index fc7257213..c5f8f2592 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -322,7 +322,7 @@ extern bool loading_flag; extern uint8_t usb_printing_counter; extern unsigned long total_filament_used; void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time); -extern unsigned int heating_status; +extern uint8_t heating_status; extern unsigned int status_number; extern unsigned int heating_status_counter; extern char snmm_filaments_used; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 4f8c88b3f..b90ae3105 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -217,7 +217,7 @@ bool prusa_sd_card_upload = false; unsigned int status_number = 0; unsigned long total_filament_used; -unsigned int heating_status; +uint8_t heating_status; unsigned int heating_status_counter; bool loading_flag = false; From 60c96406028dc898fa772932a0da4305f2dd49d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 28 Aug 2021 17:02:26 +0000 Subject: [PATCH 46/83] Change heating_status_counter to uint8_t It has a max value of 14 Saves 28 bytes of flash and 1 byte of SRAM --- Firmware/Marlin.h | 2 +- Firmware/Marlin_main.cpp | 2 +- Firmware/ultralcd.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index c5f8f2592..c62c72fef 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -324,7 +324,7 @@ extern unsigned long total_filament_used; void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time); extern uint8_t heating_status; extern unsigned int status_number; -extern unsigned int heating_status_counter; +extern uint8_t heating_status_counter; extern char snmm_filaments_used; extern unsigned long PingTime; extern bool no_response; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index b90ae3105..7f7bf0a7b 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -218,7 +218,7 @@ unsigned int status_number = 0; unsigned long total_filament_used; uint8_t heating_status; -unsigned int heating_status_counter; +uint8_t heating_status_counter; bool loading_flag = false; #define XY_NO_RESTORE_FLAG (mesh_bed_leveling_flag || homing_flag) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 8a27dbca6..c72aa7bd9 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -583,7 +583,7 @@ void lcdui_print_status_line(void) lcd_set_cursor(7, 3); lcd_space(13); - for (unsigned int dots = 0; dots < heating_status_counter; dots++) { + for (uint8_t dots = 0; dots < heating_status_counter; dots++) { lcd_putc_at(7 + dots, 3, '.'); } switch (heating_status) { From a687173e02b0a99b33f92951aaa1653f32b64c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 28 Aug 2021 17:45:31 +0000 Subject: [PATCH 47/83] Change custom_message_state_old and custom_message_state to uint8_t I see max value as 7*7+10 = 59 Saves 100 byte of flash and 1 byte of SRAM --- Firmware/Marlin_main.cpp | 2 +- Firmware/ultralcd.cpp | 2 +- Firmware/ultralcd.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 7f7bf0a7b..107e2467b 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3118,7 +3118,7 @@ static void gcode_G80() #endif //PINDA_THERMISTOR // Save custom message state, set a new custom message state to display: Calibrating point 9. CustomMsg custom_message_type_old = custom_message_type; - unsigned int custom_message_state_old = custom_message_state; + uint8_t custom_message_state_old = custom_message_state; custom_message_type = CustomMsg::MeshBedLeveling; custom_message_state = (nMeasPoints * nMeasPoints) + 10; lcd_update(1); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index c72aa7bd9..c455ca2fa 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -78,7 +78,7 @@ LcdCommands lcd_commands_type = LcdCommands::Idle; static uint8_t lcd_commands_step = 0; CustomMsg custom_message_type = CustomMsg::Status; -unsigned int custom_message_state = 0; +uint8_t custom_message_state = 0; bool isPrintPaused = false; diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 06763556b..ed04757ef 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -121,7 +121,7 @@ enum class CustomMsg : uint_least8_t }; extern CustomMsg custom_message_type; -extern unsigned int custom_message_state; +extern uint8_t custom_message_state; extern uint8_t farm_mode; extern int farm_timer; From 2013295f9401d94faddb878938e221c6e80f10f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 28 Aug 2021 18:00:03 +0000 Subject: [PATCH 48/83] Change farm_timer to uint8_t Remove extern declaration of farm_timer and farm_status as they are only used in one file. Saves 26 bytes of flash --- Firmware/ultralcd.cpp | 3 +-- Firmware/ultralcd.h | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index c455ca2fa..82a46a5d7 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -80,10 +80,9 @@ static uint8_t lcd_commands_step = 0; CustomMsg custom_message_type = CustomMsg::Status; uint8_t custom_message_state = 0; - bool isPrintPaused = false; uint8_t farm_mode = 0; -int farm_timer = 8; +uint8_t farm_timer = 8; uint8_t farm_status = 0; bool printer_connected = true; diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index ed04757ef..0ea53bd6c 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -124,8 +124,6 @@ extern CustomMsg custom_message_type; extern uint8_t custom_message_state; extern uint8_t farm_mode; -extern int farm_timer; -extern uint8_t farm_status; extern bool UserECoolEnabled(); extern bool FarmOrUserECool(); From a940c364c9244ab1bf7ca269ff6001049bd72631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 28 Aug 2021 18:23:44 +0000 Subject: [PATCH 49/83] Create enum class for heating_status variable --- Firmware/Marlin.h | 12 +++++++++++- Firmware/Marlin_main.cpp | 14 +++++++------- Firmware/temperature.cpp | 4 ++-- Firmware/ultralcd.cpp | 16 ++++++++-------- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index c62c72fef..6797b954b 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -275,6 +275,17 @@ FORCE_INLINE unsigned long millis_nc() { void setPwmFrequency(uint8_t pin, int val); #endif +enum class HeatingStatus : uint8_t +{ + NO_HEATING = 0, + EXTRUDER_HEATING = 1, + EXTRUDER_HEATING_COMPLETE = 2, + BED_HEATING = 3, + BED_HEATING_COMPLETE = 4, +}; + +extern HeatingStatus heating_status; + extern bool fans_check_enabled; extern float homing_feedrate[]; extern uint8_t axis_relative_modes; @@ -322,7 +333,6 @@ extern bool loading_flag; extern uint8_t usb_printing_counter; extern unsigned long total_filament_used; void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time); -extern uint8_t heating_status; extern unsigned int status_number; extern uint8_t heating_status_counter; extern char snmm_filaments_used; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 107e2467b..868666d29 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -217,7 +217,7 @@ bool prusa_sd_card_upload = false; unsigned int status_number = 0; unsigned long total_filament_used; -uint8_t heating_status; +HeatingStatus heating_status; uint8_t heating_status_counter; bool loading_flag = false; @@ -6676,7 +6676,7 @@ Sigma_Exit: break; } LCD_MESSAGERPGM(_T(MSG_HEATING)); - heating_status = 1; + heating_status = HeatingStatus::EXTRUDER_HEATING; if (farm_mode) { prusa_statistics(1); }; #ifdef AUTOTEMP @@ -6710,7 +6710,7 @@ Sigma_Exit: LCD_MESSAGERPGM(_T(MSG_HEATING_COMPLETE)); KEEPALIVE_STATE(IN_HANDLER); - heating_status = 2; + heating_status = HeatingStatus::EXTRUDER_HEATING_COMPLETE; if (farm_mode) { prusa_statistics(2); }; //starttime=_millis(); @@ -6736,7 +6736,7 @@ Sigma_Exit: { bool CooldownNoWait = false; LCD_MESSAGERPGM(_T(MSG_BED_HEATING)); - heating_status = 3; + heating_status = HeatingStatus::BED_HEATING; if (farm_mode) { prusa_statistics(1); }; if (code_seen('S')) { @@ -6776,7 +6776,7 @@ Sigma_Exit: } LCD_MESSAGERPGM(_T(MSG_BED_DONE)); KEEPALIVE_STATE(IN_HANDLER); - heating_status = 4; + heating_status = HeatingStatus::BED_HEATING_COMPLETE; previous_millis_cmd.start(); } @@ -11798,9 +11798,9 @@ void restore_print_from_ram_and_continue(float e_move) if (degTargetHotend(saved_active_extruder) != saved_extruder_temperature) { setTargetHotendSafe(saved_extruder_temperature, saved_active_extruder); - heating_status = 1; + heating_status = HeatingStatus::EXTRUDER_HEATING; wait_for_heater(_millis(), saved_active_extruder); - heating_status = 2; + heating_status = HeatingStatus::EXTRUDER_HEATING_COMPLETE; } axis_relative_modes ^= (-saved_extruder_relative_mode ^ axis_relative_modes) & E_AXIS_MASK; float e = saved_pos[E_AXIS] - e_move; diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 7730be05d..788d42acc 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -615,7 +615,7 @@ void fanSpeedError(unsigned char _fan) { if (get_message_level() != 0 && isPrintPaused) return; //to ensure that target temp. is not set to zero in case that we are resuming print if (card.sdprinting || is_usb_printing) { - if (heating_status != 0) { + if (heating_status != HeatingStatus::NO_HEATING) { lcd_print_stop(); } else { @@ -625,7 +625,7 @@ void fanSpeedError(unsigned char _fan) { else { // SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSED); //Why pause octoprint? is_usb_printing would be true in that case, so there is no need for this. setTargetHotend0(0); - heating_status = 0; + heating_status = HeatingStatus::NO_HEATING; fan_check_error = EFCE_REPORTED; } switch (_fan) { diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 82a46a5d7..e075e778a 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -457,7 +457,7 @@ void lcdui_print_percent_done(void) const char* src = is_usb_printing?_N("USB"):(IS_SD_PRINTING?_N(" SD"):_N(" ")); char per[4]; bool num = IS_SD_PRINTING || (PRINTER_ACTIVE && (print_percent_done_normal != PRINT_PERCENT_DONE_INIT)); - if (!num || heating_status) // either not printing or heating + if (!num || heating_status != HeatingStatus::NO_HEATING) // either not printing or heating { const int8_t sheetNR = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)); const int8_t nextSheet = eeprom_next_initialized_sheet(sheetNR); @@ -574,7 +574,7 @@ void lcdui_print_time(void) //! @Brief Print status line on status screen void lcdui_print_status_line(void) { - if (heating_status) { // If heating flag, show progress of heating + if (heating_status != HeatingStatus::NO_HEATING) { // If heating flag, show progress of heating heating_status_counter++; if (heating_status_counter > 13) { heating_status_counter = 0; @@ -586,20 +586,20 @@ void lcdui_print_status_line(void) lcd_putc_at(7 + dots, 3, '.'); } switch (heating_status) { - case 1: + case HeatingStatus::EXTRUDER_HEATING: lcd_puts_at_P(0, 3, _T(MSG_HEATING)); break; - case 2: + case HeatingStatus::EXTRUDER_HEATING_COMPLETE: lcd_puts_at_P(0, 3, _T(MSG_HEATING_COMPLETE)); - heating_status = 0; + heating_status = HeatingStatus::NO_HEATING; heating_status_counter = 0; break; - case 3: + case HeatingStatus::BED_HEATING: lcd_puts_at_P(0, 3, _T(MSG_BED_HEATING)); break; - case 4: + case HeatingStatus::BED_HEATING_COMPLETE: lcd_puts_at_P(0, 3, _T(MSG_BED_DONE)); - heating_status = 0; + heating_status = HeatingStatus::NO_HEATING; heating_status_counter = 0; break; default: From b835f31904ef1d4c56a603accfe87a0aa6f4ad1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 5 Sep 2021 17:08:30 +0000 Subject: [PATCH 50/83] Remove variable move_menu_scale The variable is just set to 1.0 and is never modified, I also removed the function lcd_move_menu_1mm() Changes save 96 bytes of flash memory and 4 bytes of SRAM --- Firmware/ultralcd.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index e075e778a..f9d36b88a 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1384,8 +1384,6 @@ void lcd_pause_usb_print() SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE); } - -float move_menu_scale; static void lcd_move_menu_axis(); @@ -2762,7 +2760,7 @@ static void _lcd_move(const char *name, uint8_t axis, int min, int max) refresh_cmd_timeout(); if (! planner_queue_full()) { - current_position[axis] += float((int)lcd_encoder) * move_menu_scale; + current_position[axis] += float((int)lcd_encoder); if (min_software_endstops && current_position[axis] < min) current_position[axis] = min; if (max_software_endstops && current_position[axis] > max) current_position[axis] = max; lcd_encoder = 0; @@ -2790,7 +2788,7 @@ void lcd_move_e() refresh_cmd_timeout(); if (! planner_queue_full()) { - current_position[E_AXIS] += float((int)lcd_encoder) * move_menu_scale; + current_position[E_AXIS] += float((int)lcd_encoder); lcd_encoder = 0; plan_buffer_line_curposXYZE(manual_feedrate[E_AXIS] / 60); lcd_draw_update = 1; @@ -4234,13 +4232,6 @@ void lcd_move_menu_axis() MENU_END(); } -static void lcd_move_menu_1mm() -{ - move_menu_scale = 1.0; - lcd_move_menu_axis(); -} - - void EEPROM_save(int pos, uint8_t* value, uint8_t size) { do @@ -5671,7 +5662,7 @@ static void lcd_settings_menu() if (!PRINTER_ACTIVE || isPrintPaused) { - MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS c=18 + MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_axis);////MSG_MOVE_AXIS c=18 MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS c=18 } @@ -8879,7 +8870,6 @@ void menu_lcd_longpress_func(void) #endif || menu_menu == lcd_support_menu ){ - move_menu_scale = 1.0; menu_submenu(lcd_move_z); } else { // otherwise consume the long press as normal click From 7787f17139380c0e3f238862712b3803d38391fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 12 Sep 2021 15:03:34 +0000 Subject: [PATCH 51/83] Smaller code in G28 Replace two blocks of code with already defined functions. Change saves 100 bytes of flash memory and 11 lines of code. --- Firmware/Marlin_main.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 868666d29..06a6dbda7 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2817,12 +2817,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon if (home_z) babystep_undo(); - saved_feedrate = feedrate; - int l_feedmultiply = feedmultiply; - feedmultiply = 100; - previous_millis_cmd.start(); - - enable_endstops(true); + int l_feedmultiply = setup_for_endstop_move(); set_destination_to_current(); feedrate = 0.0; @@ -2997,13 +2992,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon // contains the machine coordinates. plan_set_position_curposXYZE(); - #ifdef ENDSTOPS_ONLY_FOR_HOMING - enable_endstops(false); - #endif - - feedrate = saved_feedrate; - feedmultiply = l_feedmultiply; - previous_millis_cmd.start(); + clean_up_after_endstop_move(l_feedmultiply); endstops_hit_on_purpose(); #ifndef MESH_BED_LEVELING //-// Oct 2019 :: this part of code is (from) now probably un-compilable From 052ecc3782d6313fc522bd9d3d9a6f2806154651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 12 Sep 2021 16:22:47 +0000 Subject: [PATCH 52/83] G81: Change for loop variables x and y to uint8_t Saves 198 bytes of flash, that's crazy --- Firmware/Marlin_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 06a6dbda7..4b8dd2d1a 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5625,8 +5625,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\nZ search height: "); SERIAL_PROTOCOL(MESH_HOME_Z_SEARCH); SERIAL_PROTOCOLLNPGM("\nMeasured points:"); - for (int y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { - for (int x = 0; x < MESH_NUM_X_POINTS; x++) { + for (uint8_t y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { + for (uint8_t x = 0; x < MESH_NUM_X_POINTS; x++) { SERIAL_PROTOCOLPGM(" "); SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5); } From ac049c7e3c5c1bd0f627ed55897fd331c637fff9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 12 Sep 2021 16:42:31 +0000 Subject: [PATCH 53/83] Use code_value_short() in get_command() Same code but uses a defined function Saves 28 bytes of flash memory --- Firmware/cmdqueue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 7cd0c4635..fab0fe7dd 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -443,7 +443,7 @@ void get_command() char *p = cmdbuffer+bufindw+CMDHDRSIZE; while (p != strchr_pointer) checksum = checksum^(*p++); - if (int(strtol(strchr_pointer+1, NULL, 10)) != int(checksum)) { + if (code_value_short() != (int16_t)checksum) { SERIAL_ERROR_START; SERIAL_ERRORRPGM(_n("checksum mismatch, Last Line: "));////MSG_ERR_CHECKSUM_MISMATCH SERIAL_ERRORLN(gcode_LastN); From d8723c0eac7c186199fff02ba9b4c4552d0b68e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 12 Sep 2021 16:47:03 +0000 Subject: [PATCH 54/83] Use code_value_uint8() in get_command() The if statement is simplified as the value is never negative and we can get rid of one variable Saves 12 bytes of flash memory --- Firmware/cmdqueue.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index fab0fe7dd..a48fcdb5c 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -486,8 +486,7 @@ void get_command() is_usb_printing = true; } if (Stopped == true) { - int gcode = strtol(strchr_pointer+1, NULL, 10); - if (gcode >= 0 && gcode <= 3) { + if (code_value_uint8() <= 3) { SERIAL_ERRORLNRPGM(MSG_ERR_STOPPED); LCD_MESSAGERPGM(_T(MSG_STOPPED)); } From f8847edca69b9dee19b5c222b4066f6987ae5529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 29 Jan 2022 14:40:47 +0000 Subject: [PATCH 55/83] Remove one unused variable Saves 1 byte of SRAM The variable is only assigned a value but is never used. --- Firmware/Marlin.h | 1 - Firmware/Marlin_main.cpp | 2 -- Firmware/ultralcd.cpp | 1 - 3 files changed, 4 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 6797b954b..08a09a04a 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -354,7 +354,6 @@ extern unsigned long start_pause_print; extern unsigned long t_fan_rising_edge; extern bool mesh_bed_leveling_flag; -extern bool mesh_bed_run_from_menu; extern int8_t lcd_change_fil_state; // save/restore printing diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 4b8dd2d1a..711ea2488 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -208,7 +208,6 @@ static ShortTimer crashDetTimer; //unsigned long load_filament_time; bool mesh_bed_leveling_flag = false; -bool mesh_bed_run_from_menu = false; #ifdef PRUSA_M28 bool prusa_sd_card_upload = false; @@ -3448,7 +3447,6 @@ static void gcode_G80() lcd_setstatuspgm(_T(WELCOME_MSG)); custom_message_type = custom_message_type_old; custom_message_state = custom_message_state_old; - mesh_bed_run_from_menu = false; lcd_update(2); st_synchronize(); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f9d36b88a..c0afd946a 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -4493,7 +4493,6 @@ static void lcd_language_menu() void lcd_mesh_bedleveling() { - mesh_bed_run_from_menu = true; enquecommand_P(PSTR("G80")); lcd_return_to_status(); } From 581188ce2c43e5a623b39a0aa011a4f512de30bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 29 Jan 2022 14:53:23 +0000 Subject: [PATCH 56/83] Fix an issue found in code review Unfortunately this increases flash usages by 212 bytes (same usage as in current release) It seems it is most memory effcient to use int16_t (int). int8_t requires more memory. --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 711ea2488..01f9797ae 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5623,7 +5623,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\nZ search height: "); SERIAL_PROTOCOL(MESH_HOME_Z_SEARCH); SERIAL_PROTOCOLLNPGM("\nMeasured points:"); - for (uint8_t y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { + for (int16_t y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { for (uint8_t x = 0; x < MESH_NUM_X_POINTS; x++) { SERIAL_PROTOCOLPGM(" "); SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5); From c705d4aa106e1eefd87b36fc45947b0df8fc7618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 29 Jan 2022 14:58:39 +0000 Subject: [PATCH 57/83] Change set_z() parameters to uin8_t Saves 24 bytes of flash --- Firmware/mesh_bed_calibration.cpp | 6 +++--- Firmware/mesh_bed_leveling.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 23d7c8736..892415e56 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -2872,14 +2872,14 @@ bool sample_mesh_and_store_reference() } mbl.set_z(0, 0, current_position[Z_AXIS]); } - for (int8_t mesh_point = 1; mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS; ++ mesh_point) { + for (uint8_t mesh_point = 1; mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS; ++ mesh_point) { // Don't let the manage_inactivity() function remove power from the motors. refresh_cmd_timeout(); // Print the decrasing ID of the measurement point. current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; go_to_current(homing_feedrate[Z_AXIS]/60); - int8_t ix = mesh_point % MESH_MEAS_NUM_X_POINTS; - int8_t iy = mesh_point / MESH_MEAS_NUM_X_POINTS; + uint8_t ix = mesh_point % MESH_MEAS_NUM_X_POINTS; + uint8_t iy = mesh_point / MESH_MEAS_NUM_X_POINTS; if (iy & 1) ix = (MESH_MEAS_NUM_X_POINTS - 1) - ix; // Zig zag current_position[X_AXIS] = BED_X(ix, MESH_MEAS_NUM_X_POINTS); current_position[Y_AXIS] = BED_Y(iy, MESH_MEAS_NUM_Y_POINTS); diff --git a/Firmware/mesh_bed_leveling.h b/Firmware/mesh_bed_leveling.h index bf3729558..37d9ade78 100644 --- a/Firmware/mesh_bed_leveling.h +++ b/Firmware/mesh_bed_leveling.h @@ -29,7 +29,7 @@ public: // Otherwise a correction matrix is pulled from the EEPROM if available. static void get_meas_xy(int ix, int iy, float &x, float &y, bool use_default); - void set_z(int ix, int iy, float z) { z_values[iy][ix] = z; } + void set_z(uint8_t ix, uint8_t iy, float z) { z_values[iy][ix] = z; } int select_x_index(float x) { int i = 1; From 49693a9fb375f65df6cce8cd57598aab1c883ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 29 Jan 2022 15:01:51 +0000 Subject: [PATCH 58/83] Remove undefined function No change in memory footprint. --- Firmware/mesh_bed_leveling.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Firmware/mesh_bed_leveling.h b/Firmware/mesh_bed_leveling.h index 37d9ade78..7df04844a 100644 --- a/Firmware/mesh_bed_leveling.h +++ b/Firmware/mesh_bed_leveling.h @@ -24,11 +24,6 @@ public: static float get_x(int i) { return float(MESH_MIN_X) + float(MESH_X_DIST) * float(i); } static float get_y(int i) { return float(MESH_MIN_Y) + float(MESH_Y_DIST) * float(i); } - // Measurement point for the Z probe. - // If use_default=true, then the default positions for a correctly built printer are used. - // Otherwise a correction matrix is pulled from the EEPROM if available. - static void get_meas_xy(int ix, int iy, float &x, float &y, bool use_default); - void set_z(uint8_t ix, uint8_t iy, float z) { z_values[iy][ix] = z; } int select_x_index(float x) { From c081e1a5ae39d93ccb77213e4ebf5ac7c6659040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sat, 29 Jan 2022 15:08:10 +0000 Subject: [PATCH 59/83] Loop index can be unsigned Saves 4 bytes of flash memory --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 01f9797ae..bc3334c46 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -11130,7 +11130,7 @@ void uvlo_() eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), sd_position); // Store the mesh bed leveling offsets. This is 2*7*7=98 bytes, which takes 98*3.4us=333us in worst case. - for (int8_t mesh_point = 0; mesh_point < MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS; ++ mesh_point) { + for (uint8_t mesh_point = 0; mesh_point < MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS; ++ mesh_point) { uint8_t ix = mesh_point % MESH_NUM_X_POINTS; // from 0 to MESH_NUM_X_POINTS - 1 uint8_t iy = mesh_point / MESH_NUM_X_POINTS; // Scale the z value to 1u resolution. From aae562e480081e2fe813c5b3a63288f0b5c47ead Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 30 Jan 2022 02:56:05 +0100 Subject: [PATCH 60/83] Fix G81 for loop --- Firmware/Marlin_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index bc3334c46..3ed9f8165 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -5623,7 +5623,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\nZ search height: "); SERIAL_PROTOCOL(MESH_HOME_Z_SEARCH); SERIAL_PROTOCOLLNPGM("\nMeasured points:"); - for (int16_t y = MESH_NUM_Y_POINTS-1; y >= 0; y--) { + for (uint8_t y = MESH_NUM_Y_POINTS; y-- > 0;) { for (uint8_t x = 0; x < MESH_NUM_X_POINTS; x++) { SERIAL_PROTOCOLPGM(" "); SERIAL_PROTOCOL_F(mbl.z_values[y][x], 5); From 67e6361ff17dea34a61a02d71c8d04a24c9011cc Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 30 Jan 2022 13:16:05 +0100 Subject: [PATCH 61/83] Fix temperature runaway variable types (merge conflict) --- Firmware/temperature.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 401218c8d..684dcd444 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -220,10 +220,10 @@ enum TempRunawayStates : uint8_t //=========================================================================== #if (defined (TEMP_RUNAWAY_BED_HYSTERESIS) && TEMP_RUNAWAY_BED_TIMEOUT > 0) || (defined (TEMP_RUNAWAY_EXTRUDER_HYSTERESIS) && TEMP_RUNAWAY_EXTRUDER_TIMEOUT > 0) -static float temp_runaway_status[1 + EXTRUDERS]; +static uint8_t temp_runaway_status[1 + EXTRUDERS]; static float temp_runaway_target[1 + EXTRUDERS]; -static float temp_runaway_timer[1 + EXTRUDERS]; -static int temp_runaway_error_counter[1 + EXTRUDERS]; +static uint32_t temp_runaway_timer[1 + EXTRUDERS]; +static uint16_t temp_runaway_error_counter[1 + EXTRUDERS]; static void temp_runaway_check(uint8_t _heater_id, float _target_temperature, float _current_temperature, float _output, bool _isbed); static void temp_runaway_stop(bool isPreheat, bool isBed); From 1523194d3b46ed701b1c7a57da64cb117ba51166 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 30 Jan 2022 13:18:07 +0100 Subject: [PATCH 62/83] Fix build (merge conflict) --- Firmware/ultralcd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index e2f0f2044..a134965d5 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -48,7 +48,7 @@ void lcd_pause_print(); void lcd_pause_usb_print(); void lcd_resume_print(); void lcd_print_stop(); -void prusa_statistics(int _message, uint8_t _col_nr = 0); +void prusa_statistics(uint8_t _message, uint8_t _col_nr = 0); void lcd_load_filament_color_check(); //void lcd_mylang(); From c0e7e17fc357f105b7b6c95c019d0a97c400ce97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 30 Jan 2022 13:07:09 +0000 Subject: [PATCH 63/83] Fix type of nrFiles --- Firmware/cardreader.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/cardreader.h b/Firmware/cardreader.h index d13caa08b..ea6e25b44 100644 --- a/Firmware/cardreader.h +++ b/Firmware/cardreader.h @@ -135,7 +135,7 @@ private: bool autostart_stilltocheck; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware. - int16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory. + uint16_t nrFiles; //counter for the files in the current directory and recycled as position counter for getting the nrFiles'th name in the directory. bool diveSubfolder (const char *&fileName); void lsDive(const char *prepend, SdFile parent, const char * const match=NULL, LsAction lsAction = LS_GetFilename, ls_param lsParams = ls_param()); From aec2db7683bac2803fbe6ea2c77f052963de05d8 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Tue, 1 Feb 2022 18:12:13 +0100 Subject: [PATCH 64/83] Optimize MUL8x16R8 --- Firmware/speed_lookuptable.h | 57 ++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/Firmware/speed_lookuptable.h b/Firmware/speed_lookuptable.h index b72eb18b8..1d9048d3a 100644 --- a/Firmware/speed_lookuptable.h +++ b/Firmware/speed_lookuptable.h @@ -8,30 +8,36 @@ extern const uint16_t speed_lookuptable_slow[256][2] PROGMEM; #ifndef _NO_ASM -// intRes = intIn1 * intIn2 >> 8 -// uses: -// r26 to store 0 -// r27 to store the byte 1 of the 24 bit result -#define MultiU16X8toH16(intRes, charIn1, intIn2) \ -asm volatile ( \ -"clr r26 \n\t" \ -"mul %A1, %B2 \n\t" \ -"movw %A0, r0 \n\t" \ -"mul %A1, %A2 \n\t" \ -"add %A0, r1 \n\t" \ -"adc %B0, r26 \n\t" \ -"lsr r0 \n\t" \ -"adc %A0, r26 \n\t" \ -"adc %B0, r26 \n\t" \ -"clr r1 \n\t" \ -: \ -"=&r" (intRes) \ -: \ -"d" (charIn1), \ -"d" (intIn2) \ -: \ -"r26" \ -) +// return ((x * y) >> 8) with rounding when shifting right +FORCE_INLINE uint16_t MUL8x16R8(uint8_t x, uint16_t y) { + uint16_t out; + __asm__ ( + // %0 out + // %1 x + // %2 y + // uint8_t: %An or %n + // uint16_t: %Bn %An + // __uint24: %Cn %Bn %An + // uint32_t: %Dn %Cn %Bn %An + // + // + // B2 A2 * + // A1 + //--------- + // B0 A0 RR + "mul %B2, %A1" "\n\t" + "movw %0, r0" "\n\t" + "mul %A2, %A1" "\n\t" + "lsl r0" "\n\t" //push MSB to carry for rounding + "adc %A0, r1" "\n\t" //add with carry (for rounding) + "clr r1" "\n\t" //make r1 __zero_reg__ again + "adc %B0, r1" "\n\t" //propagate carry of addition (add 0 with carry) + : "=&r" (out) + : "r" (x), "r" (y) + : "r0", "r1" //clobbers: Technically these are either scratch registers or always 0 registers, but I'm making sure the compiler knows just in case. + ); + return out; +} // intRes = longIn1 * longIn2 >> 24 // uses: @@ -115,8 +121,7 @@ FORCE_INLINE unsigned short calc_timer(uint16_t step_rate, uint8_t& step_loops) unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0]; unsigned char tmp_step_rate = (step_rate & 0x00ff); uint16_t gain = (uint16_t)pgm_read_word_near(table_address+2); - MultiU16X8toH16(timer, tmp_step_rate, gain); - timer = (unsigned short)pgm_read_word_near(table_address) - timer; + timer = (unsigned short)pgm_read_word_near(table_address) - MUL8x16R8(tmp_step_rate, gain); } else { // lower step rates unsigned short table_address = (unsigned short)&speed_lookuptable_slow[0][0]; From 53dfcf9d6f1c42e54194e1cb2c6d453e8a003eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Tue, 1 Feb 2022 18:37:41 +0000 Subject: [PATCH 65/83] Optimise if-statments in world2machine_clamp Only one of the statements can be true: tmpx < X_MIN_POS or tmpx > X_MAX_POS. So we can be a little bit smarter here and skip the second if statement if the first was true. This saves 6 bytes of flash memory and potential some clock cycles --- Firmware/mesh_bed_calibration.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Firmware/mesh_bed_calibration.h b/Firmware/mesh_bed_calibration.h index c539d4b59..02b97cc2d 100644 --- a/Firmware/mesh_bed_calibration.h +++ b/Firmware/mesh_bed_calibration.h @@ -129,16 +129,15 @@ inline bool world2machine_clamp(float &x, float &y) if (tmpx < X_MIN_POS) { tmpx = X_MIN_POS; clamped = true; - } - if (tmpy < Y_MIN_POS) { - tmpy = Y_MIN_POS; - clamped = true; - } - if (tmpx > X_MAX_POS) { + } else if (tmpx > X_MAX_POS) { tmpx = X_MAX_POS; clamped = true; } - if (tmpy > Y_MAX_POS) { + + if (tmpy < Y_MIN_POS) { + tmpy = Y_MIN_POS; + clamped = true; + } else if (tmpy > Y_MAX_POS) { tmpy = Y_MAX_POS; clamped = true; } From e525bcb7f59a2e22eadb3642e9f7dc3aa4bc7aa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Tue, 1 Feb 2022 18:57:43 +0000 Subject: [PATCH 66/83] Optimise lcd_selftest_screen input parameters and return type * _progress_scale is max 3 so it can be uint8_t * _progress is max 6 so it can be uint8_t * Change _delay type to uint16_t to be explicit Changes save 102 bytes of flash memory (Arduino IDE 1.8.19) --- Firmware/ultralcd.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 2b75f5f6c..2b6922ae0 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -205,7 +205,7 @@ enum class TestError : uint_least8_t FsensorLevel }; -static int lcd_selftest_screen(TestScreen screen, int _progress, int _progress_scale, bool _clear, int _delay); +static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay); static void lcd_selftest_screen_step(uint8_t _row, uint8_t _col, uint8_t _state, const char *_name, const char *_indicator); static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite, bool _default=false); @@ -7335,7 +7335,7 @@ static void lcd_selftest_v() bool lcd_selftest() { - int _progress = 0; + uint8_t _progress = 0; bool _result = true; bool _swapped_fan = false; #ifdef IR_SENSOR_ANALOG @@ -7733,7 +7733,7 @@ static bool lcd_selfcheck_axis(int _axis, int _travel) // printf_P(PSTR("lcd_selfcheck_axis %d, %d\n"), _axis, _travel); bool _stepdone = false; bool _stepresult = false; - int _progress = 0; + uint8_t _progress = 0; int _travel_done = 0; int _err_endstop = 0; int _lcd_refresh = 0; @@ -7944,14 +7944,14 @@ static bool lcd_selfcheck_endstops() static bool lcd_selfcheck_check_heater(bool _isbed) { - int _counter = 0; - int _progress = 0; + uint8_t _counter = 0; + uint8_t _progress = 0; bool _stepresult = false; bool _docycle = true; int _checked_snapshot = (_isbed) ? degBed() : degHotend(0); int _opposite_snapshot = (_isbed) ? degHotend(0) : degBed(); - int _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s + uint8_t _cycles = (_isbed) ? 180 : 60; //~ 90s / 30s target_temperature[0] = (_isbed) ? 0 : 200; target_temperature_bed = (_isbed) ? 100 : 0; @@ -8372,7 +8372,7 @@ static FanCheck lcd_selftest_fan_auto(int _fan) #endif //FANCHECK -static int lcd_selftest_screen(TestScreen screen, int _progress, int _progress_scale, bool _clear, int _delay) +static uint8_t lcd_selftest_screen(TestScreen screen, uint8_t _progress, uint8_t _progress_scale, bool _clear, uint16_t _delay) { lcd_update_enable(false); From 459570ab660a0e2114bc696a4fc184f87011d20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Wed, 2 Feb 2022 18:35:52 +0000 Subject: [PATCH 67/83] Change prusa_stat_printerstatus parameter to uint8_t Also changes status_number global variable to uint8_t Changes save 80 bytes of flash and 1 byte of SRAM (Arduino IDE 1.8.19) --- Firmware/Marlin.h | 2 +- Firmware/Marlin_main.cpp | 4 ++-- Firmware/ultralcd.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 12d29fee3..b2a09e341 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -335,7 +335,7 @@ extern bool loading_flag; extern uint8_t usb_printing_counter; extern unsigned long total_filament_used; void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time); -extern unsigned int status_number; +extern uint8_t status_number; extern uint8_t heating_status_counter; extern char snmm_filaments_used; extern unsigned long PingTime; diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 3dd18f8ad..5b6c31717 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -213,7 +213,7 @@ bool mesh_bed_leveling_flag = false; bool prusa_sd_card_upload = false; #endif -unsigned int status_number = 0; +uint8_t status_number = 0; unsigned long total_filament_used; HeatingStatus heating_status; @@ -4509,7 +4509,7 @@ void process_commands() } } else if (code_seen_P(PSTR("PRN"))) { // PRUSA PRN - printf_P(_N("%d"), status_number); + printf_P(_N("%u"), status_number); } else if( code_seen_P(PSTR("FANPINTST"))){ gcode_PRUSA_BadRAMBoFanTest(); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 2b6922ae0..3008a7dce 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -126,7 +126,7 @@ static void lcd_control_temperature_menu(); #ifdef TMC2130 static void lcd_settings_linearity_correction_menu_save(); #endif -static void prusa_stat_printerstatus(int _status); +static void prusa_stat_printerstatus(uint8_t _status); static void prusa_stat_farm_number(); static void prusa_stat_diameter(); static void prusa_stat_temperatures(); @@ -4064,7 +4064,7 @@ void prusa_statistics(uint8_t _message, uint8_t _fil_nr) { } -static void prusa_stat_printerstatus(int _status) +static void prusa_stat_printerstatus(uint8_t _status) { SERIAL_ECHOPGM("[PRN:"); SERIAL_ECHO(_status); From 146b00818696dc65338da34c08710cca7887de16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Wed, 2 Feb 2022 18:37:55 +0000 Subject: [PATCH 68/83] Remove redundant variable farm_status It is unused and status_number variable can be used instead. --- Firmware/ultralcd.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 3008a7dce..84f90512e 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -83,7 +83,6 @@ uint8_t custom_message_state = 0; bool isPrintPaused = false; uint8_t farm_mode = 0; uint8_t farm_timer = 8; -uint8_t farm_status = 0; bool printer_connected = true; static ShortTimer display_time; //just timer for showing pid finished message on lcd; @@ -3949,7 +3948,6 @@ void prusa_statistics(uint8_t _message, uint8_t _fil_nr) { break; case 1: // 1 heating - farm_status = 2; SERIAL_ECHO('{'); prusa_stat_printerstatus(2); prusa_stat_farm_number(); @@ -3958,7 +3956,6 @@ void prusa_statistics(uint8_t _message, uint8_t _fil_nr) { break; case 2: // heating done - farm_status = 3; SERIAL_ECHO('{'); prusa_stat_printerstatus(3); prusa_stat_farm_number(); @@ -3968,7 +3965,6 @@ void prusa_statistics(uint8_t _message, uint8_t _fil_nr) { if (IS_SD_PRINTING || loading_flag) { - farm_status = 4; SERIAL_ECHO('{'); prusa_stat_printerstatus(4); prusa_stat_farm_number(); From 6ce7792045066a4526d7acad085931d0908eaff2 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 2 Feb 2022 20:58:21 +0100 Subject: [PATCH 69/83] Remove "hh" in fmt where it makes no difference --- Firmware/ConfigurationStore.cpp | 4 ++-- Firmware/Marlin_main.cpp | 8 ++++---- Firmware/cmdqueue.cpp | 2 +- Firmware/fsensor.cpp | 18 +++++++++--------- Firmware/mmu.cpp | 4 ++-- Firmware/pat9125.c | 4 ++-- Firmware/tmc2130.cpp | 10 +++++----- Firmware/ultralcd.cpp | 6 +++--- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Firmware/ConfigurationStore.cpp b/Firmware/ConfigurationStore.cpp index adccb3999..f7909a6d5 100644 --- a/Firmware/ConfigurationStore.cpp +++ b/Firmware/ConfigurationStore.cpp @@ -32,7 +32,7 @@ static bool EEPROM_writeData(uint8_t* pos, uint8_t* value, uint8_t size, const c #endif //DEBUG_EEPROM_WRITE { #ifdef DEBUG_EEPROM_WRITE - printf_P(PSTR("EEPROM_WRITE_VAR addr=0x%04x size=0x%02hhx name=%s\n"), pos, size, name); + printf_P(PSTR("EEPROM_WRITE_VAR addr=0x%04x size=0x%02x name=%s\n"), pos, size, name); #endif //DEBUG_EEPROM_WRITE while (size--) { @@ -56,7 +56,7 @@ static void EEPROM_readData(uint8_t* pos, uint8_t* value, uint8_t size, const ch #endif //DEBUG_EEPROM_READ { #ifdef DEBUG_EEPROM_READ - printf_P(PSTR("EEPROM_READ_VAR addr=0x%04x size=0x%02hhx name=%s\n"), pos, size, name); + printf_P(PSTR("EEPROM_READ_VAR addr=0x%04x size=0x%02x name=%s\n"), pos, size, name); #endif //DEBUG_EEPROM_READ while(size--) { diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5b6c31717..b04ffcdb7 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1518,7 +1518,7 @@ void setup() xflash_rd_uid(uid); puts_P(_n("XFLASH UID=")); for (uint8_t i = 0; i < 8; i ++) - printf_P(PSTR("%02hhx"), uid[i]); + printf_P(PSTR("%02x"), uid[i]); putchar('\n'); list_sec_lang_from_external_flash(); #endif //DEBUG_XFLASH @@ -4450,7 +4450,7 @@ void process_commands() tmc2130_chopper_config[axis].hend = chop2 & 15; tmc2130_chopper_config[axis].tbl = chop3 & 3; tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); - //printf_P(_N("TMC_SET_CHOP_%c %hhd %hhd %hhd %hhd\n"), "xyze"[axis], chop0, chop1, chop2, chop3); + //printf_P(_N("TMC_SET_CHOP_%c %d %d %d %d\n"), "xyze"[axis], chop0, chop1, chop2, chop3); } } } @@ -4459,7 +4459,7 @@ void process_commands() { uint8_t bl = (uint8_t)strtol(CMDBUFFER_CURRENT_STRING + 10, NULL, 10); st_backlash_x = bl; - printf_P(_N("st_backlash_x = %hhd\n"), st_backlash_x); + printf_P(_N("st_backlash_x = %d\n"), st_backlash_x); } #endif //BACKLASH_X #ifdef BACKLASH_Y @@ -4467,7 +4467,7 @@ void process_commands() { uint8_t bl = (uint8_t)strtol(CMDBUFFER_CURRENT_STRING + 10, NULL, 10); st_backlash_y = bl; - printf_P(_N("st_backlash_y = %hhd\n"), st_backlash_y); + printf_P(_N("st_backlash_y = %d\n"), st_backlash_y); } #endif //BACKLASH_Y #endif //TMC2130 diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp index 1d4e2b92d..0342c19de 100755 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -94,7 +94,7 @@ void cmdqueue_reset() { while (buflen) { - // printf_P(PSTR("dumping: \"%s\" of type %hu\n"), cmdbuffer+bufindr+CMDHDRSIZE, CMDBUFFER_CURRENT_TYPE); + // printf_P(PSTR("dumping: \"%s\" of type %u\n"), cmdbuffer+bufindr+CMDHDRSIZE, CMDBUFFER_CURRENT_TYPE); ClearToSend(); cmdqueue_pop_front(); } diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index ac7d202e4..3eab45383 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -188,7 +188,7 @@ void fsensor_init(void) { #ifdef PAT9125 uint8_t pat9125 = pat9125_init(); - printf_P(PSTR("PAT9125_init:%hhu\n"), pat9125); + printf_P(PSTR("PAT9125_init:%u\n"), pat9125); #endif //PAT9125 uint8_t fsensor_enabled = eeprom_read_byte((uint8_t*)EEPROM_FSENSOR); fsensor_autoload_enabled=eeprom_read_byte((uint8_t*)EEPROM_FSENS_AUTOLOAD_ENABLED); @@ -237,7 +237,7 @@ bool fsensor_enable(bool bUpdateEEPROM) if (mmu_enabled == false) { //filament sensor is pat9125, enable only if it is working uint8_t pat9125 = pat9125_init(); - printf_P(PSTR("PAT9125_init:%hhu\n"), pat9125); + printf_P(PSTR("PAT9125_init:%u\n"), pat9125); if (pat9125) fsensor_not_responding = false; else @@ -435,8 +435,8 @@ void fsensor_oq_meassure_stop(void) { if (!fsensor_enabled) return; if (!fsensor_oq_meassure_enabled) return; - printf_P(PSTR("fsensor_oq_meassure_stop, %hhu samples\n"), fsensor_oq_samples); - printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); + printf_P(PSTR("fsensor_oq_meassure_stop, %u samples\n"), fsensor_oq_samples); + printf_P(_N(" st_sum=%u yd_sum=%u er_sum=%u er_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max); printf_P(_N(" yd_min=%u yd_max=%u yd_avg=%u sh_avg=%u\n"), fsensor_oq_yd_min, fsensor_oq_yd_max, (uint16_t)((uint32_t)fsensor_oq_yd_sum * fsensor_chunk_len / fsensor_oq_st_sum), (uint16_t)(fsensor_oq_sh_sum / fsensor_oq_samples)); fsensor_oq_meassure = false; } @@ -453,10 +453,10 @@ bool fsensor_oq_result(void) bool res_er_sum = (fsensor_oq_er_sum <= FSENSOR_OQ_MAX_ES); printf_P(_N(" er_sum = %u %S\n"), fsensor_oq_er_sum, (res_er_sum?_OK:_NG)); bool res_er_max = (fsensor_oq_er_max <= FSENSOR_OQ_MAX_EM); - printf_P(_N(" er_max = %hhu %S\n"), fsensor_oq_er_max, (res_er_max?_OK:_NG)); + printf_P(_N(" er_max = %u %S\n"), fsensor_oq_er_max, (res_er_max?_OK:_NG)); uint8_t yd_avg = ((uint32_t)fsensor_oq_yd_sum * fsensor_chunk_len / fsensor_oq_st_sum); bool res_yd_avg = (yd_avg >= FSENSOR_OQ_MIN_YD) && (yd_avg <= FSENSOR_OQ_MAX_YD); - printf_P(_N(" yd_avg = %hhu %S\n"), yd_avg, (res_yd_avg?_OK:_NG)); + printf_P(_N(" yd_avg = %u %S\n"), yd_avg, (res_yd_avg?_OK:_NG)); bool res_yd_max = (fsensor_oq_yd_max <= (yd_avg * FSENSOR_OQ_MAX_PD)); printf_P(_N(" yd_max = %u %S\n"), fsensor_oq_yd_max, (res_yd_max?_OK:_NG)); bool res_yd_min = (fsensor_oq_yd_min >= (yd_avg / FSENSOR_OQ_MAX_ND)); @@ -472,7 +472,7 @@ bool fsensor_oq_result(void) bool res_sh_avg = (sh_avg <= FSENSOR_OQ_MAX_SH); if (yd_qua >= 8) res_sh_avg = true; - printf_P(_N(" sh_avg = %hhu %S\n"), sh_avg, (res_sh_avg?_OK:_NG)); + printf_P(_N(" sh_avg = %u %S\n"), sh_avg, (res_sh_avg?_OK:_NG)); bool res = res_er_sum && res_er_max && res_yd_avg && res_yd_max && res_yd_min && res_sh_avg; printf_P(_N("fsensor_oq_result %S\n"), (res?_OK:_NG)); return res; @@ -559,8 +559,8 @@ FORCE_INLINE static void fsensor_isr(int st_cnt) #ifdef DEBUG_FSENSOR_LOG if (fsensor_log) { - printf_P(_N("FSENSOR cnt=%d dy=%d err=%hhu %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK")); - if (fsensor_oq_meassure) printf_P(_N("FSENSOR st_sum=%u yd_sum=%u er_sum=%u er_max=%hhu yd_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max, fsensor_oq_yd_max); + printf_P(_N("FSENSOR cnt=%d dy=%d err=%u %S\n"), st_cnt, pat9125_y, fsensor_err_cnt, (fsensor_err_cnt > old_err_cnt)?_N("NG!"):_N("OK")); + if (fsensor_oq_meassure) printf_P(_N("FSENSOR st_sum=%u yd_sum=%u er_sum=%u er_max=%u yd_max=%u\n"), fsensor_oq_st_sum, fsensor_oq_yd_sum, fsensor_oq_er_sum, fsensor_oq_er_max, fsensor_oq_yd_max); } #endif //DEBUG_FSENSOR_LOG diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 0d6ebe4c2..6526b1537 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -264,7 +264,7 @@ void mmu_loop(void) case S::GetFindaInit: if (mmu_rx_ok() > 0) { - fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer + fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer. MUST BE %hhu!!! mmu_last_finda_response.start(); FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda); puts_P(PSTR("MMU - ENABLED")); @@ -377,7 +377,7 @@ void mmu_loop(void) } if (mmu_rx_ok() > 0) { - fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer + fscanf_P(uart2io, PSTR("%hhu"), &mmu_finda); //scan finda from buffer. MUST BE %hhu!!! mmu_last_finda_response.start(); FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda); //printf_P(PSTR("Eact: %d\n"), int(e_active())); diff --git a/Firmware/pat9125.c b/Firmware/pat9125.c index ea22c015b..0cfce5684 100644 --- a/Firmware/pat9125.c +++ b/Firmware/pat9125.c @@ -188,8 +188,8 @@ uint8_t pat9125_init(void) pat9125_wr_reg(PAT9125_RES_X, PAT9125_XRES); pat9125_wr_reg(PAT9125_RES_Y, PAT9125_YRES); - fprintf_P(uartout, PSTR("PAT9125_RES_X=%hhu\n"), pat9125_rd_reg(PAT9125_RES_X)); - fprintf_P(uartout, PSTR("PAT9125_RES_Y=%hhu\n"), pat9125_rd_reg(PAT9125_RES_Y)); + fprintf_P(uartout, PSTR("PAT9125_RES_X=%u\n"), pat9125_rd_reg(PAT9125_RES_X)); + fprintf_P(uartout, PSTR("PAT9125_RES_Y=%u\n"), pat9125_rd_reg(PAT9125_RES_Y)); return 1; } diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 7560a084f..f4d114df2 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -471,8 +471,8 @@ void tmc2130_setup_chopper(uint8_t axis, uint8_t mres, uint8_t current_h, uint8_ intpol = 0; } #endif -// DBG(_n("tmc2130_setup_chopper(axis=%hhd, mres=%hhd, curh=%hhd, curr=%hhd\n"), axis, mres, current_h, current_r); -// DBG(_n(" toff=%hhd, hstr=%hhd, hend=%hhd, tbl=%hhd\n"), toff, hstrt, hend, tbl); +// DBG(_n("tmc2130_setup_chopper(axis=%d, mres=%d, curh=%d, curr=%d\n"), axis, mres, current_h, current_r); +// DBG(_n(" toff=%d, hstr=%d, hend=%d, tbl=%d\n"), toff, hstrt, hend, tbl); if (current_r <= 31) { tmc2130_wr_CHOPCONF(axis, toff, hstrt, hend, fd3, 0, rndtf, chm, tbl, 1, 0, 0, 0, mres, intpol, dedge, 0); @@ -511,7 +511,7 @@ void tmc2130_print_currents() void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl) { -// DBG(_n("tmc2130_set_pwm_ampl(axis=%hhd, pwm_ampl=%hhd\n"), axis, pwm_ampl); +// DBG(_n("tmc2130_set_pwm_ampl(axis=%d, pwm_ampl=%d\n"), axis, pwm_ampl); tmc2130_pwm_ampl[axis] = pwm_ampl; if (((axis == 0) || (axis == 1)) && (tmc2130_mode == TMC2130_MODE_SILENT)) tmc2130_wr_PWMCONF(axis, tmc2130_pwm_ampl[axis], tmc2130_pwm_grad[axis], tmc2130_pwm_freq[axis], tmc2130_pwm_auto[axis], 0, 0); @@ -519,7 +519,7 @@ void tmc2130_set_pwm_ampl(uint8_t axis, uint8_t pwm_ampl) void tmc2130_set_pwm_grad(uint8_t axis, uint8_t pwm_grad) { -// DBG(_n("tmc2130_set_pwm_grad(axis=%hhd, pwm_grad=%hhd\n"), axis, pwm_grad); +// DBG(_n("tmc2130_set_pwm_grad(axis=%d, pwm_grad=%d\n"), axis, pwm_grad); tmc2130_pwm_grad[axis] = pwm_grad; if (((axis == 0) || (axis == 1)) && (tmc2130_mode == TMC2130_MODE_SILENT)) tmc2130_wr_PWMCONF(axis, tmc2130_pwm_ampl[axis], tmc2130_pwm_grad[axis], tmc2130_pwm_freq[axis], tmc2130_pwm_auto[axis], 0, 0); @@ -893,7 +893,7 @@ void tmc2130_set_wave(uint8_t axis, uint8_t amp, uint8_t fac1000) { // TMC2130 wave compression algorithm // optimized for minimal memory requirements -// printf_P(PSTR("tmc2130_set_wave %hhd %hhd\n"), axis, fac1000); +// printf_P(PSTR("tmc2130_set_wave %d %d\n"), axis, fac1000); if (fac1000 < TMC2130_WAVE_FAC1000_MIN) fac1000 = 0; if (fac1000 > TMC2130_WAVE_FAC1000_MAX) fac1000 = TMC2130_WAVE_FAC1000_MAX; float fac = 0; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 84f90512e..d80102e94 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -469,7 +469,7 @@ void lcdui_print_percent_done(void) return; //do not also print the percentage } } - sprintf_P(per, num?_N("%3hhd"):_N("---"), calc_percent_done()); + sprintf_P(per, num?_N("%3d"):_N("---"), calc_percent_done()); lcd_printf_P(_N("%3S%3s%%"), src, per); } @@ -2703,7 +2703,7 @@ void lcd_menu_statistics() "%S:\n" "%18.2fm \n" "%S:\n" - "%10ldh %02hhdm %02hhds" + "%10ldh %02dm %02ds" ), _i("Filament used"), _met, ////MSG_FILAMENT_USED c=19 _i("Print time"), _h, _m, _s); ////MSG_PRINT_TIME c=19 @@ -2725,7 +2725,7 @@ void lcd_menu_statistics() "%S:\n" "%18.2fm \n" "%S:\n" - "%10ldd %02hhdh %02hhdm" + "%10ldd %02dh %02dm" ), _i("Total filament"), _filament_m, ////MSG_TOTAL_FILAMENT c=19 _i("Total print time"), _days, _hours, _minutes); ////MSG_TOTAL_PRINT_TIME c=19 From f25bddce355a94a11e03c911bce29755583a91d4 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 2 Feb 2022 21:06:58 +0100 Subject: [PATCH 70/83] Simplify GETPC() --- Firmware/Dcodes.cpp | 2 +- Firmware/asm.h | 21 +++++++++------------ Firmware/xflash_dump.cpp | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Firmware/Dcodes.cpp b/Firmware/Dcodes.cpp index d99a2c890..4a51b4d74 100644 --- a/Firmware/Dcodes.cpp +++ b/Firmware/Dcodes.cpp @@ -990,7 +990,7 @@ void __attribute__((noinline)) serial_dump_and_reset(dump_crash_reason reason) // sample SP/PC sp = SP; - GETPC(&pc); + pc = GETPC(); // extend WDT long enough to allow writing the entire stream wdt_enable(WDTO_8S); diff --git a/Firmware/asm.h b/Firmware/asm.h index 2ffb88ad9..0c3d74572 100644 --- a/Firmware/asm.h +++ b/Firmware/asm.h @@ -1,24 +1,21 @@ #pragma once #include +#include "macros.h" #ifdef __AVR_ATmega2560__ // return the current PC (on AVRs with 22bit PC) -static inline void GETPC(uint32_t* v) +FORCE_INLINE __uint24 GETPC(void) { - uint8_t a, b, c; - asm - ( + __uint24 ret; + asm ( "rcall .\n" - "pop %2\n" - "pop %1\n" - "pop %0\n" - : "=r" (a), "=r" (b), "=r" (c) + "pop %A0\n" + "pop %B0\n" + "pop %C0\n" + : "=&r" (ret) ); - ((uint8_t*)v)[0] = a; - ((uint8_t*)v)[1] = b; - ((uint8_t*)v)[2] = c; - ((uint8_t*)v)[3] = 0; + return ret; } #endif diff --git a/Firmware/xflash_dump.cpp b/Firmware/xflash_dump.cpp index e69c1d3a0..4caba11b6 100644 --- a/Firmware/xflash_dump.cpp +++ b/Firmware/xflash_dump.cpp @@ -59,7 +59,7 @@ static void __attribute__((noinline)) xfdump_dump_core(dump_header_t& hdr, uint3 // sample SP/PC hdr.sp = SP; - GETPC(&hdr.pc); + hdr.pc = GETPC(); // write header static_assert(sizeof(hdr) <= 256, "header is larger than a single page write"); From 43bf33e791d55a90db064dfb7fa531bfad9c9be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Wed, 2 Feb 2022 20:48:36 +0000 Subject: [PATCH 71/83] Optimise usage of code_value() code_value() is float but in some cases we can save memory when the expected output is only 1 or 2 bytes. Changes save 182 bytes of flash memory on my end. --- Firmware/Marlin_main.cpp | 71 ++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 5b6c31717..684f1f224 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4319,11 +4319,11 @@ void process_commands() codenum = 0; bool hasP = false, hasS = false; if (code_seen('P')) { - codenum = code_value(); // milliseconds to wait + codenum = code_value_long(); // milliseconds to wait hasP = codenum > 0; } if (code_seen('S')) { - codenum = code_value() * 1000; // seconds to wait + codenum = code_value_long() * 1000; // seconds to wait hasS = codenum > 0; } starpos = strchr(src, '*'); @@ -4679,7 +4679,7 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF); // } else if(code_seen('G')) { - gcode_in_progress = (int)code_value(); + gcode_in_progress = code_value_short(); // printf_P(_N("BEGIN G-CODE=%u\n"), gcode_in_progress); switch (gcode_in_progress) { @@ -5827,7 +5827,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } else { - mcode_in_progress = (int)code_value(); + mcode_in_progress = code_value_short(); // printf_P(_N("BEGIN M-CODE=%u\n"), mcode_in_progress); switch(mcode_in_progress) @@ -6096,7 +6096,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) uint8_t pin_status = code_value_uint8(); int8_t pin_number = LED_PIN; if (code_seen('P')) - pin_number = code_value(); + pin_number = code_value_uint8(); for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(*sensitive_pins)); i++) { if ((int8_t)pgm_read_byte(&sensitive_pins[i]) == pin_number) @@ -6511,9 +6511,9 @@ Sigma_Exit: */ case 73: //M73 show percent done, time remaining and time to change/pause { - if(code_seen('P')) print_percent_done_normal = code_value(); + if(code_seen('P')) print_percent_done_normal = code_value_uint8(); if(code_seen('R')) print_time_remaining_normal = code_value(); - if(code_seen('Q')) print_percent_done_silent = code_value(); + if(code_seen('Q')) print_percent_done_silent = code_value_uint8(); if(code_seen('S')) print_time_remaining_silent = code_value(); if(code_seen('C')){ float print_time_to_change_normal_f = code_value_float(); @@ -6633,7 +6633,7 @@ Sigma_Exit: autoReportFeatures.SetPeriod( code_value_uint8() ); } if (code_seen('C')){ - autoReportFeatures.SetMask(code_value()); + autoReportFeatures.SetMask(code_value_uint8()); } else{ autoReportFeatures.SetMask(1); //Backwards compability to host systems like Octoprint to send only temp if paramerter `C`isn't used. } @@ -6784,10 +6784,10 @@ Sigma_Exit: */ case 106: // M106 Sxxx Fan On S 0 .. 255 if (code_seen('S')){ - fanSpeed=constrain(code_value(),0,255); + fanSpeed = code_value_uint8(); } else { - fanSpeed=255; + fanSpeed = 255; } break; @@ -7017,7 +7017,7 @@ Sigma_Exit: */ case 113: if (code_seen('S')) { - host_keepalive_interval = (uint8_t)code_value_short(); + host_keepalive_interval = code_value_uint8(); // NOMORE(host_keepalive_interval, 60); } else { @@ -7243,7 +7243,7 @@ Sigma_Exit: uint8_t extruder = active_extruder; if(code_seen('T')) { - extruder = code_value(); + extruder = code_value_uint8(); if(extruder >= EXTRUDERS) { SERIAL_ECHO_START; SERIAL_ECHO(_n("M200 Invalid extruder "));////MSG_M200_INVALID_EXTRUDER @@ -7251,14 +7251,14 @@ Sigma_Exit: } } if(code_seen('D')) { - float diameter = (float)code_value(); + float diameter = code_value(); if (diameter == 0.0) { // setting any extruder filament size disables volumetric on the assumption that // slicers either generate in extruder values as cubic mm or as as filament feeds // for all extruders cs.volumetric_enabled = false; } else { - cs.filament_size[extruder] = (float)code_value(); + cs.filament_size[extruder] = code_value(); // make sure all extruders have some sane value for the filament size cs.filament_size[0] = (cs.filament_size[0] == 0.0 ? DEFAULT_NOMINAL_FILAMENT_DIA : cs.filament_size[0]); #if EXTRUDERS > 1 @@ -7506,8 +7506,7 @@ Sigma_Exit: { if(code_seen('S')) { - int t= code_value() ; - switch(t) + switch(code_value_uint8()) { case 0: { @@ -7604,7 +7603,7 @@ Sigma_Exit: } if (code_seen('S')) { - feedmultiply = code_value(); + feedmultiply = code_value_short(); codesWereSeen = true; } if (code_seen('R')) //restore previous feedmultiply @@ -7633,7 +7632,7 @@ Sigma_Exit: { if (code_seen('S')) { - int tmp_code = code_value(); + int tmp_code = code_value_short(); if (code_seen('T')) { uint8_t extruder; @@ -7668,10 +7667,10 @@ Sigma_Exit: case 226: // M226 P S- Wait until the specified pin reaches the state required { if(code_seen('P')){ - int pin_number = code_value(); // pin number + int pin_number = code_value_short(); // pin number int pin_state = -1; // required pin state - default is inverted - if(code_seen('S')) pin_state = code_value(); // required pin state + if(code_seen('S')) pin_state = code_value_short(); // required pin state if(pin_state >= -1 && pin_state <= 1){ @@ -7949,13 +7948,13 @@ Sigma_Exit: case 303: { float temp = 150.0; - int e=0; - int c=5; - if (code_seen('E')) e=code_value(); - if (e<0) - temp=70; - if (code_seen('S')) temp=code_value(); - if (code_seen('C')) c=code_value(); + int e = 0; + int c = 5; + if (code_seen('E')) e = code_value_short(); + if (e < 0) + temp = 70; + if (code_seen('S')) temp = code_value(); + if (code_seen('C')) c = code_value_short(); PID_autotune(temp, e, c); } break; @@ -7992,8 +7991,8 @@ Sigma_Exit: { uint8_t extruder = 255; uint8_t filament = FILAMENT_UNDEFINED; - if(code_seen('E')) extruder = code_value(); - if(code_seen('F')) filament = code_value(); + if(code_seen('E')) extruder = code_value_uint8(); + if(code_seen('F')) filament = code_value_uint8(); mmu_set_filament_type(extruder, filament); } } @@ -8293,7 +8292,7 @@ Sigma_Exit: int set_target_pinda = 0; if (code_seen('S')) { - set_target_pinda = code_value(); + set_target_pinda = code_value_short(); } else { break; @@ -8386,9 +8385,9 @@ Sigma_Exit: SERIAL_PROTOCOLLN("zerorized"); } else if (code_seen('S')) { // Sxxx Iyyy - Set compensation ustep value S for compensation table index I - int16_t usteps = code_value(); + int16_t usteps = code_value_short(); if (code_seen('I')) { - uint8_t index = code_value(); + uint8_t index = code_value_uint8(); if (index < 5) { EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + index * 2, &usteps); SERIAL_PROTOCOLLN("OK"); @@ -8874,7 +8873,7 @@ Sigma_Exit: case 701: { if (mmu_enabled && code_seen('E')) - tmp_extruder = code_value(); + tmp_extruder = code_value_uint8(); gcode_M701(); } break; @@ -9131,7 +9130,7 @@ Sigma_Exit: */ else if (code_seen('D')) // D codes (debug) { - switch((int)code_value()) + switch(code_value_short()) { /*! @@ -9599,7 +9598,7 @@ void get_coordinates() if(code_seen(axis_codes[i])) { bool relative = axis_relative_modes & (1 << i); - destination[i] = (float)code_value(); + destination[i] = code_value(); if (i == E_AXIS) { float emult = extruder_multiplier[active_extruder]; if (emult != 1.) { @@ -10310,7 +10309,7 @@ bool setTargetedHotend(int code, uint8_t &extruder) { extruder = active_extruder; if(code_seen('T')) { - extruder = code_value(); + extruder = code_value_uint8(); if(extruder >= EXTRUDERS) { SERIAL_ECHO_START; switch(code){ From 858984ef354df58817cf7b84a22337a4aac03fea Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Fri, 4 Feb 2022 10:47:56 +0100 Subject: [PATCH 72/83] SD sorting entries instead of positions --- Firmware/cardreader.cpp | 28 ++++++++++++++-------------- Firmware/cardreader.h | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index 62e519a5d..708f4b02f 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -689,11 +689,11 @@ void CardReader::getfilename(uint16_t nr, const char * const match/*=NULL*/) } -void CardReader::getfilename_simple(uint32_t position, const char * const match/*=NULL*/) +void CardReader::getfilename_simple(uint16_t entry, const char * const match/*=NULL*/) { curDir = &workDir; nrFiles = 0; - curDir->seekSet(position); + curDir->seekSet((uint32_t)entry << 5); lsDive("", *curDir, match, LS_GetFilename); } @@ -775,7 +775,7 @@ void CardReader::updir() */ void CardReader::getfilename_sorted(const uint16_t nr, uint8_t sdSort) { if (nr < sort_count) - getfilename_simple(sort_positions[(sdSort == SD_SORT_ALPHA) ? (sort_count - nr - 1) : nr]); + getfilename_simple(sort_entries[(sdSort == SD_SORT_ALPHA) ? (sort_count - nr - 1) : nr]); else getfilename(nr); } @@ -832,7 +832,7 @@ void CardReader::presort() { else getfilename_next(position); sort_order[i] = i; - sort_positions[i] = position; + sort_entries[i] = position >> 5; #if HAS_FOLDER_SORTING if (filenameIsDir) dirCnt++; #endif @@ -882,7 +882,7 @@ void CardReader::presort() { manage_heater(); uint8_t orderBckp = sort_order[i]; - getfilename_simple(sort_positions[orderBckp]); + getfilename_simple(sort_entries[orderBckp]); strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it) crmod_date_bckp = crmodDate; crmod_time_bckp = crmodTime; @@ -891,7 +891,7 @@ void CardReader::presort() { #endif uint16_t j = i; - getfilename_simple(sort_positions[sort_order[j - gap]]); + getfilename_simple(sort_entries[sort_order[j - gap]]); char *name2 = LONGEST_FILENAME; // use the string in-place #if HAS_FOLDER_SORTING while (j >= gap && ((sdSort == SD_SORT_TIME)?_SORT_CMP_TIME_DIR(FOLDER_SORTING):_SORT_CMP_DIR(FOLDER_SORTING))) @@ -909,7 +909,7 @@ void CardReader::presort() { printf_P(PSTR("i%2d j%2d gap%2d orderBckp%2d\n"), i, j, gap, orderBckp); #endif if (j < gap) break; - getfilename_simple(sort_positions[sort_order[j - gap]]); + getfilename_simple(sort_entries[sort_order[j - gap]]); name2 = LONGEST_FILENAME; // use the string in-place } sort_order[j] = orderBckp; @@ -950,14 +950,14 @@ void CardReader::presort() { const uint16_t o1 = sort_order[j], o2 = sort_order[j + 1]; counter++; - getfilename_simple(sort_positions[o1]); + getfilename_simple(sort_entries[o1]); strcpy(name1, LONGEST_FILENAME); // save (or getfilename below will trounce it) crmod_date_bckp = crmodDate; crmod_time_bckp = crmodTime; #if HAS_FOLDER_SORTING bool dir1 = filenameIsDir; #endif - getfilename_simple(sort_positions[o2]); + getfilename_simple(sort_entries[o2]); char *name2 = LONGEST_FILENAME; // use the string in-place // Sort the current pair according to settings. @@ -995,26 +995,26 @@ void CardReader::presort() { { if (sort_order_reverse_index[i] != i) { - uint32_t el = sort_positions[i]; + uint32_t el = sort_entries[i]; uint8_t idx = sort_order_reverse_index[i]; while (idx != i) { - uint32_t el1 = sort_positions[idx]; + uint32_t el1 = sort_entries[idx]; uint8_t idx1 = sort_order_reverse_index[idx]; sort_order_reverse_index[idx] = idx; - sort_positions[idx] = el; + sort_entries[idx] = el; idx = idx1; el = el1; } sort_order_reverse_index[idx] = idx; - sort_positions[idx] = el; + sort_entries[idx] = el; } } menu_progressbar_finish(); } else { getfilename(0); - sort_positions[0] = position; + sort_entries[0] = position >> 5; } sort_count = fileCnt; diff --git a/Firmware/cardreader.h b/Firmware/cardreader.h index ea6e25b44..164529071 100644 --- a/Firmware/cardreader.h +++ b/Firmware/cardreader.h @@ -46,7 +46,7 @@ public: void printingHasFinished(); void getfilename(uint16_t nr, const char* const match=NULL); - void getfilename_simple(uint32_t position, const char * const match = NULL); + void getfilename_simple(uint16_t entry, const char * const match = NULL); void getfilename_next(uint32_t position, const char * const match = NULL); uint16_t getnrfilenames(); @@ -111,7 +111,7 @@ private: // Sort files and folders alphabetically. #ifdef SDCARD_SORT_ALPHA uint16_t sort_count; // Count of sorted items in the current directory - uint32_t sort_positions[SDSORT_LIMIT]; + uint16_t sort_entries[SDSORT_LIMIT]; #endif // SDCARD_SORT_ALPHA From 21a0b5364703f84aa970d23bbc7eaf4d9bb19ceb Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Fri, 4 Feb 2022 13:27:43 +0100 Subject: [PATCH 73/83] remove firstrun --- Firmware/eeprom.cpp | 5 +++++ Firmware/ultralcd.cpp | 17 +---------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/Firmware/eeprom.cpp b/Firmware/eeprom.cpp index ab904260a..03e02475f 100644 --- a/Firmware/eeprom.cpp +++ b/Firmware/eeprom.cpp @@ -100,6 +100,11 @@ if (eeprom_read_byte((uint8_t*)EEPROM_PINDA_TEMP_COMPENSATION) == 0xff) eeprom_u if (eeprom_read_dword((uint32_t*)EEPROM_JOB_ID) == EEPROM_EMPTY_VALUE32) eeprom_update_dword((uint32_t*)EEPROM_JOB_ID, 0); + + if (eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 1) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 2) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 3) == 255) { + eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0); + eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0); + } } //! @brief Get default sheet name for index diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index d80102e94..57139b5bb 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -98,7 +98,6 @@ static float manual_feedrate[] = MANUAL_FEEDRATE; uint8_t lcd_status_message_level; char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME! -unsigned char firstrun = 1; static uint8_t lay1cal_filament = 0; @@ -772,21 +771,6 @@ void lcdui_print_status_screen(void) // Main status screen. It's up to the implementation specific part to show what is needed. As this is very display dependent void lcd_status_screen() // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") { - if (firstrun == 1) - { - firstrun = 0; - if(lcd_status_message_level == 0) - { - strncpy_P(lcd_status_message, _T(WELCOME_MSG), LCD_WIDTH); - lcd_finishstatus(); - } - if (eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 1) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 2) == 255 && eeprom_read_byte((uint8_t *)EEPROM_TOTALTIME + 3) == 255) - { - eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0); - eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0); - } - } - #ifdef ULTIPANEL_FEEDMULTIPLY // Dead zone at 100% feedrate if ((feedmultiply < 100 && (feedmultiply + int(lcd_encoder)) > 100) || @@ -8588,6 +8572,7 @@ void ultralcd_init() lcd_oldcardstatus = IS_SD_INSERTED; #endif//(SDCARDDETECT > 0) lcd_encoder_diff = 0; + lcd_setstatuspgm(_T(WELCOME_MSG)); } From f068c3258f477a114d4b59ad36f83f6ae4f023c7 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Fri, 4 Feb 2022 15:24:24 +0100 Subject: [PATCH 74/83] Pack endstop flags --- Firmware/stepper.cpp | 134 +++++++++++++++++-------------------------- Firmware/stepper.h | 4 -- 2 files changed, 54 insertions(+), 84 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index dddb9449d..a27c1f15b 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -108,12 +108,7 @@ static_assert(TMC2130_MINIMUM_DELAY 1, // this will fail to compile when non-emp //=============================public variables ============================ //=========================================================================== block_t *current_block; // A pointer to the block currently being traced -bool x_min_endstop = false; -bool x_max_endstop = false; -bool y_min_endstop = false; -bool y_max_endstop = false; -bool z_min_endstop = false; -bool z_max_endstop = false; + //=========================================================================== //=============================private variables ============================ //=========================================================================== @@ -134,9 +129,7 @@ static uint16_t OCR1A_nominal; static uint8_t step_loops_nominal; volatile long endstops_trigsteps[3]={0,0,0}; -static volatile bool endstop_x_hit=false; -static volatile bool endstop_y_hit=false; -static volatile bool endstop_z_hit=false; +static volatile uint8_t endstop_hit = 0; #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED bool abort_on_endstop_hit = false; #endif @@ -146,17 +139,8 @@ bool abort_on_endstop_hit = false; int motor_current_setting_loud[3] = DEFAULT_PWM_MOTOR_CURRENT_LOUD; #endif -#if ( (defined(X_MAX_PIN) && (X_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMAXLIMIT) -static bool old_x_max_endstop=false; -#endif -#if ( (defined(Y_MAX_PIN) && (Y_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMAXLIMIT) -static bool old_y_max_endstop=false; -#endif - -static bool old_x_min_endstop=false; -static bool old_y_min_endstop=false; -static bool old_z_min_endstop=false; -static bool old_z_max_endstop=false; +static uint8_t endstop = 0; +static uint8_t old_endstop = 0; static bool check_endstops = true; @@ -205,25 +189,23 @@ extern uint16_t stepper_timer_overflow_last; void checkHitEndstops() { - if( endstop_x_hit || endstop_y_hit || endstop_z_hit) { + if( endstop_hit) { SERIAL_ECHO_START; SERIAL_ECHORPGM(MSG_ENDSTOPS_HIT); - if(endstop_x_hit) { + if(endstop_hit & _BV(X_AXIS)) { SERIAL_ECHOPAIR(" X:",(float)endstops_trigsteps[X_AXIS]/cs.axis_steps_per_unit[X_AXIS]); // LCD_MESSAGERPGM(CAT2((MSG_ENDSTOPS_HIT), PSTR("X"))); } - if(endstop_y_hit) { + if(endstop_hit & _BV(Y_AXIS)) { SERIAL_ECHOPAIR(" Y:",(float)endstops_trigsteps[Y_AXIS]/cs.axis_steps_per_unit[Y_AXIS]); // LCD_MESSAGERPGM(CAT2((MSG_ENDSTOPS_HIT), PSTR("Y"))); } - if(endstop_z_hit) { + if(endstop_hit & _BV(Z_AXIS)) { SERIAL_ECHOPAIR(" Z:",(float)endstops_trigsteps[Z_AXIS]/cs.axis_steps_per_unit[Z_AXIS]); // LCD_MESSAGERPGM(CAT2((MSG_ENDSTOPS_HIT),PSTR("Z"))); } SERIAL_ECHOLN(""); - endstop_x_hit=false; - endstop_y_hit=false; - endstop_z_hit=false; + endstop_hit = 0; #if defined(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && defined(SDSUPPORT) if (abort_on_endstop_hit) { @@ -240,17 +222,15 @@ void checkHitEndstops() bool endstops_hit_on_purpose() { - bool hit = endstop_x_hit || endstop_y_hit || endstop_z_hit; - endstop_x_hit=false; - endstop_y_hit=false; - endstop_z_hit=false; - return hit; + uint8_t old = endstop_hit; + endstop_hit = 0; + return old; } bool endstop_z_hit_on_purpose() { - bool hit = endstop_z_hit; - endstop_z_hit=false; + bool hit = endstop_hit & _BV(Z_AXIS); + endstop_hit &= ~_BV(Z_AXIS); return hit; } @@ -265,7 +245,7 @@ bool enable_z_endstop(bool check) { bool old = check_z_endstop; check_z_endstop = check; - endstop_z_hit = false; + endstop_hit &= ~_BV(Z_AXIS); return old; } @@ -509,33 +489,31 @@ FORCE_INLINE void stepper_check_endstops() #if ( (defined(X_MIN_PIN) && (X_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMINLIMIT) #ifdef TMC2130_SG_HOMING // Stall guard homing turned on - x_min_endstop = (READ(X_TMC2130_DIAG) != 0); + SET_BIT_TO(endstop, X_AXIS, (READ(X_TMC2130_DIAG) != 0)); #else // Normal homing - x_min_endstop = (READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING); + SET_BIT_TO(endstop, X_AXIS, (READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING)); #endif - if(x_min_endstop && old_x_min_endstop && (current_block->steps_x.wide > 0)) { + if((endstop & old_endstop & _BV(X_AXIS)) && (current_block->steps_x.wide > 0)) { endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; - endstop_x_hit=true; + endstop_hit |= _BV(X_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } - old_x_min_endstop = x_min_endstop; #endif } else { // +direction #if ( (defined(X_MAX_PIN) && (X_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMAXLIMIT) #ifdef TMC2130_SG_HOMING // Stall guard homing turned on - x_max_endstop = (READ(X_TMC2130_DIAG) != 0); + SET_BIT_TO(endstop, X_AXIS + 4, (READ(X_TMC2130_DIAG) != 0)); #else // Normal homing - x_max_endstop = (READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING); + SET_BIT_TO(endstop, X_AXIS + 4, (READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING)); #endif - if(x_max_endstop && old_x_max_endstop && (current_block->steps_x.wide > 0)){ + if((endstop & old_endstop & _BV(X_AXIS + 4)) && (current_block->steps_x.wide > 0)){ endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; - endstop_x_hit=true; + endstop_hit |= _BV(X_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } - old_x_max_endstop = x_max_endstop; #endif } @@ -544,37 +522,35 @@ FORCE_INLINE void stepper_check_endstops() #else if ((((out_bits & (1< -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMINLIMIT) #ifdef TMC2130_SG_HOMING // Stall guard homing turned on - y_min_endstop = (READ(Y_TMC2130_DIAG) != 0); + SET_BIT_TO(endstop, Y_AXIS, (READ(Y_TMC2130_DIAG) != 0)); #else // Normal homing - y_min_endstop = (READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING); + SET_BIT_TO(endstop, Y_AXIS, (READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING)); #endif - if(y_min_endstop && old_y_min_endstop && (current_block->steps_y.wide > 0)) { + if((endstop & old_endstop & _BV(Y_AXIS)) && (current_block->steps_y.wide > 0)) { endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; - endstop_y_hit=true; + endstop_hit |= _BV(Y_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } - old_y_min_endstop = y_min_endstop; #endif } else { // +direction #if ( (defined(Y_MAX_PIN) && (Y_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMAXLIMIT) #ifdef TMC2130_SG_HOMING // Stall guard homing turned on - y_max_endstop = (READ(Y_TMC2130_DIAG) != 0); + SET_BIT_TO(endstop, Y_AXIS + 4, (READ(Y_TMC2130_DIAG) != 0)); #else // Normal homing - y_max_endstop = (READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING); + SET_BIT_TO(endstop, Y_AXIS + 4, (READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING)); #endif - if(y_max_endstop && old_y_max_endstop && (current_block->steps_y.wide > 0)){ + if((endstop & old_endstop & _BV(Y_AXIS + 4)) && (current_block->steps_y.wide > 0)){ endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; - endstop_y_hit=true; + endstop_hit |= _BV(Y_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } - old_y_max_endstop = y_max_endstop; #endif } @@ -585,20 +561,19 @@ FORCE_INLINE void stepper_check_endstops() #ifdef TMC2130_SG_HOMING // Stall guard homing turned on #ifdef TMC2130_STEALTH_Z - if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) - z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); - else + if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) + SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); + else #endif //TMC2130_STEALTH_Z - z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0); + SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0)); #else - z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); + SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); #endif //TMC2130_SG_HOMING - if(z_min_endstop && old_z_min_endstop && (current_block->steps_z.wide > 0)) { + if((endstop & old_endstop & _BV(Z_AXIS)) && (current_block->steps_z.wide > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_z_hit=true; + endstop_hit |= _BV(Z_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } - old_z_min_endstop = z_min_endstop; } #endif } else { // +direction @@ -606,20 +581,19 @@ FORCE_INLINE void stepper_check_endstops() #ifdef TMC2130_SG_HOMING // Stall guard homing turned on #ifdef TMC2130_STEALTH_Z - if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) - z_max_endstop = false; - else + if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) + SET_BIT_TO(endstop, Z_AXIS + 4, 0); + else #endif //TMC2130_STEALTH_Z - z_max_endstop = (READ(Z_TMC2130_DIAG) != 0); + SET_BIT_TO(endstop, Z_AXIS + 4, (READ(Z_TMC2130_DIAG) != 0)); #else - z_max_endstop = (READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING); + SET_BIT_TO(endstop, Z_AXIS + 4, (READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING)); #endif //TMC2130_SG_HOMING - if(z_max_endstop && old_z_max_endstop && (current_block->steps_z.wide > 0)) { + if((endstop & old_endstop & _BV(Z_AXIS + 4)) && (current_block->steps_z.wide > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_z_hit=true; + endstop_hit |= _BV(Z_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } - old_z_max_endstop = z_max_endstop; #endif } } @@ -632,22 +606,22 @@ FORCE_INLINE void stepper_check_endstops() #ifdef TMC2130_SG_HOMING // Stall guard homing turned on #ifdef TMC2130_STEALTH_Z - if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) - z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); - else + if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) + SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); + else #endif //TMC2130_STEALTH_Z - z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0); + SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0)); #else - z_min_endstop = (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING); + SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); #endif //TMC2130_SG_HOMING - if(z_min_endstop && old_z_min_endstop) { + if(endstop & old_endstop & _BV(Z_AXIS)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_z_hit=true; + endstop_hit |= _BV(Z_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } - old_z_min_endstop = z_min_endstop; } #endif + old_endstop = endstop; } diff --git a/Firmware/stepper.h b/Firmware/stepper.h index 84773913c..3b9fb8c24 100644 --- a/Firmware/stepper.h +++ b/Firmware/stepper.h @@ -70,10 +70,6 @@ void invert_z_endstop(bool endstop_invert); void checkStepperErrors(); //Print errors detected by the stepper extern block_t *current_block; // A pointer to the block currently being traced -extern bool x_min_endstop; -extern bool x_max_endstop; -extern bool y_min_endstop; -extern bool y_max_endstop; extern volatile long count_position[NUM_AXIS]; void quickStop(); From d06e74dd6f31e1ce986ba2f73d69494989f0f0f4 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sat, 5 Feb 2022 23:44:24 +0100 Subject: [PATCH 75/83] Fix Welcome message and language flashing --- Firmware/Marlin_main.cpp | 16 ++++++++-------- Firmware/messages.c | 2 +- Firmware/messages.h | 4 +++- Firmware/mmu.cpp | 2 +- Firmware/ultralcd.cpp | 22 ++++++++++------------ 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 4e8812cae..8afdf0ac8 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1677,7 +1677,7 @@ void setup() eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0); lcd_update_enable(true); lcd_update(2); - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); } */ manage_heater(); // Update temperatures @@ -1699,7 +1699,7 @@ void setup() eeprom_update_byte((uint8_t*)EEPROM_UVLO, 0); lcd_update_enable(true); lcd_update(2); - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); } } } @@ -3445,7 +3445,7 @@ static void gcode_G80() } KEEPALIVE_STATE(NOT_BUSY); // Restore custom message state - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); custom_message_type = custom_message_type_old; custom_message_state = custom_message_state_old; lcd_update(2); @@ -3848,7 +3848,7 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float fsensor_check_autoload(); #endif //IR_SENSOR - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); custom_message_type = CustomMsg::Status; } @@ -3894,7 +3894,7 @@ void gcode_M701() } lcd_update_enable(true); lcd_update(2); - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); disable_z(); loading_flag = false; custom_message_type = CustomMsg::Status; @@ -4361,7 +4361,7 @@ void process_commands() if (IS_SD_PRINTING) custom_message_type = CustomMsg::Status; else - LCD_MESSAGERPGM(_T(WELCOME_MSG)); + LCD_MESSAGERPGM(MSG_WELCOME); } #ifdef TMC2130 @@ -6818,7 +6818,7 @@ Sigma_Exit: #endif powersupply = true; - LCD_MESSAGERPGM(_T(WELCOME_MSG)); + LCD_MESSAGERPGM(MSG_WELCOME); lcd_update(0); break; @@ -11877,7 +11877,7 @@ void restore_print_from_ram_and_continue(float e_move) //not sd printing nor usb printing } - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); saved_printing_type = PRINTING_TYPE_NONE; saved_printing = false; waiting_inside_plan_buffer_line_print_aborted = true; //unroll the stack diff --git a/Firmware/messages.c b/Firmware/messages.c index 486d78ccd..311efa07a 100644 --- a/Firmware/messages.c +++ b/Firmware/messages.c @@ -170,7 +170,7 @@ const char MSG_AUTO_DEPLETE[] PROGMEM_N1 = ISTR("SpoolJoin"); ////c=13 const char MSG_FIRMWARE[] PROGMEM_N1 = ISTR("Firmware"); ////c=8 const char MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY[] PROGMEM_N1 = ISTR("FlashAir"); ////c=8 const char MSG_PINDA[] PROGMEM_N1 = ISTR("PINDA");////c=5 -const char WELCOME_MSG[] PROGMEM_N1 = ISTR(CUSTOM_MENDEL_NAME " OK."); ////c=20 +const char MSG_WELCOME[] PROGMEM_N1 = WELCOME_MSG; ////c=20 const char MSG_SD_WORKDIR_FAIL[] PROGMEM_N1 = "workDir open failed"; //// const char MSG_BROWNOUT_RESET[] PROGMEM_N1 = " Brown out Reset"; //// const char MSG_EXTERNAL_RESET[] PROGMEM_N1 = " External Reset"; //// diff --git a/Firmware/messages.h b/Firmware/messages.h index e12a4d187..fd9ef1800 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -7,6 +7,8 @@ extern "C" { #endif //defined(__cplusplus) +#define WELCOME_MSG (CUSTOM_MENDEL_NAME " OK.") + // LCD Menu Messages //internationalized messages extern const char MSG_AUTO_HOME[]; @@ -123,7 +125,7 @@ extern const char MSG_WIZARD_WELCOME[]; extern const char MSG_WIZARD_WELCOME_SHIPPING[]; extern const char MSG_YES[]; extern const char MSG_V2_CALIBRATION[]; -extern const char WELCOME_MSG[]; +extern const char MSG_WELCOME[]; extern const char MSG_OFF[]; extern const char MSG_ON[]; extern const char MSG_NA[]; diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 6526b1537..ef8d49edd 100755 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -1366,7 +1366,7 @@ void lcd_mmu_load_to_nozzle(uint8_t filament_nr) lcd_return_to_status(); lcd_update_enable(true); lcd_load_filament_color_check(); - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); custom_message_type = CustomMsg::Status; } else diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 57139b5bb..f35e1ff9b 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -97,7 +97,7 @@ static float manual_feedrate[] = MANUAL_FEEDRATE; /* !Configuration settings */ uint8_t lcd_status_message_level; -char lcd_status_message[LCD_WIDTH + 1] = ""; //////WELCOME! +char lcd_status_message[LCD_WIDTH + 1] = WELCOME_MSG; static uint8_t lay1cal_filament = 0; @@ -642,8 +642,7 @@ void lcdui_print_status_line(void) } else { if (custom_message_state == 3) { - lcd_puts_P(_T(WELCOME_MSG)); - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); custom_message_type = CustomMsg::Status; } if (custom_message_state > 3 && custom_message_state <= 10 ) { @@ -1147,7 +1146,7 @@ void lcd_commands() if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty()) { - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); lcd_commands_step = 0; lcd_commands_type = 0; if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) { @@ -1236,7 +1235,7 @@ void lcd_commands() lcd_commands_step = 1; break; case 1: - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); lcd_commands_step = 0; lcd_commands_type = LcdCommands::Idle; if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) @@ -1330,7 +1329,7 @@ void lcd_commands() lcd_commands_step = 1; } if ((lcd_commands_step == 1) && display_time.expired(2000)) { //calibration finished message - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); custom_message_type = CustomMsg::Status; pid_temp = DEFAULT_PID_TEMP; lcd_commands_step = 0; @@ -5023,7 +5022,7 @@ void lcd_wizard(WizState state) msg = _T(MSG_WIZARD_DONE); lcd_reset_alert_level(); - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); lcd_return_to_status(); break; @@ -6290,7 +6289,7 @@ void unload_filament(bool automatic) lcd_update_enable(true); - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); custom_message_type = CustomMsg::Status; } @@ -7014,7 +7013,7 @@ void lcd_print_stop() finishAndDisableSteppers(); //M84 - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); custom_message_type = CustomMsg::Status; planner_abort_hard(); //needs to be done since plan_buffer_line resets waiting_inside_plan_buffer_line_print_aborted to false. Also copies current to destination. @@ -8479,7 +8478,7 @@ static bool check_file(const char* filename) { cmdqueue_serial_disabled = false; card.printingHasFinished(); - lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_setstatuspgm(MSG_WELCOME); lcd_finishstatus(); return result; } @@ -8572,7 +8571,6 @@ void ultralcd_init() lcd_oldcardstatus = IS_SD_INSERTED; #endif//(SDCARDDETECT > 0) lcd_encoder_diff = 0; - lcd_setstatuspgm(_T(WELCOME_MSG)); } @@ -8815,7 +8813,7 @@ void menu_lcd_lcdupdate_func(void) card.initsd(false); //delay the sorting to the sd menu. Otherwise, removing the SD card while sorting will not menu_back() card.presort_flag = true; //force sorting of the SD menu } - LCD_MESSAGERPGM(_T(WELCOME_MSG)); + LCD_MESSAGERPGM(MSG_WELCOME); bMain=false; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function menu_submenu(lcd_sdcard_menu); lcd_timeoutToStatus.start(); From 70cb30208cca68f1af7ec7ba04b2e1ad207a030c Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 6 Feb 2022 01:07:10 +0100 Subject: [PATCH 76/83] Also change MUL24x24R24 to the new format and fix rounding --- Firmware/speed_lookuptable.h | 105 +++++++++++++++++++---------------- Firmware/stepper.cpp | 5 +- 2 files changed, 59 insertions(+), 51 deletions(-) diff --git a/Firmware/speed_lookuptable.h b/Firmware/speed_lookuptable.h index 1d9048d3a..66b93c5ab 100644 --- a/Firmware/speed_lookuptable.h +++ b/Firmware/speed_lookuptable.h @@ -39,61 +39,70 @@ FORCE_INLINE uint16_t MUL8x16R8(uint8_t x, uint16_t y) { return out; } -// intRes = longIn1 * longIn2 >> 24 -// uses: -// r26 to store 0 -// r27 to store the byte 1 of the 48bit result -#define MultiU24X24toH16(intRes, longIn1, longIn2) \ -asm volatile ( \ -"clr r26 \n\t" \ -"mul %A1, %B2 \n\t" \ -"mov r27, r1 \n\t" \ -"mul %B1, %C2 \n\t" \ -"movw %A0, r0 \n\t" \ -"mul %C1, %C2 \n\t" \ -"add %B0, r0 \n\t" \ -"mul %C1, %B2 \n\t" \ -"add %A0, r0 \n\t" \ -"adc %B0, r1 \n\t" \ -"mul %A1, %C2 \n\t" \ -"add r27, r0 \n\t" \ -"adc %A0, r1 \n\t" \ -"adc %B0, r26 \n\t" \ -"mul %B1, %B2 \n\t" \ -"add r27, r0 \n\t" \ -"adc %A0, r1 \n\t" \ -"adc %B0, r26 \n\t" \ -"mul %C1, %A2 \n\t" \ -"add r27, r0 \n\t" \ -"adc %A0, r1 \n\t" \ -"adc %B0, r26 \n\t" \ -"mul %B1, %A2 \n\t" \ -"add r27, r1 \n\t" \ -"adc %A0, r26 \n\t" \ -"adc %B0, r26 \n\t" \ -"lsr r27 \n\t" \ -"adc %A0, r26 \n\t" \ -"adc %B0, r26 \n\t" \ -"clr r1 \n\t" \ -: \ -"=&r" (intRes) \ -: \ -"d" (longIn1), \ -"d" (longIn2) \ -: \ -"r26" , "r27" \ -) +// return ((x * y) >> 24) with rounding when shifting right +FORCE_INLINE uint16_t MUL24x24R24(__uint24 x, __uint24 y) { + uint16_t out; + __asm__ ( + // %0 out + // %1 x + // %2 y + // uint8_t: %An or %n + // uint16_t: %Bn %An + // __uint24: %Cn %Bn %An + // uint32_t: %Dn %Cn %Bn %An + // + // + // B2 A2 * + // A1 + //--------- + // B0 A0 RR + "clr r26 \n\t" + "mul %A1, %B2 \n\t" + "mov r27, r1 \n\t" + "mul %B1, %C2 \n\t" + "movw %A0, r0 \n\t" + "mul %C1, %C2 \n\t" + "add %B0, r0 \n\t" + "mul %C1, %B2 \n\t" + "add %A0, r0 \n\t" + "adc %B0, r1 \n\t" + "mul %A1, %C2 \n\t" + "add r27, r0 \n\t" + "adc %A0, r1 \n\t" + "adc %B0, r26 \n\t" + "mul %B1, %B2 \n\t" + "add r27, r0 \n\t" + "adc %A0, r1 \n\t" + "adc %B0, r26 \n\t" + "mul %C1, %A2 \n\t" + "add r27, r0 \n\t" + "adc %A0, r1 \n\t" + "adc %B0, r26 \n\t" + "mul %B1, %A2 \n\t" + "add r27, r1 \n\t" + "adc %A0, r26 \n\t" + "adc %B0, r26 \n\t" + "lsl r27 \n\t" + "adc %A0, r26 \n\t" + "adc %B0, r26 \n\t" + "clr r1 \n\t" + : "=&r" (out) + : "r" (x), "r" (y) + : "r0", "r1", "r26" , "r27" //clobbers: Technically these are either scratch registers or always 0 registers, but I'm making sure the compiler knows just in case. R26 is __zero_reg__, R27 is a temporary register. + ); + return out; +} #else //_NO_ASM -static inline void MultiU16X8toH16(uint16_t& intRes, uint8_t& charIn1, uint16_t& intIn2) +FORCE_INLINE uint16_t MUL8x16R8(uint8_t charIn1, uint16_t intIn2) { - intRes = ((uint32_t)charIn1 * (uint32_t)intIn2) >> 8; + return ((uint32_t)charIn1 * (uint32_t)intIn2) >> 8; } -static inline void MultiU24X24toH16(uint16_t& intRes, uint32_t& longIn1, uint32_t& longIn2) +FORCE_INLINE uint16_t MUL24x24R24(uint32_t longIn1, uint32_t longIn2) { - intRes = ((uint64_t)longIn1 * (uint64_t)longIn2) >> 24; + return ((uint64_t)longIn1 * (uint64_t)longIn2) >> 24; } #endif //_NO_ASM diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index a27c1f15b..595591520 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -818,7 +818,7 @@ FORCE_INLINE void isr() { //WRITE_NC(LOGIC_ANALYZER_CH1, true); if (step_events_completed.wide <= current_block->accelerate_until) { // v = t * a -> acc_step_rate = acceleration_time * current_block->acceleration_rate - MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate); + acc_step_rate = MUL24x24R24(acceleration_time, current_block->acceleration_rate); acc_step_rate += uint16_t(current_block->initial_rate); // upper limit if(acc_step_rate > uint16_t(current_block->nominal_rate)) @@ -838,8 +838,7 @@ FORCE_INLINE void isr() { #endif } else if (step_events_completed.wide > current_block->decelerate_after) { - uint16_t step_rate; - MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate); + uint16_t step_rate = MUL24x24R24(deceleration_time, current_block->acceleration_rate); if (step_rate > acc_step_rate) { // Check step_rate stays positive step_rate = uint16_t(current_block->final_rate); From c2bad473dc9f2bfd9d0e086303e4755e5ff197cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 6 Feb 2022 09:01:16 +0000 Subject: [PATCH 77/83] Optimise _menu_edit_P If the first if statement is true, then we don't need to check the next if statement. Saves 64 bytes of flash memory --- Firmware/menu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index 30951bbc3..86b9047e3 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -509,7 +509,7 @@ static void _menu_edit_P(void) if (lcd_draw_update) { if (lcd_encoder < _md->minEditValue) lcd_encoder = _md->minEditValue; - if (lcd_encoder > _md->maxEditValue) lcd_encoder = _md->maxEditValue; + else if (lcd_encoder > _md->maxEditValue) lcd_encoder = _md->maxEditValue; lcd_set_cursor(0, 1); menu_draw_P(' ', _md->editLabel, (int)lcd_encoder); } From 0b7aa31b2ad25f22ade9ba6929bdd7c411312444 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Wed, 9 Feb 2022 00:26:46 +0100 Subject: [PATCH 78/83] Fix MUL24x24R24 comment --- Firmware/speed_lookuptable.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/speed_lookuptable.h b/Firmware/speed_lookuptable.h index 66b93c5ab..12a9f7e5c 100644 --- a/Firmware/speed_lookuptable.h +++ b/Firmware/speed_lookuptable.h @@ -52,10 +52,10 @@ FORCE_INLINE uint16_t MUL24x24R24(__uint24 x, __uint24 y) { // uint32_t: %Dn %Cn %Bn %An // // - // B2 A2 * - // A1 - //--------- - // B0 A0 RR + // C2 B2 A2 * + // C1 B1 A1 + //------------------ + // -- B0 A0 RR RR RR "clr r26 \n\t" "mul %A1, %B2 \n\t" "mov r27, r1 \n\t" From 060581962c63853588f01790d03b2889758d689a Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 10 Feb 2022 09:33:55 +0100 Subject: [PATCH 79/83] Fix sizeof array look --- Firmware/Marlin_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8afdf0ac8..ef8556e50 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6097,7 +6097,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) int8_t pin_number = LED_PIN; if (code_seen('P')) pin_number = code_value_uint8(); - for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(*sensitive_pins)); i++) + for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(sensitive_pins[0])); i++) { if ((int8_t)pgm_read_byte(&sensitive_pins[i]) == pin_number) { @@ -7674,7 +7674,7 @@ Sigma_Exit: if(pin_state >= -1 && pin_state <= 1){ - for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(*sensitive_pins)); i++) + for(int8_t i = 0; i < (int8_t)(sizeof(sensitive_pins)/sizeof(sensitive_pins[0])); i++) { if (((int8_t)pgm_read_byte(&sensitive_pins[i]) == pin_number)) { From 380377db0fcf0c21376a8c639d3e2445a38a2fe5 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 10 Feb 2022 09:47:37 +0100 Subject: [PATCH 80/83] Add static assert --- Firmware/mesh_bed_calibration.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 16bfbbde3..4de80504f 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -2872,6 +2872,7 @@ bool sample_mesh_and_store_reference() } mbl.set_z(0, 0, current_position[Z_AXIS]); } + static_assert(MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS <= 255, "overflow....."); for (uint8_t mesh_point = 1; mesh_point != MESH_MEAS_NUM_X_POINTS * MESH_MEAS_NUM_Y_POINTS; ++ mesh_point) { // Don't let the manage_inactivity() function remove power from the motors. refresh_cmd_timeout(); From dee8da61f6c13e311635ba773bd9acc98d683be3 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 10 Feb 2022 10:35:25 +0100 Subject: [PATCH 81/83] Optimize endstop flags even more --- Firmware/stepper.cpp | 73 +++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 595591520..7195ba0e8 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -230,7 +230,9 @@ bool endstops_hit_on_purpose() bool endstop_z_hit_on_purpose() { bool hit = endstop_hit & _BV(Z_AXIS); +CRITICAL_SECTION_START; endstop_hit &= ~_BV(Z_AXIS); +CRITICAL_SECTION_END; return hit; } @@ -245,7 +247,9 @@ bool enable_z_endstop(bool check) { bool old = check_z_endstop; check_z_endstop = check; +CRITICAL_SECTION_START; endstop_hit &= ~_BV(Z_AXIS); +CRITICAL_SECTION_END; return old; } @@ -478,6 +482,9 @@ FORCE_INLINE void stepper_next_block() // Check limit switches. FORCE_INLINE void stepper_check_endstops() { + uint8_t _endstop_hit = endstop_hit; + uint8_t _endstop = endstop; + uint8_t _old_endstop = old_endstop; if(check_endstops) { #ifndef COREXY @@ -489,14 +496,14 @@ FORCE_INLINE void stepper_check_endstops() #if ( (defined(X_MIN_PIN) && (X_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMINLIMIT) #ifdef TMC2130_SG_HOMING // Stall guard homing turned on - SET_BIT_TO(endstop, X_AXIS, (READ(X_TMC2130_DIAG) != 0)); + SET_BIT_TO(_endstop, X_AXIS, (READ(X_TMC2130_DIAG) != 0)); #else // Normal homing - SET_BIT_TO(endstop, X_AXIS, (READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING)); + SET_BIT_TO(_endstop, X_AXIS, (READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING)); #endif - if((endstop & old_endstop & _BV(X_AXIS)) && (current_block->steps_x.wide > 0)) { + if((_endstop & _old_endstop & _BV(X_AXIS)) && (current_block->steps_x.wide > 0)) { endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; - endstop_hit |= _BV(X_AXIS); + _endstop_hit |= _BV(X_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } #endif @@ -504,14 +511,14 @@ FORCE_INLINE void stepper_check_endstops() #if ( (defined(X_MAX_PIN) && (X_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_XMAXLIMIT) #ifdef TMC2130_SG_HOMING // Stall guard homing turned on - SET_BIT_TO(endstop, X_AXIS + 4, (READ(X_TMC2130_DIAG) != 0)); + SET_BIT_TO(_endstop, X_AXIS + 4, (READ(X_TMC2130_DIAG) != 0)); #else // Normal homing - SET_BIT_TO(endstop, X_AXIS + 4, (READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING)); + SET_BIT_TO(_endstop, X_AXIS + 4, (READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING)); #endif - if((endstop & old_endstop & _BV(X_AXIS + 4)) && (current_block->steps_x.wide > 0)){ + if((_endstop & _old_endstop & _BV(X_AXIS + 4)) && (current_block->steps_x.wide > 0)){ endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; - endstop_hit |= _BV(X_AXIS); + _endstop_hit |= _BV(X_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } #endif @@ -526,14 +533,14 @@ FORCE_INLINE void stepper_check_endstops() #if ( (defined(Y_MIN_PIN) && (Y_MIN_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMINLIMIT) #ifdef TMC2130_SG_HOMING // Stall guard homing turned on - SET_BIT_TO(endstop, Y_AXIS, (READ(Y_TMC2130_DIAG) != 0)); + SET_BIT_TO(_endstop, Y_AXIS, (READ(Y_TMC2130_DIAG) != 0)); #else // Normal homing - SET_BIT_TO(endstop, Y_AXIS, (READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING)); + SET_BIT_TO(_endstop, Y_AXIS, (READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING)); #endif - if((endstop & old_endstop & _BV(Y_AXIS)) && (current_block->steps_y.wide > 0)) { + if((_endstop & _old_endstop & _BV(Y_AXIS)) && (current_block->steps_y.wide > 0)) { endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; - endstop_hit |= _BV(Y_AXIS); + _endstop_hit |= _BV(Y_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } #endif @@ -541,14 +548,14 @@ FORCE_INLINE void stepper_check_endstops() #if ( (defined(Y_MAX_PIN) && (Y_MAX_PIN > -1)) || defined(TMC2130_SG_HOMING) ) && !defined(DEBUG_DISABLE_YMAXLIMIT) #ifdef TMC2130_SG_HOMING // Stall guard homing turned on - SET_BIT_TO(endstop, Y_AXIS + 4, (READ(Y_TMC2130_DIAG) != 0)); + SET_BIT_TO(_endstop, Y_AXIS + 4, (READ(Y_TMC2130_DIAG) != 0)); #else // Normal homing - SET_BIT_TO(endstop, Y_AXIS + 4, (READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING)); + SET_BIT_TO(_endstop, Y_AXIS + 4, (READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING)); #endif - if((endstop & old_endstop & _BV(Y_AXIS + 4)) && (current_block->steps_y.wide > 0)){ + if((_endstop & _old_endstop & _BV(Y_AXIS + 4)) && (current_block->steps_y.wide > 0)){ endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; - endstop_hit |= _BV(Y_AXIS); + _endstop_hit |= _BV(Y_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } #endif @@ -562,16 +569,16 @@ FORCE_INLINE void stepper_check_endstops() // Stall guard homing turned on #ifdef TMC2130_STEALTH_Z if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) - SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); + SET_BIT_TO(_endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); else #endif //TMC2130_STEALTH_Z - SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0)); + SET_BIT_TO(_endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0)); #else - SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); + SET_BIT_TO(_endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); #endif //TMC2130_SG_HOMING - if((endstop & old_endstop & _BV(Z_AXIS)) && (current_block->steps_z.wide > 0)) { + if((_endstop & _old_endstop & _BV(Z_AXIS)) && (current_block->steps_z.wide > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_hit |= _BV(Z_AXIS); + _endstop_hit |= _BV(Z_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } } @@ -582,16 +589,16 @@ FORCE_INLINE void stepper_check_endstops() // Stall guard homing turned on #ifdef TMC2130_STEALTH_Z if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) - SET_BIT_TO(endstop, Z_AXIS + 4, 0); + SET_BIT_TO(_endstop, Z_AXIS + 4, 0); else #endif //TMC2130_STEALTH_Z - SET_BIT_TO(endstop, Z_AXIS + 4, (READ(Z_TMC2130_DIAG) != 0)); + SET_BIT_TO(_endstop, Z_AXIS + 4, (READ(Z_TMC2130_DIAG) != 0)); #else - SET_BIT_TO(endstop, Z_AXIS + 4, (READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING)); + SET_BIT_TO(_endstop, Z_AXIS + 4, (READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING)); #endif //TMC2130_SG_HOMING - if((endstop & old_endstop & _BV(Z_AXIS + 4)) && (current_block->steps_z.wide > 0)) { + if((_endstop & _old_endstop & _BV(Z_AXIS + 4)) && (current_block->steps_z.wide > 0)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_hit |= _BV(Z_AXIS); + _endstop_hit |= _BV(Z_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } #endif @@ -607,21 +614,23 @@ FORCE_INLINE void stepper_check_endstops() // Stall guard homing turned on #ifdef TMC2130_STEALTH_Z if ((tmc2130_mode == TMC2130_MODE_SILENT) && !(tmc2130_sg_homing_axes_mask & 0x04)) - SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); + SET_BIT_TO(_endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); else #endif //TMC2130_STEALTH_Z - SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0)); + SET_BIT_TO(_endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING) || (READ(Z_TMC2130_DIAG) != 0)); #else - SET_BIT_TO(endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); + SET_BIT_TO(_endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); #endif //TMC2130_SG_HOMING - if(endstop & old_endstop & _BV(Z_AXIS)) { + if(_endstop & _old_endstop & _BV(Z_AXIS)) { endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; - endstop_hit |= _BV(Z_AXIS); + _endstop_hit |= _BV(Z_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } } #endif - old_endstop = endstop; + endstop = _endstop; + old_endstop = _endstop; //apply current endstop state to the old endstop + endstop_hit = _endstop_hit; } From 18dde3fb6181f38ad53de78e6d84695d457373e1 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 10 Feb 2022 16:24:52 +0100 Subject: [PATCH 82/83] Faster code when endstops/probe are not enabled --- Firmware/stepper.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 7195ba0e8..73bc3157f 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -482,11 +482,11 @@ FORCE_INLINE void stepper_next_block() // Check limit switches. FORCE_INLINE void stepper_check_endstops() { - uint8_t _endstop_hit = endstop_hit; - uint8_t _endstop = endstop; - uint8_t _old_endstop = old_endstop; if(check_endstops) { + uint8_t _endstop_hit = endstop_hit; + uint8_t _endstop = endstop; + uint8_t _old_endstop = old_endstop; #ifndef COREXY if ((out_bits & (1< -1) && !defined(DEBUG_DISABLE_ZMINLIMIT) if (check_z_endstop) { + uint8_t _endstop_hit = endstop_hit; + uint8_t _endstop = endstop; + uint8_t _old_endstop = old_endstop; // Check the Z min end-stop no matter what. // Good for searching for the center of an induction target. #ifdef TMC2130_SG_HOMING @@ -626,11 +632,11 @@ FORCE_INLINE void stepper_check_endstops() _endstop_hit |= _BV(Z_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } + endstop = _endstop; + old_endstop = _endstop; //apply current endstop state to the old endstop + endstop_hit = _endstop_hit; } #endif - endstop = _endstop; - old_endstop = _endstop; //apply current endstop state to the old endstop - endstop_hit = _endstop_hit; } From 882a73b8672b7e84bfa14fec9cbbec47f1631560 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 10 Feb 2022 16:42:02 +0100 Subject: [PATCH 83/83] VERBOSE_CHECK_HIT_ENDSTOPS --- Firmware/Configuration_adv.h | 3 +++ Firmware/stepper.cpp | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Firmware/Configuration_adv.h b/Firmware/Configuration_adv.h index f1de79cb6..0f9c3fcb4 100644 --- a/Firmware/Configuration_adv.h +++ b/Firmware/Configuration_adv.h @@ -250,6 +250,9 @@ #define HAS_FOLDER_SORTING (FOLDER_SORTING) #endif +// Enabe this option to get a pretty message whenever the endstop gets hit (as in the position at which the endstop got triggered) +//#define VERBOSE_CHECK_HIT_ENDSTOPS + // Enable the option to stop SD printing when hitting and endstops, needs to be enabled from the LCD menu when this option is enabled. //#define ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 73bc3157f..e0b7e9858 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -128,7 +128,10 @@ static uint8_t step_loops; static uint16_t OCR1A_nominal; static uint8_t step_loops_nominal; +#ifdef VERBOSE_CHECK_HIT_ENDSTOPS volatile long endstops_trigsteps[3]={0,0,0}; +#endif //VERBOSE_CHECK_HIT_ENDSTOPS + static volatile uint8_t endstop_hit = 0; #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED bool abort_on_endstop_hit = false; @@ -189,7 +192,8 @@ extern uint16_t stepper_timer_overflow_last; void checkHitEndstops() { - if( endstop_hit) { + if(endstop_hit) { +#ifdef VERBOSE_CHECK_HIT_ENDSTOPS SERIAL_ECHO_START; SERIAL_ECHORPGM(MSG_ENDSTOPS_HIT); if(endstop_hit & _BV(X_AXIS)) { @@ -205,6 +209,7 @@ void checkHitEndstops() // LCD_MESSAGERPGM(CAT2((MSG_ENDSTOPS_HIT),PSTR("Z"))); } SERIAL_ECHOLN(""); +#endif //VERBOSE_CHECK_HIT_ENDSTOPS endstop_hit = 0; #if defined(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && defined(SDSUPPORT) if (abort_on_endstop_hit) @@ -502,7 +507,9 @@ FORCE_INLINE void stepper_check_endstops() SET_BIT_TO(_endstop, X_AXIS, (READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING)); #endif if((_endstop & _old_endstop & _BV(X_AXIS)) && (current_block->steps_x.wide > 0)) { +#ifdef VERBOSE_CHECK_HIT_ENDSTOPS endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; +#endif //VERBOSE_CHECK_HIT_ENDSTOPS _endstop_hit |= _BV(X_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } @@ -517,7 +524,9 @@ FORCE_INLINE void stepper_check_endstops() SET_BIT_TO(_endstop, X_AXIS + 4, (READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING)); #endif if((_endstop & _old_endstop & _BV(X_AXIS + 4)) && (current_block->steps_x.wide > 0)){ +#ifdef VERBOSE_CHECK_HIT_ENDSTOPS endstops_trigsteps[X_AXIS] = count_position[X_AXIS]; +#endif //VERBOSE_CHECK_HIT_ENDSTOPS _endstop_hit |= _BV(X_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } @@ -539,7 +548,9 @@ FORCE_INLINE void stepper_check_endstops() SET_BIT_TO(_endstop, Y_AXIS, (READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING)); #endif if((_endstop & _old_endstop & _BV(Y_AXIS)) && (current_block->steps_y.wide > 0)) { +#ifdef VERBOSE_CHECK_HIT_ENDSTOPS endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; +#endif //VERBOSE_CHECK_HIT_ENDSTOPS _endstop_hit |= _BV(Y_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } @@ -554,7 +565,9 @@ FORCE_INLINE void stepper_check_endstops() SET_BIT_TO(_endstop, Y_AXIS + 4, (READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING)); #endif if((_endstop & _old_endstop & _BV(Y_AXIS + 4)) && (current_block->steps_y.wide > 0)){ +#ifdef VERBOSE_CHECK_HIT_ENDSTOPS endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS]; +#endif //VERBOSE_CHECK_HIT_ENDSTOPS _endstop_hit |= _BV(Y_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } @@ -577,7 +590,9 @@ FORCE_INLINE void stepper_check_endstops() SET_BIT_TO(_endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); #endif //TMC2130_SG_HOMING if((_endstop & _old_endstop & _BV(Z_AXIS)) && (current_block->steps_z.wide > 0)) { +#ifdef VERBOSE_CHECK_HIT_ENDSTOPS endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; +#endif //VERBOSE_CHECK_HIT_ENDSTOPS _endstop_hit |= _BV(Z_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } @@ -597,7 +612,9 @@ FORCE_INLINE void stepper_check_endstops() SET_BIT_TO(_endstop, Z_AXIS + 4, (READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING)); #endif //TMC2130_SG_HOMING if((_endstop & _old_endstop & _BV(Z_AXIS + 4)) && (current_block->steps_z.wide > 0)) { +#ifdef VERBOSE_CHECK_HIT_ENDSTOPS endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; +#endif //VERBOSE_CHECK_HIT_ENDSTOPS _endstop_hit |= _BV(Z_AXIS); step_events_completed.wide = current_block->step_event_count.wide; } @@ -628,7 +645,9 @@ FORCE_INLINE void stepper_check_endstops() SET_BIT_TO(_endstop, Z_AXIS, (READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING)); #endif //TMC2130_SG_HOMING if(_endstop & _old_endstop & _BV(Z_AXIS)) { +#ifdef VERBOSE_CHECK_HIT_ENDSTOPS endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS]; +#endif //VERBOSE_CHECK_HIT_ENDSTOPS _endstop_hit |= _BV(Z_AXIS); step_events_completed.wide = current_block->step_event_count.wide; }