| 39 | } |
| 40 | |
| 41 | Result 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 | |
| 71 | cleanup2: |
| 72 | svcCloseHandle(hidMemHandle); |
| 73 | if(hidSharedMem != NULL) |
| 74 | { |
| 75 | mappableFree((void*) hidSharedMem); |
| 76 | hidSharedMem = NULL; |
| 77 | } |
| 78 | cleanup1: |
| 79 | svcCloseHandle(hidHandle); |
| 80 | cleanup0: |
| 81 | AtomicDecrement(&hidRefCount); |
| 82 | return ret; |
| 83 | } |
| 84 | |
| 85 | void hidExit(void) |
| 86 | { |
no test coverage detected