grblHAL core  20241107
pin_bits_masks.h
Go to the documentation of this file.
1 /*
2  pin_bits_masks.h - for adding bit definitions and masks
3 
4  NOTE: This file is not used by the core, it may be used by drivers
5 
6  Part of grblHAL
7 
8  Copyright (c) 2021-2024 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 // Sanity checks
25 
26 #if PROBE_ENABLE && !defined(PROBE_PIN)
27 #error "Probe input is not supported in this configuration!"
28 #endif
29 
30 #if SAFETY_DOOR_ENABLE && !defined(SAFETY_DOOR_PIN)
31 #error "Safety door input is not supported in this configuration!"
32 #endif
33 
34 #if MOTOR_FAULT_ENABLE && !defined(MOTOR_FAULT_PIN)
35 #error "Motor fault input is not supported in this configuration!"
36 #endif
37 
38 #if MOTOR_WARNING_ENABLE && !defined(MOTOR_WARNING_PIN)
39 #error "Motor warning input is not supported in this configuration!"
40 #endif
41 
42 #if I2C_STROBE_ENABLE && !defined(I2C_STROBE_PIN)
43 #error "I2C keypad/strobe is not supported in this configuration!"
44 #endif
45 
46 #if MPG_ENABLE == 1 && !defined(MPG_MODE_PIN)
47 #error "MPG mode input is not supported in this configuration!"
48 #endif
49 
50 #if QEI_SELECT_ENABLE && !defined(QEI_SELECT_PIN)
51 #error "Encoder select input is not supported in this configuration!"
52 #endif
53 
54 // Control input signals
55 
56 // Define the CONTROL_PORT symbol as a shorthand in the *_map.h file if all control inputs share the same port.
57 #ifdef CONTROL_PORT
58 
59 #ifndef RESET_PORT
60 #define RESET_PORT CONTROL_PORT
61 #endif
62 #ifndef FEED_HOLD_PORT
63 #define FEED_HOLD_PORT CONTROL_PORT
64 #endif
65 #ifndef CYCLE_START_PORT
66 #define CYCLE_START_PORT CONTROL_PORT
67 #endif
68 #ifndef ESTOP_PORT
69 #define ESTOP_PORT CONTROL_PORT
70 #endif
71 #ifndef PROBE_DISCONNECT_PORT
72 #define PROBE_DISCONNECT_PORT CONTROL_PORT
73 #endif
74 #ifndef STOP_DISABLE_PORT
75 #define STOP_DISABLE_PORT CONTROL_PORT
76 #endif
77 #ifndef BLOCK_DELETE_PORT
78 #define BLOCK_DELETE_PORT CONTROL_PORT
79 #endif
80 #ifndef SINGLE_BLOCK_PORT
81 #define SINGLE_BLOCK_PORT CONTROL_PORT
82 #endif
83 #ifndef MOTOR_FAULT_PORT
84 #define MOTOR_FAULT_PORT CONTROL_PORT
85 #endif
86 #ifndef MOTOR_WARNING_PORT
87 #define MOTOR_WARNING_PORT CONTROL_PORT
88 #endif
89 #ifndef LIMITS_OVERRIDE_PORT
90 #define LIMITS_OVERRIDE_PORT CONTROL_PORT
91 #endif
92 #if SAFETY_DOOR_ENABLE && !defined(SAFETY_DOOR_PORT)
93 #define SAFETY_DOOR_PORT CONTROL_PORT
94 #endif
95 
96 #endif // CONTROL_PORT
97 
98 #ifndef RESET_BIT
99 #ifdef RESET_PIN
100 #define RESET_BIT (1<<RESET_PIN)
101 #else
102 #define RESET_BIT 0
103 #endif
104 #endif
105 
106 #ifndef FEED_HOLD_BIT
107 #ifdef FEED_HOLD_PIN
108 #define FEED_HOLD_BIT (1<<FEED_HOLD_PIN)
109 #else
110 #define FEED_HOLD_BIT 0
111 #endif
112 #endif
113 
114 #ifndef CYCLE_START_BIT
115 #ifdef CYCLE_START_PIN
116 #define CYCLE_START_BIT (1<<CYCLE_START_PIN)
117 #else
118 #define CYCLE_START_BIT 0
119 #endif
120 #endif
121 
122 #ifndef ESTOP_BIT
123 #ifdef ESTOP_PIN
124 #define ESTOP_BIT (1<<ESTOP_PIN)
125 #else
126 #define ESTOP_BIT 0
127 #endif
128 #endif
129 
130 // Optional control signals
131 
132 #ifndef SAFETY_DOOR_BIT
133 #if defined(SAFETY_DOOR_PIN) && !defined(AUX_DEVICES)
134 #define SAFETY_DOOR_BIT (1<<SAFETY_DOOR_PIN)
135 #else
136 #define SAFETY_DOOR_BIT 0
137 #endif
138 #endif
139 
140 // Optional control signals, assigned to auxillary input pins
141 
142 #ifndef MOTOR_FAULT_BIT
143 #if defined(MOTOR_FAULT_PIN) && !MOTOR_FAULT_ENABLE
144 #define MOTOR_FAULT_BIT (1<<MOTOR_FAULT_PIN)
145 #else
146 #define MOTOR_FAULT_BIT 0
147 #endif
148 #endif
149 
150 #ifndef MOTOR_WARNING_BIT
151 #if defined(MOTOR_WARNING_PIN) && !MOTOR_WARNING_ENABLE
152 #define MOTOR_WARNING_BIT (1<<MOTOR_WARNING_PIN)
153 #else
154 #define MOTOR_WARNING_BIT 0
155 #endif
156 #endif
157 
158 #ifndef PROBE_DISCONNECT_BIT
159 #if defined(PROBE_DISCONNECT_PIN) && !PROBE_DISCONNECT_ENABLE
160 #define PROBE_DISCONNECT_BIT (1<<PROBE_DISCONNECT_PIN)
161 #else
162 #define PROBE_DISCONNECT_BIT 0
163 #endif
164 #endif
165 
166 #ifndef STOP_DISABLE_BIT
167 #if defined(STOP_DISABLE_PIN) && !STOP_DISABLE_ENABLE
168 #define STOP_DISABLE_BIT (1<<STOP_DISABLE_PIN)
169 #else
170 #define STOP_DISABLE_BIT 0
171 #endif
172 #endif
173 
174 #ifndef BLOCK_DELETE_BIT
175 #if defined(BLOCK_DELETE_PIN) && !BLOCK_DELETE_ENABLE
176 #define BLOCK_DELETE_BIT (1<<BLOCK_DELETE_PIN)
177 #else
178 #define BLOCK_DELETE_BIT 0
179 #endif
180 #endif
181 
182 #ifndef SINGLE_BLOCK_BIT
183 #if defined(SINGLE_BLOCK_PIN) && !SINGLE_BLOCK_ENABLE
184 #define SINGLE_BLOCK_BIT (1<<SINGLE_BLOCK_PIN)
185 #else
186 #define SINGLE_BLOCK_BIT 0
187 #endif
188 #endif
189 
190 #ifndef LIMITS_OVERRIDE_BIT
191 #if defined(LIMITS_OVERRIDE_PIN) && !LIMITS_OVERRIDE_ENABLE
192 #define LIMITS_OVERRIDE_BIT (1<<LIMITS_OVERRIDE_PIN)
193 #else
194 #define LIMITS_OVERRIDE_BIT 0
195 #endif
196 #endif
197 
198 #if SAFETY_DOOR_ENABLE || MOTOR_FAULT_ENABLE || MOTOR_WARNING_ENABLE || PROBE_DISCONNECT_ENABLE || \
199  STOP_DISABLE_ENABLE || BLOCK_DELETE_ENABLE || SINGLE_BLOCK_ENABLE || LIMITS_OVERRIDE_ENABLE || \
200  (defined(AUX_DEVICES) && (PROBE_ENABLE || I2C_STROBE_ENABLE || MPG_ENABLE == 1 || QEI_SELECT_ENABLE)) || defined __DOXYGEN__
201 
202 #define AUX_CONTROLS_ENABLED 1
203 
204 #if PROBE_DISCONNECT_ENABLE || STOP_DISABLE_ENABLE || BLOCK_DELETE_ENABLE || SINGLE_BLOCK_ENABLE || LIMITS_OVERRIDE_ENABLE
205 #define AUX_CONTROLS_SCAN 1
206 #else
207 #define AUX_CONTROLS_SCAN 0
208 #endif
209 
210 static aux_ctrl_t aux_ctrl[] = {
211 // The following pins are bound explicitly to aux input pins
212 #if PROBE_ENABLE && defined(PROBE_PIN) && defined(AUX_DEVICES)
213 #ifdef PROBE_PORT
214  { .function = Input_Probe, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .value = 0 }, .pin = PROBE_PIN, .port = PROBE_PORT },
215 #else
216  { .function = Input_Probe, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .value = 0 }, .pin = PROBE_PIN, .port = NULL },
217 #endif
218 #endif
219 #if SAFETY_DOOR_ENABLE && defined(SAFETY_DOOR_PIN)
220 #ifdef SAFETY_DOOR_PORT
221  { .function = Input_SafetyDoor, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .safety_door_ajar = On }, .pin = SAFETY_DOOR_PIN, .port = SAFETY_DOOR_PORT },
222 #else
223  { .function = Input_SafetyDoor, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .safety_door_ajar = On }, .pin = SAFETY_DOOR_PIN, .port = NULL },
224 #endif
225 #endif
226 #if MOTOR_FAULT_ENABLE && defined(MOTOR_FAULT_PIN)
227 #ifdef MOTOR_FAULT_PORT
228  { .function = Input_MotorFault, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .motor_fault = On }, .pin = MOTOR_FAULT_PIN, .port = MOTOR_FAULT_PORT },
229 #else
230  { .function = Input_MotorFault, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .motor_fault = On }, .pin = MOTOR_FAULT_PIN, .port = NULL },
231 #endif
232 #if MOTOR_WARNING_ENABLE && defined(MOTOR_WARNING_PIN)
233 #ifdef MOTOR_WARNING_PORT
234  { .function = Input_MotorWarning, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .motor_fault = On }, .pin = MOTOR_WARNING_PIN, .port = MOTOR_WARNING_PORT },
235 #else
236  { .function = Input_MotorWarning, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .motor_warning = On }, .pin = MOTOR_WARNING_PIN, .port = NULL },
237 #endif
238 #endif
239 #endif
240 #if I2C_STROBE_ENABLE && defined(I2C_STROBE_PIN) && defined(AUX_DEVICES)
241 #ifdef I2C_STROBE_PORT
242  { .function = Input_I2CStrobe, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Change), .cap = { .value = 0 }, .pin = I2C_STROBE_PIN, .port = I2C_STROBE_PORT },
243 #else
244  { .function = Input_I2CStrobe, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Change), .cap = { .value = 0 }, .pin = I2C_STROBE_PIN, .port = NULL },
245 #endif
246 #endif
247 #if MPG_ENABLE == 1 && defined(MPG_MODE_PIN) && defined(AUX_DEVICES)
248 #ifdef MPG_MODE_PORT
249  { .function = Input_MPGSelect, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Change), .cap = { .value = 0 }, .pin = MPG_MODE_PIN, .port = MPG_MODE_PORT },
250 #else
251  { .function = Input_MPGSelect, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Change), .cap = { .value = 0 }, .pin = MPG_MODE_PIN, .port = NULL },
252 #endif
253 #endif
254 #if QEI_SELECT_ENABLE && defined(QEI_SELECT_PIN) && defined(AUX_DEVICES)
255 #ifdef QEI_SELECT_PORT
256  { .function = Input_QEI_Select, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .value = 0 }, .pin = QEI_SELECT_PIN, .port = QEI_SELECT_PORT },
257 #else
258  { .function = Input_QEI_Select, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .value = 0 }, .pin = QEI_SELECT_PIN, .port = NULL },
259 #endif
260 #endif
261 // The following pins are allocated from remaining aux inputs pool
262 #if LIMITS_OVERRIDE_ENABLE
263  { .function = Input_LimitsOverride, .aux_port = 0xFF, .irq_mode = IRQ_Mode_None, .cap = { .limits_override = On }, .pin = 0xFF, .port = NULL },
264 #endif
265 #if STOP_DISABLE_ENABLE
266  { .function = Input_StopDisable, .aux_port = 0xFF, .irq_mode = IRQ_Mode_Change, .cap = { .stop_disable = On }, .pin = 0xFF, .port = NULL },
267 #endif
268 #if BLOCK_DELETE_ENABLE
269  { .function = Input_BlockDelete, .aux_port = 0xFF, .irq_mode = IRQ_Mode_Change, .cap = { .block_delete = On }, .pin = 0xFF, .port = NULL },
270 #endif
271 #if SINGLE_BLOCK_ENABLE
272  { .function = Input_SingleBlock, .aux_port = 0xFF, .irq_mode = IRQ_Mode_Change, .cap = { .single_block = On }, .pin = 0xFF, .port = NULL },
273 #endif
274 #if PROBE_DISCONNECT_ENABLE
275  { .function = Input_ProbeDisconnect, .aux_port = 0xFF, .irq_mode = (pin_irq_mode_t)(IRQ_Mode_Rising|IRQ_Mode_Falling), .cap = { .probe_disconnected = On }, .pin = 0xFF, .port = NULL },
276 #endif
277 };
278 
279 static inline aux_ctrl_t *aux_ctrl_remap_explicit (void *port, uint8_t pin, uint8_t aux_port, void *input)
280 {
281  aux_ctrl_t *ctrl_pin = NULL;
282 
283  uint_fast8_t idx = sizeof(aux_ctrl) / sizeof(aux_ctrl_t);
284 
285  do {
286  idx--;
287  if(aux_ctrl[idx].port == port && aux_ctrl[idx].pin == pin) {
288  ctrl_pin = &aux_ctrl[idx];
289  ctrl_pin->aux_port = aux_port;
290  ctrl_pin->input = input;
291  }
292  } while(idx && ctrl_pin == NULL);
293 
294  return ctrl_pin;
295 }
296 
297 static inline aux_ctrl_t *aux_ctrl_get_pin (uint8_t aux_port)
298 {
299  aux_ctrl_t *ctrl_pin = NULL;
300 
301  uint_fast8_t idx = sizeof(aux_ctrl) / sizeof(aux_ctrl_t);
302 
303  do {
304  if(aux_ctrl[--idx].aux_port == aux_port)
305  ctrl_pin = &aux_ctrl[idx];
306  } while(idx && ctrl_pin == NULL);
307 
308  return ctrl_pin;
309 }
310 
311 static inline void aux_ctrl_irq_enable (settings_t *settings, ioport_interrupt_callback_ptr aux_irq_handler)
312 {
313  uint_fast8_t idx = sizeof(aux_ctrl) / sizeof(aux_ctrl_t);
314 
315  if(idx) do {
316  if(aux_ctrl[--idx].aux_port != 0xFF) {
317 #if PROBE_ENABLE && defined(PROBE_PIN) && defined(AUX_DEVICES)
318  if(aux_ctrl[idx].function == Input_Probe) {
319  xbar_t *xbar;
320  if((xbar = hal.port.get_pin_info(Port_Digital, Port_Input, aux_ctrl[idx].aux_port))) {
321  gpio_in_config_t cfg;
323  cfg.debounce = xbar->mode.debounce;
325  xbar->config(xbar, &cfg, false);
326  }
327  } else
328 #endif
329  if(aux_ctrl[idx].irq_mode != IRQ_Mode_None) {
330  if(aux_ctrl[idx].irq_mode & (IRQ_Mode_Falling|IRQ_Mode_Rising))
331  aux_ctrl[idx].irq_mode = (settings->control_invert.mask & aux_ctrl[idx].cap.mask) ? IRQ_Mode_Falling : IRQ_Mode_Rising;
332  hal.port.register_interrupt_handler(aux_ctrl[idx].aux_port, aux_ctrl[idx].irq_mode, aux_irq_handler);
333  }
334  }
335  } while(idx);
336 }
337 
338 typedef bool (*aux_claim_explicit_ptr)(aux_ctrl_t *aux_ctrl);
339 
340 static bool aux_ctrl_claim_port (xbar_t *properties, uint8_t port, void *data)
341 {
342  if(ioport_claim(Port_Digital, Port_Input, &port, xbar_fn_to_pinname(((aux_ctrl_t *)data)->function)))
343  ((aux_ctrl_t *)data)->aux_port = port;
344 
345  return ((aux_ctrl_t *)data)->aux_port != 0xFF;
346 }
347 
348 static inline void aux_ctrl_claim_ports (aux_claim_explicit_ptr aux_claim_explicit, ioports_enumerate_callback_ptr aux_claim)
349 {
350  uint_fast8_t idx;
351 
352  if(aux_claim == NULL)
353  aux_claim = aux_ctrl_claim_port;
354 
355  for(idx = 0; idx < sizeof(aux_ctrl) / sizeof(aux_ctrl_t); idx++) {
356  if(aux_ctrl[idx].pin == 0xFF) {
357  if(ioports_enumerate(Port_Digital, Port_Input, (pin_cap_t){ .irq_mode = aux_ctrl[idx].irq_mode, .claimable = On }, aux_claim, (void *)&aux_ctrl[idx]))
358  hal.signals_cap.mask |= aux_ctrl[idx].cap.mask;
359  } else if(aux_ctrl[idx].aux_port != 0xFF)
360  aux_claim_explicit(&aux_ctrl[idx]);
361  }
362 }
363 
364 #if AUX_CONTROLS_SCAN
365 
366 static inline control_signals_t aux_ctrl_scan_status (control_signals_t signals)
367 {
368  uint_fast8_t idx = sizeof(aux_ctrl) / sizeof(aux_ctrl_t);
369 
370  if(idx) do {
371  if(aux_ctrl[--idx].pin != 0xFF)
372  break;
373  if(aux_ctrl[idx].aux_port != 0xFF) {
374  signals.mask &= ~aux_ctrl[idx].cap.mask;
375 #ifdef GRBL_ESP32 // Snowflake guru workaround
376  if(hal.port.wait_on_input(Port_Digital, aux_ctrl[idx].aux_port, WaitMode_Immediate, FZERO) == 1)
377  signals.mask |= aux_ctrl[idx].cap.mask;
378 #else
379  if(hal.port.wait_on_input(Port_Digital, aux_ctrl[idx].aux_port, WaitMode_Immediate, 0.0f) == 1)
380  signals.mask |= aux_ctrl[idx].cap.mask;
381 #endif
382  }
383  } while(idx);
384 
385  return signals;
386 }
387 
388 #endif
389 
390 #else
391 #define AUX_CONTROLS_ENABLED 0
392 #define AUX_CONTROLS_SCAN 0
393 #endif
394 
395 #ifdef AUX_CONTROLS_OUT
396 
397 // The following pins are bound explicitly to aux output pins
398 static aux_ctrl_out_t aux_ctrl_out[] = {
399 #if DRIVER_SPINDLE_ENABLE
400  { .function = Output_SpindleOn, .aux_port = 0xFF, .pin = SPINDLE_ENABLE_PIN, .port = SPINDLE_ENABLE_PORT },
401 #if DRIVER_SPINDLE_PWM_ENABLE
402  { .function = Output_SpindlePWM, .aux_port = 0xFF, .pin = SPINDLE_PWM_PIN, .port = SPINDLE_PWM_PORT },
403 #endif
404 #if DRIVER_SPINDLE_DIR_ENABLE
405  { .function = Output_SpindleDir, .aux_port = 0xFF, .pin = SPINDLE_DIRECTION_PIN, .port = SPINDLE_DIRECTION_PORT },
406 #endif
407 #endif // DRIVER_SPINDLE_ENABLE
408 #if DRIVER_SPINDLE1_ENABLE
409  { .function = Output_Spindle1On, .aux_port = 0xFF, .pin = SPINDLE1_ENABLE_PIN, .port = SPINDLE1_ENABLE_PORT },
410 #if DRIVER_SPINDLE1_PWM_ENABLE
411  { .function = Output_Spindle1PWM, .aux_port = 0xFF, .pin = SPINDLE1_PWM_PIN, .port = SPINDLE1_PWM_PORT },
412 #endif
413 #if DRIVER_SPINDLE1_DIR_ENABLE
414  { .function = Output_Spindle1Dir, .aux_port = 0xFF, .pin = SPINDLE1_DIRECTION_PIN, .port = SPINDLE1_DIRECTION_PORT },
415 #endif
416 #endif // DRIVER_SPINDLE1_DIR_ENABLE
417 /*
418 #ifdef COOLANT_FLOOD_PIN
419  { .function = Output_CoolantFlood, .aux_port = 0xFF, .pin = COOLANT_FLOOD_PIN, .port = COOLANT_FLOOD_PORT },
420 #endif
421 #ifdef COOLANT_MIST_PIN
422  { .function = Output_CoolantMist, .aux_port = 0xFF, .pin = COOLANT_MIST_PIN, .port = COOLANT_MIST_PORT },
423 #endif
424 */
425 };
426 
427 static inline aux_ctrl_out_t *aux_out_remap_explicit (void *port, uint8_t pin, uint8_t aux_port, void *output)
428 {
429  aux_ctrl_out_t *ctrl_pin = NULL;
430 
431  uint_fast8_t idx = sizeof(aux_ctrl_out) / sizeof(aux_ctrl_out_t);
432 
433  if(idx) do {
434  idx--;
435  if(aux_ctrl_out[idx].port == port && aux_ctrl_out[idx].pin == pin) {
436  ctrl_pin = &aux_ctrl_out[idx];
437  ctrl_pin->aux_port = aux_port;
438  ctrl_pin->output = output;
439  }
440  } while(idx && ctrl_pin == NULL);
441 
442  return ctrl_pin;
443 }
444 
445 typedef bool (*aux_claim_explicit_out_ptr)(aux_ctrl_out_t *aux_ctrl);
446 
447 static bool aux_ctrl_claim_out_port (xbar_t *properties, uint8_t port, void *data)
448 {
449  if(ioport_claim(Port_Digital, Port_Output, &port, xbar_fn_to_pinname(((aux_ctrl_t *)data)->function)))
450  ((aux_ctrl_t *)data)->aux_port = port;
451 
452  return ((aux_ctrl_t *)data)->aux_port != 0xFF;
453 }
454 
455 static inline void aux_ctrl_claim_out_ports (aux_claim_explicit_out_ptr aux_claim_explicit, ioports_enumerate_callback_ptr aux_claim)
456 {
457  uint_fast8_t idx;
458 
459  if(aux_claim == NULL)
460  aux_claim = aux_ctrl_claim_out_port;
461 
462  for(idx = 0; idx < sizeof(aux_ctrl_out) / sizeof(aux_ctrl_out_t); idx++) {
463  if(aux_ctrl_out[idx].pin == 0xFF)
464  ioports_enumerate(Port_Digital, Port_Output, (pin_cap_t){ .claimable = On }, aux_claim, (void *)&aux_ctrl_out[idx]);
465  else if(aux_ctrl_out[idx].aux_port != 0xFF)
466  aux_claim_explicit(&aux_ctrl_out[idx]);
467  }
468 }
469 
470 #endif // AUX_CONTROLS_OUT
471 
472 //
473 
474 #ifndef CONTROL_MASK
475 #if SAFETY_DOOR_ENABLE
476 #define CONTROL_MASK (RESET_BIT|FEED_HOLD_BIT|CYCLE_START_BIT|ESTOP_BIT|PROBE_DISCONNECT_BIT|STOP_DISABLE_BIT|BLOCK_DELETE_BIT|SINGLE_BLOCK_BIT|MOTOR_FAULT_BIT|MOTOR_WARNING_BIT|LIMITS_OVERRIDE_BIT|SAFETY_DOOR_BIT)
477 #define CONTROL_MASK_SUM (RESET_BIT+FEED_HOLD_BIT+CYCLE_START_BIT+ESTOP_BIT+PROBE_DISCONNECT_BIT+STOP_DISABLE_BIT+BLOCK_DELETE_BIT+SINGLE_BLOCK_BIT+MOTOR_FAULT_BIT+MOTOR_WARNING_BIT+LIMITS_OVERRIDE_BIT+SAFETY_DOOR_BIT)
478 #else
479 #define CONTROL_MASK (RESET_BIT|FEED_HOLD_BIT|CYCLE_START_BIT|ESTOP_BIT|PROBE_DISCONNECT_BIT|STOP_DISABLE_BIT|BLOCK_DELETE_BIT|SINGLE_BLOCK_BIT|MOTOR_FAULT_BIT|MOTOR_WARNING_BIT|LIMITS_OVERRIDE_BIT)
480 #define CONTROL_MASK_SUM (RESET_BIT+FEED_HOLD_BIT+CYCLE_START_BIT+ESTOP_BIT+PROBE_DISCONNECT_BIT+STOP_DISABLE_BIT+BLOCK_DELETE_BIT+SINGLE_BLOCK_BIT+MOTOR_FAULT_BIT+MOTOR_WARNING_BIT+LIMITS_OVERRIDE_BIT)
481 #endif
482 #endif
483 
484 // Output Signals
485 
486 #if defined(SPINDLE_ENABLE_PIN) && !defined(SPINDLE_ENABLE_BIT)
487 #define SPINDLE_ENABLE_BIT (1<<SPINDLE_ENABLE_PIN)
488 #endif
489 #if defined(SPINDLE_DIRECTION_PIN) && !defined(SPINDLE_DIRECTION_BIT)
490 #define SPINDLE_DIRECTION_BIT (1<<SPINDLE_DIRECTION_PIN)
491 #endif
492 
493 #if defined(SPINDLE1_ENABLE_PIN) && !defined(SPINDLE1_ENABLE_BIT)
494 #define SPINDLE1_ENABLE_BIT (1<<SPINDLE1_ENABLE_PIN)
495 #endif
496 #if defined(SPINDLE1_DIRECTION_PIN) && !defined(SPINDLE1_DIRECTION_BIT)
497 #define SPINDLE1_DIRECTION_BIT (1<<SPINDLE1_DIRECTION_PIN)
498 #endif
499 
500 #if defined(COOLANT_FLOOD_PIN) && !defined(COOLANT_FLOOD_BIT)
501 #define COOLANT_FLOOD_BIT (1<<COOLANT_FLOOD_PIN)
502 #endif
503 #if defined(COOLANT_MIST_PIN) && !defined(COOLANT_MIST_BIT)
504 #define COOLANT_MIST_BIT (1<<COOLANT_MIST_PIN)
505 #endif
506 
507 #if defined(RTS_PIN) && !defined(RTS_BIT)
508 #define RTS_BIT (1<<RTS_PIN)
509 #endif
510 
511 // IRQ enabled input singnals
512 
513 #ifndef AUX_DEVICES
514 
515 // IRQ capability for the probe input is optional
516 #if defined(PROBE_PIN) && !defined(PROBE_BIT)
517 #define PROBE_BIT (1<<PROBE_PIN)
518 #endif
519 
520 #if defined(MPG_MODE_PIN) && !defined(MPG_MODE_BIT)
521 #define MPG_MODE_BIT (1<<MPG_MODE_PIN)
522 #endif
523 
524 #if defined(I2C_STROBE_PIN) && !defined(I2C_STROBE_BIT)
525 #define I2C_STROBE_BIT (1<<I2C_STROBE_PIN)
526 #endif
527 
528 #if defined(QEI_SELECT_PIN) && !defined(QEI_SELECT_BIT)
529 #define QEI_SELECT_BIT (1<<QEI_SELECT_PIN)
530 #endif
531 
532 #endif // !AUX_DEVICES
533 
534 #if QEI_ENABLE
535 #ifndef QEI_A_BIT
536 #define QEI_A_BIT (1<<QEI_A_PIN)
537 #endif
538 #ifndef QEI_B_BIT
539 #define QEI_B_BIT (1<<QEI_B_PIN)
540 #endif
541 #else
542 #define QEI_A_BIT 0
543 #define QEI_B_BIT 0
544 #endif
545 
546 #ifndef QEI_SELECT_BIT
547 #define QEI_SELECT_BIT 0
548 #endif
549 #ifndef MPG_MODE_BIT
550 #define MPG_MODE_BIT 0
551 #endif
552 #ifndef I2C_STROBE_BIT
553 #define I2C_STROBE_BIT 0
554 #endif
555 
556 // Do NOT #define PROBE_BIT 0 here!
557 
558 #if SPINDLE_ENCODER_ENABLE
559 #ifndef SPINDLE_PULSE_PIN
560 #error "Spindle encoder requires at least SPINDLE_PULSE_PIN defined in the board map!"
561 #endif
562 #if !defined(SPINDLE_PULSE_BIT) && defined(SPINDLE_PULSE_PIN)
563 #define SPINDLE_PULSE_BIT (1<<SPINDLE_PULSE_PIN)
564 #endif
565 #if !defined(SPINDLE_INDEX_BIT) && defined(SPINDLE_INDEX_PIN)
566 #define SPINDLE_INDEX_BIT (1<<SPINDLE_INDEX_PIN)
567 #endif
568 #endif
569 
570 #ifndef SPINDLE_INDEX_BIT
571 #define SPINDLE_INDEX_BIT 0
572 #endif
573 #ifndef SPINDLE_PULSE_BIT
574 #define SPINDLE_PULSE_BIT 0
575 #endif
576 
577 #if SPINDLE_SYNC_ENABLE && (SPINDLE_INDEX_BIT + SPINDLE_PULSE_BIT) == 0
578 #error "Spindle sync requires SPINDLE_PULSE_PIN and SPINDLE_INDEX_PIN defined in the board map!"
579 #endif
580 
581 #ifndef SPI_IRQ_PIN
582 #define SPI_IRQ_BIT 0
583 #elif !defined(SPI_IRQ_BIT)
584 #define SPI_IRQ_BIT (1<<SPI_IRQ_PIN)
585 #endif
586 
587 #ifndef DEVICES_IRQ_MASK
588 #ifdef AUX_DEVICES
589 #define DEVICES_IRQ_MASK (SPI_IRQ_BIT|SPINDLE_INDEX_BIT|QEI_A_BIT|QEI_B_BIT)
590 #define DEVICES_IRQ_MASK_SUM (SPI_IRQ_BIT+SPINDLE_INDEX_BIT+QEI_A_BIT+QEI_B_BIT)
591 #else
592 #define DEVICES_IRQ_MASK (MPG_MODE_BIT|I2C_STROBE_BIT|QEI_SELECT_BIT|SPI_IRQ_BIT|SPINDLE_INDEX_BIT|QEI_A_BIT|QEI_B_BIT)
593 #define DEVICES_IRQ_MASK_SUM (MPG_MODE_BIT+I2C_STROBE_BIT+QEI_SELECT_BIT+SPI_IRQ_BIT+SPINDLE_INDEX_BIT+QEI_A_BIT+QEI_B_BIT)
594 #endif
595 #endif
596 
597 // Auxillary input signals
598 
599 #ifdef AUXINPUT0_PIN
600 #define AUXINPUT0_BIT (1<<AUXINPUT0_PIN)
601 #else
602 #define AUXINPUT0_BIT 0
603 #endif
604 #ifdef AUXINPUT1_PIN
605 #define AUXINPUT1_BIT (1<<AUXINPUT1_PIN)
606 #else
607 #define AUXINPUT1_BIT 0
608 #endif
609 #ifdef AUXINPUT2_PIN
610 #define AUXINPUT2_BIT (1<<AUXINPUT2_PIN)
611 #else
612 #define AUXINPUT2_BIT 0
613 #endif
614 #ifdef AUXINPUT3_PIN
615 #define AUXINPUT3_BIT (1<<AUXINPUT3_PIN)
616 #else
617 #define AUXINPUT3_BIT 0
618 #endif
619 #ifdef AUXINPUT4_PIN
620 #define AUXINPUT4_BIT (1<<AUXINPUT4_PIN)
621 #else
622 #define AUXINPUT4_BIT 0
623 #endif
624 #ifdef AUXINPUT5_PIN
625 #define AUXINPUT5_BIT (1<<AUXINPUT5_PIN)
626 #else
627 #define AUXINPUT5_BIT 0
628 #endif
629 #ifdef AUXINPUT6_PIN
630 #define AUXINPUT6_BIT (1<<AUXINPUT6_PIN)
631 #else
632 #define AUXINPUT6_BIT 0
633 #endif
634 #ifdef AUXINPUT7_PIN
635 #define AUXINPUT7_BIT (1<<AUXINPUT7_PIN)
636 #else
637 #define AUXINPUT7_BIT 0
638 #endif
639 
640 #ifndef AUXINPUT_MASK
641 #define AUXINPUT_MASK (AUXINPUT0_BIT|AUXINPUT1_BIT|AUXINPUT2_BIT|AUXINPUT3_BIT|AUXINPUT4_BIT|AUXINPUT5_BIT|AUXINPUT6_BIT|AUXINPUT7_BIT)
642 #define AUXINPUT_MASK_SUM (AUXINPUT0_BIT+AUXINPUT1_BIT+AUXINPUT2_BIT+AUXINPUT3_BIT+AUXINPUT4_BIT+AUXINPUT5_BIT+AUXINPUT6_BIT+AUXINPUT7_BIT)
643 #endif
644 
645 /*EOF*/
const char * xbar_fn_to_pinname(pin_function_t fn)
Definition: crossbar.c:131
@ PullMode_None
0b00 (0x00)
Definition: crossbar.h:485
@ PullMode_Up
0b01 (0x01)
Definition: crossbar.h:486
@ Input_Probe
Definition: crossbar.h:43
@ Input_MotorFault
Definition: crossbar.h:37
@ Input_MotorWarning
Definition: crossbar.h:38
@ Input_ProbeDisconnect
Definition: crossbar.h:36
@ Input_StopDisable
Definition: crossbar.h:34
@ Input_LimitsOverride
Definition: crossbar.h:39
@ Input_QEI_Select
Definition: crossbar.h:206
@ Input_BlockDelete
Definition: crossbar.h:33
@ Output_SpindleDir
Definition: crossbar.h:147
@ Input_SingleBlock
Definition: crossbar.h:40
@ Output_SpindleOn
Definition: crossbar.h:146
@ Input_I2CStrobe
Definition: crossbar.h:200
@ Output_Spindle1Dir
Definition: crossbar.h:150
@ Output_SpindlePWM
Definition: crossbar.h:148
@ Input_MPGSelect
Definition: crossbar.h:45
@ Output_Spindle1On
Definition: crossbar.h:149
@ Input_SafetyDoor
Definition: crossbar.h:32
@ Output_Spindle1PWM
Definition: crossbar.h:151
pin_irq_mode_t
Pin interrupt modes, may be or'ed when reporting pin capability.
Definition: crossbar.h:458
@ IRQ_Mode_Rising
0b00001 (0x01)
Definition: crossbar.h:460
@ IRQ_Mode_None
0b00000 (0x00)
Definition: crossbar.h:459
@ IRQ_Mode_Change
0b00100 (0x04)
Definition: crossbar.h:463
@ IRQ_Mode_Falling
0b00010 (0x02)
Definition: crossbar.h:461
@ WaitMode_Immediate
0 - This is the only mode allowed for analog inputs
Definition: gcode.h:279
grbl_hal_t hal
Global HAL struct.
Definition: grbllib.c:88
bool ioport_claim(io_port_type_t type, io_port_direction_t dir, uint8_t *port, const char *description)
Claim a digital or analog port for exclusive use.
Definition: ioports.c:140
bool ioports_enumerate(io_port_type_t type, io_port_direction_t dir, pin_cap_t filter, ioports_enumerate_callback_ptr callback, void *data)
Definition: ioports.c:215
@ Port_Input
0
Definition: ioports.h:30
@ Port_Output
1
Definition: ioports.h:31
bool(* ioports_enumerate_callback_ptr)(xbar_t *properties, uint8_t port, void *data)
Definition: ioports.h:108
@ Port_Digital
1
Definition: ioports.h:26
void(* ioport_interrupt_callback_ptr)(uint8_t port, bool state)
Pointer to callback function for input port interrupt events.
Definition: ioports.h:98
#define On
Definition: nuts_bolts.h:36
bool(* aux_claim_explicit_ptr)(aux_ctrl_t *aux_ctrl)
Definition: pin_bits_masks.h:338
settings_t settings
Definition: settings.c:43
Definition: crossbar.h:616
uint8_t aux_port
Definition: crossbar.h:618
void * output
Definition: crossbar.h:621
pin_function_t function
Definition: crossbar.h:617
Definition: crossbar.h:606
uint8_t aux_port
Definition: crossbar.h:608
control_signals_t cap
Definition: crossbar.h:610
pin_irq_mode_t irq_mode
Definition: crossbar.h:609
void * input
Definition: crossbar.h:613
pin_function_t function
Definition: crossbar.h:607
/a cfg_data argument to /a xbar_config_ptr for gpio input pins
Definition: crossbar.h:567
bool debounce
Definition: crossbar.h:569
bool inverted
Definition: crossbar.h:568
pull_mode_t pull_mode
Definition: crossbar.h:570
io_port_t port
Optional handlers for axuillary I/O (adds support for M62-M66).
Definition: hal.h:621
control_signals_t signals_cap
Control input signals supported by the driver.
Definition: hal.h:656
wait_on_input_ptr wait_on_input
Optional handler for reading a digital or analog input.
Definition: ioports.h:118
ioport_register_interrupt_handler_ptr register_interrupt_handler
Definition: ioports.h:123
get_pin_info_ptr get_pin_info
Optional handler for getting information about an auxiliary pin.
Definition: ioports.h:120
Definition: settings.h:804
control_signals_t control_invert
Definition: settings.h:817
probeflags_t probe
Definition: settings.h:827
Definition: crossbar.h:624
pin_mode_t mode
Current pin configuration.
Definition: crossbar.h:632
xbar_config_ptr config
Optional pointer to function for configuring the port.
Definition: crossbar.h:633
Definition: system.h:123
uint16_t mask
Definition: system.h:125
Definition: crossbar.h:502
uint16_t debounce
Definition: crossbar.h:532
uint8_t disable_probe_pullup
Definition: settings.h:580
uint8_t invert_probe_pin
Definition: settings.h:579