Skip to content

Commit

Permalink
[component/usbd/hid] update
Browse files Browse the repository at this point in the history
  • Loading branch information
versaloon committed Aug 5, 2023
1 parent 846fbf4 commit 2800c8f
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 3 deletions.
98 changes: 98 additions & 0 deletions source/component/usb/device/class/HID/vsf_usbd_HID.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,105 @@ extern "C" {

/*============================ MACROS ========================================*/


#define USB_HID_PARAM(__IN_EP, __OUT_EP, \
__REPORT_NUM, __REPORTS, __HAS_REPORT_ID, \
__DESC_NUM, __DESC, \
__RX_BUFF, __RX_BUFF_SIZE, \
__NOTIFY_EDA, __NOTIFIER) \
.ep_out = (__OUT_EP), \
.ep_in = (__IN_EP), \
.num_of_report = (__REPORT_NUM), \
.reports = (__REPORTS), \
.has_report_id = (__HAS_REPORT_ID), \
.desc_num = (__DESC_NUM), \
.desc = (__DESC), \
.rx_buffer.buffer = (__RX_BUFF), \
.rx_buffer.size = (__RX_BUFF_SIZE), \
.notify_eda = (__NOTIFY_EDA), \
.notifier = (__NOTIFIER),

#define USB_HID_IFS_NUM 1
#define USB_HID_IFS(__HID_PARAM) USB_IFS(&vk_usbd_hid, &(__HID_PARAM))


#define __usbd_hid_desc(__name, __ifs, __i_func, __subclass, __protocol, \
__version_bcd, __country_code, __report_desc_len, \
__ep_in, __ep_in_size, __ep_in_interval, \
__ep_out, __ep_out_size, __ep_out_interval) \
USB_DESC_HID((__ifs), 4 + (__i_func), (__subclass), (__protocol), \
(__version_bcd), (__country_code), (__report_desc_len), \
(__ep_in), (__ep_in_size), (__ep_in_interval), \
(__ep_out), (__ep_out_size), (__ep_out_interval) \
)
#define __usbd_hid_desc_iad(__name, __ifs, __i_func, __subclass, __protocol, \
__version_bcd, __country_code, __report_desc_len, \
__ep_in, __ep_in_size, __ep_in_interval, \
__ep_out, __ep_out_size, __ep_out_interval) \
USB_DESC_HID_IAD((__ifs), 4 + (__i_func), (__subclass), (__protocol),\
(__version_bcd), (__country_code), (__report_desc_len), \
(__ep_in), (__ep_in_size), (__ep_in_interval), \
(__ep_out), (__ep_out_size), (__ep_out_interval) \
)

#define __usbd_hid_func(__name, __func_id, \
__in_ep, __out_ep, __out_ep_size, \
__report_num, __reports, __has_report_id, \
__report_desc, __report_desc_len, \
__notify_eda, __notifier) \
uint8_t __##__name##_HID##_rx_buffer[__out_ep_size]; \
vk_usbd_desc_t __##__name##_HID##__desc[1] = { \
VSF_USBD_DESC_HID_REPORT((__report_desc), (__report_desc_len)), \
}; \
vk_usbd_hid_t __##__name##_HID##__func_id = { \
USB_HID_PARAM((__in_ep), (__out_ep), \
(__report_num), (__reports), (__has_report_id), \
dimof(__##__name##_HID##__desc), (__##__name##_HID##__desc),\
__##__name##_HID##_rx_buffer, __out_ep_size, \
__notify_eda, __notifier) \
};

#define __usbd_hid_ifs(__name, __func_id) \
USB_HID_IFS(__##__name##_HID##__func_id)

#define usbd_hid_desc(__name, __ifs, __i_func, \
__subclass, __protocol, \
__version_bcd, __country_code, __report_desc_len, \
__ep_in, __ep_in_size, __ep_in_interval, \
__ep_out, __ep_out_size, __ep_out_interval) \
__usbd_hid_desc(__name, (__ifs), (__i_func), \
(__subclass), (__protocol), \
(__version_bcd), (__country_code), (__report_desc_len), \
(__ep_in), (__ep_in_size), (__ep_in_interval), \
(__ep_out), (__ep_out_size), (__ep_out_interval))
#define usbd_hid_desc_iad(__name, __ifs, __i_func, \
__subclass, __protocol, \
__version_bcd, __country_code, __report_desc_len, \
__ep_in, __ep_in_size, __ep_in_interval, \
__ep_out, __ep_out_size, __ep_out_interval) \
__usbd_hid_desc_iad(__name, (__ifs), (__i_func), \
(__subclass), (__protocol), \
(__version_bcd), (__country_code), (__report_desc_len), \
(__ep_in), (__ep_in_size), (__ep_in_interval), \
(__ep_out), (__ep_out_size), (__ep_out_interval))

