nRF5 SDK v14.0.0
Data Structures | Macros | Typedefs | Enumerations | Functions
USB Device high level library core module

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_USBD_CORE_CLASS_CONFIGURATION   ((0, NRF_DRV_USBD_EPOUT0, NRF_DRV_USBD_EPIN0))
 Core interface configuration. More...
 
#define APP_USBD_STATE_SUSPENDED_MASK   0x80
 Suspend state mask. More...
 
#define APP_USB_STATE_BASE(state)   ((app_usbd_state_t)((uint32_t)(state) & (~APP_USBD_STATE_SUSPENDED_MASK)))
 Remove APP_USBD_STATE_SUSPENDED_MASK bit from core state.
 

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_SuspendedPowered = 0x80 | APP_USBD_STATE_Powered,
  APP_USBD_STATE_SuspendedDefault = 0x80 | APP_USBD_STATE_Default,
  APP_USBD_STATE_SuspendedAddressed = 0x80 | APP_USBD_STATE_Addressed,
  APP_USBD_STATE_SuspendedConfigured = 0x80 | 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...
 
bool app_usbd_core_feature_state_get (app_usbd_setup_stdfeature_t feature)
 Check current feature state. More...
 

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 matter because it is not used.

#define APP_USBD_STATE_SUSPENDED_MASK   0x80

Suspend state mask.

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

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_contexContext 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_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

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
epEndpoint number
p_transferDescription of the transfer to be performed. The direction of the transfer is determined by the endpoint number.
Return values
NRF_ERROR_INVALID_STATEThe 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
bool app_usbd_core_feature_state_get ( app_usbd_setup_stdfeature_t  feature)

Check current feature state.

Function checks the state of the selected feature that was configured by the host.

Parameters
featureFeature to check. Only features related to the device should be checked by this function.
Return values
trueSelected feature is set
falseSelected feature is cleared
static app_usbd_class_inst_t const* app_usbd_core_instance_access ( void  )
inlinestatic

Access to core instance.

Function that returns pointer to the USBD core instance.

Returns
pointer to the core instance
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
epEndpoint number (only IN0 and OUT0) are supported.
p_handler_descDescriptor of the handler to be called.
Return values
NRF_SUCCESSSuccessfully configured
NRF_ERROR_INVALID_ADDRLast 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
epSee app_usbd_core_ep_transfer.
p_transferSee app_usbd_core_ep_transfer.
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_setupPointer to original setup message
p_dataPointer to the response. This has to be globaly aviable data.
sizeTotal 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
epEndpoint number.
p_handlerFunction called when the next chunk of data is requested.
Return values
NRF_ERROR_INVALID_STATEThe 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
epEndpoint number
p_handlerFunction called when the next chunk of data is requested.
Return values
NRF_ERROR_INVALID_STATEThe state of the USB device does not allow data transfer on the endpoint.
Returns
Values returned by nrf_drv_usbd_ep_handled_transfer.

Documentation feedback | Developer Zone | Subscribe | Updated