Skip to content

Commit 0e127e6

Browse files
jfischer-nokartben
authored andcommitted
usb: device_next: add the missing const qualifier and save some RAM
In the USBD_DESC_STRING_DEFINE macro defenition the const qualifier is missing. Also, do not reserve room for the UTF16LE conversion, as this is done on the fly in the stack. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
1 parent 357434e commit 0e127e6

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

include/zephyr/usb/usbd.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ extern "C" {
4343
/* Maximum bulk max packet size the stack supports */
4444
#define USBD_MAX_BULK_MPS COND_CODE_1(USBD_SUPPORTS_HIGH_SPEED, (512), (64))
4545

46-
/*
47-
* The USB Unicode bString is encoded in UTF16LE, which means it takes up
48-
* twice the amount of bytes than the same string encoded in ASCII7.
49-
* Use this macro to determine the length of the bString array.
50-
*
51-
* bString length without null character:
52-
* bString_length = (sizeof(initializer_string) - 1) * 2
53-
* or:
54-
* bString_length = sizeof(initializer_string) * 2 - 2
55-
*/
56-
#define USB_BSTRING_LENGTH(s) (sizeof(s) * 2 - 2)
57-
5846
/*
5947
* The length of the string descriptor (bLength) is calculated from the
6048
* size of the two octets bLength and bDescriptorType plus the
@@ -574,7 +562,7 @@ static inline void *usbd_class_get_private(const struct usbd_class_data *const c
574562
* @param name Language string descriptor node identifier.
575563
*/
576564
#define USBD_DESC_LANG_DEFINE(name) \
577-
static uint16_t langid_##name = sys_cpu_to_le16(0x0409); \
565+
static const uint16_t langid_##name = sys_cpu_to_le16(0x0409); \
578566
static struct usbd_desc_node name = { \
579567
.str = { \
580568
.idx = 0, \
@@ -597,7 +585,7 @@ static inline void *usbd_class_get_private(const struct usbd_class_data *const c
597585
* @param d_utype String descriptor usage type
598586
*/
599587
#define USBD_DESC_STRING_DEFINE(d_name, d_string, d_utype) \
600-
static uint8_t ascii_##d_name[USB_BSTRING_LENGTH(d_string)] = d_string; \
588+
static const uint8_t ascii_##d_name[sizeof(d_string)] = d_string; \
601589
static struct usbd_desc_node d_name = { \
602590
.str = { \
603591
.utype = d_utype, \

0 commit comments

Comments
 (0)