Skip to content

Commit aa6914d

Browse files
jerome-pouillersilabs-TiborL
authored andcommitted
drivers: bluetooth: Introduce SiWx91x HCI driver
Driver was tested with a custom application which enabled the BT_SHELL. Basic functionalities were verified: - Scanning - Advertising - Connecting Configuration needed for the test: - CONFIG_BT=y - CONFIG_BT_PERIPHERAL=y - CONFIG_BT_CENTRAL=y - CONFIG_BT_SHELL=y - CONFIG_SHELL=y Co-authored-by: Tibor Laczko <tibor.laczko@silabs.com> Signed-off-by: Tibor Laczko <tibor.laczko@silabs.com> Signed-off-by: Jérôme Pouiller <jerome.pouiller@silabs.com>
1 parent 0d0e780 commit aa6914d

File tree

6 files changed

+176
-0
lines changed

6 files changed

+176
-0
lines changed

drivers/bluetooth/hci/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ zephyr_library_sources_ifdef(CONFIG_BT_STM32WBA hci_stm32wba.c)
4040
zephyr_library_sources_ifdef(CONFIG_BT_STM32WB0 hci_stm32wb0.c)
4141
zephyr_library_sources_ifdef(CONFIG_BT_USERCHAN userchan.c)
4242
zephyr_library_sources_ifdef(CONFIG_BT_SILABS_EFR32 hci_silabs_efr32.c)
43+
zephyr_library_sources_ifdef(CONFIG_BT_SILABS_SIWX91X hci_silabs_siwx91x.c)
4344
zephyr_library_sources_ifdef(CONFIG_BT_PSOC6_BLESS hci_ifx_psoc6_bless.c)
4445
zephyr_library_sources_ifdef(CONFIG_SOC_NRF5340_CPUAPP nrf53_support.c)
4546
zephyr_library_sources_ifdef(CONFIG_BT_AMBIQ_HCI hci_ambiq.c apollox_blue.c)

drivers/bluetooth/hci/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,18 @@ config BT_SILABS_EFR32
136136
help
137137
Use Silicon Labs binary Bluetooth library to connect to the
138138
controller.
139+
139140
source "drivers/bluetooth/hci/Kconfig.silabs"
140141

142+
config BT_SILABS_SIWX91X
143+
bool "Silabs SiWx91x Bluetooth interface"
144+
default y
145+
depends on DT_HAS_SILABS_SIWX91X_BT_HCI_ENABLED
146+
select WISECONNECT_NETWORK_STACK
147+
select ENTROPY_GENERATOR
148+
help
149+
Use Silicon Labs Wiseconnect 3.x Bluetooth library to connect to the controller.
150+
141151
config BT_USERCHAN
142152
bool
143153
depends on (BOARD_NATIVE_POSIX || BOARD_NATIVE_SIM)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Copyright (c) 2024 Silicon Laboratories Inc.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/kernel.h>
7+
#include <zephyr/drivers/bluetooth.h>
8+
9+
#define DT_DRV_COMPAT silabs_siwx91x_bt_hci
10+
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
11+
#include <zephyr/logging/log.h>
12+
LOG_MODULE_REGISTER(bt_hci_driver_siwg917);
13+
14+
#include "rsi_ble.h"
15+
16+
static void siwx91x_bt_resp_rcvd(uint16_t status, rsi_ble_event_rcp_rcvd_info_t *resp_buf);
17+
18+
struct hci_data {
19+
bt_hci_recv_t recv;
20+
rsi_data_packet_t rsi_data_packet;
21+
};
22+
23+
static int siwx91x_bt_open(const struct device *dev, bt_hci_recv_t recv)
24+
{
25+
struct hci_data *hci = dev->data;
26+
int status = rsi_ble_enhanced_gap_extended_register_callbacks(RSI_BLE_ON_RCP_EVENT,
27+
(void *)siwx91x_bt_resp_rcvd);
28+
29+
if (!status) {
30+
hci->recv = recv;
31+
}
32+
return status ? -EIO : 0;
33+
}
34+
35+
static int siwx91x_bt_send(const struct device *dev, struct net_buf *buf)
36+
{
37+
struct hci_data *hci = dev->data;
38+
int sc = -EOVERFLOW;
39+
uint8_t packet_type = BT_HCI_H4_NONE;
40+
41+
switch (bt_buf_get_type(buf)) {
42+
case BT_BUF_ACL_OUT:
43+
packet_type = BT_HCI_H4_ACL;
44+
break;
45+
case BT_BUF_CMD:
46+
packet_type = BT_HCI_H4_CMD;
47+
break;
48+
default:
49+
sc = -EINVAL;
50+
break;
51+
}
52+
53+
if ((packet_type != BT_HCI_H4_NONE) && (buf->len < sizeof(hci->rsi_data_packet.data))) {
54+
net_buf_push_u8(buf, packet_type);
55+
memcpy(&hci->rsi_data_packet, buf->data, buf->len);
56+
sc = rsi_bt_driver_send_cmd(RSI_BLE_REQ_HCI_RAW, &hci->rsi_data_packet, NULL);
57+
/* TODO SILABS ZEPHYR Convert to errno. A common function from rsi/sl_status should
58+
* be introduced
59+
*/
60+
if (sc) {
61+
LOG_ERR("BT command send failure: %d", sc);
62+
sc = -EIO;
63+
}
64+
}
65+
net_buf_unref(buf);
66+
return sc;
67+
}
68+
69+
static void siwx91x_bt_resp_rcvd(uint16_t status, rsi_ble_event_rcp_rcvd_info_t *resp_buf)
70+
{
71+
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0));
72+
struct hci_data *hci = dev->data;
73+
uint8_t packet_type = BT_HCI_H4_NONE;
74+
size_t len = 0;
75+
struct net_buf *buf = NULL;
76+
77+
/* TODO SILABS ZEPHYR This horror expression is from the WiseConnect from the HCI example...
78+
* No workaround have been found until now.
79+
*/
80+
memcpy(&packet_type, (resp_buf->data - 12), 1);
81+
switch (packet_type) {
82+
case BT_HCI_H4_EVT: {
83+
struct bt_hci_evt_hdr *hdr = (void *)resp_buf->data;
84+
85+
len = hdr->len + sizeof(*hdr);
86+
buf = bt_buf_get_evt(hdr->evt, false, K_FOREVER);
87+
break;
88+
}
89+
case BT_HCI_H4_ACL: {
90+
struct bt_hci_acl_hdr *hdr = (void *)resp_buf->data;
91+
92+
len = hdr->len + sizeof(*hdr);
93+
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER);
94+
break;
95+
}
96+
default:
97+
LOG_ERR("Unknown/Unhandled HCI type: %d", packet_type);
98+
break;
99+
}
100+
101+
if (buf && (len <= net_buf_tailroom(buf))) {
102+
net_buf_add_mem(buf, resp_buf->data, len);
103+
hci->recv(dev, buf);
104+
}
105+
}
106+
107+
static DEVICE_API(bt_hci, siwx91x_api) = {
108+
.open = siwx91x_bt_open,
109+
.send = siwx91x_bt_send,
110+
};
111+
112+
#define HCI_DEVICE_INIT(inst) \
113+
static struct hci_data hci_data_##inst; \
114+
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &hci_data_##inst, NULL, POST_KERNEL, \
115+
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &siwx91x_api)
116+
117+
/* Only one instance supported right now */
118+
HCI_DEVICE_INIT(0)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
description: Bluetooth HCI on Silabs boards
2+
3+
compatible: "silabs,siwx91x-bt-hci"
4+
5+
include: bt-hci.yaml
6+
7+
properties:
8+
bt-hci-name:
9+
default: "sl:bt:siwx91x"
10+
bt-hci-bus:
11+
default: "virtual"
12+
bt-hci-quirks:
13+
default: ["no-reset"]

