USB Device high level library core module

nRF5 SDK v13.1.0

nRF52840 only: Core module that manages current USB state and process device requests. More...

Data Structures

struct app_usbd_core_setup_data_handler_desc_t
Variable type used to register EP0 transfer handler. More...
struct CONCAT_2
Declare Core instance type. More...

Macros

#define APP_USB_STATE_BASE (state)   ((state) & (~ APP_USBD_STATE_SuspendedMask ))
Remove APP_USBD_STATE_SuspendedMask bit from core state.
#define APP_USBD_CORE_CLASS_CONFIGURATION ((0, NRF_DRV_USBD_EPOUT0 , NRF_DRV_USBD_EPIN0 ))
Core interface configuration. More...

Typedefs

typedef ret_code_t (* app_usbd_core_setup_data_handler_t )( nrf_drv_usbd_ep_status_t status, void *p_context)
EP0 handler function pointer. More...
typedef struct CONCAT_2 _data_t

Enumerations

enum app_usbd_state_t {
APP_USBD_STATE_Disabled = 0x00,
APP_USBD_STATE_Unattached = 0x01,
APP_USBD_STATE_Powered = 0x02,
APP_USBD_STATE_Default = 0x03,
APP_USBD_STATE_Addressed = 0x04,
APP_USBD_STATE_Configured = 0x05,
APP_USBD_STATE_SuspendedMask = 0x10,
APP_USBD_STATE_SuspendedPowered = APP_USBD_STATE_SuspendedMask | APP_USBD_STATE_Powered,
APP_USBD_STATE_SuspendedDefault = APP_USBD_STATE_SuspendedMask | APP_USBD_STATE_Default,
APP_USBD_STATE_SuspendedAddressed = APP_USBD_STATE_SuspendedMask | APP_USBD_STATE_Addressed,
APP_USBD_STATE_SuspendedConfigured = APP_USBD_STATE_SuspendedMask | APP_USBD_STATE_Configured
}
USB Device state. More...

Functions

union CONCAT_2 (app_usbd_core, _u)
CONCAT_2 (app_usbd_core, _t)
static app_usbd_class_inst_t
const *
app_usbd_core_instance_access (void)
Access to core instance. More...
ret_code_t app_usbd_core_setup_rsp ( app_usbd_setup_t const *p_setup, void const *p_data, size_t size)
Default simple response to setup command. More...
ret_code_t app_usbd_core_setup_data_handler_set ( nrf_drv_usbd_ep_t ep, app_usbd_core_setup_data_handler_desc_t const *const p_handler_desc)
Configure the handler for the nearest setup data endpoint transfer. More...
ret_code_t app_usbd_core_ep_transfer ( nrf_drv_usbd_ep_t ep, nrf_drv_usbd_transfer_t const *const p_transfer)
Endpoint transfer. More...
ret_code_t app_usbd_core_setup_data_transfer ( nrf_drv_usbd_ep_t ep, nrf_drv_usbd_transfer_t const *const p_transfer)
Setup data transfer. More...
ret_code_t app_usbd_ep_handled_transfer ( nrf_drv_usbd_ep_t ep, nrf_drv_usbd_handler_desc_t const *const p_handler)
Set up an endpoint-handled transfer. More...
ret_code_t app_usbd_setup_data_handled_transfer ( nrf_drv_usbd_ep_t ep, nrf_drv_usbd_handler_desc_t const *const p_handler)
Set up a data-handled transfer. More...
void * app_usbd_core_setup_transfer_buff_get (size_t *p_size)
Set up a data transfer buffer. More...
app_usbd_state_t app_usbd_core_state_get (void)
Return internal USBD core state. More...
static bool app_usbd_core_power_regulator_is_ready (void)
Check current USBD regulator status. More...
void app_usbd_core_class_rwu_register ( app_usbd_class_inst_t const *const p_inst)
Register class on remote wake-up feature. More...
void app_usbd_core_class_rwu_unregister ( app_usbd_class_inst_t const *const p_inst)
Unregister class from remote wake-up feature. More...
void app_usbd_core_class_rwu_pend (void)
Set remote wake-up pending.

Detailed Description

nRF52840 only: Core module that manages current USB state and process device requests.

Macro Definition Documentation

#define APP_USBD_CORE_CLASS_CONFIGURATION   ((0, NRF_DRV_USBD_EPOUT0 , NRF_DRV_USBD_EPIN0 ))

Core interface configuration.

Core instance would have 2 endpoints (IN0 and OUT0). The interface number does not care because it would not be used.

Typedef Documentation

typedef ret_code_t (* app_usbd_core_setup_data_handler_t)( nrf_drv_usbd_ep_status_t status, void *p_context)

EP0 handler function pointer.

Type of the variable that would hold the pointer to the handler for endpoint 0 messages processing.

Parameters
p_contex Context variable configured with the transmission request.

Enumeration Type Documentation

USB Device state.

Possible USB Device states according to specification.

Enumerator
APP_USBD_STATE_Disabled

The whole USBD library is disabled

APP_USBD_STATE_Unattached

Device is currently not connected to the host

APP_USBD_STATE_Powered

Device is connected to the host but has not been enumerated

