summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2023-11-11 13:53:16 +0800
committersakumisu <[email protected]>2023-11-11 14:00:29 +0800
commit2080cf1206569a3b2407f793a1920970ea281660 (patch)
tree882f291e402da02f7fa55b6ea40aa22db718fa63
parentae521bf95cd3949e9b7d7e83a1f4051c9c21a7c1 (diff)
add usbh_set_interface api
-rw-r--r--core/usbh_core.c32
-rw-r--r--core/usbh_core.h40
2 files changed, 51 insertions, 21 deletions
diff --git a/core/usbh_core.c b/core/usbh_core.c
index 310e7b3e..abebbd1e 100644
--- a/core/usbh_core.c
+++ b/core/usbh_core.c
@@ -426,6 +426,19 @@ int usbh_get_string_desc(struct usbh_hubport *hport, uint8_t index, uint8_t *out
return 0;
}
+int usbh_set_interface(struct usbh_hubport *hport, uint8_t intf, uint8_t altsetting)
+{
+ struct usb_setup_packet *setup = hport->setup;
+
+ setup->bmRequestType = USB_REQUEST_DIR_OUT | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_INTERFACE;
+ setup->bRequest = USB_REQUEST_SET_INTERFACE;
+ setup->wValue = intf;
+ setup->wIndex = altsetting;
+ setup->wLength = 0;
+
+ return usbh_control_transfer(hport->ep0, setup, NULL);
+}
+
int usbh_enumerate(struct usbh_hubport *hport)
{
struct usb_interface_descriptor *intf_desc;
@@ -644,25 +657,6 @@ errout:
return ret;
}
-struct usbh_hubport *usbh_find_hubport(uint8_t dev_addr)
-{
- struct usbh_hubport *hport;
- usb_slist_t *hub_list;
- usb_slist_for_each(hub_list, &hub_class_head)
- {
- struct usbh_hub *hub = usb_slist_entry(hub_list, struct usbh_hub, list);
- for (uint8_t port = 0; port < hub->hub_desc.bNbrPorts; port++) {
- hport = &hub->child[port];
- if (hport->connected) {
- if (hport->dev_addr == dev_addr) {
- return &hub->child[port];
- }
- }
- }
- }
- return NULL;
-}
-
void *usbh_find_class_instance(const char *devname)
{
struct usbh_hubport *hport;
diff --git a/core/usbh_core.h b/core/usbh_core.h
index 53d464b2..d5a7c6ea 100644
--- a/core/usbh_core.h
+++ b/core/usbh_core.h
@@ -169,8 +169,17 @@ struct usbh_hub {
struct usbh_hubport *parent;
};
+/**
+ * @brief Activates an endpoint for a USB host pipe on a specific hub port.
+ *
+ * This function is responsible for activating the specified endpoint
+ * described by the given endpoint descriptor on the USB host pipe.
+ * @param pipe Pointer to the USB host pipe structure.
+ * @param hport Pointer to the USB hub port structure.
+ * @param ep_desc Pointer to the USB endpoint descriptor.
+ * @return On success will return 0, and others indicate fail.
+ */
int usbh_hport_activate_epx(usbh_pipe_t *pipe, struct usbh_hubport *hport, struct usb_endpoint_descriptor *ep_desc);
-int usbh_get_string_desc(struct usbh_hubport *hport, uint8_t index, uint8_t *output);
/**
* @brief Submit an control transfer to an endpoint.
@@ -184,8 +193,35 @@ int usbh_get_string_desc(struct usbh_hubport *hport, uint8_t index, uint8_t *out
*/
int usbh_control_transfer(usbh_pipe_t pipe, struct usb_setup_packet *setup, uint8_t *buffer);
+/**
+ * @brief Retrieves a USB string descriptor from a specific hub port.
+ *
+ * This function is responsible for retrieving the USB string descriptor
+ * with the specified index from the USB device connected to the given hub port.
+ * The retrieved descriptor is stored in the output buffer provided.
+ *
+ * @param hport Pointer to the USB hub port structure.
+ * @param index Index of the string descriptor to retrieve.
+ * @param output Pointer to the buffer where the retrieved descriptor will be stored.
+ * @return On success will return 0, and others indicate fail.
+ */
+int usbh_get_string_desc(struct usbh_hubport *hport, uint8_t index, uint8_t *output);
+
+/**
+ * @brief Sets the alternate setting for a USB interface on a specific hub port.
+ *
+ * This function is responsible for setting the alternate setting of the
+ * specified USB interface on the USB device connected to the given hub port.
+ * The interface and alternate setting are identified by the respective parameters.
+ *
+ * @param hport Pointer to the USB hub port structure.
+ * @param intf Interface number to set the alternate setting for.
+ * @param altsetting Alternate setting value to set for the interface.
+ * @return On success will return 0, and others indicate fail.
+ */
+int usbh_set_interface(struct usbh_hubport *hport, uint8_t intf, uint8_t altsetting);
+
int usbh_initialize(void);
-struct usbh_hubport *usbh_find_hubport(uint8_t dev_addr);
void *usbh_find_class_instance(const char *devname);
int lsusb(int argc, char **argv);