From 7f32136238f6b7e7e12cfbcb495ea467a43c7ee7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Schm=C3=B6lzer?= Date: Thu, 4 Jul 2013 20:06:02 +0200 Subject: [PATCH] OpenULINK firmware: Use C99 designated struct initializers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Recent versions of SDCC added support for C99 designated struct initializers. This provides better code readability (no functional changes). Successfully tested with ULINK probe and STM32F103 (debug, erase and write flash). Change-Id: Idfa35147d2c3043baaa21a811b926b3845c85f9b Signed-off-by: Martin Schmölzer Reviewed-on: http://openocd.zylin.com/1484 Tested-by: jenkins Reviewed-by: Spencer Oliver --- src/jtag/drivers/OpenULINK/src/usb.c | 113 ++++++++++++--------------- 1 file changed, 49 insertions(+), 64 deletions(-) diff --git a/src/jtag/drivers/OpenULINK/src/usb.c b/src/jtag/drivers/OpenULINK/src/usb.c index 557afff5..98ae67f7 100644 --- a/src/jtag/drivers/OpenULINK/src/usb.c +++ b/src/jtag/drivers/OpenULINK/src/usb.c @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2011 by Martin Schmoelzer * + * Copyright (C) 2011-2013 by Martin Schmoelzer * * * * * * This program is free software; you can redistribute it and/or modify * @@ -43,87 +43,72 @@ volatile __xdata __at 0x7FE8 struct setup_data setup_data; * Be sure to include the neccessary endpoint descriptors! */ #define NUM_ENDPOINTS 2 -/* - * Normally, we would initialize the descriptor structures in C99 style: - * - * __code usb_device_descriptor_t device_descriptor = { - * .bLength = foo, - * .bDescriptorType = bar, - * .bcdUSB = 0xABCD, - * ... - * }; - * - * But SDCC currently does not support this, so we have to do it the - * old-fashioned way... - */ - __code struct usb_device_descriptor device_descriptor = { - /* .bLength = */ sizeof(struct usb_device_descriptor), - /* .bDescriptorType = */ DESCRIPTOR_TYPE_DEVICE, - /* .bcdUSB = */ 0x0110, /* BCD: 01.00 (Version 1.0 USB spec) */ - /* .bDeviceClass = */ 0xFF, /* 0xFF = vendor-specific */ - /* .bDeviceSubClass = */ 0xFF, - /* .bDeviceProtocol = */ 0xFF, - /* .bMaxPacketSize0 = */ 64, - /* .idVendor = */ 0xC251, - /* .idProduct = */ 0x2710, - /* .bcdDevice = */ 0x0100, - /* .iManufacturer = */ 1, - /* .iProduct = */ 2, - /* .iSerialNumber = */ 3, - /* .bNumConfigurations = */ 1 + .bLength = sizeof(struct usb_device_descriptor), + .bDescriptorType = DESCRIPTOR_TYPE_DEVICE, + .bcdUSB = 0x0110, /* BCD: 01.00 (Version 1.0 USB spec) */ + .bDeviceClass = 0xFF, /* 0xFF = vendor-specific */ + .bDeviceSubClass = 0xFF, + .bDeviceProtocol = 0xFF, + .bMaxPacketSize0 = 64, + .idVendor = 0xC251, + .idProduct = 0x2710, + .bcdDevice = 0x0100, + .iManufacturer = 1, + .iProduct = 2, + .iSerialNumber = 3, + .bNumConfigurations = 1 }; /* WARNING: ALL config, interface and endpoint descriptors MUST be adjacent! */ __code struct usb_config_descriptor config_descriptor = { - /* .bLength = */ sizeof(struct usb_config_descriptor), - /* .bDescriptorType = */ DESCRIPTOR_TYPE_CONFIGURATION, - /* .wTotalLength = */ sizeof(struct usb_config_descriptor) + - sizeof(struct usb_interface_descriptor) + - (NUM_ENDPOINTS * - sizeof(struct usb_endpoint_descriptor)), - /* .bNumInterfaces = */ 1, - /* .bConfigurationValue = */ 1, - /* .iConfiguration = */ 4, /* String describing this configuration */ - /* .bmAttributes = */ 0x80, /* Only MSB set according to USB spec */ - /* .MaxPower = */ 50 /* 100 mA */ + .bLength = sizeof(struct usb_config_descriptor), + .bDescriptorType = DESCRIPTOR_TYPE_CONFIGURATION, + .wTotalLength = sizeof(struct usb_config_descriptor) + + sizeof(struct usb_interface_descriptor) + + (NUM_ENDPOINTS * sizeof(struct usb_endpoint_descriptor)), + .bNumInterfaces = 1, + .bConfigurationValue = 1, + .iConfiguration = 4, /* String describing this configuration */ + .bmAttributes = 0x80, /* Only MSB set according to USB spec */ + .MaxPower = 50 /* 100 mA */ }; __code struct usb_interface_descriptor interface_descriptor00 = { - /* .bLength = */ sizeof(struct usb_interface_descriptor), - /* .bDescriptorType = */ DESCRIPTOR_TYPE_INTERFACE, - /* .bInterfaceNumber = */ 0, - /* .bAlternateSetting = */ 0, - /* .bNumEndpoints = */ NUM_ENDPOINTS, - /* .bInterfaceClass = */ 0xFF, - /* .bInterfaceSubclass = */ 0xFF, - /* .bInterfaceProtocol = */ 0xFF, - /* .iInterface = */ 0 + .bLength = sizeof(struct usb_interface_descriptor), + .bDescriptorType = DESCRIPTOR_TYPE_INTERFACE, + .bInterfaceNumber = 0, + .bAlternateSetting = 0, + .bNumEndpoints = NUM_ENDPOINTS, + .bInterfaceClass = 0xFF, + .bInterfaceSubclass = 0xFF, + .bInterfaceProtocol = 0xFF, + .iInterface = 0 }; __code struct usb_endpoint_descriptor Bulk_EP2_IN_Endpoint_Descriptor = { - /* .bLength = */ sizeof(struct usb_endpoint_descriptor), - /* .bDescriptorType = */ 0x05, - /* .bEndpointAddress = */ 2 | USB_DIR_IN, - /* .bmAttributes = */ 0x02, - /* .wMaxPacketSize = */ 64, - /* .bInterval = */ 0 + .bLength = sizeof(struct usb_endpoint_descriptor), + .bDescriptorType = 0x05, + .bEndpointAddress = (2 | USB_DIR_IN), + .bmAttributes = 0x02, + .wMaxPacketSize = 64, + .bInterval = 0 }; __code struct usb_endpoint_descriptor Bulk_EP2_OUT_Endpoint_Descriptor = { - /* .bLength = */ sizeof(struct usb_endpoint_descriptor), - /* .bDescriptorType = */ 0x05, - /* .bEndpointAddress = */ 2 | USB_DIR_OUT, - /* .bmAttributes = */ 0x02, - /* .wMaxPacketSize = */ 64, - /* .bInterval = */ 0 + .bLength = sizeof(struct usb_endpoint_descriptor), + .bDescriptorType = 0x05, + .bEndpointAddress = (2 | USB_DIR_OUT), + .bmAttributes = 0x02, + .wMaxPacketSize = 64, + .bInterval = 0 }; __code struct usb_language_descriptor language_descriptor = { - /* .bLength = */ 4, - /* .bDescriptorType = */ DESCRIPTOR_TYPE_STRING, - /* .wLANGID = */ {0x0409 /* US English */} + .bLength = 4, + .bDescriptorType = DESCRIPTOR_TYPE_STRING, + .wLANGID = {0x0409 /* US English */} }; __code struct usb_string_descriptor strManufacturer = -- 2.39.5