コード例 #1
0
    def id(self):  # pylint: disable=invalid-name,too-many-branches,too-many-return-statements
        """Return a unique id for the detected chip, if any."""
        # There are some times we want to trick the platform detection
        # say if a raspberry pi doesn't have the right ID, or for testing
        try:
            return os.environ['BLINKA_FORCECHIP']
        except KeyError:  # no forced chip, continue with testing!
            pass

        # Special case, if we have an environment var set, we could use FT232H
        try:
            if os.environ['BLINKA_FT232H']:
                from pyftdi.usbtools import UsbTools  # pylint: disable=import-error
                # look for it based on PID/VID
                count = len(UsbTools.find_all([(0x0403, 0x6014)]))
                if count == 0:
                    raise RuntimeError('BLINKA_FT232H environment variable' + \
                                       'set, but no FT232H device found')
                return FT232H
        except KeyError:  # no FT232H environment var
            pass

        platform = sys.platform
        if platform == "linux" or platform == "linux2":
            return self._linux_id()
        if platform == "esp8266":
            return ESP8266
        if platform == "samd21":
            return SAMD21
        if platform == "pyboard":
            return STM32
        # nothing found!
        return None
コード例 #2
0
    def _esp32_find_console_port():
        host_os = platform.system()
        if host_os == "Darwin":
            usb_paths = glob("/dev/cu.usbserial-*1")
            if usb_paths:
                return usb_paths[0]

            # Try pyftdi only on MacOS as it fails on Linux.
            # Actually, Espressif's esptool.py seems not to
            # like this at all.
            print("Trying FTDI first")
            devs = UsbTools.find_all(ESP32_FTDI_VID_PID)
            if devs:
                return "ftdi://ftdi:2232/2"
        elif host_os == "Linux":
            # Try ttyUSB1, no need to glob.
            serial_device = "/dev/ttyUSB1"
            print("Trying {serdev}".format(serdev=serial_device))
            if os.path.exists(serial_device):
                return serial_device

        print(
            "Cannot find ESP32 console /dev/... nor ftdi:// path, please specify it manually using --port"
        )
        exit(1)
コード例 #3
0
ファイル: mockusb.py プロジェクト: cruizdeg/pyftdi
 def test_string(self):
     """Retrieve a string from its identifier."""
     ftdis = [(0x403, 0x6010)]
     ft2232h = UsbTools.find_all(ftdis)[0]
     devdesc, _ = ft2232h
     dev = UsbTools.get_device(devdesc)
     serialn = UsbTools.get_string(dev, dev.iSerialNumber)
     self.assertEqual(serialn, 'FT2DEF')
コード例 #4
0
    def id(
        self,
    ):  # pylint: disable=invalid-name,too-many-branches,too-many-return-statements
        """Return a unique id for the detected chip, if any."""
        # There are some times we want to trick the platform detection
        # say if a raspberry pi doesn't have the right ID, or for testing
        try:
            return os.environ["BLINKA_FORCECHIP"]
        except KeyError:  # no forced chip, continue with testing!
            pass

        # Special cases controlled by environment var
        if os.environ.get("BLINKA_FT232H"):
            from pyftdi.usbtools import UsbTools

            # look for it based on PID/VID
            count = len(UsbTools.find_all([(0x0403, 0x6014)]))
            if count == 0:
                raise RuntimeError(
                    "BLINKA_FT232H environment variable "
                    + "set, but no FT232H device found"
                )
            return chips.FT232H
        if os.environ.get("BLINKA_MCP2221"):
            import hid

            # look for it based on PID/VID
            for dev in hid.enumerate():
                if dev["vendor_id"] == 0x04D8 and dev["product_id"] == 0x00DD:
                    return chips.MCP2221
            raise RuntimeError(
                "BLINKA_MCP2221 environment variable "
                + "set, but no MCP2221 device found"
            )
        if os.environ.get("BLINKA_GREATFET"):
            import usb

            if usb.core.find(idVendor=0x1D50, idProduct=0x60E6) is not None:
                return chips.LPC4330
            raise RuntimeError(
                "BLINKA_GREATFET environment variable "
                + "set, but no GreatFET device found"
            )
        if os.environ.get("BLINKA_NOVA"):
            return chips.BINHO

        platform = sys.platform
        if platform in ("linux", "linux2"):
            return self._linux_id()
        if platform == "esp8266":
            return chips.ESP8266
        if platform == "samd21":
            return chips.SAMD21
        if platform == "pyboard":
            return chips.STM32
        # nothing found!
        return None
