mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-06 10:40:49 +02:00
Added support for enable/disable Web CCID on the fly.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -364,7 +364,9 @@ pico_unique_board_id_t pico_serial;
|
|||||||
#include "tinyusb.h"
|
#include "tinyusb.h"
|
||||||
#include "esp_efuse.h"
|
#include "esp_efuse.h"
|
||||||
#define pico_get_unique_board_id(a) do { uint32_t value; esp_efuse_read_block(EFUSE_BLK1, &value, 0, 32); memcpy((uint8_t *)(a), &value, sizeof(uint32_t)); esp_efuse_read_block(EFUSE_BLK1, &value, 32, 32); memcpy((uint8_t *)(a)+4, &value, sizeof(uint32_t)); } while(0)
|
#define pico_get_unique_board_id(a) do { uint32_t value; esp_efuse_read_block(EFUSE_BLK1, &value, 0, 32); memcpy((uint8_t *)(a), &value, sizeof(uint32_t)); esp_efuse_read_block(EFUSE_BLK1, &value, 32, 32); memcpy((uint8_t *)(a)+4, &value, sizeof(uint32_t)); } while(0)
|
||||||
extern const tinyusb_config_t tusb_cfg;
|
extern tinyusb_config_t tusb_cfg;
|
||||||
|
extern bool enable_wcid;
|
||||||
|
extern const uint8_t desc_config[];
|
||||||
TaskHandle_t hcore0 = NULL, hcore1 = NULL;
|
TaskHandle_t hcore0 = NULL, hcore1 = NULL;
|
||||||
int app_main() {
|
int app_main() {
|
||||||
#else
|
#else
|
||||||
@@ -417,6 +419,9 @@ int main(void) {
|
|||||||
usb_init();
|
usb_init();
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
tusb_cfg.string_descriptor[3] = pico_serial_str;
|
tusb_cfg.string_descriptor[3] = pico_serial_str;
|
||||||
|
if (enable_wcid) {
|
||||||
|
tusb_cfg.configuration_descriptor = desc_config;
|
||||||
|
}
|
||||||
tinyusb_driver_install(&tusb_cfg);
|
tinyusb_driver_install(&tusb_cfg);
|
||||||
#else
|
#else
|
||||||
tusb_init();
|
tusb_init();
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ queue_t card_to_usb_q;
|
|||||||
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
extern tusb_desc_device_t desc_device;
|
extern tusb_desc_device_t desc_device;
|
||||||
bool enable_wcid = false;
|
extern bool enable_wcid;
|
||||||
#endif
|
#endif
|
||||||
void usb_init() {
|
void usb_init() {
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
|
|||||||
@@ -40,6 +40,8 @@
|
|||||||
|
|
||||||
#define MAX_USB_POWER 1
|
#define MAX_USB_POWER 1
|
||||||
|
|
||||||
|
bool enable_wcid = false;
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Device Descriptors
|
// Device Descriptors
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@@ -80,12 +82,18 @@ uint8_t const *tud_descriptor_device_cb(void) {
|
|||||||
#define TUSB_SMARTCARD_WCID_DESC_LEN (TUD_INTERFACE_DESC_LEN + TUSB_SMARTCARD_LEN + 2 * TUD_ENDPOINT_DESC_LEN)
|
#define TUSB_SMARTCARD_WCID_DESC_LEN (TUD_INTERFACE_DESC_LEN + TUSB_SMARTCARD_LEN + 2 * TUD_ENDPOINT_DESC_LEN)
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TUSB_DESC_TOTAL_LEN = TUD_CONFIG_DESC_LEN
|
TUSB_DESC_TOTAL_LEN_NOWCID = TUD_CONFIG_DESC_LEN
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
+ TUD_HID_INOUT_DESC_LEN + TUD_HID_DESC_LEN
|
+ TUD_HID_INOUT_DESC_LEN + TUD_HID_DESC_LEN
|
||||||
#endif
|
#endif
|
||||||
#ifdef USB_ITF_CCID
|
#ifdef USB_ITF_CCID
|
||||||
+ TUSB_SMARTCARD_CCID_DESC_LEN
|
+ TUSB_SMARTCARD_CCID_DESC_LEN
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
enum {
|
||||||
|
TUSB_DESC_TOTAL_LEN = TUSB_DESC_TOTAL_LEN_NOWCID
|
||||||
|
#ifdef USB_ITF_CCID
|
||||||
#ifdef USB_ITF_WCID
|
#ifdef USB_ITF_WCID
|
||||||
+ TUSB_SMARTCARD_WCID_DESC_LEN
|
+ TUSB_SMARTCARD_WCID_DESC_LEN
|
||||||
#endif
|
#endif
|
||||||
@@ -118,6 +126,17 @@ uint8_t const desc_hid_report_kb[] = {
|
|||||||
7, TUSB_DESC_ENDPOINT, _epint, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), 0
|
7, TUSB_DESC_ENDPOINT, _epint, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const uint8_t desc_config_nowcid[] = {
|
||||||
|
TUD_CONFIG_DESCRIPTOR(1, ITF_TOTAL-1, 4, TUSB_DESC_TOTAL_LEN_NOWCID, USB_CONFIG_ATT_ONE | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
||||||
|
#ifdef USB_ITF_HID
|
||||||
|
TUD_HID_INOUT_DESCRIPTOR(ITF_HID, ITF_HID + 5, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, TUSB_DIR_IN_MASK | EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10),
|
||||||
|
TUD_HID_DESCRIPTOR(ITF_KEYBOARD, ITF_KEYBOARD + 5, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report_kb), TUSB_DIR_IN_MASK | (EPNUM_HID + 1), 16, 5),
|
||||||
|
#endif
|
||||||
|
#ifdef USB_ITF_CCID
|
||||||
|
TUD_SMARTCARD_DESCRIPTOR(ITF_CCID, ITF_CCID+5, 1, TUSB_DIR_IN_MASK | 1, TUSB_DIR_IN_MASK | 2, 64),
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
const uint8_t desc_config[] = {
|
const uint8_t desc_config[] = {
|
||||||
TUD_CONFIG_DESCRIPTOR(1, ITF_TOTAL, 4, TUSB_DESC_TOTAL_LEN, USB_CONFIG_ATT_ONE | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
TUD_CONFIG_DESCRIPTOR(1, ITF_TOTAL, 4, TUSB_DESC_TOTAL_LEN, USB_CONFIG_ATT_ONE | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
@@ -149,8 +168,10 @@ uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) {
|
|||||||
#ifndef ESP_PLATFORM
|
#ifndef ESP_PLATFORM
|
||||||
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
|
(void) index; // for multiple configurations
|
||||||
printf("tud_descriptor_configuration_cb %d\n",index);
|
if (enable_wcid) {
|
||||||
return desc_config;
|
return desc_config;
|
||||||
|
}
|
||||||
|
return desc_config_nowcid;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -254,7 +275,10 @@ uint8_t const desc_bos[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
uint8_t const *tud_descriptor_bos_cb(void) {
|
uint8_t const *tud_descriptor_bos_cb(void) {
|
||||||
return desc_bos;
|
if (enable_wcid) {
|
||||||
|
return desc_bos;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@@ -281,12 +305,12 @@ char const *string_desc_arr [] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#ifdef ESP_PLATFORM
|
#ifdef ESP_PLATFORM
|
||||||
const tinyusb_config_t tusb_cfg = {
|
tinyusb_config_t tusb_cfg = {
|
||||||
.device_descriptor = &desc_device,
|
.device_descriptor = &desc_device,
|
||||||
.string_descriptor = string_desc_arr,
|
.string_descriptor = string_desc_arr,
|
||||||
.string_descriptor_count = sizeof(string_desc_arr) / sizeof(string_desc_arr[0]),
|
.string_descriptor_count = sizeof(string_desc_arr) / sizeof(string_desc_arr[0]),
|
||||||
.external_phy = false,
|
.external_phy = false,
|
||||||
.configuration_descriptor = desc_config,
|
.configuration_descriptor = desc_config_nowcid,
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
static uint16_t _desc_str[32];
|
static uint16_t _desc_str[32];
|
||||||
|
|||||||
Reference in New Issue
Block a user