mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-09 03:23:42 +02:00
@@ -39,16 +39,13 @@ extern bool wait_button();
|
|||||||
|
|
||||||
extern void low_flash_init_core1();
|
extern void low_flash_init_core1();
|
||||||
|
|
||||||
static inline const uint16_t make_uint16_t(uint8_t b1, uint8_t b2)
|
static inline const uint16_t make_uint16_t(uint8_t b1, uint8_t b2) {
|
||||||
{
|
|
||||||
return (b1 << 8) | b2;
|
return (b1 << 8) | b2;
|
||||||
}
|
}
|
||||||
static inline const uint16_t get_uint16_t(const uint8_t *b, uint16_t offset)
|
static inline const uint16_t get_uint16_t(const uint8_t *b, uint16_t offset) {
|
||||||
{
|
|
||||||
return make_uint16_t(b[offset], b[offset + 1]);
|
return make_uint16_t(b[offset], b[offset + 1]);
|
||||||
}
|
}
|
||||||
static inline void put_uint16_t(uint16_t n, uint8_t *b)
|
static inline void put_uint16_t(uint16_t n, uint8_t *b) {
|
||||||
{
|
|
||||||
*b++ = (n >> 8) & 0xff;
|
*b++ = (n >> 8) & 0xff;
|
||||||
*b = n & 0xff;
|
*b = n & 0xff;
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/main.c
36
src/main.c
@@ -62,8 +62,7 @@ app_t *current_app = NULL;
|
|||||||
|
|
||||||
const uint8_t *ccid_atr = NULL;
|
const uint8_t *ccid_atr = NULL;
|
||||||
|
|
||||||
int register_app(app_t *(*select_aid)(app_t *, const uint8_t *, uint8_t))
|
int register_app(app_t *(*select_aid)(app_t *, const uint8_t *, uint8_t)) {
|
||||||
{
|
|
||||||
if (num_apps < sizeof(apps) / sizeof(app_t)) {
|
if (num_apps < sizeof(apps) / sizeof(app_t)) {
|
||||||
apps[num_apps].select_aid = select_aid;
|
apps[num_apps].select_aid = select_aid;
|
||||||
num_apps++;
|
num_apps++;
|
||||||
@@ -74,19 +73,16 @@ int register_app(app_t *(*select_aid)(app_t *, const uint8_t *, uint8_t))
|
|||||||
|
|
||||||
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
|
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
|
||||||
|
|
||||||
void led_set_blink(uint32_t mode)
|
void led_set_blink(uint32_t mode) {
|
||||||
{
|
|
||||||
blink_interval_ms = mode;
|
blink_interval_ms = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t timeout = 0;
|
uint32_t timeout = 0;
|
||||||
void timeout_stop()
|
void timeout_stop() {
|
||||||
{
|
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void timeout_start()
|
void timeout_start() {
|
||||||
{
|
|
||||||
timeout = board_millis();
|
timeout = board_millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,8 +90,7 @@ void execute_tasks();
|
|||||||
|
|
||||||
static bool req_button_pending = false;
|
static bool req_button_pending = false;
|
||||||
|
|
||||||
bool is_req_button_pending()
|
bool is_req_button_pending() {
|
||||||
{
|
|
||||||
return req_button_pending;
|
return req_button_pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,16 +98,14 @@ uint32_t button_timeout = 15000;
|
|||||||
bool cancel_button = false;
|
bool cancel_button = false;
|
||||||
|
|
||||||
#ifdef ENABLE_EMULATION
|
#ifdef ENABLE_EMULATION
|
||||||
uint32_t board_millis()
|
uint32_t board_millis() {
|
||||||
{
|
|
||||||
struct timeval start;
|
struct timeval start;
|
||||||
gettimeofday(&start, NULL);
|
gettimeofday(&start, NULL);
|
||||||
return start.tv_sec * 1000 + start.tv_usec / 1000;
|
return start.tv_sec * 1000 + start.tv_usec / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
bool wait_button()
|
bool wait_button() {
|
||||||
{
|
|
||||||
uint32_t start_button = board_millis();
|
uint32_t start_button = board_millis();
|
||||||
bool timeout = false;
|
bool timeout = false;
|
||||||
cancel_button = false;
|
cancel_button = false;
|
||||||
@@ -144,8 +137,7 @@ bool wait_button()
|
|||||||
|
|
||||||
struct apdu apdu;
|
struct apdu apdu;
|
||||||
|
|
||||||
void led_blinking_task()
|
void led_blinking_task() {
|
||||||
{
|
|
||||||
#ifdef PICO_DEFAULT_LED_PIN
|
#ifdef PICO_DEFAULT_LED_PIN
|
||||||
static uint32_t start_ms = 0;
|
static uint32_t start_ms = 0;
|
||||||
static uint8_t led_state = false;
|
static uint8_t led_state = false;
|
||||||
@@ -168,8 +160,7 @@ void led_blinking_task()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_off_all()
|
void led_off_all() {
|
||||||
{
|
|
||||||
#ifdef PIMORONI_TINY2040
|
#ifdef PIMORONI_TINY2040
|
||||||
gpio_put(TINY2040_LED_R_PIN, 1);
|
gpio_put(TINY2040_LED_R_PIN, 1);
|
||||||
gpio_put(TINY2040_LED_G_PIN, 1);
|
gpio_put(TINY2040_LED_G_PIN, 1);
|
||||||
@@ -181,8 +172,7 @@ void led_off_all()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_rtc()
|
void init_rtc() {
|
||||||
{
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
rtc_init();
|
rtc_init();
|
||||||
datetime_t dt = {
|
datetime_t dt = {
|
||||||
@@ -201,8 +191,7 @@ void init_rtc()
|
|||||||
extern void neug_task();
|
extern void neug_task();
|
||||||
extern void usb_task();
|
extern void usb_task();
|
||||||
|
|
||||||
void execute_tasks()
|
void execute_tasks() {
|
||||||
{
|
|
||||||
usb_task();
|
usb_task();
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
tud_task(); // tinyusb device task
|
tud_task(); // tinyusb device task
|
||||||
@@ -210,8 +199,7 @@ void execute_tasks()
|
|||||||
led_blinking_task();
|
led_blinking_task();
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void) {
|
||||||
{
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
usb_init();
|
usb_init();
|
||||||
|
|
||||||
|
|||||||
@@ -39,13 +39,11 @@ static uint16_t w_len[ITF_TOTAL] = { 0 }, tx_r_offset[ITF_TOTAL] = { 0 };
|
|||||||
static uint32_t timeout_counter[ITF_TOTAL] = { 0 };
|
static uint32_t timeout_counter[ITF_TOTAL] = { 0 };
|
||||||
uint8_t card_locked_itf = ITF_TOTAL; // no locked
|
uint8_t card_locked_itf = ITF_TOTAL; // no locked
|
||||||
|
|
||||||
void usb_set_timeout_counter(uint8_t itf, uint32_t v)
|
void usb_set_timeout_counter(uint8_t itf, uint32_t v) {
|
||||||
{
|
|
||||||
timeout_counter[itf] = v;
|
timeout_counter[itf] = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t usb_write_offset(uint8_t itf, uint16_t len, uint16_t offset)
|
uint32_t usb_write_offset(uint8_t itf, uint16_t len, uint16_t offset) {
|
||||||
{
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
uint8_t pkt_max = 64;
|
uint8_t pkt_max = 64;
|
||||||
#endif
|
#endif
|
||||||
@@ -75,8 +73,7 @@ uint32_t usb_write_offset(uint8_t itf, uint16_t len, uint16_t offset)
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t usb_rx(uint8_t itf, const uint8_t *buffer, size_t len)
|
size_t usb_rx(uint8_t itf, const uint8_t *buffer, size_t len) {
|
||||||
{
|
|
||||||
uint16_t size = MIN(sizeof(rx_buffer[itf]) - w_offset[itf], len);
|
uint16_t size = MIN(sizeof(rx_buffer[itf]) - w_offset[itf], len);
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
@@ -90,7 +87,8 @@ size_t usb_rx(uint8_t itf, const uint8_t *buffer, size_t len)
|
|||||||
size = driver_read_ccid(rx_buffer[itf] + w_offset[itf], size);
|
size = driver_read_ccid(rx_buffer[itf] + w_offset[itf], size);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
memcpy(rx_buffer[itf] + w_offset[itf], buffer, size);
|
memcpy(rx_buffer[itf] + w_offset[itf], buffer, size);
|
||||||
}
|
}
|
||||||
w_offset[itf] += size;
|
w_offset[itf] += size;
|
||||||
@@ -98,8 +96,7 @@ size_t usb_rx(uint8_t itf, const uint8_t *buffer, size_t len)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t usb_write_flush(uint8_t itf)
|
uint32_t usb_write_flush(uint8_t itf) {
|
||||||
{
|
|
||||||
int w = 0;
|
int w = 0;
|
||||||
if (w_len[itf] > 0) {
|
if (w_len[itf] > 0) {
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
@@ -123,33 +120,27 @@ uint32_t usb_write_flush(uint8_t itf)
|
|||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t usb_write(uint8_t itf, uint16_t len)
|
uint32_t usb_write(uint8_t itf, uint16_t len) {
|
||||||
{
|
|
||||||
return usb_write_offset(itf, len, 0);
|
return usb_write_offset(itf, len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t usb_read_available(uint8_t itf)
|
uint16_t usb_read_available(uint8_t itf) {
|
||||||
{
|
|
||||||
return w_offset[itf] - r_offset[itf];
|
return w_offset[itf] - r_offset[itf];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t usb_write_available(uint8_t itf)
|
uint16_t usb_write_available(uint8_t itf) {
|
||||||
{
|
|
||||||
return w_len[itf] > 0;
|
return w_len[itf] > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *usb_get_rx(uint8_t itf)
|
uint8_t *usb_get_rx(uint8_t itf) {
|
||||||
{
|
|
||||||
return rx_buffer[itf];
|
return rx_buffer[itf];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *usb_get_tx(uint8_t itf)
|
uint8_t *usb_get_tx(uint8_t itf) {
|
||||||
{
|
|
||||||
return tx_buffer[itf];
|
return tx_buffer[itf];
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_clear_rx(uint8_t itf)
|
void usb_clear_rx(uint8_t itf) {
|
||||||
{
|
|
||||||
w_offset[itf] = r_offset[itf] = 0;
|
w_offset[itf] = r_offset[itf] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,8 +158,7 @@ queue_t usb_to_card_q;
|
|||||||
queue_t card_to_usb_q;
|
queue_t card_to_usb_q;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void usb_init()
|
void usb_init() {
|
||||||
{
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
queue_init(&card_to_usb_q, sizeof(uint32_t), 64);
|
queue_init(&card_to_usb_q, sizeof(uint32_t), 64);
|
||||||
queue_init(&usb_to_card_q, sizeof(uint32_t), 64);
|
queue_init(&usb_to_card_q, sizeof(uint32_t), 64);
|
||||||
@@ -178,8 +168,7 @@ void usb_init()
|
|||||||
extern int driver_process_usb_nopacket();
|
extern int driver_process_usb_nopacket();
|
||||||
extern uint32_t timeout;
|
extern uint32_t timeout;
|
||||||
|
|
||||||
static int usb_event_handle(uint8_t itf)
|
static int usb_event_handle(uint8_t itf) {
|
||||||
{
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
uint16_t rx_read = usb_read_available(itf);
|
uint16_t rx_read = usb_read_available(itf);
|
||||||
#else
|
#else
|
||||||
@@ -208,7 +197,8 @@ static int usb_event_handle(uint8_t itf)
|
|||||||
queue_add_blocking(&usb_to_card_q, &flag);
|
queue_add_blocking(&usb_to_card_q, &flag);
|
||||||
#endif
|
#endif
|
||||||
timeout_start();
|
timeout_start();
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
if (itf == ITF_HID) {
|
if (itf == ITF_HID) {
|
||||||
driver_process_usb_nopacket_hid();
|
driver_process_usb_nopacket_hid();
|
||||||
@@ -224,8 +214,7 @@ static int usb_event_handle(uint8_t itf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern void low_flash_init();
|
extern void low_flash_init();
|
||||||
void card_init_core1()
|
void card_init_core1() {
|
||||||
{
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
low_flash_init_core1();
|
low_flash_init_core1();
|
||||||
#endif
|
#endif
|
||||||
@@ -233,8 +222,7 @@ void card_init_core1()
|
|||||||
|
|
||||||
size_t finished_data_size = 0;
|
size_t finished_data_size = 0;
|
||||||
|
|
||||||
void card_start(void (*func)(void))
|
void card_start(void (*func)(void)) {
|
||||||
{
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
uint32_t m = 0;
|
uint32_t m = 0;
|
||||||
while (queue_is_empty(&usb_to_card_q) == false) {
|
while (queue_is_empty(&usb_to_card_q) == false) {
|
||||||
@@ -253,8 +241,7 @@ void card_start(void (*func)(void))
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void card_exit()
|
void card_exit() {
|
||||||
{
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
uint32_t flag = EV_EXIT;
|
uint32_t flag = EV_EXIT;
|
||||||
queue_try_add(&usb_to_card_q, &flag);
|
queue_try_add(&usb_to_card_q, &flag);
|
||||||
@@ -263,8 +250,7 @@ void card_exit()
|
|||||||
card_locked_itf = ITF_TOTAL;
|
card_locked_itf = ITF_TOTAL;
|
||||||
}
|
}
|
||||||
extern void hid_task();
|
extern void hid_task();
|
||||||
void usb_task()
|
void usb_task() {
|
||||||
{
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
bool mounted = false;
|
bool mounted = false;
|
||||||
#else
|
#else
|
||||||
@@ -308,11 +294,13 @@ void usb_task()
|
|||||||
#endif
|
#endif
|
||||||
led_set_blink(BLINK_MOUNTED);
|
led_set_blink(BLINK_MOUNTED);
|
||||||
card_locked_itf = ITF_TOTAL;
|
card_locked_itf = ITF_TOTAL;
|
||||||
} else if (m == EV_PRESS_BUTTON) {
|
}
|
||||||
|
else if (m == EV_PRESS_BUTTON) {
|
||||||
uint32_t flag = wait_button() ? EV_BUTTON_TIMEOUT : EV_BUTTON_PRESSED;
|
uint32_t flag = wait_button() ? EV_BUTTON_TIMEOUT : EV_BUTTON_PRESSED;
|
||||||
queue_try_add(&usb_to_card_q, &flag);
|
queue_try_add(&usb_to_card_q, &flag);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
if (timeout + timeout_counter[itf] < board_millis()) {
|
if (timeout + timeout_counter[itf] < board_millis()) {
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
@@ -339,8 +327,7 @@ void usb_task()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t *usb_prepare_response(uint8_t itf)
|
uint8_t *usb_prepare_response(uint8_t itf) {
|
||||||
{
|
|
||||||
#ifdef USB_ITF_HID
|
#ifdef USB_ITF_HID
|
||||||
if (itf == ITF_HID) {
|
if (itf == ITF_HID) {
|
||||||
return driver_prepare_response_hid();
|
return driver_prepare_response_hid();
|
||||||
|
|||||||
@@ -38,8 +38,7 @@
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Device Descriptors
|
// Device Descriptors
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
tusb_desc_device_t const desc_device =
|
tusb_desc_device_t const desc_device = {
|
||||||
{
|
|
||||||
.bLength = sizeof(tusb_desc_device_t),
|
.bLength = sizeof(tusb_desc_device_t),
|
||||||
.bDescriptorType = TUSB_DESC_DEVICE,
|
.bDescriptorType = TUSB_DESC_DEVICE,
|
||||||
.bcdUSB = (USB_BCD),
|
.bcdUSB = (USB_BCD),
|
||||||
@@ -60,8 +59,7 @@ tusb_desc_device_t const desc_device =
|
|||||||
.bNumConfigurations = 1
|
.bNumConfigurations = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
uint8_t const *tud_descriptor_device_cb(void)
|
uint8_t const *tud_descriptor_device_cb(void) {
|
||||||
{
|
|
||||||
return (uint8_t const *) &desc_device;
|
return (uint8_t const *) &desc_device;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,8 +68,7 @@ uint8_t const *tud_descriptor_device_cb(void)
|
|||||||
// Configuration Descriptor
|
// Configuration Descriptor
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
tusb_desc_configuration_t const desc_config =
|
tusb_desc_configuration_t const desc_config = {
|
||||||
{
|
|
||||||
.bLength = sizeof(tusb_desc_configuration_t),
|
.bLength = sizeof(tusb_desc_configuration_t),
|
||||||
.bDescriptorType = TUSB_DESC_CONFIGURATION,
|
.bDescriptorType = TUSB_DESC_CONFIGURATION,
|
||||||
.wTotalLength = (sizeof(tusb_desc_configuration_t)
|
.wTotalLength = (sizeof(tusb_desc_configuration_t)
|
||||||
@@ -118,8 +115,7 @@ static const struct ccid_class_descriptor desc_ccid = {
|
|||||||
.bMaxCCIDBusySlots = 0x01,
|
.bMaxCCIDBusySlots = 0x01,
|
||||||
};
|
};
|
||||||
|
|
||||||
tusb_desc_interface_t const desc_interface =
|
tusb_desc_interface_t const desc_interface = {
|
||||||
{
|
|
||||||
.bLength = sizeof(tusb_desc_interface_t),
|
.bLength = sizeof(tusb_desc_interface_t),
|
||||||
.bDescriptorType = TUSB_DESC_INTERFACE,
|
.bDescriptorType = TUSB_DESC_INTERFACE,
|
||||||
.bInterfaceNumber = ITF_CCID,
|
.bInterfaceNumber = ITF_CCID,
|
||||||
@@ -131,8 +127,7 @@ tusb_desc_interface_t const desc_interface =
|
|||||||
.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),
|
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||||
.bEndpointAddress = TUSB_DIR_IN_MASK | 1,
|
.bEndpointAddress = TUSB_DIR_IN_MASK | 1,
|
||||||
@@ -141,8 +136,7 @@ tusb_desc_endpoint_t const desc_ep1 =
|
|||||||
.bInterval = 0
|
.bInterval = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
tusb_desc_endpoint_t const desc_ep2 =
|
tusb_desc_endpoint_t const desc_ep2 = {
|
||||||
{
|
|
||||||
.bLength = sizeof(tusb_desc_endpoint_t),
|
.bLength = sizeof(tusb_desc_endpoint_t),
|
||||||
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
||||||
.bEndpointAddress = 2,
|
.bEndpointAddress = 2,
|
||||||
@@ -194,12 +188,10 @@ enum {
|
|||||||
HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \
|
HID_OUTPUT(HID_DATA | HID_VARIABLE | HID_ABSOLUTE), \
|
||||||
HID_COLLECTION_END \
|
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)
|
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))
|
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID_KEYBOARD))
|
||||||
};
|
};
|
||||||
#define EPNUM_HID 0x03
|
#define EPNUM_HID 0x03
|
||||||
@@ -220,20 +212,19 @@ static uint8_t desc_hid_kb[] = {
|
|||||||
sizeof(desc_hid_report_kb), 0x80 | (EPNUM_HID + 1), 16, 5)
|
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);
|
printf("report_cb %d\n", itf);
|
||||||
if (itf == ITF_HID) {
|
if (itf == ITF_HID) {
|
||||||
return desc_hid_report;
|
return desc_hid_report;
|
||||||
} else if (itf == ITF_KEYBOARD) {
|
}
|
||||||
|
else if (itf == ITF_KEYBOARD) {
|
||||||
return desc_hid_report_kb;
|
return desc_hid_report_kb;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
(void) index; // for multiple configurations
|
||||||
|
|
||||||
static uint8_t initd = 0;
|
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
|
#define MS_OS_20_DESC_LEN 0xB2
|
||||||
|
|
||||||
uint8_t const desc_bos[] =
|
uint8_t const desc_bos[] = {
|
||||||
{
|
|
||||||
// total length, number of device caps
|
// total length, number of device caps
|
||||||
TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2)
|
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;
|
return desc_bos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,8 +267,7 @@ uint8_t const *tud_descriptor_bos_cb(void)
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
// array of pointer to string descriptors
|
// 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)
|
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
|
||||||
"Pol Henarejos", // 1: Manufacturer
|
"Pol Henarejos", // 1: Manufacturer
|
||||||
"Pico Key", // 2: Product
|
"Pico Key", // 2: Product
|
||||||
@@ -296,8 +284,7 @@ char const *string_desc_arr [] =
|
|||||||
|
|
||||||
static uint16_t _desc_str[32];
|
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;
|
(void) langid;
|
||||||
|
|
||||||
uint8_t chr_count;
|
uint8_t chr_count;
|
||||||
@@ -305,7 +292,8 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid)
|
|||||||
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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user