MCPcopy Create free account
hub / github.com/devkitPro/libctru / hidInit

Function hidInit

libctru/source/services/hid.c:41–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41Result hidInit(void)
42{
43 Result ret=0;
44
45 if (AtomicPostIncrement(&hidRefCount)) return 0;
46
47 // Request service.
48 ret = srvGetServiceHandle(&hidHandle, "hid:USER");
49 if (R_FAILED(ret)) ret = srvGetServiceHandle(&hidHandle, "hid:SPVR");
50 if (R_FAILED(ret)) goto cleanup0;
51
52 // Get sharedmem handle.
53 if(R_FAILED(ret=HIDUSER_GetHandles(&hidMemHandle, &hidEvents[HIDEVENT_PAD0], &hidEvents[HIDEVENT_PAD1], &hidEvents[HIDEVENT_Accel], &hidEvents[HIDEVENT_Gyro], &hidEvents[HIDEVENT_DebugPad]))) goto cleanup1;
54
55 // Map HID shared memory.
56 hidSharedMem=(vu32*)mappableAlloc(0x2b0);
57 if(!hidSharedMem)
58 {
59 ret = -1;
60 goto cleanup1;
61 }
62
63 if(R_FAILED(ret=svcMapMemoryBlock(hidMemHandle, (u32)hidSharedMem, MEMPERM_READ, MEMPERM_DONTCARE)))goto cleanup2;
64
65 usingIrrst = hidShouldUseIrrst();
66 if(usingIrrst)
67 ret = irrstInit();
68
69 return ret;
70
71cleanup2:
72 svcCloseHandle(hidMemHandle);
73 if(hidSharedMem != NULL)
74 {
75 mappableFree((void*) hidSharedMem);
76 hidSharedMem = NULL;
77 }
78cleanup1:
79 svcCloseHandle(hidHandle);
80cleanup0:
81 AtomicDecrement(&hidRefCount);
82 return ret;
83}
84
85void hidExit(void)
86{

Callers 1

__appInitFunction · 0.85

Calls 6

srvGetServiceHandleFunction · 0.85
HIDUSER_GetHandlesFunction · 0.85
mappableAllocFunction · 0.85
hidShouldUseIrrstFunction · 0.85
irrstInitFunction · 0.85
mappableFreeFunction · 0.85

Tested by

no test coverage detected