forked from len0rd/rockbox
Usb Stack: only setup packet handling, and not enabled by default as there is a lot to do.
* settings code is not fully ready -> changing device driver has no effect * clean ups * check copyriths * find a way to detect IN transfers * support for full and highspeed * ... git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14470 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
9305c86f5b
commit
8181a0c905
29 changed files with 4585 additions and 72 deletions
80
firmware/usbstack/core/config.c
Normal file
80
firmware/usbstack/core/config.c
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id: $
|
||||
*
|
||||
* Copyright (C) 2007 by Christian Gmeiner
|
||||
*
|
||||
* Based on linux/drivers/usb/gadget/config.c
|
||||
* Copyright (C) 2003 David Brownell
|
||||
*
|
||||
* All files in this archive are subject to the GNU General Public License.
|
||||
* See the file COPYING in the source tree root for full license agreement.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "usbstack/core.h"
|
||||
|
||||
static int usb_descriptor_fillbuf(void* buf, unsigned buflen, struct usb_descriptor_header** src) {
|
||||
|
||||
uint8_t* dest = buf;
|
||||
|
||||
if (!src) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* fill buffer from src[] until null descriptor ptr */
|
||||
for (; 0 != *src; src++) {
|
||||
unsigned len = (*src)->bLength;
|
||||
|
||||
logf("len: %d", len);
|
||||
|
||||
if (len > buflen)
|
||||
return -EINVAL;
|
||||
memcpy(dest, *src, len);
|
||||
buflen -= len;
|
||||
dest += len;
|
||||
}
|
||||
return dest - (uint8_t *)buf;
|
||||
}
|
||||
|
||||
int usb_stack_configdesc(const struct usb_config_descriptor* config, void* buf, unsigned length, struct usb_descriptor_header** desc) {
|
||||
|
||||
struct usb_config_descriptor* cp = buf;
|
||||
int len;
|
||||
|
||||
if (length < USB_DT_CONFIG_SIZE || !desc) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* config descriptor first */
|
||||
*cp = *config;
|
||||
|
||||
/* then interface/endpoint/class/vendor/... */
|
||||
len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (uint8_t*)buf, length - USB_DT_CONFIG_SIZE, desc);
|
||||
|
||||
if (len < 0) {
|
||||
return len;
|
||||
}
|
||||
|
||||
len += USB_DT_CONFIG_SIZE;
|
||||
if (len > 0xffff) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* patch up the config descriptor */
|
||||
cp->bLength = USB_DT_CONFIG_SIZE;
|
||||
cp->bDescriptorType = USB_DT_CONFIG;
|
||||
cp->wTotalLength = len;
|
||||
cp->bmAttributes |= USB_CONFIG_ATT_ONE;
|
||||
|
||||
return len;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue