Fix build for non-pico boards.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
e55014cfb3
commit
4edc506759
22 changed files with 108 additions and 204 deletions
|
|
@ -19,7 +19,7 @@
|
|||
#define _APDU_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||
#if defined(PICO_PLATFORM)
|
||||
#include "pico/stdlib.h"
|
||||
#endif
|
||||
#include "compat.h"
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
#define _ASN1_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||
#if defined(PICO_PLATFORM)
|
||||
#include "pico/stdlib.h"
|
||||
#else
|
||||
#include <stdint.h>
|
||||
|
|
|
|||
|
|
@ -15,10 +15,9 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if defined(ENABLE_EMULATION)
|
||||
#elif defined(ESP_PLATFORM)
|
||||
#if defined(ESP_PLATFORM)
|
||||
#include "esp_compat.h"
|
||||
#else
|
||||
#elif defined(PICO_PLATFORM)
|
||||
#include <pico/unique_id.h>
|
||||
#endif
|
||||
#include "mbedtls/md.h"
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
#define _FILE_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||
#if defined(PICO_PLATFORM)
|
||||
#include "pico/stdlib.h"
|
||||
#else
|
||||
#include <stdbool.h>
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#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 <stdio.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -32,29 +32,29 @@
|
|||
#include "pico/bootrom.h"
|
||||
#include "boot/picobin.h"
|
||||
#else
|
||||
#ifdef _MSC_VER
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#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 <windows.h>
|
||||
#include <io.h>
|
||||
#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 <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include "emulation.h"
|
||||
#include "queue.h"
|
||||
#endif
|
||||
#endif
|
||||
#define FLASH_SECTOR_SIZE 4096
|
||||
|
|
@ -63,7 +63,7 @@
|
|||
uint8_t *map = NULL;
|
||||
#include <fcntl.h>
|
||||
#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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
23
src/main.c
23
src/main.c
|
|
@ -17,19 +17,20 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#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
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
#include "file.h"
|
||||
#include "led/led.h"
|
||||
#if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM)
|
||||
#include <stdint.h>
|
||||
#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 <string.h>
|
||||
|
|
@ -56,7 +55,7 @@
|
|||
#include <stdbool.h>
|
||||
#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
|
||||
|
|
|
|||
|
|
@ -18,20 +18,21 @@
|
|||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#if defined(ENABLE_EMULATION)
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#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 <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
#define NEUG_PRE_LOOP 32
|
||||
|
||||
#include <stdlib.h>
|
||||
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||
#if defined(PICO_PLATFORM)
|
||||
#include "pico/stdlib.h"
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pico_keys.h"
|
||||
#include "emulation.h"
|
||||
#include <stdio.h>
|
||||
#ifndef _MSC_VER
|
||||
|
|
@ -41,7 +42,6 @@ typedef int socklen_t;
|
|||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "pico_keys.h"
|
||||
#include "apdu.h"
|
||||
#include "usb.h"
|
||||
#include "ccid/ccid.h"
|
||||
|
|
|
|||
|
|
@ -20,11 +20,8 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#ifdef _MSC_VER
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#include "queue.h"
|
||||
#include "board.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#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 <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_
|
||||
|
|
|
|||
|
|
@ -15,18 +15,18 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -16,14 +16,12 @@
|
|||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// 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
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue