Skip to content

Commit

Permalink
bluetooth: call bt_driver_register common interface
Browse files Browse the repository at this point in the history
Signed-off-by: chengkai <[email protected]>
  • Loading branch information
chengkai15 committed Oct 16, 2024
1 parent 12189b2 commit 8ba9ed4
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 200 deletions.
5 changes: 0 additions & 5 deletions arch/arm/src/nrf52/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,6 @@ config NRF52_SDC_DLE
bool "Support Data Length Extension (DLE)"
default y

config NRF52_BLE_TTY_NAME
string "BLE TTY device name"
default "/dev/ttyHCI0"
depends on UART_BTH4

config NRF52_SDC_FICR_STATIC_ADDR
bool "Configure factory generated static random address"
default n
Expand Down
23 changes: 3 additions & 20 deletions arch/arm/src/nrf52/nrf52_sdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
#include <arch/nrf52/nrf52_irq.h>
#include <nuttx/wqueue.h>

#if defined(CONFIG_UART_BTH4)
# include <nuttx/serial/uart_bth4.h>
#endif

#include "arm_internal.h"
#include "ram_vectors.h"

Expand Down Expand Up @@ -918,26 +914,13 @@ int nrf52_sdc_initialize(void)
return ret;
}

#ifdef CONFIG_UART_BTH4
/* Register UART BT H4 device */

ret = uart_bth4_register(CONFIG_NRF52_BLE_TTY_NAME, &g_bt_driver);
#ifdef CONFIG_DRIVERS_BLUETOOTH
ret = bt_driver_register(&g_bt_driver);
if (ret < 0)
{
wlerr("bt_bth4_register error: %d\n", ret);
wlerr("bt_driver_register error: %d\n", ret);
return ret;
}
#elif defined(CONFIG_NET_BLUETOOTH)
/* Register network device */

ret = bt_netdev_register(&g_bt_driver);
if (ret < 0)
{
wlerr("bt_netdev_register error: %d\n", ret);
return ret;
}
#else
# error
#endif

return ret;
Expand Down
5 changes: 0 additions & 5 deletions arch/arm/src/nrf53/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -792,11 +792,6 @@ config NRF53_SDC_DLE
bool "Support Data Length Extension (DLE)"
default y

config NRF53_BLE_TTY_NAME
string "BLE TTY device name"
default "/dev/ttyHCI0"
depends on UART_BTH4

config NRF53_SDC_FICR_STATIC_ADDR
bool "Configure factory generated static random address"
default n
Expand Down
24 changes: 3 additions & 21 deletions arch/arm/src/nrf53/nrf53_sdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
#include <arch/nrf53/nrf5340_irq_cpunet.h>
#include <nuttx/wqueue.h>

#if defined(CONFIG_UART_BTH4)
# include <nuttx/serial/uart_bth4.h>
#endif
#ifdef CONFIG_BLUETOOTH_RPMSG_SERVER
# include <nuttx/wireless/bluetooth/bt_rpmsghci.h>
#endif
Expand Down Expand Up @@ -910,28 +907,13 @@ int nrf53_sdc_initialize(void)
return ret;
}

#ifdef CONFIG_UART_BTH4
/* Register UART BT H4 device */

ret = uart_bth4_register(CONFIG_NRF53_BLE_TTY_NAME, &g_bt_driver);
if (ret < 0)
{
wlerr("bt_bth4_register error: %d\n", ret);
return ret;
}
#elif defined(CONFIG_NET_BLUETOOTH)
/* Register network device */

ret = bt_netdev_register(&g_bt_driver);
#ifdef CONFIG_DRIVERS_BLUETOOTH
ret = bt_driver_register(&g_bt_driver);
if (ret < 0)
{
wlerr("bt_netdev_register error: %d\n", ret);
wlerr("bt_driver_register error: %d\n", ret);
return ret;
}
#elif defined(CONFIG_BLUETOOTH_RPMSG_SERVER)
/* Do nothing here */
#else
# error
#endif

return ret;
Expand Down
5 changes: 0 additions & 5 deletions arch/arm/src/stm32wb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1182,11 +1182,6 @@ config STM32WB_BLE_LE_CODED_PHY
default STM32WB_STM32WB15 || STM32WB_STM32WB35 || STM32WB_STM32WB55
depends on STM32WB_STM32WB15 || STM32WB_STM32WB35 || STM32WB_STM32WB55

config STM32WB_BLE_TTY_NAME
string "BLE TTY device name"
default "/dev/ttyHCI0"
depends on UART_BTH4

