@@ -23,32 +23,20 @@ Introduction
23
23
24
24
Helpers for getting USB descriptors
25
25
26
-
27
26
Dependencies
28
27
=============
29
28
This driver depends on:
30
29
31
- * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython >`_
30
+ * `Adafruit CircuitPython 9+ <https://github.com/adafruit/circuitpython >`_
32
31
33
32
Please ensure all dependencies are available on the CircuitPython filesystem.
34
33
This is easily achieved by downloading
35
34
`the Adafruit library and driver bundle <https://circuitpython.org/libraries >`_
36
35
or individual libraries can be installed using
37
36
`circup <https://github.com/adafruit/circup >`_.
38
37
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
-
46
38
Installing from PyPI
47
39
=====================
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.
52
40
53
41
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
54
42
PyPI <https://pypi.org/project/adafruit-circuitpython-usb-host-descriptors/> `_.
@@ -99,8 +87,59 @@ Or the following command to update an existing version:
99
87
Usage Example
100
88
=============
101
89
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 )
104
143
105
144
Documentation
106
145
=============
0 commit comments