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