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.

This commit is contained in:
Gregory Nutt 2017-06-02 07:11:57 -06:00
parent ac13619dc5
commit 815257743d
4 changed files with 194 additions and 81 deletions

View File

@ -181,86 +181,11 @@ static inline int boardctl_usbdevctrl(FAR struct boardioc_usbdev_ctrl_s *ctrl)
case BOARDIOC_USBDEV_CONNECT: /* Connect the Composite device */
{
#warning THIS DOES NOT BELONG HERE!!!!!!!!!!!!!!!!!!!!!!!!!!
#warning THIS BELONGS IN BOARD-SPECIFIC LOGIC!!!!!!!!!!!!!!!!!!!!!!!!!!
/* Here we are composing the configuration of the usb composite device.
*
* The standard is to use one CDC/ACM and one USB mass storage device.
*/
struct composite_devdesc_s dev[2];
int ifnobase = 0;
int strbase = COMPOSITE_NSTRIDS;
DEBUGASSERT(ctrl->handle != NULL);
/* Configure the CDC/ACM device */
*ctrl->handle =
board_composite_connect(ctrl->instance, ctrl->config);
/* Ask the cdcacm driver to fill in the constants we didn't
* know here.
*/
cdcacm_get_composite_devdesc(&dev[0]);
/* Overwrite and correct some values... */
/* The callback functions for the CDC/ACM class */
dev[0].classobject = board_cdcclassobject;
dev[0].uninitialize = board_cdcuninitialize;
/* Interfaces */
dev[0].devdesc.ifnobase = ifnobase; /* Offset to Interface-IDs */
dev[0].minor = CONFIG_SYSTEM_COMPOSITE_TTYUSB; /* The minor interface number */
/* Strings */
dev[0].devdesc.strbase = strbase; /* Offset to String Numbers */
/* Endpoints */
dev[0].devdesc.epno[CDCACM_EP_INTIN_IDX] = 3;
dev[0].devdesc.epno[CDCACM_EP_BULKIN_IDX] = 4;
dev[0].devdesc.epno[CDCACM_EP_BULKOUT_IDX] = 5;
/* Count up the base numbers */
ifnobase += dev[0].devdesc.ninterfaces;
strbase += dev[0].devdesc.nstrings;
/* Configure the mass storage device device */
/* Ask the usbmsc driver to fill in the constants we didn't
* know here.
*/
usbmsc_get_composite_devdesc(&dev[1]);
/* Overwrite and correct some values... */
/* The callback functions for the USBMSC class */
dev[1].classobject = board_mscclassobject;
dev[1].uninitialize = board_mscuninitialize;
/* Interfaces */
dev[1].devdesc.ifnobase = ifnobase; /* Offset to Interface-IDs */
dev[1].minor = CONFIG_SYSTEM_COMPOSITE_DEVMINOR1; /* The minor interface number */
/* Strings */
dev[1].devdesc.strbase = strbase; /* Offset to String Numbers */
/* Endpoints */
dev[1].devdesc.epno[USBMSC_EP_BULKIN_IDX] = 1;
dev[1].devdesc.epno[USBMSC_EP_BULKOUT_IDX] = 2;
/* Count up the base numbers */
ifnobase += dev[1].devdesc.ninterfaces;
strbase += dev[1].devdesc.nstrings;
*ctrl->handle = composite_initialize(2, dev);
if (*ctrl->handle == NULL)
{
ret = -EIO;
@ -268,7 +193,8 @@ static inline int boardctl_usbdevctrl(FAR struct boardioc_usbdev_ctrl_s *ctrl)
}
break;
case BOARDIOC_USBDEV_DISCONNECT: /* Disconnect the Composite device */
case BOARDIOC_USBDEV_DISCONNECT: /* Disconnect the Composite
* device */
{
DEBUGASSERT(ctrl->handle != NULL && *ctrl->handle != NULL);
composite_uninitialize(*ctrl->handle);

View File

@ -1,7 +1,7 @@
/****************************************************************************
* configs/samv71-xult/src/sam_composite.c
*
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2016, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -44,7 +44,7 @@
#include "samv71-xult.h"
#ifdef CONFIG_USBDEV_COMPOSITE
#if defined(CONFIG_BOARDCTL_USBDEVCTRL) && defined(CONFIG_USBDEV_COMPOSITE)
/****************************************************************************
* Public Functions
@ -63,4 +63,168 @@ int board_composite_initialize(int port)
return OK;
}
#endif /* CONFIG_USBDEV_COMPOSITE */
/****************************************************************************
* Name: board_composite_connect
*
* Description:
* Connect the USB composite device on the specified USB device port using
* the specified configuration. The interpretation of the configid is
* board specific.
*
* Input Parameters:
* port - The USB device port.
* configid - The USB composite configuration
*
* Returned Value:
* A non-NULL handle value is returned on success. NULL is returned on
* any failure.
*
****************************************************************************/
FAR void *board_composite_connect(int port, int configid)
{
/* Here we are composing the configuration of the usb composite device.
*
* The standard is to use one CDC/ACM and one USB mass storage device.
*
* You will also find an example below which generates three CDC/ACM
* devices. This example can be used on samv71-xult.
*/
#if 1
struct composite_devdesc_s dev[2];
int ifnobase = 0;
int strbase = COMPOSITE_NSTRIDS;
/* Configure the CDC/ACM device */
/* Ask the cdcacm driver to fill in the constants we didn't
* know here.
*/
cdcacm_get_composite_devdesc(&dev[0]);
/* Overwrite and correct some values... */
/* The callback functions for the CDC/ACM class */
dev[0].classobject = board_cdcclassobject;
dev[0].uninitialize = board_cdcuninitialize;
/* Interfaces */
dev[0].devdesc.ifnobase = ifnobase; /* Offset to Interface-IDs */
dev[0].minor = CONFIG_SYSTEM_COMPOSITE_TTYUSB; /* The minor interface number */
/* Strings */
dev[0].devdesc.strbase = strbase; /* Offset to String Numbers */
/* Endpoints */
dev[0].devdesc.epno[CDCACM_EP_INTIN_IDX] = 3;
dev[0].devdesc.epno[CDCACM_EP_BULKIN_IDX] = 4;
dev[0].devdesc.epno[CDCACM_EP_BULKOUT_IDX] = 5;
/* Count up the base numbers */
ifnobase += dev[0].devdesc.ninterfaces;
strbase += dev[0].devdesc.nstrings;
/* Configure the mass storage device device */
/* Ask the usbmsc driver to fill in the constants we didn't
* know here.
*/
usbmsc_get_composite_devdesc(&dev[1]);
/* Overwrite and correct some values... */
/* The callback functions for the USBMSC class */
dev[1].classobject = board_mscclassobject;
dev[1].uninitialize = board_mscuninitialize;
/* Interfaces */
dev[1].devdesc.ifnobase = ifnobase; /* Offset to Interface-IDs */
dev[1].minor = CONFIG_SYSTEM_COMPOSITE_DEVMINOR1; /* The minor interface number */
/* Strings */
dev[1].devdesc.strbase = strbase; /* Offset to String Numbers */
/* Endpoints */
dev[1].devdesc.epno[USBMSC_EP_BULKIN_IDX] = 1;
dev[1].devdesc.epno[USBMSC_EP_BULKOUT_IDX] = 2;
/* Count up the base numbers */
ifnobase += dev[1].devdesc.ninterfaces;
strbase += dev[1].devdesc.nstrings;
return composite_initialize(2, dev);
#else
/* Example with three CDC/ACMs
*
* This Example can be used e.g. on a samv71-xult. The samv71 has
* 10 Endpoints (EPs). The EPs 0 up to 7 are DMA aware. The EPs 8
* and 9 are not.
*
* In a composite device we need the EP0 as an control Endpoint.
* Each CDC/ACM needs one Interrupt driven and two bulk Endpoints.
* This is why we configure the EPs 7, 8 and 9 to be the IRQ-EPs
* and the EP-Pairs 1/2, 3/4, 5/6 to be the bulk EPs for each
* device.
*
* This means, that
*
* - the Composite device uses EP0 as the control-Endpoint,
* - the CDC/ACM 0 uses EP7, EP1 and EP2,
* - the CDC/ACM 1 uses EP8, EP3 and EP4,
* - the CDC/ACM 2 uses EP9, EP5 and EP6
*
* as its EP-Configuration.
*/
struct composite_devdesc_struct dev[3];
int strbase = COMPOSITE_NSTRIDS;
int ifnobase = 0;
int ia;
for (ia = 0; ia < 3; ia++)
{
/* Ask the cdcacm driver to fill in the constants we didn't know here */
cdcacm_get_composite_devdesc(&dev[ia]);
/* Overwrite and correct some values... */
/* The callback functions for the CDC/ACM class */
dev[ia].classobject = cdcacm_classobject;
dev[ia].uninitialize = cdcacm_uninitialize;
dev[ia].minor = ia; /* The minor interface number */
/* Interfaces */
dev[ia].devdesc.ifnobase = ifnobase; /* Offset to Interface-IDs */
/* Strings */
dev[ia].devdesc.strbase = strbase; /* Offset to String Numbers */
/* Endpoints */
dev[ia].devdesc.epno[CDCACM_EP_INTIN_IDX] = 7 + ia;
dev[ia].devdesc.epno[CDCACM_EP_BULKIN_IDX] = 1 + ia * 2;
dev[ia].devdesc.epno[CDCACM_EP_BULKOUT_IDX] = 2 + ia * 2;
ifnobase += dev[ia].devdesc.ninterfaces;
strbase += dev[ia].devdesc.nstrings;
}
return composite_initialize(3, dev);
#endif
}
#endif /* CONFIG_BOARDCTL_USBDEVCTRL && CONFIG_USBDEV_COMPOSITE */

View File

@ -263,6 +263,28 @@ int board_composite_initialize(int port);
#endif
#endif
/****************************************************************************
* Name: board_composite_connect
*
* Description:
* Connect the USB composite device on the specified USB device port using
* the specified configuration. The interpretation of the configid is
* board specific.
*
* Input Parameters:
* port - The USB device port.
* configid - The USB composite configuration
*
* Returned Value:
* A non-NULL handle value is returned on success. NULL is returned on
* any failure.
*
****************************************************************************/
#if defined(CONFIG_BOARDCTL_USBDEVCTRL) && defined(CONFIG_USBDEV_COMPOSITE)
FAR void *board_composite_connect(int port, int configid);
#endif
/****************************************************************************
* Name: board_tsc_setup
*

View File

@ -247,6 +247,7 @@ struct boardioc_usbdev_ctrl_s
uint8_t usbdev; /* See enum boardioc_usbdev_identifier_e */
uint8_t action; /* See enum boardioc_usbdev_action_e */
uint8_t instance; /* Identifies the USB device class instance */
uint8_t config; /* Configuration used with BOARDIOC_USBDEV_CONNECT */
FAR void **handle; /* Connection handle */
};
#endif /* CONFIG_BOARDCTL_USBDEVCTRL */