1 /*---------------------------------------------------------------------------*
2   Project:	   HID library
3   File: 	   hid.h
4   Programmers: Henry Cheng
5 
6   Copyright (C) Nintendo.  All rights reserved.
7 
8   These coded instructions, statements, and computer programs contain
9   proprietary information of Nintendo of America Inc. and/or Nintendo
10   Company Ltd., and are protected by Federal copyright law.  They may
11   not be disclosed to third parties or copied or duplicated in any form,
12   in whole or in part, without the prior written consent of Nintendo.
13  *---------------------------------------------------------------------------*/
14 
15 #ifndef __HID_H__
16 #define __HID_H__
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 //////////////////////////////////////////////////////////////////////////////
22 
23 
24 typedef u32 HIDDeviceHandle ;
25 
26 
27 #define HID_ERROR_OK							0
28 #define HID_ERROR_NOT_OPEN						-1
29 #define HID_ERROR_ALREADY_OPEN					-2
30 #define HID_ERROR_FIRMWARE_VERSION				-3
31 #define HID_ERROR_FIRMWARE_MALFUNCTION			-4
32 #define HID_ERROR_BUSY							-5
33 #define HID_ERROR_CANCELLED 					-6
34 
35 //---
36 
37 
38 
39 #ifndef HID_ERROR_CODE
40 #define HID_ERROR_CODE s32
41 #endif
42 
43 #define HID_ERROR_NONE	0
44 
45 typedef struct
46 {
47 
48 	u32 handle;
49 	u32 physical_device_inst;
50 	u16 vid;
51 	u16 pid;
52 	u8	interface_index;
53 	u8	sub_class;
54 	u8	protocol;
55 
56 	u16 max_packet_size_rx;
57 	u16 max_packet_size_tx;
58 
59 } HIDDevice;
60 
61 typedef struct _HIDClient HIDClient;
62 
63 #define HID_DEVICE_DETACH	0
64 #define HID_DEVICE_ATTACH	1
65 
66 typedef int (*HIDAttachCallback)(
67 						HIDClient	*p_hc,
68 						HIDDevice	*p_hd,
69 						u32 		attach
70 						);
71 
72 struct _HIDClient
73 {
74 
75 	HIDClient			*next;
76 	HIDAttachCallback	attach_callback;
77 
78 };
79 
80 
81 #ifndef HID_CALLBACK
82 typedef void (*HIDCallback)(
83 				u32 			handle,
84 				HID_ERROR_CODE	error,
85 				u8				*p_buffer,
86 				u32 			bytes_transferred,
87 				void			*p_user
88 				);
89 #endif
90 
91 
92 //////////////////////////////////////////////////////////////////////////////
93 //	API
94 //////////////////////////////////////////////////////////////////////////////
95 
96 HID_ERROR_CODE	HIDSetup(void);
97 HID_ERROR_CODE	HIDTeardown(void);
98 
99 HID_ERROR_CODE	HIDAddClient(HIDClient *p_client, HIDAttachCallback attach_callback);
100 HID_ERROR_CODE	HIDDelClient(HIDClient *p_client);
101 
102 HID_ERROR_CODE	HIDGetDescriptor(u32 handle, u8 descriptor_type, u8 descriptor_index, u16 language_id, u8 *p_buffer, u32 buffer_length, HIDCallback async_callback, void *p_user);
103 HID_ERROR_CODE	HIDSetDescriptor(u32 handle, u8 descriptor_type, u8 descriptor_index, u16 language_id, u8 *p_buffer, u32 buffer_length, HIDCallback async_callback, void *p_user);
104 HID_ERROR_CODE	HIDGetReport(u32 handle, u8 report_type, u8 report_id, u8 *p_buffer, u32 buffer_length, HIDCallback async_callback, void *p_user);
105 HID_ERROR_CODE	HIDSetReport(u32 handle, u8 report_type, u8 report_id, u8 *p_buffer, u32 buffer_length, HIDCallback async_callback, void *p_user);
106 HID_ERROR_CODE	HIDGetProtocol(u32 handle, u8 interface_index, u8 *p_protocol, HIDCallback async_callback, void *p_user);
107 HID_ERROR_CODE	HIDSetProtocol(u32 handle, u8 interface_index, u8 protocol, HIDCallback async_callback, void *p_user);
108 HID_ERROR_CODE	HIDGetIdle(u32 handle, u8 interface_index, u8 report_id, u8 *p_idle, HIDCallback async_callback, void *p_user);
109 HID_ERROR_CODE	HIDSetIdle(u32 handle, u8 interface_index, u8 report_id, u8 duration, HIDCallback async_callback, void *p_user);
110 HID_ERROR_CODE	HIDRead(u32 handle, u8 *p_buffer, u32 buffer_length, HIDCallback hc, void *p_user);
111 HID_ERROR_CODE	HIDWrite(u32 handle, u8 *p_buffer, u32 buffer_length, HIDCallback hc, void *p_user);
112 HID_ERROR_CODE  HIDResetDevice(u32 handle, HIDCallback async_callback, void *p_user);
113 
114 void			HIDDecodeError(HID_ERROR_CODE hec, u32 *p_category, s32 *p_code);
115 
116 //////////////////////////////////////////////////////////////////////////////
117 #ifdef __cplusplus
118 } /* extern "C" */
119 #endif
120 
121 /* __HID_H__ */
122 #endif
123