Skip to content

Commit

Permalink
Merge pull request #1120 from flit/bugfix/pywinusb_warning
Browse files Browse the repository at this point in the history
Remove warning about missing pywinusb on Windows
  • Loading branch information
flit authored Mar 10, 2021
2 parents f940a93 + dadeca0 commit ade9b68
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
17 changes: 10 additions & 7 deletions pyocd/probe/pydapaccess/interface/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2006-2013 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,6 +17,7 @@

import os
import logging
import platform
from ..dap_access_api import DAPAccessIntf
from .hidapi_backend import HidApiUSB
from .pyusb_backend import PyUSB
Expand All @@ -40,21 +42,22 @@
USB_BACKEND = ""

# Select backend based on OS and availability.
system = platform.system()
if not USB_BACKEND:
if os.name == "nt":
if system == "Windows":
# Prefer hidapi over pyWinUSB for Windows, since pyWinUSB has known bug(s)
if HidApiUSB.isAvailable:
USB_BACKEND = "hidapiusb"
elif PyWinUSB.isAvailable:
USB_BACKEND = "pywinusb"
else:
raise DAPAccessIntf.DeviceError("No USB backend found")
elif os.name == "posix":
# Select hidapi for OS X and pyUSB for Linux.
if os.uname()[0] == 'Darwin':
USB_BACKEND = "hidapiusb"
else:
USB_BACKEND = "pyusb"
# Default to hidapi for OS X.
elif system == "Darwin":
USB_BACKEND = "hidapiusb"
# Default to pyUSB for Linux.
elif system == "Linux":
USB_BACKEND = "pyusb"
else:
raise DAPAccessIntf.DeviceError("No USB backend found")

Expand Down
4 changes: 1 addition & 3 deletions pyocd/probe/pydapaccess/interface/hidapi_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2006-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,7 +16,6 @@
# limitations under the License.

import logging
import platform
import six

from .interface import Interface
Expand All @@ -28,8 +28,6 @@
try:
import hid
except:
if platform.system() == 'Darwin':
LOG.error("hidapi is required for CMSIS-DAP support on macOS")
IS_AVAILABLE = False
else:
IS_AVAILABLE = True
Expand Down
2 changes: 0 additions & 2 deletions pyocd/probe/pydapaccess/interface/pyusb_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import usb.core
import usb.util
except:
if platform.system() == "Linux":
LOG.error("PyUSB is required for CMSIS-DAP support on Linux")
IS_AVAILABLE = False
else:
IS_AVAILABLE = True
Expand Down
4 changes: 1 addition & 3 deletions pyocd/probe/pydapaccess/interface/pywinusb_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2006-2020 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -15,7 +16,6 @@
# limitations under the License.

import logging
import platform
import collections
from time import sleep
import six
Expand All @@ -32,8 +32,6 @@
try:
import pywinusb.hid as hid
except:
if platform.system() == "Windows":
LOG.error("PyWinUSB is required on a Windows Machine")
IS_AVAILABLE = False
else:
IS_AVAILABLE = True
Expand Down

0 comments on commit ade9b68

Please sign in to comment.