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