SAM USB Driver.
Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
#include <compiler.h>
#include <clock.h>
#include <gclk.h>
#include <pinmux.h>
#include <system_interrupt.h>
Data Structures | |
struct | usb_config |
USB configurations. More... | |
struct | usb_device_endpoint_config |
USB device endpoint configurations. More... | |
struct | usb_endpoint_callback_parameter |
USB device endpoint callback status parameter structure. More... | |
struct | usb_host_pipe_config |
USB host pipe configurations. More... | |
struct | usb_module |
USB software module instance structure. More... | |
struct | usb_pipe_callback_parameter |
USB host pipe callback status parameter structure. More... | |
Typedefs | |
Host Callback Functions Types | |
typedef void(* | usb_host_callback_t )(struct usb_module *module_inst) |
typedef void(* | usb_host_pipe_callback_t )(struct usb_module *module_inst, void *) |
Device Callback Functions Types | |
typedef void(* | usb_device_callback_t )(struct usb_module *module_inst, void *pointer) |
typedef void(* | usb_device_endpoint_callback_t )(struct usb_module *module_inst, void *pointer) |
Functions | |
static void | usb_device_attach (struct usb_module *module_inst) |
Attach USB device to the bus. More... | |
static void | usb_device_detach (struct usb_module *module_inst) |
Detach USB device from the bus. More... | |
static uint8_t | usb_device_get_address (struct usb_module *module_inst) |
Get the address of USB device. More... | |
static uint16_t | usb_device_get_frame_number (struct usb_module *module_inst) |
Get the frame number of USB device. More... | |
static uint16_t | usb_device_get_micro_frame_number (struct usb_module *module_inst) |
Get the micro-frame number of USB device. More... | |
static enum usb_speed | usb_device_get_speed (struct usb_module *module_inst) |
Get the speed mode of USB device. More... | |
static void | usb_device_send_remote_wake_up (struct usb_module *module_inst) |
USB device send the resume wakeup. More... | |
static void | usb_device_set_address (struct usb_module *module_inst, uint8_t address) |
Set the speed mode of USB device. More... | |
static void | usb_device_set_lpm_mode (struct usb_module *module_inst, enum usb_device_lpm_mode lpm_mode) |
USB device set the LPM mode. More... | |
void | usb_disable (struct usb_module *module_inst) |
Disable the USB module peripheral. More... | |
void | usb_enable (struct usb_module *module_inst) |
Enable the USB module peripheral. More... | |
void | usb_get_config_defaults (struct usb_config *module_config) |
Get the default USB module settings. More... | |
static uint8_t | usb_get_state_machine_status (struct usb_module *module_inst) |
Get the status of USB module's state machine. More... | |
enum status_code | usb_init (struct usb_module *module_inst, Usb *const hw, struct usb_config *module_config) |
Initializes USB module instance. More... | |
USB Host Callback Management | |
enum status_code | usb_host_register_callback (struct usb_module *module_inst, enum usb_host_callback callback_type, usb_host_callback_t callback_func) |
Registers a USB host callback. More... | |
enum status_code | usb_host_unregister_callback (struct usb_module *module_inst, enum usb_host_callback callback_type) |
Unregisters a USB host callback. More... | |
enum status_code | usb_host_enable_callback (struct usb_module *module_inst, enum usb_host_callback callback_type) |
Enables USB host callback generation for a given type. More... | |
enum status_code | usb_host_disable_callback (struct usb_module *module_inst, enum usb_host_callback callback_type) |
Disables USB host callback generation for a given type. More... | |
USB Device Callback Management | |
enum status_code | usb_device_register_callback (struct usb_module *module_inst, enum usb_device_callback callback_type, usb_device_callback_t callback_func) |
Registers a USB device callback. More... | |
enum status_code | usb_device_unregister_callback (struct usb_module *module_inst, enum usb_device_callback callback_type) |
Unregisters a USB device callback. More... | |
enum status_code | usb_device_enable_callback (struct usb_module *module_inst, enum usb_device_callback callback_type) |
Enables USB device callback generation for a given type. More... | |
enum status_code | usb_device_disable_callback (struct usb_module *module_inst, enum usb_device_callback callback_type) |
Disables USB device callback generation for a given type. More... | |
USB Host Pipe Configuration | |
void | usb_host_pipe_get_config_defaults (struct usb_host_pipe_config *ep_config) |
Initializes an USB host pipe configuration structure to defaults. More... | |
enum status_code | usb_host_pipe_set_config (struct usb_module *module_inst, uint8_t pipe_num, struct usb_host_pipe_config *ep_config) |
Writes an USB host pipe configuration to the hardware module. More... | |
enum status_code | usb_host_pipe_get_config (struct usb_module *module_inst, uint8_t pipe_num, struct usb_host_pipe_config *ep_config) |
Gets an USB host pipe configuration. More... | |
USB Device Endpoint Configuration | |
void | usb_device_endpoint_get_config_defaults (struct usb_device_endpoint_config *ep_config) |
Initializes an USB device endpoint configuration structure to defaults. More... | |
enum status_code | usb_device_endpoint_set_config (struct usb_module *module_inst, struct usb_device_endpoint_config *ep_config) |
Writes an USB device endpoint configuration to the hardware module. More... | |
bool | usb_device_endpoint_is_configured (struct usb_module *module_inst, uint8_t ep) |
Check if current endpoint is configured. More... | |
USB Host Pipe Callback Management | |
enum status_code | usb_host_pipe_register_callback (struct usb_module *module_inst, uint8_t pipe_num, enum usb_host_pipe_callback callback_type, usb_host_pipe_callback_t callback_func) |
Registers a USB host pipe callback. More... | |
enum status_code | usb_host_pipe_unregister_callback (struct usb_module *module_inst, uint8_t pipe_num, enum usb_host_pipe_callback callback_type) |
Unregisters a USB host pipe callback. More... | |
enum status_code | usb_host_pipe_enable_callback (struct usb_module *module_inst, uint8_t pipe_num, enum usb_host_pipe_callback callback_type) |
Enables USB host pipe callback generation for a given type. More... | |
enum status_code | usb_host_pipe_disable_callback (struct usb_module *module_inst, uint8_t pipe_num, enum usb_host_pipe_callback callback_type) |
Disables USB host callback generation for a given type. More... | |
USB Device Endpoint Callback Management | |
enum status_code | usb_device_endpoint_register_callback (struct usb_module *module_inst, uint8_t ep_num, enum usb_device_endpoint_callback callback_type, usb_device_endpoint_callback_t callback_func) |
Registers a USB device endpoint callback. More... | |
enum status_code | usb_device_endpoint_unregister_callback (struct usb_module *module_inst, uint8_t ep_num, enum usb_device_endpoint_callback callback_type) |
Unregisters a USB device endpoint callback. More... | |
enum status_code | usb_device_endpoint_enable_callback (struct usb_module *module_inst, uint8_t ep, enum usb_device_endpoint_callback callback_type) |
Enables USB device endpoint callback generation for a given type. More... | |
enum status_code | usb_device_endpoint_disable_callback (struct usb_module *module_inst, uint8_t ep, enum usb_device_endpoint_callback callback_type) |
Disables USB device endpoint callback generation for a given type. More... | |
USB Host Pipe Job Management | |
enum status_code | usb_host_pipe_setup_job (struct usb_module *module_inst, uint8_t pipe_num, uint8_t *buf) |
Sends the setup package. More... | |
enum status_code | usb_host_pipe_read_job (struct usb_module *module_inst, uint8_t pipe_num, uint8_t *buf, uint32_t buf_size) |
USB host pipe read job. More... | |
enum status_code | usb_host_pipe_write_job (struct usb_module *module_inst, uint8_t pipe_num, uint8_t *buf, uint32_t buf_size) |
USB host pipe write job. More... | |
enum status_code | usb_host_pipe_abort_job (struct usb_module *module_inst, uint8_t pipe_num) |
USB host abort a pipe job. More... | |
enum status_code | usb_host_pipe_lpm_job (struct usb_module *module_inst, uint8_t pipe_num, bool b_remotewakeup, uint8_t hird) |
Sends the LPM package. More... | |
USB Device Endpoint Job Management | |
enum status_code | usb_device_endpoint_write_buffer_job (struct usb_module *module_inst, uint8_t ep_num, uint8_t *pbuf, uint32_t buf_size) |
Start write buffer job on a endpoint. More... | |
enum status_code | usb_device_endpoint_read_buffer_job (struct usb_module *module_inst, uint8_t ep_num, uint8_t *pbuf, uint32_t buf_size) |
Start read buffer job on a endpoint. More... | |
enum status_code | usb_device_endpoint_setup_buffer_job (struct usb_module *module_inst, uint8_t *pbuf) |
Start setup packet read job on a endpoint. More... | |
void | usb_device_endpoint_abort_job (struct usb_module *module_inst, uint8_t ep) |
Abort ongoing job on the endpoint. More... | |
USB Device Endpoint Operations | |
bool | usb_device_endpoint_is_halted (struct usb_module *module_inst, uint8_t ep) |
Check if endpoint is halted. More... | |
void | usb_device_endpoint_set_halt (struct usb_module *module_inst, uint8_t ep) |
Halt the endpoint (send STALL) More... | |
void | usb_device_endpoint_clear_halt (struct usb_module *module_inst, uint8_t ep) |
Clear endpoint halt state. More... | |
typedef void(* usb_device_callback_t)(struct usb_module *module_inst, void *pointer) |
typedef void(* usb_device_endpoint_callback_t)(struct usb_module *module_inst, void *pointer) |
typedef void(* usb_host_callback_t)(struct usb_module *module_inst) |
typedef void(* usb_host_pipe_callback_t)(struct usb_module *module_inst, void *) |
enum usb_device_callback |
enum usb_device_lpm_mode |
enum usb_endpoint_size |
enum usb_host_callback |
enum usb_host_pipe_token |
enum usb_host_pipe_type |
enum usb_speed |
|
inlinestatic |
Attach USB device to the bus.
module_inst | Pointer to USB device module instance |
References usb_module::hw.
|
inlinestatic |
Detach USB device from the bus.
module_inst | Pointer to USB device module instance |
References usb_module::hw.
enum status_code usb_device_disable_callback | ( | struct usb_module * | module_inst, |
enum usb_device_callback | callback_type | ||
) |
Disables USB device callback generation for a given type.
Disables asynchronous callbacks for a given logical type.
[in] | module_inst | Pointer to USB software instance struct |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was disabled successfully. |
References Assert, usb_module::device_enabled_callback_mask, usb_module::hw, and STATUS_OK.
enum status_code usb_device_enable_callback | ( | struct usb_module * | module_inst, |
enum usb_device_callback | callback_type | ||
) |
Enables USB device callback generation for a given type.
Enables asynchronous callbacks for a given logical type. This must be called before USB device generate callback events.
[in] | module_inst | Pointer to USB software instance struct |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was enabled successfully. |
References Assert, usb_module::device_enabled_callback_mask, usb_module::hw, and STATUS_OK.
void usb_device_endpoint_abort_job | ( | struct usb_module * | module_inst, |
uint8_t | ep | ||
) |
Abort ongoing job on the endpoint.
module_inst | Pointer to USB software instance struct |
ep | Endpoint address |
References usb_module::hw, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
void usb_device_endpoint_clear_halt | ( | struct usb_module * | module_inst, |
uint8_t | ep | ||
) |
Clear endpoint halt state.
module_inst | Pointer to USB software instance struct |
ep | Endpoint address |
References usb_module::hw, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
enum status_code usb_device_endpoint_disable_callback | ( | struct usb_module * | module_inst, |
uint8_t | ep, | ||
enum usb_device_endpoint_callback | callback_type | ||
) |
Disables USB device endpoint callback generation for a given type.
Disables callbacks for a given logical type.
[in] | module_inst | Pointer to USB software instance struct |
[in] | ep | Endpoint to configure |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was disabled successfully. |
References Assert, usb_module::device_endpoint_enabled_callback_mask, usb_module::hw, STATUS_OK, USB_DEVICE_ENDPOINT_CALLBACK_RXSTP, USB_DEVICE_ENDPOINT_CALLBACK_STALL, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT, USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
enum status_code usb_device_endpoint_enable_callback | ( | struct usb_module * | module_inst, |
uint8_t | ep, | ||
enum usb_device_endpoint_callback | callback_type | ||
) |
Enables USB device endpoint callback generation for a given type.
Enables callbacks for a given logical type. This must be called before USB device pipe generate callback events.
[in] | module_inst | Pointer to USB software instance struct |
[in] | ep | Endpoint to configure |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was enabled successfully. |
References Assert, usb_module::device_endpoint_enabled_callback_mask, usb_module::hw, STATUS_OK, USB_DEVICE_ENDPOINT_CALLBACK_RXSTP, USB_DEVICE_ENDPOINT_CALLBACK_STALL, USB_DEVICE_ENDPOINT_CALLBACK_TRCPT, USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
void usb_device_endpoint_get_config_defaults | ( | struct usb_device_endpoint_config * | ep_config | ) |
Initializes an USB device endpoint configuration structure to defaults.
Initializes a given USB device endpoint configuration structure to a set of known default values. This function should be called on all new instances of these configuration structures before being modified by the user application.
The default configuration is as follows:
[out] | ep_config | Configuration structure to initialize to default values |
References Assert, usb_device_endpoint_config::auto_zlp, usb_device_endpoint_config::ep_address, usb_device_endpoint_config::ep_size, usb_device_endpoint_config::ep_type, USB_DEVICE_ENDPOINT_TYPE_CONTROL, and USB_ENDPOINT_8_BYTE.
bool usb_device_endpoint_is_configured | ( | struct usb_module * | module_inst, |
uint8_t | ep | ||
) |
Check if current endpoint is configured.
module_inst | Pointer to USB software instance struct |
ep | Endpoint address (direction & number) |
true
if endpoint is configured and ready to use References usb_module::hw, USB_DEVICE_ENDPOINT_TYPE_DISABLE, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
bool usb_device_endpoint_is_halted | ( | struct usb_module * | module_inst, |
uint8_t | ep | ||
) |
Check if endpoint is halted.
module_inst | Pointer to USB software instance struct |
ep | Endpoint address |
true
if the endpoint is halted References usb_module::hw, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
enum status_code usb_device_endpoint_read_buffer_job | ( | struct usb_module * | module_inst, |
uint8_t | ep_num, | ||
uint8_t * | pbuf, | ||
uint32_t | buf_size | ||
) |
Start read buffer job on a endpoint.
module_inst | Pointer to USB module instance |
ep_num | Endpoint number |
pbuf | Pointer to buffer |
buf_size | Size of buffer |
STATUS_OK | Job started successfully |
STATUS_ERR_DENIED | Endpoint is not ready |
References Assert, usb_module::hw, STATUS_ERR_DENIED, STATUS_OK, usb_descriptor_table, and USB_DEVICE_ENDPOINT_TYPE_DISABLE.
enum status_code usb_device_endpoint_register_callback | ( | struct usb_module * | module_inst, |
uint8_t | ep_num, | ||
enum usb_device_endpoint_callback | callback_type, | ||
usb_device_endpoint_callback_t | callback_func | ||
) |
Registers a USB device endpoint callback.
Registers a callback function which is implemented by the user.
[in] | module_inst | Pointer to USB software instance struct |
[in] | ep_num | Endpoint to configure |
[in] | callback_type | Callback type given by an enum |
[in] | callback_func | Pointer to callback function |
STATUS_OK | The callback was registered successfully. |
References Assert, usb_module::device_endpoint_callback, usb_module::device_endpoint_registered_callback_mask, and STATUS_OK.
enum status_code usb_device_endpoint_set_config | ( | struct usb_module * | module_inst, |
struct usb_device_endpoint_config * | ep_config | ||
) |
Writes an USB device endpoint configuration to the hardware module.
Writes out a given configuration of an USB device endpoint configuration to the hardware module. If the pipe is already configured, the new configuration will replace the existing one.
[in] | module_inst | Pointer to USB software instance struct |
[in] | ep_config | Configuration settings for the endpoint |
STATUS_OK | The device endpoint was configured successfully |
STATUS_ERR_DENIED | The endpoint address is already configured |
References Assert, usb_device_endpoint_config::auto_zlp, usb_device_endpoint_config::ep_address, usb_device_endpoint_config::ep_size, usb_device_endpoint_config::ep_type, usb_module::hw, STATUS_ERR_DENIED, STATUS_OK, usb_descriptor_table, USB_DEVICE_ENDPOINT_TYPE_BULK, USB_DEVICE_ENDPOINT_TYPE_CONTROL, USB_DEVICE_ENDPOINT_TYPE_DISABLE, USB_DEVICE_ENDPOINT_TYPE_INTERRUPT, USB_DEVICE_ENDPOINT_TYPE_ISOCHRONOUS, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
void usb_device_endpoint_set_halt | ( | struct usb_module * | module_inst, |
uint8_t | ep | ||
) |
Halt the endpoint (send STALL)
module_inst | Pointer to USB software instance struct |
ep | Endpoint address |
References usb_module::hw, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.
enum status_code usb_device_endpoint_setup_buffer_job | ( | struct usb_module * | module_inst, |
uint8_t * | pbuf | ||
) |
Start setup packet read job on a endpoint.
module_inst | Pointer to USB device module instance |
pbuf | Pointer to buffer |
STATUS_OK | Job started successfully |
STATUS_ERR_DENIED | Endpoint is not ready |
References Assert, usb_module::hw, STATUS_OK, and usb_descriptor_table.
enum status_code usb_device_endpoint_unregister_callback | ( | struct usb_module * | module_inst, |
uint8_t | ep_num, | ||
enum usb_device_endpoint_callback | callback_type | ||
) |
Unregisters a USB device endpoint callback.
Unregisters an callback implemented by the user. Removing it from the internal callback registration table.
[in] | module_inst | Pointer to USB software instance struct |
[in] | ep_num | Endpoint to configure |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was unregistered successfully. |
References Assert, usb_module::device_endpoint_callback, usb_module::device_endpoint_registered_callback_mask, and STATUS_OK.
enum status_code usb_device_endpoint_write_buffer_job | ( | struct usb_module * | module_inst, |
uint8_t | ep_num, | ||
uint8_t * | pbuf, | ||
uint32_t | buf_size | ||
) |
Start write buffer job on a endpoint.
module_inst | Pointer to USB module instance |
ep_num | Endpoint number |
pbuf | Pointer to buffer |
buf_size | Size of buffer |
STATUS_OK | Job started successfully |
STATUS_ERR_DENIED | Endpoint is not ready |
References Assert, usb_module::hw, STATUS_ERR_DENIED, STATUS_OK, usb_descriptor_table, and USB_DEVICE_ENDPOINT_TYPE_DISABLE.
|
inlinestatic |
Get the address of USB device.
module_inst | Pointer to USB device module instance |
References usb_module::hw.
|
inlinestatic |
Get the frame number of USB device.
module_inst | Pointer to USB device module instance |
References usb_module::hw.
|
inlinestatic |
Get the micro-frame number of USB device.
module_inst | Pointer to USB device module instance |
References usb_module::hw.
|
inlinestatic |
Get the speed mode of USB device.
module_inst | Pointer to USB device module instance |
References usb_module::hw, USB_SPEED_FULL, and USB_SPEED_LOW.
enum status_code usb_device_register_callback | ( | struct usb_module * | module_inst, |
enum usb_device_callback | callback_type, | ||
usb_device_callback_t | callback_func | ||
) |
Registers a USB device callback.
Registers a callback function which is implemented by the user.
[in] | module_inst | Pointer to USB software instance struct |
[in] | callback_type | Callback type given by an enum |
[in] | callback_func | Pointer to callback function |
STATUS_OK | The callback was registered successfully. |
References Assert, usb_module::device_callback, usb_module::device_registered_callback_mask, and STATUS_OK.
|
inlinestatic |
USB device send the resume wakeup.
module_inst | Pointer to USB device module instance |
References usb_module::hw.
|
inlinestatic |
Set the speed mode of USB device.
module_inst | Pointer to USB device module instance |
address | USB device address value |
References usb_module::hw.
|
inlinestatic |
USB device set the LPM mode.
module_inst | Pointer to USB device module instance |
lpm_mode | LPM mode |
References usb_module::hw.
enum status_code usb_device_unregister_callback | ( | struct usb_module * | module_inst, |
enum usb_device_callback | callback_type | ||
) |
Unregisters a USB device callback.
Unregisters an asynchronous callback implemented by the user. Removing it from the internal callback registration table.
[in] | module_inst | Pointer to USB software instance struct |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was unregistered successfully. |
References Assert, usb_module::device_callback, usb_module::device_registered_callback_mask, and STATUS_OK.
void usb_disable | ( | struct usb_module * | module_inst | ) |
Disable the USB module peripheral.
module_inst | pointer to USB module instance |
References Assert, and usb_module::hw.
void usb_enable | ( | struct usb_module * | module_inst | ) |
Enable the USB module peripheral.
module_inst | pointer to USB module instance |
References Assert, and usb_module::hw.
void usb_get_config_defaults | ( | struct usb_config * | module_config | ) |
Get the default USB module settings.
[out] | module_config | Configuration structure to initialize to default values |
References Assert, GCLK_GENERATOR_3, usb_config::run_in_standby, usb_config::select_host_mode, usb_config::source_generator, usb_config::speed_mode, and USB_SPEED_FULL.
|
inlinestatic |
Get the status of USB module's state machine.
module_inst | Pointer to USB module instance |
References Assert, and usb_module::hw.
enum status_code usb_host_disable_callback | ( | struct usb_module * | module_inst, |
enum usb_host_callback | callback_type | ||
) |
Disables USB host callback generation for a given type.
Disables asynchronous callbacks for a given logical type.
[in] | module_inst | Pointer to USB software instance struct |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was disabled successfully. |
References Assert, usb_module::hw, STATUS_OK, USB_HOST_CALLBACK_CONNECT, USB_HOST_CALLBACK_DISCONNECT, USB_HOST_CALLBACK_DNRSM, USB_HOST_CALLBACK_RAMACER, USB_HOST_CALLBACK_RESET, USB_HOST_CALLBACK_SOF, USB_HOST_CALLBACK_UPRSM, and USB_HOST_CALLBACK_WAKEUP.
enum status_code usb_host_enable_callback | ( | struct usb_module * | module_inst, |
enum usb_host_callback | callback_type | ||
) |
Enables USB host callback generation for a given type.
Enables asynchronous callbacks for a given logical type. This must be called before USB host generate callback events.
[in] | module_inst | Pointer to USB software instance struct |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was enabled successfully. |
References Assert, usb_module::hw, STATUS_OK, USB_HOST_CALLBACK_CONNECT, USB_HOST_CALLBACK_DISCONNECT, USB_HOST_CALLBACK_DNRSM, USB_HOST_CALLBACK_RAMACER, USB_HOST_CALLBACK_RESET, USB_HOST_CALLBACK_SOF, USB_HOST_CALLBACK_UPRSM, and USB_HOST_CALLBACK_WAKEUP.
enum status_code usb_host_pipe_abort_job | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num | ||
) |
USB host abort a pipe job.
USB host pipe abort job by freeze the pipe.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
STATUS_OK | The abort job was set successfully. |
STATUS_ERR_NOT_INITIALIZED | The pipe has not been configured. |
References Assert, usb_module::hw, STATUS_ERR_NOT_INITIALIZED, STATUS_OK, and USB_HOST_PIPE_TYPE_DISABLE.
enum status_code usb_host_pipe_disable_callback | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num, | ||
enum usb_host_pipe_callback | callback_type | ||
) |
Disables USB host callback generation for a given type.
Disables asynchronous callbacks for a given logical type.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was disabled successfully. |
References Assert, usb_module::hw, STATUS_OK, USB_HOST_PIPE_CALLBACK_ERROR, USB_HOST_PIPE_CALLBACK_SETUP, USB_HOST_PIPE_CALLBACK_STALL, and USB_HOST_PIPE_CALLBACK_TRANSFER_COMPLETE.
enum status_code usb_host_pipe_enable_callback | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num, | ||
enum usb_host_pipe_callback | callback_type | ||
) |
Enables USB host pipe callback generation for a given type.
Enables asynchronous callbacks for a given logical type. This must be called before USB host pipe generate callback events.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was enabled successfully. |
References Assert, usb_module::hw, STATUS_OK, USB_HOST_PIPE_CALLBACK_ERROR, USB_HOST_PIPE_CALLBACK_SETUP, USB_HOST_PIPE_CALLBACK_STALL, and USB_HOST_PIPE_CALLBACK_TRANSFER_COMPLETE.
enum status_code usb_host_pipe_get_config | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num, | ||
struct usb_host_pipe_config * | ep_config | ||
) |
Gets an USB host pipe configuration.
Gets out the configuration of an USB host pipe from the hardware module.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
[out] | ep_config | Configuration settings for the pipe |
STATUS_OK | The host pipe configuration was read successfully. |
References Assert, usb_host_pipe_config::binterval, usb_host_pipe_config::device_address, usb_host_pipe_config::endpoint_address, usb_module::hw, usb_host_pipe_config::pipe_type, usb_host_pipe_config::size, STATUS_OK, usb_descriptor_table, USB_EP_DIR_IN, and USB_HOST_PIPE_TOKEN_IN.
void usb_host_pipe_get_config_defaults | ( | struct usb_host_pipe_config * | ep_config | ) |
Initializes an USB host pipe configuration structure to defaults.
Initializes a given USB host pipe configuration structure to a set of known default values. This function should be called on all new instances of these configuration structures before being modified by the user application.
The default configuration is as follows:
[out] | ep_config | Configuration structure to initialize to default values |
References Assert, usb_host_pipe_config::binterval, usb_host_pipe_config::device_address, usb_host_pipe_config::endpoint_address, usb_host_pipe_config::pipe_type, usb_host_pipe_config::size, and USB_HOST_PIPE_TYPE_CONTROL.
enum status_code usb_host_pipe_lpm_job | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num, | ||
bool | b_remotewakeup, | ||
uint8_t | hird | ||
) |
Sends the LPM package.
Sends the LPM package.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
[in] | b_remotewakeup | Remote wake up flag |
[in] | hird | Host Initiated Resume Duration |
STATUS_OK | The setup job was set successfully. |
STATUS_BUSY | The pipe is busy. |
STATUS_ERR_NOT_INITIALIZED | The pipe has not been configured. |
References Assert, usb_module::hw, STATUS_BUSY, STATUS_ERR_NOT_INITIALIZED, STATUS_OK, usb_descriptor_table, USB_HOST_PIPE_TYPE_DISABLE, USB_HOST_PIPE_TYPE_EXTENDED, USB_LPM_ATTRIBUT_BLINKSTATE_L1, USB_LPM_ATTRIBUT_HIRD, and USB_LPM_ATTRIBUT_REMOTEWAKE.
enum status_code usb_host_pipe_read_job | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num, | ||
uint8_t * | buf, | ||
uint32_t | buf_size | ||
) |
USB host pipe read job.
USB host pipe read job by set and start an in transaction transfer.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
[in] | buf | Pointer to data buffer |
[in] | buf_size | Data buffer size |
STATUS_OK | The read job was set successfully. |
STATUS_BUSY | The pipe is busy. |
STATUS_ERR_NOT_INITIALIZED | The pipe has not been configured. |
References Assert, usb_module::hw, STATUS_BUSY, STATUS_ERR_NOT_INITIALIZED, STATUS_OK, usb_descriptor_table, USB_HOST_PIPE_TOKEN_IN, and USB_HOST_PIPE_TYPE_DISABLE.
enum status_code usb_host_pipe_register_callback | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num, | ||
enum usb_host_pipe_callback | callback_type, | ||
usb_host_pipe_callback_t | callback_func | ||
) |
Registers a USB host pipe callback.
Registers a callback function which is implemented by the user.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
[in] | callback_type | Callback type given by an enum |
[in] | callback_func | Pointer to callback function |
STATUS_OK | The callback was registered successfully. |
enum status_code usb_host_pipe_set_config | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num, | ||
struct usb_host_pipe_config * | ep_config | ||
) |
Writes an USB host pipe configuration to the hardware module.
Writes out a given configuration of an USB host pipe configuration to the hardware module. If the pipe is already configured, the new configuration will replace the existing one.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
[in] | ep_config | Configuration settings for the pipe |
STATUS_OK | The host pipe was configured successfully. |
References Assert, usb_host_pipe_config::binterval, clz, usb_host_pipe_config::device_address, usb_host_pipe_config::endpoint_address, usb_module::hw, max, min, usb_host_pipe_config::pipe_type, usb_host_pipe_config::size, STATUS_OK, UHD_BULK_INTERVAL_MIN, usb_descriptor_table, USB_EP_ADDR_MASK, USB_EP_DIR_IN, USB_HOST_PIPE_TOKEN_IN, USB_HOST_PIPE_TOKEN_OUT, USB_HOST_PIPE_TOKEN_SETUP, and USB_HOST_PIPE_TYPE_BULK.
enum status_code usb_host_pipe_setup_job | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num, | ||
uint8_t * | buf | ||
) |
Sends the setup package.
Sends the setup package.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
[in] | buf | Pointer to data buffer |
STATUS_OK | The setup job was set successfully. |
STATUS_BUSY | The pipe is busy. |
STATUS_ERR_NOT_INITIALIZED | The pipe has not been configured. |
References Assert, usb_module::hw, STATUS_BUSY, STATUS_ERR_NOT_INITIALIZED, STATUS_OK, usb_descriptor_table, USB_HOST_PIPE_TOKEN_SETUP, and USB_HOST_PIPE_TYPE_DISABLE.
enum status_code usb_host_pipe_unregister_callback | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num, | ||
enum usb_host_pipe_callback | callback_type | ||
) |
Unregisters a USB host pipe callback.
Unregisters an asynchronous callback implemented by the user. Removing it from the internal callback registration table.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was unregistered successfully. |
enum status_code usb_host_pipe_write_job | ( | struct usb_module * | module_inst, |
uint8_t | pipe_num, | ||
uint8_t * | buf, | ||
uint32_t | buf_size | ||
) |
USB host pipe write job.
USB host pipe write job by set and start an out transaction transfer.
[in] | module_inst | Pointer to USB software instance struct |
[in] | pipe_num | Pipe to configure |
[in] | buf | Pointer to data buffer |
[in] | buf_size | Data buffer size |
STATUS_OK | The write job was set successfully. |
STATUS_BUSY | The pipe is busy. |
STATUS_ERR_NOT_INITIALIZED | The pipe has not been configured. |
References Assert, usb_module::hw, STATUS_BUSY, STATUS_ERR_NOT_INITIALIZED, STATUS_OK, usb_descriptor_table, USB_HOST_PIPE_TOKEN_OUT, and USB_HOST_PIPE_TYPE_DISABLE.
enum status_code usb_host_register_callback | ( | struct usb_module * | module_inst, |
enum usb_host_callback | callback_type, | ||
usb_host_callback_t | callback_func | ||
) |
Registers a USB host callback.
Registers a callback function which is implemented by the user.
[in] | module_inst | Pointer to USB software instance struct |
[in] | callback_type | Callback type given by an enum |
[in] | callback_func | Pointer to callback function |
STATUS_OK | The callback was registered successfully. |
enum status_code usb_host_unregister_callback | ( | struct usb_module * | module_inst, |
enum usb_host_callback | callback_type | ||
) |
Unregisters a USB host callback.
Unregisters an asynchronous callback implemented by the user. Removing it from the internal callback registration table.
[in] | module_inst | Pointer to USB software instance struct |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | The callback was unregistered successfully. |
enum status_code usb_init | ( | struct usb_module * | module_inst, |
Usb *const | hw, | ||
struct usb_config * | module_config | ||
) |
Initializes USB module instance.
Enables the clock and initializes the USB module, based on the given configuration values.
[in,out] | module_inst | Pointer to the software module instance struct |
[in] | hw | Pointer to the USB hardware module |
[in] | module_config | Pointer to the USB configuration options struct |
STATUS_OK | The module was initialized successfully |
References Assert, usb_module::device_callback, usb_module::device_enabled_callback_mask, usb_module::device_endpoint_callback, usb_module::device_endpoint_enabled_callback_mask, usb_module::device_endpoint_registered_callback_mask, usb_module::device_registered_callback_mask, usb_module::hw, system_pinmux_config::mux_position, NVM_USB_PAD_TRANSN_POS, NVM_USB_PAD_TRANSN_SIZE, NVM_USB_PAD_TRANSP_POS, NVM_USB_PAD_TRANSP_SIZE, NVM_USB_PAD_TRIM_POS, NVM_USB_PAD_TRIM_SIZE, usb_config::run_in_standby, usb_config::select_host_mode, system_gclk_chan_config::source_generator, usb_config::source_generator, usb_config::speed_mode, STATUS_OK, system_apb_clock_set_mask(), SYSTEM_CLOCK_APB_APBB, system_gclk_chan_enable(), system_gclk_chan_get_config_defaults(), system_gclk_chan_set_config(), system_interrupt_enable(), SYSTEM_INTERRUPT_MODULE_USB, system_pinmux_get_config_defaults(), system_pinmux_pin_set_config(), usb_descriptor_table, USB_DEVICE_CALLBACK_N, USB_DEVICE_EP_CALLBACK_N, USB_HOST_CALLBACK_N, USB_HOST_PIPE_CALLBACK_N, USB_SPEED_FULL, and USB_SPEED_LOW.