summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-28 17:15:17 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-09-28 17:15:17 +0000
commit12661a30ccbf3f21b47a03b3bc1571cf437c8687 (patch)
tree01d2443084f1e698166c221b46d8f770a3ae5435
parent70c11ed7cbd8c0de81e46e47d35ba72ca52716fc (diff)
downloadpx4-nuttx-12661a30ccbf3f21b47a03b3bc1571cf437c8687.tar.gz
px4-nuttx-12661a30ccbf3f21b47a03b3bc1571cf437c8687.tar.bz2
px4-nuttx-12661a30ccbf3f21b47a03b3bc1571cf437c8687.zip
Preparing USB environment
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@957 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/arch/arm/include/lpc214x/irq.h4
-rw-r--r--nuttx/arch/arm/src/dm320/dm320_usb.h1
-rw-r--r--nuttx/arch/arm/src/lpc214x/lpc214x_usbdev.h19
-rw-r--r--nuttx/include/debug.h20
-rw-r--r--nuttx/include/nuttx/usb.h322
-rw-r--r--nuttx/include/nuttx/usbdev.h323
6 files changed, 687 insertions, 2 deletions
diff --git a/nuttx/arch/arm/include/lpc214x/irq.h b/nuttx/arch/arm/include/lpc214x/irq.h
index 8e389218f..911f51df9 100644
--- a/nuttx/arch/arm/include/lpc214x/irq.h
+++ b/nuttx/arch/arm/include/lpc214x/irq.h
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/lpc214x/irq.h
*
- * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
- * 3. Neither the name Gregory Nutt nor the names of its contributors may be
+ * 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.
*
diff --git a/nuttx/arch/arm/src/dm320/dm320_usb.h b/nuttx/arch/arm/src/dm320/dm320_usb.h
index 0e599d336..bffb0608f 100644
--- a/nuttx/arch/arm/src/dm320/dm320_usb.h
+++ b/nuttx/arch/arm/src/dm320/dm320_usb.h
@@ -223,6 +223,7 @@
/* TXFIFO2 register bit settings **************************************************/
+#define USB_TXFIF02_SZMASK (0xe0)
#define USB_TXFIFO2_SZ_8 (0x00)
#define USB_TXFIFO2_SZ_16 (0x20)
#define USB_TXFIFO2_SZ_32 (0x40)
diff --git a/nuttx/arch/arm/src/lpc214x/lpc214x_usbdev.h b/nuttx/arch/arm/src/lpc214x/lpc214x_usbdev.h
index c98919138..97ceea9e9 100644
--- a/nuttx/arch/arm/src/lpc214x/lpc214x_usbdev.h
+++ b/nuttx/arch/arm/src/lpc214x/lpc214x_usbdev.h
@@ -47,6 +47,15 @@
* Definitions
*******************************************************************************/
+/* PINSEL1 bit definitions for UART0/1:
+ *
+ * P0.23 = 01 to enable VBus sense (bits 14-15)
+ * P0.31 = 10 to enable CONNECT (bits 30-31)
+ */
+
+#define LPC214X_USBDEV_PINSEL (0x80004000) /* PINSEL1 value for USB */
+#define LPC214X_USBDEV_PINMASK (0xc000c000) /* PINSEL1 mask for USB */
+
/* USB RAM ********************************************************************/
#define LPC214X_USBDEV_RAMBASE (0x7fd00000)
@@ -260,6 +269,16 @@
/* Command Responses ***********************************************************/
+/* EP Select response */
+
+#define CMD_USB_EPSELECT_FE (0x01) /* Bit 0=1: IN empty or OUT full */
+#define CMD_USB_EPSELECT_ST (0x02) /* Bit 1=1: Endpoint is stalled */
+#define CMD_USB_EPSELECT_STP (0x04) /* Bit 2=1: Last packet was setup */
+#define CMD_USB_EPSELECT_PO (0x05) /* Bit 3=1: Previous packet was overwritten */
+#define CMD_USB_EPSELECT_EPN (0x10) /* Bit 4=1: NAK sent */
+#define CMD_USB_EPSELECT_B1FULL (0x20) /* Bit 5=1: Buffer 1 full */
+#define CMD_USB_EPSELECT_B2FULL (0x40) /* Bit 6=1: Buffer 2 full */
+
/* EP CLRBUFFER response */
#define CMD_USB_CLRBUFFER_PO (0x00000001)
diff --git a/nuttx/include/debug.h b/nuttx/include/debug.h
index c76c57313..c07eb97cc 100644
--- a/nuttx/include/debug.h
+++ b/nuttx/include/debug.h
@@ -123,6 +123,16 @@
# define nvdbg(x...)
#endif
+#ifdef CONFIG_DEBUG_USB
+# define udbg(format, arg...) dbg(format, ##arg)
+# define ulldbg(format, arg...) lldbg(format, ##arg)
+# define uvdbg(format, arg...) vdbg(format, ##arg)
+#else
+# define udbg(x...)
+# define ulldbg(x...)
+# define uvdbg(x...)
+#endif
+
#ifdef CONFIG_DEBUG_FS
# define fdbg(format, arg...) dbg(format, ##arg)
# define flldbg(format, arg...) lldbg(format, ##arg)
@@ -192,6 +202,16 @@
# define nvdbg (void)
#endif
+#ifdef CONFIG_DEBUG_USB
+# define udbg dbg
+# define ulldbg lldbg
+# define uvdbg vdbg
+#else
+# define udbg (void)
+# define ulldbg (void)
+# define uvdbg (void)
+#endif
+
#ifdef CONFIG_DEBUG_FS
# define fdbg dbg
# define flldbg lldbg
diff --git a/nuttx/include/nuttx/usb.h b/nuttx/include/nuttx/usb.h
new file mode 100644
index 000000000..687a13c9c
--- /dev/null
+++ b/nuttx/include/nuttx/usb.h
@@ -0,0 +1,322 @@
+/************************************************************************************
+ * include/nuttx/usb.h
+ *
+ * Copyright (C) 2008 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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.
+ *
+ ************************************************************************************/
+
+#ifndef __NUTTX_USB_H
+#define __NUTTX_USB_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+
+/************************************************************************************
+ * Definitions
+ ************************************************************************************/
+
+/* All 16-bit values must be little-endian */
+
+#define MSBYTE(u16) ((u16) >> 8) /* Get MS byte from uint16 */
+#define LSBYTE(u16) ((u16) & 0xff) /* Get LS byte from uint16 */
+
+#define GETUINT16(p) (((uint16)p[1] << 8)|(uint16)p[1]);
+
+/* USB directions (in endpoint addresses) */
+
+#define USB_DIR_OUT 0x00 /* To the device */
+#define USB_DIR_IN 0x80 /* To the host */
+
+#define USB_EPNO(addr) ((addr)&0x7f)
+#define USB_EPOUT(addr) ((addr)|USB_DIR_OUT)
+#define USB_EPIN(addr) ((addr)|USB_DIR_IN)
+
+/* Standard requests */
+
+#define USB_REQ_GETSTATUS 0x00
+#define USB_REQ_CLEARFEATURE 0x01
+#define USB_REQ_SETFEATURE 0x03
+#define USB_REQ_SETADDRESS 0x05
+#define USB_REQ_GETDESCRIPTOR 0x06
+#define USB_REQ_SETDESCRIPTOR 0x07
+#define USB_REQ_GETCONFIGURATION 0x08
+#define USB_REQ_SETCONFIGURATION 0x09
+#define USB_REQ_GETINTERFACE 0x0a
+#define USB_REQ_SETINTERFACE 0x0b
+#define USB_REQ_SYNCHFRAME 0x0c
+
+#define USB_REQ_SETENCRYPTION 0x0d /* Wireless USB */
+#define USB_REQ_GETENCRYPTION 0x0e
+#define USB_REQ_SETHANDSHAKE 0x0f
+#define USB_REQ_GETHANDSHAKE 0x10
+#define USB_REQ_SETCONNECTION 0x11
+#define USB_REQ_SETSECURITYDATA 0x12
+#define USB_REQ_GETSECURITYDATA 0x13
+#define USB_REQ_SETWUSBDATA 0x14
+#define USB_REQ_LOOPBACKDATAWRITE 0x15
+#define USB_REQ_LOOPBACKDATAREAD 0x16
+#define USB_REQ_SETINTERFACEDS 0x17
+
+/* Request type encoding */
+
+#define USB_REQ_RECIPIENT_MASK 0x1f
+#define USB_REQ_RECIPIENT_DEVICE 0x00
+#define USB_REQ_RECIPIENT_INTERFACE 0x01
+#define USB_REQ_RECIPIENT_ENDPOINT 0x02
+#define USB_REQ_RECIPIENT_OTHER 0x03
+#define USB_REQ_TYPE_MASK 0x60
+#define USB_REQ_DIR_IN 0x80
+
+/* USB feature values */
+
+#define USB_FEATURE_SELFPOWERED 0
+#define USB_FEATURE_REMOTEWAKEUP 1
+#define USB_FEATURE_TESTMODE 2
+#define USB_FEATURE_BATTERY 2
+#define USB_FEATURE_BHNPENABLE 3
+#define USB_FEATURE_WUSBDEVICE 3
+#define USB_FEATURE_AHNPSUPPORT 4
+#define USB_FEATURE_AALTHNPSUPPORT 5
+#define USB_FEATURE_DEBUGMODE 6
+
+#define USB_ENDPOINT_HALT 0
+
+/* Generic descriptor header offsets */
+
+#define USB_DESC_DESCLENOFFSET 0
+#define USB_DESC_DESCTYPEOFFSET 1
+
+/* Descriptor types */
+
+#define USB_DESC_TYPE_DEVICE 0x01
+#define USB_DESC_TYPE_CONFIG 0x02
+#define USB_DESC_TYPE_STRING 0x03
+#define USB_DESC_TYPE_INTERFACE 0x04
+#define USB_DESC_TYPE_ENDPOINT 0x05
+#define USB_DESC_TYPE_DEVICEQUALIFIER 0x06
+#define USB_DESC_TYPE_OTHERSPEEDCONFIG 0x07
+#define USB_DESC_TYPE_INTERFACEPOWER 0x08
+#define USB_DESC_TYPE_OTG 0x09
+#define USB_DESC_TYPE_DEBUG 0x0a
+#define USB_DESC_TYPE_INTERFACEASSOCIATION 0x0b
+#define USB_DESC_TYPE_SECURITY 0x0c
+#define USB_DESC_TYPE_KEY 0x0d
+#define USB_DESC_TYPE_ENCRYPTION_TYPE 0x0e
+#define USB_DESC_TYPE_BOS 0x0f
+#define USB_DESC_TYPE_DEVICECAPABILITY 0x10
+#define USB_DESC_TYPE_WIRELESS_ENDPOINTCOMP 0x11
+#define USB_DESC_TYPE_CSDEVICE 0x21
+#define USB_DESC_TYPE_CSCONFIG 0x22
+#define USB_DESC_TYPE_CSSTRING 0x23
+#define USB_DESC_TYPE_CSINTERFACE 0x24
+#define USB_DESC_TYPE_CSENDPOINT 0x25
+
+/* Device and interface descriptor class codes */
+
+#define USB_CLASS_PER_INTERFACE 0x00
+#define USB_CLASS_AUDIO 0x01
+#define USB_CLASS_COMM 0x02
+#define USB_CLASS_HID 0x03
+#define USB_CLASS_PHYSICAL 0x05
+#define USB_CLASS_STILL_IMAGE 0x06
+#define USB_CLASS_PRINTER 0x07
+#define USB_CLASS_MASS_STORAGE 0x08
+#define USB_CLASS_HUB 0x09
+#define USB_CLASS_CDC_DATA 0x0a
+#define USB_CLASS_CSCID 0x0b
+#define USB_CLASS_CONTENT_SEC 0x0d
+#define USB_CLASS_VIDEO 0x0e
+#define USB_CLASS_WIRELESS_CONTROLLER 0xe0
+#define USB_CLASS_APP_SPEC 0xfe
+#define USB_CLASS_VENDOR_SPEC 0xff
+
+/* Values for configuration descriptor attributes */
+
+#define USB_CONFIG_ATTR_ONE (1 << 7) /* Must be one */
+#define USB_CONFIG_ATTR_SELFPOWER (1 << 6) /* Self-powered */
+#define USB_CONFIG_ATTR_WAKEUP (1 << 5) /* Remote wakeup */
+#define USB_CONFIG_ATTR_BATTERY (1 << 4) /* Battery powered */
+
+/* Endpoint descriptor address */
+
+#define USB_EP_ADDR_NUMBER_MASK 0x0f
+#define USB_EP_ADDR_DIR_MASK 0x80
+
+/* Endpoint descriptor attributes */
+
+#define USB_EP_ATTR_XFERTYPE_MASK 0x03
+#define USB_EP_ATTR_XFER_CONTROL 0x00
+#define USB_EP_ATTR_XFER_ISOC 0x01
+#define USB_EP_ATTR_XFER_BULK 0x02
+#define USB_EP_ATTR_XFER_INT 0x03
+#define USB_EP_ATTR_MAX_ADJUSTABLE 0x80
+
+/************************************************************************************
+ * Public Types
+ ************************************************************************************/
+
+/* This structure is used to send control requests to a USB device. */
+
+struct usb_ctrlreq_s
+{
+ ubyte type; /* Matches request type */
+ ubyte req; /* Matches request field */
+ ubyte value[2];
+ ubyte index[2];
+ ubyte len[2];
+};
+
+/* Generic descriptor */
+
+struct usb_devdesc_s
+{
+ ubyte len; /* Descriptor length */
+ ubyte type; /* Descriptor type */
+};
+
+/* Device descriptor */
+
+struct usb_devdesc_s
+{
+ ubyte len; /* Descriptor length */
+ ubyte type; /* Descriptor type */
+ ubyte usb[2]; /* USB version */
+ ubyte class; /* Device class */
+ ubyte subclass; /* Device sub-class */
+ ubyte protocol; /* Device protocol */
+ ubyte mxpacketsize; /* Max packet size (ep0) */
+ ubyte vender[2]; /* Vendor ID */
+ ubyte product[2]; /* Product ID */
+ ubyte device[2]; /* Device ID */
+ ubyte imfgr; /* Manufacturer */
+ ubyte iproduct; /* Product */
+ ubyte serno; /* Serial number */
+ ubyte nconfigs; /* Number of configurations */
+};
+
+/* Configuration descriptor */
+
+struct usb_cfgdesc_s
+{
+ ubyte len; /* Descriptor length */
+ ubyte type; /* Descriptor type */
+ ubyte totallen[2]; /* Total length */
+ ubyte ninterfaces; /* Number of interfaces */
+ ubyte cfgvalue; /* Configuration value */
+ ubyte icfg; /* Configuration */
+ ubyte attr; /* Attributes */
+ ubyte mxpower; /* Max power (mA/2) */
+};
+
+/* String descriptor */
+
+struct usb_strdesc_s
+{
+ ubyte len; /* Descriptor length */
+ ubyte type; /* Descriptor type */
+ ubyte data[2];
+};
+
+/* Interface descriptor */
+
+struct usb_ifdesc_s
+{
+ ubyte len; /* Descriptor length */
+ ubyte type; /* Descriptor type */
+ ubyte ifno; /* Interface number */
+ ubyte alt; /* Alternate setting */
+ ubyte neps; /* Number of endpoints */
+ ubyte class; /* Interface class */
+ ubyte subclass; /* Interface sub-class */
+ ubyte protocol; /* Interface protocol */
+ ubyte iif; /* iInterface */
+};
+
+/* Endpoint descriptor */
+
+struct usb_epdesc_s
+{
+ ubyte len; /* Descriptor length */
+ ubyte type; /* Descriptor type */
+ ubyte addr; /* Endpoint address */
+ ubyte attr; /* Endpoint attributes */
+ ubyte mxpacketsize[2]; /* Maximum packet size */
+ ubyte interval; /* Interval */
+};
+
+struct usb_audioepdesc_s
+{
+ struct usb_epdesc_s ep;
+ ubyte refresh;
+ ubyte synchaddr;
+};
+
+/* Device qualifier descriptor */
+
+struct usb_qualdesc_s
+{
+ ubyte len; /* Descriptor length */
+ ubyte type; /* Descriptor type */
+ ubyte usb[2]; /* USB version */
+ ubyte class; /* Qualifier class */
+ ubyte subclass; /* Qualifier sub-class */
+ ubyte protocol; /* Qualifier protocol */
+ ubyte mxpacketsize; /* Max packet size (ep0) */
+ ubyte nconfigs; /* Number of configurations */
+ ubyte reserved;
+};
+
+/************************************************************************************
+ * Private Data
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Data
+ ************************************************************************************/
+
+extern const struct usb_devdesc_s UsbStandardDeviceDescriptorStr;
+extern const ubyte UsbStandardConfigurationDescriptor[];
+extern const ubyte UsbLanguagesStr[];
+extern const ubyte *const *const UsbString[];
+
+/************************************************************************************
+ * Private Functions
+ ************************************************************************************/
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+#endif // __NUTTX_USB_H
diff --git a/nuttx/include/nuttx/usbdev.h b/nuttx/include/nuttx/usbdev.h
new file mode 100644
index 000000000..f5c6f23e7
--- /dev/null
+++ b/nuttx/include/nuttx/usbdev.h
@@ -0,0 +1,323 @@
+/************************************************************************************
+ * include/nuttx/usbdev.h
+ *
+ * Copyright (C) 2008 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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.
+ *
+ ************************************************************************************/
+
+#ifndef _INCLUDE_NUTTX_USBDEV_H
+#define _INCLUDE_NUTTX_USBDEV_H
+
+/************************************************************************************
+ * Included Files
+ ************************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+
+/************************************************************************************
+ * Definitions
+ ************************************************************************************/
+
+/* Endpoint helpers *****************************************************************/
+
+/* Configure endpoint, making it usable. The class driver may deallocate or re-use
+ * the 'desc' structure after returning
+ */
+
+#define EP_CONFIGURE(ep,desc) ep->ops->configure(ep,desc)
+
+/* The endpoint will no longer be used */
+
+#define EP_DISABLE(ep) ep->ops->disable(ep)
+
+/* Allocate/free I/O requests */
+
+#define EP_ALLOCREQ(ep,nytes) ep->ops->allocreq(ep)
+#define EP_FREEREQ(ep,buff) ep->ops->freereq(ep,req)
+
+/* Allocate/free an I/O buffer */
+
+#ifdef CONFIG_ARCH_USBDEV_DMA
+# define EP_ALLOCBUFFER(ep,nytes) ep->ops->alloc(ep,nbytes)
+# define EP_FREEBUFFER(ep,buff) ep->ops->free(ep,buf)
+#else
+# define EP_ALLOCBUFFER(ep,nytes) malloc(nbytes)
+# define EP_FREEBUFFER(ep,buff) free(buf)
+#endif
+
+/* Submit an I/O request to the endpoint */
+
+#define EP_SUBMIT(ep,req) ep->ops->submit(ep,req)
+
+/* Cancel an I/O request previously sent to an endpoint */
+
+#define EP_CANCEL(ep,req) ep->ops->cancel(ep,req)
+
+/* Stall or resume an endpoint */
+
+#define EP_STALL(ep) ep->ops->stall(ep,FALSE)
+#define EP_RESUME(ep) ep->ops->stall(ep,TRUE)
+
+/* USB Device Driver Helpers ********************************************************/
+
+/* Allocate an endpoint:
+ *
+ * epphy - 7-bit physical endpoint number (without diretion bit). Zero means
+ * that any endpoint matching the other requirements will suffice.
+ * in - TRUE: IN (device-to-host) endpoint requested
+ * eptype - Endpoint type. One of {USB_EP_ATTR_XFER_ISOC, USB_EP_ATTR_XFER_BULK,
+ * USB_EP_ATTR_XFER_INT}
+ */
+
+#define DEV_ALLOCEP(dev,epno,in,type) dev->ops->allocep(dev, epphy, in, type)
+
+/* Release an endpoint */
+
+#define DEV_FREEP(dev,epno,in) dev->ops->allocep(dev, ep)
+
+/* Returns the current frame number */
+
+#define DEV_GETFRAME(dev) dev->ops->getframe(dev)
+
+/* Tries to wake up the host connected to this device */
+
+#define DEV_WAKEUP(dev) dev->ops->wakeup(dev)
+
+/* Sets the device selfpowered feature */
+
+#define DEV_SETSELFPOWERED(dev) dev->ops->selfpowered(dev, TRUE)
+
+/* Clears the device selfpowered feature */
+
+#define DEV_CLRSELFPOWERED(dev) dev->ops->selfpowered(dev, FALSE)
+
+/* Software-controlled connect to USB host */
+
+#define DEV_CONNECT(dev) dev->ops->pullup ? dev->ops->pullup(dev, TRUE) : -EOPNOTSUPP
+
+/* Software-controlled disconnect from USB host */
+
+#define DEV_DISCONNECT(dev) dev->ops->pullup ? dev->ops->pullup(dev, FALSE) : -EOPNOTSUPP
+
+/* USB Class Driver Helpsers ********************************************************/
+
+/* Invoked when the driver is bound to a USB device driver */
+
+#define CLASS_BIND(dev) (dev)->ops->bind(dev)
+
+/* Invoked when the driver is unbound from a USB device driver */
+
+#define CLASS_UNBIND(dev) (dev)->ops->unbind(dev)
+
+/* Invoked after all transfers have been stopped, when the host is disconnected. */
+
+#define CLASS_DISCONNECT(dev) (dev)->ops->disconnect(dev)
+
+/* Invoked for ep0 control requests */
+
+#define CLASS_SETUP(dev,req) (dev)->ops->setup(dev, req)
+
+/* Invoked on USB suspend. */
+
+#define CLASS_SUSPEND(dev) (dev)->ops->suspend ? (dev)->ops->suspend(dev) : (void)
+
+/* Invoked on USB resume */
+
+#define CLASS_RESUME(dev) (dev)->ops->resume ? (dev)->ops->resume(dev) : (void)
+
+/* Device speeds */
+
+#define USB_SPEED_LOW 1 /* USB 1.1 */
+#define USB_SPEED_FULL 2 /* USB 1.1 */
+#define USB_SPEED_HIGH 3 /* USB 2.0 */
+#define USB_SPEED_VARIABLE 4 /* Wireless USB 2.5 */
+
+/************************************************************************************
+ * Public Types
+ ************************************************************************************/
+
+/* USB Controller Structures ********************************************************/
+
+/* struct usbdev_req_s - describes one i/o request */
+
+struct usbdev_ep_s;
+struct usbdev_req_s
+{
+ char *buf; /* Call: Buffer used for data; Return: Unchanged */
+ uint16 len; /* Call: Length of data in buf; Return: bytes transferred */
+ sint16 result; /* Call: zero; Return: result of transfer
+
+ /* Callback when the transfer completes */
+
+ void (*callback)(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req);
+ void *private; /* Used only by callee */
+};
+
+/* Endpoint-specific interface to USB controller hardware. */
+
+struct usbdev_epops_s
+{
+ /* Configure/enable and disable endpoint */
+
+ int (*configure)(FAR struct usbdev_ep_s *ep, FAR const struct usb_epdesc_s *desc);
+ int (*disable)(FAR struct usbdev_ep_s *ep);
+
+ /* Allocate and free I/O requests */
+
+ FAR struct usbdev_req_s *(*allocreq)(FAR struct usbdev_ep_s *ep);
+ void (*freereq)(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req);
+
+ /* Allocate and free I/O buffers */
+
+#ifdef CONFIG_ARCH_USBDEV_DMA
+ FAR void *(*allocbuffer)(FAR struct usbdev_ep_s *ep, uint16 nbytes);
+ void (*freebuffer)(FAR struct usbdev_ep_s *ep, FAR void *buf);
+#endif
+
+ /* Submit and cancel I/O requests */
+
+ int (*submit)(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req);
+ int (*cancel)(FAR struct usbdev_ep_s *ep, FAR struct usbdev_req_s *req);
+
+ /* Stall or resume an endpoint */
+
+ int (*stall)(FAR struct usbdev_ep_s *ep, boolean resume);
+};
+
+/* Representation of one USB endpoint */
+
+struct usbdev_ep_s
+{
+ const struct usbdev_epops_s *ops; /* Endpoint operations */
+ uint16 maxpacket; /* Maximum packet size for this endpoint */
+ void *private; /* For use by class driver */
+};
+
+/* struct usbdev_s represents a usb device */
+
+struct usbdev_s;
+struct usbdev_ops_s
+{
+ /* Allocate and free endpoints */
+
+ FAR struct usbdev_ep_s *(*allocep)(FAR struct usbdev_s *dev, ubyte epphy, boolean in, ubyte eptype);
+ void (*freeep)(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep);
+
+ /* Get the frame number from the last SOF */
+
+ int (*getframe)(FAR struct usbdev_s *dev);
+
+ /* Hardware specific features */
+
+ int (*wakeup)(FAR struct usbdev_s *dev);
+ int (*selfpowered)(FAR struct usbdev_s *dev, boolean selfpowered);
+ int (*pullup)(FAR struct usbdev_s *dev, boolean enable);
+
+ /* Device-specific I/O command support */
+
+ int (*ioctl)(FAR struct usbdev_s *dev, unsigned code, unsigned long param);
+};
+
+struct usbdev_s
+{
+ const struct usbdev_ops_s *ops; /* Access to hardware specific features */
+ struct usbdev_ep_s *ep0; /* Endpoint zero */
+ ubyte speed; /* Current speed of host connection */
+ ubyte dualspeed:1; /* 1:supports high and full speed operation */
+};
+
+/* USB Device Class Implementations *************************************************/
+
+struct usbdevclass_driverops_s
+{
+ int (*bind)(FAR struct usbdev_s *dev, void *private);
+ void (*unbind)(FAR struct usbdev_s *dev);
+ int (*setup)(FAR struct usbdev_s *dev, const struct usb_ctrlreq_s *req);
+ void (*disconnect)(FAR struct usbdev_s *dev);
+ void (*suspend)(FAR struct usbdev_s *dev);
+ void (*resume)(FAR struct usbdev_s *dev);
+};
+
+struct usbdevclass_driver_s
+{
+ const struct usbdevclass_driverops_s ops;
+ ubyte speed; /* Highest speed that the driver handles */
+};
+
+/************************************************************************************
+ * Public Data
+ ************************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+# define EXTERN extern "C"
+extern "C"
+{
+#else
+# define EXTERN extern
+#endif
+
+/************************************************************************************
+ * Public Functions
+ ************************************************************************************/
+
+/* USB Controller Structures ********************************************************/
+
+/************************************************************************************
+ * Name: usbdevclass_register
+ *
+ * Description:
+ * Register a USB device class driver. The class driver's bind() method will be
+ * called to bind it to a USB device driver.
+ *
+ ************************************************************************************/
+
+EXTERN int usbdev_register(FAR struct usbdevclass_driver_s *driver);
+
+/************************************************************************************
+ * Name: usbdev_unregister
+ *
+ * Description:
+ * Un-register usbdev class driver.If the USB device is connected to a USB host,
+ * it will first disconnect(). The driver is also requested to unbind() and clean
+ * up any device state, before this procedure finally returns.
+ *
+ ************************************************************************************/
+
+EXTERN int usbdev_unregister(FAR struct usbdevclass_driver_s *driver);
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* _INCLUDE_NUTTX_USBDEV_H */