commit 128a953cca540dc580b2951340adcb0535fe807b Author: pstruebi Date: Thu Feb 13 16:23:24 2025 +0100 Initial commit for hci_usb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..635a99b --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# editors +*.swp +*~ + +# build +/build*/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..9abfd99 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(hci_usb) + +include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake) +target_sources(app PRIVATE src/main.c) diff --git a/Kconfig b/Kconfig new file mode 100644 index 0000000..825eba9 --- /dev/null +++ b/Kconfig @@ -0,0 +1,9 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +# Source common USB sample options used to initialize new experimental USB +# device stack. The scope of these options is limited to USB samples in project +# tree, you cannot use them in your own application. +source "samples/subsys/usb/common/Kconfig.sample_usbd" + +source "Kconfig.zephyr" diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..c8ac294 --- /dev/null +++ b/README.rst @@ -0,0 +1,24 @@ +.. zephyr:code-sample:: bluetooth_hci_usb + :name: HCI USB + :relevant-api: hci_raw bluetooth _usb_device_core_api usbd_api + + Turn a Zephyr board into a USB Bluetooth dongle (compatible with all operating systems). + +Overview +******** + +Make a USB Bluetooth dongle out of Zephyr. Requires USB device support from the +board it runs on (e.g. :ref:`nrf52840dk_nrf52840` supports both Bluetooth LE and USB). + +Requirements +************ + +* Bluetooth stack running on the host (e.g. BlueZ) +* A board with Bluetooth and USB support in Zephyr + +Building and Running +******************** +This sample can be found under :zephyr_file:`samples/bluetooth/hci_usb` in the +Zephyr tree. + +See :zephyr:code-sample-category:`bluetooth` samples for details. diff --git a/prj.conf b/prj.conf new file mode 100644 index 0000000..0f809e4 --- /dev/null +++ b/prj.conf @@ -0,0 +1,17 @@ +CONFIG_BT=y +CONFIG_BT_HCI_RAW=y + +CONFIG_USB_DEVICE_STACK=y +CONFIG_USB_DEVICE_PID=0x000B +CONFIG_USB_DEVICE_BLUETOOTH=y +CONFIG_USB_DEVICE_BLUETOOTH_VS_H4=n +CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n + +# We dont want any console or CDC ACM that may cause BlueZ to not detect hci_usb +CONFIG_SERIAL=n +CONFIG_CONSOLE=n +CONFIG_UART_CONSOLE=n + +# Workaround: Unable to allocate command buffer when using K_NO_WAIT since +# Host number of completed commands does not follow normal flow control. +CONFIG_BT_BUF_CMD_TX_COUNT=10 diff --git a/sample.yaml b/sample.yaml new file mode 100644 index 0000000..c04cf1b --- /dev/null +++ b/sample.yaml @@ -0,0 +1,21 @@ +sample: + name: Bluetooth over USB sample +tests: + sample.bluetooth.hci_usb: + harness: bluetooth + depends_on: + - usb_device + - ble + tags: + - usb + - bluetooth + sample.bluetooth.hci_usb.device_next: + harness: bluetooth + depends_on: + - usb_device + - ble + tags: + - usb + - bluetooth + extra_args: CONF_FILE="usbd_next_prj.conf" + platform_allow: nrf52840dk/nrf52840 diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..18c7f0d --- /dev/null +++ b/src/main.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#if defined(CONFIG_USB_DEVICE_STACK_NEXT) +#include + +static int enable_usb_device_next(void) +{ + struct usbd_context *sample_usbd = sample_usbd_init_device(NULL); + + if (sample_usbd == NULL) { + printk("Failed to initialize USB device"); + return -ENODEV; + } + + return usbd_enable(sample_usbd); +} +#endif /* CONFIG_USB_DEVICE_STACK_NEXT */ + +int main(void) +{ + int ret; + +#if defined(CONFIG_USB_DEVICE_STACK_NEXT) + ret = enable_usb_device_next(); +#else + ret = usb_enable(NULL); +#endif + + if (ret != 0) { + printk("Failed to enable USB"); + return 0; + } + + printk("Bluetooth over USB sample\n"); + return 0; +} diff --git a/usbd_next_prj.conf b/usbd_next_prj.conf new file mode 100644 index 0000000..e1daa84 --- /dev/null +++ b/usbd_next_prj.conf @@ -0,0 +1,17 @@ +CONFIG_STDOUT_CONSOLE=y +CONFIG_GPIO=y +CONFIG_SERIAL=y +CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n + +CONFIG_BT=y +CONFIG_BT_HCI_RAW=y + +CONFIG_USB_DEVICE_STACK_NEXT=y +CONFIG_SAMPLE_USBD_PID=0x000b +CONFIG_SAMPLE_USBD_PRODUCT="Zephyr USBD BT HCI" +CONFIG_USBD_BT_HCI=y + +CONFIG_LOG=y +CONFIG_USBD_LOG_LEVEL_WRN=y +CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y