Added usbDsGetState() and usbDsWaitReady().

This commit is contained in:
yellows8 2017-10-10 11:48:39 -04:00
parent d1ba4d4e2b
commit 7333864957
2 changed files with 57 additions and 0 deletions

View File

@ -193,8 +193,12 @@ void usbDsExit(void);
Handle usbDsGetServiceSession(void);
Handle usbDsGetStateChangeEvent(void);
Result usbDsGetState(u32 *out);
Result usbDsGetDsInterface(UsbDsInterface** interface, struct usb_interface_descriptor* descriptor, const char *interface_name);
/// Wait for initialization to finish where data-transfer is usable.
Result usbDsWaitReady(void);
/// IDsInterface
void usbDsInterface_Close(UsbDsInterface* interface);
Result usbDsInterface_GetDsEndpoint(UsbDsInterface* interface, UsbDsEndpoint** endpoint, struct usb_endpoint_descriptor* descriptor);

View File

@ -271,6 +271,59 @@ static Result _usbDsGetEvent(Handle sessionhandle, Handle* handle_out, u64 cmd_i
return rc;
}
Result usbDsGetState(u32 *out) {
if(g_usbDsServiceSession==0)return MAKERESULT(MODULE_LIBNX, LIBNX_NOTINITIALIZED);
IpcCommand c;
ipcInitialize(&c);
struct {
u64 magic;
u64 cmd_id;
} *raw;
raw = ipcPrepareHeader(&c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 4;
Result rc = ipcDispatch(g_usbDsServiceSession);
if (R_SUCCEEDED(rc)) {
IpcCommandResponse r;
ipcParseResponse(&r);
struct {
u64 magic;
u64 result;
u32 out;
} *resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc) && out)*out = resp->out;
}
return rc;
}
Result usbDsWaitReady(void) {
Result rc = 0;
u32 state=0;
s32 tmpindex = 0;
rc = usbDsGetState(&state);
if (R_FAILED(rc)) return rc;
while(R_SUCCEEDED(rc) && state!=5)
{
svcWaitSynchronization(&tmpindex, &g_usbDsStateChangeEvent, 1, U64_MAX);
svcClearEvent(g_usbDsStateChangeEvent);
rc = usbDsGetState(&state);
}
return rc;
}
static Result _usbDsSetVidPidBcd(const usbDsDeviceInfo* deviceinfo) {
if(g_usbDsServiceSession==0)return MAKERESULT(MODULE_LIBNX, LIBNX_NOTINITIALIZED);