modules/hal_silabs/wiseconnect/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ zephyr_library_sources_ifdef(CONFIG_DMA_SILABS_SIWX91X
6262
${WISECONNECT_DIR}/components/device/silabs/si91x/mcu/drivers/rom_driver/src/rsi_rom_table_si91x.c
6363
)
6464

65+
if(CONFIG_BT_SILABS_SIWX91X)
66+
zephyr_compile_definitions(
67+
SLI_SI91X_ENABLE_BLE
68+
)
69+
zephyr_include_directories(
70+
${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/ble/inc
71+
)
72+
zephyr_library_sources(
73+
${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/ble/src/rsi_bt_ble.c
74+
${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/ble/src/rsi_common_apis.c
75+
${WISECONNECT_DIR}/components/device/silabs/si91x/wireless/ble/src/rsi_utils.c
76+
)
77+
endif() # CONFIG_BT_SILABS_SIWX91X
78+
6579
if(CONFIG_WISECONNECT_NETWORK_STACK)
6680
zephyr_compile_definitions(
6781
SLI_SI91X_ENABLE_OS

soc/silabs/silabs_siwx91x/siwg917/nwp_init.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
#include "sl_wifi.h"
1616
#include "sl_wifi_callback_framework.h"
17+
#ifdef CONFIG_BT_SILABS_SIWX91X
18+
#include "rsi_ble_common_config.h"
19+
#endif
1720

1821
static int siwg917_nwp_init(void)
1922
{
@@ -36,6 +39,23 @@ static int siwg917_nwp_init(void)
3639
}
3740
};
3841

42+
#ifdef CONFIG_BT_SILABS_SIWX91X
43+
cfg->ext_custom_feature_bit_map |= SL_SI91X_EXT_FEAT_BT_CUSTOM_FEAT_ENABLE;
44+
cfg->bt_feature_bit_map |= SL_SI91X_BT_RF_TYPE | SL_SI91X_ENABLE_BLE_PROTOCOL;
45+
cfg->ble_feature_bit_map |= SL_SI91X_BLE_MAX_NBR_PERIPHERALS(RSI_BLE_MAX_NBR_PERIPHERALS) |
46+
SL_SI91X_BLE_MAX_NBR_CENTRALS(RSI_BLE_MAX_NBR_CENTRALS) |
47+
SL_SI91X_BLE_MAX_NBR_ATT_SERV(RSI_BLE_MAX_NBR_ATT_SERV) |
48+
SL_SI91X_BLE_MAX_NBR_ATT_REC(RSI_BLE_MAX_NBR_ATT_REC) |
49+
SL_SI91X_BLE_PWR_INX(RSI_BLE_PWR_INX) |
50+
SL_SI91X_BLE_PWR_SAVE_OPTIONS(RSI_BLE_PWR_SAVE_OPTIONS) |
51+
SL_SI91X_916_BLE_COMPATIBLE_FEAT_ENABLE |
52+
SL_SI91X_FEAT_BLE_CUSTOM_FEAT_EXTENSION_VALID;
53+
cfg->ble_ext_feature_bit_map |= SL_SI91X_BLE_NUM_CONN_EVENTS(RSI_BLE_NUM_CONN_EVENTS) |
54+
SL_SI91X_BLE_NUM_REC_BYTES(RSI_BLE_NUM_REC_BYTES) |
55+
SL_SI91X_BLE_ENABLE_ADV_EXTN |
56+
SL_SI91X_BLE_AE_MAX_ADV_SETS(RSI_BLE_AE_MAX_ADV_SETS);
57+
#endif
58+
3959
/* TODO: If sl_net_*_profile() functions will be needed for WiFi then call
4060
* sl_net_set_profile() here. Currently these are unused.
4161
*/

0 commit comments

Comments
 (0)