2014-01-19 13:33:28 +01:00
|
|
|
#include <stdlib.h>
|
2014-08-16 23:48:05 +02:00
|
|
|
#include <string.h>
|
2014-07-28 21:41:48 +02:00
|
|
|
#include <3ds/types.h>
|
|
|
|
#include <3ds/HID.h>
|
|
|
|
#include <3ds/srv.h>
|
|
|
|
#include <3ds/svc.h>
|
2014-01-19 13:33:28 +01:00
|
|
|
|
2014-02-03 18:21:17 +01:00
|
|
|
Handle hidHandle;
|
|
|
|
Handle hidMemHandle;
|
|
|
|
|
|
|
|
vu32* hidSharedMem;
|
|
|
|
|
2014-03-17 18:38:20 +01:00
|
|
|
Result hidInit(u32* sharedMem)
|
2014-02-03 18:21:17 +01:00
|
|
|
{
|
|
|
|
if(!sharedMem)sharedMem=(u32*)HID_SHAREDMEM_DEFAULT;
|
2014-03-17 18:38:20 +01:00
|
|
|
Result ret=0;
|
2014-02-03 18:21:17 +01:00
|
|
|
|
2014-07-28 23:23:24 +02:00
|
|
|
if((ret=srvGetServiceHandle(&hidHandle, "hid:USER")))return ret;
|
2014-02-03 18:21:17 +01:00
|
|
|
|
2014-03-17 18:38:20 +01:00
|
|
|
if((ret=HIDUSER_GetInfo(NULL, &hidMemHandle)))return ret;
|
2014-02-03 18:21:17 +01:00
|
|
|
hidSharedMem=sharedMem;
|
2014-08-16 23:48:05 +02:00
|
|
|
svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, 0x10000000);
|
2014-02-03 18:21:17 +01:00
|
|
|
|
2014-03-17 18:38:20 +01:00
|
|
|
if((ret=HIDUSER_EnableAccelerometer(NULL)))return ret;
|
|
|
|
|
|
|
|
return 0;
|
2014-02-03 18:21:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void hidExit()
|
|
|
|
{
|
2014-07-28 20:58:47 +02:00
|
|
|
svcUnmapMemoryBlock(hidMemHandle, (u32)hidSharedMem);
|
|
|
|
svcCloseHandle(hidMemHandle);
|
|
|
|
svcCloseHandle(hidHandle);
|
2014-02-03 18:21:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result HIDUSER_GetInfo(Handle* handle, Handle* outMemHandle)
|
2014-01-19 13:33:28 +01:00
|
|
|
{
|
2014-02-03 18:21:17 +01:00
|
|
|
if(!handle)handle=&hidHandle;
|
2014-01-28 23:43:59 +01:00
|
|
|
u32* cmdbuf=getThreadCommandBuffer();
|
|
|
|
cmdbuf[0]=0xa0000; //request header code
|
|
|
|
|
|
|
|
Result ret=0;
|
2014-07-28 20:58:47 +02:00
|
|
|
if((ret=svcSendSyncRequest(*handle)))return ret;
|
2014-01-28 23:43:59 +01:00
|
|
|
|
|
|
|
if(outMemHandle)*outMemHandle=cmdbuf[3];
|
|
|
|
|
|
|
|
return cmdbuf[1];
|
2014-01-19 13:33:28 +01:00
|
|
|
}
|
|
|
|
|
2014-03-17 18:38:20 +01:00
|
|
|
Result HIDUSER_EnableAccelerometer(Handle* handle)
|
2014-01-19 13:33:28 +01:00
|
|
|
{
|
2014-02-03 18:21:17 +01:00
|
|
|
if(!handle)handle=&hidHandle;
|
2014-01-28 23:43:59 +01:00
|
|
|
u32* cmdbuf=getThreadCommandBuffer();
|
|
|
|
cmdbuf[0]=0x110000; //request header code
|
|
|
|
|
|
|
|
Result ret=0;
|
2014-07-28 20:58:47 +02:00
|
|
|
if((ret=svcSendSyncRequest(*handle)))return ret;
|
2014-01-28 23:43:59 +01:00
|
|
|
|
|
|
|
return cmdbuf[1];
|
2014-01-19 13:33:28 +01:00
|
|
|
}
|