From 4c34674b6e15f1979a5543fb8a11abd6daebe299 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sat, 27 Dec 2014 20:28:01 +0100 Subject: [PATCH] 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). --- dda.c | 42 +++++++++++++++++++++--------------------- dda.h | 3 +-- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/dda.c b/dda.c index 5479cb1..73f5b07 100644 --- a/dda.c +++ b/dda.c @@ -764,9 +764,9 @@ void dda_clock() { dda = queue_current_movement(); if (dda != last_dda) { - move_state.debounce_count_xmin = move_state.debounce_count_ymin = - move_state.debounce_count_zmin = move_state.debounce_count_xmax = - move_state.debounce_count_ymax = move_state.debounce_count_zmax = 0; + move_state.debounce_count_x = + move_state.debounce_count_z = + move_state.debounce_count_y = 0; last_dda = dda; } @@ -788,57 +788,57 @@ void dda_clock() { #ifdef X_MIN_PIN if (dda->endstop_check & 0x01) { if (x_min() == dda->endstop_stop_cond) - move_state.debounce_count_xmin++; + move_state.debounce_count_x++; else - move_state.debounce_count_xmin = 0; - endstop_trigger = move_state.debounce_count_xmin >= ENDSTOP_STEPS; + move_state.debounce_count_x = 0; + endstop_trigger = move_state.debounce_count_x >= ENDSTOP_STEPS; } #endif #ifdef X_MAX_PIN if (dda->endstop_check & 0x02) { if (x_max() == dda->endstop_stop_cond) - move_state.debounce_count_xmax++; + move_state.debounce_count_x++; else - move_state.debounce_count_xmax = 0; - endstop_trigger = move_state.debounce_count_xmax >= ENDSTOP_STEPS; + move_state.debounce_count_x = 0; + endstop_trigger = move_state.debounce_count_x >= ENDSTOP_STEPS; } #endif #ifdef Y_MIN_PIN if (dda->endstop_check & 0x04) { if (y_min() == dda->endstop_stop_cond) - move_state.debounce_count_ymin++; + move_state.debounce_count_y++; else - move_state.debounce_count_ymin = 0; - endstop_trigger = move_state.debounce_count_ymin >= ENDSTOP_STEPS; + move_state.debounce_count_y = 0; + endstop_trigger = move_state.debounce_count_y >= ENDSTOP_STEPS; } #endif #ifdef Y_MAX_PIN if (dda->endstop_check & 0x08) { if (y_max() == dda->endstop_stop_cond) - move_state.debounce_count_ymax++; + move_state.debounce_count_y++; else - move_state.debounce_count_ymax = 0; - endstop_trigger = move_state.debounce_count_ymax >= ENDSTOP_STEPS; + move_state.debounce_count_y = 0; + endstop_trigger = move_state.debounce_count_y >= ENDSTOP_STEPS; } #endif #ifdef Z_MIN_PIN if (dda->endstop_check & 0x10) { if (z_min() == dda->endstop_stop_cond) - move_state.debounce_count_zmin++; + move_state.debounce_count_z++; else - move_state.debounce_count_zmin = 0; - endstop_trigger = move_state.debounce_count_zmin >= ENDSTOP_STEPS; + move_state.debounce_count_z = 0; + endstop_trigger = move_state.debounce_count_z >= ENDSTOP_STEPS; } #endif #ifdef Z_MAX_PIN if (dda->endstop_check & 0x20) { if (z_max() == dda->endstop_stop_cond) - move_state.debounce_count_zmax++; + move_state.debounce_count_z++; else - move_state.debounce_count_zmax = 0; - endstop_trigger = move_state.debounce_count_zmax >= ENDSTOP_STEPS; + move_state.debounce_count_z = 0; + endstop_trigger = move_state.debounce_count_z >= ENDSTOP_STEPS; } #endif diff --git a/dda.h b/dda.h index a9faa4e..8008741 100644 --- a/dda.h +++ b/dda.h @@ -77,8 +77,7 @@ typedef struct { /// Endstop handling. uint8_t endstop_stop; ///< Stop due to endstop trigger - uint8_t debounce_count_xmin, debounce_count_ymin, debounce_count_zmin; - uint8_t debounce_count_xmax, debounce_count_ymax, debounce_count_zmax; + uint8_t debounce_count_x, debounce_count_y, debounce_count_z; } MOVE_STATE; /**