Line data Source code
1 1 : /*
2 : * Copyright (c) 2024 Nordic Semiconductor ASA
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : /**
8 : * @file
9 : * @brief USB support message types and structure
10 : */
11 :
12 : #ifndef ZEPHYR_INCLUDE_USBD_MSG_H_
13 : #define ZEPHYR_INCLUDE_USBD_MSG_H_
14 :
15 : #include <stdint.h>
16 :
17 : #ifdef __cplusplus
18 : extern "C" {
19 : #endif
20 :
21 : /**
22 : * @defgroup usbd_msg_api USB device core API
23 : * @ingroup usb
24 : * @since 3.7
25 : * @version 0.2.0
26 : * @{
27 : */
28 :
29 : /**
30 : * @brief USB device support message types
31 : *
32 : * The first set of message types map to event types from the UDC driver API.
33 : */
34 1 : enum usbd_msg_type {
35 : /** VBUS ready message (optional) */
36 : USBD_MSG_VBUS_READY,
37 : /** VBUS removed message (optional) */
38 : USBD_MSG_VBUS_REMOVED,
39 : /** Device resume message */
40 : USBD_MSG_RESUME,
41 : /** Device suspended message */
42 : USBD_MSG_SUSPEND,
43 : /** Bus reset detected */
44 : USBD_MSG_RESET,
45 : /** Device changed configuration */
46 : USBD_MSG_CONFIGURATION,
47 : /** Non-correctable UDC error message */
48 : USBD_MSG_UDC_ERROR,
49 : /** Unrecoverable device stack error message */
50 : USBD_MSG_STACK_ERROR,
51 : /** CDC ACM Line Coding update */
52 : USBD_MSG_CDC_ACM_LINE_CODING,
53 : /** CDC ACM Line State update */
54 : USBD_MSG_CDC_ACM_CONTROL_LINE_STATE,
55 : /** USB DFU class detach request */
56 : USBD_MSG_DFU_APP_DETACH,
57 : /** USB DFU class download completed */
58 : USBD_MSG_DFU_DOWNLOAD_COMPLETED,
59 : /** Maximum number of message types */
60 : USBD_MSG_MAX_NUMBER,
61 : };
62 :
63 : /**
64 : * @cond INTERNAL_HIDDEN
65 : */
66 : static const char *const usbd_msg_type_list[] = {
67 : "VBUS ready",
68 : "VBUS removed",
69 : "Device resumed",
70 : "Device suspended",
71 : "Bus reset",
72 : "New device configuration",
73 : "Controller error",
74 : "Stack error",
75 : "CDC ACM line coding",
76 : "CDC ACM control line state",
77 : "DFU detach request",
78 : "DFU download completed",
79 : };
80 :
81 : BUILD_ASSERT(ARRAY_SIZE(usbd_msg_type_list) == USBD_MSG_MAX_NUMBER,
82 : "Number of entries in usbd_msg_type_list is not equal to USBD_MSG_MAX_NUMBER");
83 : /** @endcond */
84 :
85 : /**
86 : * @brief USB device message
87 : */
88 1 : struct usbd_msg {
89 : /** Message type */
90 1 : enum usbd_msg_type type;
91 : /** Message status, value or data */
92 : union {
93 0 : int status;
94 0 : const struct device *dev;
95 1 : };
96 : };
97 :
98 : /**
99 : * @brief Returns the message type as a constant string
100 : *
101 : * @param[in] type USBD message type
102 : *
103 : * @return Message type as a constant string
104 : */
105 1 : static inline const char *usbd_msg_type_string(const enum usbd_msg_type type)
106 : {
107 : if (type >= 0 && type < USBD_MSG_MAX_NUMBER) {
108 : return usbd_msg_type_list[type];
109 : }
110 :
111 : return "?";
112 : }
113 :
114 : /**
115 : * @}
116 : */
117 :
118 : #ifdef __cplusplus
119 : }
120 : #endif
121 :
122 : #endif /* ZEPHYR_INCLUDE_USBD_MSG_H_ */
|