1beacf11bSopenharmony_ci/* ----------------------------------------------------------------------------
2beacf11bSopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2019-2019. All rights reserved.
3beacf11bSopenharmony_ci * Description: LiteOS USB Driver HID Protocol HeadFile
4beacf11bSopenharmony_ci * Author: wanghongxu
5beacf11bSopenharmony_ci * Create: 2019-10-24
6beacf11bSopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
7beacf11bSopenharmony_ci * are permitted provided that the following conditions are met:
8beacf11bSopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of
9beacf11bSopenharmony_ci * conditions and the following disclaimer.
10beacf11bSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11beacf11bSopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials
12beacf11bSopenharmony_ci * provided with the distribution.
13beacf11bSopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used
14beacf11bSopenharmony_ci * to endorse or promote products derived from this software without specific prior written
15beacf11bSopenharmony_ci * permission.
16beacf11bSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17beacf11bSopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18beacf11bSopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19beacf11bSopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20beacf11bSopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21beacf11bSopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22beacf11bSopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23beacf11bSopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24beacf11bSopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25beacf11bSopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26beacf11bSopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27beacf11bSopenharmony_ci * --------------------------------------------------------------------------- */
28beacf11bSopenharmony_ci/* ----------------------------------------------------------------------------
29beacf11bSopenharmony_ci * Notice of Export Control Law
30beacf11bSopenharmony_ci * ===============================================
31beacf11bSopenharmony_ci * Huawei LiteOS may be subject to applicable export control laws and regulations, which might
32beacf11bSopenharmony_ci * include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
33beacf11bSopenharmony_ci * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
34beacf11bSopenharmony_ci * applicable export control laws and regulations.
35beacf11bSopenharmony_ci * --------------------------------------------------------------------------- */
36beacf11bSopenharmony_ci
37beacf11bSopenharmony_ci#ifndef _F_HID_GADGET_H
38beacf11bSopenharmony_ci#define _F_HID_GADGET_H
39beacf11bSopenharmony_ci
40beacf11bSopenharmony_ci#include "gadget/usbdev.h"
41beacf11bSopenharmony_ci#include "gadget/composite.h"
42beacf11bSopenharmony_ci
43beacf11bSopenharmony_ci#ifdef __cplusplus
44beacf11bSopenharmony_ci#if __cplusplus
45beacf11bSopenharmony_ciextern "C" {
46beacf11bSopenharmony_ci#endif /* __cplusplus */
47beacf11bSopenharmony_ci#endif /* __cplusplus */
48beacf11bSopenharmony_ci
49beacf11bSopenharmony_ci/* Define usb hid gadget path. */
50beacf11bSopenharmony_ci
51beacf11bSopenharmony_ci#define USB_HID_DEV "/dev/hid"
52beacf11bSopenharmony_ci
53beacf11bSopenharmony_ci#define HID_IN_DATA_SIZE       0x40U
54beacf11bSopenharmony_ci#define HID_OUT_DATA_SIZE      0x40U
55beacf11bSopenharmony_ci#define USB_HID_READ_EVENT     0x11
56beacf11bSopenharmony_ci
57beacf11bSopenharmony_cistruct hid_endpoint_descriptor
58beacf11bSopenharmony_ci{
59beacf11bSopenharmony_ci  uByte bLength;
60beacf11bSopenharmony_ci  uByte bDescriptorType;
61beacf11bSopenharmony_ci  uByte bEndpointAddress;
62beacf11bSopenharmony_ci  uByte bmAttributes;
63beacf11bSopenharmony_ci  uWord wMaxPacketSize;
64beacf11bSopenharmony_ci  uByte bInterval;
65beacf11bSopenharmony_ci} __attribute__((packed));
66beacf11bSopenharmony_ci
67beacf11bSopenharmony_cistruct hid_dev_s
68beacf11bSopenharmony_ci{
69beacf11bSopenharmony_ci  struct usbdev_ep_s *out_ep; /* interrupt output endpoint */
70beacf11bSopenharmony_ci  struct usbdev_ep_s *in_ep;  /* interrupt input endpoint */
71beacf11bSopenharmony_ci  bool out_ep_enabled;
72beacf11bSopenharmony_ci  bool in_ep_enabled;
73beacf11bSopenharmony_ci  struct usbdev_req_s outputreq; /* interrupt output report */
74beacf11bSopenharmony_ci  struct usbdev_req_s inputreq;  /* HID report request */
75beacf11bSopenharmony_ci
76beacf11bSopenharmony_ci  void *read_buf;
77beacf11bSopenharmony_ci  size_t read_len;
78beacf11bSopenharmony_ci  EVENT_CB_S read_event;
79beacf11bSopenharmony_ci  spinlock_t hid_lock;
80beacf11bSopenharmony_ci  atomic_t open_flag; /* Hid device status. 1: open, 0: close */
81beacf11bSopenharmony_ci
82beacf11bSopenharmony_ci  struct list_head hid_queue;
83beacf11bSopenharmony_ci  int hid_queue_len;
84beacf11bSopenharmony_ci  volatile atomic_t busy_flag;
85beacf11bSopenharmony_ci  struct hid_queue_node *cur_node;
86beacf11bSopenharmony_ci};
87beacf11bSopenharmony_ci
88beacf11bSopenharmony_cistruct hid_driver_s
89beacf11bSopenharmony_ci{
90beacf11bSopenharmony_ci  struct usbdevclass_driver_s drvr;
91beacf11bSopenharmony_ci  struct hid_dev_s *dev;
92beacf11bSopenharmony_ci};
93beacf11bSopenharmony_ci
94beacf11bSopenharmony_cistruct hid_softc
95beacf11bSopenharmony_ci{
96beacf11bSopenharmony_ci  struct hid_dev_s dev;
97beacf11bSopenharmony_ci  struct hid_driver_s drvr;
98beacf11bSopenharmony_ci};
99beacf11bSopenharmony_ci
100beacf11bSopenharmony_cistruct dev_report_desc
101beacf11bSopenharmony_ci{
102beacf11bSopenharmony_ci  size_t  report_size;
103beacf11bSopenharmony_ci  uint8_t *report_desc;
104beacf11bSopenharmony_ci};
105beacf11bSopenharmony_ci
106beacf11bSopenharmony_cistruct dev_string_desc
107beacf11bSopenharmony_ci{
108beacf11bSopenharmony_ci  char *str;
109beacf11bSopenharmony_ci  uint32_t len;
110beacf11bSopenharmony_ci};
111beacf11bSopenharmony_ci
112beacf11bSopenharmony_ciextern void hid_deviceid_info(uint16_t vendorid, uint16_t productid);
113beacf11bSopenharmony_ciextern int hid_report_descriptor_info(const void *buf, size_t len);
114beacf11bSopenharmony_ciextern int hid_device_string_info(const struct dev_string_desc *str_manufacturer,
115beacf11bSopenharmony_ci                                  const struct dev_string_desc *str_product,
116beacf11bSopenharmony_ci                                  const struct dev_string_desc *str_serial_number);
117beacf11bSopenharmony_ci
118beacf11bSopenharmony_ci#ifdef __cplusplus
119beacf11bSopenharmony_ci#if __cplusplus
120beacf11bSopenharmony_ci}
121beacf11bSopenharmony_ci#endif /* __cplusplus */
122beacf11bSopenharmony_ci#endif /* __cplusplus */
123beacf11bSopenharmony_ci
124beacf11bSopenharmony_ci#endif /* _F_HID_GADGET_H */