Attempt to have a consistent coding convention in usb_core.c

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25617 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Amaury Pouly 2010-04-13 08:40:21 +00:00
parent 99a2299654
commit d372e3c8e6

View file

@ -98,7 +98,7 @@ static struct usb_config_descriptor __attribute__((aligned(2)))
.bConfigurationValue = 1, .bConfigurationValue = 1,
.iConfiguration = 0, .iConfiguration = 0,
.bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER, .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
.bMaxPower = (USB_MAX_CURRENT+1) / 2, /* In 2mA units */ .bMaxPower = (USB_MAX_CURRENT + 1) / 2, /* In 2mA units */
}; };
static const struct usb_qualifier_descriptor __attribute__((aligned(2))) static const struct usb_qualifier_descriptor __attribute__((aligned(2)))
@ -119,7 +119,7 @@ static const struct usb_string_descriptor __attribute__((aligned(2)))
{ {
24, 24,
USB_DT_STRING, USB_DT_STRING,
{'R','o','c','k','b','o','x','.','o','r','g'} {'R', 'o', 'c', 'k', 'b', 'o', 'x', '.', 'o', 'r', 'g'}
}; };
static const struct usb_string_descriptor __attribute__((aligned(2))) static const struct usb_string_descriptor __attribute__((aligned(2)))
@ -127,9 +127,9 @@ static const struct usb_string_descriptor __attribute__((aligned(2)))
{ {
42, 42,
USB_DT_STRING, USB_DT_STRING,
{'R','o','c','k','b','o','x',' ', {'R', 'o', 'c', 'k', 'b', 'o', 'x', ' ',
'm','e','d','i','a',' ', 'm', 'e', 'd', 'i', 'a', ' ',
'p','l','a','y','e','r'} 'p', 'l', 'a', 'y', 'e', 'r'}
}; };
static struct usb_string_descriptor __attribute__((aligned(2))) static struct usb_string_descriptor __attribute__((aligned(2)))
@ -137,9 +137,10 @@ static struct usb_string_descriptor __attribute__((aligned(2)))
{ {
84, 84,
USB_DT_STRING, USB_DT_STRING,
{'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0','0','0','0','0','0','0','0','0'} '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0',
'0', '0', '0', '0', '0', '0', '0', '0'}
}; };
/* Generic for all targets */ /* Generic for all targets */
@ -167,8 +168,8 @@ static enum { DEFAULT, ADDRESS, CONFIGURED } usb_state;
static int usb_core_num_interfaces; static int usb_core_num_interfaces;
typedef void (*completion_handler_t)(int ep,int dir,int status,int length); typedef void (*completion_handler_t)(int ep, int dir, int status, int length);
typedef bool (*control_handler_t)(struct usb_ctrlrequest* req,unsigned char* dest); typedef bool (*control_handler_t)(struct usb_ctrlrequest* req, unsigned char* dest);
static struct static struct
{ {
@ -261,31 +262,31 @@ static void usb_core_control_request_handler(struct usb_ctrlrequest* req);
static unsigned char response_data[256] USB_DEVBSS_ATTR; static unsigned char response_data[256] USB_DEVBSS_ATTR;
static short hex[16] = {'0','1','2','3','4','5','6','7', static short hex[16] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8','9','A','B','C','D','E','F'}; '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
#ifdef IPOD_ARCH #ifdef IPOD_ARCH
static void set_serial_descriptor(void) static void set_serial_descriptor(void)
{ {
#ifdef IPOD_VIDEO #ifdef IPOD_VIDEO
uint32_t* serial = (uint32_t*)(0x20004034); uint32_t* serial = (uint32_t*)0x20004034;
#else #else
uint32_t* serial = (uint32_t*)(0x20002034); uint32_t* serial = (uint32_t*)0x20002034;
#endif #endif
/* We need to convert from a little-endian 64-bit int /* We need to convert from a little-endian 64-bit int
into a utf-16 string of hex characters */ into a utf-16 string of hex characters */
short* p = &usb_string_iSerial.wString[24]; short* p = &usb_string_iSerial.wString[24];
uint32_t x; uint32_t x;
int i,j; int i, j;
for (i = 0; i < 2; i++) { for(i = 0; i < 2; i++) {
x = serial[i]; x = serial[i];
for (j=0;j<8;j++) { for(j = 0; j < 8; j++) {
*p-- = hex[x & 0xf]; *p-- = hex[x & 0xf];
x >>= 4; x >>= 4;
} }
} }
usb_string_iSerial.bLength=52; usb_string_iSerial.bLength = 52;
} }
#elif defined(HAVE_AS3514) #elif defined(HAVE_AS3514)
static void set_serial_descriptor(void) static void set_serial_descriptor(void)
@ -296,11 +297,11 @@ static void set_serial_descriptor(void)
int i; int i;
ascodec_readbytes(AS3514_UID_0, 0x10, serial); ascodec_readbytes(AS3514_UID_0, 0x10, serial);
for (i = 0; i < 16; i++) { for(i = 0; i < 16; i++) {
*p++ = hex[(serial[i] >> 4) & 0xF]; *p++ = hex[(serial[i] >> 4) & 0xF];
*p++ = hex[(serial[i] >> 0) & 0xF]; *p++ = hex[(serial[i] >> 0) & 0xF];
} }
usb_string_iSerial.bLength=68; usb_string_iSerial.bLength = 68;
} }
#elif (CONFIG_STORAGE & STORAGE_ATA) #elif (CONFIG_STORAGE & STORAGE_ATA)
/* If we don't know the device serial number, use the one /* If we don't know the device serial number, use the one
@ -312,14 +313,14 @@ static void set_serial_descriptor(void)
unsigned short x; unsigned short x;
int i; int i;
for (i = 10; i < 20; i++) { for(i = 10; i < 20; i++) {
x = identify[i]; x = identify[i];
*p++ = hex[(x >> 12) & 0xF]; *p++ = hex[(x >> 12) & 0xF];
*p++ = hex[(x >> 8) & 0xF]; *p++ = hex[(x >> 8) & 0xF];
*p++ = hex[(x >> 4) & 0xF]; *p++ = hex[(x >> 4) & 0xF];
*p++ = hex[(x >> 0) & 0xF]; *p++ = hex[(x >> 0) & 0xF];
} }
usb_string_iSerial.bLength=84; usb_string_iSerial.bLength = 84;
} }
#elif (CONFIG_STORAGE & STORAGE_RAMDISK) #elif (CONFIG_STORAGE & STORAGE_RAMDISK)
/* This "serial number" isn't unique, but it should never actually /* This "serial number" isn't unique, but it should never actually
@ -328,11 +329,11 @@ static void set_serial_descriptor(void)
{ {
short* p = &usb_string_iSerial.wString[1]; short* p = &usb_string_iSerial.wString[1];
int i; int i;
for (i = 0; i < 16; i++) { for(i = 0; i < 16; i++) {
*p++ = hex[(2*i)&0xF]; *p++ = hex[(2 * i) & 0xF];
*p++ = hex[(2*i+1)&0xF]; *p++ = hex[(2 * i + 1) & 0xF];
} }
usb_string_iSerial.bLength=68; usb_string_iSerial.bLength = 68;
} }
#else #else
static void set_serial_descriptor(void) static void set_serial_descriptor(void)
@ -352,10 +353,9 @@ void usb_core_init(void)
/* class driver init functions should be safe to call even if the driver /* class driver init functions should be safe to call even if the driver
* won't be used. This simplifies other logic (i.e. we don't need to know * won't be used. This simplifies other logic (i.e. we don't need to know
* yet which drivers will be enabled */ * yet which drivers will be enabled */
for(i=0;i<USB_NUM_DRIVERS;i++) { for(i = 0; i < USB_NUM_DRIVERS; i++)
if(drivers[i].init != NULL) if(drivers[i].init != NULL)
drivers[i].init(); drivers[i].init();
}
initialized = true; initialized = true;
usb_state = DEFAULT; usb_state = DEFAULT;
@ -365,15 +365,14 @@ void usb_core_init(void)
void usb_core_exit(void) void usb_core_exit(void)
{ {
int i; int i;
for(i=0;i<USB_NUM_DRIVERS;i++) { for(i = 0; i < USB_NUM_DRIVERS; i++)
if(drivers[i].enabled && drivers[i].disconnect != NULL) if(drivers[i].enabled && drivers[i].disconnect != NULL)
{ {
drivers[i].disconnect(); drivers[i].disconnect();
drivers[i].enabled = false; drivers[i].enabled = false;
} }
}
if (initialized) { if(initialized) {
usb_drv_exit(); usb_drv_exit();
initialized = false; initialized = false;
} }
@ -381,8 +380,7 @@ void usb_core_exit(void)
logf("usb_core_exit() finished"); logf("usb_core_exit() finished");
} }
void usb_core_handle_transfer_completion( void usb_core_handle_transfer_completion(struct usb_transfer_completion_event_data* event)
struct usb_transfer_completion_event_data* event)
{ {
completion_handler_t handler; completion_handler_t handler;
int ep = event->endpoint; int ep = event->endpoint;
@ -390,18 +388,17 @@ void usb_core_handle_transfer_completion(
switch(ep) { switch(ep) {
case EP_CONTROL: case EP_CONTROL:
logf("ctrl handled %ld",current_tick); logf("ctrl handled %ld",current_tick);
usb_core_control_request_handler( usb_core_control_request_handler((struct usb_ctrlrequest*)event->data);
(struct usb_ctrlrequest*)event->data);
break; break;
default: default:
handler = ep_data[ep].completion_handler[EP_DIR(event->dir)]; handler = ep_data[ep].completion_handler[EP_DIR(event->dir)];
if(handler != NULL) if(handler != NULL)
handler(ep,event->dir,event->status,event->length); handler(ep, event->dir, event->status, event->length);
break; break;
} }
} }
void usb_core_enable_driver(int driver,bool enabled) void usb_core_enable_driver(int driver, bool enabled)
{ {
drivers[driver].enabled = enabled; drivers[driver].enabled = enabled;
} }
@ -414,37 +411,31 @@ bool usb_core_driver_enabled(int driver)
bool usb_core_any_exclusive_storage(void) bool usb_core_any_exclusive_storage(void)
{ {
int i; int i;
for(i=0;i<USB_NUM_DRIVERS;i++) { for(i = 0; i < USB_NUM_DRIVERS; i++)
if(drivers[i].enabled && drivers[i].needs_exclusive_storage) if(drivers[i].enabled && drivers[i].needs_exclusive_storage)
{
return true; return true;
}
}
return false; return false;
} }
#ifdef HAVE_HOTSWAP #ifdef HAVE_HOTSWAP
void usb_core_hotswap_event(int volume,bool inserted) void usb_core_hotswap_event(int volume, bool inserted)
{ {
int i; int i;
for(i=0;i<USB_NUM_DRIVERS;i++) { for(i = 0; i < USB_NUM_DRIVERS; i++)
if(drivers[i].enabled && drivers[i].notify_hotswap!=NULL) if(drivers[i].enabled && drivers[i].notify_hotswap != NULL)
{ drivers[i].notify_hotswap(volume, inserted);
drivers[i].notify_hotswap(volume,inserted);
}
}
} }
#endif #endif
static void usb_core_set_serial_function_id(void) static void usb_core_set_serial_function_id(void)
{ {
int id = 0; int i, id = 0;
int i;
for(i=0;i<USB_NUM_DRIVERS;i++) { for(i = 0; i < USB_NUM_DRIVERS; i++)
if(drivers[i].enabled) if(drivers[i].enabled)
id |= 1<<i; id |= 1 << i;
}
usb_string_iSerial.wString[0] = hex[id]; usb_string_iSerial.wString[0] = hex[id];
} }
@ -454,7 +445,7 @@ int usb_core_request_endpoint(int type, int dir, struct usb_class_driver* drv)
ret = usb_drv_request_endpoint(type, dir); ret = usb_drv_request_endpoint(type, dir);
if (ret==-1) if(ret == -1)
return -1; return -1;
dir = EP_DIR(ret); dir = EP_DIR(ret);
@ -482,20 +473,20 @@ void usb_core_release_endpoint(int ep)
static void allocate_interfaces_and_endpoints(void) static void allocate_interfaces_and_endpoints(void)
{ {
int i; int i;
int interface=0; int interface = 0;
memset(ep_data,0,sizeof(ep_data)); memset(ep_data, 0, sizeof(ep_data));
for (i = 0; i < USB_NUM_ENDPOINTS; i++) { for(i = 0; i < USB_NUM_ENDPOINTS; i++) {
usb_drv_release_endpoint(i | USB_DIR_OUT); usb_drv_release_endpoint(i | USB_DIR_OUT);
usb_drv_release_endpoint(i | USB_DIR_IN); usb_drv_release_endpoint(i | USB_DIR_IN);
} }
for(i=0;i<USB_NUM_DRIVERS;i++) { for(i = 0; i < USB_NUM_DRIVERS; i++) {
if(drivers[i].enabled) { if(drivers[i].enabled) {
drivers[i].first_interface = interface; drivers[i].first_interface = interface;
if (drivers[i].request_endpoints(&drivers[i])) { if(drivers[i].request_endpoints(&drivers[i])) {
drivers[i].enabled = false; drivers[i].enabled = false;
continue; continue;
} }
@ -513,7 +504,7 @@ static void control_request_handler_drivers(struct usb_ctrlrequest* req)
int i, interface = req->wIndex; int i, interface = req->wIndex;
bool handled=false; bool handled=false;
for(i=0;i<USB_NUM_DRIVERS;i++) { for(i = 0; i < USB_NUM_DRIVERS; i++) {
if(drivers[i].enabled && if(drivers[i].enabled &&
drivers[i].control_request && drivers[i].control_request &&
drivers[i].first_interface <= interface && drivers[i].first_interface <= interface &&
@ -526,7 +517,7 @@ static void control_request_handler_drivers(struct usb_ctrlrequest* req)
} }
if(!handled) { if(!handled) {
/* nope. flag error */ /* nope. flag error */
logf("bad req:desc %d:%d", req->bRequest, req->wValue>>8); logf("bad req:desc %d:%d", req->bRequest, req->wValue >> 8);
usb_drv_stall(EP_CONTROL, true, true); usb_drv_stall(EP_CONTROL, true, true);
} }
} }
@ -539,7 +530,7 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
int length = req->wLength; int length = req->wLength;
int index = req->wValue & 0xff; int index = req->wValue & 0xff;
switch(req->wValue>>8) { /* type */ switch(req->wValue >> 8) { /* type */
case USB_DT_DEVICE: case USB_DT_DEVICE:
ptr = &device_descriptor; ptr = &device_descriptor;
size = sizeof(struct usb_device_descriptor); size = sizeof(struct usb_device_descriptor);
@ -550,8 +541,8 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
int i, max_packet_size; int i, max_packet_size;
if(req->wValue>>8==USB_DT_CONFIG) { if(req->wValue>>8==USB_DT_CONFIG) {
max_packet_size=(usb_drv_port_speed() ? 512 : 64); max_packet_size = (usb_drv_port_speed() ? 512 : 64);
config_descriptor.bDescriptorType=USB_DT_CONFIG; config_descriptor.bDescriptorType = USB_DT_CONFIG;
} }
else { else {
max_packet_size=(usb_drv_port_speed() ? 64 : 512); max_packet_size=(usb_drv_port_speed() ? 64 : 512);
@ -560,15 +551,14 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
} }
size = sizeof(struct usb_config_descriptor); size = sizeof(struct usb_config_descriptor);
for(i=0;i<USB_NUM_DRIVERS;i++) { for(i = 0; i < USB_NUM_DRIVERS; i++)
if(drivers[i].enabled && drivers[i].get_config_descriptor) { if(drivers[i].enabled && drivers[i].get_config_descriptor)
size+=drivers[i].get_config_descriptor( size += drivers[i].get_config_descriptor(
&response_data[size],max_packet_size); &response_data[size], max_packet_size);
}
}
config_descriptor.bNumInterfaces = usb_core_num_interfaces; config_descriptor.bNumInterfaces = usb_core_num_interfaces;
config_descriptor.wTotalLength = (uint16_t)size; config_descriptor.wTotalLength = (uint16_t)size;
memcpy(&response_data[0],&config_descriptor, memcpy(&response_data[0], &config_descriptor,
sizeof(struct usb_config_descriptor)); sizeof(struct usb_config_descriptor));
ptr = response_data; ptr = response_data;
@ -576,15 +566,15 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
} }
case USB_DT_STRING: case USB_DT_STRING:
logf("STRING %d",index); logf("STRING %d", index);
if ((unsigned)index < (sizeof(usb_strings)/ if((unsigned)index < (sizeof(usb_strings) /
sizeof(struct usb_string_descriptor*))) { sizeof(struct usb_string_descriptor*))) {
size = usb_strings[index]->bLength; size = usb_strings[index]->bLength;
ptr = usb_strings[index]; ptr = usb_strings[index];
} }
else { else {
logf("bad string id %d",index); logf("bad string id %d", index);
usb_drv_stall(EP_CONTROL,true,true); usb_drv_stall(EP_CONTROL, true, true);
} }
break; break;
@ -600,16 +590,15 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
break; break;
} }
if (ptr) { if(ptr) {
logf("data %d (%d)",size,length); logf("data %d (%d)", size, length);
length = MIN(size,length); length = MIN(size, length);
if (ptr != response_data) { if (ptr != response_data)
memcpy(response_data,ptr,length); memcpy(response_data, ptr, length);
}
usb_drv_recv(EP_CONTROL,NULL,0); usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL,response_data,length); usb_drv_send(EP_CONTROL, response_data, length);
} }
} }
@ -621,7 +610,7 @@ static void request_handler_device(struct usb_ctrlrequest* req)
case USB_REQ_GET_CONFIGURATION: { case USB_REQ_GET_CONFIGURATION: {
logf("usb_core: GET_CONFIG"); logf("usb_core: GET_CONFIG");
response_data[0] = (usb_state == ADDRESS ? 0 : 1); response_data[0] = (usb_state == ADDRESS ? 0 : 1);
usb_drv_recv(EP_CONTROL,NULL,0); usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 1); usb_drv_send(EP_CONTROL, response_data, 1);
break; break;
} }
@ -630,21 +619,20 @@ static void request_handler_device(struct usb_ctrlrequest* req)
usb_drv_cancel_all_transfers(); usb_drv_cancel_all_transfers();
if(req->wValue) { if(req->wValue) {
usb_state = CONFIGURED; usb_state = CONFIGURED;
for(i=0;i<USB_NUM_DRIVERS;i++) { for(i = 0; i < USB_NUM_DRIVERS; i++)
if(drivers[i].enabled && drivers[i].init_connection) if(drivers[i].enabled && drivers[i].init_connection)
drivers[i].init_connection(); drivers[i].init_connection();
}
} }
else { else
usb_state = ADDRESS; usb_state = ADDRESS;
}
usb_drv_send(EP_CONTROL,NULL,0); usb_drv_send(EP_CONTROL, NULL, 0);
break; break;
} }
case USB_REQ_SET_ADDRESS: { case USB_REQ_SET_ADDRESS: {
unsigned char address = req->wValue; unsigned char address = req->wValue;
logf("usb_core: SET_ADR %d", address); logf("usb_core: SET_ADR %d", address);
usb_drv_send(EP_CONTROL,NULL,0); usb_drv_send(EP_CONTROL, NULL, 0);
usb_drv_cancel_all_transfers(); usb_drv_cancel_all_transfers();
usb_address = address; usb_address = address;
usb_drv_set_address(usb_address); usb_drv_set_address(usb_address);
@ -652,22 +640,22 @@ static void request_handler_device(struct usb_ctrlrequest* req)
break; break;
} }
case USB_REQ_GET_DESCRIPTOR: case USB_REQ_GET_DESCRIPTOR:
logf("usb_core: GET_DESC %d", req->wValue>>8); logf("usb_core: GET_DESC %d", req->wValue >> 8);
request_handler_device_get_descriptor(req); request_handler_device_get_descriptor(req);
break; break;
case USB_REQ_CLEAR_FEATURE: case USB_REQ_CLEAR_FEATURE:
break; break;
case USB_REQ_SET_FEATURE: case USB_REQ_SET_FEATURE:
if(req->wValue==USB_DEVICE_TEST_MODE) { if(req->wValue==USB_DEVICE_TEST_MODE) {
int mode=req->wIndex>>8; int mode = req->wIndex >> 8;
usb_drv_send(EP_CONTROL,NULL,0); usb_drv_send(EP_CONTROL, NULL, 0);
usb_drv_set_test_mode(mode); usb_drv_set_test_mode(mode);
} }
break; break;
case USB_REQ_GET_STATUS: case USB_REQ_GET_STATUS:
response_data[0]= 0; response_data[0] = 0;
response_data[1]= 0; response_data[1] = 0;
usb_drv_recv(EP_CONTROL,NULL,0); usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 2); usb_drv_send(EP_CONTROL, response_data, 2);
break; break;
default: default:
@ -681,23 +669,23 @@ static void request_handler_interface_standard(struct usb_ctrlrequest* req)
{ {
case USB_REQ_SET_INTERFACE: case USB_REQ_SET_INTERFACE:
logf("usb_core: SET_INTERFACE"); logf("usb_core: SET_INTERFACE");
usb_drv_send(EP_CONTROL,NULL,0); usb_drv_send(EP_CONTROL, NULL, 0);
break; break;
case USB_REQ_GET_INTERFACE: case USB_REQ_GET_INTERFACE:
logf("usb_core: GET_INTERFACE"); logf("usb_core: GET_INTERFACE");
response_data[0]=0; response_data[0] = 0;
usb_drv_recv(EP_CONTROL,NULL,0); usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL,response_data,1); usb_drv_send(EP_CONTROL, response_data, 1);
break; break;
case USB_REQ_CLEAR_FEATURE: case USB_REQ_CLEAR_FEATURE:
break; break;
case USB_REQ_SET_FEATURE: case USB_REQ_SET_FEATURE:
break; break;
case USB_REQ_GET_STATUS: case USB_REQ_GET_STATUS:
response_data[0]=0; response_data[0] = 0;
response_data[1]=0; response_data[1] = 0;
usb_drv_recv(EP_CONTROL,NULL,0); usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_send(EP_CONTROL, response_data, 2); usb_drv_send(EP_CONTROL, response_data, 2);
break; break;
default: default:
@ -731,10 +719,10 @@ static void request_handler_endoint_drivers(struct usb_ctrlrequest* req)
if(control_handler) if(control_handler)
handled = control_handler(req, response_data); handled = control_handler(req, response_data);
if (!handled) { if(!handled) {
/* nope. flag error */ /* nope. flag error */
logf("usb bad req %d",req->bRequest); logf("usb bad req %d", req->bRequest);
usb_drv_stall(EP_CONTROL,true,true); usb_drv_stall(EP_CONTROL, true, true);
} }
} }
@ -742,27 +730,26 @@ static void request_handler_endpoint_standard(struct usb_ctrlrequest* req)
{ {
switch (req->bRequest) { switch (req->bRequest) {
case USB_REQ_CLEAR_FEATURE: case USB_REQ_CLEAR_FEATURE:
if (req->wValue==USB_ENDPOINT_HALT) { if(req->wValue == USB_ENDPOINT_HALT)
usb_drv_stall(EP_NUM(req->wIndex), false, EP_DIR(req->wIndex)); usb_drv_stall(EP_NUM(req->wIndex), false, EP_DIR(req->wIndex));
}
usb_drv_send(EP_CONTROL,NULL,0); usb_drv_send(EP_CONTROL, NULL, 0);
break; break;
case USB_REQ_SET_FEATURE: case USB_REQ_SET_FEATURE:
if (req->wValue==USB_ENDPOINT_HALT) { if(req->wValue == USB_ENDPOINT_HALT)
usb_drv_stall(EP_NUM(req->wIndex), true, EP_DIR(req->wIndex)); usb_drv_stall(EP_NUM(req->wIndex), true, EP_DIR(req->wIndex));
}
usb_drv_send(EP_CONTROL,NULL,0); usb_drv_send(EP_CONTROL, NULL, 0);
break; break;
case USB_REQ_GET_STATUS: case USB_REQ_GET_STATUS:
response_data[0]=0; response_data[0] = 0;
response_data[1]=0; response_data[1] = 0;
logf("usb_core: GET_STATUS"); logf("usb_core: GET_STATUS");
if(req->wIndex>0) { if(req->wIndex > 0)
response_data[0]=usb_drv_stalled(EP_NUM(req->wIndex), response_data[0] = usb_drv_stalled(EP_NUM(req->wIndex), EP_DIR(req->wIndex));
EP_DIR(req->wIndex));
} usb_drv_recv(EP_CONTROL, NULL, 0);
usb_drv_recv(EP_CONTROL,NULL,0); usb_drv_send(EP_CONTROL, response_data, 2);
usb_drv_send(EP_CONTROL,response_data,2);
break; break;
default: default:
request_handler_endoint_drivers(req); request_handler_endoint_drivers(req);
@ -788,7 +775,7 @@ static void request_handler_endpoint(struct usb_ctrlrequest* req)
/* Handling USB requests starts here */ /* Handling USB requests starts here */
static void usb_core_control_request_handler(struct usb_ctrlrequest* req) static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
{ {
if (usb_state==DEFAULT) { if(usb_state == DEFAULT) {
set_serial_descriptor(); set_serial_descriptor();
usb_core_set_serial_function_id(); usb_core_set_serial_function_id();
@ -815,12 +802,12 @@ static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
/* called by usb_drv_int() */ /* called by usb_drv_int() */
void usb_core_bus_reset(void) void usb_core_bus_reset(void)
{ {
usb_address=0; usb_address = 0;
usb_state=DEFAULT; usb_state = DEFAULT;
} }
/* called by usb_drv_transfer_completed() */ /* called by usb_drv_transfer_completed() */
void usb_core_transfer_complete(int endpoint,int dir,int status,int length) void usb_core_transfer_complete(int endpoint, int dir, int status, int length)
{ {
struct usb_transfer_completion_event_data *completion_event; struct usb_transfer_completion_event_data *completion_event;
@ -830,13 +817,13 @@ void usb_core_transfer_complete(int endpoint,int dir,int status,int length)
break; break;
default: default:
completion_event=&ep_data[endpoint].completion_event[EP_DIR(dir)]; completion_event = &ep_data[endpoint].completion_event[EP_DIR(dir)];
completion_event->endpoint=endpoint; completion_event->endpoint = endpoint;
completion_event->dir=dir; completion_event->dir = dir;
completion_event->data=0; completion_event->data = 0;
completion_event->status=status; completion_event->status = status;
completion_event->length=length; completion_event->length = length;
/* All other endoints. Let the thread deal with it */ /* All other endoints. Let the thread deal with it */
usb_signal_transfer_completion(completion_event); usb_signal_transfer_completion(completion_event);
break; break;
@ -849,18 +836,18 @@ void usb_core_control_request(struct usb_ctrlrequest* req)
struct usb_transfer_completion_event_data* completion_event = struct usb_transfer_completion_event_data* completion_event =
&ep_data[EP_CONTROL].completion_event[EP_DIR(USB_DIR_IN)]; &ep_data[EP_CONTROL].completion_event[EP_DIR(USB_DIR_IN)];
completion_event->endpoint=EP_CONTROL; completion_event->endpoint = EP_CONTROL;
completion_event->dir=0; completion_event->dir = 0;
completion_event->data=(void*)req; completion_event->data = (void*)req;
completion_event->status=0; completion_event->status = 0;
completion_event->length=0; completion_event->length = 0;
logf("ctrl received %ld",current_tick); logf("ctrl received %ld", current_tick);
usb_signal_transfer_completion(completion_event); usb_signal_transfer_completion(completion_event);
} }
#ifdef HAVE_USB_POWER #ifdef HAVE_USB_POWER
unsigned short usb_allowed_current() unsigned short usb_allowed_current()
{ {
return (usb_state==CONFIGURED) ? MAX(USB_MAX_CURRENT, 100) : 100; return (usb_state == CONFIGURED) ? MAX(USB_MAX_CURRENT, 100) : 100;
} }
#endif #endif