Skip to content
Permalink
Browse files

usb: hid: Use UTIL_LISTIFY and device count macro

Use UTIL_LISTIFY and Kconfig device count template for specify number
of HID Devices.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
  • Loading branch information...
finikorg authored and nashif committed Feb 12, 2019
1 parent e79e4d9 commit fbd271343186c3f8de1c7bd3915f7942dbc6c05d
Showing with 42 additions and 59 deletions.
  1. +10 −20 subsys/usb/class/hid/Kconfig
  2. +28 −39 subsys/usb/class/hid/core.c
  3. +4 −0 subsys/usb/usb_descriptor.h
@@ -9,31 +9,21 @@
config USB_DEVICE_HID
bool "USB Human Interface Device support"
help
Enables USB Human Interface Device support.
Enables USB Human Interface Device support. Default device name
is "HID_0".

if USB_DEVICE_HID

config USB_HID_DEVICE_NAME_0
string "USB HID first device name"
default "HID_0"
config USB_HID_DEVICE_NAME
string "USB HID device name template"
default "HID"
help
Device name for the first HID Device.
Device name template for the HID Devices. First device would have
name $(USB_HID_DEVICE_NAME)_0, etc.

if USB_COMPOSITE_DEVICE

config USB_HID_DEVICE_1
bool "Enable second USB HID Device"
help
Enable second USB HID Device for composite configuration.

config USB_HID_DEVICE_NAME_1
string "USB HID second device name"
depends on USB_HID_DEVICE_1
default "HID_1"
help
Device name for the second HID Device.

endif # USB_COMPOSITE_DEVICE
module = USB_HID
default-count = 1
source "subsys/usb/class/Kconfig.template.composite_device_number"

config ENABLE_HID_INT_OUT_EP
bool "Enable USB HID Device Interrupt OUT Endpoint"
@@ -20,11 +20,8 @@ LOG_MODULE_REGISTER(usb_hid);

#include <stdlib.h>

#define HID_INT_IN_EP_ADDR 0x81
#define HID_INT_OUT_EP_ADDR 0x01

#define HID_INT_IN_EP_IDX 0
#define HID_INT_OUT_EP_IDX 1
#define HID_INT_IN_EP_IDX 0
#define HID_INT_OUT_EP_IDX 1

struct usb_hid_config {
struct usb_if_descriptor if0;
@@ -88,33 +85,33 @@ struct usb_hid_config {
}

#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
#define DEFINE_HID_DESCR(x) \
#define DEFINE_HID_DESCR(x, _) \
USBD_CLASS_DESCR_DEFINE(primary, x) \
struct usb_hid_config hid_cfg_##x = { \
/* Interface descriptor */ \
.if0 = INITIALIZER_IF, \
.if0_hid = INITIALIZER_IF_HID, \
.if0_int_in_ep = \
INITIALIZER_IF_EP(HID_INT_IN_EP_ADDR, \
INITIALIZER_IF_EP(AUTO_EP_IN, \
USB_DC_EP_INTERRUPT, \
CONFIG_HID_INTERRUPT_EP_MPS), \
.if0_int_out_ep = \
INITIALIZER_IF_EP(HID_INT_OUT_EP_ADDR, \
INITIALIZER_IF_EP(AUTO_EP_OUT, \
USB_DC_EP_INTERRUPT, \
CONFIG_HID_INTERRUPT_EP_MPS), \
}
};
#else
#define DEFINE_HID_DESCR(x) \
#define DEFINE_HID_DESCR(x, _) \
USBD_CLASS_DESCR_DEFINE(primary, x) \
struct usb_hid_config hid_cfg_##x = { \
/* Interface descriptor */ \
.if0 = INITIALIZER_IF, \
.if0_hid = INITIALIZER_IF_HID, \
.if0_int_in_ep = \
INITIALIZER_IF_EP(HID_INT_IN_EP_ADDR, \
INITIALIZER_IF_EP(AUTO_EP_IN, \
USB_DC_EP_INTERRUPT, \
CONFIG_HID_INTERRUPT_EP_MPS), \
}
};
#endif

