summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2021-02-24 13:54:18 +0700
committerhathach <[email protected]>2021-05-18 12:58:24 +0700
commitf1148ca5ac8f56774af4b58175d0d61442f86544 (patch)
tree3baa0d45665bbf4ea5509d62e4a82957183a7ba1
parent98f5082191e2135ca783a24a39f95ee82639b9fc (diff)
reworking hid host
-rw-r--r--src/class/hid/hid_host.c41
-rw-r--r--src/class/hid/hid_host.h8
2 files changed, 42 insertions, 7 deletions
diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c
index 9e41f9f45..7ae50e4d7 100644
--- a/src/class/hid/hid_host.c
+++ b/src/class/hid/hid_host.c
@@ -35,13 +35,40 @@
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
+/* "KEYBOARD" : in_len=8 , out_len=1, usage_page=0x01, usage=0x06 # Generic Desktop, Keyboard
+ "MOUSE" : in_len=4 , out_len=0, usage_page=0x01, usage=0x02 # Generic Desktop, Mouse
+ "CONSUMER" : in_len=2 , out_len=0, usage_page=0x0C, usage=0x01 # Consumer, Consumer Control
+ "SYS_CONTROL" : in_len=1 , out_len=0, usage_page=0x01, usage=0x80 # Generic Desktop, Sys Control
+ "GAMEPAD" : in_len=6 , out_len=0, usage_page=0x01, usage=0x05 # Generic Desktop, Game Pad
+ "DIGITIZER" : in_len=5 , out_len=0, usage_page=0x0D, usage=0x02 # Digitizers, Pen
+ "XAC_COMPATIBLE_GAMEPAD" : in_len=3 , out_len=0, usage_page=0x01, usage=0x05 # Generic Desktop, Game Pad
+ "RAW" : in_len=64, out_len=0, usage_page=0xFFAF, usage=0xAF # Vendor 0xFFAF "Adafruit", 0xAF
+ */
typedef struct {
- uint8_t itf_num;
- uint8_t ep_in;
- uint8_t ep_out;
+ uint8_t itf_num;
+ uint8_t ep_in;
+ uint8_t ep_out;
+
bool valid;
+ uint16_t report_size; // TODO remove later
+
+ uint8_t boot_protocol; // None, Keyboard, Mouse
+ bool boot_mode; // Boot or Report protocol
+ uint8_t report_count; // Number of reports
- uint16_t report_size;
+ struct {
+ uint8_t in_len; // length of IN report
+ uint8_t out_len; // length of OUT report
+ uint8_t usage_page;
+ uint8_t usage;
+ }reports[CFG_TUH_HID_MAX_REPORT];
+
+ // Parsed Report ID for convenient API
+ uint8_t report_id_keyboard;
+ uint8_t reprot_id_mouse;
+ uint8_t report_id_gamepad;
+ uint8_t report_id_consumer;
+ uint8_t report_id_vendor;
}hidh_interface_t;
//--------------------------------------------------------------------+
@@ -51,9 +78,9 @@ static inline bool hidh_interface_open(uint8_t rhport, uint8_t dev_addr, uint8_t
{
TU_ASSERT( usbh_edpt_open(rhport, dev_addr, desc_ep) );
+ p_hid->itf_num = interface_number;
p_hid->ep_in = desc_ep->bEndpointAddress;
p_hid->report_size = desc_ep->wMaxPacketSize.size; // TODO get size from report descriptor
- p_hid->itf_num = interface_number;
p_hid->valid = true;
return true;
@@ -170,12 +197,12 @@ bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
//------------- HID descriptor -------------//
p_desc = tu_desc_next(p_desc);
tusb_hid_descriptor_hid_t const *desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
- TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType, TUSB_ERROR_INVALID_PARA);
+ TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType);
//------------- Endpoint Descriptor -------------//
p_desc = tu_desc_next(p_desc);
tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType, TUSB_ERROR_INVALID_PARA);
+ TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType);
if ( HID_SUBCLASS_BOOT == desc_itf->bInterfaceSubClass )
{
diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h
index 174601594..d43158186 100644
--- a/src/class/hid/hid_host.h
+++ b/src/class/hid/hid_host.h
@@ -39,6 +39,14 @@
#endif
//--------------------------------------------------------------------+
+// Class Driver Configuration
+//--------------------------------------------------------------------+
+
+#ifndef CFG_TUH_HID_MAX_REPORT
+#define CFG_TUH_HID_MAX_REPORT 8
+#endif
+
+//--------------------------------------------------------------------+
// KEYBOARD Application API
//--------------------------------------------------------------------+
/** \addtogroup ClassDriver_HID_Keyboard Keyboard