nuttx/configs/pnev5180b/src/lpc17_composite.c

149 lines
5.1 KiB
C

/*****************************************************************************
* configs/pnev5180b/src/lpc17_composite.c
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Author: Michael Jung <mijung@gmx.net>
*
* Configure and register CDC-ACM and CDC-ECM
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*****************************************************************************/
/*****************************************************************************
* Included Files
*****************************************************************************/
#include <nuttx/config.h>
#include <syslog.h>
#include <stddef.h>
#include <nuttx/usb/cdcacm.h>
#include <nuttx/usb/cdcecm.h>
#include <nuttx/usb/composite.h>
#if defined(CONFIG_BOARDCTL_USBDEVCTRL) && defined(CONFIG_USBDEV_COMPOSITE)
/*****************************************************************************
* Public Functions
*****************************************************************************/
/*****************************************************************************
* Name: board_composite_initialize
*
* Description:
* Perform architecture specific initialization of a composite USB device.
*
*****************************************************************************/
int board_composite_initialize(int port)
{
syslog(LOG_INFO, "board_composite_initialize(port: %d)\n", port);
return OK;
}
/*****************************************************************************
* 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)
{
struct composite_devdesc_s dev[2];
int ifnobase = 0;
int strbase = COMPOSITE_NSTRIDS;
syslog(LOG_INFO, "board_composite_connect(port: %d, configid: %d)\n",
port, configid);
/* 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 = cdcacm_classobject;
dev[0].uninitialize = cdcacm_uninitialize;
/* Interfaces */
dev[0].devinfo.ifnobase = ifnobase; /* Offset to Interface-IDs */
dev[0].minor = 0; /* The minor interface number */
/* Strings */
dev[0].devinfo.strbase = strbase; /* Offset to String Numbers */
/* Endpoints */
dev[0].devinfo.epno[CDCACM_EP_INTIN_IDX] = 1;
dev[0].devinfo.epno[CDCACM_EP_BULKIN_IDX] = 5;
dev[0].devinfo.epno[CDCACM_EP_BULKOUT_IDX] = 2;
/* Count up the base numbers */
ifnobase += dev[0].devinfo.ninterfaces;
strbase += dev[0].devinfo.nstrings;
/* Configure the CDC/ECM device */
cdcecm_get_composite_devdesc(&dev[1]);
dev[1].devinfo.ifnobase = ifnobase; /* Offset to Interface-IDs */
dev[1].devinfo.strbase = strbase; /* Offset to String Numbers */
dev[1].minor = 0; /* The minor interface number */
dev[1].devinfo.epno[CDCECM_EP_INTIN_IDX] = 4;
dev[1].devinfo.epno[CDCECM_EP_BULKIN_IDX] = 11;
dev[1].devinfo.epno[CDCECM_EP_BULKOUT_IDX] = 8;
return composite_initialize(2, dev);
}
#endif /* CONFIG_BOARDCTL_USBDEVCTRL && CONFIG_USBDEV_COMPOSITE */