Skip to content

Commit 4104f73

Browse files
committed
pbdrv/bluetooth: Add driver for EV3.
The driver currently only gets the bluetooth module into a working state. It includes the runloop, some basic HCI interactions, the init scripts, and necessary build changes. All actual functionality will come in future changes.
1 parent 2f6d5a0 commit 4104f73

19 files changed

+5320
-18
lines changed

bricks/_common/common.mk

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ $(error failed)
5252
endif
5353
endif
5454
endif
55-
ifeq ($(PB_LIB_BTSTACK),1)
55+
ifneq ($(strip $(PB_LIB_BTSTACK)),)
5656
ifeq ("$(wildcard $(PBTOP)/lib/btstack/README.md)","")
5757
$(info GIT cloning btstack submodule)
5858
$(info $(shell cd $(PBTOP) && git submodule update --checkout --init lib/btstack))
@@ -122,7 +122,7 @@ endif
122122
ifeq ($(PB_LIB_BLE5STACK),1)
123123
INC += -I$(PBTOP)/lib/ble5stack/central
124124
endif
125-
ifeq ($(PB_LIB_BTSTACK),1)
125+
ifneq ($(strip $(PB_LIB_BTSTACK)),)
126126
INC += -I$(PBTOP)/lib/btstack/chipset/cc256x
127127
INC += -I$(PBTOP)/lib/btstack/src
128128
endif
@@ -380,7 +380,7 @@ BTSTACK_SRC_C = $(addprefix lib/btstack/src/,\
380380
l2cap.c \
381381
)
382382

383-
BTSTACK_SRC_C += $(addprefix lib/btstack/src/ble/,\
383+
BTSTACK_BLE_SRC_C += $(addprefix lib/btstack/src/ble/,\
384384
att_db_util.c \
385385
att_db.c \
386386
att_dispatch.c \
@@ -530,10 +530,15 @@ ifeq ($(PB_LIB_BLE5STACK),1)
530530
OBJ += $(addprefix $(BUILD)/, $(BLE5STACK_SRC_C:.c=.o))
531531
endif
532532

533-
ifeq ($(PB_LIB_BTSTACK),1)
533+
ifeq ($(PB_LIB_BTSTACK),classic)
534534
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_SRC_C:.c=.o))
535535
endif
536536

537+
ifeq ($(PB_LIB_BTSTACK),lowenergy)
538+
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_SRC_C:.c=.o))
539+
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_BLE_SRC_C:.c=.o))
540+
endif
541+
537542
ifeq ($(PB_LIB_STM32_HAL),1)
538543
OBJ += $(addprefix $(BUILD)/, $(STM32_HAL_SRC_C:.c=.o))
539544
$(BUILD)/lib/stm32lib/%.o: CFLAGS += -Wno-sign-compare
@@ -591,9 +596,9 @@ endif
591596

592597
all: $(TARGETS)
593598

594-
# handle BTStack .gatt files
599+
# handle BTStack .gatt files (only for BLE / lowenergy)
595600

596-
ifeq ($(PB_LIB_BTSTACK),1)
601+
ifeq ($(PB_LIB_BTSTACK),lowenergy)
597602

