ble testing

This commit is contained in:
J. Nick Koston
2025-06-07 15:42:41 -05:00
parent 4f1953c581
commit 123d4c3e0d
3 changed files with 102 additions and 6 deletions

View File

@@ -1,10 +1,12 @@
import os
from esphome import pins
import esphome.codegen as cg
from esphome.components import esp32
import esphome.config_validation as cv
from esphome.const import (
CONF_CLK_PIN,
CONF_ID,
CONF_RESET_PIN,
CONF_VARIANT,
KEY_CORE,
@@ -13,6 +15,10 @@ from esphome.const import (
from esphome.core import CORE
CODEOWNERS = ["@swoboda1337"]
AUTO_LOAD = ["esp32"]
esp32_hosted_ns = cg.esphome_ns.namespace("esp32_hosted")
ESP32Hosted = esp32_hosted_ns.class_("ESP32Hosted", cg.Component)
CONF_ACTIVE_HIGH = "active_high"
CONF_CMD_PIN = "cmd_pin"
@@ -22,9 +28,16 @@ CONF_D2_PIN = "d2_pin"
CONF_D3_PIN = "d3_pin"
CONF_SLOT = "slot"
VARIANTS_WITHOUT_WIFI = {
esp32.VARIANT_ESP32H2,
esp32.VARIANT_ESP32P4,
}
CONFIG_SCHEMA = cv.All(
cv.Schema(
{
cv.GenerateID(): cv.declare_id(ESP32Hosted),
cv.Required(CONF_VARIANT): cv.one_of(*esp32.VARIANTS, upper=True),
cv.Optional(CONF_ACTIVE_HIGH, default=True): cv.boolean,
cv.Required(CONF_CLK_PIN): pins.internal_gpio_output_pin_number,
@@ -41,6 +54,9 @@ CONFIG_SCHEMA = cv.All(
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
framework_ver: cv.Version = CORE.data[KEY_CORE][KEY_FRAMEWORK_VERSION]
if config[CONF_ACTIVE_HIGH]:
@@ -94,12 +110,13 @@ async def to_code(config):
os.environ["ESP_IDF_VERSION"] = f"{framework_ver.major}.{framework_ver.minor}"
esp32.add_idf_component(
name="esp_wifi_remote",
repo="https://github.com/espressif/esp-wifi-remote.git",
path="components/esp_wifi_remote",
ref="wifi_remote-v0.10.2",
)
if config[CONF_VARIANT] not in VARIANTS_WITHOUT_WIFI:
esp32.add_idf_component(
name="esp_wifi_remote",
repo="https://github.com/espressif/esp-wifi-remote.git",
path="components/esp_wifi_remote",
ref="wifi_remote-v0.10.2",
)
esp32.add_extra_script(
"post",

View File

@@ -0,0 +1,53 @@
#include "esp32_hosted.h"
#include "esphome/core/log.h"
#ifdef USE_ESP32
#ifdef USE_ESP32_BLE
#include <esp_bluedroid_hci.h>
#include <hosted_hci_bluedroid.h>
#endif
namespace esphome {
namespace esp32_hosted {
static const char *const TAG = "esp32_hosted";
void ESP32Hosted::setup() {
ESP_LOGCONFIG(TAG, "Setting up ESP32 Hosted...");
#ifdef USE_ESP32_BLE
// Initialize Bluetooth if esp32_ble component is enabled
this->init_bluetooth_();
#else
ESP_LOGD(TAG, "Bluetooth support disabled (esp32_ble not included)");
#endif
}
void ESP32Hosted::dump_config() { ESP_LOGCONFIG(TAG, "ESP32 Hosted:"); }
#ifdef USE_ESP32_BLE
void ESP32Hosted::init_bluetooth_() {
ESP_LOGD(TAG, "Initializing Bluetooth...");
// Initialize TRANSPORT first
hosted_hci_bluedroid_open();
// Get HCI driver operations
esp_bluedroid_hci_driver_operations_t operations = {
.send = hosted_hci_bluedroid_send,
.check_send_available = hosted_hci_bluedroid_check_send_available,
.register_host_callback = hosted_hci_bluedroid_register_host_callback,
};
// Attach HCI driver
esp_bluedroid_attach_hci_driver(&operations);
ESP_LOGD(TAG, "Bluetooth initialized successfully");
}
#endif
} // namespace esp32_hosted
} // namespace esphome
#endif // USE_ESP32

View File

@@ -0,0 +1,26 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/helpers.h"
#ifdef USE_ESP32
namespace esphome {
namespace esp32_hosted {
class ESP32Hosted : public Component {
public:
void setup() override;
void dump_config() override;
float get_setup_priority() const override { return setup_priority::HARDWARE; }
protected:
#ifdef USE_ESP32_BLE
void init_bluetooth_();
#endif
};
} // namespace esp32_hosted
} // namespace esphome
#endif // USE_ESP32