Bladeren bron

Direct Stepping update (#19135)

Colin Godsey 4 jaren geleden
bovenliggende
commit
131ddeaeba
No account linked to committer's email address
3 gewijzigde bestanden met toevoegingen van 34 en 51 verwijderingen
  1. 19
    30
      Marlin/src/feature/direct_stepping.cpp
  2. 1
    5
      Marlin/src/feature/direct_stepping.h
  3. 14
    16
      Marlin/src/module/stepper.cpp

+ 19
- 30
Marlin/src/feature/direct_stepping.cpp Bestand weergeven

@@ -57,9 +57,6 @@ namespace DirectStepping {
57 57
   volatile bool SerialPageManager<Cfg>::page_states_dirty;
58 58
 
59 59
   template<typename Cfg>
60
-  millis_t SerialPageManager<Cfg>::next_response;
61
-
62
-  template<typename Cfg>
63 60
   uint8_t SerialPageManager<Cfg>::pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE];
64 61
 
65 62
   template<typename Cfg>
@@ -80,7 +77,6 @@ namespace DirectStepping {
80 77
       page_states[i] = PageState::FREE;
81 78
 
82 79
     fatal_error = false;
83
-    next_response = 0;
84 80
     state = State::NEWLINE;
85 81
 
86 82
     page_states_dirty = false;
@@ -181,15 +177,8 @@ namespace DirectStepping {
181 177
       return;
182 178
     }
183 179
 
184
-    // Runs on a set interval also, as responses may get lost.
185
-    if (next_response && next_response < millis()) {
186
-      page_states_dirty = true;
187
-    }
188
-
189 180
     if (!page_states_dirty) return;
190
-
191 181
     page_states_dirty = false;
192
-    next_response = millis() + Cfg::RESPONSE_INTERVAL_MS;
193 182
 
194 183
     SERIAL_ECHO(Cfg::CONTROL_CHAR);
195 184
     constexpr int state_bits = 2;
@@ -238,29 +227,29 @@ const uint8_t segment_table[DirectStepping::Config::NUM_SEGMENTS][DirectStepping
238 227
 
239 228
   #if STEPPER_PAGE_FORMAT == SP_4x4D_128
240 229
 
241
-    { 1, 1, 1, 1, 1, 1, 1, 0 }, //  0 = -7
242
-    { 1, 1, 1, 0, 1, 1, 1, 0 }, //  1 = -6
243
-    { 0, 1, 1, 0, 1, 0, 1, 1 }, //  2 = -5
244
-    { 0, 1, 0, 1, 0, 1, 0, 1 }, //  3 = -4
245
-    { 0, 1, 0, 0, 1, 0, 0, 1 }, //  4 = -3
246
-    { 0, 0, 1, 0, 0, 0, 1, 0 }, //  5 = -2
247
-    { 0, 0, 0, 0, 1, 0, 0, 0 }, //  6 = -1
248
-    { 0, 0, 0, 0, 0, 0, 0, 0 }, //  7 =  0
249
-    { 0, 0, 0, 0, 1, 0, 0, 0 }, //  8 =  1
250
-    { 0, 0, 1, 0, 0, 0, 1, 0 }, //  9 =  2
251
-    { 0, 1, 0, 0, 1, 0, 0, 1 }, // 10 =  3
252
-    { 0, 1, 0, 1, 0, 1, 0, 1 }, // 11 =  4
253
-    { 0, 1, 1, 0, 1, 0, 1, 1 }, // 12 =  5
254
-    { 1, 1, 1, 0, 1, 1, 1, 0 }, // 13 =  6
255
-    { 1, 1, 1, 1, 1, 1, 1, 0 }, // 14 =  7
230
+    { 1, 1, 1, 1, 1, 1, 1 }, //  0 = -7
231
+    { 1, 1, 1, 0, 1, 1, 1 }, //  1 = -6
232
+    { 1, 1, 1, 0, 1, 0, 1 }, //  2 = -5
233
+    { 1, 1, 0, 1, 0, 1, 0 }, //  3 = -4
234
+    { 1, 1, 0, 0, 1, 0, 0 }, //  4 = -3
235
+    { 0, 0, 1, 0, 0, 0, 1 }, //  5 = -2
236
+    { 0, 0, 0, 1, 0, 0, 0 }, //  6 = -1
237
+    { 0, 0, 0, 0, 0, 0, 0 }, //  7 =  0
238
+    { 0, 0, 0, 1, 0, 0, 0 }, //  8 =  1
239
+    { 0, 0, 1, 0, 0, 0, 1 }, //  9 =  2
240
+    { 1, 1, 0, 0, 1, 0, 0 }, // 10 =  3
241
+    { 1, 1, 0, 1, 0, 1, 0 }, // 11 =  4
242
+    { 1, 1, 1, 0, 1, 0, 1 }, // 12 =  5
243
+    { 1, 1, 1, 0, 1, 1, 1 }, // 13 =  6
244
+    { 1, 1, 1, 1, 1, 1, 1 }, // 14 =  7
256 245
     { 0 }
257 246
 
258 247
   #elif STEPPER_PAGE_FORMAT == SP_4x2_256
259 248
 
260
-    { 0, 0, 0, 0 }, // 0
261
-    { 0, 1, 0, 0 }, // 1
262
-    { 1, 0, 1, 0 }, // 2
263
-    { 1, 1, 1, 0 }, // 3
249
+    { 0, 0, 0 }, // 0
250
+    { 0, 1, 0 }, // 1
251
+    { 1, 0, 1 }, // 2
252
+    { 1, 1, 1 }, // 3
264 253
 
265 254
   #elif STEPPER_PAGE_FORMAT == SP_4x1_512
266 255
 

+ 1
- 5
Marlin/src/feature/direct_stepping.h Bestand weergeven

@@ -70,7 +70,6 @@ namespace DirectStepping {
70 70
 
71 71
     static volatile PageState page_states[Cfg::NUM_PAGES];
72 72
     static volatile bool page_states_dirty;
73
-    static millis_t next_response;
74 73
 
75 74
     static uint8_t pages[Cfg::NUM_PAGES][Cfg::PAGE_SIZE];
76 75
     static uint8_t checksum;
@@ -94,14 +93,11 @@ namespace DirectStepping {
94 93
     static constexpr int DIRECTIONAL    = dir ? 1 : 0;
95 94
     static constexpr int SEGMENTS       = segments;
96 95
 
97
-    static constexpr int RAW            = (BITS_SEGMENT == 1) ? 1 : 0;
98 96
     static constexpr int NUM_SEGMENTS   = 1 << BITS_SEGMENT;
99
-    static constexpr int SEGMENT_STEPS  = 1 << (BITS_SEGMENT - DIRECTIONAL - RAW);
97
+    static constexpr int SEGMENT_STEPS  = (1 << (BITS_SEGMENT - DIRECTIONAL)) - 1;
100 98
     static constexpr int TOTAL_STEPS    = SEGMENT_STEPS * SEGMENTS;
101 99
     static constexpr int PAGE_SIZE      = (NUM_AXES * BITS_SEGMENT * SEGMENTS) / 8;
102 100
 
103
-    static constexpr millis_t RESPONSE_INTERVAL_MS = 50;
104
-
105 101
     typedef typename TypeSelector<(PAGE_SIZE>256), uint16_t, uint8_t>::type write_byte_idx_t;
106 102
     typedef typename TypeSelector<(NUM_PAGES>256), uint16_t, uint8_t>::type page_idx_t;
107 103
   };

+ 14
- 16
Marlin/src/module/stepper.cpp Bestand weergeven

@@ -1578,12 +1578,11 @@ void Stepper::pulse_phase_isr() {
1578 1578
 
1579 1579
         #if STEPPER_PAGE_FORMAT == SP_4x4D_128
1580 1580
 
1581
-          #define PAGE_SEGMENT_UPDATE(AXIS, VALUE, MID) do{ \
1582
-                 if ((VALUE) == MID) {}                     \
1583
-            else if ((VALUE) <  MID) SBI(dm, _AXIS(AXIS));  \
1584
-            else                     CBI(dm, _AXIS(AXIS));  \
1585
-            page_step_state.sd[_AXIS(AXIS)] = VALUE;        \
1586
-            page_step_state.bd[_AXIS(AXIS)] += VALUE;       \
1581
+          #define PAGE_SEGMENT_UPDATE(AXIS, VALUE) do{   \
1582
+                 if ((VALUE) <  7) SBI(dm, _AXIS(AXIS)); \
1583
+            else if ((VALUE) >  7) CBI(dm, _AXIS(AXIS)); \
1584
+            page_step_state.sd[_AXIS(AXIS)] = VALUE;     \
1585
+            page_step_state.bd[_AXIS(AXIS)] += VALUE;    \
1587 1586
           }while(0)
1588 1587
 
1589 1588
           #define PAGE_PULSE_PREP(AXIS) do{ \
@@ -1592,7 +1591,7 @@ void Stepper::pulse_phase_isr() {
1592 1591
           }while(0)
1593 1592
 
1594 1593
           switch (page_step_state.segment_steps) {
1595
-            case 8:
1594
+            case DirectStepping::Config::SEGMENT_STEPS:
1596 1595
               page_step_state.segment_idx += 2;
1597 1596
               page_step_state.segment_steps = 0;
1598 1597
               // fallthru
@@ -1601,10 +1600,10 @@ void Stepper::pulse_phase_isr() {
1601 1600
                            high = page_step_state.page[page_step_state.segment_idx + 1];
1602 1601
               uint8_t dm = last_direction_bits;
1603 1602
 
1604
-              PAGE_SEGMENT_UPDATE(X, low >> 4, 7);
1605
-              PAGE_SEGMENT_UPDATE(Y, low & 0xF, 7);
1606
-              PAGE_SEGMENT_UPDATE(Z, high >> 4, 7);
1607
-              PAGE_SEGMENT_UPDATE(E, high & 0xF, 7);
1603
+              PAGE_SEGMENT_UPDATE(X, low >> 4);
1604
+              PAGE_SEGMENT_UPDATE(Y, low & 0xF);
1605
+              PAGE_SEGMENT_UPDATE(Z, high >> 4);
1606
+              PAGE_SEGMENT_UPDATE(E, high & 0xF);
1608 1607
 
1609 1608
               if (dm != last_direction_bits) {
1610 1609
                 last_direction_bits = dm;
@@ -1615,9 +1614,9 @@ void Stepper::pulse_phase_isr() {
1615 1614
             default: break;
1616 1615
           }
1617 1616
 
1618
-          PAGE_PULSE_PREP(X),
1619
-          PAGE_PULSE_PREP(Y),
1620
-          PAGE_PULSE_PREP(Z),
1617
+          PAGE_PULSE_PREP(X);
1618
+          PAGE_PULSE_PREP(Y);
1619
+          PAGE_PULSE_PREP(Z);
1621 1620
           PAGE_PULSE_PREP(E);
1622 1621
 
1623 1622
           page_step_state.segment_steps++;
@@ -1634,7 +1633,7 @@ void Stepper::pulse_phase_isr() {
1634 1633
           }while(0)
1635 1634
 
1636 1635
           switch (page_step_state.segment_steps) {
1637
-            case 4:
1636
+            case DirectStepping::Config::SEGMENT_STEPS:
1638 1637
               page_step_state.segment_idx++;
1639 1638
               page_step_state.segment_steps = 0;
1640 1639
               // fallthru
@@ -1664,7 +1663,6 @@ void Stepper::pulse_phase_isr() {
1664 1663
           }while(0)
1665 1664
 
1666 1665
           uint8_t steps = page_step_state.page[page_step_state.segment_idx >> 1];
1667
-
1668 1666
           if (page_step_state.segment_idx & 0x1) steps >>= 4;
1669 1667
 
1670 1668
           PAGE_PULSE_PREP(X, 3);

Laden…
Annuleren
Opslaan