Skip to content

Bluetooth and Wi-Fi improvements - #622

Merged
KenVanHoeylandt merged 16 commits into
mainfrom
enable-bluetoot-in-dts
Aug 25, 2026
Merged

Bluetooth and Wi-Fi improvements#622
KenVanHoeylandt merged 16 commits into
mainfrom
enable-bluetoot-in-dts

Conversation

@KenVanHoeylandt

@KenVanHoeylandt KenVanHoeylandt commented Aug 25, 2026

Copy link
Copy Markdown
Contributor
  • Enable BT by default in DTS, and create separate radio on/of functionality (like recent Wi-Fi changes)
  • Bluetooth event handling now uses queued subscriptions, improving event delivery and application responsiveness.
  • Improved synchronization of Bluetooth advertising, connections, HID, MIDI, and SPP operations.
  • Enhanced cleanup during Bluetooth shutdown and subscription removal.
  • Clarified Bluetooth start and stop behavior.
  • Improved wifi driver subscription stability to prevent endless loops

@coderabbitai

coderabbitai Bot commented Aug 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request replaces Bluetooth callback registration with caller-owned event subscriptions, bounded event queues, task-event notifications, and polling APIs. The ESP32 BLE driver manages subscription registration, event delivery, cleanup, and GAP profile synchronization. Tactility uses a dedicated event thread, while Bluetooth applications poll subscriptions directly. Wi-Fi subscription cleanup tracks closed and constructed states. Multiple ESP32 device-tree nodes no longer disable BLE explicitly. Documentation and kernel symbol exports were updated.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 55 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the two main areas changed: Bluetooth functionality and Wi-Fi event-subscription stability. Although broad, it is concise and related to the pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch enable-bluetoot-in-dts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
TactilityKernel/source/drivers/bluetooth.cpp (1)

83-89: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Destroy ring_mutex even when the driver reports no matching subscription.

The header documents ERROR_NOT_FOUND as a valid outcome of event_unsubscribe. On that path the mutex stays constructed, and the caller cannot release it because internal is private. Each such call leaks one mutex object.

