mirror of
https://github.com/switchbrew/libnx.git
synced 2025-08-10 18:19:24 +02:00
usbds: Updated for new-ipc. Added sysver checking. Updated the intf_num param type for usbDsRegisterInterfaceEx, likewise with intf_num fields used elsewhere. Renamed the Service 'h' field in UsbDsInterface/UsbDsEndpoint to 's'. Minor improvements + improved docs.
usbComms: Fixed locking issue which caused a hang in usbCommsInitialize*() when init fails.
This commit is contained in:
parent
45bf08bf8d
commit
e82819d8a4
@ -7,12 +7,28 @@
|
||||
*/
|
||||
#pragma once
|
||||
#include "../types.h"
|
||||
#include "../services/sm.h"
|
||||
#include "../sf/service.h"
|
||||
#include "../services/usb.h"
|
||||
#include "../kernel/event.h"
|
||||
|
||||
#define USBDS_DEFAULT_InterfaceNumber 0x4 ///Value for usb_interface_descriptor bInterfaceNumber for automatically allocating the actual bInterfaceNumber.
|
||||
|
||||
typedef struct {
|
||||
bool initialized;
|
||||
u8 interface_index;
|
||||
Service s;
|
||||
|
||||
Event SetupEvent;
|
||||
Event CtrlInCompletionEvent;
|
||||
Event CtrlOutCompletionEvent;
|
||||
} UsbDsInterface;
|
||||
|
||||
typedef struct {
|
||||
bool initialized;
|
||||
Service s;
|
||||
Event CompletionEvent;
|
||||
} UsbDsEndpoint;
|
||||
|
||||
typedef struct {
|
||||
u16 idVendor; ///< VID
|
||||
u16 idProduct; ///< PID
|
||||
@ -34,22 +50,6 @@ typedef struct {
|
||||
u32 report_count;
|
||||
} UsbDsReportData;
|
||||
|
||||
typedef struct {
|
||||
bool initialized;
|
||||
u32 interface_index;
|
||||
Service h;
|
||||
|
||||
Event SetupEvent;
|
||||
Event CtrlInCompletionEvent;
|
||||
Event CtrlOutCompletionEvent;
|
||||
} UsbDsInterface;
|
||||
|
||||
typedef struct {
|
||||
bool initialized;
|
||||
Service h;
|
||||
Event CompletionEvent;
|
||||
} UsbDsEndpoint;
|
||||
|
||||
typedef enum {
|
||||
UsbComplexId_Default = 0x2
|
||||
} UsbComplexId;
|
||||
@ -62,35 +62,66 @@ typedef enum {
|
||||
|
||||
/// Opens a session with usb:ds.
|
||||
Result usbDsInitialize(void);
|
||||
|
||||
/// Closes the usb:ds session. Any interfaces/endpoints which are left open are automatically closed, since otherwise usb-sysmodule won't fully reset usb:ds to defaults.
|
||||
void usbDsExit(void);
|
||||
|
||||
/// Gets the Service object for the actual usb:ds service session.
|
||||
Service* usbDsGetServiceSession(void);
|
||||
|
||||
/// Helpers
|
||||
/// Helper func.
|
||||
Result usbDsWaitReady(u64 timeout);
|
||||
|
||||
/// Helper func.
|
||||
Result usbDsParseReportData(UsbDsReportData *reportdata, u32 urbId, u32 *requestedSize, u32 *transferredSize);
|
||||
|
||||
/// IDsService
|
||||
///@name IDsService
|
||||
///@{
|
||||
|
||||
Event* usbDsGetStateChangeEvent(void);
|
||||
Result usbDsGetState(u32* out);
|
||||
|
||||
/// Removed in [5.0.0+]
|
||||
/// Removed in [5.0.0+].
|
||||
Result usbDsGetDsInterface(UsbDsInterface** out, struct usb_interface_descriptor* descriptor, const char* interface_name);
|
||||
|
||||
/// Removed in [5.0.0+].
|
||||
Result usbDsSetVidPidBcd(const UsbDsDeviceInfo* deviceinfo);
|
||||
|
||||
/// Added in [5.0.0+]
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsRegisterInterface(UsbDsInterface** out);
|
||||
Result usbDsRegisterInterfaceEx(UsbDsInterface** out, u32 intf_num);
|
||||
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsRegisterInterfaceEx(UsbDsInterface** out, u8 intf_num);
|
||||
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsClearDeviceData(void);
|
||||
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsAddUsbStringDescriptor(u8* out_index, const char* string);
|
||||
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsAddUsbLanguageStringDescriptor(u8* out_index, const u16* lang_ids, u16 num_langs);
|
||||
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsDeleteUsbStringDescriptor(u8 index);
|
||||
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsSetUsbDeviceDescriptor(UsbDeviceSpeed speed, struct usb_device_descriptor* descriptor);
|
||||
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsSetBinaryObjectStore(const void* bos, size_t bos_size);
|
||||
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsEnable(void);
|
||||
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsDisable(void);
|
||||
|
||||
/// IDsInterface
|
||||
///@}
|
||||
|
||||
///@name IDsInterface
|
||||
///@{
|
||||
|
||||
void usbDsInterface_Close(UsbDsInterface* interface);
|
||||
|
||||
Result usbDsInterface_GetSetupPacket(UsbDsInterface* interface, void* buffer, size_t size);
|
||||
@ -102,15 +133,20 @@ Result usbDsInterface_GetCtrlInReportData(UsbDsInterface* interface, UsbDsReport
|
||||
Result usbDsInterface_GetCtrlOutReportData(UsbDsInterface* interface, UsbDsReportData* out);
|
||||
Result usbDsInterface_StallCtrl(UsbDsInterface* interface);
|
||||
|
||||
/// Removed in [5.0.0+]
|
||||
/// Removed in [5.0.0+].
|
||||
Result usbDsInterface_GetDsEndpoint(UsbDsInterface* interface, UsbDsEndpoint** endpoint, struct usb_endpoint_descriptor* descriptor);
|
||||
|
||||
/// Added in [5.0.0+]
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsInterface_RegisterEndpoint(UsbDsInterface* interface, UsbDsEndpoint** endpoint, u8 endpoint_address);
|
||||
|
||||
/// Only available on [5.0.0+].
|
||||
Result usbDsInterface_AppendConfigurationData(UsbDsInterface* interface, UsbDeviceSpeed speed, const void* buffer, size_t size);
|
||||
|
||||
///@}
|
||||
|
||||
///@name IDsEndpoint
|
||||
///@{
|
||||
|
||||
/// IDsEndpoint
|
||||
void usbDsEndpoint_Close(UsbDsEndpoint* endpoint);
|
||||
|
||||
Result usbDsEndpoint_Cancel(UsbDsEndpoint* endpoint);
|
||||
@ -119,3 +155,5 @@ Result usbDsEndpoint_GetReportData(UsbDsEndpoint* endpoint, UsbDsReportData* out
|
||||
Result usbDsEndpoint_Stall(UsbDsEndpoint* endpoint);
|
||||
Result usbDsEndpoint_SetZlt(UsbDsEndpoint* endpoint, bool zlt); // Sets Zero Length Termination for endpoint
|
||||
|
||||
///@}
|
||||
|
||||
|
@ -140,10 +140,6 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf
|
||||
if (R_SUCCEEDED(rc) && hosversionAtLeast(5,0,0)) {
|
||||
rc = usbDsEnable();
|
||||
}
|
||||
|
||||
if (R_FAILED(rc)) {
|
||||
usbCommsExit();
|
||||
}
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
@ -152,6 +148,11 @@ Result usbCommsInitializeEx(u32 num_interfaces, const UsbCommsInterfaceInfo *inf
|
||||
}
|
||||
|
||||
rwlockWriteUnlock(&g_usbCommsLock);
|
||||
|
||||
if (R_FAILED(rc)) {
|
||||
usbCommsExit();
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user