Bluetooth: drivers: Convert ESP32 HCI driver to new API

Convert the hci_esp32.c HCI driver to the new HCI driver API.

Signed-off-by: Johan Hedberg <johan.hedberg@gmail.com>
This commit is contained in:
Johan Hedberg 2024-05-31 14:27:11 +03:00 committed by Anas Nashif
commit 8953b4eb63
62 changed files with 195 additions and 100 deletions

View file

@ -12,9 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_ESP32_DEVKITC_WROOM_ESP32_PROCPU
if BOARD_ESP32_DEVKITC_WROOM_ESP32_APPCPU

View file

@ -36,6 +36,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
};
@ -165,3 +166,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -10,9 +10,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_ESP32_DEVKITC_WROVER_ESP32_PROCPU
if BOARD_ESP32_DEVKITC_WROVER_ESP32_APPCPU

View file

@ -36,6 +36,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
};
@ -161,3 +162,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -19,9 +19,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_ESP32_ETHERNET_KIT_ESP32_PROCPU
if BOARD_ESP32_ETHERNET_KIT_ESP32_APPCPU

View file

@ -23,6 +23,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
};
@ -122,3 +123,7 @@
&eth {
phy-handle = <&phy>;
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -9,6 +9,3 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 51200 if WIFI
default 40960 if BT
default 4096
config BT_ESP32
default y if BT

View file

@ -20,6 +20,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -130,3 +131,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -12,9 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_ESP32S3_DEVKITC_ESP32S3_PROCPU
if BOARD_ESP32S3_DEVKITC_ESP32S3_APPCPU

View file

@ -25,6 +25,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -168,3 +169,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -12,9 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_ESP32S3_DEVKITM_ESP32S3_PROCPU
if BOARD_ESP32S3_DEVKITM_ESP32S3_APPCPU

View file

@ -25,6 +25,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -172,3 +173,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -12,9 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
config DISK_DRIVER_SDMMC
default y

View file

@ -36,6 +36,7 @@
zephyr,code-partition = &slot0_partition;
zephyr,display = &ili9341;
zephyr,sdhc = &sdhc1;
zephyr,bt-hci = &esp32_bt_hci;
};
leds {
@ -243,3 +244,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -25,9 +25,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_ODROID_GO_ESP32_PROCPU
if BOARD_ODROID_GO_ESP32_APPCPU

View file

@ -20,6 +20,7 @@
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,display = &ili9341;
zephyr,bt-hci = &esp32_bt_hci;
};
leds {
@ -206,3 +207,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -12,9 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_HELTEC_WIFI_LORA32_V2_ESP32_PROCPU
if BOARD_HELTEC_WIFI_LORA32_V2_ESP32_APPCPU

View file

@ -55,6 +55,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
};
@ -149,5 +150,9 @@
};
};
&esp32_bt_hci {
status = "okay";
};
/* Required by the ssd1306_128x64 shield which enables the OLED display */
arduino_i2c: &i2c0 {};

View file

@ -13,9 +13,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_HELTEC_WIRELESS_STICK_LITE_V3_ESP32S3_PROCPU
if BOARD_HELTEC_WIRELESS_STICK_LITE_V3_ESP32S3_APPCPU

View file

@ -72,6 +72,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
};
@ -205,3 +206,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -10,9 +10,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_KINCONY_KC868_A32_ESP32_PROCPU
if BOARD_KINCONY_KC868_A32_ESP32_APPCPU

View file

@ -23,6 +23,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
};
@ -203,3 +204,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -9,6 +9,3 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 51200 if WIFI
default 40960 if BT
default 4096
config BT_ESP32
default y if BT

View file

@ -15,5 +15,6 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
};

View file

@ -130,3 +130,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -12,9 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_ESP32S3_LUATOS_CORE_ESP32S3_PROCPU || BOARD_ESP32S3_LUATOS_CORE_ESP32S3_PROCPU_USB
if BOARD_ESP32S3_LUATOS_CORE_ESP32S3_APPCPU || BOARD_ESP32S3_LUATOS_CORE_ESP32S3_APPCPU_USB

View file

@ -141,3 +141,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -26,5 +26,6 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
};

View file

@ -25,6 +25,7 @@
zephyr,console = &usb_serial;
zephyr,shell-uart = &usb_serial;
zephyr,flash = &flash0;
zephyr,bt_hci = &esp32_bt_hci;
};
};

View file

@ -12,9 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_M5STACK_ATOM_LITE_ESP32_PROCPU
if BOARD_M5STACK_ATOM_LITE_ESP32_APPCPU

View file

@ -24,6 +24,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -180,3 +181,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -14,9 +14,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_M5STACK_ATOMS3_ESP32S3_PROCPU
if BOARD_M5STACK_ATOMS3_ESP32S3_APPCPU

View file

@ -21,6 +21,7 @@
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,display = &st7789v;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -177,3 +178,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -14,9 +14,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
config KERNEL_MEM_POOL
default y
config BT_ESP32
default y if BT
endif # BOARD_M5STACK_ATOMS3_LITE_ESP32S3_PROCPU
if BOARD_M5STACK_ATOMS3_LITE_ESP32S3_APPCPU

View file

@ -22,6 +22,7 @@
zephyr,shell-uart = &usb_serial;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -145,3 +146,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -15,9 +15,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
config KERNEL_MEM_POOL
default y
config BT_ESP32
default y if BT
config GPIO_HOGS_INIT_PRIORITY
default 70

View file

@ -34,6 +34,7 @@
zephyr,display = &ili9342c;
zephyr,code-partition = &slot0_partition;
zephyr,rtc = &pfc8563_rtc;
zephyr,bt-hci = &esp32_bt_hci;
};
leds {
@ -283,3 +284,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -14,9 +14,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
config KERNEL_MEM_POOL
default y
config BT_ESP32
default y if BT
endif # BOARD_M5STACK_STAMPS3_ESP32S3_PROCPU
if BOARD_M5STACK_STAMPS3_ESP32S3_APPCPU

View file

@ -23,6 +23,7 @@
zephyr,shell-uart = &usb_serial;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -185,3 +186,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -12,9 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
config GPIO_HOGS_INIT_PRIORITY
default 70

View file

@ -33,6 +33,7 @@
zephyr,code-partition = &slot0_partition;
zephyr,rtc = &bm8563;
zephyr,display = &st7789v;
zephyr,bt-hci = &esp32_bt_hci;
};
leds {
@ -240,3 +241,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -9,10 +9,3 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 51200 if WIFI
default 40960 if BT
default 4096
if BT
config BT_ESP32
default y
endif # BT

View file

@ -20,6 +20,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -129,3 +130,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -12,9 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_OLIMEX_ESP32_EVB_ESP32_PROCPU
if BOARD_OLIMEX_ESP32_EVB_ESP32_APPCPU

View file

@ -20,6 +20,7 @@
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -164,3 +165,7 @@ uext_spi: &spi2 {};
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -7,6 +7,3 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 51200 if WIFI
default 40960 if BT
default 4096
config BT_ESP32
default y if BT

View file

@ -20,6 +20,7 @@
zephyr,shell-uart = &usb_serial;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -126,3 +127,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -7,6 +7,3 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 51200 if WIFI
default 40960 if BT
default 4096
config BT_ESP32
default y if BT

View file

@ -21,6 +21,7 @@
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,canbus = &twai;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -118,3 +119,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -10,9 +10,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_XIAO_ESP32S3_ESP32S3_PROCPU
if BOARD_XIAO_ESP32S3_ESP32S3_APPCPU

View file

@ -20,6 +20,7 @@
zephyr,shell-uart = &usb_serial;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
aliases {
@ -127,3 +128,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -12,9 +12,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_YD_ESP32_ESP32_PROCPU
if BOARD_YD_ESP32_ESP32_APPCPU

View file

@ -35,6 +35,7 @@
zephyr,shell-uart = &uart0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,bt-hci = &esp32_bt_hci;
};
};
@ -173,3 +174,7 @@
};
};
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -10,9 +10,6 @@ config HEAP_MEM_POOL_ADD_SIZE_BOARD
default 40960 if BT
default 4096
config BT_ESP32
default y if BT
endif # BOARD_ESP32S3_TOUCH_LCD_1_28_ESP32S3_PROCPU
if BOARD_ESP32S3_TOUCH_LCD_1_28_ESP32S3_APPCPU

View file

@ -30,6 +30,7 @@
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,display = &gc9a01;
zephyr,bt-hci = &esp32_bt_hci;
};
/* Buttons */
@ -174,3 +175,7 @@
&wdt0 {
status = "okay";
};
&esp32_bt_hci {
status = "okay";
};

View file

@ -98,6 +98,8 @@ config BT_USERCHAN
config BT_ESP32
bool "ESP32 HCI driver"
default y
depends on DT_HAS_ESPRESSIF_ESP32_BT_HCI_ENABLED
help
Espressif HCI bluetooth interface

View file

@ -9,7 +9,7 @@
#include <zephyr/init.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/drivers/bluetooth/hci_driver.h>
#include <zephyr/drivers/bluetooth.h>
#include <esp_bt.h>
@ -17,8 +17,14 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_hci_driver_esp32);
#define DT_DRV_COMPAT espressif_esp32_bt_hci
#define HCI_BT_ESP32_TIMEOUT K_MSEC(2000)
struct bt_esp32_data {
bt_hci_recv_t recv;
};
static K_SEM_DEFINE(hci_send_sem, 1, 1);
static bool is_hci_event_discardable(const uint8_t *evt_data)
@ -180,6 +186,8 @@ static struct net_buf *bt_esp_iso_recv(uint8_t *data, size_t remaining)
static int hci_esp_host_rcv_pkt(uint8_t *data, uint16_t len)
{
const struct device *dev = DEVICE_DT_GET(DT_DRV_INST(0));
struct bt_esp32_data *hci = dev->data;
uint8_t pkt_indicator;
struct net_buf *buf = NULL;
size_t remaining = len;
@ -210,7 +218,7 @@ static int hci_esp_host_rcv_pkt(uint8_t *data, uint16_t len)
if (buf) {
LOG_DBG("Calling bt_recv(%p)", buf);
bt_recv(buf);
hci->recv(dev, buf);
}
return 0;
@ -226,7 +234,7 @@ static esp_vhci_host_callback_t vhci_host_cb = {
hci_esp_host_rcv_pkt
};
static int bt_esp32_send(struct net_buf *buf)
static int bt_esp32_send(const struct device *dev, struct net_buf *buf)
{
int err = 0;
uint8_t pkt_indicator;
@ -316,8 +324,9 @@ static int bt_esp32_ble_deinit(void)
return 0;
}
static int bt_esp32_open(void)
static int bt_esp32_open(const struct device *dev, bt_hci_recv_t recv)
{
struct bt_esp32_data *hci = dev->data;
int err;
err = bt_esp32_ble_init();
@ -325,13 +334,16 @@ static int bt_esp32_open(void)
return err;
}
hci->recv = recv;
LOG_DBG("ESP32 BT started");
return 0;
}
static int bt_esp32_close(void)
static int bt_esp32_close(const struct device *dev)
{
struct bt_esp32_data *hci = dev->data;
int err;
err = bt_esp32_ble_deinit();
@ -339,27 +351,24 @@ static int bt_esp32_close(void)
return err;
}
hci->recv = NULL;
LOG_DBG("ESP32 BT stopped");
return 0;
}
static const struct bt_hci_driver drv = {
.name = "BT ESP32",
static const struct bt_hci_driver_api drv = {
.open = bt_esp32_open,
.send = bt_esp32_send,
.close = bt_esp32_close,
.bus = BT_HCI_DRIVER_BUS_IPM,
#if defined(CONFIG_BT_DRIVER_QUIRK_NO_AUTO_DLE)
.quirks = BT_QUIRK_NO_AUTO_DLE,
#endif
};
static int bt_esp32_init(void)
{
bt_hci_driver_register(&drv);
#define BT_ESP32_DEVICE_INIT(inst) \
static struct bt_esp32_data bt_esp32_data_##inst = { \
}; \
DEVICE_DT_INST_DEFINE(inst, NULL, NULL, &bt_esp32_data_##inst, NULL, \
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, &drv)
return 0;
}
SYS_INIT(bt_esp32_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
/* Only one instance supported */
BT_ESP32_DEVICE_INIT(0)

View file

@ -0,0 +1,13 @@
description: Bluetooth HCI for Espressif ESP32
compatible: "espressif,esp32-bt-hci"
include: bt-hci.yaml
properties:
bt-hci-name:
default: "BT ESP32"
bt-hci-bus:
default: "BT_HCI_BUS_IPM"
bt-hci-quirks:
default: ["BT_HCI_QUIRK_NO_AUTO_DLE"]

View file

@ -24,6 +24,7 @@
zephyr,canbus = &twai;
zephyr,entropy = &trng0;
zephyr,flash-controller = &flash;
zephyr,bt-hci = &esp32_bt_hci;
};
cpus {
@ -68,6 +69,11 @@
status = "disabled";
};
esp32_bt_hci: esp32_bt_hci {
compatible = "espressif,esp32-bt-hci";
status = "disabled";
};
soc {
#address-cells = <1>;
#size-cells = <1>;

View file

@ -19,6 +19,7 @@
zephyr,canbus = &twai;
zephyr,entropy = &trng0;
zephyr,flash-controller = &flash;
zephyr,bt-hci = &esp32_bt_hci;
};
cpus {
@ -66,6 +67,11 @@
status = "disabled";
};
esp32_bt_hci: esp32_bt_hci {
compatible = "espressif,esp32-bt-hci";
status = "disabled";
};
eth: eth {
compatible = "espressif,esp32-eth";
interrupts = <ETH_MAC_INTR_SOURCE>;

View file

@ -63,6 +63,11 @@
status = "disabled";
};
esp32_bt_hci: esp32_bt_hci {
compatible = "espressif,esp32-bt-hci";
status = "disabled";
};
pinctrl: pin-controller {
compatible = "espressif,esp32-pinctrl";
status = "okay";

View file

@ -70,6 +70,11 @@
status = "disabled";
};
esp32_bt_hci: esp32_bt_hci {
compatible = "espressif,esp32-bt-hci";
status = "disabled";
};
pinctrl: pin-controller {
compatible = "espressif,esp32-pinctrl";
status = "okay";