4 #if (_MSC_FULL_VER < 180031101) 5 #error At least Visual Studio 2013 Update 4 is required to compile this backend 21 #pragma comment(lib, "winusb.lib") 28 std::shared_ptr<handle_winusb>
handle)
29 : _device(device), _handle(handle)
45 WINUSB_SETUP_PACKET setupPacket;
46 ULONG length_transferred;
48 setupPacket.RequestType = request_type;
49 setupPacket.Request = request;
50 setupPacket.Value =
value;
51 setupPacket.Index =
index;
52 setupPacket.Length =
length;
54 auto interface_number = 0xFF &
index;
55 auto h =
_handle->get_interface_handle(interface_number);
61 if (!WinUsb_ControlTransfer(
h, setupPacket, buffer, length, &length_transferred,
NULL))
63 auto lastResult = GetLastError();
64 LOG_WARNING(
"control_transfer failed, error: " << lastResult);
67 transferred = length_transferred;
73 auto h =
_handle->get_interface_handle(endpoint->get_interface_number());
75 if (!WinUsb_ResetPipe(
h, endpoint->get_address()))
77 auto lastResult = GetLastError();
78 LOG_ERROR(
"control_transfer failed, error: " << lastResult);
86 ULONG length_transferred;
88 auto h =
_handle->get_interface_handle(endpoint->get_interface_number());
95 if (USB_ENDPOINT_DIRECTION_IN(endpoint->get_address()))
96 res = WinUsb_ReadPipe(
h, endpoint->get_address(),
const_cast<unsigned char*
>(
buffer), length, &length_transferred,
NULL);
98 res = WinUsb_WritePipe(
h, endpoint->get_address(),
const_cast<unsigned char*
>(
buffer), length, &length_transferred,
NULL);
101 auto lastResult = GetLastError();
102 LOG_ERROR(
"bulk_transfer failed, error: " << lastResult);
105 transferred = length_transferred;
113 auto sts = WinUsb_SetPipePolicy(handle, endpoint, PIPE_TRANSFER_TIMEOUT,
sizeof(timeout_ms), &timeout_ms);
116 auto lastResult = GetLastError();
117 LOG_ERROR(
"failed to set timeout policy, error: " << lastResult);
125 auto rv = std::make_shared<usb_request_winusb>(
_device, endpoint);
131 ULONG read_pipe_transfer_size = 0;
132 auto ep = request->get_endpoint();
133 auto in = ep->get_interface_number();
134 auto epa = request->get_endpoint()->get_address();
135 auto ovl =
reinterpret_cast<OVERLAPPED*
>(request->get_native_request());
138 auto buffer =
const_cast<uint8_t*
>(request->get_buffer().data());
139 int res = WinUsb_ReadPipe(
h, epa,
buffer, request->get_buffer().size(), &read_pipe_transfer_size, ovl);
143 auto lastError = GetLastError();
144 if (lastError != ERROR_IO_PENDING)
149 ULONG overlapped_transfer_size = 0;
151 auto sts = WinUsb_GetOverlappedResult(
h, ovl, &overlapped_transfer_size,
TRUE);
154 auto cb = request->get_callback();
155 cb->callback(request);
164 auto ovl =
reinterpret_cast<OVERLAPPED*
>(request->get_native_request());
165 auto h =
_handle->get_device_handle();
167 if(CancelIoEx(
h, ovl))
170 auto sts = GetLastError();
176 std::lock_guard<std::mutex> lk(
_mutex);
179 _dispatchers[endpoint] = std::make_shared<dispatcher>(10);
GLuint64 GLenum void * handle
GLfloat GLfloat GLfloat GLfloat h
GLenum GLuint GLenum GLsizei length