|
1 | 1 | .. _usb_api: |
2 | 2 |
|
3 | | -USB device stack |
4 | | -################ |
| 3 | +USB device support |
| 4 | +################## |
5 | 5 |
|
6 | | -.. contents:: |
7 | | - :depth: 2 |
8 | | - :local: |
9 | | - :backlinks: top |
| 6 | +.. toctree:: |
| 7 | + :maxdepth: 1 |
10 | 8 |
|
11 | | -USB Vendor and Product identifiers |
12 | | -********************************** |
13 | | - |
14 | | -The USB Vendor ID for the Zephyr project is 0x2FE3. The default USB Product |
15 | | -ID for the Zephyr project is 0x100. The USB bcdDevice Device Release Number |
16 | | -represents the Zephyr kernel major and minor versions as a binary coded |
17 | | -decimal value. When a vendor integrates the Zephyr USB subsystem into a |
18 | | -product, the vendor must use the USB Vendor and Product ID assigned to them. |
19 | | -A vendor integrating the Zephyr USB subsystem in a product must not use the |
20 | | -Vendor ID of the Zephyr project. |
21 | | - |
22 | | -The USB maintainer, if one is assigned, or otherwise the Zephyr Technical |
23 | | -Steering Committee, may allocate other USB Product IDs based on well-motivated |
24 | | -and documented requests. |
25 | | - |
26 | | -Each USB sample has its own unique Product ID. |
27 | | -When adding a new sample, add a new entry in :file:`samples/subsys/usb/usb_pid.Kconfig` |
28 | | -and a Kconfig file inside your sample subdirectory. |
29 | | -The following Product IDs are currently used: |
30 | | - |
31 | | -* :kconfig:`CONFIG_USB_PID_CDC_ACM_SAMPLE` |
32 | | -* :kconfig:`CONFIG_USB_PID_CDC_ACM_COMPOSITE_SAMPLE` |
33 | | -* :kconfig:`CONFIG_USB_PID_HID_CDC_SAMPLE` |
34 | | -* :kconfig:`CONFIG_USB_PID_CONSOLE_SAMPLE` |
35 | | -* :kconfig:`CONFIG_USB_PID_DFU_SAMPLE` |
36 | | -* :kconfig:`CONFIG_USB_PID_HID_SAMPLE` |
37 | | -* :kconfig:`CONFIG_USB_PID_HID_MOUSE_SAMPLE` |
38 | | -* :kconfig:`CONFIG_USB_PID_MASS_SAMPLE` |
39 | | -* :kconfig:`CONFIG_USB_PID_TESTUSB_SAMPLE` |
40 | | -* :kconfig:`CONFIG_USB_PID_WEBUSB_SAMPLE` |
41 | | -* :kconfig:`CONFIG_USB_PID_BLE_HCI_H4_SAMPLE` |
42 | | - |
43 | | -USB device controller drivers |
44 | | -***************************** |
45 | | - |
46 | | -The Device Controller Driver Layer implements the low level control routines |
47 | | -to deal directly with the hardware. All device controller drivers should |
48 | | -implement the APIs described in file usb_dc.h. This allows the integration of |
49 | | -new USB device controllers to be done without changing the upper layers. |
50 | | - |
51 | | -USB Device Controller API |
52 | | -========================= |
53 | | - |
54 | | -.. doxygengroup:: _usb_device_controller_api |
55 | | - |
56 | | -USB device core layer |
57 | | -********************* |
58 | | - |
59 | | -The USB Device core layer is a hardware independent interface between USB |
60 | | -device controller driver and USB device class drivers or customer applications. |
61 | | -It's a port of the LPCUSB device stack. It provides the following |
62 | | -functionalities: |
63 | | - |
64 | | -* Responds to standard device requests and returns standard descriptors, |
65 | | - essentially handling 'Chapter 9' processing, specifically the standard |
66 | | - device requests in table 9-3 from the universal serial bus specification |
67 | | - revision 2.0. |
68 | | -* Provides a programming interface to be used by USB device classes or |
69 | | - customer applications. The APIs are described in the usb_device.h file. |
70 | | -* Uses the APIs provided by the device controller drivers to interact with |
71 | | - the USB device controller. |
72 | | - |
73 | | - |
74 | | -USB Device Core Layer API |
75 | | -========================= |
76 | | - |
77 | | -There are two ways to transmit data, using the 'low' level read/write API or |
78 | | -the 'high' level transfer API. |
79 | | - |
80 | | -Low level API |
81 | | - To transmit data to the host, the class driver should call usb_write(). |
82 | | - Upon completion the registered endpoint callback will be called. Before |
83 | | - sending another packet the class driver should wait for the completion of |
84 | | - the previous write. When data is received, the registered endpoint callback |
85 | | - is called. usb_read() should be used for retrieving the received data. |
86 | | - For CDC ACM sample driver this happens via the OUT bulk endpoint handler |
87 | | - (cdc_acm_bulk_out) mentioned in the endpoint array (cdc_acm_ep_data). |
88 | | - |
89 | | -High level API |
90 | | - The usb_transfer method can be used to transfer data to/from the host. The |
91 | | - transfer API will automatically split the data transmission into one or more |
92 | | - USB transaction(s), depending endpoint max packet size. The class driver does |
93 | | - not have to implement endpoint callback and should set this callback to the |
94 | | - generic usb_transfer_ep_callback. |
95 | | - |
96 | | -.. doxygengroup:: _usb_device_core_api |
97 | | - |
98 | | -USB device class drivers |
99 | | -************************ |
100 | | - |
101 | | -Zephyr USB Device Stack supports many standard classes, such as HID, MSC |
102 | | -Ethernet over USB, DFU, Bluetooth. |
103 | | - |
104 | | -Implementing non standard USB class |
105 | | -=================================== |
106 | | - |
107 | | -Configuration of USB Device is done in the stack layer. |
108 | | - |
109 | | -The following structures and callbacks need to be defined: |
110 | | - |
111 | | -* Part of USB Descriptor table |
112 | | -* USB Endpoint configuration table |
113 | | -* USB Device configuration structure |
114 | | -* Endpoint callbacks |
115 | | -* Optionally class, vendor and custom handlers |
116 | | - |
117 | | -For example, for USB loopback application: |
118 | | - |
119 | | -.. literalinclude:: ../../../subsys/usb/class/loopback.c |
120 | | - :language: c |
121 | | - :start-after: usb.rst config structure start |
122 | | - :end-before: usb.rst config structure end |
123 | | - :linenos: |
124 | | - |
125 | | -Endpoint configuration: |
126 | | - |
127 | | -.. literalinclude:: ../../../subsys/usb/class/loopback.c |
128 | | - :language: c |
129 | | - :start-after: usb.rst endpoint configuration start |
130 | | - :end-before: usb.rst endpoint configuration end |
131 | | - :linenos: |
132 | | - |
133 | | -USB Device configuration structure: |
134 | | - |
135 | | -.. literalinclude:: ../../../subsys/usb/class/loopback.c |
136 | | - :language: c |
137 | | - :start-after: usb.rst device config data start |
138 | | - :end-before: usb.rst device config data end |
139 | | - :linenos: |
140 | | - |
141 | | - |
142 | | -The vendor device requests are forwarded by the USB stack core driver to the |
143 | | -class driver through the registered vendor handler. |
144 | | - |
145 | | -For the loopback class driver, :c:func:`loopback_vendor_handler` processes |
146 | | -the vendor requests: |
147 | | - |
148 | | -.. literalinclude:: ../../../subsys/usb/class/loopback.c |
149 | | - :language: c |
150 | | - :start-after: usb.rst vendor handler start |
151 | | - :end-before: usb.rst vendor handler end |
152 | | - :linenos: |
153 | | - |
154 | | -The class driver waits for the :makevar:`USB_DC_CONFIGURED` device status code |
155 | | -before transmitting any data. |
156 | | - |
157 | | -.. _testing_USB_native_posix: |
158 | | - |
159 | | -Testing USB over USP/IP in native_posix |
160 | | -*************************************** |
161 | | - |
162 | | -Virtual USB controller implemented through USB/IP might be used to test USB |
163 | | -Device stack. Follow general build procedure to build USB sample for |
164 | | -the native_posix configuration. |
165 | | - |
166 | | -Run built sample with: |
167 | | - |
168 | | -.. code-block:: console |
169 | | -
|
170 | | - west build -t run |
171 | | -
|
172 | | -In a terminal window, run the following command to list USB devices: |
173 | | - |
174 | | -.. code-block:: console |
175 | | -
|
176 | | - $ usbip list -r localhost |
177 | | - Exportable USB devices |
178 | | - ====================== |
179 | | - - 127.0.0.1 |
180 | | - 1-1: unknown vendor : unknown product (2fe3:0100) |
181 | | - : /sys/devices/pci0000:00/0000:00:01.2/usb1/1-1 |
182 | | - : (Defined at Interface level) (00/00/00) |
183 | | - : 0 - Vendor Specific Class / unknown subclass / unknown protocol (ff/00/00) |
184 | | -
|
185 | | -In a terminal window, run the following command to attach USB device: |
186 | | - |
187 | | -.. code-block:: console |
188 | | -
|
189 | | - $ sudo usbip attach -r localhost -b 1-1 |
190 | | -
|
191 | | -The USB device should be connected to your Linux host, and verified with the following commands: |
192 | | - |
193 | | -.. code-block:: console |
194 | | -
|
195 | | - $ sudo usbip port |
196 | | - Imported USB devices |
197 | | - ==================== |
198 | | - Port 00: <Port in Use> at Full Speed(12Mbps) |
199 | | - unknown vendor : unknown product (2fe3:0100) |
200 | | - 7-1 -> usbip://localhost:3240/1-1 |
201 | | - -> remote bus/dev 001/002 |
202 | | - $ lsusb -d 2fe3:0100 |
203 | | - Bus 007 Device 004: ID 2fe3:0100 |
204 | | -
|
205 | | -USB Human Interface Devices (HID) support |
206 | | -***************************************** |
207 | | - |
208 | | -HID Item helpers |
209 | | -================ |
210 | | - |
211 | | -HID item helper macros can be used to compose a HID Report Descriptor. |
212 | | -The names correspond to those used in the USB HID Specification. |
213 | | - |
214 | | -Example of a HID Report Descriptor: |
215 | | - |
216 | | -.. code-block:: c |
217 | | -
|
218 | | - static const uint8_t hid_report_desc[] = { |
219 | | - HID_USAGE_PAGE(HID_USAGE_GEN_DESKTOP), |
220 | | - HID_USAGE(HID_USAGE_GEN_DESKTOP_UNDEFINED), |
221 | | - HID_COLLECTION(HID_COLLECTION_APPLICATION), |
222 | | - HID_LOGICAL_MIN8(0), |
223 | | - /* logical maximum 255 */ |
224 | | - HID_LOGICAL_MAX16(0xFF, 0x00), |
225 | | - HID_REPORT_ID(1), |
226 | | - HID_REPORT_SIZE(8), |
227 | | - HID_REPORT_COUNT(1), |
228 | | - HID_USAGE(HID_USAGE_GEN_DESKTOP_UNDEFINED), |
229 | | - /* HID_INPUT (Data, Variable, Absolute) */ |
230 | | - HID_INPUT(0x02), |
231 | | - HID_END_COLLECTION, |
232 | | - }; |
233 | | -
|
234 | | -
|
235 | | -.. doxygengroup:: usb_hid_items |
236 | | - |
237 | | -.. doxygengroup:: usb_hid_types |
238 | | - |
239 | | -HID Mouse and Keyboard report descriptors |
240 | | -========================================= |
241 | | - |
242 | | -The pre-defined Mouse and Keyboard report descriptors can be used by |
243 | | -a HID device implementation or simply as examples. |
244 | | - |
245 | | -.. doxygengroup:: usb_hid_mk_report_desc |
246 | | - |
247 | | -HID Class Device API |
248 | | -******************** |
249 | | - |
250 | | -USB HID devices like mouse, keyboard, or any other specific device use this API. |
251 | | - |
252 | | -.. doxygengroup:: usb_hid_device_api |
| 9 | + udc.rst |
| 10 | + uds.rst |
| 11 | + uds_testing.rst |
| 12 | + hid.rst |
0 commit comments