VSF Documented
vsf_usbd_CDCACM.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_USBD_CDCACM_H__
19#define __VSF_USBD_CDCACM_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#if VSF_USE_USB_DEVICE == ENABLED && VSF_USBD_USE_CDCACM == ENABLED
26
29
30#if defined(__VSF_USBD_CDCACM_CLASS_IMPLEMENT)
31# undef __VSF_USBD_CDCACM_CLASS_IMPLEMENT
32# define __VSF_CLASS_IMPLEMENT__
33#endif
34#include "utilities/ooc_class.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40/*============================ MACROS ========================================*/
41
42#define USB_CDC_ACM_PARAM(__INT_IN_EP, __BULK_IN_EP, __BULK_OUT_EP, __STREAM_RX, __STREAM_TX, ...)\
43 .ep = { \
44 .notify = (__INT_IN_EP), \
45 .out = (__BULK_OUT_EP), \
46 .in = (__BULK_IN_EP), \
47 }, \
48 .line_coding = __VA_ARGS__, \
49 .stream.tx.stream = (vsf_stream_t *)(__STREAM_TX), \
50 .stream.rx.stream = (vsf_stream_t *)(__STREAM_RX),
51
52#define USB_CDC_ACM_PARITY_NONE 0
53#define USB_CDC_ACM_PARITY_ODD 1
54#define USB_CDC_ACM_PARITY_EVEN 2
55
56#define USB_CDC_ACM_STOPBIT_1 0
57#define USB_CDC_ACM_STOPBIT_1P5 1
58#define USB_CDC_ACM_STOPBIT_2 2
59
60#define USB_CDC_ACM_LINECODE(__BAUDRATE, __BITLEN, __PARITY, __STOP) \
61 { \
62 .bitrate = (__BAUDRATE), \
63 .stop = (__STOP), \
64 .parity = (__PARITY), \
65 .datalen = (__BITLEN), \
66 }
67// commonly used line coding
68#define USB_CDC_ACM_LINECODE_115200_8N1 \
69 USB_CDC_ACM_LINECODE(115200, 8, USB_CDC_ACM_PARITY_NONE, USB_CDC_ACM_STOPBIT_1)
70
71#define USB_CDC_ACM_IFS_NUM USB_CDC_IFS_NUM
72#define USB_CDC_ACM_IFS_CONTROL(__CDC_ACM_PARAM) \
73 USB_IFS(&vk_usbd_cdcacm_control, &__CDC_ACM_PARAM)
74#define USB_CDC_ACM_IFS_DATA(__CDC_ACM_PARAM) \
75 USB_IFS(&vk_usbd_cdcacm_data, &__CDC_ACM_PARAM)
76
77
78
79#define __usbd_cdc_acm_desc_iad(__name, __ifs_start, __i_func, \
80 __int_in_ep, __bulk_in_ep, __bulk_out_ep, \
81 __bulk_ep_size, __int_ep_interval) \
82 USB_DESC_CDC_ACM_IAD((__ifs_start), (__i_func), \
83 (__int_in_ep), (__bulk_in_ep), (__bulk_out_ep), \
84 (__bulk_ep_size), (__int_ep_interval))
85
86#define __usbd_cdc_acm_func(__name, __func_id, __str_func, __i_func, __ifs_start,\
87 __int_in_ep, __bulk_in_ep, __bulk_out_ep, __bulk_ep_size, __int_ep_interval,\
88 __stream_rx, __stream_tx, ...) \
89 enum { \
90 __##__name##_CDCACM##__func_id##_IFS_START = (__ifs_start), \
91 __##__name##_CDCACM##__func_id##_I_FUNC = (__i_func), \
92 __##__name##_CDCACM##__func_id##_INTIN_EP = (__int_in_ep), \
93 __##__name##_CDCACM##__func_id##_BULKIN_EP = (__bulk_in_ep), \
94 __##__name##_CDCACM##__func_id##_BULKOUT_EP = (__bulk_out_ep), \
95 __##__name##_CDCACM##__func_id##_BULK_EP_SIZE = (__bulk_ep_size),\
96 __##__name##_CDCACM##__func_id##_BULK_EP_INTERVAL = (__int_ep_interval),\
97 }; \
98 usbd_func_str_desc(__name, __func_id, __str_func) \
99 vk_usbd_cdcacm_t __##__name##_CDCACM##__func_id = { \
100 USB_CDC_ACM_PARAM((__int_in_ep), (__bulk_in_ep), (__bulk_out_ep),\
101 (__stream_rx), (__stream_tx), __VA_ARGS__) \
102 };
103
104#define __usbd_cdc_acm_ifs(__name, __func_id) \
105 USB_CDC_ACM_IFS_CONTROL(__##__name##_CDCACM##__func_id) \
106 USB_CDC_ACM_IFS_DATA(__##__name##_CDCACM##__func_id)
107
108#define usbd_cdc_acm_desc_iad(__name, __func_id) \
109 __usbd_cdc_acm_desc_iad(__name, \
110 __##__name##_CDCACM##__func_id##_IFS_START, \
111 4 + __##__name##_CDCACM##__func_id##_I_FUNC, \
112 __##__name##_CDCACM##__func_id##_INTIN_EP, \
113 __##__name##_CDCACM##__func_id##_BULKIN_EP, \
114 __##__name##_CDCACM##__func_id##_BULKOUT_EP, \
115 __##__name##_CDCACM##__func_id##_BULK_EP_SIZE, \
116 __##__name##_CDCACM##__func_id##_BULK_EP_INTERVAL)
117#define usbd_cdc_acm_func(__name, __func_id, __str_func, __i_func, __ifs_start, \
118 __int_in_ep, __bulk_in_ep, __bulk_out_ep, __bulk_ep_size, __int_ep_interval,\
119 __stream_rx, __stream_tx, ...) \
120 __usbd_cdc_acm_func(__name, __func_id, (__str_func), (__i_func), (__ifs_start),\
121 (__int_in_ep), (__bulk_in_ep), (__bulk_out_ep), (__bulk_ep_size), (__int_ep_interval),\
122 (__stream_rx), (__stream_tx), __VA_ARGS__)
123#define usbd_cdc_acm_ifs(__name, __func_id) \
124 __usbd_cdc_acm_ifs(__name, __func_id)
125
126/*============================ MACROFIED FUNCTIONS ===========================*/
127/*============================ TYPES =========================================*/
128
130
131 public_member(
132 implement(vk_usbd_cdc_t)
133
134 usb_cdcacm_line_coding_t line_coding;
135 uint8_t control_line;
136
137 struct {
138 vsf_err_t (*set_line_coding)(usb_cdcacm_line_coding_t *line_coding);
139 vsf_err_t (*set_control_line)(uint8_t control_line);
140 vsf_err_t (*get_control_line)(uint8_t *control_line);
141 vsf_err_t (*send_break)(void);
142 } callback;
144};
145
146typedef struct vk_usbd_cdcacm_cfg_t {
148#if VSF_USE_SIMPLE_STREAM == ENABLED
151#elif VSF_USE_STREAM == ENABLED
154#endif
156
157/*============================ GLOBAL VARIABLES ==============================*/
158
159extern const vk_usbd_class_op_t vk_usbd_cdcacm_control;
160extern const vk_usbd_class_op_t vk_usbd_cdcacm_data;
161
162/*============================ PROTOTYPES ====================================*/
163
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif // VSF_USE_USB_DEVICE && VSF_USBD_USE_CDCACM
171#endif // __VSF_USBD_CDCACM_H__
vsf_err_t
Definition __type.h:42
Definition vsf_usbd_CDC.h:74
Definition vsf_usbd_CDCACM.h:129
Definition vsf_simple_stream.h:254
#define vsf_class(__name)
Definition ooc_class.h:48
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_usb_CDCACM.h:31
Definition vsf_usbd_CDCACM.h:146
vsf_stream_t * rx_stream
Definition vsf_usbd_CDCACM.h:150
implement_ex(vk_usbd_cdc_ep_t, ep)
vsf_stream_t * tx_stream
Definition vsf_usbd_CDCACM.h:149
Definition vsf_stream_base.h:68
Definition vsf_usbd_CDC.h:55
vsf_stream_usr_cfg_t
Definition vsf_stream_base.h:118
const vk_usbd_class_op_t vk_usbd_cdcacm_control
vsf_err_t vk_usbd_cdcacm_init(vk_usbd_cdcacm_t *obj, const vk_usbd_cdcacm_cfg_t *cfg)
const vk_usbd_class_op_t vk_usbd_cdcacm_data