USB: add generic class/vendor request handling
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 20 Sep 2010 16:52:22 +0000 (16:52 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 20 Sep 2010 16:52:22 +0000 (16:52 +0000)
A generic USB device can handle class and/or vendor request implementing
the usb_device->event_cb callback.

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4245 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/cpu/cortex-m3/drv/usb_stm32.c
bertos/drv/usb.h

index be9ba64014f72033156e788657913d6a61fd000e..6b0b28e1d31751fa582330cfc33f9d5d922834c4 100644 (file)
@@ -1555,6 +1555,17 @@ static void USB_StandardRequestHandler(void)
        }
 }
 
+/* USB setup packet: class/vendor request handler */
+static void USB_EventHandler(void)
+{
+       /*
+        * TODO: get the appropriate usb_dev in function of the endpoint
+        * address.
+        */
+       if (usb_dev->event_cb)
+               usb_dev->event_cb(&setup_packet);
+}
+
 /* USB setup packet handler */
 static void USB_SetupHandler(void)
 {
@@ -1570,11 +1581,13 @@ static void USB_SetupHandler(void)
        case USB_TYPE_CLASS:
                LOG_INFO("%s: bmRequestType=%02x (Class)\n",
                                __func__, setup_packet.mRequestType);
+               USB_EventHandler();
                break;
        /* Vendor */
        case USB_TYPE_VENDOR:
                LOG_INFO("%s: bmRequestType=%02x (Vendor)\n",
                                __func__, setup_packet.mRequestType);
+               USB_EventHandler();
                break;
        case USB_TYPE_RESERVED:
                LOG_INFO("%s: bmRequestType=%02x (Reserved)\n",
@@ -1589,6 +1602,7 @@ static void USB_SetupHandler(void)
        }
 }
 
+/* USB: low-level hardware initialization */
 static void usb_hw_reset(void)
 {
        unsigned int i;
index 68af01362dd2d20c8d0dc1e2b8058963cfdf57dc..9909eb38f99dc5fd6e0a0d4f0b995e6c9a7cea1f 100644 (file)
@@ -331,6 +331,10 @@ struct usb_device
        usb_device_descriptor_t *device;
        usb_descriptor_header_t **config;
        usb_string_descriptor_t **strings;
+
+       /* Callbacks */
+       void (*event_cb)(usb_ctrlrequest_t *);
+
        /* Private data */
        bool configured;
 };