From 4e19c59ab3e5f466293caf4efa0912b4b0c4b063 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 16 Nov 2017 00:23:21 -0600 Subject: [PATCH] Miscellaneous cleanup --- Marlin/Marlin_main.cpp | 59 +++++++++------------------- Marlin/Max7219_Debug_LEDs.cpp | 70 ++++++++++++++-------------------- Marlin/configuration_store.cpp | 4 +- Marlin/planner.cpp | 3 +- 4 files changed, 50 insertions(+), 86 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index ec62ca85a..2d9977ca5 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -8942,8 +8942,8 @@ inline void gcode_M205() { set_home_offset((AxisEnum)i, parser.value_linear_units()); #if ENABLED(MORGAN_SCARA) - if (parser.seen('T')) set_home_offset(A_AXIS, parser.value_linear_units()); // Theta - if (parser.seen('P')) set_home_offset(B_AXIS, parser.value_linear_units()); // Psi + if (parser.seen('T')) set_home_offset(A_AXIS, parser.value_float()); // Theta + if (parser.seen('P')) set_home_offset(B_AXIS, parser.value_float()); // Psi #endif report_current_position(); @@ -9319,14 +9319,14 @@ inline void gcode_M226() { #if ENABLED(BABYSTEP_XY) for (uint8_t a = X_AXIS; a <= Z_AXIS; a++) if (parser.seenval(axis_codes[a]) || (a == Z_AXIS && parser.seenval('S'))) { - const float offs = constrain(parser.value_axis_units(a), -2, 2); + const float offs = constrain(parser.value_axis_units((AxisEnum)a), -2, 2); #if ENABLED(BABYSTEP_ZPROBE_OFFSET) if (a == Z_AXIS) { zprobe_zoffset += offs; refresh_zprobe_zoffset(true); // 'true' to not babystep } #endif - thermalManager.babystep_axis(a, offs * planner.axis_steps_per_mm[a]); + thermalManager.babystep_axis((AxisEnum)a, offs * planner.axis_steps_per_mm[a]); } #else if (parser.seenval('Z') || parser.seenval('S')) { @@ -13318,48 +13318,27 @@ void prepare_move_to_destination() { #if !AVR_AT90USB1286_FAMILY case TIMER0A: #endif - case TIMER0B: - //_SET_CS(0, val); - break; + case TIMER0B: //_SET_CS(0, val); + break; #endif - #ifdef TCCR1A - case TIMER1A: - case TIMER1B: - //_SET_CS(1, val); - break; + #ifdef TCCR1A + case TIMER1A: case TIMER1B: //_SET_CS(1, val); + break; #endif - #ifdef TCCR2 - case TIMER2: - case TIMER2: - _SET_CS(2, val); - break; + #ifdef TCCR2 + case TIMER2: case TIMER2: _SET_CS(2, val); break; #endif - #ifdef TCCR2A - case TIMER2A: - case TIMER2B: - _SET_CS(2, val); - break; + #ifdef TCCR2A + case TIMER2A: case TIMER2B: _SET_CS(2, val); break; #endif - #ifdef TCCR3A - case TIMER3A: - case TIMER3B: - case TIMER3C: - _SET_CS(3, val); - break; + #ifdef TCCR3A + case TIMER3A: case TIMER3B: case TIMER3C: _SET_CS(3, val); break; #endif - #ifdef TCCR4A - case TIMER4A: - case TIMER4B: - case TIMER4C: - _SET_CS(4, val); - break; + #ifdef TCCR4A + case TIMER4A: case TIMER4B: case TIMER4C: _SET_CS(4, val); break; #endif - #ifdef TCCR5A - case TIMER5A: - case TIMER5B: - case TIMER5C: - _SET_CS(5, val); - break; + #ifdef TCCR5A + case TIMER5A: case TIMER5B: case TIMER5C: _SET_CS(5, val); break; #endif } } diff --git a/Marlin/Max7219_Debug_LEDs.cpp b/Marlin/Max7219_Debug_LEDs.cpp index 2eb8773fd..b74c7a2b3 100644 --- a/Marlin/Max7219_Debug_LEDs.cpp +++ b/Marlin/Max7219_Debug_LEDs.cpp @@ -63,54 +63,41 @@ static uint8_t LEDs[8] = { 0 }; +#ifdef CPU_32_BIT + #define MS_DELAY() delayMicroseconds(5) // 32-bit processors need a delay to stabilize the signal +#else + #define MS_DELAY() NOOP +#endif + void Max7219_PutByte(uint8_t data) { CRITICAL_SECTION_START for (uint8_t i = 8; i--;) { - #ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed - delayMicroseconds(5); // to let the signal wires stabilize. - WRITE(MAX7219_CLK_PIN, LOW); // tick - delayMicroseconds(5); - WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit - delayMicroseconds(5); - WRITE(MAX7219_CLK_PIN, HIGH); // tock - delayMicroseconds(5); - #else - WRITE(MAX7219_CLK_PIN, LOW); // tick - WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit - WRITE(MAX7219_CLK_PIN, HIGH); // tock - #endif - + MS_DELAY(); + WRITE(MAX7219_CLK_PIN, LOW); // tick + MS_DELAY(); + WRITE(MAX7219_DIN_PIN, (data & 0x80) ? HIGH : LOW); // send 1 or 0 based on data bit + MS_DELAY(); + WRITE(MAX7219_CLK_PIN, HIGH); // tock + MS_DELAY(); data <<= 1; } CRITICAL_SECTION_END } void Max7219(const uint8_t reg, const uint8_t data) { - #ifdef CPU_32_BIT - delayMicroseconds(5); - #endif + MS_DELAY(); CRITICAL_SECTION_START WRITE(MAX7219_LOAD_PIN, LOW); // begin - #ifdef CPU_32_BIT // The 32-bit processors are so fast, a small delay in the code is needed - delayMicroseconds(5); // to let the signal wires stabilize. - #endif + MS_DELAY(); Max7219_PutByte(reg); // specify register - #ifdef CPU_32_BIT - delayMicroseconds(5); - #endif + MS_DELAY(); Max7219_PutByte(data); // put data - #ifdef CPU_32_BIT - delayMicroseconds(5); - #endif + MS_DELAY(); WRITE(MAX7219_LOAD_PIN, LOW); // and tell the chip to load the data - #ifdef CPU_32_BIT - delayMicroseconds(5); - #endif + MS_DELAY(); WRITE(MAX7219_LOAD_PIN, HIGH); CRITICAL_SECTION_END - #ifdef CPU_32_BIT - delayMicroseconds(5); - #endif + MS_DELAY(); } void Max7219_LED_Set(const uint8_t row, const uint8_t col, const bool on) { @@ -329,23 +316,22 @@ void Max7219_idle_tasks() { #if ENABLED(MAX7219_DEBUG_PRINTER_ALIVE) static millis_t next_blink = 0; - if (ELAPSED(millis(), next_blink)) { - Max7219_LED_Toggle(7, 7); - next_blink = millis() + 750; + Max7219_LED_Toggle(7, 7); + next_blink = millis() + 750; } #endif #ifdef MAX7219_DEBUG_STEPPER_HEAD static int16_t last_head_cnt=0; if (last_head_cnt != head) { - if ( last_head_cnt < 8) + if (last_head_cnt < 8) Max7219_LED_Off( last_head_cnt, MAX7219_DEBUG_STEPPER_HEAD); else Max7219_LED_Off( last_head_cnt-8, MAX7219_DEBUG_STEPPER_HEAD+1); last_head_cnt = head; - if ( head < 8) + if (head < 8) Max7219_LED_On(head, MAX7219_DEBUG_STEPPER_HEAD); else Max7219_LED_On(head-8, MAX7219_DEBUG_STEPPER_HEAD+1); @@ -355,13 +341,13 @@ void Max7219_idle_tasks() { #ifdef MAX7219_DEBUG_STEPPER_TAIL static int16_t last_tail_cnt=0; if (last_tail_cnt != tail) { - if ( last_tail_cnt < 8) + if (last_tail_cnt < 8) Max7219_LED_Off( last_tail_cnt, MAX7219_DEBUG_STEPPER_TAIL); else Max7219_LED_Off( last_tail_cnt-8, MAX7219_DEBUG_STEPPER_TAIL+1); last_tail_cnt = tail; - if ( tail < 8) + if (tail < 8) Max7219_LED_On(tail, MAX7219_DEBUG_STEPPER_TAIL); else Max7219_LED_On(tail-8, MAX7219_DEBUG_STEPPER_TAIL+1); @@ -381,10 +367,10 @@ void Max7219_idle_tasks() { en = max(current_depth, last_depth); if (current_depth < last_depth) for (uint8_t i = st; i <= en; i++) // clear the highest order LEDs - Max7219_LED_Off(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1)); + Max7219_LED_Off(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1)); else - for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth - Max7219_LED_On(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1)); + for (uint8_t i = st; i <= en; i++) // set the LEDs to current depth + Max7219_LED_On(i/2, MAX7219_DEBUG_STEPPER_QUEUE + (i & 1)); last_depth = current_depth; } diff --git a/Marlin/configuration_store.cpp b/Marlin/configuration_store.cpp index 291fbca12..8cdd57384 100644 --- a/Marlin/configuration_store.cpp +++ b/Marlin/configuration_store.cpp @@ -215,8 +215,8 @@ MarlinSettings settings; #endif /** -* Post-process after Retrieve or Reset -*/ + * Post-process after Retrieve or Reset + */ void MarlinSettings::postprocess() { // steps per s2 needs to be updated to agree with units per s2 planner.reset_acceleration_rates(); diff --git a/Marlin/planner.cpp b/Marlin/planner.cpp index a08b3b9e8..e50770861 100644 --- a/Marlin/planner.cpp +++ b/Marlin/planner.cpp @@ -528,8 +528,7 @@ void Planner::check_axes_activity() { } inline float calculate_volumetric_multiplier(const float &diameter) { - if (!parser.volumetric_enabled || diameter == 0) return 1.0; - return 1.0 / CIRCLE_AREA(diameter * 0.5); + return (parser.volumetric_enabled && diameter) ? 1.0 / CIRCLE_AREA(diameter * 0.5) : 1.0; } void Planner::calculate_volumetric_multipliers() {