1 /* -----------------------------------------------------------------------------
2 * Copyright (c) 2013-2014 ARM Limited. All rights reserved.
4 * $Date: 2. January 2014
7 * Project: USB Device Driver API
8 * -------------------------------------------------------------------------- */
12 \defgroup usbd_interface_gr USB Device Interface
13 \ingroup usb_interface_gr
14 \brief Driver API for USB Device Peripheral (%Driver_USBD.h)
19 \struct ARM_DRIVER_USBD
21 The functions of the USB Device driver are accessed by function pointers. Refer to \ref DriverFunctions for
24 Each instance of an USBD provides such an access struct. The instance is indicated by
25 a postfix in the symbol name of the access struct, for example:
26 - \b Driver_USBD0 is the name of the access struct of the first instance (no. 0).
27 - \b Driver_USBD1 is the name of the access struct of the second instance (no. 1).
30 A configuration setting in the middleware allows connecting the middleware to a specific driver instance <b>Driver_USBD<i>n</i></b>.
31 The default is \token{0}, which connects a middleware to the first instance of a driver.
33 \note The struct must remain unchanged.
34 *****************************************************************************************************************/
37 \struct ARM_USBD_CAPABILITIES
39 A USB Device driver can be implemented with different capabilities.
40 The data fields of this structure encode the capabilities implemented by this driver.
43 - \ref ARM_USBD_GetCapabilities
45 \note The struct must remain unchanged.
46 *****************************************************************************************************************/
49 \struct ARM_USBD_STATE
51 This structure stores information about the state of the USB Device. The data fields encode the established speed,
52 whether the device is powered and active.
55 - \ref ARM_USBD_DeviceGetState
56 *****************************************************************************************************************/
59 \typedef ARM_USBD_SignalDeviceEvent_t
61 Provides the typedef for the callback function \ref ARM_USBD_SignalDeviceEvent.
64 - \ref ARM_USBD_Initialize
65 *******************************************************************************************************************/
68 \typedef ARM_USBD_SignalEndpointEvent_t
70 Provides the typedef for the callback function \ref ARM_USBD_SignalEndpointEvent.
73 - \ref ARM_USBD_Initialize
74 *******************************************************************************************************************/
77 \defgroup USBD_dev_events USBD Device Events
78 \ingroup usbd_interface_gr
79 \brief The USB Device driver generates Device call back events that are notified via the function \ref ARM_USBD_SignalDeviceEvent.
81 This section provides the event values for the \ref ARM_USBD_SignalDeviceEvent callback function.
83 The following call back notification events are generated:
85 \def ARM_USBD_EVENT_VBUS_ON
86 \def ARM_USBD_EVENT_VBUS_OFF
87 \def ARM_USBD_EVENT_RESET
88 \def ARM_USBD_EVENT_HIGH_SPEED
89 \def ARM_USBD_EVENT_SUSPEND
90 \def ARM_USBD_EVENT_RESUME
95 \defgroup USBD_ep_events USBD Endpoint Events
96 \ingroup usbd_interface_gr
97 \brief The USB Device driver generates Endpoint call back events that are notified via the function \ref ARM_USBD_SignalEndpointEvent.
99 This section provides the event values for the \ref ARM_USBD_SignalEndpointEvent callback function.
101 The following call back notification events are generated:
103 \def ARM_USBD_EVENT_SETUP
104 \def ARM_USBD_EVENT_OUT
105 \def ARM_USBD_EVENT_IN
114 ARM_DRIVER_VERSION ARM_USBD_GetVersion (void) {
118 \fn ARM_DRIVER_VERSION ARM_USBD_GetVersion (void)
120 The function \b ARM_USBD_GetVersion returns version information of the driver implementation in \ref ARM_DRIVER_VERSION
121 - API version is the version of the CMSIS-Driver specification used to implement this driver.
122 - Driver version is source code version of the actual driver implementation.
126 extern ARM_DRIVER_USBD Driver_USBD0;
127 ARM_DRIVER_USBD *drv_info;
129 void setup_usbd (void) {
130 ARM_DRIVER_VERSION version;
132 drv_info = &Driver_USBD0;
133 version = drv_info->GetVersion ();
134 if (version.api < 0x10A) { // requires at minimum API version 1.10 or higher
140 *****************************************************************************************************************/
142 ARM_USBD_CAPABILITIES ARM_USBD_GetCapabilities (void) {
146 \fn ARM_USBD_CAPABILITIES ARM_USBD_GetCapabilities (void)
148 The function \b ARM_USBD_GetCapabilities returns information about capabilities in this driver implementation.
149 The data fields of the structure \ref ARM_USBD_CAPABILITIES encode various capabilities, for example
150 if the hardware can create signal events using the \ref ARM_USBD_SignalDeviceEvent callback function.
154 extern ARM_DRIVER_USBD Driver_USBD0;
155 ARM_DRIVER_USBD *drv_info;
157 void read_capabilities (void) {
158 ARM_USBD_CAPABILITIES drv_capabilities;
160 drv_info = &Driver_USBD0;
161 drv_capabilities = drv_info->GetCapabilities ();
162 // interrogate capabilities
166 *****************************************************************************************************************/
168 int32_t ARM_USBD_Initialize (ARM_USBD_SignalDeviceEvent_t cb_device_event,
169 ARM_USBD_SignalEndpointEvent_t cb_endpoint_event) {
170 return ARM_DRIVER_OK;
173 \fn int32_t ARM_USBD_Initialize (ARM_USBD_SignalDeviceEvent_t cb_device_event, ARM_USBD_SignalEndpointEvent_t cb_endpoint_event)
175 The function \b ARM_USBD_Initialize initializes the USB Device interface.
176 It is called when the middleware component starts operation.
178 The function performs the following operations:
179 - Initializes the resources needed for the USBD interface.
180 - Registers the \ref ARM_USBD_SignalDeviceEvent callback function.
181 - Registers the \ref ARM_USBD_SignalEndpointEvent callback function.
183 The parameter \em cb_device_event is a pointer to the \ref ARM_USBD_SignalDeviceEvent callback function; use a NULL pointer
184 when no device callback signals are required. \n
185 The parameter \em cb_endpoint_event is a pointer to the \ref ARM_USBD_SignalEndpointEvent callback function.
188 - see \ref usbd_interface_gr - Driver Functions
190 *****************************************************************************************************************/
192 int32_t ARM_USBD_Uninitialize (void) {
193 return ARM_DRIVER_OK;
196 \fn int32_t ARM_USBD_Uninitialize (void)
198 The function \b ARM_USBD_Uninitialize de-initializes the resources of USBD interface.
200 It is called when the middleware component stops operation and releases the software resources used by the interface.
201 *****************************************************************************************************************/
203 int32_t ARM_USBD_PowerControl (ARM_POWER_STATE state) {
204 return ARM_DRIVER_OK;
207 \fn int32_t ARM_USBD_PowerControl (ARM_POWER_STATE state)
209 The function \b ARM_USBD_PowerControl operates the power modes of the USB Device interface.
211 The parameter \em state sets the operation and can have the following values:
212 - \ref ARM_POWER_FULL : set-up peripheral for data transfers, enable interrupts (NVIC) and optionally DMA.
213 Can be called multiple times. If the peripheral is already in this mode the function performs
214 no operation and returns with \ref ARM_DRIVER_OK.
215 - \ref ARM_POWER_LOW : may use power saving. Returns \ref ARM_DRIVER_ERROR_UNSUPPORTED when not implemented.
216 - \ref ARM_POWER_OFF : terminates any pending data transfers, disables peripheral, disables related interrupts and DMA.
218 Refer to \ref CallSequence for more information.
219 *****************************************************************************************************************/
221 int32_t ARM_USBD_DeviceConnect (void) {
222 return ARM_DRIVER_OK;
225 \fn int32_t ARM_USBD_DeviceConnect (void)
227 The function \b ARM_USBD_DeviceConnect signals to the host that the device is connected.
228 *****************************************************************************************************************/
230 int32_t ARM_USBD_DeviceDisconnect (void) {
231 return ARM_DRIVER_OK;
234 \fn int32_t ARM_USBD_DeviceDisconnect (void)
236 The function \b ARM_USBD_DeviceDisconnect signals to the host that the device is disconnected.
237 *****************************************************************************************************************/
239 ARM_USBD_STATE ARM_USBD_DeviceGetState (void) {
240 return ARM_DRIVER_OK;
243 \fn ARM_USBD_STATE ARM_USBD_DeviceGetState (void)
245 Retrieves the current USB device state.
246 *****************************************************************************************************************/
248 int32_t ARM_USBD_DeviceRemoteWakeup (void) {
249 return ARM_DRIVER_OK;
252 \fn int32_t ARM_USBD_DeviceRemoteWakeup (void)
254 The function \b ARM_USBD_DeviceRemoteWakeup signals remote wakeup to the host.
255 *****************************************************************************************************************/
257 int32_t ARM_USBD_DeviceSetAddress (uint8_t dev_addr) {
258 return ARM_DRIVER_OK;
261 \fn int32_t ARM_USBD_DeviceSetAddress (uint8_t dev_addr)
263 Assigns an address to the device.
264 *****************************************************************************************************************/
266 int32_t ARM_USBD_ReadSetupPacket (uint8_t *setup) {
267 return ARM_DRIVER_OK;
270 \fn int32_t ARM_USBD_ReadSetupPacket (uint8_t *setup)
272 The function \b ARM_USBD_ReadSetupPacket reads the last SETUP packet (8 bytes) that was received over Control Endpoint (Endpoint 0)
273 which is indicated by \ref ARM_USBD_EVENT_SETUP event.
276 - \ref ARM_USBD_SignalEndpointEvent
277 *****************************************************************************************************************/
279 int32_t ARM_USBD_EndpointConfigure (uint8_t ep_addr,
281 uint16_t ep_max_packet_size) {
282 return ARM_DRIVER_OK;
285 \fn int32_t ARM_USBD_EndpointConfigure (uint8_t ep_addr, uint8_t ep_type, uint16_t ep_max_packet_size)
287 The function \b ARM_USBD_EndpointConfigure configures an endpoint for transfers.
290 *****************************************************************************************************************/
292 int32_t ARM_USBD_EndpointUnconfigure (uint8_t ep_addr) {
293 return ARM_DRIVER_OK;
296 \fn int32_t ARM_USBD_EndpointUnconfigure (uint8_t ep_addr)
298 The function \b ARM_USBD_EndpointUnconfigure de-configures the specified endpoint.
300 The parameter \em ep_addr specifies the endpoint address.
301 *****************************************************************************************************************/
303 int32_t ARM_USBD_EndpointStall (uint8_t ep_addr, bool stall) {
304 return ARM_DRIVER_OK;
307 \fn int32_t ARM_USBD_EndpointStall (uint8_t ep_addr, bool stall)
309 The function \b ARM_USBD_EndpointStall sets or clears stall condition for the specified endpoint.
311 The parameter \em ep_addr specifies the endpoint address. \n
312 The parameter \em stall is a boolean parameter.
313 *****************************************************************************************************************/
315 int32_t ARM_USBD_EndpointTransfer (uint8_t ep_addr, uint8_t *data, uint32_t num) {
316 return ARM_DRIVER_OK;
319 \fn int32_t ARM_USBD_EndpointTransfer (uint8_t ep_addr, uint8_t *data, uint32_t num)
322 The function \b ARM_USBD_EndpointTransfer reads from or writes data to an USB Endpoint.
324 The parameter \em ep_addr specifies the endpoint address. \n
325 The parameter \em data is a buffer for data to read or data to write. \n
326 The parameter \em num is the number of bytes to transfer (must be multiple of endpoint maximum packet size for Read transfers).
328 The function is non-blocking and returns as soon as the driver starts the operation on the specified endpoint.
329 During the operation it is not allowed to call this function again on the same endpoint.
330 Also the data buffer must stay allocated and the contents of data must not be modified.
332 Direction in the endpoint address specifies the type of transfer:
333 - Endpoint Read for OUT endpoint (direction = 0)
334 - Endpoint Write for IN endpoint (direction = 1)
336 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.
337 Completion of operation is indicated by \ref ARM_USBD_EVENT_OUT event. Number of successfully received data bytes can be retrieved
338 by calling \ref ARM_USBD_EndpointTransferGetResult.
340 Endpoint Write is finished when the requested number of data bytes have been sent.
341 Completion of operation is indicated by \ref ARM_USBD_EVENT_IN event. Number of successfully sent data bytes can be retrieved
342 by calling \ref ARM_USBD_EndpointTransferGetResult.
344 Transfer operation can be aborted by calling \ref ARM_USBD_EndpointTransferAbort.
345 *****************************************************************************************************************/
347 uint32_t ARM_USBD_EndpointTransferGetResult (uint8_t ep_addr) {
351 \fn uint32_t ARM_USBD_EndpointTransferGetResult (uint8_t ep_addr)
353 The function \b ARM_USBD_EndpointTransferGetResult returns the number of successfully transferred data bytes started by \ref ARM_USBD_EndpointTransfer.
355 The parameter \em ep_addr specifies the endpoint address.
356 *****************************************************************************************************************/
358 int32_t ARM_USBD_EndpointTransferAbort (uint8_t ep_addr) {
359 return ARM_DRIVER_OK;
362 \fn int32_t ARM_USBD_EndpointTransferAbort (uint8_t ep_addr)
364 The function \b ARM_USBD_EndpointTransferAbort aborts the transfer to an endpoint started by \ref ARM_USBD_EndpointTransfer.
366 The parameter \em ep_addr specifies the endpoint address.
367 *****************************************************************************************************************/
369 uint16_t ARM_USBD_GetFrameNumber (void) {
373 \fn uint16_t ARM_USBD_GetFrameNumber (void)
375 Retrieves the sequential 11-bit frame number of the last Start of Frame (SOF) packet.
376 *****************************************************************************************************************/
378 void ARM_USBD_SignalDeviceEvent (uint32_t event) {
382 \fn void ARM_USBD_SignalDeviceEvent (uint32_t event)
384 The function \b ARM_USBD_SignalDeviceEvent is a callback function registered by the function \ref ARM_USBD_Initialize.
386 The parameter \em event indicates one or more events that occurred during driver operation.
387 Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call.
389 Not every event is necessarily generated by the driver. This depends on the implemented capabilities stored in the
390 data fields of the structure \ref ARM_USBD_CAPABILITIES, which can be retrieved with the function \ref ARM_USBD_GetCapabilities.
392 The following events can be generated:
394 Event | Bit| Description | supported when \ref ARM_USBD_CAPABILITIES
395 :-------------------------------|---:|:---------------------------------------------------|----------------------------------------------
396 \ref ARM_USBD_EVENT_VBUS_ON | 0 | Occurs when valid VBUS voltage is detected. | data field \em event_vbus_on = \token{1}
397 \ref ARM_USBD_EVENT_VBUS_OFF | 1 | Occurs when VBUS voltage is turned off. | data field \em event_vbus_off = \token{1}
398 \ref ARM_USBD_EVENT_RESET | 2 | Occurs when USB Reset is detected. | <i>always supported</i>
399 \ref ARM_USBD_EVENT_HIGH_SPEED | 3 | Occurs when USB Device is switched to High-speed. | <i>always supported</i>
400 \ref ARM_USBD_EVENT_SUSPEND | 4 | Occurs when USB Suspend is detected. | <i>always supported</i>
401 \ref ARM_USBD_EVENT_RESUME | 5 | Occurs when USB Resume is detected. | <i>always supported</i>
402 *****************************************************************************************************************/
404 void ARM_USBD_SignalEndpointEvent (uint8_t ep_addr, uint32_t ep_event) {
408 \fn void ARM_USBD_SignalEndpointEvent (uint8_t ep_addr, uint32_t event)
410 The function \b ARM_USBD_SignalEndpointEvent is a callback function registered by the function \ref ARM_USBD_Initialize.
412 The argument \a ep_addr specifies the endpoint. \n
413 The parameter \em event indicates one or more events that occurred during driver operation.
414 Each event is encoded in a separate bit and therefore it is possible to signal multiple events within the same call.
416 The following events can be generated:
418 Event | Bit | Description
419 :----------------------------------------|----:|:-----------
420 \ref ARM_USBD_EVENT_SETUP | 0 | Occurs when SETUP packet is received over Control Endpoint.
421 \ref ARM_USBD_EVENT_OUT | 1 | Occurs when data is received over OUT Endpoint.
422 \ref ARM_USBD_EVENT_IN | 2 | Occurs when data is sent over IN Endpoint.
423 *****************************************************************************************************************/
428 // End USBD Interface