change HID config, move HID boot config to part of auto descriptor only
This commit is contained in:
parent
456506045f
commit
9f61493020
|
@ -61,33 +61,38 @@
|
||||||
// DEVICE CONFIGURATION
|
// DEVICE CONFIGURATION
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
|
|
||||||
/*------------- Core -------------*/
|
#define CFG_TUD_ENDOINT0_SIZE 64
|
||||||
|
|
||||||
|
/*------------- Descriptors -------------*/
|
||||||
|
|
||||||
|
/* Enable auto generated descriptor, tinyusb will try its best to create
|
||||||
|
* descriptor ( device, configuration, hid ) that matches enabled CFG_* in this file
|
||||||
|
*
|
||||||
|
* Note: All CFG_TUD_DESC_* are relevant only if CFG_TUD_DESC_AUTO is enabled
|
||||||
|
*/
|
||||||
#define CFG_TUD_DESC_AUTO 1
|
#define CFG_TUD_DESC_AUTO 1
|
||||||
|
|
||||||
|
/* USB VID/PID if not defined, tinyusb to use default value
|
||||||
|
* Note: different class combination e.g CDC and (CDC + MSC) should have different
|
||||||
|
* PID since Host OS will "remembered" device driver after the first plug */
|
||||||
// #define CFG_TUD_DESC_VID 0xCAFE
|
// #define CFG_TUD_DESC_VID 0xCAFE
|
||||||
// #define CFG_TUD_DESC_PID 0x0001
|
// #define CFG_TUD_DESC_PID 0x0001
|
||||||
|
|
||||||
#define CFG_TUD_ENDOINT0_SIZE 64
|
/* Use Boot Protocol for Keyboard, Mouse. Enable this will create separated HID interface
|
||||||
|
* require more IN endpoints. If disabled, they they are all packed into a single
|
||||||
|
* multiple report interface called "Generic".
|
||||||
|
*/
|
||||||
|
#define CFG_TUD_DESC_BOOT_KEYBOARD 1
|
||||||
|
#define CFG_TUD_DESC_BOOT_MOUSE 1
|
||||||
|
|
||||||
//------------- CLASS -------------//
|
//------------- CLASS -------------//
|
||||||
#define CFG_TUD_CDC 1
|
#define CFG_TUD_CDC 1
|
||||||
#define CFG_TUD_MSC 1
|
#define CFG_TUD_MSC 1
|
||||||
|
|
||||||
|
#define CFG_TUD_HID 1
|
||||||
#define CFG_TUD_HID_KEYBOARD 1
|
#define CFG_TUD_HID_KEYBOARD 1
|
||||||
#define CFG_TUD_HID_MOUSE 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
|
// CDC
|
||||||
|
|
|
@ -91,7 +91,7 @@ tud_desc_set_t tud_desc_set =
|
||||||
|
|
||||||
.hid_report =
|
.hid_report =
|
||||||
{
|
{
|
||||||
.composite = NULL,
|
.generic = NULL,
|
||||||
.boot_keyboard = NULL,
|
.boot_keyboard = NULL,
|
||||||
.boot_mouse = NULL
|
.boot_mouse = NULL
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
#include "tusb_option.h"
|
#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_
|
#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;
|
CFG_TUSB_ATTR_USBRAM static hidd_interface_t _mse_itf;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0 // CFG_TUD_HID_BOOT_PROTOCOL
|
CFG_TUSB_ATTR_USBRAM static hidd_interface_t _hidd_itf;
|
||||||
CFG_TUSB_ATTR_USBRAM static hidd_interface_t _composite_itf;
|
|
||||||
#endif
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// HID GENERIC API
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
bool tud_hid_generic_ready(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// KEYBOARD APPLICATION API
|
// 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
|
#endif // CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
|
||||||
|
@ -268,23 +276,25 @@ void hidd_reset(uint8_t rhport)
|
||||||
#endif
|
#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;
|
uint8_t const *p_desc = (uint8_t const *) desc_itf;
|
||||||
|
|
||||||
//------------- HID descriptor -------------//
|
//------------- HID descriptor -------------//
|
||||||
p_desc += p_desc[DESC_OFFSET_LEN];
|
p_desc += p_desc[DESC_OFFSET_LEN];
|
||||||
tusb_hid_descriptor_hid_t const *desc_hid = (tusb_hid_descriptor_hid_t const *) 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_HIDD_DESCRIPTOR_INTERFACE);
|
TU_ASSERT(HID_DESC_TYPE_HID == desc_hid->bDescriptorType, ERR_TUD_INVALID_DESCRIPTOR);
|
||||||
|
|
||||||
//------------- Endpoint Descriptor -------------//
|
//------------- Endpoint Descriptor -------------//
|
||||||
p_desc += p_desc[DESC_OFFSET_LEN];
|
p_desc += p_desc[DESC_OFFSET_LEN];
|
||||||
tusb_desc_endpoint_t const *desc_edpt = (tusb_desc_endpoint_t const *) p_desc;
|
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)
|
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;
|
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 = &_kbd_itf;
|
||||||
p_hid->report_desc = tud_desc_set.hid_report.boot_keyboard;
|
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->get_report_cb = tud_hid_keyboard_get_report_cb;
|
||||||
p_hid->set_report_cb = tud_hid_keyboard_set_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 = &_mse_itf;
|
||||||
p_hid->report_desc = tud_desc_set.hid_report.boot_mouse;
|
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->get_report_cb = tud_hid_mouse_get_report_cb;
|
||||||
p_hid->set_report_cb = tud_hid_mouse_set_report_cb;
|
p_hid->set_report_cb = tud_hid_mouse_set_report_cb;
|
||||||
}
|
}
|
||||||
#endif
|
#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);
|
VERIFY(p_hid->report_desc, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||||
|
|
||||||
TU_ASSERT( dcd_edpt_open(rhport, desc_edpt), TUSB_ERROR_DCD_FAILED );
|
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->itf_num = desc_itf->bInterfaceNumber;
|
||||||
p_hid->ep_in = desc_edpt->bEndpointAddress;
|
p_hid->ep_in = desc_edpt->bEndpointAddress;
|
||||||
p_hid->report_id = 0;
|
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
|
else
|
||||||
{
|
{
|
||||||
// TODO HID generic
|
// 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
|
// TODO parse report ID for keyboard, mouse
|
||||||
*p_length = 0;
|
p_hid->report_id = 0;
|
||||||
return TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE;
|
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;
|
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 );
|
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);
|
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);
|
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
|
/** \addtogroup ClassDriver_HID_Keyboard Keyboard
|
||||||
* @{ */
|
* @{ */
|
||||||
/** \defgroup Keyboard_Device Device
|
/** \defgroup Keyboard_Device Device
|
||||||
|
@ -78,7 +89,9 @@ typedef struct{
|
||||||
extern const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128];
|
extern const hid_ascii_to_keycode_entry_t HID_ASCII_TO_KEYCODE[128];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*------------- Callbacks, ATTR_WEAK means optional -------------*/
|
#endif
|
||||||
|
|
||||||
|
/*------------- Callbacks -------------*/
|
||||||
|
|
||||||
/** Callback invoked when USB host request \ref HID_REQ_CONTROL_GET_REPORT.
|
/** 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
|
* \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
|
/** \addtogroup ClassDriver_HID_Mouse Mouse
|
||||||
* @{ */
|
* @{ */
|
||||||
/** \defgroup Mouse_Device Device
|
/** \defgroup Mouse_Device Device
|
||||||
|
@ -141,10 +155,10 @@ static inline bool tud_hid_mouse_button_release(void)
|
||||||
|
|
||||||
/*------------- Callbacks -------------*/
|
/*------------- 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[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
|
* \param[in] reqlen number of bytes that host requested
|
||||||
* \retval non-zero Actual number of bytes in the response's buffer.
|
* \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
|
* \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);
|
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] report_type specify which report (INPUT, OUTPUT, FEATURE) that host requests
|
||||||
* \param[in] buffer buffer containing the report's data
|
* \param[in] buffer buffer containing the report's data
|
||||||
* \param[in] bufsize number of bytes in the \a p_report_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);
|
//ATTR_WEAK void tud_hid_mouse_set_protocol_cb(bool boot_protocol);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// USBD-CLASS DRIVER API
|
// INTERNAL API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
#ifdef _TINY_USB_SOURCE_FILE_
|
#ifdef _TINY_USB_SOURCE_FILE_
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,8 @@
|
||||||
ENTRY(TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED )\
|
ENTRY(TUSB_ERROR_USBD_DEVICE_NOT_CONFIGURED )\
|
||||||
ENTRY(TUSB_ERROR_NOT_ENOUGH_MEMORY )\
|
ENTRY(TUSB_ERROR_NOT_ENOUGH_MEMORY )\
|
||||||
ENTRY(TUSB_ERROR_FAILED )\
|
ENTRY(TUSB_ERROR_FAILED )\
|
||||||
|
\
|
||||||
|
ENTRY(ERR_TUD_INVALID_DESCRIPTOR)
|
||||||
|
|
||||||
|
|
||||||
/// \brief Error Code returned
|
/// \brief Error Code returned
|
||||||
|
|
|
@ -116,7 +116,7 @@ static usbd_class_driver_t const usbd_class_drivers[] =
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if TUD_OPT_HID_ENABLED
|
#if CFG_TUD_HID
|
||||||
{
|
{
|
||||||
.class_code = TUSB_CLASS_HID,
|
.class_code = TUSB_CLASS_HID,
|
||||||
.init = hidd_init,
|
.init = hidd_init,
|
||||||
|
@ -318,12 +318,12 @@ static void usbd_reset(uint8_t rhport)
|
||||||
tud_desc_set.device = (uint8_t const*) &_desc_auto_device;
|
tud_desc_set.device = (uint8_t const*) &_desc_auto_device;
|
||||||
tud_desc_set.config = _desc_auto_config;
|
tud_desc_set.config = _desc_auto_config;
|
||||||
|
|
||||||
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_DESC_BOOT_KEYBOARD
|
||||||
extern uint8_t const _desc_auto_hid_kbd_report[];
|
extern uint8_t const _desc_auto_hid_kbd_report[];
|
||||||
tud_desc_set.hid_report.boot_keyboard = _desc_auto_hid_kbd_report;
|
tud_desc_set.hid_report.boot_keyboard = _desc_auto_hid_kbd_report;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
|
#if CFG_TUD_HID_MOUSE && CFG_TUD_DESC_BOOT_MOUSE
|
||||||
extern uint8_t const _desc_auto_hid_mse_report[];
|
extern uint8_t const _desc_auto_hid_mse_report[];
|
||||||
tud_desc_set.hid_report.boot_mouse = _desc_auto_hid_mse_report;
|
tud_desc_set.hid_report.boot_mouse = _desc_auto_hid_mse_report;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -66,7 +66,7 @@ typedef struct {
|
||||||
uint16_t string_count;
|
uint16_t string_count;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint8_t const* composite;
|
uint8_t const* generic;
|
||||||
uint8_t const* boot_keyboard;
|
uint8_t const* boot_keyboard;
|
||||||
uint8_t const* boot_mouse;
|
uint8_t const* boot_mouse;
|
||||||
} hid_report;
|
} hid_report;
|
||||||
|
|
|
@ -47,9 +47,13 @@
|
||||||
|
|
||||||
#if CFG_TUD_DESC_AUTO
|
#if CFG_TUD_DESC_AUTO
|
||||||
|
|
||||||
|
// Generic (multiple) Report : Keyboard + Mouse + Gamepad + Joystick
|
||||||
|
#define HID_GENERIC (CFG_TUD_HID && ( (CFG_TUD_HID_KEYBOARD && !CFG_TUD_DESC_BOOT_KEYBOARD) || \
|
||||||
|
(CFG_TUD_HID_MOUSE && !CFG_TUD_DESC_BOOT_MOUSE) ))
|
||||||
|
|
||||||
/*------------- VID/PID -------------*/
|
/*------------- VID/PID -------------*/
|
||||||
#ifndef CFG_TUD_DESC_VID
|
#ifndef CFG_TUD_DESC_VID
|
||||||
#define CFG_TUD_DESC_VID 0xCAFE
|
#define CFG_TUD_DESC_VID 0xCAFE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CFG_TUD_DESC_PID
|
#ifndef CFG_TUD_DESC_PID
|
||||||
|
@ -58,11 +62,11 @@
|
||||||
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
|
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
|
||||||
*
|
*
|
||||||
* Auto ProductID layout's Bitmap:
|
* Auto ProductID layout's Bitmap:
|
||||||
* [MSB] HID Generic | HID Composite | HID Mouse | HID Keyboard | MSC | CDC [LSB]
|
* [MSB] HID Generic | Boot Mouse | Boot Keyboard | MSC | CDC [LSB]
|
||||||
*/
|
*/
|
||||||
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
|
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
|
||||||
#define CFG_TUD_DESC_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | \
|
#define CFG_TUD_DESC_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
|
||||||
_PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) /*| _PID_MAP(HID_GENERIC, 5)*/ )
|
_PID_MAP(HID_KEYBOARD, 2) | _PID_MAP(HID_MOUSE, 3) | (HID_GENERIC << 4) )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*------------- Interface Numbering -------------*/
|
/*------------- Interface Numbering -------------*/
|
||||||
|
@ -76,8 +80,8 @@
|
||||||
#define ITF_NUM_HID_KBD (ITF_NUM_MSC + CFG_TUD_MSC)
|
#define ITF_NUM_HID_KBD (ITF_NUM_MSC + CFG_TUD_MSC)
|
||||||
#define ITF_NUM_HID_MSE (ITF_NUM_HID_KBD + CFG_TUD_HID_KEYBOARD)
|
#define ITF_NUM_HID_MSE (ITF_NUM_HID_KBD + CFG_TUD_HID_KEYBOARD)
|
||||||
|
|
||||||
#define ITF_TOTAL (ITF_NUM_HID_MSE + CFG_TUD_HID_MOUSE)
|
#define ITF_NUM_HID_GEN (ITF_NUM_HID_MSE + CFG_TUD_HID_MOUSE)
|
||||||
|
#define ITF_TOTAL (ITF_NUM_HID_GEN + HID_GENERIC)
|
||||||
|
|
||||||
/*------------- Endpoint Numbering & Size -------------*/
|
/*------------- Endpoint Numbering & Size -------------*/
|
||||||
#define _EP_IN(x) (0x80 | (x))
|
#define _EP_IN(x) (0x80 | (x))
|
||||||
|
@ -96,23 +100,24 @@
|
||||||
|
|
||||||
|
|
||||||
// HID Keyboard with boot protocol
|
// HID Keyboard with boot protocol
|
||||||
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_DESC_BOOT_KEYBOARD
|
||||||
#define EP_HID_KBD_BOOT _EP_IN (ITF_NUM_HID_KBD+1)
|
#define EP_HID_KBD_BOOT _EP_IN (ITF_NUM_HID_KBD+1)
|
||||||
#define EP_HID_KBD_BOOT_SZ 8
|
#define EP_HID_KBD_BOOT_SZ 8
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// HID Mouse with boot protocol
|
// HID Mouse with boot protocol
|
||||||
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
|
#if CFG_TUD_HID_MOUSE && CFG_TUD_DESC_BOOT_MOUSE
|
||||||
#define EP_HID_MSE_BOOT _EP_IN (ITF_NUM_HID_MSE+1)
|
#define EP_HID_MSE_BOOT _EP_IN (ITF_NUM_HID_MSE+1)
|
||||||
#define EP_HID_MSE_BOOT_SZ 8
|
#define EP_HID_MSE_BOOT_SZ 8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0 // CFG_TUD_HID_BOOT_PROTOCOL
|
|
||||||
|
|
||||||
|
#if HID_GENERIC
|
||||||
|
|
||||||
// HID composite = keyboard + mouse
|
// HID composite = keyboard + mouse
|
||||||
#define EP_HID_COMP _EP_IN (ITF_NUM_HID_KBD+1)
|
#define EP_HID_GEN _EP_IN (EP_HID_MSE_BOOT+1)
|
||||||
#define EP_HID_COMP_SIZE 16
|
#define EP_HID_GEN_SIZE 16
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -307,7 +312,7 @@ typedef struct ATTR_PACKED
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//------------- HID -------------//
|
//------------- HID -------------//
|
||||||
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_DESC_BOOT_KEYBOARD
|
||||||
struct ATTR_PACKED
|
struct ATTR_PACKED
|
||||||
{
|
{
|
||||||
tusb_desc_interface_t itf;
|
tusb_desc_interface_t itf;
|
||||||
|
@ -316,7 +321,7 @@ typedef struct ATTR_PACKED
|
||||||
} hid_kbd_boot;
|
} hid_kbd_boot;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
|
#if CFG_TUD_HID_MOUSE && CFG_TUD_DESC_BOOT_MOUSE
|
||||||
struct ATTR_PACKED
|
struct ATTR_PACKED
|
||||||
{
|
{
|
||||||
tusb_desc_interface_t itf;
|
tusb_desc_interface_t itf;
|
||||||
|
@ -325,20 +330,18 @@ typedef struct ATTR_PACKED
|
||||||
} hid_mse_boot;
|
} hid_mse_boot;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 0 // CFG_TUD_HID_BOOT_PROTOCOL
|
#if HID_GENERIC
|
||||||
|
|
||||||
#if CFG_TUD_HID_KEYBOARD || CFG_TUD_HID_MOUSE
|
|
||||||
struct ATTR_PACKED
|
struct ATTR_PACKED
|
||||||
{
|
{
|
||||||
tusb_desc_interface_t itf;
|
tusb_desc_interface_t itf;
|
||||||
tusb_hid_descriptor_hid_t hid_desc;
|
tusb_hid_descriptor_hid_t hid_desc;
|
||||||
tusb_desc_endpoint_t ep_in;
|
tusb_desc_endpoint_t ep_in;
|
||||||
|
|
||||||
#if CFG_TUD_HID_KEYBOARD
|
#if 0 // CFG_TUD_HID_KEYBOARD
|
||||||
tusb_desc_endpoint_t ep_out;
|
tusb_desc_endpoint_t ep_out;
|
||||||
#endif
|
#endif
|
||||||
} hid_composite;
|
} hid_generic;
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -513,7 +516,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||||
},
|
},
|
||||||
#endif // msc
|
#endif // msc
|
||||||
|
|
||||||
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_HID_KEYBOARD_BOOT
|
#if CFG_TUD_HID_KEYBOARD && CFG_TUD_DESC_BOOT_KEYBOARD
|
||||||
.hid_kbd_boot =
|
.hid_kbd_boot =
|
||||||
{
|
{
|
||||||
.itf =
|
.itf =
|
||||||
|
@ -553,7 +556,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||||
#endif // boot keyboard
|
#endif // boot keyboard
|
||||||
|
|
||||||
//------------- HID Mouse -------------//
|
//------------- HID Mouse -------------//
|
||||||
#if CFG_TUD_HID_MOUSE && CFG_TUD_HID_MOUSE_BOOT
|
#if CFG_TUD_HID_MOUSE && CFG_TUD_DESC_BOOT_MOUSE
|
||||||
.hid_mse_boot =
|
.hid_mse_boot =
|
||||||
{
|
{
|
||||||
.itf =
|
.itf =
|
||||||
|
@ -593,23 +596,22 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||||
|
|
||||||
#endif // boot mouse
|
#endif // boot mouse
|
||||||
|
|
||||||
#if 0
|
#if HID_GENERIC
|
||||||
|
|
||||||
#if CFG_TUD_HID_KEYBOARD || CFG_TUD_HID_MOUSE
|
//------------- HID Generic Multiple report -------------//
|
||||||
//------------- HID Keyboard + Mouse (multiple reports) -------------//
|
|
||||||
.hid_composite =
|
.hid_composite =
|
||||||
{
|
{
|
||||||
.itf =
|
.itf =
|
||||||
{
|
{
|
||||||
.bLength = sizeof(tusb_desc_interface_t),
|
.bLength = sizeof(tusb_desc_interface_t),
|
||||||
.bDescriptorType = TUSB_DESC_INTERFACE,
|
.bDescriptorType = TUSB_DESC_INTERFACE,
|
||||||
.bInterfaceNumber = ITF_NUM_HID_KBD,
|
.bInterfaceNumber = ITF_NUM_HID_GEN,
|
||||||
.bAlternateSetting = 0x00,
|
.bAlternateSetting = 0x00,
|
||||||
.bNumEndpoints = 2,
|
.bNumEndpoints = 2,
|
||||||
.bInterfaceClass = TUSB_CLASS_HID,
|
.bInterfaceClass = TUSB_CLASS_HID,
|
||||||
.bInterfaceSubClass = 0,
|
.bInterfaceSubClass = 0,
|
||||||
.bInterfaceProtocol = 0,
|
.bInterfaceProtocol = 0,
|
||||||
.iInterface = 4 + CFG_TUD_CDC + CFG_TUD_MSC,
|
.iInterface = 0, // 4 + CFG_TUD_CDC + CFG_TUD_MSC,
|
||||||
},
|
},
|
||||||
|
|
||||||
.hid_desc =
|
.hid_desc =
|
||||||
|
@ -620,41 +622,26 @@ desc_auto_cfg_t const _desc_auto_config_struct =
|
||||||
.bCountryCode = HID_Local_NotSupported,
|
.bCountryCode = HID_Local_NotSupported,
|
||||||
.bNumDescriptors = 1,
|
.bNumDescriptors = 1,
|
||||||
.bReportType = HID_DESC_TYPE_REPORT,
|
.bReportType = HID_DESC_TYPE_REPORT,
|
||||||
.wReportLength = sizeof(_desc_auto_hid_composite_report)
|
.wReportLength = sizeof(_desc_auto_hid_generic_report)
|
||||||
},
|
},
|
||||||
|
|
||||||
.ep_in =
|
.ep_in =
|
||||||
{
|
{
|
||||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||||
.bEndpointAddress = EP_HID_COMP,
|
.bEndpointAddress = EP_HID_GEN,
|
||||||
.bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
|
.bmAttributes = { .xfer = TUSB_XFER_INTERRUPT },
|
||||||
.wMaxPacketSize = { .size = EP_HID_COMP_SIZE },
|
.wMaxPacketSize = { .size = EP_HID_GEN_SIZE },
|
||||||
.bInterval = 0x0A
|
.bInterval = 0x0A
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // boot protocol
|
#endif // hid generic
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t const * const _desc_auto_config = (uint8_t const*) &_desc_auto_config_struct;
|
uint8_t const * const _desc_auto_config = (uint8_t const*) &_desc_auto_config_struct;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
|
||||||
/* MACRO TYPEDEF CONSTANT ENUM
|
|
||||||
*------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
|
||||||
/* VARIABLE DECLARATION
|
|
||||||
*------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*/
|
|
||||||
/* FUNCTION DECLARATION
|
|
||||||
*------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -76,7 +76,7 @@
|
||||||
#if TUSB_OPT_DEVICE_ENABLED
|
#if TUSB_OPT_DEVICE_ENABLED
|
||||||
#include "device/usbd.h"
|
#include "device/usbd.h"
|
||||||
|
|
||||||
#if TUD_OPT_HID_ENABLED
|
#if CFG_TUD_HID
|
||||||
#include "class/hid/hid_device.h"
|
#include "class/hid/hid_device.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -151,8 +151,6 @@
|
||||||
//--------------------------------------------------------------------
|
//--------------------------------------------------------------------
|
||||||
#if TUSB_OPT_DEVICE_ENABLED
|
#if TUSB_OPT_DEVICE_ENABLED
|
||||||
|
|
||||||
#define TUD_OPT_HID_ENABLED ( CFG_TUD_HID_KEYBOARD + CFG_TUD_HID_MOUSE )
|
|
||||||
|
|
||||||
#ifndef CFG_TUD_ENDOINT0_SIZE
|
#ifndef CFG_TUD_ENDOINT0_SIZE
|
||||||
#define CFG_TUD_ENDOINT0_SIZE 64
|
#define CFG_TUD_ENDOINT0_SIZE 64
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -87,7 +87,7 @@ tusb_error_t stub_hidd_init(uint8_t coreid, tusb_desc_interface_t const* p_inter
|
||||||
|
|
||||||
void class_init_epxect(void)
|
void class_init_epxect(void)
|
||||||
{
|
{
|
||||||
#if TUD_OPT_HID_ENABLED
|
#if CFG_TUD_HID
|
||||||
hidd_init_StubWithCallback(stub_hidd_init);
|
hidd_init_StubWithCallback(stub_hidd_init);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue