summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-06-14 18:22:40 +0700
committerhathach <[email protected]>2013-06-14 18:22:40 +0700
commit40b65b265c4a8d2de06b9164829169d629dbd847 (patch)
tree7b08fbfce9afbd5f9e99b68cd479b8e867a3b048
parent4103cc374f8ee94a2d4d308cad5c1e24221b8ae7 (diff)
implement hidd_control_request including std & class specific to interface number.
refractor usbd_setup_received
-rw-r--r--tinyusb/class/hid.h9
-rw-r--r--tinyusb/class/hid_device.c64
-rw-r--r--tinyusb/common/errors.h1
-rw-r--r--tinyusb/device/dcd.h2
-rw-r--r--tinyusb/device/dcd_lpc175x_6x.c2
-rw-r--r--tinyusb/device/usbd.c47
6 files changed, 106 insertions, 19 deletions
diff --git a/tinyusb/class/hid.h b/tinyusb/class/hid.h
index 3e7d86a18..06374e035 100644
--- a/tinyusb/class/hid.h
+++ b/tinyusb/class/hid.h
@@ -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. */
diff --git a/tinyusb/class/hid_device.c b/tinyusb/class/hid_device.c
index 7b13727a7..8ae673560 100644
--- a/tinyusb/class/hid_device.c
+++ b/tinyusb/class/hid_device.c
@@ -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)
{
diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h
index b9edbf091..02cdae1e6 100644
--- a/tinyusb/common/errors.h
+++ b/tinyusb/common/errors.h
@@ -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 )\
diff --git a/tinyusb/device/dcd.h b/tinyusb/device/dcd.h
index 79f2e1fc8..01eae9413 100644
--- a/tinyusb/device/dcd.h
+++ b/tinyusb/device/dcd.h
@@ -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);
diff --git a/tinyusb/device/dcd_lpc175x_6x.c b/tinyusb/device/dcd_lpc175x_6x.c
index 848e4d6fe..dc19bb54e 100644
--- a/tinyusb/device/dcd_lpc175x_6x.c
+++ b/tinyusb/device/dcd_lpc175x_6x.c
@@ -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;
}
diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c
index 473148041..252363527 100644
--- a/tinyusb/device/usbd.c
+++ b/tinyusb/device/usbd.c
@@ -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);
+ }
}
//--------------------------------------------------------------------+