-
-
Notifications
You must be signed in to change notification settings - Fork 82
pbio/drv/bluetooth_btstack: Generalizations to prepare for POSIX variant. #442
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
base: master
Are you sure you want to change the base?
Changes from all commits
424dcbf
fb0a244
b3c6702
4402e8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -228,18 +228,23 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe | |
| const uint8_t *rp = hci_event_command_complete_get_return_parameters(packet); | ||
| switch (hci_event_command_complete_get_command_opcode(packet)) { | ||
| case HCI_OPCODE_HCI_READ_LOCAL_VERSION_INFORMATION: { | ||
| uint16_t lmp_pal_subversion = pbio_get_uint16_le(&rp[7]); | ||
| pbdrv_bluetooth_btstack_set_chipset(lmp_pal_subversion); | ||
| pbdrv_bluetooth_btstack_device_discriminator_t info; | ||
| info.hci_version = rp[1]; | ||
| info.hci_revision = pbio_get_uint16_le(&rp[2]); | ||
| info.lmp_pal_version = rp[4]; | ||
| info.manufacturer = pbio_get_uint16_le(&rp[5]); | ||
| info.lmp_pal_subversion = pbio_get_uint16_le(&rp[7]); | ||
| pbdrv_bluetooth_btstack_set_chipset(&info); | ||
|
|
||
| #if DEBUG | ||
| // Show version in ev3dev format. | ||
| uint16_t chip = (lmp_pal_subversion & 0x7C00) >> 10; | ||
| uint16_t min_ver = (lmp_pal_subversion & 0x007F); | ||
| uint16_t maj_ver = (lmp_pal_subversion & 0x0380) >> 7; | ||
| if (lmp_pal_subversion & 0x8000) { | ||
| uint16_t chip = (info.lmp_pal_subversion & 0x7C00) >> 10; | ||
| uint16_t min_ver = (info.lmp_pal_subversion & 0x007F); | ||
| uint16_t maj_ver = (info.lmp_pal_subversion & 0x0380) >> 7; | ||
| if (info.lmp_pal_subversion & 0x8000) { | ||
| maj_ver |= 0x0008; | ||
| } | ||
| DEBUG_PRINT("LMP %04x: TIInit_%d.%d.%d.bts\n", lmp_pal_subversion, chip, maj_ver, min_ver); | ||
| DEBUG_PRINT("LMP %04x: TIInit_%d.%d.%d.bts\n", info.lmp_pal_subversion, chip, maj_ver, min_ver); | ||
| #endif | ||
| break; | ||
| } | ||
|
|
@@ -1000,6 +1005,13 @@ static void bluetooth_btstack_run_loop_execute(void) { | |
| // not used | ||
| } | ||
|
|
||
| static bool do_poll_handler; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should be |
||
|
|
||
| static void pbdrv_bluetooth_btstack_run_loop_trigger(void) { | ||
| do_poll_handler = true; | ||
| pbio_os_request_poll(); | ||
| } | ||
|
|
||
| static const btstack_run_loop_t bluetooth_btstack_run_loop = { | ||
| .init = btstack_run_loop_base_init, | ||
| .add_data_source = btstack_run_loop_base_add_data_source, | ||
|
|
@@ -1012,15 +1024,9 @@ static const btstack_run_loop_t bluetooth_btstack_run_loop = { | |
| .execute = bluetooth_btstack_run_loop_execute, | ||
| .dump_timer = btstack_run_loop_base_dump_timer, | ||
| .get_time_ms = pbdrv_clock_get_ms, | ||
| .poll_data_sources_from_irq = pbdrv_bluetooth_btstack_run_loop_trigger, | ||
| }; | ||
|
|
||
| static bool do_poll_handler; | ||
|
|
||
| void pbdrv_bluetooth_btstack_run_loop_trigger(void) { | ||
| do_poll_handler = true; | ||
| pbio_os_request_poll(); | ||
| } | ||
|
|
||
| static pbio_os_process_t pbdrv_bluetooth_hci_process; | ||
|
|
||
| /** | ||
|
|
@@ -1034,6 +1040,8 @@ static pbio_error_t pbdrv_bluetooth_hci_process_thread(pbio_os_state_t *state, v | |
| btstack_run_loop_base_poll_data_sources(); | ||
| } | ||
|
|
||
| pbdrv_bluetooth_btstack_platform_poll(); | ||
|
|
||
| static pbio_os_timer_t btstack_timer = { | ||
| .duration = 1, | ||
| }; | ||
|
|
@@ -1055,6 +1063,12 @@ const uint8_t cc256x_init_script[] = {}; | |
|
|
||
| void pbdrv_bluetooth_init_hci(void) { | ||
|
|
||
| // Proceed to start Bluetooth process only if platform init passes. | ||
| pbio_error_t err = pbdrv_bluetooth_btstack_platform_init(); | ||
| if (err != PBIO_SUCCESS) { | ||
| return; | ||
| } | ||
|
|
||
| static btstack_packet_callback_registration_t hci_event_callback_registration; | ||
|
|
||
| #if PBDRV_CONFIG_BLUETOOTH_BTSTACK_LE | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,22 @@ | |
| #include <btstack_control.h> | ||
| #include <btstack_uart_block.h> | ||
|
|
||
| #include <pbio/error.h> | ||
|
|
||
| /** | ||
| * Optional platform initialization before BTstack takes over. | ||
| * | ||
| * Unlike some BTstack init code, this is guaranteed to be called only once. | ||
| * | ||
| * @return Any error code to skip Bluetooth or ::PBIO_SUCCESS to proceed. | ||
| */ | ||
| pbio_error_t pbdrv_bluetooth_btstack_platform_init(void); | ||
|
|
||
| /** | ||
| * Optional platform poll handler, called on every process iteration. | ||
| */ | ||
| void pbdrv_bluetooth_btstack_platform_poll(void); | ||
|
|
||
| /** Chipset info */ | ||
| typedef struct { | ||
| /** Version */ | ||
|
|
@@ -21,15 +37,31 @@ typedef struct { | |
| const uint32_t init_script_size; | ||
| } pbdrv_bluetooth_btstack_chipset_info_t; | ||
|
|
||
| void pbdrv_bluetooth_btstack_run_loop_trigger(void); | ||
| /** | ||
| * Device discriminator info from the HCI read local version information command. | ||
| */ | ||
| typedef struct { | ||
| /** HCI version. */ | ||
| uint8_t hci_version; | ||
| /** HCI revision. */ | ||
| uint16_t hci_revision; | ||
| /** LMP/PAL version. */ | ||
| uint8_t lmp_pal_version; | ||
| /** Manufacturer. */ | ||
| uint16_t manufacturer; | ||
| /** LMP/PAL subversion. */ | ||
| uint16_t lmp_pal_subversion; | ||
| } pbdrv_bluetooth_btstack_device_discriminator_t; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would put This is just an unpacked version of the return values from HCI Read Local Version Info. |
||
|
|
||
| /** | ||
| * Hook called when BTstack reads the local version information. | ||
| * | ||
| * This is called _after_ hci_set_chipset but _before_ the init script is sent | ||
| * over the wire, so this can be used to dynamically select the init script. | ||
| * | ||
| * @param device_info The device information read from the Bluetooth chip. | ||
| */ | ||
| void pbdrv_bluetooth_btstack_set_chipset(uint16_t lmp_pal_subversion); | ||
| void pbdrv_bluetooth_btstack_set_chipset(pbdrv_bluetooth_btstack_device_discriminator_t *device_info); | ||
|
|
||
| typedef struct { | ||
| const hci_transport_t *(*transport_instance)(void); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wouldn't hurt to put this unpacking in a separate function.