Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Implementation of UDC

Internal implementation.

Data Structures

struct  udc_string_desc_t
 USB device string descriptor Structure used to transfer ASCII strings to USB String descriptor structure. More...
 

Functions

static usb_conf_desc_t
UDC_DESC_STORAGE
udc_get_eof_conf (void)
 Returns a value to check the end of USB Configuration descriptor. More...
 
usb_iface_desc_t UDC_DESC_STORAGEudc_get_interface_desc (void)
 Returns a pointer on the current interface descriptor. More...
 
static bool udc_iface_disable (uint8_t iface_num)
 Disables an usb device interface (UDI) This routine call the UDI corresponding to interface number. More...
 
static bool udc_iface_enable (uint8_t iface_num, uint8_t setting_num)
 Enables an usb device interface (UDI) This routine calls the UDI corresponding to the interface and setting number. More...
 
static usb_conf_desc_t
UDC_DESC_STORAGE
udc_next_desc_in_iface (usb_conf_desc_t UDC_DESC_STORAGE *desc, uint8_t desc_id)
 Search specific descriptor in global interface descriptor. More...
 
bool udc_process_setup (void)
 Main routine to manage the USB SETUP request. More...
 
static bool udc_req_ep (void)
 Send the SETUP interface request to UDI. More...
 
static bool udc_req_iface (void)
 Send the SETUP interface request to UDI. More...
 
static bool udc_req_std_dev_clear_feature (void)
 Standard device request to change device status. More...
 
static bool udc_req_std_dev_get_configuration (void)
 Standard device request to get configuration number. More...
 
static bool udc_req_std_dev_get_descriptor (void)
 Standard device request to get descriptors about USB device. More...
 
static bool udc_req_std_dev_get_status (void)
 Standard device request to get device status. More...
 
static bool udc_req_std_dev_get_str_desc (void)
 Standard device request to get device string descriptor. More...
 
static bool udc_req_std_dev_set_address (void)
 Standard device request to set device address. More...
 
static bool udc_req_std_dev_set_configuration (void)
 Standard device request to enable a configuration. More...
 
static bool udc_req_std_dev_set_feature (void)
 Standard device request to set a feature. More...
 
static bool udc_req_std_ep_clear_feature (void)
 Standard endpoint request to clear endpoint feature. More...
 
static bool udc_req_std_ep_get_status (void)
 Standard endpoint request to get endpoint status. More...
 
static bool udc_req_std_ep_set_feature (void)
 Standard endpoint request to halt an endpoint. More...
 
static bool udc_req_std_iface_get_setting (void)
 Standard interface request to get the alternate setting number of an interface. More...
 
static bool udc_req_std_iface_set_setting (void)
 Standard interface request to set an alternate setting of an interface. More...
 
static bool udc_reqstd (void)
 Main routine to manage the standard USB SETUP request. More...
 
void udc_reset (void)
 Reset the current configuration of the USB device, This routines can be called by UDD when a RESET on the USB line occurs. More...
 
void udc_sof_notify (void)
 To signal that a SOF is occurred. More...
 
void udc_start (void)
 Start the USB Device stack. More...
 
void udc_stop (void)
 Stop the USB Device stack. More...
 
static bool udc_update_iface_desc (uint8_t iface_num, uint8_t setting_num)
 Search an interface descriptor This routine updates the internal pointer udc_ptr_iface. More...
 
static void udc_valid_address (void)
 Change the address of device Callback called at the end of request set address. More...
 

Internal variables to manage the USB device

static le16_t udc_device_status
 Device status state (see enum usb_device_status in usb_protocol.h) More...
 
static COMPILER_WORD_ALIGNED
uint8_t 
udc_iface_setting = 0
 Device interface setting value. More...
 
static COMPILER_WORD_ALIGNED
uint8_t 
udc_num_configuration = 0
 Device Configuration number selected by the USB host. More...
 
static udc_config_speed_t
UDC_DESC_STORAGE
udc_ptr_conf
 Pointer on the selected speed device configuration. More...
 
