summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorQMK Bot <hello@qmk.fm>2023-01-01 00:44:40 +0000
committerQMK Bot <hello@qmk.fm>2023-01-01 00:44:40 +0000
commit422fd8aed8d7a985a4f090deb0d166ec81db8cd9 (patch)
tree08278cfb94264d5ce2816ebb331661dcca38c080 /lib
parentc6bc439eb2018c96e4a4875d66c273a09da1843d (diff)
parentb8e12eed8038d172aacfd7381785643f2da9664c (diff)
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'lib')
-rw-r--r--lib/python/qmk/flashers.py33
1 files changed, 22 insertions, 11 deletions
diff --git a/lib/python/qmk/flashers.py b/lib/python/qmk/flashers.py
index a9cf726b44..e902e5072f 100644
--- a/lib/python/qmk/flashers.py
+++ b/lib/python/qmk/flashers.py
@@ -1,3 +1,4 @@
+import platform
import shutil
import time
import os
@@ -56,6 +57,20 @@ def _check_dfu_programmer_version():
return False
+def _find_usb_device(vid_hex, pid_hex):
+ # WSL doesnt have access to USB - use powershell instead...?
+ if 'microsoft' in platform.uname().release.lower():
+ ret = cli.run(['powershell.exe', '-command', 'Get-PnpDevice -PresentOnly | Select-Object -Property InstanceId'])
+ if f'USB\\VID_{vid_hex:04X}&PID_{pid_hex:04X}' in ret.stdout:
+ return (vid_hex, pid_hex)
+ else:
+ with DelayedKeyboardInterrupt():
+ # PyUSB does not like to be interrupted by Ctrl-C
+ # therefore we catch the interrupt with a custom handler
+ # and only process it once pyusb finished
+ return usb.core.find(idVendor=vid_hex, idProduct=pid_hex)
+
+
def _find_bootloader():
# To avoid running forever in the background, only look for bootloaders for 10min
start_time = time.time()
@@ -64,11 +79,7 @@ def _find_bootloader():
for vid, pid in BOOTLOADER_VIDS_PIDS[bl]:
vid_hex = int(f'0x{vid}', 0)
pid_hex = int(f'0x{pid}', 0)
- with DelayedKeyboardInterrupt():
- # PyUSB does not like to be interrupted by Ctrl-C
- # therefore we catch the interrupt with a custom handler
- # and only process it once pyusb finished
- dev = usb.core.find(idVendor=vid_hex, idProduct=pid_hex)
+ dev = _find_usb_device(vid_hex, pid_hex)
if dev:
if bl == 'atmel-dfu':
details = _PID_TO_MCU[pid]
@@ -178,25 +189,25 @@ def flasher(mcu, file):
# Add a small sleep to avoid race conditions
time.sleep(1)
if bl == 'atmel-dfu':
- _flash_atmel_dfu(details, file.name)
+ _flash_atmel_dfu(details, file)
elif bl == 'caterina':
- if _flash_caterina(details, file.name):
+ if _flash_caterina(details, file):
return (True, "The Caterina bootloader was found but is not writable. Check 'qmk doctor' output for advice.")
elif bl == 'hid-bootloader':
if mcu:
- if _flash_hid_bootloader(mcu, details, file.name):
+ if _flash_hid_bootloader(mcu, details, file):
return (True, "Please make sure 'teensy_loader_cli' or 'hid_bootloader_cli' is available on your system.")
else:
return (True, "Specifying the MCU with '-m' is necessary for HalfKay/HID bootloaders!")
elif bl == 'stm32-dfu' or bl == 'apm32-dfu' or bl == 'gd32v-dfu' or bl == 'kiibohd':
- _flash_dfu_util(details, file.name)
+ _flash_dfu_util(details, file)
elif bl == 'usbasploader' or bl == 'usbtinyisp':
if mcu:
- _flash_isp(mcu, bl, file.name)
+ _flash_isp(mcu, bl, file)
else:
return (True, "Specifying the MCU with '-m' is necessary for ISP flashing!")
elif bl == 'md-boot':
- _flash_mdloader(file.name)
+ _flash_mdloader(file)
else:
return (True, "Known bootloader found but flashing not currently supported!")