Browse Source

Keep Stepper encapsulation, use static data and methods

Scott Lahteine 8 years ago
parent
commit
668d50f68e
2 changed files with 83 additions and 32 deletions
  1. 52
    2
      Marlin/stepper.cpp
  2. 31
    30
      Marlin/stepper.h

+ 52
- 2
Marlin/stepper.cpp View File

@@ -60,6 +60,55 @@
60 60
 
61 61
 Stepper stepper; // Singleton
62 62
 
63
+// public:
64
+
65
+block_t* Stepper::current_block = NULL;  // A pointer to the block currently being traced
66
+
67
+#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
68
+  bool Stepper::abort_on_endstop_hit = false;
69
+#endif
70
+
71
+#if ENABLED(Z_DUAL_ENDSTOPS)
72
+  bool Stepper::performing_homing = false;
73
+#endif
74
+
75
+// private:
76
+
77
+unsigned char Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
78
+unsigned int Stepper::cleaning_buffer_counter = 0;
79
+
80
+#if ENABLED(Z_DUAL_ENDSTOPS)
81
+  bool Stepper::locked_z_motor = false;
82
+  bool Stepper::locked_z2_motor = false;
83
+#endif
84
+
85
+long  Stepper::counter_X = 0,
86
+      Stepper::counter_Y = 0,
87
+      Stepper::counter_Z = 0,
88
+      Stepper::counter_E = 0;
89
+
90
+volatile unsigned long Stepper::step_events_completed = 0; // The number of step events executed in the current block
91
+
92
+#if ENABLED(ADVANCE)
93
+  unsigned char Stepper::old_OCR0A;
94
+  long  Stepper::final_advance = 0,
95
+        Stepper::old_advance = 0,
96
+        Stepper::e_steps[4],
97
+        Stepper::advance_rate,
98
+        Stepper::advance;
99
+#endif
100
+
101
+long Stepper::acceleration_time, Stepper::deceleration_time;
102
+
103
+volatile long Stepper::count_position[NUM_AXIS] = { 0 };
104
+volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
105
+
106
+unsigned short Stepper::acc_step_rate; // needed for deceleration start point
107
+uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
108
+unsigned short Stepper::OCR1A_nominal;
109
+
110
+volatile long Stepper::endstops_trigsteps[3];
111
+
63 112
 #if ENABLED(DUAL_X_CARRIAGE)
64 113
   #define X_APPLY_DIR(v,ALWAYS) \
