mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 04:52:39 +02:00
usb: add UsbState enum (#512)
This commit is contained in:
parent
e8a4f22063
commit
21b0613fa4
@ -207,3 +207,14 @@ enum usb_iso_usage_type {
|
|||||||
USB_ISO_USAGE_TYPE_IMPLICIT = 2,
|
USB_ISO_USAGE_TYPE_IMPLICIT = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// USB Device States, per USB 2.0 spec
|
||||||
|
typedef enum {
|
||||||
|
UsbState_Detached = 0, ///< Device is not attached to USB.
|
||||||
|
UsbState_Attached = 1, ///< Device is attached, but is not powered.
|
||||||
|
UsbState_Powered = 2, ///< Device is attached and powered, but has not been reset.
|
||||||
|
UsbState_Default = 3, ///< Device is attached, powered, and has been reset, but does not have an address.
|
||||||
|
UsbState_Address = 4, ///< Device is attached, powered, has been reset, has an address, but is not configured.
|
||||||
|
UsbState_Configured = 5, ///< Device is attached, powered, has been reset, has an address, configured, and may be used.
|
||||||
|
UsbState_Suspended = 6, ///< Device is attached and powered, but has not seen bus activity for 3ms. Device is suspended and cannot be used.
|
||||||
|
} UsbState;
|
||||||
|
|
||||||
|
@ -79,7 +79,9 @@ Result usbDsParseReportData(UsbDsReportData *reportdata, u32 urbId, u32 *request
|
|||||||
///@{
|
///@{
|
||||||
|
|
||||||
Event* usbDsGetStateChangeEvent(void);
|
Event* usbDsGetStateChangeEvent(void);
|
||||||
Result usbDsGetState(u32* out);
|
|
||||||
|
/// Gets the device state. See \ref UsbState.
|
||||||
|
Result usbDsGetState(UsbState* out);
|
||||||
|
|
||||||
/// Removed in [5.0.0+].
|
/// Removed in [5.0.0+].
|
||||||
Result usbDsGetDsInterface(UsbDsInterface** out, struct usb_interface_descriptor* descriptor, const char* interface_name);
|
Result usbDsGetDsInterface(UsbDsInterface** out, struct usb_interface_descriptor* descriptor, const char* interface_name);
|
||||||
|
@ -223,18 +223,19 @@ static Result _usbDsBindDevice(UsbComplexId complexId, Handle prochandle) {
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result usbDsGetState(u32 *out) {
|
Result usbDsGetState(UsbState *out) {
|
||||||
return _usbDsCmdNoInOutU32(&g_usbDsSrv, out, hosversionAtLeast(11,0,0) ? 3 : 4);
|
_Static_assert(sizeof(*out) == sizeof(u32));
|
||||||
|
return _usbDsCmdNoInOutU32(&g_usbDsSrv, (u32 *)out, hosversionAtLeast(11,0,0) ? 3 : 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result usbDsWaitReady(u64 timeout) {
|
Result usbDsWaitReady(u64 timeout) {
|
||||||
Result rc;
|
Result rc;
|
||||||
u32 state = 0;
|
UsbState state = UsbState_Detached;
|
||||||
|
|
||||||
rc = usbDsGetState(&state);
|
rc = usbDsGetState(&state);
|
||||||
if (R_FAILED(rc)) return rc;
|
if (R_FAILED(rc)) return rc;
|
||||||
|
|
||||||
while (R_SUCCEEDED(rc) && state != 5) {
|
while (R_SUCCEEDED(rc) && state != UsbState_Configured) {
|
||||||
eventWait(&g_usbDsStateChangeEvent, timeout);
|
eventWait(&g_usbDsStateChangeEvent, timeout);
|
||||||
eventClear(&g_usbDsStateChangeEvent);
|
eventClear(&g_usbDsStateChangeEvent);
|
||||||
rc = usbDsGetState(&state);
|
rc = usbDsGetState(&state);
|
||||||
|
Loading…
Reference in New Issue
Block a user