コード例 #5
0
ファイル: mockusb.py プロジェクト: cruizdeg/pyftdi
 def test_device(self):
     """Access and release FTDI device."""
     ftdis = [(0x403, 0x6001)]
     ft232rs = UsbTools.find_all(ftdis)
     self.assertEqual(len(ft232rs), 1)
     devdesc, ifcount = ft232rs[0]
     self.assertEqual(ifcount, 1)
     dev = UsbTools.get_device(devdesc)
     self.assertIsNotNone(dev)
     UsbTools.release_device(dev)
コード例 #6
0
ファイル: esp32.py プロジェクト: OwletCare/memfault-sdk
    def _esp32_find_console_port():
        from pyftdi.usbtools import UsbTools

        # Try pyftdi first:
        devs = UsbTools.find_all([(0x0403, 0x6010)])
        if devs:
            return "ftdi://ftdi:2232/2"

        # Fall back to /dev/cu... device:
        usb_paths = glob("/dev/cu.usbserial-*1")
        if usb_paths:
            return usb_paths[0]

        print(
            "Cannot find ESP32 console /dev/... nor ftdi:// path, please specify it manually using --port"
        )
        exit(1)
コード例 #7
0
    def id(self):  # pylint: disable=invalid-name,too-many-branches,too-many-return-statements
        """Return a unique id for the detected chip, if any."""
        # There are some times we want to trick the platform detection
        # say if a raspberry pi doesn't have the right ID, or for testing
        try:
            return os.environ['BLINKA_FORCECHIP']
        except KeyError:  # no forced chip, continue with testing!
            pass

        # Special cases controlled by environment var
        if os.environ.get('BLINKA_FT232H'):
            from pyftdi.usbtools import UsbTools  # pylint: disable=import-error
            # look for it based on PID/VID
            count = len(UsbTools.find_all([(0x0403, 0x6014)]))
            if count == 0:
                raise RuntimeError('BLINKA_FT232H environment variable ' + \
                                   'set, but no FT232H device found')
            return chips.FT232H
        if os.environ.get('BLINKA_MCP2221'):
            import hid  # pylint: disable=import-error
            # look for it based on PID/VID
            for dev in hid.enumerate():
                if dev['vendor_id'] == 0x04D8 and dev['product_id'] == 0x00DD:
                    return chips.MCP2221
            raise RuntimeError('BLINKA_MCP2221 environment variable ' + \
                               'set, but no MCP2221 device found')
        if os.environ.get('BLINKA_NOVA'):
            return chips.BINHO

        platform = sys.platform
        if platform in ('linux', 'linux2'):
            return self._linux_id()
        if platform == 'esp8266':
            return chips.ESP8266
        if platform == 'samd21':
            return chips.SAMD21
        if platform == 'pyboard':
            return chips.STM32
        # nothing found!
        return None
コード例 #8
0
ファイル: mockusb.py プロジェクト: cruizdeg/pyftdi
 def test_enumerate(self):
     """Enumerate FTDI devices."""
     ftdis = [(0x403, pid)
              for pid in (0x6001, 0x6010, 0x6011, 0x6014, 0x6015)]
     count = len(UsbTools.find_all(ftdis))
     self.assertEqual(count, 6)
