Roll back to 2d3a5a9 + CONFIG_BT_ENABLED + double-init patch

This commit is contained in:
ash
2026-07-01 07:06:45 +00:00
parent 01eaf9ce80
commit 9ba48b3f9c
6 changed files with 221 additions and 121 deletions
+21 -21
View File
@@ -184,29 +184,29 @@ def patch_nimble_device():
with open(dev_path, 'r') as f:
content = f.read()
# v1.4.3 code has ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));
# Arduino framework inits controller but does NOT enable it.
# We must enable even if init returns INVALID_STATE (already init'd).
old_block = (
'ESP_ERROR_CHECK(esp_bt_controller_init(&bt_cfg));\n'
' ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));\n'
' ESP_ERROR_CHECK(esp_nimble_hci_init());'
)
new_block = (
'esp_err_t __bt_err = esp_bt_controller_init(&bt_cfg);\n'
' if (__bt_err == ESP_OK || __bt_err == ESP_ERR_INVALID_STATE) {\n'
' ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));\n'
' }\n'
' ESP_ERROR_CHECK(esp_nimble_hci_init());'
)
# Handle both init outcomes: skip if already initialized, but always try to enable.
patterns = [
(r'(\s*)ESP_ERROR_CHECK\(esp_bt_controller_init\(&bt_cfg\)\);\s*'
r'\1ESP_ERROR_CHECK\(esp_bt_controller_enable\(ESP_BT_MODE_BLE\)\);\s*'
r'\1ESP_ERROR_CHECK\(esp_nimble_hci_init\(\)\);',
r'\1esp_err_t __bt_err = esp_bt_controller_init(&bt_cfg);\n'
r'\1if (__bt_err == ESP_OK || __bt_err == ESP_ERR_INVALID_STATE) {\n'
r'\1 ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));\n'
r'\1}\n'
r'\1ESP_ERROR_CHECK(esp_nimble_hci_init());')
]
if old_block in content:
content = content.replace(old_block, new_block)
with open(dev_path, 'w') as f:
f.write(content)
print(" Patched esp_bt_controller_init to skip if already initialized")
else:
print(" WARNING: Could not find init pattern in NimBLEDevice.cpp (may already be patched)")
for pattern, replacement in patterns:
new_content = re.sub(pattern, replacement, content)
if new_content != content:
content = new_content
with open(dev_path, 'w') as f:
f.write(content)
print(" Patched esp_bt_controller_init to skip if already initialized")
return
print(" WARNING: Could not find init pattern in NimBLEDevice.cpp")
patch_usb_ids()