From eed6ae721ea2fd4a4706be53b5252768926790c6 Mon Sep 17 00:00:00 2001 From: Tomasz Duda Date: Mon, 7 Oct 2024 23:17:45 +0200 Subject: [PATCH] move implementation to s2 --- esphome/components/usb_device/__init__.py | 4 +-- esphome/components/usb_device/usb_device.cpp | 30 +++++-------------- esphome/components/usb_device/usb_device.h | 2 +- ...p32-s3-ard.yaml => test.esp32-s2-ard.yaml} | 0 ...p32-s3-idf.yaml => test.esp32-s2-idf.yaml} | 0 5 files changed, 11 insertions(+), 25 deletions(-) rename tests/components/usb_device/{test.esp32-s3-ard.yaml => test.esp32-s2-ard.yaml} (100%) rename tests/components/usb_device/{test.esp32-s3-idf.yaml => test.esp32-s2-idf.yaml} (100%) diff --git a/esphome/components/usb_device/__init__.py b/esphome/components/usb_device/__init__.py index 36e8235488..9c9961bb55 100644 --- a/esphome/components/usb_device/__init__.py +++ b/esphome/components/usb_device/__init__.py @@ -7,7 +7,7 @@ from esphome.const import ( from esphome.components.esp32.const import ( KEY_ESP32, KEY_VARIANT, - VARIANT_ESP32S3, + VARIANT_ESP32S2, ) CODEOWNERS = ["@tomaszduda23"] @@ -16,7 +16,7 @@ CONF_USB_DEVICE_ID = "usb_device_id" def _validate_variant(value): variant = CORE.data[KEY_ESP32][KEY_VARIANT] - if variant not in [VARIANT_ESP32S3]: + if variant not in [VARIANT_ESP32S2]: raise cv.Invalid(f"USB device is unsupported by ESP32 variant {variant}") return value diff --git a/esphome/components/usb_device/usb_device.cpp b/esphome/components/usb_device/usb_device.cpp index 88390b6d13..06d5ab937d 100644 --- a/esphome/components/usb_device/usb_device.cpp +++ b/esphome/components/usb_device/usb_device.cpp @@ -1,13 +1,11 @@ -#if defined(USE_ESP32_VARIANT_ESP32S3) +#if defined(USE_ESP32_VARIANT_ESP32S2) #include "usb_device.h" #include "esphome/core/log.h" #ifdef USE_ARDUINO -#if ARDUINO_USB_MODE -#include "HWCDC.h" -#endif +#include "USB.h" #else -#include "esp32s3/rom/usb/usb_dc.h" +#include "esp32s2/rom/usb/usb_dc.h" #endif namespace esphome { @@ -15,13 +13,17 @@ namespace usb_device { static const char *const TAG = "usb_device"; +#ifndef USE_ARDUINO usb_dc_status_code g_cb_status; void status_callback(enum usb_dc_status_code cb_status, uint8_t *param) { g_cb_status = cb_status; } +#endif void UsbDevice::update() { +#ifndef USE_ARDUINO ESP_LOGD(TAG, "update %d", g_cb_status); +#endif #ifdef USE_BINARY_SENSOR if (configured_ != nullptr) { configured_->publish_state(get_configured_()); @@ -42,25 +44,9 @@ void UsbDevice::set_configured_binary_sensor(binary_sensor::BinarySensor *sensor #endif bool UsbDevice::get_configured_() { -// ESP32: -// - Arduino framework does not support USB_SERIAL_JTAG. -// ESP32-S3 -// - Arduino CDC logger is based on HWCDC. - #ifdef USE_ARDUINO -// based on defines in HWCDC.cpp -#if ARDUINO_USB_MODE -#if ARDUINO_USB_CDC_ON_BOOT // Serial used for USB CDC - return Serial; + return USB; #else - return USBSerial; -#endif -#else -// this is subject of change by other components so make sure that we won't fail to report silently -#error Not implemented -#endif -#else - #endif return false; } diff --git a/esphome/components/usb_device/usb_device.h b/esphome/components/usb_device/usb_device.h index 22d5b4fa23..df3d9de0fc 100644 --- a/esphome/components/usb_device/usb_device.h +++ b/esphome/components/usb_device/usb_device.h @@ -1,5 +1,5 @@ #pragma once -#if defined(USE_ESP32_VARIANT_ESP32S3) +#if defined(USE_ESP32_VARIANT_ESP32S2) #include "esphome/core/defines.h" #include "esphome/core/component.h" #ifdef USE_BINARY_SENSOR diff --git a/tests/components/usb_device/test.esp32-s3-ard.yaml b/tests/components/usb_device/test.esp32-s2-ard.yaml similarity index 100% rename from tests/components/usb_device/test.esp32-s3-ard.yaml rename to tests/components/usb_device/test.esp32-s2-ard.yaml diff --git a/tests/components/usb_device/test.esp32-s3-idf.yaml b/tests/components/usb_device/test.esp32-s2-idf.yaml similarity index 100% rename from tests/components/usb_device/test.esp32-s3-idf.yaml rename to tests/components/usb_device/test.esp32-s2-idf.yaml