From: arighi Date: Thu, 30 Sep 2010 10:47:06 +0000 (+0000) Subject: USB: compile-time endpoints allocation X-Git-Tag: 2.6.0~24 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=46a1dfc5b039beb4495945e534c746bcce91edae;p=bertos.git USB: compile-time endpoints allocation If we want to use many USB device drivers at the same time, we need to properly allocate the endpoints among different drivers to avoid conflicts (different drivers using the same endpoint). Perform this allocation at compile-time according to the drivers enabled in the project's configuration. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4377 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cfg/cfg_usbkbd.h b/bertos/cfg/cfg_usbkbd.h index f7ade6eb..967b541f 100644 --- a/bertos/cfg/cfg_usbkbd.h +++ b/bertos/cfg/cfg_usbkbd.h @@ -38,6 +38,13 @@ #ifndef CFG_USBKBD_H #define CFG_USBKBD_H +/** + * Enable the usbkbd module. + * + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_USBKBD 0 + /** * Module logging level. * diff --git a/bertos/cfg/cfg_usbmouse.h b/bertos/cfg/cfg_usbmouse.h index c3b09719..89ff4c53 100644 --- a/bertos/cfg/cfg_usbmouse.h +++ b/bertos/cfg/cfg_usbmouse.h @@ -38,6 +38,13 @@ #ifndef CFG_USBMOUSE_H #define CFG_USBMOUSE_H +/** + * Enable the usbmouse module. + * + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_USBMOUSE 0 + /** * Module logging level. * diff --git a/bertos/cfg/cfg_usbser.h b/bertos/cfg/cfg_usbser.h index 88fcd190..6e47012a 100644 --- a/bertos/cfg/cfg_usbser.h +++ b/bertos/cfg/cfg_usbser.h @@ -38,6 +38,13 @@ #ifndef CFG_USBSER_H #define CFG_USBSER_H +/** + * Enable the usb-serial module. + * + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_USBSER 0 + /** * Module logging level. * diff --git a/bertos/cpu/cortex-m3/drv/usb_stm32.c b/bertos/cpu/cortex-m3/drv/usb_stm32.c index 7c802d60..0aa4c188 100644 --- a/bertos/cpu/cortex-m3/drv/usb_stm32.c +++ b/bertos/cpu/cortex-m3/drv/usb_stm32.c @@ -58,7 +58,10 @@ #include "usb_stm32.h" +/* XXX: consider to move this to cfg/compiler.h */ #define ALIGNED(x) __attribute__ ((__aligned__(x))) + +/* XXX: consider to move this to cfg/macros.h */ #define ALIGN_UP(value, align) (((value) & ((align) - 1)) ? \ (((value) + ((align) - 1)) & ~((align) - 1)) : \ (value)) diff --git a/bertos/drv/usb_endpoint.h b/bertos/drv/usb_endpoint.h new file mode 100644 index 00000000..7af79c06 --- /dev/null +++ b/bertos/drv/usb_endpoint.h @@ -0,0 +1,62 @@ +/** + * \file + * + * + * \author Andrea Righi + * + * \brief USB endpoint allocations + * + * This file defines how the endpoints are allocated among the supported USB + * device drivers in BeRTOs. + * + */ + +#ifndef USB_ENDPOINT_H +#define USB_ENDPOINT_H + +/* Enpoint allocation (according to the compile-time options) */ +enum { + USB_CTRL_ENDPOINT = 0, /* This must be always allocated */ +#if (defined(CONFIG_USBSER) && CONFIG_USBSER) + USB_SERIAL_EP_REPORT, + USB_SERIAL_EP_OUT, + USB_SERIAL_EP_IN, +#endif +#if (defined(CONFIG_USBKBD) && CONFIG_USBKBD) + USB_KBD_EP_REPORT, +#endif +#if (defined(CONFIG_USBMOUSE) && CONFIG_USBMOUSE) + USB_MOUSE_EP_REPORT, +#endif + USB_EP_MAX, /* Number of allocated endpoints */ +}; + +#endif /* USB_ENDPOINT_H */ diff --git a/bertos/drv/usbkbd.c b/bertos/drv/usbkbd.c index 24608770..02d1c7d9 100644 --- a/bertos/drv/usbkbd.c +++ b/bertos/drv/usbkbd.c @@ -50,6 +50,7 @@ #include // cpu_relax() #include +#include #include "drv/usb_hid.h" #include "drv/usbkbd.h" @@ -66,7 +67,7 @@ #define USB_STRING_MANUFACTURER 1 #define USB_STRING_PRODUCT 2 -#define USB_HID_REPORT_EP (USB_DIR_IN | 1) +#define USB_HID_REPORT_EP (USB_DIR_IN | USB_KBD_EP_REPORT) static UsbDeviceDesc usb_hid_device_descriptor = { diff --git a/bertos/drv/usbmouse.c b/bertos/drv/usbmouse.c index b725a8f4..a562f582 100644 --- a/bertos/drv/usbmouse.c +++ b/bertos/drv/usbmouse.c @@ -50,6 +50,7 @@ #include // cpu_relax() #include +#include #include "drv/usb_hid.h" #include "drv/usbmouse.h" @@ -66,7 +67,7 @@ #define USB_STRING_MANUFACTURER 1 #define USB_STRING_PRODUCT 2 -#define USB_HID_REPORT_EP (USB_DIR_IN | 1) +#define USB_HID_REPORT_EP (USB_DIR_IN | USB_MOUSE_EP_REPORT) static UsbDeviceDesc usb_hid_device_descriptor = { diff --git a/bertos/drv/usbser.c b/bertos/drv/usbser.c index b6c7161f..78444b13 100644 --- a/bertos/drv/usbser.c +++ b/bertos/drv/usbser.c @@ -52,6 +52,7 @@ #include /* cpu_relax() */ #include +#include #include /* memcpy() */ @@ -112,7 +113,7 @@ static const UsbEndpointDesc usb_serial_ep_report_descriptor = { .bLength = sizeof(usb_serial_ep_report_descriptor), .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_DIR_IN | 1, + .bEndpointAddress = USB_DIR_IN | USB_SERIAL_EP_REPORT, .bmAttributes = USB_ENDPOINT_XFER_INT, .wMaxPacketSize = usb_cpu_to_le16((uint16_t)8), .bInterval = 1, @@ -122,7 +123,7 @@ static const UsbEndpointDesc usb_serial_ep_in_descriptor = { .bLength = sizeof(usb_serial_ep_in_descriptor), .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_DIR_IN | 3, + .bEndpointAddress = USB_DIR_IN | USB_SERIAL_EP_IN, .bmAttributes = USB_ENDPOINT_XFER_BULK, .wMaxPacketSize = usb_cpu_to_le16((uint16_t)64), .bInterval = 0, @@ -132,7 +133,7 @@ static const UsbEndpointDesc usb_serial_ep_out_descriptor = { .bLength = sizeof(usb_serial_ep_in_descriptor), .bDescriptorType = USB_DT_ENDPOINT, - .bEndpointAddress = USB_DIR_OUT | 2, + .bEndpointAddress = USB_DIR_OUT | USB_SERIAL_EP_OUT, .bmAttributes = USB_ENDPOINT_XFER_BULK, .wMaxPacketSize = usb_cpu_to_le16((uint16_t)64), .bInterval = 0,