aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2023-04-04 11:57:25 +1000
committerDamien George <damien@micropython.org>2023-04-04 11:57:25 +1000
commit783ddfc264c8c36253a4279ef501f02f8cac1200 (patch)
tree9e482f440ff6aa12883f7cca6e559fffe48ec4f1
parent0a3600a9ade773e54cbd70e93a671ec089c3b0fe (diff)
shared/tinyusb: Allow max USB descriptor string to be configured.
Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/rp2/usbd.c2
-rw-r--r--shared/tinyusb/mp_usbd.h2
-rw-r--r--shared/tinyusb/mp_usbd_descriptor.c6
-rw-r--r--shared/tinyusb/tusb_config.h7
4 files changed, 9 insertions, 8 deletions
diff --git a/ports/rp2/usbd.c b/ports/rp2/usbd.c
index e51cef0ff..568b62841 100644
--- a/ports/rp2/usbd.c
+++ b/ports/rp2/usbd.c
@@ -38,7 +38,7 @@ void mp_usbd_port_get_serial_number(char *serial_buf) {
pico_get_unique_board_id(&id);
// convert to hex
int hexlen = sizeof(id.id) * 2;
- MP_STATIC_ASSERT(hexlen <= USBD_DESC_STR_MAX);
+ MP_STATIC_ASSERT(hexlen <= MICROPY_HW_USB_DESC_STR_MAX);
for (int i = 0; i < hexlen; i += 2) {
static const char *hexdig = "0123456789abcdef";
serial_buf[i] = hexdig[id.id[i / 2] >> 4];
diff --git a/shared/tinyusb/mp_usbd.h b/shared/tinyusb/mp_usbd.h
index a118bc34d..3a93b929c 100644
--- a/shared/tinyusb/mp_usbd.h
+++ b/shared/tinyusb/mp_usbd.h
@@ -33,7 +33,7 @@
void mp_usbd_task(void);
// Function to be implemented in port code.
-// Can write a string up to USBD_DESC_STR_MAX characters long, plus terminating byte.
+// Can write a string up to MICROPY_HW_USB_DESC_STR_MAX characters long, plus terminating byte.
extern void mp_usbd_port_get_serial_number(char *buf);
#endif // MICROPY_INCLUDED_SHARED_TINYUSB_USBD_H
diff --git a/shared/tinyusb/mp_usbd_descriptor.c b/shared/tinyusb/mp_usbd_descriptor.c
index c6d205c92..8fab599b6 100644
--- a/shared/tinyusb/mp_usbd_descriptor.c
+++ b/shared/tinyusb/mp_usbd_descriptor.c
@@ -67,8 +67,8 @@ const uint8_t mp_usbd_desc_cfg_static[USBD_STATIC_DESC_LEN] = {
};
const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
- char serial_buf[USBD_DESC_STR_MAX + 1]; // Includes terminating NUL byte
- static uint16_t desc_wstr[USBD_DESC_STR_MAX + 1]; // Includes prefix uint16_t
+ char serial_buf[MICROPY_HW_USB_DESC_STR_MAX + 1]; // Includes terminating NUL byte
+ static uint16_t desc_wstr[MICROPY_HW_USB_DESC_STR_MAX + 1]; // Includes prefix uint16_t
const char *desc_str;
uint16_t desc_len;
@@ -109,7 +109,7 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Convert from narrow string to wide string
desc_len = 2;
- for (int i = 0; i < USBD_DESC_STR_MAX && desc_str[i] != 0; i++) {
+ for (int i = 0; i < MICROPY_HW_USB_DESC_STR_MAX && desc_str[i] != 0; i++) {
desc_wstr[1 + i] = desc_str[i];
desc_len += 2;
}
diff --git a/shared/tinyusb/tusb_config.h b/shared/tinyusb/tusb_config.h
index 23dbd14a5..a6410a1c9 100644
--- a/shared/tinyusb/tusb_config.h
+++ b/shared/tinyusb/tusb_config.h
@@ -27,8 +27,7 @@
#ifndef MICROPY_INCLUDED_SHARED_TINYUSB_TUSB_CONFIG_H
#define MICROPY_INCLUDED_SHARED_TINYUSB_TUSB_CONFIG_H
-#include <py/mpconfig.h>
-#include "mpconfigport.h"
+#include "py/mpconfig.h"
#if MICROPY_HW_ENABLE_USBDEV
@@ -90,7 +89,9 @@
#define USBD_MAX_POWER_MA (250)
-#define USBD_DESC_STR_MAX (20)
+#ifndef MICROPY_HW_USB_DESC_STR_MAX
+#define MICROPY_HW_USB_DESC_STR_MAX (20)
+#endif
#if CFG_TUD_CDC
#define USBD_ITF_CDC (0) // needs 2 interfaces