struct hid_device_info {
@@ -606,16 +603,16 @@ static void hid_int_out(u8_t ep, enum usb_dc_ep_cb_status_code ep_status)

/* Describe Endpoints configuration */
#ifdef CONFIG_ENABLE_HID_INT_OUT_EP
#define DEFINE_HID_EP(x) \
#define DEFINE_HID_EP(x, _) \
static struct usb_ep_cfg_data hid_ep_data_##x[] = { \
INITIALIZER_EP_DATA(hid_int_in, HID_INT_IN_EP_ADDR), \
INITIALIZER_EP_DATA(hid_int_out, HID_INT_OUT_EP_ADDR), \
}
INITIALIZER_EP_DATA(hid_int_in, AUTO_EP_IN), \
INITIALIZER_EP_DATA(hid_int_out, AUTO_EP_OUT), \
};
#else
#define DEFINE_HID_EP(x) \
#define DEFINE_HID_EP(x, _) \
static struct usb_ep_cfg_data hid_ep_data_##x[] = { \
INITIALIZER_EP_DATA(hid_int_in, HID_INT_IN_EP_ADDR), \
}
INITIALIZER_EP_DATA(hid_int_in, AUTO_EP_IN), \
};
#endif

static void hid_interface_config(struct usb_desc_header *head,
@@ -633,7 +630,7 @@ static void hid_interface_config(struct usb_desc_header *head,
#endif
}

#define DEFINE_HID_CFG_DATA(x) \
#define DEFINE_HID_CFG_DATA(x, _) \
USBD_CFG_DATA_DEFINE(hid) \
struct usb_cfg_data hid_config_##x = { \
.usb_device_description = NULL, \
@@ -739,28 +736,20 @@ static int usb_hid_device_init(struct device *dev)
return 0;
}

#define DEFINE_HID_DEV_DATA(x) \
struct hid_device_info usb_hid_dev_data_##x
#define DEFINE_HID_DEV_DATA(x, _) \
struct hid_device_info usb_hid_dev_data_##x;

#define DEFINE_HID_DEVICE(x) \
#define DEFINE_HID_DEVICE(x, _) \
DEVICE_AND_API_INIT(usb_hid_device_##x, \
CONFIG_USB_HID_DEVICE_NAME_##x, \
CONFIG_USB_HID_DEVICE_NAME "_" #x, \
&usb_hid_device_init, \
&usb_hid_dev_data_##x, \
&hid_config_##x, POST_KERNEL, \
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, \
&hid_api)

DEFINE_HID_DESCR(0);
DEFINE_HID_EP(0);
DEFINE_HID_CFG_DATA(0);
DEFINE_HID_DEV_DATA(0);
DEFINE_HID_DEVICE(0);

#ifdef CONFIG_USB_HID_DEVICE_1
DEFINE_HID_DESCR(1);
DEFINE_HID_EP(1);
DEFINE_HID_CFG_DATA(1);
DEFINE_HID_DEV_DATA(1);
DEFINE_HID_DEVICE(1);
#endif
&hid_api);

UTIL_LISTIFY(CONFIG_USB_HID_DEVICE_COUNT, DEFINE_HID_DESCR, _)
UTIL_LISTIFY(CONFIG_USB_HID_DEVICE_COUNT, DEFINE_HID_EP, _)
UTIL_LISTIFY(CONFIG_USB_HID_DEVICE_COUNT, DEFINE_HID_CFG_DATA, _)
UTIL_LISTIFY(CONFIG_USB_HID_DEVICE_COUNT, DEFINE_HID_DEV_DATA, _)
UTIL_LISTIFY(CONFIG_USB_HID_DEVICE_COUNT, DEFINE_HID_DEVICE, _)
@@ -33,6 +33,10 @@
*/
#define USB_STRING_DESCRIPTOR_LENGTH(s) (sizeof(s) * 2)

/* Automatic endpoint assignment */
#define AUTO_EP_IN 0x81
#define AUTO_EP_OUT 0x01

/* Common part of device data */
struct usb_dev_data {
struct device *dev;

0 comments on commit fbd2713

Please sign in to comment.
You can’t perform that action at this time.