static usb_iface_desc_t
UDC_DESC_STORAGE
udc_ptr_iface
 Pointer on interface descriptor used by SETUP request. More...
 

Internal structure to store the USB device main strings

static COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE
usb_str_lgid_desc_t 
udc_string_desc_languageid
 Language ID of USB device (US ID by default) More...
 
static uint8_t udc_string_manufacturer_name [] = USB_DEVICE_MANUFACTURE_NAME
 USB device manufacture name storage String is allocated only if USB_DEVICE_MANUFACTURE_NAME is declared by usb application configuration. More...
 
static uint8_t udc_string_product_name [] = USB_DEVICE_PRODUCT_NAME
 USB device product name storage String is allocated only if USB_DEVICE_PRODUCT_NAME is declared by usb application configuration. More...
 
static COMPILER_WORD_ALIGNED
UDC_DESC_STORAGE struct
udc_string_desc_t 
udc_string_desc
 
#define USB_DEVICE_MANUFACTURE_NAME_SIZE   (sizeof(udc_string_manufacturer_name)-1)
 
#define USB_DEVICE_PRODUCT_NAME_SIZE   (sizeof(udc_string_product_name)-1)
 
#define USB_DEVICE_SERIAL_NAME_SIZE   0
 Get USB device serial number. More...
 

#define USB_DEVICE_MANUFACTURE_NAME_SIZE   (sizeof(udc_string_manufacturer_name)-1)
#define USB_DEVICE_PRODUCT_NAME_SIZE   (sizeof(udc_string_product_name)-1)
#define USB_DEVICE_SERIAL_NAME_SIZE   0

Get USB device serial number.

Use the define USB_DEVICE_SERIAL_NAME to set static serial number.

For dynamic serial number set the define USB_DEVICE_GET_SERIAL_NAME_POINTER to a suitable pointer. This will also require the serial number length define USB_DEVICE_GET_SERIAL_NAME_LENGTH.

Referenced by udc_req_std_dev_get_str_desc().

static usb_conf_desc_t UDC_DESC_STORAGE* udc_get_eof_conf ( void  )
static

Returns a value to check the end of USB Configuration descriptor.

Returns
address after the last byte of USB Configuration descriptor

References udc_config_speed_t::desc, le16_to_cpu, UDC_DESC_STORAGE, udc_ptr_conf, and usb_conf_desc_t::wTotalLength.

Referenced by udc_next_desc_in_iface(), and udc_update_iface_desc().

usb_iface_desc_t UDC_DESC_STORAGE* udc_get_interface_desc ( void  )

Returns a pointer on the current interface descriptor.

Returns
pointer on the current interface descriptor.

References udc_ptr_iface.

static bool udc_iface_disable ( uint8_t  iface_num)
static

Disables an usb device interface (UDI) This routine call the UDI corresponding to interface number.

Parameters
iface_numInterface number to disable
Returns
1 if it is done or 0 if interface is not found

References UDC_DESC_STORAGE, udc_next_desc_in_iface(), udc_ptr_conf, udc_ptr_iface, udc_update_iface_desc(), udd_ep_free(), udc_config_speed_t::udi_apis, and USB_DT_ENDPOINT.

Referenced by udc_req_std_iface_set_setting(), and udc_reset().

static bool udc_iface_enable ( uint8_t  iface_num,
uint8_t  setting_num 
)
static

Enables an usb device interface (UDI) This routine calls the UDI corresponding to the interface and setting number.

Parameters
iface_numInterface number to enable
setting_numSetting number to enable
Returns
1 if it is done or 0 if interface is not found

References udi_api_t::enable, le16_to_cpu, UDC_DESC_STORAGE, udc_next_desc_in_iface(), udc_ptr_conf, udc_ptr_iface, udc_update_iface_desc(), udd_ep_alloc(), udc_config_speed_t::udi_apis, and USB_DT_ENDPOINT.

Referenced by udc_req_std_dev_set_configuration(), and udc_req_std_iface_set_setting().

static usb_conf_desc_t UDC_DESC_STORAGE* udc_next_desc_in_iface ( usb_conf_desc_t UDC_DESC_STORAGE desc,
uint8_t  desc_id 
)
static

