summaryrefslogtreecommitdiff
path: root/tinyusb/class/hid.h
blob: 4779e9e8180477735dd1d13e4796a47f2447b9a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 * hid.h
 *
 *  Created on: Nov 27, 2012
 *      Author: hathach
 */

/*
 * Software License Agreement (BSD License)
 * Copyright (c) 2012, hathach (tinyusb.net)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 *
 * This file is part of the tinyUSB stack.
 */

/** \file
 *  \brief HID Class Driver
 *
 *  \note TBD
 */

/** 
 *  \addtogroup Group_ClassDriver Class Driver
 *  @{
 *  \defgroup Group_HID Human Interface Device
 *  @{
 */

#ifndef _TUSB_HID_H_
#define _TUSB_HID_H_

#ifdef __cplusplus
 extern "C" {
#endif

 // TODO refractor
#include "common/common.h"

#ifdef TUSB_CFG_DEVICE
#include "device/dcd.h"
#endif

#ifdef TUSB_CFG_HOST
#include "device/hcd.h"
#endif

/** \struct USB_HID_MouseReport_t
 *  \brief Standard HID Boot Protocol Mouse Report.
 *
 *  Type define for a standard Boot Protocol Mouse report
 */
typedef ATTR_PREPACKED struct
{
  uint8_t Button; /**< Button mask for currently pressed buttons in the mouse. */
  int8_t  X; /**< Current delta X movement of the mouse. */
  int8_t  Y; /**< Current delta Y movement on the mouse. */
} ATTR_PACKED USB_HID_MouseReport_t;

/** \struct USB_HID_KeyboardReport_t
 *  \brief Standard HID Boot Protocol Keyboard Report.
 *
 *  Type define for a standard Boot Protocol Keyboard report
 */
typedef ATTR_PREPACKED struct
{
  uint8_t Modifier; /**< Keyboard modifier byte, indicating pressed modifier keys (a combination of HID_KEYBOARD_MODIFER_* masks). */
  uint8_t Reserved; /**< Reserved for OEM use, always set to 0. */
  uint8_t KeyCode[6]; /**< Key codes of the currently pressed keys. */
} ATTR_PACKED USB_HID_KeyboardReport_t;

/** \enum USB_HID_MOUSE_BUTTON_CODE
 * \brief Button codes for HID mouse
 */
enum USB_HID_MOUSE_BUTTON_CODE
{
	HID_MOUSEBUTTON_RIGHT = 0,
	HID_MOUSEBUTTON_LEFT = 1,
	HID_MOUSEBUTTON_MIDDLE = 2
};

/** \enum USB_HID_KB_KEYMODIFIER_CODE
 * \brief KB modifier codes for HID KB
 */
enum USB_HID_KB_KEYMODIFIER_CODE
{
	HID_KEYMODIFIER_LEFTCTRL = 0,
	HID_KEYMODIFIER_LEFTSHIFT,
	HID_KEYMODIFIER_LEFTALT,
	HID_KEYMODIFIER_LEFTGUI,
	HID_KEYMODIFIER_RIGHTCTRL,
	HID_KEYMODIFIER_RIGHTSHIFT,
	HID_KEYMODIFIER_RIGHTALT,
	HID_KEYMODIFIER_RIGHTGUI
};

/** \enum USB_HID_LOCAL_CODE
 * \brief Local Country code for HID
 */
enum USB_HID_LOCAL_CODE
{
  HID_Local_NotSupported = 0,
  HID_Local_Arabic,
  HID_Local_Belgian,
  HID_Local_Canadian_Bilingual,
  HID_Local_Canadian_French,
  HID_Local_Czech_Republic,
  HID_Local_Danish,
  HID_Local_Finnish,
  HID_Local_French,
  HID_Local_German,
  HID_Local_Greek,
  HID_Local_Hebrew,
  HID_Local_Hungary,
  HID_Local_International,
  HID_Local_Italian,
  HID_Local_Japan_Katakana,
  HID_Local_Korean,
  HID_Local_Latin_American,
  HID_Local_Netherlands_Dutch,
  HID_Local_Norwegian,
  HID_Local_Persian_Farsi,
  HID_Local_Poland,
  HID_Local_Portuguese,
  HID_Local_Russia,
  HID_Local_Slovakia,
  HID_Local_Spanish,
  HID_Local_Swedish,
  HID_Local_Swiss_French,
  HID_Local_Swiss_German,
  HID_Local_Switzerland,
  HID_Local_Taiwan,
  HID_Local_Turkish_Q,
  HID_Local_UK,
  HID_Local_US,
  HID_Local_Yugoslavia,
  HID_Local_Turkish_F
};

#ifdef DEVICE_ROMDRIVER
/** \brief Initialize HID driver
 *
 * \param[in]  para1
 * \param[out] para2
 * \return Error Code of the \ref TUSB_ERROR enum
 * \note
 */
TUSB_Error_t tusb_hid_init(USBD_HANDLE_T hUsb, USB_INTERFACE_DESCRIPTOR const *const pIntfDesc, uint8_t const * const pHIDReportDesc, uint32_t ReportDescLength, uint32_t* mem_base, uint32_t* mem_size);

/** \brief Notify HID class that usb is configured
 *
 * \param[in]  para1
 * \param[out] para2
 * \return Error Code of the \ref TUSB_ERROR enum
 * \note
 */
TUSB_Error_t tusb_hid_configured(USBD_HANDLE_T hUsb);

/** \brief Used by Application to send Keycode to Host
 *
 * \param[in]  para1
 * \param[out] para2
 * \return Error Code of the \ref TUSB_ERROR enum
 * \note
 */
TUSB_Error_t tusb_hid_keyboard_sendKeys(uint8_t modifier, uint8_t keycodes[], uint8_t numkey);

/** \brief
 *
 * \param[in]  para1
 * \param[out] para2
 * \return Error Code of the \ref TUSB_ERROR enum
 * \note
 */
TUSB_Error_t tusb_hid_mouse_send(uint8_t buttons, int8_t x, int8_t y);
#endif


#ifdef TUSB_CFG_HOST
#endif

#ifdef __cplusplus
 }
#endif

#endif /* _TUSB_HID_H__ */

/// @}
/// @}