-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: bluetooth: siwx917: Add Bluetooth HCI driver
PR finding fixes
- Loading branch information
1 parent
892c436
commit f1f60ab
Showing
17 changed files
with
321 additions
and
40 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -11,4 +11,5 @@ toolchain: | |
supported: | ||
- gpio | ||
- i2c | ||
- bluetooth | ||
vendor: silabs |
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory(bluetooth) | ||
add_subdirectory(gpio) | ||
add_subdirectory(pinctrl) | ||
add_subdirectory(wifi) |
This file contains 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,4 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory(hci) |
This file contains 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,8 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
if BT_HCI | ||
|
||
rsource "hci/Kconfig.siwx917" | ||
|
||
endif |
This file contains 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,4 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
zephyr_library_sources_ifdef(CONFIG_BT_SIWX917 siwx917_hci.c) |
This file contains 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,10 @@ | ||
# Copyright (c) 2024 Silicon Laboratories Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config BT_SIWX917 | ||
bool "Silabs SiWx917 Bluetooth interface" | ||
default y | ||
depends on DT_HAS_SILABS_SIWX917_BT_HCI_ENABLED | ||
select SIWX917_NWP_NETWORK_STACK | ||
help | ||
Use Silicon Labs Wiseconnect 3.x Bluetooth library to connect to the controller. |
This file contains 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,118 @@ | ||
/* | ||
* Copyright (c) 2024 Silicon Laboratories Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/kernel.h> | ||
#include <zephyr/drivers/bluetooth.h> | ||
|
||
#define DT_DRV_COMPAT silabs_siwx917_bt_hci | ||
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL | ||
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(bt_hci_driver_siwg917); | ||
|
||
#include "rsi_ble.h" | ||
|
||
static void bt_siwg917_resp_rcvd(uint16_t status, rsi_ble_event_rcp_rcvd_info_t *resp_buf); | ||
|
||
struct hci_data { | ||
bt_hci_recv_t recv; | ||
rsi_data_packet_t rsi_data_packet; | ||
}; | ||
|
||
static int bt_siwg917_open(const struct device *dev, bt_hci_recv_t recv) | ||
{ | ||
struct hci_data *hci = dev->data; | ||
int status = rsi_ble_enhanced_gap_extended_register_callbacks(RSI_BLE_ON_RCP_EVENT, | ||
(void *)bt_siwg917_resp_rcvd); | ||
|
||
if (!status) { | ||
hci->recv = recv; | ||
} | ||
return status ? -EIO : 0; | ||
} | ||
|
||
static int bt_siwg917_send(const struct device *dev, struct net_buf *buf) | ||
{ | ||
struct hci_data *hci = dev->data; | ||
int sc = -EOVERFLOW; | ||
uint8_t packet_type = BT_HCI_H4_NONE; | ||
|
||
switch (bt_buf_get_type(buf)) { | ||
case BT_BUF_ACL_OUT: | ||
packet_type = BT_HCI_H4_ACL; | ||
break; | ||
case BT_BUF_CMD: | ||
packet_type = BT_HCI_H4_CMD; | ||
break; | ||
default: | ||
sc = -EINVAL; | ||
break; | ||
} | ||
|
||
if ((packet_type != BT_HCI_H4_NONE) && (buf->len < sizeof(hci->rsi_data_packet.data))) { | ||
net_buf_push_u8(buf, packet_type); | ||
memcpy(&hci->rsi_data_packet, buf->data, buf->len); | ||
sc = rsi_bt_driver_send_cmd(RSI_BLE_REQ_HCI_RAW, &hci->rsi_data_packet, NULL); | ||
/* TODO SILABS ZEPHYR Convert to errno. A common function from rsi/sl_status should | ||
* be introduced | ||
*/ | ||
if (sc) { | ||
LOG_ERR("BT command send failure: %d", sc); | ||
sc = -EIO; | ||
} | ||
} | ||
net_buf_unref(buf); | ||
return sc; | ||
} | ||
|
||
static void bt_siwg917_resp_rcvd(uint16_t status, rsi_ble_event_rcp_rcvd_info_t *resp_buf) | ||
{ | ||
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0)); | ||
struct hci_data *hci = dev->data; | ||
uint8_t packet_type = BT_HCI_H4_NONE; | ||
size_t len = 0; | ||
struct net_buf *buf = NULL; | ||
|
||
/* TODO SILABS ZEPHYR This horror expression is from the WiseConnect from the HCI example... | ||
* No workaround have been found until now. | ||
*/ | ||
memcpy(&packet_type, (resp_buf->data - 12), 1); | ||
switch (packet_type) { | ||
case BT_HCI_H4_EVT: { | ||
struct bt_hci_evt_hdr *hdr = (void *)resp_buf->data; | ||
|
||
len = hdr->len + sizeof(*hdr); | ||
buf = bt_buf_get_evt(hdr->evt, false, K_FOREVER); | ||
break; | ||
} | ||
case BT_HCI_H4_ACL: { | ||
struct bt_hci_acl_hdr *hdr = (void *)resp_buf->data; | ||
|
||
len = hdr->len + sizeof(*hdr); | ||
buf = bt_buf_get_rx(BT_BUF_ACL_IN, K_FOREVER); | ||
break; | ||
} | ||
default: | ||
LOG_ERR("Unknown/Unhandled HCI type: %d", packet_type); | ||
break; | ||
} | ||
|
||
if (buf && (len <= net_buf_tailroom(buf))) { | ||
net_buf_add_mem(buf, resp_buf->data, len); | ||
hci->recv(dev, buf); | ||
} | ||
} | ||
|
||
static const struct bt_hci_driver_api drv = { | ||
.open = bt_siwg917_open, | ||
.send = bt_siwg917_send, | ||
}; | ||
|
||
#define HCI_DEVICE_INIT(inst) \ | ||
static struct hci_data hci_data_##inst; \ | ||
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &hci_data_##inst, NULL, POST_KERNEL, \ | ||
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv) | ||
|
||
/* Only one instance supported right now */ | ||
HCI_DEVICE_INIT(0) |
This file contains 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 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 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 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,13 @@ | ||
description: Bluetooth HCI on Silabs boards | ||
|
||
compatible: "silabs,siwx917-bt-hci" | ||
|
||
include: bt-hci.yaml | ||
|
||
properties: | ||
bt-hci-name: | ||
default: "sl:siwx917:bt" | ||
bt-hci-bus: | ||
default: "BT_HCI_BUS_VIRTUAL" | ||
bt-hci-quirks: | ||
default: ["BT_HCI_QUIRK_NO_RESET"] |
This file contains 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 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.