summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Gevaerts <frank@gevaerts.be>2009-04-18 20:04:52 +0000
committerFrank Gevaerts <frank@gevaerts.be>2009-04-18 20:04:52 +0000
commitab09322b7acfa1667f3124612735ea83ce5342d5 (patch)
treec3b35f6bc62e95dfc7b1ac6840564f24e4bca557
parent8b6b46f3c47aa3772598b359b43e3efe1138e9e6 (diff)
downloadrockbox-ab09322b7acfa1667f3124612735ea83ce5342d5.tar.gz
rockbox-ab09322b7acfa1667f3124612735ea83ce5342d5.tar.bz2
rockbox-ab09322b7acfa1667f3124612735ea83ce5342d5.zip
Add a PACK_DESCRIPTOR macro to make the class drivers a bit more readable (FS#10145 by Tomer Shalev)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20733 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/usbstack/usb_charging_only.c5
-rw-r--r--firmware/usbstack/usb_class_driver.h6
-rw-r--r--firmware/usbstack/usb_serial.c15
-rw-r--r--firmware/usbstack/usb_storage.c21
4 files changed, 23 insertions, 24 deletions
diff --git a/firmware/usbstack/usb_charging_only.c b/firmware/usbstack/usb_charging_only.c
index e20d1885a0..145d0f684c 100644
--- a/firmware/usbstack/usb_charging_only.c
+++ b/firmware/usbstack/usb_charging_only.c
@@ -24,6 +24,7 @@
#include "usb_drv.h"
#include "kernel.h"
#include "usb_charging_only.h"
+#include "usb_class_driver.h"
//#define LOGF_ENABLE
#include "logf.h"
@@ -66,9 +67,7 @@ int usb_charging_only_get_config_descriptor(unsigned char *dest,int max_packet_s
unsigned char *orig_dest = dest;
interface_descriptor.bInterfaceNumber=usb_interface;
- memcpy(dest,&interface_descriptor,sizeof(struct usb_interface_descriptor));
-
- dest+=sizeof(struct usb_interface_descriptor);
+ PACK_DESCRIPTOR(dest, interface_descriptor);
return (dest-orig_dest);
}
diff --git a/firmware/usbstack/usb_class_driver.h b/firmware/usbstack/usb_class_driver.h
index 22b1c6888c..b51eb3e93f 100644
--- a/firmware/usbstack/usb_class_driver.h
+++ b/firmware/usbstack/usb_class_driver.h
@@ -85,4 +85,10 @@ struct usb_class_driver {
#endif
};
+#define PACK_DESCRIPTOR(dest, descriptor) \
+ do { \
+ memcpy(dest, &(descriptor), sizeof(descriptor)); \
+ dest += sizeof(descriptor); \
+ } while (0)
+
#endif
diff --git a/firmware/usbstack/usb_serial.c b/firmware/usbstack/usb_serial.c
index b7d5062237..514df0dc2b 100644
--- a/firmware/usbstack/usb_serial.c
+++ b/firmware/usbstack/usb_serial.c
@@ -24,7 +24,7 @@
#include "usb_drv.h"
#include "kernel.h"
#include "usb_serial.h"
-
+#include "usb_class_driver.h"
//#define LOGF_ENABLE
#include "logf.h"
@@ -102,19 +102,16 @@ int usb_serial_get_config_descriptor(unsigned char *dest,int max_packet_size)
{
unsigned char *orig_dest = dest;
- endpoint_descriptor.wMaxPacketSize=max_packet_size;
- interface_descriptor.bInterfaceNumber=usb_interface;
+ interface_descriptor.bInterfaceNumber = usb_interface;
+ PACK_DESCRIPTOR(dest, interface_descriptor);
- memcpy(dest,&interface_descriptor,sizeof(struct usb_interface_descriptor));
- dest+=sizeof(struct usb_interface_descriptor);
+ endpoint_descriptor.wMaxPacketSize = max_packet_size;
endpoint_descriptor.bEndpointAddress = ep_in;
- memcpy(dest,&endpoint_descriptor,sizeof(struct usb_endpoint_descriptor));
- dest+=sizeof(struct usb_endpoint_descriptor);
+ PACK_DESCRIPTOR(dest, endpoint_descriptor);
endpoint_descriptor.bEndpointAddress = ep_out;
- memcpy(dest,&endpoint_descriptor,sizeof(struct usb_endpoint_descriptor));
- dest+=sizeof(struct usb_endpoint_descriptor);
+ PACK_DESCRIPTOR(dest, endpoint_descriptor);
return (dest - orig_dest);
}
diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c
index eb1db5d884..2a3808dd92 100644
--- a/firmware/usbstack/usb_storage.c
+++ b/firmware/usbstack/usb_storage.c
@@ -22,6 +22,7 @@
#include "system.h"
#include "usb_core.h"
#include "usb_drv.h"
+#include "usb_class_driver.h"
//#define LOGF_ENABLE
#include "logf.h"
#include "storage.h"
@@ -371,24 +372,20 @@ int usb_storage_set_first_interface(int interface)
int usb_storage_get_config_descriptor(unsigned char *dest,int max_packet_size)
{
- endpoint_descriptor.wMaxPacketSize=max_packet_size;
- interface_descriptor.bInterfaceNumber=usb_interface;
+ unsigned char *orig_dest = dest;
- memcpy(dest,&interface_descriptor,
- sizeof(struct usb_interface_descriptor));
- dest+=sizeof(struct usb_interface_descriptor);
+ interface_descriptor.bInterfaceNumber = usb_interface;
+ PACK_DESCRIPTOR(dest, interface_descriptor);
+
+ endpoint_descriptor.wMaxPacketSize = max_packet_size;
endpoint_descriptor.bEndpointAddress = ep_in;
- memcpy(dest,&endpoint_descriptor,
- sizeof(struct usb_endpoint_descriptor));
- dest+=sizeof(struct usb_endpoint_descriptor);
+ PACK_DESCRIPTOR(dest, endpoint_descriptor);
endpoint_descriptor.bEndpointAddress = ep_out;
- memcpy(dest,&endpoint_descriptor,
- sizeof(struct usb_endpoint_descriptor));
+ PACK_DESCRIPTOR(dest, endpoint_descriptor);
- return sizeof(struct usb_interface_descriptor) +
- 2*sizeof(struct usb_endpoint_descriptor);
+ return (dest - orig_dest);
}
void usb_storage_init_connection(void)