summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2008-02-25 23:43:11 +0000
committerFrank Gevaerts <frank@gevaerts.be>2008-02-25 23:43:11 +0000
commit7bf5722a9dd6d65b1b947447ff0383b5a07cdb0b (patch)
tree397d21a62a0e342049b8de4c23a2d2697323b756
parent30b129d0250cd112499ddd260b947fb2762d8bbb (diff)
some progress towards software-selectability of usb class drivers.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16422 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/export/usb.h11
-rw-r--r--firmware/usbstack/usb_core.c101
2 files changed, 72 insertions, 40 deletions
diff --git a/firmware/export/usb.h b/firmware/export/usb.h
index c2487f3563..ebeb93ad22 100644
--- a/firmware/export/usb.h
+++ b/firmware/export/usb.h
@@ -61,6 +61,17 @@
#endif
#endif /* HAVE_USB_POWER */
+#ifdef HAVE_USBSTACK
+/* USB class drivers */
+enum {
+ USB_DRIVER_MASS_STORAGE,
+ USB_DRIVER_SERIAL,
+ USB_DRIVER_CHARGING_ONLY,
+ USB_DRIVER_COUNT
+};
+#endif
+
+
void usb_init(void);
void usb_enable(bool on);
void usb_start_monitoring(void);
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c
index 2def3711cb..d7473e4d1f 100644
--- a/firmware/usbstack/usb_core.c
+++ b/firmware/usbstack/usb_core.c
@@ -23,6 +23,7 @@
//#define LOGF_ENABLE
#include "logf.h"
+#include "usb.h"
#include "usb_ch9.h"
#include "usb_drv.h"
#include "usb_core.h"
@@ -299,6 +300,18 @@ static long usbcore_stack[DEFAULT_STACK_SIZE];
static void usb_core_thread(void);
#endif
+#ifdef USE_ROCKBOX_USB
+static bool usb_core_charging_enabled = false;
+static bool usb_core_storage_enabled = true;
+static bool usb_core_serial_enabled = true;
+#if defined(USB_BENCHMARK)
+static bool usb_core_benchmark_enabled = false;
+#endif
+#else
+static bool usb_core_charging_enabled = true;
+#endif
+
+
static void usb_core_control_request_handler(struct usb_ctrlrequest* req);
static int ack_control(struct usb_ctrlrequest* req);
@@ -490,11 +503,9 @@ static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
/* note: interrupt context */
data_connection = true;
-#if defined(IPOD_ARCH) || defined(HAVE_AS3514)
if(usb_state == DEFAULT) {
set_serial_descriptor();
}
-#endif
#ifdef USB_BENCHMARK
if ((req->bRequestType & 0x60) == USB_TYPE_VENDOR) {
@@ -510,11 +521,13 @@ static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
if (req->wValue){
usb_state = CONFIGURED;
#ifdef USB_STORAGE
- usb_storage_control_request(req);
+ if(usb_core_storage_enabled)
+ usb_storage_control_request(req);
#endif
#ifdef USB_SERIAL
- usb_serial_control_request(req);
+ if(usb_core_serial_enabled)
+ usb_serial_control_request(req);
#endif
}
else {
@@ -631,48 +644,56 @@ static void usb_core_control_request_handler(struct usb_ctrlrequest* req)
size = sizeof(config_descriptor);
#ifdef USB_CHARGING_ONLY
- charging_interface_descriptor.bInterfaceNumber=interface_number;
- interface_number++;
- memcpy(&response_data[size],&charging_interface_descriptor,sizeof(struct usb_interface_descriptor));
- size += sizeof(struct usb_interface_descriptor);
+ if(usb_core_charging_enabled){
+ charging_interface_descriptor.bInterfaceNumber=interface_number;
+ interface_number++;
+ memcpy(&response_data[size],&charging_interface_descriptor,sizeof(struct usb_interface_descriptor));
+ size += sizeof(struct usb_interface_descriptor);
+ }
#endif
#ifdef USB_STORAGE
- mass_storage_ep_in_descriptor.wMaxPacketSize=max_packet_size;
- mass_storage_ep_out_descriptor.wMaxPacketSize=max_packet_size;
- mass_storage_interface_descriptor.bInterfaceNumber=interface_number;
- interface_number++;
-
- memcpy(&response_data[size],&mass_storage_interface_descriptor,sizeof(struct usb_interface_descriptor));
- size += sizeof(struct usb_interface_descriptor);
- memcpy(&response_data[size],&mass_storage_ep_in_descriptor,sizeof(struct usb_endpoint_descriptor));
- size += sizeof(struct usb_endpoint_descriptor);
- memcpy(&response_data[size],&mass_storage_ep_out_descriptor,sizeof(struct usb_endpoint_descriptor));
- size += sizeof(struct usb_endpoint_descriptor);
+ if(usb_core_storage_enabled){
+ mass_storage_ep_in_descriptor.wMaxPacketSize=max_packet_size;
+ mass_storage_ep_out_descriptor.wMaxPacketSize=max_packet_size;
+ mass_storage_interface_descriptor.bInterfaceNumber=interface_number;
+ interface_number++;
+
+ memcpy(&response_data[size],&mass_storage_interface_descriptor,sizeof(struct usb_interface_descriptor));
+ size += sizeof(struct usb_interface_descriptor);
+ memcpy(&response_data[size],&mass_storage_ep_in_descriptor,sizeof(struct usb_endpoint_descriptor));
+ size += sizeof(struct usb_endpoint_descriptor);
+ memcpy(&response_data[size],&mass_storage_ep_out_descriptor,sizeof(struct usb_endpoint_descriptor));
+ size += sizeof(struct usb_endpoint_descriptor);
+ }
#endif
#ifdef USB_SERIAL
- serial_ep_in_descriptor.wMaxPacketSize=max_packet_size;
- serial_ep_out_descriptor.wMaxPacketSize=max_packet_size;
- serial_interface_descriptor.bInterfaceNumber=interface_number;
- interface_number++;
-
- memcpy(&response_data[size],&serial_interface_descriptor,sizeof(struct usb_interface_descriptor));
- size += sizeof(struct usb_interface_descriptor);
- memcpy(&response_data[size],&serial_ep_in_descriptor,sizeof(struct usb_endpoint_descriptor));
- size += sizeof(struct usb_endpoint_descriptor);
- memcpy(&response_data[size],&serial_ep_out_descriptor,sizeof(struct usb_endpoint_descriptor));
- size += sizeof(struct usb_endpoint_descriptor);
+ if(usb_core_serial_enabled){
+ serial_ep_in_descriptor.wMaxPacketSize=max_packet_size;
+ serial_ep_out_descriptor.wMaxPacketSize=max_packet_size;
+ serial_interface_descriptor.bInterfaceNumber=interface_number;
+ interface_number++;
+
+ memcpy(&response_data[size],&serial_interface_descriptor,sizeof(struct usb_interface_descriptor));
+ size += sizeof(struct usb_interface_descriptor);
+ memcpy(&response_data[size],&serial_ep_in_descriptor,sizeof(struct usb_endpoint_descriptor));
+ size += sizeof(struct usb_endpoint_descriptor);
+ memcpy(&response_data[size],&serial_ep_out_descriptor,sizeof(struct usb_endpoint_descriptor));
+ size += sizeof(struct usb_endpoint_descriptor);
+ }
#endif
#ifdef USB_BENCHMARK
- benchmark_ep_in_descriptor.wMaxPacketSize=max_packet_size;
- benchmark_ep_out_descriptor.wMaxPacketSize=max_packet_size;
- config_descriptor.bNumInterfaces=interface_number;
-
- memcpy(&response_data[size],&benchmark_interface_descriptor,sizeof(struct usb_interface_descriptor));
- size += sizeof(struct usb_interface_descriptor);
- memcpy(&response_data[size],&benchmark_ep_in_descriptor,sizeof(struct usb_endpoint_descriptor));
- size += sizeof(struct usb_endpoint_descriptor);
- memcpy(&response_data[size],&benchmark_ep_out_descriptor,sizeof(struct usb_endpoint_descriptor));
- size += sizeof(struct usb_endpoint_descriptor);
+ if(usb_core_benchmark_enabled){
+ benchmark_ep_in_descriptor.wMaxPacketSize=max_packet_size;
+ benchmark_ep_out_descriptor.wMaxPacketSize=max_packet_size;
+ config_descriptor.bNumInterfaces=interface_number;
+
+ memcpy(&response_data[size],&benchmark_interface_descriptor,sizeof(struct usb_interface_descriptor));
+ size += sizeof(struct usb_interface_descriptor);
+ memcpy(&response_data[size],&benchmark_ep_in_descriptor,sizeof(struct usb_endpoint_descriptor));
+ size += sizeof(struct usb_endpoint_descriptor);
+ memcpy(&response_data[size],&benchmark_ep_out_descriptor,sizeof(struct usb_endpoint_descriptor));
+ size += sizeof(struct usb_endpoint_descriptor);
+ }
#endif
config_descriptor.wTotalLength = size;
memcpy(&response_data[0],&config_descriptor,sizeof(struct usb_config_descriptor));