make device keyboard buildable & runnable with ea4357

This commit is contained in:
hathach
2013-10-27 21:33:06 +07:00
parent a98bae0d19
commit d925026089
6 changed files with 1301 additions and 6358 deletions

View File

@@ -67,102 +67,6 @@ STATIC_ hidd_interface_t keyboard_intf =
};
#endif
tusb_error_t hidd_control_request(uint8_t coreid, tusb_control_request_t const * p_request)
{
#if TUSB_CFG_DEVICE_HID_KEYBOARD
if (p_request->bmRequestType.type == TUSB_REQUEST_TYPE_STANDARD) // standard request to hid
{
uint8_t const desc_type = u16_high_u8(p_request->wValue);
uint8_t const desc_index = u16_low_u8 (p_request->wValue);
if ( p_request->bRequest == TUSB_REQUEST_GET_DESCRIPTOR &&
desc_type == HID_DESC_TYPE_REPORT)
{
dcd_pipe_control_write(coreid, keyboard_intf.p_report_desc,
keyboard_intf.p_hid_desc->wReportLength);
}else
{
ASSERT_STATUS(TUSB_ERROR_FAILED);
}
}else if ( p_request->wIndex == keyboard_intf.p_interface_desc->bInterfaceNumber) // class request
{
switch(p_request->bRequest)
{
case HID_REQUEST_CONTROL_SET_IDLE:
// TODO hidd idle rate, no data phase
break;
case HID_REQUEST_CONTROL_SET_REPORT:
// TODO hidd set report, has data phase
// TODO verify data read from control pipe
// ; uint8_t hehe[10]= { 0 };
// dcd_pipe_control_read(coreid, hehe, p_request->wLength);
break;
case HID_REQUEST_CONTROL_GET_REPORT:
case HID_REQUEST_CONTROL_GET_IDLE:
case HID_REQUEST_CONTROL_GET_PROTOCOL:
case HID_REQUEST_CONTROL_SET_PROTOCOL:
default:
ASSERT_STATUS(TUSB_ERROR_NOT_SUPPORTED_YET);
return TUSB_ERROR_NOT_SUPPORTED_YET;
}
}else
{
ASSERT_STATUS(TUSB_ERROR_FAILED);
}
#endif
return TUSB_ERROR_NONE;
}
tusb_error_t hidd_init(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
{
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
//------------- HID descriptor -------------//
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
tusb_hid_descriptor_hid_t const *p_desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
ASSERT_INT(HID_DESC_TYPE_HID, p_desc_hid->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
//------------- Endpoint Descriptor -------------//
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
tusb_descriptor_endpoint_t const *p_desc_endpoint = (tusb_descriptor_endpoint_t const *) p_desc;
ASSERT_INT(TUSB_DESC_TYPE_ENDPOINT, p_desc_endpoint->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
if (p_interface_desc->bInterfaceSubClass == HID_SUBCLASS_BOOT)
{
switch(p_interface_desc->bInterfaceProtocol)
{
#if TUSB_CFG_DEVICE_HID_KEYBOARD
case HID_PROTOCOL_KEYBOARD:
ASSERT_STATUS( dcd_pipe_open(coreid, p_desc_endpoint) );
break;
#endif
#if TUSB_CFG_DEVICE_HID_MOUSE
case HID_PROTOCOL_MOUSE:
ASSERT_STATUS( hidd_interface_init(p_interface_desc,
app_tusb_mouse_desc_report, p_desc_hid->wReportLength,
hidd_mouse_buffer , sizeof(hidd_mouse_buffer)) );
break;
#endif
default: // TODO unknown, unsupported protocol --> skip this interface
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
}
*p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t);
}else
{
// open generic
*p_length = 0;
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
}
return TUSB_ERROR_NONE;
}
#if defined(CAP_DEVICE_ROMDRIVER) && TUSB_CFG_DEVICE_USE_ROM_DRIVER
#include "device/dcd_nxp_romdriver.h" // TODO remove rom driver dependency
@@ -256,8 +160,7 @@ tusb_error_t hidd_configured(void)
return TUSB_ERROR_NONE;
}
tusb_error_t hidd_init(tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
tusb_error_t hidd_init(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
{
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
@@ -266,7 +169,7 @@ tusb_error_t hidd_init(tusb_descriptor_interface_t const * p_interface_desc, uin
tusb_hid_descriptor_hid_t const *p_desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
ASSERT_INT(HID_DESC_TYPE_HID, p_desc_hid->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
if (p_interface_desc->bInterfaceSubClass == HID_SUBCLASS_BOOT)
if (p_interface_desc->bInterfaceSubClass == HID_SUBCLASS_BOOT)
{
switch(p_interface_desc->bInterfaceProtocol)
{
@@ -439,6 +342,104 @@ ErrorCode_t HID_EpOut_Hdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
}
return LPC_OK;
}
#else // not use the rom driver
tusb_error_t hidd_control_request(uint8_t coreid, tusb_control_request_t const * p_request)
{
#if TUSB_CFG_DEVICE_HID_KEYBOARD
if (p_request->bmRequestType_bit.type == TUSB_REQUEST_TYPE_STANDARD) // standard request to hid
{
uint8_t const desc_type = u16_high_u8(p_request->wValue);
uint8_t const desc_index = u16_low_u8 (p_request->wValue);
if ( p_request->bRequest == TUSB_REQUEST_GET_DESCRIPTOR &&
desc_type == HID_DESC_TYPE_REPORT)
{
dcd_pipe_control_write(coreid, keyboard_intf.p_report_desc,
keyboard_intf.p_hid_desc->wReportLength);
}else
{
ASSERT_STATUS(TUSB_ERROR_FAILED);
}
}else if ( p_request->wIndex == keyboard_intf.p_interface_desc->bInterfaceNumber) // class request
{
switch(p_request->bRequest)
{
case HID_REQUEST_CONTROL_SET_IDLE:
// TODO hidd idle rate, no data phase
break;
case HID_REQUEST_CONTROL_SET_REPORT:
// TODO hidd set report, has data phase
// TODO verify data read from control pipe
// ; uint8_t hehe[10]= { 0 };
// dcd_pipe_control_read(coreid, hehe, p_request->wLength);
break;
case HID_REQUEST_CONTROL_GET_REPORT:
case HID_REQUEST_CONTROL_GET_IDLE:
case HID_REQUEST_CONTROL_GET_PROTOCOL:
case HID_REQUEST_CONTROL_SET_PROTOCOL:
default:
ASSERT_STATUS(TUSB_ERROR_NOT_SUPPORTED_YET);
return TUSB_ERROR_NOT_SUPPORTED_YET;
}
}else
{
ASSERT_STATUS(TUSB_ERROR_FAILED);
}
#endif
return TUSB_ERROR_NONE;
}
tusb_error_t hidd_init(uint8_t coreid, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
{
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
//------------- HID descriptor -------------//
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
tusb_hid_descriptor_hid_t const *p_desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
ASSERT_INT(HID_DESC_TYPE_HID, p_desc_hid->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
//------------- Endpoint Descriptor -------------//
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
tusb_descriptor_endpoint_t const *p_desc_endpoint = (tusb_descriptor_endpoint_t const *) p_desc;
ASSERT_INT(TUSB_DESC_TYPE_ENDPOINT, p_desc_endpoint->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
if (p_interface_desc->bInterfaceSubClass == HID_SUBCLASS_BOOT)
{
switch(p_interface_desc->bInterfaceProtocol)
{
#if TUSB_CFG_DEVICE_HID_KEYBOARD
case HID_PROTOCOL_KEYBOARD:
ASSERT_STATUS( dcd_pipe_open(coreid, p_desc_endpoint) );
break;
#endif
#if TUSB_CFG_DEVICE_HID_MOUSE
case HID_PROTOCOL_MOUSE:
ASSERT_STATUS( hidd_interface_init(p_interface_desc,
app_tusb_mouse_desc_report, p_desc_hid->wReportLength,
hidd_mouse_buffer , sizeof(hidd_mouse_buffer)) );
break;
#endif
default: // TODO unknown, unsupported protocol --> skip this interface
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
}
*p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t);
}else
{
// open generic
*p_length = 0;
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
}
return TUSB_ERROR_NONE;
}
#endif
#endif