summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2022-01-12 14:24:15 +0100
committerDamien George <damien@micropython.org>2022-01-27 17:05:34 +1100
commitb73073d2460f14cbe7501e99b882520e0456ec94 (patch)
treeb2fcb46c2531290315c2e86ebc81c45a66ef1ef8
parent30380962cff1a42dabbbdf172b951f21b5bffe14 (diff)
mimxrt: Add USB ID elements.
- Manufacturer, set by MICROPY_HW_USB_STR_MANUF; default "MicroPython" - Board name, as set by MICROPY_HW_BOARD_NAME - Unique-ID, same as returned by machine.unique_id() - USB Vendor ID, as set by MICROPY_HW_USB_VID; default 0xf055 - USB Product ID, as set by MICROPY_HW_USB_PID; default 0x9802
-rw-r--r--ports/mimxrt/tusb_port.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/ports/mimxrt/tusb_port.c b/ports/mimxrt/tusb_port.c
index 128861a49..55855674c 100644
--- a/ports/mimxrt/tusb_port.c
+++ b/ports/mimxrt/tusb_port.c
@@ -25,12 +25,20 @@
*/
#include "tusb.h"
+#include "mphalport.h"
#ifndef MICROPY_HW_USB_VID
#define MICROPY_HW_USB_VID (0xf055)
+#endif
+
+#ifndef MICROPY_HW_USB_PID
#define MICROPY_HW_USB_PID (0x9802)
#endif
+#ifndef MICROPY_HW_USB_STR_MANUF
+#define MICROPY_HW_USB_STR_MANUF ("MicroPython")
+#endif
+
#define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
#define USBD_MAX_POWER_MA (250)
@@ -77,9 +85,9 @@ static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = {
};
static const char *const usbd_desc_str[] = {
- [USBD_STR_MANUF] = "MicroPython",
- [USBD_STR_PRODUCT] = "Board in FS mode", // Todo: fix string to indicate that product is running in High Speed mode
- [USBD_STR_SERIAL] = "000000000000", // TODO
+ [USBD_STR_MANUF] = MICROPY_HW_USB_STR_MANUF,
+ [USBD_STR_PRODUCT] = MICROPY_HW_BOARD_NAME,
+ [USBD_STR_SERIAL] = "00000000000000000000",
[USBD_STR_CDC] = "Board CDC",
};
@@ -95,6 +103,9 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
#define DESC_STR_MAX (20)
static uint16_t desc_str[DESC_STR_MAX];
+ static const char hexchr[16] = "0123456789ABCDEF";
+
+ memset(desc_str, 0, sizeof(desc_str));
uint8_t len;
if (index == 0) {
@@ -104,9 +115,19 @@ const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
if (index >= sizeof(usbd_desc_str) / sizeof(usbd_desc_str[0])) {
return NULL;
}
- const char *str = usbd_desc_str[index];
- for (len = 0; len < DESC_STR_MAX - 1 && str[len]; ++len) {
- desc_str[1 + len] = str[len];
+ if (index == USBD_STR_SERIAL) {
+ uint8_t uid[8];
+ mp_hal_get_unique_id(uid);
+ // store it as a hex string
+ for (len = 0; len < 16; len += 2) {
+ desc_str[1 + len] = hexchr[uid[len / 2] >> 4];
+ desc_str[1 + len + 1] = hexchr[uid[len / 2] & 0x0f];
+ }
+ } else {
+ const char *str = usbd_desc_str[index];
+ for (len = 0; len < DESC_STR_MAX - 1 && str[len]; ++len) {
+ desc_str[1 + len] = str[len];
+ }
}
}