From ade0c9511597c2545f7216daa67554821c0bc6f4 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Fri, 10 Mar 2023 08:19:30 +0100 Subject: [PATCH] sys/auto_init/usb: add a check for the number EPs Since `auto_init_usb` provides a static auto configuration for a single USBUS stack instance using a single USB device, a static assert can be used here to check whether the number of EPs required by the configuration does not exceed the number of EPs provided by the USB device. --- sys/auto_init/usb/auto_init_usb.c | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/sys/auto_init/usb/auto_init_usb.c b/sys/auto_init/usb/auto_init_usb.c index fe288faace3d1..69ac2ea0eb7cf 100644 --- a/sys/auto_init/usb/auto_init_usb.c +++ b/sys/auto_init/usb/auto_init_usb.c @@ -27,6 +27,7 @@ #include #include "usb/usbus.h" +#include "usb/usbus/control.h" #ifdef MODULE_USBUS_CDC_ECM #include "usb/usbus/cdc/ecm.h" @@ -39,11 +40,53 @@ usbus_cdcecm_device_t cdcecm; #include "usb/usbus/dfu.h" static usbus_dfu_device_t dfu; #endif +#ifdef MODULE_USBUS_HID +#include "usb/usbus/hid.h" +#endif #ifdef MODULE_USBUS_MSC #include "usb/usbus/msc.h" static usbus_msc_device_t msc; #endif +#ifndef MODULE_USBUS_CDC_ACM +#define USBUS_CDC_ACM_EP_IN_REQUIRED_NUMOF 0 +#define USBUS_CDC_ACM_EP_OUT_REQUIRED_NUMOF 0 +#endif + +#ifndef MODULE_USBUS_CDC_ECM +#define USBUS_CDC_ECM_EP_IN_REQUIRED_NUMOF 0 +#define USBUS_CDC_ECM_EP_OUT_REQUIRED_NUMOF 0 +#endif + +#ifndef MODULE_USBUS_HID +#define USBUS_HID_EP_IN_REQUIRED_NUMOF 0 +#define USBUS_HID_EP_OUT_REQUIRED_NUMOF 0 +#endif + +#ifndef MODULE_USBUS_MSC +#define USBUS_MSC_EP_IN_REQUIRED_NUMOF 0 +#define USBUS_MSC_EP_OUT_REQUIRED_NUMOF 0 +#endif + +#define USBUS_EP_IN_REQUIRED_NUMOF (USBUS_CONTROL_EP_IN_REQUIRED_NUMOF + \ + USBUS_CDC_ACM_EP_IN_REQUIRED_NUMOF + \ + USBUS_CDC_ECM_EP_IN_REQUIRED_NUMOF + \ + USBUS_HID_EP_IN_REQUIRED_NUMOF + \ + USBUS_MSC_EP_IN_REQUIRED_NUMOF) + +#define USBUS_EP_OUT_REQUIRED_NUMOF (USBUS_CONTROL_EP_OUT_REQUIRED_NUMOF + \ + USBUS_CDC_ACM_EP_OUT_REQUIRED_NUMOF + \ + USBUS_CDC_ECM_EP_OUT_REQUIRED_NUMOF + \ + USBUS_HID_EP_OUT_REQUIRED_NUMOF + \ + USBUS_MSC_EP_OUT_REQUIRED_NUMOF) + +static_assert(USBUS_EP_IN_REQUIRED_NUMOF <= USBDEV_NUM_ENDPOINTS, + "Number of required IN endpoints exceeded"); + +static_assert(USBUS_EP_OUT_REQUIRED_NUMOF <= USBDEV_NUM_ENDPOINTS, + "Number of required OUT endpoints exceeded"); + + static char _stack[USBUS_STACKSIZE]; static usbus_t usbus;