grblHAL core  20250618
driver_opts2.h
Go to the documentation of this file.
1 /*
2  driver_opts2.h - for preprocessing options from my_machine.h, compiler symbols or from the board map file
3 
4  NOTE: This file is not used by the core, it may be included by drivers after the map file is included
5 
6  Part of grblHAL
7 
8  Copyright (c) 2024-2025 Terje Io
9 
10  grblHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  grblHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
22 */
23 
24 //
25 // NOTE: do NOT change options here - edit the driver specific my_machine.h instead!
26 //
27 
28 #ifndef WEB_BUILD
29 
30 #if (DRIVER_SPINDLE_ENABLE & SPINDLE_ENA) && !defined(SPINDLE_ENABLE_PIN)
31 #warning "Selected spindle is not supported!"
32 #endif
33 
34 #if (DRIVER_SPINDLE_ENABLE & SPINDLE_DIR) && !defined(SPINDLE_DIRECTION_PIN)
35 #warning "Selected spindle is not fully supported - no direction output!"
36 #endif
37 
38 #if (DRIVER_SPINDLE_ENABLE & SPINDLE_PWM) && !defined(SPINDLE_PWM_PIN)
39 #warning "Selected spindle is not supported!"
40 #endif
41 
42 #if (DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM) && !defined(SPINDLE1_PWM_PIN)
43 #warning "Selected spindle 1 is not supported!"
44 #endif
45 
46 #endif
47 
48 #if MPG_ENABLE == 1 && !defined(MPG_MODE_PIN)
49 #error "MPG_MODE_PIN must be defined!"
50 #endif
51 
52 #if KEYPAD_ENABLE == 1 && !defined(I2C_STROBE_PIN)
53 #error Keypad plugin not supported!
54 #elif I2C_STROBE_ENABLE && !defined(I2C_STROBE_PIN)
55 #error "I2C strobe not supported!"
56 #endif
57 
58 #define DRIVER_PROBES ((PROBE_ENABLE ? 1 : 0) + PROBE2_ENABLE + TOOLSETTER_ENABLE)
59 
60 #ifndef CONTROL_ENABLE
61 #define CONTROL_ENABLE 0
62 #endif
63 
64 #if EEPROM_ENABLE == 0
65 #define FLASH_ENABLE 1
66 #else
67 #define FLASH_ENABLE 0
68 #endif
69 
70 // Expand port shorthand names
71 
72 #ifdef ENABLE_PORT
73 #ifdef STEPPERS_ENABLE_PIN
74 #ifndef STEPPERS_ENABLE_PORT
75 #define STEPPERS_ENABLE_PORT ENABLE_PORT
76 #endif
77 #else
78 #ifdef XY_ENABLE_PIN
79 #ifndef XY_ENABLE_PORT
80 #define XY_ENABLE_PORT ENABLE_PORT
81 #endif
82 #else
83 #ifndef X_ENABLE_PORT
84 #define X_ENABLE_PORT ENABLE_PORT
85 #endif
86 #ifndef Y_ENABLE_PORT
87 #define Y_ENABLE_PORT ENABLE_PORT
88 #endif
89 #endif
90 #ifndef Z_ENABLE_PORT
91 #define Z_ENABLE_PORT ENABLE_PORT
92 #endif
93 #if defined(M3_ENABLE_PIN) && !defined(M3_ENABLE_PORT)
94 #define M3_ENABLE_PORT ENABLE_PORT
95 #endif
96 #if defined(M4_ENABLE_PIN) && !defined(M4_ENABLE_PORT)
97 #define M4_ENABLE_PORT ENABLE_PORT
98 #endif
99 #if defined(M5_ENABLE_PIN) && !defined(M5_ENABLE_PORT)
100 #define M5_ENABLE_PORT ENABLE_PORT
101 #endif
102 #if defined(M6_ENABLE_PIN) && !defined(M6_ENABLE_PORT)
103 #define M6_ENABLE_PORT ENABLE_PORT
104 #endif
105 #if defined(M7_ENABLE_PIN) && !defined(M7_ENABLE_PORT)
106 #define M7_ENABLE_PORT ENABLE_PORT
107 #endif
108 #endif
109 #endif // ENABLE_PORT
110 
111 #ifdef STEP_PORT
112 #ifndef X_STEP_PORT
113 #define X_STEP_PORT STEP_PORT
114 #endif
115 #ifndef Y_STEP_PORT
116 #define Y_STEP_PORT STEP_PORT
117 #endif
118 #ifndef Z_STEP_PORT
119 #define Z_STEP_PORT STEP_PORT
120 #endif
121 #if defined(M3_STEP_PIN) && !defined(M3_STEP_PORT)
122 #define M3_STEP_PORT STEP_PORT
123 #endif
124 #if defined(M4_STEP_PIN) && !defined(M4_STEP_PORT)
125 #define M4_STEP_PORT STEP_PORT
126 #endif
127 #if defined(M5_STEP_PIN) && !defined(M5_STEP_PORT)
128 #define M5_STEP_PORT STEP_PORT
129 #endif
130 #if defined(M6_STEP_PIN) && !defined(M6_STEP_PORT)
131 #define M6_STEP_PORT STEP_PORT
132 #endif
133 #if defined(M7_STEP_PIN) && !defined(M7_STEP_PORT)
134 #define M7_STEP_PORT STEP_PORT
135 #endif
136 #endif // STEP_PORT
137 
138 #ifdef DIRECTION_PORT
139 #ifndef X_DIRECTION_PORT
140 #define X_DIRECTION_PORT DIRECTION_PORT
141 #endif
142 #ifndef Y_DIRECTION_PORT
143 #define Y_DIRECTION_PORT DIRECTION_PORT
144 #endif
145 #ifndef Z_DIRECTION_PORT
146 #define Z_DIRECTION_PORT DIRECTION_PORT
147 #endif
148 #if defined(M3_DIRECTION_PIN) && !defined(M3_DIRECTION_PORT)
149 #define M3_DIRECTION_PORT DIRECTION_PORT
150 #endif
151 #if defined(M4_DIRECTION_PIN) && !defined(M4_DIRECTION_PORT)
152 #define M4_DIRECTION_PORT DIRECTION_PORT
153 #endif
154 #if defined(M5_DIRECTION_PIN) && !defined(M5_DIRECTION_PORT)
155 #define M5_DIRECTION_PORT DIRECTION_PORT
156 #endif
157 #if defined(M6_DIRECTION_PIN) && !defined(M6_DIRECTION_PORT)
158 #define M6_DIRECTION_PORT DIRECTION_PORT
159 #endif
160 #if defined(M7_DIRECTION_PIN) && !defined(M7_DIRECTION_PORT)
161 #define M7_DIRECTION_PORT DIRECTION_PORT
162 #endif
163 #endif // DIRECTION_PORT
164 
165 #ifdef SPINDLE_PORT
166 #ifndef SPINDLE_ENABLE_PORT
167 #define SPINDLE_ENABLE_PORT SPINDLE_PORT
168 #endif
169 #if defined(SPINDLE_PWM_PIN) && !defined(SPINDLE_PWM_PORT)
170 #define SPINDLE_PWM_PORT SPINDLE_PORT
171 #endif
172 #if defined(SPINDLE_DIRECTION_PIN) && !defined(SPINDLE_DIRECTION_PORT)
173 #define SPINDLE_DIRECTION_PORT SPINDLE_PORT
174 #endif
175 #endif // SPINDLE_PORT
176 
177 #ifdef COOLANT_PORT
178 #if defined(COOLANT_FLOOD_PIN) && !defined(COOLANT_FLOOD_PORT)
179 #define COOLANT_FLOOD_PORT COOLANT_PORT
180 #endif
181 #if defined(COOLANT_MIST_PIN) && !defined(COOLANT_MIST_PORT)
182 #define COOLANT_MIST_PORT COOLANT_PORT
183 #endif
184 #endif // COOLANT_PORT
185 
186 // End expand port shorthand names
187 
188 #if TRINAMIC_ENABLE
189 
190 #include "motors/trinamic.h"
191 
192 #ifndef TRINAMIC_MIXED_DRIVERS
193 #define TRINAMIC_MIXED_DRIVERS 1
194 #endif
195 
196 #if TRINAMIC_UART_ENABLE == 1 && !defined(TRINAMIC_STREAM)
197 #define TRINAMIC_STREAM 1
198 #endif
199 
200 #if TRINAMIC_SPI_ENABLE == 1 || TRINAMIC_ENABLE == 2130 || TRINAMIC_ENABLE == 2660 || TRINAMIC_ENABLE == 5160
201 
202 #undef TRINAMIC_SPI_ENABLE
203 #define TRINAMIC_SPI_40BIT (1<<1)
204 #define TRINAMIC_SPI_20BIT (1<<2)
205 #define TRINAMIC_SPI_CS_SINGLE (1<<3)
206 
207 #if TRINAMIC_ENABLE == 2660
208 #ifdef MOTOR_CS_PORT
209 #define TRINAMIC_SPI_ENABLE (TRINAMIC_SPI_20BIT|TRINAMIC_SPI_CS_SINGLE)
210 #else
211 #define TRINAMIC_SPI_ENABLE TRINAMIC_SPI_20BIT
212 #endif
213 #else
214 #ifdef MOTOR_CS_PIN
215 #define TRINAMIC_SPI_ENABLE (TRINAMIC_SPI_40BIT|TRINAMIC_SPI_CS_SINGLE)
216 #else
217 #define TRINAMIC_SPI_ENABLE TRINAMIC_SPI_40BIT
218 #endif
219 #endif
220 #endif // TRINAMIC_SPI_ENABLE ...
221 
222 #endif // TRINAMIC_ENABLE
223 
224 #ifndef TRINAMIC_I2C
225 #define TRINAMIC_I2C 0
226 #endif
227 #if TRINAMIC_ENABLE && TRINAMIC_I2C
228 #define TRINAMIC_MOTOR_ENABLE 1
229 #else
230 #define TRINAMIC_MOTOR_ENABLE 0
231 #endif
232 
233 #if USB_SERIAL_CDC && defined(SERIAL_PORT)
234 #define SP0 1
235 #else
236 #define SP0 0
237 #endif
238 
239 #ifdef SERIAL1_PORT
240 #define SP1 1
241 #else
242 #define SP1 0
243 #endif
244 
245 #ifdef SERIAL2_PORT
246 #define SP2 1
247 #else
248 #define SP2 0
249 #endif
250 
251 #if MODBUS_ENABLE & MODBUS_RTU_ENABLED
252 #define MODBUS_TEST 1
253 #else
254 #define MODBUS_TEST 0
255 #endif
256 
257 #if TRINAMIC_ENABLE && TRINAMIC_UART_ENABLE == 1
258 #define TRINAMIC_TEST 1
259 #else
260 #define TRINAMIC_TEST 0
261 #endif
262 
263 #if KEYPAD_ENABLE == 2 && MPG_ENABLE == 0
264 #define KEYPAD_TEST 1
265 #else
266 #define KEYPAD_TEST 0
267 #endif
268 
269 #if (MODBUS_TEST + KEYPAD_TEST + (MPG_ENABLE ? 1 : 0) + TRINAMIC_TEST + (BLUETOOTH_ENABLE == 2 ? 1 : 0)) > (SP0 + SP1 + SP2)
270 #error "Too many options that uses a serial port are enabled!"
271 #endif
272 
273 #undef SP0
274 #undef SP1
275 #undef SP2
276 #undef MODBUS_TEST
277 #undef KEYPAD_TEST
278 #undef TRINAMIC_TEST
279 
280 #if MPG_ENABLE && !defined(MPG_STREAM)
281 #if USB_SERIAL_CDC
282 #define MPG_STREAM 0
283 #else
284 #define MPG_STREAM 1
285 #endif
286 #if (MODBUS_ENABLE & MODBUS_RTU_ENABLED) && defined(MODBUS_RTU_STREAM) && MODBUS_RTU_STREAM == MPG_STREAM
287 #undef MPG_STREAM
288 #define MPG_STREAM (MODBUS_RTU_STREAM + 1)
289 #endif
290 #endif
291 
292 #if KEYPAD_ENABLE == 2 && !defined(KEYPAD_STREAM)
293 #if MPG_ENABLE
294 #define KEYPAD_STREAM MPG_STREAM
295 #elif USB_SERIAL_CDC
296 #define KEYPAD_STREAM 0
297 #else
298 #define KEYPAD_STREAM 1
299 #endif
300 #if (MODBUS_ENABLE & MODBUS_RTU_ENABLED) && defined(MODBUS_RTU_STREAM) && MODBUS_RTU_STREAM == MPG_STREAM
301 #undef KEYPAD_STREAM
302 #define KEYPAD_STREAM (MODBUS_RTU_STREAM + 1)
303 #endif
304 #endif
305 
306 #if defined(COPROC_RESET_PIN) && defined(COPROC_BOOT0_PIN)
307 #define COPROC_PASSTHRU 1
308 #else
309 #define COPROC_PASSTHRU 0
310 #endif
311 
312 #ifndef COPROC_STREAM
313 #if USB_SERIAL_CDC
314 #define COPROC_STREAM 0
315 #else
316 #define COPROC_STREAM 1
317 #endif
318 #endif
319 
320