1
0
Fork 0
forked from len0rd/rockbox

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

@ -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 */
@ -267,9 +268,9 @@ static short hex[16] = {'0','1','2','3','4','5','6','7',
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
@ -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,13 +365,12 @@ 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();
@ -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,8 +388,7 @@ 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)];
@ -414,12 +411,9 @@ 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;
} }
@ -428,23 +422,20 @@ bool usb_core_any_exclusive_storage(void)
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];
} }
@ -560,12 +551,11 @@ 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,
@ -604,9 +594,8 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req)
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);
@ -630,14 +619,13 @@ 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;
} }
@ -742,25 +730,24 @@ 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;