Browse Source

USB_STRING_DESC macro revised. USB_ARRAY_DESC macro added

Dmitry 9 năm trước cách đây
mục cha
commit
95bd4e8aab
1 tập tin đã thay đổi với 7 bổ sung2 xóa
  1. 7 2
      inc/usb_std.h

+ 7 - 2
inc/usb_std.h

@@ -19,6 +19,9 @@
 extern "C" {
 #endif
 
+#define __CAT(x,y) x ## y
+#define CAT(x,y) __CAT(x,y)
+
 /**\addtogroup USB_STD USB Standard
  * \brief This module contains generic USB device framework definitions
  * \details This module based on
@@ -34,8 +37,10 @@ extern "C" {
  */
 #define VERSION_BCD(maj, min, rev)  (((maj & 0xFF) << 8) | ((min & 0x0F) << 4) | (rev & 0x0F))
 
-/** Macro to create \ref usb_string_descriptor from array of characters */
-#define USB_STRING_DESC(...)        {.bLength = 2 + sizeof((uint16_t[]){__VA_ARGS__}), .bDescriptorType = USB_DTYPE_STRING, .wString = {__VA_ARGS__}}
+/** Macro to create \ref usb_string_descriptor from array */
+#define USB_ARRAY_DESC(...)        {.bLength = 2 + sizeof((uint16_t[]){__VA_ARGS__}), .bDescriptorType = USB_DTYPE_STRING, .wString = {__VA_ARGS__}}
+/** Macro to create \ref usb_string_descriptor from string */
+#define USB_STRING_DESC(s)         {.bLength = sizeof(CAT(u,s)), .bDescriptorType = USB_DTYPE_STRING, .wString = {CAT(u,s)}}
 
 /**\brief Macro to set мaximum power consumption field for the \ref usb_config_descriptor */
 #define USB_CFG_POWER_MA(mA)        ((mA) >> 1)