From 4edc5067593ea5596e27cd1d5ef8be6c6467df53 Mon Sep 17 00:00:00 2001 From: Pol Henarejos Date: Mon, 22 Sep 2025 23:35:46 +0200 Subject: [PATCH] Fix build for non-pico boards. Signed-off-by: Pol Henarejos --- src/apdu.h | 2 +- src/asn1.h | 2 +- src/crypto_utils.c | 5 +- src/fs/file.h | 2 +- src/fs/flash.c | 4 +- src/fs/low_flash.c | 62 +++++++++--------- src/led/led.c | 8 +-- src/led/led_pico.c | 3 + src/led/led_pimoroni.c | 3 + src/led/led_ws2812.c | 4 ++ src/main.c | 23 ++++--- src/pico_keys.h | 7 +- src/rng/hwrng.c | 35 +++++----- src/rng/hwrng.h | 2 +- src/usb/ccid/ccid.c | 4 ++ src/usb/emulation/emulation.c | 2 +- src/usb/emulation/emulation.h | 118 +--------------------------------- src/usb/hid/hid.c | 8 +-- src/usb/tusb_config.h | 3 + src/usb/usb.c | 6 +- src/usb/usb.h | 5 +- src/usb/usb_descriptors.c | 4 +- 22 files changed, 108 insertions(+), 204 deletions(-) diff --git a/src/apdu.h b/src/apdu.h index 2984288..95f5f52 100644 --- a/src/apdu.h +++ b/src/apdu.h @@ -19,7 +19,7 @@ #define _APDU_H_ #include -#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) +#if defined(PICO_PLATFORM) #include "pico/stdlib.h" #endif #include "compat.h" diff --git a/src/asn1.h b/src/asn1.h index ae2e471..9e01534 100644 --- a/src/asn1.h +++ b/src/asn1.h @@ -19,7 +19,7 @@ #define _ASN1_H_ #include -#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) +#if defined(PICO_PLATFORM) #include "pico/stdlib.h" #else #include diff --git a/src/crypto_utils.c b/src/crypto_utils.c index 3a43601..a9879dd 100644 --- a/src/crypto_utils.c +++ b/src/crypto_utils.c @@ -15,10 +15,9 @@ * along with this program. If not, see . */ -#if defined(ENABLE_EMULATION) -#elif defined(ESP_PLATFORM) +#if defined(ESP_PLATFORM) #include "esp_compat.h" -#else +#elif defined(PICO_PLATFORM) #include #endif #include "mbedtls/md.h" diff --git a/src/fs/file.h b/src/fs/file.h index 3949997..0686a74 100644 --- a/src/fs/file.h +++ b/src/fs/file.h @@ -19,7 +19,7 @@ #define _FILE_H_ #include -#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) +#if defined(PICO_PLATFORM) #include "pico/stdlib.h" #else #include diff --git a/src/fs/flash.c b/src/fs/flash.c index 08eff20..24f8abd 100644 --- a/src/fs/flash.c +++ b/src/fs/flash.c @@ -18,8 +18,9 @@ #include #include +#include "pico_keys.h" -#if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM) +#if !defined(PICO_PLATFORM) #define XIP_BASE 0 #define FLASH_SECTOR_SIZE 4096 #ifdef ESP_PLATFORM @@ -32,7 +33,6 @@ uint32_t FLASH_SIZE_BYTES = (2 * 1024 * 1024); #include "pico/stdlib.h" #include "hardware/flash.h" #endif -#include "pico_keys.h" #include "file.h" #include diff --git a/src/fs/low_flash.c b/src/fs/low_flash.c index fdc6f10..300148b 100644 --- a/src/fs/low_flash.c +++ b/src/fs/low_flash.c @@ -32,29 +32,29 @@ #include "pico/bootrom.h" #include "boot/picobin.h" #else - #ifdef _MSC_VER - #include - #include - #define O_RDWR _O_RDWR - #define O_CREAT _O_CREAT - #define open _open - #define write _write - #define mode_t unsigned short - #define lseek _lseek - #include "mman.h" + #ifdef ESP_PLATFORM + #include "esp_compat.h" + #include "esp_partition.h" + const esp_partition_t *part0; + #define save_and_disable_interrupts() 1 + #define flash_range_erase(a,b) esp_partition_erase_range(part0, a, b) + #define flash_range_program(a,b,c) esp_partition_write(part0, a, b, c); + #define restore_interrupts(a) (void)a #else - #ifdef ESP_PLATFORM - #include "esp_compat.h" - #include "esp_partition.h" - const esp_partition_t *part0; - #define save_and_disable_interrupts() 1 - #define flash_range_erase(a,b) esp_partition_erase_range(part0, a, b) - #define flash_range_program(a,b,c) esp_partition_write(part0, a, b, c); - #define restore_interrupts(a) (void)a + #ifdef _MSC_VER + #include + #include + #define O_RDWR _O_RDWR + #define O_CREAT _O_CREAT + #define open _open + #define write _write + #define mode_t unsigned short + #define lseek _lseek + #include "mman.h" #else #include #include - #include "emulation.h" + #include "queue.h" #endif #endif #define FLASH_SECTOR_SIZE 4096 @@ -63,7 +63,7 @@ uint8_t *map = NULL; #include #endif -#ifndef ENABLE_EMULATION +#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) extern uint32_t FLASH_SIZE_BYTES; #else #define FLASH_SIZE_BYTES (8 * 1024 * 1024) @@ -107,7 +107,7 @@ void do_flash() { //printf(" DO_FLASH AVAILABLE\n"); for (int r = 0; r < TOTAL_FLASH_PAGES; r++) { if (flash_pages[r].ready == true) { -#ifndef ENABLE_EMULATION +#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) //printf("WRITTING %X\n",flash_pages[r].address-XIP_BASE); while (multicore_lockout_start_timeout_us(1000) == false) { ; @@ -128,7 +128,7 @@ void do_flash() { ready_pages--; } else if (flash_pages[r].erase == true) { -#ifndef ENABLE_EMULATION +#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) while (multicore_lockout_start_timeout_us(1000) == false) { ; } @@ -144,7 +144,7 @@ void do_flash() { ready_pages--; } } -#ifdef ENABLE_EMULATION +#if !defined(PICO_PLATFORM) && !defined(ESP_PLATFORM) msync(map, FLASH_SIZE_BYTES, MS_SYNC); #endif if (ready_pages != 0) { @@ -169,14 +169,7 @@ void low_flash_init() { uint32_t data_start_addr; uint32_t data_end_addr; -#if defined(ENABLE_EMULATION) - fd_map = open("memory.flash", O_RDWR | O_CREAT, (mode_t) 0600); - lseek(fd_map, FLASH_SIZE_BYTES - 1, SEEK_SET); - write(fd_map, "", 1); - map = mmap(0, FLASH_SIZE_BYTES, PROT_READ | PROT_WRITE, MAP_SHARED, fd_map, 0); - data_start_addr = 0; - data_end_addr = FLASH_SIZE_BYTES; -#elif defined(ESP_PLATFORM) +#if defined(ESP_PLATFORM) part0 = esp_partition_find_first(0x40, 0x1, "part0"); esp_partition_mmap(part0, 0, part0->size, ESP_PARTITION_MMAP_DATA, (const void **)&map, (esp_partition_mmap_handle_t *)&fd_map); data_start_addr = 0; @@ -215,6 +208,13 @@ void low_flash_init() { data_start_addr += XIP_BASE; data_end_addr += XIP_BASE; +#else + fd_map = open("memory.flash", O_RDWR | O_CREAT, (mode_t) 0600); + lseek(fd_map, FLASH_SIZE_BYTES - 1, SEEK_SET); + write(fd_map, "", 1); + map = mmap(0, FLASH_SIZE_BYTES, PROT_READ | PROT_WRITE, MAP_SHARED, fd_map, 0); + data_start_addr = 0; + data_end_addr = FLASH_SIZE_BYTES; #endif flash_set_bounds(data_start_addr, data_end_addr); } diff --git a/src/led/led.c b/src/led/led.c index 2c229db..4b97d52 100644 --- a/src/led/led.c +++ b/src/led/led.c @@ -39,7 +39,7 @@ uint32_t led_get_mode() { } void led_blinking_task() { -#ifndef ENABLE_EMULATION +#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) static uint32_t start_ms = 0; static uint32_t stop_ms = 0; static uint32_t last_led_update_ms = 0; @@ -81,7 +81,7 @@ void led_blinking_task() { } void led_off_all() { -#ifndef ENABLE_EMULATION +#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) led_driver->set_color(LED_COLOR_OFF, 0, 0); #endif } @@ -110,8 +110,8 @@ led_driver_t led_driver_dummy = { void led_init() { led_driver = &led_driver_dummy; -#ifndef ENABLE_EMULATION -# // Guess default driver +#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) + // Guess default driver #ifdef PICO_DEFAULT_LED_PIN led_driver = &led_driver_pico; #elif defined(CYW43_WL_GPIO_LED_PIN) diff --git a/src/led/led_pico.c b/src/led/led_pico.c index fce14b7..f33ebf5 100644 --- a/src/led/led_pico.c +++ b/src/led/led_pico.c @@ -23,6 +23,7 @@ uint8_t gpio = PICO_DEFAULT_LED_PIN; uint8_t gpio = 0; #endif +#ifdef PICO_PLATFORM void led_driver_init_pico() { if (phy_data.led_gpio_present) { gpio = phy_data.led_gpio; @@ -40,3 +41,5 @@ led_driver_t led_driver_pico = { .init = led_driver_init_pico, .set_color = led_driver_color_pico, }; + +#endif diff --git a/src/led/led_pimoroni.c b/src/led/led_pimoroni.c index 65c507d..9728f4d 100644 --- a/src/led/led_pimoroni.c +++ b/src/led/led_pimoroni.c @@ -17,6 +17,7 @@ #include "pico_keys.h" +#ifdef PICO_PLATFORM #ifdef PIMORONI_TINY2040 #define LED_R_PIN TINY2040_LED_R_PIN #define LED_G_PIN TINY2040_LED_G_PIN @@ -64,3 +65,5 @@ led_driver_t led_driver_pimoroni = { .init = led_driver_init_pimoroni, .set_color = led_driver_color_pimoroni, }; + +#endif diff --git a/src/led/led_ws2812.c b/src/led/led_ws2812.c index b2832c6..c3faaab 100644 --- a/src/led/led_ws2812.c +++ b/src/led/led_ws2812.c @@ -16,6 +16,8 @@ */ #include "pico_keys.h" + +#ifdef PICO_PLATFORM #include "hardware/pio.h" #include "hardware/clocks.h" @@ -132,3 +134,5 @@ led_driver_t led_driver_ws2812 = { .init = led_driver_init_ws2812, .set_color = led_driver_color_ws2812, }; + +#endif diff --git a/src/main.c b/src/main.c index 1d866ae..0fe3196 100644 --- a/src/main.c +++ b/src/main.c @@ -17,19 +17,20 @@ #include #include +#include "pico_keys.h" -// Pico - +#if !defined(ENABLE_EMULATION) +#include "tusb.h" +#endif #if defined(ENABLE_EMULATION) #include "emulation.h" #elif defined(ESP_PLATFORM) -#include "tusb.h" #include "driver/gpio.h" #include "rom/gpio.h" #include "tinyusb.h" #include "esp_efuse.h" #define BOOT_PIN GPIO_NUM_0 -#else +#elif defined(PICO_PLATFORM) #include "pico/stdlib.h" #include "bsp/board.h" #include "pico/aon_timer.h" @@ -40,7 +41,6 @@ #endif #include "random.h" -#include "pico_keys.h" #include "apdu.h" #include "usb.h" extern void do_flash(); @@ -152,7 +152,7 @@ bool picok_board_button_read() { int boot_state = gpio_get_level(BOOT_PIN); return boot_state == 0; } -#else +#elif defined(PICO_PLATFORM) bool __no_inline_not_in_flash_func(picok_get_bootsel_button)() { const uint CS_PIN_INDEX = 1; @@ -187,10 +187,13 @@ bool __no_inline_not_in_flash_func(picok_get_bootsel_button)() { return button_state; } -uint32_t picok_board_button_read(void) -{ +bool picok_board_button_read(void) { return picok_get_bootsel_button(); } +#else +bool picok_board_button_read(void) { + return true; // always unpressed +} #endif bool button_pressed_state = false; uint32_t button_pressed_time = 0; @@ -294,7 +297,7 @@ extern const uint8_t desc_config[]; TaskHandle_t hcore0 = NULL, hcore1 = NULL; int app_main() { #else -#ifdef ENABLE_EMULATION +#ifndef PICO_PLATFORM #define pico_get_unique_board_id(a) memset(a, 0, sizeof(*(a))) #endif int main(void) { @@ -306,7 +309,7 @@ int main(void) { } #ifndef ENABLE_EMULATION -#ifndef ESP_PLATFORM +#ifdef PICO_PLATFORM board_init(); stdio_init_all(); #endif diff --git a/src/pico_keys.h b/src/pico_keys.h index 8a5022b..a72d468 100644 --- a/src/pico_keys.h +++ b/src/pico_keys.h @@ -24,7 +24,6 @@ #include "file.h" #include "led/led.h" -#if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM) #include #if !defined(MIN) #if defined(_MSC_VER) @@ -46,7 +45,7 @@ _a > _b ? _a : _b; }) #endif #endif -#else +#if defined(PICO_PLATFORM) #include "pico/unique_id.h" #endif #include @@ -56,7 +55,7 @@ #include #elif defined(ESP_PLATFORM) #include "esp_compat.h" -#else +#elif defined(PICO_PLATFORM) #include "pico/util/queue.h" #endif @@ -230,7 +229,7 @@ extern uint32_t button_timeout; #define PICOKEY_CHECK(x) do { ret = (x); if (ret != PICOKEY_OK) goto err; } while (0) -#if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM) +#if !defined (PICO_PLATFORM) #define PICO_UNIQUE_BOARD_ID_SIZE_BYTES 8 typedef struct { uint8_t id[PICO_UNIQUE_BOARD_ID_SIZE_BYTES]; } pico_unique_board_id_t; #endif diff --git a/src/rng/hwrng.c b/src/rng/hwrng.c index 7b92f83..cf5981f 100644 --- a/src/rng/hwrng.c +++ b/src/rng/hwrng.c @@ -18,20 +18,21 @@ #include #include #include -#if defined(ENABLE_EMULATION) -#include -#include -#include -#include "emulation.h" + +#if defined(PICO_PLATFORM) +#include "pico/stdlib.h" +#include "hwrng.h" +#include "bsp/board.h" +#include "pico/rand.h" #elif (ESP_PLATFORM) #include "bootloader_random.h" #include "esp_random.h" #include "esp_compat.h" #else -#include "pico/stdlib.h" -#include "hwrng.h" -#include "bsp/board.h" -#include "pico/rand.h" +#include +#include +#include +#include "board.h" #endif void hwrng_start() { @@ -57,14 +58,14 @@ static int ep_process() { } uint64_t word = 0x0; -#if defined(ENABLE_EMULATION) - word = rand(); - word <<= 32; - word |= rand(); +#if defined(PICO_PLATFORM) + word = get_rand_64(); #elif defined(ESP_PLATFORM) esp_fill_random((uint8_t *)&word, sizeof(word)); #else - word = get_rand_64(); + word = rand(); + word <<= 32; + word |= rand(); #endif random_word ^= word ^ board_millis(); random_word *= 0x00000100000001B3; @@ -169,15 +170,13 @@ uint32_t neug_get() { void neug_wait_full() { struct rng_rb *rb = &the_ring_buffer; -#ifndef ENABLE_EMULATION #ifdef ESP_PLATFORM uint8_t core = xTaskGetCurrentTaskHandle() == hcore1 ? 1 : 0; -#else +#elif defined(PICO_PLATFORM) uint core = get_core_num(); -#endif #endif while (!rb->full) { -#ifndef ENABLE_EMULATION +#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) if (core == 1) { sleep_ms(1); } diff --git a/src/rng/hwrng.h b/src/rng/hwrng.h index 7efbd22..b6b9b09 100644 --- a/src/rng/hwrng.h +++ b/src/rng/hwrng.h @@ -21,7 +21,7 @@ #define NEUG_PRE_LOOP 32 #include -#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) +#if defined(PICO_PLATFORM) #include "pico/stdlib.h" #endif diff --git a/src/usb/ccid/ccid.c b/src/usb/ccid/ccid.c index 8f61d8a..9a6b65e 100644 --- a/src/usb/ccid/ccid.c +++ b/src/usb/ccid/ccid.c @@ -378,7 +378,11 @@ static uint16_t ccid_open(uint8_t rhport, tusb_desc_interface_t const *itf_desc, tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *)((uint8_t *)itf_desc + drv_len - sizeof(tusb_desc_endpoint_t)); TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0); uint8_t msg[] = { 0x50, 0x03 }; +#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) usbd_edpt_xfer(rhport, desc_ep->bEndpointAddress, msg, sizeof(msg)); +#else + usbd_edpt_xfer(rhport, desc_ep->bEndpointAddress, msg, sizeof(msg), sizeof(msg)); +#endif #else vendord_open(rhport, (tusb_desc_interface_t *)itf_vendor, max_len); #endif diff --git a/src/usb/emulation/emulation.c b/src/usb/emulation/emulation.c index 9c37a60..107d86e 100644 --- a/src/usb/emulation/emulation.c +++ b/src/usb/emulation/emulation.c @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include "pico_keys.h" #include "emulation.h" #include #ifndef _MSC_VER @@ -41,7 +42,6 @@ typedef int socklen_t; #include #include -#include "pico_keys.h" #include "apdu.h" #include "usb.h" #include "ccid/ccid.h" diff --git a/src/usb/emulation/emulation.h b/src/usb/emulation/emulation.h index 75e74e1..9bd8537 100644 --- a/src/usb/emulation/emulation.h +++ b/src/usb/emulation/emulation.h @@ -20,11 +20,8 @@ #include #include -#ifdef _MSC_VER -#include -#else -#include -#endif +#include "queue.h" +#include "board.h" #include #define USB_BUFFER_SIZE 2048 @@ -34,12 +31,6 @@ extern uint16_t emul_rx_size, emul_tx_size; extern uint16_t driver_write_emul(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size); extern uint16_t emul_read(uint8_t itf); -static inline uint32_t board_millis() { - struct timeval start; - gettimeofday(&start, NULL); - return start.tv_sec * 1000 + start.tv_usec / 1000; -} - #ifdef USB_ITF_HID typedef uint8_t hid_report_type_t; #endif @@ -71,109 +62,4 @@ extern void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report, extern bool tud_hid_n_report(uint8_t itf, uint8_t report_id, const uint8_t *buffer, uint32_t n); #endif -#include -#include -typedef struct { - pthread_mutex_t mtx; - pthread_cond_t cnd; - size_t size_elem; - size_t num_elem; - size_t max_elem; - uint8_t buf[1024]; - bool is_init; -} queue_t; - -static inline void queue_free(queue_t *a) { - pthread_mutex_destroy(&a->mtx); - pthread_cond_destroy(&a->cnd); - a->is_init = false; -} -static inline void queue_init(queue_t *a, size_t size_elem, size_t max_elem) { - if (a->is_init) { - queue_free(a); - } - pthread_mutex_init(&a->mtx, NULL); - pthread_cond_init(&a->cnd, NULL); - a->size_elem = size_elem; - a->max_elem = max_elem; - a->num_elem = 0; - a->is_init = true; -} -static inline void queue_add_blocking(queue_t *a, const void *b) { - pthread_mutex_lock(&a->mtx); - while (a->num_elem == a->max_elem) { - pthread_cond_wait(&a->cnd, &a->mtx); - } - memcpy(a->buf + a->num_elem * a->size_elem, b, a->size_elem); - a->num_elem++; - pthread_cond_signal(&a->cnd); - pthread_mutex_unlock(&a->mtx); -} -static inline void queue_remove_blocking(queue_t *a, void *b) { - pthread_mutex_lock(&a->mtx); - while (a->num_elem == 0) { - pthread_cond_wait(&a->cnd, &a->mtx); - } - memcpy(b, a->buf, a->size_elem); - memmove(a->buf, a->buf + a->size_elem, a->size_elem * (a->num_elem - 1)); - a->num_elem--; - pthread_cond_signal(&a->cnd); - pthread_mutex_unlock(&a->mtx); -} -static inline int queue_try_add(queue_t *a, const void *b) { - pthread_mutex_lock(&a->mtx); - if (a->num_elem == a->max_elem) { - pthread_mutex_unlock(&a->mtx); - return 0; - } - memcpy(a->buf + a->num_elem * a->size_elem, b, a->size_elem); - a->num_elem++; - pthread_cond_signal(&a->cnd); - pthread_mutex_unlock(&a->mtx); - return 1; -} -static inline int queue_try_remove(queue_t *a, void *b) { - pthread_mutex_lock(&a->mtx); - if (a->num_elem == 0) { - pthread_mutex_unlock(&a->mtx); - return 0; - } - memcpy(b, a->buf, a->size_elem); - memmove(a->buf, a->buf + a->size_elem, a->size_elem * (a->num_elem - 1)); - a->num_elem--; - pthread_cond_signal(&a->cnd); - pthread_mutex_unlock(&a->mtx); - return 1; -} -static inline int queue_is_empty(queue_t *a) { - pthread_mutex_lock(&a->mtx); - bool ret = a->num_elem == 0; - pthread_mutex_unlock(&a->mtx); - return ret; -} -static inline int queue_is_full(queue_t *a) { - pthread_mutex_lock(&a->mtx); - bool ret = a->num_elem == a->max_elem; - pthread_mutex_unlock(&a->mtx); - return ret; -} -static inline void queue_clear(queue_t *a) { - pthread_mutex_lock(&a->mtx); - a->num_elem = 0; - pthread_mutex_unlock(&a->mtx); -} -extern pthread_t hcore0, hcore1; -#define multicore_launch_core1(a) pthread_create(&hcore1, NULL, (void *(*) (void *))a, NULL) -#define multicore_reset_core1() - -typedef pthread_mutex_t mutex_t; -typedef sem_t semaphore_t; -#define mutex_init(a) pthread_mutex_init(a, NULL) -#define mutex_try_enter(a,b) (pthread_mutex_trylock(a) == 0) -#define mutex_enter_blocking(a) pthread_mutex_lock(a) -#define mutex_exit(a) pthread_mutex_unlock(a) -#define sem_release(a) sem_post(a) -#define sem_acquire_blocking(a) sem_wait(a) -#define multicore_lockout_victim_init() (void)0 - #endif // _EMULATION_H_ diff --git a/src/usb/hid/hid.c b/src/usb/hid/hid.c index e3183dc..7bf6bf8 100644 --- a/src/usb/hid/hid.c +++ b/src/usb/hid/hid.c @@ -15,18 +15,18 @@ * along with this program. If not, see . */ +#include "pico_keys.h" #ifndef ENABLE_EMULATION #include "tusb.h" -#ifndef ESP_PLATFORM +#if defined(PICO_PLATFORM) #include "bsp/board.h" -#else +#elif defined(ESP_PLATFORM) static portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED; #endif #else #include "emulation.h" #endif #include "ctap_hid.h" -#include "pico_keys.h" #include "pico_keys_version.h" #include "apdu.h" #include "usb.h" @@ -418,7 +418,7 @@ int driver_process_usb_packet_hid(uint16_t read) { } last_packet_time = 0; memcpy(ctap_resp, ctap_req, sizeof(CTAPHID_FRAME)); -#ifndef ENABLE_EMULATION +#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM) sleep_ms(1000); //For blinking the device during 1 seg #endif driver_write_hid(ITF_HID_CTAP, (const uint8_t *)ctap_resp, 64); diff --git a/src/usb/tusb_config.h b/src/usb/tusb_config.h index 1fabfa4..dffdee9 100644 --- a/src/usb/tusb_config.h +++ b/src/usb/tusb_config.h @@ -58,6 +58,9 @@ extern "C" { #define CFG_TUSB_OS OPT_OS_PICO #elif CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3 #define CFG_TUSB_OS OPT_OS_FREERTOS +#elif CFG_TUSB_MCU == OPT_MCU_NONE +#define CFG_TUSB_OS OPT_OS_NONE +#define TUP_DCD_ENDPOINT_MAX 16 #endif #endif diff --git a/src/usb/usb.c b/src/usb/usb.c index aa03c9e..1a5a520 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -16,14 +16,12 @@ */ #include - -// Pico -#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) +#include "pico_keys.h" +#if defined(PICO_PLATFORM) #include "pico/stdlib.h" #include "pico/multicore.h" #include "bsp/board.h" #endif -#include "pico_keys.h" #include "usb.h" #include "apdu.h" #ifndef ENABLE_EMULATION diff --git a/src/usb/usb.h b/src/usb/usb.h index 06a799e..9f87c9c 100644 --- a/src/usb/usb.h +++ b/src/usb/usb.h @@ -22,8 +22,11 @@ #include "emulation.h" #elif defined(ESP_PLATFORM) #include "esp_compat.h" -#else +#elif defined(PICO_PLATFORM) #include "pico/util/queue.h" +#else +#include "queue.h" +#include "board.h" #endif #include "compat.h" diff --git a/src/usb/usb_descriptors.c b/src/usb/usb_descriptors.c index 25e0b4f..af516b4 100644 --- a/src/usb/usb_descriptors.c +++ b/src/usb/usb_descriptors.c @@ -15,9 +15,10 @@ * along with this program. If not, see . */ +#include "pico_keys.h" #include "tusb.h" #include "usb_descriptors.h" -#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) +#if defined(PICO_PLATFORM) #include "pico/unique_id.h" #endif #ifdef ESP_PLATFORM @@ -25,7 +26,6 @@ #endif #include "pico_keys_version.h" #include "usb.h" -#include "pico_keys.h" #ifndef USB_VID #define USB_VID 0xFEFF