598603
GATT_FILES := $(addprefix lib/pbio/drv/bluetooth/,\
599604
pybricks_service.gatt \

bricks/_common/sources.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
124124
drv/block_device/block_device_w25qxx_stm32.c \
125125
drv/bluetooth/bluetooth.c \
126126
drv/bluetooth/bluetooth_btstack_control_gpio.c \
127+
drv/bluetooth/bluetooth_btstack_uart_block_ev3.c \
127128
drv/bluetooth/bluetooth_btstack_uart_block_stm32_hal.c \
128129
drv/bluetooth/bluetooth_btstack.c \
130+
drv/bluetooth/bluetooth_btstack_classic.c \
131+
drv/bluetooth/bluetooth_init_cc2560x.c \
129132
drv/bluetooth/bluetooth_init_cc2564C_1.4.c \
130133
drv/bluetooth/bluetooth_simulation.c \
131134
drv/bluetooth/bluetooth_stm32_bluenrg.c \

bricks/essentialhub/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PB_MCU_EXT_OSC_HZ = 16000000
99
PB_LIB_STM32_HAL = 1
1010
PB_LIB_LSM6DS3TR_C = 1
1111
PB_LIB_BLUENRG = 0
12-
PB_LIB_BTSTACK = 1
12+
PB_LIB_BTSTACK = lowenergy
1313
PB_LIB_STM32_USB_DEVICE = 1
1414
TEXT0_ADDR = 0x8008000
1515
DFU_VID = 0x0694

bricks/ev3/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ PBIO_PLATFORM = ev3
22
PB_MCU_FAMILY = TIAM1808
33

44
PB_LIB_UMM_MALLOC = 1
5+
PB_LIB_BTSTACK = classic
56

67
include ../_common/common.mk

bricks/ev3/btstack_config.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright (c) 2020 The Pybricks Authors
3+
4+
// BlueKitchen BTStack config
5+
6+
#ifndef _PLATFORM_EV3_BTSTACK_CONFIG_H_
7+
#define _PLATFORM_EV3_BTSTACK_CONFIG_H_
8+
9+
// BTstack features that can be enabled
10+
#define ENABLE_CLASSIC
11+
// #define ENABLE_CC256X_BAUDRATE_CHANGE_FLOWCONTROL_BUG_WORKAROUND
12+
#define ENABLE_PRINTF_HEXDUMP
13+
14+
// Temporary, until I'm sure it's working.
15+
#define ENABLE_LOG_DEBUG
16+
#define ENABLE_LOG_ERROR
17+
#define ENABLE_LOG_INFO
18+
19+
// BTstack configuration. buffers, sizes, ...
20+
#define HCI_ACL_PAYLOAD_SIZE (1691 + 4)
21+
#define MAX_ATT_DB_SIZE 512
22+
#define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0
23+
#define MAX_NR_HCI_CONNECTIONS 2 // CC2564C can have up to 10 connections
24+
#define MAX_NR_HFP_CONNECTIONS 0
25+
#define MAX_NR_L2CAP_CHANNELS 0
26+
#define MAX_NR_L2CAP_SERVICES 0
27+
#define MAX_NR_RFCOMM_CHANNELS 4
28+
#define MAX_NR_RFCOMM_MULTIPLEXERS 0
29+
#define MAX_NR_RFCOMM_SERVICES 0
30+
#define MAX_NR_SERVICE_RECORD_ITEMS 0
31+
#define MAX_NR_WHITELIST_ENTRIES 0
32+
33+
#endif // _PLATFORM_EV3_BTSTACK_CONFIG_H_

bricks/primehub/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PB_MCU_EXT_OSC_HZ = 16000000
99
PB_LIB_STM32_HAL = 1
1010
PB_LIB_LSM6DS3TR_C = 1
1111
PB_LIB_BLUENRG = 0
12-
PB_LIB_BTSTACK = 1
12+
PB_LIB_BTSTACK = lowenergy
1313
PB_LIB_STM32_USB_DEVICE = 1
1414
TEXT0_ADDR = 0x8008000
1515
DFU_VID = 0x0694

lib/pbio/drv/bluetooth/bluetooth_btstack.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef _INTERNAL_PBDRV_BLUETOOTH_BTSTACK_H_
77
#define _INTERNAL_PBDRV_BLUETOOTH_BTSTACK_H_
88

9+
#ifdef PBDRV_CONFIG_BLUETOOTH_BTSTACK
10+
911
#include <btstack_chipset.h>
1012
#include <btstack_control.h>
1113
#include <btstack_uart_block.h>
@@ -23,4 +25,6 @@ typedef struct {
2325
// defined in platform.c
2426
extern const pbdrv_bluetooth_btstack_platform_data_t pbdrv_bluetooth_btstack_platform_data;
2527

28+
#endif // PBDRV_CONFIG_BLUETOOTH_BTSTACK
29+
2630
#endif // _INTERNAL_PBDRV_BLUETOOTH_BTSTACK_H_

0 commit comments

Comments
 (0)