change HID config, move HID boot config to part of auto descriptor only
This commit is contained in:
+34
-15
@@ -38,7 +38,7 @@
|
||||
|
||||
#include "tusb_option.h"
|
||||
|
||||
#if (TUSB_OPT_DEVICE_ENABLED && TUD_OPT_HID_ENABLED)
|
||||
#if (TUSB_OPT_DEVICE_ENABLED && CFG_TUD_HID)
|
||||
|
||||
#define _TINY_USB_SOURCE_FILE_
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -82,9 +82,16 @@ CFG_TUSB_ATTR_USBRAM static hidd_interface_t _kbd_itf;
|
||||
CFG_TUSB_ATTR_USBRAM static hidd_interface_t _mse_itf;
|
||||
#endif
|
||||
|
||||
#if 0 // CFG_TUD_HID_BOOT_PROTOCOL
|
||||
CFG_TUSB_ATTR_USBRAM static hidd_interface_t _composite_itf;
|
||||
#endif
|
||||
CFG_TUSB_ATTR_USBRAM static hidd_interface_t _hidd_itf;
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HID GENERIC API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_hid_generic_ready(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD APPLICATION API
|
||||
@@ -173,6 +180,7 @@ bool tud_hid_keyboard_key_sequence(const char* str, uint32_t interval_ms)
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
|
||||
@@ -268,23 +276,25 @@ void hidd_reset(uint8_t rhport)
|
||||
#endif
|
||||
}
|
||||
|
||||
tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_length)
|
||||
tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t *p_len)
|
||||
{
|
||||
uint8_t const *p_desc = (uint8_t const *) desc_itf;
|
||||
|
||||
//------------- HID descriptor -------------//
|
||||
p_desc += p_desc[DESC_OFFSET_LEN];
|
||||
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_HIDD_DESCRIPTOR_INTERFACE);
|
||||
TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType, ERR_TUD_INVALID_DESCRIPTOR);
|
||||
|
||||
//------------- Endpoint Descriptor -------------//
|
||||
p_desc += p_desc[DESC_OFFSET_LEN];
|
||||
tusb_desc_endpoint_t const *desc_edpt = (tusb_desc_endpoint_t const *) p_desc;
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_edpt->bDescriptorType, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_edpt->bDescriptorType, ERR_TUD_INVALID_DESCRIPTOR);
|
||||
|
||||
*p_len = 0;
|
||||
|
||||
if (desc_itf->bInterfaceSubClass == HID_SUBCLASS_BOOT)
|
||||
{
|
||||
TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE, TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE);
|
||||
TU_ASSERT(desc_itf->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD || desc_itf->bInterfaceProtocol == HID_PROTOCOL_MOUSE, ERR_TUD_INVALID_DESCRIPTOR);
|
||||
|
||||
hidd_interface_t * p_hid = NULL;
|
||||
|
||||
@@ -293,7 +303,6 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -304,13 +313,12 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u
|
||||
{
|
||||
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);
|
||||
TU_ASSERT(p_hid, ERR_TUD_INVALID_DESCRIPTOR);
|
||||
VERIFY(p_hid->report_desc, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||
|
||||
TU_ASSERT( dcd_edpt_open(rhport, desc_edpt), TUSB_ERROR_DCD_FAILED );
|
||||
@@ -319,15 +327,26 @@ tusb_error_t hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, u
|
||||
p_hid->itf_num = desc_itf->bInterfaceNumber;
|
||||
p_hid->ep_in = desc_edpt->bEndpointAddress;
|
||||
p_hid->report_id = 0;
|
||||
p_hid->boot_protocol = true; // default mode is BOOT
|
||||
|
||||
*p_length = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t);
|
||||
*p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_desc_endpoint_t);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO HID generic
|
||||
hidd_interface_t * p_hid = &_hidd_itf;
|
||||
|
||||
p_hid->itf_num = desc_itf->bInterfaceNumber;
|
||||
p_hid->ep_in = desc_edpt->bEndpointAddress;
|
||||
|
||||
// TODO parse report ID for keyboard, mouse
|
||||
*p_length = 0;
|
||||
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
|
||||
p_hid->report_id = 0;
|
||||
p_hid->report_len = 0;
|
||||
p_hid->report_desc = NULL;
|
||||
//p_hid->get_report_cb = tud_hid_get_report_cb;
|
||||
//p_hid->set_report_cb = tud_hid_set_report_cb;
|
||||
|
||||
return ERR_TUD_INVALID_DESCRIPTOR;
|
||||
}
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
@@ -352,7 +371,7 @@ tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t cons
|
||||
{
|
||||
STASK_ASSERT ( p_hid->report_len <= CFG_TUD_CTRL_BUFSIZE );
|
||||
|
||||
// use device control buffer (in USB SRAM)
|
||||
// use device control buffer
|
||||
memcpy(_usbd_ctrl_buf, p_hid->report_desc, p_hid->report_len);
|
||||
|
||||
usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, _usbd_ctrl_buf, p_hid->report_len);
|
||||
|
||||
@@ -49,8 +49,19 @@
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD APPLICATION API
|
||||
// HID GENERIC API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_hid_generic_ready(void);
|
||||
bool tud_hid_generic_report(void);
|
||||
|
||||
/*------------- Callbacks -------------*/
|
||||
ATTR_WEAK uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
|
||||
ATTR_WEAK void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// KEYBOARD API
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUD_HID_KEYBOARD
|
||||
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
|
||||
* @{ */
|
||||
/** \defgroup Keyboard_Device Device
|
||||
@@ -78,7 +89,9 @@ typedef struct{
|
||||
extern const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128];
|
||||
#endif
|
||||
|
||||
/*------------- Callbacks, ATTR_WEAK means optional -------------*/
|
||||
#endif
|
||||
|
||||
/*------------- Callbacks -------------*/
|
||||
|
||||
/** Callback invoked when USB host request \ref HID_REQ_CONTROL_GET_REPORT.
|
||||
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
|
||||
@@ -109,8 +122,9 @@ ATTR_WEAK void tud_hid_keyboard_set_report_cb(hid_report_type_t report_type, uin
|
||||
/** @} */
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MOUSE APPLICATION API
|
||||
// MOUSE API
|
||||
//--------------------------------------------------------------------+
|
||||
#if CFG_TUD_HID_MOUSE
|
||||
/** \addtogroup ClassDriver_HID_Mouse Mouse
|
||||
* @{ */
|
||||
/** \defgroup Mouse_Device Device
|
||||
@@ -141,10 +155,10 @@ static inline bool tud_hid_mouse_button_release(void)
|
||||
|
||||
/*------------- Callbacks -------------*/
|
||||
|
||||
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_GET_REPORT
|
||||
* via control endpoint.
|
||||
/**
|
||||
* Callback function that is invoked when USB host request \ref HID_REQ_CONTROL_GET_REPORT.
|
||||
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
|
||||
* \param[out] buffer buffer that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM)
|
||||
* \param[out] buffer buffer that application need to update, value must be accessible by USB controller (see \ref CFG_TUSB_ATTR_USBRAM)
|
||||
* \param[in] reqlen number of bytes that host requested
|
||||
* \retval non-zero Actual number of bytes in the response's buffer.
|
||||
* \retval zero indicates the current request is not supported. Tinyusb device stack will reject the request by
|
||||
@@ -154,8 +168,8 @@ static inline bool tud_hid_mouse_button_release(void)
|
||||
*/
|
||||
ATTR_WEAK uint16_t tud_hid_mouse_get_report_cb(hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
|
||||
|
||||
/** \brief Callback function that is invoked when USB host request \ref HID_REQUEST_CONTROL_SET_REPORT
|
||||
* via control endpoint.
|
||||
/**
|
||||
* Callback function that is invoked when USB host request \ref HID_REQ_CONTROL_SET_REPORT.
|
||||
* \param[in] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
|
||||
* \param[in] buffer buffer containing the report's data
|
||||
* \param[in] bufsize number of bytes in the \a p_report_data
|
||||
@@ -166,13 +180,15 @@ ATTR_WEAK void tud_hid_mouse_set_report_cb(hid_report_type_t report_type, uint8_
|
||||
|
||||
//ATTR_WEAK void tud_hid_mouse_set_protocol_cb(bool boot_protocol);
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD-CLASS DRIVER API
|
||||
// INTERNAL API
|
||||
//--------------------------------------------------------------------+
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
|
||||
Reference in New Issue
Block a user