Skip to content

Commit e1fda00

Browse files
committed
minor refactor to invalid index
1 parent 317177c commit e1fda00

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/host/usbh.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ typedef struct {
118118
// MACRO CONSTANT TYPEDEF
119119
//--------------------------------------------------------------------+
120120

121-
// Invalid driver ID in itf2drv[] ep2drv[][] mapping
122-
enum { DRVID_INVALID = 0xFFu };
123-
enum { CONTROLLER_INVALID = 0xFFu };
124-
125121
#if CFG_TUSB_DEBUG >= 2
126122
#define DRIVER_NAME(_name) .name = _name,
127123
#else
@@ -199,7 +195,7 @@ enum { CONFIG_NUM = 1 }; // default to use configuration 1
199195
// sum of end device + hub
200196
#define TOTAL_DEVICES (CFG_TUH_DEVICE_MAX + CFG_TUH_HUB)
201197

202-
static uint8_t _usbh_controller = CONTROLLER_INVALID;
198+
static uint8_t _usbh_controller = TU_INDEX_INVALID_8;
203199

204200
// Device with address = 0 for enumeration
205201
static usbh_dev0_t _dev0;
@@ -307,13 +303,13 @@ tusb_speed_t tuh_speed_get (uint8_t dev_addr)
307303
static void clear_device(usbh_device_t* dev)
308304
{
309305
tu_memclr(dev, sizeof(usbh_device_t));
310-
memset(dev->itf2drv, DRVID_INVALID, sizeof(dev->itf2drv)); // invalid mapping
311-
memset(dev->ep2drv , DRVID_INVALID, sizeof(dev->ep2drv )); // invalid mapping
306+
memset(dev->itf2drv, TU_INDEX_INVALID_8, sizeof(dev->itf2drv)); // invalid mapping
307+
memset(dev->ep2drv , TU_INDEX_INVALID_8, sizeof(dev->ep2drv )); // invalid mapping
312308
}
313309

314310
bool tuh_inited(void)
315311
{
316-
return _usbh_controller != CONTROLLER_INVALID;
312+
return _usbh_controller != TU_INDEX_INVALID_8;
317313
}
318314

319315
bool tuh_init(uint8_t controller_id)
@@ -402,11 +398,11 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
402398
// one device before enumerating another one.
403399
if ( _dev0.enumerating )
404400
{
405-
TU_LOG1("[%u:] USBH Defer Attach until current enumeration complete\r\n", event.rhport);
401+
TU_LOG_USBH("[%u:] USBH Defer Attach until current enumeration complete\r\n", event.rhport);
406402
osal_queue_send(_usbh_q, &event, in_isr);
407403
}else
408404
{
409-
TU_LOG1("[%u:] USBH DEVICE ATTACH\r\n", event.rhport);
405+
TU_LOG_USBH("[%u:] USBH DEVICE ATTACH\r\n", event.rhport);
410406
_dev0.enumerating = 1;
411407
enum_new_device(&event);
412408
}
@@ -1362,11 +1358,11 @@ static void process_enumeration(tuh_xfer_t* xfer)
13621358

13631359
dev->configured = 1;
13641360

1365-
// Start the Set Configuration process for interfaces (itf = DRVID_INVALID)
1361+
// Start the Set Configuration process for interfaces (itf = TU_INDEX_INVALID_8)
13661362
// Since driver can perform control transfer within its set_config, this is done asynchronously.
13671363
// The process continue with next interface when class driver complete its sequence with usbh_driver_set_config_complete()
1368-
// TODO use separated API instead of using DRVID_INVALID
1369-
usbh_driver_set_config_complete(daddr, DRVID_INVALID);
1364+
// TODO use separated API instead of using TU_INDEX_INVALID_8
1365+
usbh_driver_set_config_complete(daddr, TU_INDEX_INVALID_8);
13701366
}
13711367
break;
13721368

@@ -1566,7 +1562,7 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
15661562
uint8_t const itf_num = desc_itf->bInterfaceNumber+i;
15671563

15681564
// Interface number must not be used already
1569-
TU_ASSERT( DRVID_INVALID == dev->itf2drv[itf_num] );
1565+
TU_ASSERT( TU_INDEX_INVALID_8 == dev->itf2drv[itf_num] );
15701566
dev->itf2drv[itf_num] = drv_id;
15711567
}
15721568

@@ -1600,7 +1596,7 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
16001596
// IAD binding interface such as CDCs should return itf_num + 1 when complete
16011597
// with usbh_driver_set_config_complete()
16021598
uint8_t const drv_id = dev->itf2drv[itf_num];
1603-
if (drv_id != DRVID_INVALID)
1599+
if (drv_id != TU_INDEX_INVALID_8)
16041600
{
16051601
usbh_class_driver_t const * driver = &usbh_class_drivers[drv_id];
16061602
TU_LOG_USBH("%s set config: itf = %u\r\n", driver->name, itf_num);

0 commit comments

Comments
 (0)