xiaoxiang781216 commented on code in PR #19751:
URL: https://github.com/apache/nuttx/pull/19751#discussion_r3740551747


##########
drivers/usbhost/usbhost_enumerate.c:
##########
@@ -302,6 +556,21 @@ int usbhost_enumerate(FAR struct usbhost_hubport_s *hport,
   uint8_t cfgidx = 0;
   FAR uint8_t *buffer = NULL;
   int ret;
+#ifdef CONFIG_USBHOST_ANNOUNCE
+  bool bound = false;
+#endif
+#ifdef CONFIG_USBHOST_ANNOUNCE
+  struct
+  {
+    uint16_t bcd;
+    uint8_t  imfgr;
+    uint8_t  iprod;
+    uint8_t  iserno;
+  } strdesc =

Review Comment:
   why not remove the struct and change fields to variable directly



##########
drivers/usbhost/usbhost_enumerate.c:
##########
@@ -302,6 +556,21 @@ int usbhost_enumerate(FAR struct usbhost_hubport_s *hport,
   uint8_t cfgidx = 0;
   FAR uint8_t *buffer = NULL;
   int ret;
+#ifdef CONFIG_USBHOST_ANNOUNCE
+  bool bound = false;
+#endif
+#ifdef CONFIG_USBHOST_ANNOUNCE

Review Comment:
   remove `#endif/#ifdef`



##########
drivers/usbhost/usbhost_enumerate.c:
##########
@@ -208,6 +212,256 @@ static inline int usbhost_configdesc(const uint8_t 
*configdesc, int cfglen,
  *
  ****************************************************************************/
 
+#ifdef CONFIG_USBHOST_ANNOUNCE
+/****************************************************************************
+ * Name: usbhost_portpath
+ *
+ * Description:
+ *   The path to a device, as bus number and the port at each tier below it.
+ *
+ ****************************************************************************/
+
+static void usbhost_portpath(FAR struct usbhost_hubport_s *hport,
+                             FAR char *path, size_t pathlen)
+{
+  FAR struct usbhost_hubport_s *root = hport;
+  uint8_t ports[8];
+  size_t  used = 0;
+  int     n    = 0;
+  int     i;
+
+  /* Port numbers repeat at every tier, so the path needs all of them.
+   * Walking up collects them backwards.
+   */
+
+  while (n < (int)(sizeof(ports)) && hport != NULL)
+    {
+      ports[n++] = hport->port + 1;
+      root       = hport;
+
+#ifdef CONFIG_USBHOST_HUB
+      hport = hport->parent;
+#else
+      break;
+#endif
+    }
+
+  /* The bus first, as the port numbers below it repeat on every other one */
+
+  used = snprintf(path, pathlen, "%d-",
+                  ((FAR struct usbhost_roothubport_s *)root)->bus);
+
+  for (i = n - 1; i >= 0 && used < pathlen - 1; i--)
+    {
+      used += snprintf(path + used, pathlen - used, "%s%d",
+                       i == n - 1 ? "" : ".", ports[i]);
+    }
+}
+
+/****************************************************************************
+ * Name: usbhost_classname
+ *
+ * Description:
+ *   A readable name for a USB class code.  Classes a host is unlikely to
+ *   meet are left to be reported by number.
+ *
+ ****************************************************************************/
+
+static FAR const char *usbhost_classname(FAR const struct usbhost_id_s *id)
+{
+  switch (id->base)
+    {
+      case USB_CLASS_PER_INTERFACE:
+        return "composite";
+      case USB_CLASS_AUDIO:
+        return "audio";
+      case USB_CLASS_CDC:
+        return "CDC";
+      case USB_CLASS_HID:
+        /* The boot protocol names the device before its report
+         * descriptor has been read.
+         */
+
+        if (id->subclass == USBHID_SUBCLASS_BOOTIF)
+          {
+            if (id->proto == USBHID_PROTOCOL_KEYBOARD)
+              {
+                return "keyboard";
+              }
+            else if (id->proto == USBHID_PROTOCOL_MOUSE)
+              {
+                return "mouse";
+              }
+          }
+
+        return "HID";
+      case USB_CLASS_PRINTER:
+        return "printer";
+      case USB_CLASS_MASS_STORAGE:
+        return "mass storage";
+      case USB_CLASS_HUB:
+        return "hub";
+      case USB_CLASS_CDC_DATA:
+        return "CDC data";
+      case USB_CLASS_WIRELESS_CONTROLLER:
+        return "wireless";
+      case USB_CLASS_MISC:
+        return "misc";
+      case USB_CLASS_VENDOR_SPEC:
+        return "vendor specific";
+      default:
+        return NULL;
+    }
+}
+
+/****************************************************************************
+ * Name: usbhost_getstring
+ *
+ * Description:
+ *   Fetch one string descriptor and render it as plain text.
+ *
+ *   String descriptors are UTF-16.  Anything outside ASCII is replaced
+ *   rather than dropped, so the rendered length matches the descriptor.
+ *   Index zero means the device has no such string.
+ *
+ ****************************************************************************/
+
+static int usbhost_getstring(FAR struct usbhost_hubport_s *hport,
+                             FAR struct usb_ctrlreq_s *ctrlreq,
+                             FAR uint8_t *buffer, uint8_t index,
+                             uint16_t langid, FAR char *out, size_t outlen)
+{
+  int ret;
+  int len;
+  int i;
+
+  out[0] = '\0';
+
+  if (index == 0)
+    {
+      return -ENOENT;
+    }
+
+  ctrlreq->type = USB_REQ_DIR_IN | USB_REQ_RECIPIENT_DEVICE;
+  ctrlreq->req  = USB_REQ_GETDESCRIPTOR;
+  usbhost_putle16(ctrlreq->value, (USB_DESC_TYPE_STRING << 8) | index);
+  usbhost_putle16(ctrlreq->index, langid);
+  usbhost_putle16(ctrlreq->len, 255);
+
+  ret = DRVR_CTRLIN(hport->drvr, hport->ep0, ctrlreq, buffer);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* buffer[0] is the whole descriptor including its own two byte header */
+
+  len = (buffer[0] - 2) / 2;
+  if (len < 0)
+    {
+      return -EIO;
+    }
+
+  if (len > (int)outlen - 1)

Review Comment:
   remove the cast



##########
drivers/usbhost/usbhost_enumerate.c:
##########
@@ -208,6 +212,256 @@ static inline int usbhost_configdesc(const uint8_t 
*configdesc, int cfglen,
  *
  ****************************************************************************/
 
+#ifdef CONFIG_USBHOST_ANNOUNCE
+/****************************************************************************
+ * Name: usbhost_portpath
+ *
+ * Description:
+ *   The path to a device, as bus number and the port at each tier below it.
+ *
+ ****************************************************************************/
+
+static void usbhost_portpath(FAR struct usbhost_hubport_s *hport,
+                             FAR char *path, size_t pathlen)
+{
+  FAR struct usbhost_hubport_s *root = hport;
+  uint8_t ports[8];
+  size_t  used = 0;
+  int     n    = 0;
+  int     i;
+
+  /* Port numbers repeat at every tier, so the path needs all of them.
+   * Walking up collects them backwards.
+   */
+
+  while (n < (int)(sizeof(ports)) && hport != NULL)

Review Comment:
   change n to size_t and remove the cast



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to