Skip to content

Commit 84d3161

Browse files
jfischer-nocfriedt
authored andcommitted
samples: usb: move the legacy code out of the HIC USB sample
Move the legacy code from HCI USB sample to a separate sample in the legacy directory. Signed-off-by: Johann Fischer <[email protected]>
1 parent 375e8e6 commit 84d3161

File tree

10 files changed

+90
-54
lines changed

10 files changed

+90
-54
lines changed

samples/bluetooth/hci_usb/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. zephyr:code-sample:: bluetooth_hci_usb
22
:name: HCI USB
3-
:relevant-api: hci_raw bluetooth _usb_device_core_api usbd_api
3+
:relevant-api: hci_raw bluetooth usbd_api
44

55
Turn a Zephyr board into a USB Bluetooth dongle (compatible with all operating systems).
66

samples/bluetooth/hci_usb/prj.conf

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
CONFIG_BT=y
22
CONFIG_BT_HCI_RAW=y
3-
4-
CONFIG_USB_DEVICE_STACK=y
5-
CONFIG_USB_DEVICE_PID=0x000B
6-
CONFIG_USB_DEVICE_BLUETOOTH=y
7-
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
8-
9-
# We dont want any console or CDC ACM that may cause BlueZ to not detect hci_usb
103
CONFIG_SERIAL=n
114
CONFIG_CONSOLE=n
125
CONFIG_UART_CONSOLE=n
6+
7+
CONFIG_USB_DEVICE_STACK_NEXT=y
8+
CONFIG_SAMPLE_USBD_PID=0x000B
9+
CONFIG_SAMPLE_USBD_PRODUCT="Zephyr USBD BT HCI"
10+
CONFIG_USBD_BT_HCI=y

samples/bluetooth/hci_usb/sample.yaml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,8 @@ tests:
44
sample.bluetooth.hci_usb:
55
harness: bluetooth
66
depends_on:
7-
- usb_device
7+
- usbd
88
- ble
99
tags:
1010
- usb
1111
- bluetooth
12-
sample.bluetooth.hci_usb.device_next:
13-
harness: bluetooth
14-
depends_on:
15-
- usb_device
16-
- ble
17-
tags:
18-
- usb
19-
- bluetooth
20-
extra_args: CONF_FILE="usbd_next_prj.conf"
21-
platform_allow: nrf52840dk/nrf52840

samples/bluetooth/hci_usb/src/main.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,22 @@
66

77
#include <zephyr/kernel.h>
88
#include <zephyr/sys/printk.h>
9-
#include <zephyr/usb/usb_device.h>
109
#include <zephyr/usb/usbd.h>
1110

12-
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
1311
#include <sample_usbd.h>
1412

15-
static int enable_usb_device_next(void)
13+
int main(void)
1614
{
17-
struct usbd_context *sample_usbd = sample_usbd_init_device(NULL);
15+
struct usbd_context *sample_usbd;
16+
int ret;
1817

18+
sample_usbd = sample_usbd_init_device(NULL);
1919
if (sample_usbd == NULL) {
2020
printk("Failed to initialize USB device");
2121
return -ENODEV;
2222
}
2323

24-
return usbd_enable(sample_usbd);
25-
}
26-
#endif /* CONFIG_USB_DEVICE_STACK_NEXT */
27-
28-
int main(void)
29-
{
30-
int ret;
31-
32-
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
33-
ret = enable_usb_device_next();
34-
#else
35-
ret = usb_enable(NULL);
36-
#endif
37-
24+
ret = usbd_enable(sample_usbd);
3825
if (ret != 0) {
3926
printk("Failed to enable USB");
4027
return 0;

samples/bluetooth/hci_usb/usbd_next_prj.conf

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(hci_usb)
6+
7+
target_sources(app PRIVATE src/main.c)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. zephyr:code-sample:: legacy_bluetooth_hci_usb
2+
:name: Legacy HCI USB
3+
:relevant-api: hci_raw bluetooth _usb_device_core_api
4+
5+
Turn a Zephyr board into a USB Bluetooth dongle (compatible with all operating systems).
6+
7+
Overview
8+
********
9+
10+
Make a USB Bluetooth dongle out of Zephyr.
11+
12+
Requirements
13+
************
14+
15+
* Bluetooth stack running on the host (e.g. BlueZ)
16+
* A board with Bluetooth and USB support in Zephyr
17+
18+
Building and Running
19+
********************
20+
This sample can be found under :zephyr_file:`samples/subsys/usb/legacy/hci_usb` in the
21+
Zephyr tree.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CONFIG_BT=y
2+
CONFIG_BT_HCI_RAW=y
3+
4+
CONFIG_USB_DEVICE_STACK=y
5+
CONFIG_USB_DEVICE_PID=0x000B
6+
CONFIG_USB_DEVICE_BLUETOOTH=y
7+
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
8+
9+
# We dont want any console or CDC ACM that may cause BlueZ to not detect hci_usb
10+
CONFIG_SERIAL=n
11+
CONFIG_CONSOLE=n
12+
CONFIG_UART_CONSOLE=n
13+
14+
# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
15+
# Host number of completed commands does not follow normal flow control.
16+
CONFIG_BT_BUF_CMD_TX_COUNT=10
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
sample:
2+
name: Bluetooth over USB sample
3+
tests:
4+
sample.bluetooth.hci_usb.legacy:
5+
depends_on:
6+
- usb_device
7+
- ble
8+
build_only: true
9+
tags:
10+
- usb
11+
- bluetooth
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (c) 2018 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/sys/printk.h>
9+
#include <zephyr/usb/usb_device.h>
10+
11+
int main(void)
12+
{
13+
int ret;
14+
15+
ret = usb_enable(NULL);
16+
if (ret != 0) {
17+
printk("Failed to enable USB");
18+
return 0;
19+
}
20+
21+
printk("Bluetooth over USB sample\n");
22+
return 0;
23+
}

0 commit comments

Comments
 (0)