diff --git a/pico_keys_sdk_import.cmake b/pico_keys_sdk_import.cmake
index 0819921..5425498 100644
--- a/pico_keys_sdk_import.cmake
+++ b/pico_keys_sdk_import.cmake
@@ -86,6 +86,8 @@ endif(USB_ITF_CCID)
add_definitions(-DDEBUG_APDU=${DEBUG_APDU})
if (NOT ESP_PLATFORM)
add_definitions(-DMBEDTLS_CONFIG_FILE="${CMAKE_CURRENT_LIST_DIR}/config/mbedtls_config.h")
+else()
+add_definitions(-DCFG_TUSB_CONFIG_FILE="../../src/usb/tusb_config.h")
endif()
message(STATUS "USB VID/PID: ${USB_VID}:${USB_PID}")
diff --git a/sdkconfig.defaults b/sdkconfig.defaults
index 12e3b2f..e029fb7 100755
--- a/sdkconfig.defaults
+++ b/sdkconfig.defaults
@@ -1,8 +1,9 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration
#
+IGNORE_UNKNOWN_FILES_FOR_MANAGED_COMPONENTS=1
+
CONFIG_TINYUSB=y
-CONFIG_TINYUSB_MSC_ENABLED=y
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
@@ -11,6 +12,9 @@ CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_WL_SECTOR_SIZE_512=y
CONFIG_WL_SECTOR_MODE_PERF=y
-CONFIG_TINYUSB_CDC_ENABLED=y
+CONFIG_TINYUSB_VENDOR_ENABLED=y
+CONFIG_TINYUSB_VENDOR_COUNT=2
+CONFIG_TINYUSB_HID_ENABLED=y
+CONFIG_TINYUSB_HID_COUNT=2
# CONFIG_TINYUSB_DESC_USE_DEFAULT_PID is not set
CONFIG_TINYUSB_DESC_CUSTOM_PID=0x4001
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9e427f1..b7b3e1f 100755
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,5 @@
idf_component_register(
SRCS ${INTERNAL_SOURCES}
- INCLUDE_DIRS . fs rng usb
- PRIV_REQUIRES bootloader_support esp_partition
+ INCLUDE_DIRS . fs rng usb ../mbedtls/include
+ REQUIRES bootloader_support esp_partition tinyusb
)
diff --git a/src/crypto_utils.c b/src/crypto_utils.c
index 3c8d53a..aadb069 100644
--- a/src/crypto_utils.c
+++ b/src/crypto_utils.c
@@ -15,7 +15,10 @@
* along with this program. If not, see .
*/
-#ifndef ENABLE_EMULATION
+#if defined(ENABLE_EMULATION)
+#elif defined(ESP_PLATFORM)
+#include "esp_compat.h"
+#else
#include
#endif
#include "mbedtls/md.h"
diff --git a/src/crypto_utils.h b/src/crypto_utils.h
index 2a8d99b..9c729d5 100644
--- a/src/crypto_utils.h
+++ b/src/crypto_utils.h
@@ -18,10 +18,6 @@
#ifndef _CRYPTO_UTILS_H_
#define _CRYPTO_UTILS_H_
-#include "stdlib.h"
-#ifndef ENABLE_EMULATION
-#include "pico/stdlib.h"
-#endif
#include "mbedtls/ecp.h"
#include "mbedtls/md.h"
diff --git a/src/eac.h b/src/eac.h
index 6343906..f178a01 100644
--- a/src/eac.h
+++ b/src/eac.h
@@ -18,10 +18,6 @@
#ifndef _EAC_H_
#define _EAC_H_
-#include
-#ifndef ENABLE_EMULATION
-#include "pico/stdlib.h"
-#endif
#include "pico_keys.h"
typedef enum MSE_protocol {
diff --git a/src/fs/low_flash.c b/src/fs/low_flash.c
index 2383678..0b40636 100644
--- a/src/fs/low_flash.c
+++ b/src/fs/low_flash.c
@@ -39,6 +39,8 @@
#include "mman.h"
#else
#ifdef ESP_PLATFORM
+#include "esp_compat.h"
+esp_partition_t part0;
#else
#include
#include
diff --git a/src/idf_component.yml b/src/idf_component.yml
index 06b047d..c91e372 100755
--- a/src/idf_component.yml
+++ b/src/idf_component.yml
@@ -1,4 +1,3 @@
## IDF Component Manager Manifest File
dependencies:
- espressif/esp_tinyusb: "^1.2"
- idf: "^5.0"
+ espressif/tinyusb: "^0.15.0"
diff --git a/src/main.c b/src/main.c
index 269b30c..2531918 100644
--- a/src/main.c
+++ b/src/main.c
@@ -25,28 +25,11 @@
#endif
#include "emulation.h"
#elif defined(ESP_PLATFORM)
+#include "tusb.h"
#else
#include "pico/stdlib.h"
#endif
-// For memcpy
-#include
-
-#ifndef ENABLE_EMULATION
-// Include descriptor struct definitions
-//#include "usb_common.h"
-// USB register definitions from pico-sdk
-#include "hardware/regs/usb.h"
-// USB hardware struct definitions from pico-sdk
-#include "hardware/structs/usb.h"
-// For interrupt enable and numbers
-#include "hardware/irq.h"
-// For resetting the USB controller
-#include "hardware/resets.h"
-
-#include "pico/multicore.h"
-#endif
-
#include "random.h"
#include "pico_keys.h"
#include "apdu.h"
@@ -101,11 +84,14 @@ static inline void ws2812_program_init(PIO pio,
}
#endif
-#ifndef ENABLE_EMULATION
+#if defined(ENABLE_EMULATION)
+#else
#include "usb.h"
+#ifndef ESP_PLATFORM
#include "hardware/rtc.h"
#include "bsp/board.h"
#endif
+#endif
extern void do_flash();
extern void low_flash_init();
@@ -196,6 +182,11 @@ uint32_t board_millis() {
}
#else
+#ifdef ESP_PLATFORM
+bool board_button_read() {
+ return true;
+}
+#endif
bool button_pressed_state = false;
uint32_t button_pressed_time = 0;
uint8_t button_press = 0;
@@ -289,7 +280,9 @@ void led_off_all() {
}
void init_rtc() {
-#ifndef ENABLE_EMULATION
+#if defined(ENABLE_EMULATION)
+#elif defined(ESP_PLATFORM)
+#else
rtc_init();
datetime_t dt = {
.year = 2020,
@@ -345,15 +338,16 @@ void core0_loop() {
#ifdef ESP_PLATFORM
TaskHandle_t hcore0 = NULL, hcore1 = NULL;
-void app_main(void) {
+int app_main() {
#else
int main(void) {
#endif
#ifndef ENABLE_EMULATION
usb_init();
-
+#ifndef ESP_PLATFORM
board_init();
stdio_init_all();
+#endif
#ifdef PIMORONI_TINY2040
gpio_init(TINY2040_LED_R_PIN);
diff --git a/src/rng/random.h b/src/rng/random.h
index b0a5d7b..5899c91 100644
--- a/src/rng/random.h
+++ b/src/rng/random.h
@@ -21,9 +21,6 @@
#include
#include
-#ifndef ENABLE_EMULATION
-#include "pico/stdlib.h"
-#endif
void random_init(void);
void random_fini(void);
diff --git a/src/usb/ccid/ccid.c b/src/usb/ccid/ccid.c
index e54c0d8..3bb6974 100644
--- a/src/usb/ccid/ccid.c
+++ b/src/usb/ccid/ccid.c
@@ -15,28 +15,11 @@
* along with this program. If not, see .
*/
-#include
-
-// Pico
-#include "pico/stdlib.h"
-
-// For memcpy
-#include
-
-// Include descriptor struct definitions
-//#include "usb_common.h"
-// USB register definitions from pico-sdk
-#include "hardware/regs/usb.h"
-// USB hardware struct definitions from pico-sdk
-#include "hardware/structs/usb.h"
-// For interrupt enable and numbers
-#include "hardware/irq.h"
-// For resetting the USB controller
-#include "hardware/resets.h"
-
#include "random.h"
#include "pico_keys.h"
+#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
#include "hardware/rtc.h"
+#endif
#include "tusb.h"
#include "ccid.h"
#include "device/usbd_pvt.h"
diff --git a/src/usb/tusb_config.h b/src/usb/tusb_config.h
index 6422571..c52fdb5 100644
--- a/src/usb/tusb_config.h
+++ b/src/usb/tusb_config.h
@@ -26,8 +26,6 @@
#ifndef _TUSB_CONFIG_H_
#define _TUSB_CONFIG_H_
-#include "usb.h"
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -64,7 +62,7 @@ extern "C" {
#endif
#ifndef CFG_TUSB_OS
-//#define CFG_TUSB_OS OPT_OS_PICO
+#define CFG_TUSB_OS OPT_OS_FREERTOS
#endif
#ifndef CFG_TUSB_DEBUG
@@ -115,7 +113,7 @@ extern "C" {
#ifdef USB_ITF_CCID
#define CFG_TUD_VENDOR 2
#else
-#define CFG_TUD_VENDOR 0
+#define CFG_TUD_VENDOR 2
#endif
// HID buffer size Should be sufficient to hold ID (if any) + Data
diff --git a/src/usb/usb.c b/src/usb/usb.c
index 2a67451..45bc825 100644
--- a/src/usb/usb.c
+++ b/src/usb/usb.c
@@ -153,7 +153,7 @@ void usb_clear_rx(uint8_t itf) {
#define USB_BCD 0x0200
-#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
+#if !defined(ENABLE_EMULATION)
queue_t usb_to_card_q;
queue_t card_to_usb_q;
#endif