Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
probe.c
00001 /* 00002 probe.c - code pertaining to probing methods 00003 Part of Grbl 00004 00005 Copyright (c) 2014-2016 Sungeun K. Jeon for Gnea Research LLC 00006 00007 Grbl is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 Grbl is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Grbl. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include "grbl.h" 00022 00023 00024 // Inverts the probe pin state depending on user settings and probing cycle mode. 00025 uint8_t probe_invert_mask; 00026 00027 00028 // Probe pin initialization routine. 00029 void probe_init() 00030 { 00031 #ifdef AVRTARGET 00032 PROBE_DDR &= ~(PROBE_MASK); // Configure as input pins 00033 #ifdef DISABLE_PROBE_PIN_PULL_UP 00034 PROBE_PORT &= ~(PROBE_MASK); // Normal low operation. Requires external pull-down. 00035 #else 00036 PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation. 00037 #endif 00038 #endif 00039 #ifdef STM32F103C8 00040 GPIO_InitTypeDef GPIO_InitStructure; 00041 RCC_APB2PeriphClockCmd(RCC_PROBE_PORT, ENABLE); 00042 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 00043 #ifdef DISABLE_PROBE_PIN_PULL_UP 00044 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 00045 #else 00046 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 00047 #endif 00048 GPIO_InitStructure.GPIO_Pin = PROBE_MASK; 00049 GPIO_Init(PROBE_PORT, &GPIO_InitStructure); 00050 #endif 00051 probe_configure_invert_mask(false); // Initialize invert mask. 00052 } 00053 00054 00055 // Called by probe_init() and the mc_probe() routines. Sets up the probe pin invert mask to 00056 // appropriately set the pin logic according to setting for normal-high/normal-low operation 00057 // and the probing cycle modes for toward-workpiece/away-from-workpiece. 00058 void probe_configure_invert_mask(uint8_t is_probe_away) 00059 { 00060 probe_invert_mask = 0; // Initialize as zero. 00061 if (bit_isfalse(settings.flags,BITFLAG_INVERT_PROBE_PIN)) { probe_invert_mask ^= PROBE_MASK; } 00062 if (is_probe_away) { probe_invert_mask ^= PROBE_MASK; } 00063 } 00064 00065 00066 // Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor. 00067 uint8_t probe_get_state() 00068 { 00069 #ifdef AVRTARGET 00070 return((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask); 00071 #endif 00072 #ifdef WIN32 00073 return 0; 00074 #endif 00075 #ifdef STM32F103C8 00076 return ((GPIO_ReadInputData(PROBE_PORT) & PROBE_MASK) ^ probe_invert_mask) != 0; 00077 #endif 00078 } 00079 00080 00081 // Monitors probe pin state and records the system position when detected. Called by the 00082 // stepper ISR per ISR tick. 00083 // NOTE: This function must be extremely efficient as to not bog down the stepper ISR. 00084 void probe_state_monitor() 00085 { 00086 if (probe_get_state()) { 00087 sys_probe_state = PROBE_OFF; 00088 memcpy(sys_probe_position, sys_position, sizeof(sys_position)); 00089 bit_true(sys_rt_exec_state, EXEC_MOTION_CANCEL); 00090 } 00091 }
Generated on Tue Jul 12 2022 20:45:31 by
1.7.2