@@ -23,32 +23,20 @@ Introduction
2323
2424Helpers for getting USB descriptors
2525
26-
2726Dependencies
2827=============
2928This driver depends on:
3029
31- * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython >`_
30+ * `Adafruit CircuitPython 9+ <https://github.com/adafruit/circuitpython >`_
3231
3332Please ensure all dependencies are available on the CircuitPython filesystem.
3433This is easily achieved by downloading
3534`the Adafruit library and driver bundle <https://circuitpython.org/libraries >`_
3635or individual libraries can be installed using
3736`circup <https://github.com/adafruit/circup >`_.
3837
39-
40-
41- .. todo :: Describe the Adafruit product this library works with. For PCBs, you can also add the
42- image from the assets folder in the PCB's GitHub repo.
43-
44- `Purchase one from the Adafruit shop <http://www.adafruit.com/products/ >`_
45-
4638Installing from PyPI
4739=====================
48- .. note :: This library is not available on PyPI yet. Install documentation is included
49- as a standard element. Stay tuned for PyPI availability!
50-
51- .. todo :: Remove the above note if PyPI version is/will be available at time of release.
5240
5341On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
5442PyPI <https://pypi.org/project/adafruit-circuitpython-usb-host-descriptors/> `_.
@@ -99,8 +87,59 @@ Or the following command to update an existing version:
9987 Usage Example
10088=============
10189
102- .. todo :: Add a quick, simple example. It and other examples should live in the
103- examples folder and be included in docs/examples.rst.
90+ Print basic information about a device and its first (and usually only) configuration.
91+
92+ .. code-block :: python
93+
94+ # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
95+ # SPDX-FileCopyrightText: Copyright (c) 2023 Scott Shawcroft for Adafruit Industries
96+ #
97+ # SPDX-License-Identifier: Unlicense
98+
99+ import time
100+ import usb.core
101+
102+ import adafruit_usb_host_descriptors
103+
104+ DIR_IN = 0x 80
105+
106+ while True :
107+ print (" searching for devices" )
108+ for device in usb.core.find(find_all = True ):
109+ print (" pid" , hex (device.idProduct))
110+ print (" vid" , hex (device.idVendor))
111+ print (" man" , device.manufacturer)
112+ print (" product" , device.product)
113+ print (" serial" , device.serial_number)
114+ print (" config[0]:" )
115+ config_descriptor = adafruit_usb_host_descriptors.get_configuration_descriptor(
116+ device, 0
117+ )
118+
119+ i = 0
120+ while i < len (config_descriptor):
121+ descriptor_len = config_descriptor[i]
122+ descriptor_type = config_descriptor[i + 1 ]
123+ if descriptor_type == adafruit_usb_host_descriptors.DESC_CONFIGURATION :
124+ config_value = config_descriptor[i + 5 ]
125+ print (f " value { config_value:d } " )
126+ elif descriptor_type == adafruit_usb_host_descriptors.DESC_INTERFACE :
127+ interface_number = config_descriptor[i + 2 ]
128+ interface_class = config_descriptor[i + 5 ]
129+ interface_subclass = config_descriptor[i + 6 ]
130+ print (f " interface[ { interface_number:d } ] " )
131+ print (
132+ f " class { interface_class:02x } subclass { interface_subclass:02x } "
133+ )
134+ elif descriptor_type == adafruit_usb_host_descriptors.DESC_ENDPOINT :
135+ endpoint_address = config_descriptor[i + 2 ]
136+ if endpoint_address & DIR_IN :
137+ print (f " IN { endpoint_address:02x } " )
138+ else :
139+ print (f " OUT { endpoint_address:02x } " )
140+ i += descriptor_len
141+ print ()
142+ time.sleep(5 )
104143
105144 Documentation
106145=============
0 commit comments