-
Notifications
You must be signed in to change notification settings - Fork 6.1k
/
main.c
65 lines (53 loc) · 1.27 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Copyright (c) 2016 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <sample_usbd.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/usb/usb_device.h>
#include <zephyr/usb/usbd.h>
#include <zephyr/drivers/uart.h>
BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart),
"Console device is not ACM CDC UART device");
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
static struct usbd_context *sample_usbd;
static int enable_usb_device_next(void)
{
int err;
sample_usbd = sample_usbd_init_device(NULL);
if (sample_usbd == NULL) {
return -ENODEV;
}
err = usbd_enable(sample_usbd);
if (err) {
return err;
}
return 0;
}
#endif /* defined(CONFIG_USB_DEVICE_STACK_NEXT) */
int main(void)
{
const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
uint32_t dtr = 0;
#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
if (enable_usb_device_next()) {
return 0;
}
#else
if (usb_enable(NULL)) {
return 0;
}
#endif
/* Poll if the DTR flag was set */
while (!dtr) {
uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
/* Give CPU resources to low priority threads. */
k_sleep(K_MSEC(100));
}
while (1) {
printk("Hello World! %s\n", CONFIG_ARCH);
k_sleep(K_SECONDS(1));
}
}