Browse Source

Merge pull request #3922 from thinkyhead/rc_statics_stepper

Apply static to Stepper class
pull/1/head
Scott Lahteine 9 years ago
parent
commit
663d2463dc
  1. 54
      Marlin/stepper.cpp
  2. 61
      Marlin/stepper.h

54
Marlin/stepper.cpp

@ -60,6 +60,55 @@
Stepper stepper; // Singleton Stepper stepper; // Singleton
// public:
block_t* Stepper::current_block = NULL; // A pointer to the block currently being traced
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
bool Stepper::abort_on_endstop_hit = false;
#endif
#if ENABLED(Z_DUAL_ENDSTOPS)
bool Stepper::performing_homing = false;
#endif
// private:
unsigned char Stepper::last_direction_bits = 0; // The next stepping-bits to be output
unsigned int Stepper::cleaning_buffer_counter = 0;
#if ENABLED(Z_DUAL_ENDSTOPS)
bool Stepper::locked_z_motor = false;
bool Stepper::locked_z2_motor = false;
#endif
long Stepper::counter_X = 0,
Stepper::counter_Y = 0,
Stepper::counter_Z = 0,
Stepper::counter_E = 0;
volatile unsigned long Stepper::step_events_completed = 0; // The number of step events executed in the current block
#if ENABLED(ADVANCE)
unsigned char Stepper::old_OCR0A;
long Stepper::final_advance = 0,
Stepper::old_advance = 0,
Stepper::e_steps[4],
Stepper::advance_rate,
Stepper::advance;
#endif
long Stepper::acceleration_time, Stepper::deceleration_time;
volatile long Stepper::count_position[NUM_AXIS] = { 0 };
volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 };
unsigned short Stepper::acc_step_rate; // needed for deceleration start point
uint8_t Stepper::step_loops, Stepper::step_loops_nominal;
unsigned short Stepper::OCR1A_nominal;
volatile long Stepper::endstops_trigsteps[3];
#if ENABLED(DUAL_X_CARRIAGE) #if ENABLED(DUAL_X_CARRIAGE)
#define X_APPLY_DIR(v,ALWAYS) \ #define X_APPLY_DIR(v,ALWAYS) \
if (extruder_duplication_enabled || ALWAYS) { \ if (extruder_duplication_enabled || ALWAYS) { \
@ -238,7 +287,7 @@ void Stepper::set_directions() {
// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse. // "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately. // It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
ISR(TIMER1_COMPA_vect) { stepper.isr(); } ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
void Stepper::isr() { void Stepper::isr() {
if (cleaning_buffer_counter) { if (cleaning_buffer_counter) {
@ -405,7 +454,7 @@ void Stepper::isr() {
#if ENABLED(ADVANCE) #if ENABLED(ADVANCE)
// Timer interrupt for E. e_steps is set in the main routine; // Timer interrupt for E. e_steps is set in the main routine;
// Timer 0 is shared with millies // Timer 0 is shared with millies
ISR(TIMER0_COMPA_vect) { stepper.advance_isr(); } ISR(TIMER0_COMPA_vect) { Stepper::advance_isr(); }
void Stepper::advance_isr() { void Stepper::advance_isr() {
old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz) old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
@ -443,6 +492,7 @@ void Stepper::isr() {
#endif // ADVANCE #endif // ADVANCE
void Stepper::init() { void Stepper::init() {
digipot_init(); //Initialize Digipot Motor Current digipot_init(); //Initialize Digipot Motor Current
microstep_init(); //Initialize Microstepping Pins microstep_init(); //Initialize Microstepping Pins

61
Marlin/stepper.h

@ -80,49 +80,46 @@ class Stepper {
public: public:
block_t* current_block = NULL; // A pointer to the block currently being traced static block_t* current_block; // A pointer to the block currently being traced
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) #if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED)
bool abort_on_endstop_hit = false; static bool abort_on_endstop_hit;
#endif #endif
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
bool performing_homing = false; static bool performing_homing;
#endif #endif
#if ENABLED(ADVANCE) #if ENABLED(ADVANCE)
long e_steps[4]; static long e_steps[4];
#endif #endif
private: private:
unsigned char last_direction_bits = 0; // The next stepping-bits to be output static unsigned char last_direction_bits; // The next stepping-bits to be output
unsigned int cleaning_buffer_counter = 0; static unsigned int cleaning_buffer_counter;
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
bool locked_z_motor = false, static bool locked_z_motor, locked_z2_motor;
locked_z2_motor = false;
#endif #endif
// Counter variables for the Bresenham line tracer // Counter variables for the Bresenham line tracer
long counter_X = 0, counter_Y = 0, counter_Z = 0, counter_E = 0; static long counter_X, counter_Y, counter_Z, counter_E;
volatile unsigned long step_events_completed = 0; // The number of step events executed in the current block static volatile unsigned long step_events_completed; // The number of step events executed in the current block
#if ENABLED(ADVANCE) #if ENABLED(ADVANCE)
unsigned char old_OCR0A; static unsigned char old_OCR0A;
long advance_rate, advance, final_advance = 0; static long advance_rate, advance, old_advance, final_advance;
long old_advance = 0;
#endif #endif
long acceleration_time, deceleration_time; static long acceleration_time, deceleration_time;
//unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate; //unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
unsigned short acc_step_rate; // needed for deceleration start point static unsigned short acc_step_rate; // needed for deceleration start point
uint8_t step_loops; static uint8_t step_loops, step_loops_nominal;
uint8_t step_loops_nominal; static unsigned short OCR1A_nominal;
unsigned short OCR1A_nominal;
volatile long endstops_trigsteps[3]; static volatile long endstops_trigsteps[3];
volatile long endstops_stepsTotal, endstops_stepsDone; static volatile long endstops_stepsTotal, endstops_stepsDone;
#if HAS_MOTOR_CURRENT_PWM #if HAS_MOTOR_CURRENT_PWM
#ifndef PWM_MOTOR_CURRENT #ifndef PWM_MOTOR_CURRENT
@ -134,19 +131,19 @@ class Stepper {
// //
// Positions of stepper motors, in step units // Positions of stepper motors, in step units
// //
volatile long count_position[NUM_AXIS] = { 0 }; static volatile long count_position[NUM_AXIS];
// //
// Current direction of stepper motors (+1 or -1) // Current direction of stepper motors (+1 or -1)
// //
volatile signed char count_direction[NUM_AXIS] = { 1, 1, 1, 1 }; static volatile signed char count_direction[NUM_AXIS];
public: public:
// //
// Constructor / initializer // Constructor / initializer
// //
Stepper() {}; Stepper() { };
// //
// Initialize stepper hardware // Initialize stepper hardware
@ -157,10 +154,10 @@ class Stepper {
// Interrupt Service Routines // Interrupt Service Routines
// //
void isr(); static void isr();
#if ENABLED(ADVANCE) #if ENABLED(ADVANCE)
void advance_isr(); static void advance_isr();
#endif #endif
// //
@ -177,7 +174,7 @@ class Stepper {
// //
// Set direction bits for all steppers // Set direction bits for all steppers
// //
void set_directions(); static void set_directions();
// //
// Get the position of a stepper, in steps // Get the position of a stepper, in steps
@ -213,7 +210,7 @@ class Stepper {
// //
// The direction of a single motor // The direction of a single motor
// //
FORCE_INLINE bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); } static FORCE_INLINE bool motor_direction(AxisEnum axis) { return TEST(last_direction_bits, axis); }
#if HAS_DIGIPOTSS #if HAS_DIGIPOTSS
void digitalPotWrite(int address, int value); void digitalPotWrite(int address, int value);
@ -251,7 +248,7 @@ class Stepper {
private: private:
FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) { static FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
unsigned short timer; unsigned short timer;
NOMORE(step_rate, MAX_STEP_FREQUENCY); NOMORE(step_rate, MAX_STEP_FREQUENCY);
@ -283,13 +280,17 @@ class Stepper {
timer = (unsigned short)pgm_read_word_near(table_address); timer = (unsigned short)pgm_read_word_near(table_address);
timer -= (((unsigned short)pgm_read_word_near(table_address + 2) * (unsigned char)(step_rate & 0x0007)) >> 3); timer -= (((unsigned short)pgm_read_word_near(table_address + 2) * (unsigned char)(step_rate & 0x0007)) >> 3);
} }
if (timer < 100) { timer = 100; MYSERIAL.print(MSG_STEPPER_TOO_HIGH); MYSERIAL.println(step_rate); }//(20kHz this should never happen) if (timer < 100) { // (20kHz - this should never happen)
timer = 100;
MYSERIAL.print(MSG_STEPPER_TOO_HIGH);
MYSERIAL.println(step_rate);
}
return timer; return timer;
} }
// Initializes the trapezoid generator from the current block. Called whenever a new // Initializes the trapezoid generator from the current block. Called whenever a new
// block begins. // block begins.
FORCE_INLINE void trapezoid_generator_reset() { static FORCE_INLINE void trapezoid_generator_reset() {
static int8_t last_extruder = -1; static int8_t last_extruder = -1;

Loading…
Cancel
Save