Universal Serial Bus Device (USBD) peripheral driver. More...
Modules | |
USBD peripheral driver configuration | |
Data Structures | |
struct | nrfx_usbd_evt_t |
Event structure. More... | |
union | nrfx_usbd_data_ptr_t |
Universal data pointer. More... | |
struct | nrfx_usbd_ep_transfer_t |
Structure to be filled with information about the next transfer. More... | |
struct | nrfx_usbd_transfer_t |
Total transfer configuration. More... | |
union | nrfx_usbd_handler_t |
Universal transfer handler. More... | |
struct | nrfx_usbd_handler_desc_t |
USBD transfer descriptor. More... | |
struct | nrfx_usbd_setup_t |
Setup packet structure. More... | |
Macros | |
#define | NRFX_USBD_EPSIZE 64 |
Number of bytes in the endpoint. | |
#define | NRFX_USBD_ISOSIZE 1024 |
Number of bytes for isochronous endpoints. More... | |
#define | NRFX_USBD_FEEDER_BUFFER_SIZE NRFX_USBD_EPSIZE |
The size of internal feeder buffer. More... | |
#define | NRFX_USBD_TRANSFER_IN(name, tx_buff, tx_size, tx_flags) |
Auxiliary macro for declaring IN transfer description with optional flags. More... | |
#define | NRFX_USBD_TRANSFER_OUT(name, rx_buff, rx_size) |
Helper macro for declaring OUT transfer item (nrfx_usbd_transfer_t). More... | |
Typedefs | |
typedef void(* | nrfx_usbd_event_handler_t )(nrfx_usbd_evt_t const *p_event) |
USBD event callback function type. More... | |
typedef bool(* | nrfx_usbd_feeder_t )(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size) |
USBD transfer feeder. More... | |
typedef bool(* | nrfx_usbd_consumer_t )(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size, size_t data_size) |
USBD transfer consumer. More... | |
Functions | |
nrfx_err_t | nrfx_usbd_init (nrfx_usbd_event_handler_t event_handler) |
Driver initialization. More... | |
void | nrfx_usbd_uninit (void) |
Driver deinitialization. | |
void | nrfx_usbd_enable (void) |
Enable the USBD port. More... | |
void | nrfx_usbd_disable (void) |
Disable the USBD port. More... | |
void | nrfx_usbd_start (bool enable_sof) |
Start USB functionality. More... | |
void | nrfx_usbd_stop (void) |
Stop USB functionality. More... | |
bool | nrfx_usbd_is_initialized (void) |
Check if driver is initialized. More... | |
bool | nrfx_usbd_is_enabled (void) |
Check if driver is enabled. More... | |
bool | nrfx_usbd_is_started (void) |
Check if driver is started. More... | |
bool | nrfx_usbd_suspend (void) |
Suspend USBD operation. More... | |
bool | nrfx_usbd_wakeup_req (void) |
Start wake up procedure. More... | |
bool | nrfx_usbd_suspend_check (void) |
Check if USBD is in SUSPEND mode. More... | |
void | nrfx_usbd_suspend_irq_config (void) |
Enable only interrupts that should be processed in SUSPEND mode. More... | |
void | nrfx_usbd_active_irq_config (void) |
Default active interrupt configuration. More... | |
bool | nrfx_usbd_bus_suspend_check (void) |
Check the bus state. More... | |
void | nrfx_usbd_force_bus_wakeup (void) |
Force the bus state to active. | |
void | nrfx_usbd_ep_max_packet_size_set (nrfx_usbd_ep_t ep, uint16_t size) |
Configure packet size that should be supported by the endpoint. More... | |
uint16_t | nrfx_usbd_ep_max_packet_size_get (nrfx_usbd_ep_t ep) |
Get configured endpoint packet size. More... | |
bool | nrfx_usbd_ep_enable_check (nrfx_usbd_ep_t ep) |
Check if the selected endpoint is enabled. More... | |
void | nrfx_usbd_ep_enable (nrfx_usbd_ep_t ep) |
Enable selected endpoint. More... | |
void | nrfx_usbd_ep_disable (nrfx_usbd_ep_t ep) |
Disable selected endpoint. More... | |
void | nrfx_usbd_ep_default_config (void) |
Disable all endpoints except for EP0. More... | |
nrfx_err_t | nrfx_usbd_ep_transfer (nrfx_usbd_ep_t ep, nrfx_usbd_transfer_t const *p_transfer) |
Start sending data over endpoint. More... | |
nrfx_err_t | nrfx_usbd_ep_handled_transfer (nrfx_usbd_ep_t ep, nrfx_usbd_handler_desc_t const *p_handler) |
Start sending data over the endpoint using the transfer handler function. More... | |
void * | nrfx_usbd_feeder_buffer_get (void) |
Get the temporary buffer to be used by the feeder. More... | |
nrfx_usbd_ep_status_t | nrfx_usbd_ep_status_get (nrfx_usbd_ep_t ep, size_t *p_size) |
Get the information about last finished or current transfer. More... | |
size_t | nrfx_usbd_epout_size_get (nrfx_usbd_ep_t ep) |
Get number of received bytes. More... | |
bool | nrfx_usbd_ep_is_busy (nrfx_usbd_ep_t ep) |
Check if endpoint buffer is ready or is under USB IP control. More... | |
void | nrfx_usbd_ep_stall (nrfx_usbd_ep_t ep) |
Stall endpoint. More... | |
void | nrfx_usbd_ep_stall_clear (nrfx_usbd_ep_t ep) |
Clear stall flag on endpoint. More... | |
bool | nrfx_usbd_ep_stall_check (nrfx_usbd_ep_t ep) |
Check if endpoint is stalled. More... | |
void | nrfx_usbd_ep_dtoggle_clear (nrfx_usbd_ep_t ep) |
Clear current endpoint data toggle. More... | |
void | nrfx_usbd_setup_get (nrfx_usbd_setup_t *p_setup) |
Get parsed setup data. More... | |
void | nrfx_usbd_setup_data_clear (void) |
Clear the control endpoint for packet reception during DATA stage. More... | |
void | nrfx_usbd_setup_clear (void) |
Clear setup endpoint. More... | |
void | nrfx_usbd_setup_stall (void) |
Stall setup endpoint. More... | |
void | nrfx_usbd_ep_abort (nrfx_usbd_ep_t ep) |
Abort pending transfer on selected endpoint. More... | |
nrfx_usbd_ep_t | nrfx_usbd_last_setup_dir_get (void) |
Get the information about expected transfer SETUP data direction. More... | |
void | nrfx_usbd_transfer_out_drop (nrfx_usbd_ep_t ep) |
Drop transfer on OUT endpoint. More... | |
Macros for creating endpoint identifiers. | ||||
Create identifier for IN endpoint. Auxiliary macros for creating endpoint identifiers compatible with the USB specification. Simple macro to create IN endpoint identifier for given endpoint number.
| ||||
#define | NRFX_USBD_EPIN(n) ((nrfx_usbd_ep_t)NRF_USBD_EPIN(n)) | |||
#define | NRFX_USBD_EPOUT(n) ((nrfx_usbd_ep_t)NRF_USBD_EPOUT(n)) | |||
Create identifier for OUT endpoint. More... | ||||
Universal Serial Bus Device (USBD) peripheral driver.
#define NRFX_USBD_EPOUT | ( | n | ) | ((nrfx_usbd_ep_t)NRF_USBD_EPOUT(n)) |
Create identifier for OUT endpoint.
Simple macro to create OUT endpoint identifier for given endpoint number.
[in] | n | Endpoint number. |
#define NRFX_USBD_FEEDER_BUFFER_SIZE NRFX_USBD_EPSIZE |
The size of internal feeder buffer.
#define NRFX_USBD_ISOSIZE 1024 |
Number of bytes for isochronous endpoints.
Number of bytes for isochronous endpoints in total. This number would be shared between IN and OUT endpoint. It may be also assigned totaly to one endpoint.
#define NRFX_USBD_TRANSFER_IN | ( | name, | |
tx_buff, | |||
tx_size, | |||
tx_flags | |||
) |
Auxiliary macro for declaring IN transfer description with optional flags.
The base macro for creating transfers with any configuration option.
name | Instance name. |
tx_buff | Buffer to transfer. |
tx_size | Transfer size. |
tx_flags | Flags for the transfer (see nrfx_usbd_transfer_flags_t). |
#define NRFX_USBD_TRANSFER_OUT | ( | name, | |
rx_buff, | |||
rx_size | |||
) |
Helper macro for declaring OUT transfer item (nrfx_usbd_transfer_t).
name | Instance name. |
rx_buff | Buffer to transfer. |
rx_size | Transfer size. |
typedef bool(* nrfx_usbd_consumer_t)(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size, size_t data_size) |
USBD transfer consumer.
Pointer for a transfer consumer. Transfer consumer is a feedback function used to prepare a single RX (Host->Device) endpoint transfer.
The transfer must provide a buffer big enough to fit the whole data from the endpoint. Otherwise, the NRFX_USBD_EP_OVERLOAD event is generated.
[out] | p_next | Structure with the data for the next transfer to be filled. Required only if the function returns true. |
[in,out] | p_context | Context variable configured with the transfer. |
[in] | ep_size | The endpoint size. |
[in] | data_size | Number of received bytes in the endpoint buffer. |
false | Current transfer is the last one - you do not need to call the function again. |
true | There is more data to be prepared and when current transfer finishes, the feeder function is expected to be called again. |
typedef void(* nrfx_usbd_event_handler_t)(nrfx_usbd_evt_t const *p_event) |
USBD event callback function type.
[in] | p_event | Event information structure. |
typedef bool(* nrfx_usbd_feeder_t)(nrfx_usbd_ep_transfer_t *p_next, void *p_context, size_t ep_size) |
USBD transfer feeder.
Pointer for a transfer feeder. Transfer feeder is a feedback function used to prepare a single TX (Device->Host) endpoint transfer.
The transfers provided by the feeder must be simple:
[out] | p_next | Structure with the data for the next transfer to be filled. Required only if the function returns true. |
[in,out] | p_context | Context variable configured with the transfer. |
[in] | ep_size | The endpoint size. |
false | The current transfer is the last one - you do not need to call the function again. |
true | There is more data to be prepared and when the current transfer finishes, the feeder function is expected to be called again. |
Endpoint status codes.
Status codes that may be returned by nrfx_usbd_ep_status_get or, except for NRFX_USBD_EP_BUSY, reported together with NRFX_USBD_EVT_EPTRANSFER.
enum nrfx_usbd_ep_t |
Endpoint identifier.
Endpoint identifier used in the driver. This endpoint number is consistent with USB 2.0 specification.
Events generated by the driver.
Enumeration of possible events that may be generated by the driver.
void nrfx_usbd_active_irq_config | ( | void | ) |
Default active interrupt configuration.
Default interrupt configuration. Use in a pair with nrfx_usbd_active_irq_config.
bool nrfx_usbd_bus_suspend_check | ( | void | ) |
Check the bus state.
This function checks if the bus state is suspended.
true | USBD bus is suspended. |
false | USBD bus is active. |
void nrfx_usbd_disable | ( | void | ) |
Disable the USBD port.
After calling this function USBD peripheral would be disabled. No events would be detected or processed by the driver. Clock for the peripheral would be disconnected.
void nrfx_usbd_enable | ( | void | ) |
Enable the USBD port.
After calling this function USBD peripheral would be enabled. The USB LDO would be enabled. Enabled USBD peripheral would request HFCLK. This function does not enable external oscillator, so if it is not enabled by other part of the program after enabling USBD driver HFINT would be used for the USBD peripheral. It is perfectly fine until USBD is started. See nrfx_usbd_start.
In normal situation this function should be called in reaction to USBDETECTED event from POWER peripheral.
Interrupts and USB pins pull-up would stay disabled until nrfx_usbd_start function is called.
void nrfx_usbd_ep_abort | ( | nrfx_usbd_ep_t | ep | ) |
Abort pending transfer on selected endpoint.
[in] | ep | Endpoint number. |
void nrfx_usbd_ep_default_config | ( | void | ) |
Disable all endpoints except for EP0.
Disable all endpoints that can be disabled in USB device while it is still active.
void nrfx_usbd_ep_disable | ( | nrfx_usbd_ep_t | ep | ) |
Disable selected endpoint.
This function disables endpoint itself and its interrupts.
[in] | ep | Endpoint number to disable. |
void nrfx_usbd_ep_dtoggle_clear | ( | nrfx_usbd_ep_t | ep | ) |
Clear current endpoint data toggle.
[in] | ep | Endpoint number to clear. |
void nrfx_usbd_ep_enable | ( | nrfx_usbd_ep_t | ep | ) |
Enable selected endpoint.
This function enables endpoint itself and its interrupts.
[in] | ep | Endpoint number to enable. |
bool nrfx_usbd_ep_enable_check | ( | nrfx_usbd_ep_t | ep | ) |
Check if the selected endpoint is enabled.
[in] | ep | Endpoint number to check. |
true | Endpoint is enabled. |
false | Endpoint is disabled. |
nrfx_err_t nrfx_usbd_ep_handled_transfer | ( | nrfx_usbd_ep_t | ep, |
nrfx_usbd_handler_desc_t const * | p_handler | ||
) |
Start sending data over the endpoint using the transfer handler function.
This function initializes an endpoint transmission. Just before data is transmitted, the transfer handler is called and it prepares a data chunk.
[in] | ep | Endpoint number. For an IN endpoint, sending is initiated. For an OUT endpoint, receiving is initiated. |
[in] | p_handler | Transfer handler - feeder for IN direction and consumer for OUT direction. |
NRFX_SUCCESS | Transfer queued or started. |
NRFX_ERROR_BUSY | Selected endpoint is pending. |
NRFX_ERROR_INVALID_ADDR | Unexpected transfer on EPIN0 or EPOUT0. |
bool nrfx_usbd_ep_is_busy | ( | nrfx_usbd_ep_t | ep | ) |
Check if endpoint buffer is ready or is under USB IP control.
Function to test if endpoint is busy. Endpoint that is busy cannot be accessed by MCU. It means that:
[in] | ep | Endpoint number. |
false | Endpoint is not busy. |
true | Endpoint is busy. |
uint16_t nrfx_usbd_ep_max_packet_size_get | ( | nrfx_usbd_ep_t | ep | ) |
Get configured endpoint packet size.
Function to get configured endpoint size on the buffer.
[in] | ep | Endpoint number. |
void nrfx_usbd_ep_max_packet_size_set | ( | nrfx_usbd_ep_t | ep, |
uint16_t | size | ||
) |
Configure packet size that should be supported by the endpoint.
The real endpoint buffer size is always the same. This value sets max packet size that would be transmitted over the endpoint. This is required by the driver.
[in] | ep | Endpoint number. |
[in] | size | Required maximum packet size. |
void nrfx_usbd_ep_stall | ( | nrfx_usbd_ep_t | ep | ) |
Stall endpoint.
Stall endpoit to send error information during next transfer request from the host.
[in] | ep | Endpoint number to stall. |
bool nrfx_usbd_ep_stall_check | ( | nrfx_usbd_ep_t | ep | ) |
Check if endpoint is stalled.
This function gets stall state of selected endpoint.
[in] | ep | Endpoint number to check. |
false | Endpoint is not stalled. |
true | Endpoint is stalled. |
void nrfx_usbd_ep_stall_clear | ( | nrfx_usbd_ep_t | ep | ) |
Clear stall flag on endpoint.
This function clears endpoint that is stalled.
[in] | ep | Endpoint number. |
nrfx_usbd_ep_status_t nrfx_usbd_ep_status_get | ( | nrfx_usbd_ep_t | ep, |
size_t * | p_size | ||
) |
Get the information about last finished or current transfer.
Function returns the status of the last buffer set for transfer on selected endpoint. The status considers last buffer set by nrfx_usbd_ep_transfer function or by transfer callback function.
[in] | ep | Endpoint number. |
[out] | p_size | Information about the current/last transfer size. |
nrfx_err_t nrfx_usbd_ep_transfer | ( | nrfx_usbd_ep_t | ep, |
nrfx_usbd_transfer_t const * | p_transfer | ||
) |
Start sending data over endpoint.
Function initializes endpoint transmission. This is asynchronous function - it finishes immediately after configuration for transmission is prepared.
[in] | ep | Endpoint number. For IN endpoint sending would be initiated. For OUT endpoint receiving would be initiated. |
[in] | p_transfer | Transfer parameters. |
NRFX_SUCCESS | Transfer queued or started. |
NRFX_ERROR_BUSY | Selected endpoint is pending. |
NRFX_ERROR_INVALID_ADDR | Unexpected transfer on EPIN0 or EPOUT0. |
size_t nrfx_usbd_epout_size_get | ( | nrfx_usbd_ep_t | ep | ) |
Get number of received bytes.
Get the number of received bytes. The function behavior is undefined when called on IN endpoint.
[in] | ep | Endpoint number. |
void* nrfx_usbd_feeder_buffer_get | ( | void | ) |
Get the temporary buffer to be used by the feeder.
This buffer is used for TX transfers and it can be reused automatically when the transfer is finished. Use it for transfer preparation.
May be used inside the feeder configured in nrfx_usbd_ep_handled_transfer.
nrfx_err_t nrfx_usbd_init | ( | nrfx_usbd_event_handler_t | event_handler | ) |
Driver initialization.
[in] | event_handler | Event handler provided by the user. Cannot be null. |
NRFX_SUCCESS | Initialization successful. |
NRFX_ERROR_INVALID_STATE | Driver was already initialized. |
bool nrfx_usbd_is_enabled | ( | void | ) |
Check if driver is enabled.
false | Driver is disabled. |
true | Driver is enabled. |
bool nrfx_usbd_is_initialized | ( | void | ) |
Check if driver is initialized.
false | Driver is not initialized. |
true | Driver is initialized. |
bool nrfx_usbd_is_started | ( | void | ) |
Check if driver is started.
false | Driver is not started. |
true | Driver is started (fully functional). |
nrfx_usbd_ep_t nrfx_usbd_last_setup_dir_get | ( | void | ) |
Get the information about expected transfer SETUP data direction.
Function returns the information about last expected transfer direction.
NRFX_USBD_EPOUT0 | Expecting OUT (Host->Device) direction or no data. |
NRFX_USBD_EPIN0 | Expecting IN (Device->Host) direction. |
void nrfx_usbd_setup_clear | ( | void | ) |
Clear setup endpoint.
This function acknowledges setup when SETUP command was received and processed. It has to be called if no data respond for the SETUP command is sent.
void nrfx_usbd_setup_data_clear | ( | void | ) |
Clear the control endpoint for packet reception during DATA stage.
This function may be called if any more data in control write transfer is expected. Clears only OUT endpoint to be able to take another OUT data token. It does not allow STATUS stage.
void nrfx_usbd_setup_get | ( | nrfx_usbd_setup_t * | p_setup | ) |
Get parsed setup data.
Function fills the parsed setup data structure.
[out] | p_setup | Pointer to data structure that would be filled by parsed data. |
void nrfx_usbd_setup_stall | ( | void | ) |
Stall setup endpoint.
Mark an error on setup endpoint.
void nrfx_usbd_start | ( | bool | enable_sof | ) |
Start USB functionality.
After calling this function USBD peripheral should be fully functional and all new incoming events / interrupts would be processed by the driver.
Also only after calling this function host sees new connected device.
Call this function when USBD power LDO regulator is ready - on USBPWRRDY event from POWER peripheral.
Before USBD interrupts are enabled, external HFXO is requested.
enable_sof | The flag that is used to enable SOF processing. If it is false, SOF interrupt is left disabled and will not be generated. This improves power saving if SOF is not required. |
void nrfx_usbd_stop | ( | void | ) |
Stop USB functionality.
This function disables USBD pull-up and interrupts.
The HFXO request is released in this function.
bool nrfx_usbd_suspend | ( | void | ) |
Suspend USBD operation.
The USBD peripheral is forced to go into the low power mode. The function has to be called in the reaction to NRFX_USBD_EVT_SUSPEND event when the firmware is ready.
After successful call of this function most of the USBD registers would be unavailable.
true | USBD peripheral successfully suspended. |
false | USBD peripheral was not suspended due to resume detection. |
bool nrfx_usbd_suspend_check | ( | void | ) |
Check if USBD is in SUSPEND mode.
true | USBD peripheral is suspended. |
false | USBD peripheral is active. |
void nrfx_usbd_suspend_irq_config | ( | void | ) |
Enable only interrupts that should be processed in SUSPEND mode.
Auxiliary function to help with SUSPEND mode integration. It enables only the interrupts that can be properly processed without stable HFCLK.
Normally all the interrupts are enabled. Use this function to suspend interrupt processing that may require stable HFCLK until the clock is enabled.
void nrfx_usbd_transfer_out_drop | ( | nrfx_usbd_ep_t | ep | ) |
Drop transfer on OUT endpoint.
[in] | ep | OUT endpoint ID. |
bool nrfx_usbd_wakeup_req | ( | void | ) |
Start wake up procedure.
The USBD peripheral is forced to quit the low power mode. After calling this function all the USBD registers would be available.
The hardware starts measuring time when wake up is possible. This may take 0-5 ms depending on how long the SUSPEND state was kept on the USB line.
When NRFX_USBD_EVT_WUREQ event is generated it means that Wake Up signaling has just been started on the USB lines.
true | WakeUp procedure started. |
false | No WakeUp procedure started - bus is already active. |