Search specific descriptor in global interface descriptor.

Parameters
descAddress of interface descriptor or previous specific descriptor found
desc_idDescriptor ID to search
Returns
address of specific descriptor found
NULL if it is the end of global interface descriptor

References UDC_DESC_STORAGE, udc_get_eof_conf(), and USB_DT_INTERFACE.

Referenced by udc_iface_disable(), and udc_iface_enable().

bool udc_process_setup ( void  )

Main routine to manage the USB SETUP request.

Decodes and manages a setup request.

This function parses a USB SETUP request and submits an appropriate response back to the host or, in the case of SETUP OUT requests with data, sets up a buffer for receiving the data payload.

The main standard requests defined by the USB 2.0 standard are handled internally. The interface requests are sent to UDI, and the specific request sent to a specific application callback.

Returns
true if the request is supported, else the request is stalled by UDD

References udd_ctrl_request_t::callback, udd_ctrl_request_t::over_under_run, udd_ctrl_request_t::payload_size, udd_ctrl_request_t::req, udc_req_ep(), udc_req_iface(), udc_reqstd(), udd_g_ctrlreq, Udd_setup_is_in, Udd_setup_recipient, Udd_setup_type, USB_REQ_RECIP_ENDPOINT, USB_REQ_RECIP_INTERFACE, USB_REQ_TYPE_STANDARD, and usb_setup_req_t::wLength.

Referenced by _usb_ep0_on_setup().

static bool udc_req_ep ( void  )
static
static bool udc_req_iface ( void  )
static
static bool udc_req_std_dev_clear_feature ( void  )
static

Standard device request to change device status.

Returns
true if success

References CPU_TO_LE16, udd_ctrl_request_t::req, udc_device_status, udd_g_ctrlreq, USB_DEV_FEATURE_REMOTE_WAKEUP, USB_DEV_STATUS_REMOTEWAKEUP, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.

Referenced by udc_reqstd().

static bool udc_req_std_dev_get_configuration ( void  )
static

Standard device request to get configuration number.

Returns
true if success

References udd_ctrl_request_t::req, udc_num_configuration, udd_g_ctrlreq, udd_set_setup_payload(), and usb_setup_req_t::wLength.

Referenced by udc_reqstd().

static bool udc_req_std_dev_get_status ( void  )
static

Standard device request to get device status.

Returns
true if success

References udd_ctrl_request_t::req, udc_device_status, udd_g_ctrlreq, udd_set_setup_payload(), and usb_setup_req_t::wLength.

Referenced by udc_reqstd().

static bool udc_req_std_dev_set_address ( void  )
static

Standard device request to set device address.

Returns
true if success

References udd_ctrl_request_t::callback, udd_ctrl_request_t::req, udc_valid_address(), udd_g_ctrlreq, and usb_setup_req_t::wLength.

Referenced by udc_reqstd().

static bool udc_req_std_ep_clear_feature ( void  )
static

Standard endpoint request to clear endpoint feature.

Returns
true if success

References udd_ctrl_request_t::req, udd_ep_clear_halt(), udd_g_ctrlreq, USB_EP_FEATURE_HALT, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.

Referenced by udc_reqstd().

static bool udc_req_std_ep_get_status ( void  )
static

Standard endpoint request to get endpoint status.

Returns
true if success

References CPU_TO_LE16, udd_ctrl_request_t::req, udd_ep_is_halted(), udd_g_ctrlreq, udd_set_setup_payload(), USB_EP_STATUS_HALTED, and usb_setup_req_t::wLength.

Referenced by udc_reqstd().

static bool udc_req_std_ep_set_feature ( void  )
static

Standard endpoint request to halt an endpoint.

Returns
true if success

References udd_ctrl_request_t::req, udd_ep_abort(), udd_ep_set_halt(), udd_g_ctrlreq, USB_EP_FEATURE_HALT, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.

Referenced by udc_reqstd().

static bool udc_req_std_iface_get_setting ( void  )
static
static bool udc_req_std_iface_set_setting ( void  )
static

Standard interface request to set an alternate setting of an interface.

