Add BT controller diagnostics, init BLE before USB MIDI

This commit is contained in:
ash
2026-06-30 06:43:58 +00:00
parent 8a36296043
commit 2db09b76bf
4 changed files with 81 additions and 9 deletions
+60 -3
View File
@@ -1,5 +1,6 @@
import os
import fileinput
import re
def patch_usb_ids():
# Find the core's pins_arduino.h for ESP32-S3 DevKitC-1
@@ -15,7 +16,7 @@ def patch_usb_ids():
pins_file = os.path.join(core_variants, "esp32s3", "pins_arduino.h")
if os.path.exists(pins_file):
print(f"Patching {pins_file} with Launchpad X VID/PID")
print(f"Patching {pins_file} with JOC Midi USB descriptors")
# Read and replace
with open(pins_file, 'r') as f:
@@ -46,4 +47,60 @@ def patch_usb_ids():
else:
print(f"WARNING: Could not find pins_arduino.h at {pins_file}")
patch_usb_ids()
def patch_sdkconfig_bt():
# Find the precompiled sdkconfig.h for this board variant
sdk_dir = os.path.expanduser(
"~/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32s3/qio_opi/include"
)
alt_name = os.path.join(os.environ.get("PLATFORMIO_PACKAGES_DIR", ""),
"framework-arduinoespressif32/tools/sdk/esp32s3/qio_opi/include")
if not os.path.exists(sdk_dir):
sdk_dir = alt_name
sdkconfig_file = os.path.join(sdk_dir, "sdkconfig.h")
if not os.path.exists(sdkconfig_file):
print(f"WARNING: sdkconfig.h not found at {sdkconfig_file}")
return
print(f"Patching {sdkconfig_file} with BLE/NimBLE support")
with open(sdkconfig_file, 'r') as f:
content = f.read()
defines = {
"CONFIG_BT_ENABLED": 1,
"CONFIG_BT_NIMBLE_ENABLED": 1,
"CONFIG_BTDM_CTRL_MODE_BLE_ONLY": 1,
"CONFIG_BT_NIMBLE_MAX_CONNECTIONS": 1,
"CONFIG_BT_NIMBLE_TASK_STACK_SIZE": 6144,
"CONFIG_BT_NIMBLE_ROLE_PERIPHERAL": 1,
"CONFIG_BT_NIMBLE_ROLE_BROADCASTER": 1,
}
changed = False
for name, value in defines.items():
pattern = re.compile(
r'^[#/]*\s*#?\s*(define\s+' + re.escape(name) + r'\b).*$',
re.MULTILINE
)
if pattern.search(content):
# Already defined, replace the line
content = pattern.sub(r'#define ' + name + ' ' + str(value), content)
changed = True
elif f'#define {name}' not in content:
# Not present at all, add it
content += f'\n#define {name} {value}'
changed = True
if changed:
with open(sdkconfig_file, 'w') as f:
f.write(content)
print("BLE/NimBLE sdkconfig patched successfully")
else:
print("BLE/NimBLE already configured in sdkconfig")
patch_usb_ids()
patch_sdkconfig_bt()