nRF52840 only: Module for easy support for any USB device configuration.
More...
nRF52840 only: Module for easy support for any USB device configuration.
This module manages class instances that would create the USB device, manages endpoints and interfaces transactions.
Auxiliary function that process event by every instance in the list.
This function ignores the result of called handler.
- Parameters
-
p_event | Event to pass to every instance |
Call interface event handlers and stop when served.
Call event handlers from instances as long as we get result different than NRF_ERROR_NOT_SUPPORTED
- Parameters
-
[in] | p_event | Event structure to send |
- Returns
- Operation status or NRF_ERROR_NOT_SUPPORTED if none of instances in the list can support given event.
Add class instance.
This function connects given instance into internal class instance chain and into all required endpoints. The instance event handler would be connected into endpoint by default, but this can be overwritten by app_usbd_ep_handler_set.
After successful attachment APP_USBD_EVT_INST_APPEND would be passed to class instance.
- Note
- This function can only be called after USBD library is initialized but still disabled. Assertion would be generated otherwise.
- Parameters
-
[in,out] | p_cinst | Instance to connect. Chain data would be written into writable instance data. |
const void* app_usbd_class_descriptor_find |
( |
app_usbd_class_inst_t const *const |
p_cinst, |
|
|
uint8_t |
desc_type, |
|
|
uint8_t |
desc_index, |
|
|
size_t * |
p_desc_len |
|
) |
| |
Function finds a given descriptor type in class descriptors payload.
- Parameters
-
- Returns
- Address of the descriptor (NULL if not found)
Get first class instance in the list.
Get first instance from the list of active class instances. That instance may be used then in app_usbd_class_next_get function.
- Returns
- First instance in the list or NULL if there are no instances available.
Get next instance in the list.
Get the next instance from the list of active instances. Used to iterate through all instances.
- Parameters
-
[in] | p_cinst | The current instance from with next one is required. |
- Returns
- Next instance to the given one or NULL if there is no more instances in the list.
Remove class instance.
Instance is removed from instance chain. Instance and event handlers are removed also from endpoints. Endpoints used by by the class instance are left disabled.
- Note
- This function can only be called after USBD library is initialized but still disabled. Assertion would be generated otherwise.
- Parameters
-
p_cinst | Instance pointer to remove. |
- Return values
-
NRF_SUCCESS | Instance successfully removed. |
NRF_ERROR_NOT_FOUND | Instance not found in the instance chain. |
Remove all class instances.
This function basically calls app_usbd_class_remove on instances chain as long as there is any element left.
- Note
- This function can only be called after USBD library is initialized but still disabled. Assertion would be generated otherwise.
- See Also
- app_usbd_class_remove
- Returns
- Is should always return NRF_SUCCESS. Any error value returned would mean there is an error inside the library.
bool app_usbd_class_rwu_enabled_check |
( |
void |
| ) |
|
Check if there is any class with remote wakeup.
The function checks internal registered class with remote wakeup counter.
- See Also
- app_usbd_class_rwu_register, app_usbd_class_rwu_unregister
- Return values
-
true | The remote wakeup functionality is required by some class instance |
false | There is no class instance that requires wakeup functionality |
Register class on remote wake-up feature.
- Parameters
-
[in] | p_inst | Instance of the class |
- Return values
-
NRF_SUCCESS | Instance that requires remote wake-up registered |
Unregister class from remote wake-up feature.
- Parameters
-
[in] | p_inst | Instance of the class |
- Return values
-
NRF_SUCCESS | Instance that requires remote wake-up removed |
Get first instance in SOF list.
Start iteration through the list of instances that requires SOF event processing.
- Returns
- First instance in the list or NULL if the list is empty
- See Also
- app_usbd_class_first_get
Get next instance in the SOF list.
Get the next instance from the list of instances requiring SOF event processing. Used to iterate through all SOF instances.
- Parameters
-
p_cinst | The current instance from with next one is required. |
- Returns
- Next instance to the given one or NULL if there is no more instances in the list.
Register class instance as the one that requires SOF events.
This function should be called in reaction on APP_USBD_EVT_INST_APPEND event. Connect the class instance to the list of instances that requires SOF processing. If none of the appended instances requires SOF event - it is disabled.
- Parameters
-
p_cinst | Instance that requires SOF event. |
- Return values
-
NRF_SUCCESS | Instance linked into SOF processing list. |
- See Also
- app_usbd_class_sof_unregister
Unregister class instance from SOF processing instances list.
Every class that calls app_usbd_class_sof_register have to call also unregistering function in reaction to APP_USBD_EVT_INST_REMOVE event.
- Parameters
-
p_cinst | Instance to be unregistered from SOF event processing list. |
- Return values
-
NRF_SUCCESS | Instance linked into SOF processing list. |
NRF_ERROR_NOT_FOUND | Instance not found in the SOF processing list. |
- See Also
- app_usbd_class_sof_register
void app_usbd_disable |
( |
void |
| ) |
|
Disable USBD.
Disabled USDB peripheral cannot be accessed but also stops requesting High Frequency clock and releases power regulator.
- Note
- This function cannot be called when USB is started. Stop it first.
void app_usbd_enable |
( |
void |
| ) |
|
Enable USBD.
USBD is enabled. Since now the high frequency clock may be requested when USB RESET would be detected.
Standard endpoint request handle.
- Parameters
-
[in] | p_setup_ev | Setup event |
- Returns
- Standard error code
Call endpoint event handler.
Call event handler for the selected endpoint.
- Parameters
-
[in] | ep | Endpoint number |
[in] | p_event | Event structure to send |
- Returns
- Operation status
Change endpoint handler.
This function may be called for the endpoint only if the class instance is already properly attached by the app_usbd_class_append function.
The endpoint event handler function can be only overwritten by the class instance that was connected into the endpoint.
- Note
- This function can only be called after USBD library is initialized but still disabled. Assertion would be generated otherwise.
- Parameters
-
[in] | p_cinst | Instance of a class that wish to set new event handler. It has to match currently configured instance for the selected endpoint. In other situation error would be returned. |
[in] | ep | Endpoint address to configure. |
[in] | handler | Event handler function to set. |
- Return values
-
NRF_SUCCESS | New handler successfully set |
NRF_ERROR_INVALID_PARAM | p_cinst is not the same as currently set for the endpoint |
USBD event processor.
Function to be called on each event to be processed by the library.
bool app_usbd_event_queue_process |
( |
void |
| ) |
|
Function that process events from the queue.
- Note
- This function calls app_usbd_event_execute internally.
- Return values
-
true | Event was processed |
false | The event queue is empty |
Call interface event handler.
Call event handler for selected interface.
- Parameters
-
[in] | iface | Target interface number |
[in] | p_event | Event structure to send |
- Returns
- Operation status
USB library initialization.
Call this function before any configuration or class attachment. USBD peripheral would be ready to accept commands, and library would be ready, but it would not be connected to the bus. Call app_usbd_enable to enable USBD communication with the host.
- Parameters
-
p_config | Configuration. NULL pointer might be passed here and default configuration will be applied then. |
Standard interface request handle.
- Parameters
-
[in] | p_setup_ev | Setup event |
- Returns
- Standard error code
Standard interface set request handle.
- Parameters
-
[in] | p_cinst | Instance of a class |
[in] | p_setup_ev | Setup event |
- Returns
- Standard error code
void app_usbd_start |
( |
void |
| ) |
|
Request USBD to start.
The function sends start request to the event queue. If the queue is enabled (APP_USBD_EVENT_QUEUE_ENABLE) it would be processed when the queue is processed. If queue is disabled it would be processed immediately inside this function. It means that if queue is disabled this function cannot be called from interrupt with priority higher than USB interrupt.
When start is processed it would:
- Start library.
- Enable interrupts.
- Enable USB pull-ups.
- Note
- In some specific circumstances the library can be left not started and this function would silently exit. This may happen if some glitches appears on USB power line or if the plug was disconnected before whole starting process finishes. User would get the event from POWER peripheral then. Also no APP_USBD_EVT_STARTED event would be generated to the classes and user event handler. For the safe code it is recommended to wait for APP_USBD_EVT_STARTED event if anything has to be initialized after USB driver is started (just before enabling the interrupts). If library is properly started the APP_USBD_EVT_STARTED event passed to the user handler from this function body.
void app_usbd_stop |
( |
void |
| ) |
|
Stop USB to work.
The function sends stop request to the event queue. If the queue is enabled (APP_USBD_EVENT_QUEUE_ENABLE) it would be processed when the queue is processed. If queue is disabled it would be processed immediately inside this function. It means that if queue is disabled this function cannot be called from interrupt with priority higher than USB interrupt.
When the event is processed interrupts and USB pull-ups are disabled. The peripheral itself is left enabled so it can be programmed, but a HOST sees it as a peripheral disconnection.
- Note
- If the library is not started when this function is called it exits silently - also no APP_USBD_EVT_STOPPED is generated.
void app_usbd_suspend_req |
( |
void |
| ) |
|
Request library to suspend.
This function send suspend request to the event queue.
- Note
- This function should only be called after APP_USBD_EVT_DRV_SUSPEND os received. Internal suspend request processing would give no effect if the bus is not in suspend state.
USB library un-initialization.
- Note
- Currently not supported
bool app_usbd_wakeup_req |
( |
void |
| ) |
|
Request library to wake-up.
This function send wakeup request to the event queue.
- Note
- Calling this function does not mean that peripheral is active - the wakeup request is sent into message queue and needs to be processed.
- Return values
-
true | Wakeup generation has been started. |
false | No wakeup would be generated becouse it is disabled by the host. |