summaryrefslogtreecommitdiff
path: root/src/tusb.c
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2024-10-10 17:00:40 +0700
committerGitHub <[email protected]>2024-10-10 17:00:40 +0700
commita4fb8354e41b2604f66e7da22afa292b1a44f0a2 (patch)
tree1e980f0c18f558e3041dbef3021afa346297a85d /src/tusb.c
parentffdf81f53a84111a2536defa86e4a637c3c46854 (diff)
parent57aac432b52df6d284c98daf591e661d1c55aa05 (diff)
Merge pull request #2834 from hathach/add-tusb_int_handler-update-tinyusb_init
add new tusb_int_handler(rhport, in_isr) and update tusb_init(rhport, role)
Diffstat (limited to 'src/tusb.c')
-rw-r--r--src/tusb.c60
1 files changed, 53 insertions, 7 deletions
diff --git a/src/tusb.c b/src/tusb.c
index 11690b203..9f0e45fef 100644
--- a/src/tusb.c
+++ b/src/tusb.c
@@ -39,21 +39,50 @@
#include "host/usbh_pvt.h"
#endif
+#define TUP_USBIP_CONTROLLER_NUM 2
+
+static tusb_role_t _rhport_role[TUP_USBIP_CONTROLLER_NUM] = { 0 };
+
//--------------------------------------------------------------------+
// Public API
//--------------------------------------------------------------------+
-bool tusb_init(void) {
- #if CFG_TUD_ENABLED && defined(TUD_OPT_RHPORT)
- // init device stack CFG_TUSB_RHPORTx_MODE must be defined
- TU_ASSERT ( tud_init(TUD_OPT_RHPORT) );
+bool _tusb_rhport_init(uint8_t rhport, tusb_role_t role) {
+ // backward compatible called with tusb_init(void)
+ #if defined(TUD_OPT_RHPORT) || defined(TUH_OPT_RHPORT)
+ if (rhport == 0xff || role == TUSB_ROLE_INVALID) {
+ #if CFG_TUD_ENABLED && defined(TUD_OPT_RHPORT)
+ // init device stack CFG_TUSB_RHPORTx_MODE must be defined
+ TU_ASSERT ( tud_init(TUD_OPT_RHPORT) );
+ _rhport_role[TUD_OPT_RHPORT] = TUSB_ROLE_DEVICE;
+ #endif
+
+ #if CFG_TUH_ENABLED && defined(TUH_OPT_RHPORT)
+ // init host stack CFG_TUSB_RHPORTx_MODE must be defined
+ TU_ASSERT( tuh_init(TUH_OPT_RHPORT) );
+ _rhport_role[TUH_OPT_RHPORT] = TUSB_ROLE_HOST;
+ #endif
+
+ return true;
+ }
+ #endif
+
+ // new API with explicit rhport and role
+ TU_ASSERT(rhport < TUP_USBIP_CONTROLLER_NUM && role != TUSB_ROLE_INVALID);
+
+ #if CFG_TUD_ENABLED
+ if (role == TUSB_ROLE_DEVICE) {
+ TU_ASSERT( tud_init(rhport) );
+ }
#endif
- #if CFG_TUH_ENABLED && defined(TUH_OPT_RHPORT)
- // init host stack CFG_TUSB_RHPORTx_MODE must be defined
- TU_ASSERT( tuh_init(TUH_OPT_RHPORT) );
+ #if CFG_TUH_ENABLED
+ if (role == TUSB_ROLE_HOST) {
+ TU_ASSERT( tuh_init(rhport) );
+ }
#endif
+ _rhport_role[rhport] = role;
return true;
}
@@ -71,6 +100,23 @@ bool tusb_inited(void) {
return ret;
}
+void tusb_int_handler(uint8_t rhport, bool in_isr) {
+ TU_VERIFY(rhport < TUP_USBIP_CONTROLLER_NUM,);
+
+ #if CFG_TUD_ENABLED
+ if (_rhport_role[rhport] == TUSB_ROLE_DEVICE) {
+ (void) in_isr;
+ tud_int_handler(rhport);
+ }
+ #endif
+
+ #if CFG_TUH_ENABLED
+ if (_rhport_role[rhport] == TUSB_ROLE_HOST) {
+ tuh_int_handler(rhport, in_isr);
+ }
+ #endif
+}
+
//--------------------------------------------------------------------+
// Descriptor helper
//--------------------------------------------------------------------+