2 \defgroup usbd_interface_gr USB Device Interface
3 \ingroup usb_interface_gr
4 \brief Driver API for USB Device Peripheral (%Driver_USBD.h)
9 \struct ARM_DRIVER_USBD
11 The functions of the USB Device driver are accessed by function pointers. Refer to \ref DriverFunctions for
14 Each instance of an USBD provides such an access struct. The instance is indicated by
15 a postfix in the symbol name of the access struct, for example:
16 - \b Driver_USBD0 is the name of the access struct of the first instance (no. 0).
17 - \b Driver_USBD1 is the name of the access struct of the second instance (no. 1).
20 A configuration setting in the middleware allows connecting the middleware to a specific driver instance <b>Driver_USBD<i>n</i></b>.
21 The default is \token{0}, which connects a middleware to the first instance of a driver.
23 \note The struct must remain unchanged.
24 *****************************************************************************************************************/
27 \struct ARM_USBD_CAPABILITIES
29 A USB Device driver can be implemented with different capabilities.
30 The data fields of this structure encode the capabilities implemented by this driver.
33 - \ref ARM_USBD_GetCapabilities
35 \note The struct must remain unchanged.
36 *****************************************************************************************************************/
39 \struct ARM_USBD_STATE
41 This structure stores information about the state of the USB Device. The data fields encode the established speed,
42 whether the device is powered and active.
45 - \ref ARM_USBD_DeviceGetState
46 *****************************************************************************************************************/
49 \typedef ARM_USBD_SignalDeviceEvent_t
51 Provides the typedef for the callback function \ref ARM_USBD_SignalDeviceEvent.
54 - \ref ARM_USBD_Initialize
55 *******************************************************************************************************************/
58 \typedef ARM_USBD_SignalEndpointEvent_t
60 Provides the typedef for the callback function \ref ARM_USBD_SignalEndpointEvent.
63 - \ref ARM_USBD_Initialize
64 *******************************************************************************************************************/
67 \defgroup USBD_dev_events USBD Device Events
68 \ingroup usbd_interface_gr
69 \brief The USB Device driver generates Device call back events that are notified via the function \ref ARM_USBD_SignalDeviceEvent.
71 This section provides the event values for the \ref ARM_USBD_SignalDeviceEvent callback function.
73 The following call back notification events are generated:
75 \def ARM_USBD_EVENT_VBUS_ON
76 \def ARM_USBD_EVENT_VBUS_OFF
77 \def ARM_USBD_EVENT_RESET
78 \def ARM_USBD_EVENT_HIGH_SPEED
79 \def ARM_USBD_EVENT_SUSPEND
80 \def ARM_USBD_EVENT_RESUME
85 \defgroup USBD_ep_events USBD Endpoint Events
86 \ingroup usbd_interface_gr
87 \brief The USB Device driver generates Endpoint call back events that are notified via the function \ref ARM_USBD_SignalEndpointEvent.
89 This section provides the event values for the \ref ARM_USBD_SignalEndpointEvent callback function.
91 The following call back notification events are generated:
93 \def ARM_USBD_EVENT_SETUP
94 \def ARM_USBD_EVENT_OUT
95 \def ARM_USBD_EVENT_IN
104 ARM_DRIVER_VERSION ARM_USBD_GetVersion (void) {
108 \fn ARM_DRIVER_VERSION ARM_USBD_GetVersion (void)
110 The function \b ARM_USBD_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION
111 - API version is the version of the CMSIS-Driver specification used to implement this driver.
112 - Driver version is source code version of the actual driver implementation.
116 extern ARM_DRIVER_USBD Driver_USBD0;
117 ARM_DRIVER_USBD *drv_info;
119 void setup_usbd (void) {
120 ARM_DRIVER_VERSION version;
122 drv_info = &Driver_USBD0;
123 version = drv_info->GetVersion ();
124 if (version.api < 0x10A) { // requires at minimum API version 1.10 or higher
130 *****************************************************************************************************************/
132 ARM_USBD_CAPABILITIES ARM_USBD_GetCapabilities (void) {
136 \fn ARM_USBD_CAPABILITIES ARM_USBD_GetCapabilities (void)
138 The function \b ARM_USBD_GetCapabilities returns information about capabilities in this driver implementation.
139 The data fields of the structure \ref ARM_USBD_CAPABILITIES encode various capabilities, for example
140 if the hardware can create signal events using the \ref ARM_USBD_SignalDeviceEvent callback function.
144 extern ARM_DRIVER_USBD Driver_USBD0;
145 ARM_DRIVER_USBD *drv_info;
147 void read_capabilities (void) {
148 ARM_USBD_CAPABILITIES drv_capabilities;
150 drv_info = &Driver_USBD0;
151 drv_capabilities = drv_info->GetCapabilities ();
152 // interrogate capabilities
156 *****************************************************************************************************************/
158 int32_t ARM_USBD_Initialize (ARM_USBD_SignalDeviceEvent_t cb_device_event,
159 ARM_USBD_SignalEndpointEvent_t cb_endpoint_event) {
160 return ARM_DRIVER_OK;
163 \fn int32_t ARM_USBD_Initialize (ARM_USBD_SignalDeviceEvent_t cb_device_event, ARM_USBD_SignalEndpointEvent_t cb_endpoint_event)
165 The function \b ARM_USBD_Initialize initializes the USB Device interface.
166 It is called when the middleware component starts operation.
168 The function performs the following operations:
169 - Initializes the resources needed for the USBD interface.
170 - Registers the \ref ARM_USBD_SignalDeviceEvent callback function.
171 - Registers the \ref ARM_USBD_SignalEndpointEvent callback function.
173 The parameter \em cb_device_event is a pointer to the \ref ARM_USBD_SignalDeviceEvent callback function; use a NULL pointer
174 when no device callback signals are required. \n
175 The parameter \em cb_endpoint_event is a pointer to the \ref ARM_USBD_SignalEndpointEvent callback function.
178 - see \ref usbd_interface_gr - Driver Functions
180 *****************************************************************************************************************/
182 int32_t ARM_USBD_Uninitialize (void) {
183 return ARM_DRIVER_OK;
186 \fn int32_t ARM_USBD_Uninitialize (void)
188 The function \b ARM_USBD_Uninitialize de-initializes the resources of USBD interface.
190 It is called when the middleware component stops operation and releases the software resources used by the interface.
191 *****************************************************************************************************************/
193 int32_t ARM_USBD_PowerControl (ARM_POWER_STATE state) {
194 return ARM_DRIVER_OK;
197 \fn int32_t ARM_USBD_PowerControl (ARM_POWER_STATE state)
199 The function \b ARM_USBD_PowerControl operates the power modes of the USB Device interface.
201 The parameter \em state sets the operation and can have the following values:
202 - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA.
203 Can be called multiple times. If the peripheral is already in this mode the function performs
204 no operation and returns with \ref ARM_DRIVER_OK.
205 - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
206 - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
208 Refer to \ref CallSequence for more information.
209 *****************************************************************************************************************/
211 int32_t ARM_USBD_DeviceConnect (void) {
212 return ARM_DRIVER_OK;
215 \fn int32_t ARM_USBD_DeviceConnect (void)
217 The function \b ARM_USBD_DeviceConnect signals to the host that the device is connected.
218 *****************************************************************************************************************/
220 int32_t ARM_USBD_DeviceDisconnect (void) {
221 return ARM_DRIVER_OK;
224 \fn int32_t ARM_USBD_DeviceDisconnect (void)
226 The function \b ARM_USBD_DeviceDisconnect signals to the host that the device is disconnected.
227 *****************************************************************************************************************/
229 ARM_USBD_STATE ARM_USBD_DeviceGetState (void) {
230 return ARM_DRIVER_OK;
233 \fn ARM_USBD_STATE ARM_USBD_DeviceGetState (void)
235 Retrieves the current USB device state.
236 *****************************************************************************************************************/
238 int32_t ARM_USBD_DeviceRemoteWakeup (void) {
239 return ARM_DRIVER_OK;
242 \fn int32_t ARM_USBD_DeviceRemoteWakeup (void)
244 The function \b ARM_USBD_DeviceRemoteWakeup signals remote wakeup to the host.
245 *****************************************************************************************************************/
247 int32_t ARM_USBD_DeviceSetAddress (uint8_t dev_addr) {
248 return ARM_DRIVER_OK;
251 \fn int32_t ARM_USBD_DeviceSetAddress (uint8_t dev_addr)
253 Assigns an address to the device.
254 \note This function is called after status stage of the Set Address request (after IN packet in status stage was sent with the old address).
256 *****************************************************************************************************************/
258 int32_t ARM_USBD_ReadSetupPacket (uint8_t *setup) {
259 return ARM_DRIVER_OK;
262 \fn int32_t ARM_USBD_ReadSetupPacket (uint8_t *setup)
264 The function \b ARM_USBD_ReadSetupPacket reads the last SETUP packet (8 bytes) that was received over Control Endpoint (Endpoint 0)
265 which is indicated by \ref ARM_USBD_EVENT_SETUP event.
268 - \ref ARM_USBD_SignalEndpointEvent
269 *****************************************************************************************************************/
271 int32_t ARM_USBD_EndpointConfigure (uint8_t ep_addr,
273 uint16_t ep_max_packet_size) {
274 return ARM_DRIVER_OK;
277 \fn int32_t ARM_USBD_EndpointConfigure (uint8_t ep_addr, uint8_t ep_type, uint16_t ep_max_packet_size)
279 The function \b ARM_USBD_EndpointConfigure configures an endpoint for transfers.
282 *****************************************************************************************************************/
284 int32_t ARM_USBD_EndpointUnconfigure (uint8_t ep_addr) {
285 return ARM_DRIVER_OK;
288 \fn int32_t ARM_USBD_EndpointUnconfigure (uint8_t ep_addr)
290 The function \b ARM_USBD_EndpointUnconfigure de-configures the specified endpoint.
292 The parameter \em ep_addr specifies the endpoint address.
293 *****************************************************************************************************************/
295 int32_t ARM_USBD_EndpointStall (uint8_t ep_addr, bool stall) {
296 return ARM_DRIVER_OK;
299 \fn int32_t ARM_USBD_EndpointStall (uint8_t ep_addr, bool stall)
301 The function \b ARM_USBD_EndpointStall sets or clears stall condition for the specified endpoint.
303 The parameter \em ep_addr specifies the endpoint address. \n
304 The parameter \em stall is a boolean parameter.
305 *****************************************************************************************************************/
307 int32_t ARM_USBD_EndpointTransfer (uint8_t ep_addr, uint8_t *data, uint32_t num) {
308 return ARM_DRIVER_OK;
311 \fn int32_t ARM_USBD_EndpointTransfer (uint8_t ep_addr, uint8_t *data, uint32_t num)
314 The function \b ARM_USBD_EndpointTransfer reads from or writes data to an USB Endpoint.
316 The parameter \em ep_addr specifies the endpoint address. \n
317 The parameter \em data is a buffer for data to read or data to write. \n
318 The parameter \em num is the number of bytes to transfer (must be multiple of endpoint maximum packet size for Read transfers).
320 The function is non-blocking and returns as soon as the driver starts the operation on the specified endpoint.
321 During the operation it is not allowed to call this function again on the same endpoint.
322 Also the data buffer must stay allocated and the contents of data must not be modified.
324 Direction in the endpoint address specifies the type of transfer:
325 - Endpoint Read for OUT endpoint (direction = 0)
326 - Endpoint Write for IN endpoint (direction = 1)
328 Endpoint Read is finished when the requested number of data bytes have been received or when a short packet or ZLP (Zero-Length Packet) has been received.
329 Completion of operation is indicated by \ref ARM_USBD_EVENT_OUT event. Number of successfully received data bytes can be retrieved
330 by calling \ref ARM_USBD_EndpointTransferGetResult.
332 Endpoint Write is finished when the requested number of data bytes have been sent.
333 Completion of operation is indicated by \ref ARM_USBD_EVENT_IN event. Number of successfully sent data bytes can be retrieved
334 by calling \ref ARM_USBD_EndpointTransferGetResult.
336 Transfer operation can be aborted by calling \ref ARM_USBD_EndpointTransferAbort.
337 *****************************************************************************************************************/
339 uint32_t ARM_USBD_EndpointTransferGetResult (uint8_t ep_addr) {
343 \fn uint32_t ARM_USBD_EndpointTransferGetResult (uint8_t ep_addr)
345 The function \b ARM_USBD_EndpointTransferGetResult returns the number of successfully transferred data bytes started by \ref ARM_USBD_EndpointTransfer.
347 The parameter \em ep_addr specifies the endpoint address.
348 *****************************************************************************************************************/
350 int32_t ARM_USBD_EndpointTransferAbort (uint8_t ep_addr) {
351 return ARM_DRIVER_OK;
354 \fn int32_t ARM_USBD_EndpointTransferAbort (uint8_t ep_addr)
356 The function \b ARM_USBD_EndpointTransferAbort aborts the transfer to an endpoint started by \ref ARM_USBD_EndpointTransfer.
358 The parameter \em ep_addr specifies the endpoint address.
359 *****************************************************************************************************************/
361 uint16_t ARM_USBD_GetFrameNumber (void) {
365 \fn uint16_t ARM_USBD_GetFrameNumber (void)
367 Retrieves the sequential 11-bit frame number of the last Start of Frame (SOF) packet.
368 *****************************************************************************************************************/
370 void ARM_USBD_SignalDeviceEvent (uint32_t event) {
374 \fn void ARM_USBD_SignalDeviceEvent (uint32_t event)
376 The function \b ARM_USBD_SignalDeviceEvent is a callback function registered by the function \ref ARM_USBD_Initialize.
378 The parameter \em event indicates one or more events that occurred during driver operation.
379 Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call.
381 Not every event is necessarily generated by the driver. This depends on the implemented capabilities stored in the
382 data fields of the structure \ref ARM_USBD_CAPABILITIES, which can be retrieved with the function \ref ARM_USBD_GetCapabilities.
384 The following events can be generated:
386 Event | Bit| Description | supported when \ref ARM_USBD_CAPABILITIES
387 :-------------------------------|---:|:---------------------------------------------------|----------------------------------------------
388 \ref ARM_USBD_EVENT_VBUS_ON | 0 | Occurs when valid VBUS voltage is detected. | data field \em event_vbus_on = \token{1}
389 \ref ARM_USBD_EVENT_VBUS_OFF | 1 | Occurs when VBUS voltage is turned off. | data field \em event_vbus_off = \token{1}
390 \ref ARM_USBD_EVENT_RESET | 2 | Occurs when USB Reset is detected. | <i>always supported</i>
391 \ref ARM_USBD_EVENT_HIGH_SPEED | 3 | Occurs when USB Device is switched to High-speed. | <i>always supported</i>
392 \ref ARM_USBD_EVENT_SUSPEND | 4 | Occurs when USB Suspend is detected. | <i>always supported</i>
393 \ref ARM_USBD_EVENT_RESUME | 5 | Occurs when USB Resume is detected. | <i>always supported</i>
394 *****************************************************************************************************************/
396 void ARM_USBD_SignalEndpointEvent (uint8_t ep_addr, uint32_t ep_event) {
400 \fn void ARM_USBD_SignalEndpointEvent (uint8_t ep_addr, uint32_t event)
402 The function \b ARM_USBD_SignalEndpointEvent is a callback function registered by the function \ref ARM_USBD_Initialize.
404 The argument \a ep_addr specifies the endpoint. \n
405 The parameter \em event indicates one or more events that occurred during driver operation.
406 Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call.
408 The following events can be generated:
410 Event | Bit | Description
411 :----------------------------------------|----:|:-----------
412 \ref ARM_USBD_EVENT_SETUP | 0 | Occurs when SETUP packet is received over Control Endpoint.
413 \ref ARM_USBD_EVENT_OUT | 1 | Occurs when data is received over OUT Endpoint.
414 \ref ARM_USBD_EVENT_IN | 2 | Occurs when data is sent over IN Endpoint.
415 *****************************************************************************************************************/
420 // End USBD Interface