-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Zelin Cai <[email protected]>
- Loading branch information
Showing
5 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* 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) | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |