move implementation to s2

This commit is contained in:
Tomasz Duda 2024-10-07 23:17:45 +02:00
parent 9a4dc7a3e1
commit eed6ae721e
5 changed files with 11 additions and 25 deletions

View file

@ -7,7 +7,7 @@ from esphome.const import (
from esphome.components.esp32.const import ( from esphome.components.esp32.const import (
KEY_ESP32, KEY_ESP32,
KEY_VARIANT, KEY_VARIANT,
VARIANT_ESP32S3, VARIANT_ESP32S2,
) )
CODEOWNERS = ["@tomaszduda23"] CODEOWNERS = ["@tomaszduda23"]
@ -16,7 +16,7 @@ CONF_USB_DEVICE_ID = "usb_device_id"
def _validate_variant(value): def _validate_variant(value):
variant = CORE.data[KEY_ESP32][KEY_VARIANT] 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}") raise cv.Invalid(f"USB device is unsupported by ESP32 variant {variant}")
return value return value

View file

@ -1,13 +1,11 @@
#if defined(USE_ESP32_VARIANT_ESP32S3) #if defined(USE_ESP32_VARIANT_ESP32S2)
#include "usb_device.h" #include "usb_device.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#ifdef USE_ARDUINO #ifdef USE_ARDUINO
#if ARDUINO_USB_MODE #include "USB.h"
#include "HWCDC.h"
#endif
#else #else
#include "esp32s3/rom/usb/usb_dc.h" #include "esp32s2/rom/usb/usb_dc.h"
#endif #endif
namespace esphome { namespace esphome {
@ -15,13 +13,17 @@ namespace usb_device {
static const char *const TAG = "usb_device"; static const char *const TAG = "usb_device";
#ifndef USE_ARDUINO
usb_dc_status_code g_cb_status; usb_dc_status_code g_cb_status;
void status_callback(enum usb_dc_status_code cb_status, uint8_t *param) { void status_callback(enum usb_dc_status_code cb_status, uint8_t *param) {
g_cb_status = cb_status; g_cb_status = cb_status;
} }
#endif
void UsbDevice::update() { void UsbDevice::update() {
#ifndef USE_ARDUINO
ESP_LOGD(TAG, "update %d", g_cb_status); ESP_LOGD(TAG, "update %d", g_cb_status);
#endif
#ifdef USE_BINARY_SENSOR #ifdef USE_BINARY_SENSOR
if (configured_ != nullptr) { if (configured_ != nullptr) {
configured_->publish_state(get_configured_()); configured_->publish_state(get_configured_());
@ -42,25 +44,9 @@ void UsbDevice::set_configured_binary_sensor(binary_sensor::BinarySensor *sensor
#endif #endif
bool UsbDevice::get_configured_() { 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 #ifdef USE_ARDUINO
// based on defines in HWCDC.cpp return USB;
#if ARDUINO_USB_MODE
#if ARDUINO_USB_CDC_ON_BOOT // Serial used for USB CDC
return Serial;
#else #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 #endif
return false; return false;
} }

View file

@ -1,5 +1,5 @@
#pragma once #pragma once
#if defined(USE_ESP32_VARIANT_ESP32S3) #if defined(USE_ESP32_VARIANT_ESP32S2)
#include "esphome/core/defines.h" #include "esphome/core/defines.h"
#include "esphome/core/component.h" #include "esphome/core/component.h"
#ifdef USE_BINARY_SENSOR #ifdef USE_BINARY_SENSOR