Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BT VHCI configuration for 3rd party stack #464

Open
AndyDevLat opened this issue Aug 25, 2024 · 6 comments
Open

BT VHCI configuration for 3rd party stack #464

AndyDevLat opened this issue Aug 25, 2024 · 6 comments

Comments

@AndyDevLat
Copy link

AndyDevLat commented Aug 25, 2024

What is correct way to configure ESP hosted for 3rd party BTStack operation via VHCI? At the moment it supports NimBLE only.
But i want to use BlueKitchen BtStack which uses esp_vhci_host_... APIs to access controller.
More specifically, it uses these APIs:
esp_vhci_host_register_callback
esp_vhci_host_check_send_available
esp_vhci_host_send_packet

Do i need to clone ESP Hosted component and patch host\drivers\bt\vhci_drv.c file for this purpose?
Or is there some other solution?
Note that I am not considering UART H4 mode yet, as it requires 4 more GPIO pins and more difficult to setup.

My host is ESP32-P4 (ESP32-P4-Function-EV-Board) and slave is ESP32 (ESP-WROVER-KIT) connected via SPI transport.

@mantriyogesh
Copy link
Collaborator

Hello @AndyDevLat ,

Thank you for the detailed question.

You can have a look at
https://github.com/espressif/esp-hosted/blob/feature/esp_as_mcu_host/docs/bluetooth_implementation.md#4-nimble-host-stack

The lower level APIs used from NimBLE are shown there. These nimBLE Specific APIs can be ported/replaced to one's from BlueKitchen.

@AndyDevLat
Copy link
Author

Thank you! I figured out, that i need to disable BT support in sdkconfig (CONFIG_BT_ENABLED must not be defined) and replace esp_vhci_host_send_packet calls with direct calls to esp_hosted_tx.
And i use free_buf_fun as callback that packet was sent. Seems to work.
The only downside is that i had to clone esp_hosted to my own component, because i need to add WEAK attribute to hci_rx_handler inside esp_hosted\host\drivers\bt\hci_stub_drv.c, as i have my own implementation for it. I suggest you add WEAK attribute to official code like this:
WEAK int hci_rx_handler(interface_buffer_handle_t *buf_handle).
Then espessif esp_hosted component can be used as is without patching, just need to add some header for missing definitions and that's it.

@mantriyogesh
Copy link
Collaborator

Understood. Point taken.

Also, if you are comfortable, you can also raise PR with your BlueKitchen port. Will be helpful for us and others as lot.

@AndyDevLat
Copy link
Author

AndyDevLat commented Aug 26, 2024

Thank you, will do!
bluekitchen/btstack#625

@AndyDevLat
Copy link
Author

I have also made another optimization for BtStack: inside process_spi_rx_buf i do not forward ESP_HCI_IF packets to spi_process_rx_task via _h_queue_item. Instead i call hci_rx_handler directly and then call spi_buffer_free. This is because BtStack already has own ring buffer and queues incoming packets for processing inside own thread. This way we remove unnecessary packet copying and reduce latency. Maybe it would be good idea to add some menuconfig option for this.

@mantriyogesh
Copy link
Collaborator

Hmm. Seems great.. will add shortly. Else wait for your PR..

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

No branches or pull requests

4 participants
@mantriyogesh @AndyDevLat and others