grblHAL core  20260225
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-2026 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 #if ENCODER_ENABLE > 0 && !(defined(QEI_A_PIN) && defined(QEI_B_PIN))
47 #warning "ENCODER_ENABLE requires encoder input pins A and B to be defined!"
48 #endif
49 
50 #endif
51 
52 #if MPG_ENABLE == 1 && !defined(MPG_MODE_PIN)
53 #error "MPG_MODE_PIN must be defined!"
54 #endif
55 
56 #if KEYPAD_ENABLE == 1 && !defined(I2C_STROBE_PIN)
57 #error Keypad plugin not supported!
58 #elif I2C_STROBE_ENABLE && !defined(I2C_STROBE_PIN)
59 #error "I2C strobe not supported!"
60 #endif
61 
62 #define DRIVER_PROBES ((PROBE_ENABLE ? 1 : 0) + PROBE2_ENABLE + TOOLSETTER_ENABLE)
63 
64 #ifndef CONTROL_ENABLE
65 #define CONTROL_ENABLE 0
66 #endif
67 
68 #if EEPROM_ENABLE == 0
69 #define FLASH_ENABLE 1
70 #else
71 #define FLASH_ENABLE 0
72 #endif
73 
74 #ifndef SDCARD_SDIO
75 #define SDCARD_SDIO 0
76 #endif
77 
78 #ifndef SPI_ENABLE
79 #if (SDCARD_ENABLE && !SDCARD_SDIO) || TRINAMIC_SPI_ENABLE
80 #define SPI_ENABLE 1
81 #else
82 #define SPI_ENABLE 0
83 #endif
84 #endif
85 
86 #if SDCARD_ENABLE && !SDCARD_SDIO && !defined(SD_CS_PIN)
87 #error SD card plugin not supported!
88 #endif
89 
90 // Expand port shorthand names
91 
92 #ifdef ENABLE_PORT
93 #ifdef STEPPERS_ENABLE_PIN
94 #ifndef STEPPERS_ENABLE_PORT
95 #define STEPPERS_ENABLE_PORT ENABLE_PORT
96 #endif
97 #else
98 #ifdef XY_ENABLE_PIN
99 #ifndef XY_ENABLE_PORT
100 #define XY_ENABLE_PORT ENABLE_PORT
101 #endif
102 #else
103 #ifndef X_ENABLE_PORT
104 #define X_ENABLE_PORT ENABLE_PORT
105 #endif
106 #ifndef Y_ENABLE_PORT
107 #define Y_ENABLE_PORT ENABLE_PORT
108 #endif
109 #endif
110 #ifndef Z_ENABLE_PORT
111 #define Z_ENABLE_PORT ENABLE_PORT
112 #endif
113 #if defined(M3_ENABLE_PIN) && !defined(M3_ENABLE_PORT)
114 #define M3_ENABLE_PORT ENABLE_PORT
115 #endif
116 #if defined(M4_ENABLE_PIN) && !defined(M4_ENABLE_PORT)
117 #define M4_ENABLE_PORT ENABLE_PORT
118 #endif
119 #if defined(M5_ENABLE_PIN) && !defined(M5_ENABLE_PORT)
120 #define M5_ENABLE_PORT ENABLE_PORT
121 #endif
122 #if defined(M6_ENABLE_PIN) && !defined(M6_ENABLE_PORT)
123 #define M6_ENABLE_PORT ENABLE_PORT
124 #endif
125 #if defined(M7_ENABLE_PIN) && !defined(M7_ENABLE_PORT)
126 #define M7_ENABLE_PORT ENABLE_PORT
127 #endif
128 #endif
129 #endif // ENABLE_PORT
130 
131 #ifdef STEP_PORT
132 #ifndef X_STEP_PORT
133 #define X_STEP_PORT STEP_PORT
134 #endif
135 #ifndef Y_STEP_PORT
136 #define Y_STEP_PORT STEP_PORT
137 #endif
138 #ifndef Z_STEP_PORT
139 #define Z_STEP_PORT STEP_PORT
140 #endif
141 #if defined(M3_STEP_PIN) && !defined(M3_STEP_PORT)
142 #define M3_STEP_PORT STEP_PORT
143 #endif
144 #if defined(M4_STEP_PIN) && !defined(M4_STEP_PORT)
145 #define M4_STEP_PORT STEP_PORT
146 #endif
147 #if defined(M5_STEP_PIN) && !defined(M5_STEP_PORT)
148 #define M5_STEP_PORT STEP_PORT
149 #endif
150 #if defined(M6_STEP_PIN) && !defined(M6_STEP_PORT)
151 #define M6_STEP_PORT STEP_PORT
152 #endif
153 #if defined(M7_STEP_PIN) && !defined(M7_STEP_PORT)
154 #define M7_STEP_PORT STEP_PORT
155 #endif
156 #endif // STEP_PORT
157 
158 #ifdef DIRECTION_PORT
159 #ifndef X_DIRECTION_PORT
160 #define X_DIRECTION_PORT DIRECTION_PORT
161 #endif
162 #ifndef Y_DIRECTION_PORT
163 #define Y_DIRECTION_PORT DIRECTION_PORT
164 #endif
165 #ifndef Z_DIRECTION_PORT
166 #define Z_DIRECTION_PORT DIRECTION_PORT
167 #endif
168 #if defined(M3_DIRECTION_PIN) && !defined(M3_DIRECTION_PORT)
169 #define M3_DIRECTION_PORT DIRECTION_PORT
170 #endif
171 #if defined(M4_DIRECTION_PIN) && !defined(M4_DIRECTION_PORT)
172 #define M4_DIRECTION_PORT DIRECTION_PORT
173 #endif
174 #if defined(M5_DIRECTION_PIN) && !defined(M5_DIRECTION_PORT)
175 #define M5_DIRECTION_PORT DIRECTION_PORT
176 #endif
177 #if defined(M6_DIRECTION_PIN) && !defined(M6_DIRECTION_PORT)
178 #define M6_DIRECTION_PORT DIRECTION_PORT
179 #endif
180 #if defined(M7_DIRECTION_PIN) && !defined(M7_DIRECTION_PORT)
181 #define M7_DIRECTION_PORT DIRECTION_PORT
182 #endif
183 #endif // DIRECTION_PORT
184 
185 #ifdef SPINDLE_PORT
186 #ifndef SPINDLE_ENABLE_PORT
187 #define SPINDLE_ENABLE_PORT SPINDLE_PORT
188 #endif
189 #if defined(SPINDLE_PWM_PIN) && !defined(SPINDLE_PWM_PORT)
190 #define SPINDLE_PWM_PORT SPINDLE_PORT
191 #endif
192 #if defined(SPINDLE_DIRECTION_PIN) && !defined(SPINDLE_DIRECTION_PORT)
193 #define SPINDLE_DIRECTION_PORT SPINDLE_PORT
194 #endif
195 #endif // SPINDLE_PORT
196 
197 #ifdef COOLANT_PORT
198 #if defined(COOLANT_FLOOD_PIN) && !defined(COOLANT_FLOOD_PORT)
199 #define COOLANT_FLOOD_PORT COOLANT_PORT
200 #endif
201 #if defined(COOLANT_MIST_PIN) && !defined(COOLANT_MIST_PORT)
202 #define COOLANT_MIST_PORT COOLANT_PORT
203 #endif
204 #endif // COOLANT_PORT
205 
206 // End expand port shorthand names
207 
208 #if TRINAMIC_ENABLE
209 
210 #include "motors/trinamic.h"
211 
212 #ifndef TRINAMIC_MIXED_DRIVERS
213 #define TRINAMIC_MIXED_DRIVERS 1
214 #endif
215 
216 #if TRINAMIC_UART_ENABLE == 1 && !defined(TRINAMIC_STREAM)
217 #define TRINAMIC_STREAM 1
218 #endif
219 
220 #if TRINAMIC_SPI_ENABLE == 1 || TRINAMIC_ENABLE == 2130 || TRINAMIC_ENABLE == 2660 || TRINAMIC_ENABLE == 5160
221 
222 #undef TRINAMIC_SPI_ENABLE
223 #define TRINAMIC_SPI_40BIT (1<<1)
224 #define TRINAMIC_SPI_20BIT (1<<2)
225 #define TRINAMIC_SPI_CS_SINGLE (1<<3)
226 
227 #if TRINAMIC_ENABLE == 2660
228 #ifdef MOTOR_CS_PORT
229 #define TRINAMIC_SPI_ENABLE (TRINAMIC_SPI_20BIT|TRINAMIC_SPI_CS_SINGLE)
230 #else
231 #define TRINAMIC_SPI_ENABLE TRINAMIC_SPI_20BIT
232 #endif
233 #else
234 #ifdef MOTOR_CS_PIN
235 #define TRINAMIC_SPI_ENABLE (TRINAMIC_SPI_40BIT|TRINAMIC_SPI_CS_SINGLE)
236 #else
237 #define TRINAMIC_SPI_ENABLE TRINAMIC_SPI_40BIT
238 #endif
239 #endif
240 #endif // TRINAMIC_SPI_ENABLE ...
241 
242 #endif // TRINAMIC_ENABLE
243 
244 #ifndef TRINAMIC_I2C
245 #define TRINAMIC_I2C 0
246 #endif
247 #if TRINAMIC_ENABLE && TRINAMIC_I2C
248 #define TRINAMIC_MOTOR_ENABLE 1
249 #else
250 #define TRINAMIC_MOTOR_ENABLE 0
251 #endif
252 
253 #if MPG_ENABLE && !defined(MPG_STREAM)
254 #if USB_SERIAL_CDC
255 #define MPG_STREAM 0
256 #else
257 #define MPG_STREAM 1
258 #endif
259 #if (MODBUS_ENABLE & MODBUS_RTU_ENABLED) && defined(MODBUS_RTU_STREAM) && MODBUS_RTU_STREAM == MPG_STREAM
260 #undef MPG_STREAM
261 #define MPG_STREAM (MODBUS_RTU_STREAM + 1)
262 #endif
263 #endif
264 
265 #if MPG_ENABLE && MPG_ENABLE != 2 && MPG_STREAM == 20 && BLUETOOTH_ENABLE != 1
266 #error "MPG can only be used with native Bluetooth and character mode switching!"
267 #endif
268 
269 #if BLUETOOTH_ENABLE == 2 && !defined(BLUETOOTH_STREAM)
270 #define BLUETOOTH_STREAM 255 // Select first free UART stream
271 #endif
272 
273 #if USB_SERIAL_CDC && defined(SERIAL_PORT)
274 #define SP0 1
275 #else
276 #define SP0 0
277 #endif
278 
279 #ifdef SERIAL1_PORT
280 #define SP1 1
281 #else
282 #define SP1 0
283 #endif
284 
285 #ifdef SERIAL2_PORT
286 #define SP2 1
287 #else
288 #define SP2 0
289 #endif
290 
291 #if MODBUS_ENABLE & MODBUS_RTU_ENABLED
292 #define MODBUS_TEST 1
293 #else
294 #define MODBUS_TEST 0
295 #endif
296 
297 #if TRINAMIC_ENABLE && TRINAMIC_UART_ENABLE == 1
298 #define TRINAMIC_TEST 1
299 #else
300 #define TRINAMIC_TEST 0
301 #endif
302 
303 #if MPG_ENABLE && MPG_STREAM != 20
304 #define MPG_TEST 1
305 #else
306 #define MPG_TEST 0
307 #endif
308 
309 #if KEYPAD_ENABLE == 2 && !MPG_TEST
310 #define KEYPAD_TEST 1
311 #else
312 #define KEYPAD_TEST 0
313 #endif
314 
315 #if BLUETOOTH_ENABLE == 2 && (!MPG_ENABLE || MPG_STREAM != BLUETOOTH_STREAM)
316 #define BT_TEST 1
317 #else
318 #define BT_TEST 0
319 #endif
320 
321 #if (MODBUS_TEST + KEYPAD_TEST + MPG_TEST + TRINAMIC_TEST + BT_TEST) > (SP0 + SP1 + SP2)
322 #error "Too many options that requires a serial port are enabled!"
323 #endif
324 
325 #undef SP0
326 #undef SP1
327 #undef SP2
328 #undef BT_TEST
329 #undef MODBUS_TEST
330 #undef MPG_TEST
331 #undef KEYPAD_TEST
332 #undef TRINAMIC_TEST
333 
334 #if KEYPAD_ENABLE == 2 && !defined(KEYPAD_STREAM)
335 #if MPG_ENABLE
336 #define KEYPAD_STREAM MPG_STREAM
337 #elif USB_SERIAL_CDC
338 #define KEYPAD_STREAM 0
339 #else
340 #define KEYPAD_STREAM 1
341 #endif
342 #if (MODBUS_ENABLE & MODBUS_RTU_ENABLED) && defined(MODBUS_RTU_STREAM) && MODBUS_RTU_STREAM == MPG_STREAM
343 #undef KEYPAD_STREAM
344 #define KEYPAD_STREAM (MODBUS_RTU_STREAM + 1)
345 #endif
346 #endif
347 
348 #if defined(COPROC_RESET_PIN) && defined(COPROC_BOOT0_PIN)
349 #define COPROC_PASSTHRU 1
350 #else
351 #define COPROC_PASSTHRU 0
352 #endif
353 
354 #ifndef COPROC_STREAM
355 #if USB_SERIAL_CDC
356 #define COPROC_STREAM 0
357 #else
358 #define COPROC_STREAM 1
359 #endif
360 #endif
361 
362