My Project
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
hid.h
Go to the documentation of this file.
1 #pragma once
2 
3 //See also: http://3dbrew.org/wiki/HID_Services http://3dbrew.org/wiki/HID_Shared_Memory
4 
5 #define HID_SHAREDMEM_DEFAULT (0x10000000)
6 
7 typedef enum
8 {
9  KEY_A = BIT(0),
10  KEY_B = BIT(1),
12  KEY_START = BIT(3),
14  KEY_DLEFT = BIT(5),
15  KEY_DUP = BIT(6),
16  KEY_DDOWN = BIT(7),
17  KEY_R = BIT(8),
18  KEY_L = BIT(9),
19  KEY_X = BIT(10),
20  KEY_Y = BIT(11),
21  KEY_ZL = BIT(14), // (new 3DS only)
22  KEY_ZR = BIT(15), // (new 3DS only)
23  KEY_TOUCH = BIT(20), // Not actually provided by HID
24  KEY_CSTICK_RIGHT = BIT(24), // c-stick (new 3DS only)
25  KEY_CSTICK_LEFT = BIT(25), // c-stick (new 3DS only)
26  KEY_CSTICK_UP = BIT(26), // c-stick (new 3DS only)
27  KEY_CSTICK_DOWN = BIT(27), // c-stick (new 3DS only)
28  KEY_CPAD_RIGHT = BIT(28), // circle pad
29  KEY_CPAD_LEFT = BIT(29), // circle pad
30  KEY_CPAD_UP = BIT(30), // circle pad
31  KEY_CPAD_DOWN = BIT(31), // circle pad
32 
33  // Generic catch-all directions
38 } PAD_KEY;
39 
40 typedef struct
41 {
42  u16 px, py;
44 
45 typedef struct
46 {
47  s16 dx, dy;
49 
50 typedef struct
51 {
52  s16 x;
53  s16 y;
54  s16 z;
55 } accelVector;
56 
57 typedef struct
58 {
59  s16 x;//roll
60  s16 z;//yaw
61  s16 y;//pitch
62 } angularRate;
63 
64 typedef enum
65 {
66  HIDEVENT_PAD0 = 0, //"Event signaled by HID-module, when the sharedmem+0(PAD/circle-pad)/+0xA8(touch-screen) region was updated."
67  HIDEVENT_PAD1, //"Event signaled by HID-module, when the sharedmem+0(PAD/circle-pad)/+0xA8(touch-screen) region was updated."
68  HIDEVENT_Accel, //"Event signaled by HID-module, when the sharedmem accelerometer state was updated."
69  HIDEVENT_Gyro, //"Event signaled by HID-module, when the sharedmem gyroscope state was updated."
70  HIDEVENT_DebugPad, //"Event signaled by HID-module, when the sharedmem DebugPad state was updated."
71 
72  HIDEVENT_MAX, // used to know how many events there are
73 } HID_Event;
74 
75 extern Handle hidMemHandle;
76 extern vu32* hidSharedMem;
77 
78 Result hidInit(u32* sharedMem);
79 void hidExit();
80 
81 void hidScanInput();
84 u32 hidKeysUp();
85 void hidTouchRead(touchPosition* pos);
86 void hidCircleRead(circlePosition* pos);
87 void hidAccelRead(accelVector* vector);
88 void hidGyroRead(angularRate* rate);
89 
90 void hidWaitForEvent(HID_Event id, bool nextEvent);
91 
92 // libnds compatibility defines
93 #define scanKeys hidScanInput
94 #define keysHeld hidKeysHeld
95 #define keysDown hidKeysDown
96 #define keysUp hidKeysUp
97 #define touchRead hidTouchRead
98 #define circleRead hidCircleRead
99 
100 Result HIDUSER_GetHandles(Handle* outMemHandle, Handle *eventpad0, Handle *eventpad1, Handle *eventaccel, Handle *eventgyro, Handle *eventdebugpad);
105 
u32 hidKeysDown()
Definition: hid.c:155
u16 py
Definition: hid.h:42
volatile u32 vu32
Definition: types.h:33
s32 Result
Definition: types.h:42
Definition: hid.h:22
s16 z
Definition: hid.h:60
s16 y
Definition: hid.h:53
uint16_t u16
Definition: types.h:22
s16 x
Definition: hid.h:52
s16 dy
Definition: hid.h:47
void hidWaitForEvent(HID_Event id, bool nextEvent)
Definition: hid.c:74
Definition: hid.h:20
u32 Handle
Definition: types.h:41
Definition: hid.h:37
s16 x
Definition: hid.h:59
Definition: hid.h:12
Result hidInit(u32 *sharedMem)
Definition: hid.c:22
void hidTouchRead(touchPosition *pos)
Definition: hid.c:165
Definition: hid.h:36
void hidAccelRead(accelVector *vector)
Definition: hid.c:175
void hidExit()
Definition: hid.c:57
uint32_t u32
Definition: types.h:23
void hidCircleRead(circlePosition *pos)
Definition: hid.c:170
PAD_KEY
Definition: hid.h:7
s16 y
Definition: hid.h:61
Definition: hid.h:14
Result HIDUSER_GetHandles(Handle *outMemHandle, Handle *eventpad0, Handle *eventpad1, Handle *eventaccel, Handle *eventgyro, Handle *eventdebugpad)
Definition: hid.c:185
HID_Event
Definition: hid.h:64
Definition: hid.h:9
Definition: hid.h:18
Definition: hid.h:11
Result HIDUSER_DisableAccelerometer()
Definition: hid.c:215
Definition: hid.h:16
u32 hidKeysHeld()
Definition: hid.c:150
Definition: hid.h:13
Definition: hid.h:17
void hidGyroRead(angularRate *rate)
Definition: hid.c:180
Result HIDUSER_EnableGyroscope()
Definition: hid.c:226
Definition: hid.h:15
#define BIT(n)
Definition: types.h:45
Handle hidMemHandle
Definition: hid.c:9
Definition: hid.h:23
u32 hidKeysUp()
Definition: hid.c:160
vu32 * hidSharedMem
Definition: hid.c:13
void hidScanInput()
Definition: hid.c:100
Result HIDUSER_EnableAccelerometer()
Definition: hid.c:204
Definition: hid.h:34
s16 z
Definition: hid.h:54
Definition: hid.h:10
Definition: hid.h:21
Definition: hid.h:35
Definition: hid.h:19
Result HIDUSER_DisableGyroscope()
Definition: hid.c:237
int16_t s16
Definition: types.h:27