1 /*---------------------------------------------------------------------------*
2   Project:  HID lib API
3   File:     hid.h
4 
5   Copyright (C)1998-2007 Nintendo  All Rights Reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Log: hid.h,v $
14   Revision 2.9.6.1  2009/10/14 10:11:05  iwai_yuma
15   Rool back into StackB.
16 
17   Revision 2.8  2007/11/12 22:01:23  henrch
18   HID_ERROR_CANCELLED
19 
20   Revision 2.7  2007/11/06 19:28:15  henrch
21   changed ep reference fro n to in / out
22 
23   Revision 2.6  2007/11/01 20:51:58  henrch
24   - changed HID_MEM_SIZE
25 
26   Revision 2.5  2007/09/26 19:27:47  henrch
27   - changed HIDUnregisterClient() to HIDUnregisterClientAsync()
28   - added HIDClientHandler
29   - changed HID_MEM_SIZE
30 
31   Revision 2.4  2007/09/25 20:37:49  henrch
32   - changed HID_MEM_SIZE
33   - removed max end point size from HIDDevice
34 
35   Revision 2.3  2007/09/21 19:53:42  henrch
36   - remove MEM2 data requirement
37   - API change, now async task buffer is handeled by HID lib
38   - chnaged HID_MEM_SIZE
39 
40   Revision 2.2  2007/09/18 20:04:33  henrch
41   - added max size for endpoint
42   - increased  HID_MEM_SIZE
43 
44   Revision 2.1  2007/09/07 22:08:28  henrch
45   changed HID_MEM_SIZE, increased to include cancel intr message feature
46 
47   Revision 2.0  2007/09/07 18:55:39  henrch
48   created
49 
50   $NoKeywords: $
51  *---------------------------------------------------------------------------*/
52 #ifndef __HID_H__
53 #define __HID_H__
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 ///////////////////////////////////////////////////////////////////////////////
58 #define HID_MEM_SIZE    15072
59 ///////////////////////////////////////////////////////////////////////////////
60 typedef s32 HIDError;
61 
62 #define HID_ERROR_OK                            0
63 #define HID_ERROR_NOT_OPEN                      -1
64 #define HID_ERROR_ALREADY_OPEN                  -2
65 #define HID_ERROR_FIRMWARE_VERSION              -3
66 #define HID_ERROR_FIRMWARE_MALFUNCTION          -4
67 #define HID_ERROR_BUSY                          -5
68 #define HID_ERROR_CANCELLED                     -6
69 
70 ///////////////////////////////////////////////////////////////////////////////
71 // Standard Device Descriptor
72 typedef struct
73 {
74 
75     u8  bLength;
76     u8  bDescriptorType;
77     u16 bcdUSB;
78     u8  bDeviceClass;
79     u8  bDeviceSubClass;
80     u8  bDeviceProtocol;
81     u8  bMaxPacketSize;
82     u16 idVendor;
83     u16 idProduct;
84     u16 bcdDevice;
85     u8  iManufacturer;
86     u8  iProduct;
87     u8  iSerialNumber;
88     u8  bNumConfigurations;
89 
90     u8  pad[2];
91 
92 } HIDDeviceDescriptor;
93 
94 
95 // Standard Configuration Descriptor
96 typedef struct
97 {
98 
99     u8  bLength;
100     u8  bDescriptorType;
101     u16 wTotalLength;
102     u8  bNumInterfaces;
103     u8  bConfigurationValue;
104     u8  iConfiguration;
105     u8  bmAttributes;
106     u8  bMaxPower;
107 
108     u8  pad[3];
109 
110 } HIDConfigurationDescriptor;
111 
112 
113 // Standard Interface Descriptor
114 typedef struct
115 {
116 
117     u8  bLength;
118     u8  bDescriptorType;
119     u8  bInterfaceNumber;
120     u8  bAlternateSetting;
121     u8  bNumEndpoints;
122     u8  bInterfaceClass;
123     u8  bInterfaceSubClass;
124     u8  bInterfaceProtocol;
125     u8  iInterface;
126 
127     u8  pad[3];
128 
129 } HIDInterfaceDescriptor;
130 
131 
132 // Standard Endpoint Descriptor
133 typedef struct
134 {
135 
136     u8  bLength;
137     u8  bDescriptorType;
138     u8  bEndpointAddress;
139     u8  bmAttributes;
140     u16 wMaxPacketSize;
141     u8  bInterval;
142 
143     u8  pad[1];
144 
145 } HIDEndpointDescriptor;
146 
147 
148 // client gets reference to one of these on attach
149 typedef struct
150 {
151 
152     s32                         fd;
153     u16                         vid;
154     u16                         pid;
155     u8                          iInterface;
156     u8                          endpoint_address_in;
157     u8                          endpoint_address_out;
158     volatile u8                 inst;
159     HIDDeviceDescriptor         *p_hdd;
160     HIDConfigurationDescriptor  *p_hcd;
161     HIDInterfaceDescriptor      *p_hid;
162     HIDEndpointDescriptor       *p_hed0;
163     HIDEndpointDescriptor       *p_hed1;
164 
165 } HIDDevice;
166 
167 
168 ///////////////////////////////////////////////////////////////////////////////
169 typedef struct _HIDClient HIDClient;
170 
171 typedef int (*HIDAttachHandler)(
172                         HIDClient   *p_hc,
173                         HIDDevice   *p_hd,
174                         u32         attach
175                         );
176 
177 struct _HIDClient
178 {
179 
180     HIDClient           *next;
181     HIDAttachHandler    attachHandler;
182     u32					user;
183 
184 };
185 
186 
187 ///////////////////////////////////////////////////////////////////////////////
188 // setup and teardown
189 typedef void (*HIDSetupHandler)(HIDError he, u32 user);
190 
191 HIDError HIDOpenAsync(
192                 void *mem,
193                 HIDSetupHandler hsh,
194                 u32             user
195                 );
196 
197 HIDError HIDCloseAsync(
198                 HIDSetupHandler hsh,
199                 u32             user
200                 );
201 
202 // client registration
203 typedef void (*HIDClientHandler)(HIDError he, u32 user);
204 
205 HIDError HIDRegisterClient(
206                 HIDClient       *hClient,
207                 HIDAttachHandler hah
208                 );
209 
210 HIDError HIDUnregisterClientAsync(
211                 HIDClient       *hClient,
212                 HIDClientHandler hch,
213                 u32             user
214                 );
215 
216 // HID runtime APIs
217 typedef void (*HIDDoneHandler)(
218                 HIDDevice       *p_hd,
219                 HIDError        error,
220                 u8              *p_data,
221                 u32             size,
222                 u32             user
223                 );
224 
225 HIDError HIDGetAsciiStringAsync(
226                 HIDDevice       *p_hd,
227                 u8              index,
228                 u8              *p_data,
229                 u32             size,
230                 HIDDoneHandler  hdh,
231                 u32             user
232                 );
233 
234 HIDError HIDGetDescriptorAsync(
235                 HIDDevice       *p_hd,
236                 u8              descriptor_type,
237                 u8              descriptor_index,
238                 u16             language_id,
239                 u8              *p_data,
240                 u32             size,
241                 HIDDoneHandler  hdh,
242                 u32             user
243                 );
244 
245 HIDError HIDSetDescriptorAsync(
246                 HIDDevice       *p_hd,
247                 u8              descriptor_type,
248                 u8              descriptor_index,
249                 u16             language_id,
250                 u8              *p_data,
251                 u32             size,
252                 HIDDoneHandler  hdh,
253                 u32             user
254                 );
255 
256 HIDError HIDGetReportAsync(
257                 HIDDevice       *p_hd,
258                 u8              report_type,
259                 u8              report_id,
260                 u8              *p_data,
261                 u32             size,
262                 HIDDoneHandler  hdh,
263                 u32             user
264                 );
265 
266 HIDError HIDSetReportAsync(
267                 HIDDevice       *p_hd,
268                 u8              report_type,
269                 u8              report_id,
270                 u8              *p_data,
271                 u32             size,
272                 HIDDoneHandler  hdh,
273                 u32             user
274                 );
275 
276 HIDError HIDGetIdleAsync(
277                 HIDDevice       *p_hd,
278                 u8              report_id,
279                 u8              *p_data,
280                 HIDDoneHandler  hdh,
281                 u32             user
282                 );
283 
284 HIDError HIDSetIdleAsync(
285                 HIDDevice       *p_hd,
286                 u8              report_id,
287                 u8              duration,
288                 HIDDoneHandler  hdh,
289                 u32             user
290                 );
291 
292 HIDError HIDGetProtocolAsync(
293                 HIDDevice       *p_hd,
294                 u8              *p_data,
295                 HIDDoneHandler  hdh,
296                 u32             user
297                 );
298 
299 HIDError HIDSetProtocolAsync(
300                 HIDDevice       *p_hd,
301                 u8              protocol,
302                 HIDDoneHandler  hdh,
303                 u32             user
304                 );
305 
306 HIDError HIDGetReportIntAsync(
307                 HIDDevice       *p_hd,
308                 u8              *p_data,
309                 u32             size,
310                 HIDDoneHandler  hdh,
311                 u32             user
312                 );
313 
314 HIDError HIDSetReportIntAsync(
315                 HIDDevice       *p_hd,
316                 u8              *p_data,
317                 u32             size,
318                 HIDDoneHandler  hdh,
319                 u32             user
320                 );
321 
322 /*---------------------------------------------------------------------------*/
323 #ifdef __cplusplus
324 }
325 #endif
326 #endif  // __HID_H__
327