#define usbd_hid_func(__name, __func_id, \
__in_ep, __out_ep, __out_ep_size, \
__report_num, __reports, __has_report_id, \
__report_desc, __report_desc_size, \
__notify_eda, __notifier) \
__usbd_hid_func(__name, __func_id, \
(__in_ep), (__out_ep), (__out_ep_size), \
(__report_num), (__reports), (__has_report_id), \
(__report_desc), (__report_desc_size), \
(__notify_eda), (__notifier))
#define usbd_hid_ifs(__name, __func_id) \
__usbd_hid_ifs(__name, __func_id)

#define VSF_USBD_DESC_HID_REPORT(__PTR, __SIZE) \
{USB_HID_DT_REPORT, 0, 0, (__SIZE), (uint8_t*)(__PTR)}
#define VSF_USBD_HID_REPORT(__TYPE, __ID, __BUFFER, __SIZE, __IDLE) \
{(__TYPE), {(__BUFFER), (__SIZE)}, (__ID), (__IDLE)}

/*============================ MACROFIED FUNCTIONS ===========================*/
/*============================ TYPES =========================================*/
Expand Down Expand Up @@ -81,6 +178,7 @@ vsf_class(vk_usbd_hid_t) {
union {
vsf_err_t (*on_report)(vk_usbd_hid_t *hid, vk_usbd_hid_report_t *report);
vsf_eda_t *eda;
void *notifier;
};
)

Expand Down
7 changes: 4 additions & 3 deletions source/component/usb/device/class/HID/vsf_usbd_HID_desc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ extern "C" {
#define USB_HID_PROTOCOL_MOUSE 2

#define USB_DT_HID_SIZE 9
#define USB_DESC_HID(__IFS, __I_FUNC, __SUBCLASS, __PROTOCOL, __VERSION_BCD, __COUNTRY_CODE, __REPORT_DESC_LEN,\
#define USB_DESC_HID(__IFS, __I_FUNC, __SUBCLASS, __PROTOCOL, \
__VERSION_BCD, __COUNTRY_CODE, __REPORT_DESC_LEN, \
__EP_IN, __EP_IN_SIZE, __EP_IN_INTERVAL, \
__EP_OUT, __EP_OUT_SIZE, __EP_OUT_INTERVAL) \
USB_DESC_IFS((__IFS), 0, 2, USB_CLASS_HID, (__SUBCLASS), (__PROTOCOL), (__I_FUNC))\
Expand All @@ -44,8 +45,8 @@ extern "C" {
(1), /* bNumDescriptor: number of class descriptors */\
USB_DT_REPORT, /* bDescriptorType */ \
USB_DESC_WORD(__REPORT_DESC_LEN), /* wDescriptorLen */ \
USB_DESC_EP(USB_DIR_IN | (__EP_IN), USB_ENDPOINT_XFER_INT, 64, __EP_IN_INTERVAL)\
USB_DESC_EP(USB_DIR_OUT | (__EP_OUT), USB_ENDPOINT_XFER_INT, 64, __EP_OUT_INTERVAL)
USB_DESC_EP(USB_DIR_IN | (__EP_IN), USB_ENDPOINT_XFER_INT, __EP_IN_SIZE, __EP_IN_INTERVAL)\
USB_DESC_EP(USB_DIR_OUT | (__EP_OUT), USB_ENDPOINT_XFER_INT, __EP_OUT_SIZE, __EP_OUT_INTERVAL)
#define USB_DESC_HID_LEN (USB_DESC_IFS_LEN + USB_DT_HID_SIZE + 2 * USB_DESC_EP_LEN)

#define USB_DESC_HID_IAD(__IFS, __I_FUNC, __SUBCLASS, __PROTOCOL, __VERSION_BCD, __COUNTRY_CODE, __REPORT_DESC_LEN,\
Expand Down

0 comments on commit 2800c8f

Please sign in to comment.