implement hidd_control_request including std & class specific to interface number.

refractor usbd_setup_received
This commit is contained in:
hathach 2013-06-14 18:22:40 +07:00
parent 4103cc374f
commit 40b65b265c
6 changed files with 106 additions and 19 deletions

View File

@ -75,6 +75,15 @@ enum {
HID_REQUEST_REPORT_FEATURE
};
enum {
HID_REQUEST_CONTROL_GET_REPORT = 0x01,
HID_REQUEST_CONTROL_GET_IDLE = 0x02,
HID_REQUEST_CONTROL_GET_PROTOCOL = 0x03,
HID_REQUEST_CONTROL_SET_REPORT = 0x09,
HID_REQUEST_CONTROL_SET_IDLE = 0x0a,
HID_REQUEST_CONTROL_SET_PROTOCOL = 0x0b
};
typedef ATTR_PREPACKED struct ATTR_PACKED {
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
uint8_t bDescriptorType; /**< Constant name specifying type of HID descriptor. */

View File

@ -48,7 +48,71 @@
#include "hid_device.h"
#include "tusb_descriptors.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
typedef struct {
tusb_descriptor_interface_t const * p_interface_desc;
tusb_hid_descriptor_hid_t const * p_hid_desc;
uint8_t const * p_report_desc;
// volatile tusb_interface_status_t status;
}hidd_interface_t;
#if TUSB_CFG_DEVICE_HID_KEYBOARD
STATIC_ hidd_interface_t keyboard_intf =
{
.p_interface_desc = &app_tusb_desc_configuration.keyboard_interface,
.p_hid_desc = &app_tusb_desc_configuration.keyboard_hid,
.p_report_desc = app_tusb_keyboard_desc_report
};
#endif
tusb_error_t hidd_control_request(uint8_t coreid, tusb_std_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
// dcd_pipe_control_read(coreid, .....
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)
{

View File

@ -75,6 +75,7 @@
ENTRY(TUSB_ERROR_EHCI_NOT_ENOUGH_QTD )\
ENTRY(TUSB_ERROR_USBD_DESCRIPTOR_STRING )\
ENTRY(TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE )\
ENTRY(TUSB_ERROR_NOT_SUPPORTED_YET )\
ENTRY(TUSB_ERROR_FAILED )\

View File

@ -63,6 +63,8 @@ void dcd_controller_connect(uint8_t coreid);
void dcd_isr(uint8_t coreid);
tusb_error_t dcd_pipe_control_write(uint8_t coreid, void const * buffer, uint16_t length);
tusb_error_t dcd_pipe_control_read(uint8_t coreid, void const * buffer, uint16_t length);
void dcd_pipe_control_write_zero_length(uint8_t coreid);
tusb_error_t dcd_endpoint_configure(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc) ATTR_WARN_UNUSED_RESULT;
void dcd_device_set_address(uint8_t coreid, uint8_t dev_addr);

View File

@ -304,7 +304,7 @@ tusb_error_t dcd_pipe_control_write(uint8_t coreid, void const * buffer, uint16_
return TUSB_ERROR_NONE;
}
tusb_error_t dcd_pipe_control_read(uint8_t coreid)
tusb_error_t dcd_pipe_control_read(uint8_t coreid, void const * buffer, uint16_t length)
{
return TUSB_ERROR_NONE;
}

View File

@ -97,7 +97,7 @@ void std_get_descriptor(uint8_t coreid)
uint16_t const requested_length = min16_of(usbd_devices[coreid].setup_packet.wLength, sizeof(app_tusb_desc_configuration)-1);
ASSERT(requested_length <= TUSB_CFG_DEVICE_CONTROL_PACKET_SIZE, (void)0 ); // multiple packets requires a task a-like
dcd_pipe_control_write(coreid, ((uint8_t*)&app_tusb_desc_configuration),
dcd_pipe_control_write(coreid, &app_tusb_desc_configuration,
requested_length);
}
break;
@ -122,29 +122,40 @@ void std_get_descriptor(uint8_t coreid)
void usbd_setup_received(uint8_t coreid)
{
usbd_device_info_t *p_device = &usbd_devices[coreid];
switch ( p_device->setup_packet.bRequest)
// check device configured TODO
if ( p_device->setup_packet.bmRequestType.recipient == TUSB_REQUEST_RECIPIENT_INTERFACE)
{
case TUSB_REQUEST_GET_DESCRIPTOR:
std_get_descriptor(coreid);
break;
// TODO detect which class
hidd_control_request(coreid, &p_device->setup_packet);
}else
{
switch ( p_device->setup_packet.bRequest )
{
case TUSB_REQUEST_GET_DESCRIPTOR:
std_get_descriptor(coreid);
break;
case TUSB_REQUEST_SET_ADDRESS:
p_device->address = (uint8_t) p_device->setup_packet.wValue;
dcd_device_set_address(coreid, p_device->address);
dcd_pipe_control_write_zero_length(coreid);
usbd_devices[coreid].state = TUSB_DEVICE_STATE_ADDRESSED;
break;
case TUSB_REQUEST_SET_ADDRESS:
p_device->address = (uint8_t) p_device->setup_packet.wValue;
dcd_device_set_address(coreid, p_device->address);
usbd_devices[coreid].state = TUSB_DEVICE_STATE_ADDRESSED;
break;
case TUSB_REQUEST_SET_CONFIGURATION:
dcd_device_set_configuration(coreid, (uint8_t) p_device->setup_packet.wValue);
dcd_pipe_control_write_zero_length(coreid);
usbd_devices[coreid].state = TUSB_DEVICE_STATE_CONFIGURED;
break;
case TUSB_REQUEST_SET_CONFIGURATION:
dcd_device_set_configuration(coreid, (uint8_t) p_device->setup_packet.wValue);
usbd_devices[coreid].state = TUSB_DEVICE_STATE_CONFIGURED;
break;
default:
return;
default:
return;
}
}
if (p_device->setup_packet.bmRequestType.direction == TUSB_DIR_HOST_TO_DEV)
{
dcd_pipe_control_write_zero_length(coreid);
}
}
//--------------------------------------------------------------------+