shared/tinyusb: Allow max USB descriptor string to be configured.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
0a3600a9ad
commit
783ddfc264
@ -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];
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user