Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.

Commit 1e5436f

Browse files
authored
Merge pull request #586 from qmfrederik/features/more-winusb-apis
Add WinUsb_FlushPipe, WinUsb_GetAssociatedInterface
2 parents 891ad63 + 2e82470 commit 1e5436f

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/WinUsb/PublicAPI.Unshipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ static PInvoke.WinUsb.WinUsb_WritePipe(PInvoke.WinUsb.SafeUsbHandle interfaceHan
2525
static PInvoke.WinUsb.WinUsb_WritePipe(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte pipeID, byte[] buffer, int bufferLength, out int lengthTransferred, System.Threading.NativeOverlapped? overlapped) -> bool
2626
static PInvoke.WinUsb.WinUsb_WritePipeAsync(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte pipeID, System.ReadOnlyMemory<byte> buffer, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<int>
2727
static extern PInvoke.WinUsb.WinUsb_AbortPipe(PInvoke.WinUsb.SafeUsbHandle handle, byte pipeID) -> bool
28+
static extern PInvoke.WinUsb.WinUsb_FlushPipe(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte pipeID) -> bool
29+
static extern PInvoke.WinUsb.WinUsb_GetAssociatedInterface(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte associatedInterfaceIndex, out PInvoke.WinUsb.SafeUsbHandle associatedInterfaceHandle) -> bool
2830
static extern PInvoke.WinUsb.WinUsb_Initialize(PInvoke.Kernel32.SafeObjectHandle deviceHandle, out PInvoke.WinUsb.SafeUsbHandle interfaceHandle) -> bool
2931
static extern PInvoke.WinUsb.WinUsb_QueryPipe(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte alternateInterfaceNumber, byte pipeIndex, PInvoke.WinUsb.WINUSB_PIPE_INFORMATION* pipeInformation) -> bool
3032
static extern PInvoke.WinUsb.WinUsb_ReadPipe(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte pipeID, byte* buffer, int bufferLength, out int lengthTransferred, System.Threading.NativeOverlapped* overlapped) -> bool

src/WinUsb/WinUsb.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,53 @@ public static unsafe extern bool WinUsb_QueryPipe(
6161
byte pipeIndex,
6262
[Friendly(FriendlyFlags.Out)] WINUSB_PIPE_INFORMATION* pipeInformation);
6363

64+
/// <summary>
65+
/// The <see cref="WinUsb_FlushPipe"/> function discards any data that is cached in a pipe. This is a synchronous operation.
66+
/// </summary>
67+
/// <param name="interfaceHandle">
68+
/// An opaque handle to the interface with which the specified pipe's endpoint is associated. To clear data in a pipe that is
69+
/// associated with the endpoint on the first (default) interface, use the handle returned by <see cref="WinUsb_Initialize"/>.
70+
/// For all other interfaces, use the handle to the target interface, retrieved by <see cref="WinUsb_GetAssociatedInterface"/>.
71+
/// </param>
72+
/// <param name="pipeID">
73+
/// The identifier (ID) of the control pipe. The PipeID parameter is an 8-bit value that consists of a 7-bit address and a direction bit.
74+
/// This parameter corresponds to the bEndpointAddress field in the endpoint descriptor.
75+
/// </param>
76+
/// <returns>
77+
/// <see cref="WinUsb_FlushPipe"/> returns <see langword="true"/> if the operation succeeds. Otherwise, this routine returns
78+
/// <see langword="false"/>, and the caller can retrieve the logged error by calling <see cref="Kernel32.GetLastError"/>.
79+
/// </returns>
80+
[DllImport(nameof(WinUsb), SetLastError = true)]
81+
[return: MarshalAs(UnmanagedType.Bool)]
82+
public static unsafe extern bool WinUsb_FlushPipe(
83+
SafeUsbHandle interfaceHandle,
84+
byte pipeID);
85+
86+
/// <summary>
87+
/// The <see cref="WinUsb_GetAssociatedInterface"/> function retrieves a handle for an associated interface. This is a synchronous operation.
88+
/// </summary>
89+
/// <param name="interfaceHandle">
90+
/// An opaque handle to the first (default) interface on the device, which is returned by <see cref="WinUsb_Initialize"/>.
91+
/// </param>
92+
/// <param name="associatedInterfaceIndex">
93+
/// An index that specifies the associated interface to retrieve. A value of 0 indicates the first associated interface,
94+
/// a value of 1 indicates the second associated interface, and so on.
95+
/// </param>
96+
/// <param name="associatedInterfaceHandle">
97+
/// A handle for the associated interface. Callers must pass this interface handle to WinUSB Functions exposed by <c>Winusb.dll</c>.
98+
/// To close this handle, call <see cref="WinUsb_Free"/>.
99+
/// </param>
100+
/// <returns>
101+
/// <see cref="WinUsb_GetAssociatedInterface"/> returns <see langword="true"/> if the operation succeeds. Otherwise, this routine returns
102+
/// <see langword="true"/>, and the caller can retrieve the logged error by calling <see cref="Kernel32.GetLastError"/>.
103+
/// </returns>
104+
[DllImport(nameof(WinUsb), SetLastError = true)]
105+
[return: MarshalAs(UnmanagedType.Bool)]
106+
public static unsafe extern bool WinUsb_GetAssociatedInterface(
107+
SafeUsbHandle interfaceHandle,
108+
byte associatedInterfaceIndex,
109+
out SafeUsbHandle associatedInterfaceHandle);
110+
64111
/// <summary>
65112
/// Writes data to a pipe.
66113
/// </summary>

0 commit comments

Comments
 (0)