more hub improve, handle more failed transfer with polling interrupt status endpoint

This commit is contained in:
hathach
2025-02-19 15:50:42 +07:00
parent 27a4895b79
commit 70ddb7a867
3 changed files with 123 additions and 128 deletions

View File

@@ -41,58 +41,9 @@
#define CFG_TUH_HUB_BUFSIZE 12
#endif
//D1...D0: Logical Power Switching Mode
//00: Ganged power switching (all portspower at
//once)
//01: Individual port power switching
//1X: Reserved. Used only on 1.0 compliant hubs
//that implement no power switching
//D2: Identifies a Compound Device
//0: Hub is not part of a compound device.
//1: Hub is part of a compound device.
//D4...D3: Over-current Protection Mode
//00: Global Over-current Protection. The hub
//reports over-current as a summation of all
//portscurrent draw, without a breakdown of
//individual port over-current status.
//01: Individual Port Over-current Protection. The
//hub reports over-current on a per-port basis.
//Each port has an over-current status.
//1X: No Over-current Protection. This option is
//allowed only for bus-powered hubs that do not
//implement over-current protection.
//--------------------------------------------------------------------+
//
//D6...D5: TT Think TIme
//00: TT requires at most 8 FS bit times of inter
//transaction gap on a full-/low-speed
//downstream bus.
//01: TT requires at most 16 FS bit times.
//10: TT requires at most 24 FS bit times.
//11: TT requires at most 32 FS bit times.
//D7: Port Indicators Supported
//0: Port Indicators are not supported on its
//downstream facing ports and the
//PORT_INDICATOR request has no effect.
//1: Port Indicators are supported on its
//downstream facing ports and the
//PORT_INDICATOR request controls the
//indicators. See Section 11.5.3.
//D15...D8: Reserved
typedef struct TU_ATTR_PACKED{
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint8_t bNbrPorts;
uint16_t wHubCharacteristics;
uint8_t bPwrOn2PwrGood;
uint8_t bHubContrCurrent;
uint8_t DeviceRemovable; // bitmap each bit for a port (from bit1)
uint8_t PortPwrCtrlMask; // just for compatibility, should be 0xff
} hub_desc_cs_t;
TU_VERIFY_STATIC(sizeof(hub_desc_cs_t) == 9, "size is not correct");
TU_VERIFY_STATIC(CFG_TUH_HUB_BUFSIZE >= sizeof(hub_desc_cs_t), "buffer is not big enough");
//--------------------------------------------------------------------+
enum {
HUB_REQUEST_GET_STATUS = 0 ,
HUB_REQUEST_CLEAR_FEATURE = 1 ,
@@ -131,6 +82,41 @@ enum{
HUB_FEATURE_PORT_INDICATOR = 22
};
enum {
HUB_CHARS_POWER_GANGED_SWITCHING = 0,
HUB_CHARS_POWER_INDIVIDUAL_SWITCHING = 1,
};
enum {
HUB_CHARS_OVER_CURRENT_GLOBAL = 0,
HUB_CHARS_OVER_CURRENT_INDIVIDUAL = 1,
};
typedef struct TU_ATTR_PACKED{
uint8_t bLength ; ///< Size of descriptor
uint8_t bDescriptorType ; ///< Other_speed_Configuration Type
uint8_t bNbrPorts;
uint16_t wHubCharacteristics;
uint8_t bPwrOn2PwrGood;
uint8_t bHubContrCurrent;
uint8_t DeviceRemovable; // bitmap each bit for a port (from bit1)
uint8_t PortPwrCtrlMask; // just for compatibility, should be 0xff
} hub_desc_cs_t;
TU_VERIFY_STATIC(sizeof(hub_desc_cs_t) == 9, "size is not correct");
TU_VERIFY_STATIC(CFG_TUH_HUB_BUFSIZE >= sizeof(hub_desc_cs_t), "buffer is not big enough");
typedef struct TU_ATTR_PACKED {
struct TU_ATTR_PACKED {
uint8_t logical_power_switching_mode : 2; // [0..1] gannged or individual power switching
uint8_t compound_device : 1; // [2] hub is part of compound device
uint8_t over_current_protect_mode : 2; // [3..4] global or individual port over-current protection
uint8_t tt_think_time : 2; // [5..6] TT think time
uint8_t port_indicator_supported : 1; // [7] port indicator supported
};
uint8_t rsv1;
} hub_characteristics_t;
TU_VERIFY_STATIC(sizeof(hub_characteristics_t) == 2, "size is not correct");
// data in response of HUB_REQUEST_GET_STATUS, wIndex = 0 (hub)
typedef struct {
union{
@@ -143,19 +129,20 @@ typedef struct {
uint16_t value;
} status, change;
} hub_status_response_t;
TU_VERIFY_STATIC( sizeof(hub_status_response_t) == 4, "size is not correct");
// data in response of HUB_REQUEST_GET_STATUS, wIndex = Port num
typedef struct {
union TU_ATTR_PACKED {
struct TU_ATTR_PACKED {
// Bit 0-4 are for change & status
uint16_t connection : 1; // [0] 0 = no device, 1 = device connected
uint16_t port_enable : 1; // [1] port is enabled
uint16_t suspend : 1; // [2]
uint16_t over_current : 1; // [3] over-current exists
uint16_t reset : 1; // [4] 0 = no reset, 1 = resetting
// From Bit 5 are for status only
uint16_t rsv5_7 : 3; // [5..7] reserved
uint16_t port_power : 1; // [8] 0 = port is off, 1 = port is on
uint16_t low_speed : 1; // [9] low speed device attached
@@ -168,7 +155,6 @@ typedef struct {
uint16_t value;
} status, change;
} hub_port_status_response_t;
TU_VERIFY_STATIC( sizeof(hub_port_status_response_t) == 4, "size is not correct");
//--------------------------------------------------------------------+
@@ -220,7 +206,7 @@ bool hub_init (void);
bool hub_deinit (void);
bool hub_open (uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len);
bool hub_set_config (uint8_t dev_addr, uint8_t itf_num);
bool hub_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
bool hub_xfer_cb (uint8_t daddr, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes);
void hub_close (uint8_t dev_addr);
#ifdef __cplusplus