コード例 #9
0
    def id(
        self,
    ) -> Optional[
        str
    ]:  # pylint: disable=invalid-name,too-many-branches,too-many-return-statements
        """Return a unique id for the detected chip, if any."""
        # There are some times we want to trick the platform detection
        # say if a raspberry pi doesn't have the right ID, or for testing

        # Caching
        if self._chip_id:
            return self._chip_id

        if getattr(os, "environ", None) is not None:
            try:
                return os.environ["BLINKA_FORCECHIP"]
            except KeyError:  # no forced chip, continue with testing!
                pass

            # Special cases controlled by environment var
            if os.environ.get("BLINKA_FT232H"):
                from pyftdi.usbtools import UsbTools

                # look for it based on PID/VID
                count = len(UsbTools.find_all([(0x0403, 0x6014)]))
                if count == 0:
                    raise RuntimeError(
                        "BLINKA_FT232H environment variable "
                        + "set, but no FT232H device found"
                    )
                self._chip_id = chips.FT232H
                return self._chip_id
            if os.environ.get("BLINKA_FT2232H"):
                from pyftdi.usbtools import UsbTools

                # look for it based on PID/VID
                count = len(UsbTools.find_all([(0x0403, 0x6010)]))
                if count == 0:
                    raise RuntimeError(
                        "BLINKA_FT2232H environment variable "
                        + "set, but no FT2232H device found"
                    )
                self._chip_id = chips.FT2232H
                return self._chip_id
            if os.environ.get("BLINKA_MCP2221"):
                import hid

                # look for it based on PID/VID
                for dev in hid.enumerate():
                    if dev["vendor_id"] == 0x04D8 and dev["product_id"] == 0x00DD:
                        self._chip_id = chips.MCP2221
                        return self._chip_id
                raise RuntimeError(
                    "BLINKA_MCP2221 environment variable "
                    + "set, but no MCP2221 device found"
                )
            if os.environ.get("BLINKA_U2IF"):
                import hid

                # look for it based on PID/VID
                for dev in hid.enumerate():
                    vendor = dev["vendor_id"]
                    product = dev["product_id"]
                    # NOTE: If any products are added here, they need added
                    # to _rp2040_u2if_id() in board.py as well.
                    if (
                        # Raspberry Pi Pico
                        vendor == 0xCAFE
                        and product == 0x4005
                    ) or (
                        # Feather RP2040
                        # Itsy Bitsy RP2040
                        # QT Py RP2040
                        # QT2040 Trinkey
                        # MacroPad RP2040
                        vendor == 0x239A
                        and product in (0x00F1, 0x00FD, 0x00F7, 0x0109, 0x0107)
                    ):
                        self._chip_id = chips.RP2040_U2IF
                        return self._chip_id
                raise RuntimeError(
                    "BLINKA_U2IF environment variable "
                    + "set, but no compatible device found"
                )
            if os.environ.get("BLINKA_GREATFET"):
                import usb

                if usb.core.find(idVendor=0x1D50, idProduct=0x60E6) is not None:
                    self._chip_id = chips.LPC4330
                    return self._chip_id
                raise RuntimeError(
                    "BLINKA_GREATFET environment variable "
                    + "set, but no GreatFET device found"
                )
            if os.environ.get("BLINKA_NOVA"):
                self._chip_id = chips.BINHO
                return self._chip_id

        platform = sys.platform
        if platform in ("linux", "linux2"):
            self._chip_id = self._linux_id()
            return self._chip_id
        if platform == "esp8266":
            self._chip_id = chips.ESP8266
            return self._chip_id
        if platform == "samd21":
            self._chip_id = chips.SAMD21
            return self._chip_id
        if platform == "pyboard":
            self._chip_id = chips.STM32F405
            return self._chip_id
        if platform == "rp2":
            self._chip_id = chips.RP2040
            return self._chip_id
        # nothing found!
        return None
コード例 #10
0
ファイル: ftdi.py プロジェクト: kery-chen/pyftdi
 def find_all(vps, nocache=False):
     """Find all devices that match the vendor/product pairs of the vps
        list."""
     return UsbTools.find_all(vps, nocache)
コード例 #11
0
 def find_all(vps, nocache=False):
     """Find all devices that match the vendor/product pairs of the vps
        list."""
     return UsbTools.find_all(vps, nocache)