Skip to content

Commit e87f4c5

Browse files
committed
feat(bootcfg): set usb identification with a kwargs-dict
1 parent 5e20076 commit e87f4c5

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

docs/en/boot.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bootcfg(
3333
nkro: bool = False,
3434
pan: bool = False,
3535
storage: bool = True,
36-
usb_id: Optional[tuple[str, str]] = None,
36+
usb_id: Optional[dict] = {},
3737
**kwargs,
3838
) -> bool
3939
```
@@ -128,6 +128,9 @@ I have to mount!" every time you plug in your keyboard.
128128
#### `usb_id`
129129
A recent addition to CircuitPython 8 is the ability to give your keyboard an
130130
identity other than "MCU board manufacturer" - "CircuitPython device".
131+
The argument is expected to be a kwargs-dictionary that is passed to
132+
`supervisor.set_usb_identification`.
133+
See the example 1 and the [CircuitPython documentation](https://docs.circuitpython.org/en/latest/shared-bindings/supervisor/index.html#supervisor.set_usb_identification) for reference.
131134

132135

133136
#### return value
@@ -156,7 +159,7 @@ bootcfg(
156159
midi=False,
157160
mouse=False,
158161
storage=False,
159-
usb_id=('KMK Keyboards', 'Custom 60% Ergo'),
162+
usb_id={'manufacturer': 'KMK Keyboards', 'product': 'Custom 60% Ergo'},
160163
)
161164

162165
```

kmk/bootcfg.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def bootcfg(
2222
nkro: bool = False,
2323
pan: bool = False,
2424
storage: bool = True,
25-
usb_id: Optional[tuple[str, str]] = None,
25+
usb_id: Optional[dict, tuple[str, str]] = {},
2626
**kwargs,
2727
) -> bool:
2828

@@ -44,6 +44,11 @@ def bootcfg(
4444

4545
supervisor.runtime.autoreload = False
4646

47+
# Parse `usb_id` tuple for backwards compatibility. This can be removed at
48+
# some point in the future(TM).
49+
if type(usb_id) is tuple:
50+
usb_id = {'manufacturer': usb_id[0], 'product': usb_id[1]}
51+
4752
# configure HID devices
4853
devices = []
4954
if keyboard:
@@ -74,11 +79,13 @@ def bootcfg(
7479
usb_midi.disable()
7580

7681
# configure usb vendor and product id
77-
if usb_id is not None:
82+
if usb_id:
7883
import supervisor
7984

80-
if hasattr(supervisor, 'set_usb_identification'):
81-
supervisor.set_usb_identification(*usb_id)
85+
try:
86+
supervisor.set_usb_identification(**usb_id)
87+
except Exception as e:
88+
print('supervisor.set_usb_identification: ', e, type(e))
8289

8390
# configure data serial
8491
if cdc_data:

util/aspell.en.pws

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
personal_ws-1.1 en 376
1+
personal_ws-1.1 en 377
22
ADNS
33
AMS
44
ANAVI
@@ -312,6 +312,7 @@ klar
312312
klardotsh
313313
kmk
314314
kmkfw
315+
kwargs
315316
kyria
316317
leds
317318
licensor

0 commit comments

Comments
 (0)