Initial commit for hci_usb

This commit is contained in:
2025-02-13 16:23:24 +01:00
commit 128a953cca
8 changed files with 147 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
# editors
*.swp
*~
# build
/build*/

8
CMakeLists.txt Normal file
View File

@@ -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)

9
Kconfig Normal file
View File

@@ -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"

24
README.rst Normal file
View File

@@ -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.

17
prj.conf Normal file
View File

@@ -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

21
sample.yaml Normal file
View File

@@ -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

45
src/main.c Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/usb/usb_device.h>
#include <zephyr/usb/usbd.h>
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
#include <sample_usbd.h>
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;
}

17
usbd_next_prj.conf Normal file
View File

@@ -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