|  | 
| 7 | 7 | #include <zephyr/kernel.h> | 
| 8 | 8 | #include <zephyr/sys/printk.h> | 
| 9 | 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_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 */ | 
| 10 | 73 | 
 | 
| 11 | 74 | void main(void) | 
| 12 | 75 | { | 
| 13 | 76 | 	int ret; | 
| 14 | 77 | 
 | 
|  | 78 | +#if defined(CONFIG_USB_DEVICE_STACK_NEXT) | 
|  | 79 | +	ret = enable_usb_device_next(); | 
|  | 80 | +#else | 
| 15 | 81 | 	ret = usb_enable(NULL); | 
|  | 82 | +#endif | 
|  | 83 | + | 
| 16 | 84 | 	if (ret != 0) { | 
| 17 | 85 | 		printk("Failed to enable USB"); | 
| 18 | 86 | 		return; | 
|  | 
0 commit comments