VSF Documented
vsf_usbd_HID.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_HID_H__
19#define __VSF_USBD_HID_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#if VSF_USE_USB_DEVICE == ENABLED && VSF_USBD_USE_HID == ENABLED
26
27#include "../../../common/class/HID/vsf_usb_HID.h"
28#include "./vsf_usbd_HID_desc.h"
29
30#if defined(__VSF_USBD_HID_CLASS_IMPLEMENT)
31# undef __VSF_USBD_HID_CLASS_IMPLEMENT
32# define __VSF_CLASS_IMPLEMENT__
33#elif defined(__VSF_USBD_HID_CLASS_INHERIT__)
34# undef __VSF_USBD_HID_CLASS_INHERIT__
35# define __VSF_CLASS_INHERIT__
36#endif
37#include "utilities/ooc_class.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43/*============================ MACROS ========================================*/
44
45#define USB_HID_PARAM(__IN_EP, __OUT_EP, \
46 __REPORT_NUM, __REPORTS, __HAS_REPORT_ID, \
47 __DESC_NUM, __DESC, \
48 __RX_BUFF, __RX_BUFF_SIZE, \
49 __NOTIFY_EDA, __NOTIFIER) \
50 .ep_out = (__OUT_EP), \
51 .ep_in = (__IN_EP), \
52 .num_of_report = (__REPORT_NUM), \
53 .reports = (__REPORTS), \
54 .has_report_id = (__HAS_REPORT_ID), \
55 .desc_num = (__DESC_NUM), \
56 .desc = (vk_usbd_desc_t *)(__DESC), \
57 .rx_buffer.buffer = (__RX_BUFF), \
58 .rx_buffer.size = (__RX_BUFF_SIZE), \
59 .notify_eda = (__NOTIFY_EDA), \
60 .notifier = (__NOTIFIER),
61
62#define USB_HID_IFS_NUM 1
63#define USB_HID_IFS(__HID_PARAM) USB_IFS(&vk_usbd_hid, &(__HID_PARAM))
64
65
66#define __usbd_hid_desc(__name, __ifs, __i_func, __subclass, __protocol, \
67 __version_bcd, __country_code, __report_desc_len, \
68 __ep_in, __ep_in_size, __ep_in_interval, \
69 __ep_out, __ep_out_size, __ep_out_interval) \
70 USB_DESC_HID((__ifs), 4 + (__i_func), (__subclass), (__protocol), \
71 (__version_bcd), (__country_code), (__report_desc_len), \
72 (__ep_in), (__ep_in_size), (__ep_in_interval), \
73 (__ep_out), (__ep_out_size), (__ep_out_interval) \
74 )
75#define __usbd_hid_desc_iad(__name, __ifs, __i_func, __subclass, __protocol, \
76 __version_bcd, __country_code, __report_desc_len, \
77 __ep_in, __ep_in_size, __ep_in_interval, \
78 __ep_out, __ep_out_size, __ep_out_interval) \
79 USB_DESC_HID_IAD((__ifs), 4 + (__i_func), (__subclass), (__protocol),\
80 (__version_bcd), (__country_code), (__report_desc_len), \
81 (__ep_in), (__ep_in_size), (__ep_in_interval), \
82 (__ep_out), (__ep_out_size), (__ep_out_interval) \
83 )
84
85#define __usbd_hid_func(__name, __func_id, \
86 __in_ep, __out_ep, __out_ep_size, \
87 __report_num, __reports, __has_report_id, \
88 __report_desc, __report_desc_len, \
89 __notify_eda, __notifier) \
90 uint8_t __##__name##_HID##_rx_buffer[__out_ep_size]; \
91 const vk_usbd_desc_t __##__name##_HID##__desc[1] = { \
92 VSF_USBD_DESC_HID_REPORT((__report_desc), (__report_desc_len)), \
93 }; \
94 vk_usbd_hid_t __##__name##_HID##__func_id = { \
95 USB_HID_PARAM((__in_ep), (__out_ep), \
96 (__report_num), (__reports), (__has_report_id), \
97 dimof(__##__name##_HID##__desc), (__##__name##_HID##__desc),\
98 __##__name##_HID##_rx_buffer, __out_ep_size, \
99 __notify_eda, __notifier) \
100 };
101
102#define __usbd_hid_ifs(__name, __func_id) \
103 USB_HID_IFS(__##__name##_HID##__func_id)
104
105#define usbd_hid_desc(__name, __ifs, __i_func, \
106 __subclass, __protocol, \
107 __version_bcd, __country_code, __report_desc_len, \
108 __ep_in, __ep_in_size, __ep_in_interval, \
109 __ep_out, __ep_out_size, __ep_out_interval) \
110 __usbd_hid_desc(__name, (__ifs), (__i_func), \
111 (__subclass), (__protocol), \
112 (__version_bcd), (__country_code), (__report_desc_len), \
113 (__ep_in), (__ep_in_size), (__ep_in_interval), \
114 (__ep_out), (__ep_out_size), (__ep_out_interval))
115#define usbd_hid_desc_iad(__name, __ifs, __i_func, \
116 __subclass, __protocol, \
117 __version_bcd, __country_code, __report_desc_len, \
118 __ep_in, __ep_in_size, __ep_in_interval, \
119 __ep_out, __ep_out_size, __ep_out_interval) \
120 __usbd_hid_desc_iad(__name, (__ifs), (__i_func), \
121 (__subclass), (__protocol), \
122 (__version_bcd), (__country_code), (__report_desc_len), \
123 (__ep_in), (__ep_in_size), (__ep_in_interval), \
124 (__ep_out), (__ep_out_size), (__ep_out_interval))
125
126#define usbd_hid_func(__name, __func_id, \
127 __in_ep, __out_ep, __out_ep_size, \
128 __report_num, __reports, __has_report_id, \
129 __report_desc, __report_desc_size, \
130 __notify_eda, __notifier) \
131 __usbd_hid_func(__name, __func_id, \
132 (__in_ep), (__out_ep), (__out_ep_size), \
133 (__report_num), (__reports), (__has_report_id), \
134 (__report_desc), (__report_desc_size), \
135 (__notify_eda), (__notifier))
136#define usbd_hid_ifs(__name, __func_id) \
137 __usbd_hid_ifs(__name, __func_id)
138
139#define VSF_USBD_DESC_HID_REPORT(__PTR, __SIZE) \
140 {USB_HID_DT_REPORT, 0, 0, (__SIZE), (uint8_t*)(__PTR)}
141#define VSF_USBD_HID_REPORT(__TYPE, __ID, __BUFFER, __SIZE, __IDLE) \
142 {(__TYPE), {(__BUFFER), (__SIZE)}, (__ID), (__IDLE)}
143
144/*============================ MACROFIED FUNCTIONS ===========================*/
145/*============================ TYPES =========================================*/
146
148
149 public_member(
151 vsf_mem_t mem;
152 uint8_t id;
153 uint8_t idle;
155
156 protected_member(
157 bool changed;
158 uint8_t idle_cnt;
160};
161
163
164 public_member(
165 uint8_t ep_out;
166 uint8_t ep_in;
167 uint8_t num_of_report;
168
169 uint8_t has_report_id : 1;
170 uint8_t notify_eda : 1;
171 uint8_t desc_num : 6;
172
173 vsf_mem_t rx_buffer;
174 vk_usbd_hid_report_t *reports;
175 vk_usbd_desc_t *desc;
176
177 union {
178 vsf_err_t (*on_report)(vk_usbd_hid_t *hid, vk_usbd_hid_report_t *report);
179 vsf_eda_t *eda;
180 void *notifier;
181 };
183
184 private_member(
185 uint8_t protocol;
186 uint8_t cur_report;
187 uint8_t cur_in_id;
188
189 uint8_t busy : 1;
190 uint8_t report_from_control : 1;
191
192 vk_usbd_trans_t transact_in;
193 vk_usbd_trans_t transact_out;
194 vsf_teda_t teda;
195
196 vk_usbd_dev_t *dev;
197 vk_usbd_ifs_t *ifs;
198 )
199};
200
201/*============================ GLOBAL VARIABLES ==============================*/
202
203extern const vk_usbd_class_op_t vk_usbd_hid;
204
205/*============================ PROTOTYPES ====================================*/
206
210
211#ifdef __cplusplus
212}
213#endif
214
215/*============================ INCLUDES ======================================*/
216
217#include "./vsf_usbd_hidmsc.h"
218
219#endif // VSF_USE_USB_DEVICE && VSF_USBD_USE_HID
220#endif // __VSF_USBD_HID_H__
vsf_err_t
Definition __type.h:42
Definition vsf_usbd_HID.h:147
Definition vsf_usbd_HID.h:162
Definition vsf_usbd.h:402
Definition vsf_eda.h:766
Definition vsf_eda.h:834
#define vsf_class(__name)
Definition ooc_class.h:48
unsigned char uint8_t
Definition stdint.h:5
Definition vsf_usbd.h:379
Definition vsf_utilities.h:51
vk_av_control_type_t type
Definition vsf_audio.h:170
usb_hid_report_type_t
Definition vsf_usb_HID.h:49
bool vk_usbd_hid_in_report_can_update(vk_usbd_hid_report_t *report)
void vk_usbd_hid_out_report_processed(vk_usbd_hid_t *hid, vk_usbd_hid_report_t *report)
void vk_usbd_hid_in_report_changed(vk_usbd_hid_t *hid, vk_usbd_hid_report_t *report)
const vk_usbd_class_op_t vk_usbd_hid
vk_input_notifier_t notifier
Definition vsf_xboot.c:31