@@ -65,21 +65,11 @@ uint8_t _picotool_itf_num;
6565
6666int usb_hid_poll_interval __attribute__ ((weak)) = 10;
6767
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-
7868uint8_t USBClass::registerEndpointIn () {
7969 if (!_endpointIn) {
8070 return 0 ; // ERROR, out of EPs
8171 }
82- int firstFree = ffs (_endpointIn);
72+ int firstFree = __builtin_ctz (_endpointIn);
8373 _endpointIn &= ~(1 << firstFree);
8474 return 0x80 + firstFree;
8575}
@@ -92,7 +82,7 @@ uint8_t USBClass::registerEndpointOut() {
9282 if (!_endpointOut) {
9383 return 0 ; // ERROR, out of EPs
9484 }
95- int firstFree = ffs (_endpointOut);
85+ int firstFree = __builtin_ctz (_endpointOut);
9686 _endpointOut &= ~(1 << firstFree);
9787 return firstFree;
9888}
@@ -439,7 +429,6 @@ void __freertos_usb_task(void *param) {
439429 }
440430}
441431#else
442- static int __usb_task_irq;
443432static void usb_irq () {
444433 // if the mutex is already owned, then we are in user code
445434 // in this file which will do a tud_task itself, so we'll just do nothing
@@ -451,7 +440,7 @@ static void usb_irq() {
451440}
452441
453442static 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 );
455444 return USB_TASK_INTERVAL;
456445}
457446#endif
@@ -503,11 +492,6 @@ void USBClass::connect() {
503492#endif
504493}
505494
506-
507-
508-
509-
510-
511495void USBClass::begin () {
512496 if (tusb_inited ()) {
513497 // Already called
@@ -527,9 +511,9 @@ void USBClass::begin() {
527511 xTaskCreate (__freertos_usb_task, " USB" , 256 , 0 , configMAX_PRIORITIES - 2 , &usbTask);
528512 vTaskCoreAffinitySet (usbTask, 1 << 0 );
529513#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 );
533517 add_alarm_in_us (USB_TASK_INTERVAL, timer_task, nullptr , true );
534518#endif
535519}
0 commit comments