config STM32WB_BLE_FICR_STATIC_ADDR
bool "Configure factory generated static random address"
default n
Expand Down
21 changes: 3 additions & 18 deletions arch/arm/src/stm32wb/stm32wb_blehci.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
#include <nuttx/mutex.h>
#include <nuttx/wqueue.h>

#if defined(CONFIG_UART_BTH4)
# include <nuttx/serial/uart_bth4.h>
#endif

#include "stm32wb_ipcc.h"
#include "stm32wb_mbox.h"
#include "stm32wb_mbox_shci.h"
Expand Down Expand Up @@ -336,22 +332,11 @@ static int stm32wb_blehci_driverinitialize(void)
{
int ret = 0;

#ifdef CONFIG_UART_BTH4
/* Register UART BT H4 device */

ret = uart_bth4_register(CONFIG_STM32WB_BLE_TTY_NAME, &g_blehci_driver);
if (ret < 0)
{
wlerr("bt_bth4_register error: %d\n", ret);
return ret;
}
#elif defined(CONFIG_NET_BLUETOOTH)
/* Register network device */

ret = bt_netdev_register(&g_blehci_driver);
#ifdef CONFIG_DRIVERS_BLUETOOTH
ret = bt_driver_register(&g_blehci_driver);
if (ret < 0)
{
wlerr("bt_netdev_register error: %d\n", ret);
wlerr("bt_driver_register error: %d\n", ret);
return ret;
}
#endif
Expand Down
57 changes: 6 additions & 51 deletions arch/sim/src/sim/sim_hcisocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
#include <nuttx/net/bluetooth.h>
#include <nuttx/wireless/bluetooth/bt_driver.h>
#include <nuttx/wireless/bluetooth/bt_uart.h>
#include <nuttx/wireless/bluetooth/bt_bridge.h>
#include <nuttx/serial/uart_bth4.h>

#include "sim_internal.h"
#include "sim_hosthcisocket.h"
Expand Down Expand Up @@ -256,27 +254,6 @@ static void bthcisock_free(struct bthcisock_s *dev)
kmm_free(dev);
}

static int bthcisock_driver_register(struct bt_driver_s *drv, int id,
bool bt)
{
#ifdef CONFIG_UART_BTH4
char name[32];

if (bt)
{
snprintf(name, sizeof(name), "/dev/ttyBT%d", id);
}
else
{
snprintf(name, sizeof(name), "/dev/ttyBLE%d", id);
}

return uart_bth4_register(name, drv);
#else
return bt_netdev_register(drv);
#endif
}

/****************************************************************************
* Name: sim_bthcisock_work
*
Expand Down Expand Up @@ -320,10 +297,6 @@ static void sim_bthcisock_work(void *arg)
int sim_bthcisock_register(int dev_id)
{
struct bthcisock_s *dev;
#if defined(CONFIG_BLUETOOTH_BRIDGE)
struct bt_driver_s *btdrv;
struct bt_driver_s *bledrv;
#endif
int ret;

dev = bthcisock_alloc(dev_id);
Expand All @@ -332,35 +305,17 @@ int sim_bthcisock_register(int dev_id)
return -ENOMEM;
}

#if defined(CONFIG_BLUETOOTH_BRIDGE)
ret = bt_bridge_register(&dev->drv, &btdrv, &bledrv);
if (ret < 0)
{
goto end;
}

ret = bthcisock_driver_register(btdrv, dev_id, true);
if (ret < 0)
{
goto end;
}

ret = bthcisock_driver_register(bledrv, dev_id, false);
if (ret < 0)
{
goto end;
}

end:
#else
ret = bthcisock_driver_register(&dev->drv, dev_id, true);
#endif

#ifdef CONFIG_DRIVERS_BLUETOOTH
ret = bt_driver_register_with_id(&dev->drv, dev_id);
if (ret < 0)
{
wlerr("bt_driver_register error: %d\n", ret);
bthcisock_free(dev);
return ret;
}
#else
# error "Please select CONFIG_DRIVERS_BLUETOOTH"
#endif

return work_queue(HPWORK, &dev->worker, sim_bthcisock_work, dev, 0);
}
5 changes: 0 additions & 5 deletions arch/xtensa/src/esp32/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2175,11 +2175,6 @@ config ESP32_BLE_PKTBUF_NUM
int "BLE netcard packet buffer number per netcard"
default 16

config ESP32_BLE_TTY_NAME
string "BLE TTY device name"
default "/dev/ttyHCI0"
depends on UART_BTH4

config ESP32_BLE_TASK_STACK_SIZE
int "Controller task stack size"
default 4096
Expand Down
14 changes: 4 additions & 10 deletions arch/xtensa/src/esp32/esp32_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
#include <nuttx/wireless/bluetooth/bt_driver.h>
#include <nuttx/wireless/bluetooth/bt_uart.h>

#if defined(CONFIG_UART_BTH4)
# include <nuttx/serial/uart_bth4.h>
#endif

#include "esp32_ble_adapter.h"

/****************************************************************************
Expand Down Expand Up @@ -322,16 +318,14 @@ int esp32_ble_initialize(void)
return ERROR;
}

#if defined(CONFIG_UART_BTH4)
ret = uart_bth4_register(CONFIG_BT_UART_ON_DEV_NAME, &g_ble_priv.drv);
#else
ret = bt_netdev_register(&g_ble_priv.drv);
#endif
#ifdef CONFIG_DRIVERS_BLUETOOTH
ret = bt_driver_register(&g_ble_priv.drv);
if (ret < 0)
{
wlerr("bt_netdev_register or uart_bth4_register error: %d\n", ret);
wlerr("bt_driver_register error: %d\n", ret);
return ret;
}
#endif

return OK;
}
5 changes: 0 additions & 5 deletions arch/xtensa/src/esp32s3/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1682,11 +1682,6 @@ endif # ESP32S3_OPENETH
menu "BLE Configuration"
depends on ESP32S3_BLE

config ESP32S3_BLE_TTY_NAME
string "BLE TTY device name"
default "/dev/ttyHCI0"
depends on UART_BTH4

config ESP32S3_BLE_TASK_STACK_SIZE
int "Controller task stack size"
default 4096
Expand Down
14 changes: 4 additions & 10 deletions arch/xtensa/src/esp32s3/esp32s3_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
#include <nuttx/wireless/bluetooth/bt_driver.h>
#include <nuttx/wireless/bluetooth/bt_uart.h>

#if defined(CONFIG_UART_BTH4)
# include <nuttx/serial/uart_bth4.h>
#endif

#include "esp32s3_ble_adapter.h"

/****************************************************************************
Expand Down Expand Up @@ -310,16 +306,14 @@ int esp32s3_ble_initialize(void)
return ERROR;
}

#if defined(CONFIG_UART_BTH4)
ret = uart_bth4_register(CONFIG_ESP32S3_BLE_TTY_NAME, &g_ble_priv.drv);
#else
ret = bt_netdev_register(&g_ble_priv.drv);
#endif
#ifdef CONFIG_DRIVERS_BLUETOOTH
ret = bt_driver_register(&g_ble_priv.drv);
if (ret < 0)
{
wlerr("bt_netdev_register or uart_bth4_register error: %d\n", ret);
wlerr("bt_driver_register error: %d\n", ret);
return ret;
}
#endif

return OK;
}
21 changes: 4 additions & 17 deletions boards/arm/nrf53/nrf5340-dk/src/nrf53_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@

#ifdef CONFIG_RPTUN
# include <nuttx/wireless/bluetooth/bt_rpmsghci.h>
# ifdef CONFIG_UART_BTH4
# include <nuttx/serial/uart_bth4.h>
# endif
# ifdef CONFIG_NET_BLUETOOTH
# ifdef CONFIG_DRIVERS_BLUETOOTH
# include <nuttx/wireless/bluetooth/bt_driver.h>
# endif
# include "nrf53_rptun.h"
Expand Down Expand Up @@ -104,21 +101,11 @@ static int nrf53_appcore_bleinit(void)
return -ENOMEM;
}

# ifdef CONFIG_UART_BTH4
/* Register UART BT H4 device */

ret = uart_bth4_register("/dev/ttyHCI", bt_dev);
if (ret < 0)
{
syslog(LOG_ERR, "bt_bth4_register error: %d\n", ret);
}
# elif defined(CONFIG_NET_BLUETOOTH)
/* Register network device */

ret = bt_netdev_register(bt_dev);
# ifdef CONFIG_DRIVERS_BLUETOOTH
ret = bt_driver_register(bt_dev);
if (ret < 0)
{
syslog(LOG_ERR, "bt_netdev_register error: %d\n", ret);
syslog(LOG_ERR, "bt_driver_register error: %d\n", ret);
}
# else
# error
Expand Down
Loading

0 comments on commit 8ba9ed4

Please sign in to comment.