mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 23:21:54 +00:00 
			
		
		
		
	Revert "[esp32_ble] Add PHY configuration and default to 1M for compatibility"
This reverts commit 5c44cd8962.
			
			
This commit is contained in:
		| @@ -117,22 +117,9 @@ CONF_BLE_ID = "ble_id" | |||||||
| CONF_IO_CAPABILITY = "io_capability" | CONF_IO_CAPABILITY = "io_capability" | ||||||
| CONF_ADVERTISING_CYCLE_TIME = "advertising_cycle_time" | CONF_ADVERTISING_CYCLE_TIME = "advertising_cycle_time" | ||||||
| CONF_DISABLE_BT_LOGS = "disable_bt_logs" | CONF_DISABLE_BT_LOGS = "disable_bt_logs" | ||||||
| CONF_PREFERRED_PHY = "preferred_phy" |  | ||||||
|  |  | ||||||
| NO_BLUETOOTH_VARIANTS = [const.VARIANT_ESP32S2] | NO_BLUETOOTH_VARIANTS = [const.VARIANT_ESP32S2] | ||||||
|  |  | ||||||
| # ESP32 variants that support BLE |  | ||||||
| BLE_VARIANTS = { |  | ||||||
|     const.VARIANT_ESP32, |  | ||||||
|     const.VARIANT_ESP32C3, |  | ||||||
|     const.VARIANT_ESP32S3, |  | ||||||
|     const.VARIANT_ESP32C6, |  | ||||||
|     const.VARIANT_ESP32H2, |  | ||||||
| } |  | ||||||
|  |  | ||||||
| # ESP32 variants that support 2M PHY |  | ||||||
| BLE_2M_PHY_VARIANTS = BLE_VARIANTS - {const.VARIANT_ESP32} |  | ||||||
|  |  | ||||||
| esp32_ble_ns = cg.esphome_ns.namespace("esp32_ble") | esp32_ble_ns = cg.esphome_ns.namespace("esp32_ble") | ||||||
| ESP32BLE = esp32_ble_ns.class_("ESP32BLE", cg.Component) | ESP32BLE = esp32_ble_ns.class_("ESP32BLE", cg.Component) | ||||||
|  |  | ||||||
| @@ -153,13 +140,6 @@ IO_CAPABILITY = { | |||||||
|     "display_yes_no": IoCapability.IO_CAP_IO, |     "display_yes_no": IoCapability.IO_CAP_IO, | ||||||
| } | } | ||||||
|  |  | ||||||
| BLEPhy = esp32_ble_ns.enum("BLEPhy") |  | ||||||
| BLE_PHY_OPTIONS = { |  | ||||||
|     "1m": BLEPhy.BLE_PHY_1M, |  | ||||||
|     "2m": BLEPhy.BLE_PHY_2M, |  | ||||||
|     "auto": BLEPhy.BLE_PHY_AUTO, |  | ||||||
| } |  | ||||||
|  |  | ||||||
| esp_power_level_t = cg.global_ns.enum("esp_power_level_t") | esp_power_level_t = cg.global_ns.enum("esp_power_level_t") | ||||||
|  |  | ||||||
| TX_POWER_LEVELS = { | TX_POWER_LEVELS = { | ||||||
| @@ -173,18 +153,6 @@ TX_POWER_LEVELS = { | |||||||
|     9: esp_power_level_t.ESP_PWR_LVL_P9, |     9: esp_power_level_t.ESP_PWR_LVL_P9, | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| def validate_phy(value: str) -> str: |  | ||||||
|     """Validate PHY selection based on ESP32 variant.""" |  | ||||||
|     variant = get_esp32_variant() |  | ||||||
|     if value == "2m" and variant not in BLE_2M_PHY_VARIANTS: |  | ||||||
|         raise cv.Invalid( |  | ||||||
|             f"2M PHY is not supported on {variant}. " |  | ||||||
|             f"Only supported on: {', '.join(sorted(BLE_2M_PHY_VARIANTS))}" |  | ||||||
|         ) |  | ||||||
|     return value |  | ||||||
|  |  | ||||||
|  |  | ||||||
| CONFIG_SCHEMA = cv.Schema( | CONFIG_SCHEMA = cv.Schema( | ||||||
|     { |     { | ||||||
|         cv.GenerateID(): cv.declare_id(ESP32BLE), |         cv.GenerateID(): cv.declare_id(ESP32BLE), | ||||||
| @@ -199,10 +167,6 @@ CONFIG_SCHEMA = cv.Schema( | |||||||
|         cv.SplitDefault(CONF_DISABLE_BT_LOGS, esp32_idf=True): cv.All( |         cv.SplitDefault(CONF_DISABLE_BT_LOGS, esp32_idf=True): cv.All( | ||||||
|             cv.only_with_esp_idf, cv.boolean |             cv.only_with_esp_idf, cv.boolean | ||||||
|         ), |         ), | ||||||
|         cv.Optional(CONF_PREFERRED_PHY, default="1m"): cv.All( |  | ||||||
|             cv.enum(BLE_PHY_OPTIONS, lower=True), |  | ||||||
|             validate_phy, |  | ||||||
|         ), |  | ||||||
|     } |     } | ||||||
| ).extend(cv.COMPONENT_SCHEMA) | ).extend(cv.COMPONENT_SCHEMA) | ||||||
|  |  | ||||||
| @@ -273,7 +237,6 @@ async def to_code(config): | |||||||
|     cg.add(var.set_enable_on_boot(config[CONF_ENABLE_ON_BOOT])) |     cg.add(var.set_enable_on_boot(config[CONF_ENABLE_ON_BOOT])) | ||||||
|     cg.add(var.set_io_capability(config[CONF_IO_CAPABILITY])) |     cg.add(var.set_io_capability(config[CONF_IO_CAPABILITY])) | ||||||
|     cg.add(var.set_advertising_cycle_time(config[CONF_ADVERTISING_CYCLE_TIME])) |     cg.add(var.set_advertising_cycle_time(config[CONF_ADVERTISING_CYCLE_TIME])) | ||||||
|     cg.add(var.set_preferred_phy(config[CONF_PREFERRED_PHY])) |  | ||||||
|     if (name := config.get(CONF_NAME)) is not None: |     if (name := config.get(CONF_NAME)) is not None: | ||||||
|         cg.add(var.set_name(name)) |         cg.add(var.set_name(name)) | ||||||
|     await cg.register_component(var, config) |     await cg.register_component(var, config) | ||||||
|   | |||||||
| @@ -23,35 +23,6 @@ namespace esphome::esp32_ble { | |||||||
|  |  | ||||||
| static const char *const TAG = "esp32_ble"; | static const char *const TAG = "esp32_ble"; | ||||||
|  |  | ||||||
| static const char *phy_mode_to_string(BLEPhy phy) { |  | ||||||
|   switch (phy) { |  | ||||||
|     case BLE_PHY_1M: |  | ||||||
|       return "1M"; |  | ||||||
|     case BLE_PHY_2M: |  | ||||||
|       return "2M"; |  | ||||||
|     case BLE_PHY_AUTO: |  | ||||||
|       return "AUTO"; |  | ||||||
|     default: |  | ||||||
|       return "UNKNOWN"; |  | ||||||
|   } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32C6) || \ |  | ||||||
|     defined(USE_ESP32_VARIANT_ESP32H2) |  | ||||||
| static uint8_t phy_mode_to_mask(BLEPhy phy) { |  | ||||||
|   switch (phy) { |  | ||||||
|     case BLE_PHY_1M: |  | ||||||
|       return ESP_BLE_GAP_PHY_1M_PREF_MASK; |  | ||||||
|     case BLE_PHY_2M: |  | ||||||
|       return ESP_BLE_GAP_PHY_2M_PREF_MASK; |  | ||||||
|     case BLE_PHY_AUTO: |  | ||||||
|       return ESP_BLE_GAP_PHY_1M_PREF_MASK | ESP_BLE_GAP_PHY_2M_PREF_MASK; |  | ||||||
|     default: |  | ||||||
|       return ESP_BLE_GAP_PHY_1M_PREF_MASK;  // Default to 1M |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| void ESP32BLE::setup() { | void ESP32BLE::setup() { | ||||||
|   global_ble = this; |   global_ble = this; | ||||||
|   if (!ble_pre_setup_()) { |   if (!ble_pre_setup_()) { | ||||||
| @@ -237,23 +208,6 @@ bool ESP32BLE::ble_setup_() { | |||||||
|     return false; |     return false; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Configure PHY settings |  | ||||||
| #if defined(USE_ESP32_VARIANT_ESP32C3) || defined(USE_ESP32_VARIANT_ESP32S3) || defined(USE_ESP32_VARIANT_ESP32C6) || \ |  | ||||||
|     defined(USE_ESP32_VARIANT_ESP32H2) |  | ||||||
|   // Only newer ESP32 variants support PHY configuration |  | ||||||
|   if (this->preferred_phy_ != BLE_PHY_AUTO) { |  | ||||||
|     uint8_t phy_mask = phy_mode_to_mask(this->preferred_phy_); |  | ||||||
|  |  | ||||||
|     err = esp_ble_gap_set_preferred_default_phy(phy_mask, phy_mask); |  | ||||||
|     if (err != ESP_OK) { |  | ||||||
|       ESP_LOGW(TAG, "esp_ble_gap_set_preferred_default_phy failed: %d", err); |  | ||||||
|       // Not a fatal error, continue |  | ||||||
|     } else { |  | ||||||
|       ESP_LOGD(TAG, "Set preferred PHY to %s", phy_mode_to_string(this->preferred_phy_)); |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
|   // BLE takes some time to be fully set up, 200ms should be more than enough |   // BLE takes some time to be fully set up, 200ms should be more than enough | ||||||
|   delay(200);  // NOLINT |   delay(200);  // NOLINT | ||||||
|  |  | ||||||
| @@ -563,10 +517,8 @@ void ESP32BLE::dump_config() { | |||||||
|     ESP_LOGCONFIG(TAG, |     ESP_LOGCONFIG(TAG, | ||||||
|                   "BLE:\n" |                   "BLE:\n" | ||||||
|                   "  MAC address: %s\n" |                   "  MAC address: %s\n" | ||||||
|                   "  IO Capability: %s\n" |                   "  IO Capability: %s", | ||||||
|                   "  Preferred PHY: %s", |                   format_mac_address_pretty(mac_address).c_str(), io_capability_s); | ||||||
|                   format_mac_address_pretty(mac_address).c_str(), io_capability_s, |  | ||||||
|                   phy_mode_to_string(this->preferred_phy_)); |  | ||||||
|   } else { |   } else { | ||||||
|     ESP_LOGCONFIG(TAG, "Bluetooth stack is not enabled"); |     ESP_LOGCONFIG(TAG, "Bluetooth stack is not enabled"); | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -55,12 +55,6 @@ enum IoCapability { | |||||||
|   IO_CAP_KBDISP = ESP_IO_CAP_KBDISP, |   IO_CAP_KBDISP = ESP_IO_CAP_KBDISP, | ||||||
| }; | }; | ||||||
|  |  | ||||||
| enum BLEPhy : uint8_t { |  | ||||||
|   BLE_PHY_1M = 0x01, |  | ||||||
|   BLE_PHY_2M = 0x02, |  | ||||||
|   BLE_PHY_AUTO = 0x03, |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| enum BLEComponentState : uint8_t { | enum BLEComponentState : uint8_t { | ||||||
|   /** Nothing has been initialized yet. */ |   /** Nothing has been initialized yet. */ | ||||||
|   BLE_COMPONENT_STATE_OFF = 0, |   BLE_COMPONENT_STATE_OFF = 0, | ||||||
| @@ -104,7 +98,6 @@ class BLEStatusEventHandler { | |||||||
| class ESP32BLE : public Component { | class ESP32BLE : public Component { | ||||||
|  public: |  public: | ||||||
|   void set_io_capability(IoCapability io_capability) { this->io_cap_ = (esp_ble_io_cap_t) io_capability; } |   void set_io_capability(IoCapability io_capability) { this->io_cap_ = (esp_ble_io_cap_t) io_capability; } | ||||||
|   void set_preferred_phy(BLEPhy phy) { this->preferred_phy_ = phy; } |  | ||||||
|  |  | ||||||
|   void set_advertising_cycle_time(uint32_t advertising_cycle_time) { |   void set_advertising_cycle_time(uint32_t advertising_cycle_time) { | ||||||
|     this->advertising_cycle_time_ = advertising_cycle_time; |     this->advertising_cycle_time_ = advertising_cycle_time; | ||||||
| @@ -177,7 +170,6 @@ class ESP32BLE : public Component { | |||||||
|   // 1-byte aligned members (grouped together to minimize padding) |   // 1-byte aligned members (grouped together to minimize padding) | ||||||
|   BLEComponentState state_{BLE_COMPONENT_STATE_OFF};  // 1 byte (uint8_t enum) |   BLEComponentState state_{BLE_COMPONENT_STATE_OFF};  // 1 byte (uint8_t enum) | ||||||
|   bool enable_on_boot_{};                             // 1 byte |   bool enable_on_boot_{};                             // 1 byte | ||||||
|   BLEPhy preferred_phy_{BLE_PHY_1M};                  // 1 byte (uint8_t enum) |  | ||||||
| }; | }; | ||||||
|  |  | ||||||
| // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) | // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user