mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
Squashed commit of the following:
commit69fcf3e849Author: Alan Carvalho de Assis <acassis@gmail.com> Date: Sun Jul 16 08:39:33 2017 -0600 Fix spark/stm32_composite.c: board_composite_connect cannot be static commit28eb253401Author: Gregory Nutt <gnutt@nuttx.org> Date: Sun Jul 16 08:36:01 2017 -0600 Composite: Final review for coding style before merge commite6af1b9994Author: Gregory Nutt <gnutt@nuttx.org> Date: Sun Jul 16 07:41:38 2017 -0600 Composite: Simplify some intiialization of data structures. commit771c367411Author: Gregory Nutt <gnutt@nuttx.org> Date: Sun Jul 16 07:15:08 2017 -0600 Cosmetic changes to alignment. commit5d67ddda4eAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Sun Jul 16 07:00:48 2017 -0600 USBMSC: Add missing logic to saved device description. commit0729151d29Author: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jul 15 17:11:41 2017 -0600 Trivial, costmetic commit74b916ff84Author: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jul 15 14:50:29 2017 -0600 Composite: Private functions need to be marked static. Move static functions out of 'Public Functions' to 'Private Functions' where they belong. Disable composite configuration 1 in all STM32 F1 configurations. commitcfaa4ece13Author: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jul 15 13:20:34 2017 -0600 Add some comments. commit8143563be6Author: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jul 15 12:33:10 2017 -0600 Spark: Need to condition out MSC logic in composite setup if there is no MSC in the composite. commit69d3a91ef1Author: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jul 15 11:03:33 2017 -0600 Composite: Remove all dependencies on CONFIG_SYSTEM_COMPOSITE_* configuration settings. Nothing in the OS can depend on external application settings. commit55a4388bbdAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jul 15 09:59:31 2017 -0600 All composite configurations now also support a dual CDC/ACM configuration. commit428f2147afAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jul 15 09:24:32 2017 -0600 Composite: Move board_msc* interfaces from apps/system/composite to the board specific OS logic where they belong. commitf1cc168a5cAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jul 15 08:56:33 2017 -0600 Refresh all composite configurations. commit246afcaa10Merge:919877191d02c6672868Author: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jul 15 08:22:26 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commit919877191dAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jul 15 08:20:02 2017 -0600 Composite setup: Remove useless board_cdc* wrapper. commit82129cf8c6Merge:f2cb8b252a6537e4ea20Author: Gregory Nutt <gnutt@nuttx.org> Date: Fri Jul 14 16:23:57 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commitf2cb8b252aAuthor: Alan Carvalho de Assis <acassis@gmail.com> Date: Fri Jul 14 10:19:35 2017 -0600 Composite: Fix for another cloned typo. commit676cfd526aAuthor: Alan Carvalho de Assis <acassis@gmail.com> Date: Fri Jul 14 09:11:37 2017 -0600 Composite: Fix some typos commit1ea0368c18Author: Alan Carvalho de Assis <acassis@gmail.com> Date: Fri Jul 14 09:10:18 2017 -0600 Composite: ./stm3210e-eval/src/stm32_composite.c commite485caced9Author: Gregory Nutt <gnutt@nuttx.org> Date: Fri Jul 14 09:08:17 2017 -0600 Composite: I don't think the original code should have forced minor=0. commit6443c29621Author: Gregory Nutt <gnutt@nuttx.org> Date: Fri Jul 14 07:15:38 2017 -0600 Composite: Flesh out support for all of other configurations that support composite. commit23cbc28b05Author: Gregory Nutt <gnutt@nuttx.org> Date: Fri Jul 14 06:59:45 2017 -0600 Detangle use of board_xyzclassobject() and board_xyzuninitialize() commit1674cb8c8eMerge:6bc881a1925033a6def7Author: Gregory Nutt <gnutt@nuttx.org> Date: Thu Jul 13 13:57:40 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commit6bc881a192Merge:fe3af4941d85b8d16d8cAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Tue Jul 11 12:24:07 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commitfe3af4941dMerge:0f9ad16e181bc0eea143Author: Gregory Nutt <gnutt@nuttx.org> Date: Mon Jul 10 11:07:36 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commit0f9ad16e18Merge:a4cd90d4efaa2e9c15a5Author: Gregory Nutt <gnutt@nuttx.org> Date: Fri Jul 7 20:26:53 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commita4cd90d4efMerge:8a4be7175e31f832d8c5Author: Gregory Nutt <gnutt@nuttx.org> Date: Wed Jul 5 11:12:52 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commit8a4be7175eMerge:18a32ed2caae1771454aAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Fri Jun 30 16:14:04 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commit18a32ed2caMerge:aaa81ce4976d8df90b79Author: Gregory Nutt <gnutt@nuttx.org> Date: Thu Jun 29 10:18:16 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commitaaa81ce497Merge:4eb548226b8cb4636bb1Author: Gregory Nutt <gnutt@nuttx.org> Date: Mon Jun 26 11:56:11 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commit4eb548226bMerge:2327f5a1b4dc8eec0b61Author: Gregory Nutt <gnutt@nuttx.org> Date: Mon Jun 19 17:27:00 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commit2327f5a1b4Merge:49cd279fc699bf0b522bAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Fri Jun 16 17:30:03 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commit49cd279fc6Merge:bb6a13f30a46f86982eeAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Wed Jun 14 09:17:49 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commitbb6a13f30aMerge:918480047aac93d4bda9Author: Gregory Nutt <gnutt@nuttx.org> Date: Mon Jun 5 17:40:06 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commit918480047aMerge:e4d262436c4526cd665eAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Sat Jun 3 08:52:31 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commite4d262436cAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Fri Jun 2 07:19:27 2017 -0600 SAMV71-Xult Composite: Now can switch between two different composite configurations dynamically. commit815257743dAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Fri Jun 2 07:11:57 2017 -0600 usbdev composite and SAMV7-Xult: Move board-specific USB composite configuration out of boardctl.c and into board-specific logic where it belongs. Add a configuration option to the boardctl() calls to support multiple composite device configurations dynamically. commitac13619dc5Author: Gregory Nutt <gnutt@nuttx.org> Date: Thu Jun 1 17:03:58 2017 -0600 Cosmetic commit9dd41bdd2fAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Thu Jun 1 17:02:43 2017 -0600 Composite: More compile-related fixes commitfc1438c95dMerge:049ccbfcbeff2b54a5e0Author: Gregory Nutt <gnutt@nuttx.org> Date: Thu Jun 1 16:35:41 2017 -0600 Merge remote-tracking branch 'origin/master' into composite commit049ccbfcbeAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Thu Jun 1 16:35:16 2017 -0600 Composite: Add some structure definitions missed in first application of the patch. commitef33329e3aAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Thu Jun 1 16:14:46 2017 -0600 Add a warning commit89f77cd91aAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Thu Jun 1 16:11:27 2017 -0600 Fix some incomplete name changes commit0bb7af549aAuthor: Gregory Nutt <gnutt@nuttx.org> Date: Thu Jun 1 15:09:50 2017 -0600 It is unnecessary to pack a structure that consists only of uint8_t data fields. commitbd9b548914Author: Gregory Nutt <gnutt@nuttx.org> Date: Thu Jun 1 15:05:41 2017 -0600 Remove COMPILE_TIME_ASSERTION commit7e6f481581Author: Frank Benkert <Frank.Benkert@avat.de> Date: Thu Jun 1 14:58:04 2017 -0600 Part II of the same big commit commitdcc9b07715Author: Frank Benkert <Frank.Benkert@avat.de> Date: Thu Jun 1 14:08:22 2017 -0600 [[This is part 1 or several commits]] We developed a huge Changeset over a year ago to make USB Composite configuration dynamical and be able to instanciate the CDCACM multiple times inside this device. We use this feature to switch between one in normal and up to three CDCACMs in maintenance boot. The control path starts in “boardctl.c” where the configuration for the device is constructed. There are still a few issues which I’ll ask you to have a look at before this beast can be merged. 1. To be able to construct the data dynamically I have changed some USB-Structs to be packed. Maybe there are additional structs to change (just for completeness – not for current functionality). 2. I’ve added the Macro “COMPILE_TIME_ASSERTION” two times (in usbmsc_desc.c and in cdcacm_desc.c) to stay private. Maybe you’ll find a better place. It’s used to check the size of the structs against the assumptions. 3. I’ve changed the interface for some USB-Functions to receive also the dynamic configuration. Maybe this can be done more elegant. 4. The original NuttX (without the patch) seems to have problems with a Composite device holding a CDCACM and an MSC. The “USB SET CONFIGURATION” request does not to work at all. This makes the test fail under Windows and under Linux. Applying this patch doesn’t change anything – because it only changes the configuration – not the behavior. Maybe you’ll have a look at this problem before applying the patch.
This commit is contained in:
committed by
Gregory Nutt
parent
02c6672868
commit
eacb4f0e84
+124
-89
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* drivers/usbdev/composite.c
|
||||
*
|
||||
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2016-2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -60,17 +60,6 @@
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure describes the internal state of the driver */
|
||||
|
||||
struct composite_dev_s
|
||||
{
|
||||
FAR struct usbdev_s *usbdev; /* usbdev driver pointer */
|
||||
uint8_t config; /* Configuration number */
|
||||
FAR struct usbdev_req_s *ctrlreq; /* Allocated control request */
|
||||
struct usbdevclass_driver_s *dev1; /* Device 1 class object */
|
||||
struct usbdevclass_driver_s *dev2; /* Device 2 class object */
|
||||
};
|
||||
|
||||
/* The internal version of the class driver */
|
||||
|
||||
struct composite_driver_s
|
||||
@@ -123,6 +112,7 @@ static void composite_resume(FAR struct usbdevclass_driver_s *driver,
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* USB class device *********************************************************/
|
||||
|
||||
static const struct usbdevclass_driverops_s g_driverops =
|
||||
@@ -146,9 +136,6 @@ const char g_compserialstr[] = CONFIG_COMPOSITE_SERIALSTR;
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Helpers
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: composite_ep0incomplete
|
||||
@@ -165,7 +152,8 @@ static void composite_ep0incomplete(FAR struct usbdev_ep_s *ep,
|
||||
|
||||
if (req->result || req->xfrd != req->len)
|
||||
{
|
||||
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_REQRESULT), (uint16_t)-req->result);
|
||||
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_REQRESULT),
|
||||
(uint16_t)-req->result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,17 +173,20 @@ static int composite_classsetup(FAR struct composite_dev_s *priv,
|
||||
uint16_t index;
|
||||
uint8_t interface;
|
||||
int ret = -EOPNOTSUPP;
|
||||
int i;
|
||||
|
||||
index = GETUINT16(ctrl->index);
|
||||
interface = (uint8_t)(index & 0xff);
|
||||
|
||||
if (interface >= DEV1_FIRSTINTERFACE && interface < (DEV1_FIRSTINTERFACE + DEV1_NINTERFACES))
|
||||
for (i = 0; i < priv->ndevices; i++)
|
||||
{
|
||||
ret = CLASS_SETUP(priv->dev1, dev, ctrl, dataout, outlen);
|
||||
}
|
||||
else if (interface >= DEV2_FIRSTINTERFACE && interface < (DEV2_FIRSTINTERFACE + DEV2_NINTERFACES))
|
||||
{
|
||||
ret = CLASS_SETUP(priv->dev2, dev, ctrl, dataout, outlen);
|
||||
if (interface >= priv->device[i].compdesc.devdesc.ifnobase &&
|
||||
interface < (priv->device[i].compdesc.devdesc.ifnobase +
|
||||
priv->device[i].compdesc.devdesc.ninterfaces))
|
||||
{
|
||||
ret = CLASS_SETUP(priv->device[i].dev, dev, ctrl, dataout, outlen);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -225,6 +216,7 @@ static struct usbdev_req_s *composite_allocreq(FAR struct usbdev_ep_s *ep,
|
||||
req = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
@@ -245,6 +237,7 @@ static void composite_freereq(FAR struct usbdev_ep_s *ep,
|
||||
{
|
||||
EP_FREEBUFFER(ep, req->buf);
|
||||
}
|
||||
|
||||
EP_FREEREQ(ep, req);
|
||||
}
|
||||
}
|
||||
@@ -264,8 +257,11 @@ static void composite_freereq(FAR struct usbdev_ep_s *ep,
|
||||
static int composite_bind(FAR struct usbdevclass_driver_s *driver,
|
||||
FAR struct usbdev_s *dev)
|
||||
{
|
||||
FAR struct composite_dev_s *priv = ((FAR struct composite_driver_s *)driver)->dev;
|
||||
FAR struct composite_dev_s *priv =
|
||||
((FAR struct composite_driver_s *)driver)->dev;
|
||||
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
usbtrace(TRACE_CLASSBIND, 0);
|
||||
|
||||
@@ -281,7 +277,7 @@ static int composite_bind(FAR struct usbdevclass_driver_s *driver,
|
||||
|
||||
/* Preallocate one control request */
|
||||
|
||||
priv->ctrlreq = composite_allocreq(dev->ep0, COMPOSITE_CFGDESCSIZE);
|
||||
priv->ctrlreq = composite_allocreq(dev->ep0, priv->cfgdescsize);
|
||||
if (priv->ctrlreq == NULL)
|
||||
{
|
||||
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_ALLOCCTRLREQ), 0);
|
||||
@@ -295,16 +291,13 @@ static int composite_bind(FAR struct usbdevclass_driver_s *driver,
|
||||
|
||||
/* Then bind each of the constituent class drivers */
|
||||
|
||||
ret = CLASS_BIND(priv->dev1, dev);
|
||||
if (ret < 0)
|
||||
for (i = 0; i < priv->ndevices; i++)
|
||||
{
|
||||
goto errout;
|
||||
}
|
||||
|
||||
ret = CLASS_BIND(priv->dev2, dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
ret = CLASS_BIND(priv->device[i].dev, dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout;
|
||||
}
|
||||
}
|
||||
|
||||
/* Report if we are selfpowered */
|
||||
@@ -363,11 +356,15 @@ static void composite_unbind(FAR struct usbdevclass_driver_s *driver,
|
||||
|
||||
if (priv != NULL)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Unbind the constituent class drivers */
|
||||
|
||||
flags = enter_critical_section();
|
||||
CLASS_UNBIND(priv->dev1, dev);
|
||||
CLASS_UNBIND(priv->dev2, dev);
|
||||
for (i = 0; i < priv->ndevices; i++)
|
||||
{
|
||||
CLASS_UNBIND(priv->device[i].dev, dev);
|
||||
}
|
||||
|
||||
/* Free the pre-allocated control request */
|
||||
|
||||
@@ -377,6 +374,7 @@ static void composite_unbind(FAR struct usbdevclass_driver_s *driver,
|
||||
composite_freereq(dev->ep0, priv->ctrlreq);
|
||||
priv->ctrlreq = NULL;
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
}
|
||||
@@ -423,6 +421,7 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
|
||||
return -ENODEV;
|
||||
}
|
||||
#endif
|
||||
|
||||
ctrlreq = priv->ctrlreq;
|
||||
|
||||
/* Extract the little-endian 16-bit values to host order */
|
||||
@@ -472,10 +471,10 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
|
||||
case USB_DESC_TYPE_CONFIG:
|
||||
{
|
||||
#ifdef CONFIG_USBDEV_DUALSPEED
|
||||
ret = composite_mkcfgdesc(ctrlreq->buf, dev->speed,
|
||||
ret = composite_mkcfgdesc(priv, ctrlreq->buf, dev->speed,
|
||||
ctrl->value[1]);
|
||||
#else
|
||||
ret = composite_mkcfgdesc(ctrlreq->buf);
|
||||
ret = composite_mkcfgdesc(priv, ctrlreq->buf);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
@@ -491,18 +490,21 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
|
||||
{
|
||||
ret = composite_mkstrdesc(strid, buf);
|
||||
}
|
||||
#if DEV1_NSTRIDS > 0
|
||||
else if (strid <= DEV1_STRIDBASE + DEV1_NSTRIDS)
|
||||
else
|
||||
{
|
||||
ret = DEV1_MKSTRDESC(strid, buf);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < priv->ndevices; i++)
|
||||
{
|
||||
if (strid >= priv->device[i].compdesc.devdesc.strbase &&
|
||||
strid < priv->device[i].compdesc.devdesc.strbase +
|
||||
priv->device[i].compdesc.devdesc.nstrings)
|
||||
{
|
||||
ret = priv->device[i].compdesc.mkstrdesc(strid - priv->device[i].compdesc.devdesc.strbase, buf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if DEV2_NSTRIDS > 0
|
||||
else if (strid <= DEV2_STRIDBASE + DEV2_NSTRIDS)
|
||||
{
|
||||
ret = DEV2_MKSTRDESC(strid, buf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -519,19 +521,17 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
|
||||
{
|
||||
if (ctrl->type == 0)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Save the configuration and inform the constituent classes */
|
||||
|
||||
ret = CLASS_SETUP(priv->dev1, dev, ctrl, dataout, outlen);
|
||||
dispatched = true;
|
||||
|
||||
if (ret >= 0)
|
||||
for (i = 0; i < priv->ndevices; i++)
|
||||
{
|
||||
ret = CLASS_SETUP(priv->dev2, dev, ctrl, dataout, outlen);
|
||||
if (ret >= 0)
|
||||
{
|
||||
priv->config = value;
|
||||
}
|
||||
ret = CLASS_SETUP(priv->device[i].dev, dev, ctrl, dataout, outlen);
|
||||
}
|
||||
|
||||
dispatched = true;
|
||||
priv->config = value;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -593,10 +593,9 @@ static int composite_setup(FAR struct usbdevclass_driver_s *driver,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Respond to the setup command if (1) data was returned, and (2) the request was
|
||||
* NOT successfully dispatched to the component class driver. On an error return
|
||||
* value (ret < 0), the USB driver will stall EP0.
|
||||
/* Respond to the setup command if (1) data was returned, and (2) the
|
||||
* request was NOT successfully dispatched to the component class driver.
|
||||
* On an error return value (ret < 0), the USB driver will stall EP0.
|
||||
*/
|
||||
|
||||
if (ret >= 0 && !dispatched)
|
||||
@@ -635,6 +634,7 @@ static void composite_disconnect(FAR struct usbdevclass_driver_s *driver,
|
||||
{
|
||||
FAR struct composite_dev_s *priv;
|
||||
irqstate_t flags;
|
||||
int i;
|
||||
|
||||
usbtrace(TRACE_CLASSDISCONNECT, 0);
|
||||
|
||||
@@ -664,8 +664,12 @@ static void composite_disconnect(FAR struct usbdevclass_driver_s *driver,
|
||||
|
||||
flags = enter_critical_section();
|
||||
priv->config = COMPOSITE_CONFIGIDNONE;
|
||||
CLASS_DISCONNECT(priv->dev1, dev);
|
||||
CLASS_DISCONNECT(priv->dev2, dev);
|
||||
|
||||
for (i = 0; i < priv->ndevices; i++)
|
||||
{
|
||||
CLASS_DISCONNECT(priv->device[i].dev, dev);
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
|
||||
/* Perform the soft connect function so that we will we can be
|
||||
@@ -688,6 +692,7 @@ static void composite_suspend(FAR struct usbdevclass_driver_s *driver,
|
||||
{
|
||||
FAR struct composite_dev_s *priv;
|
||||
irqstate_t flags;
|
||||
int i;
|
||||
|
||||
usbtrace(TRACE_CLASSSUSPEND, 0);
|
||||
|
||||
@@ -714,8 +719,12 @@ static void composite_suspend(FAR struct usbdevclass_driver_s *driver,
|
||||
/* Forward the suspend event to the constituent devices */
|
||||
|
||||
flags = enter_critical_section();
|
||||
CLASS_SUSPEND(priv->dev1, priv->usbdev);
|
||||
CLASS_SUSPEND(priv->dev2, priv->usbdev);
|
||||
|
||||
for (i = 0; i < priv->ndevices; i++)
|
||||
{
|
||||
CLASS_SUSPEND(priv->device[i].dev, priv->usbdev);
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
@@ -732,6 +741,7 @@ static void composite_resume(FAR struct usbdevclass_driver_s *driver,
|
||||
{
|
||||
FAR struct composite_dev_s *priv = NULL;
|
||||
irqstate_t flags;
|
||||
int i;
|
||||
|
||||
#ifdef CONFIG_DEBUG_FEATURES
|
||||
if (!dev)
|
||||
@@ -756,8 +766,12 @@ static void composite_resume(FAR struct usbdevclass_driver_s *driver,
|
||||
/* Forward the resume event to the constituent devices */
|
||||
|
||||
flags = enter_critical_section();
|
||||
CLASS_RESUME(priv->dev1, priv->usbdev);
|
||||
CLASS_RESUME(priv->dev2, priv->usbdev);
|
||||
|
||||
for (i = 0; i < priv->ndevices; i++)
|
||||
{
|
||||
CLASS_RESUME(priv->device[i].dev, priv->usbdev);
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
@@ -770,8 +784,7 @@ static void composite_resume(FAR struct usbdevclass_driver_s *driver,
|
||||
* Description:
|
||||
* Register USB composite device as configured. This function will call
|
||||
* board-specific implementations in order to obtain the class objects for
|
||||
* each of the members of the composite (see board_mscclassobject(),
|
||||
* board_cdcclassobjec(), ...)
|
||||
* each of the members of the composite.
|
||||
*
|
||||
* Input Parameter:
|
||||
* None
|
||||
@@ -786,16 +799,22 @@ static void composite_resume(FAR struct usbdevclass_driver_s *driver,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *composite_initialize(void)
|
||||
FAR void *composite_initialize(uint8_t ndevices,
|
||||
FAR struct composite_devdesc_s *pdevices)
|
||||
{
|
||||
FAR struct composite_alloc_s *alloc;
|
||||
FAR struct composite_dev_s *priv;
|
||||
FAR struct composite_driver_s *drvr;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(pdevices != NULL && ndevices <= NUM_DEVICES_TO_HANDLE);
|
||||
|
||||
/* Allocate the structures needed */
|
||||
|
||||
alloc = (FAR struct composite_alloc_s *)kmm_malloc(sizeof(struct composite_alloc_s));
|
||||
alloc = (FAR struct composite_alloc_s *)
|
||||
kmm_malloc(sizeof(struct composite_alloc_s));
|
||||
|
||||
if (!alloc)
|
||||
{
|
||||
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_ALLOCDEVSTRUCT), 0);
|
||||
@@ -811,21 +830,32 @@ FAR void *composite_initialize(void)
|
||||
|
||||
memset(priv, 0, sizeof(struct composite_dev_s));
|
||||
|
||||
/* Get the constitueat class driver objects */
|
||||
priv->cfgdescsize = USB_SIZEOF_CFGDESC;
|
||||
priv->ninterfaces = 0;
|
||||
|
||||
ret = DEV1_CLASSOBJECT(&priv->dev1);
|
||||
if (ret < 0)
|
||||
/* Get the constituent class driver objects */
|
||||
|
||||
for (i = 0; i < ndevices; i++)
|
||||
{
|
||||
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_CLASSOBJECT), (uint16_t)-ret);
|
||||
goto errout_with_alloc;
|
||||
memcpy(&priv->device[i].compdesc, &pdevices[i],
|
||||
sizeof(struct composite_devdesc_s));
|
||||
|
||||
ret =
|
||||
priv->device[i].compdesc.classobject(priv->device[i].compdesc.minor,
|
||||
&priv->device[i].compdesc.devdesc,
|
||||
&priv->device[i].dev);
|
||||
if (ret < 0)
|
||||
{
|
||||
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_CLASSOBJECT),
|
||||
(uint16_t)-ret);
|
||||
goto errout_with_alloc;
|
||||
}
|
||||
|
||||
priv->cfgdescsize += priv->device[i].compdesc.cfgdescsize;
|
||||
priv->ninterfaces += priv->device[i].compdesc.devdesc.ninterfaces;
|
||||
}
|
||||
|
||||
ret = DEV2_CLASSOBJECT(&priv->dev2);
|
||||
if (ret < 0)
|
||||
{
|
||||
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_CLASSOBJECT), (uint16_t)-ret);
|
||||
goto errout_with_alloc;
|
||||
}
|
||||
priv->ndevices = ndevices;
|
||||
|
||||
/* Initialize the USB class driver structure */
|
||||
|
||||
@@ -840,9 +870,10 @@ FAR void *composite_initialize(void)
|
||||
/* Register the USB composite class driver */
|
||||
|
||||
ret = usbdev_register(&drvr->drvr);
|
||||
if (ret)
|
||||
if (ret < 0)
|
||||
{
|
||||
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_DEVREGISTER), (uint16_t)-ret);
|
||||
usbtrace(TRACE_CLSERROR(USBCOMPOSITE_TRACEERR_DEVREGISTER),
|
||||
(uint16_t)-ret);
|
||||
goto errout_with_alloc;
|
||||
}
|
||||
|
||||
@@ -860,8 +891,7 @@ errout_with_alloc:
|
||||
* Un-initialize the USB composite driver. The handle is the USB composite
|
||||
* class' device object as was returned by composite_initialize(). This
|
||||
* function will call board-specific implementations in order to free the
|
||||
* class objects for each of the members of the composite (see
|
||||
* board_mscuninitialize(), board_cdcuninitialize(), ...)
|
||||
* class objects for each of the members of the composite.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle returned by a previous call to composite_initialize().
|
||||
@@ -875,6 +905,7 @@ void composite_uninitialize(FAR void *handle)
|
||||
{
|
||||
FAR struct composite_alloc_s *alloc = (FAR struct composite_alloc_s *)handle;
|
||||
FAR struct composite_dev_s *priv;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(alloc != NULL);
|
||||
|
||||
@@ -882,8 +913,10 @@ void composite_uninitialize(FAR void *handle)
|
||||
|
||||
priv = &alloc->dev;
|
||||
|
||||
DEV1_UNINITIALIZE(priv->dev1);
|
||||
DEV2_UNINITIALIZE(priv->dev2);
|
||||
for (i = 0; i < priv->ndevices; i++)
|
||||
{
|
||||
priv->device[i].compdesc.uninitialize(priv->device[i].dev);
|
||||
}
|
||||
|
||||
/* Then unregister and destroy the composite class */
|
||||
|
||||
@@ -894,8 +927,10 @@ void composite_uninitialize(FAR void *handle)
|
||||
|
||||
/* Second phase uninitialization: Clean up all memory resources */
|
||||
|
||||
DEV1_UNINITIALIZE(priv->dev1);
|
||||
DEV2_UNINITIALIZE(priv->dev2);
|
||||
for (i = 0; i < priv->ndevices; i++)
|
||||
{
|
||||
priv->device[i].compdesc.uninitialize(priv->device[i].dev);
|
||||
}
|
||||
|
||||
/* Then free the composite driver state structure itself */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user