Skip to content

Commit cad8ae7

Browse files
jfischer-nostephanosio
authored andcommitted
samples: hci_usb: enable new experimental USB device support
Enable Bluetooth HCI USB tranport layer from new experimental USB device support. Signed-off-by: Johann Fischer <[email protected]>
1 parent 5c077d7 commit cad8ae7

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

samples/bluetooth/hci_usb/sample.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ tests:
77
tags: usb bluetooth
88
# FIXME: exclude due to build error
99
platform_exclude: 96b_carbon
10+
sample.bluetooth.hci_usb.device_next:
11+
harness: bluetooth
12+
depends_on: usb_device ble
13+
tags: usb bluetooth
14+
extra_args: CONF_FILE="usbd_next_prj.conf"
15+
platform_allow: nrf52840dk_nrf52840

samples/bluetooth/hci_usb/src/main.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,80 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/sys/printk.h>
99
#include <zephyr/usb/usb_device.h>
10+
#include <zephyr/usb/usbd.h>
11+
12+
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
13+
USBD_CONFIGURATION_DEFINE(config_1,
14+
USB_SCD_SELF_POWERED,
15+
200);
16+
17+
USBD_DESC_LANG_DEFINE(sample_lang);
18+
USBD_DESC_STRING_DEFINE(sample_mfr, "ZEPHYR", 1);
19+
USBD_DESC_STRING_DEFINE(sample_product, "Zephyr USBD BT HCI", 2);
20+
USBD_DESC_STRING_DEFINE(sample_sn, "0123456789ABCDEF", 3);
21+
22+
USBD_DEVICE_DEFINE(sample_usbd,
23+
DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)),
24+
0x2fe3, 0x000b);
25+
26+
static int enable_usb_device_next(void)
27+
{
28+
int err;
29+
30+
err = usbd_add_descriptor(&sample_usbd, &sample_lang);
31+
if (err) {
32+
return err;
33+
}
34+
35+
err = usbd_add_descriptor(&sample_usbd, &sample_mfr);
36+
if (err) {
37+
return err;
38+
}
39+
40+
err = usbd_add_descriptor(&sample_usbd, &sample_product);
41+
if (err) {
42+
return err;
43+
}
44+
45+
err = usbd_add_descriptor(&sample_usbd, &sample_sn);
46+
if (err) {
47+
return err;
48+
}
49+
50+
err = usbd_add_configuration(&sample_usbd, &config_1);
51+
if (err) {
52+
return err;
53+
}
54+
55+
err = usbd_register_class(&sample_usbd, "bt_hci_0", 1);
56+
if (err) {
57+
return err;
58+
}
59+
60+
err = usbd_init(&sample_usbd);
61+
if (err) {
62+
return err;
63+
}
64+
65+
err = usbd_enable(&sample_usbd);
66+
if (err) {
67+
return err;
68+
}
69+
70+
return 0;
71+
}
72+
#endif /* CONFIG_USB_DEVICE_STACK_NEXT */
1073

1174
void main(void)
1275
{
1376
int ret;
1477

78+
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
79+
ret = enable_usb_device_next();
80+
#else
1581
ret = usb_enable(NULL);
82+
#endif
83+
1684
if (ret != 0) {
1785
printk("Failed to enable USB");
1886
return;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CONFIG_STDOUT_CONSOLE=y
2+
CONFIG_GPIO=y
3+
CONFIG_SERIAL=y
4+
CONFIG_UART_INTERRUPT_DRIVEN=y
5+
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
6+
7+
CONFIG_BT=y
8+
CONFIG_BT_HCI_RAW=y
9+
10+
CONFIG_USB_DEVICE_STACK_NEXT=y
11+
CONFIG_USBD_BT_HCI=y
12+
13+
CONFIG_LOG=y
14+
CONFIG_USBD_LOG_LEVEL_WRN=y
15+
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y

0 commit comments

Comments
 (0)