diff options
author | Jim Mussared <jim.mussared@gmail.com> | 2020-06-05 15:41:08 +1000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-06-10 22:40:02 +1000 |
commit | 3f77f2c60ca80ea9189f85193dbd746e9a6034a9 (patch) | |
tree | 6ed7bc3115e6d586ebc3acc63f57e2fb58db092f | |
parent | c6fd6a0d728fea590e7f731e41a33754111770bd (diff) | |
download | micropython-3f77f2c60ca80ea9189f85193dbd746e9a6034a9.tar.gz micropython-3f77f2c60ca80ea9189f85193dbd746e9a6034a9.zip |
unix/btstack_usb: Allow choosing adaptor via environment variable.
This allows running (for example):
env MICROPYBTUSB=2-2 ./micropython-dev ../../examples/bluetooth/ble_temperature_central.py
-rw-r--r-- | ports/unix/btstack_usb.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/ports/unix/btstack_usb.c b/ports/unix/btstack_usb.c index da9d72fe15..76f32d6d27 100644 --- a/ports/unix/btstack_usb.c +++ b/ports/unix/btstack_usb.c @@ -110,7 +110,23 @@ void mp_bluetooth_btstack_port_init(void) { btstack_run_loop_embedded_get_instance()->init(); } - // TODO: allow setting USB device path via cmdline/env var. + // MICROPYBTUSB can be a ':'' or '-' separated port list. + char *path = getenv("MICROPYBTUSB"); + if (path != NULL) { + uint8_t usb_path[7] = {0}; + size_t usb_path_len = 0; + + while (usb_path_len < MP_ARRAY_SIZE(usb_path)) { + char *delimiter; + usb_path[usb_path_len++] = strtol(path, &delimiter, 16); + if (!delimiter || (*delimiter != ':' && *delimiter != '-')) { + break; + } + path = delimiter + 1; + } + + hci_transport_usb_set_path(usb_path_len, usb_path); + } // hci_dump_open(NULL, HCI_DUMP_STDOUT); hci_init(hci_transport_usb_instance(), NULL); |