add tuh_configure() for port/dynamic host behavior config
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
// #endif
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
typedef enum
|
||||
@@ -106,6 +106,9 @@ typedef struct
|
||||
// Controller API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// optional hcd configuration, called by tuh_config()
|
||||
bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) TU_ATTR_WEAK;
|
||||
|
||||
// Initialize controller to host mode
|
||||
bool hcd_init(uint8_t rhport);
|
||||
|
||||
|
||||
@@ -274,9 +274,32 @@ static void process_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t h
|
||||
static bool usbh_edpt_control_open(uint8_t dev_addr, uint8_t max_packet_size);
|
||||
static bool usbh_control_xfer_cb (uint8_t daddr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes);
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
// TODO rework time-related function later
|
||||
void osal_task_delay(uint32_t msec)
|
||||
{
|
||||
(void) msec;
|
||||
|
||||
const uint32_t start = hcd_frame_number(TUH_OPT_RHPORT);
|
||||
while ( ( hcd_frame_number(TUH_OPT_RHPORT) - start ) < msec ) {}
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PUBLIC API (Parameter Verification is required)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
bool tuh_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param)
|
||||
{
|
||||
if (hcd_configure)
|
||||
{
|
||||
return hcd_configure(rhport, cfg_id, cfg_param);
|
||||
}else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool tuh_mounted(uint8_t dev_addr)
|
||||
{
|
||||
usbh_device_t* dev = get_device(dev_addr);
|
||||
@@ -303,20 +326,6 @@ tusb_speed_t tuh_speed_get (uint8_t dev_addr)
|
||||
return (tusb_speed_t) (dev ? get_device(dev_addr)->speed : _dev0.speed);
|
||||
}
|
||||
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE
|
||||
void osal_task_delay(uint32_t msec)
|
||||
{
|
||||
(void) msec;
|
||||
|
||||
const uint32_t start = hcd_frame_number(TUH_OPT_RHPORT);
|
||||
while ( ( hcd_frame_number(TUH_OPT_RHPORT) - start ) < msec ) {}
|
||||
}
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CLASS-USBD API (don't require to verify parameters)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static void clear_device(usbh_device_t* dev)
|
||||
{
|
||||
tu_memclr(dev, sizeof(usbh_device_t));
|
||||
@@ -334,7 +343,7 @@ bool tuh_init(uint8_t rhport)
|
||||
// skip if already initialized
|
||||
if (_usbh_initialized) return _usbh_initialized;
|
||||
|
||||
TU_LOG2("USBH init\r\n");
|
||||
TU_LOG2("USBH init rhport %u\r\n", rhport);
|
||||
TU_LOG2_INT(sizeof(usbh_device_t));
|
||||
TU_LOG2_INT(sizeof(hcd_event_t));
|
||||
TU_LOG2_INT(sizeof(_ctrl_xfer));
|
||||
|
||||
@@ -46,8 +46,8 @@ typedef void (*tuh_xfer_cb_t)(tuh_xfer_t* xfer);
|
||||
|
||||
// Note1: layout and order of this will be changed in near future
|
||||
// it is advised to initialize it using member name
|
||||
// Note2: not all field is available/meaningful in callback, some info is not saved by
|
||||
// usbh to save SRAM
|
||||
// Note2: not all field is available/meaningful in callback,
|
||||
// some info is not saved by usbh to save SRAM
|
||||
struct tuh_xfer_s
|
||||
{
|
||||
uint8_t daddr;
|
||||
@@ -69,6 +69,12 @@ struct tuh_xfer_s
|
||||
// uint32_t timeout_ms; // place holder, not supported yet
|
||||
};
|
||||
|
||||
// ConfigID for tuh_config()
|
||||
enum
|
||||
{
|
||||
TUH_CFGID_RPI_PIO_USB_CONFIGURATION = OPT_MCU_RP2040 // cfg_param: pio_usb_configuration_t
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CALLBACK
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -85,6 +91,12 @@ TU_ATTR_WEAK void tuh_umount_cb(uint8_t daddr);
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// Configure host stack behavior with dynamic or port-specific parameters.
|
||||
// Should be called before tuh_init()
|
||||
// - cfg_id : configure ID (TBD)
|
||||
// - cfg_param: configure data, structure depends on the ID
|
||||
bool tuh_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param);
|
||||
|
||||
// Init host stack
|
||||
bool tuh_init(uint8_t rhport);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user