Committer:
Sergunb
Date:
Mon Sep 04 12:03:42 2017 +0000
Revision:
0:f1834a63f7c1
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sergunb 0:f1834a63f7c1 1 /*
Sergunb 0:f1834a63f7c1 2 coolant_control.c - coolant control methods
Sergunb 0:f1834a63f7c1 3 Part of Grbl
Sergunb 0:f1834a63f7c1 4
Sergunb 0:f1834a63f7c1 5 Copyright (c) 2012-2016 Sungeun K. Jeon for Gnea Research LLC
Sergunb 0:f1834a63f7c1 6
Sergunb 0:f1834a63f7c1 7 Grbl is free software: you can redistribute it and/or modify
Sergunb 0:f1834a63f7c1 8 it under the terms of the GNU General Public License as published by
Sergunb 0:f1834a63f7c1 9 the Free Software Foundation, either version 3 of the License, or
Sergunb 0:f1834a63f7c1 10 (at your option) any later version.
Sergunb 0:f1834a63f7c1 11
Sergunb 0:f1834a63f7c1 12 Grbl is distributed in the hope that it will be useful,
Sergunb 0:f1834a63f7c1 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
Sergunb 0:f1834a63f7c1 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Sergunb 0:f1834a63f7c1 15 GNU General Public License for more details.
Sergunb 0:f1834a63f7c1 16
Sergunb 0:f1834a63f7c1 17 You should have received a copy of the GNU General Public License
Sergunb 0:f1834a63f7c1 18 along with Grbl. If not, see <http://www.gnu.org/licenses/>.
Sergunb 0:f1834a63f7c1 19 */
Sergunb 0:f1834a63f7c1 20
Sergunb 0:f1834a63f7c1 21 #include "grbl.h"
Sergunb 0:f1834a63f7c1 22
Sergunb 0:f1834a63f7c1 23
Sergunb 0:f1834a63f7c1 24 void coolant_init()
Sergunb 0:f1834a63f7c1 25 {
Sergunb 0:f1834a63f7c1 26 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 27 COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); // Configure as output pin
Sergunb 0:f1834a63f7c1 28 #ifdef ENABLE_M7
Sergunb 0:f1834a63f7c1 29 COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT);
Sergunb 0:f1834a63f7c1 30 #endif
Sergunb 0:f1834a63f7c1 31 #endif
Sergunb 0:f1834a63f7c1 32 #ifdef STM32F103C8
Sergunb 0:f1834a63f7c1 33 GPIO_InitTypeDef GPIO_InitStructure;
Sergunb 0:f1834a63f7c1 34 RCC_APB2PeriphClockCmd(RCC_COOLANT_FLOOD_PORT, ENABLE);
Sergunb 0:f1834a63f7c1 35 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
Sergunb 0:f1834a63f7c1 36 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
Sergunb 0:f1834a63f7c1 37 GPIO_InitStructure.GPIO_Pin = 1 << COOLANT_FLOOD_BIT;
Sergunb 0:f1834a63f7c1 38 GPIO_Init(COOLANT_FLOOD_PORT, &GPIO_InitStructure);
Sergunb 0:f1834a63f7c1 39
Sergunb 0:f1834a63f7c1 40 RCC_APB2PeriphClockCmd(RCC_COOLANT_MIST_PORT, ENABLE);
Sergunb 0:f1834a63f7c1 41 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
Sergunb 0:f1834a63f7c1 42 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
Sergunb 0:f1834a63f7c1 43 GPIO_InitStructure.GPIO_Pin = 1 << COOLANT_MIST_BIT;
Sergunb 0:f1834a63f7c1 44 GPIO_Init(COOLANT_MIST_PORT, &GPIO_InitStructure);
Sergunb 0:f1834a63f7c1 45 #endif
Sergunb 0:f1834a63f7c1 46 coolant_stop();
Sergunb 0:f1834a63f7c1 47 }
Sergunb 0:f1834a63f7c1 48
Sergunb 0:f1834a63f7c1 49
Sergunb 0:f1834a63f7c1 50 // Returns current coolant output state. Overrides may alter it from programmed state.
Sergunb 0:f1834a63f7c1 51 uint8_t coolant_get_state()
Sergunb 0:f1834a63f7c1 52 {
Sergunb 0:f1834a63f7c1 53 uint8_t cl_state = COOLANT_STATE_DISABLE;
Sergunb 0:f1834a63f7c1 54 #if defined(AVRTARGET) || defined(STM32F103C8)
Sergunb 0:f1834a63f7c1 55 #ifdef INVERT_COOLANT_FLOOD_PIN
Sergunb 0:f1834a63f7c1 56 if (bit_isfalse(
Sergunb 0:f1834a63f7c1 57 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 58 COOLANT_FLOOD_PORT
Sergunb 0:f1834a63f7c1 59 #else
Sergunb 0:f1834a63f7c1 60 GPIO_ReadOutputData(COOLANT_FLOOD_PORT)
Sergunb 0:f1834a63f7c1 61 #endif
Sergunb 0:f1834a63f7c1 62 ,(1 << COOLANT_FLOOD_BIT))) {
Sergunb 0:f1834a63f7c1 63 #else
Sergunb 0:f1834a63f7c1 64 if (bit_istrue(
Sergunb 0:f1834a63f7c1 65 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 66 COOLANT_FLOOD_PORT
Sergunb 0:f1834a63f7c1 67 #else
Sergunb 0:f1834a63f7c1 68 GPIO_ReadOutputData(COOLANT_FLOOD_PORT)
Sergunb 0:f1834a63f7c1 69 #endif
Sergunb 0:f1834a63f7c1 70 ,(1 << COOLANT_FLOOD_BIT))) {
Sergunb 0:f1834a63f7c1 71 #endif
Sergunb 0:f1834a63f7c1 72 cl_state |= COOLANT_STATE_FLOOD;
Sergunb 0:f1834a63f7c1 73 }
Sergunb 0:f1834a63f7c1 74 #ifdef ENABLE_M7
Sergunb 0:f1834a63f7c1 75 #ifdef INVERT_COOLANT_MIST_PIN
Sergunb 0:f1834a63f7c1 76 if (bit_isfalse(
Sergunb 0:f1834a63f7c1 77 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 78 COOLANT_MIST_PORT
Sergunb 0:f1834a63f7c1 79 #else
Sergunb 0:f1834a63f7c1 80 GPIO_ReadOutputData(COOLANT_MIST_PORT)
Sergunb 0:f1834a63f7c1 81 #endif
Sergunb 0:f1834a63f7c1 82 ,(1 << COOLANT_MIST_BIT))) {
Sergunb 0:f1834a63f7c1 83 #else
Sergunb 0:f1834a63f7c1 84 if (bit_istrue(
Sergunb 0:f1834a63f7c1 85 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 86 COOLANT_MIST_PORT
Sergunb 0:f1834a63f7c1 87 #else
Sergunb 0:f1834a63f7c1 88 GPIO_ReadOutputData(COOLANT_MIST_PORT)
Sergunb 0:f1834a63f7c1 89 #endif
Sergunb 0:f1834a63f7c1 90 ,(1 << COOLANT_MIST_BIT))) {
Sergunb 0:f1834a63f7c1 91 #endif
Sergunb 0:f1834a63f7c1 92 cl_state |= COOLANT_STATE_MIST;
Sergunb 0:f1834a63f7c1 93 }
Sergunb 0:f1834a63f7c1 94 #endif
Sergunb 0:f1834a63f7c1 95 #endif
Sergunb 0:f1834a63f7c1 96 return(cl_state);
Sergunb 0:f1834a63f7c1 97 }
Sergunb 0:f1834a63f7c1 98
Sergunb 0:f1834a63f7c1 99
Sergunb 0:f1834a63f7c1 100 // Directly called by coolant_init(), coolant_set_state(), and mc_reset(), which can be at
Sergunb 0:f1834a63f7c1 101 // an interrupt-level. No report flag set, but only called by routines that don't need it.
Sergunb 0:f1834a63f7c1 102 void coolant_stop()
Sergunb 0:f1834a63f7c1 103 {
Sergunb 0:f1834a63f7c1 104 #if defined(AVRTARGET) || defined(STM32F103C8)
Sergunb 0:f1834a63f7c1 105 #ifdef INVERT_COOLANT_FLOOD_PIN
Sergunb 0:f1834a63f7c1 106 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 107 COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
Sergunb 0:f1834a63f7c1 108 #else
Sergunb 0:f1834a63f7c1 109 GPIO_SetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
Sergunb 0:f1834a63f7c1 110 #endif
Sergunb 0:f1834a63f7c1 111 #else
Sergunb 0:f1834a63f7c1 112 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 113 COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
Sergunb 0:f1834a63f7c1 114 #else
Sergunb 0:f1834a63f7c1 115 GPIO_ResetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
Sergunb 0:f1834a63f7c1 116 #endif
Sergunb 0:f1834a63f7c1 117 #endif
Sergunb 0:f1834a63f7c1 118 #ifdef ENABLE_M7
Sergunb 0:f1834a63f7c1 119 #ifdef INVERT_COOLANT_MIST_PIN
Sergunb 0:f1834a63f7c1 120 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 121 COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
Sergunb 0:f1834a63f7c1 122 #else
Sergunb 0:f1834a63f7c1 123 GPIO_SetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT);
Sergunb 0:f1834a63f7c1 124 #endif
Sergunb 0:f1834a63f7c1 125 #else
Sergunb 0:f1834a63f7c1 126 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 127 COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
Sergunb 0:f1834a63f7c1 128 #else
Sergunb 0:f1834a63f7c1 129 GPIO_ResetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT);
Sergunb 0:f1834a63f7c1 130 #endif
Sergunb 0:f1834a63f7c1 131 #endif
Sergunb 0:f1834a63f7c1 132 #endif
Sergunb 0:f1834a63f7c1 133 #endif
Sergunb 0:f1834a63f7c1 134 }
Sergunb 0:f1834a63f7c1 135
Sergunb 0:f1834a63f7c1 136
Sergunb 0:f1834a63f7c1 137 // Main program only. Immediately sets flood coolant running state and also mist coolant,
Sergunb 0:f1834a63f7c1 138 // if enabled. Also sets a flag to report an update to a coolant state.
Sergunb 0:f1834a63f7c1 139 // Called by coolant toggle override, parking restore, parking retract, sleep mode, g-code
Sergunb 0:f1834a63f7c1 140 // parser program end, and g-code parser coolant_sync().
Sergunb 0:f1834a63f7c1 141 void coolant_set_state(uint8_t mode)
Sergunb 0:f1834a63f7c1 142 {
Sergunb 0:f1834a63f7c1 143 if (sys.abort) { return; } // Block during abort.
Sergunb 0:f1834a63f7c1 144
Sergunb 0:f1834a63f7c1 145 if (mode == COOLANT_DISABLE) {
Sergunb 0:f1834a63f7c1 146
Sergunb 0:f1834a63f7c1 147 coolant_stop();
Sergunb 0:f1834a63f7c1 148
Sergunb 0:f1834a63f7c1 149 } else {
Sergunb 0:f1834a63f7c1 150
Sergunb 0:f1834a63f7c1 151 #if defined(AVRTARGET) || defined(STM32F103C8)
Sergunb 0:f1834a63f7c1 152 if (mode & COOLANT_FLOOD_ENABLE) {
Sergunb 0:f1834a63f7c1 153 #ifdef INVERT_COOLANT_FLOOD_PIN
Sergunb 0:f1834a63f7c1 154 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 155 COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT);
Sergunb 0:f1834a63f7c1 156 #else
Sergunb 0:f1834a63f7c1 157 GPIO_ResetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
Sergunb 0:f1834a63f7c1 158 #endif
Sergunb 0:f1834a63f7c1 159 #else
Sergunb 0:f1834a63f7c1 160 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 161 COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT);
Sergunb 0:f1834a63f7c1 162 #else
Sergunb 0:f1834a63f7c1 163 GPIO_SetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT);
Sergunb 0:f1834a63f7c1 164 #endif
Sergunb 0:f1834a63f7c1 165 #endif
Sergunb 0:f1834a63f7c1 166 }
Sergunb 0:f1834a63f7c1 167
Sergunb 0:f1834a63f7c1 168 #ifdef ENABLE_M7
Sergunb 0:f1834a63f7c1 169 if (mode & COOLANT_MIST_ENABLE) {
Sergunb 0:f1834a63f7c1 170 #ifdef INVERT_COOLANT_MIST_PIN
Sergunb 0:f1834a63f7c1 171 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 172 COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT);
Sergunb 0:f1834a63f7c1 173 #else
Sergunb 0:f1834a63f7c1 174 GPIO_ResetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT);
Sergunb 0:f1834a63f7c1 175 #endif
Sergunb 0:f1834a63f7c1 176 #else
Sergunb 0:f1834a63f7c1 177 #ifdef AVRTARGET
Sergunb 0:f1834a63f7c1 178 COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT);
Sergunb 0:f1834a63f7c1 179 #else
Sergunb 0:f1834a63f7c1 180 GPIO_SetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT);
Sergunb 0:f1834a63f7c1 181 #endif
Sergunb 0:f1834a63f7c1 182 #endif
Sergunb 0:f1834a63f7c1 183 }
Sergunb 0:f1834a63f7c1 184 #endif
Sergunb 0:f1834a63f7c1 185 #endif
Sergunb 0:f1834a63f7c1 186 }
Sergunb 0:f1834a63f7c1 187 sys.report_ovr_counter = 0; // Set to report change immediately
Sergunb 0:f1834a63f7c1 188 }
Sergunb 0:f1834a63f7c1 189
Sergunb 0:f1834a63f7c1 190
Sergunb 0:f1834a63f7c1 191 // G-code parser entry-point for setting coolant state. Forces a planner buffer sync and bails
Sergunb 0:f1834a63f7c1 192 // if an abort or check-mode is active.
Sergunb 0:f1834a63f7c1 193 void coolant_sync(uint8_t mode)
Sergunb 0:f1834a63f7c1 194 {
Sergunb 0:f1834a63f7c1 195 if (sys.state == STATE_CHECK_MODE) { return; }
Sergunb 0:f1834a63f7c1 196 protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program.
Sergunb 0:f1834a63f7c1 197 coolant_set_state(mode);
Sergunb 0:f1834a63f7c1 198 }