diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e760225a04..389097c6ac1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -288,7 +288,7 @@ set(includedirs variants/${CONFIG_ARDUINO_VARIANT}/ cores/esp32/ ${ARDUINO_LIBRA set(srcs ${CORE_SRCS} ${ARDUINO_LIBRARIES_SRCS}) set(priv_includes cores/esp32/libb64) set(requires spi_flash esp_partition mbedtls wifi_provisioning wpa_supplicant esp_adc esp_eth http_parser) -set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support bt esp_hid ${ARDUINO_LIBRARIES_REQUIRES}) +set(priv_requires fatfs nvs_flash app_update spiffs bootloader_support bt esp_hid usb ${ARDUINO_LIBRARIES_REQUIRES}) idf_component_register(INCLUDE_DIRS ${includedirs} PRIV_INCLUDE_DIRS ${priv_includes} SRCS ${srcs} REQUIRES ${requires} PRIV_REQUIRES ${priv_requires}) diff --git a/cores/esp32/esp32-hal-tinyusb.c b/cores/esp32/esp32-hal-tinyusb.c index bab17a3980f..c6ad7460ac4 100644 --- a/cores/esp32/esp32-hal-tinyusb.c +++ b/cores/esp32/esp32-hal-tinyusb.c @@ -22,7 +22,6 @@ #include "rom/gpio.h" -#include "hal/usb_hal.h" #include "hal/gpio_ll.h" #include "hal/clk_gate_ll.h" @@ -63,6 +62,10 @@ typedef struct { bool external_phy; } tinyusb_config_t; +#if __has_include("hal/usb_hal.h") + +#include "hal/usb_hal.h" + static bool usb_otg_deinit(void *busptr) { // Once USB OTG is initialized, its GPIOs are assigned and it shall never be deinited // except when S3 swithicng usb from cdc to jtag while resetting to bootrom @@ -101,10 +104,67 @@ static void configure_pins(usb_hal_context_t *usb) { } } -esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) { - usb_hal_context_t hal = {.use_external_phy = config->external_phy}; +esp_err_t init_usb_hal(bool external_phy) { + usb_hal_context_t hal = {.use_external_phy = external_phy}; usb_hal_init(&hal); configure_pins(&hal); + return ESP_OK; +} + +esp_err_t deinit_usb_hal() { + return ESP_OK; +} + +#elif __has_include("esp_private/usb_phy.h") + +#include "esp_private/usb_phy.h" + +static usb_phy_handle_t phy_handle = NULL; + +esp_err_t init_usb_hal(bool external_phy) { + esp_err_t ret = ESP_OK; + usb_phy_config_t phy_config = { + .controller = USB_PHY_CTRL_OTG, + .target = USB_PHY_TARGET_INT, + .otg_mode = USB_OTG_MODE_DEVICE, + .otg_speed = USB_PHY_SPEED_FULL, + .ext_io_conf = NULL, + .otg_io_conf = NULL, + }; + + ret = usb_new_phy(&phy_config, &phy_handle); + if (ret != ESP_OK) { + log_e("Failed to init USB PHY"); + } + return ret; +} + +esp_err_t deinit_usb_hal() { + esp_err_t ret = ESP_OK; + if (phy_handle) { + ret = usb_del_phy(phy_handle); + if (ret != ESP_OK) { + log_e("Failed to deinit USB PHY"); + } + } + return ret; +} + +#else + +#error No way to initialize USP PHY + +void init_usb_hal(bool external_phy) { + return ESP_OK; +} + +void deinit_usb_hal() { + return ESP_OK; +} +#endif + +esp_err_t tinyusb_driver_install(const tinyusb_config_t *config) { + init_usb_hal(config->external_phy); if (!tusb_init()) { log_e("Can't initialize the TinyUSB stack."); return ESP_FAIL; @@ -420,6 +480,7 @@ static void hw_cdc_reset_handler(void *arg) { static void usb_switch_to_cdc_jtag() { // Disable USB-OTG + deinit_usb_hal(); periph_ll_reset(PERIPH_USB_MODULE); //periph_ll_enable_clk_clear_rst(PERIPH_USB_MODULE); periph_ll_disable_clk_set_rst(PERIPH_USB_MODULE); diff --git a/libraries/TFLiteMicro/examples/micro_speech/README.md b/libraries/TFLiteMicro/examples/micro_speech/README.md deleted file mode 100644 index ed293bf2e06..00000000000 --- a/libraries/TFLiteMicro/examples/micro_speech/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# Micro Speech Example - -This example shows how to run a 20 kB model that can recognize 2 keywords, -"yes" and "no", from speech data. - -The application listens to its surroundings with a microphone and indicates -when it has detected a word by displaying data on a screen. - -## Deploy to ESP32 - -The sample has been tested on ESP-IDF version `release/v4.2` and `release/v4.4` with the following devices: -- [ESP32-DevKitC](http://esp-idf.readthedocs.io/en/latest/get-started/get-started-devkitc.html) -- [ESP32-S3-DevKitC](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s3/hw-reference/esp32s3/user-guide-devkitc-1.html) -- [ESP-EYE](https://github.com/espressif/esp-who/blob/master/docs/en/get-started/ESP-EYE_Getting_Started_Guide.md) - -### Sample output - - * When a keyword is detected you will see following output sample output on the log screen: - -``` -Heard yes () at