usbdev: add usbdev fs device for usb char device
Add usb_fs driver so that userspace can directly transfer USB packets through the EP node. ADB, Fastboot, MTP will use usb_fs, these class driver only need to provide the descriptors and register the usb_fs device. Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com> Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
This commit is contained in:
parent
3f8f3340d1
commit
1f6d9bbd17
@ -59,7 +59,12 @@ if(CONFIG_USBDEV)
|
||||
list(APPEND SRCS cdcecm.c)
|
||||
endif()
|
||||
|
||||
list(APPEND SRCS composite.c usbdev_req.c usbdev_trace.c usbdev_trprintf.c)
|
||||
if(CONFIG_USBDEV_FS)
|
||||
list(APPEND SRCS usbdev_fs.c)
|
||||
endif()
|
||||
|
||||
list(APPEND SRCS composite.c usbdev_desc.c usbdev_req.c)
|
||||
list(APPEND SRCS usbdev_trace.c usbdev_trprintf.c)
|
||||
|
||||
target_sources(drivers PRIVATE ${SRCS})
|
||||
endif()
|
||||
|
@ -1210,4 +1210,26 @@ config CDCECM_PRODUCTSTR
|
||||
endif # !CDCECM_COMPOSITE
|
||||
endif # CDCECM
|
||||
|
||||
config USBDEV_FS
|
||||
bool
|
||||
default n
|
||||
---help---
|
||||
Enables USBDEV FS support, userspace can use fs to control USB device.
|
||||
|
||||
if USBDEV_FS
|
||||
|
||||
config USBDEV_FS_EPNUM
|
||||
int "Number of EP for USBDEV FS"
|
||||
default 4
|
||||
---help---
|
||||
Maximum number of eps for USBDEV FS.
|
||||
|
||||
config USBDEV_FS_NPOLLWAITERS
|
||||
int "Number of poll waiters for USBDEV FS"
|
||||
default 2
|
||||
---help---
|
||||
Maximum number of threads that can be waiting on poll().
|
||||
|
||||
endif #USBDEV_FS
|
||||
|
||||
endif # USBDEV
|
||||
|
@ -58,7 +58,11 @@ ifeq ($(CONFIG_NET_CDCECM),y)
|
||||
CSRCS += cdcecm.c
|
||||
endif
|
||||
|
||||
CSRCS += composite.c usbdev_req.c
|
||||
ifeq ($(CONFIG_USBDEV_FS),y)
|
||||
CSRCS += usbdev_fs.c
|
||||
endif
|
||||
|
||||
CSRCS += composite.c usbdev_desc.c usbdev_req.c
|
||||
CSRCS += usbdev_trace.c usbdev_trprintf.c
|
||||
|
||||
# Include USB device build support
|
||||
|
72
drivers/usbdev/usbdev_desc.c
Normal file
72
drivers/usbdev/usbdev_desc.c
Normal file
@ -0,0 +1,72 @@
|
||||
/****************************************************************************
|
||||
* drivers/usbdev/usbdev_desc.c
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <nuttx/usb/usbdev.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* 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)
|
||||
{
|
||||
#ifndef CONFIG_USBDEV_DUALSPEED
|
||||
UNUSED(hispeed);
|
||||
#endif
|
||||
|
||||
memcpy(epdesc, &epinfo->desc, sizeof(struct usb_epdesc_s));
|
||||
epdesc->addr |= epno;
|
||||
|
||||
#ifdef CONFIG_USBDEV_DUALSPEED
|
||||
if (hispeed)
|
||||
{
|
||||
/* Maximum packet size (high speed) */
|
||||
|
||||
epdesc->mxpacketsize[0] = LSBYTE(epinfo->hssize);
|
||||
epdesc->mxpacketsize[1] = MSBYTE(epinfo->hssize);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* Maximum packet size (full speed) */
|
||||
|
||||
epdesc->mxpacketsize[0] = LSBYTE(epinfo->fssize);
|
||||
epdesc->mxpacketsize[1] = MSBYTE(epinfo->fssize);
|
||||
}
|
||||
}
|
1382
drivers/usbdev/usbdev_fs.c
Normal file
1382
drivers/usbdev/usbdev_fs.c
Normal file
File diff suppressed because it is too large
Load Diff
88
drivers/usbdev/usbdev_fs.h
Normal file
88
drivers/usbdev/usbdev_fs.h
Normal file
@ -0,0 +1,88 @@
|
||||
/****************************************************************************
|
||||
* drivers/usbdev/usbdev_fs.h
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __DRIVERS_USBDEV_FS_H
|
||||
#define __DRIVERS_USBDEV_FS_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/usb/usbdev.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbdev_fs_initialize
|
||||
*
|
||||
* Description:
|
||||
* USBDEV fs initialize
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 on success, negative error code on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *usbdev_fs_initialize(FAR const struct usbdev_devdescs_s *devdescs,
|
||||
FAR struct composite_devdesc_s *pdevice);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbdev_fs_uninitialize
|
||||
*
|
||||
* Description:
|
||||
* USBDEV fs uninitialize
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 on success, negative error code on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void usbdev_fs_uninitialize(FAR void *handle);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbclass_classobject
|
||||
*
|
||||
* Description:
|
||||
* Register USB driver and return the class object.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 on success, negative error code on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int usbdev_fs_classobject(int minor,
|
||||
FAR struct usbdev_devinfo_s *devinfo,
|
||||
FAR struct usbdevclass_driver_s **classdev);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbdev_fs_classuninitialize
|
||||
*
|
||||
* Description:
|
||||
* Free allocated class memory
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void usbdev_fs_classuninitialize(FAR struct usbdevclass_driver_s *classdev);
|
||||
|
||||
#endif /* __DRIVERS_USBDEV_FS_H */
|
@ -190,10 +190,21 @@ struct usbdev_devdescs_s
|
||||
#endif
|
||||
};
|
||||
|
||||
struct usbdev_epinfo_s
|
||||
{
|
||||
struct usb_epdesc_s desc;
|
||||
uint16_t fssize;
|
||||
#ifdef CONFIG_USBDEV_DUALSPEED
|
||||
uint16_t hssize;
|
||||
#endif
|
||||
uint16_t reqnum;
|
||||
};
|
||||
|
||||
/* usbdev_devinfo_s - describes the low level bindings of an usb device */
|
||||
|
||||
struct usbdev_devinfo_s
|
||||
{
|
||||
FAR const char *name;
|
||||
int ninterfaces; /* Number of interfaces in the configuration */
|
||||
int ifnobase; /* Offset to Interface-IDs */
|
||||
|
||||
@ -202,6 +213,7 @@ struct usbdev_devinfo_s
|
||||
|
||||
int nendpoints; /* Number of Endpoints referenced in the following allay */
|
||||
int epno[5]; /* Array holding the endpoint configuration for this device */
|
||||
FAR const struct usbdev_epinfo_s **epinfos;
|
||||
};
|
||||
|
||||
struct usbdevclass_driver_s;
|
||||
@ -297,6 +309,7 @@ struct usbdev_ep_s
|
||||
uint8_t eplog; /* Logical endpoint address */
|
||||
uint16_t maxpacket; /* Maximum packet size for this endpoint */
|
||||
FAR void *priv; /* For use by class driver */
|
||||
FAR void *fs; /* USB fs device this ep belongs */
|
||||
};
|
||||
|
||||
/* struct usbdev_s represents a usb device */
|
||||
@ -398,6 +411,20 @@ FAR struct usbdev_req_s *usbdev_allocreq(FAR struct usbdev_ep_s *ep,
|
||||
void usbdev_freereq(FAR struct usbdev_ep_s *ep,
|
||||
FAR struct usbdev_req_s *req);
|
||||
|
||||
/****************************************************************************
|
||||
* 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);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: usbdevclass_register
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user