Skip to content

Commit be280e2

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

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
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: 14 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,14 @@ def bootcfg(
4444

4545
supervisor.runtime.autoreload = False
4646

47+
<<<<<<< HEAD
48+
=======
49+
# Parse `usb_id` tuple for backwards compatibility. This can be removed at
50+
# some point in the future(TM).
51+
if type(usb_id) is tuple:
52+
usb_id = {'manufacturer': usb_id[0], 'product': usb_id[1]}
53+
54+
>>>>>>> 28dcc3e (feat(bootcfg): set usb identification with a kwargs-dict)
4755
# configure HID devices
4856
devices = []
4957
if keyboard:
@@ -74,11 +82,13 @@ def bootcfg(
7482
usb_midi.disable()
7583

7684
# configure usb vendor and product id
77-
if usb_id is not None:
85+
if usb_id:
7886
import supervisor
7987

80-
if hasattr(supervisor, 'set_usb_identification'):
81-
supervisor.set_usb_identification(*usb_id)
88+
try:
89+
supervisor.set_usb_identification(**usb_id)
90+
except Exception as e:
91+
print('supervisor.set_usb_identification: ', e, type(e))
8292

8393
# configure data serial
8494
if cdc_data:

0 commit comments

Comments
 (0)