STM32: USB: properly catch device's GET_DESCRIPTOR requests
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 21 Sep 2010 10:37:55 +0000 (10:37 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 21 Sep 2010 10:37:55 +0000 (10:37 +0000)
Getting descriptor for a device is a standard request (e.g., USB HID
requires this). So, be sure to call the device's event handler when this
request occurs.

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

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

index 6b0b28e1d31751fa582330cfc33f9d5d922834c4..89782fca20454d8a03df0f7bd6628be08741f774 100644 (file)
@@ -1381,6 +1381,17 @@ static void UsbGetDescriptor(void)
        }
 }
 
+/* USB setup packet: class/vendor request handler */
+static void usb_event_handler(struct usb_device *dev)
+{
+       /*
+        * TODO: get the appropriate usb_dev in function of the endpoint
+        * address.
+        */
+       if (dev->event_cb)
+               dev->event_cb(&setup_packet);
+}
+
 /* USB setup packet: GET_DESCRIPTOR handler */
 static void UBS_GetDescriptorHandler(void)
 {
@@ -1390,6 +1401,9 @@ static void UBS_GetDescriptorHandler(void)
        if ((setup_packet.mRequestType & USB_RECIP_MASK) ==
                        USB_RECIP_DEVICE)
                UsbGetDescriptor();
+       /* Getting descriptor for a device is a standard request */
+       else if ((setup_packet.mRequestType & USB_DIR_MASK) == USB_DIR_IN)
+               usb_event_handler(usb_dev);
        else
                ep_cnfg[CTRL_ENP_OUT].status = STALLED;
 }
@@ -1555,17 +1569,6 @@ 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)
 {
@@ -1581,13 +1584,13 @@ static void USB_SetupHandler(void)
        case USB_TYPE_CLASS:
                LOG_INFO("%s: bmRequestType=%02x (Class)\n",
                                __func__, setup_packet.mRequestType);
-               USB_EventHandler();
+               usb_event_handler(usb_dev);
                break;
        /* Vendor */
        case USB_TYPE_VENDOR:
                LOG_INFO("%s: bmRequestType=%02x (Vendor)\n",
                                __func__, setup_packet.mRequestType);
-               USB_EventHandler();
+               usb_event_handler(usb_dev);
                break;
        case USB_TYPE_RESERVED:
                LOG_INFO("%s: bmRequestType=%02x (Reserved)\n",
index 9909eb38f99dc5fd6e0a0d4f0b995e6c9a7cea1f..29dcb73c17709a154eb8f25d32588e872fa902a8 100644 (file)
@@ -89,6 +89,7 @@ enum usb_device_state {
  */
 #define USB_DIR_OUT                    0               /* to device */
 #define USB_DIR_IN                     0x80            /* to host */
+#define USB_DIR_MASK                   0x80
 
 /*
  * USB types, the second of three bRequestType fields
@@ -310,7 +311,7 @@ typedef struct usb_endpoint_descriptor
  * Endpoints
  */
 #define USB_ENDPOINT_NUMBER_MASK       0x0f    /* in bEndpointAddress */
-#define USB_ENDPOINT_DIR_MASK          0x80
+#define USB_ENDPOINT_DIR_MASK          USB_DIR_MASK
 
 #define USB_ENDPOINT_SYNCTYPE          0x0c
 #define USB_ENDPOINT_SYNC_NONE         (0 << 2)