Returns
true if success

References udd_ctrl_request_t::req, udc_iface_disable(), udc_iface_enable(), udc_num_configuration, udd_g_ctrlreq, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.

Referenced by udc_reqstd().

void udc_reset ( void  )
void udc_sof_notify ( void  )

To signal that a SOF is occurred.

The UDC must send the signal to all UDIs enabled

References usb_conf_desc_t::bNumInterfaces, udc_config_speed_t::desc, udi_api_t::sof_notify, udc_num_configuration, udc_ptr_conf, and udc_config_speed_t::udi_apis.

Referenced by _usb_on_sof_notify().

void udc_start ( void  )

Start the USB Device stack.

References udd_enable().

Referenced by main(), usb_dual_enable(), and usb_id_handler().

void udc_stop ( void  )

Stop the USB Device stack.

References udc_reset(), and udd_disable().

Referenced by usb_id_handler().

static bool udc_update_iface_desc ( uint8_t  iface_num,
uint8_t  setting_num 
)
static

Search an interface descriptor This routine updates the internal pointer udc_ptr_iface.

Parameters
iface_numInterface number to find in Configuration Descriptor
setting_numSetting number of interface to find
Returns
1 if found or 0 if not found

References usb_iface_desc_t::bAlternateSetting, usb_iface_desc_t::bDescriptorType, usb_iface_desc_t::bInterfaceNumber, usb_iface_desc_t::bLength, usb_conf_desc_t::bNumInterfaces, udc_config_speed_t::desc, UDC_DESC_STORAGE, udc_get_eof_conf(), udc_num_configuration, udc_ptr_conf, udc_ptr_iface, and USB_DT_INTERFACE.

Referenced by udc_iface_disable(), udc_iface_enable(), udc_req_ep(), udc_req_iface(), and udc_req_std_iface_get_setting().

static void udc_valid_address ( void  )
static

Change the address of device Callback called at the end of request set address.

References udd_ctrl_request_t::req, udd_g_ctrlreq, udd_set_address(), and usb_setup_req_t::wValue.

Referenced by udc_req_std_dev_set_address().

le16_t udc_device_status
static

Device status state (see enum usb_device_status in usb_protocol.h)

Referenced by udc_req_std_dev_clear_feature(), udc_req_std_dev_get_status(), udc_req_std_dev_set_feature(), and udc_reset().

COMPILER_WORD_ALIGNED uint8_t udc_iface_setting = 0
static

Device interface setting value.

Referenced by udc_req_std_iface_get_setting().

usb_iface_desc_t UDC_DESC_STORAGE* udc_ptr_iface
static

Pointer on interface descriptor used by SETUP request.

Referenced by udc_get_interface_desc(), udc_iface_disable(), udc_iface_enable(), and udc_update_iface_desc().

Initial value:
= {
.header.bDescriptorType = USB_DT_STRING
}
Definition: usb_protocol.h:192
COMPILER_WORD_ALIGNED UDC_DESC_STORAGE usb_str_lgid_desc_t udc_string_desc_languageid
static
Initial value:
= {
.desc.bLength = sizeof(usb_str_lgid_desc_t),
.desc.bDescriptorType = USB_DT_STRING,
.string = {LE16(USB_LANGID_EN_US)}
}
English (United States)
Definition: usb_protocol.h:260
Definition: usb_protocol.h:192
Definition: usb_protocol.h:479
#define LE16(x)
Definition: compiler.h:773

Language ID of USB device (US ID by default)

Referenced by udc_req_std_dev_get_str_desc().

uint8_t udc_string_manufacturer_name[] = USB_DEVICE_MANUFACTURE_NAME
static

USB device manufacture name storage String is allocated only if USB_DEVICE_MANUFACTURE_NAME is declared by usb application configuration.

Referenced by udc_req_std_dev_get_str_desc().

uint8_t udc_string_product_name[] = USB_DEVICE_PRODUCT_NAME
static

USB device product name storage String is allocated only if USB_DEVICE_PRODUCT_NAME is declared by usb application configuration.

Referenced by udc_req_std_dev_get_str_desc().