-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_boards_to_json.py
More file actions
459 lines (430 loc) · 27 KB
/
convert_boards_to_json.py
File metadata and controls
459 lines (430 loc) · 27 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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
import os
import json
import glob
from pathlib import Path
from convert_components_to_json import get_image_from_adafruit_product_url
# Base directory for the boards
BOARDS_DIR = r"./Wippersnapper_Boards/boards"
OUTPUT_FILE = r"./wippersnapper_boards.json"
def add_custom_board_definitions(boards):
"""
Add custom board definitions for boards that don't have definition.json files
"""
# Generic ESP32-S2 based board
boards["generic-esp32-s2"] = {
"boardName": "Generic ESP32-S2",
"mcuName": "ESP32-S2",
"referenceVoltage": 3.3,
"displayName": "Generic ESP32-S2 Board",
"vendor": "Generic",
"productURL": "",
"documentationURL": "",
"installMethod": "uf2",
"installBoardName": "",
"rtc": None,
"sdCardCS": None,
"totalGPIOPins": 43,
"totalAnalogPins": 20,
"pins": [
{"number": 1, "name": "D1", "displayName": "GPIO1", "hasPWM": True, "hasServo": True},
{"number": 2, "name": "D2", "displayName": "GPIO2", "hasPWM": True, "hasServo": True},
{"number": 3, "name": "D3", "displayName": "GPIO3", "hasPWM": True, "hasServo": True},
{"number": 4, "name": "D4", "displayName": "GPIO4", "hasPWM": True, "hasServo": True},
{"number": 5, "name": "D5", "displayName": "GPIO5", "hasPWM": True, "hasServo": True},
{"number": 6, "name": "D6", "displayName": "GPIO6", "hasPWM": True, "hasServo": True},
{"number": 7, "name": "D7", "displayName": "GPIO7", "hasPWM": True, "hasServo": True},
{"number": 8, "name": "D8", "displayName": "GPIO8", "hasPWM": True, "hasServo": True},
{"number": 9, "name": "D9", "displayName": "GPIO9", "hasPWM": True, "hasServo": True},
{"number": 10, "name": "D10", "displayName": "GPIO10", "hasPWM": True, "hasServo": True},
{"number": 11, "name": "D11", "displayName": "GPIO11", "hasPWM": True, "hasServo": True},
{"number": 12, "name": "D12", "displayName": "GPIO12", "hasPWM": True, "hasServo": True},
{"number": 13, "name": "D13", "displayName": "GPIO13", "hasPWM": True, "hasServo": True},
{"number": 14, "name": "D14", "displayName": "GPIO14", "hasPWM": True, "hasServo": True},
{"number": 15, "name": "D15", "displayName": "GPIO15", "hasPWM": True, "hasServo": True},
{"number": 16, "name": "D16", "displayName": "GPIO16", "hasPWM": True, "hasServo": True},
{"number": 17, "name": "D17", "displayName": "GPIO17", "hasPWM": True, "hasServo": True},
{"number": 18, "name": "D18", "displayName": "GPIO18", "hasPWM": True, "hasServo": True},
{"number": 21, "name": "D21", "displayName": "GPIO21", "hasPWM": True, "hasServo": True},
{"number": 33, "name": "D33", "displayName": "GPIO33", "hasPWM": True, "hasServo": True},
{"number": 34, "name": "D34", "displayName": "GPIO34", "hasPWM": True, "hasServo": True},
{"number": 35, "name": "D35", "displayName": "GPIO35", "hasPWM": True, "hasServo": True},
{"number": 36, "name": "D36", "displayName": "GPIO36", "hasPWM": True, "hasServo": True},
{"number": 37, "name": "D37", "displayName": "GPIO37", "hasPWM": True, "hasServo": True},
{"number": 38, "name": "D38", "displayName": "GPIO38", "hasPWM": True, "hasServo": True},
{"number": 39, "name": "D39", "displayName": "GPIO39", "hasPWM": True, "hasServo": True},
{"number": 40, "name": "D40", "displayName": "GPIO40", "hasPWM": True, "hasServo": True},
{"number": 41, "name": "D41", "displayName": "GPIO41", "hasPWM": True, "hasServo": True},
{"number": 42, "name": "D42", "displayName": "GPIO42", "hasPWM": True, "hasServo": True},
{"number": 43, "name": "D43", "displayName": "GPIO43", "hasPWM": True, "hasServo": True},
{"number": 44, "name": "D44", "displayName": "GPIO44", "hasPWM": True, "hasServo": True},
{"number": 45, "name": "D45", "displayName": "GPIO45", "hasPWM": True, "hasServo": True},
{"number": 46, "name": "D46", "displayName": "GPIO46", "hasPWM": True, "hasServo": True}
],
"analogPins": [
{"name": "A0", "displayName": "ADC1_CH0", "direction": "INPUT"},
{"name": "A1", "displayName": "ADC1_CH1", "direction": "INPUT"},
{"name": "A2", "displayName": "ADC1_CH2", "direction": "INPUT"},
{"name": "A3", "displayName": "ADC1_CH3", "direction": "INPUT"},
{"name": "A4", "displayName": "ADC1_CH4", "direction": "INPUT"},
{"name": "A5", "displayName": "ADC1_CH5", "direction": "INPUT"},
{"name": "A6", "displayName": "ADC1_CH6", "direction": "INPUT"},
{"name": "A7", "displayName": "ADC1_CH7", "direction": "INPUT"},
{"name": "A8", "displayName": "ADC1_CH8", "direction": "INPUT"},
{"name": "A9", "displayName": "ADC1_CH9", "direction": "INPUT"}
],
"defaultI2C": {
"i2cPortId": 0,
"SCL": 9,
"SDA": 8
},
"image": None
}
# Generic ESP32-S3 based board
boards["generic-esp32-s3"] = {
"boardName": "Generic ESP32-S3",
"mcuName": "ESP32-S3",
"referenceVoltage": 3.3,
"displayName": "Generic ESP32-S3 Board",
"vendor": "Generic",
"productURL": "",
"documentationURL": "",
"installMethod": "uf2",
"installBoardName": "",
"rtc": None,
"sdCardCS": None,
"totalGPIOPins": 48,
"totalAnalogPins": 20,
"pins": [
{"number": 1, "name": "D1", "displayName": "GPIO1", "hasPWM": True, "hasServo": True},
{"number": 2, "name": "D2", "displayName": "GPIO2", "hasPWM": True, "hasServo": True},
{"number": 3, "name": "D3", "displayName": "GPIO3", "hasPWM": True, "hasServo": True},
{"number": 4, "name": "D4", "displayName": "GPIO4", "hasPWM": True, "hasServo": True},
{"number": 5, "name": "D5", "displayName": "GPIO5", "hasPWM": True, "hasServo": True},
{"number": 6, "name": "D6", "displayName": "GPIO6", "hasPWM": True, "hasServo": True},
{"number": 7, "name": "D7", "displayName": "GPIO7", "hasPWM": True, "hasServo": True},
{"number": 8, "name": "D8", "displayName": "GPIO8", "hasPWM": True, "hasServo": True},
{"number": 9, "name": "D9", "displayName": "GPIO9", "hasPWM": True, "hasServo": True},
{"number": 10, "name": "D10", "displayName": "GPIO10", "hasPWM": True, "hasServo": True},
{"number": 11, "name": "D11", "displayName": "GPIO11", "hasPWM": True, "hasServo": True},
{"number": 12, "name": "D12", "displayName": "GPIO12", "hasPWM": True, "hasServo": True},
{"number": 13, "name": "D13", "displayName": "GPIO13", "hasPWM": True, "hasServo": True},
{"number": 14, "name": "D14", "displayName": "GPIO14", "hasPWM": True, "hasServo": True},
{"number": 15, "name": "D15", "displayName": "GPIO15", "hasPWM": True, "hasServo": True},
{"number": 16, "name": "D16", "displayName": "GPIO16", "hasPWM": True, "hasServo": True},
{"number": 17, "name": "D17", "displayName": "GPIO17", "hasPWM": True, "hasServo": True},
{"number": 18, "name": "D18", "displayName": "GPIO18", "hasPWM": True, "hasServo": True},
{"number": 19, "name": "D19", "displayName": "GPIO19", "hasPWM": True, "hasServo": True},
{"number": 20, "name": "D20", "displayName": "GPIO20", "hasPWM": True, "hasServo": True},
{"number": 21, "name": "D21", "displayName": "GPIO21", "hasPWM": True, "hasServo": True},
{"number": 35, "name": "D35", "displayName": "GPIO35", "hasPWM": True, "hasServo": True},
{"number": 36, "name": "D36", "displayName": "GPIO36", "hasPWM": True, "hasServo": True},
{"number": 37, "name": "D37", "displayName": "GPIO37", "hasPWM": True, "hasServo": True},
{"number": 38, "name": "D38", "displayName": "GPIO38", "hasPWM": True, "hasServo": True},
{"number": 39, "name": "D39", "displayName": "GPIO39", "hasPWM": True, "hasServo": True},
{"number": 40, "name": "D40", "displayName": "GPIO40", "hasPWM": True, "hasServo": True},
{"number": 41, "name": "D41", "displayName": "GPIO41", "hasPWM": True, "hasServo": True},
{"number": 42, "name": "D42", "displayName": "GPIO42", "hasPWM": True, "hasServo": True},
{"number": 43, "name": "D43", "displayName": "GPIO43", "hasPWM": True, "hasServo": True},
{"number": 44, "name": "D44", "displayName": "GPIO44", "hasPWM": True, "hasServo": True},
{"number": 45, "name": "D45", "displayName": "GPIO45", "hasPWM": True, "hasServo": True},
{"number": 46, "name": "D46", "displayName": "GPIO46", "hasPWM": True, "hasServo": True},
{"number": 47, "name": "D47", "displayName": "GPIO47", "hasPWM": True, "hasServo": True},
{"number": 48, "name": "D48", "displayName": "GPIO48", "hasPWM": True, "hasServo": True}
],
"analogPins": [
{"name": "A0", "displayName": "ADC1_CH0", "direction": "INPUT"},
{"name": "A1", "displayName": "ADC1_CH1", "direction": "INPUT"},
{"name": "A2", "displayName": "ADC1_CH2", "direction": "INPUT"},
{"name": "A3", "displayName": "ADC1_CH3", "direction": "INPUT"},
{"name": "A4", "displayName": "ADC1_CH4", "direction": "INPUT"},
{"name": "A5", "displayName": "ADC1_CH5", "direction": "INPUT"},
{"name": "A6", "displayName": "ADC1_CH6", "direction": "INPUT"},
{"name": "A7", "displayName": "ADC1_CH7", "direction": "INPUT"},
{"name": "A8", "displayName": "ADC1_CH8", "direction": "INPUT"},
{"name": "A9", "displayName": "ADC1_CH9", "direction": "INPUT"}
],
"defaultI2C": {
"i2cPortId": 0,
"SCL": 9,
"SDA": 8
},
"image": None
}
# Generic RP2040 based board
boards["generic-rp2040"] = {
"boardName": "Generic RP2040",
"mcuName": "RP2040",
"referenceVoltage": 3.3,
"displayName": "Generic RP2040 Board",
"vendor": "Generic",
"productURL": "",
"documentationURL": "",
"installMethod": "uf2",
"installBoardName": "",
"rtc": None,
"sdCardCS": None,
"totalGPIOPins": 30,
"totalAnalogPins": 4,
"pins": [
{"number": 0, "name": "D0", "displayName": "GPIO0", "hasPWM": True, "hasServo": True},
{"number": 1, "name": "D1", "displayName": "GPIO1", "hasPWM": True, "hasServo": True},
{"number": 2, "name": "D2", "displayName": "GPIO2", "hasPWM": True, "hasServo": True},
{"number": 3, "name": "D3", "displayName": "GPIO3", "hasPWM": True, "hasServo": True},
{"number": 4, "name": "D4", "displayName": "GPIO4", "hasPWM": True, "hasServo": True},
{"number": 5, "name": "D5", "displayName": "GPIO5", "hasPWM": True, "hasServo": True},
{"number": 6, "name": "D6", "displayName": "GPIO6", "hasPWM": True, "hasServo": True},
{"number": 7, "name": "D7", "displayName": "GPIO7", "hasPWM": True, "hasServo": True},
{"number": 8, "name": "D8", "displayName": "GPIO8", "hasPWM": True, "hasServo": True},
{"number": 9, "name": "D9", "displayName": "GPIO9", "hasPWM": True, "hasServo": True},
{"number": 10, "name": "D10", "displayName": "GPIO10", "hasPWM": True, "hasServo": True},
{"number": 11, "name": "D11", "displayName": "GPIO11", "hasPWM": True, "hasServo": True},
{"number": 12, "name": "D12", "displayName": "GPIO12", "hasPWM": True, "hasServo": True},
{"number": 13, "name": "D13", "displayName": "GPIO13", "hasPWM": True, "hasServo": True},
{"number": 14, "name": "D14", "displayName": "GPIO14", "hasPWM": True, "hasServo": True},
{"number": 15, "name": "D15", "displayName": "GPIO15", "hasPWM": True, "hasServo": True},
{"number": 16, "name": "D16", "displayName": "GPIO16", "hasPWM": True, "hasServo": True},
{"number": 17, "name": "D17", "displayName": "GPIO17", "hasPWM": True, "hasServo": True},
{"number": 18, "name": "D18", "displayName": "GPIO18", "hasPWM": True, "hasServo": True},
{"number": 19, "name": "D19", "displayName": "GPIO19", "hasPWM": True, "hasServo": True},
{"number": 20, "name": "D20", "displayName": "GPIO20", "hasPWM": True, "hasServo": True},
{"number": 21, "name": "D21", "displayName": "GPIO21", "hasPWM": True, "hasServo": True},
{"number": 22, "name": "D22", "displayName": "GPIO22", "hasPWM": True, "hasServo": True},
{"number": 23, "name": "D23", "displayName": "GPIO23", "hasPWM": True, "hasServo": True},
{"number": 24, "name": "D24", "displayName": "GPIO24", "hasPWM": True, "hasServo": True},
{"number": 25, "name": "D25", "displayName": "GPIO25", "hasPWM": True, "hasServo": True},
{"number": 26, "name": "D26", "displayName": "GPIO26", "hasPWM": True, "hasServo": True},
{"number": 27, "name": "D27", "displayName": "GPIO27", "hasPWM": True, "hasServo": True},
{"number": 28, "name": "D28", "displayName": "GPIO28", "hasPWM": True, "hasServo": True},
{"number": 29, "name": "D29", "displayName": "GPIO29", "hasPWM": True, "hasServo": True}
],
"analogPins": [
{"name": "A0", "displayName": "ADC0", "direction": "INPUT"},
{"name": "A1", "displayName": "ADC1", "direction": "INPUT"},
{"name": "A2", "displayName": "ADC2", "direction": "INPUT"},
{"name": "A3", "displayName": "ADC3", "direction": "INPUT"}
],
"defaultI2C": {
"i2cPortId": 0,
"SCL": 3,
"SDA": 2
},
"image": None
}
# Generic RP23xx based board
boards["generic-rp23xx"] = {
"boardName": "Generic RP23xx",
"mcuName": "RP23xx",
"referenceVoltage": 3.3,
"displayName": "Generic RP2350/RP2354 board",
"vendor": "Generic",
"productURL": "",
"documentationURL": "",
"installMethod": "uf2",
"installBoardName": "",
"rtc": None,
"sdCardCS": None,
"totalGPIOPins": 48,
"totalAnalogPins": 8,
"pins": [
{"number": 0, "name": "D0", "displayName": "GPIO0", "hasPWM": True, "hasServo": True},
{"number": 1, "name": "D1", "displayName": "GPIO1", "hasPWM": True, "hasServo": True},
{"number": 2, "name": "D2", "displayName": "GPIO2", "hasPWM": True, "hasServo": True},
{"number": 3, "name": "D3", "displayName": "GPIO3", "hasPWM": True, "hasServo": True},
{"number": 4, "name": "D4", "displayName": "GPIO4", "hasPWM": True, "hasServo": True},
{"number": 5, "name": "D5", "displayName": "GPIO5", "hasPWM": True, "hasServo": True},
{"number": 6, "name": "D6", "displayName": "GPIO6", "hasPWM": True, "hasServo": True},
{"number": 7, "name": "D7", "displayName": "GPIO7", "hasPWM": True, "hasServo": True},
{"number": 8, "name": "D8", "displayName": "GPIO8", "hasPWM": True, "hasServo": True},
{"number": 9, "name": "D9", "displayName": "GPIO9", "hasPWM": True, "hasServo": True},
{"number": 10, "name": "D10", "displayName": "GPIO10", "hasPWM": True, "hasServo": True},
{"number": 11, "name": "D11", "displayName": "GPIO11", "hasPWM": True, "hasServo": True},
{"number": 12, "name": "D12", "displayName": "GPIO12", "hasPWM": True, "hasServo": True},
{"number": 13, "name": "D13", "displayName": "GPIO13", "hasPWM": True, "hasServo": True},
{"number": 14, "name": "D14", "displayName": "GPIO14", "hasPWM": True, "hasServo": True},
{"number": 15, "name": "D15", "displayName": "GPIO15", "hasPWM": True, "hasServo": True},
{"number": 16, "name": "D16", "displayName": "GPIO16", "hasPWM": True, "hasServo": True},
{"number": 17, "name": "D17", "displayName": "GPIO17", "hasPWM": True, "hasServo": True},
{"number": 18, "name": "D18", "displayName": "GPIO18", "hasPWM": True, "hasServo": True},
{"number": 19, "name": "D19", "displayName": "GPIO19", "hasPWM": True, "hasServo": True},
{"number": 20, "name": "D20", "displayName": "GPIO20", "hasPWM": True, "hasServo": True},
{"number": 21, "name": "D21", "displayName": "GPIO21", "hasPWM": True, "hasServo": True},
{"number": 22, "name": "D22", "displayName": "GPIO22", "hasPWM": True, "hasServo": True},
{"number": 23, "name": "D23", "displayName": "GPIO23", "hasPWM": True, "hasServo": True},
{"number": 24, "name": "D24", "displayName": "GPIO24", "hasPWM": True, "hasServo": True},
{"number": 25, "name": "D25", "displayName": "GPIO25", "hasPWM": True, "hasServo": True},
{"number": 26, "name": "A26", "displayName": "GPIO26 (ADC0)", "hasPWM": True, "hasServo": True},
{"number": 27, "name": "A27", "displayName": "GPIO27 (ADC1)", "hasPWM": True, "hasServo": True},
{"number": 28, "name": "A28", "displayName": "GPIO28 (ADC2)", "hasPWM": True, "hasServo": True},
{"number": 29, "name": "A29", "displayName": "GPIO29 (ADC3)", "hasPWM": True, "hasServo": True},
{"number": 30, "name": "D30", "displayName": "GPIO30", "hasPWM": True, "hasServo": True},
{"number": 31, "name": "D31", "displayName": "GPIO31", "hasPWM": True, "hasServo": True},
{"number": 32, "name": "D32", "displayName": "GPIO32", "hasPWM": True, "hasServo": True},
{"number": 33, "name": "D33", "displayName": "GPIO33", "hasPWM": True, "hasServo": True},
{"number": 34, "name": "D34", "displayName": "GPIO34", "hasPWM": True, "hasServo": True},
{"number": 35, "name": "D35", "displayName": "GPIO35", "hasPWM": True, "hasServo": True},
{"number": 36, "name": "D36", "displayName": "GPIO36", "hasPWM": True, "hasServo": True},
{"number": 37, "name": "D37", "displayName": "GPIO37", "hasPWM": True, "hasServo": True},
{"number": 38, "name": "D38", "displayName": "GPIO38", "hasPWM": True, "hasServo": True},
{"number": 39, "name": "D39", "displayName": "GPIO39", "hasPWM": True, "hasServo": True},
{"number": 40, "name": "A40", "displayName": "GPIO40 (ADC0)", "hasPWM": True, "hasServo": True},
{"number": 41, "name": "A41", "displayName": "GPIO41 (ADC1)", "hasPWM": True, "hasServo": True},
{"number": 42, "name": "A42", "displayName": "GPIO42 (ADC2)", "hasPWM": True, "hasServo": True},
{"number": 43, "name": "A43", "displayName": "GPIO43 (ADC3)", "hasPWM": True, "hasServo": True},
{"number": 44, "name": "D44", "displayName": "GPIO44", "hasPWM": True, "hasServo": True},
{"number": 45, "name": "D45", "displayName": "GPIO45", "hasPWM": True, "hasServo": True},
{"number": 46, "name": "D46", "displayName": "GPIO46", "hasPWM": True, "hasServo": True},
{"number": 47, "name": "D47", "displayName": "GPIO47", "hasPWM": True, "hasServo": True},
{"number": 48, "name": "D48", "displayName": "GPIO48", "hasPWM": True, "hasServo": True}
],
"analogPins": [
{"name": "A26", "displayName": "GPIO26 (ADC0)", "direction": "INPUT"},
{"name": "A27", "displayName": "GPIO27 (ADC1)", "direction": "INPUT"},
{"name": "A28", "displayName": "GPIO28 (ADC2)", "direction": "INPUT"},
{"name": "A29", "displayName": "GPIO29 (ADC3)", "direction": "INPUT"},
{"name": "A40", "displayName": "GPIO40 (ADC0)", "direction": "INPUT"},
{"name": "A41", "displayName": "GPIO41 (ADC1)", "direction": "INPUT"},
{"name": "A42", "displayName": "GPIO42 (ADC2)", "direction": "INPUT"},
{"name": "A43", "displayName": "GPIO43 (ADC3)", "direction": "INPUT"}
],
"defaultI2C": {
"i2cPortId": 0,
"SCL": 3,
"SDA": 2
},
"image": None
}
return boards
def convert_boards_to_json():
"""
Convert all board definition.json files into a single JSON file
that can be used in the Wippersnapper Configuration Builder.
"""
boards = {}
# Get all board directories
board_dirs = [d for d in os.listdir(BOARDS_DIR) if os.path.isdir(os.path.join(BOARDS_DIR, d)) and not d.startswith('.')]
for board_dir in board_dirs:
board_path = os.path.join(BOARDS_DIR, board_dir)
definition_file = os.path.join(board_path, "definition.json")
# Skip if the definition.json doesn't exist
if not os.path.exists(definition_file):
print(f"Skipping {board_dir} - No definition.json found")
continue
try:
# Read the definition.json file
with open(definition_file, 'r') as f:
board_data = json.load(f)
# Extract relevant information
board_info = {
"boardName": board_data.get("boardName"),
"mcuName": board_data.get("mcuName"),
"referenceVoltage": board_data.get("mcuRefVoltage", 3.3),
"displayName": board_data.get("displayName"),
"vendor": board_data.get("vendor"),
"productURL": board_data.get("productURL", ""),
"documentationURL": board_data.get("documentationURL", ""),
"installMethod": board_data.get("installMethod", ""),
"installBoardName": board_data.get("installBoardName", board_data.get("boardName", "")),
"rtc": board_data.get("rtc", None),
"sdCardCS": board_data.get("sdCardCS", None),
"pins": [],
"analogPins": [],
"defaultI2C": {},
"image": None
}
SUPPORTED_ARCHITECTURES = ["rp2350", "rp2040", "esp32s2", "esp32s3"]
# Filter out boards that are not supported
if board_info["mcuName"] not in SUPPORTED_ARCHITECTURES:
print(f"Skipping {board_dir} - Unsupported architecture {board_info['mcuName']}")
continue
# Get pins
if "components" in board_data and "digitalPins" in board_data["components"]:
for pin in board_data["components"]["digitalPins"]:
# Extract the numeric part of the pin name (e.g., "D13" -> 13)
pin_name = pin.get("name", "")
if pin_name.startswith("D"):
# if board_info["pins"].filter(lambda x: x["name"] == pin_name) == 0:
try:
pin_number = int(pin_name[1:])
board_info["pins"].append({
"number": pin_number,
"name": pin_name,
"displayName": pin.get("displayName", pin_name),
"hasPWM": pin.get("hasPWM", False),
"hasServo": pin.get("hasServo", False),
"direction": pin.get("direction", "")
})
except ValueError:
print(f"Skipping pin {pin_name} - Cannot parse pin number")
# Get analog pins
if "components" in board_data and "analogPins" in board_data["components"]:
analog_count = 0
for pin in board_data["components"]["analogPins"]:
pin_name = pin.get("name", "")
try:
pin_number = int(pin_name[1:])
board_info["analogPins"].append({
"number": pin_number,
"name": pin_name,
"displayName": pin.get("displayName", pin_name),
"direction": pin.get("direction", "")
})
analog_count += 1
# Add to pins list as well if number not already present
if not any(p["number"] == pin_number for p in board_info["pins"]):
board_info["pins"].append({
"number": pin_number,
"name": pin_name,
"displayName": pin.get("displayName", pin_name),
"direction": "", # Blank for both input and output
"hasPWM": True,
"hasServo": True
})
except ValueError:
print(f"Skipping pin {pin_name} - Cannot parse pin number")
board_info["totalAnalogPins"] = analog_count
# Get I2C ports
if "components" in board_data and "i2cPorts" in board_data["components"]:
i2c_ports = board_data["components"]["i2cPorts"]
if i2c_ports and len(i2c_ports) > 0:
default_i2c = i2c_ports[0] # Use the first I2C port as default
board_info["defaultI2C"] = {
"i2cPortId": default_i2c.get("i2cPortId", 0),
"SCL": default_i2c.get("SCL"),
"SDA": default_i2c.get("SDA")
}
# Store all I2C ports
board_info["i2cPorts"] = i2c_ports
# Count total GPIO pins
board_info["totalGPIOPins"] = len(board_info["pins"])
# Look for an image file
image_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.svg']
for ext in image_extensions:
image_file = os.path.join(board_path, f"image{ext}")
if os.path.exists(image_file):
# Store relative path to image
board_info["image"] = f"boards/{board_dir}/image{ext}"
break
# Fetch missing images
if board_info["image"] is None and board_info["productURL"] != "":
board_info["image"] = get_image_from_adafruit_product_url(board_info["productURL"])
# Add to boards dictionary
boards[board_dir] = board_info
print(f"Processed {board_dir}")
except Exception as e:
print(f"Error processing {board_dir}: {str(e)}")
# Add custom board definitions
boards = add_custom_board_definitions(boards)
# Write the consolidated JSON file
with open(OUTPUT_FILE, 'w') as f:
json.dump({"boards": boards}, f, indent=2)
# Write the consolidated JS file
with open(OUTPUT_FILE.replace('.json', '.js'), 'w') as f:
f.write("window.jsonBoardObject = ")
json.dump({"boards": boards}, f, indent=2)
f.write(";\n")
print(f"Successfully created {OUTPUT_FILE} with {len(boards)} boards")
return boards
# Execute the function
if __name__ == "__main__":
boards = convert_boards_to_json()
print(f"Converted {len(boards)} board definitions")