From 8670f475b8cb309ad2a068d2c1fc648bd2c19087 Mon Sep 17 00:00:00 2001 From: Colin Godsey Date: Wed, 26 Aug 2020 00:32:56 -0600 Subject: [PATCH] Direct Stepping update (#19135) --- Marlin/src/feature/direct_stepping.cpp | 49 ++++++++++---------------- Marlin/src/feature/direct_stepping.h | 6 +--- Marlin/src/module/stepper.cpp | 30 ++++++++-------- 3 files changed, 34 insertions(+), 51 deletions(-) diff --git a/Marlin/src/feature/direct_stepping.cpp b/Marlin/src/feature/direct_stepping.cpp index d3bdb43ab3..9766d14640 100644 --- a/Marlin/src/feature/direct_stepping.cpp +++ b/Marlin/src/feature/direct_stepping.cpp @@ -56,9 +56,6 @@ namespace DirectStepping { template volatile bool SerialPageManager::page_states_dirty; - template - millis_t SerialPageManager::next_response; - template uint8_t SerialPageManager::pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE]; @@ -80,7 +77,6 @@ namespace DirectStepping { page_states[i] = PageState::FREE; fatal_error = false; - next_response = 0; state = State::NEWLINE; page_states_dirty = false; @@ -181,15 +177,8 @@ namespace DirectStepping { return; } - // Runs on a set interval also, as responses may get lost. - if (next_response && next_response < millis()) { - page_states_dirty = true; - } - if (!page_states_dirty) return; - page_states_dirty = false; - next_response = millis() + Cfg::RESPONSE_INTERVAL_MS; SERIAL_ECHO(Cfg::CONTROL_CHAR); constexpr int state_bits = 2; @@ -238,29 +227,29 @@ const uint8_t segment_table[DirectStepping::Config::NUM_SEGMENTS][DirectStepping #if STEPPER_PAGE_FORMAT == SP_4x4D_128 - { 1, 1, 1, 1, 1, 1, 1, 0 }, // 0 = -7 - { 1, 1, 1, 0, 1, 1, 1, 0 }, // 1 = -6 - { 0, 1, 1, 0, 1, 0, 1, 1 }, // 2 = -5 - { 0, 1, 0, 1, 0, 1, 0, 1 }, // 3 = -4 - { 0, 1, 0, 0, 1, 0, 0, 1 }, // 4 = -3 - { 0, 0, 1, 0, 0, 0, 1, 0 }, // 5 = -2 - { 0, 0, 0, 0, 1, 0, 0, 0 }, // 6 = -1 - { 0, 0, 0, 0, 0, 0, 0, 0 }, // 7 = 0 - { 0, 0, 0, 0, 1, 0, 0, 0 }, // 8 = 1 - { 0, 0, 1, 0, 0, 0, 1, 0 }, // 9 = 2 - { 0, 1, 0, 0, 1, 0, 0, 1 }, // 10 = 3 - { 0, 1, 0, 1, 0, 1, 0, 1 }, // 11 = 4 - { 0, 1, 1, 0, 1, 0, 1, 1 }, // 12 = 5 - { 1, 1, 1, 0, 1, 1, 1, 0 }, // 13 = 6 - { 1, 1, 1, 1, 1, 1, 1, 0 }, // 14 = 7 + { 1, 1, 1, 1, 1, 1, 1 }, // 0 = -7 + { 1, 1, 1, 0, 1, 1, 1 }, // 1 = -6 + { 1, 1, 1, 0, 1, 0, 1 }, // 2 = -5 + { 1, 1, 0, 1, 0, 1, 0 }, // 3 = -4 + { 1, 1, 0, 0, 1, 0, 0 }, // 4 = -3 + { 0, 0, 1, 0, 0, 0, 1 }, // 5 = -2 + { 0, 0, 0, 1, 0, 0, 0 }, // 6 = -1 + { 0, 0, 0, 0, 0, 0, 0 }, // 7 = 0 + { 0, 0, 0, 1, 0, 0, 0 }, // 8 = 1 + { 0, 0, 1, 0, 0, 0, 1 }, // 9 = 2 + { 1, 1, 0, 0, 1, 0, 0 }, // 10 = 3 + { 1, 1, 0, 1, 0, 1, 0 }, // 11 = 4 + { 1, 1, 1, 0, 1, 0, 1 }, // 12 = 5 + { 1, 1, 1, 0, 1, 1, 1 }, // 13 = 6 + { 1, 1, 1, 1, 1, 1, 1 }, // 14 = 7 { 0 } #elif STEPPER_PAGE_FORMAT == SP_4x2_256 - { 0, 0, 0, 0 }, // 0 - { 0, 1, 0, 0 }, // 1 - { 1, 0, 1, 0 }, // 2 - { 1, 1, 1, 0 }, // 3 + { 0, 0, 0 }, // 0 + { 0, 1, 0 }, // 1 + { 1, 0, 1 }, // 2 + { 1, 1, 1 }, // 3 #elif STEPPER_PAGE_FORMAT == SP_4x1_512 diff --git a/Marlin/src/feature/direct_stepping.h b/Marlin/src/feature/direct_stepping.h index dea2616508..cde9d1a0b4 100644 --- a/Marlin/src/feature/direct_stepping.h +++ b/Marlin/src/feature/direct_stepping.h @@ -70,7 +70,6 @@ namespace DirectStepping { static volatile PageState page_states[Cfg::NUM_PAGES]; static volatile bool page_states_dirty; - static millis_t next_response; static uint8_t pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE]; static uint8_t checksum; @@ -94,14 +93,11 @@ namespace DirectStepping { static constexpr int DIRECTIONAL = dir ? 1 : 0; static constexpr int SEGMENTS = segments; - static constexpr int RAW = (BITS_SEGMENT == 1) ? 1 : 0; static constexpr int NUM_SEGMENTS = 1 << BITS_SEGMENT; - static constexpr int SEGMENT_STEPS = 1 << (BITS_SEGMENT - DIRECTIONAL - RAW); + static constexpr int SEGMENT_STEPS = (1 << (BITS_SEGMENT - DIRECTIONAL)) - 1; static constexpr int TOTAL_STEPS = SEGMENT_STEPS * SEGMENTS; static constexpr int PAGE_SIZE = (NUM_AXES * BITS_SEGMENT * SEGMENTS) / 8; - static constexpr millis_t RESPONSE_INTERVAL_MS = 50; - typedef typename TypeSelector<(PAGE_SIZE>256), uint16_t, uint8_t>::type write_byte_idx_t; typedef typename TypeSelector<(NUM_PAGES>256), uint16_t, uint8_t>::type page_idx_t; }; diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index e5f65a3cdd..0e70fd370c 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -1578,12 +1578,11 @@ void Stepper::pulse_phase_isr() { #if STEPPER_PAGE_FORMAT == SP_4x4D_128 - #define PAGE_SEGMENT_UPDATE(AXIS, VALUE, MID) do{ \ - if ((VALUE) == MID) {} \ - else if ((VALUE) < MID) SBI(dm, _AXIS(AXIS)); \ - else CBI(dm, _AXIS(AXIS)); \ - page_step_state.sd[_AXIS(AXIS)] = VALUE; \ - page_step_state.bd[_AXIS(AXIS)] += VALUE; \ + #define PAGE_SEGMENT_UPDATE(AXIS, VALUE) do{ \ + if ((VALUE) < 7) SBI(dm, _AXIS(AXIS)); \ + else if ((VALUE) > 7) CBI(dm, _AXIS(AXIS)); \ + page_step_state.sd[_AXIS(AXIS)] = VALUE; \ + page_step_state.bd[_AXIS(AXIS)] += VALUE; \ }while(0) #define PAGE_PULSE_PREP(AXIS) do{ \ @@ -1592,7 +1591,7 @@ void Stepper::pulse_phase_isr() { }while(0) switch (page_step_state.segment_steps) { - case 8: + case DirectStepping::Config::SEGMENT_STEPS: page_step_state.segment_idx += 2; page_step_state.segment_steps = 0; // fallthru @@ -1601,10 +1600,10 @@ void Stepper::pulse_phase_isr() { high = page_step_state.page[page_step_state.segment_idx + 1]; uint8_t dm = last_direction_bits; - PAGE_SEGMENT_UPDATE(X, low >> 4, 7); - PAGE_SEGMENT_UPDATE(Y, low & 0xF, 7); - PAGE_SEGMENT_UPDATE(Z, high >> 4, 7); - PAGE_SEGMENT_UPDATE(E, high & 0xF, 7); + PAGE_SEGMENT_UPDATE(X, low >> 4); + PAGE_SEGMENT_UPDATE(Y, low & 0xF); + PAGE_SEGMENT_UPDATE(Z, high >> 4); + PAGE_SEGMENT_UPDATE(E, high & 0xF); if (dm != last_direction_bits) { last_direction_bits = dm; @@ -1615,9 +1614,9 @@ void Stepper::pulse_phase_isr() { default: break; } - PAGE_PULSE_PREP(X), - PAGE_PULSE_PREP(Y), - PAGE_PULSE_PREP(Z), + PAGE_PULSE_PREP(X); + PAGE_PULSE_PREP(Y); + PAGE_PULSE_PREP(Z); PAGE_PULSE_PREP(E); page_step_state.segment_steps++; @@ -1634,7 +1633,7 @@ void Stepper::pulse_phase_isr() { }while(0) switch (page_step_state.segment_steps) { - case 4: + case DirectStepping::Config::SEGMENT_STEPS: page_step_state.segment_idx++; page_step_state.segment_steps = 0; // fallthru @@ -1664,7 +1663,6 @@ void Stepper::pulse_phase_isr() { }while(0) uint8_t steps = page_step_state.page[page_step_state.segment_idx >> 1]; - if (page_step_state.segment_idx & 0x1) steps >>= 4; PAGE_PULSE_PREP(X, 3);