Fix build for non-pico boards.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2025-09-22 23:35:46 +02:00
parent e55014cfb3
commit 4edc506759
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
22 changed files with 108 additions and 204 deletions

View file

@ -19,7 +19,7 @@
#define _APDU_H_ #define _APDU_H_
#include <stdlib.h> #include <stdlib.h>
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) #if defined(PICO_PLATFORM)
#include "pico/stdlib.h" #include "pico/stdlib.h"
#endif #endif
#include "compat.h" #include "compat.h"

View file

@ -19,7 +19,7 @@
#define _ASN1_H_ #define _ASN1_H_
#include <stdlib.h> #include <stdlib.h>
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) #if defined(PICO_PLATFORM)
#include "pico/stdlib.h" #include "pico/stdlib.h"
#else #else
#include <stdint.h> #include <stdint.h>

View file

@ -15,10 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#if defined(ENABLE_EMULATION) #if defined(ESP_PLATFORM)
#elif defined(ESP_PLATFORM)
#include "esp_compat.h" #include "esp_compat.h"
#else #elif defined(PICO_PLATFORM)
#include <pico/unique_id.h> #include <pico/unique_id.h>
#endif #endif
#include "mbedtls/md.h" #include "mbedtls/md.h"

View file

@ -19,7 +19,7 @@
#define _FILE_H_ #define _FILE_H_
#include <stdlib.h> #include <stdlib.h>
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) #if defined(PICO_PLATFORM)
#include "pico/stdlib.h" #include "pico/stdlib.h"
#else #else
#include <stdbool.h> #include <stdbool.h>

View file

@ -18,8 +18,9 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include "pico_keys.h"
#if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM) #if !defined(PICO_PLATFORM)
#define XIP_BASE 0 #define XIP_BASE 0
#define FLASH_SECTOR_SIZE 4096 #define FLASH_SECTOR_SIZE 4096
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
@ -32,7 +33,6 @@ uint32_t FLASH_SIZE_BYTES = (2 * 1024 * 1024);
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include "hardware/flash.h" #include "hardware/flash.h"
#endif #endif
#include "pico_keys.h"
#include "file.h" #include "file.h"
#include <stdio.h> #include <stdio.h>

View file

