Bluetooth: drivers: Convert ST STM32WBA driver to new API
Convert the hci_stm32wba.c driver to the new HCI API. Unlike in most cases, the devicetree node is already enabled on the SoC level (rather than board level). This is in order to mirror how the Kconfig option was originally enabled, i.e. on the SoC level. Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
This commit is contained in:
parent
5a09c17746
commit
b7b606bdaf
5 changed files with 48 additions and 22 deletions
|
@ -66,6 +66,8 @@ config BT_STM32_IPM
|
||||||
|
|
||||||
config BT_STM32WBA
|
config BT_STM32WBA
|
||||||
bool "STM32WBA HCI driver"
|
bool "STM32WBA HCI driver"
|
||||||
|
default y
|
||||||
|
depends on DT_HAS_ST_HCI_STM32WBA_ENABLED
|
||||||
select HAS_STM32LIB
|
select HAS_STM32LIB
|
||||||
help
|
help
|
||||||
ST STM32WBA HCI Bluetooth interface
|
ST STM32WBA HCI Bluetooth interface
|
||||||
|
|
|
@ -7,11 +7,10 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/sys/util.h>
|
#include <zephyr/sys/util.h>
|
||||||
#include <zephyr/bluetooth/hci.h>
|
#include <zephyr/bluetooth/hci.h>
|
||||||
#include <zephyr/drivers/bluetooth/hci_driver.h>
|
#include <zephyr/drivers/bluetooth.h>
|
||||||
#include <zephyr/bluetooth/addr.h>
|
#include <zephyr/bluetooth/addr.h>
|
||||||
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
|
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
|
||||||
#include <linklayer_plat_local.h>
|
#include <linklayer_plat_local.h>
|
||||||
|
@ -27,6 +26,12 @@
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
LOG_MODULE_REGISTER(hci_wba);
|
LOG_MODULE_REGISTER(hci_wba);
|
||||||
|
|
||||||
|
#define DT_DRV_COMPAT st_hci_stm32wba
|
||||||
|
|
||||||
|
struct hci_data {
|
||||||
|
bt_hci_recv_t recv;
|
||||||
|
};
|
||||||
|
|
||||||
static K_SEM_DEFINE(hci_sem, 1, 1);
|
static K_SEM_DEFINE(hci_sem, 1, 1);
|
||||||
|
|
||||||
#define BLE_CTRLR_STACK_BUFFER_SIZE 300
|
#define BLE_CTRLR_STACK_BUFFER_SIZE 300
|
||||||
|
@ -212,9 +217,10 @@ static struct net_buf *treat_iso(const uint8_t *data, size_t len,
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int receive_data(const uint8_t *data, size_t len,
|
static int receive_data(const struct device *dev, const uint8_t *data, size_t len,
|
||||||
const uint8_t *ext_data, size_t ext_len)
|
const uint8_t *ext_data, size_t ext_len)
|
||||||
{
|
{
|
||||||
|
struct hci_data *hci = dev->data;
|
||||||
uint8_t pkt_indicator;
|
uint8_t pkt_indicator;
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -242,7 +248,7 @@ static int receive_data(const uint8_t *data, size_t len,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf) {
|
if (buf) {
|
||||||
bt_recv(buf);
|
hci->recv(dev, buf);
|
||||||
} else {
|
} else {
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
ll_state_busy = 1;
|
ll_state_busy = 1;
|
||||||
|
@ -254,6 +260,7 @@ static int receive_data(const uint8_t *data, size_t len,
|
||||||
uint8_t BLECB_Indication(const uint8_t *data, uint16_t length,
|
uint8_t BLECB_Indication(const uint8_t *data, uint16_t length,
|
||||||
const uint8_t *ext_data, uint16_t ext_length)
|
const uint8_t *ext_data, uint16_t ext_length)
|
||||||
{
|
{
|
||||||
|
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0));
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
@ -264,7 +271,7 @@ uint8_t BLECB_Indication(const uint8_t *data, uint16_t length,
|
||||||
|
|
||||||
k_sem_take(&hci_sem, K_FOREVER);
|
k_sem_take(&hci_sem, K_FOREVER);
|
||||||
|
|
||||||
err = receive_data(data, (size_t)length - 1,
|
err = receive_data(dev, data, (size_t)length - 1,
|
||||||
ext_data, (size_t)ext_length);
|
ext_data, (size_t)ext_length);
|
||||||
|
|
||||||
k_sem_give(&hci_sem);
|
k_sem_give(&hci_sem);
|
||||||
|
@ -278,12 +285,14 @@ uint8_t BLECB_Indication(const uint8_t *data, uint16_t length,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bt_hci_stm32wba_send(struct net_buf *buf)
|
static int bt_hci_stm32wba_send(const struct device *dev, struct net_buf *buf)
|
||||||
{
|
{
|
||||||
uint16_t event_length;
|
uint16_t event_length;
|
||||||
uint8_t pkt_indicator;
|
uint8_t pkt_indicator;
|
||||||
uint8_t tx_buffer[BLE_CTRLR_STACK_BUFFER_SIZE];
|
uint8_t tx_buffer[BLE_CTRLR_STACK_BUFFER_SIZE];
|
||||||
|
|
||||||
|
ARG_UNUSED(dev);
|
||||||
|
|
||||||
k_sem_take(&hci_sem, K_FOREVER);
|
k_sem_take(&hci_sem, K_FOREVER);
|
||||||
|
|
||||||
LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
|
LOG_DBG("buf %p type %u len %u", buf, bt_buf_get_type(buf), buf->len);
|
||||||
|
@ -311,7 +320,7 @@ static int bt_hci_stm32wba_send(struct net_buf *buf)
|
||||||
LOG_DBG("event_length: %u", event_length);
|
LOG_DBG("event_length: %u", event_length);
|
||||||
|
|
||||||
if (event_length) {
|
if (event_length) {
|
||||||
receive_data((uint8_t *)&tx_buffer, (size_t)event_length, NULL, 0);
|
receive_data(dev, (uint8_t *)&tx_buffer, (size_t)event_length, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
k_sem_give(&hci_sem);
|
k_sem_give(&hci_sem);
|
||||||
|
@ -349,8 +358,9 @@ static int bt_ble_ctlr_init(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bt_hci_stm32wba_open(void)
|
static int bt_hci_stm32wba_open(const struct device *dev, bt_hci_recv_t recv)
|
||||||
{
|
{
|
||||||
|
struct hci_data *data = dev->data;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
link_layer_register_isr();
|
link_layer_register_isr();
|
||||||
|
@ -358,6 +368,9 @@ static int bt_hci_stm32wba_open(void)
|
||||||
ll_sys_config_params();
|
ll_sys_config_params();
|
||||||
|
|
||||||
ret = bt_ble_ctlr_init();
|
ret = bt_ble_ctlr_init();
|
||||||
|
if (ret == 0) {
|
||||||
|
data->recv = recv;
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO. Enable Flash manager once available */
|
/* TODO. Enable Flash manager once available */
|
||||||
if (IS_ENABLED(CONFIG_FLASH)) {
|
if (IS_ENABLED(CONFIG_FLASH)) {
|
||||||
|
@ -367,18 +380,16 @@ static int bt_hci_stm32wba_open(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct bt_hci_driver drv = {
|
static const struct bt_hci_driver_api drv = {
|
||||||
.name = "BT IPM",
|
|
||||||
.bus = BT_HCI_DRIVER_BUS_IPM,
|
|
||||||
.open = bt_hci_stm32wba_open,
|
.open = bt_hci_stm32wba_open,
|
||||||
.send = bt_hci_stm32wba_send,
|
.send = bt_hci_stm32wba_send,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int bt_stm32wba_hci_init(void)
|
#define HCI_DEVICE_INIT(inst) \
|
||||||
{
|
static struct hci_data hci_data_##inst = { \
|
||||||
bt_hci_driver_register(&drv);
|
}; \
|
||||||
|
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &hci_data_##inst, NULL, \
|
||||||
|
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv)
|
||||||
|
|
||||||
return 0;
|
/* Only one instance supported */
|
||||||
}
|
HCI_DEVICE_INIT(0)
|
||||||
|
|
||||||
SYS_INIT(bt_stm32wba_hci_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
|
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
zephyr,entropy = &rng;
|
zephyr,entropy = &rng;
|
||||||
zephyr,flash-controller = &flash;
|
zephyr,flash-controller = &flash;
|
||||||
st,lptim-stdby-timer = &rtc;
|
st,lptim-stdby-timer = &rtc;
|
||||||
|
zephyr,bt-hci = &bt_hci_wba;
|
||||||
};
|
};
|
||||||
|
|
||||||
cpus {
|
cpus {
|
||||||
|
@ -472,6 +473,11 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bt_hci_wba: bt_hci_wba {
|
||||||
|
compatible = "st,hci-stm32wba";
|
||||||
|
status = "okay";
|
||||||
|
};
|
||||||
|
|
||||||
swj_port: swj_port {
|
swj_port: swj_port {
|
||||||
compatible = "swj-connector";
|
compatible = "swj-connector";
|
||||||
pinctrl-0 = <&debug_jtms_swdio_pa13 &debug_jtck_swclk_pa14
|
pinctrl-0 = <&debug_jtms_swdio_pa13 &debug_jtck_swclk_pa14
|
||||||
|
|
11
dts/bindings/bluetooth/st,hci-stm32wba.yaml
Normal file
11
dts/bindings/bluetooth/st,hci-stm32wba.yaml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
description: Bluetooth HCI driver for ST STM32WBA
|
||||||
|
|
||||||
|
compatible: "st,hci-stm32wba"
|
||||||
|
|
||||||
|
include: bt-hci.yaml
|
||||||
|
|
||||||
|
properties:
|
||||||
|
bt-hci-name:
|
||||||
|
default: "BT IPM"
|
||||||
|
bt-hci-bus:
|
||||||
|
default: "BT_HCI_BUS_IPM"
|
|
@ -13,10 +13,6 @@ config STM32_LPTIM_TIMER
|
||||||
config STM32_FLASH_PREFETCH
|
config STM32_FLASH_PREFETCH
|
||||||
default y
|
default y
|
||||||
|
|
||||||
config BT_STM32WBA
|
|
||||||
depends on BT
|
|
||||||
default y
|
|
||||||
|
|
||||||
config BT_STM32WBA
|
config BT_STM32WBA
|
||||||
select DYNAMIC_INTERRUPTS
|
select DYNAMIC_INTERRUPTS
|
||||||
select DYNAMIC_DIRECT_INTERRUPTS
|
select DYNAMIC_DIRECT_INTERRUPTS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue