mirror of
https://github.com/hathach/tinyusb.git
synced 2025-04-17 08:45:13 +00:00
seperate CFG_TUD_HID_BOOT_PROTOCOL to CFG_TUD_HID_KEYBOARD_BOOT & CFG_TUD_HID_MOUSE_BOOT
This commit is contained in:
parent
cf6c534c19
commit
456506045f
@ -75,6 +75,19 @@
|
||||
|
||||
#define CFG_TUD_HID_KEYBOARD 1
|
||||
#define CFG_TUD_HID_MOUSE 1
|
||||
//#define CFG_TUD_HID_GENERIC 0
|
||||
|
||||
/* Enable boot protocol will create separated HID interface for Keyboard,
|
||||
* Consumer Key and Mouse --> require more In endpoints. Otherwise they
|
||||
* are all packed into a single Multiple Report Interface.
|
||||
*
|
||||
* Note: If your device is meant to work with simple host running on
|
||||
* an MCU (e.g with tinyusb host), boot protocol should be enabled.
|
||||
*/
|
||||
//#define CFG_TUD_HID_BOOT_PROTOCOL 1
|
||||
|
||||
#define CFG_TUD_HID_KEYBOARD_BOOT 1
|
||||
#define CFG_TUD_HID_MOUSE_BOOT 1
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// CDC
|
||||
@ -117,15 +130,6 @@
|
||||
// HID
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
/* Enable boot protocol will create separated HID interface for Keyboard,
|
||||
* Consumer Key and Mouse --> require more In endpoints. Otherwise they
|
||||
* are all packed into a single Multiple Report Interface.
|
||||
*
|
||||
* Note: If your device is meant to work with simple host running on
|
||||
* an MCU (e.g with tinyusb host), boot protocol should be enabled.
|
||||
*/
|
||||
#define CFG_TUD_HID_BOOT_PROTOCOL 1
|
||||
|
||||
/* Use the HID_ASCII_TO_KEYCODE lookup if CFG_TUD_HID_KEYBOARD is enabled.
|
||||
* This will occupies 256 bytes of ROM. It will also enable the use of 2 extra APIs
|
||||
* - tud_hid_keyboard_send_char()
|
||||
|
@ -73,15 +73,17 @@ typedef struct {
|
||||
CFG_TUSB_MEM_ALIGN uint8_t report_buf[REPORT_BUFSIZE];
|
||||
}hidd_interface_t;
|
||||
|
||||
#if CFG_TUD_HID_BOOT_PROTOCOL
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
CFG_TUSB_ATTR_USBRAM static hidd_interface_t _kbd_itf;
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
CFG_TUSB_ATTR_USBRAM static hidd_interface_t _mse_itf;
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if 0 // CFG_TUD_HID_BOOT_PROTOCOL
|
||||
CFG_TUSB_ATTR_USBRAM static hidd_interface_t _composite_itf;
|
||||
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -282,51 +284,43 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u
|
||||
|
||||
if (desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT)
|
||||
{
|
||||
#if CFG_TUD_HID_BOOT_PROTOCOL
|
||||
if ( (desc_itf->bInterfaceProtocol != HID_PROTOCOL_KEYBOARD) && (desc_itf->bInterfaceProtocol != HID_PROTOCOL_MOUSE) )
|
||||
TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
|
||||
|
||||
hidd_interface_t * p_hid = NULL;
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD)
|
||||
{
|
||||
// unknown, unsupported protocol
|
||||
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
|
||||
}else
|
||||
{
|
||||
hidd_interface_t * p_hid = NULL;
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD)
|
||||
{
|
||||
p_hid = &_kbd_itf;
|
||||
p_hid->report_desc = tud_desc_set.hid_report.boot_keyboard;
|
||||
p_hid->get_report_cb = tud_hid_keyboard_get_report_cb;
|
||||
p_hid->set_report_cb = tud_hid_keyboard_set_report_cb;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE)
|
||||
{
|
||||
p_hid = &_mse_itf;
|
||||
p_hid->report_desc = tud_desc_set.hid_report.boot_mouse;
|
||||
p_hid->get_report_cb = tud_hid_mouse_get_report_cb;
|
||||
p_hid->set_report_cb = tud_hid_mouse_set_report_cb;
|
||||
}
|
||||
#endif
|
||||
|
||||
TU_ASSERT(p_hid, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
|
||||
VERIFY(p_hid->report_desc, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||
|
||||
TU_ASSERT( dcd_edpt_open(rhport, desc_edpt), TUSB_ERROR_DCD_FAILED );
|
||||
|
||||
p_hid->boot_protocol = true; // default to boot mode when mounted
|
||||
p_hid->report_len = desc_hid->wReportLength;
|
||||
p_hid->itf_num = desc_itf->bInterfaceNumber;
|
||||
p_hid->ep_in = desc_edpt->bEndpointAddress;
|
||||
p_hid->report_id = 0;
|
||||
|
||||
*p_length = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t);
|
||||
p_hid = &_kbd_itf;
|
||||
p_hid->report_desc = tud_desc_set.hid_report.boot_keyboard;
|
||||
p_hid->boot_protocol = CFG_TUD_HID_KEYBOARD_BOOT; // default mode is BOOT if enabled
|
||||
p_hid->get_report_cb = tud_hid_keyboard_get_report_cb;
|
||||
p_hid->set_report_cb = tud_hid_keyboard_set_report_cb;
|
||||
}
|
||||
#else
|
||||
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
if (desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE)
|
||||
{
|
||||
p_hid = &_mse_itf;
|
||||
p_hid->report_desc = tud_desc_set.hid_report.boot_mouse;
|
||||
p_hid->boot_protocol = CFG_TUD_HID_MOUSE_BOOT; // default mode is BOOT if enabled
|
||||
p_hid->get_report_cb = tud_hid_mouse_get_report_cb;
|
||||
p_hid->set_report_cb = tud_hid_mouse_set_report_cb;
|
||||
}
|
||||
#endif
|
||||
|
||||
TU_ASSERT(p_hid, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
|
||||
VERIFY(p_hid->report_desc, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||
|
||||
TU_ASSERT( dcd_edpt_open(rhport, desc_edpt), TUSB_ERROR_DCD_FAILED );
|
||||
|
||||
p_hid->report_len = desc_hid->wReportLength;
|
||||
p_hid->itf_num = desc_itf->bInterfaceNumber;
|
||||
p_hid->ep_in = desc_edpt->bEndpointAddress;
|
||||
p_hid->report_id = 0;
|
||||
|
||||
*p_length = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -318,19 +318,17 @@ static void usbd_reset(uint8_t rhport)
|
||||
tud_desc_set.device = (uint8_t const*) &_desc_auto_device;
|
||||
tud_desc_set.config = _desc_auto_config;
|
||||
|
||||
#if CFG_TUD_HID_BOOT_PROTOCOL
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
||||
extern uint8_t const _desc_auto_hid_kbd_report[];
|
||||
tud_desc_set.hid_report.boot_keyboard = _desc_auto_hid_kbd_report;
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
|
||||
extern uint8_t const _desc_auto_hid_mse_report[];
|
||||
tud_desc_set.hid_report.boot_mouse = _desc_auto_hid_mse_report;
|
||||
#endif
|
||||
|
||||
#else
|
||||
#if 0 // CFG_TUD_HID_BOOT_PROTOCOL
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD + CFG_TUD_HID_MOUSE
|
||||
tud_desc_set.hid_report.composite = ;
|
||||
|
@ -62,7 +62,7 @@
|
||||
*/
|
||||
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
|
||||
#define CFG_TUD_DESC_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | \
|
||||
_PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) )
|
||||
_PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) /*| _PID_MAP(HID_GENERIC, 5)*/ )
|
||||
#endif
|
||||
|
||||
/*------------- Interface Numbering -------------*/
|
||||
@ -94,17 +94,21 @@
|
||||
#define EP_MSC_OUT _EP_OUT(ITF_NUM_MSC+1)
|
||||
#define EP_MSC_IN _EP_IN (ITF_NUM_MSC+1)
|
||||
|
||||
// Boot protocol each report has its own interface
|
||||
#if CFG_TUD_HID_BOOT_PROTOCOL
|
||||
// HID Keyboard
|
||||
#define EP_HID_KBD _EP_IN (ITF_NUM_HID_KBD+1)
|
||||
#define EP_HID_KBD_SIZE 8
|
||||
|
||||
// HID Mouse
|
||||
#define EP_HID_MSE _EP_IN (ITF_NUM_HID_MSE+1)
|
||||
#define EP_HID_MSE_SIZE 8
|
||||
// HID Keyboard with boot protocol
|
||||
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
||||
#define EP_HID_KBD_BOOT _EP_IN (ITF_NUM_HID_KBD+1)
|
||||
#define EP_HID_KBD_BOOT_SZ 8
|
||||
|
||||
#else
|
||||
#endif
|
||||
|
||||
// HID Mouse with boot protocol
|
||||
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
|
||||
#define EP_HID_MSE_BOOT _EP_IN (ITF_NUM_HID_MSE+1)
|
||||
#define EP_HID_MSE_BOOT_SZ 8
|
||||
#endif
|
||||
|
||||
#if 0 // CFG_TUD_HID_BOOT_PROTOCOL
|
||||
|
||||
// HID composite = keyboard + mouse
|
||||
#define EP_HID_COMP _EP_IN (ITF_NUM_HID_KBD+1)
|
||||
@ -303,27 +307,25 @@ typedef struct ATTR_PACKED
|
||||
#endif
|
||||
|
||||
//------------- HID -------------//
|
||||
#if CFG_TUD_HID_BOOT_PROTOCOL
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
||||
struct ATTR_PACKED
|
||||
{
|
||||
tusb_desc_interface_t itf;
|
||||
tusb_hid_descriptor_hid_t hid_desc;
|
||||
tusb_desc_endpoint_t ep_in;
|
||||
} hid_kbd;
|
||||
} hid_kbd_boot;
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
|
||||
struct ATTR_PACKED
|
||||
{
|
||||
tusb_desc_interface_t itf;
|
||||
tusb_hid_descriptor_hid_t hid_desc;
|
||||
tusb_desc_endpoint_t ep_in;
|
||||
} hid_mse;
|
||||
} hid_mse_boot;
|
||||
#endif
|
||||
|
||||
#else
|
||||
#if 0 // CFG_TUD_HID_BOOT_PROTOCOL
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD || CFG_TUD_HID_MOUSE
|
||||
struct ATTR_PACKED
|
||||
@ -470,7 +472,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||
.bInterval = 0
|
||||
},
|
||||
},
|
||||
#endif
|
||||
#endif // cdc
|
||||
|
||||
#if CFG_TUD_MSC
|
||||
//------------- Mass Storage-------------//
|
||||
@ -509,12 +511,10 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||
.bInterval = 1
|
||||
}
|
||||
},
|
||||
#endif
|
||||
#endif // msc
|
||||
|
||||
#if CFG_TUD_HID_BOOT_PROTOCOL
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
.hid_kbd =
|
||||
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
||||
.hid_kbd_boot =
|
||||
{
|
||||
.itf =
|
||||
{
|
||||
@ -526,7 +526,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||
.bInterfaceClass = TUSB_CLASS_HID,
|
||||
.bInterfaceSubClass = HID_SUBCLASS_BOOT,
|
||||
.bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
|
||||
.iInterface = 4 + CFG_TUD_CDC + CFG_TUD_MSC
|
||||
.iInterface = 0 //4 + CFG_TUD_CDC + CFG_TUD_MSC
|
||||
},
|
||||
|
||||
.hid_desc =
|
||||
@ -544,17 +544,17 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||
{
|
||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||
.bEndpointAddress = EP_HID_KBD,
|
||||
.bEndpointAddress = EP_HID_KBD_BOOT,
|
||||
.bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
|
||||
.wMaxPacketSize = { .size = EP_HID_KBD_SIZE },
|
||||
.wMaxPacketSize = { .size = EP_HID_KBD_BOOT_SZ },
|
||||
.bInterval = 0x0A
|
||||
}
|
||||
},
|
||||
#endif // keyboard
|
||||
#endif // boot keyboard
|
||||
|
||||
//------------- HID Mouse -------------//
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
.hid_mse =
|
||||
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
|
||||
.hid_mse_boot =
|
||||
{
|
||||
.itf =
|
||||
{
|
||||
@ -566,7 +566,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||
.bInterfaceClass = TUSB_CLASS_HID,
|
||||
.bInterfaceSubClass = HID_SUBCLASS_BOOT,
|
||||
.bInterfaceProtocol = HID_PROTOCOL_MOUSE,
|
||||
.iInterface = 4 + CFG_TUD_CDC + CFG_TUD_MSC + CFG_TUD_HID_KEYBOARD
|
||||
.iInterface = 0 // 4 + CFG_TUD_CDC + CFG_TUD_MSC + CFG_TUD_HID_KEYBOARD
|
||||
},
|
||||
|
||||
.hid_desc =
|
||||
@ -584,16 +584,16 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||
{
|
||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||
.bEndpointAddress = EP_HID_MSE,
|
||||
.bEndpointAddress = EP_HID_MSE_BOOT,
|
||||
.bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
|
||||
.wMaxPacketSize = { .size = EP_HID_MSE_SIZE },
|
||||
.wMaxPacketSize = { .size = EP_HID_MSE_BOOT_SZ },
|
||||
.bInterval = 0x0A
|
||||
},
|
||||
},
|
||||
|
||||
#endif // mouse
|
||||
#endif // boot mouse
|
||||
|
||||
#else
|
||||
#if 0
|
||||
|
||||
#if CFG_TUD_HID_KEYBOARD || CFG_TUD_HID_MOUSE
|
||||
//------------- HID Keyboard + Mouse (multiple reports) -------------//
|
||||
|
Loading…
x
Reference in New Issue
Block a user