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);
|
||||
}
|
||||
|
||||
/*
|
||||
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
|
||||
*/
|
||||
|
||||
void dda_step(DDA *dda) {
|
||||
// called from interrupt context! keep it as simple as possible
|
||||
uint8_t step_option = 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
|
||||
uint8_t did_step = 0;
|
||||
|
||||
// step_option |= can_step(x_min(), x_max(), current_position.X, dda->endpoint.X, dda->x_direction) & X_CAN_STEP;
|
||||
step_option |= can_step(0 , 0 , current_position.X, dda->endpoint.X, dda->x_direction) & X_CAN_STEP;
|
||||
// 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) {
|
||||
if (current_position.X != dda->endpoint.X /* &&
|
||||
x_max() != dda->x_direction && x_min() == dda->x_direction */) {
|
||||
dda->x_counter -= dda->x_delta;
|
||||
if (dda->x_counter < 0) {
|
||||
x_step();
|
||||
step_option |= DID_STEP;
|
||||
did_step = 1;
|
||||
if (dda->x_direction)
|
||||
current_position.X++;
|
||||
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;
|
||||
if (dda->y_counter < 0) {
|
||||
y_step();
|
||||
step_option |= DID_STEP;
|
||||
did_step = 1;
|
||||
if (dda->y_direction)
|
||||
current_position.Y++;
|
||||
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;
|
||||
if (dda->z_counter < 0) {
|
||||
z_step();
|
||||
step_option |= DID_STEP;
|
||||
did_step = 1;
|
||||
if (dda->z_direction)
|
||||
current_position.Z++;
|
||||
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;
|
||||
if (dda->e_counter < 0) {
|
||||
e_step();
|
||||
step_option |= DID_STEP;
|
||||
did_step = 1;
|
||||
if (dda->e_direction)
|
||||
current_position.E++;
|
||||
else
|
||||
|
|
@ -440,7 +406,7 @@ void dda_step(DDA *dda) {
|
|||
// else we are already at target speed
|
||||
}
|
||||
|
||||
if (step_option) {
|
||||
if (did_step) {
|
||||
// we stepped, reset timeout
|
||||
steptimeout = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue