Microchip® Advanced Software Framework

usb.h File Reference

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)
 

Enumerations

enum  usb_device_callback {
  USB_DEVICE_CALLBACK_SOF,
  USB_DEVICE_CALLBACK_RESET,
  USB_DEVICE_CALLBACK_WAKEUP,
  USB_DEVICE_CALLBACK_RAMACER,
  USB_DEVICE_CALLBACK_SUSPEND,
  USB_DEVICE_CALLBACK_LPMNYET,
  USB_DEVICE_CALLBACK_LPMSUSP,
  USB_DEVICE_CALLBACK_N
}
 Enumeration for the possible callback types for the USB in device module. More...
 
enum  usb_device_endpoint_callback {
  USB_DEVICE_ENDPOINT_CALLBACK_TRCPT,
  USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL,
  USB_DEVICE_ENDPOINT_CALLBACK_RXSTP,
  USB_DEVICE_ENDPOINT_CALLBACK_STALL,
  USB_DEVICE_EP_CALLBACK_N
}
 Enumeration for the possible callback types for the USB endpoint in device module. More...
 
enum  usb_device_endpoint_type {
  USB_DEVICE_ENDPOINT_TYPE_DISABLE,
  USB_DEVICE_ENDPOINT_TYPE_CONTROL,
  USB_DEVICE_ENDPOINT_TYPE_ISOCHRONOUS,
  USB_DEVICE_ENDPOINT_TYPE_BULK,
  USB_DEVICE_ENDPOINT_TYPE_INTERRUPT
}
 Device Endpoint types. More...
 
enum  usb_device_lpm_mode {
  USB_DEVICE_LPM_NOT_SUPPORT,
  USB_DEVICE_LPM_ACK,
  USB_DEVICE_LPM_NYET
}
 Link Power Management Handshake. More...
 
enum  usb_endpoint_size {
  USB_ENDPOINT_8_BYTE,
  USB_ENDPOINT_16_BYTE,
  USB_ENDPOINT_32_BYTE,
  USB_ENDPOINT_64_BYTE,
  USB_ENDPOINT_128_BYTE,
  USB_ENDPOINT_256_BYTE,
  USB_ENDPOINT_512_BYTE,
  USB_ENDPOINT_1023_BYTE
}
 Endpoint Size. More...
 
enum  usb_host_callback {
  USB_HOST_CALLBACK_SOF,
  USB_HOST_CALLBACK_RESET,
  USB_HOST_CALLBACK_WAKEUP,
  USB_HOST_CALLBACK_DNRSM,
  USB_HOST_CALLBACK_UPRSM,
  USB_HOST_CALLBACK_RAMACER,
  USB_HOST_CALLBACK_CONNECT,
  USB_HOST_CALLBACK_DISCONNECT,
  USB_HOST_CALLBACK_N
}
 Enum for the possible callback types for the USB in host module. More...
 
enum  usb_host_pipe_callback {
  USB_HOST_PIPE_CALLBACK_TRANSFER_COMPLETE,
  USB_HOST_PIPE_CALLBACK_ERROR,
  USB_HOST_PIPE_CALLBACK_SETUP,
  USB_HOST_PIPE_CALLBACK_STALL,
  USB_HOST_PIPE_CALLBACK_N
}
 Enum for the possible callback types for the USB pipe in host module. More...
 
enum  usb_host_pipe_token {
  USB_HOST_PIPE_TOKEN_SETUP,
  USB_HOST_PIPE_TOKEN_IN,
  USB_HOST_PIPE_TOKEN_OUT
}
 Host pipe token types. More...
 
enum  usb_host_pipe_type {
  USB_HOST_PIPE_TYPE_DISABLE,
  USB_HOST_PIPE_TYPE_CONTROL,
  USB_HOST_PIPE_TYPE_ISO,
  USB_HOST_PIPE_TYPE_BULK,
  USB_HOST_PIPE_TYPE_INTERRUPT,
  USB_HOST_PIPE_TYPE_EXTENDED
}
 Host pipe types. More...
 
enum  usb_speed {
  USB_SPEED_LOW,
  USB_SPEED_FULL
}
 Enum for the speed status for the USB module. More...
 

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 *)

Enumeration for the possible callback types for the USB in device module.

Enumerator
USB_DEVICE_CALLBACK_SOF 
USB_DEVICE_CALLBACK_RESET 
USB_DEVICE_CALLBACK_WAKEUP 
USB_DEVICE_CALLBACK_RAMACER 
USB_DEVICE_CALLBACK_SUSPEND 
USB_DEVICE_CALLBACK_LPMNYET 
USB_DEVICE_CALLBACK_LPMSUSP 
USB_DEVICE_CALLBACK_N 

Enumeration for the possible callback types for the USB endpoint in device module.

Enumerator
USB_DEVICE_ENDPOINT_CALLBACK_TRCPT 
USB_DEVICE_ENDPOINT_CALLBACK_TRFAIL 
USB_DEVICE_ENDPOINT_CALLBACK_RXSTP 
USB_DEVICE_ENDPOINT_CALLBACK_STALL 
USB_DEVICE_EP_CALLBACK_N 

Device Endpoint types.

Enumerator
USB_DEVICE_ENDPOINT_TYPE_DISABLE 
USB_DEVICE_ENDPOINT_TYPE_CONTROL 
USB_DEVICE_ENDPOINT_TYPE_ISOCHRONOUS 
USB_DEVICE_ENDPOINT_TYPE_BULK 
USB_DEVICE_ENDPOINT_TYPE_INTERRUPT 

Link Power Management Handshake.

Enumerator
USB_DEVICE_LPM_NOT_SUPPORT 
USB_DEVICE_LPM_ACK 
USB_DEVICE_LPM_NYET 

Endpoint Size.

Enumerator
USB_ENDPOINT_8_BYTE 
USB_ENDPOINT_16_BYTE 
USB_ENDPOINT_32_BYTE 
USB_ENDPOINT_64_BYTE 
USB_ENDPOINT_128_BYTE 
USB_ENDPOINT_256_BYTE 
USB_ENDPOINT_512_BYTE 
USB_ENDPOINT_1023_BYTE 

Enum for the possible callback types for the USB in host module.

Enumerator
USB_HOST_CALLBACK_SOF 
USB_HOST_CALLBACK_RESET 
USB_HOST_CALLBACK_WAKEUP 
USB_HOST_CALLBACK_DNRSM 
USB_HOST_CALLBACK_UPRSM 
USB_HOST_CALLBACK_RAMACER 
USB_HOST_CALLBACK_CONNECT 
USB_HOST_CALLBACK_DISCONNECT 
USB_HOST_CALLBACK_N 

Enum for the possible callback types for the USB pipe in host module.

Enumerator
USB_HOST_PIPE_CALLBACK_TRANSFER_COMPLETE 
USB_HOST_PIPE_CALLBACK_ERROR 
USB_HOST_PIPE_CALLBACK_SETUP 
USB_HOST_PIPE_CALLBACK_STALL 
USB_HOST_PIPE_CALLBACK_N 

Host pipe token types.

Enumerator
USB_HOST_PIPE_TOKEN_SETUP 
USB_HOST_PIPE_TOKEN_IN 
USB_HOST_PIPE_TOKEN_OUT 

Host pipe types.

Enumerator
USB_HOST_PIPE_TYPE_DISABLE 
USB_HOST_PIPE_TYPE_CONTROL 
USB_HOST_PIPE_TYPE_ISO 
USB_HOST_PIPE_TYPE_BULK 
USB_HOST_PIPE_TYPE_INTERRUPT 
USB_HOST_PIPE_TYPE_EXTENDED 
enum usb_speed

Enum for the speed status for the USB module.

Enumerator
USB_SPEED_LOW 
USB_SPEED_FULL 

static void usb_device_attach ( struct usb_module module_inst)
inlinestatic

Attach USB device to the bus.

Parameters
module_instPointer to USB device module instance

References usb_module::hw.

Referenced by udd_attach().

static void usb_device_detach ( struct usb_module module_inst)
inlinestatic

Detach USB device from the bus.

Parameters
module_instPointer to USB device module instance

References usb_module::hw.

Referenced by udd_detach().

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]callback_typeCallback type given by an enum
Returns
Status of the callback disable operation.
Return values
STATUS_OKThe callback was disabled successfully.

References Assert, usb_module::device_enabled_callback_mask, usb_module::hw, and STATUS_OK.

Referenced by _usb_device_lpm_suspend(), _usb_on_suspend(), and _usb_on_wakeup().

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]callback_typeCallback type given by an enum
Returns
Status of the callback enable operation.
Return values
STATUS_OKThe callback was enabled successfully.

References Assert, usb_module::device_enabled_callback_mask, usb_module::hw, and STATUS_OK.

Referenced by _usb_device_lpm_suspend(), _usb_on_suspend(), _usb_on_wakeup(), and udd_attach().

void usb_device_endpoint_abort_job ( struct usb_module module_inst,
uint8_t  ep 
)

Abort ongoing job on the endpoint.

Parameters
module_instPointer to USB software instance struct
epEndpoint address

References usb_module::hw, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.

Referenced by udd_ep_abort().

void usb_device_endpoint_clear_halt ( struct usb_module module_inst,
uint8_t  ep 
)

Clear endpoint halt state.

Parameters
module_instPointer to USB software instance struct
epEndpoint address

References usb_module::hw, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.

Referenced by udd_ctrl_stall_data(), and udd_ep_clear_halt().

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]epEndpoint to configure
[in]callback_typeCallback type given by an enum
Returns
Status of the callback disable operation.
Return values
STATUS_OKThe 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.

Referenced by udd_ep_free().

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]epEndpoint to configure
[in]callback_typeCallback type given by an enum
Returns
Status of the callback enable operation.
Return values
STATUS_OKThe 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.

Referenced by udd_ctrl_ep_enable(), and udd_ep_alloc().

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:

  • endpoint address is 0
  • endpoint size is 8 bytes
  • auto_zlp is false
  • endpoint type is control
Parameters
[out]ep_configConfiguration 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.

Referenced by udd_ctrl_ep_enable(), udd_ep_alloc(), and udd_ep_free().

bool usb_device_endpoint_is_configured ( struct usb_module module_inst,
uint8_t  ep 
)

Check if current endpoint is configured.

Parameters
module_instPointer to USB software instance struct
epEndpoint address (direction & number)
Returns
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.

Referenced by udd_ep_wait_stall_clear().

bool usb_device_endpoint_is_halted ( struct usb_module module_inst,
uint8_t  ep 
)

Check if endpoint is halted.

Parameters
module_instPointer to USB software instance struct
epEndpoint address
Returns
true if the endpoint is halted

References usb_module::hw, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.

Referenced by udd_ep_is_halted(), and udd_ep_wait_stall_clear().

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.

Parameters
module_instPointer to USB module instance
ep_numEndpoint number
pbufPointer to buffer
buf_sizeSize of buffer
Returns
Status of procedure
Return values
STATUS_OKJob started successfully
STATUS_ERR_DENIEDEndpoint is not ready

References Assert, usb_module::hw, STATUS_ERR_DENIED, STATUS_OK, usb_descriptor_table, and USB_DEVICE_ENDPOINT_TYPE_DISABLE.

Referenced by _usb_ep0_on_setup(), udd_ctrl_out_received(), udd_ep_run(), and udd_ep_trans_out_next().

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.

Note
The callback must be enabled by usb_device_endpoint_enable_callback, in order for the interrupt handler to call it when the conditions for the callback type is met.
Parameters
[in]module_instPointer to USB software instance struct
[in]ep_numEndpoint to configure
[in]callback_typeCallback type given by an enum
[in]callback_funcPointer to callback function
Returns
Status of the registration operation.
Return values
STATUS_OKThe callback was registered successfully.

References Assert, usb_module::device_endpoint_callback, usb_module::device_endpoint_registered_callback_mask, and STATUS_OK.

Referenced by udd_ctrl_ep_enable(), and udd_ep_alloc().

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]ep_configConfiguration settings for the endpoint
Returns
Status of the device endpoint configuration operation
Return values
STATUS_OKThe device endpoint was configured successfully
STATUS_ERR_DENIEDThe 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.

Referenced by udd_ctrl_ep_enable(), udd_ep_alloc(), and udd_ep_free().

void usb_device_endpoint_set_halt ( struct usb_module module_inst,
uint8_t  ep 
)

Halt the endpoint (send STALL)

Parameters
module_instPointer to USB software instance struct
epEndpoint address

References usb_module::hw, USB_EP_ADDR_MASK, and USB_EP_DIR_IN.

Referenced by udd_ctrl_overflow(), udd_ctrl_stall_data(), udd_ctrl_underflow(), and udd_ep_set_halt().

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.

Parameters
module_instPointer to USB device module instance
pbufPointer to buffer
Returns
Status of procedure
Return values
STATUS_OKJob started successfully
STATUS_ERR_DENIEDEndpoint is not ready

References Assert, usb_module::hw, STATUS_OK, and usb_descriptor_table.

Referenced by udd_ctrl_ep_enable(), udd_ctrl_in_sent(), and udd_ctrl_send_zlp_in().

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]ep_numEndpoint to configure
[in]callback_typeCallback type given by an enum
Returns
Status of the de-registration operation.
Return values
STATUS_OKThe callback was unregistered successfully.

References Assert, usb_module::device_endpoint_callback, usb_module::device_endpoint_registered_callback_mask, and STATUS_OK.

Referenced by udd_ep_free().

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.

Parameters
module_instPointer to USB module instance
ep_numEndpoint number
pbufPointer to buffer
buf_sizeSize of buffer
Returns
Status of procedure
Return values
STATUS_OKJob started successfully
STATUS_ERR_DENIEDEndpoint is not ready

References Assert, usb_module::hw, STATUS_ERR_DENIED, STATUS_OK, usb_descriptor_table, and USB_DEVICE_ENDPOINT_TYPE_DISABLE.

Referenced by udd_ctrl_in_sent(), udd_ctrl_send_zlp_in(), udd_ep_run(), and udd_ep_trans_in_next().

static uint8_t usb_device_get_address ( struct usb_module module_inst)
inlinestatic

Get the address of USB device.

Parameters
module_instPointer to USB device module instance
Returns
USB device address value.

References usb_module::hw.

Referenced by udd_getaddress().

static uint16_t usb_device_get_frame_number ( struct usb_module module_inst)
inlinestatic

Get the frame number of USB device.

Parameters
module_instPointer to USB device module instance
Returns
USB device frame number value.

References usb_module::hw.

Referenced by udd_get_frame_number().

static uint16_t usb_device_get_micro_frame_number ( struct usb_module module_inst)
inlinestatic

Get the micro-frame number of USB device.

Parameters
module_instPointer to USB device module instance
Returns
USB device micro-frame number value.

References usb_module::hw.

Referenced by udd_get_micro_frame_number().

static enum usb_speed usb_device_get_speed ( struct usb_module module_inst)
inlinestatic

Get the speed mode of USB device.

Parameters
module_instPointer to USB device module instance
Returns
USB Speed mode (usb_speed).

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.

Note
The callback must be enabled by usb_device_enable_callback, in order for the interrupt handler to call it when the conditions for the callback type is met.
Parameters
[in]module_instPointer to USB software instance struct
[in]callback_typeCallback type given by an enum
[in]callback_funcPointer to callback function
Returns
Status of the registration operation.
Return values
STATUS_OKThe callback was registered successfully.

References Assert, usb_module::device_callback, usb_module::device_registered_callback_mask, and STATUS_OK.

Referenced by _usb_on_wakeup(), and udd_attach().

static void usb_device_send_remote_wake_up ( struct usb_module module_inst)
inlinestatic

USB device send the resume wakeup.

Parameters
module_instPointer to USB device module instance

References usb_module::hw.

Referenced by udd_send_remotewakeup().

static void usb_device_set_address ( struct usb_module module_inst,
uint8_t  address 
)
inlinestatic

Set the speed mode of USB device.

Parameters
module_instPointer to USB device module instance
addressUSB device address value

References usb_module::hw.

Referenced by _usb_on_bus_reset(), and udd_set_address().

static void usb_device_set_lpm_mode ( struct usb_module module_inst,
enum usb_device_lpm_mode  lpm_mode 
)
inlinestatic

USB device set the LPM mode.

Parameters
module_instPointer to USB device module instance
lpm_modeLPM mode

References usb_module::hw.

Referenced by udd_ctrl_ep_enable().

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]callback_typeCallback type given by an enum
Returns
Status of the de-registration operation.
Return values
STATUS_OKThe 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.

Parameters
module_instpointer to USB module instance

References Assert, and usb_module::hw.

void usb_enable ( struct usb_module module_inst)

Enable the USB module peripheral.

Parameters
module_instpointer to USB module instance

References Assert, and usb_module::hw.

Referenced by udd_enable().

void usb_get_config_defaults ( struct usb_config module_config)

Get the default USB module settings.

Parameters
[out]module_configConfiguration 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.

Referenced by udd_enable().

static uint8_t usb_get_state_machine_status ( struct usb_module module_inst)
inlinestatic

Get the status of USB module's state machine.

Parameters
module_instPointer to USB module instance

References Assert, and usb_module::hw.

Referenced by udd_send_remotewakeup().

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]callback_typeCallback type given by an enum
Returns
Status of the callback disable operation.
Return values
STATUS_OKThe 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.

Parameters
[in]module_instPointer to USB software instance struct
[in]callback_typeCallback type given by an enum
Returns
Status of the callback enable operation.
Return values
STATUS_OKThe 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.

Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
Returns
Status of the setting operation.
Return values
STATUS_OKThe abort job was set successfully.
STATUS_ERR_NOT_INITIALIZEDThe 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.

Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
[in]callback_typeCallback type given by an enum
Returns
Status of the callback disable operation.
Return values
STATUS_OKThe 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.

Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
[in]callback_typeCallback type given by an enum
Returns
Status of the callback enable operation.
Return values
STATUS_OKThe 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.

Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
[out]ep_configConfiguration settings for the pipe
Returns
Status of the get host pipe configuration operation.
Return values
STATUS_OKThe 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:

  • device address is 0
  • endpoint address is 0
  • pipe type is control
  • interval is 0
  • pipe size is 8
Parameters
[out]ep_configConfiguration 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.

Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
[in]b_remotewakeupRemote wake up flag
[in]hirdHost Initiated Resume Duration
Returns
Status of the setup operation.
Return values
STATUS_OKThe setup job was set successfully.
STATUS_BUSYThe pipe is busy.
STATUS_ERR_NOT_INITIALIZEDThe 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.

Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
[in]bufPointer to data buffer
[in]buf_sizeData buffer size
Note
The buffer length should not larger than 0x3FFF
Returns
Status of the setting operation.
Return values
STATUS_OKThe read job was set successfully.
STATUS_BUSYThe pipe is busy.
STATUS_ERR_NOT_INITIALIZEDThe 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.

Note
The callback must be enabled by usb_host_pipe_enable_callback, in order for the interrupt handler to call it when the conditions for the callback type is met.
Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
[in]callback_typeCallback type given by an enum
[in]callback_funcPointer to callback function
Returns
Status of the registration operation.
Return values
STATUS_OKThe callback was registered successfully.

References Assert, and STATUS_OK.

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
[in]ep_configConfiguration settings for the pipe
Returns
Status of the host pipe configuration operation.
Return values
STATUS_OKThe 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.

Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
[in]bufPointer to data buffer
Returns
Status of the setup operation.
Return values
STATUS_OKThe setup job was set successfully.
STATUS_BUSYThe pipe is busy.
STATUS_ERR_NOT_INITIALIZEDThe 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.

Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
[in]callback_typeCallback type given by an enum
Returns
Status of the de-registration operation.
Return values
STATUS_OKThe callback was unregistered successfully.

References Assert, and STATUS_OK.

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]pipe_numPipe to configure
[in]bufPointer to data buffer
[in]buf_sizeData buffer size
Note
The buffer length should not larger than 0x3FFF
Returns
Status of the setting operation.
Return values
STATUS_OKThe write job was set successfully.
STATUS_BUSYThe pipe is busy.
STATUS_ERR_NOT_INITIALIZEDThe 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.

Note
The callback must be enabled by usb_host_enable_callback, in order for the interrupt handler to call it when the conditions for the callback type is met.
Parameters
[in]module_instPointer to USB software instance struct
[in]callback_typeCallback type given by an enum
[in]callback_funcPointer to callback function
Returns
Status of the registration operation.
Return values
STATUS_OKThe callback was registered successfully.

References Assert, and STATUS_OK.

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.

Parameters
[in]module_instPointer to USB software instance struct
[in]callback_typeCallback type given by an enum
Returns
Status of the de-registration operation.
Return values
STATUS_OKThe callback was unregistered successfully.

References Assert, and STATUS_OK.

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.

Parameters
[in,out]module_instPointer to the software module instance struct
[in]hwPointer to the USB hardware module
[in]module_configPointer to the USB configuration options struct
Returns
Status of the initialization procedure.
Return values
STATUS_OKThe 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.

Referenced by udd_enable().