8
8
9
9
import skidl
10
10
11
- KISWITCH_LIBRARY_METADATA = {
12
- "modules" : {
13
- "MX" : {
14
- "name" : "Switch_Keyboard_Cherry_MX" ,
15
- "footprint-nameformat" : "SW_Cherry_MX_PCB_{:.2f}u" ,
16
- "iso-enter" : "SW_Cherry_MX_PCB_ISOEnter" ,
17
- },
18
- "Alps" : {
19
- "name" : "Switch_Keyboard_Alps_Matias" ,
20
- "footprint-nameformat" : "SW_Alps_Matias_{:.2f}u" ,
21
- "iso-enter" : "SW_Alps_Matias_ISOEnter" ,
22
- },
23
- "MX/Alps Hybrid" : {
24
- "name" : "Switch_Keyboard_Hybrid" ,
25
- "footprint-nameformat" : "SW_Hybrid_Cherry_MX_Alps_{:.2f}u" ,
26
- "iso-enter" : "SW_Hybrid_Cherry_MX_Alps_ISOEnter" ,
27
- },
28
- "Hotswap Kailh MX" : {
29
- "name" : "Switch_Keyboard_Hotswap_Kailh" ,
30
- "footprint-nameformat" : "SW_Hotswap_Kailh_MX_{:.2f}u" ,
31
- "iso-enter" : "SW_Hotswap_Kailh_MX_ISOEnter" ,
32
- }
33
- },
34
- "supported-widths" : [
35
- 1 ,
36
- 1.25 ,
37
- 1.5 ,
38
- 1.75 ,
39
- 2 ,
40
- 2.25 ,
41
- 2.5 ,
42
- 2.75 ,
43
- 3 ,
44
- 4 ,
45
- 4.5 ,
46
- 5.5 ,
47
- 6 ,
48
- 6.25 ,
49
- 6.5 ,
50
- 7 ,
51
- ],
52
- "supported-stabilizers" : [
53
- 2 ,
54
- 3 ,
55
- 6 ,
56
- 6.25 ,
57
- 7 ,
58
- 8 ,
59
- ],
60
- }
61
-
62
- SUPPORTED_LIBRARIES = {
63
- "ai03-2725/MX_Alps_Hybrid" : {
64
- "modules" : {
65
- "MX" : {
66
- "name" : "MX_Only" ,
67
- "footprint-nameformat" : "MXOnly-{:g}U-NoLED" ,
68
- "iso-enter" : "MXOnly-ISO" ,
69
- },
70
- "Alps" : {
71
- "name" : "Alps_Only" ,
72
- "footprint-nameformat" : "ALPS-{:g}U" ,
73
- },
74
- "MX/Alps Hybrid" : {
75
- "name" : "MX_Alps_Hybrid" ,
76
- "footprint-nameformat" : "MX-{:g}U-NoLED" ,
77
- "iso-enter" : "MX-ISO" ,
78
- },
79
- },
80
- "supported-widths" : [
81
- 1 ,
82
- 1.25 ,
83
- 1.5 ,
84
- 1.75 ,
85
- 2 ,
86
- 2.25 ,
87
- 2.5 ,
88
- 2.75 ,
89
- 3 ,
90
- 6 ,
91
- 6.25 ,
92
- 6.5 ,
93
- 7 ,
94
- 8 ,
95
- 9 ,
96
- 10 ,
97
- ],
98
- "supported-stabilizers" : [], # stabilizers are part of switch footprint
99
- },
100
- # tested with https://github.com/perigoso/keyswitch-kicad-library/releases/tag/v2.2
101
- "perigoso/keyswitch-kicad-library" : KISWITCH_LIBRARY_METADATA ,
102
- # perigoso library has been moved to new location:
103
- # tested with https://github.com/kiswitch/keyswitch-kicad-library/releases/tag/v2.4
104
- "kiswitch/keyswitch-kicad-library" : KISWITCH_LIBRARY_METADATA ,
105
- }
106
-
107
11
ATMEGA32U4AU_PIN_ASSIGN_ORDER = [
108
12
"PB0" ,
109
13
"PB1" ,
@@ -153,66 +57,66 @@ def find_closest_smaller_or_equal(lst, target):
153
57
return lst [index - 1 ]
154
58
155
59
156
- def add_stabilizer (reference , key_width ):
157
- # this function works only for perigoso/keyswitch-kicad-library
158
- supported_stabilizer_size = SUPPORTED_LIBRARIES ["perigoso/keyswitch-kicad-library" ][
159
- "supported-stabilizers"
160
- ]
161
- stabilizer_width = find_closest_smaller_or_equal (
162
- supported_stabilizer_size , key_width
163
- )
60
+ def add_stabilizer (reference , stabilizer_footprint , key_width ):
61
+ supported_stabilizers = [2 , 3 , 6 , 6.25 , 7 , 8 ]
62
+ stabilizer_width = find_closest_smaller_or_equal (supported_stabilizers , key_width )
164
63
165
64
if stabilizer_width :
166
- stabilizer_footprint = (
167
- f"Mounting_Keyboard_Stabilizer:Stabilizer_Cherry_MX_{ stabilizer_width :.2f} u"
168
- )
65
+ stabilizer_footprint = f"{ stabilizer_footprint } " .format (stabilizer_width )
169
66
stabilizer = skidl .Part (
170
67
"Mechanical" , "MountingHole" , footprint = stabilizer_footprint
171
68
)
172
69
stabilizer .ref = reference
173
70
174
71
175
- def add_iso_enter_switch (switch_module , diode_footprint ):
176
- module_name = switch_module ["name" ]
177
-
178
- try :
179
- switch_footprint = switch_module ["iso-enter" ]
180
- except KeyError :
181
- footprint_format = switch_module ["footprint-nameformat" ]
182
- switch_footprint = f"{ footprint_format } " .format (1 )
183
-
184
- switch_footprint = f"{ module_name } :{ switch_footprint } "
72
+ def add_iso_enter_switch (switch_footprint , diode_footprint , stabilizer_footprint ):
73
+ # use 1u switch, do not bother with detection of dedicated ISO key which
74
+ # name is library dependent (and it is not passed via CLI yet)
75
+ switch_footprint = f"{ switch_footprint } " .format (1 )
185
76
186
77
switch = skidl .Part ("Switch" , "SW_Push" , footprint = switch_footprint )
187
- diode = skidl .Part ("Device" , "D" , footprint = f"Diode_SMD: { diode_footprint } " )
78
+ diode = skidl .Part ("Device" , "D" , footprint = diode_footprint )
188
79
189
- if module_name in ["Switch_Keyboard_Cherry_MX" , "Switch_Keyboard_Hybrid" ]:
190
- stabilizer_footprint = "Mounting_Keyboard_Stabilizer:Stabilizer_Cherry_MX_2.00u"
191
- stabilizer = skidl .Part (
192
- "Mechanical" , "MountingHole" , footprint = stabilizer_footprint
193
- )
194
- switch_reference_number = switch .ref [2 :]
195
- stabilizer .ref = f"ST{ switch_reference_number } "
80
+ switch_reference_number = switch .ref [2 :]
81
+ add_stabilizer (f"ST{ switch_reference_number } " , stabilizer_footprint , 2 )
196
82
197
83
return switch , diode
198
84
199
85
200
- def add_regular_switch (switch_module , key_width , diode_footprint ):
201
- footprint_format = switch_module ["footprint-nameformat" ]
202
- module_name = switch_module ["name" ]
86
+ def add_regular_switch (
87
+ switch_footprint , key_width , diode_footprint , stabilizer_footprint
88
+ ):
89
+ # probably should use some searching to see if given footprint exist,
90
+ # for now just assume that any library supports following widths:
91
+ supported_widths = [
92
+ 1 ,
93
+ 1.25 ,
94
+ 1.5 ,
95
+ 1.75 ,
96
+ 2 ,
97
+ 2.25 ,
98
+ 2.5 ,
99
+ 2.75 ,
100
+ 3 ,
101
+ 4 ,
102
+ 4.5 ,
103
+ 5.5 ,
104
+ 6 ,
105
+ 6.25 ,
106
+ 6.5 ,
107
+ 7 ,
108
+ ]
109
+ if key_width not in supported_widths :
110
+ key_width = 1
203
111
204
- switch_footprint = f"{ footprint_format } " .format (key_width )
205
- switch_footprint = f"{ module_name } :{ switch_footprint } "
112
+ switch_footprint = f"{ switch_footprint } " .format (key_width )
206
113
207
114
switch = skidl .Part ("Switch" , "SW_Push" , footprint = switch_footprint )
208
- diode = skidl .Part ("Device" , "D" , footprint = f"Diode_SMD: { diode_footprint } " )
115
+ diode = skidl .Part ("Device" , "D" , footprint = diode_footprint )
209
116
210
- if (
211
- module_name in ["Switch_Keyboard_Cherry_MX" , "Switch_Keyboard_Hybrid" ]
212
- and key_width >= 2
213
- ):
117
+ if stabilizer_footprint and key_width >= 2 :
214
118
switch_reference_number = switch .ref [2 :]
215
- add_stabilizer (f"ST{ switch_reference_number } " , key_width )
119
+ add_stabilizer (f"ST{ switch_reference_number } " , stabilizer_footprint , key_width )
216
120
217
121
return switch , diode
218
122
@@ -224,7 +128,7 @@ def is_key_label_valid(label):
224
128
return False
225
129
226
130
227
- def handle_switch_matrix (keys , switch_module , supported_widths , diode_footprint ):
131
+ def handle_switch_matrix (keys , switch_footprint , diode_footprint , stabilizer_footprint ):
228
132
rows = {}
229
133
columns = {}
230
134
@@ -252,13 +156,13 @@ def handle_switch_matrix(keys, switch_module, supported_widths, diode_footprint)
252
156
columns [column ] = skidl .Net (f"COL{ column } " )
253
157
254
158
if is_iso_enter (key ):
255
- switch , diode = add_iso_enter_switch (switch_module , diode_footprint )
159
+ switch , diode = add_iso_enter_switch (
160
+ switch_footprint , diode_footprint , stabilizer_footprint
161
+ )
256
162
else :
257
163
key_width = float (key ["width" ])
258
164
switch , diode = add_regular_switch (
259
- switch_module ,
260
- key_width if key_width in supported_widths else 1 ,
261
- diode_footprint ,
165
+ switch_footprint , key_width , diode_footprint , stabilizer_footprint
262
166
)
263
167
264
168
rows [row ] += diode [1 ]
@@ -417,20 +321,16 @@ def build_circuit(layout, **kwargs):
417
321
skidl .lib_search_paths [skidl .KICAD ].append (default_search_path )
418
322
419
323
try :
420
- switch_library = kwargs .get ("switch_library" )
421
- library = SUPPORTED_LIBRARIES [switch_library ]
422
-
423
324
switch_footprint = kwargs .get ("switch_footprint" )
325
+ stabilizer_footprint = kwargs .get ("stabilizer_footprint" )
424
326
diode_footprint = kwargs .get ("diode_footprint" )
425
- switch_module = library ["modules" ][switch_footprint ]
426
- supported_widths = library ["supported-widths" ]
427
327
428
328
except KeyError as err :
429
329
msg = "Unsupported argument"
430
330
raise RuntimeError (msg ) from err
431
331
432
332
rows , columns = handle_switch_matrix (
433
- layout ["keys" ], switch_module , supported_widths , diode_footprint
333
+ layout ["keys" ], switch_footprint , diode_footprint , stabilizer_footprint
434
334
)
435
335
436
336
if kwargs .get ("controller_circuit" ):
0 commit comments