mirror of
https://github.com/switchbrew/libnx.git
synced 2025-08-06 08:19:22 +02:00
Added usbCommsSetErrorHandling, don't throw fatalSimple for usbComms by default.
This commit is contained in:
parent
493d433ac2
commit
cfbc3e9278
@ -23,6 +23,9 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf
|
|||||||
/// Exits usbComms.
|
/// Exits usbComms.
|
||||||
void usbCommsExit(void);
|
void usbCommsExit(void);
|
||||||
|
|
||||||
|
/// Sets whether to throw a fatal error in usbComms{Read/Write}* on failure, or just return the transferred size. By default (false) the latter is used.
|
||||||
|
void usbCommsSetErrorHandling(bool flag);
|
||||||
|
|
||||||
/// Read data with the default interface.
|
/// Read data with the default interface.
|
||||||
size_t usbCommsRead(void* buffer, size_t size);
|
size_t usbCommsRead(void* buffer, size_t size);
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ static bool g_usbCommsInitialized = false;
|
|||||||
|
|
||||||
static usbCommsInterface g_usbCommsInterfaces[TOTAL_INTERFACES];
|
static usbCommsInterface g_usbCommsInterfaces[TOTAL_INTERFACES];
|
||||||
|
|
||||||
|
static bool g_usbCommsErrorHandling = 0;
|
||||||
|
|
||||||
static RwLock g_usbCommsLock;
|
static RwLock g_usbCommsLock;
|
||||||
|
|
||||||
static Result _usbCommsInterfaceInit1x(u32 intf_ind, const UsbCommsInterfaceInfo *info);
|
static Result _usbCommsInterfaceInit1x(u32 intf_ind, const UsbCommsInterfaceInfo *info);
|
||||||
@ -143,7 +145,10 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) g_usbCommsInitialized = true;
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
g_usbCommsInitialized = true;
|
||||||
|
g_usbCommsErrorHandling = false;
|
||||||
|
}
|
||||||
|
|
||||||
rwlockWriteUnlock(&g_usbCommsLock);
|
rwlockWriteUnlock(&g_usbCommsLock);
|
||||||
return rc;
|
return rc;
|
||||||
@ -386,6 +391,10 @@ static Result _usbCommsInterfaceInit1x(u32 intf_ind, const UsbCommsInterfaceInfo
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void usbCommsSetErrorHandling(bool flag) {
|
||||||
|
g_usbCommsErrorHandling = flag;
|
||||||
|
}
|
||||||
|
|
||||||
static Result _usbCommsRead(usbCommsInterface *interface, void* buffer, size_t size, size_t *transferredSize)
|
static Result _usbCommsRead(usbCommsInterface *interface, void* buffer, size_t size, size_t *transferredSize)
|
||||||
{
|
{
|
||||||
Result rc=0;
|
Result rc=0;
|
||||||
@ -542,7 +551,7 @@ size_t usbCommsReadEx(void* buffer, size_t size, u32 interface)
|
|||||||
rwlockWriteUnlock(&inter->lock_out);
|
rwlockWriteUnlock(&inter->lock_out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (R_FAILED(rc)) fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadUsbCommsRead));
|
if (R_FAILED(rc) && g_usbCommsErrorHandling) fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadUsbCommsRead));
|
||||||
}
|
}
|
||||||
return transferredSize;
|
return transferredSize;
|
||||||
}
|
}
|
||||||
@ -579,7 +588,7 @@ size_t usbCommsWriteEx(const void* buffer, size_t size, u32 interface)
|
|||||||
rwlockWriteUnlock(&inter->lock_in);
|
rwlockWriteUnlock(&inter->lock_in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (R_FAILED(rc)) fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadUsbCommsWrite));
|
if (R_FAILED(rc) && g_usbCommsErrorHandling) fatalSimple(MAKERESULT(Module_Libnx, LibnxError_BadUsbCommsWrite));
|
||||||
}
|
}
|
||||||
return transferredSize;
|
return transferredSize;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user