-
-
Notifications
You must be signed in to change notification settings - Fork 80
[FYI] Further ev3 bluetooth-related changes #405
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
Draft
jaguilar
wants to merge
23
commits into
pybricks:master
Choose a base branch
from
jaguilar:ev3-bluetooth-platform-data
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
f039d01
pbdrv/uart: Use uint32_t for read/write length.
jaguilar a6fcf10
pbdrv/bluetooth: UART block for EV3.
jaguilar db6e51c
pbio/platform/ev3: Pins for ev3 bluetooth module.
jaguilar f0565c5
pbio/platform/ev3: Bluetooth platform_data defs.
jaguilar dfd7676
PR fixes.
jaguilar 899bf13
pbio/platform/ev3: Add more Bluetooth pins.
jaguilar 24695d8
pbdrv/platform/ev3: Format&comment fixup.
jaguilar 670fe21
pbdrv/bluetooth: Rename fns in ev3 uart block.
jaguilar 671033e
pbdrv/bluetooth: EV3 comment fixup for PR.
jaguilar 5360a0d
pbdrv/bluetooth: Format fixup.
jaguilar 28d9654
bricks: PB_LIB_BTSTACK as string variable
jaguilar b704379
pbdrv/uart_debug_first_port: fix bugs/va_list func
jaguilar 580f3de
platform/ev3: Finish bluetooth configuration.
jaguilar 6e2c634
pbdrv/bluetooth: UART block fixes for EV3.
jaguilar bb384be
pbdrv/bluetooth: Init scripts for cc2560x.
jaguilar 98c13bf
pbdrv/bluetooth: Add classic runloop.
jaguilar cccb6ef
compile fix for le hubs
jaguilar 66b55df
pbdrv/bluetooth: Add forgotten pbdrvconfig include.
jaguilar f68fc89
bricks: Restore accidentally removed cc2564C_1.4.c.
jaguilar 0d83746
pbdrv/bluetooth: EV3 UART block return errors.
jaguilar 0853e88
pbdrv/bluetooth: Refactor classic, add scan API.
jaguilar 33cfa70
bricks/ev3: Add Bluetooth classic object.
jaguilar 940d87f
pbdrv/bluetooth: Classic scan now reports name.
jaguilar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) 2020 The Pybricks Authors | ||
|
|
||
| // BlueKitchen BTStack config | ||
|
|
||
| #ifndef _PLATFORM_EV3_BTSTACK_CONFIG_H_ | ||
| #define _PLATFORM_EV3_BTSTACK_CONFIG_H_ | ||
|
|
||
| // BTstack features that can be enabled | ||
| #define ENABLE_CLASSIC | ||
| // #define ENABLE_CC256X_BAUDRATE_CHANGE_FLOWCONTROL_BUG_WORKAROUND | ||
| #define ENABLE_PRINTF_HEXDUMP | ||
|
|
||
| // Temporary, until I'm sure it's working. | ||
| #define ENABLE_LOG_DEBUG | ||
| #define ENABLE_LOG_ERROR | ||
| #define ENABLE_LOG_INFO | ||
|
|
||
| // BTstack configuration. buffers, sizes, ... | ||
| #define HCI_ACL_PAYLOAD_SIZE (1691 + 4) | ||
| #define MAX_ATT_DB_SIZE 512 | ||
| #define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0 | ||
| #define MAX_NR_HCI_CONNECTIONS 2 // CC2564C can have up to 10 connections | ||
| #define MAX_NR_HFP_CONNECTIONS 0 | ||
| #define MAX_NR_L2CAP_CHANNELS 0 | ||
| #define MAX_NR_L2CAP_SERVICES 0 | ||
| #define MAX_NR_RFCOMM_CHANNELS 4 | ||
| #define MAX_NR_RFCOMM_MULTIPLEXERS 0 | ||
| #define MAX_NR_RFCOMM_SERVICES 0 | ||
| #define MAX_NR_SERVICE_RECORD_ITEMS 0 | ||
| #define MAX_NR_WHITELIST_ENTRIES 0 | ||
|
|
||
| #endif // _PLATFORM_EV3_BTSTACK_CONFIG_H_ |
192 changes: 192 additions & 0 deletions
192
lib/pbio/drv/bluetooth/bluetooth_btstack_uart_block_ev3.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) 2025 The Pybricks Authors | ||
|
|
||
| // EV3 UART driver for BlueKitchen BTStack (stubs). | ||
|
|
||
| #include <pbdrv/config.h> | ||
|
|
||
| #if PBDRV_CONFIG_BLUETOOTH_BTSTACK_EV3_UART | ||
|
|
||
| #include <stdint.h> | ||
|
|
||
| #include <btstack.h> | ||
| #include <btstack_uart_block.h> | ||
| #include <pbdrv/uart.h> | ||
| #include <pbio/os.h> | ||
|
|
||
| #include "bluetooth_btstack_uart_block_ev3.h" | ||
|
|
||
| // If a read has been requested, a pointer to the buffer and its length, else | ||
| // null and zero. | ||
| static uint8_t *read_buf; | ||
| static int read_buf_len; | ||
|
|
||
| // If a write has been requested, a pointer to the buffer and its length, else | ||
| // null and zero. | ||
| static const uint8_t *write_buf; | ||
| static int write_buf_len; | ||
|
|
||
| // Should the reader and writer processes shut down? | ||
| static bool start_shutdown; | ||
|
|
||
| // How many threads have processes have exited since the request to shut down? | ||
jaguilar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static int8_t threads_shutdown_complete; | ||
|
|
||
| // Called when a block finishes sending. | ||
| static void (*block_sent)(void); | ||
| // Called when a block finishes being received. | ||
| static void (*block_received)(void); | ||
|
|
||
| // Processes for reading and writing blocks. | ||
| static pbio_os_process_t reader_process; | ||
| static pbio_os_process_t writer_process; | ||
|
|
||
| static pbdrv_uart_dev_t *uart_device() { | ||
| const pbdrv_bluetooth_btstack_uart_block_ev3_platform_data_t *pdata = | ||
| &pbdrv_bluetooth_btstack_uart_block_ev3_platform_data; | ||
| pbdrv_uart_dev_t *uart; | ||
| pbio_error_t err = pbdrv_uart_get_instance(pdata->uart_id, &uart); | ||
| if (err != PBIO_SUCCESS) { | ||
| return NULL; | ||
jaguilar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| return uart; | ||
| } | ||
|
|
||
| static int btstack_uart_block_ev3_init(const btstack_uart_config_t *config) { | ||
jaguilar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pbdrv_uart_set_baud_rate(uart_device(), config->baudrate); | ||
| // TODO: add parity, flow control APIs and obey them. | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static pbio_error_t do_read_process(pbio_os_state_t *state, void *context) { | ||
| pbdrv_uart_dev_t *const uart = uart_device(); | ||
|
|
||
| pbio_os_state_t read_state; | ||
| PBIO_OS_ASYNC_BEGIN(state); | ||
|
|
||
| while (true) { | ||
jaguilar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| PBIO_OS_AWAIT_UNTIL(state, read_buf || start_shutdown); | ||
| if (start_shutdown) { | ||
| break; | ||
| } | ||
|
|
||
| PBIO_OS_AWAIT(state, &read_state, | ||
| pbdrv_uart_read(state, uart, read_buf, read_buf_len, /*timeout=*/ 0)); | ||
| read_buf = NULL; | ||
| read_buf_len = 0; | ||
| if (block_received) { | ||
| block_received(); | ||
| } | ||
| } | ||
|
|
||
| ++threads_shutdown_complete; | ||
| PBIO_OS_ASYNC_END(PBIO_SUCCESS); | ||
| } | ||
|
|
||
| static pbio_error_t do_write_process(pbio_os_state_t *state, void *context) { | ||
| pbdrv_uart_dev_t *const uart = uart_device(); | ||
|
|
||
| pbio_os_state_t write_state; | ||
|
|
||
| PBIO_OS_ASYNC_BEGIN(state); | ||
|
|
||
| while (true) { | ||
| PBIO_OS_AWAIT_UNTIL(state, write_buf || start_shutdown); | ||
| if (start_shutdown) { | ||
| break; | ||
| } | ||
|
|
||
| PBIO_OS_AWAIT(state, &write_state, | ||
| pbdrv_uart_write(&write_state, uart, (uint8_t *)write_buf, write_buf_len, /*timeout=*/ 0)); | ||
| write_buf = NULL; | ||
| write_buf_len = 0; | ||
| if (block_sent) { | ||
| block_sent(); | ||
| } | ||
| } | ||
|
|
||
| ++threads_shutdown_complete; | ||
| PBIO_OS_ASYNC_END(PBIO_SUCCESS); | ||
| } | ||
|
|
||
|
|
||
| static int btstack_uart_block_ev3_open(void) { | ||
| write_buf = NULL; | ||
| write_buf_len = 0; | ||
| read_buf = NULL; | ||
| read_buf_len = 0; | ||
| start_shutdown = false; | ||
| threads_shutdown_complete = 0; | ||
| block_received = NULL; | ||
| block_sent = NULL; | ||
|
|
||
| pbio_os_process_start(&reader_process, do_read_process, NULL); | ||
| pbio_os_process_start(&writer_process, do_write_process, NULL); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int btstack_uart_block_ev3_close(void) { | ||
| start_shutdown = true; | ||
| while (threads_shutdown_complete < 2) { | ||
| pbio_os_run_processes_and_wait_for_event(); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static void btstack_uart_block_ev3_set_block_received(void (*handler)(void)) { | ||
| block_received = handler; | ||
| } | ||
|
|
||
| static void btstack_uart_block_ev3_set_block_sent(void (*handler)(void)) { | ||
| block_sent = handler; | ||
| } | ||
|
|
||
| static int btstack_uart_block_ev3_set_baudrate(uint32_t baud) { | ||
| pbdrv_uart_set_baud_rate(uart_device(), baud); | ||
| return 0; | ||
| } | ||
|
|
||
| static int btstack_uart_block_ev3_set_parity(int parity) { | ||
| // TODO: maybe implement the parity setting. | ||
| return 0; | ||
| } | ||
|
|
||
| static void btstack_uart_block_ev3_receive_block(uint8_t *buffer, | ||
| uint16_t len) { | ||
| read_buf = buffer; | ||
| read_buf_len = len; | ||
| pbio_os_request_poll(); | ||
| } | ||
|
|
||
| static void btstack_uart_block_ev3_send_block(const uint8_t *data, | ||
| uint16_t size) { | ||
| write_buf = data; | ||
| write_buf_len = size; | ||
| pbio_os_request_poll(); | ||
| } | ||
|
|
||
| static const btstack_uart_block_t btstack_uart_block_ev3 = { | ||
| .init = btstack_uart_block_ev3_init, | ||
| .open = btstack_uart_block_ev3_open, | ||
| .close = btstack_uart_block_ev3_close, | ||
| .set_block_received = btstack_uart_block_ev3_set_block_received, | ||
| .set_block_sent = btstack_uart_block_ev3_set_block_sent, | ||
| .set_baudrate = btstack_uart_block_ev3_set_baudrate, | ||
| .set_parity = btstack_uart_block_ev3_set_parity, | ||
| .set_flowcontrol = NULL, | ||
| .receive_block = btstack_uart_block_ev3_receive_block, | ||
| .send_block = btstack_uart_block_ev3_send_block, | ||
| .get_supported_sleep_modes = NULL, | ||
| .set_sleep = NULL, | ||
| .set_wakeup_handler = NULL, | ||
| }; | ||
|
|
||
| const btstack_uart_block_t *pbdrv_bluetooth_btstack_uart_block_ev3_instance( | ||
| void) { | ||
jaguilar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return &btstack_uart_block_ev3; | ||
| } | ||
|
|
||
| #endif // PBDRV_CONFIG_BLUETOOTH_BTSTACK_EV3_UART | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) 2025 The Pybricks Authors | ||
|
|
||
| // EV3 UART driver for BlueKitchen BTStack (stubs). | ||
|
|
||
| #ifndef _INTERNAL_PBDRV_BLUETOOTH_BTSTACK_UART_BLOCK_EV3_H_ | ||
| #define _INTERNAL_PBDRV_BLUETOOTH_BTSTACK_UART_BLOCK_EV3_H_ | ||
|
|
||
| #include <btstack_uart_block.h> | ||
| #include <pbdrv/uart.h> | ||
| #include <stdint.h> | ||
|
|
||
| const btstack_uart_block_t *pbdrv_bluetooth_btstack_uart_block_ev3_instance( | ||
| void); | ||
|
|
||
| typedef struct { | ||
| // The uart device connected to the Bluetooth module. | ||
| uint8_t uart_id; | ||
| } pbdrv_bluetooth_btstack_uart_block_ev3_platform_data_t; | ||
|
|
||
| // To be defined in platform/ev3/platform.c | ||
| extern const pbdrv_bluetooth_btstack_uart_block_ev3_platform_data_t | ||
| pbdrv_bluetooth_btstack_uart_block_ev3_platform_data; | ||
|
|
||
| #endif // _INTERNAL_PBDRV_BLUETOOTH_BTSTACK_UART_BLOCK_EV3_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.