Bluetooth: drivers: Convert Ambiq Apollo driver to new API
Convert the Ambiq Apollo HCI driver to the new HCI API. Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
This commit is contained in:
parent
eddac27c4e
commit
130ae9e120
13 changed files with 49 additions and 32 deletions
|
|
@ -15,6 +15,7 @@
|
|||
zephyr,shell-uart = &uart0;
|
||||
zephyr,uart-pipe = &uart0;
|
||||
zephyr,flash-controller = &flash;
|
||||
zephyr,bt_hci = &bt_hci_apollo;
|
||||
};
|
||||
|
||||
aliases {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
zephyr,shell-uart = &uart0;
|
||||
zephyr,uart-pipe = &uart0;
|
||||
zephyr,flash-controller = &flash;
|
||||
zephyr,bt_hci = &bt_hci_apollo;
|
||||
};
|
||||
|
||||
aliases {
|
||||
|
|
|
|||
|
|
@ -9,9 +9,6 @@ if BT
|
|||
config MAIN_STACK_SIZE
|
||||
default 2048
|
||||
|
||||
config BT_AMBIQ_HCI
|
||||
default y
|
||||
|
||||
config BT_BUF_ACL_TX_COUNT
|
||||
default 14
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
zephyr,shell-uart = &uart0;
|
||||
zephyr,uart-pipe = &uart0;
|
||||
zephyr,flash-controller = &flash;
|
||||
zephyr,bt-hci = &bt_hci_apollo;
|
||||
};
|
||||
|
||||
aliases {
|
||||
|
|
|
|||
|
|
@ -127,6 +127,8 @@ config BT_NO_DRIVER
|
|||
|
||||
config BT_AMBIQ_HCI
|
||||
bool "AMBIQ BT HCI driver"
|
||||
default y
|
||||
depends on DT_HAS_AMBIQ_BT_HCI_SPI_ENABLED
|
||||
select SPI
|
||||
select GPIO if SOC_SERIES_APOLLO4X
|
||||
select CLOCK_CONTROL if SOC_SERIES_APOLLO4X
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/drivers/gpio.h>
|
||||
#include <zephyr/drivers/pinctrl.h>
|
||||
#include <zephyr/drivers/bluetooth/hci_driver.h>
|
||||
#include <zephyr/drivers/bluetooth.h>
|
||||
#include <zephyr/bluetooth/hci.h>
|
||||
#include <zephyr/bluetooth/hci_raw.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
#include <zephyr/init.h>
|
||||
#include <zephyr/sys/byteorder.h>
|
||||
#include <zephyr/drivers/spi.h>
|
||||
#include <zephyr/drivers/bluetooth/hci_driver.h>
|
||||
#include <zephyr/drivers/bluetooth.h>
|
||||
#include <zephyr/bluetooth/hci.h>
|
||||
|
||||
#define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
|
||||
|
|
@ -72,6 +72,10 @@ static const struct spi_buf_set spi_rx = {.buffers = &spi_rx_buf, .count = 1};
|
|||
static K_SEM_DEFINE(sem_irq, 0, 1);
|
||||
static K_SEM_DEFINE(sem_spi_available, 1, 1);
|
||||
|
||||
struct bt_apollo_data {
|
||||
bt_hci_recv_t recv;
|
||||
};
|
||||
|
||||
void bt_packet_irq_isr(const struct device *unused1, struct gpio_callback *unused2,
|
||||
uint32_t unused3)
|
||||
{
|
||||
|
|
@ -288,7 +292,9 @@ static struct net_buf *bt_hci_acl_recv(uint8_t *data, size_t len)
|
|||
|
||||
static void bt_spi_rx_thread(void *p1, void *p2, void *p3)
|
||||
{
|
||||
ARG_UNUSED(p1);
|
||||
const struct device *dev = p1;
|
||||
struct bt_apollo_data *hci = dev->data;
|
||||
|
||||
ARG_UNUSED(p2);
|
||||
ARG_UNUSED(p3);
|
||||
|
||||
|
|
@ -331,13 +337,13 @@ static void bt_spi_rx_thread(void *p1, void *p2, void *p3)
|
|||
|
||||
/* Post the RX message to host stack to process */
|
||||
if (buf) {
|
||||
bt_recv(buf);
|
||||
hci->recv(dev, buf);
|
||||
}
|
||||
} while (0);
|
||||
}
|
||||
}
|
||||
|
||||
static int bt_hci_send(struct net_buf *buf)
|
||||
static int bt_apollo_send(const struct device *dev, struct net_buf *buf)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
|
@ -368,8 +374,9 @@ static int bt_hci_send(struct net_buf *buf)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int bt_hci_open(void)
|
||||
static int bt_apollo_open(const struct device *dev, bt_hci_recv_t recv)
|
||||
{
|
||||
struct bt_apollo_data *hci = dev->data;
|
||||
int ret;
|
||||
|
||||
ret = bt_hci_transport_setup(spi_dev);
|
||||
|
|
@ -379,15 +386,18 @@ static int bt_hci_open(void)
|
|||
|
||||
/* Start RX thread */
|
||||
k_thread_create(&spi_rx_thread_data, spi_rx_stack, K_KERNEL_STACK_SIZEOF(spi_rx_stack),
|
||||
(k_thread_entry_t)bt_spi_rx_thread, NULL, NULL, NULL,
|
||||
(k_thread_entry_t)bt_spi_rx_thread, (void *)dev, NULL, NULL,
|
||||
K_PRIO_COOP(CONFIG_BT_DRIVER_RX_HIGH_PRIO), 0, K_NO_WAIT);
|
||||
|
||||
ret = bt_apollo_controller_init(spi_send_packet);
|
||||
if (ret == 0) {
|
||||
hci->recv = recv;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int bt_spi_setup(const struct bt_hci_setup_params *params)
|
||||
static int bt_apollo_setup(const struct device *dev, const struct bt_hci_setup_params *params)
|
||||
{
|
||||
ARG_UNUSED(params);
|
||||
|
||||
|
|
@ -398,18 +408,18 @@ static int bt_spi_setup(const struct bt_hci_setup_params *params)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static const struct bt_hci_driver drv = {
|
||||
.name = "ambiq hci",
|
||||
.bus = BT_HCI_DRIVER_BUS_SPI,
|
||||
.open = bt_hci_open,
|
||||
.send = bt_hci_send,
|
||||
.setup = bt_spi_setup,
|
||||
static const struct bt_hci_driver_api drv = {
|
||||
.open = bt_apollo_open,
|
||||
.send = bt_apollo_send,
|
||||
.setup = bt_apollo_setup,
|
||||
};
|
||||
|
||||
static int bt_hci_init(void)
|
||||
static int bt_apollo_init(const struct device *dev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ARG_UNUSED(dev);
|
||||
|
||||
if (!device_is_ready(spi_dev)) {
|
||||
LOG_ERR("SPI device not ready");
|
||||
return -ENODEV;
|
||||
|
|
@ -420,11 +430,16 @@ static int bt_hci_init(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
bt_hci_driver_register(&drv);
|
||||
|
||||
LOG_DBG("BT HCI initialized");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SYS_INIT(bt_hci_init, POST_KERNEL, CONFIG_BT_HCI_INIT_PRIORITY);
|
||||
#define HCI_DEVICE_INIT(inst) \
|
||||
static struct bt_apollo_data hci_data_##inst = { \
|
||||
}; \
|
||||
DEVICE_DT_INST_DEFINE(inst, bt_apollo_init, NULL, &hci_data_##inst, NULL, \
|
||||
POST_KERNEL, CONFIG_BT_HCI_INIT_PRIORITY, &drv)
|
||||
|
||||
/* Only one instance supported right now */
|
||||
HCI_DEVICE_INIT(0)
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@
|
|||
status = "disabled";
|
||||
ambiq,pwrcfg = <&pwrcfg 0x8 0x8000>;
|
||||
|
||||
bt-hci@0 {
|
||||
bt_hci_apollo: bt-hci@0 {
|
||||
compatible = "ambiq,bt-hci-spi";
|
||||
reg = <0>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -307,7 +307,7 @@
|
|||
status = "disabled";
|
||||
ambiq,pwrcfg = <&pwrcfg 0x8 0x8000>;
|
||||
|
||||
bt-hci@0 {
|
||||
bt_hci_apollo: bt-hci@0 {
|
||||
compatible = "ambiq,bt-hci-spi";
|
||||
reg = <0>;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@
|
|||
status = "disabled";
|
||||
ambiq,pwrcfg = <&pwrcfg 0x4 0x20>;
|
||||
|
||||
bt-hci@0 {
|
||||
bt_hci_apollo: bt-hci@0 {
|
||||
compatible = "ambiq,bt-hci-spi";
|
||||
reg = <0>;
|
||||
irq-gpios = <&gpio32_63 21 GPIO_ACTIVE_HIGH>;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ description: |
|
|||
|
||||
compatible: "ambiq,bt-hci-spi"
|
||||
|
||||
include: bt-hci.yaml
|
||||
|
||||
properties:
|
||||
reg:
|
||||
type: array
|
||||
|
|
@ -30,3 +32,9 @@ properties:
|
|||
controller. The host needs to enable XO32MHz when receiving low to high
|
||||
edge interrupts and disable XO32MHz when receiving high to low edge
|
||||
interrupts.
|
||||
|
||||
bt-hci-name:
|
||||
default: "ambiq hci"
|
||||
|
||||
bt-hci-bus:
|
||||
default: "BT_HCI_BUS_SPI"
|
||||
|
|
|
|||
|
|
@ -12,10 +12,6 @@ config MAIN_STACK_SIZE
|
|||
|
||||
if BT
|
||||
|
||||
choice BT_HCI_BUS_TYPE
|
||||
default BT_AMBIQ_HCI
|
||||
endchoice
|
||||
|
||||
config BT_BUF_ACL_TX_COUNT
|
||||
default 4
|
||||
|
||||
|
|
|
|||
|
|
@ -12,10 +12,6 @@ config MAIN_STACK_SIZE
|
|||
|
||||
if BT
|
||||
|
||||
choice BT_HCI_BUS_TYPE
|
||||
default BT_AMBIQ_HCI
|
||||
endchoice
|
||||
|
||||
config BT_BUF_ACL_TX_COUNT
|
||||
default 4
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue