usb: introduce USB_NOTIFY_CLASS_DRIVER

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]>
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit eb692117912524d556fe23f85d09e0e037d21585
Author: mojyack <[email protected]>
Date:   Fri Dec 19 15:22:25 2025 +0900

    usb: introduce USB_NOTIFY_CLASS_DRIVER
    
    this invokes specified class driver's notify_event method.
    initial purpose is to trigger a callback from isr, like a timer event.
    
    Change-Id: Id600e9f0d8840a12da779d5a15783edf14bd76b5

diff --git a/firmware/export/usb.h b/firmware/export/usb.h
index c16fecc69f..6d9784f93e 100644
--- a/firmware/export/usb.h
+++ b/firmware/export/usb.h
@@ -119,6 +119,7 @@ enum
     USB_NOTIFY_SET_ADDR,     /* Event */
     USB_NOTIFY_SET_CONFIG,   /* Event */
     USB_NOTIFY_BUS_RESET,    /* Event */
+    USB_NOTIFY_CLASS_DRIVER, /* Event - notify_event() of specified class driver */
 #endif
 #ifdef USB_FIREWIRE_HANDLING
     USB_REQUEST_REBOOT,      /* Event */
@@ -238,12 +239,23 @@ void usb_set_mode(int mode);
 /* USB driver call this function to notify that a transfer has completed */
 void usb_signal_transfer_completion(
     struct usb_transfer_completion_event_data *event_data);
+
 /* Clear all signaled transfer completion events from event queue */
 void usb_clear_pending_transfer_completion_events(void);
+
 /* notify the USB code that some important event has occurred which influences the
  * USB state (like USB_NOTIFY_SET_ADDR). USB drivers should call usb_core_notify_*
- * functions and not this function. */
+ * functions and not this function.
+ * for USB_NOTIFY_CLASS_DRIVER, use usb_signal_class_notify() instead */
 void usb_signal_notify(long id, intptr_t data);
+
+/* wrapper for usb_signal_notify(USB_NOTIFY_CLASS_DRIVER)
+ * class_num: target driver. USB_DRIVER_*
+ * data: optional data. note that its upper 8 bits will be masked */
+static inline void usb_signal_class_notify(int8_t class_num, uint32_t data) {
+    usb_signal_notify(USB_NOTIFY_CLASS_DRIVER, class_num << 24 | (data & 0x00ffffff));
+}
+
 /* returns whether a USB_DRIVER_* is enabled (like HID, mass storage, ...) */
 bool usb_driver_enabled(int driver);
 /* returns whether exclusive storage is available for USB */
diff --git a/firmware/usb.c b/firmware/usb.c
index 49b4e70b3e..c088db4ef1 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -423,6 +423,7 @@ static void NORETURN_ATTR usb_thread(void)
         case USB_NOTIFY_SET_ADDR:
         case USB_NOTIFY_SET_CONFIG:
         case USB_NOTIFY_BUS_RESET:
+        case USB_NOTIFY_CLASS_DRIVER:
             if(usb_state <= USB_EXTRACTED)
                 break;
             usb_core_handle_notify(ev.id, ev.data);
diff --git a/firmware/usbstack/usb_class_driver.h b/firmware/usbstack/usb_class_driver.h
index 0dab7ea0b0..f26324fe20 100644
--- a/firmware/usbstack/usb_class_driver.h
+++ b/firmware/usbstack/usb_class_driver.h
@@ -118,6 +118,10 @@ struct usb_class_driver {
      * Returns value on success and -1 on error.
      * Mandatory function if alternate interface support is needed */
     int (*get_interface)(int interface);
+
+    /* Invoked by USB_NOTIFY_CLASS_DRIVER
+       Optional function */
+    void (*notify_event)(intptr_t data);
 };
 
 #define PACK_DATA(dest, data) pack_data(dest, &(data), sizeof(data))
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c
index da02d256a3..60d07879ef 100644
--- a/firmware/usbstack/usb_core.c
+++ b/firmware/usbstack/usb_core.c
@@ -1181,6 +1181,16 @@ void usb_core_handle_notify(long id, intptr_t data)
             usb_charging_maxcurrent_change(usb_charging_maxcurrent());
 #endif
             break;
+        case USB_NOTIFY_CLASS_DRIVER: {
+            uint8_t index = data >> 24;
+            if(index >= USB_NUM_DRIVERS) {
+                logf("usb_core: invalid notification destination index=%u", index);
+                return;
+            }
+            if(is_active(drivers[index]) && drivers[index].notify_event != NULL) {
+                drivers[index].notify_event(data & 0x00ffffff);
+            }
+        } break;
         default:
             break;
     }
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.