xiaoxiang781216 commented on code in PR #20967:
URL: https://github.com/apache/nuttx/pull/20967#discussion_r4367844625
##########
drivers/usbhost/usbhost_hidmouse.c:
##########
@@ -1586,17 +1735,41 @@ static inline int usbhost_devinit(FAR struct
usbhost_state_s *priv)
return ret;
}
+ /* Some devices ignore SET_PROTOCOL(boot) and keep sending report
+ * protocol reports, which start with a report ID. Read the report
+ * descriptor to find the report ID of the mouse (the transfer buffer is
+ * not in use yet, so it holds the request and the descriptor).
+ */
+
+ ctrlreq = (FAR struct usb_ctrlreq_s *)priv->tbuffer;
+ ctrlreq->type = USB_REQ_DIR_IN | USB_REQ_RECIPIENT_INTERFACE;
+ ctrlreq->req = USB_REQ_GETDESCRIPTOR;
+ ctrlreq->value[0] = 0;
+ ctrlreq->value[1] = USBHID_DESCTYPE_REPORT;
+ ctrlreq->index[0] = priv->ifno;
+ ctrlreq->index[1] = 0;
+ ctrlreq->len[0] = priv->tbuflen - USB_SIZEOF_CTRLREQ;
+ ctrlreq->len[1] = 0;
+
+ ret = DRVR_CTRLIN(priv->usbclass.hport->drvr, priv->usbclass.hport->ep0,
+ ctrlreq, priv->tbuffer + USB_SIZEOF_CTRLREQ);
+ if (ret >= 0)
+ {
+ usbhost_reportdesc(priv, priv->tbuffer + USB_SIZEOF_CTRLREQ,
+ priv->tbuflen - USB_SIZEOF_CTRLREQ);
+ }
+
/* The reports are decoded using the fixed boot protocol format, but a HID
* device starts in report protocol after configuration. Select the boot
- * protocol (the transfer buffer is not in use yet, so it holds the
- * request).
+ * protocol, or the report protocol if the mouse report has a report ID
+ * and the boot protocol layout.
*/
ctrlreq = (FAR struct usb_ctrlreq_s *)priv->tbuffer;
ctrlreq->type = USB_REQ_DIR_OUT | USB_REQ_TYPE_CLASS |
USB_REQ_RECIPIENT_INTERFACE;
ctrlreq->req = USBHID_REQUEST_SETPROTOCOL;
- ctrlreq->value[0] = 0; /* 0 = Boot protocol */
+ ctrlreq->value[0] = priv->reportid != 0 ? 1 : 0; /* 1 = Report */
Review Comment:
```suggestion
ctrlreq->value[0] = priv->reportid != 0 ; /* 1 = Report */
```
##########
drivers/usbhost/usbhost_hidkbd.c:
##########
@@ -1354,22 +1357,50 @@ static int usbhost_kbdpoll(int argc, FAR char *argv[])
#ifdef CONFIG_HIDKBD_NOGETREPORT
nxmutex_unlock(&priv->lock);
#else
- /* Send HID report request */
+ if (!priv->intin)
+ {
+ /* Send HID report request */
+
+ ret = usbhost_send_request(priv, USB_REQ_DIR_IN,
+ USBHID_REQUEST_GETREPORT,
+ USBHID_REPORTTYPE_INPUT << 8,
+ priv->ifno,
+ sizeof(struct usbhid_kbdreport_s),
+ priv->tbuffer);
+
+ /* Some devices (e.g. wireless receivers) stall GET_REPORT. Then
+ * read the reports from the interrupt IN endpoint instead.
+ */
- ret = usbhost_send_request(priv, USB_REQ_DIR_IN,
- USBHID_REQUEST_GETREPORT,
- USBHID_REPORTTYPE_INPUT << 8,
- priv->ifno,
- sizeof(struct usbhid_kbdreport_s),
- priv->tbuffer);
+ if (ret == -EPERM && priv->epin != NULL)
+ {
+ uwarn("WARNING: GET_REPORT stalled, using interrupt IN EP\n");
+ priv->intin = true;
+ }
+ }
nxmutex_unlock(&priv->lock);
+ if (priv->intin)
+ {
+ /* Wait for the next report. -EAGAIN means no new report. */
+
+ ssize_t nbytes = DRVR_TRANSFER(priv->usbclass.hport->drvr,
+ priv->epin, priv->tbuffer,
+ priv->tbuflen);
+
+ ret = nbytes < 0 ? (int)nbytes : OK;
Review Comment:
```suggestion
ret = nbytes < 0 ? nbytes : OK;
```
--
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]