summaryrefslogtreecommitdiff
path: root/src/device/usbd.c
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2023-08-15 23:33:19 +0700
committerGitHub <[email protected]>2023-08-15 23:33:19 +0700
commit7537985c080e439f6f97a021ce49f5ef48979c78 (patch)
tree65f71c832d6feb6bda4e14eb50c35a83f750b11e /src/device/usbd.c
parentd713571cd44f05d2fc72efc09c670787b74106e0 (diff)
parent67a374d932cbe14bf1651bdd6fea82c2e2ecfa10 (diff)
Merge pull request #2222 from rppicomidi/fix-2188
fix issue 2188: support usbh_app_driver_get_cb()
Diffstat (limited to 'src/device/usbd.c')
-rw-r--r--src/device/usbd.c31
1 files changed, 11 insertions, 20 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c
index 156b92ce1..f0d9fba52 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -238,34 +238,25 @@ enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(_usbd_driver) };
tu_static usbd_class_driver_t const * _app_driver = NULL;
tu_static uint8_t _app_driver_count = 0;
+#define TOTAL_DRIVER_COUNT (_app_driver_count + BUILTIN_DRIVER_COUNT)
+
// virtually joins built-in and application drivers together.
// Application is positioned first to allow overwriting built-in ones.
static inline usbd_class_driver_t const * get_driver(uint8_t drvid)
{
- // Application drivers
- if ( usbd_app_driver_get_cb )
- {
- if ( drvid < _app_driver_count ) return &_app_driver[drvid];
- drvid -= _app_driver_count;
- }
-
- // when there is no built-in drivers BUILTIN_DRIVER_COUNT = 0 will cause -Wtype-limits warning
-#ifdef __GNUC__
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wtype-limits"
-#endif
-
- // Built-in drivers
- if (drvid < BUILTIN_DRIVER_COUNT) return &_usbd_driver[drvid];
+ usbd_class_driver_t const * driver = NULL;
-#ifdef __GNUC__
-#pragma GCC diagnostic pop
-#endif
+ if ( drvid < _app_driver_count ) {
+ // Application drivers
+ driver = &_app_driver[drvid];
+ } else if ( drvid < TOTAL_DRIVER_COUNT && BUILTIN_DRIVER_COUNT > 0 ){
+ driver = &_usbd_driver[drvid - _app_driver_count];
+ }
- return NULL;
+ return driver;
}
-#define TOTAL_DRIVER_COUNT (_app_driver_count + BUILTIN_DRIVER_COUNT)
+
//--------------------------------------------------------------------+
// DCD Event