dda.c/.h: reduce debounce counting variable.

As we can always only move towards one end of an axis, one common
variable to count debouncing is sufficient.

Binary size 12 bytes smaller (and faster).
This commit is contained in:
Markus Hitter 2014-12-27 20:28:01 +01:00
parent f577431aac
commit 4c34674b6e
2 changed files with 22 additions and 23 deletions

42
dda.c
View File

@ -764,9 +764,9 @@ void dda_clock() {
dda = queue_current_movement(); dda = queue_current_movement();
if (dda != last_dda) { if (dda != last_dda) {
move_state.debounce_count_xmin = move_state.debounce_count_ymin = move_state.debounce_count_x =
move_state.debounce_count_zmin = move_state.debounce_count_xmax = move_state.debounce_count_z =
move_state.debounce_count_ymax = move_state.debounce_count_zmax = 0; move_state.debounce_count_y = 0;
last_dda = dda; last_dda = dda;
} }
@ -788,57 +788,57 @@ void dda_clock() {
#ifdef X_MIN_PIN #ifdef X_MIN_PIN
if (dda->endstop_check & 0x01) { if (dda->endstop_check & 0x01) {
if (x_min() == dda->endstop_stop_cond) if (x_min() == dda->endstop_stop_cond)
move_state.debounce_count_xmin++; move_state.debounce_count_x++;
else else
move_state.debounce_count_xmin = 0; move_state.debounce_count_x = 0;
endstop_trigger = move_state.debounce_count_xmin >= ENDSTOP_STEPS; endstop_trigger = move_state.debounce_count_x >= ENDSTOP_STEPS;
} }
#endif #endif
#ifdef X_MAX_PIN #ifdef X_MAX_PIN
if (dda->endstop_check & 0x02) { if (dda->endstop_check & 0x02) {
if (x_max() == dda->endstop_stop_cond) if (x_max() == dda->endstop_stop_cond)
move_state.debounce_count_xmax++; move_state.debounce_count_x++;
else else
move_state.debounce_count_xmax = 0; move_state.debounce_count_x = 0;
endstop_trigger = move_state.debounce_count_xmax >= ENDSTOP_STEPS; endstop_trigger = move_state.debounce_count_x >= ENDSTOP_STEPS;
} }
#endif #endif
#ifdef Y_MIN_PIN #ifdef Y_MIN_PIN
if (dda->endstop_check & 0x04) { if (dda->endstop_check & 0x04) {
if (y_min() == dda->endstop_stop_cond) if (y_min() == dda->endstop_stop_cond)
move_state.debounce_count_ymin++; move_state.debounce_count_y++;
else else
move_state.debounce_count_ymin = 0; move_state.debounce_count_y = 0;
endstop_trigger = move_state.debounce_count_ymin >= ENDSTOP_STEPS; endstop_trigger = move_state.debounce_count_y >= ENDSTOP_STEPS;
} }
#endif #endif
#ifdef Y_MAX_PIN #ifdef Y_MAX_PIN
if (dda->endstop_check & 0x08) { if (dda->endstop_check & 0x08) {
if (y_max() == dda->endstop_stop_cond) if (y_max() == dda->endstop_stop_cond)
move_state.debounce_count_ymax++; move_state.debounce_count_y++;
else else
move_state.debounce_count_ymax = 0; move_state.debounce_count_y = 0;
endstop_trigger = move_state.debounce_count_ymax >= ENDSTOP_STEPS; endstop_trigger = move_state.debounce_count_y >= ENDSTOP_STEPS;
} }
#endif #endif
#ifdef Z_MIN_PIN #ifdef Z_MIN_PIN
if (dda->endstop_check & 0x10) { if (dda->endstop_check & 0x10) {
if (z_min() == dda->endstop_stop_cond) if (z_min() == dda->endstop_stop_cond)
move_state.debounce_count_zmin++; move_state.debounce_count_z++;
else else
move_state.debounce_count_zmin = 0; move_state.debounce_count_z = 0;
endstop_trigger = move_state.debounce_count_zmin >= ENDSTOP_STEPS; endstop_trigger = move_state.debounce_count_z >= ENDSTOP_STEPS;
} }
#endif #endif
#ifdef Z_MAX_PIN #ifdef Z_MAX_PIN
if (dda->endstop_check & 0x20) { if (dda->endstop_check & 0x20) {
if (z_max() == dda->endstop_stop_cond) if (z_max() == dda->endstop_stop_cond)
move_state.debounce_count_zmax++; move_state.debounce_count_z++;
else else
move_state.debounce_count_zmax = 0; move_state.debounce_count_z = 0;
endstop_trigger = move_state.debounce_count_zmax >= ENDSTOP_STEPS; endstop_trigger = move_state.debounce_count_z >= ENDSTOP_STEPS;
} }
#endif #endif

3
dda.h
View File

@ -77,8 +77,7 @@ typedef struct {
/// Endstop handling. /// Endstop handling.
uint8_t endstop_stop; ///< Stop due to endstop trigger uint8_t endstop_stop; ///< Stop due to endstop trigger
uint8_t debounce_count_xmin, debounce_count_ymin, debounce_count_zmin; uint8_t debounce_count_x, debounce_count_y, debounce_count_z;
uint8_t debounce_count_xmax, debounce_count_ymax, debounce_count_zmax;
} MOVE_STATE; } MOVE_STATE;
/** /**