Introducing EF_PHY to store PHY (VIDPID and LED no.).

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2024-04-16 23:22:11 +02:00
parent afc71f6942
commit ade730ffb5
5 changed files with 23 additions and 21 deletions

View File

@@ -41,8 +41,10 @@ extern uint8_t flash_read_uint8(uintptr_t addr);
extern uint8_t *flash_read(uintptr_t addr); extern uint8_t *flash_read(uintptr_t addr);
extern void low_flash_available(); extern void low_flash_available();
#ifndef ENABLE_EMULATION
file_t sef_phy = {.fid = EF_PHY, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH | FILE_PERSISTENT, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = {0xff}}; file_t sef_phy = {.fid = EF_PHY, .parent = 5, .name = NULL, .type = FILE_TYPE_INTERNAL_EF | FILE_DATA_FLASH | FILE_PERSISTENT, .data = NULL, .ef_structure = FILE_EF_TRANSPARENT, .acl = {0xff}};
file_t *ef_phy = &sef_phy; file_t *ef_phy = &sef_phy;
#endif
//puts FCI in the RAPDU //puts FCI in the RAPDU
void process_fci(const file_t *pe, int fmd) { void process_fci(const file_t *pe, int fmd) {
@@ -147,7 +149,9 @@ file_t *search_by_name(uint8_t *name, uint16_t namelen) {
} }
file_t *search_by_fid(const uint16_t fid, const file_t *parent, const uint8_t sp) { file_t *search_by_fid(const uint16_t fid, const file_t *parent, const uint8_t sp) {
if (fid == EF_PHY) {
return ef_phy;
}
for (file_t *p = file_entries; p != file_last; p++) { for (file_t *p = file_entries; p != file_last; p++) {
if (p->fid != 0x0000 && p->fid == fid) { if (p->fid != 0x0000 && p->fid == fid) {
if (!parent || (parent && is_parent(p, parent))) { if (!parent || (parent && is_parent(p, parent))) {
@@ -266,9 +270,6 @@ void scan_region(bool persistent) {
} }
} }
void wait_flash_finish(); void wait_flash_finish();
#ifndef ENABLE_EMULATION
extern uint16_t usb_vid, usb_pid;
#endif
void scan_flash() { void scan_flash() {
initialize_flash(false); //soft initialization initialize_flash(false); //soft initialization
if (*(uintptr_t *) flash_read(end_rom_pool) == 0xffffffff && if (*(uintptr_t *) flash_read(end_rom_pool) == 0xffffffff &&
@@ -284,13 +285,6 @@ void scan_flash() {
printf("SCAN\n"); printf("SCAN\n");
scan_region(true); scan_region(true);
scan_region(false); scan_region(false);
#ifndef ENABLE_EMULATION
if (file_has_data(ef_phy) && file_get_size(ef_phy) >= 4) {
uint8_t *data = file_get_data(ef_phy);
usb_vid = (data[PHY_VID] << 8) | data[PHY_VID+1];
usb_pid = (data[PHY_PID] << 8) | data[PHY_PID+1];
}
#endif
} }
uint8_t *file_read(const uint8_t *addr) { uint8_t *file_read(const uint8_t *addr) {

View File

@@ -72,6 +72,9 @@
#define PHY_VID 0x0 #define PHY_VID 0x0
#define PHY_PID 0x2 #define PHY_PID 0x2
#define PHY_LED_GPIO 0x4 #define PHY_LED_GPIO 0x4
#define PHY_LED_MODE 0x5
#define PHY_MAX_SIZE 6
#define MAX_DEPTH 4 #define MAX_DEPTH 4

View File

@@ -423,7 +423,11 @@ int main(void) {
//ccid_prepare_receive(&ccid); //ccid_prepare_receive(&ccid);
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
neopixel = neopixel_Init(1, GPIO_NUM_48); uint8_t gpio = GPIO_NUM_48;
if (file_has_data(ef_phy)) {
gpio = file_get_data(ef_phy)[PHY_LED_GPIO];
}
neopixel = neopixel_Init(1, gpio);
#endif #endif
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM

View File

@@ -161,16 +161,21 @@ queue_t card_to_usb_q;
#endif #endif
#ifndef ENABLE_EMULATION #ifndef ENABLE_EMULATION
extern uint16_t usb_vid, usb_pid;
extern tusb_desc_device_t desc_device; extern tusb_desc_device_t desc_device;
#endif #endif
void usb_init() void usb_init() {
{
#ifndef ENABLE_EMULATION #ifndef ENABLE_EMULATION
queue_init(&card_to_usb_q, sizeof(uint32_t), 64); uint16_t usb_vid = USB_VID, usb_pid = USB_PID;
queue_init(&usb_to_card_q, sizeof(uint32_t), 64); if (file_has_data(ef_phy) && file_get_size(ef_phy) >= 4) {
uint8_t *data = file_get_data(ef_phy);
usb_vid = (data[PHY_VID] << 8) | data[PHY_VID+1];
usb_pid = (data[PHY_PID] << 8) | data[PHY_PID+1];
}
desc_device.idVendor = usb_vid; desc_device.idVendor = usb_vid;
desc_device.idProduct = usb_pid; desc_device.idProduct = usb_pid;
queue_init(&card_to_usb_q, sizeof(uint32_t), 64);
queue_init(&usb_to_card_q, sizeof(uint32_t), 64);
#endif #endif
} }

View File

@@ -40,10 +40,6 @@
#define MAX_USB_POWER 1 #define MAX_USB_POWER 1
uint16_t usb_vid = USB_VID;
uint16_t usb_pid = USB_PID;
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Device Descriptors // Device Descriptors
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+