mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
Adjust logic.
This commit is contained in:
parent
0fce7d1f54
commit
e250b82377
@ -195,6 +195,7 @@
|
||||
#elif TU_CHECK_MCU(OPT_MCU_STM32F4)
|
||||
#define TUP_USBIP_DWC2
|
||||
#define TUP_USBIP_DWC2_STM32
|
||||
#define TUP_USBIP_DWC2_TEST_MODE
|
||||
|
||||
// For most mcu, FS has 4, HS has 6. TODO 446/469/479 HS has 9
|
||||
#define TUP_DCD_ENDPOINT_MAX 6
|
||||
@ -209,7 +210,7 @@
|
||||
// MCU with on-chip HS Phy
|
||||
#if defined(STM32F723xx) || defined(STM32F730xx) || defined(STM32F733xx)
|
||||
#define TUP_RHPORT_HIGHSPEED 1 // Port0: FS, Port1: HS
|
||||
#define TUP_USBIP_DWC2_TEST_MODE_SUPPORT
|
||||
#define TUP_USBIP_DWC2_TEST_MODE
|
||||
#endif
|
||||
|
||||
#elif TU_CHECK_MCU(OPT_MCU_STM32H7)
|
||||
@ -278,7 +279,7 @@
|
||||
defined(STM32U5F7xx) || defined(STM32U5F9xx) || defined(STM32U5G7xx) || defined(STM32U5G9xx)
|
||||
#define TUP_DCD_ENDPOINT_MAX 9
|
||||
#define TUP_RHPORT_HIGHSPEED 1
|
||||
#define TUP_USBIP_DWC2_TEST_MODE_SUPPORT
|
||||
#define TUP_USBIP_DWC2_TEST_MODE
|
||||
#else
|
||||
#define TUP_DCD_ENDPOINT_MAX 6
|
||||
#endif
|
||||
|
@ -97,8 +97,7 @@ typedef struct TU_ATTR_ALIGNED(4) {
|
||||
};
|
||||
} dcd_event_t;
|
||||
|
||||
typedef enum _test_mode_selector
|
||||
{
|
||||
typedef enum {
|
||||
TEST_J = 1,
|
||||
TEST_K,
|
||||
TEST_SE0_NAK,
|
||||
@ -158,12 +157,13 @@ void dcd_disconnect(uint8_t rhport) TU_ATTR_WEAK;
|
||||
// Enable/Disable Start-of-frame interrupt. Default is disabled
|
||||
void dcd_sof_enable(uint8_t rhport, bool en);
|
||||
|
||||
#if CFG_TUD_TEST_MODE
|
||||
// Check if the test mode is supported, returns true is test mode selector is supported
|
||||
bool dcd_check_test_mode_support(test_mode_t test_selector) TU_ATTR_WEAK;
|
||||
|
||||
// Put device into a test mode (needs power cycle to quit)
|
||||
void dcd_enter_test_mode(uint8_t rhport, test_mode_t test_selector) TU_ATTR_WEAK;
|
||||
|
||||
#endif
|
||||
//--------------------------------------------------------------------+
|
||||
// Endpoint API
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -313,8 +313,9 @@ TU_ATTR_ALWAYS_INLINE static inline bool queue_event(dcd_event_t const * event,
|
||||
static bool process_control_request(uint8_t rhport, tusb_control_request_t const * p_request);
|
||||
static bool process_set_config(uint8_t rhport, uint8_t cfg_num);
|
||||
static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const * p_request);
|
||||
#if CFG_TUD_TEST_MODE
|
||||
static bool process_test_mode_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
|
||||
|
||||
#endif
|
||||
// from usbd_control.c
|
||||
void usbd_control_reset(void);
|
||||
void usbd_control_set_request(tusb_control_request_t const *request);
|
||||
@ -766,16 +767,16 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
tud_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
#if !defined(TUSB_NO_TEST_MODE_SUPPORT)
|
||||
#if CFG_TUD_TEST_MODE
|
||||
// Support for TEST_MODE
|
||||
case TUSB_REQ_FEATURE_TEST_MODE:
|
||||
case TUSB_REQ_FEATURE_TEST_MODE: {
|
||||
// Only handle the test mode if supported and valid
|
||||
TU_VERIFY(dcd_enter_test_mode && dcd_check_test_mode_support && 0 == tu_u16_low(p_request->wIndex));
|
||||
|
||||
uint8_t selector = tu_u16_high(p_request->wIndex);
|
||||
|
||||
// Stall request if the selected test mode isn't supported
|
||||
if (!dcd_check_test_mode_support(selector))
|
||||
if (!dcd_check_test_mode_support((test_mode_t)selector))
|
||||
{
|
||||
TU_LOG_USBD(" Unsupported Test Mode (test selector index: %d)\r\n", selector);
|
||||
|
||||
@ -788,8 +789,9 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
TU_LOG_USBD(" Enter Test Mode (test selector index: %d)\r\n", selector);
|
||||
|
||||
usbd_control_set_complete_callback(process_test_mode_cb);
|
||||
break;
|
||||
#endif /* !TUSB_NO_TEST_MODE_SUPPORT */
|
||||
break;
|
||||
}
|
||||
#endif /* CFG_TUD_TEST_MODE */
|
||||
|
||||
// Stall unsupported feature selector
|
||||
default: return false;
|
||||
@ -1121,7 +1123,7 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(TUSB_NO_TEST_MODE_SUPPORT)
|
||||
#if CFG_TUD_TEST_MODE
|
||||
static bool process_test_mode_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request)
|
||||
{
|
||||
// At this point it should already be ensured that dcd_enter_test_mode() is defined
|
||||
@ -1129,11 +1131,11 @@ static bool process_test_mode_cb(uint8_t rhport, uint8_t stage, tusb_control_req
|
||||
// Only enter the test mode after the request for it has completed
|
||||
TU_VERIFY(CONTROL_STAGE_ACK == stage);
|
||||
|
||||
dcd_enter_test_mode(rhport, tu_u16_high(request->wIndex));
|
||||
dcd_enter_test_mode(rhport, (test_mode_t)tu_u16_high(request->wIndex));
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif /* !TUSB_NO_TEST_MODE_SUPPORT */
|
||||
#endif /* CFG_TUD_TEST_MODE */
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DCD Event Handler
|
||||
|
@ -1195,7 +1195,7 @@ void dcd_int_handler(uint8_t rhport) {
|
||||
// }
|
||||
}
|
||||
|
||||
#if defined(TUP_USBIP_DWC2_TEST_MODE_SUPPORT) && !defined(TUSB_NO_TEST_MODE_SUPPORT)
|
||||
#if defined(TUP_USBIP_DWC2_TEST_MODE) && CFG_TUD_TEST_MODE
|
||||
|
||||
bool dcd_check_test_mode_support(test_mode_t test_selector) {
|
||||
// Check if test mode selector is unsupported
|
||||
@ -1218,6 +1218,6 @@ void dcd_enter_test_mode(uint8_t rhport, test_mode_t test_selector) {
|
||||
dwc2->dctl = (dwc2->dctl & ~DCTL_TCTL_Msk) | (test_selector << DCTL_TCTL_Pos);
|
||||
}
|
||||
|
||||
#endif /* TUP_USBIP_DWC2_TEST_MODE_SUPPORT && !TUSB_NO_TEST_MODE_SUPPORT */
|
||||
#endif /* TUP_USBIP_DWC2_TEST_MODE && CFG_TUD_TEST_MODE */
|
||||
|
||||
#endif
|
||||
|
@ -364,6 +364,11 @@
|
||||
#define CFG_TUD_INTERFACE_MAX 16
|
||||
#endif
|
||||
|
||||
// USB 2.0 compliance test mode support
|
||||
#ifndef CFG_TUD_TEST_MODE
|
||||
#define CFG_TUD_TEST_MODE 0
|
||||
#endif
|
||||
|
||||
//------------- Device Class Driver -------------//
|
||||
#ifndef CFG_TUD_BTH
|
||||
#define CFG_TUD_BTH 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user