@ -32,29 +32,29 @@
#include "pico/bootrom.h" #include "pico/bootrom.h"
#include "boot/picobin.h" #include "boot/picobin.h"
#else #else
#ifdef _MSC_VER #ifdef ESP_PLATFORM
#include <windows.h> #include "esp_compat.h"
#include <io.h> #include "esp_partition.h"
#define O_RDWR _O_RDWR const esp_partition_t *part0;
#define O_CREAT _O_CREAT #define save_and_disable_interrupts() 1
#define open _open #define flash_range_erase(a,b) esp_partition_erase_range(part0, a, b)
#define write _write #define flash_range_program(a,b,c) esp_partition_write(part0, a, b, c);
#define mode_t unsigned short #define restore_interrupts(a) (void)a
#define lseek _lseek
#include "mman.h"
#else #else
#ifdef ESP_PLATFORM #ifdef _MSC_VER
#include "esp_compat.h" #include <windows.h>
#include "esp_partition.h" #include <io.h>
const esp_partition_t *part0; #define O_RDWR _O_RDWR
#define save_and_disable_interrupts() 1 #define O_CREAT _O_CREAT
#define flash_range_erase(a,b) esp_partition_erase_range(part0, a, b) #define open _open
#define flash_range_program(a,b,c) esp_partition_write(part0, a, b, c); #define write _write
#define restore_interrupts(a) (void)a #define mode_t unsigned short
#define lseek _lseek
#include "mman.h"
#else #else
#include <unistd.h> #include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#include "emulation.h" #include "queue.h"
#endif #endif
#endif #endif
#define FLASH_SECTOR_SIZE 4096 #define FLASH_SECTOR_SIZE 4096
@ -63,7 +63,7 @@
uint8_t *map = NULL; uint8_t *map = NULL;
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#ifndef ENABLE_EMULATION #if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
extern uint32_t FLASH_SIZE_BYTES; extern uint32_t FLASH_SIZE_BYTES;
#else #else
#define FLASH_SIZE_BYTES (8 * 1024 * 1024) #define FLASH_SIZE_BYTES (8 * 1024 * 1024)
@ -107,7 +107,7 @@ void do_flash() {
//printf(" DO_FLASH AVAILABLE\n"); //printf(" DO_FLASH AVAILABLE\n");
for (int r = 0; r < TOTAL_FLASH_PAGES; r++) { for (int r = 0; r < TOTAL_FLASH_PAGES; r++) {
if (flash_pages[r].ready == true) { 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); //printf("WRITTING %X\n",flash_pages[r].address-XIP_BASE);
while (multicore_lockout_start_timeout_us(1000) == false) { while (multicore_lockout_start_timeout_us(1000) == false) {
; ;
@ -128,7 +128,7 @@ void do_flash() {
ready_pages--; ready_pages--;
} }
else if (flash_pages[r].erase == true) { 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) { while (multicore_lockout_start_timeout_us(1000) == false) {
; ;
} }
@ -144,7 +144,7 @@ void do_flash() {
ready_pages--; ready_pages--;
} }
} }
#ifdef ENABLE_EMULATION #if !defined(PICO_PLATFORM) && !defined(ESP_PLATFORM)
msync(map, FLASH_SIZE_BYTES, MS_SYNC); msync(map, FLASH_SIZE_BYTES, MS_SYNC);
#endif #endif
if (ready_pages != 0) { if (ready_pages != 0) {
@ -169,14 +169,7 @@ void low_flash_init() {
uint32_t data_start_addr; uint32_t data_start_addr;
uint32_t data_end_addr; uint32_t data_end_addr;
#if defined(ENABLE_EMULATION) #if defined(ESP_PLATFORM)
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)
part0 = esp_partition_find_first(0x40, 0x1, "part0"); 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); 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; data_start_addr = 0;
@ -215,6 +208,13 @@ void low_flash_init() {
data_start_addr += XIP_BASE; data_start_addr += XIP_BASE;
data_end_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 #endif
flash_set_bounds(data_start_addr, data_end_addr); flash_set_bounds(data_start_addr, data_end_addr);
} }

View file

@ -39,7 +39,7 @@ uint32_t led_get_mode() {
} }
void led_blinking_task() { void led_blinking_task() {
#ifndef ENABLE_EMULATION #if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
static uint32_t start_ms = 0; static uint32_t start_ms = 0;
static uint32_t stop_ms = 0; static uint32_t stop_ms = 0;
static uint32_t last_led_update_ms = 0; static uint32_t last_led_update_ms = 0;
@ -81,7 +81,7 @@ void led_blinking_task() {
} }
void led_off_all() { void led_off_all() {
#ifndef ENABLE_EMULATION #if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
led_driver->set_color(LED_COLOR_OFF, 0, 0); led_driver->set_color(LED_COLOR_OFF, 0, 0);
#endif #endif
} }
@ -110,8 +110,8 @@ led_driver_t led_driver_dummy = {
void led_init() { void led_init() {
led_driver = &led_driver_dummy; led_driver = &led_driver_dummy;
#ifndef ENABLE_EMULATION #if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
# // Guess default driver // Guess default driver
#ifdef PICO_DEFAULT_LED_PIN #ifdef PICO_DEFAULT_LED_PIN
led_driver = &led_driver_pico; led_driver = &led_driver_pico;
#elif defined(CYW43_WL_GPIO_LED_PIN) #elif defined(CYW43_WL_GPIO_LED_PIN)

View file

@ -23,6 +23,7 @@ uint8_t gpio = PICO_DEFAULT_LED_PIN;
uint8_t gpio = 0; uint8_t gpio = 0;
#endif #endif
#ifdef PICO_PLATFORM
void led_driver_init_pico() { void led_driver_init_pico() {
if (phy_data.led_gpio_present) { if (phy_data.led_gpio_present) {
gpio = phy_data.led_gpio; gpio = phy_data.led_gpio;
@ -40,3 +41,5 @@ led_driver_t led_driver_pico = {
.init = led_driver_init_pico, .init = led_driver_init_pico,
.set_color = led_driver_color_pico, .set_color = led_driver_color_pico,
}; };
#endif

View file

@ -17,6 +17,7 @@
#include "pico_keys.h" #include "pico_keys.h"
#ifdef PICO_PLATFORM
#ifdef PIMORONI_TINY2040 #ifdef PIMORONI_TINY2040
#define LED_R_PIN TINY2040_LED_R_PIN #define LED_R_PIN TINY2040_LED_R_PIN
#define LED_G_PIN TINY2040_LED_G_PIN #define LED_G_PIN TINY2040_LED_G_PIN
@ -64,3 +65,5 @@ led_driver_t led_driver_pimoroni = {
.init = led_driver_init_pimoroni, .init = led_driver_init_pimoroni,
.set_color = led_driver_color_pimoroni, .set_color = led_driver_color_pimoroni,
}; };
#endif

View file

@ -16,6 +16,8 @@
*/ */
#include "pico_keys.h" #include "pico_keys.h"
#ifdef PICO_PLATFORM
#include "hardware/pio.h" #include "hardware/pio.h"
#include "hardware/clocks.h" #include "hardware/clocks.h"
@ -132,3 +134,5 @@ led_driver_t led_driver_ws2812 = {
.init = led_driver_init_ws2812, .init = led_driver_init_ws2812,
.set_color = led_driver_color_ws2812, .set_color = led_driver_color_ws2812,
}; };
#endif

View file

@ -17,19 +17,20 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "pico_keys.h"
// Pico #if !defined(ENABLE_EMULATION)
#include "tusb.h"
#endif
#if defined(ENABLE_EMULATION) #if defined(ENABLE_EMULATION)
#include "emulation.h" #include "emulation.h"
#elif defined(ESP_PLATFORM) #elif defined(ESP_PLATFORM)
#include "tusb.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "rom/gpio.h" #include "rom/gpio.h"
#include "tinyusb.h" #include "tinyusb.h"
#include "esp_efuse.h" #include "esp_efuse.h"
#define BOOT_PIN GPIO_NUM_0 #define BOOT_PIN GPIO_NUM_0
#else #elif defined(PICO_PLATFORM)
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include "bsp/board.h" #include "bsp/board.h"
#include "pico/aon_timer.h" #include "pico/aon_timer.h"
@ -40,7 +41,6 @@
#endif #endif
#include "random.h" #include "random.h"
#include "pico_keys.h"
#include "apdu.h" #include "apdu.h"
#include "usb.h" #include "usb.h"
extern void do_flash(); extern void do_flash();
@ -152,7 +152,7 @@ bool picok_board_button_read() {
int boot_state = gpio_get_level(BOOT_PIN); int boot_state = gpio_get_level(BOOT_PIN);
return boot_state == 0; return boot_state == 0;
} }
#else #elif defined(PICO_PLATFORM)
bool __no_inline_not_in_flash_func(picok_get_bootsel_button)() { bool __no_inline_not_in_flash_func(picok_get_bootsel_button)() {
const uint CS_PIN_INDEX = 1; const uint CS_PIN_INDEX = 1;
@ -187,10 +187,13 @@ bool __no_inline_not_in_flash_func(picok_get_bootsel_button)() {
return button_state; return button_state;
} }
uint32_t picok_board_button_read(void) bool picok_board_button_read(void) {
{
return picok_get_bootsel_button(); return picok_get_bootsel_button();
} }
#else
bool picok_board_button_read(void) {
return true; // always unpressed
}
#endif #endif
bool button_pressed_state = false; bool button_pressed_state = false;
uint32_t button_pressed_time = 0; uint32_t button_pressed_time = 0;
@ -294,7 +297,7 @@ 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
#ifdef ENABLE_EMULATION #ifndef PICO_PLATFORM
#define pico_get_unique_board_id(a) memset(a, 0, sizeof(*(a))) #define pico_get_unique_board_id(a) memset(a, 0, sizeof(*(a)))
#endif #endif
int main(void) { int main(void) {
@ -306,7 +309,7 @@ int main(void) {
} }
#ifndef ENABLE_EMULATION #ifndef ENABLE_EMULATION
#ifndef ESP_PLATFORM #ifdef PICO_PLATFORM
board_init(); board_init();
stdio_init_all(); stdio_init_all();
#endif #endif

View file

@ -24,7 +24,6 @@
#include "file.h" #include "file.h"
#include "led/led.h" #include "led/led.h"
#if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM)
#include <stdint.h> #include <stdint.h>
#if !defined(MIN) #if !defined(MIN)
#if defined(_MSC_VER) #if defined(_MSC_VER)
@ -46,7 +45,7 @@
_a > _b ? _a : _b; }) _a > _b ? _a : _b; })
#endif #endif
#endif #endif
#else #if defined(PICO_PLATFORM)
#include "pico/unique_id.h" #include "pico/unique_id.h"
#endif #endif
#include <string.h> #include <string.h>
@ -56,7 +55,7 @@
#include <stdbool.h> #include <stdbool.h>
#elif defined(ESP_PLATFORM) #elif defined(ESP_PLATFORM)
#include "esp_compat.h" #include "esp_compat.h"
#else #elif defined(PICO_PLATFORM)
#include "pico/util/queue.h" #include "pico/util/queue.h"
#endif #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) #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 #define PICO_UNIQUE_BOARD_ID_SIZE_BYTES 8
typedef struct { uint8_t id[PICO_UNIQUE_BOARD_ID_SIZE_BYTES]; } pico_unique_board_id_t; typedef struct { uint8_t id[PICO_UNIQUE_BOARD_ID_SIZE_BYTES]; } pico_unique_board_id_t;
#endif #endif

View file

@ -18,20 +18,21 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#if defined(ENABLE_EMULATION)
#include <stdbool.h> #if defined(PICO_PLATFORM)
#include <stdlib.h> #include "pico/stdlib.h"
#include <time.h> #include "hwrng.h"
#include "emulation.h" #include "bsp/board.h"
#include "pico/rand.h"
#elif (ESP_PLATFORM) #elif (ESP_PLATFORM)
#include "bootloader_random.h" #include "bootloader_random.h"
#include "esp_random.h" #include "esp_random.h"
#include "esp_compat.h" #include "esp_compat.h"
#else #else
#include "pico/stdlib.h" #include <stdbool.h>
#include "hwrng.h" #include <stdlib.h>
#include "bsp/board.h" #include <time.h>
#include "pico/rand.h" #include "board.h"
#endif #endif
void hwrng_start() { void hwrng_start() {
@ -57,14 +58,14 @@ static int ep_process() {
} }
uint64_t word = 0x0; uint64_t word = 0x0;
#if defined(ENABLE_EMULATION) #if defined(PICO_PLATFORM)
word = rand(); word = get_rand_64();
word <<= 32;
word |= rand();
#elif defined(ESP_PLATFORM) #elif defined(ESP_PLATFORM)
esp_fill_random((uint8_t *)&word, sizeof(word)); esp_fill_random((uint8_t *)&word, sizeof(word));
#else #else
word = get_rand_64(); word = rand();
word <<= 32;
word |= rand();
#endif #endif
random_word ^= word ^ board_millis(); random_word ^= word ^ board_millis();
random_word *= 0x00000100000001B3; random_word *= 0x00000100000001B3;
@ -169,15 +170,13 @@ uint32_t neug_get() {
void neug_wait_full() { void neug_wait_full() {
struct rng_rb *rb = &the_ring_buffer; struct rng_rb *rb = &the_ring_buffer;
#ifndef ENABLE_EMULATION
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
uint8_t core = xTaskGetCurrentTaskHandle() == hcore1 ? 1 : 0; uint8_t core = xTaskGetCurrentTaskHandle() == hcore1 ? 1 : 0;
#else #elif defined(PICO_PLATFORM)
uint core = get_core_num(); uint core = get_core_num();
#endif
#endif #endif
while (!rb->full) { while (!rb->full) {
#ifndef ENABLE_EMULATION #if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
if (core == 1) { if (core == 1) {
sleep_ms(1); sleep_ms(1);
} }

View file

@ -21,7 +21,7 @@
#define NEUG_PRE_LOOP 32 #define NEUG_PRE_LOOP 32
#include <stdlib.h> #include <stdlib.h>
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) #if defined(PICO_PLATFORM)
#include "pico/stdlib.h" #include "pico/stdlib.h"
#endif #endif

View file

@ -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)); 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); TU_ASSERT(usbd_edpt_open(rhport, desc_ep), 0);
uint8_t msg[] = { 0x50, 0x03 }; uint8_t msg[] = { 0x50, 0x03 };
#if defined(PICO_PLATFORM) || defined(ESP_PLATFORM)
usbd_edpt_xfer(rhport, desc_ep->bEndpointAddress, msg, sizeof(msg)); 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 #else
vendord_open(rhport, (tusb_desc_interface_t *)itf_vendor, max_len); vendord_open(rhport, (tusb_desc_interface_t *)itf_vendor, max_len);
#endif #endif

View file

@ -15,6 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "pico_keys.h"
#include "emulation.h" #include "emulation.h"
#include <stdio.h> #include <stdio.h>
#ifndef _MSC_VER #ifndef _MSC_VER
@ -41,7 +42,6 @@ typedef int socklen_t;
#include <errno.h> #include <errno.h>
#include <time.h> #include <time.h>
#include "pico_keys.h"
#include "apdu.h" #include "apdu.h"
#include "usb.h" #include "usb.h"
#include "ccid/ccid.h" #include "ccid/ccid.h"

View file

@ -20,11 +20,8 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#ifdef _MSC_VER #include "queue.h"
#include <windows.h> #include "board.h"
#else
#include <sys/time.h>
#endif
#include <stdbool.h> #include <stdbool.h>
#define USB_BUFFER_SIZE 2048 #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 driver_write_emul(uint8_t itf, const uint8_t *buffer, uint16_t buffer_size);
extern uint16_t emul_read(uint8_t itf); 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 #ifdef USB_ITF_HID
typedef uint8_t hid_report_type_t; typedef uint8_t hid_report_type_t;
#endif #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); extern bool tud_hid_n_report(uint8_t itf, uint8_t report_id, const uint8_t *buffer, uint32_t n);
#endif #endif
#include <pthread.h>
#include <semaphore.h>
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_ #endif // _EMULATION_H_

View file

@ -15,18 +15,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "pico_keys.h"
#ifndef ENABLE_EMULATION #ifndef ENABLE_EMULATION
#include "tusb.h" #include "tusb.h"
#ifndef ESP_PLATFORM #if defined(PICO_PLATFORM)
#include "bsp/board.h" #include "bsp/board.h"
#else #elif defined(ESP_PLATFORM)
static portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED; static portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED;
#endif #endif
#else #else
#include "emulation.h" #include "emulation.h"
#endif #endif
#include "ctap_hid.h" #include "ctap_hid.h"
#include "pico_keys.h"
#include "pico_keys_version.h" #include "pico_keys_version.h"
#include "apdu.h" #include "apdu.h"
#include "usb.h" #include "usb.h"
@ -418,7 +418,7 @@ int driver_process_usb_packet_hid(uint16_t read) {
} }
last_packet_time = 0; last_packet_time = 0;
memcpy(ctap_resp, ctap_req, sizeof(CTAPHID_FRAME)); 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 sleep_ms(1000); //For blinking the device during 1 seg
#endif #endif
driver_write_hid(ITF_HID_CTAP, (const uint8_t *)ctap_resp, 64); driver_write_hid(ITF_HID_CTAP, (const uint8_t *)ctap_resp, 64);

View file

@ -58,6 +58,9 @@ extern "C" {
#define CFG_TUSB_OS OPT_OS_PICO #define CFG_TUSB_OS OPT_OS_PICO
#elif CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3 #elif CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
#define CFG_TUSB_OS OPT_OS_FREERTOS #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
#endif #endif

View file

@ -16,14 +16,12 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include "pico_keys.h"
// Pico #if defined(PICO_PLATFORM)
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
#include "pico/stdlib.h" #include "pico/stdlib.h"
#include "pico/multicore.h" #include "pico/multicore.h"
#include "bsp/board.h" #include "bsp/board.h"
#endif #endif
#include "pico_keys.h"
#include "usb.h" #include "usb.h"
#include "apdu.h" #include "apdu.h"
#ifndef ENABLE_EMULATION #ifndef ENABLE_EMULATION

View file

@ -22,8 +22,11 @@
#include "emulation.h" #include "emulation.h"
#elif defined(ESP_PLATFORM) #elif defined(ESP_PLATFORM)
#include "esp_compat.h" #include "esp_compat.h"
#else #elif defined(PICO_PLATFORM)
#include "pico/util/queue.h" #include "pico/util/queue.h"
#else
#include "queue.h"
#include "board.h"
#endif #endif
#include "compat.h" #include "compat.h"

View file

@ -15,9 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "pico_keys.h"
#include "tusb.h" #include "tusb.h"
#include "usb_descriptors.h" #include "usb_descriptors.h"
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) #if defined(PICO_PLATFORM)
#include "pico/unique_id.h" #include "pico/unique_id.h"
#endif #endif
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
@ -25,7 +26,6 @@
#endif #endif
#include "pico_keys_version.h" #include "pico_keys_version.h"
#include "usb.h" #include "usb.h"
#include "pico_keys.h"
#ifndef USB_VID #ifndef USB_VID
#define USB_VID 0xFEFF #define USB_VID 0xFEFF