#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)
{
}
}
((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,
#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 {
{
.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 =
.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 */
};
{
.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 =
.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 */
};
.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,
};
.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,
};
.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,
};