Browse Source

Direct Stepping update (#19135)

vanilla_fb_2.0.x
Colin Godsey 4 years ago
committed by GitHub
parent
commit
131ddeaeba
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      Marlin/src/feature/direct_stepping.cpp
  2. 6
      Marlin/src/feature/direct_stepping.h
  3. 26
      Marlin/src/module/stepper.cpp

49
Marlin/src/feature/direct_stepping.cpp

@ -56,9 +56,6 @@ namespace DirectStepping {
template<typename Cfg> template<typename Cfg>
volatile bool SerialPageManager<Cfg>::page_states_dirty; volatile bool SerialPageManager<Cfg>::page_states_dirty;
template<typename Cfg>
millis_t SerialPageManager<Cfg>::next_response;
template<typename Cfg> template<typename Cfg>
uint8_t SerialPageManager<Cfg>::pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE]; uint8_t SerialPageManager<Cfg>::pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE];
@ -80,7 +77,6 @@ namespace DirectStepping {
page_states[i] = PageState::FREE; page_states[i] = PageState::FREE;
fatal_error = false; fatal_error = false;
next_response = 0;
state = State::NEWLINE; state = State::NEWLINE;
page_states_dirty = false; page_states_dirty = false;
@ -181,15 +177,8 @@ namespace DirectStepping {
return; 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; if (!page_states_dirty) return;
page_states_dirty = false; page_states_dirty = false;
next_response = millis() + Cfg::RESPONSE_INTERVAL_MS;
SERIAL_ECHO(Cfg::CONTROL_CHAR); SERIAL_ECHO(Cfg::CONTROL_CHAR);
constexpr int state_bits = 2; 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 #if STEPPER_PAGE_FORMAT == SP_4x4D_128
{ 1, 1, 1, 1, 1, 1, 1, 0 }, // 0 = -7 { 1, 1, 1, 1, 1, 1, 1 }, // 0 = -7
{ 1, 1, 1, 0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, // 0 { 0, 0, 0 }, // 0
{ 0, 1, 0, 0 }, // 1 { 0, 1, 0 }, // 1
{ 1, 0, 1, 0 }, // 2 { 1, 0, 1 }, // 2
{ 1, 1, 1, 0 }, // 3 { 1, 1, 1 }, // 3
#elif STEPPER_PAGE_FORMAT == SP_4x1_512 #elif STEPPER_PAGE_FORMAT == SP_4x1_512

6
Marlin/src/feature/direct_stepping.h

@ -70,7 +70,6 @@ namespace DirectStepping {
static volatile PageState page_states[Cfg::NUM_PAGES]; static volatile PageState page_states[Cfg::NUM_PAGES];
static volatile bool page_states_dirty; static volatile bool page_states_dirty;
static millis_t next_response;
static uint8_t pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE]; static uint8_t pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE];
static uint8_t checksum; static uint8_t checksum;
@ -94,14 +93,11 @@ namespace DirectStepping {
static constexpr int DIRECTIONAL = dir ? 1 : 0; static constexpr int DIRECTIONAL = dir ? 1 : 0;
static constexpr int SEGMENTS = segments; 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 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 TOTAL_STEPS = SEGMENT_STEPS * SEGMENTS;
static constexpr int PAGE_SIZE = (NUM_AXES * BITS_SEGMENT * SEGMENTS) / 8; 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<(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; typedef typename TypeSelector<(NUM_PAGES>256), uint16_t, uint8_t>::type page_idx_t;
}; };

26
Marlin/src/module/stepper.cpp

@ -1578,10 +1578,9 @@ void Stepper::pulse_phase_isr() {
#if STEPPER_PAGE_FORMAT == SP_4x4D_128 #if STEPPER_PAGE_FORMAT == SP_4x4D_128
#define PAGE_SEGMENT_UPDATE(AXIS, VALUE, MID) do{ \ #define PAGE_SEGMENT_UPDATE(AXIS, VALUE) do{ \
if ((VALUE) == MID) {} \ if ((VALUE) < 7) SBI(dm, _AXIS(AXIS)); \
else if ((VALUE) < MID) SBI(dm, _AXIS(AXIS)); \ else if ((VALUE) > 7) CBI(dm, _AXIS(AXIS)); \
else CBI(dm, _AXIS(AXIS)); \
page_step_state.sd[_AXIS(AXIS)] = VALUE; \ page_step_state.sd[_AXIS(AXIS)] = VALUE; \
page_step_state.bd[_AXIS(AXIS)] += VALUE; \ page_step_state.bd[_AXIS(AXIS)] += VALUE; \
}while(0) }while(0)
@ -1592,7 +1591,7 @@ void Stepper::pulse_phase_isr() {
}while(0) }while(0)
switch (page_step_state.segment_steps) { switch (page_step_state.segment_steps) {
case 8: case DirectStepping::Config::SEGMENT_STEPS:
page_step_state.segment_idx += 2; page_step_state.segment_idx += 2;
page_step_state.segment_steps = 0; page_step_state.segment_steps = 0;
// fallthru // fallthru
@ -1601,10 +1600,10 @@ void Stepper::pulse_phase_isr() {
high = page_step_state.page[page_step_state.segment_idx + 1]; high = page_step_state.page[page_step_state.segment_idx + 1];
uint8_t dm = last_direction_bits; uint8_t dm = last_direction_bits;
PAGE_SEGMENT_UPDATE(X, low >> 4, 7); PAGE_SEGMENT_UPDATE(X, low >> 4);
PAGE_SEGMENT_UPDATE(Y, low & 0xF, 7); PAGE_SEGMENT_UPDATE(Y, low & 0xF);
PAGE_SEGMENT_UPDATE(Z, high >> 4, 7); PAGE_SEGMENT_UPDATE(Z, high >> 4);
PAGE_SEGMENT_UPDATE(E, high & 0xF, 7); PAGE_SEGMENT_UPDATE(E, high & 0xF);
if (dm != last_direction_bits) { if (dm != last_direction_bits) {
last_direction_bits = dm; last_direction_bits = dm;
@ -1615,9 +1614,9 @@ void Stepper::pulse_phase_isr() {
default: break; default: break;
} }
PAGE_PULSE_PREP(X), PAGE_PULSE_PREP(X);
PAGE_PULSE_PREP(Y), PAGE_PULSE_PREP(Y);
PAGE_PULSE_PREP(Z), PAGE_PULSE_PREP(Z);
PAGE_PULSE_PREP(E); PAGE_PULSE_PREP(E);
page_step_state.segment_steps++; page_step_state.segment_steps++;
@ -1634,7 +1633,7 @@ void Stepper::pulse_phase_isr() {
}while(0) }while(0)
switch (page_step_state.segment_steps) { switch (page_step_state.segment_steps) {
case 4: case DirectStepping::Config::SEGMENT_STEPS:
page_step_state.segment_idx++; page_step_state.segment_idx++;
page_step_state.segment_steps = 0; page_step_state.segment_steps = 0;
// fallthru // fallthru
@ -1664,7 +1663,6 @@ void Stepper::pulse_phase_isr() {
}while(0) }while(0)
uint8_t steps = page_step_state.page[page_step_state.segment_idx >> 1]; uint8_t steps = page_step_state.page[page_step_state.segment_idx >> 1];
if (page_step_state.segment_idx & 0x1) steps >>= 4; if (page_step_state.segment_idx & 0x1) steps >>= 4;
PAGE_PULSE_PREP(X, 3); PAGE_PULSE_PREP(X, 3);

Loading…
Cancel
Save