USB: make use of standard byte order functions
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 23 Sep 2010 17:30:11 +0000 (17:30 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 23 Sep 2010 17:30:11 +0000 (17:30 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4279 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/cpu/cortex-m3/drv/usb_stm32.c
bertos/drv/usb.h
bertos/drv/usb_keyboard.c
bertos/drv/usb_mouse.c
bertos/drv/usb_serial.c

index a47237e9b51c2e1f2ec10428634ee411a13da91a..a7f9d8c809461fc6ac6b1eb5e67f5e1d522943c6 100644 (file)
@@ -1308,6 +1308,7 @@ static int usb_get_device_descriptor(int id)
 
 #define USB_BUFSIZE (128)
 static uint8_t usb_cfg_buffer[USB_BUFSIZE];
+STATIC_ASSERT(USB_BUFSIZE < (1 << (sizeof(uint16_t) * 8)));
 
 static int usb_get_configuration_descriptor(int id)
 {
@@ -1332,7 +1333,7 @@ static int usb_get_configuration_descriptor(int id)
                }
        }
        ((UsbConfigDesc *)usb_cfg_buffer)->wTotalLength =
-                                       usb_cpu_to_le16(p - usb_cfg_buffer);
+                       usb_cpu_to_le16((uint16_t)(p - usb_cfg_buffer));
        __usb_ep_write(CTRL_ENP_IN,
                        usb_cfg_buffer,
                        usb_size(p - usb_cfg_buffer,
index 3804fdce960b2f4942c18214580c1f9dc0680c4c..02448f2c398982cd247c8d9171e369b811c0c663 100644 (file)
 
 #include <cpu/byteorder.h>
 
-/*
- * Handle CPU endianess
- *
- * TODO: consider to move this stuff in compiler.h
- */
-#define usb_bswap16(x) (((x & 0xff) << 8) | (x >> 8))
-#define usb_bswap32(x) ((usb_bswap16(x & 0xffff) << 16) | usb_bswap16(x >> 16))
-
-#if CPU_BYTE_ORDER == CPU_LITTLE_ENDIAN
-#define usb_cpu_to_le16(x) (x)
-#define usb_le16_to_cpu(x) (x)
-#define usb_cpu_to_le32(x) (x)
-#define usb_le32_to_cpu(x) (x)
-#elif CPU_BYTE_ORDER == CPU_BIG_ENDIAN
-#define usb_cpu_to_le16(x) usb_bswap16(x)
-#define usb_le16_to_cpu(x) usb_bswap16(x)
-#define usb_cpu_to_le32(x) usb_bswap32(x)
-#define usb_le32_to_cpu(x) usb_bswap32(x)
-#else
-#error "unrecognized CPU endianness"
-#endif
+#define usb_cpu_to_le16(x)     cpu_to_le16(x)
+#define usb_le16_to_cpu(x)     le16_to_cpu(x)
+#define usb_cpu_to_le32(x)     cpu_to_le32(x)
+#define usb_le32_to_cpu(x)     le32_to_cpu(x)
 
 /* State of a USB device */
 enum usb_device_state {
index 89264c8e4c96fe5db3b1fa4ee1d8b1579ed2d8b0..69ad6417d3099eadaab86a397039b32cdbd36ef5 100644 (file)
@@ -155,11 +155,12 @@ static const usb_hid_descriptor_t usb_hid_descriptor =
 {
        .bLength = sizeof(usb_hid_descriptor),
        .bDescriptorType = HID_DT_HID,
-       .bcdHID = usb_cpu_to_le16(0x0110),
+       .bcdHID = usb_cpu_to_le16((uint16_t)0x0110),
        .bCountryCode = 0,
        .bNumDescriptors = 1,
        .bDescriptorHidType = HID_DT_REPORT,
-       .wDescriptorLength = usb_cpu_to_le16(sizeof(hid_report_descriptor)),
+       .wDescriptorLength =
+               usb_cpu_to_le16((uint16_t)sizeof(hid_report_descriptor)),
 };
 
 static const UsbEndpointDesc usb_hid_ep_descriptor =
@@ -168,7 +169,7 @@ static const UsbEndpointDesc usb_hid_ep_descriptor =
        .bDescriptorType = USB_DT_ENDPOINT,
        .bEndpointAddress = USB_HID_REPORT_EP,
        .bmAttributes = USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize = usb_cpu_to_le16(4),
+       .wMaxPacketSize = usb_cpu_to_le16((uint16_t)4),
        .bInterval = 10, /* resolution in ms */
 };
 
index 7ab6c7cdc08d2670d87b7ac64968f30326fe59dc..748ffc3ba6a3cdd02c15884f01a5079ca28cc9fe 100644 (file)
@@ -144,11 +144,12 @@ static const usb_hid_descriptor_t usb_hid_descriptor =
 {
        .bLength = sizeof(usb_hid_descriptor),
        .bDescriptorType = HID_DT_HID,
-       .bcdHID = usb_cpu_to_le16(0x0110),
+       .bcdHID = usb_cpu_to_le16((uint16_t)0x0110),
        .bCountryCode = 0,
        .bNumDescriptors = 1,
        .bDescriptorHidType = HID_DT_REPORT,
-       .wDescriptorLength = usb_cpu_to_le16(sizeof(hid_report_descriptor)),
+       .wDescriptorLength =
+               usb_cpu_to_le16((uint16_t)sizeof(hid_report_descriptor)),
 };
 
 static const UsbEndpointDesc usb_hid_ep_descriptor =
@@ -157,7 +158,7 @@ static const UsbEndpointDesc usb_hid_ep_descriptor =
        .bDescriptorType = USB_DT_ENDPOINT,
        .bEndpointAddress = USB_HID_REPORT_EP,
        .bmAttributes = USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize = usb_cpu_to_le16(4),
+       .wMaxPacketSize = usb_cpu_to_le16((uint16_t)4),
        .bInterval = 10, /* resolution in ms */
 };
 
index 0a57a7b6da04c5dd76c26a36838dc757cbcac2ed..be39fe69855c8d2da47037a1b1b27c3efa102a51 100644 (file)
@@ -114,7 +114,7 @@ static const UsbEndpointDesc usb_serial_ep_report_descriptor =
        .bDescriptorType = USB_DT_ENDPOINT,
        .bEndpointAddress = USB_DIR_IN | 1,
        .bmAttributes = USB_ENDPOINT_XFER_INT,
-       .wMaxPacketSize = usb_cpu_to_le16(8),
+       .wMaxPacketSize = usb_cpu_to_le16((uint16_t)8),
        .bInterval = 1,
 };
 
@@ -124,7 +124,7 @@ static const UsbEndpointDesc usb_serial_ep_in_descriptor =
        .bDescriptorType = USB_DT_ENDPOINT,
        .bEndpointAddress = USB_DIR_IN | 3,
        .bmAttributes = USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize = usb_cpu_to_le16(64),
+       .wMaxPacketSize = usb_cpu_to_le16((uint16_t)64),
        .bInterval = 0,
 };
 
@@ -134,7 +134,7 @@ static const UsbEndpointDesc usb_serial_ep_out_descriptor =
        .bDescriptorType = USB_DT_ENDPOINT,
        .bEndpointAddress = USB_DIR_OUT | 2,
        .bmAttributes = USB_ENDPOINT_XFER_BULK,
-       .wMaxPacketSize = usb_cpu_to_le16(64),
+       .wMaxPacketSize = usb_cpu_to_le16((uint16_t)64),
        .bInterval = 0,
 };