From 4c2126b5a8b0bea04d4c5ba8bee032f9bc0efbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C3=ABl=20Carr=C3=A9?= Date: Thu, 29 Dec 2011 21:58:34 +0000 Subject: usb PACK_DATA: use a static inline to enable type checking git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31467 a1c6a512-1295-4272-9138-f99709370657 --- firmware/usbstack/usb_charging_only.c | 2 +- firmware/usbstack/usb_class_driver.h | 12 ++++++------ firmware/usbstack/usb_hid.c | 6 +++--- firmware/usbstack/usb_serial.c | 6 +++--- firmware/usbstack/usb_storage.c | 6 +++--- 5 files changed, 16 insertions(+), 16 deletions(-) (limited to 'firmware/usbstack') diff --git a/firmware/usbstack/usb_charging_only.c b/firmware/usbstack/usb_charging_only.c index 7a8389e620..6bd17a92de 100644 --- a/firmware/usbstack/usb_charging_only.c +++ b/firmware/usbstack/usb_charging_only.c @@ -64,7 +64,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; - PACK_DATA(dest, interface_descriptor); + PACK_DATA(&dest, interface_descriptor); return (dest-orig_dest); } diff --git a/firmware/usbstack/usb_class_driver.h b/firmware/usbstack/usb_class_driver.h index c8d1e7047d..20ee26a3d0 100644 --- a/firmware/usbstack/usb_class_driver.h +++ b/firmware/usbstack/usb_class_driver.h @@ -85,10 +85,10 @@ struct usb_class_driver { #endif }; -#define PACK_DATA(dest, data) \ - do { \ - memcpy(dest, &(data), sizeof(data)); \ - dest += sizeof(data); \ - } while (0) - +#define PACK_DATA(dest, data) pack_data(dest, &(data), sizeof(data)) +static inline void pack_data(uint8_t **dest, const void *data, size_t size) +{ + memcpy(*dest, data, size); + *dest += size; +} #endif diff --git a/firmware/usbstack/usb_hid.c b/firmware/usbstack/usb_hid.c index b89e46f291..ed0816395a 100644 --- a/firmware/usbstack/usb_hid.c +++ b/firmware/usbstack/usb_hid.c @@ -561,7 +561,7 @@ static void descriptor_hid_get(unsigned char **dest) logf("hid: desc len %u", hid_descriptor.wDescriptorLength0); buf_dump(report_descriptor, hid_descriptor.wDescriptorLength0, "desc"); - PACK_DATA(*dest, hid_descriptor); + PACK_DATA(dest, hid_descriptor); } int usb_hid_get_config_descriptor(unsigned char *dest, int max_packet_size) @@ -574,7 +574,7 @@ int usb_hid_get_config_descriptor(unsigned char *dest, int max_packet_size) /* Interface descriptor */ interface_descriptor.bInterfaceNumber = usb_interface; - PACK_DATA(dest, interface_descriptor); + PACK_DATA(&dest, interface_descriptor); /* HID descriptor */ descriptor_hid_get(&dest); @@ -583,7 +583,7 @@ int usb_hid_get_config_descriptor(unsigned char *dest, int max_packet_size) endpoint_descriptor.wMaxPacketSize = 8; endpoint_descriptor.bInterval = 8; endpoint_descriptor.bEndpointAddress = ep_in; - PACK_DATA(dest, endpoint_descriptor); + PACK_DATA(&dest, endpoint_descriptor); return (int)(dest - orig_dest); } diff --git a/firmware/usbstack/usb_serial.c b/firmware/usbstack/usb_serial.c index e7159099fe..4a80433435 100644 --- a/firmware/usbstack/usb_serial.c +++ b/firmware/usbstack/usb_serial.c @@ -100,15 +100,15 @@ int usb_serial_get_config_descriptor(unsigned char *dest, int max_packet_size) unsigned char *orig_dest = dest; interface_descriptor.bInterfaceNumber = usb_interface; - PACK_DATA(dest, interface_descriptor); + PACK_DATA(&dest, interface_descriptor); endpoint_descriptor.wMaxPacketSize = max_packet_size; endpoint_descriptor.bEndpointAddress = ep_in; - PACK_DATA(dest, endpoint_descriptor); + PACK_DATA(&dest, endpoint_descriptor); endpoint_descriptor.bEndpointAddress = ep_out; - PACK_DATA(dest, endpoint_descriptor); + PACK_DATA(&dest, endpoint_descriptor); return (dest - orig_dest); } diff --git a/firmware/usbstack/usb_storage.c b/firmware/usbstack/usb_storage.c index c156d80396..8d1b94bf7a 100644 --- a/firmware/usbstack/usb_storage.c +++ b/firmware/usbstack/usb_storage.c @@ -430,15 +430,15 @@ int usb_storage_get_config_descriptor(unsigned char *dest,int max_packet_size) unsigned char *orig_dest = dest; interface_descriptor.bInterfaceNumber = usb_interface; - PACK_DATA(dest, interface_descriptor); + PACK_DATA(&dest, interface_descriptor); endpoint_descriptor.wMaxPacketSize = max_packet_size; endpoint_descriptor.bEndpointAddress = ep_in; - PACK_DATA(dest, endpoint_descriptor); + PACK_DATA(&dest, endpoint_descriptor); endpoint_descriptor.bEndpointAddress = ep_out; - PACK_DATA(dest, endpoint_descriptor); + PACK_DATA(&dest, endpoint_descriptor); return (dest - orig_dest); } -- cgit v1.2.3