mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-19 06:40:45 +00:00
add tud_hid_descriptor_report_cb()
- remove tud_desc_set.hid_report - remove tud_desc_set_t
This commit is contained in:
parent
de56a0ca89
commit
ba2136486c
@ -79,25 +79,34 @@ uint8_t const desc_hid_report[] =
|
||||
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD), ),
|
||||
TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE), )
|
||||
};
|
||||
|
||||
// Invoked when received GET HID REPORT DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_hid_descriptor_report_cb(void)
|
||||
{
|
||||
return desc_hid_report;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//------------- Configuration Descriptor -------------//
|
||||
enum
|
||||
{
|
||||
#if CFG_TUD_CDC
|
||||
ITF_NUM_CDC = 0,
|
||||
ITF_NUM_CDC_DATA,
|
||||
#endif
|
||||
#if CFG_TUD_CDC
|
||||
ITF_NUM_CDC = 0,
|
||||
ITF_NUM_CDC_DATA,
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MSC
|
||||
ITF_NUM_MSC,
|
||||
#endif
|
||||
#if CFG_TUD_MSC
|
||||
ITF_NUM_MSC,
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID
|
||||
ITF_NUM_HID,
|
||||
#endif
|
||||
#if CFG_TUD_HID
|
||||
ITF_NUM_HID,
|
||||
#endif
|
||||
|
||||
ITF_NUM_TOTAL
|
||||
ITF_NUM_TOTAL
|
||||
};
|
||||
|
||||
enum
|
||||
@ -136,17 +145,20 @@ uint8_t const desc_configuration[] =
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
// tud_desc_set is required by tinyusb stack
|
||||
tud_desc_set_t tud_desc_set =
|
||||
// Invoked when received GET DEVICE DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
uint8_t const * tud_descriptor_device_cb(void)
|
||||
{
|
||||
.device = &desc_device,
|
||||
.config = desc_configuration,
|
||||
return (uint8_t const *) &desc_device;
|
||||
}
|
||||
|
||||
#if CFG_TUD_HID
|
||||
.hid_report = desc_hid_report,
|
||||
#endif
|
||||
};
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_descriptor_configuration_cb(void)
|
||||
{
|
||||
return desc_configuration;
|
||||
}
|
||||
|
||||
//------------- String Descriptors -------------//
|
||||
|
||||
|
@ -79,25 +79,34 @@ uint8_t const desc_hid_report[] =
|
||||
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD), ),
|
||||
TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE), )
|
||||
};
|
||||
|
||||
// Invoked when received GET HID REPORT DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_hid_descriptor_report_cb(void)
|
||||
{
|
||||
return desc_hid_report;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//------------- Configuration Descriptor -------------//
|
||||
enum
|
||||
{
|
||||
#if CFG_TUD_CDC
|
||||
ITF_NUM_CDC = 0,
|
||||
ITF_NUM_CDC_DATA,
|
||||
#endif
|
||||
#if CFG_TUD_CDC
|
||||
ITF_NUM_CDC = 0,
|
||||
ITF_NUM_CDC_DATA,
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_MSC
|
||||
ITF_NUM_MSC,
|
||||
#endif
|
||||
#if CFG_TUD_MSC
|
||||
ITF_NUM_MSC,
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_HID
|
||||
ITF_NUM_HID,
|
||||
#endif
|
||||
#if CFG_TUD_HID
|
||||
ITF_NUM_HID,
|
||||
#endif
|
||||
|
||||
ITF_NUM_TOTAL
|
||||
ITF_NUM_TOTAL
|
||||
};
|
||||
|
||||
enum
|
||||
@ -136,16 +145,20 @@ uint8_t const desc_configuration[] =
|
||||
#endif
|
||||
};
|
||||
|
||||
// tud_desc_set is required by tinyusb stack
|
||||
tud_desc_set_t tud_desc_set =
|
||||
// Invoked when received GET DEVICE DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
uint8_t const * tud_descriptor_device_cb(void)
|
||||
{
|
||||
.device = &desc_device,
|
||||
.config = desc_configuration,
|
||||
return (uint8_t const *) &desc_device;
|
||||
}
|
||||
|
||||
#if CFG_TUD_HID
|
||||
.hid_report = desc_hid_report,
|
||||
#endif
|
||||
};
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_descriptor_configuration_cb(void)
|
||||
{
|
||||
return desc_configuration;
|
||||
}
|
||||
|
||||
//------------- String Descriptors -------------//
|
||||
|
||||
|
@ -89,16 +89,28 @@ uint8_t const desc_configuration[] =
|
||||
};
|
||||
|
||||
|
||||
// tud_desc_set is required by tinyusb stack
|
||||
tud_desc_set_t tud_desc_set =
|
||||
// Invoked when received GET DEVICE DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
uint8_t const * tud_descriptor_device_cb(void)
|
||||
{
|
||||
.device = &desc_device,
|
||||
.config = desc_configuration,
|
||||
return (uint8_t const *) &desc_device;
|
||||
}
|
||||
|
||||
#if CFG_TUD_HID
|
||||
.hid_report = desc_hid_report,
|
||||
#endif
|
||||
};
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_descriptor_configuration_cb(void)
|
||||
{
|
||||
return desc_configuration;
|
||||
}
|
||||
|
||||
// Invoked when received GET HID REPORT DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_hid_descriptor_report_cb(void)
|
||||
{
|
||||
return desc_hid_report;
|
||||
}
|
||||
|
||||
//------------- String Descriptors -------------//
|
||||
|
||||
|
@ -82,17 +82,20 @@ uint8_t const desc_configuration[] =
|
||||
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 0, EPNUM_MSC, 0x80 | EPNUM_MSC, 64), // highspeed 512
|
||||
};
|
||||
|
||||
|
||||
// tud_desc_set is required by tinyusb stack
|
||||
tud_desc_set_t tud_desc_set =
|
||||
// Invoked when received GET DEVICE DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
uint8_t const * tud_descriptor_device_cb(void)
|
||||
{
|
||||
.device = &desc_device,
|
||||
.config = desc_configuration,
|
||||
return (uint8_t const *) &desc_device;
|
||||
}
|
||||
|
||||
#if CFG_TUD_HID
|
||||
.hid_report = desc_hid_report,
|
||||
#endif
|
||||
};
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_descriptor_configuration_cb(void)
|
||||
{
|
||||
return desc_configuration;
|
||||
}
|
||||
|
||||
//------------- String Descriptors -------------//
|
||||
|
||||
|
@ -201,7 +201,8 @@ bool hidd_control_request(uint8_t rhport, tusb_control_request_t const * p_reque
|
||||
|
||||
if (p_request->bRequest == TUSB_REQ_GET_DESCRIPTOR && desc_type == HID_DESC_TYPE_REPORT)
|
||||
{
|
||||
usbd_control_xfer(rhport, p_request, (void*) tud_desc_set.hid_report, p_hid->reprot_desc_len);
|
||||
uint8_t const * desc_report = tud_hid_descriptor_report_cb();
|
||||
usbd_control_xfer(rhport, p_request, (void*) desc_report, p_hid->reprot_desc_len);
|
||||
}else
|
||||
{
|
||||
return false; // stall unsupported request
|
||||
|
@ -68,6 +68,11 @@ bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y
|
||||
// Callbacks (Weak is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when received GET HID REPORT DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_hid_descriptor_report_cb(void);
|
||||
|
||||
// Invoked when received GET_REPORT control request
|
||||
// Application must fill buffer report's content and return its length.
|
||||
// Return zero will cause the stack to STALL request
|
||||
|
@ -479,7 +479,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
// This function parse configuration descriptor & open drivers accordingly
|
||||
static bool process_set_config(uint8_t rhport)
|
||||
{
|
||||
tusb_desc_configuration_t const * desc_cfg = (tusb_desc_configuration_t const *) tud_desc_set.config;
|
||||
tusb_desc_configuration_t const * desc_cfg = (tusb_desc_configuration_t const *) tud_descriptor_configuration_cb();
|
||||
TU_ASSERT(desc_cfg != NULL && desc_cfg->bDescriptorType == TUSB_DESC_CONFIGURATION);
|
||||
|
||||
// Parse configuration descriptor
|
||||
@ -558,11 +558,14 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
|
||||
switch(desc_type)
|
||||
{
|
||||
case TUSB_DESC_DEVICE:
|
||||
return usbd_control_xfer(rhport, p_request, (void*) tud_desc_set.device, sizeof(tusb_desc_device_t));
|
||||
return usbd_control_xfer(rhport, p_request, (void*) tud_descriptor_device_cb(), sizeof(tusb_desc_device_t));
|
||||
break;
|
||||
|
||||
case TUSB_DESC_CONFIGURATION:
|
||||
return usbd_control_xfer(rhport, p_request, (void*) tud_desc_set.config, ((tusb_desc_configuration_t const*) tud_desc_set.config)->wTotalLength);
|
||||
{
|
||||
tusb_desc_configuration_t const* desc_config = (tusb_desc_configuration_t const*) tud_descriptor_configuration_cb();
|
||||
return usbd_control_xfer(rhport, p_request, (void*) desc_config, desc_config->wTotalLength);
|
||||
}
|
||||
break;
|
||||
|
||||
case TUSB_DESC_STRING:
|
||||
|
@ -37,17 +37,6 @@
|
||||
#include "common/tusb_common.h"
|
||||
#include "device/dcd.h"
|
||||
|
||||
/// \brief Descriptor pointer collector to all the needed.
|
||||
typedef struct {
|
||||
void const * device; ///< pointer to device descriptor \ref tusb_desc_device_t
|
||||
void const * config; ///< pointer to the whole configuration descriptor, starting by \ref tusb_desc_configuration_t
|
||||
uint8_t const* hid_report;
|
||||
|
||||
}tud_desc_set_t;
|
||||
|
||||
// Descriptor collection set, must be defined by application
|
||||
extern tud_desc_set_t tud_desc_set;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Application API
|
||||
//--------------------------------------------------------------------+
|
||||
@ -74,9 +63,18 @@ bool tud_remote_wakeup(void);
|
||||
// Application Callbacks (WEAK is optional)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Invoked when received GET_STRING_DESC request
|
||||
// Invoked when received GET DEVICE DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
uint8_t const * tud_descriptor_device_cb(void);
|
||||
|
||||
// Invoked when received GET CONFIGURATION DESCRIPTOR
|
||||
// Application return pointer to descriptor
|
||||
// Descriptor contents must exist long enough for transfer to complete
|
||||
uint8_t const * tud_descriptor_configuration_cb(void);
|
||||
|
||||
// Invoked when received GET STRING DESC request
|
||||
// max_char is CFG_TUD_ENDOINT0_SIZE/2 -1, typically max_char = 31 if Endpoint0 size is 64
|
||||
// Return number of characters. Note usb string is in 16-bits unicode format
|
||||
// Return number of characters. Note usb string is in UTF-16 format
|
||||
uint8_t tud_descriptor_string_cb(uint8_t index, uint16_t* desc, uint8_t max_char);
|
||||
|
||||
// Invoked when device is mounted (configured)
|
||||
|
@ -93,8 +93,10 @@ bool usbd_control_xfer(uint8_t rhport, tusb_control_request_t const * request, v
|
||||
_control_state.total_len = tu_min16(len, request->wLength);
|
||||
_control_state.total_transferred = 0;
|
||||
|
||||
if ( (buffer != NULL) && len )
|
||||
if ( len )
|
||||
{
|
||||
TU_ASSERT(buffer);
|
||||
|
||||
// Data stage
|
||||
TU_ASSERT( start_control_data_xact(rhport) );
|
||||
}else
|
||||
|
Loading…
x
Reference in New Issue
Block a user