stepper.cpp macros rework
delete some tabs
This commit is contained in:
parent
075386e7fe
commit
79a44a9de3
1 changed files with 71 additions and 50 deletions
|
@ -46,7 +46,7 @@ block_t *current_block; // A pointer to the block currently being traced
|
||||||
|
|
||||||
// Variables used by The Stepper Driver Interrupt
|
// Variables used by The Stepper Driver Interrupt
|
||||||
static unsigned char out_bits; // The next stepping-bits to be output
|
static unsigned char out_bits; // The next stepping-bits to be output
|
||||||
static unsigned int cleaning_buffer_counter;
|
static unsigned int cleaning_buffer_counter;
|
||||||
|
|
||||||
#ifdef Z_DUAL_ENDSTOPS
|
#ifdef Z_DUAL_ENDSTOPS
|
||||||
static bool performing_homing = false,
|
static bool performing_homing = false,
|
||||||
|
@ -285,8 +285,8 @@ void checkHitEndstops() {
|
||||||
}
|
}
|
||||||
#ifdef Z_PROBE_ENDSTOP
|
#ifdef Z_PROBE_ENDSTOP
|
||||||
if (endstop_z_probe_hit) {
|
if (endstop_z_probe_hit) {
|
||||||
SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
|
SERIAL_ECHOPAIR(" Z_PROBE:", (float)endstops_trigsteps[Z_AXIS] / axis_steps_per_unit[Z_AXIS]);
|
||||||
LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP");
|
LCD_MESSAGEPGM(MSG_ENDSTOPS_HIT "ZP");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
SERIAL_EOL;
|
SERIAL_EOL;
|
||||||
|
@ -411,7 +411,7 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
OCR1A = 200;
|
OCR1A = 200;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no current block, attempt to pop one from the buffer
|
// If there is no current block, attempt to pop one from the buffer
|
||||||
if (!current_block) {
|
if (!current_block) {
|
||||||
// Anything in the buffer?
|
// Anything in the buffer?
|
||||||
|
@ -463,14 +463,22 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
count_direction[Y_AXIS] = 1;
|
count_direction[Y_AXIS] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define _ENDSTOP(axis, minmax) axis ##_## minmax ##_endstop
|
||||||
|
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
|
||||||
|
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
|
||||||
|
#define _OLD_ENDSTOP(axis, minmax) old_## axis ##_## minmax ##_endstop
|
||||||
|
#define _AXIS(AXIS) AXIS ##_AXIS
|
||||||
|
#define _ENDSTOP_HIT(axis) endstop_## axis ##_hit
|
||||||
|
|
||||||
#define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
|
#define UPDATE_ENDSTOP(axis,AXIS,minmax,MINMAX) \
|
||||||
bool axis ##_## minmax ##_endstop = (READ(AXIS ##_## MINMAX ##_PIN) != AXIS ##_## MINMAX ##_ENDSTOP_INVERTING); \
|
bool _ENDSTOP(axis, minmax) = (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)); \
|
||||||
if (axis ##_## minmax ##_endstop && old_## axis ##_## minmax ##_endstop && (current_block->steps[AXIS ##_AXIS] > 0)) { \
|
if (_ENDSTOP(axis, minmax) && _OLD_ENDSTOP(axis, minmax) && (current_block->steps[_AXIS(AXIS)] > 0)) { \
|
||||||
endstops_trigsteps[AXIS ##_AXIS] = count_position[AXIS ##_AXIS]; \
|
endstops_trigsteps[_AXIS(AXIS)] = count_position[_AXIS(AXIS)]; \
|
||||||
endstop_## axis ##_hit = true; \
|
_ENDSTOP_HIT(axis) = true; \
|
||||||
step_events_completed = current_block->step_event_count; \
|
step_events_completed = current_block->step_event_count; \
|
||||||
} \
|
} \
|
||||||
old_## axis ##_## minmax ##_endstop = axis ##_## minmax ##_endstop;
|
_OLD_ENDSTOP(axis, minmax) = _ENDSTOP(axis, minmax);
|
||||||
|
|
||||||
|
|
||||||
// Check X and Y endstops
|
// Check X and Y endstops
|
||||||
if (check_endstops) {
|
if (check_endstops) {
|
||||||
|
@ -486,7 +494,7 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
#ifdef DUAL_X_CARRIAGE
|
#ifdef DUAL_X_CARRIAGE
|
||||||
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
||||||
if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
|
if ((current_block->active_extruder == 0 && X_HOME_DIR == -1) || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if HAS_X_MIN
|
#if HAS_X_MIN
|
||||||
UPDATE_ENDSTOP(x, X, min, MIN);
|
UPDATE_ENDSTOP(x, X, min, MIN);
|
||||||
|
@ -572,14 +580,14 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
|
z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
|
||||||
if(z_probe_endstop && old_z_probe_endstop)
|
if(z_probe_endstop && old_z_probe_endstop)
|
||||||
{
|
{
|
||||||
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
||||||
endstop_z_probe_hit=true;
|
endstop_z_probe_hit=true;
|
||||||
|
|
||||||
// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
||||||
}
|
}
|
||||||
old_z_probe_endstop = z_probe_endstop;
|
old_z_probe_endstop = z_probe_endstop;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} // check_endstops
|
} // check_endstops
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -625,15 +633,15 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
#endif // !Z_DUAL_ENDSTOPS
|
#endif // !Z_DUAL_ENDSTOPS
|
||||||
|
|
||||||
#endif // Z_MAX_PIN
|
#endif // Z_MAX_PIN
|
||||||
|
|
||||||
#ifdef Z_PROBE_ENDSTOP
|
#ifdef Z_PROBE_ENDSTOP
|
||||||
UPDATE_ENDSTOP(z, Z, probe, PROBE);
|
UPDATE_ENDSTOP(z, Z, probe, PROBE);
|
||||||
z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
|
z_probe_endstop=(READ(Z_PROBE_PIN) != Z_PROBE_ENDSTOP_INVERTING);
|
||||||
if(z_probe_endstop && old_z_probe_endstop)
|
if(z_probe_endstop && old_z_probe_endstop)
|
||||||
{
|
{
|
||||||
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
||||||
endstop_z_probe_hit=true;
|
endstop_z_probe_hit=true;
|
||||||
// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
// if (z_probe_endstop && old_z_probe_endstop) SERIAL_ECHOLN("z_probe_endstop = true");
|
||||||
}
|
}
|
||||||
old_z_probe_endstop = z_probe_endstop;
|
old_z_probe_endstop = z_probe_endstop;
|
||||||
#endif
|
#endif
|
||||||
|
@ -667,6 +675,11 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
}
|
}
|
||||||
#endif //ADVANCE
|
#endif //ADVANCE
|
||||||
|
|
||||||
|
#define _COUNTER(axis) counter_## axis
|
||||||
|
#define _WRITE_STEP(AXIS, HIGHLOW) AXIS ##_STEP_WRITE(HIGHLOW)
|
||||||
|
#define _APPLY_STEP(AXIS) AXIS ##_APPLY_STEP
|
||||||
|
#define _INVERT_STEP_PIN(AXIS) INVERT_## AXIS ##_STEP_PIN
|
||||||
|
|
||||||
#ifdef CONFIG_STEPPERS_TOSHIBA
|
#ifdef CONFIG_STEPPERS_TOSHIBA
|
||||||
/**
|
/**
|
||||||
* The Toshiba stepper controller require much longer pulses.
|
* The Toshiba stepper controller require much longer pulses.
|
||||||
|
@ -675,8 +688,8 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
* lag to allow it work with without needing NOPs
|
* lag to allow it work with without needing NOPs
|
||||||
*/
|
*/
|
||||||
#define STEP_ADD(axis, AXIS) \
|
#define STEP_ADD(axis, AXIS) \
|
||||||
counter_## axis += current_block->steps[AXIS ##_AXIS]; \
|
_COUNTER(axis) += current_block->steps[_AXIS(AXIS)]; \
|
||||||
if (counter_## axis > 0) { AXIS ##_STEP_WRITE(HIGH); }
|
if (_COUNTER(axis) > 0) { _WRITE_STEP(AXIS, HIGH); }
|
||||||
STEP_ADD(x,X);
|
STEP_ADD(x,X);
|
||||||
STEP_ADD(y,Y);
|
STEP_ADD(y,Y);
|
||||||
STEP_ADD(z,Z);
|
STEP_ADD(z,Z);
|
||||||
|
@ -685,10 +698,10 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STEP_IF_COUNTER(axis, AXIS) \
|
#define STEP_IF_COUNTER(axis, AXIS) \
|
||||||
if (counter_## axis > 0) { \
|
if (_COUNTER(axis) > 0) { \
|
||||||
counter_## axis -= current_block->step_event_count; \
|
_COUNTER(axis) -= current_block->step_event_count; \
|
||||||
count_position[AXIS ##_AXIS] += count_direction[AXIS ##_AXIS]; \
|
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
|
||||||
AXIS ##_STEP_WRITE(LOW); \
|
_WRITE_STEP(AXIS, LOW); \
|
||||||
}
|
}
|
||||||
|
|
||||||
STEP_IF_COUNTER(x, X);
|
STEP_IF_COUNTER(x, X);
|
||||||
|
@ -701,12 +714,12 @@ ISR(TIMER1_COMPA_vect) {
|
||||||
#else // !CONFIG_STEPPERS_TOSHIBA
|
#else // !CONFIG_STEPPERS_TOSHIBA
|
||||||
|
|
||||||
#define APPLY_MOVEMENT(axis, AXIS) \
|
#define APPLY_MOVEMENT(axis, AXIS) \
|
||||||
counter_## axis += current_block->steps[AXIS ##_AXIS]; \
|
_COUNTER(axis) += current_block->steps[_AXIS(AXIS)]; \
|
||||||
if (counter_## axis > 0) { \
|
if (_COUNTER(axis) > 0) { \
|
||||||
AXIS ##_APPLY_STEP(!INVERT_## AXIS ##_STEP_PIN,0); \
|
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS),0); \
|
||||||
counter_## axis -= current_block->step_event_count; \
|
_COUNTER(axis) -= current_block->step_event_count; \
|
||||||
count_position[AXIS ##_AXIS] += count_direction[AXIS ##_AXIS]; \
|
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
|
||||||
AXIS ##_APPLY_STEP(INVERT_## AXIS ##_STEP_PIN,0); \
|
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS),0); \
|
||||||
}
|
}
|
||||||
|
|
||||||
APPLY_MOVEMENT(x, X);
|
APPLY_MOVEMENT(x, X);
|
||||||
|
@ -874,7 +887,7 @@ void st_init() {
|
||||||
#ifdef HAVE_L6470DRIVER
|
#ifdef HAVE_L6470DRIVER
|
||||||
L6470_init();
|
L6470_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize Dir Pins
|
// Initialize Dir Pins
|
||||||
#if HAS_X_DIR
|
#if HAS_X_DIR
|
||||||
X_DIR_INIT;
|
X_DIR_INIT;
|
||||||
|
@ -920,11 +933,11 @@ void st_init() {
|
||||||
#if HAS_Y_ENABLE
|
#if HAS_Y_ENABLE
|
||||||
Y_ENABLE_INIT;
|
Y_ENABLE_INIT;
|
||||||
if (!Y_ENABLE_ON) Y_ENABLE_WRITE(HIGH);
|
if (!Y_ENABLE_ON) Y_ENABLE_WRITE(HIGH);
|
||||||
|
|
||||||
#if defined(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_ENABLE
|
#if defined(Y_DUAL_STEPPER_DRIVERS) && HAS_Y2_ENABLE
|
||||||
Y2_ENABLE_INIT;
|
Y2_ENABLE_INIT;
|
||||||
if (!Y_ENABLE_ON) Y2_ENABLE_WRITE(HIGH);
|
if (!Y_ENABLE_ON) Y2_ENABLE_WRITE(HIGH);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#if HAS_Z_ENABLE
|
#if HAS_Z_ENABLE
|
||||||
Z_ENABLE_INIT;
|
Z_ENABLE_INIT;
|
||||||
|
@ -1001,8 +1014,8 @@ void st_init() {
|
||||||
#ifdef ENDSTOPPULLUP_ZMAX
|
#ifdef ENDSTOPPULLUP_ZMAX
|
||||||
WRITE(Z2_MAX_PIN,HIGH);
|
WRITE(Z2_MAX_PIN,HIGH);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
|
#if (defined(Z_PROBE_PIN) && Z_PROBE_PIN >= 0) && defined(Z_PROBE_ENDSTOP) // Check for Z_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
|
||||||
SET_INPUT(Z_PROBE_PIN);
|
SET_INPUT(Z_PROBE_PIN);
|
||||||
#ifdef ENDSTOPPULLUP_ZPROBE
|
#ifdef ENDSTOPPULLUP_ZPROBE
|
||||||
|
@ -1010,10 +1023,13 @@ void st_init() {
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define _STEP_INIT(AXIS) AXIS ##_STEP_INIT
|
||||||
|
#define _DISABLE(axis) disable_## axis()
|
||||||
|
|
||||||
#define AXIS_INIT(axis, AXIS, PIN) \
|
#define AXIS_INIT(axis, AXIS, PIN) \
|
||||||
AXIS ##_STEP_INIT; \
|
_STEP_INIT(AXIS); \
|
||||||
AXIS ##_STEP_WRITE(INVERT_## PIN ##_STEP_PIN); \
|
_WRITE_STEP(AXIS, _INVERT_STEP_PIN(PIN)); \
|
||||||
disable_## axis()
|
_DISABLE(axis)
|
||||||
|
|
||||||
#define E_AXIS_INIT(NUM) AXIS_INIT(e## NUM, E## NUM, E)
|
#define E_AXIS_INIT(NUM) AXIS_INIT(e## NUM, E## NUM, E)
|
||||||
|
|
||||||
|
@ -1146,14 +1162,19 @@ void quickStop() {
|
||||||
// No other ISR should ever interrupt this!
|
// No other ISR should ever interrupt this!
|
||||||
void babystep(const uint8_t axis, const bool direction) {
|
void babystep(const uint8_t axis, const bool direction) {
|
||||||
|
|
||||||
|
#define _ENABLE(axis) enable_## axis()
|
||||||
|
#define _READ_DIR(AXIS) AXIS ##_DIR_READ
|
||||||
|
#define _INVERT_DIR(AXIS) INVERT_## AXIS ##_DIR
|
||||||
|
#define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
|
||||||
|
|
||||||
#define BABYSTEP_AXIS(axis, AXIS, INVERT) { \
|
#define BABYSTEP_AXIS(axis, AXIS, INVERT) { \
|
||||||
enable_## axis(); \
|
_ENABLE(axis); \
|
||||||
uint8_t old_pin = AXIS ##_DIR_READ; \
|
uint8_t old_pin = _READ_DIR(AXIS); \
|
||||||
AXIS ##_APPLY_DIR(INVERT_## AXIS ##_DIR^direction^INVERT, true); \
|
_APPLY_DIR(AXIS, _INVERT_DIR(AXIS)^direction^INVERT); \
|
||||||
AXIS ##_APPLY_STEP(!INVERT_## AXIS ##_STEP_PIN, true); \
|
_APPLY_STEP(AXIS)(!_INVERT_STEP_PIN(AXIS), true); \
|
||||||
delayMicroseconds(2); \
|
delayMicroseconds(2); \
|
||||||
AXIS ##_APPLY_STEP(INVERT_## AXIS ##_STEP_PIN, true); \
|
_APPLY_STEP(AXIS)(_INVERT_STEP_PIN(AXIS), true); \
|
||||||
AXIS ##_APPLY_DIR(old_pin, true); \
|
_APPLY_DIR(AXIS, old_pin); \
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(axis) {
|
switch(axis) {
|
||||||
|
@ -1165,7 +1186,7 @@ void quickStop() {
|
||||||
case Y_AXIS:
|
case Y_AXIS:
|
||||||
BABYSTEP_AXIS(y, Y, false);
|
BABYSTEP_AXIS(y, Y, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Z_AXIS: {
|
case Z_AXIS: {
|
||||||
|
|
||||||
#ifndef DELTA
|
#ifndef DELTA
|
||||||
|
@ -1202,7 +1223,7 @@ void quickStop() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1266,7 +1287,7 @@ void microstep_init() {
|
||||||
|
|
||||||
#if HAS_MICROSTEPS
|
#if HAS_MICROSTEPS
|
||||||
pinMode(X_MS1_PIN,OUTPUT);
|
pinMode(X_MS1_PIN,OUTPUT);
|
||||||
pinMode(X_MS2_PIN,OUTPUT);
|
pinMode(X_MS2_PIN,OUTPUT);
|
||||||
pinMode(Y_MS1_PIN,OUTPUT);
|
pinMode(Y_MS1_PIN,OUTPUT);
|
||||||
pinMode(Y_MS2_PIN,OUTPUT);
|
pinMode(Y_MS2_PIN,OUTPUT);
|
||||||
pinMode(Z_MS1_PIN,OUTPUT);
|
pinMode(Z_MS1_PIN,OUTPUT);
|
||||||
|
|
Reference in a new issue