Commit 32cac08e authored by Johann Fischer's avatar Johann Fischer Committed by Carles Cufi
Browse files

usb: class: adapt functions for new composite interface



Adapt functions for new composite interface.

Assign bInterfaceNumber and similar variables of a Interface
default values, these should be valid values for non-composite
configuration. For the case of the composite configuration,
these variables must be set by the interface configuration
function (interface_config) accordingly.

Signed-off-by: default avatarJohann Fischer <j.fischer@phytec.de>
parent 1383dad8
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ USBD_CLASS_DESCR_DEFINE(primary) struct usb_bluetooth_config bluetooth_cfg = {
	.if0 = {
		.bLength = sizeof(struct usb_if_descriptor),
		.bDescriptorType = USB_INTERFACE_DESC,
		.bInterfaceNumber = FIRST_IFACE_BLUETOOTH,
		.bInterfaceNumber = 0,
		.bAlternateSetting = 0,
		.bNumEndpoints = 3,
		.bInterfaceClass = WIRELESS_DEVICE_CLASS,
@@ -261,8 +261,14 @@ static int bluetooth_class_handler(struct usb_setup_packet *setup,
	return 0;
}

static void bluetooth_interface_config(u8_t bInterfaceNumber)
{
	bluetooth_cfg.if0.bInterfaceNumber = bInterfaceNumber;
}

USBD_CFG_DATA_DEFINE(hci) struct usb_cfg_data bluetooth_config = {
	.usb_device_description = NULL,
	.interface_config = bluetooth_interface_config,
	.interface_descriptor = &bluetooth_cfg.if0,
	.cb_usb_status = bluetooth_status_cb,
	.interface = {
@@ -271,7 +277,7 @@ USBD_CFG_DATA_DEFINE(hci) struct usb_cfg_data bluetooth_config = {
		.vendor_handler = NULL,
		.payload_data = NULL,
	},
	.num_endpoints = NUMOF_ENDPOINTS_BLUETOOTH,
	.num_endpoints = ARRAY_SIZE(bluetooth_ep_data),
	.endpoint = bluetooth_ep_data,
};

@@ -287,14 +293,7 @@ static int bluetooth_init(struct device *dev)
		return ret;
	}

#ifdef CONFIG_USB_COMPOSITE_DEVICE
	ret = composite_add_function(&bluetooth_config,
				     FIRST_IFACE_BLUETOOTH);
	if (ret < 0) {
		SYS_LOG_ERR("Failed to add bluetooth function");
		return ret;
	}
#else
#ifndef CONFIG_USB_COMPOSITE_DEVICE
	bluetooth_config.interface.payload_data = interface_data;
	bluetooth_config.usb_device_description =
		usb_get_device_descriptor();
+20 −14
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@
#include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb_descriptor.h>
#include <composite.h>

#ifndef CONFIG_UART_INTERRUPT_DRIVEN
#error "CONFIG_UART_INTERRUPT_DRIVEN must be set for CDC ACM driver"
@@ -77,6 +76,8 @@
#define ACM_OUT_EP_IDX			1
#define ACM_IN_EP_IDX			2

#define ACM_IF0_STRING			"ACM-CDC"

struct usb_cdc_acm_config {
#ifdef CONFIG_USB_COMPOSITE_DEVICE
	struct usb_association_descriptor iad_cdc;
@@ -98,7 +99,7 @@ USBD_CLASS_DESCR_DEFINE(primary) struct usb_cdc_acm_config cdc_acm_cfg = {
	.iad_cdc = {
		.bLength = sizeof(struct usb_association_descriptor),
		.bDescriptorType = USB_ASSOCIATION_DESC,
		.bFirstInterface = FIRST_IFACE_CDC_ACM,
		.bFirstInterface = 0,
		.bInterfaceCount = 0x02,
		.bFunctionClass = COMMUNICATION_DEVICE_CLASS,
		.bFunctionSubClass = ACM_SUBCLASS,
@@ -110,7 +111,7 @@ USBD_CLASS_DESCR_DEFINE(primary) struct usb_cdc_acm_config cdc_acm_cfg = {
	.if0 = {
		.bLength = sizeof(struct usb_if_descriptor),
		.bDescriptorType = USB_INTERFACE_DESC,
		.bInterfaceNumber = FIRST_IFACE_CDC_ACM,
		.bInterfaceNumber = 0,
		.bAlternateSetting = 0,
		.bNumEndpoints = 1,
		.bInterfaceClass = COMMUNICATION_DEVICE_CLASS,
@@ -169,7 +170,7 @@ USBD_CLASS_DESCR_DEFINE(primary) struct usb_cdc_acm_config cdc_acm_cfg = {
	.if1 = {
		.bLength = sizeof(struct usb_if_descriptor),
		.bDescriptorType = USB_INTERFACE_DESC,
		.bInterfaceNumber = FIRST_IFACE_CDC_ACM + 1,
		.bInterfaceNumber = 1,
		.bAlternateSetting = 0,
		.bNumEndpoints = 2,
		.bInterfaceClass = COMMUNICATION_DEVICE_CLASS_DATA,
@@ -424,6 +425,17 @@ static void cdc_acm_dev_status_cb(enum usb_dc_status_code status, u8_t *param)
	}
}

static void cdc_interface_config(u8_t bInterfaceNumber)
{
	cdc_acm_cfg.if0.bInterfaceNumber = bInterfaceNumber;
	cdc_acm_cfg.if0_union.bControlInterface = bInterfaceNumber;
	cdc_acm_cfg.if1.bInterfaceNumber = bInterfaceNumber + 1;
	cdc_acm_cfg.if0_union.bSubordinateInterface0 = bInterfaceNumber + 1;
#ifdef CONFIG_USB_COMPOSITE_DEVICE
	cdc_acm_cfg.iad_cdc.bFirstInterface = bInterfaceNumber;
#endif
}

/* Describe EndPoints configuration */
static struct usb_ep_cfg_data cdc_acm_ep_data[] = {
	{
@@ -443,6 +455,7 @@ static struct usb_ep_cfg_data cdc_acm_ep_data[] = {
/* Configuration of the CDC-ACM Device send to the USB Driver */
USBD_CFG_DATA_DEFINE(cdc_acm) struct usb_cfg_data cdc_acm_config = {
	.usb_device_description = NULL,
	.interface_config = cdc_interface_config,
	.interface_descriptor = &cdc_acm_cfg.if0,
	.cb_usb_status = cdc_acm_dev_status_cb,
	.interface = {
@@ -450,7 +463,7 @@ USBD_CFG_DATA_DEFINE(cdc_acm) struct usb_cfg_data cdc_acm_config = {
		.custom_handler = NULL,
		.payload_data = NULL,
	},
	.num_endpoints = NUMOF_ENDPOINTS_CDC_ACM,
	.num_endpoints = ARRAY_SIZE(cdc_acm_ep_data),
	.endpoint = cdc_acm_ep_data
};

@@ -483,17 +496,10 @@ static void cdc_acm_baudrate_set(struct device *dev, u32_t baudrate)
 */
static int cdc_acm_init(struct device *dev)
{
	int ret;

	cdc_acm_dev = dev;

#ifdef CONFIG_USB_COMPOSITE_DEVICE
	ret = composite_add_function(&cdc_acm_config, FIRST_IFACE_CDC_ACM);
	if (ret < 0) {
		SYS_LOG_ERR("Failed to add a function");
		return ret;
	}
#else
#ifndef CONFIG_USB_COMPOSITE_DEVICE
	int ret;
	struct cdc_acm_dev_data_t * const dev_data = DEV_DATA(dev);

	cdc_acm_config.interface.payload_data = dev_data->interface_data;
+11 −15
Original line number Diff line number Diff line
@@ -17,10 +17,6 @@
#include <usb_descriptor.h>
#include <class/usb_hid.h>

#ifdef CONFIG_USB_COMPOSITE_DEVICE
#include <composite.h>
#endif

struct usb_hid_config {
	struct usb_if_descriptor if0;
	struct usb_hid_descriptor if0_hid;
@@ -32,7 +28,7 @@ USBD_CLASS_DESCR_DEFINE(primary) struct usb_hid_config hid_cfg = {
	.if0 = {
		.bLength = sizeof(struct usb_if_descriptor),
		.bDescriptorType = USB_INTERFACE_DESC,
		.bInterfaceNumber = FIRST_IFACE_HID,
		.bInterfaceNumber = 0,
		.bAlternateSetting = 0,
		.bNumEndpoints = 1,
		.bInterfaceClass = HID_CLASS,
@@ -210,8 +206,14 @@ static struct usb_ep_cfg_data hid_ep_data[] = {
	}
};

static void hid_interface_config(u8_t bInterfaceNumber)
{
	hid_cfg.if0.bInterfaceNumber = bInterfaceNumber;
}

USBD_CFG_DATA_DEFINE(hid) struct usb_cfg_data hid_config = {
	.usb_device_description = NULL,
	.interface_config = hid_interface_config,
	.interface_descriptor = &hid_cfg.if0,
	.cb_usb_status = hid_status_cb,
	.interface = {
@@ -219,7 +221,7 @@ USBD_CFG_DATA_DEFINE(hid) struct usb_cfg_data hid_config = {
		.custom_handler = hid_custom_handle_req,
		.payload_data = NULL,
	},
	.num_endpoints = NUMOF_ENDPOINTS_HID,
	.num_endpoints = ARRAY_SIZE(hid_ep_data),
	.endpoint = hid_ep_data,
};

@@ -229,8 +231,6 @@ static u8_t interface_data[64];

int usb_hid_init(void)
{
	int ret;

	SYS_LOG_DBG("Iinitializing HID Device");

	/*
@@ -238,13 +238,9 @@ int usb_hid_init(void)
	 */
	usb_set_hid_report_size(hid_device.report_size);

#ifdef CONFIG_USB_COMPOSITE_DEVICE
	ret = composite_add_function(&hid_config, FIRST_IFACE_HID);
	if (ret < 0) {
		SYS_LOG_ERR("Failed to add HID function");
		return ret;
	}
#else
#ifndef CONFIG_USB_COMPOSITE_DEVICE
	int ret;

	hid_config.interface.payload_data = interface_data;
	hid_config.usb_device_description = usb_get_device_descriptor();

+11 −12
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@
#include <usb/usb_device.h>
#include <usb/usb_common.h>
#include <usb_descriptor.h>
#include <composite.h>

#define SYS_LOG_LEVEL CONFIG_SYS_LOG_USB_MASS_STORAGE_LEVEL
#define SYS_LOG_DOMAIN "usb/msc"
@@ -71,7 +70,7 @@ USBD_CLASS_DESCR_DEFINE(primary) struct usb_mass_config mass_cfg = {
	.if0 = {
		.bLength = sizeof(struct usb_if_descriptor),
		.bDescriptorType = USB_INTERFACE_DESC,
		.bInterfaceNumber = FIRST_IFACE_MASS_STORAGE,
		.bInterfaceNumber = 0,
		.bAlternateSetting = 0,
		.bNumEndpoints = 2,
		.bInterfaceClass = MASS_STORAGE_CLASS,
@@ -817,9 +816,15 @@ static void mass_storage_status_cb(enum usb_dc_status_code status, u8_t *param)
	}
}

static void mass_interface_config(u8_t bInterfaceNumber)
{
	mass_cfg.if0.bInterfaceNumber = bInterfaceNumber;
}

/* Configuration of the Mass Storage Device send to the USB Driver */
USBD_CFG_DATA_DEFINE(msd) struct usb_cfg_data mass_storage_config = {
	.usb_device_description = NULL,
	.interface_config = mass_interface_config,
	.interface_descriptor = &mass_cfg.if0,
	.cb_usb_status = mass_storage_status_cb,
	.interface = {
@@ -827,7 +832,7 @@ USBD_CFG_DATA_DEFINE(msd) struct usb_cfg_data mass_storage_config = {
		.custom_handler = NULL,
		.payload_data = NULL,
	},
	.num_endpoints = NUMOF_ENDPOINTS_MASS,
	.num_endpoints = ARRAY_SIZE(mass_ep_data),
	.endpoint = mass_ep_data
};

@@ -881,7 +886,6 @@ static u8_t interface_data[64];
 */
static int mass_storage_init(struct device *dev)
{
	int ret;
	u32_t block_size = 0;

	ARG_UNUSED(dev);
@@ -917,14 +921,9 @@ static int mass_storage_init(struct device *dev)
	msd_state_machine_reset();
	msd_init();

#ifdef CONFIG_USB_COMPOSITE_DEVICE
	ret = composite_add_function(&mass_storage_config,
				 FIRST_IFACE_MASS_STORAGE);
	if (ret < 0) {
		SYS_LOG_ERR("Failed to add a function");
		return ret;
	}
#else
#ifndef CONFIG_USB_COMPOSITE_DEVICE
	int ret;

	mass_storage_config.interface.payload_data = interface_data;
	mass_storage_config.usb_device_description =
		usb_get_device_descriptor();
+1 −1
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ static inline void ecm_status_interface(u8_t *iface)
	SYS_LOG_DBG("iface %u", *iface);

	/* First interface is CDC Comm interface */
	if (*iface != NETUSB_IFACE_IDX + 1) {
	if (*iface != netusb_get_first_iface_number() + 1) {
		return;
	}

Loading