Skip to content

Commit 539508f

Browse files
committed
pbio/drv/bluetooth_btstack: Allow other firmware files.
For platforms like EV3, the firmware patch is dynamically determined. We can apply the same technique for the STM32 platforms for conistency. Also move the firmware files to the Bluetooth folder since they are not associated with one particular hub.
1 parent dfeec3a commit 539508f

File tree

6 files changed

+37
-16
lines changed

6 files changed

+37
-16
lines changed

bricks/_common/sources.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
118118
drv/bluetooth/bluetooth_simulation.c \
119119
drv/bluetooth/bluetooth_stm32_bluenrg.c \
120120
drv/bluetooth/bluetooth_stm32_cc2640.c \
121+
drv/bluetooth/firmware/bluetooth_init_cc2564C_1.4.c \
121122
drv/bluetooth/pybricks_service_server.c \
122123
drv/button/button_gpio.c \
123124
drv/button/button_nxt.c \
@@ -187,7 +188,6 @@ PBIO_SRC_C = $(addprefix lib/pbio/,\
187188
drv/watchdog/watchdog_ev3.c \
188189
drv/watchdog/watchdog_stm32.c \
189190
platform/$(PBIO_PLATFORM)/platform.c \
190-
platform/prime_hub/bluetooth_init_cc2564C_1.4.c \
191191
src/angle.c \
192192
src/battery.c \
193193
src/busy_count.c \

lib/pbio/drv/bluetooth/bluetooth_btstack.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,10 @@ static pbio_error_t pbdrv_bluetooth_hci_process_thread(pbio_os_state_t *state, v
11171117
return bluetooth_thread_err;
11181118
}
11191119

1120+
// Have to be defined, but are not used.
1121+
const uint32_t cc256x_init_script_size = 0;
1122+
const uint8_t cc256x_init_script[] = {};
1123+
11201124
void pbdrv_bluetooth_init_hci(void) {
11211125

11221126
static btstack_packet_callback_registration_t hci_event_callback_registration;

lib/pbio/drv/bluetooth/bluetooth_btstack.h

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

9+
#include <btstack.h>
910
#include <btstack_chipset.h>
1011
#include <btstack_control.h>
1112
#include <btstack_uart_block.h>
1213

14+
/** Chipset info */
15+
typedef struct {
16+
/** Version */
17+
const uint16_t lmp_version;
18+
/** Initialization script */
19+
const uint8_t *init_script;
20+
/** Initialization script size */
21+
const uint32_t init_script_size;
22+
} pbdrv_bluetooth_btstack_chipset_info_t;
23+
1324
void pbdrv_bluetooth_btstack_run_loop_trigger(void);
1425

1526
/**

lib/pbio/drv/bluetooth/bluetooth_btstack_stm32_hal.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,23 @@
2020
#include "bluetooth_btstack_stm32_hal.h"
2121
#include "hci_transport_h4.h"
2222

23+
#include "btstack_chipset_cc256x.h"
24+
2325
#include <pbdrv/gpio.h>
2426

2527
void pbdrv_bluetooth_btstack_set_chipset(uint16_t lmp_pal_subversion) {
28+
29+
const pbdrv_bluetooth_btstack_platform_data_t *pdata =
30+
&pbdrv_bluetooth_btstack_platform_data;
31+
2632
// All platforms supported by this abstraction use a cc2560x with the same
27-
// init script, so nothing to do here.
28-
}
33+
// init script.
34+
extern const pbdrv_bluetooth_btstack_chipset_info_t cc2564c_info;
35+
btstack_chipset_cc256x_set_init_script((uint8_t *)cc2564c_info.init_script, cc2564c_info.init_script_size);
36+
37+
// Needed to apply init script.
38+
hci_set_chipset(pdata->chipset_instance());
39+
};
2940

3041
static int btstack_control_gpio_on(void) {
3142
const pbdrv_bluetooth_btstack_stm32_platform_data_t *pdata =

lib/pbio/platform/prime_hub/bluetooth_init_cc2564C_1.4.c renamed to lib/pbio/drv/bluetooth/firmware/bluetooth_init_cc2564C_1.4.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,17 @@
88
// - AKA TIInit_6.12.26.bts
99
// - initscripts-TIInit_6.12.26_ble_add-on_v1.4.bts
1010
#include <stdint.h>
11-
#include "btstack_chipset_cc256x.h"
1211

13-
14-
const uint16_t cc256x_init_script_lmp_subversion = 0x9a1a;
15-
16-
uint16_t btstack_chipset_cc256x_lmp_subversion(void) {
17-
return cc256x_init_script_lmp_subversion;
18-
}
12+
#include "../bluetooth_btstack.h"
1913

2014
#if defined(__GNUC__) && defined(__MSP430X__) && (__MSP430X__ > 0)
2115
__attribute__((section(".fartext")))
2216
#endif
2317
#ifdef __AVR__
2418
__attribute__((__progmem__))
2519
#endif
26-
const uint8_t cc256x_init_script[] = {
20+
21+
static const uint8_t cc2564c_init_script[] = {
2722

2823
// #--------------------------------------------------------------------------------
2924
// # Description : Orca C ROM Initialization Script
@@ -600,6 +595,10 @@ const uint8_t cc256x_init_script[] = {
600595

601596
};
602597

603-
const uint32_t cc256x_init_script_size = 6646;
598+
const pbdrv_bluetooth_btstack_chipset_info_t cc2564c_info = {
599+
.lmp_version = 0x9a1a,
600+
.init_script = cc2564c_init_script,
601+
.init_script_size = sizeof(cc2564c_init_script),
602+
};
604603

605604
#endif // PBDRV_CONFIG_BLUETOOTH_BTSTACK_CC2564C

lib/pbio/test/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ PBIO_SRC = $(PBIO_DIR)/platform/test/platform.c \
125125
$(shell find $(PBIO_DIR)/sys -name "*.c") \
126126
$(shell find $(PBIO_DIR)/src/motor -name "*.c") \
127127

128-
PBIO_SRC += $(addprefix $(PBIO_DIR)/,\
129-
platform/prime_hub/bluetooth_init_cc2564C_1.4.c \
130-
)
131-
132128
# tests
133129
TEST_INC = -I. -I$(PBIO_DIR)/platform/test
134130
TEST_SRC = $(shell find . -name "*.c")

0 commit comments

Comments
 (0)