2021-01-28 19:21:44 +01:00
|
|
|
/****************************************************************************
|
2010-12-14 03:33:39 +00:00
|
|
|
* include/nuttx/usb/usbdev.h
|
2008-09-28 17:15:17 +00:00
|
|
|
*
|
2021-01-29 14:39:49 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
|
* License. You may obtain a copy of the License at
|
2008-09-28 17:15:17 +00:00
|
|
|
*
|
2021-01-29 14:39:49 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-09-30 22:13:52 +00:00
|
|
|
*
|
2021-01-29 14:39:49 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
|
* under the License.
|
2008-09-28 17:15:17 +00:00
|
|
|
*
|
2021-01-28 19:21:44 +01:00
|
|
|
****************************************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2016-08-06 19:21:42 -06:00
|
|
|
#ifndef __INCLUDE_NUTTX_USB_USBDEV_H
|
|
|
|
|
#define __INCLUDE_NUTTX_USB_USBDEV_H
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/****************************************************************************
|
2008-09-28 17:15:17 +00:00
|
|
|
* Included Files
|
2021-01-28 19:21:44 +01:00
|
|
|
****************************************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2009-12-14 23:32:23 +00:00
|
|
|
|
2008-09-28 17:15:17 +00:00
|
|
|
#include <sys/types.h>
|
2009-12-14 23:32:23 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdbool.h>
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2012-01-26 19:37:34 +00:00
|
|
|
#include <nuttx/usb/pl2303.h>
|
|
|
|
|
#include <nuttx/usb/cdcacm.h>
|
|
|
|
|
#include <nuttx/usb/usbmsc.h>
|
|
|
|
|
#include <nuttx/usb/composite.h>
|
|
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/****************************************************************************
|
2009-12-14 23:32:23 +00:00
|
|
|
* Pre-processor Definitions
|
2021-01-28 19:21:44 +01:00
|
|
|
****************************************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/* Endpoint helpers *********************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/* Configure endpoint, making it usable.
|
|
|
|
|
* The class driver may deallocate or re-use the 'desc' structure after
|
|
|
|
|
* returning:
|
2008-10-09 15:14:17 +00:00
|
|
|
*
|
|
|
|
|
* ep - the struct usbdev_ep_s instance obtained from allocep()
|
|
|
|
|
* desc - A struct usb_epdesc_s instance describing the endpoint
|
2021-01-28 19:21:44 +01:00
|
|
|
* last - true if this is the last endpoint to be configured. Some hardware
|
|
|
|
|
* needs to take special action when all of the endpoints have been
|
|
|
|
|
* configured.
|
2008-09-28 17:15:17 +00:00
|
|
|
*/
|
|
|
|
|
|
2008-10-09 15:14:17 +00:00
|
|
|
#define EP_CONFIGURE(ep,desc,last) (ep)->ops->configure(ep,desc,last)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* The endpoint will no longer be used */
|
|
|
|
|
|
2008-09-30 20:53:58 +00:00
|
|
|
#define EP_DISABLE(ep) (ep)->ops->disable(ep)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Submit an I/O request to the endpoint */
|
|
|
|
|
|
2008-09-30 20:53:58 +00:00
|
|
|
#define EP_SUBMIT(ep,req) (ep)->ops->submit(ep,req)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Cancel an I/O request previously sent to an endpoint */
|
|
|
|
|
|
2008-09-30 20:53:58 +00:00
|
|
|
#define EP_CANCEL(ep,req) (ep)->ops->cancel(ep,req)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Stall or resume an endpoint */
|
|
|
|
|
|
2009-12-14 23:32:23 +00:00
|
|
|
#define EP_STALL(ep) (ep)->ops->stall(ep,false)
|
|
|
|
|
#define EP_RESUME(ep) (ep)->ops->stall(ep,true)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/* USB Device Driver Helpers ************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Allocate an endpoint:
|
|
|
|
|
*
|
2021-01-28 19:21:44 +01:00
|
|
|
* ep - 7-bit logical endpoint number (direction bit ignored).
|
|
|
|
|
* Zero means that any endpoint matching the other requirements
|
|
|
|
|
* will suffice.
|
|
|
|
|
* The assigned endpoint can be found in the eplog field.
|
2009-12-14 23:32:23 +00:00
|
|
|
* in - true: IN (device-to-host) endpoint requested
|
2021-01-28 19:21:44 +01:00
|
|
|
* eptype - Endpoint type. One of {USB_EP_ATTR_XFER_ISOC,
|
|
|
|
|
* USB_EP_ATTR_XFER_BULK, USB_EP_ATTR_XFER_INT}
|
2008-09-28 17:15:17 +00:00
|
|
|
*/
|
|
|
|
|
|
2008-09-30 20:53:58 +00:00
|
|
|
#define DEV_ALLOCEP(dev,ep,in,type) (dev)->ops->allocep(dev,ep,in,type)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Release an endpoint */
|
|
|
|
|
|
2008-09-30 20:53:58 +00:00
|
|
|
#define DEV_FREEEP(dev,ep) (dev)->ops->freeep(dev,ep)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Returns the current frame number */
|
|
|
|
|
|
2008-09-30 20:53:58 +00:00
|
|
|
#define DEV_GETFRAME(dev) (dev)->ops->getframe(dev)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Tries to wake up the host connected to this device */
|
|
|
|
|
|
2008-09-30 20:53:58 +00:00
|
|
|
#define DEV_WAKEUP(dev) (dev)->ops->wakeup(dev)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Sets the device selfpowered feature */
|
|
|
|
|
|
2009-12-14 23:32:23 +00:00
|
|
|
#define DEV_SETSELFPOWERED(dev) (dev)->ops->selfpowered(dev,true)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Clears the device selfpowered feature */
|
|
|
|
|
|
2009-12-14 23:32:23 +00:00
|
|
|
#define DEV_CLRSELFPOWERED(dev) (dev)->ops->selfpowered(dev, false)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/* Software-controlled connect to USB host. All USB class drivers need to
|
|
|
|
|
* call DEV_CONNECT() when they are ready to be enumerated. That is, (1)
|
|
|
|
|
* initially when bound to the USB driver, and (2) after a USB reset.
|
2010-12-04 17:35:19 +00:00
|
|
|
*/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2009-12-14 23:32:23 +00:00
|
|
|
#define DEV_CONNECT(dev) (dev)->ops->pullup ? (dev)->ops->pullup(dev,true) : -EOPNOTSUPP
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Software-controlled disconnect from USB host */
|
|
|
|
|
|
2009-12-14 23:32:23 +00:00
|
|
|
#define DEV_DISCONNECT(dev) (dev)->ops->pullup ? (dev)->ops->pullup(dev,false) : -EOPNOTSUPP
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/* USB Class Driver Helpers *************************************************/
|
Sources and Docs: Fix typos and nxstyle issues
Documentation/contributing/coding_style.rst:
* Fix repeated words: ("this this").
* Remove trailing spaces.
boards/z80/z80/z80sim/README.txt:
* Fix repeated words: ("this this") and rewrap lines.
graphics/Kconfig,
libs/libc/math/Kconfig:
* Fix repeated words: ("this this").
arch/arm/src/armv7-a/arm_assert.c,
arch/arm/src/armv7-r/arm_assert.c,
arch/arm/src/imxrt/imxrt_enet.c,
arch/arm/src/kinetis/kinetis_enet.c,
arch/arm/src/kinetis/kinetis_flexcan.c,
arch/arm/src/s32k1xx/s32k1xx_enet.c,
arch/arm/src/s32k1xx/s32k1xx_flexcan.c,
arch/arm/src/stm32/stm32_pwm.c,
arch/arm/src/stm32h7/stm32_pwm.c,
arch/arm/src/stm32l4/stm32l4_pwm.c,
arch/renesas/src/rx65n/rx65n_usbdev.c,
binfmt/libnxflat/libnxflat_bind.c,
drivers/pipes/pipe_common.c,
net/igmp/igmp_input.c,
net/tcp/tcp_conn.c,
sched/sched/sched_roundrobin.c:
* Fix typo in comment ("this this").
arch/arm/src/cxd56xx/cxd56_usbdev.c,
arch/arm/src/lc823450/lc823450_usbdev.c:
* Fix typo in comment and rewrap lines.
arch/arm/src/imxrt/imxrt_usbdev.c,
arch/arm/src/stm32/stm32_dac.c,
arch/arm/src/stm32f0l0g0/stm32_pwm.c,
arch/arm/src/stm32f7/stm32_pwm.c,
arch/arm/src/tiva/lm/lm4f_gpio.h,
fs/nxffs/nxffs_write.c,
include/nuttx/analog/pga11x.h,
include/nuttx/usb/usbdev.h,
net/mld/mld_join.c:
* Fix typo in comment ("this this").
* Fix nxstyle issues.
2020-10-01 19:29:35 -04:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/* All may be called from interrupt handling logic except bind() and
|
|
|
|
|
* unbind()
|
|
|
|
|
*/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2008-10-08 20:17:08 +00:00
|
|
|
/* Invoked when the driver is bound to a USB device driver. */
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2012-01-26 17:42:44 +00:00
|
|
|
#define CLASS_BIND(drvr,dev) (drvr)->ops->bind(drvr,dev)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Invoked when the driver is unbound from a USB device driver */
|
|
|
|
|
|
2012-01-26 17:42:44 +00:00
|
|
|
#define CLASS_UNBIND(drvr,dev) (drvr)->ops->unbind(drvr,dev)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/* Invoked after all transfers have been stopped, when the host is
|
|
|
|
|
* disconnected.
|
|
|
|
|
*/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2012-01-26 17:42:44 +00:00
|
|
|
#define CLASS_DISCONNECT(drvr,dev) (drvr)->ops->disconnect(drvr,dev)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Invoked for ep0 control requests */
|
|
|
|
|
|
2012-04-12 16:30:48 +00:00
|
|
|
#define CLASS_SETUP(drvr,dev,ctrl,dataout,outlen) \
|
|
|
|
|
(drvr)->ops->setup(drvr,dev,ctrl,dataout,outlen)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Invoked on USB suspend. */
|
|
|
|
|
|
2012-01-25 19:27:20 +00:00
|
|
|
#define CLASS_SUSPEND(drvr,dev) \
|
2012-01-26 17:42:44 +00:00
|
|
|
do { if ((drvr)->ops->suspend) (drvr)->ops->suspend(drvr,dev); } while (0)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Invoked on USB resume */
|
|
|
|
|
|
2012-01-25 19:27:20 +00:00
|
|
|
#define CLASS_RESUME(drvr,dev) \
|
2012-01-26 17:42:44 +00:00
|
|
|
do { if ((drvr)->ops->resume) (drvr)->ops->resume(drvr,dev); } while (0)
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2013-09-01 11:31:12 -06:00
|
|
|
/* Maximum size of a request buffer */
|
|
|
|
|
|
|
|
|
|
#define USBDEV_MAXREQUEUST UINT16_MAX
|
|
|
|
|
|
2008-10-25 14:40:37 +00:00
|
|
|
/* Request flags */
|
|
|
|
|
|
2010-05-26 12:51:06 +00:00
|
|
|
#define USBDEV_REQFLAGS_NULLPKT 1 /* Bit 0: Terminate w/short packet; null packet if necessary */
|
|
|
|
|
/* Bits 1-7: Available */
|
2008-10-25 14:40:37 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/****************************************************************************
|
2008-09-28 17:15:17 +00:00
|
|
|
* Public Types
|
2021-01-28 19:21:44 +01:00
|
|
|
****************************************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/* USB Controller Structures ************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2023-08-24 19:30:54 +08:00
|
|
|
struct usbdev_strdesc_s
|
|
|
|
|
{
|
|
|
|
|
uint8_t id;
|
|
|
|
|
FAR const char *string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct usbdev_strdescs_s
|
|
|
|
|
{
|
|
|
|
|
uint16_t language;
|
|
|
|
|
FAR const struct usbdev_strdesc_s *strdesc;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct usbdev_devdescs_s
|
|
|
|
|
{
|
|
|
|
|
FAR const struct usb_cfgdesc_s *cfgdesc;
|
|
|
|
|
FAR const struct usbdev_strdescs_s *strdescs;
|
|
|
|
|
FAR const struct usb_devdesc_s *devdesc;
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
|
FAR const struct usb_qualdesc_s *qualdesc;
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
2023-07-19 10:09:41 +08:00
|
|
|
struct usbdev_epinfo_s
|
|
|
|
|
{
|
|
|
|
|
struct usb_epdesc_s desc;
|
|
|
|
|
uint16_t fssize;
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
|
uint16_t hssize;
|
|
|
|
|
#endif
|
|
|
|
|
uint16_t reqnum;
|
|
|
|
|
};
|
|
|
|
|
|
2017-07-20 09:34:48 -06:00
|
|
|
/* usbdev_devinfo_s - describes the low level bindings of an usb device */
|
2017-07-16 08:43:17 -06:00
|
|
|
|
2017-07-20 09:34:48 -06:00
|
|
|
struct usbdev_devinfo_s
|
2017-07-16 08:43:17 -06:00
|
|
|
{
|
2023-07-19 10:09:41 +08:00
|
|
|
FAR const char *name;
|
2017-07-16 08:43:17 -06:00
|
|
|
int ninterfaces; /* Number of interfaces in the configuration */
|
|
|
|
|
int ifnobase; /* Offset to Interface-IDs */
|
|
|
|
|
|
|
|
|
|
int nstrings; /* Number of Strings */
|
|
|
|
|
int strbase; /* Offset to String Numbers */
|
|
|
|
|
|
|
|
|
|
int nendpoints; /* Number of Endpoints referenced in the following allay */
|
|
|
|
|
int epno[5]; /* Array holding the endpoint configuration for this device */
|
2023-07-19 10:09:41 +08:00
|
|
|
FAR const struct usbdev_epinfo_s **epinfos;
|
2017-07-16 08:43:17 -06:00
|
|
|
};
|
|
|
|
|
|
2023-07-05 09:23:26 +08:00
|
|
|
struct usbdevclass_driver_s;
|
2017-07-16 08:43:17 -06:00
|
|
|
struct composite_devdesc_s
|
|
|
|
|
{
|
|
|
|
|
#ifdef CONFIG_USBDEV_DUALSPEED
|
|
|
|
|
CODE int16_t (*mkconfdesc)(FAR uint8_t *buf,
|
2017-07-21 07:51:45 -06:00
|
|
|
FAR struct usbdev_devinfo_s *devinfo,
|
2017-07-16 08:43:17 -06:00
|
|
|
uint8_t speed, uint8_t type);
|
|
|
|
|
#else
|
|
|
|
|
CODE int16_t (*mkconfdesc)(FAR uint8_t *buf,
|
2017-07-21 07:51:45 -06:00
|
|
|
FAR struct usbdev_devinfo_s *devinfo);
|
2017-07-16 08:43:17 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
CODE int (*mkstrdesc)(uint8_t id, FAR struct usb_strdesc_s *strdesc);
|
|
|
|
|
CODE int (*classobject)(int minor,
|
2017-07-21 07:51:45 -06:00
|
|
|
FAR struct usbdev_devinfo_s *devinfo,
|
2017-07-16 08:43:17 -06:00
|
|
|
FAR struct usbdevclass_driver_s **classdev);
|
|
|
|
|
CODE void (*uninitialize)(FAR struct usbdevclass_driver_s *classdev);
|
|
|
|
|
|
|
|
|
|
int nconfigs; /* Number of configurations supported */
|
|
|
|
|
int configid; /* The only supported configuration ID */
|
|
|
|
|
|
|
|
|
|
int cfgdescsize; /* The size of the config descriptor */
|
|
|
|
|
int minor;
|
|
|
|
|
|
2018-11-02 18:12:07 +02:00
|
|
|
#ifdef CONFIG_COMPOSITE_MSFT_OS_DESCRIPTORS
|
|
|
|
|
uint8_t msft_compatible_id[8];
|
|
|
|
|
uint8_t msft_sub_id[8];
|
|
|
|
|
#endif
|
2020-01-31 07:15:01 -08:00
|
|
|
|
2017-07-21 07:51:45 -06:00
|
|
|
struct usbdev_devinfo_s devinfo;
|
2017-07-16 08:43:17 -06:00
|
|
|
};
|
|
|
|
|
|
2008-09-28 17:15:17 +00:00
|
|
|
/* struct usbdev_req_s - describes one i/o request */
|
|
|
|
|
|
|
|
|
|
struct usbdev_ep_s;
|
|
|
|
|
struct usbdev_req_s
|
|
|
|
|
{
|
2009-12-14 23:32:23 +00:00
|
|
|
uint8_t *buf; /* Call: Buffer used for data; Return: Unchanged */
|
|
|
|
|
uint8_t flags; /* See USBDEV_REQFLAGS_* definitions */
|
|
|
|
|
uint16_t len; /* Call: Total length of data in buf; Return: Unchanged */
|
|
|
|
|
uint16_t xfrd; /* Call: zero; Return: Bytes transferred so far */
|
|
|
|
|
int16_t result; /* Call: zero; Return: Result of transfer (O or -errno) */
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Callback when the transfer completes */
|
|
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
CODE void (*callback)(FAR struct usbdev_ep_s *ep,
|
|
|
|
|
FAR struct usbdev_req_s *req);
|
2019-11-02 18:12:59 -06:00
|
|
|
FAR void *priv; /* Used only by callee */
|
2008-09-28 17:15:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Endpoint-specific interface to USB controller hardware. */
|
|
|
|
|
|
|
|
|
|
struct usbdev_epops_s
|
|
|
|
|
{
|
|
|
|
|
/* Configure/enable and disable endpoint */
|
|
|
|
|
|
2019-11-02 18:12:59 -06:00
|
|
|
CODE int (*configure)(FAR struct usbdev_ep_s *ep,
|
|
|
|
|
FAR const struct usb_epdesc_s *desc, bool last);
|
|
|
|
|
CODE int (*disable)(FAR struct usbdev_ep_s *ep);
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Allocate and free I/O requests */
|
|
|
|
|
|
2019-11-02 18:12:59 -06:00
|
|
|
CODE FAR struct usbdev_req_s *(*allocreq)(FAR struct usbdev_ep_s *ep);
|
|
|
|
|
CODE void (*freereq)(FAR struct usbdev_ep_s *ep,
|
|
|
|
|
FAR struct usbdev_req_s *req);
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Allocate and free I/O buffers */
|
|
|
|
|
|
2012-09-13 14:14:18 +00:00
|
|
|
#ifdef CONFIG_USBDEV_DMA
|
2019-11-02 18:12:59 -06:00
|
|
|
CODE FAR void *(*allocbuffer)(FAR struct usbdev_ep_s *ep, uint16_t nbytes);
|
|
|
|
|
CODE void (*freebuffer)(FAR struct usbdev_ep_s *ep, FAR void *buf);
|
2008-09-28 17:15:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Submit and cancel I/O requests */
|
|
|
|
|
|
2019-11-03 09:28:37 -06:00
|
|
|
CODE int (*submit)(FAR struct usbdev_ep_s *ep,
|
2019-11-02 18:12:59 -06:00
|
|
|
FAR struct usbdev_req_s *req);
|
2019-11-03 13:16:30 -06:00
|
|
|
CODE int (*cancel)(FAR struct usbdev_ep_s *ep,
|
2019-11-02 18:12:59 -06:00
|
|
|
FAR struct usbdev_req_s *req);
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Stall or resume an endpoint */
|
|
|
|
|
|
2019-11-02 18:12:59 -06:00
|
|
|
CODE int (*stall)(FAR struct usbdev_ep_s *ep, bool resume);
|
2008-09-28 17:15:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Representation of one USB endpoint */
|
|
|
|
|
|
|
|
|
|
struct usbdev_ep_s
|
|
|
|
|
{
|
2019-11-02 18:12:59 -06:00
|
|
|
FAR const struct usbdev_epops_s *ops; /* Endpoint operations */
|
|
|
|
|
uint8_t eplog; /* Logical endpoint address */
|
|
|
|
|
uint16_t maxpacket; /* Maximum packet size for this endpoint */
|
|
|
|
|
FAR void *priv; /* For use by class driver */
|
2023-07-19 10:09:41 +08:00
|
|
|
FAR void *fs; /* USB fs device this ep belongs */
|
2008-09-28 17:15:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* struct usbdev_s represents a usb device */
|
|
|
|
|
|
|
|
|
|
struct usbdev_s;
|
|
|
|
|
struct usbdev_ops_s
|
|
|
|
|
{
|
|
|
|
|
/* Allocate and free endpoints */
|
|
|
|
|
|
2019-11-02 18:12:59 -06:00
|
|
|
CODE FAR struct usbdev_ep_s *(*allocep)(FAR struct usbdev_s *dev,
|
|
|
|
|
uint8_t epphy, bool in, uint8_t eptype);
|
|
|
|
|
CODE void (*freeep)(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep);
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Get the frame number from the last SOF */
|
|
|
|
|
|
2019-11-02 18:12:59 -06:00
|
|
|
CODE int (*getframe)(FAR struct usbdev_s *dev);
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Hardware specific features */
|
|
|
|
|
|
2019-11-02 18:12:59 -06:00
|
|
|
CODE int (*wakeup)(FAR struct usbdev_s *dev);
|
|
|
|
|
CODE int (*selfpowered)(FAR struct usbdev_s *dev, bool selfpowered);
|
|
|
|
|
CODE int (*pullup)(FAR struct usbdev_s *dev, bool enable);
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
/* Device-specific I/O command support */
|
|
|
|
|
|
Sources and Docs: Fix typos and nxstyle issues
Documentation/contributing/coding_style.rst:
* Fix repeated words: ("this this").
* Remove trailing spaces.
boards/z80/z80/z80sim/README.txt:
* Fix repeated words: ("this this") and rewrap lines.
graphics/Kconfig,
libs/libc/math/Kconfig:
* Fix repeated words: ("this this").
arch/arm/src/armv7-a/arm_assert.c,
arch/arm/src/armv7-r/arm_assert.c,
arch/arm/src/imxrt/imxrt_enet.c,
arch/arm/src/kinetis/kinetis_enet.c,
arch/arm/src/kinetis/kinetis_flexcan.c,
arch/arm/src/s32k1xx/s32k1xx_enet.c,
arch/arm/src/s32k1xx/s32k1xx_flexcan.c,
arch/arm/src/stm32/stm32_pwm.c,
arch/arm/src/stm32h7/stm32_pwm.c,
arch/arm/src/stm32l4/stm32l4_pwm.c,
arch/renesas/src/rx65n/rx65n_usbdev.c,
binfmt/libnxflat/libnxflat_bind.c,
drivers/pipes/pipe_common.c,
net/igmp/igmp_input.c,
net/tcp/tcp_conn.c,
sched/sched/sched_roundrobin.c:
* Fix typo in comment ("this this").
arch/arm/src/cxd56xx/cxd56_usbdev.c,
arch/arm/src/lc823450/lc823450_usbdev.c:
* Fix typo in comment and rewrap lines.
arch/arm/src/imxrt/imxrt_usbdev.c,
arch/arm/src/stm32/stm32_dac.c,
arch/arm/src/stm32f0l0g0/stm32_pwm.c,
arch/arm/src/stm32f7/stm32_pwm.c,
arch/arm/src/tiva/lm/lm4f_gpio.h,
fs/nxffs/nxffs_write.c,
include/nuttx/analog/pga11x.h,
include/nuttx/usb/usbdev.h,
net/mld/mld_join.c:
* Fix typo in comment ("this this").
* Fix nxstyle issues.
2020-10-01 19:29:35 -04:00
|
|
|
CODE int (*ioctl)(FAR struct usbdev_s *dev, unsigned code,
|
|
|
|
|
unsigned long param);
|
2008-09-28 17:15:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct usbdev_s
|
|
|
|
|
{
|
2019-11-02 18:12:59 -06:00
|
|
|
FAR const struct usbdev_ops_s *ops; /* Access to hardware specific features */
|
|
|
|
|
FAR struct usbdev_ep_s *ep0; /* Endpoint zero */
|
|
|
|
|
uint8_t speed; /* Current speed of the host connection */
|
|
|
|
|
uint8_t dualspeed:1; /* 1:supports high and full speed operation */
|
2008-09-28 17:15:17 +00:00
|
|
|
};
|
|
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/* USB Device Class Implementations *****************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
struct usbdevclass_driverops_s
|
|
|
|
|
{
|
2019-11-02 18:12:59 -06:00
|
|
|
CODE int (*bind)(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
|
FAR struct usbdev_s *dev);
|
|
|
|
|
CODE void (*unbind)(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
|
FAR struct usbdev_s *dev);
|
|
|
|
|
CODE int (*setup)(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
|
FAR struct usbdev_s *dev, FAR const struct usb_ctrlreq_s *ctrl,
|
|
|
|
|
FAR uint8_t *dataout, size_t outlen);
|
|
|
|
|
CODE void (*disconnect)(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
|
FAR struct usbdev_s *dev);
|
|
|
|
|
CODE void (*suspend)(FAR struct usbdevclass_driver_s *driver,
|
|
|
|
|
FAR struct usbdev_s *dev);
|
|
|
|
|
CODE void (*resume)(FAR struct usbdevclass_driver_s *driver,
|
2012-01-26 17:42:44 +00:00
|
|
|
FAR struct usbdev_s *dev);
|
2008-09-28 17:15:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct usbdevclass_driver_s
|
|
|
|
|
{
|
2019-11-02 18:12:59 -06:00
|
|
|
FAR const struct usbdevclass_driverops_s *ops;
|
2009-12-14 23:32:23 +00:00
|
|
|
uint8_t speed; /* Highest speed that the driver handles */
|
2008-09-28 17:15:17 +00:00
|
|
|
};
|
|
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/****************************************************************************
|
2008-09-28 17:15:17 +00:00
|
|
|
* Public Data
|
2021-01-28 19:21:44 +01:00
|
|
|
****************************************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
|
# define EXTERN extern "C"
|
|
|
|
|
extern "C"
|
|
|
|
|
{
|
|
|
|
|
#else
|
|
|
|
|
# define EXTERN extern
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/****************************************************************************
|
Sources and Docs: Fix typos and nxstyle issues
Documentation/contributing/coding_style.rst:
* Fix repeated words: ("this this").
* Remove trailing spaces.
boards/z80/z80/z80sim/README.txt:
* Fix repeated words: ("this this") and rewrap lines.
graphics/Kconfig,
libs/libc/math/Kconfig:
* Fix repeated words: ("this this").
arch/arm/src/armv7-a/arm_assert.c,
arch/arm/src/armv7-r/arm_assert.c,
arch/arm/src/imxrt/imxrt_enet.c,
arch/arm/src/kinetis/kinetis_enet.c,
arch/arm/src/kinetis/kinetis_flexcan.c,
arch/arm/src/s32k1xx/s32k1xx_enet.c,
arch/arm/src/s32k1xx/s32k1xx_flexcan.c,
arch/arm/src/stm32/stm32_pwm.c,
arch/arm/src/stm32h7/stm32_pwm.c,
arch/arm/src/stm32l4/stm32l4_pwm.c,
arch/renesas/src/rx65n/rx65n_usbdev.c,
binfmt/libnxflat/libnxflat_bind.c,
drivers/pipes/pipe_common.c,
net/igmp/igmp_input.c,
net/tcp/tcp_conn.c,
sched/sched/sched_roundrobin.c:
* Fix typo in comment ("this this").
arch/arm/src/cxd56xx/cxd56_usbdev.c,
arch/arm/src/lc823450/lc823450_usbdev.c:
* Fix typo in comment and rewrap lines.
arch/arm/src/imxrt/imxrt_usbdev.c,
arch/arm/src/stm32/stm32_dac.c,
arch/arm/src/stm32f0l0g0/stm32_pwm.c,
arch/arm/src/stm32f7/stm32_pwm.c,
arch/arm/src/tiva/lm/lm4f_gpio.h,
fs/nxffs/nxffs_write.c,
include/nuttx/analog/pga11x.h,
include/nuttx/usb/usbdev.h,
net/mld/mld_join.c:
* Fix typo in comment ("this this").
* Fix nxstyle issues.
2020-10-01 19:29:35 -04:00
|
|
|
* Public Function Prototypes
|
2021-01-28 19:21:44 +01:00
|
|
|
****************************************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2023-07-06 13:57:42 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: usbdev_allocreq
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Allocate a request instance along with its buffer
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
FAR struct usbdev_req_s *usbdev_allocreq(FAR struct usbdev_ep_s *ep,
|
|
|
|
|
uint16_t len);
|
|
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: usbdev_freereq
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Free a request instance along with its buffer
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void usbdev_freereq(FAR struct usbdev_ep_s *ep,
|
|
|
|
|
FAR struct usbdev_req_s *req);
|
|
|
|
|
|
2023-07-19 10:09:41 +08:00
|
|
|
/****************************************************************************
|
|
|
|
|
* Name: usbdev_copy_epdesc
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* Copies the requested Endpoint Description into the buffer given.
|
|
|
|
|
* Returns the number of Bytes filled in ( sizeof(struct usb_epdesc_s) ).
|
|
|
|
|
* This function is provided by various classes.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
void usbdev_copy_epdesc(FAR struct usb_epdesc_s *epdesc,
|
|
|
|
|
uint8_t epno, bool hispeed,
|
|
|
|
|
FAR const struct usbdev_epinfo_s *epinfo);
|
|
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/****************************************************************************
|
2008-09-28 17:15:17 +00:00
|
|
|
* Name: usbdevclass_register
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
2021-01-28 19:21:44 +01:00
|
|
|
* Register a USB device class driver. The class driver's bind() method
|
|
|
|
|
* will be called to bind it to a USB device driver.
|
2008-09-28 17:15:17 +00:00
|
|
|
*
|
2021-01-28 19:21:44 +01:00
|
|
|
****************************************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2013-07-12 07:09:24 -06:00
|
|
|
int usbdev_register(FAR struct usbdevclass_driver_s *driver);
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/****************************************************************************
|
2008-09-28 17:15:17 +00:00
|
|
|
* Name: usbdev_unregister
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
2021-01-28 19:21:44 +01:00
|
|
|
* 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.
|
2008-09-28 17:15:17 +00:00
|
|
|
*
|
2021-01-28 19:21:44 +01:00
|
|
|
****************************************************************************/
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2013-07-12 07:09:24 -06:00
|
|
|
int usbdev_unregister(FAR struct usbdevclass_driver_s *driver);
|
2008-09-28 17:15:17 +00:00
|
|
|
|
2021-01-28 19:21:44 +01:00
|
|
|
/****************************************************************************
|
2012-09-13 14:14:18 +00:00
|
|
|
* Name: usbdev_dma_alloc and usbdev_dma_free
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
|
|
|
|
* The USB class driver allocates packet I/O buffers for data transfer by
|
|
|
|
|
* calling the driver allocbuffer() and freebuffer() methods. Those
|
|
|
|
|
* methods are only available if CONFIG_USBDEV_DMA is defined in the
|
|
|
|
|
* system configuration.
|
|
|
|
|
*
|
|
|
|
|
* If CONFIG_USBDEV_DMAMEMORY is also defined in the NuttX configuration,
|
|
|
|
|
* then the driver implementations of the allocbuffer() and freebuffer()
|
|
|
|
|
* methods may use board-specific usbdev_dma_alloc() and usbdev_dma_free().
|
|
|
|
|
* If CONFIG_USBDEV_DMA and CONFIG_USBDEV_DMAMEMORY are both defined,
|
|
|
|
|
* then the board-specific logic must provide the functions
|
|
|
|
|
* usbdev_dma_alloc() and usbdev_dma_free() as prototyped below:
|
|
|
|
|
* usbdev_dma_alloc() will allocate DMA-capable memory of the specified
|
|
|
|
|
* size; usbdev_dma_free() is the corresponding function that will be
|
|
|
|
|
* called to free the DMA-capable memory.
|
|
|
|
|
*
|
|
|
|
|
* This functions may be simple wrappers around gran_alloc() and
|
2014-09-24 06:55:26 -06:00
|
|
|
* gran_free() (See nuttx/mm/gran.h). Note that the gran_free() function
|
2012-09-13 14:14:18 +00:00
|
|
|
* does require the size of the allocation to be freed; that would need
|
|
|
|
|
* to be managed in the board-specific logic.
|
|
|
|
|
*
|
2021-01-28 19:21:44 +01:00
|
|
|
****************************************************************************/
|
2012-09-13 14:14:18 +00:00
|
|
|
|
|
|
|
|
#if defined(CONFIG_USBDEV_DMA) && defined(CONFIG_USBDEV_DMAMEMORY)
|
2013-07-12 07:09:24 -06:00
|
|
|
FAR void *usbdev_dma_alloc(size_t size);
|
|
|
|
|
void usbdev_dma_free(FAR void *memory);
|
2012-09-13 14:14:18 +00:00
|
|
|
#endif
|
|
|
|
|
|
2008-09-28 17:15:17 +00:00
|
|
|
#undef EXTERN
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-08-06 19:21:42 -06:00
|
|
|
#endif /* __INCLUDE_NUTTX_USB_USBDEV_H */
|