65 114
     if (extruder_duplication_enabled || ALWAYS) { \
@@ -238,7 +287,7 @@ void Stepper::set_directions() {
238 287
 
239 288
 // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
240 289
 // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
241
-ISR(TIMER1_COMPA_vect) { stepper.isr(); }
290
+ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
242 291
 
243 292
 void Stepper::isr() {
244 293
   if (cleaning_buffer_counter) {
@@ -405,7 +454,7 @@ void Stepper::isr() {
405 454
 #if ENABLED(ADVANCE)
406 455
   // Timer interrupt for E. e_steps is set in the main routine;
407 456
   // Timer 0 is shared with millies
408
-  ISR(TIMER0_COMPA_vect) { stepper.advance_isr(); }
457
+  ISR(TIMER0_COMPA_vect) { Stepper::advance_isr(); }
409 458
 
410 459
   void Stepper::advance_isr() {
411 460
     old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
@@ -443,6 +492,7 @@ void Stepper::isr() {
443 492
 #endif // ADVANCE
444 493
 
445 494
 void Stepper::init() {
495
+
446 496
   digipot_init(); //Initialize Digipot Motor Current
447 497
   microstep_init(); //Initialize Microstepping Pins
448 498
 

+ 31
- 30
Marlin/stepper.h View File

@@ -80,49 +80,46 @@ class Stepper {
80 80
 
81 81
   public:
82 82
 
83
-    block_t* current_block = NULL;  // A pointer to the block currently being traced
83
+    static block_t* current_block;  // A pointer to the block currently being traced
84 84
 
85 85
     #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
86
-      bool abort_on_endstop_hit = false;
86
+      static bool abort_on_endstop_hit;
87 87
     #endif
88 88
 
89 89
     #if ENABLED(Z_DUAL_ENDSTOPS)
90
-      bool performing_homing = false;
90
+      static bool performing_homing;
91 91
     #endif
92 92
 
93 93
     #if ENABLED(ADVANCE)
94
-      long e_steps[4];
94
+      static long e_steps[4];
95 95
     #endif
96 96
 
97 97
   private:
98 98
 
99
-    unsigned char last_direction_bits = 0;        // The next stepping-bits to be output
100
-    unsigned int cleaning_buffer_counter = 0;
99
+    static unsigned char last_direction_bits;        // The next stepping-bits to be output
100
+    static unsigned int cleaning_buffer_counter;
101 101
 
102 102
     #if ENABLED(Z_DUAL_ENDSTOPS)
103
-      bool locked_z_motor = false,
104
-           locked_z2_motor = false;
103
+      static bool locked_z_motor, locked_z2_motor;
105 104
     #endif
106 105
 
107 106
     // Counter variables for the Bresenham line tracer
108
-    long counter_X = 0, counter_Y = 0, counter_Z = 0, counter_E = 0;
109
-    volatile unsigned long step_events_completed = 0; // The number of step events executed in the current block
107
+    static long counter_X, counter_Y, counter_Z, counter_E;
108
+    static volatile unsigned long step_events_completed; // The number of step events executed in the current block
110 109
 
111 110
     #if ENABLED(ADVANCE)
112
-      unsigned char old_OCR0A;
113
-      long advance_rate, advance, final_advance = 0;
114
-      long old_advance = 0;
111
+      static unsigned char old_OCR0A;
112
+      static long advance_rate, advance, old_advance, final_advance;
115 113
     #endif
116 114
 
117
-    long acceleration_time, deceleration_time;
115
+    static long acceleration_time, deceleration_time;
118 116
     //unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
119
-    unsigned short acc_step_rate; // needed for deceleration start point
120
-    uint8_t step_loops;
121
-    uint8_t step_loops_nominal;
122
-    unsigned short OCR1A_nominal;
117
+    static unsigned short acc_step_rate; // needed for deceleration start point
118
+    static uint8_t step_loops, step_loops_nominal;
119
+    static unsigned short OCR1A_nominal;
123 120
 
124
-    volatile long endstops_trigsteps[3];
125
-    volatile long endstops_stepsTotal, endstops_stepsDone;
121
+    static volatile long endstops_trigsteps[3];
122
+    static volatile long endstops_stepsTotal, endstops_stepsDone;
126 123
 
127 124
     #if HAS_MOTOR_CURRENT_PWM
128 125
       #ifndef PWM_MOTOR_CURRENT
@@ -134,19 +131,19 @@ class Stepper {
134 131
     //
135 132
     // Positions of stepper motors, in step units
136 133
     //
137
-    volatile long count_position[NUM_AXIS] = { 0 };
134
+    static volatile long count_position[NUM_AXIS];
138 135
 
139 136
     //
140 137
     // Current direction of stepper motors (+1 or -1)
141 138
     //
142
-    volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
139
+    static volatile signed char count_direction[NUM_AXIS];
143 140
 
144 141
   public:
145 142
 
146 143
     //
147 144
     // Constructor / initializer
148 145
     //
149
-    Stepper() {};
146
+    Stepper() { };
150 147
 
151 148
     //
152 149
     // Initialize stepper hardware
@@ -157,10 +154,10 @@ class Stepper {
157 154
     // Interrupt Service Routines
158 155
     //
159 156
 
160
-    void isr();
157
+    static void isr();
161 158
 
162 159
     #if ENABLED(ADVANCE)
163
-      void advance_isr();
160
+      static void advance_isr();
164 161
     #endif
165 162
 
166 163
     //
@@ -177,7 +174,7 @@ class Stepper {
177 174
     //
178 175
     // Set direction bits for all steppers
179 176
     //
180
-    void set_directions();
177
+    static void set_directions();
181 178
 
182 179
     //
183 180
     // Get the position of a stepper, in steps
@@ -213,7 +210,7 @@ class Stepper {
213 210
     //
214 211
     // The direction of a single motor
215 212
     //
216
-    FORCE_INLINE bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); }
213
+    static FORCE_INLINE bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); }
217 214
 
218 215
     #if HAS_DIGIPOTSS
219 216
       void digitalPotWrite(int address, int value);
@@ -251,7 +248,7 @@ class Stepper {
251 248
 
252 249
   private:
253 250
 
254
-    FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
251
+    static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
255 252
       unsigned short timer;
256 253
 
257 254
       NOMORE(step_rate, MAX_STEP_FREQUENCY);
@@ -283,13 +280,17 @@ class Stepper {
283 280
         timer = (unsigned short)pgm_read_word_near(table_address);
284 281
         timer -= (((unsigned short)pgm_read_word_near(table_address + 2) * (unsigned char)(step_rate & 0x0007)) >> 3);
285 282
       }
286
-      if (timer < 100) { timer = 100; MYSERIAL.print(MSG_STEPPER_TOO_HIGH); MYSERIAL.println(step_rate); }//(20kHz this should never happen)
283
+      if (timer < 100) { // (20kHz - this should never happen)
284
+        timer = 100;
285
+        MYSERIAL.print(MSG_STEPPER_TOO_HIGH);
286
+        MYSERIAL.println(step_rate);
287
+      }
287 288
       return timer;
288 289
     }
289 290
 
290 291
     // Initializes the trapezoid generator from the current block. Called whenever a new
291 292
     // block begins.
292
-    FORCE_INLINE void trapezoid_generator_reset() {
293
+    static FORCE_INLINE void trapezoid_generator_reset() {
293 294
 
294 295
       static int8_t last_extruder = -1;
295 296
 

Loading…
Cancel
Save