♻️ Proposed change
 error_t bluetooth_event_unsubscribe(struct Device* device, struct BtEventSubscription* sub) {
     error_t result = BT_API(device)->event_unsubscribe(device, sub);
-    if (result == ERROR_NONE) {
-        mutex_destruct(&sub->internal.ring_mutex);
-    }
+    mutex_destruct(&sub->internal.ring_mutex);
     return result;
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9e6082e1-d9f5-4f79-9f52-a9fe36a1a6f6

📥 Commits

Reviewing files that changed from the base of the PR and between ab75d20 and 3b4b580.

📒 Files selected for processing (45)
  • Devices/btt-panda-touch/bigtreetech,panda-touch.dts
  • Devices/cyd-4848s040c/cyd,4848s040c.dts
  • Devices/cyd-8048s043c/cyd,8048s043c.dts
  • Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts
  • Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts
  • Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts
  • Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts
  • Devices/es3c28p/es3c28p.dts
  • Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts
  • Devices/guition-jc8048w550c/guition,jc8048w550c.dts
  • Devices/heltec-wifi-lora-32-v3/heltec,wifi-lora-32-v3.dts
  • Devices/lilygo-tdeck-plus/lilygo,tdeck-plus.dts
  • Devices/lilygo-tdeck/lilygo,tdeck.dts
  • Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts
  • Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts
  • Devices/lilygo-thmi/lilygo,thmi.dts
  • Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts
  • Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts
  • Devices/m5stack-cardputer/m5stack,cardputer.dts
  • Devices/m5stack-cores3/m5stack,cores3.dts
  • Devices/m5stack-papers3/m5stack,papers3.dts
  • Devices/m5stack-stackchan/m5stack,stackchan.dts
  • Devices/m5stack-sticks3/m5stack,sticks3.dts
  • Devices/m5stack-tab5/m5stack,tab5.dts
  • Devices/tulip-4r11/tulip-4r11.dts
  • Devices/unphone/unphone.dts
  • Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts
  • Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts
  • Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts
  • Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts
  • Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts
  • Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts
  • Platforms/platform-esp32/private/bluetooth/esp32_ble_internal.h
  • Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp
  • Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_hid.cpp
  • Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_midi.cpp
  • Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_spp.cpp
  • Tactility/Include/Tactility/bluetooth/Bluetooth.h
  • Tactility/Private/Tactility/app/btmanage/BtManagePrivate.h
  • Tactility/Source/app/btmanage/BtManage.cpp
  • Tactility/Source/app/btpeersettings/BtPeerSettings.cpp
  • Tactility/Source/bluetooth/Bluetooth.cpp
  • TactilityKernel/include/tactility/drivers/bluetooth.h
  • TactilityKernel/source/drivers/bluetooth.cpp
  • TactilityKernel/source/symbols.c
💤 Files with no reviewable changes (32)
  • Devices/cyd-8048s043c/cyd,8048s043c.dts
  • Devices/tulip-4r11/tulip-4r11.dts
  • Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts
  • Devices/m5stack-cores3/m5stack,cores3.dts
  • Devices/m5stack-papers3/m5stack,papers3.dts
  • Devices/cyd-4848s040c/cyd,4848s040c.dts
  • Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts
  • Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts
  • Devices/unphone/unphone.dts
  • Devices/btt-panda-touch/bigtreetech,panda-touch.dts
  • Devices/es3c28p/es3c28p.dts
  • Devices/heltec-wifi-lora-32-v3/heltec,wifi-lora-32-v3.dts
  • Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts
  • Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts
  • Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts
  • Devices/lilygo-tdeck-plus/lilygo,tdeck-plus.dts
  • Devices/m5stack-cardputer/m5stack,cardputer.dts
  • Devices/guition-jc8048w550c/guition,jc8048w550c.dts
  • Devices/lilygo-thmi/lilygo,thmi.dts
  • Devices/lilygo-tdeck/lilygo,tdeck.dts
  • Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts
  • Devices/m5stack-tab5/m5stack,tab5.dts
  • Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts
  • Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts
  • Devices/m5stack-sticks3/m5stack,sticks3.dts
  • Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts
  • Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts
  • Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts
  • Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts
  • Devices/m5stack-stackchan/m5stack,stackchan.dts
  • Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts
  • Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp Outdated
Comment thread Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp
Comment thread Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp
Comment thread Tactility/Source/app/btmanage/BtManage.cpp
Comment thread Tactility/Source/bluetooth/Bluetooth.cpp
@KenVanHoeylandt KenVanHoeylandt changed the title Enable bluetoot in dts Bluetooth and Wi-Fi improvements Aug 25, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
Tactility/Source/bluetooth/Bluetooth.cpp (1)

363-368: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Cancel deferred bridge actions before disabling the radio.

bt_event_bridge() posts radio-on and scan-finished work to getMainDispatcher(). stopBtEventThread() joins only the polling thread. It does not drain or cancel posted tasks. A queued task can run after Line [365] disables the radio and start scanning or a profile.

Add a radio-generation check to each deferred action, or synchronize with the dispatcher before disabling the radio.

Tactility/Source/app/btmanage/BtManage.cpp (1)

176-184: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Handle subscription failure before entering the event-driven UI.

If bluetooth_event_subscribe() fails, ctx.btDevice remains null, but appMain() still creates the window and accepts Bluetooth controls. No Bluetooth events are polled, so the state and view cannot update. Return after cleanup or disable event-dependent controls when subscription fails.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 51959d84-eee5-48c7-a07f-3f8acfc9f017

📥 Commits

Reviewing files that changed from the base of the PR and between 3b4b580 and e28e754.

📒 Files selected for processing (14)
  • Documentation/ideas.md
  • Platforms/platform-esp32/private/bluetooth/esp32_ble_internal.h
  • Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp
  • Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_hid.cpp
  • Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_midi.cpp
  • Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_spp.cpp
  • Platforms/platform-esp32/source/drivers/esp32_wifi.cpp
  • Platforms/platform-posix/source/drivers/mock_wifi.cpp
  • Tactility/Source/app/btmanage/BtManage.cpp
  • Tactility/Source/bluetooth/Bluetooth.cpp
  • TactilityKernel/include/tactility/drivers/bluetooth.h
  • TactilityKernel/include/tactility/drivers/wifi.h
  • TactilityKernel/source/drivers/bluetooth.cpp
  • TactilityKernel/source/drivers/wifi.cpp

Included review availability: Your plan provides up to 4 included reviews per hour; 2 remain after this review.

Comment thread Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp
Comment thread Platforms/platform-esp32/source/drivers/esp32_wifi.cpp
Comment thread Tactility/Source/bluetooth/Bluetooth.cpp
Comment thread Tactility/Source/bluetooth/Bluetooth.cpp
Comment thread TactilityKernel/source/drivers/bluetooth.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d69c0f8b-8f09-45a2-bd2d-92d724551925

📥 Commits

Reviewing files that changed from the base of the PR and between e28e754 and 9ea0029.

📒 Files selected for processing (5)
  • Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp
  • TactilityKernel/include/tactility/drivers/bluetooth.h
  • TactilityKernel/include/tactility/drivers/wifi.h
  • TactilityKernel/source/drivers/bluetooth.cpp
  • TactilityKernel/source/drivers/wifi.cpp

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.

Comment thread Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp (2)

1019-1025: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Check for an already-constructed subscription before reinitializing it.

bluetooth_event_subscribe() constructs and resets sub->internal.ring_mutex before calling this handler. A second subscribe of the same live sub reaches this duplicate branch afterward. The wrapper then marks the subscription unconstructed and destructs the mutex, while ctx->subscriptions still points to sub. The next event or poll uses a destroyed mutex.

Move the constructed-state check before initialization in TactilityKernel/source/drivers/bluetooth.cpp, or reject an already-constructed subscription without modifying its fields. The full-list traversal fixes the earlier cycle issue but does not make this rejection safe. (raw.githubusercontent.com)


1235-1257: 🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Wake blocked waiters before releasing a closed subscription bit.

Teardown sets closed, then calls task_event_group_release_bit(). That function clears and unclaims the bit; it does not signal it. A caller blocked in task_event_group_wait() can remain blocked forever and cannot call bluetooth_event_poll() to observe the closed state.

Keep the bit claimed until the final unsubscribe, signal it after setting closed, and release it from the unsubscribe path. Signaling and immediately releasing is not sufficient because release clears the event bit. (raw.githubusercontent.com)


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6e58321e-2314-4e4d-9023-35d78a5020dc

📥 Commits

Reviewing files that changed from the base of the PR and between 9ea0029 and b4608ee.

📒 Files selected for processing (1)
  • Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.

Comment thread Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp
Comment thread Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp
@KenVanHoeylandt
KenVanHoeylandt merged commit 0ee2415 into main Aug 25, 2026
63 checks passed
@KenVanHoeylandt
KenVanHoeylandt deleted the enable-bluetoot-in-dts branch August 25, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant