User | Revision | Line number | New contents of line |
Sergunb |
0:8f0d870509fe
|
1
|
/*
|
Sergunb |
0:8f0d870509fe
|
2
|
coolant_control.c - coolant control methods
|
Sergunb |
0:8f0d870509fe
|
3
|
Part of Grbl
|
Sergunb |
0:8f0d870509fe
|
4
|
|
Sergunb |
0:8f0d870509fe
|
5
|
Copyright (c) 2012-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
|
void coolant_init()
|
Sergunb |
0:8f0d870509fe
|
25
|
{
|
Sergunb |
0:8f0d870509fe
|
26
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
27
|
COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); // Configure as output pin
|
Sergunb |
0:8f0d870509fe
|
28
|
#ifdef ENABLE_M7
|
Sergunb |
0:8f0d870509fe
|
29
|
COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT);
|
Sergunb |
0:8f0d870509fe
|
30
|
#endif
|
Sergunb |
0:8f0d870509fe
|
31
|
#endif
|
Sergunb |
0:8f0d870509fe
|
32
|
#ifdef STM32F103C8
|
Sergunb |
0:8f0d870509fe
|
33
|
GPIO_InitTypeDef GPIO_InitStructure;
|
Sergunb |
0:8f0d870509fe
|
34
|
RCC_APB2PeriphClockCmd(RCC_COOLANT_FLOOD_PORT, ENABLE);
|
Sergunb |
0:8f0d870509fe
|
35
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
Sergunb |
0:8f0d870509fe
|
36
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
Sergunb |
0:8f0d870509fe
|
37
|
GPIO_InitStructure.GPIO_Pin = 1 << COOLANT_FLOOD_BIT;
|
Sergunb |
0:8f0d870509fe
|
38
|
GPIO_Init(COOLANT_FLOOD_PORT, &GPIO_InitStructure);
|
Sergunb |
0:8f0d870509fe
|
39
|
|
Sergunb |
0:8f0d870509fe
|
40
|
RCC_APB2PeriphClockCmd(RCC_COOLANT_MIST_PORT, ENABLE);
|
Sergunb |
0:8f0d870509fe
|
41
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
Sergunb |
0:8f0d870509fe
|
42
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
Sergunb |
0:8f0d870509fe
|
43
|
GPIO_InitStructure.GPIO_Pin = 1 << COOLANT_MIST_BIT;
|
Sergunb |
0:8f0d870509fe
|
44
|
GPIO_Init(COOLANT_MIST_PORT, &GPIO_InitStructure);
|
Sergunb |
0:8f0d870509fe
|
45
|
#endif
|
Sergunb |
0:8f0d870509fe
|
46
|
coolant_stop();
|
Sergunb |
0:8f0d870509fe
|
47
|
}
|
Sergunb |
0:8f0d870509fe
|
48
|
|
Sergunb |
0:8f0d870509fe
|
49
|
|
Sergunb |
0:8f0d870509fe
|
50
|
// Returns current coolant output state. Overrides may alter it from programmed state.
|
Sergunb |
0:8f0d870509fe
|
51
|
uint8_t coolant_get_state()
|
Sergunb |
0:8f0d870509fe
|
52
|
{
|
Sergunb |
0:8f0d870509fe
|
53
|
uint8_t cl_state = COOLANT_STATE_DISABLE;
|
Sergunb |
0:8f0d870509fe
|
54
|
#if defined(AVRTARGET) || defined(STM32F103C8)
|
Sergunb |
0:8f0d870509fe
|
55
|
#ifdef INVERT_COOLANT_FLOOD_PIN
|
Sergunb |
0:8f0d870509fe
|
56
|
if (bit_isfalse(
|
Sergunb |
0:8f0d870509fe
|
57
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
58
|
COOLANT_FLOOD_PORT
|
Sergunb |
0:8f0d870509fe
|
59
|
#else
|
Sergunb |
0:8f0d870509fe
|
60
|
GPIO_ReadOutputData(COOLANT_FLOOD_PORT)
|
Sergunb |
0:8f0d870509fe
|
61
|
#endif
|
Sergunb |
0:8f0d870509fe
|
62
|
,(1 << COOLANT_FLOOD_BIT))) {
|
Sergunb |
0:8f0d870509fe
|
63
|
#else
|
Sergunb |
0:8f0d870509fe
|
64
|
if (bit_istrue(
|
Sergunb |
0:8f0d870509fe
|
65
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
66
|
COOLANT_FLOOD_PORT
|
Sergunb |
0:8f0d870509fe
|
67
|
#else
|
Sergunb |
0:8f0d870509fe
|
68
|
GPIO_ReadOutputData(COOLANT_FLOOD_PORT)
|
Sergunb |
0:8f0d870509fe
|
69
|
#endif
|
Sergunb |
0:8f0d870509fe
|
70
|
,(1 << COOLANT_FLOOD_BIT))) {
|
Sergunb |
0:8f0d870509fe
|
71
|
#endif
|
Sergunb |
0:8f0d870509fe
|
72
|
cl_state |= COOLANT_STATE_FLOOD;
|
Sergunb |
0:8f0d870509fe
|
73
|
}
|
Sergunb |
0:8f0d870509fe
|
74
|
#ifdef ENABLE_M7
|
Sergunb |
0:8f0d870509fe
|
75
|
#ifdef INVERT_COOLANT_MIST_PIN
|
Sergunb |
0:8f0d870509fe
|
76
|
if (bit_isfalse(
|
Sergunb |
0:8f0d870509fe
|
77
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
78
|
COOLANT_MIST_PORT
|
Sergunb |
0:8f0d870509fe
|
79
|
#else
|
Sergunb |
0:8f0d870509fe
|
80
|
GPIO_ReadOutputData(COOLANT_MIST_PORT)
|
Sergunb |
0:8f0d870509fe
|
81
|
#endif
|
Sergunb |
0:8f0d870509fe
|
82
|
,(1 << COOLANT_MIST_BIT))) {
|
Sergunb |
0:8f0d870509fe
|
83
|
#else
|
Sergunb |
0:8f0d870509fe
|
84
|
if (bit_istrue(
|
Sergunb |
0:8f0d870509fe
|
85
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
86
|
COOLANT_MIST_PORT
|
Sergunb |
0:8f0d870509fe
|
87
|
#else
|
Sergunb |
0:8f0d870509fe
|
88
|
GPIO_ReadOutputData(COOLANT_MIST_PORT)
|
Sergunb |
0:8f0d870509fe
|
89
|
#endif
|
Sergunb |
0:8f0d870509fe
|
90
|
,(1 << COOLANT_MIST_BIT))) {
|
Sergunb |
0:8f0d870509fe
|
91
|
#endif
|
Sergunb |
0:8f0d870509fe
|
92
|
cl_state |= COOLANT_STATE_MIST;
|
Sergunb |
0:8f0d870509fe
|
93
|
}
|
Sergunb |
0:8f0d870509fe
|
94
|
#endif
|
Sergunb |
0:8f0d870509fe
|
95
|
#endif
|
Sergunb |
0:8f0d870509fe
|
96
|
return(cl_state);
|
Sergunb |
0:8f0d870509fe
|
97
|
}
|
Sergunb |
0:8f0d870509fe
|
98
|
|
Sergunb |
0:8f0d870509fe
|
99
|
|
Sergunb |
0:8f0d870509fe
|
100
|
// Directly called by coolant_init(), coolant_set_state(), and mc_reset(), which can be at
|
Sergunb |
0:8f0d870509fe
|
101
|
// an interrupt-level. No report flag set, but only called by routines that don't need it.
|
Sergunb |
0:8f0d870509fe
|
102
|
void coolant_stop()
|
Sergunb |
0:8f0d870509fe
|
103
|
{
|
Sergunb |
0:8f0d870509fe
|
104
|
#if defined(AVRTARGET) || defined(STM32F103C8)
|
Sergunb |
0:8f0d870509fe
|
105
|
#ifdef INVERT_COOLANT_FLOOD_PIN
|
Sergunb |
0:8f0d870509fe
|
106
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
107
|
COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
|
Sergunb |
0:8f0d870509fe
|
108
|
#else
|
Sergunb |
0:8f0d870509fe
|
109
|
GPIO_SetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
|
Sergunb |
0:8f0d870509fe
|
110
|
#endif
|
Sergunb |
0:8f0d870509fe
|
111
|
#else
|
Sergunb |
0:8f0d870509fe
|
112
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
113
|
COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
|
Sergunb |
0:8f0d870509fe
|
114
|
#else
|
Sergunb |
0:8f0d870509fe
|
115
|
GPIO_ResetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
|
Sergunb |
0:8f0d870509fe
|
116
|
#endif
|
Sergunb |
0:8f0d870509fe
|
117
|
#endif
|
Sergunb |
0:8f0d870509fe
|
118
|
#ifdef ENABLE_M7
|
Sergunb |
0:8f0d870509fe
|
119
|
#ifdef INVERT_COOLANT_MIST_PIN
|
Sergunb |
0:8f0d870509fe
|
120
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
121
|
COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
|
Sergunb |
0:8f0d870509fe
|
122
|
#else
|
Sergunb |
0:8f0d870509fe
|
123
|
GPIO_SetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT);
|
Sergunb |
0:8f0d870509fe
|
124
|
#endif
|
Sergunb |
0:8f0d870509fe
|
125
|
#else
|
Sergunb |
0:8f0d870509fe
|
126
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
127
|
COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
|
Sergunb |
0:8f0d870509fe
|
128
|
#else
|
Sergunb |
0:8f0d870509fe
|
129
|
GPIO_ResetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT);
|
Sergunb |
0:8f0d870509fe
|
130
|
#endif
|
Sergunb |
0:8f0d870509fe
|
131
|
#endif
|
Sergunb |
0:8f0d870509fe
|
132
|
#endif
|
Sergunb |
0:8f0d870509fe
|
133
|
#endif
|
Sergunb |
0:8f0d870509fe
|
134
|
}
|
Sergunb |
0:8f0d870509fe
|
135
|
|
Sergunb |
0:8f0d870509fe
|
136
|
|
Sergunb |
0:8f0d870509fe
|
137
|
// Main program only. Immediately sets flood coolant running state and also mist coolant,
|
Sergunb |
0:8f0d870509fe
|
138
|
// if enabled. Also sets a flag to report an update to a coolant state.
|
Sergunb |
0:8f0d870509fe
|
139
|
// Called by coolant toggle override, parking restore, parking retract, sleep mode, g-code
|
Sergunb |
0:8f0d870509fe
|
140
|
// parser program end, and g-code parser coolant_sync().
|
Sergunb |
0:8f0d870509fe
|
141
|
void coolant_set_state(uint8_t mode)
|
Sergunb |
0:8f0d870509fe
|
142
|
{
|
Sergunb |
0:8f0d870509fe
|
143
|
if (sys.abort) { return; } // Block during abort.
|
Sergunb |
0:8f0d870509fe
|
144
|
|
Sergunb |
0:8f0d870509fe
|
145
|
if (mode == COOLANT_DISABLE) {
|
Sergunb |
0:8f0d870509fe
|
146
|
|
Sergunb |
0:8f0d870509fe
|
147
|
coolant_stop();
|
Sergunb |
0:8f0d870509fe
|
148
|
|
Sergunb |
0:8f0d870509fe
|
149
|
} else {
|
Sergunb |
0:8f0d870509fe
|
150
|
|
Sergunb |
0:8f0d870509fe
|
151
|
#if defined(AVRTARGET) || defined(STM32F103C8)
|
Sergunb |
0:8f0d870509fe
|
152
|
if (mode & COOLANT_FLOOD_ENABLE) {
|
Sergunb |
0:8f0d870509fe
|
153
|
#ifdef INVERT_COOLANT_FLOOD_PIN
|
Sergunb |
0:8f0d870509fe
|
154
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
155
|
COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
|
Sergunb |
0:8f0d870509fe
|
156
|
#else
|
Sergunb |
0:8f0d870509fe
|
157
|
GPIO_ResetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
|
Sergunb |
0:8f0d870509fe
|
158
|
#endif
|
Sergunb |
0:8f0d870509fe
|
159
|
#else
|
Sergunb |
0:8f0d870509fe
|
160
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
161
|
COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
|
Sergunb |
0:8f0d870509fe
|
162
|
#else
|
Sergunb |
0:8f0d870509fe
|
163
|
GPIO_SetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
|
Sergunb |
0:8f0d870509fe
|
164
|
#endif
|
Sergunb |
0:8f0d870509fe
|
165
|
#endif
|
Sergunb |
0:8f0d870509fe
|
166
|
}
|
Sergunb |
0:8f0d870509fe
|
167
|
|
Sergunb |
0:8f0d870509fe
|
168
|
#ifdef ENABLE_M7
|
Sergunb |
0:8f0d870509fe
|
169
|
if (mode & COOLANT_MIST_ENABLE) {
|
Sergunb |
0:8f0d870509fe
|
170
|
#ifdef INVERT_COOLANT_MIST_PIN
|
Sergunb |
0:8f0d870509fe
|
171
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
172
|
COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
|
Sergunb |
0:8f0d870509fe
|
173
|
#else
|
Sergunb |
0:8f0d870509fe
|
174
|
GPIO_ResetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT);
|
Sergunb |
0:8f0d870509fe
|
175
|
#endif
|
Sergunb |
0:8f0d870509fe
|
176
|
#else
|
Sergunb |
0:8f0d870509fe
|
177
|
#ifdef AVRTARGET
|
Sergunb |
0:8f0d870509fe
|
178
|
COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
|
Sergunb |
0:8f0d870509fe
|
179
|
#else
|
Sergunb |
0:8f0d870509fe
|
180
|
GPIO_SetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT);
|
Sergunb |
0:8f0d870509fe
|
181
|
#endif
|
Sergunb |
0:8f0d870509fe
|
182
|
#endif
|
Sergunb |
0:8f0d870509fe
|
183
|
}
|
Sergunb |
0:8f0d870509fe
|
184
|
#endif
|
Sergunb |
0:8f0d870509fe
|
185
|
#endif
|
Sergunb |
0:8f0d870509fe
|
186
|
}
|
Sergunb |
0:8f0d870509fe
|
187
|
sys.report_ovr_counter = 0; // Set to report change immediately
|
Sergunb |
0:8f0d870509fe
|
188
|
}
|
Sergunb |
0:8f0d870509fe
|
189
|
|
Sergunb |
0:8f0d870509fe
|
190
|
|
Sergunb |
0:8f0d870509fe
|
191
|
// G-code parser entry-point for setting coolant state. Forces a planner buffer sync and bails
|
Sergunb |
0:8f0d870509fe
|
192
|
// if an abort or check-mode is active.
|
Sergunb |
0:8f0d870509fe
|
193
|
void coolant_sync(uint8_t mode)
|
Sergunb |
0:8f0d870509fe
|
194
|
{
|
Sergunb |
0:8f0d870509fe
|
195
|
if (sys.state == STATE_CHECK_MODE) { return; }
|
Sergunb |
0:8f0d870509fe
|
196
|
protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program.
|
Sergunb |
0:8f0d870509fe
|
197
|
coolant_set_state(mode);
|
Sergunb |
0:8f0d870509fe
|
198
|
}
|