Luigi Santivetti | 69972f9 | 2019-11-12 22:55:40 +0000 | [diff] [blame^] | 1 | /* |
| 2 | probe.c - code pertaining to probing methods |
| 3 | Part of Grbl |
| 4 | |
| 5 | Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC |
| 6 | |
| 7 | Grbl is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | Grbl is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with Grbl. If not, see <http://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include "grbl.h" |
| 22 | |
| 23 | |
| 24 | // Inverts the probe pin state depending on user settings and probing cycle mode. |
| 25 | uint8_t probe_invert_mask; |
| 26 | |
| 27 | |
| 28 | // Probe pin initialization routine. |
| 29 | void probe_init() |
| 30 | { |
| 31 | PROBE_DDR &= ~(PROBE_MASK); // Configure as input pins |
| 32 | #ifdef DISABLE_PROBE_PIN_PULL_UP |
| 33 | PROBE_PORT &= ~(PROBE_MASK); // Normal low operation. Requires external pull-down. |
| 34 | #else |
| 35 | PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation. |
| 36 | #endif |
| 37 | probe_configure_invert_mask(false); // Initialize invert mask. |
| 38 | } |
| 39 | |
| 40 | |
| 41 | // Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to |
| 42 | // appropriately set the pin logic according to setting for normal-high/normal-low operation |
| 43 | // and the probing cycle modes for toward-workpiece/away-from-workpiece. |
| 44 | void probe_configure_invert_mask(uint8_t is_probe_away) |
| 45 | { |
| 46 | probe_invert_mask = 0; // Initialize as zero. |
| 47 | if (bit_isfalse(settings.flags,BITFLAG_INVERT_PROBE_PIN)) { probe_invert_mask ^= PROBE_MASK; } |
| 48 | if (is_probe_away) { probe_invert_mask ^= PROBE_MASK; } |
| 49 | } |
| 50 | |
| 51 | |
| 52 | // Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor. |
| 53 | uint8_t probe_get_state() { return((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask); } |
| 54 | |
| 55 | |
| 56 | // Monitors probe pin state and records the system position when detected. Called by the |
| 57 | // stepper ISR per ISR tick. |
| 58 | // NOTE: This function must be extremely efficient as to not bog down the stepper ISR. |
| 59 | void probe_state_monitor() |
| 60 | { |
| 61 | if (probe_get_state()) { |
| 62 | sys_probe_state = PROBE_OFF; |
| 63 | memcpy(sys_probe_position, sys_position, sizeof(sys_position)); |
| 64 | bit_true(sys_rt_exec_state, EXEC_MOTION_CANCEL); |
| 65 | } |
| 66 | } |