APP_USBD_STATE_Default

USB Reset condition detected, waiting for the address

APP_USBD_STATE_Addressed

Device has been addressed but have not been configured

APP_USBD_STATE_Configured

Device is addressed and configured

APP_USBD_STATE_SuspendedMask

Mask used to mark suspended state, suspended state remembers also the target state after wake up

APP_USBD_STATE_SuspendedPowered

Device is Suspended and on wakeup it will return to Powered state

APP_USBD_STATE_SuspendedDefault

Device is Suspended and on wakeup it will return to Default state

APP_USBD_STATE_SuspendedAddressed

Device is Suspended and on wakeup it will return to Addressed state

APP_USBD_STATE_SuspendedConfigured

Device is Suspended and on wakeup it will return to Configured state

Function Documentation

void app_usbd_core_class_rwu_register ( app_usbd_class_inst_t const *const p_inst )

Register class on remote wake-up feature.

Parameters
[in] p_inst Instance of the class
void app_usbd_core_class_rwu_unregister ( app_usbd_class_inst_t const *const p_inst )

Unregister class from remote wake-up feature.

Parameters
[in] p_inst Instance of the class
ret_code_t app_usbd_core_ep_transfer ( nrf_drv_usbd_ep_t ep ,
nrf_drv_usbd_transfer_t const *const p_transfer
)

Endpoint transfer.

Parameters
ep Endpoint number
p_transfer Description of the transfer to be performed. The direction of the transfer is determined by the endpoint number.
Return values
NRF_ERROR_INVALID_STATE The state of the USB device does not allow data transfer on the endpoint.
Returns
Values returned by nrf_drv_usbd_ep_transfer
Note
This function can work only if the USB is in Configured state. See app_usbd_core_setup_data_transfer for transfers before device configuration is done.
See Also
app_usbd_core_setup_data_transfer
static app_usbd_class_inst_t const* app_usbd_core_instance_access ( void )
inline static

Access to core instance.

Function that returns pointer to the USBD core instance.

Returns
pointer to the core instance
static bool app_usbd_core_power_regulator_is_ready ( void )
inline static

Check current USBD regulator status.

Returns
true when regulator is ready
ret_code_t app_usbd_core_setup_data_handler_set ( nrf_drv_usbd_ep_t ep ,
app_usbd_core_setup_data_handler_desc_t const *const p_handler_desc
)

Configure the handler for the nearest setup data endpoint transfer.

This function would be called on incomming setup data. The correct place to set the handler for a data is when SETUP command was received.

Parameters
ep Endpoint number (only IN0 and OUT0) are supported.
p_handler_desc Descriptor of the handler to be called.
Return values
NRF_SUCCESS Successfully configured
NRF_ERROR_INVALID_ADDR Last received setup direction does not match configured endpoint.
ret_code_t app_usbd_core_setup_data_transfer ( nrf_drv_usbd_ep_t ep ,
nrf_drv_usbd_transfer_t const *const p_transfer
)

Setup data transfer.

Function similar to app_usbd_core_ep_transfer . The only technical diference is that it should be used with setup transfers that are going to be performed before device is configured.

Parameters
Returns
The same values like app_usbd_core_ep_transfer
ret_code_t app_usbd_core_setup_rsp ( app_usbd_setup_t const * p_setup ,
void const * p_data ,
size_t size
)

Default simple response to setup command.

This function generates default simple response. It sends ZLP when required and on takes care on allowing status stage when transfer is finished.

Parameters
p_setup Pointer to original setup message
p_data Pointer to the response. This has to be globaly aviable data.
size Total size of the answer - The function takes care about limiting the size of transfered data to the size required by setup command.
void* app_usbd_core_setup_transfer_buff_get ( size_t * p_size )

Set up a data transfer buffer.

Returns special internal buffer that can be used in setup transfer.

Returns
Internal buffer pointer
app_usbd_state_t app_usbd_core_state_get ( void )

Return internal USBD core state.

Returns
Check app_usbd_state_t to find possible USBD core states
ret_code_t app_usbd_ep_handled_transfer ( nrf_drv_usbd_ep_t ep ,
nrf_drv_usbd_handler_desc_t const *const p_handler
)

Set up an endpoint-handled transfer.

Configures a transfer handled by the feedback function.

Parameters
ep Endpoint number.
p_handler Function called when the next chunk of data is requested.
Return values
NRF_ERROR_INVALID_STATE The state of the USB device does not allow data transfer on the endpoint.
Returns
Values returned by nrf_drv_usbd_ep_handled_transfer .
ret_code_t app_usbd_setup_data_handled_transfer ( nrf_drv_usbd_ep_t ep ,
nrf_drv_usbd_handler_desc_t const *const p_handler
)

Set up a data-handled transfer.

Function similar to app_usbd_ep_handled_transfer . The only technical diference is that it should be used with setup transfers that are performed before the device is configured.

Parameters
ep Endpoint number
p_handler Function called when the next chunk of data is requested.
Return values
NRF_ERROR_INVALID_STATE The state of the USB device does not allow data transfer on the endpoint.
Returns
Values returned by nrf_drv_usbd_ep_handled_transfer .