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