Exemplo n.º 1
0
static int16_t usbclass_mkcfgdesc(uint8_t * buf, uint8_t speed, uint8_t type)
{
    struct usb_cfgdesc_s *cfgdesc = (struct usb_cfgdesc_s *)buf;
    bool hispeed = (speed == USB_SPEED_HIGH);
    uint16_t mxpacket;
    uint16_t totallen;

    /* This is the total length of the configuration (not necessarily the
     * size that we will be sending now.
     */

    totallen =
        USB_SIZEOF_CFGDESC + USB_SIZEOF_IFDESC +
        APBRIDGE_NENDPOINTS * USB_SIZEOF_EPDESC;

    /* Configuration descriptor -- Copy the canned descriptor and fill in the
     * type (we'll also need to update the size below
     */

    memcpy(cfgdesc, &g_cfgdesc, USB_SIZEOF_CFGDESC);
    buf += USB_SIZEOF_CFGDESC;

    /*  Copy the canned interface descriptor */

    memcpy(buf, &g_ifdesc, USB_SIZEOF_IFDESC);
    buf += USB_SIZEOF_IFDESC;

    /* Make the three endpoint configurations.  First, check for switches
     * between high and full speed
     */

    if (type == USB_DESC_TYPE_OTHERSPEEDCONFIG) {
        hispeed = !hispeed;
    }

    if (hispeed) {
        mxpacket = APBRIDGE_EPINTIN_MXPACKET;
    } else {
        mxpacket = 64;
    }

    usbclass_mkepdesc(&g_epintindesc, mxpacket, (struct usb_epdesc_s *)buf);
    buf += USB_SIZEOF_EPDESC;

    if (hispeed) {
        mxpacket = APBRIDGE_BULK_MXPACKET;
    } else {
        mxpacket = 64;
    }

    usbclass_mkepdesc(&g_epbulkoutdesc, mxpacket, (struct usb_epdesc_s *)buf);
    buf += USB_SIZEOF_EPDESC;
    usbclass_mkepdesc(&g_epbulkindesc, mxpacket, (struct usb_epdesc_s *)buf);

    /* Finally, fill in the total size of the configuration descriptor */

    cfgdesc->totallen[0] = LSBYTE(totallen);
    cfgdesc->totallen[1] = MSBYTE(totallen);
    return totallen;
}
Exemplo n.º 2
0
int usbmsc_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
{
  const char *str;
  int len;
  int ndata;
  int i;

  switch (id)
    {
#ifndef CONFIG_USBMSC_COMPOSITE
    case 0:
      {
        /* Descriptor 0 is the language id */

        strdesc->len     = 4;
        strdesc->type    = USB_DESC_TYPE_STRING;
        strdesc->data[0] = LSBYTE(USBMSC_STR_LANGUAGE);
        strdesc->data[1] = MSBYTE(USBMSC_STR_LANGUAGE);
        return 4;
      }

      case USBMSC_MANUFACTURERSTRID:
      str = g_mscvendorstr;
      break;

    case USBMSC_PRODUCTSTRID:
      str = g_mscproductstr;
      break;

    case USBMSC_SERIALSTRID:
      str = g_mscserialstr;
      break;
#endif

 /* case USBMSC_CONFIGSTRID: */
    case USBMSC_INTERFACESTRID:
      str = CONFIG_USBMSC_CONFIGSTR;
      break;

    default:
      return -EINVAL;
    }

   /* The string is utf16-le.  The poor man's utf-8 to utf16-le
    * conversion below will only handle 7-bit en-us ascii
    */

   len = strlen(str);
   for (i = 0, ndata = 0; i < len; i++, ndata += 2)
     {
       strdesc->data[ndata]   = str[i];
       strdesc->data[ndata+1] = 0;
     }

   strdesc->len  = ndata+2;
   strdesc->type = USB_DESC_TYPE_STRING;
   return strdesc->len;
}
Exemplo n.º 3
0
void cdcacm_cpepdesc(FAR const struct usb_epdesc_s *indesc, uint16_t mxpacket, FAR struct usb_epdesc_s *outdesc)
{
	/* Copy the "canned" descriptor */

	memcpy(outdesc, indesc, USB_SIZEOF_EPDESC);

	/* Then add the correct max packet size */

	outdesc->mxpacketsize[0] = LSBYTE(mxpacket);
	outdesc->mxpacketsize[1] = MSBYTE(mxpacket);
}
Exemplo n.º 4
0
static int usbclass_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
{
    const char *str;
    int len;
    int ndata;
    int i;

    switch (id) {
    case 0:
        {
            /* Descriptor 0 is the language id */

            strdesc->len = 4;
            strdesc->type = USB_DESC_TYPE_STRING;
            strdesc->data[0] = LSBYTE(APBRIDGE_STR_LANGUAGE);
            strdesc->data[1] = MSBYTE(APBRIDGE_STR_LANGUAGE);
            return 4;
        }

    case APBRIDGE_MANUFACTURERSTRID:
        str = CONFIG_APBRIDGE_VENDORSTR;
        break;

    case APBRIDGE_PRODUCTSTRID:
        str = CONFIG_APBRIDGE_PRODUCTSTR;
        break;

    case APBRIDGE_SERIALSTRID:
        str = CONFIG_APBRIDGE_SERIALSTR;
        break;

    case APBRIDGE_CONFIGSTRID:
        str = CONFIG_APBRIDGE_CONFIGSTR;
        break;

    default:
        return -EINVAL;
    }

    /* The string is utf16-le.  The poor man's utf-8 to utf16-le
     * conversion below will only handle 7-bit en-us ascii
     */

    len = strlen(str);
    for (i = 0, ndata = 0; i < len; i++, ndata += 2) {
        strdesc->data[ndata] = str[i];
        strdesc->data[ndata + 1] = 0;
    }

    strdesc->len = ndata + 2;
    strdesc->type = USB_DESC_TYPE_STRING;
    return strdesc->len;
}
Exemplo n.º 5
0
static inline void usbclass_mkepdesc(const struct usb_epdesc_s *indesc,
                                     uint16_t mxpacket,
                                     struct usb_epdesc_s *outdesc)
{
    /* Copy the canned descriptor */

    memcpy(outdesc, indesc, USB_SIZEOF_EPDESC);

    /* Then add the correct max packet size */

    outdesc->mxpacketsize[0] = LSBYTE(mxpacket);
    outdesc->mxpacketsize[1] = MSBYTE(mxpacket);
}
Exemplo n.º 6
0
/****************************************************************************
 * Private Data
 ****************************************************************************/
/* Descriptors **************************************************************/
/* Device descriptor.  If the USB mass storage device is configured as part
 * of a composite device, then the device descriptor will be provided by the
 * composite device logic.
 */

#ifndef CONFIG_USBMSC_COMPOSITE
static const struct usb_devdesc_s g_devdesc =
{
  USB_SIZEOF_DEVDESC,                           /* len */
  USB_DESC_TYPE_DEVICE,                         /* type */
  {LSBYTE(0x0200), MSBYTE(0x0200)},             /* usb */
  USB_CLASS_PER_INTERFACE,                      /* classid */
  0,                                            /* subclass */
  0,                                            /* protocol */
  CONFIG_USBMSC_EP0MAXPACKET,                   /* maxpacketsize */
  {                                             /* vendor */
    LSBYTE(CONFIG_USBMSC_VENDORID),
    MSBYTE(CONFIG_USBMSC_VENDORID)
  },
  {                                             /* product */
    LSBYTE(CONFIG_USBMSC_PRODUCTID),
    MSBYTE(CONFIG_USBMSC_PRODUCTID) },
  {                                             /* device */
    LSBYTE(CONFIG_USBMSC_VERSIONNO),
    MSBYTE(CONFIG_USBMSC_VERSIONNO)
  },
Exemplo n.º 7
0
/****************************************************************************
 * Private Function Prototypes
 ****************************************************************************/

/****************************************************************************
 * Private Data
 ****************************************************************************/
/* Device Descriptor */

static const struct usb_devdesc_s g_devdesc =
{
  USB_SIZEOF_DEVDESC,                           /* len */
  USB_DESC_TYPE_DEVICE,                         /* type */
  {                                             /* usb */
    LSBYTE(0x0200),
    MSBYTE(0x0200)
  },
#ifdef CONFIG_COMPOSITE_IAD
  USB_CLASS_MISC,                               /* classid */
  2,                                            /* subclass */
  1,                                            /* protocol */
#else
  USB_CLASS_PER_INTERFACE,                      /* classid */
  0,                                            /* subclass */
  0,                                            /* protocol */
#endif
  CONFIG_COMPOSITE_EP0MAXPACKET,                /* maxpacketsize */
  {
    LSBYTE(CONFIG_COMPOSITE_VENDORID),          /* vendor */
    MSBYTE(CONFIG_COMPOSITE_VENDORID)
  },
Exemplo n.º 8
0
int cdcacm_mkstrdesc(uint8_t id, struct usb_strdesc_s *strdesc)
{
#if !defined(CONFIG_CDCACM_COMPOSITE) || defined(CONFIG_CDCACM_NOTIFSTR) || \
	 defined(CONFIG_CDCACM_DATAIFSTR)

	const char *str;
	int len;
	int ndata;
	int i;

	switch (id) {
#ifndef CONFIG_CDCACM_COMPOSITE
	case 0: {
		/* Descriptor 0 is the language id */

		strdesc->len = 4;
		strdesc->type = USB_DESC_TYPE_STRING;
		strdesc->data[0] = LSBYTE(CDCACM_STR_LANGUAGE);
		strdesc->data[1] = MSBYTE(CDCACM_STR_LANGUAGE);
		return 4;
	}

	case CDCACM_MANUFACTURERSTRID:
		str = CONFIG_CDCACM_VENDORSTR;
		break;

	case CDCACM_PRODUCTSTRID:
		str = CONFIG_CDCACM_PRODUCTSTR;
		break;

	case CDCACM_SERIALSTRID:
		str = CONFIG_CDCACM_SERIALSTR;
		break;

	case CDCACM_CONFIGSTRID:
		str = CONFIG_CDCACM_CONFIGSTR;
		break;
#endif

#ifdef CONFIG_CDCACM_NOTIFSTR
	case CDCACM_NOTIFSTRID:
		str = CONFIG_CDCACM_NOTIFSTR;
		break;
#endif

#ifdef CONFIG_CDCACM_DATAIFSTR
	case CDCACM_DATAIFSTRID:
		str = CONFIG_CDCACM_DATAIFSTR;
		break;
#endif

	default:
		return -EINVAL;
	}

	/* The string is utf16-le.  The poor man's utf-8 to utf16-le
	 * conversion below will only handle 7-bit en-us ascii
	 */

	len = strlen(str);
	if (len > (CDCACM_MAXSTRLEN / 2)) {
		len = (CDCACM_MAXSTRLEN / 2);
	}

	for (i = 0, ndata = 0; i < len; i++, ndata += 2) {
		strdesc->data[ndata] = str[i];
		strdesc->data[ndata + 1] = 0;
	}

	strdesc->len = ndata + 2;
	strdesc->type = USB_DESC_TYPE_STRING;
	return strdesc->len;
#else
	return -EINVAL;
#endif
}
Exemplo n.º 9
0
 * Private Data
 ****************************************************************************/

/* USB descriptor templates these will be copied and modified **************/
/* Device Descriptor.  If the USB serial device is configured as part of
 * composite device, then the device descriptor will be provided by the
 * composite device logic.
 */

#ifndef CONFIG_CDCACM_COMPOSITE
static const struct usb_devdesc_s g_devdesc = {
	USB_SIZEOF_DEVDESC,			/* len */
	USB_DESC_TYPE_DEVICE,		/* type */
	{							/* usb */
		LSBYTE(0x0200),
		MSBYTE(0x0200)
	},
	USB_CLASS_CDC,				/* class */
	CDC_SUBCLASS_NONE,			/* subclass */
	CDC_PROTO_NONE,				/* protocol */
	CONFIG_CDCACM_EP0MAXPACKET,	/* maxpacketsize */
	{
		LSBYTE(CONFIG_CDCACM_VENDORID),	/* vendor */
		MSBYTE(CONFIG_CDCACM_VENDORID)
	},
	{
		LSBYTE(CONFIG_CDCACM_PRODUCTID),	/* product */
		MSBYTE(CONFIG_CDCACM_PRODUCTID)
	},
	{
		LSBYTE(CDCACM_VERSIONNO),	/* device */
Exemplo n.º 10
0
static const struct usbdevclass_driverops_s g_driverops = {
    usbclass_bind,              /* bind */
    usbclass_unbind,            /* unbind */
    usbclass_setup,             /* setup */
    usbclass_disconnect,        /* disconnect */
    NULL,                       /* suspend */
    NULL,                       /* resume */
};

/* USB descriptor templates these will be copied and modified **************/

static const struct usb_devdesc_s g_devdesc = {
    USB_SIZEOF_DEVDESC,         /* len */
    USB_DESC_TYPE_DEVICE,       /* type */
    {LSBYTE(0x0200), MSBYTE(0x0200)},   /* usb */
    USB_CLASS_PER_INTERFACE,    /* classid */
    0,                          /* subclass */
    0,                          /* protocol */
    CONFIG_APBRIDGE_EP0MAXPACKET,       /* maxpacketsize */
    {LSBYTE(CONFIG_APBRIDGE_VENDORID),  /* vendor */
     MSBYTE(CONFIG_APBRIDGE_VENDORID)},
    {LSBYTE(CONFIG_APBRIDGE_PRODUCTID), /* product */
     MSBYTE(CONFIG_APBRIDGE_PRODUCTID)},
    {LSBYTE(APBRIDGE_VERSIONNO),        /* device */
     MSBYTE(APBRIDGE_VERSIONNO)},
    APBRIDGE_MANUFACTURERSTRID, /* imfgr */
    APBRIDGE_PRODUCTSTRID,      /* iproduct */
    APBRIDGE_SERIALSTRID,       /* serno */
    APBRIDGE_NCONFIGS           /* nconfigs */
};