dda.c: replaced can_step() with a more simple solution. This
saves a whopping 270 bytes in interrupt context.
This commit is contained in:
parent
7f57634e8c
commit
548b79f3d6
60
dda.c
60
dda.c
|
|
@ -314,56 +314,20 @@ void dda_start(DDA *dda) {
|
||||||
setTimer(dda->c >> 8);
|
setTimer(dda->c >> 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
CAN STEP
|
|
||||||
*/
|
|
||||||
|
|
||||||
uint8_t can_step(uint8_t min, uint8_t max, int32_t current, int32_t target, uint8_t dir) {
|
|
||||||
if (dir) {
|
|
||||||
// forwards/positive
|
|
||||||
if (max)
|
|
||||||
return 0;
|
|
||||||
if (current >= target)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// backwards/negative
|
|
||||||
if (min)
|
|
||||||
return 0;
|
|
||||||
if (target >= current)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
STEP
|
STEP
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void dda_step(DDA *dda) {
|
void dda_step(DDA *dda) {
|
||||||
// called from interrupt context! keep it as simple as possible
|
// called from interrupt context! keep it as simple as possible
|
||||||
uint8_t step_option = 0;
|
uint8_t did_step = 0;
|
||||||
#define X_CAN_STEP 1
|
|
||||||
#define Y_CAN_STEP 2
|
|
||||||
#define Z_CAN_STEP 4
|
|
||||||
#define E_CAN_STEP 8
|
|
||||||
#define DID_STEP 128
|
|
||||||
|
|
||||||
// step_option |= can_step(x_min(), x_max(), current_position.X, dda->endpoint.X, dda->x_direction) & X_CAN_STEP;
|
if (current_position.X != dda->endpoint.X /* &&
|
||||||
step_option |= can_step(0 , 0 , current_position.X, dda->endpoint.X, dda->x_direction) & X_CAN_STEP;
|
x_max() != dda->x_direction && x_min() == dda->x_direction */) {
|
||||||
// step_option |= can_step(y_min(), y_max(), current_position.Y, dda->endpoint.Y, dda->y_direction) & Y_CAN_STEP;
|
|
||||||
step_option |= can_step(0 , 0 , current_position.Y, dda->endpoint.Y, dda->y_direction) & Y_CAN_STEP;
|
|
||||||
// step_option |= can_step(z_min(), z_max(), current_position.Z, dda->endpoint.Z, dda->z_direction) & Z_CAN_STEP;
|
|
||||||
step_option |= can_step(0 , 0 , current_position.Z, dda->endpoint.Z, dda->z_direction) & Z_CAN_STEP;
|
|
||||||
step_option |= can_step(0 , 0 , current_position.E, dda->endpoint.E, dda->e_direction) & E_CAN_STEP;
|
|
||||||
// step_option |= can_step(0 , 0 , current_position.F, dda->endpoint.F, dda->f_direction) & F_CAN_STEP;
|
|
||||||
|
|
||||||
if (step_option & X_CAN_STEP) {
|
|
||||||
dda->x_counter -= dda->x_delta;
|
dda->x_counter -= dda->x_delta;
|
||||||
if (dda->x_counter < 0) {
|
if (dda->x_counter < 0) {
|
||||||
x_step();
|
x_step();
|
||||||
step_option |= DID_STEP;
|
did_step = 1;
|
||||||
if (dda->x_direction)
|
if (dda->x_direction)
|
||||||
current_position.X++;
|
current_position.X++;
|
||||||
else
|
else
|
||||||
|
|
@ -373,11 +337,12 @@ void dda_step(DDA *dda) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (step_option & Y_CAN_STEP) {
|
if (current_position.Y != dda->endpoint.Y /* &&
|
||||||
|
y_max() != dda->y_direction && y_min() == dda->y_direction */) {
|
||||||
dda->y_counter -= dda->y_delta;
|
dda->y_counter -= dda->y_delta;
|
||||||
if (dda->y_counter < 0) {
|
if (dda->y_counter < 0) {
|
||||||
y_step();
|
y_step();
|
||||||
step_option |= DID_STEP;
|
did_step = 1;
|
||||||
if (dda->y_direction)
|
if (dda->y_direction)
|
||||||
current_position.Y++;
|
current_position.Y++;
|
||||||
else
|
else
|
||||||
|
|
@ -387,11 +352,12 @@ void dda_step(DDA *dda) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (step_option & Z_CAN_STEP) {
|
if (current_position.Z != dda->endpoint.Z /* &&
|
||||||
|
z_max() != dda->z_direction && z_min() == dda->z_direction */) {
|
||||||
dda->z_counter -= dda->z_delta;
|
dda->z_counter -= dda->z_delta;
|
||||||
if (dda->z_counter < 0) {
|
if (dda->z_counter < 0) {
|
||||||
z_step();
|
z_step();
|
||||||
step_option |= DID_STEP;
|
did_step = 1;
|
||||||
if (dda->z_direction)
|
if (dda->z_direction)
|
||||||
current_position.Z++;
|
current_position.Z++;
|
||||||
else
|
else
|
||||||
|
|
@ -401,11 +367,11 @@ void dda_step(DDA *dda) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (step_option & E_CAN_STEP) {
|
if (current_position.E != dda->endpoint.E) {
|
||||||
dda->e_counter -= dda->e_delta;
|
dda->e_counter -= dda->e_delta;
|
||||||
if (dda->e_counter < 0) {
|
if (dda->e_counter < 0) {
|
||||||
e_step();
|
e_step();
|
||||||
step_option |= DID_STEP;
|
did_step = 1;
|
||||||
if (dda->e_direction)
|
if (dda->e_direction)
|
||||||
current_position.E++;
|
current_position.E++;
|
||||||
else
|
else
|
||||||
|
|
@ -440,7 +406,7 @@ void dda_step(DDA *dda) {
|
||||||
// else we are already at target speed
|
// else we are already at target speed
|
||||||
}
|
}
|
||||||
|
|
||||||
if (step_option) {
|
if (did_step) {
|
||||||
// we stepped, reset timeout
|
// we stepped, reset timeout
|
||||||
steptimeout = 0;
|
steptimeout = 0;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue