1
0
Fork 0
forked from len0rd/rockbox

code police, no functional changes

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14737 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Peter D'Hoye 2007-09-17 20:49:02 +00:00
parent 5011d43d13
commit b0c996ba92
5 changed files with 60 additions and 34 deletions

View file

@ -23,7 +23,8 @@
#include <string.h> #include <string.h>
#include "usbstack/core.h" #include "usbstack/core.h"
static int usb_descriptor_fillbuf(void* buf, unsigned buflen, struct usb_descriptor_header** src) static int usb_descriptor_fillbuf(void* buf, unsigned buflen,
struct usb_descriptor_header** src)
{ {
uint8_t* dest = buf; uint8_t* dest = buf;
@ -45,7 +46,8 @@ static int usb_descriptor_fillbuf(void* buf, unsigned buflen, struct usb_descrip
return dest - (uint8_t *)buf; return dest - (uint8_t *)buf;
} }
int usb_stack_configdesc(const struct usb_config_descriptor* config, void* buf, unsigned length, struct usb_descriptor_header** desc) 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; struct usb_config_descriptor* cp = buf;
int len; int len;
@ -58,7 +60,8 @@ int usb_stack_configdesc(const struct usb_config_descriptor* config, void* buf,
*cp = *config; *cp = *config;
/* then interface/endpoint/class/vendor/... */ /* then interface/endpoint/class/vendor/... */
len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (uint8_t*)buf, length - USB_DT_CONFIG_SIZE, desc); len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (uint8_t*)buf,
length - USB_DT_CONFIG_SIZE, desc);
if (len < 0) { if (len < 0) {
return len; return len;

View file

@ -99,7 +99,8 @@ void usb_stack_start(void)
* and if it has a device driver bind to it */ * and if it has a device driver bind to it */
logf("check for auto bind"); logf("check for auto bind");
if (usbcore.active_controller->type == DEVICE) { if (usbcore.active_controller->type == DEVICE) {
if (usbcore.active_controller->device_driver == NULL && usbcore.device_driver != NULL) { if (usbcore.active_controller->device_driver == NULL &&
usbcore.device_driver != NULL) {
/* bind driver */ /* bind driver */
logf("binding..."); logf("binding...");
bind_device_driver(usbcore.device_driver); bind_device_driver(usbcore.device_driver);
@ -130,7 +131,8 @@ void usb_stack_stop(void)
void usb_stack_irq(void) void usb_stack_irq(void)
{ {
/* simply notify usb controller */ /* simply notify usb controller */
if (usbcore.active_controller != NULL && usbcore.active_controller->irq != NULL) { if (usbcore.active_controller != NULL &&
usbcore.active_controller->irq != NULL) {
usbcore.active_controller->irq(); usbcore.active_controller->irq();
} }
} }
@ -190,7 +192,8 @@ int usb_controller_register(struct usb_controller* ctrl)
* @param ctrl pointer to controller to unregister. * @param ctrl pointer to controller to unregister.
* @return 0 on success else a defined error code. * @return 0 on success else a defined error code.
*/ */
int usb_controller_unregister(struct usb_controller* ctrl) { int usb_controller_unregister(struct usb_controller* ctrl)
{
if (ctrl == NULL) { if (ctrl == NULL) {
return EINVAL; return EINVAL;
@ -226,7 +229,8 @@ void usb_controller_select(int type)
struct usb_controller* new = NULL; struct usb_controller* new = NULL;
/* check if a controller of the wanted type is already loaded */ /* check if a controller of the wanted type is already loaded */
if (usbcore.active_controller != NULL && (int)usbcore.active_controller->type == type) { if (usbcore.active_controller != NULL &&
(int)usbcore.active_controller->type == type) {
logf("controller already set"); logf("controller already set");
return; return;
} }
@ -263,7 +267,8 @@ void usb_controller_select(int type)
usbcore.active_controller->init(); usbcore.active_controller->init();
} }
int usb_stack_get_mode(void) { int usb_stack_get_mode(void)
{
return usbcore.mode; return usbcore.mode;
} }
@ -296,8 +301,8 @@ int usb_device_driver_register(struct usb_device_driver* driver)
return 0; return 0;
} }
int usb_device_driver_bind(const char* name) { int usb_device_driver_bind(const char* name)
{
int i; int i;
struct usb_device_driver *tmp = NULL; struct usb_device_driver *tmp = NULL;
struct usb_device_driver *driver = NULL; struct usb_device_driver *driver = NULL;
@ -340,8 +345,8 @@ int usb_device_driver_bind(const char* name) {
return 0; return 0;
} }
void usb_device_driver_unbind(void) { void usb_device_driver_unbind(void)
{
logf("usb_device_driver_unbind"); logf("usb_device_driver_unbind");
if (usbcore.active_controller->device_driver != NULL) { if (usbcore.active_controller->device_driver != NULL) {
usbcore.active_controller->device_driver->unbind(); usbcore.active_controller->device_driver->unbind();
@ -351,8 +356,8 @@ void usb_device_driver_unbind(void) {
usbcore.device_driver = NULL; usbcore.device_driver = NULL;
} }
static void update_driver_names(unsigned char* result) { static void update_driver_names(unsigned char* result)
{
int i; int i;
int pos = 0; int pos = 0;
unsigned char terminator = ','; unsigned char terminator = ',';
@ -376,8 +381,8 @@ static void update_driver_names(unsigned char* result) {
} }
} }
static void bind_device_driver(struct usb_device_driver* driver) { static void bind_device_driver(struct usb_device_driver* driver)
{
int ret = 0; int ret = 0;
/* look if there is an old driver */ /* look if there is an old driver */

View file

@ -151,13 +151,15 @@ static int ep_matches(struct usb_ep* ep, struct usb_endpoint_descriptor* desc)
switch (type) { switch (type) {
case USB_ENDPOINT_XFER_INT: case USB_ENDPOINT_XFER_INT:
/* INT: limit 64 bytes full speed, 1024 high speed */ /* INT: limit 64 bytes full speed, 1024 high speed */
if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 64)) { if ((usbcore.active_controller->speed != USB_SPEED_HIGH) &&
(max > 64)) {
return 0; return 0;
} }
/* FALLTHROUGH */ /* FALLTHROUGH */
case USB_ENDPOINT_XFER_ISOC: case USB_ENDPOINT_XFER_ISOC:
if ((usbcore.active_controller->speed != USB_SPEED_HIGH) && (max > 1023)) { if ((usbcore.active_controller->speed != USB_SPEED_HIGH) &&
(max > 1023)) {
return 0; return 0;
} }
break; break;

View file

@ -209,7 +209,8 @@ int usb_serial_driver_bind(void* controler_ops)
serial_debug_desc.bDebugInEndpoint = dev.in->ep_num; serial_debug_desc.bDebugInEndpoint = dev.in->ep_num;
serial_debug_desc.bDebugOutEndpoint = dev.out->ep_num; serial_debug_desc.bDebugOutEndpoint = dev.out->ep_num;
/* update hs descriptors as we asume that endpoints are the same for fs and hs */ /* update hs descriptors as we asume that endpoints
are the same for fs and hs */
serial_hs_in_desc.bEndpointAddress = serial_fs_in_desc.bEndpointAddress; serial_hs_in_desc.bEndpointAddress = serial_fs_in_desc.bEndpointAddress;
serial_hs_out_desc.bEndpointAddress = serial_fs_out_desc.bEndpointAddress; serial_hs_out_desc.bEndpointAddress = serial_fs_out_desc.bEndpointAddress;
@ -242,13 +243,15 @@ int usb_serial_driver_request(struct usb_ctrlrequest* request)
switch (request->wValue >> 8) { switch (request->wValue >> 8) {
case USB_DT_DEVICE: case USB_DT_DEVICE:
logf("usb serial: sending device desc"); logf("usb serial: sending device desc");
ret = MIN(sizeof(struct usb_device_descriptor), request->wLength); ret = MIN(sizeof(struct usb_device_descriptor),
request->wLength);
res.buf = &serial_device_desc; res.buf = &serial_device_desc;
break; break;
case USB_DT_DEVICE_QUALIFIER: case USB_DT_DEVICE_QUALIFIER:
logf("usb serial: sending qualifier dec"); logf("usb serial: sending qualifier dec");
ret = MIN(sizeof(struct usb_qualifier_descriptor), request->wLength); ret = MIN(sizeof(struct usb_qualifier_descriptor),
request->wLength);
res.buf = &serial_qualifier_desc; res.buf = &serial_qualifier_desc;
break; break;
@ -256,7 +259,8 @@ int usb_serial_driver_request(struct usb_ctrlrequest* request)
case USB_DT_CONFIG: case USB_DT_CONFIG:
logf("usb serial: sending config desc"); logf("usb serial: sending config desc");
ret = config_buf(buf, request->wValue >> 8, request->wValue & 0xff); ret = config_buf(buf, request->wValue >> 8,
request->wValue & 0xff);
if (ret >= 0) { if (ret >= 0) {
logf("%d, vs %d", request->wLength, ret); logf("%d, vs %d", request->wLength, ret);
ret = MIN(request->wLength, (uint16_t)ret); ret = MIN(request->wLength, (uint16_t)ret);
@ -266,13 +270,15 @@ int usb_serial_driver_request(struct usb_ctrlrequest* request)
case USB_DT_DEBUG: case USB_DT_DEBUG:
logf("usb serial: sending debug desc"); logf("usb serial: sending debug desc");
ret = MIN(sizeof(struct usb_debug_descriptor), request->wLength); ret = MIN(sizeof(struct usb_debug_descriptor),
request->wLength);
res.buf = &serial_debug_desc; res.buf = &serial_debug_desc;
break; break;
case USB_DT_STRING: case USB_DT_STRING:
logf("usb serial: sending string desc"); logf("usb serial: sending string desc");
ret = usb_stack_get_string(strings, request->wValue & 0xff, buf); ret = usb_stack_get_string(strings, request->wValue & 0xff,
buf);
ret = MIN(ret, request->wLength); ret = MIN(ret, request->wLength);
res.buf = buf; res.buf = buf;
break; break;
@ -324,7 +330,8 @@ static int config_buf(uint8_t *buf, uint8_t type, unsigned index)
/* TODO check index*/ /* TODO check index*/
(void)index; (void)index;
len = usb_stack_configdesc(&serial_bulk_config_desc, buf, BUFFER_SIZE, dev.descriptors); len = usb_stack_configdesc(&serial_bulk_config_desc, buf, BUFFER_SIZE,
dev.descriptors);
if (len < 0) { if (len < 0) {
return len; return len;
} }

View file

@ -207,9 +207,12 @@ int usb_storage_driver_bind(void* controler_ops)
/* update device decsriptor */ /* update device decsriptor */
storage_device_desc.bMaxPacketSize0 = ops->ep0->maxpacket; storage_device_desc.bMaxPacketSize0 = ops->ep0->maxpacket;
/* update hs descriptors as we asume that endpoints are the same for fs and hs */ /* update hs descriptors as we asume that endpoints
storage_hs_bulk_in_desc.bEndpointAddress = storage_fs_bulk_in_desc.bEndpointAddress; are the same for fs and hs */
storage_hs_bulk_out_desc.bEndpointAddress = storage_fs_bulk_out_desc.bEndpointAddress; storage_hs_bulk_in_desc.bEndpointAddress =
storage_fs_bulk_in_desc.bEndpointAddress;
storage_hs_bulk_out_desc.bEndpointAddress =
storage_fs_bulk_out_desc.bEndpointAddress;
return 0; return 0;
@ -218,7 +221,8 @@ autoconf_fail:
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
void usb_storage_driver_unbind(void) { void usb_storage_driver_unbind(void)
{
/* disable endpoints... */ /* disable endpoints... */
} }
@ -240,13 +244,15 @@ int usb_storage_driver_request(struct usb_ctrlrequest* request)
switch (request->wValue >> 8) { switch (request->wValue >> 8) {
case USB_DT_DEVICE: case USB_DT_DEVICE:
logf("usb storage: sending device desc"); logf("usb storage: sending device desc");
ret = MIN(sizeof(struct usb_device_descriptor), request->wLength); ret = MIN(sizeof(struct usb_device_descriptor),
request->wLength);
res.buf = &storage_device_desc; res.buf = &storage_device_desc;
break; break;
case USB_DT_DEVICE_QUALIFIER: case USB_DT_DEVICE_QUALIFIER:
logf("usb storage: sending qualifier dec"); logf("usb storage: sending qualifier dec");
ret = MIN(sizeof(struct usb_qualifier_descriptor), request->wLength); ret = MIN(sizeof(struct usb_qualifier_descriptor),
request->wLength);
res.buf = &storage_qualifier_desc; res.buf = &storage_qualifier_desc;
break; break;
@ -254,7 +260,8 @@ int usb_storage_driver_request(struct usb_ctrlrequest* request)
case USB_DT_CONFIG: case USB_DT_CONFIG:
logf("usb storage: sending config desc"); logf("usb storage: sending config desc");
ret = config_buf(buf, request->wValue >> 8, request->wValue & 0xff); ret = config_buf(buf, request->wValue >> 8,
request->wValue & 0xff);
if (ret >= 0) { if (ret >= 0) {
logf("%d, vs %d", request->wLength, ret); logf("%d, vs %d", request->wLength, ret);
ret = MIN(request->wLength, (uint16_t)ret); ret = MIN(request->wLength, (uint16_t)ret);
@ -264,7 +271,8 @@ int usb_storage_driver_request(struct usb_ctrlrequest* request)
case USB_DT_STRING: case USB_DT_STRING:
logf("usb storage: sending string desc"); logf("usb storage: sending string desc");
ret = usb_stack_get_string(strings, request->wValue & 0xff, buf); ret = usb_stack_get_string(strings, request->wValue & 0xff,
buf);
ret = MIN(ret, request->wLength); ret = MIN(ret, request->wLength);
res.buf = buf; res.buf = buf;
break; break;
@ -336,7 +344,8 @@ static int config_buf(uint8_t *buf, uint8_t type, unsigned index)
(void)index; (void)index;
len = usb_stack_configdesc(&storage_config_desc, buf, BUFFER_SIZE, dev.descriptors); len = usb_stack_configdesc(&storage_config_desc, buf, BUFFER_SIZE,
dev.descriptors);
logf("result %d", len); logf("result %d", len);
if (len < 0) { if (len < 0) {
return len; return len;