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

Splitting BLE and BT Classic dependencies #332

Merged
merged 4 commits into from
Mar 10, 2023

Conversation

MrGreensWorkshop
Copy link
Contributor

@MrGreensWorkshop MrGreensWorkshop commented Feb 15, 2023

When only using BT Classic, we don't need to add pico_btstack_ble, but the current release doesn't let us do that. I got various compile errors.

In my test application, when I add, pico_btstack_ble binary(uf2) size is 833KB.

target_link_libraries(PicoTest
    pico_stdlib
    pico_btstack_ble
    pico_btstack_classic
    pico_btstack_cyw43
    pico_cyw43_arch_none
)

After this modifications, and removing pico_btstack_ble from config, binary(uf2) size reduce to 748KB.

I think 85KB (833 -748) is a huge difference for applications that only need BT Classic. If you want me to create an issue or change anything, please let me know.

@lurch
Copy link
Contributor

lurch commented Feb 15, 2023

I know nothing about Bluetooth myself, but doing a couple of find and grep commands I see that there's also a btstack_config.h at pico_w/bt/standalone/btstack_config.h (which doesn't have the 'packetsw' typo) in pico-examples and at test/kitchen_sink/btstack_config.h (which does have the 'packetsw' typo) in pico-sdk. And all three versions also (incorrectly) end with #endif // MICROPY_INCLUDED_EXTMOD_BTSTACK_BTSTACK_CONFIG_H

@peterharperuk Interestingly, pico_w/wifi/access_point/dhcpserver/dhcpserver.h in pico-examples also uses MICROPY_INCLUDED_LIB_NETUTILS_DHCPSERVER_H as an include-guard, which is probably worth tweaking?

pico_w/bt/picow_bt_example_common.c Outdated Show resolved Hide resolved
pico_w/bt/picow_bt_example_common.c Outdated Show resolved Hide resolved
@peterharperuk
Copy link
Contributor

It was a fairly last minute change to split pico_btstack_ble and pico_btstack_classic. I think we need some test code to check we don't break it again.

@MrGreensWorkshop
Copy link
Contributor Author

It was a fairly last minute change to split pico_btstack_ble and pico_btstack_classic. I think we need some test code to check we don't break it again.

@peterharperuk I really appreciate the work you've done here.

For the changes that you requested at picow_bt_example_common.c, Please check this file. I believe that all changes are necessary. Please remove pico_btstack_ble to see the errors you get.

Similarly, some of the examples can be built for BLE only.
Put back the packet_handler
@peterharperuk
Copy link
Contributor

I'll push a change that addresses my issues if that's ok?

@MrGreensWorkshop
Copy link
Contributor Author

MrGreensWorkshop commented Feb 15, 2023

I'll push a change that addresses my issues if that's ok?

You didn't even wait my answer.. Please let me explain before going any further.

I made two projects, one with your modifications and one with mine. Please check the code.

If I do with yours I got these errors.

/prj/src/picow_bt_example_common.c: In function 'packet_handler':
/prj/src/picow_bt_example_common.c:48:58: error: 'HCI_STATE_WORKING' undeclared (first use in this function)
   48 |             if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return;
      |                                                          ^~~~~~~~~~~~~~~~~
/prj/src/picow_bt_example_common.c:48:58: note: each undeclared identifier is reported only once for each function it appears in
/prj/src/picow_bt_example_common.c:49:13: warning: implicit declaration of function 'gap_local_bd_addr' [-Wimplicit-function-declaration]
   49 |             gap_local_bd_addr(local_addr);
      |             ^~~~~~~~~~~~~~~~~
[ 14%] Building C object CMakeFiles/PicoBTSPP.dir/Users/wizard/pico-sdk/src/rp2_common/pico_platform/platform.c.obj
/prj/src/picow_bt_example_common.c: In function 'picow_bt_example_init':
/prj/src/picow_bt_example_common.c:78:5: error: 'hci_event_callback_registration' undeclared (first use in this function); did you mean 'btstack_context_callback_registration_t'?
   78 |     hci_event_callback_registration.callback = &packet_handler;
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |     btstack_context_callback_registration_t
/prj/src/picow_bt_example_common.c:79:5: warning: implicit declaration of function 'hci_add_event_handler' [-Wimplicit-function-declaration]
   79 |     hci_add_event_handler(&hci_event_callback_registration);
      |     ^~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/PicoBTSPP.dir/src/picow_bt_example_common.c.obj] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/PicoBTSPP.dir/all] Error 2
make: *** [all] Error 2

@peterharperuk
Copy link
Contributor

I think they are just issues with the include files? Try adding #include "btstack.h"

@MrGreensWorkshop
Copy link
Contributor Author

MrGreensWorkshop commented Feb 15, 2023

I think they are just issues with the include files? Try adding #include "btstack.h"

All these files, picow_bt_example_common.c, picow_bt_example_common.h, btstack_config.h taken from this repo. It should work without "btstack.h".

But I hear you; even if I add #include "btstack.h," I still get this error. That's why I added ifdef.

Could you please check the code and see yourself.

/prj/src/picow_bt_example_common.c: In function 'picow_bt_example_init':
/prj/src/picow_bt_example_common.c:80:5: error: 'hci_event_callback_registration' undeclared (first use in this function); did you mean 'btstack_context_callback_registration_t'?
   80 |     hci_event_callback_registration.callback = &packet_handler;
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |     btstack_context_callback_registration_t
/prj/src/picow_bt_example_common.c:80:5: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [CMakeFiles/PicoBTSPP.dir/src/picow_bt_example_common.c.obj] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/PicoBTSPP.dir/all] Error 2
make: *** [all] Error 2

@peterharperuk
Copy link
Contributor

Try this
working.zip

@MrGreensWorkshop
Copy link
Contributor Author

MrGreensWorkshop commented Feb 15, 2023

I see, I missed btstack_packet_callback_registration_t. Thank you.

but one thing, #include "btstack.h" was missing at pico_w/bt/picow_bt_example_common.c

If we remove packet_handler from Bluetooth Classic( pico_btstack_classic), we can't get the HCI events like the message BTstack up and running on ... That's the difference.

I agree with you. I wish you had said that beforehand.

@kilograham kilograham merged commit 26368b1 into raspberrypi:develop Mar 10, 2023
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.

4 participants