diff --git a/samples/ble/hci_usb/CMakeLists.txt b/samples/ble/hci_usb/CMakeLists.txt new file mode 100644 index 0000000..714d9c3 --- /dev/null +++ b/samples/ble/hci_usb/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(hci_usb) + +target_sources(app PRIVATE src/main.c) diff --git a/samples/ble/hci_usb/prj.conf b/samples/ble/hci_usb/prj.conf new file mode 100644 index 0000000..0f809e4 --- /dev/null +++ b/samples/ble/hci_usb/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/samples/ble/hci_usb/sample.yaml b/samples/ble/hci_usb/sample.yaml new file mode 100644 index 0000000..e8b8000 --- /dev/null +++ b/samples/ble/hci_usb/sample.yaml @@ -0,0 +1,11 @@ +sample: + name: Bluetooth over USB sample +common: + build_only: true + integration_platforms: + - connectkit_nrf52840 + - dongle_nrf52840 +tests: + sample.bluetooth.hci_usb: {} + sample.bluetooth.hci_usb.device_next: + extra_args: CONF_FILE="usbd_next_prj.conf" diff --git a/samples/ble/hci_usb/src/main.c b/samples/ble/hci_usb/src/main.c new file mode 100644 index 0000000..429358f --- /dev/null +++ b/samples/ble/hci_usb/src/main.c @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2018 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#if defined(CONFIG_USB_DEVICE_STACK_NEXT) +USBD_CONFIGURATION_DEFINE(config_1, + USB_SCD_SELF_POWERED, + 200); + +USBD_DESC_LANG_DEFINE(sample_lang); +USBD_DESC_MANUFACTURER_DEFINE(sample_mfr, "ZEPHYR"); +USBD_DESC_PRODUCT_DEFINE(sample_product, "Zephyr USBD BT HCI"); +USBD_DESC_SERIAL_NUMBER_DEFINE(sample_sn, "0123456789ABCDEF"); + + +USBD_DEVICE_DEFINE(sample_usbd, + DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)), + 0x2fe3, 0x000b); + +static int enable_usb_device_next(void) +{ + int err; + + err = usbd_add_descriptor(&sample_usbd, &sample_lang); + if (err) { + return err; + } + + err = usbd_add_descriptor(&sample_usbd, &sample_mfr); + if (err) { + return err; + } + + err = usbd_add_descriptor(&sample_usbd, &sample_product); + if (err) { + return err; + } + + err = usbd_add_descriptor(&sample_usbd, &sample_sn); + if (err) { + return err; + } + + err = usbd_add_configuration(&sample_usbd, &config_1); + if (err) { + return err; + } + + err = usbd_register_class(&sample_usbd, "bt_hci_0", 1); + if (err) { + return err; + } + + err = usbd_init(&sample_usbd); + if (err) { + return err; + } + + err = usbd_enable(&sample_usbd); + if (err) { + return err; + } + + return 0; +} +#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/samples/ble/hci_usb/usbd_next_prj.conf b/samples/ble/hci_usb/usbd_next_prj.conf new file mode 100644 index 0000000..e3071e1 --- /dev/null +++ b/samples/ble/hci_usb/usbd_next_prj.conf @@ -0,0 +1,15 @@ +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_USBD_BT_HCI=y + +CONFIG_LOG=y +CONFIG_USBD_LOG_LEVEL_WRN=y +CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y