Scan descriptor rather than elying on hardcoded endpoint number
This commit is contained in:
parent
a17e3c978b
commit
9ba74de61a
2 changed files with 33 additions and 2 deletions
|
@ -181,6 +181,20 @@ struct grub_usb_device
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum grub_usb_ep_type
|
||||||
|
{
|
||||||
|
GRUB_USB_EP_CONTROL,
|
||||||
|
GRUB_USB_EP_ISOCHRONOUS,
|
||||||
|
GRUB_USB_EP_BULK,
|
||||||
|
GRUB_USB_EP_INTERRUPT
|
||||||
|
} grub_usb_ep_type_t;
|
||||||
|
|
||||||
|
static inline enum grub_usb_ep_type
|
||||||
|
grub_usb_get_ep_type (struct grub_usb_desc_endp *ep)
|
||||||
|
{
|
||||||
|
return ep->attrib & 3;
|
||||||
|
}
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
GRUB_USB_CLASS_NOTHERE,
|
GRUB_USB_CLASS_NOTHERE,
|
||||||
|
|
|
@ -83,6 +83,7 @@ struct grub_usb_keyboard_data
|
||||||
grub_usb_device_t usbdev;
|
grub_usb_device_t usbdev;
|
||||||
grub_uint8_t status;
|
grub_uint8_t status;
|
||||||
int key;
|
int key;
|
||||||
|
struct grub_usb_desc_endp *endp;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct grub_term_input grub_usb_keyboards[16];
|
static struct grub_term_input grub_usb_keyboards[16];
|
||||||
|
@ -109,6 +110,8 @@ grub_usb_keyboard_attach (grub_usb_device_t usbdev, int configno, int interfno)
|
||||||
{
|
{
|
||||||
unsigned curnum;
|
unsigned curnum;
|
||||||
struct grub_usb_keyboard_data *data;
|
struct grub_usb_keyboard_data *data;
|
||||||
|
struct grub_usb_desc_endp *endp = NULL;
|
||||||
|
int j;
|
||||||
|
|
||||||
grub_dprintf ("usb_keyboard", "%x %x %x %d %d\n",
|
grub_dprintf ("usb_keyboard", "%x %x %x %d %d\n",
|
||||||
usbdev->descdev.class, usbdev->descdev.subclass,
|
usbdev->descdev.class, usbdev->descdev.subclass,
|
||||||
|
@ -131,6 +134,18 @@ grub_usb_keyboard_attach (grub_usb_device_t usbdev, int configno, int interfno)
|
||||||
!= USB_HID_KBD_PROTOCOL)
|
!= USB_HID_KBD_PROTOCOL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
for (j = 0; j < usbdev->config[configno].interf[interfno].descif->endpointcnt;
|
||||||
|
j++)
|
||||||
|
{
|
||||||
|
endp = &usbdev->config[configno].interf[interfno].descendp[j];
|
||||||
|
|
||||||
|
if ((endp->endp_addr & 128) && grub_usb_get_ep_type(endp)
|
||||||
|
== GRUB_USB_EP_INTERRUPT)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (j == usbdev->config[configno].interf[interfno].descif->endpointcnt)
|
||||||
|
return 0;
|
||||||
|
|
||||||
grub_printf ("HID found!\n");
|
grub_printf ("HID found!\n");
|
||||||
|
|
||||||
data = grub_malloc (sizeof (*data));
|
data = grub_malloc (sizeof (*data));
|
||||||
|
@ -141,6 +156,7 @@ grub_usb_keyboard_attach (grub_usb_device_t usbdev, int configno, int interfno)
|
||||||
}
|
}
|
||||||
|
|
||||||
data->usbdev = usbdev;
|
data->usbdev = usbdev;
|
||||||
|
data->endp = endp;
|
||||||
|
|
||||||
/* Place the device in boot mode. */
|
/* Place the device in boot mode. */
|
||||||
grub_usb_control_msg (usbdev, GRUB_USB_REQTYPE_CLASS_INTERFACE_OUT,
|
grub_usb_control_msg (usbdev, GRUB_USB_REQTYPE_CLASS_INTERFACE_OUT,
|
||||||
|
@ -201,8 +217,9 @@ grub_usb_keyboard_checkkey (struct grub_term_input *term)
|
||||||
|
|
||||||
data[2] = 0;
|
data[2] = 0;
|
||||||
/* Poll interrupt pipe. */
|
/* Poll interrupt pipe. */
|
||||||
err = grub_usb_bulk_read_extended (termdata->usbdev, 1, sizeof (data),
|
err = grub_usb_bulk_read_extended (termdata->usbdev,
|
||||||
(char *) data, 1, &actual);
|
termdata->endp->endp_addr, sizeof (data),
|
||||||
|
(char *) data, 10, &actual);
|
||||||
|
|
||||||
if (err)
|
if (err)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in a new issue