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_STORAGE * | udc_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) |
Referenced by udc_req_std_dev_get_str_desc().
#define USB_DEVICE_PRODUCT_NAME_SIZE (sizeof(udc_string_product_name)-1) |
Referenced by udc_req_std_dev_get_str_desc().
#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 |
Returns a value to check the end 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.
References udc_ptr_iface.
Referenced by udi_hid_reqstdifaceget_descriptor().
|
static |
Disables an usb device interface (UDI) This routine call the UDI corresponding to interface number.
iface_num | Interface number to disable |
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 |
Enables an usb device interface (UDI) This routine calls the UDI corresponding to the interface and setting number.
iface_num | Interface number to enable |
setting_num | Setting number to enable |
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 |
Search specific descriptor in global interface descriptor.
desc | Address of interface descriptor or previous specific descriptor found |
desc_id | Descriptor ID to search |
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.
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 udd_ctrl_setup_received().
|
static |
Send the SETUP interface request to UDI.
References usb_conf_desc_t::bNumInterfaces, udc_config_speed_t::desc, udd_ctrl_request_t::req, UDC_DESC_STORAGE, udc_num_configuration, udc_ptr_conf, udc_update_iface_desc(), udd_g_ctrlreq, udc_config_speed_t::udi_apis, and usb_setup_req_t::wIndex.
Referenced by udc_process_setup().
|
static |
Send the SETUP interface request to UDI.
References usb_conf_desc_t::bNumInterfaces, udc_config_speed_t::desc, udd_ctrl_request_t::req, udi_api_t::setup, UDC_DESC_STORAGE, udc_num_configuration, udc_ptr_conf, udc_update_iface_desc(), udd_g_ctrlreq, udc_config_speed_t::udi_apis, and usb_setup_req_t::wIndex.
Referenced by udc_process_setup().
|
static |
Standard device request to change device status.
References CPU_TO_LE16, udd_ctrl_request_t::req, udc_device_status, UDC_REMOTEWAKEUP_DISABLE, 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 |
Standard device request to get configuration number.
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 |
Standard device request to get descriptors about USB device.
References usb_dev_desc_t::bLength, udc_config_t::conf_bos, udc_config_t::conf_lsfs, udc_config_t::confdev_lsfs, udc_config_speed_t::desc, le16_to_cpu, udd_ctrl_request_t::payload, udd_ctrl_request_t::payload_size, udd_ctrl_request_t::req, udc_config, udc_req_std_dev_get_str_desc(), udd_g_ctrlreq, udd_is_high_speed(), udd_set_setup_payload(), USB_DT_BOS, USB_DT_CONFIGURATION, USB_DT_DEVICE, USB_DT_DEVICE_QUALIFIER, USB_DT_OTHER_SPEED_CONFIGURATION, USB_DT_STRING, usb_setup_req_t::wLength, usb_dev_bos_desc_t::wTotalLength, usb_conf_desc_t::wTotalLength, and usb_setup_req_t::wValue.
Referenced by udc_reqstd().
|
static |
Standard device request to get device status.
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 |
Standard device request to get device string descriptor.
References usb_str_desc_t::bLength, cpu_to_le16, udc_string_desc_t::header, udd_ctrl_request_t::req, udc_string_desc_t::string, udc_string_desc_languageid, udc_string_manufacturer_name, udc_string_product_name, udd_g_ctrlreq, udd_set_setup_payload(), USB_DEVICE_MANUFACTURE_NAME_SIZE, USB_DEVICE_PRODUCT_NAME_SIZE, USB_DEVICE_SERIAL_NAME_SIZE, and usb_setup_req_t::wValue.
Referenced by udc_req_std_dev_get_descriptor().
|
static |
Standard device request to set device address.
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 |
Standard device request to enable a configuration.
References usb_dev_desc_t::bNumConfigurations, usb_conf_desc_t::bNumInterfaces, udc_config_t::conf_lsfs, udc_config_t::confdev_lsfs, udc_config_speed_t::desc, udd_ctrl_request_t::req, udc_config, udc_iface_enable(), udc_num_configuration, udc_ptr_conf, udc_reset(), udd_g_ctrlreq, udd_getaddress(), udd_is_high_speed(), usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
Referenced by udc_reqstd().
|
static |
Standard device request to set a feature.
References udd_ctrl_request_t::callback, CPU_TO_LE16, udd_ctrl_request_t::req, udc_device_status, UDC_REMOTEWAKEUP_ENABLE, udc_reset(), udd_g_ctrlreq, udd_is_high_speed(), udd_test_mode_j(), udd_test_mode_k(), udd_test_mode_packet(), udd_test_mode_se0_nak(), USB_DEV_FEATURE_REMOTE_WAKEUP, USB_DEV_FEATURE_TEST_MODE, USB_DEV_STATUS_REMOTEWAKEUP, USB_DEV_TEST_MODE_FORCE_ENABLE, USB_DEV_TEST_MODE_J, USB_DEV_TEST_MODE_K, USB_DEV_TEST_MODE_PACKET, USB_DEV_TEST_MODE_SE0_NAK, usb_setup_req_t::wIndex, usb_setup_req_t::wLength, and usb_setup_req_t::wValue.
Referenced by udc_reqstd().
|
static |
Standard endpoint request to clear endpoint feature.
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 |
Standard endpoint request to get endpoint status.
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 |
Standard endpoint request to halt an endpoint.
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 |
Standard interface request to get the alternate setting number of an interface.
References usb_conf_desc_t::bNumInterfaces, udc_config_speed_t::desc, udd_ctrl_request_t::req, UDC_DESC_STORAGE, udc_iface_setting, udc_num_configuration, udc_ptr_conf, udc_update_iface_desc(), udd_g_ctrlreq, udd_set_setup_payload(), udc_config_speed_t::udi_apis, usb_setup_req_t::wIndex, and usb_setup_req_t::wLength.
Referenced by udc_reqstd().
|
static |
Standard interface request to set an alternate setting of an interface.
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().
|
static |
Main routine to manage the standard USB SETUP request.
References usb_setup_req_t::bRequest, udd_ctrl_request_t::req, udc_req_std_dev_clear_feature(), udc_req_std_dev_get_configuration(), udc_req_std_dev_get_descriptor(), udc_req_std_dev_get_status(), udc_req_std_dev_set_address(), udc_req_std_dev_set_configuration(), udc_req_std_dev_set_feature(), udc_req_std_ep_clear_feature(), udc_req_std_ep_get_status(), udc_req_std_ep_set_feature(), udc_req_std_iface_get_setting(), udc_req_std_iface_set_setting(), udd_g_ctrlreq, Udd_setup_is_in, Udd_setup_recipient, USB_REQ_CLEAR_FEATURE, USB_REQ_GET_CONFIGURATION, USB_REQ_GET_DESCRIPTOR, USB_REQ_GET_INTERFACE, USB_REQ_GET_STATUS, USB_REQ_RECIP_DEVICE, USB_REQ_RECIP_ENDPOINT, USB_REQ_RECIP_INTERFACE, USB_REQ_SET_ADDRESS, USB_REQ_SET_CONFIGURATION, USB_REQ_SET_DESCRIPTOR, USB_REQ_SET_FEATURE, USB_REQ_SET_INTERFACE, and usb_setup_req_t::wLength.
Referenced by udc_process_setup().
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.
Reset the UDC.
References usb_conf_desc_t::bNumInterfaces, CPU_TO_LE16, udc_config_speed_t::desc, udc_device_status, udc_iface_disable(), udc_num_configuration, udc_ptr_conf, UDC_REMOTEWAKEUP_DISABLE, USB_DEV_STATUS_BUS_POWERED, USB_DEV_STATUS_REMOTEWAKEUP, and USB_DEV_STATUS_SELF_POWERED.
Referenced by udc_req_std_dev_set_configuration(), udc_req_std_dev_set_feature(), and udc_stop().
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.
void udc_start | ( | void | ) |
Start the USB Device stack.
References udd_enable().
Referenced by otg_dual_enable(), and otg_id_handler().
void udc_stop | ( | void | ) |
Stop the USB Device stack.
References udc_reset(), and udd_disable().
Referenced by otg_id_handler().
|
static |
Search an interface descriptor This routine updates the internal pointer udc_ptr_iface.
iface_num | Interface number to find in Configuration Descriptor |
setting_num | Setting number of interface to find |
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 |
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().
|
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().
|
static |
Device interface setting value.
Referenced by udc_req_std_iface_get_setting().
|
static |
Device Configuration number selected by the USB host.
Referenced by udc_req_ep(), udc_req_iface(), udc_req_std_dev_get_configuration(), udc_req_std_dev_set_configuration(), udc_req_std_iface_get_setting(), udc_req_std_iface_set_setting(), udc_reset(), udc_sof_notify(), and udc_update_iface_desc().
|
static |
Pointer on the selected speed device configuration.
Referenced by udc_get_eof_conf(), udc_iface_disable(), udc_iface_enable(), udc_req_ep(), udc_req_iface(), udc_req_std_dev_set_configuration(), udc_req_std_iface_get_setting(), udc_reset(), udc_sof_notify(), and udc_update_iface_desc().
|
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().
|
static |
|
static |
Language ID of USB device (US ID by default)
Referenced by udc_req_std_dev_get_str_desc().
|
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().
|
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().