refractor descriptor passing for device with user-friendly structures
This commit is contained in:
@@ -46,7 +46,6 @@
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "tusb.h"
|
||||
#include "tusb_descriptors.h" // TODO callback include
|
||||
#include "usbd_dcd.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -270,6 +269,10 @@ tusb_error_t usbd_init (void)
|
||||
|
||||
ASSERT_STATUS( osal_task_create( OSAL_TASK_REF(usbd_task) ));
|
||||
|
||||
//------------- Descriptor Check -------------//
|
||||
ASSERT_PTR(tusbd_descriptor_pointers.p_device, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||
ASSERT_PTR(tusbd_descriptor_pointers.p_configuration, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||
|
||||
//------------- class init -------------//
|
||||
for (uint8_t class_code = TUSB_CLASS_AUDIO; class_code < USBD_CLASS_DRIVER_COUNT; class_code++)
|
||||
{
|
||||
@@ -293,7 +296,7 @@ static tusb_error_t usbd_set_configure_received(uint8_t coreid, uint8_t config_n
|
||||
usbd_devices[coreid].state = TUSB_DEVICE_STATE_CONFIGURED;
|
||||
|
||||
//------------- parse configuration & open drivers -------------//
|
||||
uint8_t* p_desc_configure = (uint8_t*) &tusbd_descriptor_configuration;
|
||||
uint8_t* p_desc_configure = tusbd_descriptor_pointers.p_configuration;
|
||||
uint8_t* p_desc = p_desc_configure + sizeof(tusb_descriptor_configuration_t);
|
||||
|
||||
while( p_desc < p_desc_configure + ((tusb_descriptor_configuration_t*)p_desc_configure)->wTotalLength )
|
||||
@@ -333,19 +336,19 @@ static tusb_error_t get_descriptor(uint8_t coreid, tusb_control_request_t const
|
||||
|
||||
if ( TUSB_DESC_TYPE_DEVICE == desc_type )
|
||||
{
|
||||
(*pp_buffer) = (uint8_t *) &tusbd_descriptor_device;
|
||||
(*pp_buffer) = tusbd_descriptor_pointers.p_device;
|
||||
(*p_length) = sizeof(tusb_descriptor_device_t);
|
||||
}
|
||||
else if ( TUSB_DESC_TYPE_CONFIGURATION == desc_type )
|
||||
{
|
||||
(*pp_buffer) = (uint8_t *) &tusbd_descriptor_configuration;
|
||||
(*p_length) = sizeof(tusbd_descriptor_configuration);
|
||||
(*pp_buffer) = tusbd_descriptor_pointers.p_configuration;
|
||||
(*p_length) = ((tusb_descriptor_configuration_t*)tusbd_descriptor_pointers.p_configuration)->wTotalLength;
|
||||
}
|
||||
else if ( TUSB_DESC_TYPE_STRING == desc_type )
|
||||
{
|
||||
if ( ! (desc_index < TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT) ) return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
|
||||
|
||||
(*pp_buffer) = (uint8_t *) tusbd_descriptor_string_table[desc_index];
|
||||
(*pp_buffer) = tusbd_descriptor_pointers.p_string_arr[desc_index];
|
||||
(*p_length) = **pp_buffer;
|
||||
}else
|
||||
{
|
||||
|
||||
@@ -43,17 +43,19 @@
|
||||
#ifndef _TUSB_USBD_H_
|
||||
#define _TUSB_USBD_H_
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "common/common.h"
|
||||
#include "osal/osal.h"
|
||||
#include "dcd.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include "common/common.h"
|
||||
#include "dcd.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
// LPC11uxx and LPC13uxx requires each buffer has to be 64-byte alignment
|
||||
#if TUSB_CFG_MCU == MCU_LPC11UXX || TUSB_CFG_MCU == MCU_LPC13UXX
|
||||
#define ATTR_USB_MIN_ALIGNMENT ATTR_ALIGNED(64)
|
||||
@@ -61,9 +63,18 @@
|
||||
#define ATTR_USB_MIN_ALIGNMENT
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
uint8_t * p_device;
|
||||
uint8_t * p_configuration;
|
||||
uint8_t * p_string_arr[TUSB_CFG_DEVICE_STRING_DESCRIPTOR_COUNT];
|
||||
|
||||
uint8_t * p_hid_keyboard_report;
|
||||
uint8_t * p_hid_mouse_report;
|
||||
}tusbd_descriptor_pointer_t;
|
||||
|
||||
// define by application
|
||||
extern tusbd_descriptor_pointer_t tusbd_descriptor_pointers;
|
||||
|
||||
typedef struct {
|
||||
void (* const init) (void);
|
||||
tusb_error_t (* const open)(uint8_t, tusb_descriptor_interface_t const *, uint16_t*);
|
||||
|
||||
Reference in New Issue
Block a user