1 /*
2  * Copyright (c) 2021 TiaC Systems
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/logging/log.h>
8 LOG_MODULE_DECLARE(net_echo_server_sample, LOG_LEVEL_DBG);
9 
10 #include <zephyr/usb/usb_device.h>
11 #include <zephyr/net/net_config.h>
12 
13 #if defined(CONFIG_USB_DEVICE_STACK_NEXT)
14 #include <sample_usbd.h>
15 
16 static struct usbd_context *sample_usbd;
17 
enable_usb_device_next(void)18 static int enable_usb_device_next(void)
19 {
20 	int err;
21 
22 	sample_usbd = sample_usbd_init_device(NULL);
23 	if (sample_usbd == NULL) {
24 		return -ENODEV;
25 	}
26 
27 	err = usbd_enable(sample_usbd);
28 	if (err) {
29 		return err;
30 	}
31 
32 	return 0;
33 }
34 #endif /* CONFIG_USB_DEVICE_STACK_NEXT */
35 
init_usb(void)36 int init_usb(void)
37 {
38 #if defined(CONFIG_USB_DEVICE_STACK)
39 	int ret;
40 
41 	ret = usb_enable(NULL);
42 	if (ret != 0) {
43 		LOG_ERR("Cannot enable USB (%d)", ret);
44 		return ret;
45 	}
46 #endif /* CONFIG_USB_DEVICE_STACK */
47 
48 #if defined(CONFIG_USB_DEVICE_STACK_NEXT)
49 	if (enable_usb_device_next()) {
50 		return 0;
51 	}
52 #endif /* CONFIG_USB_DEVICE_STACK_NEXT */
53 
54 	(void)net_config_init_app(NULL, "Initializing network");
55 
56 	return 0;
57 }
58