From 21b3bcd0c0a67f314109047f5660620eb8dc1eee Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Wed, 28 Sep 2022 23:52:45 +0200 Subject: [PATCH] pkg/tinyusb: add ESP32-S2 and ESP32-S3 support --- pkg/tinyusb/Makefile | 3 +++ pkg/tinyusb/Makefile.dep | 7 ++++++ pkg/tinyusb/Makefile.include | 8 +++++++ pkg/tinyusb/hw/hw_esp32.c | 41 ++++++++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 pkg/tinyusb/hw/hw_esp32.c diff --git a/pkg/tinyusb/Makefile b/pkg/tinyusb/Makefile index af9b4ef35d..1e2ff1b4a7 100644 --- a/pkg/tinyusb/Makefile +++ b/pkg/tinyusb/Makefile @@ -67,3 +67,6 @@ tinyusb_device: tinyusb_host: $(QQ)"$(MAKE)" -C $(PSRC)/host -f $(RIOTBASE)/Makefile.base MODULE=$@ + +tinyusb_portable_espressif: + $(QQ)"$(MAKE)" -C $(PSRC)/portable/espressif/esp32sx -f $(RIOTBASE)/Makefile.base MODULE=$@ diff --git a/pkg/tinyusb/Makefile.dep b/pkg/tinyusb/Makefile.dep index 564c3782db..5821fd3beb 100644 --- a/pkg/tinyusb/Makefile.dep +++ b/pkg/tinyusb/Makefile.dep @@ -55,6 +55,13 @@ ifneq (,$(filter tinyusb_class_video,$(USEMODULE))) FEATURES_REQUIRED += tinyusb_device endif +# tinyUSB hardware driver selection +ifneq (,$(filter esp32s2 esp32s3,$(CPU_FAM))) + USEMODULE += tinyusb_portable_espressif +else + $(error CPU family not supported) +endif + # other module dependencies USEMODULE += periph_usbdev_clk USEMODULE += sema diff --git a/pkg/tinyusb/Makefile.include b/pkg/tinyusb/Makefile.include index 0055efc30f..55c2ef5581 100644 --- a/pkg/tinyusb/Makefile.include +++ b/pkg/tinyusb/Makefile.include @@ -6,6 +6,14 @@ INCLUDES += -I$(PKGDIRBASE)/tinyusb/src CFLAGS += -DCFG_TUSB_OS=OPT_OS_CUSTOM CFLAGS += -Wno-format-nonliteral +ifeq (esp32s2,$(CPU_FAM)) + CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S2 +else ifeq (esp32s3,$(CPU_FAM)) + CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_ESP32S3 +else + $(error CPU family not supported) +endif + ifneq (,$(filter tinyusb_class_net_ecm_rndis,$(USEMODULE))) INCLUDES += -I$(PKGDIRBASE)/tinyusb/lib/networking endif diff --git a/pkg/tinyusb/hw/hw_esp32.c b/pkg/tinyusb/hw/hw_esp32.c new file mode 100644 index 0000000000..a0ebe80cfe --- /dev/null +++ b/pkg/tinyusb/hw/hw_esp32.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2022 Gunar Schorcht + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup pkg_tinyusb + * @brief + * @{ + * + * @brief tinyUSB hardware driver for ESP32x SoCs + * @author Gunar Schorcht + */ + +#include + +#include "esp_err.h" +#include "esp_private/usb_phy.h" + +#include "log.h" + +static usb_phy_handle_t phy_hdl; + +int tinyusb_hw_init(void) +{ + usb_phy_config_t phy_conf = { + .controller = USB_PHY_CTRL_OTG, + .otg_mode = USB_OTG_MODE_DEVICE, + .target = USB_PHY_TARGET_INT, /* only internal PHY supported */ + }; + + if (usb_new_phy(&phy_conf, &phy_hdl) != ESP_OK) { + LOG_TAG_ERROR("usb", "Install USB PHY failed"); + return -ENODEV; + } + + return 0; +}