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.
coolant_control.c
00001 /* 00002 coolant_control.c - coolant control methods 00003 Part of Grbl 00004 00005 Copyright (c) 2012-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 void coolant_init() 00025 { 00026 #ifdef AVRTARGET 00027 COOLANT_FLOOD_DDR |= (1 << COOLANT_FLOOD_BIT); // Configure as output pin 00028 #ifdef ENABLE_M7 00029 COOLANT_MIST_DDR |= (1 << COOLANT_MIST_BIT); 00030 #endif 00031 #endif 00032 #ifdef STM32F103C8 00033 GPIO_InitTypeDef GPIO_InitStructure; 00034 RCC_APB2PeriphClockCmd(RCC_COOLANT_FLOOD_PORT, ENABLE); 00035 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 00036 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 00037 GPIO_InitStructure.GPIO_Pin = 1 << COOLANT_FLOOD_BIT; 00038 GPIO_Init(COOLANT_FLOOD_PORT, &GPIO_InitStructure); 00039 00040 RCC_APB2PeriphClockCmd(RCC_COOLANT_MIST_PORT, ENABLE); 00041 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 00042 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 00043 GPIO_InitStructure.GPIO_Pin = 1 << COOLANT_MIST_BIT; 00044 GPIO_Init(COOLANT_MIST_PORT, &GPIO_InitStructure); 00045 #endif 00046 coolant_stop(); 00047 } 00048 00049 00050 // Returns current coolant output state. Overrides may alter it from programmed state. 00051 uint8_t coolant_get_state() 00052 { 00053 uint8_t cl_state = COOLANT_STATE_DISABLE; 00054 #if defined(AVRTARGET) || defined(STM32F103C8) 00055 #ifdef INVERT_COOLANT_FLOOD_PIN 00056 if (bit_isfalse( 00057 #ifdef AVRTARGET 00058 COOLANT_FLOOD_PORT 00059 #else 00060 GPIO_ReadOutputData(COOLANT_FLOOD_PORT) 00061 #endif 00062 ,(1 << COOLANT_FLOOD_BIT))) { 00063 #else 00064 if (bit_istrue( 00065 #ifdef AVRTARGET 00066 COOLANT_FLOOD_PORT 00067 #else 00068 GPIO_ReadOutputData(COOLANT_FLOOD_PORT) 00069 #endif 00070 ,(1 << COOLANT_FLOOD_BIT))) { 00071 #endif 00072 cl_state |= COOLANT_STATE_FLOOD; 00073 } 00074 #ifdef ENABLE_M7 00075 #ifdef INVERT_COOLANT_MIST_PIN 00076 if (bit_isfalse( 00077 #ifdef AVRTARGET 00078 COOLANT_MIST_PORT 00079 #else 00080 GPIO_ReadOutputData(COOLANT_MIST_PORT) 00081 #endif 00082 ,(1 << COOLANT_MIST_BIT))) { 00083 #else 00084 if (bit_istrue( 00085 #ifdef AVRTARGET 00086 COOLANT_MIST_PORT 00087 #else 00088 GPIO_ReadOutputData(COOLANT_MIST_PORT) 00089 #endif 00090 ,(1 << COOLANT_MIST_BIT))) { 00091 #endif 00092 cl_state |= COOLANT_STATE_MIST; 00093 } 00094 #endif 00095 #endif 00096 return(cl_state); 00097 } 00098 00099 00100 // Directly called by coolant_init(), coolant_set_state(), and mc_reset(), which can be at 00101 // an interrupt-level. No report flag set, but only called by routines that don't need it. 00102 void coolant_stop() 00103 { 00104 #if defined(AVRTARGET) || defined(STM32F103C8) 00105 #ifdef INVERT_COOLANT_FLOOD_PIN 00106 #ifdef AVRTARGET 00107 COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); 00108 #else 00109 GPIO_SetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT); 00110 #endif 00111 #else 00112 #ifdef AVRTARGET 00113 COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); 00114 #else 00115 GPIO_ResetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT); 00116 #endif 00117 #endif 00118 #ifdef ENABLE_M7 00119 #ifdef INVERT_COOLANT_MIST_PIN 00120 #ifdef AVRTARGET 00121 COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); 00122 #else 00123 GPIO_SetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT); 00124 #endif 00125 #else 00126 #ifdef AVRTARGET 00127 COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); 00128 #else 00129 GPIO_ResetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT); 00130 #endif 00131 #endif 00132 #endif 00133 #endif 00134 } 00135 00136 00137 // Main program only. Immediately sets flood coolant running state and also mist coolant, 00138 // if enabled. Also sets a flag to report an update to a coolant state. 00139 // Called by coolant toggle override, parking restore, parking retract, sleep mode, g-code 00140 // parser program end, and g-code parser coolant_sync(). 00141 void coolant_set_state(uint8_t mode) 00142 { 00143 if (sys.abort) { return; } // Block during abort. 00144 00145 if (mode == COOLANT_DISABLE) { 00146 00147 coolant_stop(); 00148 00149 } else { 00150 00151 #if defined(AVRTARGET) || defined(STM32F103C8) 00152 if (mode & COOLANT_FLOOD_ENABLE) { 00153 #ifdef INVERT_COOLANT_FLOOD_PIN 00154 #ifdef AVRTARGET 00155 COOLANT_FLOOD_PORT &= ~(1 << COOLANT_FLOOD_BIT); 00156 #else 00157 GPIO_ResetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT); 00158 #endif 00159 #else 00160 #ifdef AVRTARGET 00161 COOLANT_FLOOD_PORT |= (1 << COOLANT_FLOOD_BIT); 00162 #else 00163 GPIO_SetBits(COOLANT_FLOOD_PORT,1 << COOLANT_FLOOD_BIT); 00164 #endif 00165 #endif 00166 } 00167 00168 #ifdef ENABLE_M7 00169 if (mode & COOLANT_MIST_ENABLE) { 00170 #ifdef INVERT_COOLANT_MIST_PIN 00171 #ifdef AVRTARGET 00172 COOLANT_MIST_PORT &= ~(1 << COOLANT_MIST_BIT); 00173 #else 00174 GPIO_ResetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT); 00175 #endif 00176 #else 00177 #ifdef AVRTARGET 00178 COOLANT_MIST_PORT |= (1 << COOLANT_MIST_BIT); 00179 #else 00180 GPIO_SetBits(COOLANT_MIST_PORT, 1 << COOLANT_MIST_BIT); 00181 #endif 00182 #endif 00183 } 00184 #endif 00185 #endif 00186 } 00187 sys.report_ovr_counter = 0; // Set to report change immediately 00188 } 00189 00190 00191 // G-code parser entry-point for setting coolant state. Forces a planner buffer sync and bails 00192 // if an abort or check-mode is active. 00193 void coolant_sync(uint8_t mode) 00194 { 00195 if (sys.state == STATE_CHECK_MODE) { return; } 00196 protocol_buffer_synchronize(); // Ensure coolant turns on when specified in program. 00197 coolant_set_state(mode); 00198 }
Generated on Tue Jul 12 2022 20:45:31 by
1.7.2