diff --git a/limits.c b/limits.c index 535c681..269f243 100755 --- a/limits.c +++ b/limits.c @@ -35,8 +35,8 @@ void limits_init() { - LIMIT_DDR &= ~(LIMIT_MASK); // Input pin - LIMIT_PORT |= (LIMIT_MASK); // Enable internal pull-up resistors for normal high + LIMIT_DDR &= ~(LIMIT_MASK); // Set as input pins + LIMIT_PORT |= (LIMIT_MASK); // Enable internal pull-up resistors. Normal high operation. } // Moves all specified axes in same specified direction (positive=true, negative=false) @@ -47,7 +47,8 @@ void limits_init() // algorithm is written here. This also lets users hack and tune this code freely for // their own particular needs without affecting the rest of Grbl. // NOTE: Only the abort runtime command can interrupt this process. -static void homing_cycle(bool x_axis, bool y_axis, bool z_axis, int8_t pos_dir, float homing_rate) +static void homing_cycle(bool x_axis, bool y_axis, bool z_axis, int8_t pos_dir, + bool invert_pin, float homing_rate) { // Determine governing axes with finest step resolution per distance for the Bresenham // algorithm. This solves the issue when homing multiple axes that have different @@ -92,17 +93,22 @@ static void homing_cycle(bool x_axis, bool y_axis, bool z_axis, int8_t pos_dir, uint32_t step_rate = 0; // Tracks step rate. Initialized from 0 rate. (in step/min) uint32_t trap_counter = MICROSECONDS_PER_ACCELERATION_TICK/2; // Acceleration trapezoid counter uint8_t out_bits; + uint8_t limit_state; for(;;) { // Reset out bits. Both direction and step pins appropriately inverted and set. out_bits = out_bits0; + // Get limit pin state. + limit_state = LIMIT_PIN; + if (invert_pin) { limit_state ^= LIMIT_MASK; } // If leaving switch, invert to move. + // Set step pins by Bresenham line algorithm. If limit switch reached, disable and // flag for completion. if (x_axis) { counter_x += steps[X_AXIS]; if (counter_x > 0) { - if (LIMIT_PIN & (1< 0) { - if (LIMIT_PIN & (1< 0) { - if (LIMIT_PIN & (1<