mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-05-28 17:11:23 +02:00
@@ -38,8 +38,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// Device Descriptors
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_desc_device_t const desc_device =
|
||||
{
|
||||
tusb_desc_device_t const desc_device = {
|
||||
.bLength = sizeof(tusb_desc_device_t),
|
||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||
.bcdUSB = (USB_BCD),
|
||||
@@ -60,8 +59,7 @@ tusb_desc_device_t const desc_device =
|
||||
.bNumConfigurations = 1
|
||||
};
|
||||
|
||||
uint8_t const *tud_descriptor_device_cb(void)
|
||||
{
|
||||
uint8_t const *tud_descriptor_device_cb(void) {
|
||||
return (uint8_t const *) &desc_device;
|
||||
}
|
||||
|
||||
@@ -70,14 +68,13 @@ uint8_t const *tud_descriptor_device_cb(void)
|
||||
// Configuration Descriptor
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
tusb_desc_configuration_t const desc_config =
|
||||
{
|
||||
tusb_desc_configuration_t const desc_config = {
|
||||
.bLength = sizeof(tusb_desc_configuration_t),
|
||||
.bDescriptorType = TUSB_DESC_CONFIGURATION,
|
||||
.wTotalLength = (sizeof(tusb_desc_configuration_t)
|
||||
#ifdef USB_ITF_CCID
|
||||
+ sizeof(tusb_desc_interface_t) + sizeof(struct ccid_class_descriptor) +
|
||||
2*sizeof(tusb_desc_endpoint_t)
|
||||
2 * sizeof(tusb_desc_endpoint_t)
|
||||
#endif
|
||||
#ifdef USB_ITF_HID
|
||||
+ TUD_HID_INOUT_DESC_LEN + TUD_HID_DESC_LEN
|
||||
@@ -87,7 +84,7 @@ tusb_desc_configuration_t const desc_config =
|
||||
.bConfigurationValue = 1,
|
||||
.iConfiguration = 4,
|
||||
.bmAttributes = USB_CONFIG_ATT_ONE | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP,
|
||||
.bMaxPower = TUSB_DESC_CONFIG_POWER_MA(MAX_USB_POWER+1),
|
||||
.bMaxPower = TUSB_DESC_CONFIG_POWER_MA(MAX_USB_POWER + 1),
|
||||
};
|
||||
|
||||
#ifdef USB_ITF_CCID
|
||||
@@ -98,7 +95,7 @@ static const struct ccid_class_descriptor desc_ccid = {
|
||||
.bMaxSlotIndex = 0,
|
||||
.bVoltageSupport = 0x01, // 5.0V
|
||||
.dwProtocols = (
|
||||
0x01| // T=0
|
||||
0x01 | // T=0
|
||||
0x02), // T=1
|
||||
.dwDefaultClock = (0xDFC),
|
||||
.dwMaximumClock = (0xDFC),
|
||||
@@ -110,7 +107,7 @@ static const struct ccid_class_descriptor desc_ccid = {
|
||||
.dwSynchProtocols = (0),
|
||||
.dwMechanical = (0),
|
||||
.dwFeatures = 0x40840, //USB-ICC, short & extended APDU
|
||||
.dwMaxCCIDMessageLength = 65544+10,
|
||||
.dwMaxCCIDMessageLength = 65544 + 10,
|
||||
.bClassGetResponse = 0xFF,
|
||||
.bclassEnvelope = 0xFF,
|
||||
.wLcdLayout = 0x0,
|
||||
@@ -118,8 +115,7 @@ static const struct ccid_class_descriptor desc_ccid = {
|
||||
.bMaxCCIDBusySlots = 0x01,
|
||||
};
|
||||
|
||||
tusb_desc_interface_t const desc_interface =
|
||||
{
|
||||
tusb_desc_interface_t const desc_interface = {
|
||||
.bLength = sizeof(tusb_desc_interface_t),
|
||||
.bDescriptorType = TUSB_DESC_INTERFACE,
|
||||
.bInterfaceNumber = ITF_CCID,
|
||||
@@ -128,11 +124,10 @@ tusb_desc_interface_t const desc_interface =
|
||||
.bInterfaceClass = TUSB_CLASS_SMART_CARD,
|
||||
.bInterfaceSubClass = 0,
|
||||
.bInterfaceProtocol = 0,
|
||||
.iInterface = ITF_CCID+5,
|
||||
.iInterface = ITF_CCID + 5,
|
||||
};
|
||||
|
||||
tusb_desc_endpoint_t const desc_ep1 =
|
||||
{
|
||||
tusb_desc_endpoint_t const desc_ep1 = {
|
||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||
.bEndpointAddress = TUSB_DIR_IN_MASK | 1,
|
||||
@@ -141,8 +136,7 @@ tusb_desc_endpoint_t const desc_ep1 =
|
||||
.bInterval = 0
|
||||
};
|
||||
|
||||
tusb_desc_endpoint_t const desc_ep2 =
|
||||
{
|
||||
tusb_desc_endpoint_t const desc_ep2 = {
|
||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||
.bEndpointAddress = 2,
|
||||
@@ -155,7 +149,7 @@ tusb_desc_endpoint_t const desc_ep2 =
|
||||
static uint8_t desc_config_extended[sizeof(tusb_desc_configuration_t)
|
||||
#ifdef USB_ITF_CCID
|
||||
+ sizeof(tusb_desc_interface_t) +
|
||||
sizeof(struct ccid_class_descriptor) + 2*
|
||||
sizeof(struct ccid_class_descriptor) + 2 *
|
||||
sizeof(tusb_desc_endpoint_t)
|
||||
#endif
|
||||
#ifdef USB_ITF_HID
|
||||
@@ -194,19 +188,17 @@ enum {
|
||||
HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \
|
||||
HID_COLLECTION_END \
|
||||
|
||||
uint8_t const desc_hid_report[] =
|
||||
{
|
||||
uint8_t const desc_hid_report[] = {
|
||||
TUD_HID_REPORT_DESC_FIDO_U2F(CFG_TUD_HID_EP_BUFSIZE)
|
||||
};
|
||||
uint8_t const desc_hid_report_kb[] =
|
||||
{
|
||||
uint8_t const desc_hid_report_kb[] = {
|
||||
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID_KEYBOARD))
|
||||
};
|
||||
#define EPNUM_HID 0x03
|
||||
|
||||
static uint8_t desc_hid[] = {
|
||||
TUD_HID_INOUT_DESCRIPTOR(ITF_HID,
|
||||
ITF_HID+5,
|
||||
ITF_HID + 5,
|
||||
HID_ITF_PROTOCOL_NONE,
|
||||
sizeof(desc_hid_report),
|
||||
EPNUM_HID,
|
||||
@@ -216,24 +208,23 @@ static uint8_t desc_hid[] = {
|
||||
};
|
||||
|
||||
static uint8_t desc_hid_kb[] = {
|
||||
TUD_HID_DESCRIPTOR(ITF_KEYBOARD, ITF_KEYBOARD+5, HID_ITF_PROTOCOL_NONE,
|
||||
sizeof(desc_hid_report_kb), 0x80 | (EPNUM_HID+1), 16, 5)
|
||||
TUD_HID_DESCRIPTOR(ITF_KEYBOARD, ITF_KEYBOARD + 5, HID_ITF_PROTOCOL_NONE,
|
||||
sizeof(desc_hid_report_kb), 0x80 | (EPNUM_HID + 1), 16, 5)
|
||||
};
|
||||
|
||||
uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf)
|
||||
{
|
||||
uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) {
|
||||
printf("report_cb %d\n", itf);
|
||||
if (itf == ITF_HID) {
|
||||
return desc_hid_report;
|
||||
} else if (itf == ITF_KEYBOARD) {
|
||||
}
|
||||
else if (itf == ITF_KEYBOARD) {
|
||||
return desc_hid_report_kb;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint8_t const *tud_descriptor_configuration_cb(uint8_t index)
|
||||
{
|
||||
uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
|
||||
(void) index; // for multiple configurations
|
||||
|
||||
static uint8_t initd = 0;
|
||||
@@ -262,14 +253,12 @@ uint8_t const *tud_descriptor_configuration_cb(uint8_t index)
|
||||
|
||||
#define MS_OS_20_DESC_LEN 0xB2
|
||||
|
||||
uint8_t const desc_bos[] =
|
||||
{
|
||||
uint8_t const desc_bos[] = {
|
||||
// total length, number of device caps
|
||||
TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2)
|
||||
};
|
||||
|
||||
uint8_t const *tud_descriptor_bos_cb(void)
|
||||
{
|
||||
uint8_t const *tud_descriptor_bos_cb(void) {
|
||||
return desc_bos;
|
||||
}
|
||||
|
||||
@@ -278,8 +267,7 @@ uint8_t const *tud_descriptor_bos_cb(void)
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// array of pointer to string descriptors
|
||||
char const *string_desc_arr [] =
|
||||
{
|
||||
char const *string_desc_arr [] = {
|
||||
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||
"Pol Henarejos", // 1: Manufacturer
|
||||
"Pico Key", // 2: Product
|
||||
@@ -296,8 +284,7 @@ char const *string_desc_arr [] =
|
||||
|
||||
static uint16_t _desc_str[32];
|
||||
|
||||
uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid)
|
||||
{
|
||||
uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
|
||||
(void) langid;
|
||||
|
||||
uint8_t chr_count;
|
||||
@@ -305,11 +292,12 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid)
|
||||
if (index == 0) {
|
||||
memcpy(&_desc_str[1], string_desc_arr[0], 2);
|
||||
chr_count = 1;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// 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
|
||||
|
||||
if (!(index < sizeof(string_desc_arr)/sizeof(string_desc_arr[0]))) {
|
||||
if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -329,11 +317,11 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid)
|
||||
|
||||
// Convert ASCII string into UTF-16
|
||||
for (uint8_t i = 0; i < chr_count; i++) {
|
||||
_desc_str[1+i] = str[i];
|
||||
_desc_str[1 + i] = str[i];
|
||||
}
|
||||
}
|
||||
|
||||
_desc_str[0] = (TUSB_DESC_STRING << 8) | (2*chr_count + 2);
|
||||
_desc_str[0] = (TUSB_DESC_STRING << 8) | (2 * chr_count + 2);
|
||||
|
||||
return _desc_str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user