Added support for dynamic USB_VID / USB_PID.

It can be changed on runtime without rebuilding or patching.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2024-04-16 00:04:23 +02:00
parent b6b53010cc
commit 6f7ab69a9d
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
3 changed files with 13 additions and 3 deletions

View file

@ -283,8 +283,10 @@ void scan_flash() {
scan_region(false);
#ifndef ENABLE_EMULATION
file_t *ef_vp = search_dynamic_file(EF_VP);
if (file_has_data(ef_vp)) {
if (file_has_data(ef_vp) && file_get_size(ef_vp) >= 4) {
uint8_t *data = file_get_data(ef_vp);
usb_vid = (data[0] << 8) | data[1];
usb_pid = (data[2] << 8) | data[3];
}
#endif
}

View file

@ -26,7 +26,9 @@
#include "pico_keys.h"
#include "usb.h"
#include "apdu.h"
#ifndef ENABLE_EMULATION
#include "tusb.h"
#endif
// For memcpy
#include <string.h>
@ -158,8 +160,10 @@ queue_t usb_to_card_q;
queue_t card_to_usb_q;
#endif
#ifndef ENABLE_EMULATION
extern uint16_t usb_vid, usb_pid;
extern tusb_desc_device_t desc_device;
#endif
void usb_init()
{
#ifndef ENABLE_EMULATION

View file

@ -25,6 +25,7 @@
#endif
#include "pico_keys_version.h"
#include "usb.h"
#include "pico_keys.h"
#ifndef USB_VID
#define USB_VID 0xFEFF
@ -39,11 +40,14 @@
#define MAX_USB_POWER 1
uint16_t usb_vid = USB_VID;
uint16_t usb_pid = USB_PID;
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
tusb_desc_device_t const desc_device = {
tusb_desc_device_t desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = (USB_BCD),