@@ -65,21 +65,11 @@ uint8_t _picotool_itf_num;
65
65
66
66
int usb_hid_poll_interval __attribute__ ((weak)) = 10;
67
67
68
- // GCC doesn't seem to have builtin_ffs here
69
- int USBClass::ffs (uint32_t v) {
70
- for (auto i = 0 ; i < 32 ; i++) {
71
- if (v & (1 << i)) {
72
- return i;
73
- }
74
- }
75
- return 0 ;
76
- }
77
-
78
68
uint8_t USBClass::registerEndpointIn () {
79
69
if (!_endpointIn) {
80
70
return 0 ; // ERROR, out of EPs
81
71
}
82
- int firstFree = ffs (_endpointIn);
72
+ int firstFree = __builtin_ctz (_endpointIn);
83
73
_endpointIn &= ~(1 << firstFree);
84
74
return 0x80 + firstFree;
85
75
}
@@ -92,7 +82,7 @@ uint8_t USBClass::registerEndpointOut() {
92
82
if (!_endpointOut) {
93
83
return 0 ; // ERROR, out of EPs
94
84
}
95
- int firstFree = ffs (_endpointOut);
85
+ int firstFree = __builtin_ctz (_endpointOut);
96
86
_endpointOut &= ~(1 << firstFree);
97
87
return firstFree;
98
88
}
@@ -439,7 +429,6 @@ void __freertos_usb_task(void *param) {
439
429
}
440
430
}
441
431
#else
442
- static int __usb_task_irq;
443
432
static void usb_irq () {
444
433
// if the mutex is already owned, then we are in user code
445
434
// in this file which will do a tud_task itself, so we'll just do nothing
@@ -451,7 +440,7 @@ static void usb_irq() {
451
440
}
452
441
453
442
static int64_t timer_task (__unused alarm_id_t id, __unused void *user_data) {
454
- irq_set_pending (__usb_task_irq );
443
+ irq_set_pending (USB. usbTaskIRQ );
455
444
return USB_TASK_INTERVAL;
456
445
}
457
446
#endif
@@ -503,11 +492,6 @@ void USBClass::connect() {
503
492
#endif
504
493
}
505
494
506
-
507
-
508
-
509
-
510
-
511
495
void USBClass::begin () {
512
496
if (tusb_inited ()) {
513
497
// Already called
@@ -527,9 +511,9 @@ void USBClass::begin() {
527
511
xTaskCreate (__freertos_usb_task, " USB" , 256 , 0 , configMAX_PRIORITIES - 2 , &usbTask);
528
512
vTaskCoreAffinitySet (usbTask, 1 << 0 );
529
513
#else
530
- __usb_task_irq = user_irq_claim_unused (true );
531
- irq_set_exclusive_handler (__usb_task_irq , usb_irq);
532
- irq_set_enabled (__usb_task_irq , true );
514
+ usbTaskIRQ = user_irq_claim_unused (true );
515
+ irq_set_exclusive_handler (usbTaskIRQ , usb_irq);
516
+ irq_set_enabled (usbTaskIRQ , true );
533
517
add_alarm_in_us (USB_TASK_INTERVAL, timer_task, nullptr , true );
534
518
#endif
535
519
}
0 commit comments