From f5729acab3560972ec31e397844b9fe39c7455ce Mon Sep 17 00:00:00 2001 From: arighi Date: Mon, 20 Sep 2010 16:52:22 +0000 Subject: [PATCH] USB: add generic class/vendor request handling 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 | 14 ++++++++++++++ bertos/drv/usb.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/bertos/cpu/cortex-m3/drv/usb_stm32.c b/bertos/cpu/cortex-m3/drv/usb_stm32.c index be9ba640..6b0b28e1 100644 --- a/bertos/cpu/cortex-m3/drv/usb_stm32.c +++ b/bertos/cpu/cortex-m3/drv/usb_stm32.c @@ -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; diff --git a/bertos/drv/usb.h b/bertos/drv/usb.h index 68af0136..9909eb38 100644 --- a/bertos/drv/usb.h +++ b/bertos/drv/usb.h @@ -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; }; -- 2.25.1