Skip to content

Commit e66642a

Browse files
jaguilarlaurensvalk
authored andcommitted
!wip pbdrv/bluetooth: RFCOMM socket API.
This implements the complete RFCOMM socket API, including listen, connect, send and recv. Tested via manual ping-pong testing for both listen and connect, against a Windows desktop.
1 parent efa2712 commit e66642a

File tree

26 files changed

+2341
-35
lines changed

26 files changed

+2341
-35
lines changed

.vscode/c_cpp_properties.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"gcc",
8080
"MICROPY_MODULE_FROZEN_MPY",
8181
"MICROPY_ROM_TEXT_COMPRESSION",
82+
"HAVE_UMM_MALLOC=1"
8283
],
8384
"compilerArgs": [
8485
"-Wall",
@@ -286,7 +287,8 @@
286287
],
287288
"defines": [
288289
"MICROPY_MODULE_FROZEN_MPY",
289-
"MICROPY_ROM_TEXT_COMPRESSION"
290+
"MICROPY_ROM_TEXT_COMPRESSION",
291+
"HAVE_UMM_MALLOC=1"
290292
],
291293
"compilerArgs": [
292294
"-mthumb",
@@ -404,7 +406,8 @@
404406
],
405407
"defines": [
406408
"MICROPY_MODULE_FROZEN_MPY",
407-
"MICROPY_USE_READLINE=1"
409+
"MICROPY_USE_READLINE=1",
410+
"HAVE_UMM_MALLOC=1",
408411
],
409412
"compilerPath": "/usr/bin/gcc",
410413
"cStandard": "c11",

bricks/_common/common.mk

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,16 @@ BTSTACK_BLE_SRC_C += $(addprefix lib/btstack/src/ble/,\
416416
sm.c \
417417
)
418418

419+
BTSTACK_CLASSIC_SRC_C = $(addprefix lib/btstack/src/classic/,\
420+
btstack_link_key_db_memory.c \
421+
rfcomm.c \
422+
sdp_client.c \
423+
sdp_client_rfcomm.c \
424+
sdp_server.c \
425+
sdp_util.c \
426+
spp_server.c \
427+
)
428+
419429
BTSTACK_SRC_C += $(addprefix lib/btstack/chipset/cc256x/,\
420430
btstack_chipset_cc256x.c \
421431
)
@@ -519,7 +529,7 @@ SRC_STM32_USB_DEV += $(addprefix lib/pbio/drv/usb/stm32_usbd/,\
519529
SRC_UMM_MALLOC = lib/umm_malloc/src/umm_malloc.c
520530

521531
ifeq ($(PB_LIB_UMM_MALLOC),1)
522-
CFLAGS += -I$(PBTOP)/lib/umm_malloc/src
532+
CFLAGS += -I$(PBTOP)/lib/umm_malloc/src -DHAVE_UMM_MALLOC=1
523533
endif
524534

525535
# NXT OS
@@ -579,6 +589,7 @@ ifeq ($(PB_LIB_BTSTACK),1)
579589
ifneq ($(CI_MODE),1)
580590
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_SRC_C:.c=.o))
581591
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_BLE_SRC_C:.c=.o))
592+
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_CLASSIC_SRC_C:.c=.o))
582593
$(BUILD)/lib/btstack/%.o: CFLAGS += -Wno-error
583594
endif
584595
endif

lib/pbio/drv/bluetooth/bluetooth.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,10 @@ pbio_error_t pbdrv_bluetooth_close_user_tasks(pbio_os_state_t *state, pbio_os_ti
729729

730730
PBIO_OS_ASYNC_BEGIN(state);
731731

732+
#if PBDRV_CONFIG_BLUETOOTH_NUM_CLASSIC_CONNECTIONS
733+
pbdrv_bluetooth_rfcomm_disconnect_all();
734+
#endif // PBDRV_CONFIG_BLUETOOTH_NUM_CLASSIC_CONNECTIONS
735+
732736
for (peri_index = 0; peri_index < PBDRV_CONFIG_BLUETOOTH_NUM_PERIPHERALS; peri_index++) {
733737
peri = pbdrv_bluetooth_peripheral_get_by_index(peri_index);
734738
// Await ongoing peripheral user task, requesting cancellation to

lib/pbio/drv/bluetooth/bluetooth.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ typedef struct {
9999

100100
pbio_error_t pbdrv_bluetooth_inquiry_scan_func(pbio_os_state_t *state, void *context);
101101

102+
// The following functions are defined in each Bluetooth implementation that
103+
// supports RFCOMM sockets.
104+
105+
// Cancels all pending connection attempts. Called e.g. when the user interrupts
106+
// execution to drop into the debug REPL.
107+
void pbdrv_bluetooth_rfcomm_cancel_connection();
108+
109+
// Disconnects all active RFCOMM connections and cleans up all sockets. Called
110+
// during user program termination.
111+
void pbdrv_bluetooth_rfcomm_disconnect_all();
112+
102113
#endif // PBDRV_CONFIG_BLUETOOTH
103114

104115
#endif // _INTERNAL_PBDRV_BLUETOOTH_H_

0 commit comments

Comments
 (0)