-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathcrossbar.c
More file actions
208 lines (178 loc) · 5.55 KB
/
crossbar.c
File metadata and controls
208 lines (178 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
crossbar.h - signal crossbar functions
Part of grblHAL
Copyright (c) 2023-2026 Terje Io
grblHAL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
grblHAL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
*/
#include "hal.h"
static limit_signals_t home_source = {0};
axes_signals_t xbar_fn_to_axismask (pin_function_t fn)
{
axes_signals_t mask = {0};
switch(fn) {
case Output_StepperEnable:
mask.bits = AXES_BITMASK;
break;
case Output_StepperEnableXY:
mask.x = mask.y = On;
break;
#if defined(A_AXIS) || defined(B_AXIS)
case Output_StepperEnableAB:
#ifdef A_AXIS
mask.a = On;
#endif
#ifdef B_AXIS
mask.b = On;
#endif
break;
#endif
case Input_LimitX:
case Input_LimitX_Max:
case Input_LimitX_2:
case Input_HomeX:
case Input_MotorFaultX:
case Input_MotorFaultX2:
case Output_StepperEnableX:
mask.x = On;
break;
case Input_LimitY:
case Input_LimitY_Max:
case Input_LimitY_2:
case Input_HomeY:
case Input_MotorFaultY:
case Input_MotorFaultY2:
case Output_StepperEnableY:
mask.y = On;
break;
case Input_LimitZ:
case Input_LimitZ_Max:
case Input_LimitZ_2:
case Input_HomeZ:
case Input_MotorFaultZ:
case Input_MotorFaultZ2:
case Output_StepperEnableZ:
mask.z = On;
break;
#ifdef A_AXIS
case Input_LimitA:
case Input_LimitA_Max:
case Input_HomeA:
case Input_MotorFaultA:
case Output_StepperEnableA:
mask.a = On;
break;
#endif
#ifdef B_AXIS
case Input_LimitB:
case Input_LimitB_Max:
case Input_HomeB:
case Input_MotorFaultB:
case Output_StepperEnableB:
mask.b = On;
break;
#endif
#ifdef C_AXIS
case Input_LimitC:
case Input_LimitC_Max:
case Input_HomeC:
case Input_MotorFaultC:
case Output_StepperEnableC:
mask.c = On;
break;
#endif
#ifdef U_AXIS
case Input_LimitU:
case Input_LimitU_Max:
case Input_HomeU:
case Input_MotorFaultU:
case Output_StepperEnableU:
mask.u = On;
break;
#endif
#ifdef V_AXIS
case Input_LimitV:
case Input_LimitV_Max:
case Input_HomeV:
case Input_MotorFaultV:
case Output_StepperEnableV:
mask.v = On;
break;
#endif
#ifdef W_AXIS
case Input_LimitW:
case Input_LimitW_Max:
case Input_HomeW:
case Input_MotorFaultW:
case Output_StepperEnableW:
mask.w = On;
break;
#endif
default:
break;
}
return mask;
}
// Sets limit signals used by homing when home signals are not available.
// For internal use, called by settings.c when homing direction mask is changed.
void xbar_set_homing_source (void)
{
if(hal.home_cap.a.mask == 0) {
home_source.max.mask = hal.limits_cap.max.mask & ((~settings.homing.dir_mask.mask) & AXES_BITMASK);
home_source.min.mask = (~home_source.max.mask) & AXES_BITMASK;
home_source.max2.mask = hal.limits_cap.max2.mask & ((~settings.homing.dir_mask.mask) & AXES_BITMASK);
home_source.min2.mask = (~home_source.max2.mask) & AXES_BITMASK;
}
}
// Returns limit signals used by homing when home signals are not available.
ISR_CODE limit_signals_t xbar_get_homing_source (void)
{
return home_source;
}
// Returns limit signals used by homing cycle when home signals are not available.
limit_signals_t xbar_get_homing_source_from_cycle (axes_signals_t homing_cycle)
{
limit_signals_t source = home_source;
if(hal.home_cap.a.mask == 0) {
source.min.mask &= homing_cycle.mask;
source.min2.mask &= homing_cycle.mask;
source.min.mask |= source.min2.mask;
source.max.mask &= homing_cycle.mask;
source.max2.mask &= homing_cycle.mask;
source.max.mask |= source.max2.mask;
}
return source;
}
const char *xbar_fn_to_pinname (pin_function_t fn)
{
const char *name = NULL;
uint_fast8_t idx = sizeof(pin_names) / sizeof(pin_name_t);
do {
if(pin_names[--idx].function == fn)
name = pin_names[idx].name;
} while(idx && !name);
return name ? name : "N/A";
}
// Only returns description for UART groups
const char *xbar_group_to_description ( pin_group_t group)
{
return group >= PinGroup_UART && group <= PinGroup_UART4 ? (const char * const[]){ "UART1", "UART2", "UART3", "UART4" }[group - PinGroup_UART] : NULL;
}
control_signals_t xbar_fn_to_signals_mask (pin_function_t fn)
{
control_signals_t signals;
signals.mask = fn >= Input_Probe ? 0 : 1 << (uint32_t)fn;
return signals;
}
const char *xbar_resolution_to_string (pin_cap_t cap)
{
return !cap.analog || cap.pwm || cap.servo_pwm ? "?" : ((const char * const[]){"4", "8", "10", "12", "14", "16", "18", "20", "24", "32"})[cap.resolution];
}