Skip to content
This repository was archived by the owner on Jul 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/WinUsb/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ static PInvoke.WinUsb.WinUsb_WritePipe(PInvoke.WinUsb.SafeUsbHandle interfaceHan
static PInvoke.WinUsb.WinUsb_WritePipe(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte pipeID, byte[] buffer, int bufferLength, out int lengthTransferred, System.Threading.NativeOverlapped? overlapped) -> bool
static PInvoke.WinUsb.WinUsb_WritePipeAsync(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte pipeID, System.ReadOnlyMemory<byte> buffer, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.ValueTask<int>
static extern PInvoke.WinUsb.WinUsb_AbortPipe(PInvoke.WinUsb.SafeUsbHandle handle, byte pipeID) -> bool
static extern PInvoke.WinUsb.WinUsb_FlushPipe(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte pipeID) -> bool
static extern PInvoke.WinUsb.WinUsb_GetAssociatedInterface(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte associatedInterfaceIndex, out PInvoke.WinUsb.SafeUsbHandle associatedInterfaceHandle) -> bool
static extern PInvoke.WinUsb.WinUsb_Initialize(PInvoke.Kernel32.SafeObjectHandle deviceHandle, out PInvoke.WinUsb.SafeUsbHandle interfaceHandle) -> bool
static extern PInvoke.WinUsb.WinUsb_QueryPipe(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte alternateInterfaceNumber, byte pipeIndex, PInvoke.WinUsb.WINUSB_PIPE_INFORMATION* pipeInformation) -> bool
static extern PInvoke.WinUsb.WinUsb_ReadPipe(PInvoke.WinUsb.SafeUsbHandle interfaceHandle, byte pipeID, byte* buffer, int bufferLength, out int lengthTransferred, System.Threading.NativeOverlapped* overlapped) -> bool
Expand Down
47 changes: 47 additions & 0 deletions src/WinUsb/WinUsb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,53 @@ public static unsafe extern bool WinUsb_QueryPipe(
byte pipeIndex,
[Friendly(FriendlyFlags.Out)] WINUSB_PIPE_INFORMATION* pipeInformation);

/// <summary>
/// The <see cref="WinUsb_FlushPipe"/> function discards any data that is cached in a pipe. This is a synchronous operation.
/// </summary>
/// <param name="interfaceHandle">
/// An opaque handle to the interface with which the specified pipe's endpoint is associated. To clear data in a pipe that is
/// associated with the endpoint on the first (default) interface, use the handle returned by <see cref="WinUsb_Initialize"/>.
/// For all other interfaces, use the handle to the target interface, retrieved by <see cref="WinUsb_GetAssociatedInterface"/>.
/// </param>
/// <param name="pipeID">
/// 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.
/// This parameter corresponds to the bEndpointAddress field in the endpoint descriptor.
/// </param>
/// <returns>
/// <see cref="WinUsb_FlushPipe"/> returns <see langword="true"/> if the operation succeeds. Otherwise, this routine returns
/// <see langword="false"/>, and the caller can retrieve the logged error by calling <see cref="Kernel32.GetLastError"/>.
/// </returns>
[DllImport(nameof(WinUsb), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static unsafe extern bool WinUsb_FlushPipe(
SafeUsbHandle interfaceHandle,
byte pipeID);

/// <summary>
/// The <see cref="WinUsb_GetAssociatedInterface"/> function retrieves a handle for an associated interface. This is a synchronous operation.
/// </summary>
/// <param name="interfaceHandle">
/// An opaque handle to the first (default) interface on the device, which is returned by <see cref="WinUsb_Initialize"/>.
/// </param>
/// <param name="associatedInterfaceIndex">
/// An index that specifies the associated interface to retrieve. A value of 0 indicates the first associated interface,
/// a value of 1 indicates the second associated interface, and so on.
/// </param>
/// <param name="associatedInterfaceHandle">
/// A handle for the associated interface. Callers must pass this interface handle to WinUSB Functions exposed by <c>Winusb.dll</c>.
/// To close this handle, call <see cref="WinUsb_Free"/>.
/// </param>
/// <returns>
/// <see cref="WinUsb_GetAssociatedInterface"/> returns <see langword="true"/> if the operation succeeds. Otherwise, this routine returns
/// <see langword="true"/>, and the caller can retrieve the logged error by calling <see cref="Kernel32.GetLastError"/>.
/// </returns>
[DllImport(nameof(WinUsb), SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static unsafe extern bool WinUsb_GetAssociatedInterface(
SafeUsbHandle interfaceHandle,
byte associatedInterfaceIndex,
out SafeUsbHandle associatedInterfaceHandle);

/// <summary>
/// Writes data to a pipe.
/// </summary>
Expand Down