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 #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_MANUFACTURER_DEFINE(sample_mfr, "ZEPHYR");
19 USBD_DESC_PRODUCT_DEFINE(sample_product, "Zephyr USBD BT HCI");
20 USBD_DESC_SERIAL_NUMBER_DEFINE(sample_sn, "0123456789ABCDEF");
21
22
23 USBD_DEVICE_DEFINE(sample_usbd,
24 DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)),
25 0x2fe3, 0x000b);
26
enable_usb_device_next(void)27 static int enable_usb_device_next(void)
28 {
29 int err;
30
31 err = usbd_add_descriptor(&sample_usbd, &sample_lang);
32 if (err) {
33 return err;
34 }
35
36 err = usbd_add_descriptor(&sample_usbd, &sample_mfr);
37 if (err) {
38 return err;
39 }
40
41 err = usbd_add_descriptor(&sample_usbd, &sample_product);
42 if (err) {
43 return err;
44 }
45
46 err = usbd_add_descriptor(&sample_usbd, &sample_sn);
47 if (err) {
48 return err;
49 }
50
51 err = usbd_add_configuration(&sample_usbd, &config_1);
52 if (err) {
53 return err;
54 }
55
56 err = usbd_register_class(&sample_usbd, "bt_hci_0", 1);
57 if (err) {
58 return err;
59 }
60
61 err = usbd_init(&sample_usbd);
62 if (err) {
63 return err;
64 }
65
66 err = usbd_enable(&sample_usbd);
67 if (err) {
68 return err;
69 }
70
71 return 0;
72 }
73 #endif /* CONFIG_USB_DEVICE_STACK_NEXT */
74
main(void)75 int main(void)
76 {
77 int ret;
78
79 #if defined(CONFIG_USB_DEVICE_STACK_NEXT)
80 ret = enable_usb_device_next();
81 #else
82 ret = usb_enable(NULL);
83 #endif
84
85 if (ret != 0) {
86 printk("Failed to enable USB");
87 return 0;
88 }
89
90 printk("Bluetooth over USB sample\n");
91 return 0;
92 }
93