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