Better support for multi-interface HID: Logitech unifying receivers

- Select mouse interface first
 - Correctly specify active interface when retrieving HID descriptors
USG_1.0
Robert Fisk 7 years ago
parent c55b525c41
commit d7f66cd393

@ -53,7 +53,7 @@
#define USBH_MAX_NUM_ENDPOINTS 2
/*---------- -----------*/
#define USBH_MAX_NUM_INTERFACES 2
#define USBH_MAX_NUM_INTERFACES 3
/*---------- -----------*/
#define USBH_MAX_NUM_CONFIGURATION 1

@ -141,44 +141,30 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost)
{
uint8_t max_ep;
uint8_t num = 0;
uint8_t interface;
uint8_t interface = 0xFF;
USBH_StatusTypeDef status = USBH_FAIL ;
HID_HandleTypeDef *HID_Handle;
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, 0xFF);
#ifdef CONFIG_MOUSE_ENABLED
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, HID_MOUSE_BOOT_CODE); //Search for mouse interfaces first
#endif
#ifdef CONFIG_KEYBOARD_ENABLED
if (interface == 0xFF)
{
interface = USBH_FindInterface(phost, phost->pActiveClass->ClassCode, HID_BOOT_CODE, HID_KEYBRD_BOOT_CODE);
}
#endif
if(interface == 0xFF) /* No Valid Interface */
{
status = USBH_FAIL;
USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name);
return USBH_FAIL;
}
else
{
USBH_SelectInterface (phost, interface);
phost->pActiveClass->pData = (HID_HandleTypeDef *)USBH_malloc (sizeof(HID_HandleTypeDef));
HID_Handle = (HID_HandleTypeDef *) phost->pActiveClass->pData;
HID_Handle->state = HID_ERROR;
/*Decode Bootclass Protocol: Mouse or Keyboard*/
#ifdef CONFIG_KEYBOARD_ENABLED
if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_KEYBRD_BOOT_CODE)
{
USBH_UsrLog ("KeyBoard device found!");
}
else
#endif
#ifdef CONFIG_MOUSE_ENABLED
if(phost->device.CfgDesc.Itf_Desc[phost->device.current_interface].bInterfaceProtocol == HID_MOUSE_BOOT_CODE)
{
USBH_UsrLog ("Mouse device found!");
}
else
#endif
{
USBH_UsrLog ("Protocol not supported.");
return USBH_FAIL;
}
HID_Handle->state = HID_INIT;
HID_Handle->ctl_state = HID_REQ_INIT;
@ -245,9 +231,7 @@ static USBH_StatusTypeDef USBH_HID_InterfaceInit (USBH_HandleTypeDef *phost)
}
}
status = USBH_OK;
}
return status;
return USBH_OK;
}
/**
@ -488,7 +472,8 @@ USBH_StatusTypeDef USBH_HID_GetHIDReportDescriptor (USBH_HandleTypeDef *phost,
status = USBH_GetDescriptor(phost,
USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD,
USB_DESC_HID_REPORT,
USB_DESC_HID_REPORT,
phost->device.current_interface,
phost->device.Data,
length);
@ -524,6 +509,7 @@ USBH_StatusTypeDef USBH_HID_GetHIDDescriptor (USBH_HandleTypeDef *phost,
status = USBH_GetDescriptor( phost,
USB_REQ_RECIPIENT_INTERFACE | USB_REQ_TYPE_STANDARD,
USB_DESC_HID,
phost->device.current_interface,
phost->device.Data,
length);

@ -102,7 +102,8 @@ USBH_StatusTypeDef USBH_CtlReq (USBH_HandleTypeDef *phost,
USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost,
uint8_t req_type,
uint16_t value_idx,
uint16_t type_idx,
uint16_t value,
uint8_t* buff,
uint16_t length );

@ -123,7 +123,8 @@ USBH_StatusTypeDef USBH_Get_DevDesc(USBH_HandleTypeDef *phost, uint16_t length)
if((status = USBH_GetDescriptor(phost,
USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD,
USB_DESC_DEVICE,
USB_DESC_DEVICE,
0,
phost->device.Data,
length)) == USBH_OK)
{
@ -166,7 +167,8 @@ USBH_StatusTypeDef USBH_Get_CfgDesc(USBH_HandleTypeDef *phost,
#endif
if((status = USBH_GetDescriptor(phost,
USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD,
USB_DESC_CONFIGURATION,
USB_DESC_CONFIGURATION,
0,
pData,
length)) == USBH_OK)
{
@ -204,7 +206,8 @@ USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost,
if((status = USBH_GetDescriptor(phost,
USB_REQ_RECIPIENT_DEVICE | USB_REQ_TYPE_STANDARD,
USB_DESC_STRING | string_index,
USB_DESC_STRING | string_index,
0x0409,
phost->device.Data,
length)) == USBH_OK)
{
@ -227,7 +230,8 @@ USBH_StatusTypeDef USBH_Get_StringDesc(USBH_HandleTypeDef *phost,
*/
USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost,
uint8_t req_type,
uint16_t value_idx,
uint16_t type_idx,
uint16_t value,
uint8_t* buff,
uint16_t length )
{
@ -235,16 +239,8 @@ USBH_StatusTypeDef USBH_GetDescriptor(USBH_HandleTypeDef *phost,
{
phost->Control.setup.b.bmRequestType = USB_D2H | req_type;
phost->Control.setup.b.bRequest = USB_REQ_GET_DESCRIPTOR;
phost->Control.setup.b.wValue.w = value_idx;
if ((value_idx & 0xff00) == USB_DESC_STRING)
{
phost->Control.setup.b.wIndex.w = 0x0409;
}
else
{
phost->Control.setup.b.wIndex.w = 0;
}
phost->Control.setup.b.wValue.w = type_idx;
phost->Control.setup.b.wIndex.w = value;
phost->Control.setup.b.wLength.w = length;
}
return USBH_CtlReq(phost, buff , length );

Loading…
Cancel
Save