Skip to content

Commit 4b78225

Browse files
Loic PoulainAnas Nashif
authored andcommitted
doc: usb: Update API doc
Add missing DC driver functions: - usb_dc_ep_read_wait - usb_dc_ep_read_continue - usb_dc_ep_mps Add missing DC status code: - USB_DC_INTERFACE Document new transfer API. Signed-off-by: Loic Poulain <[email protected]>
1 parent fe46c75 commit 4b78225

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

doc/subsystems/usb/usb.rst

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Structure containing the USB endpoint configuration.
5959
USB_DC_DISCONNECTED,
6060
USB_DC_SUSPEND,
6161
USB_DC_RESUME,
62+
USB_DC_INTERFACE,
6263
USB_DC_UNKNOWN
6364
};
6465
@@ -70,6 +71,7 @@ Status codes reported by the registered device status callback.
7071
* USB_DC_DISCONNECTED: USB connection lost.
7172
* USB_DC_SUSPEND: USB connection suspended by the HOST.
7273
* USB_DC_RESUME: USB connection resumed by the HOST.
74+
* USB_DC_INTERFACE: USB Interface selected by the HOST.
7375
* USB_DC_UNKNOWN: Initial USB connection status.
7476

7577
.. code-block:: c
@@ -155,6 +157,21 @@ The following APIs are provided by the device controller driver:
155157
and available to application or transmit done on the selected endpoint.
156158
The callback status code is described by usb_dc_ep_cb_status_code.
157159

160+
:c:func:`usb_dc_ep_read_wait()`
161+
This function is similar to usb_dc_ep_read, the difference being that, it
162+
doesn't clear the endpoint NAKs so that the consumer is not bogged down by
163+
further upcalls till he is done with the processing of the data. The caller
164+
should reactivate ep by invoking usb_dc_ep_read_continue() do so.
165+
166+
:c:func:`usb_dc_ep_read_continue()`
167+
Clear the endpoint NAK and enable the endpoint to accept more data from the
168+
host. Usually called after usb_dc_ep_read_wait() when the consumer is fine
169+
to accept more data. Thus these calls together acts as flow control
170+
mechanism.
171+
172+
:c:func:`usb_dc_ep_mps()`
173+
Get endpoint max packet size.
174+
158175
USB device core layer
159176
*********************
160177

@@ -282,6 +299,14 @@ APIs
282299
interrupt has been received for that EP. The application must only call
283300
this function through the supplied usb_ep_callback function.
284301

302+
:c:func:`usb_transfer()`
303+
This asynchronous function starts a usb transfer from/to a specified buffer.
304+
A callback can be provided and will be called on transfer completion.
305+
This function can be used in IRQ context.
306+
307+
:c:func:`usb_transfer_sync()`
308+
This function is the synchronous version of the usb_transfer function,
309+
waiting for transfer completion before returning.
285310

286311
USB device class drivers
287312
************************
@@ -525,18 +550,28 @@ class requests:
525550
return 0;
526551
}
527552
528-
The class driver should wait for the USB_DC_CONFIGURED device status code
553+
The class driver should wait for the USB_DC_INTERFACE device status code
529554
before transmitting any data.
530555

556+
There are two ways to transmit data, using the 'low' level read/write API or
557+
the 'high' level transfer API.
558+
559+
low level API:
560+
531561
To transmit data to the host, the class driver should call usb_write().
532562
Upon completion the registered endpoint callback will be called. Before
533563
sending another packet the class driver should wait for the completion of
534-
the previous transfer.
564+
the previous write. When data is received, the registered endpoint callback
565+
is called. usb_read() should be used for retrieving the received data.
566+
For CDC ACM sample driver this happens via the OUT bulk endpoint handler
567+
(cdc_acm_bulk_out) mentioned in the endpoint array (cdc_acm_ep_data).
568+
569+
high level API:
570+
571+
The usb_transfer method can be used to transfer data to/from the host. The
572+
transfer API will automatically split the data transmission into one or more
573+
USB transaction(s), depending endpoint max packet size. The class driver does
574+
not have to implement endpoint callback and should set this callback to the
575+
generic usb_transfer_ep_callback.
535576

536-
When data is received, the registered endpoint callback is called.
537-
usb_read() should be used for retrieving the received data. It must
538-
always be called through the registered endpoint callback. For CDC ACM
539-
sample driver this happens via the OUT bulk endpoint handler (cdc_acm_bulk_out)
540-
mentioned in the endpoint array (cdc_acm_ep_data).
541577

542-
Only CDC ACM and DFU class driver examples are provided for now.

0 commit comments

Comments
 (0)