Skip to content

Commit

Permalink
shared/tinyusb: Allow max USB descriptor string to be configured.
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <[email protected]>
  • Loading branch information
dpgeorge committed Apr 4, 2023
1 parent 0a3600a commit 783ddfc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ports/rp2/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion shared/tinyusb/mp_usbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions shared/tinyusb/mp_usbd_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions shared/tinyusb/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 783ddfc

Please sign in to comment.