summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/class/hid/hid_device.c3
-rw-r--r--src/class/hid/hid_device.h5
-rw-r--r--src/device/usbd.c9
-rw-r--r--src/device/usbd.h24
-rw-r--r--src/device/usbd_control.c4
5 files changed, 27 insertions, 18 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index e82932e1f..1c971a606 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -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
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h
index 825be2181..9becab148 100644
--- a/src/class/hid/hid_device.h
+++ b/src/class/hid/hid_device.h
@@ -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
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 8812a70f4..64ed7668e 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -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:
diff --git a/src/device/usbd.h b/src/device/usbd.h
index 0e7ed58f1..f8485166d 100644
--- a/src/device/usbd.h
+++ b/src/device/usbd.h
@@ -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)
diff --git a/src/device/usbd_control.c b/src/device/usbd_control.c
index 31f447c03..0b878fbcb 100644
--- a/src/device/usbd_control.c
+++ b/src/device/usbd_control.c
@@ -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