mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-10 11:59:05 +02:00
Added some string descriptors.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -25,6 +25,8 @@
|
|||||||
|
|
||||||
#include "tusb.h"
|
#include "tusb.h"
|
||||||
#include "u2f_hid.h"
|
#include "u2f_hid.h"
|
||||||
|
#include "pico/unique_id.h"
|
||||||
|
#include "hsm_version.h"
|
||||||
|
|
||||||
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
|
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
|
||||||
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
|
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
|
||||||
@@ -49,7 +51,7 @@ tusb_desc_device_t const desc_device =
|
|||||||
|
|
||||||
.idVendor = 0xCafe,
|
.idVendor = 0xCafe,
|
||||||
.idProduct = 0x4231,
|
.idProduct = 0x4231,
|
||||||
.bcdDevice = 0x0100,
|
.bcdDevice = HSM_SDK_VERSION,
|
||||||
|
|
||||||
.iManufacturer = 0x01,
|
.iManufacturer = 0x01,
|
||||||
.iProduct = 0x02,
|
.iProduct = 0x02,
|
||||||
@@ -145,8 +147,8 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
|
|||||||
char const* string_desc_arr [] =
|
char const* string_desc_arr [] =
|
||||||
{
|
{
|
||||||
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||||
"TinyUSB", // 1: Manufacturer
|
"Pol Henarejos", // 1: Manufacturer
|
||||||
"TinyUSB Device", // 2: Product
|
"Pico HSM", // 2: Product
|
||||||
"123456", // 3: Serials, should use chip ID
|
"123456", // 3: Serials, should use chip ID
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -160,33 +162,37 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid)
|
|||||||
|
|
||||||
uint8_t chr_count;
|
uint8_t chr_count;
|
||||||
|
|
||||||
if ( index == 0)
|
if (index == 0) {
|
||||||
{
|
|
||||||
memcpy(&_desc_str[1], string_desc_arr[0], 2);
|
memcpy(&_desc_str[1], string_desc_arr[0], 2);
|
||||||
chr_count = 1;
|
chr_count = 1;
|
||||||
}else
|
}
|
||||||
{
|
else {
|
||||||
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
|
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
|
||||||
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
|
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
|
||||||
|
|
||||||
if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) ) return NULL;
|
if ( !(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0])) )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
const char* str = string_desc_arr[index];
|
const char* str = string_desc_arr[index];
|
||||||
|
char unique_id_str[2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1];
|
||||||
|
if (index == 3) {
|
||||||
|
pico_unique_board_id_t unique_id;
|
||||||
|
pico_get_unique_board_id(&unique_id);
|
||||||
|
pico_get_unique_board_id_string(unique_id_str, 2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1);
|
||||||
|
str = unique_id_str;
|
||||||
|
}
|
||||||
|
|
||||||
// Cap at max char
|
chr_count = strlen(str);
|
||||||
chr_count = (uint8_t) strlen(str);
|
if ( chr_count > 31 )
|
||||||
if ( chr_count > 31 ) chr_count = 31;
|
chr_count = 31;
|
||||||
|
|
||||||
// Convert ASCII string into UTF-16
|
// Convert ASCII string into UTF-16
|
||||||
for(uint8_t i=0; i<chr_count; i++)
|
for(uint8_t i=0; i<chr_count; i++) {
|
||||||
{
|
|
||||||
_desc_str[1+i] = str[i];
|
_desc_str[1+i] = str[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// first byte is length (including header), second byte is string type
|
_desc_str[0] = (TUSB_DESC_STRING << 8 ) | (2*chr_count + 2);
|
||||||
_desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8 ) | (2*chr_count + 2));
|
|
||||||
|
|
||||||
return _desc_str;
|
return _desc_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user