more minor clean up

- also rename usbh_classdriver.h to usbh_pvt.h to consitent with usbd
This commit is contained in:
hathach
2023-08-15 22:51:21 +07:00
parent 9d94296741
commit 1b33a31536
9 changed files with 61 additions and 79 deletions

View File

@@ -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;
usbd_class_driver_t const * driver = NULL;
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];
}
// 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];
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
return NULL;
return driver;
}
#define TOTAL_DRIVER_COUNT (_app_driver_count + BUILTIN_DRIVER_COUNT)
//--------------------------------------------------------------------+
// DCD Event